blob: 220ec15e9864adb6dd6d71fd668722bf1d0ab6fc [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Chris Wilsonf13d3f72010-09-20 17:36:15 +010043enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010044 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010046 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047};
Ben Gamari433e12f2009-02-17 20:08:51 -050048
Damien Lespiau497666d2013-10-15 18:55:39 +010049/* As the drm_debugfs_init() routines are called before dev->dev_private is
50 * allocated we need to hook into the minor for release. */
51static int
52drm_add_fake_info_node(struct drm_minor *minor,
53 struct dentry *ent,
54 const void *key)
55{
56 struct drm_info_node *node;
57
58 node = kmalloc(sizeof(*node), GFP_KERNEL);
59 if (node == NULL) {
60 debugfs_remove(ent);
61 return -ENOMEM;
62 }
63
64 node->minor = minor;
65 node->dent = ent;
66 node->info_ent = (void *) key;
67
68 mutex_lock(&minor->debugfs_lock);
69 list_add(&node->list, &minor->debugfs_list);
70 mutex_unlock(&minor->debugfs_lock);
71
72 return 0;
73}
74
Chris Wilson70d39fe2010-08-25 16:03:34 +010075static int i915_capabilities(struct seq_file *m, void *data)
76{
Damien Lespiau9f25d002014-05-13 15:30:28 +010077 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010078 struct drm_device *dev = node->minor->dev;
79 const struct intel_device_info *info = INTEL_INFO(dev);
80
81 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030082 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010083#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
84#define SEP_SEMICOLON ;
85 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
86#undef PRINT_FLAG
87#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010088
89 return 0;
90}
Ben Gamari433e12f2009-02-17 20:08:51 -050091
Imre Deaka7363de2016-05-12 16:18:52 +030092static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000093{
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010094 return obj->active ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000095}
96
Imre Deaka7363de2016-05-12 16:18:52 +030097static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010098{
99 return obj->pin_display ? 'p' : ' ';
100}
101
Imre Deaka7363de2016-05-12 16:18:52 +0300102static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000103{
Akshay Joshi0206e352011-08-16 15:34:10 -0400104 switch (obj->tiling_mode) {
105 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100106 case I915_TILING_NONE: return ' ';
107 case I915_TILING_X: return 'X';
108 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -0400109 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000110}
111
Imre Deaka7363de2016-05-12 16:18:52 +0300112static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700113{
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100114 return i915_gem_obj_to_ggtt(obj) ? 'g' : ' ';
115}
116
Imre Deaka7363de2016-05-12 16:18:52 +0300117static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100118{
119 return obj->mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700120}
121
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100122static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
123{
124 u64 size = 0;
125 struct i915_vma *vma;
126
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000127 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson596c5922016-02-26 11:03:20 +0000128 if (vma->is_ggtt && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100129 size += vma->node.size;
130 }
131
132 return size;
133}
134
Chris Wilson37811fc2010-08-25 22:45:57 +0100135static void
136describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
137{
Chris Wilsonb4716182015-04-27 13:41:17 +0100138 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000139 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700140 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800141 int pin_count = 0;
Dave Gordonc3232b12016-03-23 18:19:53 +0000142 enum intel_engine_id id;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800143
Chris Wilson188c1ab2016-04-03 14:14:20 +0100144 lockdep_assert_held(&obj->base.dev->struct_mutex);
145
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100146 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100147 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100148 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100149 get_pin_flag(obj),
150 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700151 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100152 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800153 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100154 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100155 obj->base.write_domain);
Dave Gordonc3232b12016-03-23 18:19:53 +0000156 for_each_engine_id(engine, dev_priv, id)
Chris Wilsonb4716182015-04-27 13:41:17 +0100157 seq_printf(m, "%x ",
Dave Gordonc3232b12016-03-23 18:19:53 +0000158 i915_gem_request_get_seqno(obj->last_read_req[id]));
Chris Wilsonb4716182015-04-27 13:41:17 +0100159 seq_printf(m, "] %x %x%s%s%s",
John Harrison97b2a6a2014-11-24 18:49:26 +0000160 i915_gem_request_get_seqno(obj->last_write_req),
161 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100162 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100163 obj->dirty ? " dirty" : "",
164 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
165 if (obj->base.name)
166 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000167 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800168 if (vma->pin_count > 0)
169 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300170 }
171 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100172 if (obj->pin_display)
173 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100174 if (obj->fence_reg != I915_FENCE_REG_NONE)
175 seq_printf(m, " (fence: %d)", obj->fence_reg);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000176 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100177 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson596c5922016-02-26 11:03:20 +0000178 vma->is_ggtt ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100179 vma->node.start, vma->node.size);
Chris Wilson596c5922016-02-26 11:03:20 +0000180 if (vma->is_ggtt)
181 seq_printf(m, ", type: %u", vma->ggtt_view.type);
182 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700183 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000184 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100185 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100186 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000187 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100188 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000189 *t++ = 'p';
190 if (obj->fault_mappable)
191 *t++ = 'f';
192 *t = '\0';
193 seq_printf(m, " (%s mappable)", s);
194 }
Chris Wilsonb4716182015-04-27 13:41:17 +0100195 if (obj->last_write_req != NULL)
John Harrison41c52412014-11-24 18:49:43 +0000196 seq_printf(m, " (%s)",
Tvrtko Ursulin666796d2016-03-16 11:00:39 +0000197 i915_gem_request_get_engine(obj->last_write_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200198 if (obj->frontbuffer_bits)
199 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100200}
201
Oscar Mateo273497e2014-05-22 14:13:37 +0100202static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700203{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100204 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700205 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
206 seq_putc(m, ' ');
207}
208
Ben Gamari433e12f2009-02-17 20:08:51 -0500209static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500210{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100211 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500212 uintptr_t list = (uintptr_t) node->info_ent->data;
213 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500214 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300215 struct drm_i915_private *dev_priv = to_i915(dev);
216 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Ben Widawskyca191b12013-07-31 17:00:14 -0700217 struct i915_vma *vma;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300218 u64 total_obj_size, total_gtt_size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100219 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100220
221 ret = mutex_lock_interruptible(&dev->struct_mutex);
222 if (ret)
223 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500224
Ben Widawskyca191b12013-07-31 17:00:14 -0700225 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500226 switch (list) {
227 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100228 seq_puts(m, "Active:\n");
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300229 head = &ggtt->base.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500230 break;
231 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100232 seq_puts(m, "Inactive:\n");
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300233 head = &ggtt->base.inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500234 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500235 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100236 mutex_unlock(&dev->struct_mutex);
237 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500238 }
239
Chris Wilson8f2480f2010-09-26 11:44:19 +0100240 total_obj_size = total_gtt_size = count = 0;
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000241 list_for_each_entry(vma, head, vm_link) {
Ben Widawskyca191b12013-07-31 17:00:14 -0700242 seq_printf(m, " ");
243 describe_obj(m, vma->obj);
244 seq_printf(m, "\n");
245 total_obj_size += vma->obj->base.size;
246 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100247 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500248 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100249 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700250
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300251 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson8f2480f2010-09-26 11:44:19 +0100252 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500253 return 0;
254}
255
Chris Wilson6d2b88852013-08-07 18:30:54 +0100256static int obj_rank_by_stolen(void *priv,
257 struct list_head *A, struct list_head *B)
258{
259 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200260 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100261 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200262 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100263
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200264 if (a->stolen->start < b->stolen->start)
265 return -1;
266 if (a->stolen->start > b->stolen->start)
267 return 1;
268 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100269}
270
271static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
272{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100273 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100274 struct drm_device *dev = node->minor->dev;
275 struct drm_i915_private *dev_priv = dev->dev_private;
276 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300277 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100278 LIST_HEAD(stolen);
279 int count, ret;
280
281 ret = mutex_lock_interruptible(&dev->struct_mutex);
282 if (ret)
283 return ret;
284
285 total_obj_size = total_gtt_size = count = 0;
286 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
287 if (obj->stolen == NULL)
288 continue;
289
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200290 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100291
292 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100293 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100294 count++;
295 }
296 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
297 if (obj->stolen == NULL)
298 continue;
299
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200300 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100301
302 total_obj_size += obj->base.size;
303 count++;
304 }
305 list_sort(NULL, &stolen, obj_rank_by_stolen);
306 seq_puts(m, "Stolen:\n");
307 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200308 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100309 seq_puts(m, " ");
310 describe_obj(m, obj);
311 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200312 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100313 }
314 mutex_unlock(&dev->struct_mutex);
315
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300316 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100317 count, total_obj_size, total_gtt_size);
318 return 0;
319}
320
Chris Wilson6299f992010-11-24 12:23:44 +0000321#define count_objects(list, member) do { \
322 list_for_each_entry(obj, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100323 size += i915_gem_obj_total_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000324 ++count; \
325 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700326 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000327 ++mappable_count; \
328 } \
329 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400330} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000331
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100332struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000333 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300334 unsigned long count;
335 u64 total, unbound;
336 u64 global, shared;
337 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100338};
339
340static int per_file_stats(int id, void *ptr, void *data)
341{
342 struct drm_i915_gem_object *obj = ptr;
343 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000344 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100345
346 stats->count++;
347 stats->total += obj->base.size;
348
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000349 if (obj->base.name || obj->base.dma_buf)
350 stats->shared += obj->base.size;
351
Chris Wilson6313c202014-03-19 13:45:45 +0000352 if (USES_FULL_PPGTT(obj->base.dev)) {
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000353 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson6313c202014-03-19 13:45:45 +0000354 struct i915_hw_ppgtt *ppgtt;
355
356 if (!drm_mm_node_allocated(&vma->node))
357 continue;
358
Chris Wilson596c5922016-02-26 11:03:20 +0000359 if (vma->is_ggtt) {
Chris Wilson6313c202014-03-19 13:45:45 +0000360 stats->global += obj->base.size;
361 continue;
362 }
363
364 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200365 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000366 continue;
367
John Harrison41c52412014-11-24 18:49:43 +0000368 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000369 stats->active += obj->base.size;
370 else
371 stats->inactive += obj->base.size;
372
373 return 0;
374 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100375 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000376 if (i915_gem_obj_ggtt_bound(obj)) {
377 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000378 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000379 stats->active += obj->base.size;
380 else
381 stats->inactive += obj->base.size;
382 return 0;
383 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100384 }
385
Chris Wilson6313c202014-03-19 13:45:45 +0000386 if (!list_empty(&obj->global_list))
387 stats->unbound += obj->base.size;
388
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100389 return 0;
390}
391
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100392#define print_file_stats(m, name, stats) do { \
393 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300394 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 +0100395 name, \
396 stats.count, \
397 stats.total, \
398 stats.active, \
399 stats.inactive, \
400 stats.global, \
401 stats.shared, \
402 stats.unbound); \
403} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800404
405static void print_batch_pool_stats(struct seq_file *m,
406 struct drm_i915_private *dev_priv)
407{
408 struct drm_i915_gem_object *obj;
409 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000410 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000411 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800412
413 memset(&stats, 0, sizeof(stats));
414
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000415 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000416 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100417 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000418 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100419 batch_pool_link)
420 per_file_stats(0, obj, &stats);
421 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100422 }
Brad Volkin493018d2014-12-11 12:13:08 -0800423
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100424 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800425}
426
Ben Widawskyca191b12013-07-31 17:00:14 -0700427#define count_vmas(list, member) do { \
428 list_for_each_entry(vma, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100429 size += i915_gem_obj_total_ggtt_size(vma->obj); \
Ben Widawskyca191b12013-07-31 17:00:14 -0700430 ++count; \
431 if (vma->obj->map_and_fenceable) { \
432 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
433 ++mappable_count; \
434 } \
435 } \
436} while (0)
437
438static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100439{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100440 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100441 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300442 struct drm_i915_private *dev_priv = to_i915(dev);
443 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200444 u32 count, mappable_count, purgeable_count;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300445 u64 size, mappable_size, purgeable_size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100446 unsigned long pin_mapped_count = 0, pin_mapped_purgeable_count = 0;
447 u64 pin_mapped_size = 0, pin_mapped_purgeable_size = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000448 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100449 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700450 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100451 int ret;
452
453 ret = mutex_lock_interruptible(&dev->struct_mutex);
454 if (ret)
455 return ret;
456
Chris Wilson6299f992010-11-24 12:23:44 +0000457 seq_printf(m, "%u objects, %zu bytes\n",
458 dev_priv->mm.object_count,
459 dev_priv->mm.object_memory);
460
461 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700462 count_objects(&dev_priv->mm.bound_list, global_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300463 seq_printf(m, "%u [%u] objects, %llu [%llu] bytes in gtt\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000464 count, mappable_count, size, mappable_size);
465
466 size = count = mappable_size = mappable_count = 0;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300467 count_vmas(&ggtt->base.active_list, vm_link);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300468 seq_printf(m, " %u [%u] active objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000469 count, mappable_count, size, mappable_size);
470
471 size = count = mappable_size = mappable_count = 0;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300472 count_vmas(&ggtt->base.inactive_list, vm_link);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300473 seq_printf(m, " %u [%u] inactive objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000474 count, mappable_count, size, mappable_size);
475
Chris Wilsonb7abb712012-08-20 11:33:30 +0200476 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700477 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200478 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200479 if (obj->madv == I915_MADV_DONTNEED)
480 purgeable_size += obj->base.size, ++purgeable_count;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100481 if (obj->mapping) {
482 pin_mapped_count++;
483 pin_mapped_size += obj->base.size;
484 if (obj->pages_pin_count == 0) {
485 pin_mapped_purgeable_count++;
486 pin_mapped_purgeable_size += obj->base.size;
487 }
488 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200489 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300490 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
Chris Wilson6c085a72012-08-20 11:40:46 +0200491
Chris Wilson6299f992010-11-24 12:23:44 +0000492 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700493 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000494 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700495 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000496 ++count;
497 }
Chris Wilson30154652015-04-07 17:28:24 +0100498 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700499 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000500 ++mappable_count;
501 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200502 if (obj->madv == I915_MADV_DONTNEED) {
503 purgeable_size += obj->base.size;
504 ++purgeable_count;
505 }
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100506 if (obj->mapping) {
507 pin_mapped_count++;
508 pin_mapped_size += obj->base.size;
509 if (obj->pages_pin_count == 0) {
510 pin_mapped_purgeable_count++;
511 pin_mapped_purgeable_size += obj->base.size;
512 }
513 }
Chris Wilson6299f992010-11-24 12:23:44 +0000514 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300515 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200516 purgeable_count, purgeable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300517 seq_printf(m, "%u pinned mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000518 mappable_count, mappable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300519 seq_printf(m, "%u fault mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000520 count, size);
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100521 seq_printf(m,
522 "%lu [%lu] pin mapped objects, %llu [%llu] bytes [purgeable]\n",
523 pin_mapped_count, pin_mapped_purgeable_count,
524 pin_mapped_size, pin_mapped_purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000525
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300526 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300527 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100528
Damien Lespiau267f0c92013-06-24 22:59:48 +0100529 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800530 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200531
532 mutex_unlock(&dev->struct_mutex);
533
534 mutex_lock(&dev->filelist_mutex);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100535 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
536 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900537 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100538
539 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000540 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100541 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100542 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100543 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900544 /*
545 * Although we have a valid reference on file->pid, that does
546 * not guarantee that the task_struct who called get_pid() is
547 * still alive (e.g. get_pid(current) => fork() => exit()).
548 * Therefore, we need to protect this ->comm access using RCU.
549 */
550 rcu_read_lock();
551 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800552 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900553 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100554 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200555 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100556
557 return 0;
558}
559
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100560static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000561{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100562 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000563 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100564 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000565 struct drm_i915_private *dev_priv = dev->dev_private;
566 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300567 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000568 int count, ret;
569
570 ret = mutex_lock_interruptible(&dev->struct_mutex);
571 if (ret)
572 return ret;
573
574 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700575 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800576 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100577 continue;
578
Damien Lespiau267f0c92013-06-24 22:59:48 +0100579 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000580 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100581 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000582 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100583 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000584 count++;
585 }
586
587 mutex_unlock(&dev->struct_mutex);
588
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300589 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000590 count, total_obj_size, total_gtt_size);
591
592 return 0;
593}
594
Maarten Lankhorst68858432016-05-17 15:07:52 +0200595static void i915_dump_pageflip(struct seq_file *m,
596 struct drm_i915_private *dev_priv,
597 struct intel_crtc *crtc,
598 struct intel_flip_work *work)
599{
600 const char pipe = pipe_name(crtc->pipe);
601 const char plane = plane_name(crtc->plane);
602 u32 pending;
603 u32 addr;
604
605 pending = atomic_read(&work->pending);
606 if (pending) {
607 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
608 pipe, plane);
609 } else {
610 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
611 pipe, plane);
612 }
613 if (work->flip_queued_req) {
614 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
615
616 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
617 engine->name,
618 i915_gem_request_get_seqno(work->flip_queued_req),
619 dev_priv->next_seqno,
620 engine->get_seqno(engine),
621 i915_gem_request_completed(work->flip_queued_req, true));
622 } else
623 seq_printf(m, "Flip not associated with any ring\n");
624 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
625 work->flip_queued_vblank,
626 work->flip_ready_vblank,
627 intel_crtc_get_vblank_counter(crtc));
628 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
629
630 if (INTEL_INFO(dev_priv)->gen >= 4)
631 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
632 else
633 addr = I915_READ(DSPADDR(crtc->plane));
634 seq_printf(m, "Current scanout address 0x%08x\n", addr);
635
636 if (work->pending_flip_obj) {
637 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
638 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
639 }
640}
641
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100642static int i915_gem_pageflip_info(struct seq_file *m, void *data)
643{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100644 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100645 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100646 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100647 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200648 int ret;
649
650 ret = mutex_lock_interruptible(&dev->struct_mutex);
651 if (ret)
652 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100653
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100654 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800655 const char pipe = pipe_name(crtc->pipe);
656 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200657 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100658
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200659 spin_lock_irq(&dev->event_lock);
Maarten Lankhorst68858432016-05-17 15:07:52 +0200660 if (list_empty(&crtc->flip_work)) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800661 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100662 pipe, plane);
663 } else {
Maarten Lankhorst68858432016-05-17 15:07:52 +0200664 list_for_each_entry(work, &crtc->flip_work, head) {
665 i915_dump_pageflip(m, dev_priv, crtc, work);
666 seq_puts(m, "\n");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100667 }
668 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200669 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100670 }
671
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200672 mutex_unlock(&dev->struct_mutex);
673
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100674 return 0;
675}
676
Brad Volkin493018d2014-12-11 12:13:08 -0800677static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
678{
679 struct drm_info_node *node = m->private;
680 struct drm_device *dev = node->minor->dev;
681 struct drm_i915_private *dev_priv = dev->dev_private;
682 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000683 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100684 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000685 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800686
687 ret = mutex_lock_interruptible(&dev->struct_mutex);
688 if (ret)
689 return ret;
690
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000691 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000692 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100693 int count;
694
695 count = 0;
696 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000697 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100698 batch_pool_link)
699 count++;
700 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000701 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100702
703 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000704 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100705 batch_pool_link) {
706 seq_puts(m, " ");
707 describe_obj(m, obj);
708 seq_putc(m, '\n');
709 }
710
711 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100712 }
Brad Volkin493018d2014-12-11 12:13:08 -0800713 }
714
Chris Wilson8d9d5742015-04-07 16:20:38 +0100715 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800716
717 mutex_unlock(&dev->struct_mutex);
718
719 return 0;
720}
721
Ben Gamari20172632009-02-17 20:08:50 -0500722static int i915_gem_request_info(struct seq_file *m, void *data)
723{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100724 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500725 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300726 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000727 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200728 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000729 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100730
731 ret = mutex_lock_interruptible(&dev->struct_mutex);
732 if (ret)
733 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500734
Chris Wilson2d1070b2015-04-01 10:36:56 +0100735 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000736 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100737 int count;
738
739 count = 0;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000740 list_for_each_entry(req, &engine->request_list, list)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100741 count++;
742 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100743 continue;
744
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000745 seq_printf(m, "%s requests: %d\n", engine->name, count);
746 list_for_each_entry(req, &engine->request_list, list) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100747 struct task_struct *task;
748
749 rcu_read_lock();
750 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200751 if (req->pid)
752 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100753 seq_printf(m, " %x @ %d: %s [%d]\n",
Daniel Vettereed29a52015-05-21 14:21:25 +0200754 req->seqno,
755 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100756 task ? task->comm : "<unknown>",
757 task ? task->pid : -1);
758 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100759 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100760
761 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500762 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100763 mutex_unlock(&dev->struct_mutex);
764
Chris Wilson2d1070b2015-04-01 10:36:56 +0100765 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100766 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100767
Ben Gamari20172632009-02-17 20:08:50 -0500768 return 0;
769}
770
Chris Wilsonb2223492010-10-27 15:27:33 +0100771static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000772 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100773{
Chris Wilson12471ba2016-04-09 10:57:55 +0100774 seq_printf(m, "Current sequence (%s): %x\n",
775 engine->name, engine->get_seqno(engine));
776 seq_printf(m, "Current user interrupts (%s): %x\n",
777 engine->name, READ_ONCE(engine->user_interrupts));
Chris Wilsonb2223492010-10-27 15:27:33 +0100778}
779
Ben Gamari20172632009-02-17 20:08:50 -0500780static int i915_gem_seqno_info(struct seq_file *m, void *data)
781{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100782 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500783 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300784 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000785 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000786 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100787
788 ret = mutex_lock_interruptible(&dev->struct_mutex);
789 if (ret)
790 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200791 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500792
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000793 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000794 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100795
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200796 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100797 mutex_unlock(&dev->struct_mutex);
798
Ben Gamari20172632009-02-17 20:08:50 -0500799 return 0;
800}
801
802
803static int i915_interrupt_info(struct seq_file *m, void *data)
804{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100805 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500806 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300807 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000808 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800809 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100810
811 ret = mutex_lock_interruptible(&dev->struct_mutex);
812 if (ret)
813 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200814 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500815
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300816 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300817 seq_printf(m, "Master Interrupt Control:\t%08x\n",
818 I915_READ(GEN8_MASTER_IRQ));
819
820 seq_printf(m, "Display IER:\t%08x\n",
821 I915_READ(VLV_IER));
822 seq_printf(m, "Display IIR:\t%08x\n",
823 I915_READ(VLV_IIR));
824 seq_printf(m, "Display IIR_RW:\t%08x\n",
825 I915_READ(VLV_IIR_RW));
826 seq_printf(m, "Display IMR:\t%08x\n",
827 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100828 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300829 seq_printf(m, "Pipe %c stat:\t%08x\n",
830 pipe_name(pipe),
831 I915_READ(PIPESTAT(pipe)));
832
833 seq_printf(m, "Port hotplug:\t%08x\n",
834 I915_READ(PORT_HOTPLUG_EN));
835 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
836 I915_READ(VLV_DPFLIPSTAT));
837 seq_printf(m, "DPINVGTT:\t%08x\n",
838 I915_READ(DPINVGTT));
839
840 for (i = 0; i < 4; i++) {
841 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
842 i, I915_READ(GEN8_GT_IMR(i)));
843 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
844 i, I915_READ(GEN8_GT_IIR(i)));
845 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
846 i, I915_READ(GEN8_GT_IER(i)));
847 }
848
849 seq_printf(m, "PCU interrupt mask:\t%08x\n",
850 I915_READ(GEN8_PCU_IMR));
851 seq_printf(m, "PCU interrupt identity:\t%08x\n",
852 I915_READ(GEN8_PCU_IIR));
853 seq_printf(m, "PCU interrupt enable:\t%08x\n",
854 I915_READ(GEN8_PCU_IER));
855 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700856 seq_printf(m, "Master Interrupt Control:\t%08x\n",
857 I915_READ(GEN8_MASTER_IRQ));
858
859 for (i = 0; i < 4; i++) {
860 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
861 i, I915_READ(GEN8_GT_IMR(i)));
862 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
863 i, I915_READ(GEN8_GT_IIR(i)));
864 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
865 i, I915_READ(GEN8_GT_IER(i)));
866 }
867
Damien Lespiau055e3932014-08-18 13:49:10 +0100868 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200869 enum intel_display_power_domain power_domain;
870
871 power_domain = POWER_DOMAIN_PIPE(pipe);
872 if (!intel_display_power_get_if_enabled(dev_priv,
873 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300874 seq_printf(m, "Pipe %c power disabled\n",
875 pipe_name(pipe));
876 continue;
877 }
Ben Widawskya123f152013-11-02 21:07:10 -0700878 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000879 pipe_name(pipe),
880 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700881 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000882 pipe_name(pipe),
883 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700884 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000885 pipe_name(pipe),
886 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200887
888 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700889 }
890
891 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
892 I915_READ(GEN8_DE_PORT_IMR));
893 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
894 I915_READ(GEN8_DE_PORT_IIR));
895 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
896 I915_READ(GEN8_DE_PORT_IER));
897
898 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
899 I915_READ(GEN8_DE_MISC_IMR));
900 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
901 I915_READ(GEN8_DE_MISC_IIR));
902 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
903 I915_READ(GEN8_DE_MISC_IER));
904
905 seq_printf(m, "PCU interrupt mask:\t%08x\n",
906 I915_READ(GEN8_PCU_IMR));
907 seq_printf(m, "PCU interrupt identity:\t%08x\n",
908 I915_READ(GEN8_PCU_IIR));
909 seq_printf(m, "PCU interrupt enable:\t%08x\n",
910 I915_READ(GEN8_PCU_IER));
911 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700912 seq_printf(m, "Display IER:\t%08x\n",
913 I915_READ(VLV_IER));
914 seq_printf(m, "Display IIR:\t%08x\n",
915 I915_READ(VLV_IIR));
916 seq_printf(m, "Display IIR_RW:\t%08x\n",
917 I915_READ(VLV_IIR_RW));
918 seq_printf(m, "Display IMR:\t%08x\n",
919 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100920 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700921 seq_printf(m, "Pipe %c stat:\t%08x\n",
922 pipe_name(pipe),
923 I915_READ(PIPESTAT(pipe)));
924
925 seq_printf(m, "Master IER:\t%08x\n",
926 I915_READ(VLV_MASTER_IER));
927
928 seq_printf(m, "Render IER:\t%08x\n",
929 I915_READ(GTIER));
930 seq_printf(m, "Render IIR:\t%08x\n",
931 I915_READ(GTIIR));
932 seq_printf(m, "Render IMR:\t%08x\n",
933 I915_READ(GTIMR));
934
935 seq_printf(m, "PM IER:\t\t%08x\n",
936 I915_READ(GEN6_PMIER));
937 seq_printf(m, "PM IIR:\t\t%08x\n",
938 I915_READ(GEN6_PMIIR));
939 seq_printf(m, "PM IMR:\t\t%08x\n",
940 I915_READ(GEN6_PMIMR));
941
942 seq_printf(m, "Port hotplug:\t%08x\n",
943 I915_READ(PORT_HOTPLUG_EN));
944 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
945 I915_READ(VLV_DPFLIPSTAT));
946 seq_printf(m, "DPINVGTT:\t%08x\n",
947 I915_READ(DPINVGTT));
948
949 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800950 seq_printf(m, "Interrupt enable: %08x\n",
951 I915_READ(IER));
952 seq_printf(m, "Interrupt identity: %08x\n",
953 I915_READ(IIR));
954 seq_printf(m, "Interrupt mask: %08x\n",
955 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100956 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800957 seq_printf(m, "Pipe %c stat: %08x\n",
958 pipe_name(pipe),
959 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800960 } else {
961 seq_printf(m, "North Display Interrupt enable: %08x\n",
962 I915_READ(DEIER));
963 seq_printf(m, "North Display Interrupt identity: %08x\n",
964 I915_READ(DEIIR));
965 seq_printf(m, "North Display Interrupt mask: %08x\n",
966 I915_READ(DEIMR));
967 seq_printf(m, "South Display Interrupt enable: %08x\n",
968 I915_READ(SDEIER));
969 seq_printf(m, "South Display Interrupt identity: %08x\n",
970 I915_READ(SDEIIR));
971 seq_printf(m, "South Display Interrupt mask: %08x\n",
972 I915_READ(SDEIMR));
973 seq_printf(m, "Graphics Interrupt enable: %08x\n",
974 I915_READ(GTIER));
975 seq_printf(m, "Graphics Interrupt identity: %08x\n",
976 I915_READ(GTIIR));
977 seq_printf(m, "Graphics Interrupt mask: %08x\n",
978 I915_READ(GTIMR));
979 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000980 for_each_engine(engine, dev_priv) {
Ben Widawskya123f152013-11-02 21:07:10 -0700981 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100982 seq_printf(m,
983 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000984 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000985 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000986 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000987 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200988 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100989 mutex_unlock(&dev->struct_mutex);
990
Ben Gamari20172632009-02-17 20:08:50 -0500991 return 0;
992}
993
Chris Wilsona6172a82009-02-11 14:26:38 +0000994static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
995{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100996 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000997 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300998 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100999 int i, ret;
1000
1001 ret = mutex_lock_interruptible(&dev->struct_mutex);
1002 if (ret)
1003 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +00001004
Chris Wilsona6172a82009-02-11 14:26:38 +00001005 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
1006 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +00001007 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +00001008
Chris Wilson6c085a72012-08-20 11:40:46 +02001009 seq_printf(m, "Fence %d, pin count = %d, object = ",
1010 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001011 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001012 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001013 else
Chris Wilson05394f32010-11-08 19:18:58 +00001014 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001015 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +00001016 }
1017
Chris Wilson05394f32010-11-08 19:18:58 +00001018 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +00001019 return 0;
1020}
1021
Ben Gamari20172632009-02-17 20:08:50 -05001022static int i915_hws_info(struct seq_file *m, void *data)
1023{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001024 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -05001025 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001026 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001027 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +01001028 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +01001029 int i;
Ben Gamari20172632009-02-17 20:08:50 -05001030
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001031 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001032 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -05001033 if (hws == NULL)
1034 return 0;
1035
1036 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
1037 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
1038 i * 4,
1039 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
1040 }
1041 return 0;
1042}
1043
Daniel Vetterd5442302012-04-27 15:17:40 +02001044static ssize_t
1045i915_error_state_write(struct file *filp,
1046 const char __user *ubuf,
1047 size_t cnt,
1048 loff_t *ppos)
1049{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001050 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001051 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001052 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001053
1054 DRM_DEBUG_DRIVER("Resetting error state\n");
1055
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001056 ret = mutex_lock_interruptible(&dev->struct_mutex);
1057 if (ret)
1058 return ret;
1059
Daniel Vetterd5442302012-04-27 15:17:40 +02001060 i915_destroy_error_state(dev);
1061 mutex_unlock(&dev->struct_mutex);
1062
1063 return cnt;
1064}
1065
1066static int i915_error_state_open(struct inode *inode, struct file *file)
1067{
1068 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001069 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001070
1071 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1072 if (!error_priv)
1073 return -ENOMEM;
1074
1075 error_priv->dev = dev;
1076
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001077 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001078
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001079 file->private_data = error_priv;
1080
1081 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001082}
1083
1084static int i915_error_state_release(struct inode *inode, struct file *file)
1085{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001086 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001087
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001088 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001089 kfree(error_priv);
1090
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001091 return 0;
1092}
1093
1094static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1095 size_t count, loff_t *pos)
1096{
1097 struct i915_error_state_file_priv *error_priv = file->private_data;
1098 struct drm_i915_error_state_buf error_str;
1099 loff_t tmp_pos = 0;
1100 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001101 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001102
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001103 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001104 if (ret)
1105 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001106
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001107 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001108 if (ret)
1109 goto out;
1110
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001111 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1112 error_str.buf,
1113 error_str.bytes);
1114
1115 if (ret_count < 0)
1116 ret = ret_count;
1117 else
1118 *pos = error_str.start + ret_count;
1119out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001120 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001121 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001122}
1123
1124static const struct file_operations i915_error_state_fops = {
1125 .owner = THIS_MODULE,
1126 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001127 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001128 .write = i915_error_state_write,
1129 .llseek = default_llseek,
1130 .release = i915_error_state_release,
1131};
1132
Kees Cook647416f2013-03-10 14:10:06 -07001133static int
1134i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001135{
Kees Cook647416f2013-03-10 14:10:06 -07001136 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001137 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001138 int ret;
1139
1140 ret = mutex_lock_interruptible(&dev->struct_mutex);
1141 if (ret)
1142 return ret;
1143
Kees Cook647416f2013-03-10 14:10:06 -07001144 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001145 mutex_unlock(&dev->struct_mutex);
1146
Kees Cook647416f2013-03-10 14:10:06 -07001147 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001148}
1149
Kees Cook647416f2013-03-10 14:10:06 -07001150static int
1151i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001152{
Kees Cook647416f2013-03-10 14:10:06 -07001153 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001154 int ret;
1155
Mika Kuoppala40633212012-12-04 15:12:00 +02001156 ret = mutex_lock_interruptible(&dev->struct_mutex);
1157 if (ret)
1158 return ret;
1159
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001160 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001161 mutex_unlock(&dev->struct_mutex);
1162
Kees Cook647416f2013-03-10 14:10:06 -07001163 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001164}
1165
Kees Cook647416f2013-03-10 14:10:06 -07001166DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1167 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001168 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001169
Deepak Sadb4bd12014-03-31 11:30:02 +05301170static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001171{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001172 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001173 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001174 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001175 int ret = 0;
1176
1177 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001178
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001179 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1180
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001181 if (IS_GEN5(dev)) {
1182 u16 rgvswctl = I915_READ16(MEMSWCTL);
1183 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1184
1185 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1186 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1187 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1188 MEMSTAT_VID_SHIFT);
1189 seq_printf(m, "Current P-state: %d\n",
1190 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Wayne Boyer666a4532015-12-09 12:29:35 -08001191 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
1192 u32 freq_sts;
1193
1194 mutex_lock(&dev_priv->rps.hw_lock);
1195 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1196 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1197 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1198
1199 seq_printf(m, "actual GPU freq: %d MHz\n",
1200 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1201
1202 seq_printf(m, "current GPU freq: %d MHz\n",
1203 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1204
1205 seq_printf(m, "max GPU freq: %d MHz\n",
1206 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1207
1208 seq_printf(m, "min GPU freq: %d MHz\n",
1209 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1210
1211 seq_printf(m, "idle GPU freq: %d MHz\n",
1212 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1213
1214 seq_printf(m,
1215 "efficient (RPe) frequency: %d MHz\n",
1216 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1217 mutex_unlock(&dev_priv->rps.hw_lock);
1218 } else if (INTEL_INFO(dev)->gen >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001219 u32 rp_state_limits;
1220 u32 gt_perf_status;
1221 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001222 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001223 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001224 u32 rpupei, rpcurup, rpprevup;
1225 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001226 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001227 int max_freq;
1228
Bob Paauwe35040562015-06-25 14:54:07 -07001229 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1230 if (IS_BROXTON(dev)) {
1231 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1232 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1233 } else {
1234 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1235 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1236 }
1237
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001238 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001239 ret = mutex_lock_interruptible(&dev->struct_mutex);
1240 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001241 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001242
Mika Kuoppala59bad942015-01-16 11:34:40 +02001243 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001244
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001245 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301246 if (IS_GEN9(dev))
1247 reqf >>= 23;
1248 else {
1249 reqf &= ~GEN6_TURBO_DISABLE;
1250 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1251 reqf >>= 24;
1252 else
1253 reqf >>= 25;
1254 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001255 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001256
Chris Wilson0d8f9492014-03-27 09:06:14 +00001257 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1258 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1259 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1260
Jesse Barnesccab5c82011-01-18 15:49:25 -08001261 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301262 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1263 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1264 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1265 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1266 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1267 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Akash Goel60260a52015-03-06 11:07:21 +05301268 if (IS_GEN9(dev))
1269 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1270 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001271 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1272 else
1273 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001274 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001275
Mika Kuoppala59bad942015-01-16 11:34:40 +02001276 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001277 mutex_unlock(&dev->struct_mutex);
1278
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001279 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1280 pm_ier = I915_READ(GEN6_PMIER);
1281 pm_imr = I915_READ(GEN6_PMIMR);
1282 pm_isr = I915_READ(GEN6_PMISR);
1283 pm_iir = I915_READ(GEN6_PMIIR);
1284 pm_mask = I915_READ(GEN6_PMINTRMSK);
1285 } else {
1286 pm_ier = I915_READ(GEN8_GT_IER(2));
1287 pm_imr = I915_READ(GEN8_GT_IMR(2));
1288 pm_isr = I915_READ(GEN8_GT_ISR(2));
1289 pm_iir = I915_READ(GEN8_GT_IIR(2));
1290 pm_mask = I915_READ(GEN6_PMINTRMSK);
1291 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001292 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 -03001293 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001294 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001295 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301296 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001297 seq_printf(m, "Render p-state VID: %d\n",
1298 gt_perf_status & 0xff);
1299 seq_printf(m, "Render p-state limit: %d\n",
1300 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001301 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1302 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1303 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1304 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001305 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001306 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301307 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1308 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1309 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1310 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1311 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1312 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001313 seq_printf(m, "Up threshold: %d%%\n",
1314 dev_priv->rps.up_threshold);
1315
Akash Goeld6cda9c2016-04-23 00:05:46 +05301316 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1317 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1318 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1319 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1320 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1321 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001322 seq_printf(m, "Down threshold: %d%%\n",
1323 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001324
Bob Paauwe35040562015-06-25 14:54:07 -07001325 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1326 rp_state_cap >> 16) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001327 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1328 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001329 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001330 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001331
1332 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001333 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1334 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001335 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001336 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001337
Bob Paauwe35040562015-06-25 14:54:07 -07001338 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1339 rp_state_cap >> 0) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001340 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1341 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001342 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001343 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001344 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001345 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001346
Chris Wilsond86ed342015-04-27 13:41:19 +01001347 seq_printf(m, "Current freq: %d MHz\n",
1348 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1349 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001350 seq_printf(m, "Idle freq: %d MHz\n",
1351 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001352 seq_printf(m, "Min freq: %d MHz\n",
1353 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1354 seq_printf(m, "Max freq: %d MHz\n",
1355 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1356 seq_printf(m,
1357 "efficient (RPe) frequency: %d MHz\n",
1358 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001359 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001360 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001361 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001362
Mika Kahola1170f282015-09-25 14:00:32 +03001363 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1364 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1365 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1366
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001367out:
1368 intel_runtime_pm_put(dev_priv);
1369 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001370}
1371
Chris Wilsonf6544492015-01-26 18:03:04 +02001372static int i915_hangcheck_info(struct seq_file *m, void *unused)
1373{
1374 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001375 struct drm_device *dev = node->minor->dev;
1376 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001377 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001378 u64 acthd[I915_NUM_ENGINES];
1379 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001380 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001381 enum intel_engine_id id;
1382 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001383
1384 if (!i915.enable_hangcheck) {
1385 seq_printf(m, "Hangcheck disabled\n");
1386 return 0;
1387 }
1388
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001389 intel_runtime_pm_get(dev_priv);
1390
Dave Gordonc3232b12016-03-23 18:19:53 +00001391 for_each_engine_id(engine, dev_priv, id) {
Dave Gordonc3232b12016-03-23 18:19:53 +00001392 acthd[id] = intel_ring_get_active_head(engine);
Chris Wilsonc04e0f32016-04-09 10:57:54 +01001393 seqno[id] = engine->get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001394 }
1395
Chris Wilsonc0336662016-05-06 15:40:21 +01001396 i915_get_extra_instdone(dev_priv, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001397
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001398 intel_runtime_pm_put(dev_priv);
1399
Chris Wilsonf6544492015-01-26 18:03:04 +02001400 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1401 seq_printf(m, "Hangcheck active, fires in %dms\n",
1402 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1403 jiffies));
1404 } else
1405 seq_printf(m, "Hangcheck inactive\n");
1406
Dave Gordonc3232b12016-03-23 18:19:53 +00001407 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001408 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001409 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1410 engine->hangcheck.seqno,
1411 seqno[id],
1412 engine->last_submitted_seqno);
Chris Wilson12471ba2016-04-09 10:57:55 +01001413 seq_printf(m, "\tuser interrupts = %x [current %x]\n",
1414 engine->hangcheck.user_interrupts,
1415 READ_ONCE(engine->user_interrupts));
Chris Wilsonf6544492015-01-26 18:03:04 +02001416 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001417 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001418 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001419 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1420 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001421
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001422 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001423 seq_puts(m, "\tinstdone read =");
1424
1425 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1426 seq_printf(m, " 0x%08x", instdone[j]);
1427
1428 seq_puts(m, "\n\tinstdone accu =");
1429
1430 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1431 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001432 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001433
1434 seq_puts(m, "\n");
1435 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001436 }
1437
1438 return 0;
1439}
1440
Ben Widawsky4d855292011-12-12 19:34:16 -08001441static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001442{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001443 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001444 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001445 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001446 u32 rgvmodectl, rstdbyctl;
1447 u16 crstandvid;
1448 int ret;
1449
1450 ret = mutex_lock_interruptible(&dev->struct_mutex);
1451 if (ret)
1452 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001453 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001454
1455 rgvmodectl = I915_READ(MEMMODECTL);
1456 rstdbyctl = I915_READ(RSTDBYCTL);
1457 crstandvid = I915_READ16(CRSTANDVID);
1458
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001459 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001460 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001461
Jani Nikula742f4912015-09-03 11:16:09 +03001462 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001463 seq_printf(m, "Boost freq: %d\n",
1464 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1465 MEMMODE_BOOST_FREQ_SHIFT);
1466 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001467 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001468 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001469 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001470 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001471 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001472 seq_printf(m, "Starting frequency: P%d\n",
1473 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001474 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001475 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001476 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1477 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1478 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1479 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001480 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001481 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001482 switch (rstdbyctl & RSX_STATUS_MASK) {
1483 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001484 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001485 break;
1486 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001487 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001488 break;
1489 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001490 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001491 break;
1492 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001493 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001494 break;
1495 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001496 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001497 break;
1498 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001499 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001500 break;
1501 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001502 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001503 break;
1504 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001505
1506 return 0;
1507}
1508
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001509static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001510{
1511 struct drm_info_node *node = m->private;
1512 struct drm_device *dev = node->minor->dev;
1513 struct drm_i915_private *dev_priv = dev->dev_private;
1514 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001515
1516 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001517 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001518 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001519 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001520 fw_domain->wake_count);
1521 }
1522 spin_unlock_irq(&dev_priv->uncore.lock);
1523
1524 return 0;
1525}
1526
Deepak S669ab5a2014-01-10 15:18:26 +05301527static int vlv_drpc_info(struct seq_file *m)
1528{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001529 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301530 struct drm_device *dev = node->minor->dev;
1531 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001532 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301533
Imre Deakd46c0512014-04-14 20:24:27 +03001534 intel_runtime_pm_get(dev_priv);
1535
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001536 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301537 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1538 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1539
Imre Deakd46c0512014-04-14 20:24:27 +03001540 intel_runtime_pm_put(dev_priv);
1541
Deepak S669ab5a2014-01-10 15:18:26 +05301542 seq_printf(m, "Video Turbo Mode: %s\n",
1543 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1544 seq_printf(m, "Turbo enabled: %s\n",
1545 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1546 seq_printf(m, "HW control enabled: %s\n",
1547 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1548 seq_printf(m, "SW control enabled: %s\n",
1549 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1550 GEN6_RP_MEDIA_SW_MODE));
1551 seq_printf(m, "RC6 Enabled: %s\n",
1552 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1553 GEN6_RC_CTL_EI_MODE(1))));
1554 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001555 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301556 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001557 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301558
Imre Deak9cc19be2014-04-14 20:24:24 +03001559 seq_printf(m, "Render RC6 residency since boot: %u\n",
1560 I915_READ(VLV_GT_RENDER_RC6));
1561 seq_printf(m, "Media RC6 residency since boot: %u\n",
1562 I915_READ(VLV_GT_MEDIA_RC6));
1563
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001564 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301565}
1566
Ben Widawsky4d855292011-12-12 19:34:16 -08001567static int gen6_drpc_info(struct seq_file *m)
1568{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001569 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001570 struct drm_device *dev = node->minor->dev;
1571 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001572 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001573 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001574 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001575
1576 ret = mutex_lock_interruptible(&dev->struct_mutex);
1577 if (ret)
1578 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001579 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001580
Chris Wilson907b28c2013-07-19 20:36:52 +01001581 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001582 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001583 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001584
1585 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001586 seq_puts(m, "RC information inaccurate because somebody "
1587 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001588 } else {
1589 /* NB: we cannot use forcewake, else we read the wrong values */
1590 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1591 udelay(10);
1592 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1593 }
1594
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001595 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001596 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001597
1598 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1599 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1600 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001601 mutex_lock(&dev_priv->rps.hw_lock);
1602 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1603 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001604
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001605 intel_runtime_pm_put(dev_priv);
1606
Ben Widawsky4d855292011-12-12 19:34:16 -08001607 seq_printf(m, "Video Turbo Mode: %s\n",
1608 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1609 seq_printf(m, "HW control enabled: %s\n",
1610 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1611 seq_printf(m, "SW control enabled: %s\n",
1612 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1613 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001614 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001615 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1616 seq_printf(m, "RC6 Enabled: %s\n",
1617 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1618 seq_printf(m, "Deep RC6 Enabled: %s\n",
1619 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1620 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1621 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001622 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001623 switch (gt_core_status & GEN6_RCn_MASK) {
1624 case GEN6_RC0:
1625 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001626 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001627 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001628 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001629 break;
1630 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001631 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001632 break;
1633 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001634 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001635 break;
1636 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001637 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001638 break;
1639 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001640 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001641 break;
1642 }
1643
1644 seq_printf(m, "Core Power Down: %s\n",
1645 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001646
1647 /* Not exactly sure what this is */
1648 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1649 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1650 seq_printf(m, "RC6 residency since boot: %u\n",
1651 I915_READ(GEN6_GT_GFX_RC6));
1652 seq_printf(m, "RC6+ residency since boot: %u\n",
1653 I915_READ(GEN6_GT_GFX_RC6p));
1654 seq_printf(m, "RC6++ residency since boot: %u\n",
1655 I915_READ(GEN6_GT_GFX_RC6pp));
1656
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001657 seq_printf(m, "RC6 voltage: %dmV\n",
1658 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1659 seq_printf(m, "RC6+ voltage: %dmV\n",
1660 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1661 seq_printf(m, "RC6++ voltage: %dmV\n",
1662 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001663 return 0;
1664}
1665
1666static int i915_drpc_info(struct seq_file *m, void *unused)
1667{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001668 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001669 struct drm_device *dev = node->minor->dev;
1670
Wayne Boyer666a4532015-12-09 12:29:35 -08001671 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Deepak S669ab5a2014-01-10 15:18:26 +05301672 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001673 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001674 return gen6_drpc_info(m);
1675 else
1676 return ironlake_drpc_info(m);
1677}
1678
Daniel Vetter9a851782015-06-18 10:30:22 +02001679static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1680{
1681 struct drm_info_node *node = m->private;
1682 struct drm_device *dev = node->minor->dev;
1683 struct drm_i915_private *dev_priv = dev->dev_private;
1684
1685 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1686 dev_priv->fb_tracking.busy_bits);
1687
1688 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1689 dev_priv->fb_tracking.flip_bits);
1690
1691 return 0;
1692}
1693
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001694static int i915_fbc_status(struct seq_file *m, void *unused)
1695{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001696 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001697 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001698 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001699
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001700 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001701 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001702 return 0;
1703 }
1704
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001705 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001706 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001707
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001708 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001709 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001710 else
1711 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001712 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001713
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001714 if (INTEL_INFO(dev_priv)->gen >= 7)
1715 seq_printf(m, "Compressing: %s\n",
1716 yesno(I915_READ(FBC_STATUS2) &
1717 FBC_COMPRESSION_MASK));
1718
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001719 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001720 intel_runtime_pm_put(dev_priv);
1721
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001722 return 0;
1723}
1724
Rodrigo Vivida46f932014-08-01 02:04:45 -07001725static int i915_fbc_fc_get(void *data, u64 *val)
1726{
1727 struct drm_device *dev = data;
1728 struct drm_i915_private *dev_priv = dev->dev_private;
1729
1730 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1731 return -ENODEV;
1732
Rodrigo Vivida46f932014-08-01 02:04:45 -07001733 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001734
1735 return 0;
1736}
1737
1738static int i915_fbc_fc_set(void *data, u64 val)
1739{
1740 struct drm_device *dev = data;
1741 struct drm_i915_private *dev_priv = dev->dev_private;
1742 u32 reg;
1743
1744 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1745 return -ENODEV;
1746
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001747 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001748
1749 reg = I915_READ(ILK_DPFC_CONTROL);
1750 dev_priv->fbc.false_color = val;
1751
1752 I915_WRITE(ILK_DPFC_CONTROL, val ?
1753 (reg | FBC_CTL_FALSE_COLOR) :
1754 (reg & ~FBC_CTL_FALSE_COLOR));
1755
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001756 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001757 return 0;
1758}
1759
1760DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1761 i915_fbc_fc_get, i915_fbc_fc_set,
1762 "%llu\n");
1763
Paulo Zanoni92d44622013-05-31 16:33:24 -03001764static int i915_ips_status(struct seq_file *m, void *unused)
1765{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001766 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001767 struct drm_device *dev = node->minor->dev;
1768 struct drm_i915_private *dev_priv = dev->dev_private;
1769
Damien Lespiauf5adf942013-06-24 18:29:34 +01001770 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001771 seq_puts(m, "not supported\n");
1772 return 0;
1773 }
1774
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001775 intel_runtime_pm_get(dev_priv);
1776
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001777 seq_printf(m, "Enabled by kernel parameter: %s\n",
1778 yesno(i915.enable_ips));
1779
1780 if (INTEL_INFO(dev)->gen >= 8) {
1781 seq_puts(m, "Currently: unknown\n");
1782 } else {
1783 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1784 seq_puts(m, "Currently: enabled\n");
1785 else
1786 seq_puts(m, "Currently: disabled\n");
1787 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001788
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001789 intel_runtime_pm_put(dev_priv);
1790
Paulo Zanoni92d44622013-05-31 16:33:24 -03001791 return 0;
1792}
1793
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001794static int i915_sr_status(struct seq_file *m, void *unused)
1795{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001796 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001797 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001798 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001799 bool sr_enabled = false;
1800
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001801 intel_runtime_pm_get(dev_priv);
1802
Yuanhan Liu13982612010-12-15 15:42:31 +08001803 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001804 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001805 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1806 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001807 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1808 else if (IS_I915GM(dev))
1809 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1810 else if (IS_PINEVIEW(dev))
1811 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Wayne Boyer666a4532015-12-09 12:29:35 -08001812 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001813 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001814
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001815 intel_runtime_pm_put(dev_priv);
1816
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001817 seq_printf(m, "self-refresh: %s\n",
1818 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001819
1820 return 0;
1821}
1822
Jesse Barnes7648fa92010-05-20 14:28:11 -07001823static int i915_emon_status(struct seq_file *m, void *unused)
1824{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001825 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001826 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001827 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001828 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001829 int ret;
1830
Chris Wilson582be6b2012-04-30 19:35:02 +01001831 if (!IS_GEN5(dev))
1832 return -ENODEV;
1833
Chris Wilsonde227ef2010-07-03 07:58:38 +01001834 ret = mutex_lock_interruptible(&dev->struct_mutex);
1835 if (ret)
1836 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001837
1838 temp = i915_mch_val(dev_priv);
1839 chipset = i915_chipset_val(dev_priv);
1840 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001841 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001842
1843 seq_printf(m, "GMCH temp: %ld\n", temp);
1844 seq_printf(m, "Chipset power: %ld\n", chipset);
1845 seq_printf(m, "GFX power: %ld\n", gfx);
1846 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1847
1848 return 0;
1849}
1850
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001851static int i915_ring_freq_table(struct seq_file *m, void *unused)
1852{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001853 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001854 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001855 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001856 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001857 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301858 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001859
Akash Goel97d33082015-06-29 14:50:23 +05301860 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001861 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001862 return 0;
1863 }
1864
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001865 intel_runtime_pm_get(dev_priv);
1866
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001867 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1868
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001869 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001870 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001871 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001872
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001873 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301874 /* Convert GT frequency to 50 HZ units */
1875 min_gpu_freq =
1876 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1877 max_gpu_freq =
1878 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1879 } else {
1880 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1881 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1882 }
1883
Damien Lespiau267f0c92013-06-24 22:59:48 +01001884 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001885
Akash Goelf936ec32015-06-29 14:50:22 +05301886 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001887 ia_freq = gpu_freq;
1888 sandybridge_pcode_read(dev_priv,
1889 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1890 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001891 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301892 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001893 (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1894 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001895 ((ia_freq >> 0) & 0xff) * 100,
1896 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001897 }
1898
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001899 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001900
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001901out:
1902 intel_runtime_pm_put(dev_priv);
1903 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001904}
1905
Chris Wilson44834a62010-08-19 16:09:23 +01001906static int i915_opregion(struct seq_file *m, void *unused)
1907{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001908 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001909 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001910 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001911 struct intel_opregion *opregion = &dev_priv->opregion;
1912 int ret;
1913
1914 ret = mutex_lock_interruptible(&dev->struct_mutex);
1915 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001916 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001917
Jani Nikula2455a8e2015-12-14 12:50:53 +02001918 if (opregion->header)
1919 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001920
1921 mutex_unlock(&dev->struct_mutex);
1922
Daniel Vetter0d38f002012-04-21 22:49:10 +02001923out:
Chris Wilson44834a62010-08-19 16:09:23 +01001924 return 0;
1925}
1926
Jani Nikulaada8f952015-12-15 13:17:12 +02001927static int i915_vbt(struct seq_file *m, void *unused)
1928{
1929 struct drm_info_node *node = m->private;
1930 struct drm_device *dev = node->minor->dev;
1931 struct drm_i915_private *dev_priv = dev->dev_private;
1932 struct intel_opregion *opregion = &dev_priv->opregion;
1933
1934 if (opregion->vbt)
1935 seq_write(m, opregion->vbt, opregion->vbt_size);
1936
1937 return 0;
1938}
1939
Chris Wilson37811fc2010-08-25 22:45:57 +01001940static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1941{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001942 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001943 struct drm_device *dev = node->minor->dev;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301944 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001945 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001946 int ret;
1947
1948 ret = mutex_lock_interruptible(&dev->struct_mutex);
1949 if (ret)
1950 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001951
Daniel Vetter06957262015-08-10 13:34:08 +02001952#ifdef CONFIG_DRM_FBDEV_EMULATION
Namrta Salonieb13b8402015-11-27 13:43:11 +05301953 if (to_i915(dev)->fbdev) {
1954 fbdev_fb = to_intel_framebuffer(to_i915(dev)->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001955
Namrta Salonieb13b8402015-11-27 13:43:11 +05301956 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1957 fbdev_fb->base.width,
1958 fbdev_fb->base.height,
1959 fbdev_fb->base.depth,
1960 fbdev_fb->base.bits_per_pixel,
1961 fbdev_fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001962 drm_framebuffer_read_refcount(&fbdev_fb->base));
Namrta Salonieb13b8402015-11-27 13:43:11 +05301963 describe_obj(m, fbdev_fb->obj);
1964 seq_putc(m, '\n');
1965 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001966#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001967
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001968 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001969 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301970 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1971 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001972 continue;
1973
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001974 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 +01001975 fb->base.width,
1976 fb->base.height,
1977 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001978 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001979 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001980 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001981 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001982 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001983 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001984 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001985 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001986
1987 return 0;
1988}
1989
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001990static void describe_ctx_ringbuf(struct seq_file *m,
1991 struct intel_ringbuffer *ringbuf)
1992{
1993 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1994 ringbuf->space, ringbuf->head, ringbuf->tail,
1995 ringbuf->last_retired_head);
1996}
1997
Ben Widawskye76d3632011-03-19 18:14:29 -07001998static int i915_context_status(struct seq_file *m, void *unused)
1999{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002000 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07002001 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03002002 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002003 struct intel_engine_cs *engine;
Oscar Mateo273497e2014-05-22 14:13:37 +01002004 struct intel_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00002005 enum intel_engine_id id;
2006 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07002007
Daniel Vetterf3d28872014-05-29 23:23:08 +02002008 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002009 if (ret)
2010 return ret;
2011
Ben Widawskya33afea2013-09-17 21:12:45 -07002012 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002013 if (!i915.enable_execlists &&
2014 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01002015 continue;
2016
Chris Wilson5d1808e2016-04-28 09:56:51 +01002017 seq_printf(m, "HW context %u ", ctx->hw_id);
Ben Widawsky3ccfd192013-09-18 19:03:18 -07002018 describe_ctx(m, ctx);
Dave Gordone28e4042016-01-19 19:02:55 +00002019 if (ctx == dev_priv->kernel_context)
2020 seq_printf(m, "(kernel context) ");
Ben Widawskya33afea2013-09-17 21:12:45 -07002021
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002022 if (i915.enable_execlists) {
2023 seq_putc(m, '\n');
Dave Gordonc3232b12016-03-23 18:19:53 +00002024 for_each_engine_id(engine, dev_priv, id) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002025 struct drm_i915_gem_object *ctx_obj =
Dave Gordonc3232b12016-03-23 18:19:53 +00002026 ctx->engine[id].state;
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002027 struct intel_ringbuffer *ringbuf =
Dave Gordonc3232b12016-03-23 18:19:53 +00002028 ctx->engine[id].ringbuf;
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002029
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002030 seq_printf(m, "%s: ", engine->name);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002031 if (ctx_obj)
2032 describe_obj(m, ctx_obj);
2033 if (ringbuf)
2034 describe_ctx_ringbuf(m, ringbuf);
2035 seq_putc(m, '\n');
2036 }
2037 } else {
2038 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
2039 }
2040
Ben Widawskya33afea2013-09-17 21:12:45 -07002041 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002042 }
2043
Daniel Vetterf3d28872014-05-29 23:23:08 +02002044 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002045
2046 return 0;
2047}
2048
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002049static void i915_dump_lrc_obj(struct seq_file *m,
Tvrtko Ursulinca825802016-01-15 15:10:27 +00002050 struct intel_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002051 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002052{
2053 struct page *page;
2054 uint32_t *reg_state;
2055 int j;
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002056 struct drm_i915_gem_object *ctx_obj = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002057 unsigned long ggtt_offset = 0;
2058
Chris Wilson7069b142016-04-28 09:56:52 +01002059 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2060
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002061 if (ctx_obj == NULL) {
Chris Wilson7069b142016-04-28 09:56:52 +01002062 seq_puts(m, "\tNot allocated\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002063 return;
2064 }
2065
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002066 if (!i915_gem_obj_ggtt_bound(ctx_obj))
2067 seq_puts(m, "\tNot bound in GGTT\n");
2068 else
2069 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
2070
2071 if (i915_gem_object_get_pages(ctx_obj)) {
2072 seq_puts(m, "\tFailed to get pages for context object\n");
2073 return;
2074 }
2075
Alex Daid1675192015-08-12 15:43:43 +01002076 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002077 if (!WARN_ON(page == NULL)) {
2078 reg_state = kmap_atomic(page);
2079
2080 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2081 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2082 ggtt_offset + 4096 + (j * 4),
2083 reg_state[j], reg_state[j + 1],
2084 reg_state[j + 2], reg_state[j + 3]);
2085 }
2086 kunmap_atomic(reg_state);
2087 }
2088
2089 seq_putc(m, '\n');
2090}
2091
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002092static int i915_dump_lrc(struct seq_file *m, void *unused)
2093{
2094 struct drm_info_node *node = (struct drm_info_node *) m->private;
2095 struct drm_device *dev = node->minor->dev;
2096 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002097 struct intel_engine_cs *engine;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002098 struct intel_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002099 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002100
2101 if (!i915.enable_execlists) {
2102 seq_printf(m, "Logical Ring Contexts are disabled\n");
2103 return 0;
2104 }
2105
2106 ret = mutex_lock_interruptible(&dev->struct_mutex);
2107 if (ret)
2108 return ret;
2109
Dave Gordone28e4042016-01-19 19:02:55 +00002110 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002111 for_each_engine(engine, dev_priv)
2112 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002113
2114 mutex_unlock(&dev->struct_mutex);
2115
2116 return 0;
2117}
2118
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002119static int i915_execlists(struct seq_file *m, void *data)
2120{
2121 struct drm_info_node *node = (struct drm_info_node *)m->private;
2122 struct drm_device *dev = node->minor->dev;
2123 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002124 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002125 u32 status_pointer;
2126 u8 read_pointer;
2127 u8 write_pointer;
2128 u32 status;
2129 u32 ctx_id;
2130 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002131 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002132
2133 if (!i915.enable_execlists) {
2134 seq_puts(m, "Logical Ring Contexts are disabled\n");
2135 return 0;
2136 }
2137
2138 ret = mutex_lock_interruptible(&dev->struct_mutex);
2139 if (ret)
2140 return ret;
2141
Michel Thierryfc0412e2014-10-16 16:13:38 +01002142 intel_runtime_pm_get(dev_priv);
2143
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002144 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002145 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002146 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002147
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002148 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002149
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002150 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2151 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002152 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2153 status, ctx_id);
2154
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002155 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002156 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2157
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002158 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002159 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002160 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002161 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002162 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2163 read_pointer, write_pointer);
2164
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002165 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002166 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2167 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002168
2169 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2170 i, status, ctx_id);
2171 }
2172
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002173 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002174 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002175 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002176 head_req = list_first_entry_or_null(&engine->execlist_queue,
2177 struct drm_i915_gem_request,
2178 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002179 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002180
2181 seq_printf(m, "\t%d requests in queue\n", count);
2182 if (head_req) {
Chris Wilson7069b142016-04-28 09:56:52 +01002183 seq_printf(m, "\tHead request context: %u\n",
2184 head_req->ctx->hw_id);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002185 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002186 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002187 }
2188
2189 seq_putc(m, '\n');
2190 }
2191
Michel Thierryfc0412e2014-10-16 16:13:38 +01002192 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002193 mutex_unlock(&dev->struct_mutex);
2194
2195 return 0;
2196}
2197
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002198static const char *swizzle_string(unsigned swizzle)
2199{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002200 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002201 case I915_BIT_6_SWIZZLE_NONE:
2202 return "none";
2203 case I915_BIT_6_SWIZZLE_9:
2204 return "bit9";
2205 case I915_BIT_6_SWIZZLE_9_10:
2206 return "bit9/bit10";
2207 case I915_BIT_6_SWIZZLE_9_11:
2208 return "bit9/bit11";
2209 case I915_BIT_6_SWIZZLE_9_10_11:
2210 return "bit9/bit10/bit11";
2211 case I915_BIT_6_SWIZZLE_9_17:
2212 return "bit9/bit17";
2213 case I915_BIT_6_SWIZZLE_9_10_17:
2214 return "bit9/bit10/bit17";
2215 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002216 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002217 }
2218
2219 return "bug";
2220}
2221
2222static int i915_swizzle_info(struct seq_file *m, void *data)
2223{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002224 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002225 struct drm_device *dev = node->minor->dev;
2226 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002227 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002228
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002229 ret = mutex_lock_interruptible(&dev->struct_mutex);
2230 if (ret)
2231 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002232 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002233
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002234 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2235 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2236 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2237 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2238
2239 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2240 seq_printf(m, "DDC = 0x%08x\n",
2241 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002242 seq_printf(m, "DDC2 = 0x%08x\n",
2243 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002244 seq_printf(m, "C0DRB3 = 0x%04x\n",
2245 I915_READ16(C0DRB3));
2246 seq_printf(m, "C1DRB3 = 0x%04x\n",
2247 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002248 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002249 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2250 I915_READ(MAD_DIMM_C0));
2251 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2252 I915_READ(MAD_DIMM_C1));
2253 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2254 I915_READ(MAD_DIMM_C2));
2255 seq_printf(m, "TILECTL = 0x%08x\n",
2256 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002257 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002258 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2259 I915_READ(GAMTARBMODE));
2260 else
2261 seq_printf(m, "ARB_MODE = 0x%08x\n",
2262 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002263 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2264 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002265 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002266
2267 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2268 seq_puts(m, "L-shaped memory detected\n");
2269
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002270 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002271 mutex_unlock(&dev->struct_mutex);
2272
2273 return 0;
2274}
2275
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002276static int per_file_ctx(int id, void *ptr, void *data)
2277{
Oscar Mateo273497e2014-05-22 14:13:37 +01002278 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002279 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002280 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2281
2282 if (!ppgtt) {
2283 seq_printf(m, " no ppgtt for context %d\n",
2284 ctx->user_handle);
2285 return 0;
2286 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002287
Oscar Mateof83d6512014-05-22 14:13:38 +01002288 if (i915_gem_context_is_default(ctx))
2289 seq_puts(m, " default context:\n");
2290 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002291 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002292 ppgtt->debug_dump(ppgtt, m);
2293
2294 return 0;
2295}
2296
Ben Widawsky77df6772013-11-02 21:07:30 -07002297static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002298{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002299 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002300 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002301 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002302 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002303
Ben Widawsky77df6772013-11-02 21:07:30 -07002304 if (!ppgtt)
2305 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002306
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002307 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002308 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002309 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002310 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002311 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002312 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002313 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002314 }
2315 }
2316}
2317
2318static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2319{
2320 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002321 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002322
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002323 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002324 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2325
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002326 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002327 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002328 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002329 seq_printf(m, "GFX_MODE: 0x%08x\n",
2330 I915_READ(RING_MODE_GEN7(engine)));
2331 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2332 I915_READ(RING_PP_DIR_BASE(engine)));
2333 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2334 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2335 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2336 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002337 }
2338 if (dev_priv->mm.aliasing_ppgtt) {
2339 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2340
Damien Lespiau267f0c92013-06-24 22:59:48 +01002341 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002342 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002343
Ben Widawsky87d60b62013-12-06 14:11:29 -08002344 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002345 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002346
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002347 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002348}
2349
2350static int i915_ppgtt_info(struct seq_file *m, void *data)
2351{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002352 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002353 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002354 struct drm_i915_private *dev_priv = dev->dev_private;
Michel Thierryea91e402015-07-29 17:23:57 +01002355 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002356
2357 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2358 if (ret)
2359 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002360 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002361
2362 if (INTEL_INFO(dev)->gen >= 8)
2363 gen8_ppgtt_info(m, dev);
2364 else if (INTEL_INFO(dev)->gen >= 6)
2365 gen6_ppgtt_info(m, dev);
2366
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002367 mutex_lock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002368 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2369 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002370 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002371
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002372 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002373 if (!task) {
2374 ret = -ESRCH;
2375 goto out_put;
2376 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002377 seq_printf(m, "\nproc: %s\n", task->comm);
2378 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002379 idr_for_each(&file_priv->context_idr, per_file_ctx,
2380 (void *)(unsigned long)m);
2381 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002382 mutex_unlock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002383
Dan Carpenter06812762015-10-02 18:14:22 +03002384out_put:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002385 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002386 mutex_unlock(&dev->struct_mutex);
2387
Dan Carpenter06812762015-10-02 18:14:22 +03002388 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002389}
2390
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002391static int count_irq_waiters(struct drm_i915_private *i915)
2392{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002393 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002394 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002395
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002396 for_each_engine(engine, i915)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002397 count += engine->irq_refcount;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002398
2399 return count;
2400}
2401
Chris Wilson1854d5c2015-04-07 16:20:32 +01002402static int i915_rps_boost_info(struct seq_file *m, void *data)
2403{
2404 struct drm_info_node *node = m->private;
2405 struct drm_device *dev = node->minor->dev;
2406 struct drm_i915_private *dev_priv = dev->dev_private;
2407 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002408
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002409 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2410 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2411 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2412 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2413 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2414 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2415 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2416 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2417 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002418
2419 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002420 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002421 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2422 struct drm_i915_file_private *file_priv = file->driver_priv;
2423 struct task_struct *task;
2424
2425 rcu_read_lock();
2426 task = pid_task(file->pid, PIDTYPE_PID);
2427 seq_printf(m, "%s [%d]: %d boosts%s\n",
2428 task ? task->comm : "<unknown>",
2429 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002430 file_priv->rps.boosts,
2431 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002432 rcu_read_unlock();
2433 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002434 seq_printf(m, "Semaphore boosts: %d%s\n",
2435 dev_priv->rps.semaphores.boosts,
2436 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2437 seq_printf(m, "MMIO flip boosts: %d%s\n",
2438 dev_priv->rps.mmioflips.boosts,
2439 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002440 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002441 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002442 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002443
Chris Wilson8d3afd72015-05-21 21:01:47 +01002444 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002445}
2446
Ben Widawsky63573eb2013-07-04 11:02:07 -07002447static int i915_llc(struct seq_file *m, void *data)
2448{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002449 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002450 struct drm_device *dev = node->minor->dev;
2451 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002452 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002453
Ben Widawsky63573eb2013-07-04 11:02:07 -07002454 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002455 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2456 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002457
2458 return 0;
2459}
2460
Alex Daifdf5d352015-08-12 15:43:37 +01002461static int i915_guc_load_status_info(struct seq_file *m, void *data)
2462{
2463 struct drm_info_node *node = m->private;
2464 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2465 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2466 u32 tmp, i;
2467
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002468 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002469 return 0;
2470
2471 seq_printf(m, "GuC firmware status:\n");
2472 seq_printf(m, "\tpath: %s\n",
2473 guc_fw->guc_fw_path);
2474 seq_printf(m, "\tfetch: %s\n",
2475 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2476 seq_printf(m, "\tload: %s\n",
2477 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2478 seq_printf(m, "\tversion wanted: %d.%d\n",
2479 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2480 seq_printf(m, "\tversion found: %d.%d\n",
2481 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002482 seq_printf(m, "\theader: offset is %d; size = %d\n",
2483 guc_fw->header_offset, guc_fw->header_size);
2484 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2485 guc_fw->ucode_offset, guc_fw->ucode_size);
2486 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2487 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002488
2489 tmp = I915_READ(GUC_STATUS);
2490
2491 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2492 seq_printf(m, "\tBootrom status = 0x%x\n",
2493 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2494 seq_printf(m, "\tuKernel status = 0x%x\n",
2495 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2496 seq_printf(m, "\tMIA Core status = 0x%x\n",
2497 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2498 seq_puts(m, "\nScratch registers:\n");
2499 for (i = 0; i < 16; i++)
2500 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2501
2502 return 0;
2503}
2504
Dave Gordon8b417c22015-08-12 15:43:44 +01002505static void i915_guc_client_info(struct seq_file *m,
2506 struct drm_i915_private *dev_priv,
2507 struct i915_guc_client *client)
2508{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002509 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002510 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002511
2512 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2513 client->priority, client->ctx_index, client->proc_desc_offset);
2514 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2515 client->doorbell_id, client->doorbell_offset, client->cookie);
2516 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2517 client->wq_size, client->wq_offset, client->wq_tail);
2518
2519 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2520 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2521 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2522
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002523 for_each_engine(engine, dev_priv) {
Dave Gordon8b417c22015-08-12 15:43:44 +01002524 seq_printf(m, "\tSubmissions: %llu %s\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002525 client->submissions[engine->guc_id],
2526 engine->name);
2527 tot += client->submissions[engine->guc_id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002528 }
2529 seq_printf(m, "\tTotal: %llu\n", tot);
2530}
2531
2532static int i915_guc_info(struct seq_file *m, void *data)
2533{
2534 struct drm_info_node *node = m->private;
2535 struct drm_device *dev = node->minor->dev;
2536 struct drm_i915_private *dev_priv = dev->dev_private;
2537 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002538 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002539 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002540 u64 total = 0;
2541
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002542 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002543 return 0;
2544
Alex Dai5a843302015-12-02 16:56:29 -08002545 if (mutex_lock_interruptible(&dev->struct_mutex))
2546 return 0;
2547
Dave Gordon8b417c22015-08-12 15:43:44 +01002548 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002549 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002550 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002551 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002552
2553 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002554
2555 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2556 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2557 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2558 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2559 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2560
2561 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002562 for_each_engine(engine, dev_priv) {
Alex Dai397097b2016-01-23 11:58:14 -08002563 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002564 engine->name, guc.submissions[engine->guc_id],
2565 guc.last_seqno[engine->guc_id]);
2566 total += guc.submissions[engine->guc_id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002567 }
2568 seq_printf(m, "\t%s: %llu\n", "Total", total);
2569
2570 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2571 i915_guc_client_info(m, dev_priv, &client);
2572
2573 /* Add more as required ... */
2574
2575 return 0;
2576}
2577
Alex Dai4c7e77f2015-08-12 15:43:40 +01002578static int i915_guc_log_dump(struct seq_file *m, void *data)
2579{
2580 struct drm_info_node *node = m->private;
2581 struct drm_device *dev = node->minor->dev;
2582 struct drm_i915_private *dev_priv = dev->dev_private;
2583 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2584 u32 *log;
2585 int i = 0, pg;
2586
2587 if (!log_obj)
2588 return 0;
2589
2590 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2591 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2592
2593 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2594 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2595 *(log + i), *(log + i + 1),
2596 *(log + i + 2), *(log + i + 3));
2597
2598 kunmap_atomic(log);
2599 }
2600
2601 seq_putc(m, '\n');
2602
2603 return 0;
2604}
2605
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002606static int i915_edp_psr_status(struct seq_file *m, void *data)
2607{
2608 struct drm_info_node *node = m->private;
2609 struct drm_device *dev = node->minor->dev;
2610 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002611 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002612 u32 stat[3];
2613 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002614 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002615
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002616 if (!HAS_PSR(dev)) {
2617 seq_puts(m, "PSR not supported\n");
2618 return 0;
2619 }
2620
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002621 intel_runtime_pm_get(dev_priv);
2622
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002623 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002624 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2625 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002626 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002627 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002628 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2629 dev_priv->psr.busy_frontbuffer_bits);
2630 seq_printf(m, "Re-enable work scheduled: %s\n",
2631 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002632
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002633 if (HAS_DDI(dev))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002634 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002635 else {
2636 for_each_pipe(dev_priv, pipe) {
2637 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2638 VLV_EDP_PSR_CURR_STATE_MASK;
2639 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2640 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2641 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002642 }
2643 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002644
2645 seq_printf(m, "Main link in standby mode: %s\n",
2646 yesno(dev_priv->psr.link_standby));
2647
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002648 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002649
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002650 if (!HAS_DDI(dev))
2651 for_each_pipe(dev_priv, pipe) {
2652 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2653 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2654 seq_printf(m, " pipe %c", pipe_name(pipe));
2655 }
2656 seq_puts(m, "\n");
2657
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002658 /*
2659 * VLV/CHV PSR has no kind of performance counter
2660 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2661 */
2662 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002663 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002664 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002665
2666 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2667 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002668 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002669
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002670 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002671 return 0;
2672}
2673
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002674static int i915_sink_crc(struct seq_file *m, void *data)
2675{
2676 struct drm_info_node *node = m->private;
2677 struct drm_device *dev = node->minor->dev;
2678 struct intel_encoder *encoder;
2679 struct intel_connector *connector;
2680 struct intel_dp *intel_dp = NULL;
2681 int ret;
2682 u8 crc[6];
2683
2684 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002685 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002686
2687 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2688 continue;
2689
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002690 if (!connector->base.encoder)
2691 continue;
2692
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002693 encoder = to_intel_encoder(connector->base.encoder);
2694 if (encoder->type != INTEL_OUTPUT_EDP)
2695 continue;
2696
2697 intel_dp = enc_to_intel_dp(&encoder->base);
2698
2699 ret = intel_dp_sink_crc(intel_dp, crc);
2700 if (ret)
2701 goto out;
2702
2703 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2704 crc[0], crc[1], crc[2],
2705 crc[3], crc[4], crc[5]);
2706 goto out;
2707 }
2708 ret = -ENODEV;
2709out:
2710 drm_modeset_unlock_all(dev);
2711 return ret;
2712}
2713
Jesse Barnesec013e72013-08-20 10:29:23 +01002714static int i915_energy_uJ(struct seq_file *m, void *data)
2715{
2716 struct drm_info_node *node = m->private;
2717 struct drm_device *dev = node->minor->dev;
2718 struct drm_i915_private *dev_priv = dev->dev_private;
2719 u64 power;
2720 u32 units;
2721
2722 if (INTEL_INFO(dev)->gen < 6)
2723 return -ENODEV;
2724
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002725 intel_runtime_pm_get(dev_priv);
2726
Jesse Barnesec013e72013-08-20 10:29:23 +01002727 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2728 power = (power & 0x1f00) >> 8;
2729 units = 1000000 / (1 << power); /* convert to uJ */
2730 power = I915_READ(MCH_SECP_NRG_STTS);
2731 power *= units;
2732
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002733 intel_runtime_pm_put(dev_priv);
2734
Jesse Barnesec013e72013-08-20 10:29:23 +01002735 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002736
2737 return 0;
2738}
2739
Damien Lespiau6455c872015-06-04 18:23:57 +01002740static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002741{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002742 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002743 struct drm_device *dev = node->minor->dev;
2744 struct drm_i915_private *dev_priv = dev->dev_private;
2745
Chris Wilsona156e642016-04-03 14:14:21 +01002746 if (!HAS_RUNTIME_PM(dev_priv))
2747 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002748
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002749 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002750 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002751 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002752#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002753 seq_printf(m, "Usage count: %d\n",
2754 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002755#else
2756 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2757#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002758 seq_printf(m, "PCI device power state: %s [%d]\n",
2759 pci_power_name(dev_priv->dev->pdev->current_state),
2760 dev_priv->dev->pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002761
Jesse Barnesec013e72013-08-20 10:29:23 +01002762 return 0;
2763}
2764
Imre Deak1da51582013-11-25 17:15:35 +02002765static int i915_power_domain_info(struct seq_file *m, void *unused)
2766{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002767 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002768 struct drm_device *dev = node->minor->dev;
2769 struct drm_i915_private *dev_priv = dev->dev_private;
2770 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2771 int i;
2772
2773 mutex_lock(&power_domains->lock);
2774
2775 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2776 for (i = 0; i < power_domains->power_well_count; i++) {
2777 struct i915_power_well *power_well;
2778 enum intel_display_power_domain power_domain;
2779
2780 power_well = &power_domains->power_wells[i];
2781 seq_printf(m, "%-25s %d\n", power_well->name,
2782 power_well->count);
2783
2784 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2785 power_domain++) {
2786 if (!(BIT(power_domain) & power_well->domains))
2787 continue;
2788
2789 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002790 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002791 power_domains->domain_use_count[power_domain]);
2792 }
2793 }
2794
2795 mutex_unlock(&power_domains->lock);
2796
2797 return 0;
2798}
2799
Damien Lespiaub7cec662015-10-27 14:47:01 +02002800static int i915_dmc_info(struct seq_file *m, void *unused)
2801{
2802 struct drm_info_node *node = m->private;
2803 struct drm_device *dev = node->minor->dev;
2804 struct drm_i915_private *dev_priv = dev->dev_private;
2805 struct intel_csr *csr;
2806
2807 if (!HAS_CSR(dev)) {
2808 seq_puts(m, "not supported\n");
2809 return 0;
2810 }
2811
2812 csr = &dev_priv->csr;
2813
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002814 intel_runtime_pm_get(dev_priv);
2815
Damien Lespiaub7cec662015-10-27 14:47:01 +02002816 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2817 seq_printf(m, "path: %s\n", csr->fw_path);
2818
2819 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002820 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002821
2822 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2823 CSR_VERSION_MINOR(csr->version));
2824
Damien Lespiau83372062015-10-30 17:53:32 +02002825 if (IS_SKYLAKE(dev) && csr->version >= CSR_VERSION(1, 6)) {
2826 seq_printf(m, "DC3 -> DC5 count: %d\n",
2827 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2828 seq_printf(m, "DC5 -> DC6 count: %d\n",
2829 I915_READ(SKL_CSR_DC5_DC6_COUNT));
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002830 } else if (IS_BROXTON(dev) && csr->version >= CSR_VERSION(1, 4)) {
2831 seq_printf(m, "DC3 -> DC5 count: %d\n",
2832 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002833 }
2834
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002835out:
2836 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2837 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2838 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2839
Damien Lespiau83372062015-10-30 17:53:32 +02002840 intel_runtime_pm_put(dev_priv);
2841
Damien Lespiaub7cec662015-10-27 14:47:01 +02002842 return 0;
2843}
2844
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002845static void intel_seq_print_mode(struct seq_file *m, int tabs,
2846 struct drm_display_mode *mode)
2847{
2848 int i;
2849
2850 for (i = 0; i < tabs; i++)
2851 seq_putc(m, '\t');
2852
2853 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",
2854 mode->base.id, mode->name,
2855 mode->vrefresh, mode->clock,
2856 mode->hdisplay, mode->hsync_start,
2857 mode->hsync_end, mode->htotal,
2858 mode->vdisplay, mode->vsync_start,
2859 mode->vsync_end, mode->vtotal,
2860 mode->type, mode->flags);
2861}
2862
2863static void intel_encoder_info(struct seq_file *m,
2864 struct intel_crtc *intel_crtc,
2865 struct intel_encoder *intel_encoder)
2866{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002867 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002868 struct drm_device *dev = node->minor->dev;
2869 struct drm_crtc *crtc = &intel_crtc->base;
2870 struct intel_connector *intel_connector;
2871 struct drm_encoder *encoder;
2872
2873 encoder = &intel_encoder->base;
2874 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002875 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002876 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2877 struct drm_connector *connector = &intel_connector->base;
2878 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2879 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002880 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002881 drm_get_connector_status_name(connector->status));
2882 if (connector->status == connector_status_connected) {
2883 struct drm_display_mode *mode = &crtc->mode;
2884 seq_printf(m, ", mode:\n");
2885 intel_seq_print_mode(m, 2, mode);
2886 } else {
2887 seq_putc(m, '\n');
2888 }
2889 }
2890}
2891
2892static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2893{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002894 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002895 struct drm_device *dev = node->minor->dev;
2896 struct drm_crtc *crtc = &intel_crtc->base;
2897 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002898 struct drm_plane_state *plane_state = crtc->primary->state;
2899 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002900
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002901 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002902 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002903 fb->base.id, plane_state->src_x >> 16,
2904 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002905 else
2906 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002907 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2908 intel_encoder_info(m, intel_crtc, intel_encoder);
2909}
2910
2911static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2912{
2913 struct drm_display_mode *mode = panel->fixed_mode;
2914
2915 seq_printf(m, "\tfixed mode:\n");
2916 intel_seq_print_mode(m, 2, mode);
2917}
2918
2919static void intel_dp_info(struct seq_file *m,
2920 struct intel_connector *intel_connector)
2921{
2922 struct intel_encoder *intel_encoder = intel_connector->encoder;
2923 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2924
2925 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002926 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002927 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2928 intel_panel_info(m, &intel_connector->panel);
2929}
2930
2931static void intel_hdmi_info(struct seq_file *m,
2932 struct intel_connector *intel_connector)
2933{
2934 struct intel_encoder *intel_encoder = intel_connector->encoder;
2935 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2936
Jani Nikula742f4912015-09-03 11:16:09 +03002937 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002938}
2939
2940static void intel_lvds_info(struct seq_file *m,
2941 struct intel_connector *intel_connector)
2942{
2943 intel_panel_info(m, &intel_connector->panel);
2944}
2945
2946static void intel_connector_info(struct seq_file *m,
2947 struct drm_connector *connector)
2948{
2949 struct intel_connector *intel_connector = to_intel_connector(connector);
2950 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002951 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002952
2953 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002954 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002955 drm_get_connector_status_name(connector->status));
2956 if (connector->status == connector_status_connected) {
2957 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2958 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2959 connector->display_info.width_mm,
2960 connector->display_info.height_mm);
2961 seq_printf(m, "\tsubpixel order: %s\n",
2962 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2963 seq_printf(m, "\tCEA rev: %d\n",
2964 connector->display_info.cea_rev);
2965 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002966 if (intel_encoder) {
2967 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2968 intel_encoder->type == INTEL_OUTPUT_EDP)
2969 intel_dp_info(m, intel_connector);
2970 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2971 intel_hdmi_info(m, intel_connector);
2972 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2973 intel_lvds_info(m, intel_connector);
2974 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002975
Jesse Barnesf103fc72014-02-20 12:39:57 -08002976 seq_printf(m, "\tmodes:\n");
2977 list_for_each_entry(mode, &connector->modes, head)
2978 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002979}
2980
Chris Wilson065f2ec22014-03-12 09:13:13 +00002981static bool cursor_active(struct drm_device *dev, int pipe)
2982{
2983 struct drm_i915_private *dev_priv = dev->dev_private;
2984 u32 state;
2985
2986 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002987 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002988 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002989 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002990
2991 return state;
2992}
2993
2994static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2995{
2996 struct drm_i915_private *dev_priv = dev->dev_private;
2997 u32 pos;
2998
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002999 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00003000
3001 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3002 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3003 *x = -*x;
3004
3005 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3006 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3007 *y = -*y;
3008
3009 return cursor_active(dev, pipe);
3010}
3011
Robert Fekete3abc4e02015-10-27 16:58:32 +01003012static const char *plane_type(enum drm_plane_type type)
3013{
3014 switch (type) {
3015 case DRM_PLANE_TYPE_OVERLAY:
3016 return "OVL";
3017 case DRM_PLANE_TYPE_PRIMARY:
3018 return "PRI";
3019 case DRM_PLANE_TYPE_CURSOR:
3020 return "CUR";
3021 /*
3022 * Deliberately omitting default: to generate compiler warnings
3023 * when a new drm_plane_type gets added.
3024 */
3025 }
3026
3027 return "unknown";
3028}
3029
3030static const char *plane_rotation(unsigned int rotation)
3031{
3032 static char buf[48];
3033 /*
3034 * According to doc only one DRM_ROTATE_ is allowed but this
3035 * will print them all to visualize if the values are misused
3036 */
3037 snprintf(buf, sizeof(buf),
3038 "%s%s%s%s%s%s(0x%08x)",
3039 (rotation & BIT(DRM_ROTATE_0)) ? "0 " : "",
3040 (rotation & BIT(DRM_ROTATE_90)) ? "90 " : "",
3041 (rotation & BIT(DRM_ROTATE_180)) ? "180 " : "",
3042 (rotation & BIT(DRM_ROTATE_270)) ? "270 " : "",
3043 (rotation & BIT(DRM_REFLECT_X)) ? "FLIPX " : "",
3044 (rotation & BIT(DRM_REFLECT_Y)) ? "FLIPY " : "",
3045 rotation);
3046
3047 return buf;
3048}
3049
3050static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3051{
3052 struct drm_info_node *node = m->private;
3053 struct drm_device *dev = node->minor->dev;
3054 struct intel_plane *intel_plane;
3055
3056 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3057 struct drm_plane_state *state;
3058 struct drm_plane *plane = &intel_plane->base;
3059
3060 if (!plane->state) {
3061 seq_puts(m, "plane->state is NULL!\n");
3062 continue;
3063 }
3064
3065 state = plane->state;
3066
3067 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",
3068 plane->base.id,
3069 plane_type(intel_plane->base.type),
3070 state->crtc_x, state->crtc_y,
3071 state->crtc_w, state->crtc_h,
3072 (state->src_x >> 16),
3073 ((state->src_x & 0xffff) * 15625) >> 10,
3074 (state->src_y >> 16),
3075 ((state->src_y & 0xffff) * 15625) >> 10,
3076 (state->src_w >> 16),
3077 ((state->src_w & 0xffff) * 15625) >> 10,
3078 (state->src_h >> 16),
3079 ((state->src_h & 0xffff) * 15625) >> 10,
3080 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3081 plane_rotation(state->rotation));
3082 }
3083}
3084
3085static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3086{
3087 struct intel_crtc_state *pipe_config;
3088 int num_scalers = intel_crtc->num_scalers;
3089 int i;
3090
3091 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3092
3093 /* Not all platformas have a scaler */
3094 if (num_scalers) {
3095 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3096 num_scalers,
3097 pipe_config->scaler_state.scaler_users,
3098 pipe_config->scaler_state.scaler_id);
3099
3100 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3101 struct intel_scaler *sc =
3102 &pipe_config->scaler_state.scalers[i];
3103
3104 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3105 i, yesno(sc->in_use), sc->mode);
3106 }
3107 seq_puts(m, "\n");
3108 } else {
3109 seq_puts(m, "\tNo scalers available on this platform\n");
3110 }
3111}
3112
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003113static int i915_display_info(struct seq_file *m, void *unused)
3114{
Damien Lespiau9f25d002014-05-13 15:30:28 +01003115 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003116 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003117 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003118 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003119 struct drm_connector *connector;
3120
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003121 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003122 drm_modeset_lock_all(dev);
3123 seq_printf(m, "CRTC info\n");
3124 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003125 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003126 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003127 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003128 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003129
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003130 pipe_config = to_intel_crtc_state(crtc->base.state);
3131
Robert Fekete3abc4e02015-10-27 16:58:32 +01003132 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00003133 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003134 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003135 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3136 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3137
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003138 if (pipe_config->base.active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003139 intel_crtc_info(m, crtc);
3140
Paulo Zanonia23dc652014-04-01 14:55:11 -03003141 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003142 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 +03003143 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003144 x, y, crtc->base.cursor->state->crtc_w,
3145 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003146 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003147 intel_scaler_info(m, crtc);
3148 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003149 }
Daniel Vettercace8412014-05-22 17:56:31 +02003150
3151 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3152 yesno(!crtc->cpu_fifo_underrun_disabled),
3153 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003154 }
3155
3156 seq_printf(m, "\n");
3157 seq_printf(m, "Connector info\n");
3158 seq_printf(m, "--------------\n");
3159 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3160 intel_connector_info(m, connector);
3161 }
3162 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003163 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003164
3165 return 0;
3166}
3167
Ben Widawskye04934c2014-06-30 09:53:42 -07003168static int i915_semaphore_status(struct seq_file *m, void *unused)
3169{
3170 struct drm_info_node *node = (struct drm_info_node *) m->private;
3171 struct drm_device *dev = node->minor->dev;
3172 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003173 struct intel_engine_cs *engine;
Ben Widawskye04934c2014-06-30 09:53:42 -07003174 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
Dave Gordonc3232b12016-03-23 18:19:53 +00003175 enum intel_engine_id id;
3176 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003177
Chris Wilsonc0336662016-05-06 15:40:21 +01003178 if (!i915_semaphore_is_enabled(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003179 seq_puts(m, "Semaphores are disabled\n");
3180 return 0;
3181 }
3182
3183 ret = mutex_lock_interruptible(&dev->struct_mutex);
3184 if (ret)
3185 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003186 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003187
3188 if (IS_BROADWELL(dev)) {
3189 struct page *page;
3190 uint64_t *seqno;
3191
3192 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3193
3194 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003195 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003196 uint64_t offset;
3197
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003198 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003199
3200 seq_puts(m, " Last signal:");
3201 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003202 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003203 seq_printf(m, "0x%08llx (0x%02llx) ",
3204 seqno[offset], offset * 8);
3205 }
3206 seq_putc(m, '\n');
3207
3208 seq_puts(m, " Last wait: ");
3209 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003210 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003211 seq_printf(m, "0x%08llx (0x%02llx) ",
3212 seqno[offset], offset * 8);
3213 }
3214 seq_putc(m, '\n');
3215
3216 }
3217 kunmap_atomic(seqno);
3218 } else {
3219 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003220 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003221 for (j = 0; j < num_rings; j++)
3222 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003223 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003224 seq_putc(m, '\n');
3225 }
3226
3227 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003228 for_each_engine(engine, dev_priv) {
3229 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003230 seq_printf(m, " 0x%08x ",
3231 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003232 seq_putc(m, '\n');
3233 }
3234 seq_putc(m, '\n');
3235
Paulo Zanoni03872062014-07-09 14:31:57 -03003236 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003237 mutex_unlock(&dev->struct_mutex);
3238 return 0;
3239}
3240
Daniel Vetter728e29d2014-06-25 22:01:53 +03003241static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3242{
3243 struct drm_info_node *node = (struct drm_info_node *) m->private;
3244 struct drm_device *dev = node->minor->dev;
3245 struct drm_i915_private *dev_priv = dev->dev_private;
3246 int i;
3247
3248 drm_modeset_lock_all(dev);
3249 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3250 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3251
3252 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003253 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3254 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003255 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003256 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3257 seq_printf(m, " dpll_md: 0x%08x\n",
3258 pll->config.hw_state.dpll_md);
3259 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3260 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3261 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003262 }
3263 drm_modeset_unlock_all(dev);
3264
3265 return 0;
3266}
3267
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003268static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003269{
3270 int i;
3271 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003272 struct intel_engine_cs *engine;
Arun Siluvery888b5992014-08-26 14:44:51 +01003273 struct drm_info_node *node = (struct drm_info_node *) m->private;
3274 struct drm_device *dev = node->minor->dev;
3275 struct drm_i915_private *dev_priv = dev->dev_private;
Arun Siluvery33136b02016-01-21 21:43:47 +00003276 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003277 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003278
Arun Siluvery888b5992014-08-26 14:44:51 +01003279 ret = mutex_lock_interruptible(&dev->struct_mutex);
3280 if (ret)
3281 return ret;
3282
3283 intel_runtime_pm_get(dev_priv);
3284
Arun Siluvery33136b02016-01-21 21:43:47 +00003285 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003286 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003287 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003288 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003289 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003290 i915_reg_t addr;
3291 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003292 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003293
Arun Siluvery33136b02016-01-21 21:43:47 +00003294 addr = workarounds->reg[i].addr;
3295 mask = workarounds->reg[i].mask;
3296 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003297 read = I915_READ(addr);
3298 ok = (value & mask) == (read & mask);
3299 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 +02003300 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003301 }
3302
3303 intel_runtime_pm_put(dev_priv);
3304 mutex_unlock(&dev->struct_mutex);
3305
3306 return 0;
3307}
3308
Damien Lespiauc5511e42014-11-04 17:06:51 +00003309static int i915_ddb_info(struct seq_file *m, void *unused)
3310{
3311 struct drm_info_node *node = m->private;
3312 struct drm_device *dev = node->minor->dev;
3313 struct drm_i915_private *dev_priv = dev->dev_private;
3314 struct skl_ddb_allocation *ddb;
3315 struct skl_ddb_entry *entry;
3316 enum pipe pipe;
3317 int plane;
3318
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003319 if (INTEL_INFO(dev)->gen < 9)
3320 return 0;
3321
Damien Lespiauc5511e42014-11-04 17:06:51 +00003322 drm_modeset_lock_all(dev);
3323
3324 ddb = &dev_priv->wm.skl_hw.ddb;
3325
3326 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3327
3328 for_each_pipe(dev_priv, pipe) {
3329 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3330
Damien Lespiaudd740782015-02-28 14:54:08 +00003331 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003332 entry = &ddb->plane[pipe][plane];
3333 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3334 entry->start, entry->end,
3335 skl_ddb_entry_size(entry));
3336 }
3337
Matt Roper4969d332015-09-24 15:53:10 -07003338 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003339 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3340 entry->end, skl_ddb_entry_size(entry));
3341 }
3342
3343 drm_modeset_unlock_all(dev);
3344
3345 return 0;
3346}
3347
Vandana Kannana54746e2015-03-03 20:53:10 +05303348static void drrs_status_per_crtc(struct seq_file *m,
3349 struct drm_device *dev, struct intel_crtc *intel_crtc)
3350{
3351 struct intel_encoder *intel_encoder;
3352 struct drm_i915_private *dev_priv = dev->dev_private;
3353 struct i915_drrs *drrs = &dev_priv->drrs;
3354 int vrefresh = 0;
3355
3356 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3357 /* Encoder connected on this CRTC */
3358 switch (intel_encoder->type) {
3359 case INTEL_OUTPUT_EDP:
3360 seq_puts(m, "eDP:\n");
3361 break;
3362 case INTEL_OUTPUT_DSI:
3363 seq_puts(m, "DSI:\n");
3364 break;
3365 case INTEL_OUTPUT_HDMI:
3366 seq_puts(m, "HDMI:\n");
3367 break;
3368 case INTEL_OUTPUT_DISPLAYPORT:
3369 seq_puts(m, "DP:\n");
3370 break;
3371 default:
3372 seq_printf(m, "Other encoder (id=%d).\n",
3373 intel_encoder->type);
3374 return;
3375 }
3376 }
3377
3378 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3379 seq_puts(m, "\tVBT: DRRS_type: Static");
3380 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3381 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3382 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3383 seq_puts(m, "\tVBT: DRRS_type: None");
3384 else
3385 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3386
3387 seq_puts(m, "\n\n");
3388
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003389 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303390 struct intel_panel *panel;
3391
3392 mutex_lock(&drrs->mutex);
3393 /* DRRS Supported */
3394 seq_puts(m, "\tDRRS Supported: Yes\n");
3395
3396 /* disable_drrs() will make drrs->dp NULL */
3397 if (!drrs->dp) {
3398 seq_puts(m, "Idleness DRRS: Disabled");
3399 mutex_unlock(&drrs->mutex);
3400 return;
3401 }
3402
3403 panel = &drrs->dp->attached_connector->panel;
3404 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3405 drrs->busy_frontbuffer_bits);
3406
3407 seq_puts(m, "\n\t\t");
3408 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3409 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3410 vrefresh = panel->fixed_mode->vrefresh;
3411 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3412 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3413 vrefresh = panel->downclock_mode->vrefresh;
3414 } else {
3415 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3416 drrs->refresh_rate_type);
3417 mutex_unlock(&drrs->mutex);
3418 return;
3419 }
3420 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3421
3422 seq_puts(m, "\n\t\t");
3423 mutex_unlock(&drrs->mutex);
3424 } else {
3425 /* DRRS not supported. Print the VBT parameter*/
3426 seq_puts(m, "\tDRRS Supported : No");
3427 }
3428 seq_puts(m, "\n");
3429}
3430
3431static int i915_drrs_status(struct seq_file *m, void *unused)
3432{
3433 struct drm_info_node *node = m->private;
3434 struct drm_device *dev = node->minor->dev;
3435 struct intel_crtc *intel_crtc;
3436 int active_crtc_cnt = 0;
3437
3438 for_each_intel_crtc(dev, intel_crtc) {
3439 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3440
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003441 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303442 active_crtc_cnt++;
3443 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3444
3445 drrs_status_per_crtc(m, dev, intel_crtc);
3446 }
3447
3448 drm_modeset_unlock(&intel_crtc->base.mutex);
3449 }
3450
3451 if (!active_crtc_cnt)
3452 seq_puts(m, "No active crtc found\n");
3453
3454 return 0;
3455}
3456
Damien Lespiau07144422013-10-15 18:55:40 +01003457struct pipe_crc_info {
3458 const char *name;
3459 struct drm_device *dev;
3460 enum pipe pipe;
3461};
3462
Dave Airlie11bed952014-05-12 15:22:27 +10003463static int i915_dp_mst_info(struct seq_file *m, void *unused)
3464{
3465 struct drm_info_node *node = (struct drm_info_node *) m->private;
3466 struct drm_device *dev = node->minor->dev;
3467 struct drm_encoder *encoder;
3468 struct intel_encoder *intel_encoder;
3469 struct intel_digital_port *intel_dig_port;
3470 drm_modeset_lock_all(dev);
3471 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3472 intel_encoder = to_intel_encoder(encoder);
3473 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3474 continue;
3475 intel_dig_port = enc_to_dig_port(encoder);
3476 if (!intel_dig_port->dp.can_mst)
3477 continue;
Jim Bride40ae80c2016-04-14 10:18:37 -07003478 seq_printf(m, "MST Source Port %c\n",
3479 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003480 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3481 }
3482 drm_modeset_unlock_all(dev);
3483 return 0;
3484}
3485
Damien Lespiau07144422013-10-15 18:55:40 +01003486static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003487{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003488 struct pipe_crc_info *info = inode->i_private;
3489 struct drm_i915_private *dev_priv = info->dev->dev_private;
3490 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3491
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003492 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3493 return -ENODEV;
3494
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003495 spin_lock_irq(&pipe_crc->lock);
3496
3497 if (pipe_crc->opened) {
3498 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003499 return -EBUSY; /* already open */
3500 }
3501
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003502 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003503 filep->private_data = inode->i_private;
3504
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003505 spin_unlock_irq(&pipe_crc->lock);
3506
Damien Lespiau07144422013-10-15 18:55:40 +01003507 return 0;
3508}
3509
3510static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3511{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003512 struct pipe_crc_info *info = inode->i_private;
3513 struct drm_i915_private *dev_priv = info->dev->dev_private;
3514 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3515
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003516 spin_lock_irq(&pipe_crc->lock);
3517 pipe_crc->opened = false;
3518 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003519
Damien Lespiau07144422013-10-15 18:55:40 +01003520 return 0;
3521}
3522
3523/* (6 fields, 8 chars each, space separated (5) + '\n') */
3524#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3525/* account for \'0' */
3526#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3527
3528static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3529{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003530 assert_spin_locked(&pipe_crc->lock);
3531 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3532 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003533}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003534
Damien Lespiau07144422013-10-15 18:55:40 +01003535static ssize_t
3536i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3537 loff_t *pos)
3538{
3539 struct pipe_crc_info *info = filep->private_data;
3540 struct drm_device *dev = info->dev;
3541 struct drm_i915_private *dev_priv = dev->dev_private;
3542 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3543 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003544 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003545 ssize_t bytes_read;
3546
3547 /*
3548 * Don't allow user space to provide buffers not big enough to hold
3549 * a line of data.
3550 */
3551 if (count < PIPE_CRC_LINE_LEN)
3552 return -EINVAL;
3553
3554 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3555 return 0;
3556
3557 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003558 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003559 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003560 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003561
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003562 if (filep->f_flags & O_NONBLOCK) {
3563 spin_unlock_irq(&pipe_crc->lock);
3564 return -EAGAIN;
3565 }
3566
3567 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3568 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3569 if (ret) {
3570 spin_unlock_irq(&pipe_crc->lock);
3571 return ret;
3572 }
Damien Lespiau07144422013-10-15 18:55:40 +01003573 }
3574
3575 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003576 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003577
Damien Lespiau07144422013-10-15 18:55:40 +01003578 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003579 while (n_entries > 0) {
3580 struct intel_pipe_crc_entry *entry =
3581 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003582 int ret;
3583
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003584 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3585 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3586 break;
3587
3588 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3589 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3590
Damien Lespiau07144422013-10-15 18:55:40 +01003591 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3592 "%8u %8x %8x %8x %8x %8x\n",
3593 entry->frame, entry->crc[0],
3594 entry->crc[1], entry->crc[2],
3595 entry->crc[3], entry->crc[4]);
3596
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003597 spin_unlock_irq(&pipe_crc->lock);
3598
3599 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003600 if (ret == PIPE_CRC_LINE_LEN)
3601 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003602
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003603 user_buf += PIPE_CRC_LINE_LEN;
3604 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003605
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003606 spin_lock_irq(&pipe_crc->lock);
3607 }
3608
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003609 spin_unlock_irq(&pipe_crc->lock);
3610
Damien Lespiau07144422013-10-15 18:55:40 +01003611 return bytes_read;
3612}
3613
3614static const struct file_operations i915_pipe_crc_fops = {
3615 .owner = THIS_MODULE,
3616 .open = i915_pipe_crc_open,
3617 .read = i915_pipe_crc_read,
3618 .release = i915_pipe_crc_release,
3619};
3620
3621static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3622 {
3623 .name = "i915_pipe_A_crc",
3624 .pipe = PIPE_A,
3625 },
3626 {
3627 .name = "i915_pipe_B_crc",
3628 .pipe = PIPE_B,
3629 },
3630 {
3631 .name = "i915_pipe_C_crc",
3632 .pipe = PIPE_C,
3633 },
3634};
3635
3636static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3637 enum pipe pipe)
3638{
3639 struct drm_device *dev = minor->dev;
3640 struct dentry *ent;
3641 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3642
3643 info->dev = dev;
3644 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3645 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003646 if (!ent)
3647 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003648
3649 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003650}
3651
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003652static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003653 "none",
3654 "plane1",
3655 "plane2",
3656 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003657 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003658 "TV",
3659 "DP-B",
3660 "DP-C",
3661 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003662 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003663};
3664
3665static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3666{
3667 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3668 return pipe_crc_sources[source];
3669}
3670
Damien Lespiaubd9db022013-10-15 18:55:36 +01003671static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003672{
3673 struct drm_device *dev = m->private;
3674 struct drm_i915_private *dev_priv = dev->dev_private;
3675 int i;
3676
3677 for (i = 0; i < I915_MAX_PIPES; i++)
3678 seq_printf(m, "%c %s\n", pipe_name(i),
3679 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3680
3681 return 0;
3682}
3683
Damien Lespiaubd9db022013-10-15 18:55:36 +01003684static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003685{
3686 struct drm_device *dev = inode->i_private;
3687
Damien Lespiaubd9db022013-10-15 18:55:36 +01003688 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003689}
3690
Daniel Vetter46a19182013-11-01 10:50:20 +01003691static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003692 uint32_t *val)
3693{
Daniel Vetter46a19182013-11-01 10:50:20 +01003694 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3695 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3696
3697 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003698 case INTEL_PIPE_CRC_SOURCE_PIPE:
3699 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3700 break;
3701 case INTEL_PIPE_CRC_SOURCE_NONE:
3702 *val = 0;
3703 break;
3704 default:
3705 return -EINVAL;
3706 }
3707
3708 return 0;
3709}
3710
Daniel Vetter46a19182013-11-01 10:50:20 +01003711static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3712 enum intel_pipe_crc_source *source)
3713{
3714 struct intel_encoder *encoder;
3715 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003716 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003717 int ret = 0;
3718
3719 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3720
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003721 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003722 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003723 if (!encoder->base.crtc)
3724 continue;
3725
3726 crtc = to_intel_crtc(encoder->base.crtc);
3727
3728 if (crtc->pipe != pipe)
3729 continue;
3730
3731 switch (encoder->type) {
3732 case INTEL_OUTPUT_TVOUT:
3733 *source = INTEL_PIPE_CRC_SOURCE_TV;
3734 break;
3735 case INTEL_OUTPUT_DISPLAYPORT:
3736 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003737 dig_port = enc_to_dig_port(&encoder->base);
3738 switch (dig_port->port) {
3739 case PORT_B:
3740 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3741 break;
3742 case PORT_C:
3743 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3744 break;
3745 case PORT_D:
3746 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3747 break;
3748 default:
3749 WARN(1, "nonexisting DP port %c\n",
3750 port_name(dig_port->port));
3751 break;
3752 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003753 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003754 default:
3755 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003756 }
3757 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003758 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003759
3760 return ret;
3761}
3762
3763static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3764 enum pipe pipe,
3765 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003766 uint32_t *val)
3767{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003768 struct drm_i915_private *dev_priv = dev->dev_private;
3769 bool need_stable_symbols = false;
3770
Daniel Vetter46a19182013-11-01 10:50:20 +01003771 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3772 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3773 if (ret)
3774 return ret;
3775 }
3776
3777 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003778 case INTEL_PIPE_CRC_SOURCE_PIPE:
3779 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3780 break;
3781 case INTEL_PIPE_CRC_SOURCE_DP_B:
3782 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003783 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003784 break;
3785 case INTEL_PIPE_CRC_SOURCE_DP_C:
3786 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003787 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003788 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003789 case INTEL_PIPE_CRC_SOURCE_DP_D:
3790 if (!IS_CHERRYVIEW(dev))
3791 return -EINVAL;
3792 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3793 need_stable_symbols = true;
3794 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003795 case INTEL_PIPE_CRC_SOURCE_NONE:
3796 *val = 0;
3797 break;
3798 default:
3799 return -EINVAL;
3800 }
3801
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003802 /*
3803 * When the pipe CRC tap point is after the transcoders we need
3804 * to tweak symbol-level features to produce a deterministic series of
3805 * symbols for a given frame. We need to reset those features only once
3806 * a frame (instead of every nth symbol):
3807 * - DC-balance: used to ensure a better clock recovery from the data
3808 * link (SDVO)
3809 * - DisplayPort scrambling: used for EMI reduction
3810 */
3811 if (need_stable_symbols) {
3812 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3813
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003814 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003815 switch (pipe) {
3816 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003817 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003818 break;
3819 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003820 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003821 break;
3822 case PIPE_C:
3823 tmp |= PIPE_C_SCRAMBLE_RESET;
3824 break;
3825 default:
3826 return -EINVAL;
3827 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003828 I915_WRITE(PORT_DFT2_G4X, tmp);
3829 }
3830
Daniel Vetter7ac01292013-10-18 16:37:06 +02003831 return 0;
3832}
3833
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003834static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003835 enum pipe pipe,
3836 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003837 uint32_t *val)
3838{
Daniel Vetter84093602013-11-01 10:50:21 +01003839 struct drm_i915_private *dev_priv = dev->dev_private;
3840 bool need_stable_symbols = false;
3841
Daniel Vetter46a19182013-11-01 10:50:20 +01003842 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3843 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3844 if (ret)
3845 return ret;
3846 }
3847
3848 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003849 case INTEL_PIPE_CRC_SOURCE_PIPE:
3850 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3851 break;
3852 case INTEL_PIPE_CRC_SOURCE_TV:
3853 if (!SUPPORTS_TV(dev))
3854 return -EINVAL;
3855 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3856 break;
3857 case INTEL_PIPE_CRC_SOURCE_DP_B:
3858 if (!IS_G4X(dev))
3859 return -EINVAL;
3860 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003861 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003862 break;
3863 case INTEL_PIPE_CRC_SOURCE_DP_C:
3864 if (!IS_G4X(dev))
3865 return -EINVAL;
3866 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003867 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003868 break;
3869 case INTEL_PIPE_CRC_SOURCE_DP_D:
3870 if (!IS_G4X(dev))
3871 return -EINVAL;
3872 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003873 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003874 break;
3875 case INTEL_PIPE_CRC_SOURCE_NONE:
3876 *val = 0;
3877 break;
3878 default:
3879 return -EINVAL;
3880 }
3881
Daniel Vetter84093602013-11-01 10:50:21 +01003882 /*
3883 * When the pipe CRC tap point is after the transcoders we need
3884 * to tweak symbol-level features to produce a deterministic series of
3885 * symbols for a given frame. We need to reset those features only once
3886 * a frame (instead of every nth symbol):
3887 * - DC-balance: used to ensure a better clock recovery from the data
3888 * link (SDVO)
3889 * - DisplayPort scrambling: used for EMI reduction
3890 */
3891 if (need_stable_symbols) {
3892 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3893
3894 WARN_ON(!IS_G4X(dev));
3895
3896 I915_WRITE(PORT_DFT_I9XX,
3897 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3898
3899 if (pipe == PIPE_A)
3900 tmp |= PIPE_A_SCRAMBLE_RESET;
3901 else
3902 tmp |= PIPE_B_SCRAMBLE_RESET;
3903
3904 I915_WRITE(PORT_DFT2_G4X, tmp);
3905 }
3906
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003907 return 0;
3908}
3909
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003910static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3911 enum pipe pipe)
3912{
3913 struct drm_i915_private *dev_priv = dev->dev_private;
3914 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3915
Ville Syrjäläeb736672014-12-09 21:28:28 +02003916 switch (pipe) {
3917 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003918 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003919 break;
3920 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003921 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003922 break;
3923 case PIPE_C:
3924 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3925 break;
3926 default:
3927 return;
3928 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003929 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3930 tmp &= ~DC_BALANCE_RESET_VLV;
3931 I915_WRITE(PORT_DFT2_G4X, tmp);
3932
3933}
3934
Daniel Vetter84093602013-11-01 10:50:21 +01003935static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3936 enum pipe pipe)
3937{
3938 struct drm_i915_private *dev_priv = dev->dev_private;
3939 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3940
3941 if (pipe == PIPE_A)
3942 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3943 else
3944 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3945 I915_WRITE(PORT_DFT2_G4X, tmp);
3946
3947 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3948 I915_WRITE(PORT_DFT_I9XX,
3949 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3950 }
3951}
3952
Daniel Vetter46a19182013-11-01 10:50:20 +01003953static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003954 uint32_t *val)
3955{
Daniel Vetter46a19182013-11-01 10:50:20 +01003956 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3957 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3958
3959 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003960 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3961 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3962 break;
3963 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3964 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3965 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003966 case INTEL_PIPE_CRC_SOURCE_PIPE:
3967 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3968 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003969 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003970 *val = 0;
3971 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003972 default:
3973 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003974 }
3975
3976 return 0;
3977}
3978
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003979static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003980{
3981 struct drm_i915_private *dev_priv = dev->dev_private;
3982 struct intel_crtc *crtc =
3983 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003984 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003985 struct drm_atomic_state *state;
3986 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003987
3988 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003989 state = drm_atomic_state_alloc(dev);
3990 if (!state) {
3991 ret = -ENOMEM;
3992 goto out;
3993 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003994
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003995 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
3996 pipe_config = intel_atomic_get_crtc_state(state, crtc);
3997 if (IS_ERR(pipe_config)) {
3998 ret = PTR_ERR(pipe_config);
3999 goto out;
4000 }
4001
4002 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004003 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004004 pipe_config->pch_pfit.enabled != enable)
4005 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004006
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004007 ret = drm_atomic_commit(state);
4008out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004009 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004010 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
4011 if (ret)
4012 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004013}
4014
4015static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
4016 enum pipe pipe,
4017 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004018 uint32_t *val)
4019{
Daniel Vetter46a19182013-11-01 10:50:20 +01004020 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4021 *source = INTEL_PIPE_CRC_SOURCE_PF;
4022
4023 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004024 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4025 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4026 break;
4027 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4028 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4029 break;
4030 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004031 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004032 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004033
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004034 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4035 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004036 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004037 *val = 0;
4038 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004039 default:
4040 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004041 }
4042
4043 return 0;
4044}
4045
Daniel Vetter926321d2013-10-16 13:30:34 +02004046static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
4047 enum intel_pipe_crc_source source)
4048{
4049 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004050 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004051 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
4052 pipe));
Imre Deake1296492016-02-12 18:55:17 +02004053 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004054 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004055 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004056
Damien Lespiaucc3da172013-10-15 18:55:31 +01004057 if (pipe_crc->source == source)
4058 return 0;
4059
Damien Lespiauae676fc2013-10-15 18:55:32 +01004060 /* forbid changing the source without going back to 'none' */
4061 if (pipe_crc->source && source)
4062 return -EINVAL;
4063
Imre Deake1296492016-02-12 18:55:17 +02004064 power_domain = POWER_DOMAIN_PIPE(pipe);
4065 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004066 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4067 return -EIO;
4068 }
4069
Daniel Vetter52f843f2013-10-21 17:26:38 +02004070 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004071 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02004072 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01004073 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Wayne Boyer666a4532015-12-09 12:29:35 -08004074 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004075 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004076 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004077 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004078 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004079 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004080
4081 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004082 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004083
Damien Lespiau4b584362013-10-15 18:55:33 +01004084 /* none -> real source transition */
4085 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004086 struct intel_pipe_crc_entry *entries;
4087
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004088 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4089 pipe_name(pipe), pipe_crc_source_name(source));
4090
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004091 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4092 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004093 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004094 if (!entries) {
4095 ret = -ENOMEM;
4096 goto out;
4097 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004098
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004099 /*
4100 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4101 * enabled and disabled dynamically based on package C states,
4102 * user space can't make reliable use of the CRCs, so let's just
4103 * completely disable it.
4104 */
4105 hsw_disable_ips(crtc);
4106
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004107 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004108 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004109 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004110 pipe_crc->head = 0;
4111 pipe_crc->tail = 0;
4112 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004113 }
4114
Damien Lespiaucc3da172013-10-15 18:55:31 +01004115 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004116
Daniel Vetter926321d2013-10-16 13:30:34 +02004117 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4118 POSTING_READ(PIPE_CRC_CTL(pipe));
4119
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004120 /* real source -> none transition */
4121 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004122 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004123 struct intel_crtc *crtc =
4124 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004125
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004126 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4127 pipe_name(pipe));
4128
Daniel Vettera33d7102014-06-06 08:22:08 +02004129 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004130 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004131 intel_wait_for_vblank(dev, pipe);
4132 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004133
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004134 spin_lock_irq(&pipe_crc->lock);
4135 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004136 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004137 pipe_crc->head = 0;
4138 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004139 spin_unlock_irq(&pipe_crc->lock);
4140
4141 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004142
4143 if (IS_G4X(dev))
4144 g4x_undo_pipe_scramble_reset(dev, pipe);
Wayne Boyer666a4532015-12-09 12:29:35 -08004145 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004146 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004147 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004148 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004149
4150 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004151 }
4152
Imre Deake1296492016-02-12 18:55:17 +02004153 ret = 0;
4154
4155out:
4156 intel_display_power_put(dev_priv, power_domain);
4157
4158 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004159}
4160
4161/*
4162 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004163 * command: wsp* object wsp+ name wsp+ source wsp*
4164 * object: 'pipe'
4165 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004166 * source: (none | plane1 | plane2 | pf)
4167 * wsp: (#0x20 | #0x9 | #0xA)+
4168 *
4169 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004170 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4171 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004172 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004173static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004174{
4175 int n_words = 0;
4176
4177 while (*buf) {
4178 char *end;
4179
4180 /* skip leading white space */
4181 buf = skip_spaces(buf);
4182 if (!*buf)
4183 break; /* end of buffer */
4184
4185 /* find end of word */
4186 for (end = buf; *end && !isspace(*end); end++)
4187 ;
4188
4189 if (n_words == max_words) {
4190 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4191 max_words);
4192 return -EINVAL; /* ran out of words[] before bytes */
4193 }
4194
4195 if (*end)
4196 *end++ = '\0';
4197 words[n_words++] = buf;
4198 buf = end;
4199 }
4200
4201 return n_words;
4202}
4203
Damien Lespiaub94dec82013-10-15 18:55:35 +01004204enum intel_pipe_crc_object {
4205 PIPE_CRC_OBJECT_PIPE,
4206};
4207
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004208static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004209 "pipe",
4210};
4211
4212static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004213display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004214{
4215 int i;
4216
4217 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4218 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004219 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004220 return 0;
4221 }
4222
4223 return -EINVAL;
4224}
4225
Damien Lespiaubd9db022013-10-15 18:55:36 +01004226static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004227{
4228 const char name = buf[0];
4229
4230 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4231 return -EINVAL;
4232
4233 *pipe = name - 'A';
4234
4235 return 0;
4236}
4237
4238static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004239display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004240{
4241 int i;
4242
4243 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4244 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004245 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004246 return 0;
4247 }
4248
4249 return -EINVAL;
4250}
4251
Damien Lespiaubd9db022013-10-15 18:55:36 +01004252static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004253{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004254#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004255 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004256 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004257 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004258 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004259 enum intel_pipe_crc_source source;
4260
Damien Lespiaubd9db022013-10-15 18:55:36 +01004261 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004262 if (n_words != N_WORDS) {
4263 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4264 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004265 return -EINVAL;
4266 }
4267
Damien Lespiaubd9db022013-10-15 18:55:36 +01004268 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004269 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004270 return -EINVAL;
4271 }
4272
Damien Lespiaubd9db022013-10-15 18:55:36 +01004273 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004274 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4275 return -EINVAL;
4276 }
4277
Damien Lespiaubd9db022013-10-15 18:55:36 +01004278 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004279 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004280 return -EINVAL;
4281 }
4282
4283 return pipe_crc_set_source(dev, pipe, source);
4284}
4285
Damien Lespiaubd9db022013-10-15 18:55:36 +01004286static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4287 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004288{
4289 struct seq_file *m = file->private_data;
4290 struct drm_device *dev = m->private;
4291 char *tmpbuf;
4292 int ret;
4293
4294 if (len == 0)
4295 return 0;
4296
4297 if (len > PAGE_SIZE - 1) {
4298 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4299 PAGE_SIZE);
4300 return -E2BIG;
4301 }
4302
4303 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4304 if (!tmpbuf)
4305 return -ENOMEM;
4306
4307 if (copy_from_user(tmpbuf, ubuf, len)) {
4308 ret = -EFAULT;
4309 goto out;
4310 }
4311 tmpbuf[len] = '\0';
4312
Damien Lespiaubd9db022013-10-15 18:55:36 +01004313 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004314
4315out:
4316 kfree(tmpbuf);
4317 if (ret < 0)
4318 return ret;
4319
4320 *offp += len;
4321 return len;
4322}
4323
Damien Lespiaubd9db022013-10-15 18:55:36 +01004324static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004325 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004326 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004327 .read = seq_read,
4328 .llseek = seq_lseek,
4329 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004330 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004331};
4332
Todd Previteeb3394fa2015-04-18 00:04:19 -07004333static ssize_t i915_displayport_test_active_write(struct file *file,
4334 const char __user *ubuf,
4335 size_t len, loff_t *offp)
4336{
4337 char *input_buffer;
4338 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004339 struct drm_device *dev;
4340 struct drm_connector *connector;
4341 struct list_head *connector_list;
4342 struct intel_dp *intel_dp;
4343 int val = 0;
4344
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304345 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004346
Todd Previteeb3394fa2015-04-18 00:04:19 -07004347 connector_list = &dev->mode_config.connector_list;
4348
4349 if (len == 0)
4350 return 0;
4351
4352 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4353 if (!input_buffer)
4354 return -ENOMEM;
4355
4356 if (copy_from_user(input_buffer, ubuf, len)) {
4357 status = -EFAULT;
4358 goto out;
4359 }
4360
4361 input_buffer[len] = '\0';
4362 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4363
4364 list_for_each_entry(connector, connector_list, head) {
4365
4366 if (connector->connector_type !=
4367 DRM_MODE_CONNECTOR_DisplayPort)
4368 continue;
4369
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304370 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004371 connector->encoder != NULL) {
4372 intel_dp = enc_to_intel_dp(connector->encoder);
4373 status = kstrtoint(input_buffer, 10, &val);
4374 if (status < 0)
4375 goto out;
4376 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4377 /* To prevent erroneous activation of the compliance
4378 * testing code, only accept an actual value of 1 here
4379 */
4380 if (val == 1)
4381 intel_dp->compliance_test_active = 1;
4382 else
4383 intel_dp->compliance_test_active = 0;
4384 }
4385 }
4386out:
4387 kfree(input_buffer);
4388 if (status < 0)
4389 return status;
4390
4391 *offp += len;
4392 return len;
4393}
4394
4395static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4396{
4397 struct drm_device *dev = m->private;
4398 struct drm_connector *connector;
4399 struct list_head *connector_list = &dev->mode_config.connector_list;
4400 struct intel_dp *intel_dp;
4401
Todd Previteeb3394fa2015-04-18 00:04:19 -07004402 list_for_each_entry(connector, connector_list, head) {
4403
4404 if (connector->connector_type !=
4405 DRM_MODE_CONNECTOR_DisplayPort)
4406 continue;
4407
4408 if (connector->status == connector_status_connected &&
4409 connector->encoder != NULL) {
4410 intel_dp = enc_to_intel_dp(connector->encoder);
4411 if (intel_dp->compliance_test_active)
4412 seq_puts(m, "1");
4413 else
4414 seq_puts(m, "0");
4415 } else
4416 seq_puts(m, "0");
4417 }
4418
4419 return 0;
4420}
4421
4422static int i915_displayport_test_active_open(struct inode *inode,
4423 struct file *file)
4424{
4425 struct drm_device *dev = inode->i_private;
4426
4427 return single_open(file, i915_displayport_test_active_show, dev);
4428}
4429
4430static const struct file_operations i915_displayport_test_active_fops = {
4431 .owner = THIS_MODULE,
4432 .open = i915_displayport_test_active_open,
4433 .read = seq_read,
4434 .llseek = seq_lseek,
4435 .release = single_release,
4436 .write = i915_displayport_test_active_write
4437};
4438
4439static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4440{
4441 struct drm_device *dev = m->private;
4442 struct drm_connector *connector;
4443 struct list_head *connector_list = &dev->mode_config.connector_list;
4444 struct intel_dp *intel_dp;
4445
Todd Previteeb3394fa2015-04-18 00:04:19 -07004446 list_for_each_entry(connector, connector_list, head) {
4447
4448 if (connector->connector_type !=
4449 DRM_MODE_CONNECTOR_DisplayPort)
4450 continue;
4451
4452 if (connector->status == connector_status_connected &&
4453 connector->encoder != NULL) {
4454 intel_dp = enc_to_intel_dp(connector->encoder);
4455 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4456 } else
4457 seq_puts(m, "0");
4458 }
4459
4460 return 0;
4461}
4462static int i915_displayport_test_data_open(struct inode *inode,
4463 struct file *file)
4464{
4465 struct drm_device *dev = inode->i_private;
4466
4467 return single_open(file, i915_displayport_test_data_show, dev);
4468}
4469
4470static const struct file_operations i915_displayport_test_data_fops = {
4471 .owner = THIS_MODULE,
4472 .open = i915_displayport_test_data_open,
4473 .read = seq_read,
4474 .llseek = seq_lseek,
4475 .release = single_release
4476};
4477
4478static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4479{
4480 struct drm_device *dev = m->private;
4481 struct drm_connector *connector;
4482 struct list_head *connector_list = &dev->mode_config.connector_list;
4483 struct intel_dp *intel_dp;
4484
Todd Previteeb3394fa2015-04-18 00:04:19 -07004485 list_for_each_entry(connector, connector_list, head) {
4486
4487 if (connector->connector_type !=
4488 DRM_MODE_CONNECTOR_DisplayPort)
4489 continue;
4490
4491 if (connector->status == connector_status_connected &&
4492 connector->encoder != NULL) {
4493 intel_dp = enc_to_intel_dp(connector->encoder);
4494 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4495 } else
4496 seq_puts(m, "0");
4497 }
4498
4499 return 0;
4500}
4501
4502static int i915_displayport_test_type_open(struct inode *inode,
4503 struct file *file)
4504{
4505 struct drm_device *dev = inode->i_private;
4506
4507 return single_open(file, i915_displayport_test_type_show, dev);
4508}
4509
4510static const struct file_operations i915_displayport_test_type_fops = {
4511 .owner = THIS_MODULE,
4512 .open = i915_displayport_test_type_open,
4513 .read = seq_read,
4514 .llseek = seq_lseek,
4515 .release = single_release
4516};
4517
Damien Lespiau97e94b22014-11-04 17:06:50 +00004518static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004519{
4520 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004521 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004522 int num_levels;
4523
4524 if (IS_CHERRYVIEW(dev))
4525 num_levels = 3;
4526 else if (IS_VALLEYVIEW(dev))
4527 num_levels = 1;
4528 else
4529 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004530
4531 drm_modeset_lock_all(dev);
4532
4533 for (level = 0; level < num_levels; level++) {
4534 unsigned int latency = wm[level];
4535
Damien Lespiau97e94b22014-11-04 17:06:50 +00004536 /*
4537 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004538 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004539 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004540 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev) ||
4541 IS_CHERRYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004542 latency *= 10;
4543 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004544 latency *= 5;
4545
4546 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004547 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004548 }
4549
4550 drm_modeset_unlock_all(dev);
4551}
4552
4553static int pri_wm_latency_show(struct seq_file *m, void *data)
4554{
4555 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004556 struct drm_i915_private *dev_priv = dev->dev_private;
4557 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004558
Damien Lespiau97e94b22014-11-04 17:06:50 +00004559 if (INTEL_INFO(dev)->gen >= 9)
4560 latencies = dev_priv->wm.skl_latency;
4561 else
4562 latencies = to_i915(dev)->wm.pri_latency;
4563
4564 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004565
4566 return 0;
4567}
4568
4569static int spr_wm_latency_show(struct seq_file *m, void *data)
4570{
4571 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004572 struct drm_i915_private *dev_priv = dev->dev_private;
4573 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004574
Damien Lespiau97e94b22014-11-04 17:06:50 +00004575 if (INTEL_INFO(dev)->gen >= 9)
4576 latencies = dev_priv->wm.skl_latency;
4577 else
4578 latencies = to_i915(dev)->wm.spr_latency;
4579
4580 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004581
4582 return 0;
4583}
4584
4585static int cur_wm_latency_show(struct seq_file *m, void *data)
4586{
4587 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004588 struct drm_i915_private *dev_priv = dev->dev_private;
4589 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004590
Damien Lespiau97e94b22014-11-04 17:06:50 +00004591 if (INTEL_INFO(dev)->gen >= 9)
4592 latencies = dev_priv->wm.skl_latency;
4593 else
4594 latencies = to_i915(dev)->wm.cur_latency;
4595
4596 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004597
4598 return 0;
4599}
4600
4601static int pri_wm_latency_open(struct inode *inode, struct file *file)
4602{
4603 struct drm_device *dev = inode->i_private;
4604
Ville Syrjäläde38b952015-06-24 22:00:09 +03004605 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004606 return -ENODEV;
4607
4608 return single_open(file, pri_wm_latency_show, dev);
4609}
4610
4611static int spr_wm_latency_open(struct inode *inode, struct file *file)
4612{
4613 struct drm_device *dev = inode->i_private;
4614
Sonika Jindal9ad02572014-07-21 15:23:39 +05304615 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004616 return -ENODEV;
4617
4618 return single_open(file, spr_wm_latency_show, dev);
4619}
4620
4621static int cur_wm_latency_open(struct inode *inode, struct file *file)
4622{
4623 struct drm_device *dev = inode->i_private;
4624
Sonika Jindal9ad02572014-07-21 15:23:39 +05304625 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004626 return -ENODEV;
4627
4628 return single_open(file, cur_wm_latency_show, dev);
4629}
4630
4631static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004632 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004633{
4634 struct seq_file *m = file->private_data;
4635 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004636 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004637 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004638 int level;
4639 int ret;
4640 char tmp[32];
4641
Ville Syrjäläde38b952015-06-24 22:00:09 +03004642 if (IS_CHERRYVIEW(dev))
4643 num_levels = 3;
4644 else if (IS_VALLEYVIEW(dev))
4645 num_levels = 1;
4646 else
4647 num_levels = ilk_wm_max_level(dev) + 1;
4648
Ville Syrjälä369a1342014-01-22 14:36:08 +02004649 if (len >= sizeof(tmp))
4650 return -EINVAL;
4651
4652 if (copy_from_user(tmp, ubuf, len))
4653 return -EFAULT;
4654
4655 tmp[len] = '\0';
4656
Damien Lespiau97e94b22014-11-04 17:06:50 +00004657 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4658 &new[0], &new[1], &new[2], &new[3],
4659 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004660 if (ret != num_levels)
4661 return -EINVAL;
4662
4663 drm_modeset_lock_all(dev);
4664
4665 for (level = 0; level < num_levels; level++)
4666 wm[level] = new[level];
4667
4668 drm_modeset_unlock_all(dev);
4669
4670 return len;
4671}
4672
4673
4674static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4675 size_t len, loff_t *offp)
4676{
4677 struct seq_file *m = file->private_data;
4678 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004679 struct drm_i915_private *dev_priv = dev->dev_private;
4680 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004681
Damien Lespiau97e94b22014-11-04 17:06:50 +00004682 if (INTEL_INFO(dev)->gen >= 9)
4683 latencies = dev_priv->wm.skl_latency;
4684 else
4685 latencies = to_i915(dev)->wm.pri_latency;
4686
4687 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004688}
4689
4690static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4691 size_t len, loff_t *offp)
4692{
4693 struct seq_file *m = file->private_data;
4694 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004695 struct drm_i915_private *dev_priv = dev->dev_private;
4696 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004697
Damien Lespiau97e94b22014-11-04 17:06:50 +00004698 if (INTEL_INFO(dev)->gen >= 9)
4699 latencies = dev_priv->wm.skl_latency;
4700 else
4701 latencies = to_i915(dev)->wm.spr_latency;
4702
4703 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004704}
4705
4706static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4707 size_t len, loff_t *offp)
4708{
4709 struct seq_file *m = file->private_data;
4710 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004711 struct drm_i915_private *dev_priv = dev->dev_private;
4712 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004713
Damien Lespiau97e94b22014-11-04 17:06:50 +00004714 if (INTEL_INFO(dev)->gen >= 9)
4715 latencies = dev_priv->wm.skl_latency;
4716 else
4717 latencies = to_i915(dev)->wm.cur_latency;
4718
4719 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004720}
4721
4722static const struct file_operations i915_pri_wm_latency_fops = {
4723 .owner = THIS_MODULE,
4724 .open = pri_wm_latency_open,
4725 .read = seq_read,
4726 .llseek = seq_lseek,
4727 .release = single_release,
4728 .write = pri_wm_latency_write
4729};
4730
4731static const struct file_operations i915_spr_wm_latency_fops = {
4732 .owner = THIS_MODULE,
4733 .open = spr_wm_latency_open,
4734 .read = seq_read,
4735 .llseek = seq_lseek,
4736 .release = single_release,
4737 .write = spr_wm_latency_write
4738};
4739
4740static const struct file_operations i915_cur_wm_latency_fops = {
4741 .owner = THIS_MODULE,
4742 .open = cur_wm_latency_open,
4743 .read = seq_read,
4744 .llseek = seq_lseek,
4745 .release = single_release,
4746 .write = cur_wm_latency_write
4747};
4748
Kees Cook647416f2013-03-10 14:10:06 -07004749static int
4750i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004751{
Kees Cook647416f2013-03-10 14:10:06 -07004752 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004753 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004754
Chris Wilsond98c52c2016-04-13 17:35:05 +01004755 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004756
Kees Cook647416f2013-03-10 14:10:06 -07004757 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004758}
4759
Kees Cook647416f2013-03-10 14:10:06 -07004760static int
4761i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004762{
Kees Cook647416f2013-03-10 14:10:06 -07004763 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004764 struct drm_i915_private *dev_priv = dev->dev_private;
4765
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004766 /*
4767 * There is no safeguard against this debugfs entry colliding
4768 * with the hangcheck calling same i915_handle_error() in
4769 * parallel, causing an explosion. For now we assume that the
4770 * test harness is responsible enough not to inject gpu hangs
4771 * while it is writing to 'i915_wedged'
4772 */
4773
Chris Wilsond98c52c2016-04-13 17:35:05 +01004774 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004775 return -EAGAIN;
4776
Imre Deakd46c0512014-04-14 20:24:27 +03004777 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004778
Chris Wilsonc0336662016-05-06 15:40:21 +01004779 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004780 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004781
4782 intel_runtime_pm_put(dev_priv);
4783
Kees Cook647416f2013-03-10 14:10:06 -07004784 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004785}
4786
Kees Cook647416f2013-03-10 14:10:06 -07004787DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4788 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004789 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004790
Kees Cook647416f2013-03-10 14:10:06 -07004791static int
4792i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004793{
Kees Cook647416f2013-03-10 14:10:06 -07004794 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004795 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004796
Kees Cook647416f2013-03-10 14:10:06 -07004797 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004798
Kees Cook647416f2013-03-10 14:10:06 -07004799 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004800}
4801
Kees Cook647416f2013-03-10 14:10:06 -07004802static int
4803i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004804{
Kees Cook647416f2013-03-10 14:10:06 -07004805 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004806 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004807 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004808
Kees Cook647416f2013-03-10 14:10:06 -07004809 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004810
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004811 ret = mutex_lock_interruptible(&dev->struct_mutex);
4812 if (ret)
4813 return ret;
4814
Daniel Vetter99584db2012-11-14 17:14:04 +01004815 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004816 mutex_unlock(&dev->struct_mutex);
4817
Kees Cook647416f2013-03-10 14:10:06 -07004818 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004819}
4820
Kees Cook647416f2013-03-10 14:10:06 -07004821DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4822 i915_ring_stop_get, i915_ring_stop_set,
4823 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004824
Chris Wilson094f9a52013-09-25 17:34:55 +01004825static int
4826i915_ring_missed_irq_get(void *data, u64 *val)
4827{
4828 struct drm_device *dev = data;
4829 struct drm_i915_private *dev_priv = dev->dev_private;
4830
4831 *val = dev_priv->gpu_error.missed_irq_rings;
4832 return 0;
4833}
4834
4835static int
4836i915_ring_missed_irq_set(void *data, u64 val)
4837{
4838 struct drm_device *dev = data;
4839 struct drm_i915_private *dev_priv = dev->dev_private;
4840 int ret;
4841
4842 /* Lock against concurrent debugfs callers */
4843 ret = mutex_lock_interruptible(&dev->struct_mutex);
4844 if (ret)
4845 return ret;
4846 dev_priv->gpu_error.missed_irq_rings = val;
4847 mutex_unlock(&dev->struct_mutex);
4848
4849 return 0;
4850}
4851
4852DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4853 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4854 "0x%08llx\n");
4855
4856static int
4857i915_ring_test_irq_get(void *data, u64 *val)
4858{
4859 struct drm_device *dev = data;
4860 struct drm_i915_private *dev_priv = dev->dev_private;
4861
4862 *val = dev_priv->gpu_error.test_irq_rings;
4863
4864 return 0;
4865}
4866
4867static int
4868i915_ring_test_irq_set(void *data, u64 val)
4869{
4870 struct drm_device *dev = data;
4871 struct drm_i915_private *dev_priv = dev->dev_private;
4872 int ret;
4873
4874 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4875
4876 /* Lock against concurrent debugfs callers */
4877 ret = mutex_lock_interruptible(&dev->struct_mutex);
4878 if (ret)
4879 return ret;
4880
4881 dev_priv->gpu_error.test_irq_rings = val;
4882 mutex_unlock(&dev->struct_mutex);
4883
4884 return 0;
4885}
4886
4887DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4888 i915_ring_test_irq_get, i915_ring_test_irq_set,
4889 "0x%08llx\n");
4890
Chris Wilsondd624af2013-01-15 12:39:35 +00004891#define DROP_UNBOUND 0x1
4892#define DROP_BOUND 0x2
4893#define DROP_RETIRE 0x4
4894#define DROP_ACTIVE 0x8
4895#define DROP_ALL (DROP_UNBOUND | \
4896 DROP_BOUND | \
4897 DROP_RETIRE | \
4898 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004899static int
4900i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004901{
Kees Cook647416f2013-03-10 14:10:06 -07004902 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004903
Kees Cook647416f2013-03-10 14:10:06 -07004904 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004905}
4906
Kees Cook647416f2013-03-10 14:10:06 -07004907static int
4908i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004909{
Kees Cook647416f2013-03-10 14:10:06 -07004910 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004911 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004912 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004913
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004914 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004915
4916 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4917 * on ioctls on -EAGAIN. */
4918 ret = mutex_lock_interruptible(&dev->struct_mutex);
4919 if (ret)
4920 return ret;
4921
4922 if (val & DROP_ACTIVE) {
4923 ret = i915_gpu_idle(dev);
4924 if (ret)
4925 goto unlock;
4926 }
4927
4928 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004929 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004930
Chris Wilson21ab4e72014-09-09 11:16:08 +01004931 if (val & DROP_BOUND)
4932 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004933
Chris Wilson21ab4e72014-09-09 11:16:08 +01004934 if (val & DROP_UNBOUND)
4935 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004936
4937unlock:
4938 mutex_unlock(&dev->struct_mutex);
4939
Kees Cook647416f2013-03-10 14:10:06 -07004940 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004941}
4942
Kees Cook647416f2013-03-10 14:10:06 -07004943DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4944 i915_drop_caches_get, i915_drop_caches_set,
4945 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004946
Kees Cook647416f2013-03-10 14:10:06 -07004947static int
4948i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004949{
Kees Cook647416f2013-03-10 14:10:06 -07004950 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004951 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004952 int ret;
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
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004957 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4958
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004959 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004960 if (ret)
4961 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004962
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004963 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004964 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004965
Kees Cook647416f2013-03-10 14:10:06 -07004966 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004967}
4968
Kees Cook647416f2013-03-10 14:10:06 -07004969static int
4970i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004971{
Kees Cook647416f2013-03-10 14:10:06 -07004972 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004973 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304974 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004975 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004976
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004977 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004978 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004979
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004980 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4981
Kees Cook647416f2013-03-10 14:10:06 -07004982 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004983
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004984 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004985 if (ret)
4986 return ret;
4987
Jesse Barnes358733e2011-07-27 11:53:01 -07004988 /*
4989 * Turbo will still be enabled, but won't go above the set value.
4990 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304991 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004992
Akash Goelbc4d91f2015-02-26 16:09:47 +05304993 hw_max = dev_priv->rps.max_freq;
4994 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004995
Ben Widawskyb39fb292014-03-19 18:31:11 -07004996 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004997 mutex_unlock(&dev_priv->rps.hw_lock);
4998 return -EINVAL;
4999 }
5000
Ben Widawskyb39fb292014-03-19 18:31:11 -07005001 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005002
Chris Wilsondc979972016-05-10 14:10:04 +01005003 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005004
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005005 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005006
Kees Cook647416f2013-03-10 14:10:06 -07005007 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005008}
5009
Kees Cook647416f2013-03-10 14:10:06 -07005010DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5011 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005012 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005013
Kees Cook647416f2013-03-10 14:10:06 -07005014static int
5015i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005016{
Kees Cook647416f2013-03-10 14:10:06 -07005017 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03005018 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07005019 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005020
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005021 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005022 return -ENODEV;
5023
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005024 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5025
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005026 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005027 if (ret)
5028 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07005029
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005030 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005031 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005032
Kees Cook647416f2013-03-10 14:10:06 -07005033 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005034}
5035
Kees Cook647416f2013-03-10 14:10:06 -07005036static int
5037i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005038{
Kees Cook647416f2013-03-10 14:10:06 -07005039 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07005040 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305041 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005042 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005043
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005044 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005045 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005046
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005047 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5048
Kees Cook647416f2013-03-10 14:10:06 -07005049 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005050
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005051 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005052 if (ret)
5053 return ret;
5054
Jesse Barnes1523c312012-05-25 12:34:54 -07005055 /*
5056 * Turbo will still be enabled, but won't go below the set value.
5057 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305058 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005059
Akash Goelbc4d91f2015-02-26 16:09:47 +05305060 hw_max = dev_priv->rps.max_freq;
5061 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005062
Ben Widawskyb39fb292014-03-19 18:31:11 -07005063 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005064 mutex_unlock(&dev_priv->rps.hw_lock);
5065 return -EINVAL;
5066 }
5067
Ben Widawskyb39fb292014-03-19 18:31:11 -07005068 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005069
Chris Wilsondc979972016-05-10 14:10:04 +01005070 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005071
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005072 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005073
Kees Cook647416f2013-03-10 14:10:06 -07005074 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005075}
5076
Kees Cook647416f2013-03-10 14:10:06 -07005077DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5078 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005079 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005080
Kees Cook647416f2013-03-10 14:10:06 -07005081static int
5082i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005083{
Kees Cook647416f2013-03-10 14:10:06 -07005084 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03005085 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005086 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005087 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005088
Daniel Vetter004777c2012-08-09 15:07:01 +02005089 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5090 return -ENODEV;
5091
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005092 ret = mutex_lock_interruptible(&dev->struct_mutex);
5093 if (ret)
5094 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005095 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005096
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005097 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005098
5099 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005100 mutex_unlock(&dev_priv->dev->struct_mutex);
5101
Kees Cook647416f2013-03-10 14:10:06 -07005102 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005103
Kees Cook647416f2013-03-10 14:10:06 -07005104 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005105}
5106
Kees Cook647416f2013-03-10 14:10:06 -07005107static int
5108i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005109{
Kees Cook647416f2013-03-10 14:10:06 -07005110 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005111 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005112 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005113
Daniel Vetter004777c2012-08-09 15:07:01 +02005114 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5115 return -ENODEV;
5116
Kees Cook647416f2013-03-10 14:10:06 -07005117 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005118 return -EINVAL;
5119
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005120 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005121 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005122
5123 /* Update the cache sharing policy here as well */
5124 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5125 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5126 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5127 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5128
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005129 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005130 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005131}
5132
Kees Cook647416f2013-03-10 14:10:06 -07005133DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5134 i915_cache_sharing_get, i915_cache_sharing_set,
5135 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005136
Jeff McGee5d395252015-04-03 18:13:17 -07005137struct sseu_dev_status {
5138 unsigned int slice_total;
5139 unsigned int subslice_total;
5140 unsigned int subslice_per_slice;
5141 unsigned int eu_total;
5142 unsigned int eu_per_subslice;
5143};
5144
5145static void cherryview_sseu_device_status(struct drm_device *dev,
5146 struct sseu_dev_status *stat)
5147{
5148 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005149 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005150 int ss;
5151 u32 sig1[ss_max], sig2[ss_max];
5152
5153 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5154 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5155 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5156 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5157
5158 for (ss = 0; ss < ss_max; ss++) {
5159 unsigned int eu_cnt;
5160
5161 if (sig1[ss] & CHV_SS_PG_ENABLE)
5162 /* skip disabled subslice */
5163 continue;
5164
5165 stat->slice_total = 1;
5166 stat->subslice_per_slice++;
5167 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5168 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5169 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5170 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
5171 stat->eu_total += eu_cnt;
5172 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
5173 }
5174 stat->subslice_total = stat->subslice_per_slice;
5175}
5176
5177static void gen9_sseu_device_status(struct drm_device *dev,
5178 struct sseu_dev_status *stat)
5179{
5180 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005181 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005182 int s, ss;
5183 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5184
Jeff McGee1c046bc2015-04-03 18:13:18 -07005185 /* BXT has a single slice and at most 3 subslices. */
5186 if (IS_BROXTON(dev)) {
5187 s_max = 1;
5188 ss_max = 3;
5189 }
5190
5191 for (s = 0; s < s_max; s++) {
5192 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5193 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5194 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5195 }
5196
Jeff McGee5d395252015-04-03 18:13:17 -07005197 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5198 GEN9_PGCTL_SSA_EU19_ACK |
5199 GEN9_PGCTL_SSA_EU210_ACK |
5200 GEN9_PGCTL_SSA_EU311_ACK;
5201 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5202 GEN9_PGCTL_SSB_EU19_ACK |
5203 GEN9_PGCTL_SSB_EU210_ACK |
5204 GEN9_PGCTL_SSB_EU311_ACK;
5205
5206 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005207 unsigned int ss_cnt = 0;
5208
Jeff McGee5d395252015-04-03 18:13:17 -07005209 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5210 /* skip disabled slice */
5211 continue;
5212
5213 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005214
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07005215 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Jeff McGee1c046bc2015-04-03 18:13:18 -07005216 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5217
Jeff McGee5d395252015-04-03 18:13:17 -07005218 for (ss = 0; ss < ss_max; ss++) {
5219 unsigned int eu_cnt;
5220
Jeff McGee1c046bc2015-04-03 18:13:18 -07005221 if (IS_BROXTON(dev) &&
5222 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5223 /* skip disabled subslice */
5224 continue;
5225
5226 if (IS_BROXTON(dev))
5227 ss_cnt++;
5228
Jeff McGee5d395252015-04-03 18:13:17 -07005229 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5230 eu_mask[ss%2]);
5231 stat->eu_total += eu_cnt;
5232 stat->eu_per_subslice = max(stat->eu_per_subslice,
5233 eu_cnt);
5234 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005235
5236 stat->subslice_total += ss_cnt;
5237 stat->subslice_per_slice = max(stat->subslice_per_slice,
5238 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005239 }
5240}
5241
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005242static void broadwell_sseu_device_status(struct drm_device *dev,
5243 struct sseu_dev_status *stat)
5244{
5245 struct drm_i915_private *dev_priv = dev->dev_private;
5246 int s;
5247 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
5248
5249 stat->slice_total = hweight32(slice_info & GEN8_LSLICESTAT_MASK);
5250
5251 if (stat->slice_total) {
5252 stat->subslice_per_slice = INTEL_INFO(dev)->subslice_per_slice;
5253 stat->subslice_total = stat->slice_total *
5254 stat->subslice_per_slice;
5255 stat->eu_per_subslice = INTEL_INFO(dev)->eu_per_subslice;
5256 stat->eu_total = stat->eu_per_subslice * stat->subslice_total;
5257
5258 /* subtract fused off EU(s) from enabled slice(s) */
5259 for (s = 0; s < stat->slice_total; s++) {
5260 u8 subslice_7eu = INTEL_INFO(dev)->subslice_7eu[s];
5261
5262 stat->eu_total -= hweight8(subslice_7eu);
5263 }
5264 }
5265}
5266
Jeff McGee38732182015-02-13 10:27:54 -06005267static int i915_sseu_status(struct seq_file *m, void *unused)
5268{
5269 struct drm_info_node *node = (struct drm_info_node *) m->private;
5270 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07005271 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005272
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005273 if (INTEL_INFO(dev)->gen < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005274 return -ENODEV;
5275
5276 seq_puts(m, "SSEU Device Info\n");
5277 seq_printf(m, " Available Slice Total: %u\n",
5278 INTEL_INFO(dev)->slice_total);
5279 seq_printf(m, " Available Subslice Total: %u\n",
5280 INTEL_INFO(dev)->subslice_total);
5281 seq_printf(m, " Available Subslice Per Slice: %u\n",
5282 INTEL_INFO(dev)->subslice_per_slice);
5283 seq_printf(m, " Available EU Total: %u\n",
5284 INTEL_INFO(dev)->eu_total);
5285 seq_printf(m, " Available EU Per Subslice: %u\n",
5286 INTEL_INFO(dev)->eu_per_subslice);
5287 seq_printf(m, " Has Slice Power Gating: %s\n",
5288 yesno(INTEL_INFO(dev)->has_slice_pg));
5289 seq_printf(m, " Has Subslice Power Gating: %s\n",
5290 yesno(INTEL_INFO(dev)->has_subslice_pg));
5291 seq_printf(m, " Has EU Power Gating: %s\n",
5292 yesno(INTEL_INFO(dev)->has_eu_pg));
5293
Jeff McGee7f992ab2015-02-13 10:27:55 -06005294 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005295 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08005296 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005297 cherryview_sseu_device_status(dev, &stat);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005298 } else if (IS_BROADWELL(dev)) {
5299 broadwell_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005300 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005301 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005302 }
Jeff McGee5d395252015-04-03 18:13:17 -07005303 seq_printf(m, " Enabled Slice Total: %u\n",
5304 stat.slice_total);
5305 seq_printf(m, " Enabled Subslice Total: %u\n",
5306 stat.subslice_total);
5307 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5308 stat.subslice_per_slice);
5309 seq_printf(m, " Enabled EU Total: %u\n",
5310 stat.eu_total);
5311 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5312 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005313
Jeff McGee38732182015-02-13 10:27:54 -06005314 return 0;
5315}
5316
Ben Widawsky6d794d42011-04-25 11:25:56 -07005317static int i915_forcewake_open(struct inode *inode, struct file *file)
5318{
5319 struct drm_device *dev = inode->i_private;
5320 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005321
Daniel Vetter075edca2012-01-24 09:44:28 +01005322 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005323 return 0;
5324
Chris Wilson6daccb02015-01-16 11:34:35 +02005325 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005326 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005327
5328 return 0;
5329}
5330
Ben Widawskyc43b5632012-04-16 14:07:40 -07005331static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005332{
5333 struct drm_device *dev = inode->i_private;
5334 struct drm_i915_private *dev_priv = dev->dev_private;
5335
Daniel Vetter075edca2012-01-24 09:44:28 +01005336 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005337 return 0;
5338
Mika Kuoppala59bad942015-01-16 11:34:40 +02005339 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005340 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005341
5342 return 0;
5343}
5344
5345static const struct file_operations i915_forcewake_fops = {
5346 .owner = THIS_MODULE,
5347 .open = i915_forcewake_open,
5348 .release = i915_forcewake_release,
5349};
5350
5351static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5352{
5353 struct drm_device *dev = minor->dev;
5354 struct dentry *ent;
5355
5356 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005357 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005358 root, dev,
5359 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005360 if (!ent)
5361 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005362
Ben Widawsky8eb57292011-05-11 15:10:58 -07005363 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005364}
5365
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005366static int i915_debugfs_create(struct dentry *root,
5367 struct drm_minor *minor,
5368 const char *name,
5369 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005370{
5371 struct drm_device *dev = minor->dev;
5372 struct dentry *ent;
5373
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005374 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005375 S_IRUGO | S_IWUSR,
5376 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005377 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005378 if (!ent)
5379 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005380
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005381 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005382}
5383
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005384static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005385 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005386 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005387 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005388 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005389 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005390 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005391 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005392 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005393 {"i915_gem_request", i915_gem_request_info, 0},
5394 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005395 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005396 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005397 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5398 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5399 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005400 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005401 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005402 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005403 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005404 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305405 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005406 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005407 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005408 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005409 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005410 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005411 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005412 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005413 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005414 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005415 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005416 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005417 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005418 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005419 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005420 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005421 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005422 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005423 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005424 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005425 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005426 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005427 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005428 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005429 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005430 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005431 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005432 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005433 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005434 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005435 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005436 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305437 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005438 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005439};
Ben Gamari27c202a2009-07-01 22:26:52 -04005440#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005441
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005442static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005443 const char *name;
5444 const struct file_operations *fops;
5445} i915_debugfs_files[] = {
5446 {"i915_wedged", &i915_wedged_fops},
5447 {"i915_max_freq", &i915_max_freq_fops},
5448 {"i915_min_freq", &i915_min_freq_fops},
5449 {"i915_cache_sharing", &i915_cache_sharing_fops},
5450 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005451 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5452 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005453 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5454 {"i915_error_state", &i915_error_state_fops},
5455 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005456 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005457 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5458 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5459 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005460 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005461 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5462 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5463 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005464};
5465
Damien Lespiau07144422013-10-15 18:55:40 +01005466void intel_display_crc_init(struct drm_device *dev)
5467{
5468 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005469 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005470
Damien Lespiau055e3932014-08-18 13:49:10 +01005471 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005472 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005473
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005474 pipe_crc->opened = false;
5475 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005476 init_waitqueue_head(&pipe_crc->wq);
5477 }
5478}
5479
Ben Gamari27c202a2009-07-01 22:26:52 -04005480int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005481{
Daniel Vetter34b96742013-07-04 20:49:44 +02005482 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005483
Ben Widawsky6d794d42011-04-25 11:25:56 -07005484 ret = i915_forcewake_create(minor->debugfs_root, minor);
5485 if (ret)
5486 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005487
Damien Lespiau07144422013-10-15 18:55:40 +01005488 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5489 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5490 if (ret)
5491 return ret;
5492 }
5493
Daniel Vetter34b96742013-07-04 20:49:44 +02005494 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5495 ret = i915_debugfs_create(minor->debugfs_root, minor,
5496 i915_debugfs_files[i].name,
5497 i915_debugfs_files[i].fops);
5498 if (ret)
5499 return ret;
5500 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005501
Ben Gamari27c202a2009-07-01 22:26:52 -04005502 return drm_debugfs_create_files(i915_debugfs_list,
5503 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005504 minor->debugfs_root, minor);
5505}
5506
Ben Gamari27c202a2009-07-01 22:26:52 -04005507void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005508{
Daniel Vetter34b96742013-07-04 20:49:44 +02005509 int i;
5510
Ben Gamari27c202a2009-07-01 22:26:52 -04005511 drm_debugfs_remove_files(i915_debugfs_list,
5512 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005513
Ben Widawsky6d794d42011-04-25 11:25:56 -07005514 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5515 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005516
Daniel Vettere309a992013-10-16 22:55:51 +02005517 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005518 struct drm_info_list *info_list =
5519 (struct drm_info_list *)&i915_pipe_crc_data[i];
5520
5521 drm_debugfs_remove_files(info_list, 1, minor);
5522 }
5523
Daniel Vetter34b96742013-07-04 20:49:44 +02005524 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5525 struct drm_info_list *info_list =
5526 (struct drm_info_list *) i915_debugfs_files[i].fops;
5527
5528 drm_debugfs_remove_files(info_list, 1, minor);
5529 }
Ben Gamari20172632009-02-17 20:08:50 -05005530}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005531
5532struct dpcd_block {
5533 /* DPCD dump start address. */
5534 unsigned int offset;
5535 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5536 unsigned int end;
5537 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5538 size_t size;
5539 /* Only valid for eDP. */
5540 bool edp;
5541};
5542
5543static const struct dpcd_block i915_dpcd_debug[] = {
5544 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5545 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5546 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5547 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5548 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5549 { .offset = DP_SET_POWER },
5550 { .offset = DP_EDP_DPCD_REV },
5551 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5552 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5553 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5554};
5555
5556static int i915_dpcd_show(struct seq_file *m, void *data)
5557{
5558 struct drm_connector *connector = m->private;
5559 struct intel_dp *intel_dp =
5560 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5561 uint8_t buf[16];
5562 ssize_t err;
5563 int i;
5564
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005565 if (connector->status != connector_status_connected)
5566 return -ENODEV;
5567
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005568 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5569 const struct dpcd_block *b = &i915_dpcd_debug[i];
5570 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5571
5572 if (b->edp &&
5573 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5574 continue;
5575
5576 /* low tech for now */
5577 if (WARN_ON(size > sizeof(buf)))
5578 continue;
5579
5580 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5581 if (err <= 0) {
5582 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5583 size, b->offset, err);
5584 continue;
5585 }
5586
5587 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005588 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005589
5590 return 0;
5591}
5592
5593static int i915_dpcd_open(struct inode *inode, struct file *file)
5594{
5595 return single_open(file, i915_dpcd_show, inode->i_private);
5596}
5597
5598static const struct file_operations i915_dpcd_fops = {
5599 .owner = THIS_MODULE,
5600 .open = i915_dpcd_open,
5601 .read = seq_read,
5602 .llseek = seq_lseek,
5603 .release = single_release,
5604};
5605
5606/**
5607 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5608 * @connector: pointer to a registered drm_connector
5609 *
5610 * Cleanup will be done by drm_connector_unregister() through a call to
5611 * drm_debugfs_connector_remove().
5612 *
5613 * Returns 0 on success, negative error codes on error.
5614 */
5615int i915_debugfs_connector_add(struct drm_connector *connector)
5616{
5617 struct dentry *root = connector->debugfs_entry;
5618
5619 /* The connector must have been registered beforehands. */
5620 if (!root)
5621 return -ENODEV;
5622
5623 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5624 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5625 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5626 &i915_dpcd_fops);
5627
5628 return 0;
5629}