blob: 58e2f48b4fd7bd1a3c9ede60927299bd6c1a5c4e [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
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010092static const 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
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010097static const char get_pin_flag(struct drm_i915_gem_object *obj)
98{
99 return obj->pin_display ? 'p' : ' ';
100}
101
102static const 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
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100112static inline const 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
117static inline const char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
118{
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);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100531 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
532 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900533 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100534
535 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000536 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100537 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100538 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100539 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900540 /*
541 * Although we have a valid reference on file->pid, that does
542 * not guarantee that the task_struct who called get_pid() is
543 * still alive (e.g. get_pid(current) => fork() => exit()).
544 * Therefore, we need to protect this ->comm access using RCU.
545 */
546 rcu_read_lock();
547 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800548 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900549 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100550 }
551
Chris Wilson73aa8082010-09-30 11:46:12 +0100552 mutex_unlock(&dev->struct_mutex);
553
554 return 0;
555}
556
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100557static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000558{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100559 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000560 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100561 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000562 struct drm_i915_private *dev_priv = dev->dev_private;
563 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300564 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000565 int count, ret;
566
567 ret = mutex_lock_interruptible(&dev->struct_mutex);
568 if (ret)
569 return ret;
570
571 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700572 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800573 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100574 continue;
575
Damien Lespiau267f0c92013-06-24 22:59:48 +0100576 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000577 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100578 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000579 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100580 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000581 count++;
582 }
583
584 mutex_unlock(&dev->struct_mutex);
585
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300586 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000587 count, total_obj_size, total_gtt_size);
588
589 return 0;
590}
591
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100592static int i915_gem_pageflip_info(struct seq_file *m, void *data)
593{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100594 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100595 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100596 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100597 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200598 int ret;
599
600 ret = mutex_lock_interruptible(&dev->struct_mutex);
601 if (ret)
602 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100603
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100604 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800605 const char pipe = pipe_name(crtc->pipe);
606 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100607 struct intel_unpin_work *work;
608
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200609 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100610 work = crtc->unpin_work;
611 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800612 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100613 pipe, plane);
614 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100615 u32 addr;
616
Chris Wilsone7d841c2012-12-03 11:36:30 +0000617 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800618 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100619 pipe, plane);
620 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800621 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100622 pipe, plane);
623 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100624 if (work->flip_queued_req) {
Tvrtko Ursulin666796d2016-03-16 11:00:39 +0000625 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100626
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200627 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000628 engine->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000629 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100630 dev_priv->next_seqno,
Chris Wilsonc04e0f32016-04-09 10:57:54 +0100631 engine->get_seqno(engine),
John Harrison1b5a4332014-11-24 18:49:42 +0000632 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100633 } else
634 seq_printf(m, "Flip not associated with any ring\n");
635 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
636 work->flip_queued_vblank,
637 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100638 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100639 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100640 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100641 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100642 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000643 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100644
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100645 if (INTEL_INFO(dev)->gen >= 4)
646 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
647 else
648 addr = I915_READ(DSPADDR(crtc->plane));
649 seq_printf(m, "Current scanout address 0x%08x\n", addr);
650
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100651 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100652 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
653 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100654 }
655 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200656 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100657 }
658
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200659 mutex_unlock(&dev->struct_mutex);
660
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100661 return 0;
662}
663
Brad Volkin493018d2014-12-11 12:13:08 -0800664static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
665{
666 struct drm_info_node *node = m->private;
667 struct drm_device *dev = node->minor->dev;
668 struct drm_i915_private *dev_priv = dev->dev_private;
669 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000670 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100671 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000672 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800673
674 ret = mutex_lock_interruptible(&dev->struct_mutex);
675 if (ret)
676 return ret;
677
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000678 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000679 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100680 int count;
681
682 count = 0;
683 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000684 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100685 batch_pool_link)
686 count++;
687 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000688 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100689
690 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000691 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100692 batch_pool_link) {
693 seq_puts(m, " ");
694 describe_obj(m, obj);
695 seq_putc(m, '\n');
696 }
697
698 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100699 }
Brad Volkin493018d2014-12-11 12:13:08 -0800700 }
701
Chris Wilson8d9d5742015-04-07 16:20:38 +0100702 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800703
704 mutex_unlock(&dev->struct_mutex);
705
706 return 0;
707}
708
Ben Gamari20172632009-02-17 20:08:50 -0500709static int i915_gem_request_info(struct seq_file *m, void *data)
710{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100711 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500712 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300713 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000714 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200715 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000716 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100717
718 ret = mutex_lock_interruptible(&dev->struct_mutex);
719 if (ret)
720 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500721
Chris Wilson2d1070b2015-04-01 10:36:56 +0100722 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000723 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100724 int count;
725
726 count = 0;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000727 list_for_each_entry(req, &engine->request_list, list)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100728 count++;
729 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100730 continue;
731
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000732 seq_printf(m, "%s requests: %d\n", engine->name, count);
733 list_for_each_entry(req, &engine->request_list, list) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100734 struct task_struct *task;
735
736 rcu_read_lock();
737 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200738 if (req->pid)
739 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100740 seq_printf(m, " %x @ %d: %s [%d]\n",
Daniel Vettereed29a52015-05-21 14:21:25 +0200741 req->seqno,
742 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100743 task ? task->comm : "<unknown>",
744 task ? task->pid : -1);
745 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100746 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100747
748 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500749 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100750 mutex_unlock(&dev->struct_mutex);
751
Chris Wilson2d1070b2015-04-01 10:36:56 +0100752 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100753 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100754
Ben Gamari20172632009-02-17 20:08:50 -0500755 return 0;
756}
757
Chris Wilsonb2223492010-10-27 15:27:33 +0100758static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000759 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100760{
Chris Wilson12471ba2016-04-09 10:57:55 +0100761 seq_printf(m, "Current sequence (%s): %x\n",
762 engine->name, engine->get_seqno(engine));
763 seq_printf(m, "Current user interrupts (%s): %x\n",
764 engine->name, READ_ONCE(engine->user_interrupts));
Chris Wilsonb2223492010-10-27 15:27:33 +0100765}
766
Ben Gamari20172632009-02-17 20:08:50 -0500767static int i915_gem_seqno_info(struct seq_file *m, void *data)
768{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100769 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500770 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300771 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000772 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000773 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100774
775 ret = mutex_lock_interruptible(&dev->struct_mutex);
776 if (ret)
777 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200778 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500779
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000780 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000781 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100782
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200783 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100784 mutex_unlock(&dev->struct_mutex);
785
Ben Gamari20172632009-02-17 20:08:50 -0500786 return 0;
787}
788
789
790static int i915_interrupt_info(struct seq_file *m, void *data)
791{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100792 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500793 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300794 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000795 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800796 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100797
798 ret = mutex_lock_interruptible(&dev->struct_mutex);
799 if (ret)
800 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200801 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500802
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300803 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300804 seq_printf(m, "Master Interrupt Control:\t%08x\n",
805 I915_READ(GEN8_MASTER_IRQ));
806
807 seq_printf(m, "Display IER:\t%08x\n",
808 I915_READ(VLV_IER));
809 seq_printf(m, "Display IIR:\t%08x\n",
810 I915_READ(VLV_IIR));
811 seq_printf(m, "Display IIR_RW:\t%08x\n",
812 I915_READ(VLV_IIR_RW));
813 seq_printf(m, "Display IMR:\t%08x\n",
814 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100815 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300816 seq_printf(m, "Pipe %c stat:\t%08x\n",
817 pipe_name(pipe),
818 I915_READ(PIPESTAT(pipe)));
819
820 seq_printf(m, "Port hotplug:\t%08x\n",
821 I915_READ(PORT_HOTPLUG_EN));
822 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
823 I915_READ(VLV_DPFLIPSTAT));
824 seq_printf(m, "DPINVGTT:\t%08x\n",
825 I915_READ(DPINVGTT));
826
827 for (i = 0; i < 4; i++) {
828 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
829 i, I915_READ(GEN8_GT_IMR(i)));
830 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
831 i, I915_READ(GEN8_GT_IIR(i)));
832 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
833 i, I915_READ(GEN8_GT_IER(i)));
834 }
835
836 seq_printf(m, "PCU interrupt mask:\t%08x\n",
837 I915_READ(GEN8_PCU_IMR));
838 seq_printf(m, "PCU interrupt identity:\t%08x\n",
839 I915_READ(GEN8_PCU_IIR));
840 seq_printf(m, "PCU interrupt enable:\t%08x\n",
841 I915_READ(GEN8_PCU_IER));
842 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700843 seq_printf(m, "Master Interrupt Control:\t%08x\n",
844 I915_READ(GEN8_MASTER_IRQ));
845
846 for (i = 0; i < 4; i++) {
847 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
848 i, I915_READ(GEN8_GT_IMR(i)));
849 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
850 i, I915_READ(GEN8_GT_IIR(i)));
851 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
852 i, I915_READ(GEN8_GT_IER(i)));
853 }
854
Damien Lespiau055e3932014-08-18 13:49:10 +0100855 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200856 enum intel_display_power_domain power_domain;
857
858 power_domain = POWER_DOMAIN_PIPE(pipe);
859 if (!intel_display_power_get_if_enabled(dev_priv,
860 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300861 seq_printf(m, "Pipe %c power disabled\n",
862 pipe_name(pipe));
863 continue;
864 }
Ben Widawskya123f152013-11-02 21:07:10 -0700865 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000866 pipe_name(pipe),
867 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700868 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000869 pipe_name(pipe),
870 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700871 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000872 pipe_name(pipe),
873 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200874
875 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700876 }
877
878 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
879 I915_READ(GEN8_DE_PORT_IMR));
880 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
881 I915_READ(GEN8_DE_PORT_IIR));
882 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
883 I915_READ(GEN8_DE_PORT_IER));
884
885 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
886 I915_READ(GEN8_DE_MISC_IMR));
887 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
888 I915_READ(GEN8_DE_MISC_IIR));
889 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
890 I915_READ(GEN8_DE_MISC_IER));
891
892 seq_printf(m, "PCU interrupt mask:\t%08x\n",
893 I915_READ(GEN8_PCU_IMR));
894 seq_printf(m, "PCU interrupt identity:\t%08x\n",
895 I915_READ(GEN8_PCU_IIR));
896 seq_printf(m, "PCU interrupt enable:\t%08x\n",
897 I915_READ(GEN8_PCU_IER));
898 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700899 seq_printf(m, "Display IER:\t%08x\n",
900 I915_READ(VLV_IER));
901 seq_printf(m, "Display IIR:\t%08x\n",
902 I915_READ(VLV_IIR));
903 seq_printf(m, "Display IIR_RW:\t%08x\n",
904 I915_READ(VLV_IIR_RW));
905 seq_printf(m, "Display IMR:\t%08x\n",
906 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100907 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700908 seq_printf(m, "Pipe %c stat:\t%08x\n",
909 pipe_name(pipe),
910 I915_READ(PIPESTAT(pipe)));
911
912 seq_printf(m, "Master IER:\t%08x\n",
913 I915_READ(VLV_MASTER_IER));
914
915 seq_printf(m, "Render IER:\t%08x\n",
916 I915_READ(GTIER));
917 seq_printf(m, "Render IIR:\t%08x\n",
918 I915_READ(GTIIR));
919 seq_printf(m, "Render IMR:\t%08x\n",
920 I915_READ(GTIMR));
921
922 seq_printf(m, "PM IER:\t\t%08x\n",
923 I915_READ(GEN6_PMIER));
924 seq_printf(m, "PM IIR:\t\t%08x\n",
925 I915_READ(GEN6_PMIIR));
926 seq_printf(m, "PM IMR:\t\t%08x\n",
927 I915_READ(GEN6_PMIMR));
928
929 seq_printf(m, "Port hotplug:\t%08x\n",
930 I915_READ(PORT_HOTPLUG_EN));
931 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
932 I915_READ(VLV_DPFLIPSTAT));
933 seq_printf(m, "DPINVGTT:\t%08x\n",
934 I915_READ(DPINVGTT));
935
936 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800937 seq_printf(m, "Interrupt enable: %08x\n",
938 I915_READ(IER));
939 seq_printf(m, "Interrupt identity: %08x\n",
940 I915_READ(IIR));
941 seq_printf(m, "Interrupt mask: %08x\n",
942 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100943 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800944 seq_printf(m, "Pipe %c stat: %08x\n",
945 pipe_name(pipe),
946 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800947 } else {
948 seq_printf(m, "North Display Interrupt enable: %08x\n",
949 I915_READ(DEIER));
950 seq_printf(m, "North Display Interrupt identity: %08x\n",
951 I915_READ(DEIIR));
952 seq_printf(m, "North Display Interrupt mask: %08x\n",
953 I915_READ(DEIMR));
954 seq_printf(m, "South Display Interrupt enable: %08x\n",
955 I915_READ(SDEIER));
956 seq_printf(m, "South Display Interrupt identity: %08x\n",
957 I915_READ(SDEIIR));
958 seq_printf(m, "South Display Interrupt mask: %08x\n",
959 I915_READ(SDEIMR));
960 seq_printf(m, "Graphics Interrupt enable: %08x\n",
961 I915_READ(GTIER));
962 seq_printf(m, "Graphics Interrupt identity: %08x\n",
963 I915_READ(GTIIR));
964 seq_printf(m, "Graphics Interrupt mask: %08x\n",
965 I915_READ(GTIMR));
966 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000967 for_each_engine(engine, dev_priv) {
Ben Widawskya123f152013-11-02 21:07:10 -0700968 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100969 seq_printf(m,
970 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000971 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000972 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000973 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000974 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200975 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100976 mutex_unlock(&dev->struct_mutex);
977
Ben Gamari20172632009-02-17 20:08:50 -0500978 return 0;
979}
980
Chris Wilsona6172a82009-02-11 14:26:38 +0000981static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
982{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100983 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000984 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300985 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100986 int i, ret;
987
988 ret = mutex_lock_interruptible(&dev->struct_mutex);
989 if (ret)
990 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000991
Chris Wilsona6172a82009-02-11 14:26:38 +0000992 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
993 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000994 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000995
Chris Wilson6c085a72012-08-20 11:40:46 +0200996 seq_printf(m, "Fence %d, pin count = %d, object = ",
997 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100998 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100999 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001000 else
Chris Wilson05394f32010-11-08 19:18:58 +00001001 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001002 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +00001003 }
1004
Chris Wilson05394f32010-11-08 19:18:58 +00001005 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +00001006 return 0;
1007}
1008
Ben Gamari20172632009-02-17 20:08:50 -05001009static int i915_hws_info(struct seq_file *m, void *data)
1010{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001011 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -05001012 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001013 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001014 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +01001015 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +01001016 int i;
Ben Gamari20172632009-02-17 20:08:50 -05001017
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001018 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001019 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -05001020 if (hws == NULL)
1021 return 0;
1022
1023 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
1024 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
1025 i * 4,
1026 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
1027 }
1028 return 0;
1029}
1030
Daniel Vetterd5442302012-04-27 15:17:40 +02001031static ssize_t
1032i915_error_state_write(struct file *filp,
1033 const char __user *ubuf,
1034 size_t cnt,
1035 loff_t *ppos)
1036{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001037 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001038 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001039 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001040
1041 DRM_DEBUG_DRIVER("Resetting error state\n");
1042
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001043 ret = mutex_lock_interruptible(&dev->struct_mutex);
1044 if (ret)
1045 return ret;
1046
Daniel Vetterd5442302012-04-27 15:17:40 +02001047 i915_destroy_error_state(dev);
1048 mutex_unlock(&dev->struct_mutex);
1049
1050 return cnt;
1051}
1052
1053static int i915_error_state_open(struct inode *inode, struct file *file)
1054{
1055 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001056 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001057
1058 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1059 if (!error_priv)
1060 return -ENOMEM;
1061
1062 error_priv->dev = dev;
1063
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001064 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001065
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001066 file->private_data = error_priv;
1067
1068 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001069}
1070
1071static int i915_error_state_release(struct inode *inode, struct file *file)
1072{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001073 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001074
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001075 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001076 kfree(error_priv);
1077
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001078 return 0;
1079}
1080
1081static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1082 size_t count, loff_t *pos)
1083{
1084 struct i915_error_state_file_priv *error_priv = file->private_data;
1085 struct drm_i915_error_state_buf error_str;
1086 loff_t tmp_pos = 0;
1087 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001088 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001089
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001090 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001091 if (ret)
1092 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001093
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001094 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001095 if (ret)
1096 goto out;
1097
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001098 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1099 error_str.buf,
1100 error_str.bytes);
1101
1102 if (ret_count < 0)
1103 ret = ret_count;
1104 else
1105 *pos = error_str.start + ret_count;
1106out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001107 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001108 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001109}
1110
1111static const struct file_operations i915_error_state_fops = {
1112 .owner = THIS_MODULE,
1113 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001114 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001115 .write = i915_error_state_write,
1116 .llseek = default_llseek,
1117 .release = i915_error_state_release,
1118};
1119
Kees Cook647416f2013-03-10 14:10:06 -07001120static int
1121i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001122{
Kees Cook647416f2013-03-10 14:10:06 -07001123 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001124 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001125 int ret;
1126
1127 ret = mutex_lock_interruptible(&dev->struct_mutex);
1128 if (ret)
1129 return ret;
1130
Kees Cook647416f2013-03-10 14:10:06 -07001131 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001132 mutex_unlock(&dev->struct_mutex);
1133
Kees Cook647416f2013-03-10 14:10:06 -07001134 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001135}
1136
Kees Cook647416f2013-03-10 14:10:06 -07001137static int
1138i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001139{
Kees Cook647416f2013-03-10 14:10:06 -07001140 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001141 int ret;
1142
Mika Kuoppala40633212012-12-04 15:12:00 +02001143 ret = mutex_lock_interruptible(&dev->struct_mutex);
1144 if (ret)
1145 return ret;
1146
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001147 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001148 mutex_unlock(&dev->struct_mutex);
1149
Kees Cook647416f2013-03-10 14:10:06 -07001150 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001151}
1152
Kees Cook647416f2013-03-10 14:10:06 -07001153DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1154 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001155 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001156
Deepak Sadb4bd12014-03-31 11:30:02 +05301157static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001158{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001159 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001160 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001161 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001162 int ret = 0;
1163
1164 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001165
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001166 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1167
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001168 if (IS_GEN5(dev)) {
1169 u16 rgvswctl = I915_READ16(MEMSWCTL);
1170 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1171
1172 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1173 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1174 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1175 MEMSTAT_VID_SHIFT);
1176 seq_printf(m, "Current P-state: %d\n",
1177 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Wayne Boyer666a4532015-12-09 12:29:35 -08001178 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
1179 u32 freq_sts;
1180
1181 mutex_lock(&dev_priv->rps.hw_lock);
1182 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1183 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1184 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1185
1186 seq_printf(m, "actual GPU freq: %d MHz\n",
1187 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1188
1189 seq_printf(m, "current GPU freq: %d MHz\n",
1190 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1191
1192 seq_printf(m, "max GPU freq: %d MHz\n",
1193 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1194
1195 seq_printf(m, "min GPU freq: %d MHz\n",
1196 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1197
1198 seq_printf(m, "idle GPU freq: %d MHz\n",
1199 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1200
1201 seq_printf(m,
1202 "efficient (RPe) frequency: %d MHz\n",
1203 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1204 mutex_unlock(&dev_priv->rps.hw_lock);
1205 } else if (INTEL_INFO(dev)->gen >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001206 u32 rp_state_limits;
1207 u32 gt_perf_status;
1208 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001209 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001210 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001211 u32 rpupei, rpcurup, rpprevup;
1212 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001213 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001214 int max_freq;
1215
Bob Paauwe35040562015-06-25 14:54:07 -07001216 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1217 if (IS_BROXTON(dev)) {
1218 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1219 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1220 } else {
1221 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1222 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1223 }
1224
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001225 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001226 ret = mutex_lock_interruptible(&dev->struct_mutex);
1227 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001228 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001229
Mika Kuoppala59bad942015-01-16 11:34:40 +02001230 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001231
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001232 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301233 if (IS_GEN9(dev))
1234 reqf >>= 23;
1235 else {
1236 reqf &= ~GEN6_TURBO_DISABLE;
1237 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1238 reqf >>= 24;
1239 else
1240 reqf >>= 25;
1241 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001242 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001243
Chris Wilson0d8f9492014-03-27 09:06:14 +00001244 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1245 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1246 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1247
Jesse Barnesccab5c82011-01-18 15:49:25 -08001248 rpstat = I915_READ(GEN6_RPSTAT1);
1249 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1250 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1251 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1252 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1253 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1254 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Akash Goel60260a52015-03-06 11:07:21 +05301255 if (IS_GEN9(dev))
1256 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1257 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001258 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1259 else
1260 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001261 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001262
Mika Kuoppala59bad942015-01-16 11:34:40 +02001263 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001264 mutex_unlock(&dev->struct_mutex);
1265
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001266 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1267 pm_ier = I915_READ(GEN6_PMIER);
1268 pm_imr = I915_READ(GEN6_PMIMR);
1269 pm_isr = I915_READ(GEN6_PMISR);
1270 pm_iir = I915_READ(GEN6_PMIIR);
1271 pm_mask = I915_READ(GEN6_PMINTRMSK);
1272 } else {
1273 pm_ier = I915_READ(GEN8_GT_IER(2));
1274 pm_imr = I915_READ(GEN8_GT_IMR(2));
1275 pm_isr = I915_READ(GEN8_GT_ISR(2));
1276 pm_iir = I915_READ(GEN8_GT_IIR(2));
1277 pm_mask = I915_READ(GEN6_PMINTRMSK);
1278 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001279 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 -03001280 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001281 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001282 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301283 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001284 seq_printf(m, "Render p-state VID: %d\n",
1285 gt_perf_status & 0xff);
1286 seq_printf(m, "Render p-state limit: %d\n",
1287 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001288 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1289 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1290 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1291 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001292 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001293 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001294 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1295 GEN6_CURICONT_MASK);
1296 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1297 GEN6_CURBSYTAVG_MASK);
1298 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1299 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001300 seq_printf(m, "Up threshold: %d%%\n",
1301 dev_priv->rps.up_threshold);
1302
Jesse Barnesccab5c82011-01-18 15:49:25 -08001303 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1304 GEN6_CURIAVG_MASK);
1305 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1306 GEN6_CURBSYTAVG_MASK);
1307 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1308 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001309 seq_printf(m, "Down threshold: %d%%\n",
1310 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001311
Bob Paauwe35040562015-06-25 14:54:07 -07001312 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1313 rp_state_cap >> 16) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001314 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1315 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001316 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001317 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001318
1319 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001320 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1321 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001322 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001323 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001324
Bob Paauwe35040562015-06-25 14:54:07 -07001325 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1326 rp_state_cap >> 0) & 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, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001330 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001331 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001332 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001333
Chris Wilsond86ed342015-04-27 13:41:19 +01001334 seq_printf(m, "Current freq: %d MHz\n",
1335 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1336 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001337 seq_printf(m, "Idle freq: %d MHz\n",
1338 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001339 seq_printf(m, "Min freq: %d MHz\n",
1340 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1341 seq_printf(m, "Max freq: %d MHz\n",
1342 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1343 seq_printf(m,
1344 "efficient (RPe) frequency: %d MHz\n",
1345 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001346 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001347 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001348 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001349
Mika Kahola1170f282015-09-25 14:00:32 +03001350 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1351 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1352 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1353
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001354out:
1355 intel_runtime_pm_put(dev_priv);
1356 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001357}
1358
Chris Wilsonf6544492015-01-26 18:03:04 +02001359static int i915_hangcheck_info(struct seq_file *m, void *unused)
1360{
1361 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001362 struct drm_device *dev = node->minor->dev;
1363 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001364 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001365 u64 acthd[I915_NUM_ENGINES];
1366 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001367 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001368 enum intel_engine_id id;
1369 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001370
1371 if (!i915.enable_hangcheck) {
1372 seq_printf(m, "Hangcheck disabled\n");
1373 return 0;
1374 }
1375
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001376 intel_runtime_pm_get(dev_priv);
1377
Dave Gordonc3232b12016-03-23 18:19:53 +00001378 for_each_engine_id(engine, dev_priv, id) {
Dave Gordonc3232b12016-03-23 18:19:53 +00001379 acthd[id] = intel_ring_get_active_head(engine);
Chris Wilsonc04e0f32016-04-09 10:57:54 +01001380 seqno[id] = engine->get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001381 }
1382
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001383 i915_get_extra_instdone(dev, instdone);
1384
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001385 intel_runtime_pm_put(dev_priv);
1386
Chris Wilsonf6544492015-01-26 18:03:04 +02001387 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1388 seq_printf(m, "Hangcheck active, fires in %dms\n",
1389 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1390 jiffies));
1391 } else
1392 seq_printf(m, "Hangcheck inactive\n");
1393
Dave Gordonc3232b12016-03-23 18:19:53 +00001394 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001395 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001396 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1397 engine->hangcheck.seqno,
1398 seqno[id],
1399 engine->last_submitted_seqno);
Chris Wilson12471ba2016-04-09 10:57:55 +01001400 seq_printf(m, "\tuser interrupts = %x [current %x]\n",
1401 engine->hangcheck.user_interrupts,
1402 READ_ONCE(engine->user_interrupts));
Chris Wilsonf6544492015-01-26 18:03:04 +02001403 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001404 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001405 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001406 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1407 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001408
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001409 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001410 seq_puts(m, "\tinstdone read =");
1411
1412 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1413 seq_printf(m, " 0x%08x", instdone[j]);
1414
1415 seq_puts(m, "\n\tinstdone accu =");
1416
1417 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1418 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001419 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001420
1421 seq_puts(m, "\n");
1422 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001423 }
1424
1425 return 0;
1426}
1427
Ben Widawsky4d855292011-12-12 19:34:16 -08001428static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001429{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001430 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001431 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001432 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001433 u32 rgvmodectl, rstdbyctl;
1434 u16 crstandvid;
1435 int ret;
1436
1437 ret = mutex_lock_interruptible(&dev->struct_mutex);
1438 if (ret)
1439 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001440 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001441
1442 rgvmodectl = I915_READ(MEMMODECTL);
1443 rstdbyctl = I915_READ(RSTDBYCTL);
1444 crstandvid = I915_READ16(CRSTANDVID);
1445
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001446 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001447 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001448
Jani Nikula742f4912015-09-03 11:16:09 +03001449 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001450 seq_printf(m, "Boost freq: %d\n",
1451 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1452 MEMMODE_BOOST_FREQ_SHIFT);
1453 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001454 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001455 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001456 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001457 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001458 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001459 seq_printf(m, "Starting frequency: P%d\n",
1460 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001461 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001462 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001463 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1464 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1465 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1466 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001467 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001468 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001469 switch (rstdbyctl & RSX_STATUS_MASK) {
1470 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001471 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001472 break;
1473 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001474 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001475 break;
1476 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001477 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001478 break;
1479 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001480 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001481 break;
1482 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001483 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001484 break;
1485 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001486 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001487 break;
1488 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001489 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001490 break;
1491 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001492
1493 return 0;
1494}
1495
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001496static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001497{
1498 struct drm_info_node *node = m->private;
1499 struct drm_device *dev = node->minor->dev;
1500 struct drm_i915_private *dev_priv = dev->dev_private;
1501 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001502
1503 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001504 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001505 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001506 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001507 fw_domain->wake_count);
1508 }
1509 spin_unlock_irq(&dev_priv->uncore.lock);
1510
1511 return 0;
1512}
1513
Deepak S669ab5a2014-01-10 15:18:26 +05301514static int vlv_drpc_info(struct seq_file *m)
1515{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001516 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301517 struct drm_device *dev = node->minor->dev;
1518 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001519 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301520
Imre Deakd46c0512014-04-14 20:24:27 +03001521 intel_runtime_pm_get(dev_priv);
1522
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001523 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301524 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1525 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1526
Imre Deakd46c0512014-04-14 20:24:27 +03001527 intel_runtime_pm_put(dev_priv);
1528
Deepak S669ab5a2014-01-10 15:18:26 +05301529 seq_printf(m, "Video Turbo Mode: %s\n",
1530 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1531 seq_printf(m, "Turbo enabled: %s\n",
1532 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1533 seq_printf(m, "HW control enabled: %s\n",
1534 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1535 seq_printf(m, "SW control enabled: %s\n",
1536 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1537 GEN6_RP_MEDIA_SW_MODE));
1538 seq_printf(m, "RC6 Enabled: %s\n",
1539 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1540 GEN6_RC_CTL_EI_MODE(1))));
1541 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001542 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301543 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001544 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301545
Imre Deak9cc19be2014-04-14 20:24:24 +03001546 seq_printf(m, "Render RC6 residency since boot: %u\n",
1547 I915_READ(VLV_GT_RENDER_RC6));
1548 seq_printf(m, "Media RC6 residency since boot: %u\n",
1549 I915_READ(VLV_GT_MEDIA_RC6));
1550
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001551 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301552}
1553
Ben Widawsky4d855292011-12-12 19:34:16 -08001554static int gen6_drpc_info(struct seq_file *m)
1555{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001556 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001557 struct drm_device *dev = node->minor->dev;
1558 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001559 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001560 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001561 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001562
1563 ret = mutex_lock_interruptible(&dev->struct_mutex);
1564 if (ret)
1565 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001566 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001567
Chris Wilson907b28c2013-07-19 20:36:52 +01001568 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001569 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001570 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001571
1572 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001573 seq_puts(m, "RC information inaccurate because somebody "
1574 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001575 } else {
1576 /* NB: we cannot use forcewake, else we read the wrong values */
1577 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1578 udelay(10);
1579 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1580 }
1581
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001582 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001583 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001584
1585 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1586 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1587 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001588 mutex_lock(&dev_priv->rps.hw_lock);
1589 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1590 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001591
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001592 intel_runtime_pm_put(dev_priv);
1593
Ben Widawsky4d855292011-12-12 19:34:16 -08001594 seq_printf(m, "Video Turbo Mode: %s\n",
1595 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1596 seq_printf(m, "HW control enabled: %s\n",
1597 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1598 seq_printf(m, "SW control enabled: %s\n",
1599 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1600 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001601 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001602 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1603 seq_printf(m, "RC6 Enabled: %s\n",
1604 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1605 seq_printf(m, "Deep RC6 Enabled: %s\n",
1606 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1607 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1608 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001609 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001610 switch (gt_core_status & GEN6_RCn_MASK) {
1611 case GEN6_RC0:
1612 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001613 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001614 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001615 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001616 break;
1617 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001618 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001619 break;
1620 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001621 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001622 break;
1623 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001624 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001625 break;
1626 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001627 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001628 break;
1629 }
1630
1631 seq_printf(m, "Core Power Down: %s\n",
1632 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001633
1634 /* Not exactly sure what this is */
1635 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1636 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1637 seq_printf(m, "RC6 residency since boot: %u\n",
1638 I915_READ(GEN6_GT_GFX_RC6));
1639 seq_printf(m, "RC6+ residency since boot: %u\n",
1640 I915_READ(GEN6_GT_GFX_RC6p));
1641 seq_printf(m, "RC6++ residency since boot: %u\n",
1642 I915_READ(GEN6_GT_GFX_RC6pp));
1643
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001644 seq_printf(m, "RC6 voltage: %dmV\n",
1645 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1646 seq_printf(m, "RC6+ voltage: %dmV\n",
1647 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1648 seq_printf(m, "RC6++ voltage: %dmV\n",
1649 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001650 return 0;
1651}
1652
1653static int i915_drpc_info(struct seq_file *m, void *unused)
1654{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001655 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001656 struct drm_device *dev = node->minor->dev;
1657
Wayne Boyer666a4532015-12-09 12:29:35 -08001658 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Deepak S669ab5a2014-01-10 15:18:26 +05301659 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001660 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001661 return gen6_drpc_info(m);
1662 else
1663 return ironlake_drpc_info(m);
1664}
1665
Daniel Vetter9a851782015-06-18 10:30:22 +02001666static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1667{
1668 struct drm_info_node *node = m->private;
1669 struct drm_device *dev = node->minor->dev;
1670 struct drm_i915_private *dev_priv = dev->dev_private;
1671
1672 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1673 dev_priv->fb_tracking.busy_bits);
1674
1675 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1676 dev_priv->fb_tracking.flip_bits);
1677
1678 return 0;
1679}
1680
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001681static int i915_fbc_status(struct seq_file *m, void *unused)
1682{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001683 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001684 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001685 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001686
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001687 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001688 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001689 return 0;
1690 }
1691
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001692 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001693 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001694
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001695 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001696 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001697 else
1698 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001699 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001700
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001701 if (INTEL_INFO(dev_priv)->gen >= 7)
1702 seq_printf(m, "Compressing: %s\n",
1703 yesno(I915_READ(FBC_STATUS2) &
1704 FBC_COMPRESSION_MASK));
1705
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001706 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001707 intel_runtime_pm_put(dev_priv);
1708
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001709 return 0;
1710}
1711
Rodrigo Vivida46f932014-08-01 02:04:45 -07001712static int i915_fbc_fc_get(void *data, u64 *val)
1713{
1714 struct drm_device *dev = data;
1715 struct drm_i915_private *dev_priv = dev->dev_private;
1716
1717 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1718 return -ENODEV;
1719
Rodrigo Vivida46f932014-08-01 02:04:45 -07001720 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001721
1722 return 0;
1723}
1724
1725static int i915_fbc_fc_set(void *data, u64 val)
1726{
1727 struct drm_device *dev = data;
1728 struct drm_i915_private *dev_priv = dev->dev_private;
1729 u32 reg;
1730
1731 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1732 return -ENODEV;
1733
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001734 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001735
1736 reg = I915_READ(ILK_DPFC_CONTROL);
1737 dev_priv->fbc.false_color = val;
1738
1739 I915_WRITE(ILK_DPFC_CONTROL, val ?
1740 (reg | FBC_CTL_FALSE_COLOR) :
1741 (reg & ~FBC_CTL_FALSE_COLOR));
1742
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001743 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001744 return 0;
1745}
1746
1747DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1748 i915_fbc_fc_get, i915_fbc_fc_set,
1749 "%llu\n");
1750
Paulo Zanoni92d44622013-05-31 16:33:24 -03001751static int i915_ips_status(struct seq_file *m, void *unused)
1752{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001753 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001754 struct drm_device *dev = node->minor->dev;
1755 struct drm_i915_private *dev_priv = dev->dev_private;
1756
Damien Lespiauf5adf942013-06-24 18:29:34 +01001757 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001758 seq_puts(m, "not supported\n");
1759 return 0;
1760 }
1761
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001762 intel_runtime_pm_get(dev_priv);
1763
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001764 seq_printf(m, "Enabled by kernel parameter: %s\n",
1765 yesno(i915.enable_ips));
1766
1767 if (INTEL_INFO(dev)->gen >= 8) {
1768 seq_puts(m, "Currently: unknown\n");
1769 } else {
1770 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1771 seq_puts(m, "Currently: enabled\n");
1772 else
1773 seq_puts(m, "Currently: disabled\n");
1774 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001775
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001776 intel_runtime_pm_put(dev_priv);
1777
Paulo Zanoni92d44622013-05-31 16:33:24 -03001778 return 0;
1779}
1780
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001781static int i915_sr_status(struct seq_file *m, void *unused)
1782{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001783 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001784 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001785 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001786 bool sr_enabled = false;
1787
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001788 intel_runtime_pm_get(dev_priv);
1789
Yuanhan Liu13982612010-12-15 15:42:31 +08001790 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001791 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001792 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1793 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001794 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1795 else if (IS_I915GM(dev))
1796 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1797 else if (IS_PINEVIEW(dev))
1798 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Wayne Boyer666a4532015-12-09 12:29:35 -08001799 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001800 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001801
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001802 intel_runtime_pm_put(dev_priv);
1803
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001804 seq_printf(m, "self-refresh: %s\n",
1805 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001806
1807 return 0;
1808}
1809
Jesse Barnes7648fa92010-05-20 14:28:11 -07001810static int i915_emon_status(struct seq_file *m, void *unused)
1811{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001812 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001813 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001814 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001815 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001816 int ret;
1817
Chris Wilson582be6b2012-04-30 19:35:02 +01001818 if (!IS_GEN5(dev))
1819 return -ENODEV;
1820
Chris Wilsonde227ef2010-07-03 07:58:38 +01001821 ret = mutex_lock_interruptible(&dev->struct_mutex);
1822 if (ret)
1823 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001824
1825 temp = i915_mch_val(dev_priv);
1826 chipset = i915_chipset_val(dev_priv);
1827 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001828 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001829
1830 seq_printf(m, "GMCH temp: %ld\n", temp);
1831 seq_printf(m, "Chipset power: %ld\n", chipset);
1832 seq_printf(m, "GFX power: %ld\n", gfx);
1833 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1834
1835 return 0;
1836}
1837
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001838static int i915_ring_freq_table(struct seq_file *m, void *unused)
1839{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001840 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001841 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001842 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001843 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001844 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301845 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001846
Akash Goel97d33082015-06-29 14:50:23 +05301847 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001848 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001849 return 0;
1850 }
1851
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001852 intel_runtime_pm_get(dev_priv);
1853
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001854 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1855
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001856 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001857 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001858 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001859
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001860 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301861 /* Convert GT frequency to 50 HZ units */
1862 min_gpu_freq =
1863 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1864 max_gpu_freq =
1865 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1866 } else {
1867 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1868 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1869 }
1870
Damien Lespiau267f0c92013-06-24 22:59:48 +01001871 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001872
Akash Goelf936ec32015-06-29 14:50:22 +05301873 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001874 ia_freq = gpu_freq;
1875 sandybridge_pcode_read(dev_priv,
1876 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1877 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001878 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301879 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001880 (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1881 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001882 ((ia_freq >> 0) & 0xff) * 100,
1883 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001884 }
1885
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001886 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001887
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001888out:
1889 intel_runtime_pm_put(dev_priv);
1890 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001891}
1892
Chris Wilson44834a62010-08-19 16:09:23 +01001893static int i915_opregion(struct seq_file *m, void *unused)
1894{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001895 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001896 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001897 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001898 struct intel_opregion *opregion = &dev_priv->opregion;
1899 int ret;
1900
1901 ret = mutex_lock_interruptible(&dev->struct_mutex);
1902 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001903 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001904
Jani Nikula2455a8e2015-12-14 12:50:53 +02001905 if (opregion->header)
1906 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001907
1908 mutex_unlock(&dev->struct_mutex);
1909
Daniel Vetter0d38f002012-04-21 22:49:10 +02001910out:
Chris Wilson44834a62010-08-19 16:09:23 +01001911 return 0;
1912}
1913
Jani Nikulaada8f952015-12-15 13:17:12 +02001914static int i915_vbt(struct seq_file *m, void *unused)
1915{
1916 struct drm_info_node *node = m->private;
1917 struct drm_device *dev = node->minor->dev;
1918 struct drm_i915_private *dev_priv = dev->dev_private;
1919 struct intel_opregion *opregion = &dev_priv->opregion;
1920
1921 if (opregion->vbt)
1922 seq_write(m, opregion->vbt, opregion->vbt_size);
1923
1924 return 0;
1925}
1926
Chris Wilson37811fc2010-08-25 22:45:57 +01001927static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1928{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001929 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001930 struct drm_device *dev = node->minor->dev;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301931 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001932 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001933 int ret;
1934
1935 ret = mutex_lock_interruptible(&dev->struct_mutex);
1936 if (ret)
1937 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001938
Daniel Vetter06957262015-08-10 13:34:08 +02001939#ifdef CONFIG_DRM_FBDEV_EMULATION
Namrta Salonieb13b8402015-11-27 13:43:11 +05301940 if (to_i915(dev)->fbdev) {
1941 fbdev_fb = to_intel_framebuffer(to_i915(dev)->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001942
Namrta Salonieb13b8402015-11-27 13:43:11 +05301943 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1944 fbdev_fb->base.width,
1945 fbdev_fb->base.height,
1946 fbdev_fb->base.depth,
1947 fbdev_fb->base.bits_per_pixel,
1948 fbdev_fb->base.modifier[0],
1949 atomic_read(&fbdev_fb->base.refcount.refcount));
1950 describe_obj(m, fbdev_fb->obj);
1951 seq_putc(m, '\n');
1952 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001953#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001954
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001955 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001956 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301957 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1958 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001959 continue;
1960
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001961 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 +01001962 fb->base.width,
1963 fb->base.height,
1964 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001965 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001966 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001967 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001968 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001969 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001970 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001971 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001972 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001973
1974 return 0;
1975}
1976
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001977static void describe_ctx_ringbuf(struct seq_file *m,
1978 struct intel_ringbuffer *ringbuf)
1979{
1980 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1981 ringbuf->space, ringbuf->head, ringbuf->tail,
1982 ringbuf->last_retired_head);
1983}
1984
Ben Widawskye76d3632011-03-19 18:14:29 -07001985static int i915_context_status(struct seq_file *m, void *unused)
1986{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001987 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001988 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001989 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001990 struct intel_engine_cs *engine;
Oscar Mateo273497e2014-05-22 14:13:37 +01001991 struct intel_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00001992 enum intel_engine_id id;
1993 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001994
Daniel Vetterf3d28872014-05-29 23:23:08 +02001995 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001996 if (ret)
1997 return ret;
1998
Ben Widawskya33afea2013-09-17 21:12:45 -07001999 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002000 if (!i915.enable_execlists &&
2001 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01002002 continue;
2003
Ben Widawskya33afea2013-09-17 21:12:45 -07002004 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07002005 describe_ctx(m, ctx);
Dave Gordone28e4042016-01-19 19:02:55 +00002006 if (ctx == dev_priv->kernel_context)
2007 seq_printf(m, "(kernel context) ");
Ben Widawskya33afea2013-09-17 21:12:45 -07002008
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002009 if (i915.enable_execlists) {
2010 seq_putc(m, '\n');
Dave Gordonc3232b12016-03-23 18:19:53 +00002011 for_each_engine_id(engine, dev_priv, id) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002012 struct drm_i915_gem_object *ctx_obj =
Dave Gordonc3232b12016-03-23 18:19:53 +00002013 ctx->engine[id].state;
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002014 struct intel_ringbuffer *ringbuf =
Dave Gordonc3232b12016-03-23 18:19:53 +00002015 ctx->engine[id].ringbuf;
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002016
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002017 seq_printf(m, "%s: ", engine->name);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002018 if (ctx_obj)
2019 describe_obj(m, ctx_obj);
2020 if (ringbuf)
2021 describe_ctx_ringbuf(m, ringbuf);
2022 seq_putc(m, '\n');
2023 }
2024 } else {
2025 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
2026 }
2027
Ben Widawskya33afea2013-09-17 21:12:45 -07002028 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002029 }
2030
Daniel Vetterf3d28872014-05-29 23:23:08 +02002031 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002032
2033 return 0;
2034}
2035
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002036static void i915_dump_lrc_obj(struct seq_file *m,
Tvrtko Ursulinca825802016-01-15 15:10:27 +00002037 struct intel_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002038 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002039{
2040 struct page *page;
2041 uint32_t *reg_state;
2042 int j;
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002043 struct drm_i915_gem_object *ctx_obj = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002044 unsigned long ggtt_offset = 0;
2045
2046 if (ctx_obj == NULL) {
2047 seq_printf(m, "Context on %s with no gem object\n",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002048 engine->name);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002049 return;
2050 }
2051
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002052 seq_printf(m, "CONTEXT: %s %u\n", engine->name,
2053 intel_execlists_ctx_id(ctx, engine));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002054
2055 if (!i915_gem_obj_ggtt_bound(ctx_obj))
2056 seq_puts(m, "\tNot bound in GGTT\n");
2057 else
2058 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
2059
2060 if (i915_gem_object_get_pages(ctx_obj)) {
2061 seq_puts(m, "\tFailed to get pages for context object\n");
2062 return;
2063 }
2064
Alex Daid1675192015-08-12 15:43:43 +01002065 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002066 if (!WARN_ON(page == NULL)) {
2067 reg_state = kmap_atomic(page);
2068
2069 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2070 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2071 ggtt_offset + 4096 + (j * 4),
2072 reg_state[j], reg_state[j + 1],
2073 reg_state[j + 2], reg_state[j + 3]);
2074 }
2075 kunmap_atomic(reg_state);
2076 }
2077
2078 seq_putc(m, '\n');
2079}
2080
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002081static int i915_dump_lrc(struct seq_file *m, void *unused)
2082{
2083 struct drm_info_node *node = (struct drm_info_node *) m->private;
2084 struct drm_device *dev = node->minor->dev;
2085 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002086 struct intel_engine_cs *engine;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002087 struct intel_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002088 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002089
2090 if (!i915.enable_execlists) {
2091 seq_printf(m, "Logical Ring Contexts are disabled\n");
2092 return 0;
2093 }
2094
2095 ret = mutex_lock_interruptible(&dev->struct_mutex);
2096 if (ret)
2097 return ret;
2098
Dave Gordone28e4042016-01-19 19:02:55 +00002099 list_for_each_entry(ctx, &dev_priv->context_list, link)
2100 if (ctx != dev_priv->kernel_context)
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002101 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002102 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002103
2104 mutex_unlock(&dev->struct_mutex);
2105
2106 return 0;
2107}
2108
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002109static int i915_execlists(struct seq_file *m, void *data)
2110{
2111 struct drm_info_node *node = (struct drm_info_node *)m->private;
2112 struct drm_device *dev = node->minor->dev;
2113 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002114 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002115 u32 status_pointer;
2116 u8 read_pointer;
2117 u8 write_pointer;
2118 u32 status;
2119 u32 ctx_id;
2120 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002121 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002122
2123 if (!i915.enable_execlists) {
2124 seq_puts(m, "Logical Ring Contexts are disabled\n");
2125 return 0;
2126 }
2127
2128 ret = mutex_lock_interruptible(&dev->struct_mutex);
2129 if (ret)
2130 return ret;
2131
Michel Thierryfc0412e2014-10-16 16:13:38 +01002132 intel_runtime_pm_get(dev_priv);
2133
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002134 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002135 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002136 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002137
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002138 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002139
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002140 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2141 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002142 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2143 status, ctx_id);
2144
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002145 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002146 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2147
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002148 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002149 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002150 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002151 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002152 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2153 read_pointer, write_pointer);
2154
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002155 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002156 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2157 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002158
2159 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2160 i, status, ctx_id);
2161 }
2162
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002163 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002164 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002165 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002166 head_req = list_first_entry_or_null(&engine->execlist_queue,
2167 struct drm_i915_gem_request,
2168 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002169 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002170
2171 seq_printf(m, "\t%d requests in queue\n", count);
2172 if (head_req) {
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002173 seq_printf(m, "\tHead request id: %u\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002174 intel_execlists_ctx_id(head_req->ctx, engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002175 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002176 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002177 }
2178
2179 seq_putc(m, '\n');
2180 }
2181
Michel Thierryfc0412e2014-10-16 16:13:38 +01002182 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002183 mutex_unlock(&dev->struct_mutex);
2184
2185 return 0;
2186}
2187
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002188static const char *swizzle_string(unsigned swizzle)
2189{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002190 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002191 case I915_BIT_6_SWIZZLE_NONE:
2192 return "none";
2193 case I915_BIT_6_SWIZZLE_9:
2194 return "bit9";
2195 case I915_BIT_6_SWIZZLE_9_10:
2196 return "bit9/bit10";
2197 case I915_BIT_6_SWIZZLE_9_11:
2198 return "bit9/bit11";
2199 case I915_BIT_6_SWIZZLE_9_10_11:
2200 return "bit9/bit10/bit11";
2201 case I915_BIT_6_SWIZZLE_9_17:
2202 return "bit9/bit17";
2203 case I915_BIT_6_SWIZZLE_9_10_17:
2204 return "bit9/bit10/bit17";
2205 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002206 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002207 }
2208
2209 return "bug";
2210}
2211
2212static int i915_swizzle_info(struct seq_file *m, void *data)
2213{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002214 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002215 struct drm_device *dev = node->minor->dev;
2216 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002217 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002218
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002219 ret = mutex_lock_interruptible(&dev->struct_mutex);
2220 if (ret)
2221 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002222 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002223
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002224 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2225 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2226 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2227 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2228
2229 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2230 seq_printf(m, "DDC = 0x%08x\n",
2231 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002232 seq_printf(m, "DDC2 = 0x%08x\n",
2233 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002234 seq_printf(m, "C0DRB3 = 0x%04x\n",
2235 I915_READ16(C0DRB3));
2236 seq_printf(m, "C1DRB3 = 0x%04x\n",
2237 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002238 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002239 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2240 I915_READ(MAD_DIMM_C0));
2241 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2242 I915_READ(MAD_DIMM_C1));
2243 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2244 I915_READ(MAD_DIMM_C2));
2245 seq_printf(m, "TILECTL = 0x%08x\n",
2246 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002247 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002248 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2249 I915_READ(GAMTARBMODE));
2250 else
2251 seq_printf(m, "ARB_MODE = 0x%08x\n",
2252 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002253 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2254 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002255 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002256
2257 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2258 seq_puts(m, "L-shaped memory detected\n");
2259
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002260 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002261 mutex_unlock(&dev->struct_mutex);
2262
2263 return 0;
2264}
2265
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002266static int per_file_ctx(int id, void *ptr, void *data)
2267{
Oscar Mateo273497e2014-05-22 14:13:37 +01002268 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002269 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002270 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2271
2272 if (!ppgtt) {
2273 seq_printf(m, " no ppgtt for context %d\n",
2274 ctx->user_handle);
2275 return 0;
2276 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002277
Oscar Mateof83d6512014-05-22 14:13:38 +01002278 if (i915_gem_context_is_default(ctx))
2279 seq_puts(m, " default context:\n");
2280 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002281 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002282 ppgtt->debug_dump(ppgtt, m);
2283
2284 return 0;
2285}
2286
Ben Widawsky77df6772013-11-02 21:07:30 -07002287static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002288{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002289 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002290 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002291 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002292 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002293
Ben Widawsky77df6772013-11-02 21:07:30 -07002294 if (!ppgtt)
2295 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002296
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002297 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002298 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002299 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002300 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002301 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002302 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002303 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002304 }
2305 }
2306}
2307
2308static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2309{
2310 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002311 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002312
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002313 if (INTEL_INFO(dev)->gen == 6)
2314 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2315
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002316 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002317 seq_printf(m, "%s\n", engine->name);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002318 if (INTEL_INFO(dev)->gen == 7)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002319 seq_printf(m, "GFX_MODE: 0x%08x\n",
2320 I915_READ(RING_MODE_GEN7(engine)));
2321 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2322 I915_READ(RING_PP_DIR_BASE(engine)));
2323 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2324 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2325 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2326 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002327 }
2328 if (dev_priv->mm.aliasing_ppgtt) {
2329 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2330
Damien Lespiau267f0c92013-06-24 22:59:48 +01002331 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002332 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002333
Ben Widawsky87d60b62013-12-06 14:11:29 -08002334 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002335 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002336
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002337 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002338}
2339
2340static int i915_ppgtt_info(struct seq_file *m, void *data)
2341{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002342 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002343 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002344 struct drm_i915_private *dev_priv = dev->dev_private;
Michel Thierryea91e402015-07-29 17:23:57 +01002345 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002346
2347 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2348 if (ret)
2349 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002350 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002351
2352 if (INTEL_INFO(dev)->gen >= 8)
2353 gen8_ppgtt_info(m, dev);
2354 else if (INTEL_INFO(dev)->gen >= 6)
2355 gen6_ppgtt_info(m, dev);
2356
Michel Thierryea91e402015-07-29 17:23:57 +01002357 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2358 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002359 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002360
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002361 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002362 if (!task) {
2363 ret = -ESRCH;
2364 goto out_put;
2365 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002366 seq_printf(m, "\nproc: %s\n", task->comm);
2367 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002368 idr_for_each(&file_priv->context_idr, per_file_ctx,
2369 (void *)(unsigned long)m);
2370 }
2371
Dan Carpenter06812762015-10-02 18:14:22 +03002372out_put:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002373 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002374 mutex_unlock(&dev->struct_mutex);
2375
Dan Carpenter06812762015-10-02 18:14:22 +03002376 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002377}
2378
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002379static int count_irq_waiters(struct drm_i915_private *i915)
2380{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002381 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002382 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002383
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002384 for_each_engine(engine, i915)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002385 count += engine->irq_refcount;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002386
2387 return count;
2388}
2389
Chris Wilson1854d5c2015-04-07 16:20:32 +01002390static int i915_rps_boost_info(struct seq_file *m, void *data)
2391{
2392 struct drm_info_node *node = m->private;
2393 struct drm_device *dev = node->minor->dev;
2394 struct drm_i915_private *dev_priv = dev->dev_private;
2395 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002396
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002397 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2398 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2399 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2400 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2401 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2402 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2403 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2404 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2405 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson8d3afd72015-05-21 21:01:47 +01002406 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002407 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2408 struct drm_i915_file_private *file_priv = file->driver_priv;
2409 struct task_struct *task;
2410
2411 rcu_read_lock();
2412 task = pid_task(file->pid, PIDTYPE_PID);
2413 seq_printf(m, "%s [%d]: %d boosts%s\n",
2414 task ? task->comm : "<unknown>",
2415 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002416 file_priv->rps.boosts,
2417 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002418 rcu_read_unlock();
2419 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002420 seq_printf(m, "Semaphore boosts: %d%s\n",
2421 dev_priv->rps.semaphores.boosts,
2422 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2423 seq_printf(m, "MMIO flip boosts: %d%s\n",
2424 dev_priv->rps.mmioflips.boosts,
2425 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002426 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002427 spin_unlock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002428
Chris Wilson8d3afd72015-05-21 21:01:47 +01002429 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002430}
2431
Ben Widawsky63573eb2013-07-04 11:02:07 -07002432static int i915_llc(struct seq_file *m, void *data)
2433{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002434 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002435 struct drm_device *dev = node->minor->dev;
2436 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002437 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002438
Ben Widawsky63573eb2013-07-04 11:02:07 -07002439 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002440 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2441 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002442
2443 return 0;
2444}
2445
Alex Daifdf5d352015-08-12 15:43:37 +01002446static int i915_guc_load_status_info(struct seq_file *m, void *data)
2447{
2448 struct drm_info_node *node = m->private;
2449 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2450 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2451 u32 tmp, i;
2452
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002453 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002454 return 0;
2455
2456 seq_printf(m, "GuC firmware status:\n");
2457 seq_printf(m, "\tpath: %s\n",
2458 guc_fw->guc_fw_path);
2459 seq_printf(m, "\tfetch: %s\n",
2460 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2461 seq_printf(m, "\tload: %s\n",
2462 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2463 seq_printf(m, "\tversion wanted: %d.%d\n",
2464 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2465 seq_printf(m, "\tversion found: %d.%d\n",
2466 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002467 seq_printf(m, "\theader: offset is %d; size = %d\n",
2468 guc_fw->header_offset, guc_fw->header_size);
2469 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2470 guc_fw->ucode_offset, guc_fw->ucode_size);
2471 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2472 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002473
2474 tmp = I915_READ(GUC_STATUS);
2475
2476 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2477 seq_printf(m, "\tBootrom status = 0x%x\n",
2478 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2479 seq_printf(m, "\tuKernel status = 0x%x\n",
2480 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2481 seq_printf(m, "\tMIA Core status = 0x%x\n",
2482 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2483 seq_puts(m, "\nScratch registers:\n");
2484 for (i = 0; i < 16; i++)
2485 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2486
2487 return 0;
2488}
2489
Dave Gordon8b417c22015-08-12 15:43:44 +01002490static void i915_guc_client_info(struct seq_file *m,
2491 struct drm_i915_private *dev_priv,
2492 struct i915_guc_client *client)
2493{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002494 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002495 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002496
2497 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2498 client->priority, client->ctx_index, client->proc_desc_offset);
2499 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2500 client->doorbell_id, client->doorbell_offset, client->cookie);
2501 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2502 client->wq_size, client->wq_offset, client->wq_tail);
2503
2504 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2505 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2506 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2507
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002508 for_each_engine(engine, dev_priv) {
Dave Gordon8b417c22015-08-12 15:43:44 +01002509 seq_printf(m, "\tSubmissions: %llu %s\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002510 client->submissions[engine->guc_id],
2511 engine->name);
2512 tot += client->submissions[engine->guc_id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002513 }
2514 seq_printf(m, "\tTotal: %llu\n", tot);
2515}
2516
2517static int i915_guc_info(struct seq_file *m, void *data)
2518{
2519 struct drm_info_node *node = m->private;
2520 struct drm_device *dev = node->minor->dev;
2521 struct drm_i915_private *dev_priv = dev->dev_private;
2522 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002523 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002524 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002525 u64 total = 0;
2526
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002527 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002528 return 0;
2529
Alex Dai5a843302015-12-02 16:56:29 -08002530 if (mutex_lock_interruptible(&dev->struct_mutex))
2531 return 0;
2532
Dave Gordon8b417c22015-08-12 15:43:44 +01002533 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002534 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002535 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002536 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002537
2538 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002539
2540 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2541 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2542 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2543 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2544 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2545
2546 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002547 for_each_engine(engine, dev_priv) {
Alex Dai397097b2016-01-23 11:58:14 -08002548 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002549 engine->name, guc.submissions[engine->guc_id],
2550 guc.last_seqno[engine->guc_id]);
2551 total += guc.submissions[engine->guc_id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002552 }
2553 seq_printf(m, "\t%s: %llu\n", "Total", total);
2554
2555 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2556 i915_guc_client_info(m, dev_priv, &client);
2557
2558 /* Add more as required ... */
2559
2560 return 0;
2561}
2562
Alex Dai4c7e77f2015-08-12 15:43:40 +01002563static int i915_guc_log_dump(struct seq_file *m, void *data)
2564{
2565 struct drm_info_node *node = m->private;
2566 struct drm_device *dev = node->minor->dev;
2567 struct drm_i915_private *dev_priv = dev->dev_private;
2568 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2569 u32 *log;
2570 int i = 0, pg;
2571
2572 if (!log_obj)
2573 return 0;
2574
2575 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2576 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2577
2578 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2579 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2580 *(log + i), *(log + i + 1),
2581 *(log + i + 2), *(log + i + 3));
2582
2583 kunmap_atomic(log);
2584 }
2585
2586 seq_putc(m, '\n');
2587
2588 return 0;
2589}
2590
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002591static int i915_edp_psr_status(struct seq_file *m, void *data)
2592{
2593 struct drm_info_node *node = m->private;
2594 struct drm_device *dev = node->minor->dev;
2595 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002596 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002597 u32 stat[3];
2598 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002599 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002600
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002601 if (!HAS_PSR(dev)) {
2602 seq_puts(m, "PSR not supported\n");
2603 return 0;
2604 }
2605
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002606 intel_runtime_pm_get(dev_priv);
2607
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002608 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002609 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2610 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002611 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002612 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002613 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2614 dev_priv->psr.busy_frontbuffer_bits);
2615 seq_printf(m, "Re-enable work scheduled: %s\n",
2616 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002617
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002618 if (HAS_DDI(dev))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002619 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002620 else {
2621 for_each_pipe(dev_priv, pipe) {
2622 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2623 VLV_EDP_PSR_CURR_STATE_MASK;
2624 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2625 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2626 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002627 }
2628 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002629
2630 seq_printf(m, "Main link in standby mode: %s\n",
2631 yesno(dev_priv->psr.link_standby));
2632
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002633 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002634
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002635 if (!HAS_DDI(dev))
2636 for_each_pipe(dev_priv, pipe) {
2637 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2638 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2639 seq_printf(m, " pipe %c", pipe_name(pipe));
2640 }
2641 seq_puts(m, "\n");
2642
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002643 /*
2644 * VLV/CHV PSR has no kind of performance counter
2645 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2646 */
2647 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002648 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002649 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002650
2651 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2652 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002653 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002654
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002655 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002656 return 0;
2657}
2658
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002659static int i915_sink_crc(struct seq_file *m, void *data)
2660{
2661 struct drm_info_node *node = m->private;
2662 struct drm_device *dev = node->minor->dev;
2663 struct intel_encoder *encoder;
2664 struct intel_connector *connector;
2665 struct intel_dp *intel_dp = NULL;
2666 int ret;
2667 u8 crc[6];
2668
2669 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002670 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002671
2672 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2673 continue;
2674
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002675 if (!connector->base.encoder)
2676 continue;
2677
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002678 encoder = to_intel_encoder(connector->base.encoder);
2679 if (encoder->type != INTEL_OUTPUT_EDP)
2680 continue;
2681
2682 intel_dp = enc_to_intel_dp(&encoder->base);
2683
2684 ret = intel_dp_sink_crc(intel_dp, crc);
2685 if (ret)
2686 goto out;
2687
2688 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2689 crc[0], crc[1], crc[2],
2690 crc[3], crc[4], crc[5]);
2691 goto out;
2692 }
2693 ret = -ENODEV;
2694out:
2695 drm_modeset_unlock_all(dev);
2696 return ret;
2697}
2698
Jesse Barnesec013e72013-08-20 10:29:23 +01002699static int i915_energy_uJ(struct seq_file *m, void *data)
2700{
2701 struct drm_info_node *node = m->private;
2702 struct drm_device *dev = node->minor->dev;
2703 struct drm_i915_private *dev_priv = dev->dev_private;
2704 u64 power;
2705 u32 units;
2706
2707 if (INTEL_INFO(dev)->gen < 6)
2708 return -ENODEV;
2709
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002710 intel_runtime_pm_get(dev_priv);
2711
Jesse Barnesec013e72013-08-20 10:29:23 +01002712 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2713 power = (power & 0x1f00) >> 8;
2714 units = 1000000 / (1 << power); /* convert to uJ */
2715 power = I915_READ(MCH_SECP_NRG_STTS);
2716 power *= units;
2717
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002718 intel_runtime_pm_put(dev_priv);
2719
Jesse Barnesec013e72013-08-20 10:29:23 +01002720 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002721
2722 return 0;
2723}
2724
Damien Lespiau6455c872015-06-04 18:23:57 +01002725static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002726{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002727 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002728 struct drm_device *dev = node->minor->dev;
2729 struct drm_i915_private *dev_priv = dev->dev_private;
2730
Chris Wilsona156e642016-04-03 14:14:21 +01002731 if (!HAS_RUNTIME_PM(dev_priv))
2732 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002733
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002734 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002735 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002736 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002737#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002738 seq_printf(m, "Usage count: %d\n",
2739 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002740#else
2741 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2742#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002743 seq_printf(m, "PCI device power state: %s [%d]\n",
2744 pci_power_name(dev_priv->dev->pdev->current_state),
2745 dev_priv->dev->pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002746
Jesse Barnesec013e72013-08-20 10:29:23 +01002747 return 0;
2748}
2749
Imre Deak1da51582013-11-25 17:15:35 +02002750static int i915_power_domain_info(struct seq_file *m, void *unused)
2751{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002752 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002753 struct drm_device *dev = node->minor->dev;
2754 struct drm_i915_private *dev_priv = dev->dev_private;
2755 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2756 int i;
2757
2758 mutex_lock(&power_domains->lock);
2759
2760 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2761 for (i = 0; i < power_domains->power_well_count; i++) {
2762 struct i915_power_well *power_well;
2763 enum intel_display_power_domain power_domain;
2764
2765 power_well = &power_domains->power_wells[i];
2766 seq_printf(m, "%-25s %d\n", power_well->name,
2767 power_well->count);
2768
2769 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2770 power_domain++) {
2771 if (!(BIT(power_domain) & power_well->domains))
2772 continue;
2773
2774 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002775 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002776 power_domains->domain_use_count[power_domain]);
2777 }
2778 }
2779
2780 mutex_unlock(&power_domains->lock);
2781
2782 return 0;
2783}
2784
Damien Lespiaub7cec662015-10-27 14:47:01 +02002785static int i915_dmc_info(struct seq_file *m, void *unused)
2786{
2787 struct drm_info_node *node = m->private;
2788 struct drm_device *dev = node->minor->dev;
2789 struct drm_i915_private *dev_priv = dev->dev_private;
2790 struct intel_csr *csr;
2791
2792 if (!HAS_CSR(dev)) {
2793 seq_puts(m, "not supported\n");
2794 return 0;
2795 }
2796
2797 csr = &dev_priv->csr;
2798
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002799 intel_runtime_pm_get(dev_priv);
2800
Damien Lespiaub7cec662015-10-27 14:47:01 +02002801 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2802 seq_printf(m, "path: %s\n", csr->fw_path);
2803
2804 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002805 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002806
2807 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2808 CSR_VERSION_MINOR(csr->version));
2809
Damien Lespiau83372062015-10-30 17:53:32 +02002810 if (IS_SKYLAKE(dev) && csr->version >= CSR_VERSION(1, 6)) {
2811 seq_printf(m, "DC3 -> DC5 count: %d\n",
2812 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2813 seq_printf(m, "DC5 -> DC6 count: %d\n",
2814 I915_READ(SKL_CSR_DC5_DC6_COUNT));
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002815 } else if (IS_BROXTON(dev) && csr->version >= CSR_VERSION(1, 4)) {
2816 seq_printf(m, "DC3 -> DC5 count: %d\n",
2817 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002818 }
2819
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002820out:
2821 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2822 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2823 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2824
Damien Lespiau83372062015-10-30 17:53:32 +02002825 intel_runtime_pm_put(dev_priv);
2826
Damien Lespiaub7cec662015-10-27 14:47:01 +02002827 return 0;
2828}
2829
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002830static void intel_seq_print_mode(struct seq_file *m, int tabs,
2831 struct drm_display_mode *mode)
2832{
2833 int i;
2834
2835 for (i = 0; i < tabs; i++)
2836 seq_putc(m, '\t');
2837
2838 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",
2839 mode->base.id, mode->name,
2840 mode->vrefresh, mode->clock,
2841 mode->hdisplay, mode->hsync_start,
2842 mode->hsync_end, mode->htotal,
2843 mode->vdisplay, mode->vsync_start,
2844 mode->vsync_end, mode->vtotal,
2845 mode->type, mode->flags);
2846}
2847
2848static void intel_encoder_info(struct seq_file *m,
2849 struct intel_crtc *intel_crtc,
2850 struct intel_encoder *intel_encoder)
2851{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002852 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002853 struct drm_device *dev = node->minor->dev;
2854 struct drm_crtc *crtc = &intel_crtc->base;
2855 struct intel_connector *intel_connector;
2856 struct drm_encoder *encoder;
2857
2858 encoder = &intel_encoder->base;
2859 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002860 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002861 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2862 struct drm_connector *connector = &intel_connector->base;
2863 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2864 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002865 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002866 drm_get_connector_status_name(connector->status));
2867 if (connector->status == connector_status_connected) {
2868 struct drm_display_mode *mode = &crtc->mode;
2869 seq_printf(m, ", mode:\n");
2870 intel_seq_print_mode(m, 2, mode);
2871 } else {
2872 seq_putc(m, '\n');
2873 }
2874 }
2875}
2876
2877static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2878{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002879 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002880 struct drm_device *dev = node->minor->dev;
2881 struct drm_crtc *crtc = &intel_crtc->base;
2882 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002883 struct drm_plane_state *plane_state = crtc->primary->state;
2884 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002885
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002886 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002887 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002888 fb->base.id, plane_state->src_x >> 16,
2889 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002890 else
2891 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002892 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2893 intel_encoder_info(m, intel_crtc, intel_encoder);
2894}
2895
2896static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2897{
2898 struct drm_display_mode *mode = panel->fixed_mode;
2899
2900 seq_printf(m, "\tfixed mode:\n");
2901 intel_seq_print_mode(m, 2, mode);
2902}
2903
2904static void intel_dp_info(struct seq_file *m,
2905 struct intel_connector *intel_connector)
2906{
2907 struct intel_encoder *intel_encoder = intel_connector->encoder;
2908 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2909
2910 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002911 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002912 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2913 intel_panel_info(m, &intel_connector->panel);
2914}
2915
Libin Yang3d52ccf2015-12-02 14:09:44 +08002916static void intel_dp_mst_info(struct seq_file *m,
2917 struct intel_connector *intel_connector)
2918{
2919 struct intel_encoder *intel_encoder = intel_connector->encoder;
2920 struct intel_dp_mst_encoder *intel_mst =
2921 enc_to_mst(&intel_encoder->base);
2922 struct intel_digital_port *intel_dig_port = intel_mst->primary;
2923 struct intel_dp *intel_dp = &intel_dig_port->dp;
2924 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
2925 intel_connector->port);
2926
2927 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
2928}
2929
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002930static void intel_hdmi_info(struct seq_file *m,
2931 struct intel_connector *intel_connector)
2932{
2933 struct intel_encoder *intel_encoder = intel_connector->encoder;
2934 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2935
Jani Nikula742f4912015-09-03 11:16:09 +03002936 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002937}
2938
2939static void intel_lvds_info(struct seq_file *m,
2940 struct intel_connector *intel_connector)
2941{
2942 intel_panel_info(m, &intel_connector->panel);
2943}
2944
2945static void intel_connector_info(struct seq_file *m,
2946 struct drm_connector *connector)
2947{
2948 struct intel_connector *intel_connector = to_intel_connector(connector);
2949 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002950 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002951
2952 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002953 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002954 drm_get_connector_status_name(connector->status));
2955 if (connector->status == connector_status_connected) {
2956 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2957 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2958 connector->display_info.width_mm,
2959 connector->display_info.height_mm);
2960 seq_printf(m, "\tsubpixel order: %s\n",
2961 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2962 seq_printf(m, "\tCEA rev: %d\n",
2963 connector->display_info.cea_rev);
2964 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002965 if (intel_encoder) {
2966 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2967 intel_encoder->type == INTEL_OUTPUT_EDP)
2968 intel_dp_info(m, intel_connector);
2969 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2970 intel_hdmi_info(m, intel_connector);
2971 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2972 intel_lvds_info(m, intel_connector);
Libin Yang3d52ccf2015-12-02 14:09:44 +08002973 else if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
2974 intel_dp_mst_info(m, intel_connector);
Dave Airlie36cd7442014-05-02 13:44:18 +10002975 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002976
Jesse Barnesf103fc72014-02-20 12:39:57 -08002977 seq_printf(m, "\tmodes:\n");
2978 list_for_each_entry(mode, &connector->modes, head)
2979 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002980}
2981
Chris Wilson065f2ec2014-03-12 09:13:13 +00002982static bool cursor_active(struct drm_device *dev, int pipe)
2983{
2984 struct drm_i915_private *dev_priv = dev->dev_private;
2985 u32 state;
2986
2987 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002988 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002989 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002990 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002991
2992 return state;
2993}
2994
2995static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2996{
2997 struct drm_i915_private *dev_priv = dev->dev_private;
2998 u32 pos;
2999
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003000 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00003001
3002 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3003 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3004 *x = -*x;
3005
3006 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3007 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3008 *y = -*y;
3009
3010 return cursor_active(dev, pipe);
3011}
3012
Robert Fekete3abc4e02015-10-27 16:58:32 +01003013static const char *plane_type(enum drm_plane_type type)
3014{
3015 switch (type) {
3016 case DRM_PLANE_TYPE_OVERLAY:
3017 return "OVL";
3018 case DRM_PLANE_TYPE_PRIMARY:
3019 return "PRI";
3020 case DRM_PLANE_TYPE_CURSOR:
3021 return "CUR";
3022 /*
3023 * Deliberately omitting default: to generate compiler warnings
3024 * when a new drm_plane_type gets added.
3025 */
3026 }
3027
3028 return "unknown";
3029}
3030
3031static const char *plane_rotation(unsigned int rotation)
3032{
3033 static char buf[48];
3034 /*
3035 * According to doc only one DRM_ROTATE_ is allowed but this
3036 * will print them all to visualize if the values are misused
3037 */
3038 snprintf(buf, sizeof(buf),
3039 "%s%s%s%s%s%s(0x%08x)",
3040 (rotation & BIT(DRM_ROTATE_0)) ? "0 " : "",
3041 (rotation & BIT(DRM_ROTATE_90)) ? "90 " : "",
3042 (rotation & BIT(DRM_ROTATE_180)) ? "180 " : "",
3043 (rotation & BIT(DRM_ROTATE_270)) ? "270 " : "",
3044 (rotation & BIT(DRM_REFLECT_X)) ? "FLIPX " : "",
3045 (rotation & BIT(DRM_REFLECT_Y)) ? "FLIPY " : "",
3046 rotation);
3047
3048 return buf;
3049}
3050
3051static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3052{
3053 struct drm_info_node *node = m->private;
3054 struct drm_device *dev = node->minor->dev;
3055 struct intel_plane *intel_plane;
3056
3057 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3058 struct drm_plane_state *state;
3059 struct drm_plane *plane = &intel_plane->base;
3060
3061 if (!plane->state) {
3062 seq_puts(m, "plane->state is NULL!\n");
3063 continue;
3064 }
3065
3066 state = plane->state;
3067
3068 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",
3069 plane->base.id,
3070 plane_type(intel_plane->base.type),
3071 state->crtc_x, state->crtc_y,
3072 state->crtc_w, state->crtc_h,
3073 (state->src_x >> 16),
3074 ((state->src_x & 0xffff) * 15625) >> 10,
3075 (state->src_y >> 16),
3076 ((state->src_y & 0xffff) * 15625) >> 10,
3077 (state->src_w >> 16),
3078 ((state->src_w & 0xffff) * 15625) >> 10,
3079 (state->src_h >> 16),
3080 ((state->src_h & 0xffff) * 15625) >> 10,
3081 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3082 plane_rotation(state->rotation));
3083 }
3084}
3085
3086static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3087{
3088 struct intel_crtc_state *pipe_config;
3089 int num_scalers = intel_crtc->num_scalers;
3090 int i;
3091
3092 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3093
3094 /* Not all platformas have a scaler */
3095 if (num_scalers) {
3096 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3097 num_scalers,
3098 pipe_config->scaler_state.scaler_users,
3099 pipe_config->scaler_state.scaler_id);
3100
3101 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3102 struct intel_scaler *sc =
3103 &pipe_config->scaler_state.scalers[i];
3104
3105 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3106 i, yesno(sc->in_use), sc->mode);
3107 }
3108 seq_puts(m, "\n");
3109 } else {
3110 seq_puts(m, "\tNo scalers available on this platform\n");
3111 }
3112}
3113
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003114static int i915_display_info(struct seq_file *m, void *unused)
3115{
Damien Lespiau9f25d002014-05-13 15:30:28 +01003116 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003117 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003118 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003119 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003120 struct drm_connector *connector;
3121
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003122 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003123 drm_modeset_lock_all(dev);
3124 seq_printf(m, "CRTC info\n");
3125 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003126 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003127 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003128 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003129 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003130
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003131 pipe_config = to_intel_crtc_state(crtc->base.state);
3132
Robert Fekete3abc4e02015-10-27 16:58:32 +01003133 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003134 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003135 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003136 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3137 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3138
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003139 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003140 intel_crtc_info(m, crtc);
3141
Paulo Zanonia23dc652014-04-01 14:55:11 -03003142 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003143 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 +03003144 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003145 x, y, crtc->base.cursor->state->crtc_w,
3146 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003147 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003148 intel_scaler_info(m, crtc);
3149 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003150 }
Daniel Vettercace8412014-05-22 17:56:31 +02003151
3152 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3153 yesno(!crtc->cpu_fifo_underrun_disabled),
3154 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003155 }
3156
3157 seq_printf(m, "\n");
3158 seq_printf(m, "Connector info\n");
3159 seq_printf(m, "--------------\n");
3160 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3161 intel_connector_info(m, connector);
3162 }
3163 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003164 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003165
3166 return 0;
3167}
3168
Ben Widawskye04934c2014-06-30 09:53:42 -07003169static int i915_semaphore_status(struct seq_file *m, void *unused)
3170{
3171 struct drm_info_node *node = (struct drm_info_node *) m->private;
3172 struct drm_device *dev = node->minor->dev;
3173 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003174 struct intel_engine_cs *engine;
Ben Widawskye04934c2014-06-30 09:53:42 -07003175 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
Dave Gordonc3232b12016-03-23 18:19:53 +00003176 enum intel_engine_id id;
3177 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003178
3179 if (!i915_semaphore_is_enabled(dev)) {
3180 seq_puts(m, "Semaphores are disabled\n");
3181 return 0;
3182 }
3183
3184 ret = mutex_lock_interruptible(&dev->struct_mutex);
3185 if (ret)
3186 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003187 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003188
3189 if (IS_BROADWELL(dev)) {
3190 struct page *page;
3191 uint64_t *seqno;
3192
3193 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3194
3195 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003196 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003197 uint64_t offset;
3198
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003199 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003200
3201 seq_puts(m, " Last signal:");
3202 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003203 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003204 seq_printf(m, "0x%08llx (0x%02llx) ",
3205 seqno[offset], offset * 8);
3206 }
3207 seq_putc(m, '\n');
3208
3209 seq_puts(m, " Last wait: ");
3210 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003211 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003212 seq_printf(m, "0x%08llx (0x%02llx) ",
3213 seqno[offset], offset * 8);
3214 }
3215 seq_putc(m, '\n');
3216
3217 }
3218 kunmap_atomic(seqno);
3219 } else {
3220 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003221 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003222 for (j = 0; j < num_rings; j++)
3223 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003224 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003225 seq_putc(m, '\n');
3226 }
3227
3228 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003229 for_each_engine(engine, dev_priv) {
3230 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003231 seq_printf(m, " 0x%08x ",
3232 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003233 seq_putc(m, '\n');
3234 }
3235 seq_putc(m, '\n');
3236
Paulo Zanoni03872062014-07-09 14:31:57 -03003237 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003238 mutex_unlock(&dev->struct_mutex);
3239 return 0;
3240}
3241
Daniel Vetter728e29d2014-06-25 22:01:53 +03003242static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3243{
3244 struct drm_info_node *node = (struct drm_info_node *) m->private;
3245 struct drm_device *dev = node->minor->dev;
3246 struct drm_i915_private *dev_priv = dev->dev_private;
3247 int i;
3248
3249 drm_modeset_lock_all(dev);
3250 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3251 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3252
3253 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003254 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3255 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003256 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003257 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3258 seq_printf(m, " dpll_md: 0x%08x\n",
3259 pll->config.hw_state.dpll_md);
3260 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3261 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3262 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003263 }
3264 drm_modeset_unlock_all(dev);
3265
3266 return 0;
3267}
3268
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003269static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003270{
3271 int i;
3272 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003273 struct intel_engine_cs *engine;
Arun Siluvery888b5992014-08-26 14:44:51 +01003274 struct drm_info_node *node = (struct drm_info_node *) m->private;
3275 struct drm_device *dev = node->minor->dev;
3276 struct drm_i915_private *dev_priv = dev->dev_private;
Arun Siluvery33136b02016-01-21 21:43:47 +00003277 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003278 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003279
Arun Siluvery888b5992014-08-26 14:44:51 +01003280 ret = mutex_lock_interruptible(&dev->struct_mutex);
3281 if (ret)
3282 return ret;
3283
3284 intel_runtime_pm_get(dev_priv);
3285
Arun Siluvery33136b02016-01-21 21:43:47 +00003286 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003287 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003288 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003289 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003290 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003291 i915_reg_t addr;
3292 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003293 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003294
Arun Siluvery33136b02016-01-21 21:43:47 +00003295 addr = workarounds->reg[i].addr;
3296 mask = workarounds->reg[i].mask;
3297 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003298 read = I915_READ(addr);
3299 ok = (value & mask) == (read & mask);
3300 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 +02003301 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003302 }
3303
3304 intel_runtime_pm_put(dev_priv);
3305 mutex_unlock(&dev->struct_mutex);
3306
3307 return 0;
3308}
3309
Damien Lespiauc5511e42014-11-04 17:06:51 +00003310static int i915_ddb_info(struct seq_file *m, void *unused)
3311{
3312 struct drm_info_node *node = m->private;
3313 struct drm_device *dev = node->minor->dev;
3314 struct drm_i915_private *dev_priv = dev->dev_private;
3315 struct skl_ddb_allocation *ddb;
3316 struct skl_ddb_entry *entry;
3317 enum pipe pipe;
3318 int plane;
3319
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003320 if (INTEL_INFO(dev)->gen < 9)
3321 return 0;
3322
Damien Lespiauc5511e42014-11-04 17:06:51 +00003323 drm_modeset_lock_all(dev);
3324
3325 ddb = &dev_priv->wm.skl_hw.ddb;
3326
3327 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3328
3329 for_each_pipe(dev_priv, pipe) {
3330 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3331
Damien Lespiaudd740782015-02-28 14:54:08 +00003332 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003333 entry = &ddb->plane[pipe][plane];
3334 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3335 entry->start, entry->end,
3336 skl_ddb_entry_size(entry));
3337 }
3338
Matt Roper4969d332015-09-24 15:53:10 -07003339 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003340 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3341 entry->end, skl_ddb_entry_size(entry));
3342 }
3343
3344 drm_modeset_unlock_all(dev);
3345
3346 return 0;
3347}
3348
Vandana Kannana54746e2015-03-03 20:53:10 +05303349static void drrs_status_per_crtc(struct seq_file *m,
3350 struct drm_device *dev, struct intel_crtc *intel_crtc)
3351{
3352 struct intel_encoder *intel_encoder;
3353 struct drm_i915_private *dev_priv = dev->dev_private;
3354 struct i915_drrs *drrs = &dev_priv->drrs;
3355 int vrefresh = 0;
3356
3357 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3358 /* Encoder connected on this CRTC */
3359 switch (intel_encoder->type) {
3360 case INTEL_OUTPUT_EDP:
3361 seq_puts(m, "eDP:\n");
3362 break;
3363 case INTEL_OUTPUT_DSI:
3364 seq_puts(m, "DSI:\n");
3365 break;
3366 case INTEL_OUTPUT_HDMI:
3367 seq_puts(m, "HDMI:\n");
3368 break;
3369 case INTEL_OUTPUT_DISPLAYPORT:
3370 seq_puts(m, "DP:\n");
3371 break;
3372 default:
3373 seq_printf(m, "Other encoder (id=%d).\n",
3374 intel_encoder->type);
3375 return;
3376 }
3377 }
3378
3379 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3380 seq_puts(m, "\tVBT: DRRS_type: Static");
3381 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3382 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3383 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3384 seq_puts(m, "\tVBT: DRRS_type: None");
3385 else
3386 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3387
3388 seq_puts(m, "\n\n");
3389
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003390 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303391 struct intel_panel *panel;
3392
3393 mutex_lock(&drrs->mutex);
3394 /* DRRS Supported */
3395 seq_puts(m, "\tDRRS Supported: Yes\n");
3396
3397 /* disable_drrs() will make drrs->dp NULL */
3398 if (!drrs->dp) {
3399 seq_puts(m, "Idleness DRRS: Disabled");
3400 mutex_unlock(&drrs->mutex);
3401 return;
3402 }
3403
3404 panel = &drrs->dp->attached_connector->panel;
3405 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3406 drrs->busy_frontbuffer_bits);
3407
3408 seq_puts(m, "\n\t\t");
3409 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3410 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3411 vrefresh = panel->fixed_mode->vrefresh;
3412 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3413 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3414 vrefresh = panel->downclock_mode->vrefresh;
3415 } else {
3416 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3417 drrs->refresh_rate_type);
3418 mutex_unlock(&drrs->mutex);
3419 return;
3420 }
3421 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3422
3423 seq_puts(m, "\n\t\t");
3424 mutex_unlock(&drrs->mutex);
3425 } else {
3426 /* DRRS not supported. Print the VBT parameter*/
3427 seq_puts(m, "\tDRRS Supported : No");
3428 }
3429 seq_puts(m, "\n");
3430}
3431
3432static int i915_drrs_status(struct seq_file *m, void *unused)
3433{
3434 struct drm_info_node *node = m->private;
3435 struct drm_device *dev = node->minor->dev;
3436 struct intel_crtc *intel_crtc;
3437 int active_crtc_cnt = 0;
3438
3439 for_each_intel_crtc(dev, intel_crtc) {
3440 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3441
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003442 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303443 active_crtc_cnt++;
3444 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3445
3446 drrs_status_per_crtc(m, dev, intel_crtc);
3447 }
3448
3449 drm_modeset_unlock(&intel_crtc->base.mutex);
3450 }
3451
3452 if (!active_crtc_cnt)
3453 seq_puts(m, "No active crtc found\n");
3454
3455 return 0;
3456}
3457
Damien Lespiau07144422013-10-15 18:55:40 +01003458struct pipe_crc_info {
3459 const char *name;
3460 struct drm_device *dev;
3461 enum pipe pipe;
3462};
3463
Dave Airlie11bed952014-05-12 15:22:27 +10003464static int i915_dp_mst_info(struct seq_file *m, void *unused)
3465{
3466 struct drm_info_node *node = (struct drm_info_node *) m->private;
3467 struct drm_device *dev = node->minor->dev;
3468 struct drm_encoder *encoder;
3469 struct intel_encoder *intel_encoder;
3470 struct intel_digital_port *intel_dig_port;
3471 drm_modeset_lock_all(dev);
3472 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3473 intel_encoder = to_intel_encoder(encoder);
3474 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3475 continue;
3476 intel_dig_port = enc_to_dig_port(encoder);
3477 if (!intel_dig_port->dp.can_mst)
3478 continue;
3479
3480 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
Mika Kuoppala58174462014-02-25 17:11:26 +02004779 i915_handle_error(dev, val,
4780 "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))
4929 i915_gem_retire_requests(dev);
4930
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
Ville Syrjäläffe02b42015-02-02 19:09:50 +02005003 intel_set_rps(dev, 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
Ville Syrjäläffe02b42015-02-02 19:09:50 +02005070 intel_set_rps(dev, 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}