blob: b29ba16c90b31c2d5662655b5412307d12bf0ff1 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Chris Wilsonf13d3f72010-09-20 17:36:15 +010043enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010044 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010046 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047};
Ben Gamari433e12f2009-02-17 20:08:51 -050048
Damien Lespiau497666d2013-10-15 18:55:39 +010049/* As the drm_debugfs_init() routines are called before dev->dev_private is
50 * allocated we need to hook into the minor for release. */
51static int
52drm_add_fake_info_node(struct drm_minor *minor,
53 struct dentry *ent,
54 const void *key)
55{
56 struct drm_info_node *node;
57
58 node = kmalloc(sizeof(*node), GFP_KERNEL);
59 if (node == NULL) {
60 debugfs_remove(ent);
61 return -ENOMEM;
62 }
63
64 node->minor = minor;
65 node->dent = ent;
66 node->info_ent = (void *) key;
67
68 mutex_lock(&minor->debugfs_lock);
69 list_add(&node->list, &minor->debugfs_list);
70 mutex_unlock(&minor->debugfs_lock);
71
72 return 0;
73}
74
Chris Wilson70d39fe2010-08-25 16:03:34 +010075static int i915_capabilities(struct seq_file *m, void *data)
76{
Damien Lespiau9f25d002014-05-13 15:30:28 +010077 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010078 struct drm_device *dev = node->minor->dev;
79 const struct intel_device_info *info = INTEL_INFO(dev);
80
81 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030082 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010083#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
84#define SEP_SEMICOLON ;
85 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
86#undef PRINT_FLAG
87#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010088
89 return 0;
90}
Ben Gamari433e12f2009-02-17 20:08:51 -050091
Imre Deaka7363de2016-05-12 16:18:52 +030092static char get_active_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000093{
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010094 return obj->active ? '*' : ' ';
Chris Wilsona6172a82009-02-11 14:26:38 +000095}
96
Imre Deaka7363de2016-05-12 16:18:52 +030097static char get_pin_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +010098{
99 return obj->pin_display ? 'p' : ' ';
100}
101
Imre Deaka7363de2016-05-12 16:18:52 +0300102static char get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000103{
Akshay Joshi0206e352011-08-16 15:34:10 -0400104 switch (obj->tiling_mode) {
105 default:
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100106 case I915_TILING_NONE: return ' ';
107 case I915_TILING_X: return 'X';
108 case I915_TILING_Y: return 'Y';
Akshay Joshi0206e352011-08-16 15:34:10 -0400109 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000110}
111
Imre Deaka7363de2016-05-12 16:18:52 +0300112static char get_global_flag(struct drm_i915_gem_object *obj)
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700113{
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100114 return i915_gem_obj_to_ggtt(obj) ? 'g' : ' ';
115}
116
Imre Deaka7363de2016-05-12 16:18:52 +0300117static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100118{
119 return obj->mapping ? 'M' : ' ';
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700120}
121
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100122static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
123{
124 u64 size = 0;
125 struct i915_vma *vma;
126
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000127 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson596c5922016-02-26 11:03:20 +0000128 if (vma->is_ggtt && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100129 size += vma->node.size;
130 }
131
132 return size;
133}
134
Chris Wilson37811fc2010-08-25 22:45:57 +0100135static void
136describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
137{
Chris Wilsonb4716182015-04-27 13:41:17 +0100138 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000139 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700140 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800141 int pin_count = 0;
Dave Gordonc3232b12016-03-23 18:19:53 +0000142 enum intel_engine_id id;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800143
Chris Wilson188c1ab2016-04-03 14:14:20 +0100144 lockdep_assert_held(&obj->base.dev->struct_mutex);
145
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100146 seq_printf(m, "%pK: %c%c%c%c%c %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100147 &obj->base,
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100148 get_active_flag(obj),
Chris Wilson37811fc2010-08-25 22:45:57 +0100149 get_pin_flag(obj),
150 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700151 get_global_flag(obj),
Tvrtko Ursulinbe12a862016-04-15 11:34:52 +0100152 get_pin_mapped_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800153 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100154 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100155 obj->base.write_domain);
Dave Gordonc3232b12016-03-23 18:19:53 +0000156 for_each_engine_id(engine, dev_priv, id)
Chris Wilsonb4716182015-04-27 13:41:17 +0100157 seq_printf(m, "%x ",
Dave Gordonc3232b12016-03-23 18:19:53 +0000158 i915_gem_request_get_seqno(obj->last_read_req[id]));
Chris Wilsonb4716182015-04-27 13:41:17 +0100159 seq_printf(m, "] %x %x%s%s%s",
John Harrison97b2a6a2014-11-24 18:49:26 +0000160 i915_gem_request_get_seqno(obj->last_write_req),
161 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100162 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100163 obj->dirty ? " dirty" : "",
164 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
165 if (obj->base.name)
166 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000167 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800168 if (vma->pin_count > 0)
169 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300170 }
171 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100172 if (obj->pin_display)
173 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100174 if (obj->fence_reg != I915_FENCE_REG_NONE)
175 seq_printf(m, " (fence: %d)", obj->fence_reg);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000176 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100177 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson596c5922016-02-26 11:03:20 +0000178 vma->is_ggtt ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100179 vma->node.start, vma->node.size);
Chris Wilson596c5922016-02-26 11:03:20 +0000180 if (vma->is_ggtt)
181 seq_printf(m, ", type: %u", vma->ggtt_view.type);
182 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700183 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000184 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100185 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100186 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000187 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100188 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000189 *t++ = 'p';
190 if (obj->fault_mappable)
191 *t++ = 'f';
192 *t = '\0';
193 seq_printf(m, " (%s mappable)", s);
194 }
Chris Wilsonb4716182015-04-27 13:41:17 +0100195 if (obj->last_write_req != NULL)
John Harrison41c52412014-11-24 18:49:43 +0000196 seq_printf(m, " (%s)",
Tvrtko Ursulin666796d2016-03-16 11:00:39 +0000197 i915_gem_request_get_engine(obj->last_write_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200198 if (obj->frontbuffer_bits)
199 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100200}
201
Ben Gamari433e12f2009-02-17 20:08:51 -0500202static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500203{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100204 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500205 uintptr_t list = (uintptr_t) node->info_ent->data;
206 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500207 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300208 struct drm_i915_private *dev_priv = to_i915(dev);
209 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Ben Widawskyca191b12013-07-31 17:00:14 -0700210 struct i915_vma *vma;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300211 u64 total_obj_size, total_gtt_size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100212 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100213
214 ret = mutex_lock_interruptible(&dev->struct_mutex);
215 if (ret)
216 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500217
Ben Widawskyca191b12013-07-31 17:00:14 -0700218 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500219 switch (list) {
220 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100221 seq_puts(m, "Active:\n");
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300222 head = &ggtt->base.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500223 break;
224 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100225 seq_puts(m, "Inactive:\n");
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300226 head = &ggtt->base.inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500227 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500228 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100229 mutex_unlock(&dev->struct_mutex);
230 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500231 }
232
Chris Wilson8f2480f2010-09-26 11:44:19 +0100233 total_obj_size = total_gtt_size = count = 0;
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000234 list_for_each_entry(vma, head, vm_link) {
Ben Widawskyca191b12013-07-31 17:00:14 -0700235 seq_printf(m, " ");
236 describe_obj(m, vma->obj);
237 seq_printf(m, "\n");
238 total_obj_size += vma->obj->base.size;
239 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100240 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500241 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100242 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700243
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300244 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson8f2480f2010-09-26 11:44:19 +0100245 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500246 return 0;
247}
248
Chris Wilson6d2b88852013-08-07 18:30:54 +0100249static int obj_rank_by_stolen(void *priv,
250 struct list_head *A, struct list_head *B)
251{
252 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200253 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100254 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200255 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100256
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200257 if (a->stolen->start < b->stolen->start)
258 return -1;
259 if (a->stolen->start > b->stolen->start)
260 return 1;
261 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100262}
263
264static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
265{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100266 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100267 struct drm_device *dev = node->minor->dev;
268 struct drm_i915_private *dev_priv = dev->dev_private;
269 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300270 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100271 LIST_HEAD(stolen);
272 int count, ret;
273
274 ret = mutex_lock_interruptible(&dev->struct_mutex);
275 if (ret)
276 return ret;
277
278 total_obj_size = total_gtt_size = count = 0;
279 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
280 if (obj->stolen == NULL)
281 continue;
282
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200283 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100284
285 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100286 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100287 count++;
288 }
289 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
290 if (obj->stolen == NULL)
291 continue;
292
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200293 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100294
295 total_obj_size += obj->base.size;
296 count++;
297 }
298 list_sort(NULL, &stolen, obj_rank_by_stolen);
299 seq_puts(m, "Stolen:\n");
300 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200301 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100302 seq_puts(m, " ");
303 describe_obj(m, obj);
304 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200305 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100306 }
307 mutex_unlock(&dev->struct_mutex);
308
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300309 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100310 count, total_obj_size, total_gtt_size);
311 return 0;
312}
313
Chris Wilson6299f992010-11-24 12:23:44 +0000314#define count_objects(list, member) do { \
315 list_for_each_entry(obj, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100316 size += i915_gem_obj_total_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000317 ++count; \
318 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700319 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000320 ++mappable_count; \
321 } \
322 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400323} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000324
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100325struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000326 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300327 unsigned long count;
328 u64 total, unbound;
329 u64 global, shared;
330 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100331};
332
333static int per_file_stats(int id, void *ptr, void *data)
334{
335 struct drm_i915_gem_object *obj = ptr;
336 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000337 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100338
339 stats->count++;
340 stats->total += obj->base.size;
341
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000342 if (obj->base.name || obj->base.dma_buf)
343 stats->shared += obj->base.size;
344
Chris Wilson6313c202014-03-19 13:45:45 +0000345 if (USES_FULL_PPGTT(obj->base.dev)) {
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000346 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson6313c202014-03-19 13:45:45 +0000347 struct i915_hw_ppgtt *ppgtt;
348
349 if (!drm_mm_node_allocated(&vma->node))
350 continue;
351
Chris Wilson596c5922016-02-26 11:03:20 +0000352 if (vma->is_ggtt) {
Chris Wilson6313c202014-03-19 13:45:45 +0000353 stats->global += obj->base.size;
354 continue;
355 }
356
357 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200358 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000359 continue;
360
John Harrison41c52412014-11-24 18:49:43 +0000361 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000362 stats->active += obj->base.size;
363 else
364 stats->inactive += obj->base.size;
365
366 return 0;
367 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100368 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000369 if (i915_gem_obj_ggtt_bound(obj)) {
370 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000371 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000372 stats->active += obj->base.size;
373 else
374 stats->inactive += obj->base.size;
375 return 0;
376 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100377 }
378
Chris Wilson6313c202014-03-19 13:45:45 +0000379 if (!list_empty(&obj->global_list))
380 stats->unbound += obj->base.size;
381
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100382 return 0;
383}
384
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100385#define print_file_stats(m, name, stats) do { \
386 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300387 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 +0100388 name, \
389 stats.count, \
390 stats.total, \
391 stats.active, \
392 stats.inactive, \
393 stats.global, \
394 stats.shared, \
395 stats.unbound); \
396} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800397
398static void print_batch_pool_stats(struct seq_file *m,
399 struct drm_i915_private *dev_priv)
400{
401 struct drm_i915_gem_object *obj;
402 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000403 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000404 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800405
406 memset(&stats, 0, sizeof(stats));
407
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000408 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000409 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100410 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000411 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100412 batch_pool_link)
413 per_file_stats(0, obj, &stats);
414 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100415 }
Brad Volkin493018d2014-12-11 12:13:08 -0800416
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100417 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800418}
419
Chris Wilson15da9562016-05-24 14:53:43 +0100420static int per_file_ctx_stats(int id, void *ptr, void *data)
421{
422 struct i915_gem_context *ctx = ptr;
423 int n;
424
425 for (n = 0; n < ARRAY_SIZE(ctx->engine); n++) {
426 if (ctx->engine[n].state)
427 per_file_stats(0, ctx->engine[n].state, data);
428 if (ctx->engine[n].ringbuf)
429 per_file_stats(0, ctx->engine[n].ringbuf->obj, data);
430 }
431
432 return 0;
433}
434
435static void print_context_stats(struct seq_file *m,
436 struct drm_i915_private *dev_priv)
437{
438 struct file_stats stats;
439 struct drm_file *file;
440
441 memset(&stats, 0, sizeof(stats));
442
443 mutex_lock(&dev_priv->dev->struct_mutex);
444 if (dev_priv->kernel_context)
445 per_file_ctx_stats(0, dev_priv->kernel_context, &stats);
446
447 list_for_each_entry(file, &dev_priv->dev->filelist, lhead) {
448 struct drm_i915_file_private *fpriv = file->driver_priv;
449 idr_for_each(&fpriv->context_idr, per_file_ctx_stats, &stats);
450 }
451 mutex_unlock(&dev_priv->dev->struct_mutex);
452
453 print_file_stats(m, "[k]contexts", stats);
454}
455
Ben Widawskyca191b12013-07-31 17:00:14 -0700456#define count_vmas(list, member) do { \
457 list_for_each_entry(vma, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100458 size += i915_gem_obj_total_ggtt_size(vma->obj); \
Ben Widawskyca191b12013-07-31 17:00:14 -0700459 ++count; \
460 if (vma->obj->map_and_fenceable) { \
461 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
462 ++mappable_count; \
463 } \
464 } \
465} while (0)
466
467static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100468{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100469 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100470 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300471 struct drm_i915_private *dev_priv = to_i915(dev);
472 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200473 u32 count, mappable_count, purgeable_count;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300474 u64 size, mappable_size, purgeable_size;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100475 unsigned long pin_mapped_count = 0, pin_mapped_purgeable_count = 0;
476 u64 pin_mapped_size = 0, pin_mapped_purgeable_size = 0;
Chris Wilson6299f992010-11-24 12:23:44 +0000477 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100478 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700479 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100480 int ret;
481
482 ret = mutex_lock_interruptible(&dev->struct_mutex);
483 if (ret)
484 return ret;
485
Chris Wilson6299f992010-11-24 12:23:44 +0000486 seq_printf(m, "%u objects, %zu bytes\n",
487 dev_priv->mm.object_count,
488 dev_priv->mm.object_memory);
489
490 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700491 count_objects(&dev_priv->mm.bound_list, global_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300492 seq_printf(m, "%u [%u] objects, %llu [%llu] bytes in gtt\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000493 count, mappable_count, size, mappable_size);
494
495 size = count = mappable_size = mappable_count = 0;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300496 count_vmas(&ggtt->base.active_list, vm_link);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300497 seq_printf(m, " %u [%u] active objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000498 count, mappable_count, size, mappable_size);
499
500 size = count = mappable_size = mappable_count = 0;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300501 count_vmas(&ggtt->base.inactive_list, vm_link);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300502 seq_printf(m, " %u [%u] inactive objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000503 count, mappable_count, size, mappable_size);
504
Chris Wilsonb7abb712012-08-20 11:33:30 +0200505 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700506 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200507 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200508 if (obj->madv == I915_MADV_DONTNEED)
509 purgeable_size += obj->base.size, ++purgeable_count;
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100510 if (obj->mapping) {
511 pin_mapped_count++;
512 pin_mapped_size += obj->base.size;
513 if (obj->pages_pin_count == 0) {
514 pin_mapped_purgeable_count++;
515 pin_mapped_purgeable_size += obj->base.size;
516 }
517 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200518 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300519 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
Chris Wilson6c085a72012-08-20 11:40:46 +0200520
Chris Wilson6299f992010-11-24 12:23:44 +0000521 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700522 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000523 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700524 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000525 ++count;
526 }
Chris Wilson30154652015-04-07 17:28:24 +0100527 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700528 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000529 ++mappable_count;
530 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200531 if (obj->madv == I915_MADV_DONTNEED) {
532 purgeable_size += obj->base.size;
533 ++purgeable_count;
534 }
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100535 if (obj->mapping) {
536 pin_mapped_count++;
537 pin_mapped_size += obj->base.size;
538 if (obj->pages_pin_count == 0) {
539 pin_mapped_purgeable_count++;
540 pin_mapped_purgeable_size += obj->base.size;
541 }
542 }
Chris Wilson6299f992010-11-24 12:23:44 +0000543 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300544 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200545 purgeable_count, purgeable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300546 seq_printf(m, "%u pinned mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000547 mappable_count, mappable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300548 seq_printf(m, "%u fault mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000549 count, size);
Tvrtko Ursulinbe19b102016-04-15 11:34:53 +0100550 seq_printf(m,
551 "%lu [%lu] pin mapped objects, %llu [%llu] bytes [purgeable]\n",
552 pin_mapped_count, pin_mapped_purgeable_count,
553 pin_mapped_size, pin_mapped_purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000554
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300555 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300556 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100557
Damien Lespiau267f0c92013-06-24 22:59:48 +0100558 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800559 print_batch_pool_stats(m, dev_priv);
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200560 mutex_unlock(&dev->struct_mutex);
561
562 mutex_lock(&dev->filelist_mutex);
Chris Wilson15da9562016-05-24 14:53:43 +0100563 print_context_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100564 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
565 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900566 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100567
568 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000569 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100570 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100571 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100572 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900573 /*
574 * Although we have a valid reference on file->pid, that does
575 * not guarantee that the task_struct who called get_pid() is
576 * still alive (e.g. get_pid(current) => fork() => exit()).
577 * Therefore, we need to protect this ->comm access using RCU.
578 */
579 rcu_read_lock();
580 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800581 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900582 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100583 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +0200584 mutex_unlock(&dev->filelist_mutex);
Chris Wilson73aa8082010-09-30 11:46:12 +0100585
586 return 0;
587}
588
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100589static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000590{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100591 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000592 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100593 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000594 struct drm_i915_private *dev_priv = dev->dev_private;
595 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300596 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000597 int count, ret;
598
599 ret = mutex_lock_interruptible(&dev->struct_mutex);
600 if (ret)
601 return ret;
602
603 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700604 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800605 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100606 continue;
607
Damien Lespiau267f0c92013-06-24 22:59:48 +0100608 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000609 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100610 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000611 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100612 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000613 count++;
614 }
615
616 mutex_unlock(&dev->struct_mutex);
617
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300618 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000619 count, total_obj_size, total_gtt_size);
620
621 return 0;
622}
623
Maarten Lankhorst68858432016-05-17 15:07:52 +0200624static void i915_dump_pageflip(struct seq_file *m,
625 struct drm_i915_private *dev_priv,
626 struct intel_crtc *crtc,
627 struct intel_flip_work *work)
628{
629 const char pipe = pipe_name(crtc->pipe);
Maarten Lankhorst68858432016-05-17 15:07:52 +0200630 u32 pending;
Maarten Lankhorst143f73b32016-05-17 15:07:54 +0200631 int i;
Maarten Lankhorst68858432016-05-17 15:07:52 +0200632
633 pending = atomic_read(&work->pending);
634 if (pending) {
635 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
Maarten Lankhorst143f73b32016-05-17 15:07:54 +0200636 pipe, plane_name(crtc->plane));
Maarten Lankhorst68858432016-05-17 15:07:52 +0200637 } else {
638 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Maarten Lankhorst143f73b32016-05-17 15:07:54 +0200639 pipe, plane_name(crtc->plane));
Maarten Lankhorst68858432016-05-17 15:07:52 +0200640 }
Maarten Lankhorst68858432016-05-17 15:07:52 +0200641
Maarten Lankhorst143f73b32016-05-17 15:07:54 +0200642 for (i = 0; i < work->num_planes; i++) {
643 struct intel_plane_state *old_plane_state = work->old_plane_state[i];
644 struct drm_plane *plane = old_plane_state->base.plane;
645 struct drm_i915_gem_request *req = old_plane_state->wait_req;
646 struct intel_engine_cs *engine;
647
648 seq_printf(m, "[PLANE:%i] part of flip.\n", plane->base.id);
649
650 if (!req) {
651 seq_printf(m, "Plane not associated with any engine\n");
652 continue;
653 }
654
655 engine = i915_gem_request_get_engine(req);
656
657 seq_printf(m, "Plane blocked on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
Maarten Lankhorst68858432016-05-17 15:07:52 +0200658 engine->name,
Maarten Lankhorst143f73b32016-05-17 15:07:54 +0200659 i915_gem_request_get_seqno(req),
Maarten Lankhorst68858432016-05-17 15:07:52 +0200660 dev_priv->next_seqno,
661 engine->get_seqno(engine),
Maarten Lankhorst143f73b32016-05-17 15:07:54 +0200662 i915_gem_request_completed(req, true));
663 }
664
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +0200665 seq_printf(m, "Flip queued on frame %d, now %d\n",
666 pending ? work->flip_queued_vblank : -1,
Maarten Lankhorst68858432016-05-17 15:07:52 +0200667 intel_crtc_get_vblank_counter(crtc));
Maarten Lankhorst68858432016-05-17 15:07:52 +0200668}
669
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100670static int i915_gem_pageflip_info(struct seq_file *m, void *data)
671{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100672 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100673 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100674 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100675 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200676 int ret;
677
678 ret = mutex_lock_interruptible(&dev->struct_mutex);
679 if (ret)
680 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100681
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100682 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800683 const char pipe = pipe_name(crtc->pipe);
684 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200685 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100686
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200687 spin_lock_irq(&dev->event_lock);
Maarten Lankhorst68858432016-05-17 15:07:52 +0200688 if (list_empty(&crtc->flip_work)) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800689 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100690 pipe, plane);
691 } else {
Maarten Lankhorst68858432016-05-17 15:07:52 +0200692 list_for_each_entry(work, &crtc->flip_work, head) {
693 i915_dump_pageflip(m, dev_priv, crtc, work);
694 seq_puts(m, "\n");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100695 }
696 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200697 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100698 }
699
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200700 mutex_unlock(&dev->struct_mutex);
701
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100702 return 0;
703}
704
Brad Volkin493018d2014-12-11 12:13:08 -0800705static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
706{
707 struct drm_info_node *node = m->private;
708 struct drm_device *dev = node->minor->dev;
709 struct drm_i915_private *dev_priv = dev->dev_private;
710 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000711 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100712 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000713 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800714
715 ret = mutex_lock_interruptible(&dev->struct_mutex);
716 if (ret)
717 return ret;
718
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000719 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000720 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100721 int count;
722
723 count = 0;
724 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000725 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100726 batch_pool_link)
727 count++;
728 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000729 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100730
731 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000732 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100733 batch_pool_link) {
734 seq_puts(m, " ");
735 describe_obj(m, obj);
736 seq_putc(m, '\n');
737 }
738
739 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100740 }
Brad Volkin493018d2014-12-11 12:13:08 -0800741 }
742
Chris Wilson8d9d5742015-04-07 16:20:38 +0100743 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800744
745 mutex_unlock(&dev->struct_mutex);
746
747 return 0;
748}
749
Ben Gamari20172632009-02-17 20:08:50 -0500750static int i915_gem_request_info(struct seq_file *m, void *data)
751{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100752 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500753 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300754 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000755 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200756 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000757 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100758
759 ret = mutex_lock_interruptible(&dev->struct_mutex);
760 if (ret)
761 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500762
Chris Wilson2d1070b2015-04-01 10:36:56 +0100763 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000764 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100765 int count;
766
767 count = 0;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000768 list_for_each_entry(req, &engine->request_list, list)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100769 count++;
770 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100771 continue;
772
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000773 seq_printf(m, "%s requests: %d\n", engine->name, count);
774 list_for_each_entry(req, &engine->request_list, list) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100775 struct task_struct *task;
776
777 rcu_read_lock();
778 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200779 if (req->pid)
780 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100781 seq_printf(m, " %x @ %d: %s [%d]\n",
Daniel Vettereed29a52015-05-21 14:21:25 +0200782 req->seqno,
783 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100784 task ? task->comm : "<unknown>",
785 task ? task->pid : -1);
786 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100787 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100788
789 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500790 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100791 mutex_unlock(&dev->struct_mutex);
792
Chris Wilson2d1070b2015-04-01 10:36:56 +0100793 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100794 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100795
Ben Gamari20172632009-02-17 20:08:50 -0500796 return 0;
797}
798
Chris Wilsonb2223492010-10-27 15:27:33 +0100799static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000800 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100801{
Chris Wilson12471ba2016-04-09 10:57:55 +0100802 seq_printf(m, "Current sequence (%s): %x\n",
803 engine->name, engine->get_seqno(engine));
804 seq_printf(m, "Current user interrupts (%s): %x\n",
805 engine->name, READ_ONCE(engine->user_interrupts));
Chris Wilsonb2223492010-10-27 15:27:33 +0100806}
807
Ben Gamari20172632009-02-17 20:08:50 -0500808static int i915_gem_seqno_info(struct seq_file *m, void *data)
809{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100810 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500811 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300812 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000813 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000814 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100815
816 ret = mutex_lock_interruptible(&dev->struct_mutex);
817 if (ret)
818 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200819 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500820
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000821 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000822 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100823
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200824 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100825 mutex_unlock(&dev->struct_mutex);
826
Ben Gamari20172632009-02-17 20:08:50 -0500827 return 0;
828}
829
830
831static int i915_interrupt_info(struct seq_file *m, void *data)
832{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100833 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500834 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300835 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000836 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800837 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100838
839 ret = mutex_lock_interruptible(&dev->struct_mutex);
840 if (ret)
841 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200842 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500843
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300844 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300845 seq_printf(m, "Master Interrupt Control:\t%08x\n",
846 I915_READ(GEN8_MASTER_IRQ));
847
848 seq_printf(m, "Display IER:\t%08x\n",
849 I915_READ(VLV_IER));
850 seq_printf(m, "Display IIR:\t%08x\n",
851 I915_READ(VLV_IIR));
852 seq_printf(m, "Display IIR_RW:\t%08x\n",
853 I915_READ(VLV_IIR_RW));
854 seq_printf(m, "Display IMR:\t%08x\n",
855 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100856 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300857 seq_printf(m, "Pipe %c stat:\t%08x\n",
858 pipe_name(pipe),
859 I915_READ(PIPESTAT(pipe)));
860
861 seq_printf(m, "Port hotplug:\t%08x\n",
862 I915_READ(PORT_HOTPLUG_EN));
863 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
864 I915_READ(VLV_DPFLIPSTAT));
865 seq_printf(m, "DPINVGTT:\t%08x\n",
866 I915_READ(DPINVGTT));
867
868 for (i = 0; i < 4; i++) {
869 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
870 i, I915_READ(GEN8_GT_IMR(i)));
871 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
872 i, I915_READ(GEN8_GT_IIR(i)));
873 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
874 i, I915_READ(GEN8_GT_IER(i)));
875 }
876
877 seq_printf(m, "PCU interrupt mask:\t%08x\n",
878 I915_READ(GEN8_PCU_IMR));
879 seq_printf(m, "PCU interrupt identity:\t%08x\n",
880 I915_READ(GEN8_PCU_IIR));
881 seq_printf(m, "PCU interrupt enable:\t%08x\n",
882 I915_READ(GEN8_PCU_IER));
883 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700884 seq_printf(m, "Master Interrupt Control:\t%08x\n",
885 I915_READ(GEN8_MASTER_IRQ));
886
887 for (i = 0; i < 4; i++) {
888 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
889 i, I915_READ(GEN8_GT_IMR(i)));
890 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
891 i, I915_READ(GEN8_GT_IIR(i)));
892 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
893 i, I915_READ(GEN8_GT_IER(i)));
894 }
895
Damien Lespiau055e3932014-08-18 13:49:10 +0100896 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200897 enum intel_display_power_domain power_domain;
898
899 power_domain = POWER_DOMAIN_PIPE(pipe);
900 if (!intel_display_power_get_if_enabled(dev_priv,
901 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300902 seq_printf(m, "Pipe %c power disabled\n",
903 pipe_name(pipe));
904 continue;
905 }
Ben Widawskya123f152013-11-02 21:07:10 -0700906 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000907 pipe_name(pipe),
908 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700909 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000910 pipe_name(pipe),
911 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700912 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000913 pipe_name(pipe),
914 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200915
916 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700917 }
918
919 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
920 I915_READ(GEN8_DE_PORT_IMR));
921 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
922 I915_READ(GEN8_DE_PORT_IIR));
923 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
924 I915_READ(GEN8_DE_PORT_IER));
925
926 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
927 I915_READ(GEN8_DE_MISC_IMR));
928 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
929 I915_READ(GEN8_DE_MISC_IIR));
930 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
931 I915_READ(GEN8_DE_MISC_IER));
932
933 seq_printf(m, "PCU interrupt mask:\t%08x\n",
934 I915_READ(GEN8_PCU_IMR));
935 seq_printf(m, "PCU interrupt identity:\t%08x\n",
936 I915_READ(GEN8_PCU_IIR));
937 seq_printf(m, "PCU interrupt enable:\t%08x\n",
938 I915_READ(GEN8_PCU_IER));
939 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700940 seq_printf(m, "Display IER:\t%08x\n",
941 I915_READ(VLV_IER));
942 seq_printf(m, "Display IIR:\t%08x\n",
943 I915_READ(VLV_IIR));
944 seq_printf(m, "Display IIR_RW:\t%08x\n",
945 I915_READ(VLV_IIR_RW));
946 seq_printf(m, "Display IMR:\t%08x\n",
947 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100948 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700949 seq_printf(m, "Pipe %c stat:\t%08x\n",
950 pipe_name(pipe),
951 I915_READ(PIPESTAT(pipe)));
952
953 seq_printf(m, "Master IER:\t%08x\n",
954 I915_READ(VLV_MASTER_IER));
955
956 seq_printf(m, "Render IER:\t%08x\n",
957 I915_READ(GTIER));
958 seq_printf(m, "Render IIR:\t%08x\n",
959 I915_READ(GTIIR));
960 seq_printf(m, "Render IMR:\t%08x\n",
961 I915_READ(GTIMR));
962
963 seq_printf(m, "PM IER:\t\t%08x\n",
964 I915_READ(GEN6_PMIER));
965 seq_printf(m, "PM IIR:\t\t%08x\n",
966 I915_READ(GEN6_PMIIR));
967 seq_printf(m, "PM IMR:\t\t%08x\n",
968 I915_READ(GEN6_PMIMR));
969
970 seq_printf(m, "Port hotplug:\t%08x\n",
971 I915_READ(PORT_HOTPLUG_EN));
972 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
973 I915_READ(VLV_DPFLIPSTAT));
974 seq_printf(m, "DPINVGTT:\t%08x\n",
975 I915_READ(DPINVGTT));
976
977 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800978 seq_printf(m, "Interrupt enable: %08x\n",
979 I915_READ(IER));
980 seq_printf(m, "Interrupt identity: %08x\n",
981 I915_READ(IIR));
982 seq_printf(m, "Interrupt mask: %08x\n",
983 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100984 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800985 seq_printf(m, "Pipe %c stat: %08x\n",
986 pipe_name(pipe),
987 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800988 } else {
989 seq_printf(m, "North Display Interrupt enable: %08x\n",
990 I915_READ(DEIER));
991 seq_printf(m, "North Display Interrupt identity: %08x\n",
992 I915_READ(DEIIR));
993 seq_printf(m, "North Display Interrupt mask: %08x\n",
994 I915_READ(DEIMR));
995 seq_printf(m, "South Display Interrupt enable: %08x\n",
996 I915_READ(SDEIER));
997 seq_printf(m, "South Display Interrupt identity: %08x\n",
998 I915_READ(SDEIIR));
999 seq_printf(m, "South Display Interrupt mask: %08x\n",
1000 I915_READ(SDEIMR));
1001 seq_printf(m, "Graphics Interrupt enable: %08x\n",
1002 I915_READ(GTIER));
1003 seq_printf(m, "Graphics Interrupt identity: %08x\n",
1004 I915_READ(GTIIR));
1005 seq_printf(m, "Graphics Interrupt mask: %08x\n",
1006 I915_READ(GTIMR));
1007 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001008 for_each_engine(engine, dev_priv) {
Ben Widawskya123f152013-11-02 21:07:10 -07001009 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001010 seq_printf(m,
1011 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001012 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +00001013 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001014 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +00001015 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001016 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001017 mutex_unlock(&dev->struct_mutex);
1018
Ben Gamari20172632009-02-17 20:08:50 -05001019 return 0;
1020}
1021
Chris Wilsona6172a82009-02-11 14:26:38 +00001022static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
1023{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001024 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +00001025 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001026 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001027 int i, ret;
1028
1029 ret = mutex_lock_interruptible(&dev->struct_mutex);
1030 if (ret)
1031 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +00001032
Chris Wilsona6172a82009-02-11 14:26:38 +00001033 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
1034 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +00001035 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +00001036
Chris Wilson6c085a72012-08-20 11:40:46 +02001037 seq_printf(m, "Fence %d, pin count = %d, object = ",
1038 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001039 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001040 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001041 else
Chris Wilson05394f32010-11-08 19:18:58 +00001042 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001043 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +00001044 }
1045
Chris Wilson05394f32010-11-08 19:18:58 +00001046 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +00001047 return 0;
1048}
1049
Ben Gamari20172632009-02-17 20:08:50 -05001050static int i915_hws_info(struct seq_file *m, void *data)
1051{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001052 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -05001053 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001054 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001055 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +01001056 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +01001057 int i;
Ben Gamari20172632009-02-17 20:08:50 -05001058
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001059 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001060 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -05001061 if (hws == NULL)
1062 return 0;
1063
1064 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
1065 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
1066 i * 4,
1067 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
1068 }
1069 return 0;
1070}
1071
Daniel Vetterd5442302012-04-27 15:17:40 +02001072static ssize_t
1073i915_error_state_write(struct file *filp,
1074 const char __user *ubuf,
1075 size_t cnt,
1076 loff_t *ppos)
1077{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001078 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001079 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001080 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001081
1082 DRM_DEBUG_DRIVER("Resetting error state\n");
1083
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001084 ret = mutex_lock_interruptible(&dev->struct_mutex);
1085 if (ret)
1086 return ret;
1087
Daniel Vetterd5442302012-04-27 15:17:40 +02001088 i915_destroy_error_state(dev);
1089 mutex_unlock(&dev->struct_mutex);
1090
1091 return cnt;
1092}
1093
1094static int i915_error_state_open(struct inode *inode, struct file *file)
1095{
1096 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001097 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001098
1099 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1100 if (!error_priv)
1101 return -ENOMEM;
1102
1103 error_priv->dev = dev;
1104
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001105 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001106
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001107 file->private_data = error_priv;
1108
1109 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001110}
1111
1112static int i915_error_state_release(struct inode *inode, struct file *file)
1113{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001114 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001115
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001116 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001117 kfree(error_priv);
1118
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001119 return 0;
1120}
1121
1122static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1123 size_t count, loff_t *pos)
1124{
1125 struct i915_error_state_file_priv *error_priv = file->private_data;
1126 struct drm_i915_error_state_buf error_str;
1127 loff_t tmp_pos = 0;
1128 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001129 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001130
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001131 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001132 if (ret)
1133 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001134
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001135 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001136 if (ret)
1137 goto out;
1138
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001139 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1140 error_str.buf,
1141 error_str.bytes);
1142
1143 if (ret_count < 0)
1144 ret = ret_count;
1145 else
1146 *pos = error_str.start + ret_count;
1147out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001148 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001149 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001150}
1151
1152static const struct file_operations i915_error_state_fops = {
1153 .owner = THIS_MODULE,
1154 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001155 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001156 .write = i915_error_state_write,
1157 .llseek = default_llseek,
1158 .release = i915_error_state_release,
1159};
1160
Kees Cook647416f2013-03-10 14:10:06 -07001161static int
1162i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001163{
Kees Cook647416f2013-03-10 14:10:06 -07001164 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001165 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001166 int ret;
1167
1168 ret = mutex_lock_interruptible(&dev->struct_mutex);
1169 if (ret)
1170 return ret;
1171
Kees Cook647416f2013-03-10 14:10:06 -07001172 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001173 mutex_unlock(&dev->struct_mutex);
1174
Kees Cook647416f2013-03-10 14:10:06 -07001175 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001176}
1177
Kees Cook647416f2013-03-10 14:10:06 -07001178static int
1179i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001180{
Kees Cook647416f2013-03-10 14:10:06 -07001181 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001182 int ret;
1183
Mika Kuoppala40633212012-12-04 15:12:00 +02001184 ret = mutex_lock_interruptible(&dev->struct_mutex);
1185 if (ret)
1186 return ret;
1187
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001188 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001189 mutex_unlock(&dev->struct_mutex);
1190
Kees Cook647416f2013-03-10 14:10:06 -07001191 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001192}
1193
Kees Cook647416f2013-03-10 14:10:06 -07001194DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1195 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001196 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001197
Deepak Sadb4bd12014-03-31 11:30:02 +05301198static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001199{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001200 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001201 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001202 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001203 int ret = 0;
1204
1205 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001206
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001207 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1208
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001209 if (IS_GEN5(dev)) {
1210 u16 rgvswctl = I915_READ16(MEMSWCTL);
1211 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1212
1213 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1214 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1215 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1216 MEMSTAT_VID_SHIFT);
1217 seq_printf(m, "Current P-state: %d\n",
1218 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Wayne Boyer666a4532015-12-09 12:29:35 -08001219 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
1220 u32 freq_sts;
1221
1222 mutex_lock(&dev_priv->rps.hw_lock);
1223 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1224 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1225 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1226
1227 seq_printf(m, "actual GPU freq: %d MHz\n",
1228 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1229
1230 seq_printf(m, "current GPU freq: %d MHz\n",
1231 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1232
1233 seq_printf(m, "max GPU freq: %d MHz\n",
1234 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1235
1236 seq_printf(m, "min GPU freq: %d MHz\n",
1237 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1238
1239 seq_printf(m, "idle GPU freq: %d MHz\n",
1240 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1241
1242 seq_printf(m,
1243 "efficient (RPe) frequency: %d MHz\n",
1244 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1245 mutex_unlock(&dev_priv->rps.hw_lock);
1246 } else if (INTEL_INFO(dev)->gen >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001247 u32 rp_state_limits;
1248 u32 gt_perf_status;
1249 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001250 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001251 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001252 u32 rpupei, rpcurup, rpprevup;
1253 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001254 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001255 int max_freq;
1256
Bob Paauwe35040562015-06-25 14:54:07 -07001257 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1258 if (IS_BROXTON(dev)) {
1259 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1260 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1261 } else {
1262 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1263 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1264 }
1265
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001266 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001267 ret = mutex_lock_interruptible(&dev->struct_mutex);
1268 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001269 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001270
Mika Kuoppala59bad942015-01-16 11:34:40 +02001271 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001272
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001273 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301274 if (IS_GEN9(dev))
1275 reqf >>= 23;
1276 else {
1277 reqf &= ~GEN6_TURBO_DISABLE;
1278 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1279 reqf >>= 24;
1280 else
1281 reqf >>= 25;
1282 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001283 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001284
Chris Wilson0d8f9492014-03-27 09:06:14 +00001285 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1286 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1287 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1288
Jesse Barnesccab5c82011-01-18 15:49:25 -08001289 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301290 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1291 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1292 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1293 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1294 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1295 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Akash Goel60260a52015-03-06 11:07:21 +05301296 if (IS_GEN9(dev))
1297 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1298 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001299 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1300 else
1301 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001302 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001303
Mika Kuoppala59bad942015-01-16 11:34:40 +02001304 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001305 mutex_unlock(&dev->struct_mutex);
1306
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001307 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1308 pm_ier = I915_READ(GEN6_PMIER);
1309 pm_imr = I915_READ(GEN6_PMIMR);
1310 pm_isr = I915_READ(GEN6_PMISR);
1311 pm_iir = I915_READ(GEN6_PMIIR);
1312 pm_mask = I915_READ(GEN6_PMINTRMSK);
1313 } else {
1314 pm_ier = I915_READ(GEN8_GT_IER(2));
1315 pm_imr = I915_READ(GEN8_GT_IMR(2));
1316 pm_isr = I915_READ(GEN8_GT_ISR(2));
1317 pm_iir = I915_READ(GEN8_GT_IIR(2));
1318 pm_mask = I915_READ(GEN6_PMINTRMSK);
1319 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001320 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 -03001321 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001322 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001323 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301324 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001325 seq_printf(m, "Render p-state VID: %d\n",
1326 gt_perf_status & 0xff);
1327 seq_printf(m, "Render p-state limit: %d\n",
1328 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001329 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1330 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1331 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1332 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001333 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001334 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301335 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1336 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1337 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1338 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1339 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1340 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001341 seq_printf(m, "Up threshold: %d%%\n",
1342 dev_priv->rps.up_threshold);
1343
Akash Goeld6cda9c2016-04-23 00:05:46 +05301344 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1345 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1346 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1347 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1348 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1349 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001350 seq_printf(m, "Down threshold: %d%%\n",
1351 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001352
Bob Paauwe35040562015-06-25 14:54:07 -07001353 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1354 rp_state_cap >> 16) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001355 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1356 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001357 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001358 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001359
1360 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001361 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1362 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001363 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001364 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001365
Bob Paauwe35040562015-06-25 14:54:07 -07001366 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1367 rp_state_cap >> 0) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001368 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1369 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001370 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001371 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001372 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001373 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001374
Chris Wilsond86ed342015-04-27 13:41:19 +01001375 seq_printf(m, "Current freq: %d MHz\n",
1376 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1377 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001378 seq_printf(m, "Idle freq: %d MHz\n",
1379 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001380 seq_printf(m, "Min freq: %d MHz\n",
1381 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1382 seq_printf(m, "Max freq: %d MHz\n",
1383 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1384 seq_printf(m,
1385 "efficient (RPe) frequency: %d MHz\n",
1386 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001387 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001388 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001389 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001390
Mika Kahola1170f282015-09-25 14:00:32 +03001391 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1392 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1393 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1394
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001395out:
1396 intel_runtime_pm_put(dev_priv);
1397 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001398}
1399
Chris Wilsonf6544492015-01-26 18:03:04 +02001400static int i915_hangcheck_info(struct seq_file *m, void *unused)
1401{
1402 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001403 struct drm_device *dev = node->minor->dev;
1404 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001405 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001406 u64 acthd[I915_NUM_ENGINES];
1407 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001408 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001409 enum intel_engine_id id;
1410 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001411
1412 if (!i915.enable_hangcheck) {
1413 seq_printf(m, "Hangcheck disabled\n");
1414 return 0;
1415 }
1416
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001417 intel_runtime_pm_get(dev_priv);
1418
Dave Gordonc3232b12016-03-23 18:19:53 +00001419 for_each_engine_id(engine, dev_priv, id) {
Dave Gordonc3232b12016-03-23 18:19:53 +00001420 acthd[id] = intel_ring_get_active_head(engine);
Chris Wilsonc04e0f32016-04-09 10:57:54 +01001421 seqno[id] = engine->get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001422 }
1423
Chris Wilsonc0336662016-05-06 15:40:21 +01001424 i915_get_extra_instdone(dev_priv, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001425
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001426 intel_runtime_pm_put(dev_priv);
1427
Chris Wilsonf6544492015-01-26 18:03:04 +02001428 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1429 seq_printf(m, "Hangcheck active, fires in %dms\n",
1430 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1431 jiffies));
1432 } else
1433 seq_printf(m, "Hangcheck inactive\n");
1434
Dave Gordonc3232b12016-03-23 18:19:53 +00001435 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001436 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001437 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1438 engine->hangcheck.seqno,
1439 seqno[id],
1440 engine->last_submitted_seqno);
Chris Wilson12471ba2016-04-09 10:57:55 +01001441 seq_printf(m, "\tuser interrupts = %x [current %x]\n",
1442 engine->hangcheck.user_interrupts,
1443 READ_ONCE(engine->user_interrupts));
Chris Wilsonf6544492015-01-26 18:03:04 +02001444 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001445 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001446 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001447 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1448 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001449
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001450 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001451 seq_puts(m, "\tinstdone read =");
1452
1453 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1454 seq_printf(m, " 0x%08x", instdone[j]);
1455
1456 seq_puts(m, "\n\tinstdone accu =");
1457
1458 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1459 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001460 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001461
1462 seq_puts(m, "\n");
1463 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001464 }
1465
1466 return 0;
1467}
1468
Ben Widawsky4d855292011-12-12 19:34:16 -08001469static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001470{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001471 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001472 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001473 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001474 u32 rgvmodectl, rstdbyctl;
1475 u16 crstandvid;
1476 int ret;
1477
1478 ret = mutex_lock_interruptible(&dev->struct_mutex);
1479 if (ret)
1480 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001481 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001482
1483 rgvmodectl = I915_READ(MEMMODECTL);
1484 rstdbyctl = I915_READ(RSTDBYCTL);
1485 crstandvid = I915_READ16(CRSTANDVID);
1486
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001487 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001488 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001489
Jani Nikula742f4912015-09-03 11:16:09 +03001490 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001491 seq_printf(m, "Boost freq: %d\n",
1492 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1493 MEMMODE_BOOST_FREQ_SHIFT);
1494 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001495 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001496 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001497 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001498 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001499 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001500 seq_printf(m, "Starting frequency: P%d\n",
1501 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001502 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001503 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001504 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1505 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1506 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1507 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001508 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001509 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001510 switch (rstdbyctl & RSX_STATUS_MASK) {
1511 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001512 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001513 break;
1514 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001515 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001516 break;
1517 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001518 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001519 break;
1520 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001521 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001522 break;
1523 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001524 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001525 break;
1526 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001527 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001528 break;
1529 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001530 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001531 break;
1532 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001533
1534 return 0;
1535}
1536
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001537static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001538{
1539 struct drm_info_node *node = m->private;
1540 struct drm_device *dev = node->minor->dev;
1541 struct drm_i915_private *dev_priv = dev->dev_private;
1542 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001543
1544 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001545 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001546 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001547 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001548 fw_domain->wake_count);
1549 }
1550 spin_unlock_irq(&dev_priv->uncore.lock);
1551
1552 return 0;
1553}
1554
Deepak S669ab5a2014-01-10 15:18:26 +05301555static int vlv_drpc_info(struct seq_file *m)
1556{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001557 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301558 struct drm_device *dev = node->minor->dev;
1559 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001560 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301561
Imre Deakd46c0512014-04-14 20:24:27 +03001562 intel_runtime_pm_get(dev_priv);
1563
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001564 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301565 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1566 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1567
Imre Deakd46c0512014-04-14 20:24:27 +03001568 intel_runtime_pm_put(dev_priv);
1569
Deepak S669ab5a2014-01-10 15:18:26 +05301570 seq_printf(m, "Video Turbo Mode: %s\n",
1571 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1572 seq_printf(m, "Turbo enabled: %s\n",
1573 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1574 seq_printf(m, "HW control enabled: %s\n",
1575 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1576 seq_printf(m, "SW control enabled: %s\n",
1577 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1578 GEN6_RP_MEDIA_SW_MODE));
1579 seq_printf(m, "RC6 Enabled: %s\n",
1580 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1581 GEN6_RC_CTL_EI_MODE(1))));
1582 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001583 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301584 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001585 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301586
Imre Deak9cc19be2014-04-14 20:24:24 +03001587 seq_printf(m, "Render RC6 residency since boot: %u\n",
1588 I915_READ(VLV_GT_RENDER_RC6));
1589 seq_printf(m, "Media RC6 residency since boot: %u\n",
1590 I915_READ(VLV_GT_MEDIA_RC6));
1591
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001592 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301593}
1594
Ben Widawsky4d855292011-12-12 19:34:16 -08001595static int gen6_drpc_info(struct seq_file *m)
1596{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001597 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001598 struct drm_device *dev = node->minor->dev;
1599 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001600 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001601 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001602 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001603
1604 ret = mutex_lock_interruptible(&dev->struct_mutex);
1605 if (ret)
1606 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001607 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001608
Chris Wilson907b28c2013-07-19 20:36:52 +01001609 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001610 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001611 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001612
1613 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001614 seq_puts(m, "RC information inaccurate because somebody "
1615 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001616 } else {
1617 /* NB: we cannot use forcewake, else we read the wrong values */
1618 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1619 udelay(10);
1620 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1621 }
1622
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001623 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001624 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001625
1626 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1627 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1628 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001629 mutex_lock(&dev_priv->rps.hw_lock);
1630 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1631 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001632
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001633 intel_runtime_pm_put(dev_priv);
1634
Ben Widawsky4d855292011-12-12 19:34:16 -08001635 seq_printf(m, "Video Turbo Mode: %s\n",
1636 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1637 seq_printf(m, "HW control enabled: %s\n",
1638 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1639 seq_printf(m, "SW control enabled: %s\n",
1640 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1641 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001642 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001643 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1644 seq_printf(m, "RC6 Enabled: %s\n",
1645 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1646 seq_printf(m, "Deep RC6 Enabled: %s\n",
1647 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1648 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1649 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001650 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001651 switch (gt_core_status & GEN6_RCn_MASK) {
1652 case GEN6_RC0:
1653 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001654 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001655 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001656 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001657 break;
1658 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001659 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001660 break;
1661 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001662 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001663 break;
1664 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001665 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001666 break;
1667 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001668 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001669 break;
1670 }
1671
1672 seq_printf(m, "Core Power Down: %s\n",
1673 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001674
1675 /* Not exactly sure what this is */
1676 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1677 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1678 seq_printf(m, "RC6 residency since boot: %u\n",
1679 I915_READ(GEN6_GT_GFX_RC6));
1680 seq_printf(m, "RC6+ residency since boot: %u\n",
1681 I915_READ(GEN6_GT_GFX_RC6p));
1682 seq_printf(m, "RC6++ residency since boot: %u\n",
1683 I915_READ(GEN6_GT_GFX_RC6pp));
1684
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001685 seq_printf(m, "RC6 voltage: %dmV\n",
1686 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1687 seq_printf(m, "RC6+ voltage: %dmV\n",
1688 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1689 seq_printf(m, "RC6++ voltage: %dmV\n",
1690 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001691 return 0;
1692}
1693
1694static int i915_drpc_info(struct seq_file *m, void *unused)
1695{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001696 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001697 struct drm_device *dev = node->minor->dev;
1698
Wayne Boyer666a4532015-12-09 12:29:35 -08001699 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Deepak S669ab5a2014-01-10 15:18:26 +05301700 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001701 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001702 return gen6_drpc_info(m);
1703 else
1704 return ironlake_drpc_info(m);
1705}
1706
Daniel Vetter9a851782015-06-18 10:30:22 +02001707static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1708{
1709 struct drm_info_node *node = m->private;
1710 struct drm_device *dev = node->minor->dev;
1711 struct drm_i915_private *dev_priv = dev->dev_private;
1712
1713 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1714 dev_priv->fb_tracking.busy_bits);
1715
1716 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1717 dev_priv->fb_tracking.flip_bits);
1718
1719 return 0;
1720}
1721
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001722static int i915_fbc_status(struct seq_file *m, void *unused)
1723{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001724 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001725 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001726 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001727
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001728 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001729 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001730 return 0;
1731 }
1732
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001733 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001734 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001735
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001736 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001737 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001738 else
1739 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001740 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001741
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001742 if (INTEL_INFO(dev_priv)->gen >= 7)
1743 seq_printf(m, "Compressing: %s\n",
1744 yesno(I915_READ(FBC_STATUS2) &
1745 FBC_COMPRESSION_MASK));
1746
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001747 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001748 intel_runtime_pm_put(dev_priv);
1749
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001750 return 0;
1751}
1752
Rodrigo Vivida46f932014-08-01 02:04:45 -07001753static int i915_fbc_fc_get(void *data, u64 *val)
1754{
1755 struct drm_device *dev = data;
1756 struct drm_i915_private *dev_priv = dev->dev_private;
1757
1758 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1759 return -ENODEV;
1760
Rodrigo Vivida46f932014-08-01 02:04:45 -07001761 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001762
1763 return 0;
1764}
1765
1766static int i915_fbc_fc_set(void *data, u64 val)
1767{
1768 struct drm_device *dev = data;
1769 struct drm_i915_private *dev_priv = dev->dev_private;
1770 u32 reg;
1771
1772 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1773 return -ENODEV;
1774
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001775 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001776
1777 reg = I915_READ(ILK_DPFC_CONTROL);
1778 dev_priv->fbc.false_color = val;
1779
1780 I915_WRITE(ILK_DPFC_CONTROL, val ?
1781 (reg | FBC_CTL_FALSE_COLOR) :
1782 (reg & ~FBC_CTL_FALSE_COLOR));
1783
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001784 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001785 return 0;
1786}
1787
1788DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1789 i915_fbc_fc_get, i915_fbc_fc_set,
1790 "%llu\n");
1791
Paulo Zanoni92d44622013-05-31 16:33:24 -03001792static int i915_ips_status(struct seq_file *m, void *unused)
1793{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001794 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001795 struct drm_device *dev = node->minor->dev;
1796 struct drm_i915_private *dev_priv = dev->dev_private;
1797
Damien Lespiauf5adf942013-06-24 18:29:34 +01001798 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001799 seq_puts(m, "not supported\n");
1800 return 0;
1801 }
1802
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001803 intel_runtime_pm_get(dev_priv);
1804
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001805 seq_printf(m, "Enabled by kernel parameter: %s\n",
1806 yesno(i915.enable_ips));
1807
1808 if (INTEL_INFO(dev)->gen >= 8) {
1809 seq_puts(m, "Currently: unknown\n");
1810 } else {
1811 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1812 seq_puts(m, "Currently: enabled\n");
1813 else
1814 seq_puts(m, "Currently: disabled\n");
1815 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001816
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001817 intel_runtime_pm_put(dev_priv);
1818
Paulo Zanoni92d44622013-05-31 16:33:24 -03001819 return 0;
1820}
1821
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001822static int i915_sr_status(struct seq_file *m, void *unused)
1823{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001824 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001825 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001826 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001827 bool sr_enabled = false;
1828
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001829 intel_runtime_pm_get(dev_priv);
1830
Yuanhan Liu13982612010-12-15 15:42:31 +08001831 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001832 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001833 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1834 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001835 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1836 else if (IS_I915GM(dev))
1837 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1838 else if (IS_PINEVIEW(dev))
1839 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Wayne Boyer666a4532015-12-09 12:29:35 -08001840 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001841 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001842
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001843 intel_runtime_pm_put(dev_priv);
1844
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001845 seq_printf(m, "self-refresh: %s\n",
1846 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001847
1848 return 0;
1849}
1850
Jesse Barnes7648fa92010-05-20 14:28:11 -07001851static int i915_emon_status(struct seq_file *m, void *unused)
1852{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001853 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001854 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001855 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001856 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001857 int ret;
1858
Chris Wilson582be6b2012-04-30 19:35:02 +01001859 if (!IS_GEN5(dev))
1860 return -ENODEV;
1861
Chris Wilsonde227ef2010-07-03 07:58:38 +01001862 ret = mutex_lock_interruptible(&dev->struct_mutex);
1863 if (ret)
1864 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001865
1866 temp = i915_mch_val(dev_priv);
1867 chipset = i915_chipset_val(dev_priv);
1868 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001869 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001870
1871 seq_printf(m, "GMCH temp: %ld\n", temp);
1872 seq_printf(m, "Chipset power: %ld\n", chipset);
1873 seq_printf(m, "GFX power: %ld\n", gfx);
1874 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1875
1876 return 0;
1877}
1878
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001879static int i915_ring_freq_table(struct seq_file *m, void *unused)
1880{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001881 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001882 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001883 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001884 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001885 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301886 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001887
Akash Goel97d33082015-06-29 14:50:23 +05301888 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001889 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001890 return 0;
1891 }
1892
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001893 intel_runtime_pm_get(dev_priv);
1894
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001895 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1896
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001897 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001898 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001899 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001900
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001901 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301902 /* Convert GT frequency to 50 HZ units */
1903 min_gpu_freq =
1904 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1905 max_gpu_freq =
1906 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1907 } else {
1908 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1909 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1910 }
1911
Damien Lespiau267f0c92013-06-24 22:59:48 +01001912 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001913
Akash Goelf936ec32015-06-29 14:50:22 +05301914 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001915 ia_freq = gpu_freq;
1916 sandybridge_pcode_read(dev_priv,
1917 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1918 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001919 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301920 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001921 (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1922 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001923 ((ia_freq >> 0) & 0xff) * 100,
1924 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001925 }
1926
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001927 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001928
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001929out:
1930 intel_runtime_pm_put(dev_priv);
1931 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001932}
1933
Chris Wilson44834a62010-08-19 16:09:23 +01001934static int i915_opregion(struct seq_file *m, void *unused)
1935{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001936 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001937 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001938 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001939 struct intel_opregion *opregion = &dev_priv->opregion;
1940 int ret;
1941
1942 ret = mutex_lock_interruptible(&dev->struct_mutex);
1943 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001944 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001945
Jani Nikula2455a8e2015-12-14 12:50:53 +02001946 if (opregion->header)
1947 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001948
1949 mutex_unlock(&dev->struct_mutex);
1950
Daniel Vetter0d38f002012-04-21 22:49:10 +02001951out:
Chris Wilson44834a62010-08-19 16:09:23 +01001952 return 0;
1953}
1954
Jani Nikulaada8f952015-12-15 13:17:12 +02001955static int i915_vbt(struct seq_file *m, void *unused)
1956{
1957 struct drm_info_node *node = m->private;
1958 struct drm_device *dev = node->minor->dev;
1959 struct drm_i915_private *dev_priv = dev->dev_private;
1960 struct intel_opregion *opregion = &dev_priv->opregion;
1961
1962 if (opregion->vbt)
1963 seq_write(m, opregion->vbt, opregion->vbt_size);
1964
1965 return 0;
1966}
1967
Chris Wilson37811fc2010-08-25 22:45:57 +01001968static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1969{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001970 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001971 struct drm_device *dev = node->minor->dev;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301972 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001973 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001974 int ret;
1975
1976 ret = mutex_lock_interruptible(&dev->struct_mutex);
1977 if (ret)
1978 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001979
Daniel Vetter06957262015-08-10 13:34:08 +02001980#ifdef CONFIG_DRM_FBDEV_EMULATION
Namrta Salonieb13b8402015-11-27 13:43:11 +05301981 if (to_i915(dev)->fbdev) {
1982 fbdev_fb = to_intel_framebuffer(to_i915(dev)->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001983
Namrta Salonieb13b8402015-11-27 13:43:11 +05301984 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1985 fbdev_fb->base.width,
1986 fbdev_fb->base.height,
1987 fbdev_fb->base.depth,
1988 fbdev_fb->base.bits_per_pixel,
1989 fbdev_fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001990 drm_framebuffer_read_refcount(&fbdev_fb->base));
Namrta Salonieb13b8402015-11-27 13:43:11 +05301991 describe_obj(m, fbdev_fb->obj);
1992 seq_putc(m, '\n');
1993 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001994#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001995
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001996 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001997 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301998 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1999 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01002000 continue;
2001
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00002002 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 +01002003 fb->base.width,
2004 fb->base.height,
2005 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01002006 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00002007 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10002008 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00002009 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01002010 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01002011 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002012 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01002013 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01002014
2015 return 0;
2016}
2017
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002018static void describe_ctx_ringbuf(struct seq_file *m,
2019 struct intel_ringbuffer *ringbuf)
2020{
2021 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
2022 ringbuf->space, ringbuf->head, ringbuf->tail,
2023 ringbuf->last_retired_head);
2024}
2025
Ben Widawskye76d3632011-03-19 18:14:29 -07002026static int i915_context_status(struct seq_file *m, void *unused)
2027{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002028 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07002029 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03002030 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002031 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002032 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00002033 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07002034
Daniel Vetterf3d28872014-05-29 23:23:08 +02002035 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002036 if (ret)
2037 return ret;
2038
Ben Widawskya33afea2013-09-17 21:12:45 -07002039 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01002040 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsond28b99a2016-05-24 14:53:39 +01002041 if (IS_ERR(ctx->file_priv)) {
2042 seq_puts(m, "(deleted) ");
2043 } else if (ctx->file_priv) {
2044 struct pid *pid = ctx->file_priv->file->pid;
2045 struct task_struct *task;
2046
2047 task = get_pid_task(pid, PIDTYPE_PID);
2048 if (task) {
2049 seq_printf(m, "(%s [%d]) ",
2050 task->comm, task->pid);
2051 put_task_struct(task);
2052 }
2053 } else {
2054 seq_puts(m, "(kernel) ");
2055 }
2056
Chris Wilsonbca44d82016-05-24 14:53:41 +01002057 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
2058 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07002059
Chris Wilsonbca44d82016-05-24 14:53:41 +01002060 for_each_engine(engine, dev_priv) {
2061 struct intel_context *ce = &ctx->engine[engine->id];
2062
2063 seq_printf(m, "%s: ", engine->name);
2064 seq_putc(m, ce->initialised ? 'I' : 'i');
2065 if (ce->state)
2066 describe_obj(m, ce->state);
2067 if (ce->ringbuf)
2068 describe_ctx_ringbuf(m, ce->ringbuf);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002069 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002070 }
2071
Ben Widawskya33afea2013-09-17 21:12:45 -07002072 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002073 }
2074
Daniel Vetterf3d28872014-05-29 23:23:08 +02002075 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002076
2077 return 0;
2078}
2079
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002080static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002081 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002082 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002083{
Chris Wilsonbca44d82016-05-24 14:53:41 +01002084 struct drm_i915_gem_object *ctx_obj = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002085 struct page *page;
2086 uint32_t *reg_state;
2087 int j;
2088 unsigned long ggtt_offset = 0;
2089
Chris Wilson7069b142016-04-28 09:56:52 +01002090 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2091
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002092 if (ctx_obj == NULL) {
Chris Wilson7069b142016-04-28 09:56:52 +01002093 seq_puts(m, "\tNot allocated\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002094 return;
2095 }
2096
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002097 if (!i915_gem_obj_ggtt_bound(ctx_obj))
2098 seq_puts(m, "\tNot bound in GGTT\n");
2099 else
2100 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
2101
2102 if (i915_gem_object_get_pages(ctx_obj)) {
2103 seq_puts(m, "\tFailed to get pages for context object\n");
2104 return;
2105 }
2106
Alex Daid1675192015-08-12 15:43:43 +01002107 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002108 if (!WARN_ON(page == NULL)) {
2109 reg_state = kmap_atomic(page);
2110
2111 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2112 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2113 ggtt_offset + 4096 + (j * 4),
2114 reg_state[j], reg_state[j + 1],
2115 reg_state[j + 2], reg_state[j + 3]);
2116 }
2117 kunmap_atomic(reg_state);
2118 }
2119
2120 seq_putc(m, '\n');
2121}
2122
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002123static int i915_dump_lrc(struct seq_file *m, void *unused)
2124{
2125 struct drm_info_node *node = (struct drm_info_node *) m->private;
2126 struct drm_device *dev = node->minor->dev;
2127 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002128 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002129 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002130 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002131
2132 if (!i915.enable_execlists) {
2133 seq_printf(m, "Logical Ring Contexts are disabled\n");
2134 return 0;
2135 }
2136
2137 ret = mutex_lock_interruptible(&dev->struct_mutex);
2138 if (ret)
2139 return ret;
2140
Dave Gordone28e4042016-01-19 19:02:55 +00002141 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002142 for_each_engine(engine, dev_priv)
2143 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002144
2145 mutex_unlock(&dev->struct_mutex);
2146
2147 return 0;
2148}
2149
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002150static int i915_execlists(struct seq_file *m, void *data)
2151{
2152 struct drm_info_node *node = (struct drm_info_node *)m->private;
2153 struct drm_device *dev = node->minor->dev;
2154 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002155 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002156 u32 status_pointer;
2157 u8 read_pointer;
2158 u8 write_pointer;
2159 u32 status;
2160 u32 ctx_id;
2161 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002162 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002163
2164 if (!i915.enable_execlists) {
2165 seq_puts(m, "Logical Ring Contexts are disabled\n");
2166 return 0;
2167 }
2168
2169 ret = mutex_lock_interruptible(&dev->struct_mutex);
2170 if (ret)
2171 return ret;
2172
Michel Thierryfc0412e2014-10-16 16:13:38 +01002173 intel_runtime_pm_get(dev_priv);
2174
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002175 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002176 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002177 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002178
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002179 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002180
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002181 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2182 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002183 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2184 status, ctx_id);
2185
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002186 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002187 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2188
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002189 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002190 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002191 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002192 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002193 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2194 read_pointer, write_pointer);
2195
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002196 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002197 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2198 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002199
2200 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2201 i, status, ctx_id);
2202 }
2203
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002204 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002205 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002206 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002207 head_req = list_first_entry_or_null(&engine->execlist_queue,
2208 struct drm_i915_gem_request,
2209 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002210 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002211
2212 seq_printf(m, "\t%d requests in queue\n", count);
2213 if (head_req) {
Chris Wilson7069b142016-04-28 09:56:52 +01002214 seq_printf(m, "\tHead request context: %u\n",
2215 head_req->ctx->hw_id);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002216 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002217 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002218 }
2219
2220 seq_putc(m, '\n');
2221 }
2222
Michel Thierryfc0412e2014-10-16 16:13:38 +01002223 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002224 mutex_unlock(&dev->struct_mutex);
2225
2226 return 0;
2227}
2228
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002229static const char *swizzle_string(unsigned swizzle)
2230{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002231 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002232 case I915_BIT_6_SWIZZLE_NONE:
2233 return "none";
2234 case I915_BIT_6_SWIZZLE_9:
2235 return "bit9";
2236 case I915_BIT_6_SWIZZLE_9_10:
2237 return "bit9/bit10";
2238 case I915_BIT_6_SWIZZLE_9_11:
2239 return "bit9/bit11";
2240 case I915_BIT_6_SWIZZLE_9_10_11:
2241 return "bit9/bit10/bit11";
2242 case I915_BIT_6_SWIZZLE_9_17:
2243 return "bit9/bit17";
2244 case I915_BIT_6_SWIZZLE_9_10_17:
2245 return "bit9/bit10/bit17";
2246 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002247 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002248 }
2249
2250 return "bug";
2251}
2252
2253static int i915_swizzle_info(struct seq_file *m, void *data)
2254{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002255 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002256 struct drm_device *dev = node->minor->dev;
2257 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002258 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002259
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002260 ret = mutex_lock_interruptible(&dev->struct_mutex);
2261 if (ret)
2262 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002263 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002264
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002265 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2266 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2267 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2268 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2269
2270 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2271 seq_printf(m, "DDC = 0x%08x\n",
2272 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002273 seq_printf(m, "DDC2 = 0x%08x\n",
2274 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002275 seq_printf(m, "C0DRB3 = 0x%04x\n",
2276 I915_READ16(C0DRB3));
2277 seq_printf(m, "C1DRB3 = 0x%04x\n",
2278 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002279 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002280 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2281 I915_READ(MAD_DIMM_C0));
2282 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2283 I915_READ(MAD_DIMM_C1));
2284 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2285 I915_READ(MAD_DIMM_C2));
2286 seq_printf(m, "TILECTL = 0x%08x\n",
2287 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002288 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002289 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2290 I915_READ(GAMTARBMODE));
2291 else
2292 seq_printf(m, "ARB_MODE = 0x%08x\n",
2293 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002294 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2295 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002296 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002297
2298 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2299 seq_puts(m, "L-shaped memory detected\n");
2300
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002301 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002302 mutex_unlock(&dev->struct_mutex);
2303
2304 return 0;
2305}
2306
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002307static int per_file_ctx(int id, void *ptr, void *data)
2308{
Chris Wilsone2efd132016-05-24 14:53:34 +01002309 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002310 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002311 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2312
2313 if (!ppgtt) {
2314 seq_printf(m, " no ppgtt for context %d\n",
2315 ctx->user_handle);
2316 return 0;
2317 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002318
Oscar Mateof83d6512014-05-22 14:13:38 +01002319 if (i915_gem_context_is_default(ctx))
2320 seq_puts(m, " default context:\n");
2321 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002322 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002323 ppgtt->debug_dump(ppgtt, m);
2324
2325 return 0;
2326}
2327
Ben Widawsky77df6772013-11-02 21:07:30 -07002328static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002329{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002330 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002331 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002332 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002333 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002334
Ben Widawsky77df6772013-11-02 21:07:30 -07002335 if (!ppgtt)
2336 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002337
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002338 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002339 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002340 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002341 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002342 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002343 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002344 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002345 }
2346 }
2347}
2348
2349static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2350{
2351 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002352 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002353
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002354 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002355 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2356
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002357 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002358 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002359 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002360 seq_printf(m, "GFX_MODE: 0x%08x\n",
2361 I915_READ(RING_MODE_GEN7(engine)));
2362 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2363 I915_READ(RING_PP_DIR_BASE(engine)));
2364 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2365 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2366 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2367 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002368 }
2369 if (dev_priv->mm.aliasing_ppgtt) {
2370 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2371
Damien Lespiau267f0c92013-06-24 22:59:48 +01002372 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002373 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002374
Ben Widawsky87d60b62013-12-06 14:11:29 -08002375 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002376 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002377
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002378 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002379}
2380
2381static int i915_ppgtt_info(struct seq_file *m, void *data)
2382{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002383 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002384 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002385 struct drm_i915_private *dev_priv = dev->dev_private;
Michel Thierryea91e402015-07-29 17:23:57 +01002386 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002387
2388 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2389 if (ret)
2390 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002391 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002392
2393 if (INTEL_INFO(dev)->gen >= 8)
2394 gen8_ppgtt_info(m, dev);
2395 else if (INTEL_INFO(dev)->gen >= 6)
2396 gen6_ppgtt_info(m, dev);
2397
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002398 mutex_lock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002399 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2400 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002401 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002402
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002403 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002404 if (!task) {
2405 ret = -ESRCH;
2406 goto out_put;
2407 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002408 seq_printf(m, "\nproc: %s\n", task->comm);
2409 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002410 idr_for_each(&file_priv->context_idr, per_file_ctx,
2411 (void *)(unsigned long)m);
2412 }
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002413 mutex_unlock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002414
Dan Carpenter06812762015-10-02 18:14:22 +03002415out_put:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002416 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002417 mutex_unlock(&dev->struct_mutex);
2418
Dan Carpenter06812762015-10-02 18:14:22 +03002419 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002420}
2421
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002422static int count_irq_waiters(struct drm_i915_private *i915)
2423{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002424 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002425 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002426
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002427 for_each_engine(engine, i915)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002428 count += engine->irq_refcount;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002429
2430 return count;
2431}
2432
Chris Wilson1854d5c2015-04-07 16:20:32 +01002433static int i915_rps_boost_info(struct seq_file *m, void *data)
2434{
2435 struct drm_info_node *node = m->private;
2436 struct drm_device *dev = node->minor->dev;
2437 struct drm_i915_private *dev_priv = dev->dev_private;
2438 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002439
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002440 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2441 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2442 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2443 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2444 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2445 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2446 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2447 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2448 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002449
2450 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002451 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002452 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2453 struct drm_i915_file_private *file_priv = file->driver_priv;
2454 struct task_struct *task;
2455
2456 rcu_read_lock();
2457 task = pid_task(file->pid, PIDTYPE_PID);
2458 seq_printf(m, "%s [%d]: %d boosts%s\n",
2459 task ? task->comm : "<unknown>",
2460 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002461 file_priv->rps.boosts,
2462 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002463 rcu_read_unlock();
2464 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002465 seq_printf(m, "Semaphore boosts: %d%s\n",
2466 dev_priv->rps.semaphores.boosts,
2467 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2468 seq_printf(m, "MMIO flip boosts: %d%s\n",
2469 dev_priv->rps.mmioflips.boosts,
2470 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002471 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002472 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002473 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002474
Chris Wilson8d3afd72015-05-21 21:01:47 +01002475 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002476}
2477
Ben Widawsky63573eb2013-07-04 11:02:07 -07002478static int i915_llc(struct seq_file *m, void *data)
2479{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002480 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002481 struct drm_device *dev = node->minor->dev;
2482 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002483 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002484
Ben Widawsky63573eb2013-07-04 11:02:07 -07002485 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002486 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2487 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002488
2489 return 0;
2490}
2491
Alex Daifdf5d352015-08-12 15:43:37 +01002492static int i915_guc_load_status_info(struct seq_file *m, void *data)
2493{
2494 struct drm_info_node *node = m->private;
2495 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2496 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2497 u32 tmp, i;
2498
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002499 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002500 return 0;
2501
2502 seq_printf(m, "GuC firmware status:\n");
2503 seq_printf(m, "\tpath: %s\n",
2504 guc_fw->guc_fw_path);
2505 seq_printf(m, "\tfetch: %s\n",
2506 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2507 seq_printf(m, "\tload: %s\n",
2508 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2509 seq_printf(m, "\tversion wanted: %d.%d\n",
2510 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2511 seq_printf(m, "\tversion found: %d.%d\n",
2512 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002513 seq_printf(m, "\theader: offset is %d; size = %d\n",
2514 guc_fw->header_offset, guc_fw->header_size);
2515 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2516 guc_fw->ucode_offset, guc_fw->ucode_size);
2517 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2518 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002519
2520 tmp = I915_READ(GUC_STATUS);
2521
2522 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2523 seq_printf(m, "\tBootrom status = 0x%x\n",
2524 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2525 seq_printf(m, "\tuKernel status = 0x%x\n",
2526 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2527 seq_printf(m, "\tMIA Core status = 0x%x\n",
2528 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2529 seq_puts(m, "\nScratch registers:\n");
2530 for (i = 0; i < 16; i++)
2531 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2532
2533 return 0;
2534}
2535
Dave Gordon8b417c22015-08-12 15:43:44 +01002536static void i915_guc_client_info(struct seq_file *m,
2537 struct drm_i915_private *dev_priv,
2538 struct i915_guc_client *client)
2539{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002540 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002541 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002542
2543 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2544 client->priority, client->ctx_index, client->proc_desc_offset);
2545 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2546 client->doorbell_id, client->doorbell_offset, client->cookie);
2547 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2548 client->wq_size, client->wq_offset, client->wq_tail);
2549
Dave Gordon551aaec2016-05-13 15:36:33 +01002550 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002551 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2552 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2553 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2554
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002555 for_each_engine(engine, dev_priv) {
Dave Gordon8b417c22015-08-12 15:43:44 +01002556 seq_printf(m, "\tSubmissions: %llu %s\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002557 client->submissions[engine->guc_id],
2558 engine->name);
2559 tot += client->submissions[engine->guc_id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002560 }
2561 seq_printf(m, "\tTotal: %llu\n", tot);
2562}
2563
2564static int i915_guc_info(struct seq_file *m, void *data)
2565{
2566 struct drm_info_node *node = m->private;
2567 struct drm_device *dev = node->minor->dev;
2568 struct drm_i915_private *dev_priv = dev->dev_private;
2569 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002570 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002571 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002572 u64 total = 0;
2573
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002574 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002575 return 0;
2576
Alex Dai5a843302015-12-02 16:56:29 -08002577 if (mutex_lock_interruptible(&dev->struct_mutex))
2578 return 0;
2579
Dave Gordon8b417c22015-08-12 15:43:44 +01002580 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002581 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002582 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002583 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002584
2585 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002586
2587 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2588 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2589 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2590 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2591 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2592
2593 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002594 for_each_engine(engine, dev_priv) {
Alex Dai397097b2016-01-23 11:58:14 -08002595 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002596 engine->name, guc.submissions[engine->guc_id],
2597 guc.last_seqno[engine->guc_id]);
2598 total += guc.submissions[engine->guc_id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002599 }
2600 seq_printf(m, "\t%s: %llu\n", "Total", total);
2601
2602 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2603 i915_guc_client_info(m, dev_priv, &client);
2604
2605 /* Add more as required ... */
2606
2607 return 0;
2608}
2609
Alex Dai4c7e77f2015-08-12 15:43:40 +01002610static int i915_guc_log_dump(struct seq_file *m, void *data)
2611{
2612 struct drm_info_node *node = m->private;
2613 struct drm_device *dev = node->minor->dev;
2614 struct drm_i915_private *dev_priv = dev->dev_private;
2615 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2616 u32 *log;
2617 int i = 0, pg;
2618
2619 if (!log_obj)
2620 return 0;
2621
2622 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2623 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2624
2625 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2626 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2627 *(log + i), *(log + i + 1),
2628 *(log + i + 2), *(log + i + 3));
2629
2630 kunmap_atomic(log);
2631 }
2632
2633 seq_putc(m, '\n');
2634
2635 return 0;
2636}
2637
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002638static int i915_edp_psr_status(struct seq_file *m, void *data)
2639{
2640 struct drm_info_node *node = m->private;
2641 struct drm_device *dev = node->minor->dev;
2642 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002643 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002644 u32 stat[3];
2645 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002646 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002647
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002648 if (!HAS_PSR(dev)) {
2649 seq_puts(m, "PSR not supported\n");
2650 return 0;
2651 }
2652
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002653 intel_runtime_pm_get(dev_priv);
2654
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002655 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002656 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2657 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002658 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002659 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002660 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2661 dev_priv->psr.busy_frontbuffer_bits);
2662 seq_printf(m, "Re-enable work scheduled: %s\n",
2663 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002664
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002665 if (HAS_DDI(dev))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002666 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002667 else {
2668 for_each_pipe(dev_priv, pipe) {
2669 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2670 VLV_EDP_PSR_CURR_STATE_MASK;
2671 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2672 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2673 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002674 }
2675 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002676
2677 seq_printf(m, "Main link in standby mode: %s\n",
2678 yesno(dev_priv->psr.link_standby));
2679
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002680 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002681
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002682 if (!HAS_DDI(dev))
2683 for_each_pipe(dev_priv, pipe) {
2684 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2685 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2686 seq_printf(m, " pipe %c", pipe_name(pipe));
2687 }
2688 seq_puts(m, "\n");
2689
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002690 /*
2691 * VLV/CHV PSR has no kind of performance counter
2692 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2693 */
2694 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002695 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002696 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002697
2698 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2699 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002700 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002701
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002702 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002703 return 0;
2704}
2705
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002706static int i915_sink_crc(struct seq_file *m, void *data)
2707{
2708 struct drm_info_node *node = m->private;
2709 struct drm_device *dev = node->minor->dev;
2710 struct intel_encoder *encoder;
2711 struct intel_connector *connector;
2712 struct intel_dp *intel_dp = NULL;
2713 int ret;
2714 u8 crc[6];
2715
2716 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002717 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002718
2719 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2720 continue;
2721
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002722 if (!connector->base.encoder)
2723 continue;
2724
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002725 encoder = to_intel_encoder(connector->base.encoder);
2726 if (encoder->type != INTEL_OUTPUT_EDP)
2727 continue;
2728
2729 intel_dp = enc_to_intel_dp(&encoder->base);
2730
2731 ret = intel_dp_sink_crc(intel_dp, crc);
2732 if (ret)
2733 goto out;
2734
2735 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2736 crc[0], crc[1], crc[2],
2737 crc[3], crc[4], crc[5]);
2738 goto out;
2739 }
2740 ret = -ENODEV;
2741out:
2742 drm_modeset_unlock_all(dev);
2743 return ret;
2744}
2745
Jesse Barnesec013e72013-08-20 10:29:23 +01002746static int i915_energy_uJ(struct seq_file *m, void *data)
2747{
2748 struct drm_info_node *node = m->private;
2749 struct drm_device *dev = node->minor->dev;
2750 struct drm_i915_private *dev_priv = dev->dev_private;
2751 u64 power;
2752 u32 units;
2753
2754 if (INTEL_INFO(dev)->gen < 6)
2755 return -ENODEV;
2756
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002757 intel_runtime_pm_get(dev_priv);
2758
Jesse Barnesec013e72013-08-20 10:29:23 +01002759 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2760 power = (power & 0x1f00) >> 8;
2761 units = 1000000 / (1 << power); /* convert to uJ */
2762 power = I915_READ(MCH_SECP_NRG_STTS);
2763 power *= units;
2764
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002765 intel_runtime_pm_put(dev_priv);
2766
Jesse Barnesec013e72013-08-20 10:29:23 +01002767 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002768
2769 return 0;
2770}
2771
Damien Lespiau6455c872015-06-04 18:23:57 +01002772static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002773{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002774 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002775 struct drm_device *dev = node->minor->dev;
2776 struct drm_i915_private *dev_priv = dev->dev_private;
2777
Chris Wilsona156e642016-04-03 14:14:21 +01002778 if (!HAS_RUNTIME_PM(dev_priv))
2779 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002780
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002781 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002782 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002783 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002784#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002785 seq_printf(m, "Usage count: %d\n",
2786 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002787#else
2788 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2789#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002790 seq_printf(m, "PCI device power state: %s [%d]\n",
2791 pci_power_name(dev_priv->dev->pdev->current_state),
2792 dev_priv->dev->pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002793
Jesse Barnesec013e72013-08-20 10:29:23 +01002794 return 0;
2795}
2796
Imre Deak1da51582013-11-25 17:15:35 +02002797static int i915_power_domain_info(struct seq_file *m, void *unused)
2798{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002799 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002800 struct drm_device *dev = node->minor->dev;
2801 struct drm_i915_private *dev_priv = dev->dev_private;
2802 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2803 int i;
2804
2805 mutex_lock(&power_domains->lock);
2806
2807 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2808 for (i = 0; i < power_domains->power_well_count; i++) {
2809 struct i915_power_well *power_well;
2810 enum intel_display_power_domain power_domain;
2811
2812 power_well = &power_domains->power_wells[i];
2813 seq_printf(m, "%-25s %d\n", power_well->name,
2814 power_well->count);
2815
2816 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2817 power_domain++) {
2818 if (!(BIT(power_domain) & power_well->domains))
2819 continue;
2820
2821 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002822 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002823 power_domains->domain_use_count[power_domain]);
2824 }
2825 }
2826
2827 mutex_unlock(&power_domains->lock);
2828
2829 return 0;
2830}
2831
Damien Lespiaub7cec662015-10-27 14:47:01 +02002832static int i915_dmc_info(struct seq_file *m, void *unused)
2833{
2834 struct drm_info_node *node = m->private;
2835 struct drm_device *dev = node->minor->dev;
2836 struct drm_i915_private *dev_priv = dev->dev_private;
2837 struct intel_csr *csr;
2838
2839 if (!HAS_CSR(dev)) {
2840 seq_puts(m, "not supported\n");
2841 return 0;
2842 }
2843
2844 csr = &dev_priv->csr;
2845
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002846 intel_runtime_pm_get(dev_priv);
2847
Damien Lespiaub7cec662015-10-27 14:47:01 +02002848 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2849 seq_printf(m, "path: %s\n", csr->fw_path);
2850
2851 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002852 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002853
2854 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2855 CSR_VERSION_MINOR(csr->version));
2856
Damien Lespiau83372062015-10-30 17:53:32 +02002857 if (IS_SKYLAKE(dev) && csr->version >= CSR_VERSION(1, 6)) {
2858 seq_printf(m, "DC3 -> DC5 count: %d\n",
2859 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2860 seq_printf(m, "DC5 -> DC6 count: %d\n",
2861 I915_READ(SKL_CSR_DC5_DC6_COUNT));
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002862 } else if (IS_BROXTON(dev) && csr->version >= CSR_VERSION(1, 4)) {
2863 seq_printf(m, "DC3 -> DC5 count: %d\n",
2864 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002865 }
2866
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002867out:
2868 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2869 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2870 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2871
Damien Lespiau83372062015-10-30 17:53:32 +02002872 intel_runtime_pm_put(dev_priv);
2873
Damien Lespiaub7cec662015-10-27 14:47:01 +02002874 return 0;
2875}
2876
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002877static void intel_seq_print_mode(struct seq_file *m, int tabs,
2878 struct drm_display_mode *mode)
2879{
2880 int i;
2881
2882 for (i = 0; i < tabs; i++)
2883 seq_putc(m, '\t');
2884
2885 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",
2886 mode->base.id, mode->name,
2887 mode->vrefresh, mode->clock,
2888 mode->hdisplay, mode->hsync_start,
2889 mode->hsync_end, mode->htotal,
2890 mode->vdisplay, mode->vsync_start,
2891 mode->vsync_end, mode->vtotal,
2892 mode->type, mode->flags);
2893}
2894
2895static void intel_encoder_info(struct seq_file *m,
2896 struct intel_crtc *intel_crtc,
2897 struct intel_encoder *intel_encoder)
2898{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002899 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002900 struct drm_device *dev = node->minor->dev;
2901 struct drm_crtc *crtc = &intel_crtc->base;
2902 struct intel_connector *intel_connector;
2903 struct drm_encoder *encoder;
2904
2905 encoder = &intel_encoder->base;
2906 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002907 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002908 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2909 struct drm_connector *connector = &intel_connector->base;
2910 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2911 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002912 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002913 drm_get_connector_status_name(connector->status));
2914 if (connector->status == connector_status_connected) {
2915 struct drm_display_mode *mode = &crtc->mode;
2916 seq_printf(m, ", mode:\n");
2917 intel_seq_print_mode(m, 2, mode);
2918 } else {
2919 seq_putc(m, '\n');
2920 }
2921 }
2922}
2923
2924static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2925{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002926 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002927 struct drm_device *dev = node->minor->dev;
2928 struct drm_crtc *crtc = &intel_crtc->base;
2929 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002930 struct drm_plane_state *plane_state = crtc->primary->state;
2931 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002932
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002933 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002934 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002935 fb->base.id, plane_state->src_x >> 16,
2936 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002937 else
2938 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002939 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2940 intel_encoder_info(m, intel_crtc, intel_encoder);
2941}
2942
2943static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2944{
2945 struct drm_display_mode *mode = panel->fixed_mode;
2946
2947 seq_printf(m, "\tfixed mode:\n");
2948 intel_seq_print_mode(m, 2, mode);
2949}
2950
2951static void intel_dp_info(struct seq_file *m,
2952 struct intel_connector *intel_connector)
2953{
2954 struct intel_encoder *intel_encoder = intel_connector->encoder;
2955 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2956
2957 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002958 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002959 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2960 intel_panel_info(m, &intel_connector->panel);
2961}
2962
2963static void intel_hdmi_info(struct seq_file *m,
2964 struct intel_connector *intel_connector)
2965{
2966 struct intel_encoder *intel_encoder = intel_connector->encoder;
2967 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2968
Jani Nikula742f4912015-09-03 11:16:09 +03002969 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002970}
2971
2972static void intel_lvds_info(struct seq_file *m,
2973 struct intel_connector *intel_connector)
2974{
2975 intel_panel_info(m, &intel_connector->panel);
2976}
2977
2978static void intel_connector_info(struct seq_file *m,
2979 struct drm_connector *connector)
2980{
2981 struct intel_connector *intel_connector = to_intel_connector(connector);
2982 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002983 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002984
2985 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002986 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002987 drm_get_connector_status_name(connector->status));
2988 if (connector->status == connector_status_connected) {
2989 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2990 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2991 connector->display_info.width_mm,
2992 connector->display_info.height_mm);
2993 seq_printf(m, "\tsubpixel order: %s\n",
2994 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2995 seq_printf(m, "\tCEA rev: %d\n",
2996 connector->display_info.cea_rev);
2997 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002998 if (intel_encoder) {
2999 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
3000 intel_encoder->type == INTEL_OUTPUT_EDP)
3001 intel_dp_info(m, intel_connector);
3002 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
3003 intel_hdmi_info(m, intel_connector);
3004 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
3005 intel_lvds_info(m, intel_connector);
3006 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003007
Jesse Barnesf103fc72014-02-20 12:39:57 -08003008 seq_printf(m, "\tmodes:\n");
3009 list_for_each_entry(mode, &connector->modes, head)
3010 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003011}
3012
Chris Wilson065f2ec22014-03-12 09:13:13 +00003013static bool cursor_active(struct drm_device *dev, int pipe)
3014{
3015 struct drm_i915_private *dev_priv = dev->dev_private;
3016 u32 state;
3017
3018 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03003019 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003020 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003021 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003022
3023 return state;
3024}
3025
3026static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
3027{
3028 struct drm_i915_private *dev_priv = dev->dev_private;
3029 u32 pos;
3030
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003031 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00003032
3033 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3034 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3035 *x = -*x;
3036
3037 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3038 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3039 *y = -*y;
3040
3041 return cursor_active(dev, pipe);
3042}
3043
Robert Fekete3abc4e02015-10-27 16:58:32 +01003044static const char *plane_type(enum drm_plane_type type)
3045{
3046 switch (type) {
3047 case DRM_PLANE_TYPE_OVERLAY:
3048 return "OVL";
3049 case DRM_PLANE_TYPE_PRIMARY:
3050 return "PRI";
3051 case DRM_PLANE_TYPE_CURSOR:
3052 return "CUR";
3053 /*
3054 * Deliberately omitting default: to generate compiler warnings
3055 * when a new drm_plane_type gets added.
3056 */
3057 }
3058
3059 return "unknown";
3060}
3061
3062static const char *plane_rotation(unsigned int rotation)
3063{
3064 static char buf[48];
3065 /*
3066 * According to doc only one DRM_ROTATE_ is allowed but this
3067 * will print them all to visualize if the values are misused
3068 */
3069 snprintf(buf, sizeof(buf),
3070 "%s%s%s%s%s%s(0x%08x)",
3071 (rotation & BIT(DRM_ROTATE_0)) ? "0 " : "",
3072 (rotation & BIT(DRM_ROTATE_90)) ? "90 " : "",
3073 (rotation & BIT(DRM_ROTATE_180)) ? "180 " : "",
3074 (rotation & BIT(DRM_ROTATE_270)) ? "270 " : "",
3075 (rotation & BIT(DRM_REFLECT_X)) ? "FLIPX " : "",
3076 (rotation & BIT(DRM_REFLECT_Y)) ? "FLIPY " : "",
3077 rotation);
3078
3079 return buf;
3080}
3081
3082static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3083{
3084 struct drm_info_node *node = m->private;
3085 struct drm_device *dev = node->minor->dev;
3086 struct intel_plane *intel_plane;
3087
3088 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3089 struct drm_plane_state *state;
3090 struct drm_plane *plane = &intel_plane->base;
3091
3092 if (!plane->state) {
3093 seq_puts(m, "plane->state is NULL!\n");
3094 continue;
3095 }
3096
3097 state = plane->state;
3098
3099 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",
3100 plane->base.id,
3101 plane_type(intel_plane->base.type),
3102 state->crtc_x, state->crtc_y,
3103 state->crtc_w, state->crtc_h,
3104 (state->src_x >> 16),
3105 ((state->src_x & 0xffff) * 15625) >> 10,
3106 (state->src_y >> 16),
3107 ((state->src_y & 0xffff) * 15625) >> 10,
3108 (state->src_w >> 16),
3109 ((state->src_w & 0xffff) * 15625) >> 10,
3110 (state->src_h >> 16),
3111 ((state->src_h & 0xffff) * 15625) >> 10,
3112 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3113 plane_rotation(state->rotation));
3114 }
3115}
3116
3117static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3118{
3119 struct intel_crtc_state *pipe_config;
3120 int num_scalers = intel_crtc->num_scalers;
3121 int i;
3122
3123 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3124
3125 /* Not all platformas have a scaler */
3126 if (num_scalers) {
3127 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3128 num_scalers,
3129 pipe_config->scaler_state.scaler_users,
3130 pipe_config->scaler_state.scaler_id);
3131
3132 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3133 struct intel_scaler *sc =
3134 &pipe_config->scaler_state.scalers[i];
3135
3136 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3137 i, yesno(sc->in_use), sc->mode);
3138 }
3139 seq_puts(m, "\n");
3140 } else {
3141 seq_puts(m, "\tNo scalers available on this platform\n");
3142 }
3143}
3144
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003145static int i915_display_info(struct seq_file *m, void *unused)
3146{
Damien Lespiau9f25d002014-05-13 15:30:28 +01003147 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003148 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003149 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003150 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003151 struct drm_connector *connector;
3152
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003153 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003154 drm_modeset_lock_all(dev);
3155 seq_printf(m, "CRTC info\n");
3156 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003157 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003158 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003159 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003160 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003161
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003162 pipe_config = to_intel_crtc_state(crtc->base.state);
3163
Robert Fekete3abc4e02015-10-27 16:58:32 +01003164 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00003165 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003166 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003167 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3168 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3169
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003170 if (pipe_config->base.active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003171 intel_crtc_info(m, crtc);
3172
Paulo Zanonia23dc652014-04-01 14:55:11 -03003173 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003174 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 +03003175 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003176 x, y, crtc->base.cursor->state->crtc_w,
3177 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003178 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003179 intel_scaler_info(m, crtc);
3180 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003181 }
Daniel Vettercace8412014-05-22 17:56:31 +02003182
3183 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3184 yesno(!crtc->cpu_fifo_underrun_disabled),
3185 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003186 }
3187
3188 seq_printf(m, "\n");
3189 seq_printf(m, "Connector info\n");
3190 seq_printf(m, "--------------\n");
3191 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3192 intel_connector_info(m, connector);
3193 }
3194 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003195 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003196
3197 return 0;
3198}
3199
Ben Widawskye04934c2014-06-30 09:53:42 -07003200static int i915_semaphore_status(struct seq_file *m, void *unused)
3201{
3202 struct drm_info_node *node = (struct drm_info_node *) m->private;
3203 struct drm_device *dev = node->minor->dev;
3204 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003205 struct intel_engine_cs *engine;
Ben Widawskye04934c2014-06-30 09:53:42 -07003206 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
Dave Gordonc3232b12016-03-23 18:19:53 +00003207 enum intel_engine_id id;
3208 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003209
Chris Wilsonc0336662016-05-06 15:40:21 +01003210 if (!i915_semaphore_is_enabled(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003211 seq_puts(m, "Semaphores are disabled\n");
3212 return 0;
3213 }
3214
3215 ret = mutex_lock_interruptible(&dev->struct_mutex);
3216 if (ret)
3217 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003218 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003219
3220 if (IS_BROADWELL(dev)) {
3221 struct page *page;
3222 uint64_t *seqno;
3223
3224 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3225
3226 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003227 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003228 uint64_t offset;
3229
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003230 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003231
3232 seq_puts(m, " Last signal:");
3233 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003234 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003235 seq_printf(m, "0x%08llx (0x%02llx) ",
3236 seqno[offset], offset * 8);
3237 }
3238 seq_putc(m, '\n');
3239
3240 seq_puts(m, " Last wait: ");
3241 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003242 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003243 seq_printf(m, "0x%08llx (0x%02llx) ",
3244 seqno[offset], offset * 8);
3245 }
3246 seq_putc(m, '\n');
3247
3248 }
3249 kunmap_atomic(seqno);
3250 } else {
3251 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003252 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003253 for (j = 0; j < num_rings; j++)
3254 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003255 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003256 seq_putc(m, '\n');
3257 }
3258
3259 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003260 for_each_engine(engine, dev_priv) {
3261 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003262 seq_printf(m, " 0x%08x ",
3263 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003264 seq_putc(m, '\n');
3265 }
3266 seq_putc(m, '\n');
3267
Paulo Zanoni03872062014-07-09 14:31:57 -03003268 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003269 mutex_unlock(&dev->struct_mutex);
3270 return 0;
3271}
3272
Daniel Vetter728e29d2014-06-25 22:01:53 +03003273static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3274{
3275 struct drm_info_node *node = (struct drm_info_node *) m->private;
3276 struct drm_device *dev = node->minor->dev;
3277 struct drm_i915_private *dev_priv = dev->dev_private;
3278 int i;
3279
3280 drm_modeset_lock_all(dev);
3281 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3282 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3283
3284 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003285 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3286 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003287 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003288 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3289 seq_printf(m, " dpll_md: 0x%08x\n",
3290 pll->config.hw_state.dpll_md);
3291 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3292 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3293 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003294 }
3295 drm_modeset_unlock_all(dev);
3296
3297 return 0;
3298}
3299
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003300static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003301{
3302 int i;
3303 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003304 struct intel_engine_cs *engine;
Arun Siluvery888b5992014-08-26 14:44:51 +01003305 struct drm_info_node *node = (struct drm_info_node *) m->private;
3306 struct drm_device *dev = node->minor->dev;
3307 struct drm_i915_private *dev_priv = dev->dev_private;
Arun Siluvery33136b02016-01-21 21:43:47 +00003308 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003309 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003310
Arun Siluvery888b5992014-08-26 14:44:51 +01003311 ret = mutex_lock_interruptible(&dev->struct_mutex);
3312 if (ret)
3313 return ret;
3314
3315 intel_runtime_pm_get(dev_priv);
3316
Arun Siluvery33136b02016-01-21 21:43:47 +00003317 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003318 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003319 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003320 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003321 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003322 i915_reg_t addr;
3323 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003324 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003325
Arun Siluvery33136b02016-01-21 21:43:47 +00003326 addr = workarounds->reg[i].addr;
3327 mask = workarounds->reg[i].mask;
3328 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003329 read = I915_READ(addr);
3330 ok = (value & mask) == (read & mask);
3331 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 +02003332 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003333 }
3334
3335 intel_runtime_pm_put(dev_priv);
3336 mutex_unlock(&dev->struct_mutex);
3337
3338 return 0;
3339}
3340
Damien Lespiauc5511e42014-11-04 17:06:51 +00003341static int i915_ddb_info(struct seq_file *m, void *unused)
3342{
3343 struct drm_info_node *node = m->private;
3344 struct drm_device *dev = node->minor->dev;
3345 struct drm_i915_private *dev_priv = dev->dev_private;
3346 struct skl_ddb_allocation *ddb;
3347 struct skl_ddb_entry *entry;
3348 enum pipe pipe;
3349 int plane;
3350
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003351 if (INTEL_INFO(dev)->gen < 9)
3352 return 0;
3353
Damien Lespiauc5511e42014-11-04 17:06:51 +00003354 drm_modeset_lock_all(dev);
3355
3356 ddb = &dev_priv->wm.skl_hw.ddb;
3357
3358 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3359
3360 for_each_pipe(dev_priv, pipe) {
3361 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3362
Damien Lespiaudd740782015-02-28 14:54:08 +00003363 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003364 entry = &ddb->plane[pipe][plane];
3365 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3366 entry->start, entry->end,
3367 skl_ddb_entry_size(entry));
3368 }
3369
Matt Roper4969d332015-09-24 15:53:10 -07003370 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003371 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3372 entry->end, skl_ddb_entry_size(entry));
3373 }
3374
3375 drm_modeset_unlock_all(dev);
3376
3377 return 0;
3378}
3379
Vandana Kannana54746e2015-03-03 20:53:10 +05303380static void drrs_status_per_crtc(struct seq_file *m,
3381 struct drm_device *dev, struct intel_crtc *intel_crtc)
3382{
3383 struct intel_encoder *intel_encoder;
3384 struct drm_i915_private *dev_priv = dev->dev_private;
3385 struct i915_drrs *drrs = &dev_priv->drrs;
3386 int vrefresh = 0;
3387
3388 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3389 /* Encoder connected on this CRTC */
3390 switch (intel_encoder->type) {
3391 case INTEL_OUTPUT_EDP:
3392 seq_puts(m, "eDP:\n");
3393 break;
3394 case INTEL_OUTPUT_DSI:
3395 seq_puts(m, "DSI:\n");
3396 break;
3397 case INTEL_OUTPUT_HDMI:
3398 seq_puts(m, "HDMI:\n");
3399 break;
3400 case INTEL_OUTPUT_DISPLAYPORT:
3401 seq_puts(m, "DP:\n");
3402 break;
3403 default:
3404 seq_printf(m, "Other encoder (id=%d).\n",
3405 intel_encoder->type);
3406 return;
3407 }
3408 }
3409
3410 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3411 seq_puts(m, "\tVBT: DRRS_type: Static");
3412 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3413 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3414 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3415 seq_puts(m, "\tVBT: DRRS_type: None");
3416 else
3417 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3418
3419 seq_puts(m, "\n\n");
3420
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003421 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303422 struct intel_panel *panel;
3423
3424 mutex_lock(&drrs->mutex);
3425 /* DRRS Supported */
3426 seq_puts(m, "\tDRRS Supported: Yes\n");
3427
3428 /* disable_drrs() will make drrs->dp NULL */
3429 if (!drrs->dp) {
3430 seq_puts(m, "Idleness DRRS: Disabled");
3431 mutex_unlock(&drrs->mutex);
3432 return;
3433 }
3434
3435 panel = &drrs->dp->attached_connector->panel;
3436 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3437 drrs->busy_frontbuffer_bits);
3438
3439 seq_puts(m, "\n\t\t");
3440 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3441 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3442 vrefresh = panel->fixed_mode->vrefresh;
3443 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3444 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3445 vrefresh = panel->downclock_mode->vrefresh;
3446 } else {
3447 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3448 drrs->refresh_rate_type);
3449 mutex_unlock(&drrs->mutex);
3450 return;
3451 }
3452 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3453
3454 seq_puts(m, "\n\t\t");
3455 mutex_unlock(&drrs->mutex);
3456 } else {
3457 /* DRRS not supported. Print the VBT parameter*/
3458 seq_puts(m, "\tDRRS Supported : No");
3459 }
3460 seq_puts(m, "\n");
3461}
3462
3463static int i915_drrs_status(struct seq_file *m, void *unused)
3464{
3465 struct drm_info_node *node = m->private;
3466 struct drm_device *dev = node->minor->dev;
3467 struct intel_crtc *intel_crtc;
3468 int active_crtc_cnt = 0;
3469
3470 for_each_intel_crtc(dev, intel_crtc) {
3471 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3472
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003473 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303474 active_crtc_cnt++;
3475 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3476
3477 drrs_status_per_crtc(m, dev, intel_crtc);
3478 }
3479
3480 drm_modeset_unlock(&intel_crtc->base.mutex);
3481 }
3482
3483 if (!active_crtc_cnt)
3484 seq_puts(m, "No active crtc found\n");
3485
3486 return 0;
3487}
3488
Damien Lespiau07144422013-10-15 18:55:40 +01003489struct pipe_crc_info {
3490 const char *name;
3491 struct drm_device *dev;
3492 enum pipe pipe;
3493};
3494
Dave Airlie11bed952014-05-12 15:22:27 +10003495static int i915_dp_mst_info(struct seq_file *m, void *unused)
3496{
3497 struct drm_info_node *node = (struct drm_info_node *) m->private;
3498 struct drm_device *dev = node->minor->dev;
3499 struct drm_encoder *encoder;
3500 struct intel_encoder *intel_encoder;
3501 struct intel_digital_port *intel_dig_port;
3502 drm_modeset_lock_all(dev);
3503 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3504 intel_encoder = to_intel_encoder(encoder);
3505 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3506 continue;
3507 intel_dig_port = enc_to_dig_port(encoder);
3508 if (!intel_dig_port->dp.can_mst)
3509 continue;
Jim Bride40ae80c2016-04-14 10:18:37 -07003510 seq_printf(m, "MST Source Port %c\n",
3511 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003512 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3513 }
3514 drm_modeset_unlock_all(dev);
3515 return 0;
3516}
3517
Damien Lespiau07144422013-10-15 18:55:40 +01003518static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003519{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003520 struct pipe_crc_info *info = inode->i_private;
3521 struct drm_i915_private *dev_priv = info->dev->dev_private;
3522 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3523
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003524 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3525 return -ENODEV;
3526
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003527 spin_lock_irq(&pipe_crc->lock);
3528
3529 if (pipe_crc->opened) {
3530 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003531 return -EBUSY; /* already open */
3532 }
3533
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003534 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003535 filep->private_data = inode->i_private;
3536
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003537 spin_unlock_irq(&pipe_crc->lock);
3538
Damien Lespiau07144422013-10-15 18:55:40 +01003539 return 0;
3540}
3541
3542static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3543{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003544 struct pipe_crc_info *info = inode->i_private;
3545 struct drm_i915_private *dev_priv = info->dev->dev_private;
3546 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3547
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003548 spin_lock_irq(&pipe_crc->lock);
3549 pipe_crc->opened = false;
3550 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003551
Damien Lespiau07144422013-10-15 18:55:40 +01003552 return 0;
3553}
3554
3555/* (6 fields, 8 chars each, space separated (5) + '\n') */
3556#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3557/* account for \'0' */
3558#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3559
3560static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3561{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003562 assert_spin_locked(&pipe_crc->lock);
3563 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3564 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003565}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003566
Damien Lespiau07144422013-10-15 18:55:40 +01003567static ssize_t
3568i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3569 loff_t *pos)
3570{
3571 struct pipe_crc_info *info = filep->private_data;
3572 struct drm_device *dev = info->dev;
3573 struct drm_i915_private *dev_priv = dev->dev_private;
3574 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3575 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003576 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003577 ssize_t bytes_read;
3578
3579 /*
3580 * Don't allow user space to provide buffers not big enough to hold
3581 * a line of data.
3582 */
3583 if (count < PIPE_CRC_LINE_LEN)
3584 return -EINVAL;
3585
3586 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3587 return 0;
3588
3589 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003590 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003591 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003592 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003593
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003594 if (filep->f_flags & O_NONBLOCK) {
3595 spin_unlock_irq(&pipe_crc->lock);
3596 return -EAGAIN;
3597 }
3598
3599 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3600 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3601 if (ret) {
3602 spin_unlock_irq(&pipe_crc->lock);
3603 return ret;
3604 }
Damien Lespiau07144422013-10-15 18:55:40 +01003605 }
3606
3607 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003608 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003609
Damien Lespiau07144422013-10-15 18:55:40 +01003610 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003611 while (n_entries > 0) {
3612 struct intel_pipe_crc_entry *entry =
3613 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003614 int ret;
3615
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003616 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3617 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3618 break;
3619
3620 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3621 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3622
Damien Lespiau07144422013-10-15 18:55:40 +01003623 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3624 "%8u %8x %8x %8x %8x %8x\n",
3625 entry->frame, entry->crc[0],
3626 entry->crc[1], entry->crc[2],
3627 entry->crc[3], entry->crc[4]);
3628
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003629 spin_unlock_irq(&pipe_crc->lock);
3630
3631 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003632 if (ret == PIPE_CRC_LINE_LEN)
3633 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003634
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003635 user_buf += PIPE_CRC_LINE_LEN;
3636 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003637
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003638 spin_lock_irq(&pipe_crc->lock);
3639 }
3640
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003641 spin_unlock_irq(&pipe_crc->lock);
3642
Damien Lespiau07144422013-10-15 18:55:40 +01003643 return bytes_read;
3644}
3645
3646static const struct file_operations i915_pipe_crc_fops = {
3647 .owner = THIS_MODULE,
3648 .open = i915_pipe_crc_open,
3649 .read = i915_pipe_crc_read,
3650 .release = i915_pipe_crc_release,
3651};
3652
3653static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3654 {
3655 .name = "i915_pipe_A_crc",
3656 .pipe = PIPE_A,
3657 },
3658 {
3659 .name = "i915_pipe_B_crc",
3660 .pipe = PIPE_B,
3661 },
3662 {
3663 .name = "i915_pipe_C_crc",
3664 .pipe = PIPE_C,
3665 },
3666};
3667
3668static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3669 enum pipe pipe)
3670{
3671 struct drm_device *dev = minor->dev;
3672 struct dentry *ent;
3673 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3674
3675 info->dev = dev;
3676 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3677 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003678 if (!ent)
3679 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003680
3681 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003682}
3683
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003684static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003685 "none",
3686 "plane1",
3687 "plane2",
3688 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003689 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003690 "TV",
3691 "DP-B",
3692 "DP-C",
3693 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003694 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003695};
3696
3697static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3698{
3699 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3700 return pipe_crc_sources[source];
3701}
3702
Damien Lespiaubd9db022013-10-15 18:55:36 +01003703static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003704{
3705 struct drm_device *dev = m->private;
3706 struct drm_i915_private *dev_priv = dev->dev_private;
3707 int i;
3708
3709 for (i = 0; i < I915_MAX_PIPES; i++)
3710 seq_printf(m, "%c %s\n", pipe_name(i),
3711 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3712
3713 return 0;
3714}
3715
Damien Lespiaubd9db022013-10-15 18:55:36 +01003716static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003717{
3718 struct drm_device *dev = inode->i_private;
3719
Damien Lespiaubd9db022013-10-15 18:55:36 +01003720 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003721}
3722
Daniel Vetter46a19182013-11-01 10:50:20 +01003723static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003724 uint32_t *val)
3725{
Daniel Vetter46a19182013-11-01 10:50:20 +01003726 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3727 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3728
3729 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003730 case INTEL_PIPE_CRC_SOURCE_PIPE:
3731 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3732 break;
3733 case INTEL_PIPE_CRC_SOURCE_NONE:
3734 *val = 0;
3735 break;
3736 default:
3737 return -EINVAL;
3738 }
3739
3740 return 0;
3741}
3742
Daniel Vetter46a19182013-11-01 10:50:20 +01003743static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3744 enum intel_pipe_crc_source *source)
3745{
3746 struct intel_encoder *encoder;
3747 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003748 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003749 int ret = 0;
3750
3751 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3752
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003753 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003754 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003755 if (!encoder->base.crtc)
3756 continue;
3757
3758 crtc = to_intel_crtc(encoder->base.crtc);
3759
3760 if (crtc->pipe != pipe)
3761 continue;
3762
3763 switch (encoder->type) {
3764 case INTEL_OUTPUT_TVOUT:
3765 *source = INTEL_PIPE_CRC_SOURCE_TV;
3766 break;
3767 case INTEL_OUTPUT_DISPLAYPORT:
3768 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003769 dig_port = enc_to_dig_port(&encoder->base);
3770 switch (dig_port->port) {
3771 case PORT_B:
3772 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3773 break;
3774 case PORT_C:
3775 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3776 break;
3777 case PORT_D:
3778 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3779 break;
3780 default:
3781 WARN(1, "nonexisting DP port %c\n",
3782 port_name(dig_port->port));
3783 break;
3784 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003785 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003786 default:
3787 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003788 }
3789 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003790 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003791
3792 return ret;
3793}
3794
3795static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3796 enum pipe pipe,
3797 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003798 uint32_t *val)
3799{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003800 struct drm_i915_private *dev_priv = dev->dev_private;
3801 bool need_stable_symbols = false;
3802
Daniel Vetter46a19182013-11-01 10:50:20 +01003803 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3804 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3805 if (ret)
3806 return ret;
3807 }
3808
3809 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003810 case INTEL_PIPE_CRC_SOURCE_PIPE:
3811 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3812 break;
3813 case INTEL_PIPE_CRC_SOURCE_DP_B:
3814 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003815 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003816 break;
3817 case INTEL_PIPE_CRC_SOURCE_DP_C:
3818 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003819 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003820 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003821 case INTEL_PIPE_CRC_SOURCE_DP_D:
3822 if (!IS_CHERRYVIEW(dev))
3823 return -EINVAL;
3824 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3825 need_stable_symbols = true;
3826 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003827 case INTEL_PIPE_CRC_SOURCE_NONE:
3828 *val = 0;
3829 break;
3830 default:
3831 return -EINVAL;
3832 }
3833
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003834 /*
3835 * When the pipe CRC tap point is after the transcoders we need
3836 * to tweak symbol-level features to produce a deterministic series of
3837 * symbols for a given frame. We need to reset those features only once
3838 * a frame (instead of every nth symbol):
3839 * - DC-balance: used to ensure a better clock recovery from the data
3840 * link (SDVO)
3841 * - DisplayPort scrambling: used for EMI reduction
3842 */
3843 if (need_stable_symbols) {
3844 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3845
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003846 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003847 switch (pipe) {
3848 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003849 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003850 break;
3851 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003852 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003853 break;
3854 case PIPE_C:
3855 tmp |= PIPE_C_SCRAMBLE_RESET;
3856 break;
3857 default:
3858 return -EINVAL;
3859 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003860 I915_WRITE(PORT_DFT2_G4X, tmp);
3861 }
3862
Daniel Vetter7ac01292013-10-18 16:37:06 +02003863 return 0;
3864}
3865
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003866static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003867 enum pipe pipe,
3868 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003869 uint32_t *val)
3870{
Daniel Vetter84093602013-11-01 10:50:21 +01003871 struct drm_i915_private *dev_priv = dev->dev_private;
3872 bool need_stable_symbols = false;
3873
Daniel Vetter46a19182013-11-01 10:50:20 +01003874 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3875 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3876 if (ret)
3877 return ret;
3878 }
3879
3880 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003881 case INTEL_PIPE_CRC_SOURCE_PIPE:
3882 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3883 break;
3884 case INTEL_PIPE_CRC_SOURCE_TV:
3885 if (!SUPPORTS_TV(dev))
3886 return -EINVAL;
3887 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3888 break;
3889 case INTEL_PIPE_CRC_SOURCE_DP_B:
3890 if (!IS_G4X(dev))
3891 return -EINVAL;
3892 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003893 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003894 break;
3895 case INTEL_PIPE_CRC_SOURCE_DP_C:
3896 if (!IS_G4X(dev))
3897 return -EINVAL;
3898 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003899 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003900 break;
3901 case INTEL_PIPE_CRC_SOURCE_DP_D:
3902 if (!IS_G4X(dev))
3903 return -EINVAL;
3904 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003905 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003906 break;
3907 case INTEL_PIPE_CRC_SOURCE_NONE:
3908 *val = 0;
3909 break;
3910 default:
3911 return -EINVAL;
3912 }
3913
Daniel Vetter84093602013-11-01 10:50:21 +01003914 /*
3915 * When the pipe CRC tap point is after the transcoders we need
3916 * to tweak symbol-level features to produce a deterministic series of
3917 * symbols for a given frame. We need to reset those features only once
3918 * a frame (instead of every nth symbol):
3919 * - DC-balance: used to ensure a better clock recovery from the data
3920 * link (SDVO)
3921 * - DisplayPort scrambling: used for EMI reduction
3922 */
3923 if (need_stable_symbols) {
3924 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3925
3926 WARN_ON(!IS_G4X(dev));
3927
3928 I915_WRITE(PORT_DFT_I9XX,
3929 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3930
3931 if (pipe == PIPE_A)
3932 tmp |= PIPE_A_SCRAMBLE_RESET;
3933 else
3934 tmp |= PIPE_B_SCRAMBLE_RESET;
3935
3936 I915_WRITE(PORT_DFT2_G4X, tmp);
3937 }
3938
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003939 return 0;
3940}
3941
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003942static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3943 enum pipe pipe)
3944{
3945 struct drm_i915_private *dev_priv = dev->dev_private;
3946 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3947
Ville Syrjäläeb736672014-12-09 21:28:28 +02003948 switch (pipe) {
3949 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003950 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003951 break;
3952 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003953 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003954 break;
3955 case PIPE_C:
3956 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3957 break;
3958 default:
3959 return;
3960 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003961 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3962 tmp &= ~DC_BALANCE_RESET_VLV;
3963 I915_WRITE(PORT_DFT2_G4X, tmp);
3964
3965}
3966
Daniel Vetter84093602013-11-01 10:50:21 +01003967static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3968 enum pipe pipe)
3969{
3970 struct drm_i915_private *dev_priv = dev->dev_private;
3971 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3972
3973 if (pipe == PIPE_A)
3974 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3975 else
3976 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3977 I915_WRITE(PORT_DFT2_G4X, tmp);
3978
3979 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3980 I915_WRITE(PORT_DFT_I9XX,
3981 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3982 }
3983}
3984
Daniel Vetter46a19182013-11-01 10:50:20 +01003985static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003986 uint32_t *val)
3987{
Daniel Vetter46a19182013-11-01 10:50:20 +01003988 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3989 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3990
3991 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003992 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3993 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3994 break;
3995 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3996 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3997 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003998 case INTEL_PIPE_CRC_SOURCE_PIPE:
3999 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4000 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004001 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004002 *val = 0;
4003 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004004 default:
4005 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004006 }
4007
4008 return 0;
4009}
4010
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004011static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004012{
4013 struct drm_i915_private *dev_priv = dev->dev_private;
4014 struct intel_crtc *crtc =
4015 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004016 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004017 struct drm_atomic_state *state;
4018 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004019
4020 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004021 state = drm_atomic_state_alloc(dev);
4022 if (!state) {
4023 ret = -ENOMEM;
4024 goto out;
4025 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004026
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004027 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4028 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4029 if (IS_ERR(pipe_config)) {
4030 ret = PTR_ERR(pipe_config);
4031 goto out;
4032 }
4033
4034 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004035 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004036 pipe_config->pch_pfit.enabled != enable)
4037 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004038
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004039 ret = drm_atomic_commit(state);
4040out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004041 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004042 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
4043 if (ret)
4044 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004045}
4046
4047static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
4048 enum pipe pipe,
4049 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004050 uint32_t *val)
4051{
Daniel Vetter46a19182013-11-01 10:50:20 +01004052 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4053 *source = INTEL_PIPE_CRC_SOURCE_PF;
4054
4055 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004056 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4057 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4058 break;
4059 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4060 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4061 break;
4062 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004063 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004064 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004065
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004066 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4067 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004068 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004069 *val = 0;
4070 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004071 default:
4072 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004073 }
4074
4075 return 0;
4076}
4077
Daniel Vetter926321d2013-10-16 13:30:34 +02004078static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
4079 enum intel_pipe_crc_source source)
4080{
4081 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004082 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004083 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
4084 pipe));
Imre Deake1296492016-02-12 18:55:17 +02004085 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004086 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004087 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004088
Damien Lespiaucc3da172013-10-15 18:55:31 +01004089 if (pipe_crc->source == source)
4090 return 0;
4091
Damien Lespiauae676fc2013-10-15 18:55:32 +01004092 /* forbid changing the source without going back to 'none' */
4093 if (pipe_crc->source && source)
4094 return -EINVAL;
4095
Imre Deake1296492016-02-12 18:55:17 +02004096 power_domain = POWER_DOMAIN_PIPE(pipe);
4097 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004098 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4099 return -EIO;
4100 }
4101
Daniel Vetter52f843f2013-10-21 17:26:38 +02004102 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004103 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02004104 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01004105 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Wayne Boyer666a4532015-12-09 12:29:35 -08004106 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004107 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004108 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004109 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004110 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004111 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004112
4113 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004114 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004115
Damien Lespiau4b584362013-10-15 18:55:33 +01004116 /* none -> real source transition */
4117 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004118 struct intel_pipe_crc_entry *entries;
4119
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004120 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4121 pipe_name(pipe), pipe_crc_source_name(source));
4122
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004123 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4124 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004125 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004126 if (!entries) {
4127 ret = -ENOMEM;
4128 goto out;
4129 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004130
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004131 /*
4132 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4133 * enabled and disabled dynamically based on package C states,
4134 * user space can't make reliable use of the CRCs, so let's just
4135 * completely disable it.
4136 */
4137 hsw_disable_ips(crtc);
4138
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004139 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004140 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004141 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004142 pipe_crc->head = 0;
4143 pipe_crc->tail = 0;
4144 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004145 }
4146
Damien Lespiaucc3da172013-10-15 18:55:31 +01004147 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004148
Daniel Vetter926321d2013-10-16 13:30:34 +02004149 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4150 POSTING_READ(PIPE_CRC_CTL(pipe));
4151
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004152 /* real source -> none transition */
4153 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004154 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004155 struct intel_crtc *crtc =
4156 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004157
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004158 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4159 pipe_name(pipe));
4160
Daniel Vettera33d7102014-06-06 08:22:08 +02004161 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004162 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004163 intel_wait_for_vblank(dev, pipe);
4164 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004165
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004166 spin_lock_irq(&pipe_crc->lock);
4167 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004168 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004169 pipe_crc->head = 0;
4170 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004171 spin_unlock_irq(&pipe_crc->lock);
4172
4173 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004174
4175 if (IS_G4X(dev))
4176 g4x_undo_pipe_scramble_reset(dev, pipe);
Wayne Boyer666a4532015-12-09 12:29:35 -08004177 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004178 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004179 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004180 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004181
4182 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004183 }
4184
Imre Deake1296492016-02-12 18:55:17 +02004185 ret = 0;
4186
4187out:
4188 intel_display_power_put(dev_priv, power_domain);
4189
4190 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004191}
4192
4193/*
4194 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004195 * command: wsp* object wsp+ name wsp+ source wsp*
4196 * object: 'pipe'
4197 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004198 * source: (none | plane1 | plane2 | pf)
4199 * wsp: (#0x20 | #0x9 | #0xA)+
4200 *
4201 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004202 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4203 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004204 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004205static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004206{
4207 int n_words = 0;
4208
4209 while (*buf) {
4210 char *end;
4211
4212 /* skip leading white space */
4213 buf = skip_spaces(buf);
4214 if (!*buf)
4215 break; /* end of buffer */
4216
4217 /* find end of word */
4218 for (end = buf; *end && !isspace(*end); end++)
4219 ;
4220
4221 if (n_words == max_words) {
4222 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4223 max_words);
4224 return -EINVAL; /* ran out of words[] before bytes */
4225 }
4226
4227 if (*end)
4228 *end++ = '\0';
4229 words[n_words++] = buf;
4230 buf = end;
4231 }
4232
4233 return n_words;
4234}
4235
Damien Lespiaub94dec82013-10-15 18:55:35 +01004236enum intel_pipe_crc_object {
4237 PIPE_CRC_OBJECT_PIPE,
4238};
4239
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004240static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004241 "pipe",
4242};
4243
4244static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004245display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004246{
4247 int i;
4248
4249 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4250 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004251 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004252 return 0;
4253 }
4254
4255 return -EINVAL;
4256}
4257
Damien Lespiaubd9db022013-10-15 18:55:36 +01004258static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004259{
4260 const char name = buf[0];
4261
4262 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4263 return -EINVAL;
4264
4265 *pipe = name - 'A';
4266
4267 return 0;
4268}
4269
4270static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004271display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004272{
4273 int i;
4274
4275 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4276 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004277 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004278 return 0;
4279 }
4280
4281 return -EINVAL;
4282}
4283
Damien Lespiaubd9db022013-10-15 18:55:36 +01004284static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004285{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004286#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004287 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004288 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004289 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004290 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004291 enum intel_pipe_crc_source source;
4292
Damien Lespiaubd9db022013-10-15 18:55:36 +01004293 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004294 if (n_words != N_WORDS) {
4295 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4296 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004297 return -EINVAL;
4298 }
4299
Damien Lespiaubd9db022013-10-15 18:55:36 +01004300 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004301 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004302 return -EINVAL;
4303 }
4304
Damien Lespiaubd9db022013-10-15 18:55:36 +01004305 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004306 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4307 return -EINVAL;
4308 }
4309
Damien Lespiaubd9db022013-10-15 18:55:36 +01004310 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004311 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004312 return -EINVAL;
4313 }
4314
4315 return pipe_crc_set_source(dev, pipe, source);
4316}
4317
Damien Lespiaubd9db022013-10-15 18:55:36 +01004318static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4319 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004320{
4321 struct seq_file *m = file->private_data;
4322 struct drm_device *dev = m->private;
4323 char *tmpbuf;
4324 int ret;
4325
4326 if (len == 0)
4327 return 0;
4328
4329 if (len > PAGE_SIZE - 1) {
4330 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4331 PAGE_SIZE);
4332 return -E2BIG;
4333 }
4334
4335 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4336 if (!tmpbuf)
4337 return -ENOMEM;
4338
4339 if (copy_from_user(tmpbuf, ubuf, len)) {
4340 ret = -EFAULT;
4341 goto out;
4342 }
4343 tmpbuf[len] = '\0';
4344
Damien Lespiaubd9db022013-10-15 18:55:36 +01004345 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004346
4347out:
4348 kfree(tmpbuf);
4349 if (ret < 0)
4350 return ret;
4351
4352 *offp += len;
4353 return len;
4354}
4355
Damien Lespiaubd9db022013-10-15 18:55:36 +01004356static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004357 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004358 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004359 .read = seq_read,
4360 .llseek = seq_lseek,
4361 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004362 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004363};
4364
Todd Previteeb3394fa2015-04-18 00:04:19 -07004365static ssize_t i915_displayport_test_active_write(struct file *file,
4366 const char __user *ubuf,
4367 size_t len, loff_t *offp)
4368{
4369 char *input_buffer;
4370 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004371 struct drm_device *dev;
4372 struct drm_connector *connector;
4373 struct list_head *connector_list;
4374 struct intel_dp *intel_dp;
4375 int val = 0;
4376
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304377 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004378
Todd Previteeb3394fa2015-04-18 00:04:19 -07004379 connector_list = &dev->mode_config.connector_list;
4380
4381 if (len == 0)
4382 return 0;
4383
4384 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4385 if (!input_buffer)
4386 return -ENOMEM;
4387
4388 if (copy_from_user(input_buffer, ubuf, len)) {
4389 status = -EFAULT;
4390 goto out;
4391 }
4392
4393 input_buffer[len] = '\0';
4394 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4395
4396 list_for_each_entry(connector, connector_list, head) {
4397
4398 if (connector->connector_type !=
4399 DRM_MODE_CONNECTOR_DisplayPort)
4400 continue;
4401
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304402 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004403 connector->encoder != NULL) {
4404 intel_dp = enc_to_intel_dp(connector->encoder);
4405 status = kstrtoint(input_buffer, 10, &val);
4406 if (status < 0)
4407 goto out;
4408 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4409 /* To prevent erroneous activation of the compliance
4410 * testing code, only accept an actual value of 1 here
4411 */
4412 if (val == 1)
4413 intel_dp->compliance_test_active = 1;
4414 else
4415 intel_dp->compliance_test_active = 0;
4416 }
4417 }
4418out:
4419 kfree(input_buffer);
4420 if (status < 0)
4421 return status;
4422
4423 *offp += len;
4424 return len;
4425}
4426
4427static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4428{
4429 struct drm_device *dev = m->private;
4430 struct drm_connector *connector;
4431 struct list_head *connector_list = &dev->mode_config.connector_list;
4432 struct intel_dp *intel_dp;
4433
Todd Previteeb3394fa2015-04-18 00:04:19 -07004434 list_for_each_entry(connector, connector_list, head) {
4435
4436 if (connector->connector_type !=
4437 DRM_MODE_CONNECTOR_DisplayPort)
4438 continue;
4439
4440 if (connector->status == connector_status_connected &&
4441 connector->encoder != NULL) {
4442 intel_dp = enc_to_intel_dp(connector->encoder);
4443 if (intel_dp->compliance_test_active)
4444 seq_puts(m, "1");
4445 else
4446 seq_puts(m, "0");
4447 } else
4448 seq_puts(m, "0");
4449 }
4450
4451 return 0;
4452}
4453
4454static int i915_displayport_test_active_open(struct inode *inode,
4455 struct file *file)
4456{
4457 struct drm_device *dev = inode->i_private;
4458
4459 return single_open(file, i915_displayport_test_active_show, dev);
4460}
4461
4462static const struct file_operations i915_displayport_test_active_fops = {
4463 .owner = THIS_MODULE,
4464 .open = i915_displayport_test_active_open,
4465 .read = seq_read,
4466 .llseek = seq_lseek,
4467 .release = single_release,
4468 .write = i915_displayport_test_active_write
4469};
4470
4471static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4472{
4473 struct drm_device *dev = m->private;
4474 struct drm_connector *connector;
4475 struct list_head *connector_list = &dev->mode_config.connector_list;
4476 struct intel_dp *intel_dp;
4477
Todd Previteeb3394fa2015-04-18 00:04:19 -07004478 list_for_each_entry(connector, connector_list, head) {
4479
4480 if (connector->connector_type !=
4481 DRM_MODE_CONNECTOR_DisplayPort)
4482 continue;
4483
4484 if (connector->status == connector_status_connected &&
4485 connector->encoder != NULL) {
4486 intel_dp = enc_to_intel_dp(connector->encoder);
4487 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4488 } else
4489 seq_puts(m, "0");
4490 }
4491
4492 return 0;
4493}
4494static int i915_displayport_test_data_open(struct inode *inode,
4495 struct file *file)
4496{
4497 struct drm_device *dev = inode->i_private;
4498
4499 return single_open(file, i915_displayport_test_data_show, dev);
4500}
4501
4502static const struct file_operations i915_displayport_test_data_fops = {
4503 .owner = THIS_MODULE,
4504 .open = i915_displayport_test_data_open,
4505 .read = seq_read,
4506 .llseek = seq_lseek,
4507 .release = single_release
4508};
4509
4510static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4511{
4512 struct drm_device *dev = m->private;
4513 struct drm_connector *connector;
4514 struct list_head *connector_list = &dev->mode_config.connector_list;
4515 struct intel_dp *intel_dp;
4516
Todd Previteeb3394fa2015-04-18 00:04:19 -07004517 list_for_each_entry(connector, connector_list, head) {
4518
4519 if (connector->connector_type !=
4520 DRM_MODE_CONNECTOR_DisplayPort)
4521 continue;
4522
4523 if (connector->status == connector_status_connected &&
4524 connector->encoder != NULL) {
4525 intel_dp = enc_to_intel_dp(connector->encoder);
4526 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4527 } else
4528 seq_puts(m, "0");
4529 }
4530
4531 return 0;
4532}
4533
4534static int i915_displayport_test_type_open(struct inode *inode,
4535 struct file *file)
4536{
4537 struct drm_device *dev = inode->i_private;
4538
4539 return single_open(file, i915_displayport_test_type_show, dev);
4540}
4541
4542static const struct file_operations i915_displayport_test_type_fops = {
4543 .owner = THIS_MODULE,
4544 .open = i915_displayport_test_type_open,
4545 .read = seq_read,
4546 .llseek = seq_lseek,
4547 .release = single_release
4548};
4549
Damien Lespiau97e94b22014-11-04 17:06:50 +00004550static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004551{
4552 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004553 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004554 int num_levels;
4555
4556 if (IS_CHERRYVIEW(dev))
4557 num_levels = 3;
4558 else if (IS_VALLEYVIEW(dev))
4559 num_levels = 1;
4560 else
4561 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004562
4563 drm_modeset_lock_all(dev);
4564
4565 for (level = 0; level < num_levels; level++) {
4566 unsigned int latency = wm[level];
4567
Damien Lespiau97e94b22014-11-04 17:06:50 +00004568 /*
4569 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004570 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004571 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004572 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev) ||
4573 IS_CHERRYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004574 latency *= 10;
4575 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004576 latency *= 5;
4577
4578 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004579 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004580 }
4581
4582 drm_modeset_unlock_all(dev);
4583}
4584
4585static int pri_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.pri_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 spr_wm_latency_show(struct seq_file *m, void *data)
4602{
4603 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004604 struct drm_i915_private *dev_priv = dev->dev_private;
4605 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004606
Damien Lespiau97e94b22014-11-04 17:06:50 +00004607 if (INTEL_INFO(dev)->gen >= 9)
4608 latencies = dev_priv->wm.skl_latency;
4609 else
4610 latencies = to_i915(dev)->wm.spr_latency;
4611
4612 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004613
4614 return 0;
4615}
4616
4617static int cur_wm_latency_show(struct seq_file *m, void *data)
4618{
4619 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004620 struct drm_i915_private *dev_priv = dev->dev_private;
4621 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004622
Damien Lespiau97e94b22014-11-04 17:06:50 +00004623 if (INTEL_INFO(dev)->gen >= 9)
4624 latencies = dev_priv->wm.skl_latency;
4625 else
4626 latencies = to_i915(dev)->wm.cur_latency;
4627
4628 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004629
4630 return 0;
4631}
4632
4633static int pri_wm_latency_open(struct inode *inode, struct file *file)
4634{
4635 struct drm_device *dev = inode->i_private;
4636
Ville Syrjäläde38b952015-06-24 22:00:09 +03004637 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004638 return -ENODEV;
4639
4640 return single_open(file, pri_wm_latency_show, dev);
4641}
4642
4643static int spr_wm_latency_open(struct inode *inode, struct file *file)
4644{
4645 struct drm_device *dev = inode->i_private;
4646
Sonika Jindal9ad02572014-07-21 15:23:39 +05304647 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004648 return -ENODEV;
4649
4650 return single_open(file, spr_wm_latency_show, dev);
4651}
4652
4653static int cur_wm_latency_open(struct inode *inode, struct file *file)
4654{
4655 struct drm_device *dev = inode->i_private;
4656
Sonika Jindal9ad02572014-07-21 15:23:39 +05304657 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004658 return -ENODEV;
4659
4660 return single_open(file, cur_wm_latency_show, dev);
4661}
4662
4663static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004664 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004665{
4666 struct seq_file *m = file->private_data;
4667 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004668 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004669 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004670 int level;
4671 int ret;
4672 char tmp[32];
4673
Ville Syrjäläde38b952015-06-24 22:00:09 +03004674 if (IS_CHERRYVIEW(dev))
4675 num_levels = 3;
4676 else if (IS_VALLEYVIEW(dev))
4677 num_levels = 1;
4678 else
4679 num_levels = ilk_wm_max_level(dev) + 1;
4680
Ville Syrjälä369a1342014-01-22 14:36:08 +02004681 if (len >= sizeof(tmp))
4682 return -EINVAL;
4683
4684 if (copy_from_user(tmp, ubuf, len))
4685 return -EFAULT;
4686
4687 tmp[len] = '\0';
4688
Damien Lespiau97e94b22014-11-04 17:06:50 +00004689 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4690 &new[0], &new[1], &new[2], &new[3],
4691 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004692 if (ret != num_levels)
4693 return -EINVAL;
4694
4695 drm_modeset_lock_all(dev);
4696
4697 for (level = 0; level < num_levels; level++)
4698 wm[level] = new[level];
4699
4700 drm_modeset_unlock_all(dev);
4701
4702 return len;
4703}
4704
4705
4706static ssize_t pri_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.pri_latency;
4718
4719 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004720}
4721
4722static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4723 size_t len, loff_t *offp)
4724{
4725 struct seq_file *m = file->private_data;
4726 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004727 struct drm_i915_private *dev_priv = dev->dev_private;
4728 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004729
Damien Lespiau97e94b22014-11-04 17:06:50 +00004730 if (INTEL_INFO(dev)->gen >= 9)
4731 latencies = dev_priv->wm.skl_latency;
4732 else
4733 latencies = to_i915(dev)->wm.spr_latency;
4734
4735 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004736}
4737
4738static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4739 size_t len, loff_t *offp)
4740{
4741 struct seq_file *m = file->private_data;
4742 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004743 struct drm_i915_private *dev_priv = dev->dev_private;
4744 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004745
Damien Lespiau97e94b22014-11-04 17:06:50 +00004746 if (INTEL_INFO(dev)->gen >= 9)
4747 latencies = dev_priv->wm.skl_latency;
4748 else
4749 latencies = to_i915(dev)->wm.cur_latency;
4750
4751 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004752}
4753
4754static const struct file_operations i915_pri_wm_latency_fops = {
4755 .owner = THIS_MODULE,
4756 .open = pri_wm_latency_open,
4757 .read = seq_read,
4758 .llseek = seq_lseek,
4759 .release = single_release,
4760 .write = pri_wm_latency_write
4761};
4762
4763static const struct file_operations i915_spr_wm_latency_fops = {
4764 .owner = THIS_MODULE,
4765 .open = spr_wm_latency_open,
4766 .read = seq_read,
4767 .llseek = seq_lseek,
4768 .release = single_release,
4769 .write = spr_wm_latency_write
4770};
4771
4772static const struct file_operations i915_cur_wm_latency_fops = {
4773 .owner = THIS_MODULE,
4774 .open = cur_wm_latency_open,
4775 .read = seq_read,
4776 .llseek = seq_lseek,
4777 .release = single_release,
4778 .write = cur_wm_latency_write
4779};
4780
Kees Cook647416f2013-03-10 14:10:06 -07004781static int
4782i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004783{
Kees Cook647416f2013-03-10 14:10:06 -07004784 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004785 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004786
Chris Wilsond98c52c2016-04-13 17:35:05 +01004787 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004788
Kees Cook647416f2013-03-10 14:10:06 -07004789 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004790}
4791
Kees Cook647416f2013-03-10 14:10:06 -07004792static int
4793i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004794{
Kees Cook647416f2013-03-10 14:10:06 -07004795 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004796 struct drm_i915_private *dev_priv = dev->dev_private;
4797
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004798 /*
4799 * There is no safeguard against this debugfs entry colliding
4800 * with the hangcheck calling same i915_handle_error() in
4801 * parallel, causing an explosion. For now we assume that the
4802 * test harness is responsible enough not to inject gpu hangs
4803 * while it is writing to 'i915_wedged'
4804 */
4805
Chris Wilsond98c52c2016-04-13 17:35:05 +01004806 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004807 return -EAGAIN;
4808
Imre Deakd46c0512014-04-14 20:24:27 +03004809 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004810
Chris Wilsonc0336662016-05-06 15:40:21 +01004811 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004812 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004813
4814 intel_runtime_pm_put(dev_priv);
4815
Kees Cook647416f2013-03-10 14:10:06 -07004816 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004817}
4818
Kees Cook647416f2013-03-10 14:10:06 -07004819DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4820 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004821 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004822
Kees Cook647416f2013-03-10 14:10:06 -07004823static int
4824i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004825{
Kees Cook647416f2013-03-10 14:10:06 -07004826 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004827 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004828
Kees Cook647416f2013-03-10 14:10:06 -07004829 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004830
Kees Cook647416f2013-03-10 14:10:06 -07004831 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004832}
4833
Kees Cook647416f2013-03-10 14:10:06 -07004834static int
4835i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004836{
Kees Cook647416f2013-03-10 14:10:06 -07004837 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004838 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004839 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004840
Kees Cook647416f2013-03-10 14:10:06 -07004841 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004842
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004843 ret = mutex_lock_interruptible(&dev->struct_mutex);
4844 if (ret)
4845 return ret;
4846
Daniel Vetter99584db2012-11-14 17:14:04 +01004847 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004848 mutex_unlock(&dev->struct_mutex);
4849
Kees Cook647416f2013-03-10 14:10:06 -07004850 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004851}
4852
Kees Cook647416f2013-03-10 14:10:06 -07004853DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4854 i915_ring_stop_get, i915_ring_stop_set,
4855 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004856
Chris Wilson094f9a52013-09-25 17:34:55 +01004857static int
4858i915_ring_missed_irq_get(void *data, u64 *val)
4859{
4860 struct drm_device *dev = data;
4861 struct drm_i915_private *dev_priv = dev->dev_private;
4862
4863 *val = dev_priv->gpu_error.missed_irq_rings;
4864 return 0;
4865}
4866
4867static int
4868i915_ring_missed_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 /* Lock against concurrent debugfs callers */
4875 ret = mutex_lock_interruptible(&dev->struct_mutex);
4876 if (ret)
4877 return ret;
4878 dev_priv->gpu_error.missed_irq_rings = val;
4879 mutex_unlock(&dev->struct_mutex);
4880
4881 return 0;
4882}
4883
4884DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4885 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4886 "0x%08llx\n");
4887
4888static int
4889i915_ring_test_irq_get(void *data, u64 *val)
4890{
4891 struct drm_device *dev = data;
4892 struct drm_i915_private *dev_priv = dev->dev_private;
4893
4894 *val = dev_priv->gpu_error.test_irq_rings;
4895
4896 return 0;
4897}
4898
4899static int
4900i915_ring_test_irq_set(void *data, u64 val)
4901{
4902 struct drm_device *dev = data;
4903 struct drm_i915_private *dev_priv = dev->dev_private;
4904 int ret;
4905
4906 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4907
4908 /* Lock against concurrent debugfs callers */
4909 ret = mutex_lock_interruptible(&dev->struct_mutex);
4910 if (ret)
4911 return ret;
4912
4913 dev_priv->gpu_error.test_irq_rings = val;
4914 mutex_unlock(&dev->struct_mutex);
4915
4916 return 0;
4917}
4918
4919DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4920 i915_ring_test_irq_get, i915_ring_test_irq_set,
4921 "0x%08llx\n");
4922
Chris Wilsondd624af2013-01-15 12:39:35 +00004923#define DROP_UNBOUND 0x1
4924#define DROP_BOUND 0x2
4925#define DROP_RETIRE 0x4
4926#define DROP_ACTIVE 0x8
4927#define DROP_ALL (DROP_UNBOUND | \
4928 DROP_BOUND | \
4929 DROP_RETIRE | \
4930 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004931static int
4932i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004933{
Kees Cook647416f2013-03-10 14:10:06 -07004934 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004935
Kees Cook647416f2013-03-10 14:10:06 -07004936 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004937}
4938
Kees Cook647416f2013-03-10 14:10:06 -07004939static int
4940i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004941{
Kees Cook647416f2013-03-10 14:10:06 -07004942 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004943 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004944 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004945
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004946 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004947
4948 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4949 * on ioctls on -EAGAIN. */
4950 ret = mutex_lock_interruptible(&dev->struct_mutex);
4951 if (ret)
4952 return ret;
4953
4954 if (val & DROP_ACTIVE) {
4955 ret = i915_gpu_idle(dev);
4956 if (ret)
4957 goto unlock;
4958 }
4959
4960 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004961 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004962
Chris Wilson21ab4e72014-09-09 11:16:08 +01004963 if (val & DROP_BOUND)
4964 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004965
Chris Wilson21ab4e72014-09-09 11:16:08 +01004966 if (val & DROP_UNBOUND)
4967 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004968
4969unlock:
4970 mutex_unlock(&dev->struct_mutex);
4971
Kees Cook647416f2013-03-10 14:10:06 -07004972 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004973}
4974
Kees Cook647416f2013-03-10 14:10:06 -07004975DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4976 i915_drop_caches_get, i915_drop_caches_set,
4977 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004978
Kees Cook647416f2013-03-10 14:10:06 -07004979static int
4980i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004981{
Kees Cook647416f2013-03-10 14:10:06 -07004982 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004983 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004984 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004985
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004986 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004987 return -ENODEV;
4988
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004989 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4990
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004991 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004992 if (ret)
4993 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004994
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004995 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004996 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004997
Kees Cook647416f2013-03-10 14:10:06 -07004998 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004999}
5000
Kees Cook647416f2013-03-10 14:10:06 -07005001static int
5002i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07005003{
Kees Cook647416f2013-03-10 14:10:06 -07005004 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07005005 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305006 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005007 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005008
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005009 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005010 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07005011
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005012 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5013
Kees Cook647416f2013-03-10 14:10:06 -07005014 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07005015
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005016 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005017 if (ret)
5018 return ret;
5019
Jesse Barnes358733e2011-07-27 11:53:01 -07005020 /*
5021 * Turbo will still be enabled, but won't go above the set value.
5022 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305023 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005024
Akash Goelbc4d91f2015-02-26 16:09:47 +05305025 hw_max = dev_priv->rps.max_freq;
5026 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07005027
Ben Widawskyb39fb292014-03-19 18:31:11 -07005028 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005029 mutex_unlock(&dev_priv->rps.hw_lock);
5030 return -EINVAL;
5031 }
5032
Ben Widawskyb39fb292014-03-19 18:31:11 -07005033 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005034
Chris Wilsondc979972016-05-10 14:10:04 +01005035 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005036
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005037 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005038
Kees Cook647416f2013-03-10 14:10:06 -07005039 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005040}
5041
Kees Cook647416f2013-03-10 14:10:06 -07005042DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5043 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005044 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005045
Kees Cook647416f2013-03-10 14:10:06 -07005046static int
5047i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005048{
Kees Cook647416f2013-03-10 14:10:06 -07005049 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03005050 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07005051 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005052
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005053 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005054 return -ENODEV;
5055
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005056 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5057
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005058 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005059 if (ret)
5060 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07005061
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005062 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005063 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005064
Kees Cook647416f2013-03-10 14:10:06 -07005065 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005066}
5067
Kees Cook647416f2013-03-10 14:10:06 -07005068static int
5069i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005070{
Kees Cook647416f2013-03-10 14:10:06 -07005071 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07005072 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305073 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005074 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005075
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005076 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005077 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005078
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005079 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5080
Kees Cook647416f2013-03-10 14:10:06 -07005081 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005082
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005083 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005084 if (ret)
5085 return ret;
5086
Jesse Barnes1523c312012-05-25 12:34:54 -07005087 /*
5088 * Turbo will still be enabled, but won't go below the set value.
5089 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305090 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005091
Akash Goelbc4d91f2015-02-26 16:09:47 +05305092 hw_max = dev_priv->rps.max_freq;
5093 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005094
Ben Widawskyb39fb292014-03-19 18:31:11 -07005095 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005096 mutex_unlock(&dev_priv->rps.hw_lock);
5097 return -EINVAL;
5098 }
5099
Ben Widawskyb39fb292014-03-19 18:31:11 -07005100 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005101
Chris Wilsondc979972016-05-10 14:10:04 +01005102 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005103
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005104 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005105
Kees Cook647416f2013-03-10 14:10:06 -07005106 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005107}
5108
Kees Cook647416f2013-03-10 14:10:06 -07005109DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5110 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005111 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005112
Kees Cook647416f2013-03-10 14:10:06 -07005113static int
5114i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005115{
Kees Cook647416f2013-03-10 14:10:06 -07005116 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03005117 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005118 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005119 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005120
Daniel Vetter004777c2012-08-09 15:07:01 +02005121 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5122 return -ENODEV;
5123
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005124 ret = mutex_lock_interruptible(&dev->struct_mutex);
5125 if (ret)
5126 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005127 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005128
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005129 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005130
5131 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005132 mutex_unlock(&dev_priv->dev->struct_mutex);
5133
Kees Cook647416f2013-03-10 14:10:06 -07005134 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005135
Kees Cook647416f2013-03-10 14:10:06 -07005136 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005137}
5138
Kees Cook647416f2013-03-10 14:10:06 -07005139static int
5140i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005141{
Kees Cook647416f2013-03-10 14:10:06 -07005142 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005143 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005144 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005145
Daniel Vetter004777c2012-08-09 15:07:01 +02005146 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5147 return -ENODEV;
5148
Kees Cook647416f2013-03-10 14:10:06 -07005149 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005150 return -EINVAL;
5151
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005152 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005153 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005154
5155 /* Update the cache sharing policy here as well */
5156 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5157 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5158 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5159 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5160
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005161 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005162 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005163}
5164
Kees Cook647416f2013-03-10 14:10:06 -07005165DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5166 i915_cache_sharing_get, i915_cache_sharing_set,
5167 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005168
Jeff McGee5d395252015-04-03 18:13:17 -07005169struct sseu_dev_status {
5170 unsigned int slice_total;
5171 unsigned int subslice_total;
5172 unsigned int subslice_per_slice;
5173 unsigned int eu_total;
5174 unsigned int eu_per_subslice;
5175};
5176
5177static void cherryview_sseu_device_status(struct drm_device *dev,
5178 struct sseu_dev_status *stat)
5179{
5180 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005181 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005182 int ss;
5183 u32 sig1[ss_max], sig2[ss_max];
5184
5185 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5186 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5187 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5188 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5189
5190 for (ss = 0; ss < ss_max; ss++) {
5191 unsigned int eu_cnt;
5192
5193 if (sig1[ss] & CHV_SS_PG_ENABLE)
5194 /* skip disabled subslice */
5195 continue;
5196
5197 stat->slice_total = 1;
5198 stat->subslice_per_slice++;
5199 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5200 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5201 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5202 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
5203 stat->eu_total += eu_cnt;
5204 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
5205 }
5206 stat->subslice_total = stat->subslice_per_slice;
5207}
5208
5209static void gen9_sseu_device_status(struct drm_device *dev,
5210 struct sseu_dev_status *stat)
5211{
5212 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005213 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005214 int s, ss;
5215 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5216
Jeff McGee1c046bc2015-04-03 18:13:18 -07005217 /* BXT has a single slice and at most 3 subslices. */
5218 if (IS_BROXTON(dev)) {
5219 s_max = 1;
5220 ss_max = 3;
5221 }
5222
5223 for (s = 0; s < s_max; s++) {
5224 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5225 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5226 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5227 }
5228
Jeff McGee5d395252015-04-03 18:13:17 -07005229 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5230 GEN9_PGCTL_SSA_EU19_ACK |
5231 GEN9_PGCTL_SSA_EU210_ACK |
5232 GEN9_PGCTL_SSA_EU311_ACK;
5233 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5234 GEN9_PGCTL_SSB_EU19_ACK |
5235 GEN9_PGCTL_SSB_EU210_ACK |
5236 GEN9_PGCTL_SSB_EU311_ACK;
5237
5238 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005239 unsigned int ss_cnt = 0;
5240
Jeff McGee5d395252015-04-03 18:13:17 -07005241 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5242 /* skip disabled slice */
5243 continue;
5244
5245 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005246
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07005247 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Jeff McGee1c046bc2015-04-03 18:13:18 -07005248 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5249
Jeff McGee5d395252015-04-03 18:13:17 -07005250 for (ss = 0; ss < ss_max; ss++) {
5251 unsigned int eu_cnt;
5252
Jeff McGee1c046bc2015-04-03 18:13:18 -07005253 if (IS_BROXTON(dev) &&
5254 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5255 /* skip disabled subslice */
5256 continue;
5257
5258 if (IS_BROXTON(dev))
5259 ss_cnt++;
5260
Jeff McGee5d395252015-04-03 18:13:17 -07005261 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5262 eu_mask[ss%2]);
5263 stat->eu_total += eu_cnt;
5264 stat->eu_per_subslice = max(stat->eu_per_subslice,
5265 eu_cnt);
5266 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005267
5268 stat->subslice_total += ss_cnt;
5269 stat->subslice_per_slice = max(stat->subslice_per_slice,
5270 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005271 }
5272}
5273
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005274static void broadwell_sseu_device_status(struct drm_device *dev,
5275 struct sseu_dev_status *stat)
5276{
5277 struct drm_i915_private *dev_priv = dev->dev_private;
5278 int s;
5279 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
5280
5281 stat->slice_total = hweight32(slice_info & GEN8_LSLICESTAT_MASK);
5282
5283 if (stat->slice_total) {
5284 stat->subslice_per_slice = INTEL_INFO(dev)->subslice_per_slice;
5285 stat->subslice_total = stat->slice_total *
5286 stat->subslice_per_slice;
5287 stat->eu_per_subslice = INTEL_INFO(dev)->eu_per_subslice;
5288 stat->eu_total = stat->eu_per_subslice * stat->subslice_total;
5289
5290 /* subtract fused off EU(s) from enabled slice(s) */
5291 for (s = 0; s < stat->slice_total; s++) {
5292 u8 subslice_7eu = INTEL_INFO(dev)->subslice_7eu[s];
5293
5294 stat->eu_total -= hweight8(subslice_7eu);
5295 }
5296 }
5297}
5298
Jeff McGee38732182015-02-13 10:27:54 -06005299static int i915_sseu_status(struct seq_file *m, void *unused)
5300{
5301 struct drm_info_node *node = (struct drm_info_node *) m->private;
5302 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07005303 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005304
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005305 if (INTEL_INFO(dev)->gen < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005306 return -ENODEV;
5307
5308 seq_puts(m, "SSEU Device Info\n");
5309 seq_printf(m, " Available Slice Total: %u\n",
5310 INTEL_INFO(dev)->slice_total);
5311 seq_printf(m, " Available Subslice Total: %u\n",
5312 INTEL_INFO(dev)->subslice_total);
5313 seq_printf(m, " Available Subslice Per Slice: %u\n",
5314 INTEL_INFO(dev)->subslice_per_slice);
5315 seq_printf(m, " Available EU Total: %u\n",
5316 INTEL_INFO(dev)->eu_total);
5317 seq_printf(m, " Available EU Per Subslice: %u\n",
5318 INTEL_INFO(dev)->eu_per_subslice);
5319 seq_printf(m, " Has Slice Power Gating: %s\n",
5320 yesno(INTEL_INFO(dev)->has_slice_pg));
5321 seq_printf(m, " Has Subslice Power Gating: %s\n",
5322 yesno(INTEL_INFO(dev)->has_subslice_pg));
5323 seq_printf(m, " Has EU Power Gating: %s\n",
5324 yesno(INTEL_INFO(dev)->has_eu_pg));
5325
Jeff McGee7f992ab2015-02-13 10:27:55 -06005326 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005327 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08005328 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005329 cherryview_sseu_device_status(dev, &stat);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005330 } else if (IS_BROADWELL(dev)) {
5331 broadwell_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005332 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005333 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005334 }
Jeff McGee5d395252015-04-03 18:13:17 -07005335 seq_printf(m, " Enabled Slice Total: %u\n",
5336 stat.slice_total);
5337 seq_printf(m, " Enabled Subslice Total: %u\n",
5338 stat.subslice_total);
5339 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5340 stat.subslice_per_slice);
5341 seq_printf(m, " Enabled EU Total: %u\n",
5342 stat.eu_total);
5343 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5344 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005345
Jeff McGee38732182015-02-13 10:27:54 -06005346 return 0;
5347}
5348
Ben Widawsky6d794d42011-04-25 11:25:56 -07005349static int i915_forcewake_open(struct inode *inode, struct file *file)
5350{
5351 struct drm_device *dev = inode->i_private;
5352 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005353
Daniel Vetter075edca2012-01-24 09:44:28 +01005354 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005355 return 0;
5356
Chris Wilson6daccb02015-01-16 11:34:35 +02005357 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005358 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005359
5360 return 0;
5361}
5362
Ben Widawskyc43b5632012-04-16 14:07:40 -07005363static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005364{
5365 struct drm_device *dev = inode->i_private;
5366 struct drm_i915_private *dev_priv = dev->dev_private;
5367
Daniel Vetter075edca2012-01-24 09:44:28 +01005368 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005369 return 0;
5370
Mika Kuoppala59bad942015-01-16 11:34:40 +02005371 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005372 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005373
5374 return 0;
5375}
5376
5377static const struct file_operations i915_forcewake_fops = {
5378 .owner = THIS_MODULE,
5379 .open = i915_forcewake_open,
5380 .release = i915_forcewake_release,
5381};
5382
5383static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5384{
5385 struct drm_device *dev = minor->dev;
5386 struct dentry *ent;
5387
5388 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005389 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005390 root, dev,
5391 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005392 if (!ent)
5393 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005394
Ben Widawsky8eb57292011-05-11 15:10:58 -07005395 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005396}
5397
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005398static int i915_debugfs_create(struct dentry *root,
5399 struct drm_minor *minor,
5400 const char *name,
5401 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005402{
5403 struct drm_device *dev = minor->dev;
5404 struct dentry *ent;
5405
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005406 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005407 S_IRUGO | S_IWUSR,
5408 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005409 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005410 if (!ent)
5411 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005412
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005413 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005414}
5415
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005416static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005417 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005418 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005419 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005420 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005421 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005422 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005423 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005424 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005425 {"i915_gem_request", i915_gem_request_info, 0},
5426 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005427 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005428 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005429 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5430 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5431 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005432 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005433 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005434 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005435 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005436 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305437 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005438 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005439 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005440 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005441 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005442 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005443 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005444 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005445 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005446 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005447 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005448 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005449 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005450 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005451 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005452 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005453 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005454 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005455 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005456 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005457 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005458 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005459 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005460 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005461 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005462 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005463 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005464 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005465 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005466 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005467 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005468 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305469 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005470 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005471};
Ben Gamari27c202a2009-07-01 22:26:52 -04005472#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005473
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005474static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005475 const char *name;
5476 const struct file_operations *fops;
5477} i915_debugfs_files[] = {
5478 {"i915_wedged", &i915_wedged_fops},
5479 {"i915_max_freq", &i915_max_freq_fops},
5480 {"i915_min_freq", &i915_min_freq_fops},
5481 {"i915_cache_sharing", &i915_cache_sharing_fops},
5482 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005483 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5484 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005485 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5486 {"i915_error_state", &i915_error_state_fops},
5487 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005488 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005489 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5490 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5491 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005492 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005493 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5494 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5495 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005496};
5497
Damien Lespiau07144422013-10-15 18:55:40 +01005498void intel_display_crc_init(struct drm_device *dev)
5499{
5500 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005501 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005502
Damien Lespiau055e3932014-08-18 13:49:10 +01005503 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005504 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005505
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005506 pipe_crc->opened = false;
5507 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005508 init_waitqueue_head(&pipe_crc->wq);
5509 }
5510}
5511
Ben Gamari27c202a2009-07-01 22:26:52 -04005512int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005513{
Daniel Vetter34b96742013-07-04 20:49:44 +02005514 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005515
Ben Widawsky6d794d42011-04-25 11:25:56 -07005516 ret = i915_forcewake_create(minor->debugfs_root, minor);
5517 if (ret)
5518 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005519
Damien Lespiau07144422013-10-15 18:55:40 +01005520 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5521 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5522 if (ret)
5523 return ret;
5524 }
5525
Daniel Vetter34b96742013-07-04 20:49:44 +02005526 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5527 ret = i915_debugfs_create(minor->debugfs_root, minor,
5528 i915_debugfs_files[i].name,
5529 i915_debugfs_files[i].fops);
5530 if (ret)
5531 return ret;
5532 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005533
Ben Gamari27c202a2009-07-01 22:26:52 -04005534 return drm_debugfs_create_files(i915_debugfs_list,
5535 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005536 minor->debugfs_root, minor);
5537}
5538
Ben Gamari27c202a2009-07-01 22:26:52 -04005539void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005540{
Daniel Vetter34b96742013-07-04 20:49:44 +02005541 int i;
5542
Ben Gamari27c202a2009-07-01 22:26:52 -04005543 drm_debugfs_remove_files(i915_debugfs_list,
5544 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005545
Ben Widawsky6d794d42011-04-25 11:25:56 -07005546 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5547 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005548
Daniel Vettere309a992013-10-16 22:55:51 +02005549 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005550 struct drm_info_list *info_list =
5551 (struct drm_info_list *)&i915_pipe_crc_data[i];
5552
5553 drm_debugfs_remove_files(info_list, 1, minor);
5554 }
5555
Daniel Vetter34b96742013-07-04 20:49:44 +02005556 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5557 struct drm_info_list *info_list =
5558 (struct drm_info_list *) i915_debugfs_files[i].fops;
5559
5560 drm_debugfs_remove_files(info_list, 1, minor);
5561 }
Ben Gamari20172632009-02-17 20:08:50 -05005562}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005563
5564struct dpcd_block {
5565 /* DPCD dump start address. */
5566 unsigned int offset;
5567 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5568 unsigned int end;
5569 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5570 size_t size;
5571 /* Only valid for eDP. */
5572 bool edp;
5573};
5574
5575static const struct dpcd_block i915_dpcd_debug[] = {
5576 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5577 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5578 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5579 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5580 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5581 { .offset = DP_SET_POWER },
5582 { .offset = DP_EDP_DPCD_REV },
5583 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5584 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5585 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5586};
5587
5588static int i915_dpcd_show(struct seq_file *m, void *data)
5589{
5590 struct drm_connector *connector = m->private;
5591 struct intel_dp *intel_dp =
5592 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5593 uint8_t buf[16];
5594 ssize_t err;
5595 int i;
5596
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005597 if (connector->status != connector_status_connected)
5598 return -ENODEV;
5599
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005600 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5601 const struct dpcd_block *b = &i915_dpcd_debug[i];
5602 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5603
5604 if (b->edp &&
5605 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5606 continue;
5607
5608 /* low tech for now */
5609 if (WARN_ON(size > sizeof(buf)))
5610 continue;
5611
5612 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5613 if (err <= 0) {
5614 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5615 size, b->offset, err);
5616 continue;
5617 }
5618
5619 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005620 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005621
5622 return 0;
5623}
5624
5625static int i915_dpcd_open(struct inode *inode, struct file *file)
5626{
5627 return single_open(file, i915_dpcd_show, inode->i_private);
5628}
5629
5630static const struct file_operations i915_dpcd_fops = {
5631 .owner = THIS_MODULE,
5632 .open = i915_dpcd_open,
5633 .read = seq_read,
5634 .llseek = seq_lseek,
5635 .release = single_release,
5636};
5637
5638/**
5639 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5640 * @connector: pointer to a registered drm_connector
5641 *
5642 * Cleanup will be done by drm_connector_unregister() through a call to
5643 * drm_debugfs_connector_remove().
5644 *
5645 * Returns 0 on success, negative error codes on error.
5646 */
5647int i915_debugfs_connector_add(struct drm_connector *connector)
5648{
5649 struct dentry *root = connector->debugfs_entry;
5650
5651 /* The connector must have been registered beforehands. */
5652 if (!root)
5653 return -ENODEV;
5654
5655 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5656 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5657 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5658 &i915_dpcd_fops);
5659
5660 return 0;
5661}