blob: f5899b631c0ee8fb3f59ccd68d3bd8c9e9dd4a61 [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
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100624static int i915_gem_pageflip_info(struct seq_file *m, void *data)
625{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100626 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100627 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100628 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100629 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200630 int ret;
631
632 ret = mutex_lock_interruptible(&dev->struct_mutex);
633 if (ret)
634 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100635
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100636 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800637 const char pipe = pipe_name(crtc->pipe);
638 const char plane = plane_name(crtc->plane);
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +0200639 struct intel_flip_work *work;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100640
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200641 spin_lock_irq(&dev->event_lock);
Daniel Vetter5a21b662016-05-24 17:13:53 +0200642 work = crtc->flip_work;
643 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800644 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100645 pipe, plane);
646 } else {
Daniel Vetter5a21b662016-05-24 17:13:53 +0200647 u32 pending;
648 u32 addr;
649
650 pending = atomic_read(&work->pending);
651 if (pending) {
652 seq_printf(m, "Flip ioctl preparing on pipe %c (plane %c)\n",
653 pipe, plane);
654 } else {
655 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
656 pipe, plane);
657 }
658 if (work->flip_queued_req) {
659 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
660
661 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
662 engine->name,
663 i915_gem_request_get_seqno(work->flip_queued_req),
664 dev_priv->next_seqno,
Chris Wilson1b7744e2016-07-01 17:23:17 +0100665 intel_engine_get_seqno(engine),
Chris Wilsonf69a02c2016-07-01 17:23:16 +0100666 i915_gem_request_completed(work->flip_queued_req));
Daniel Vetter5a21b662016-05-24 17:13:53 +0200667 } else
668 seq_printf(m, "Flip not associated with any ring\n");
669 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
670 work->flip_queued_vblank,
671 work->flip_ready_vblank,
672 intel_crtc_get_vblank_counter(crtc));
673 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
674
675 if (INTEL_INFO(dev)->gen >= 4)
676 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
677 else
678 addr = I915_READ(DSPADDR(crtc->plane));
679 seq_printf(m, "Current scanout address 0x%08x\n", addr);
680
681 if (work->pending_flip_obj) {
682 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
683 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100684 }
685 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200686 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100687 }
688
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200689 mutex_unlock(&dev->struct_mutex);
690
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100691 return 0;
692}
693
Brad Volkin493018d2014-12-11 12:13:08 -0800694static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
695{
696 struct drm_info_node *node = m->private;
697 struct drm_device *dev = node->minor->dev;
698 struct drm_i915_private *dev_priv = dev->dev_private;
699 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000700 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100701 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000702 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800703
704 ret = mutex_lock_interruptible(&dev->struct_mutex);
705 if (ret)
706 return ret;
707
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000708 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000709 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100710 int count;
711
712 count = 0;
713 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000714 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100715 batch_pool_link)
716 count++;
717 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000718 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100719
720 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000721 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100722 batch_pool_link) {
723 seq_puts(m, " ");
724 describe_obj(m, obj);
725 seq_putc(m, '\n');
726 }
727
728 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100729 }
Brad Volkin493018d2014-12-11 12:13:08 -0800730 }
731
Chris Wilson8d9d5742015-04-07 16:20:38 +0100732 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800733
734 mutex_unlock(&dev->struct_mutex);
735
736 return 0;
737}
738
Ben Gamari20172632009-02-17 20:08:50 -0500739static int i915_gem_request_info(struct seq_file *m, void *data)
740{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100741 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500742 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300743 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000744 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200745 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000746 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100747
748 ret = mutex_lock_interruptible(&dev->struct_mutex);
749 if (ret)
750 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500751
Chris Wilson2d1070b2015-04-01 10:36:56 +0100752 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000753 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100754 int count;
755
756 count = 0;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000757 list_for_each_entry(req, &engine->request_list, list)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100758 count++;
759 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100760 continue;
761
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000762 seq_printf(m, "%s requests: %d\n", engine->name, count);
763 list_for_each_entry(req, &engine->request_list, list) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100764 struct task_struct *task;
765
766 rcu_read_lock();
767 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200768 if (req->pid)
769 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100770 seq_printf(m, " %x @ %d: %s [%d]\n",
Daniel Vettereed29a52015-05-21 14:21:25 +0200771 req->seqno,
772 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100773 task ? task->comm : "<unknown>",
774 task ? task->pid : -1);
775 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100776 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100777
778 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500779 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100780 mutex_unlock(&dev->struct_mutex);
781
Chris Wilson2d1070b2015-04-01 10:36:56 +0100782 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100783 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100784
Ben Gamari20172632009-02-17 20:08:50 -0500785 return 0;
786}
787
Chris Wilsonb2223492010-10-27 15:27:33 +0100788static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000789 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100790{
Chris Wilson688e6c72016-07-01 17:23:15 +0100791 struct intel_breadcrumbs *b = &engine->breadcrumbs;
792 struct rb_node *rb;
793
Chris Wilson12471ba2016-04-09 10:57:55 +0100794 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilson1b7744e2016-07-01 17:23:17 +0100795 engine->name, intel_engine_get_seqno(engine));
Chris Wilson12471ba2016-04-09 10:57:55 +0100796 seq_printf(m, "Current user interrupts (%s): %x\n",
797 engine->name, READ_ONCE(engine->user_interrupts));
Chris Wilson688e6c72016-07-01 17:23:15 +0100798
799 spin_lock(&b->lock);
800 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
801 struct intel_wait *w = container_of(rb, typeof(*w), node);
802
803 seq_printf(m, "Waiting (%s): %s [%d] on %x\n",
804 engine->name, w->tsk->comm, w->tsk->pid, w->seqno);
805 }
806 spin_unlock(&b->lock);
Chris Wilsonb2223492010-10-27 15:27:33 +0100807}
808
Ben Gamari20172632009-02-17 20:08:50 -0500809static int i915_gem_seqno_info(struct seq_file *m, void *data)
810{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100811 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500812 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300813 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000814 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000815 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100816
817 ret = mutex_lock_interruptible(&dev->struct_mutex);
818 if (ret)
819 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200820 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500821
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000822 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000823 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100824
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200825 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100826 mutex_unlock(&dev->struct_mutex);
827
Ben Gamari20172632009-02-17 20:08:50 -0500828 return 0;
829}
830
831
832static int i915_interrupt_info(struct seq_file *m, void *data)
833{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100834 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500835 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300836 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000837 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800838 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100839
840 ret = mutex_lock_interruptible(&dev->struct_mutex);
841 if (ret)
842 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200843 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500844
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300845 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300846 seq_printf(m, "Master Interrupt Control:\t%08x\n",
847 I915_READ(GEN8_MASTER_IRQ));
848
849 seq_printf(m, "Display IER:\t%08x\n",
850 I915_READ(VLV_IER));
851 seq_printf(m, "Display IIR:\t%08x\n",
852 I915_READ(VLV_IIR));
853 seq_printf(m, "Display IIR_RW:\t%08x\n",
854 I915_READ(VLV_IIR_RW));
855 seq_printf(m, "Display IMR:\t%08x\n",
856 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100857 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300858 seq_printf(m, "Pipe %c stat:\t%08x\n",
859 pipe_name(pipe),
860 I915_READ(PIPESTAT(pipe)));
861
862 seq_printf(m, "Port hotplug:\t%08x\n",
863 I915_READ(PORT_HOTPLUG_EN));
864 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
865 I915_READ(VLV_DPFLIPSTAT));
866 seq_printf(m, "DPINVGTT:\t%08x\n",
867 I915_READ(DPINVGTT));
868
869 for (i = 0; i < 4; i++) {
870 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
871 i, I915_READ(GEN8_GT_IMR(i)));
872 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
873 i, I915_READ(GEN8_GT_IIR(i)));
874 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
875 i, I915_READ(GEN8_GT_IER(i)));
876 }
877
878 seq_printf(m, "PCU interrupt mask:\t%08x\n",
879 I915_READ(GEN8_PCU_IMR));
880 seq_printf(m, "PCU interrupt identity:\t%08x\n",
881 I915_READ(GEN8_PCU_IIR));
882 seq_printf(m, "PCU interrupt enable:\t%08x\n",
883 I915_READ(GEN8_PCU_IER));
884 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700885 seq_printf(m, "Master Interrupt Control:\t%08x\n",
886 I915_READ(GEN8_MASTER_IRQ));
887
888 for (i = 0; i < 4; i++) {
889 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
890 i, I915_READ(GEN8_GT_IMR(i)));
891 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
892 i, I915_READ(GEN8_GT_IIR(i)));
893 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
894 i, I915_READ(GEN8_GT_IER(i)));
895 }
896
Damien Lespiau055e3932014-08-18 13:49:10 +0100897 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200898 enum intel_display_power_domain power_domain;
899
900 power_domain = POWER_DOMAIN_PIPE(pipe);
901 if (!intel_display_power_get_if_enabled(dev_priv,
902 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300903 seq_printf(m, "Pipe %c power disabled\n",
904 pipe_name(pipe));
905 continue;
906 }
Ben Widawskya123f152013-11-02 21:07:10 -0700907 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000908 pipe_name(pipe),
909 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700910 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000911 pipe_name(pipe),
912 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700913 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000914 pipe_name(pipe),
915 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200916
917 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700918 }
919
920 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
921 I915_READ(GEN8_DE_PORT_IMR));
922 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
923 I915_READ(GEN8_DE_PORT_IIR));
924 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
925 I915_READ(GEN8_DE_PORT_IER));
926
927 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
928 I915_READ(GEN8_DE_MISC_IMR));
929 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
930 I915_READ(GEN8_DE_MISC_IIR));
931 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
932 I915_READ(GEN8_DE_MISC_IER));
933
934 seq_printf(m, "PCU interrupt mask:\t%08x\n",
935 I915_READ(GEN8_PCU_IMR));
936 seq_printf(m, "PCU interrupt identity:\t%08x\n",
937 I915_READ(GEN8_PCU_IIR));
938 seq_printf(m, "PCU interrupt enable:\t%08x\n",
939 I915_READ(GEN8_PCU_IER));
940 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700941 seq_printf(m, "Display IER:\t%08x\n",
942 I915_READ(VLV_IER));
943 seq_printf(m, "Display IIR:\t%08x\n",
944 I915_READ(VLV_IIR));
945 seq_printf(m, "Display IIR_RW:\t%08x\n",
946 I915_READ(VLV_IIR_RW));
947 seq_printf(m, "Display IMR:\t%08x\n",
948 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100949 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700950 seq_printf(m, "Pipe %c stat:\t%08x\n",
951 pipe_name(pipe),
952 I915_READ(PIPESTAT(pipe)));
953
954 seq_printf(m, "Master IER:\t%08x\n",
955 I915_READ(VLV_MASTER_IER));
956
957 seq_printf(m, "Render IER:\t%08x\n",
958 I915_READ(GTIER));
959 seq_printf(m, "Render IIR:\t%08x\n",
960 I915_READ(GTIIR));
961 seq_printf(m, "Render IMR:\t%08x\n",
962 I915_READ(GTIMR));
963
964 seq_printf(m, "PM IER:\t\t%08x\n",
965 I915_READ(GEN6_PMIER));
966 seq_printf(m, "PM IIR:\t\t%08x\n",
967 I915_READ(GEN6_PMIIR));
968 seq_printf(m, "PM IMR:\t\t%08x\n",
969 I915_READ(GEN6_PMIMR));
970
971 seq_printf(m, "Port hotplug:\t%08x\n",
972 I915_READ(PORT_HOTPLUG_EN));
973 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
974 I915_READ(VLV_DPFLIPSTAT));
975 seq_printf(m, "DPINVGTT:\t%08x\n",
976 I915_READ(DPINVGTT));
977
978 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800979 seq_printf(m, "Interrupt enable: %08x\n",
980 I915_READ(IER));
981 seq_printf(m, "Interrupt identity: %08x\n",
982 I915_READ(IIR));
983 seq_printf(m, "Interrupt mask: %08x\n",
984 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100985 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800986 seq_printf(m, "Pipe %c stat: %08x\n",
987 pipe_name(pipe),
988 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800989 } else {
990 seq_printf(m, "North Display Interrupt enable: %08x\n",
991 I915_READ(DEIER));
992 seq_printf(m, "North Display Interrupt identity: %08x\n",
993 I915_READ(DEIIR));
994 seq_printf(m, "North Display Interrupt mask: %08x\n",
995 I915_READ(DEIMR));
996 seq_printf(m, "South Display Interrupt enable: %08x\n",
997 I915_READ(SDEIER));
998 seq_printf(m, "South Display Interrupt identity: %08x\n",
999 I915_READ(SDEIIR));
1000 seq_printf(m, "South Display Interrupt mask: %08x\n",
1001 I915_READ(SDEIMR));
1002 seq_printf(m, "Graphics Interrupt enable: %08x\n",
1003 I915_READ(GTIER));
1004 seq_printf(m, "Graphics Interrupt identity: %08x\n",
1005 I915_READ(GTIIR));
1006 seq_printf(m, "Graphics Interrupt mask: %08x\n",
1007 I915_READ(GTIMR));
1008 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001009 for_each_engine(engine, dev_priv) {
Ben Widawskya123f152013-11-02 21:07:10 -07001010 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001011 seq_printf(m,
1012 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001013 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +00001014 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001015 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +00001016 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001017 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001018 mutex_unlock(&dev->struct_mutex);
1019
Ben Gamari20172632009-02-17 20:08:50 -05001020 return 0;
1021}
1022
Chris Wilsona6172a82009-02-11 14:26:38 +00001023static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
1024{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001025 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +00001026 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001027 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001028 int i, ret;
1029
1030 ret = mutex_lock_interruptible(&dev->struct_mutex);
1031 if (ret)
1032 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +00001033
Chris Wilsona6172a82009-02-11 14:26:38 +00001034 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
1035 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +00001036 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +00001037
Chris Wilson6c085a72012-08-20 11:40:46 +02001038 seq_printf(m, "Fence %d, pin count = %d, object = ",
1039 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001040 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001041 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001042 else
Chris Wilson05394f32010-11-08 19:18:58 +00001043 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001044 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +00001045 }
1046
Chris Wilson05394f32010-11-08 19:18:58 +00001047 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +00001048 return 0;
1049}
1050
Ben Gamari20172632009-02-17 20:08:50 -05001051static int i915_hws_info(struct seq_file *m, void *data)
1052{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001053 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -05001054 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001055 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001056 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +01001057 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +01001058 int i;
Ben Gamari20172632009-02-17 20:08:50 -05001059
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001060 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001061 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -05001062 if (hws == NULL)
1063 return 0;
1064
1065 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
1066 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
1067 i * 4,
1068 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
1069 }
1070 return 0;
1071}
1072
Daniel Vetterd5442302012-04-27 15:17:40 +02001073static ssize_t
1074i915_error_state_write(struct file *filp,
1075 const char __user *ubuf,
1076 size_t cnt,
1077 loff_t *ppos)
1078{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001079 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001080 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001081 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001082
1083 DRM_DEBUG_DRIVER("Resetting error state\n");
1084
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001085 ret = mutex_lock_interruptible(&dev->struct_mutex);
1086 if (ret)
1087 return ret;
1088
Daniel Vetterd5442302012-04-27 15:17:40 +02001089 i915_destroy_error_state(dev);
1090 mutex_unlock(&dev->struct_mutex);
1091
1092 return cnt;
1093}
1094
1095static int i915_error_state_open(struct inode *inode, struct file *file)
1096{
1097 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001098 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001099
1100 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1101 if (!error_priv)
1102 return -ENOMEM;
1103
1104 error_priv->dev = dev;
1105
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001106 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001107
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001108 file->private_data = error_priv;
1109
1110 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001111}
1112
1113static int i915_error_state_release(struct inode *inode, struct file *file)
1114{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001115 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001116
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001117 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001118 kfree(error_priv);
1119
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001120 return 0;
1121}
1122
1123static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1124 size_t count, loff_t *pos)
1125{
1126 struct i915_error_state_file_priv *error_priv = file->private_data;
1127 struct drm_i915_error_state_buf error_str;
1128 loff_t tmp_pos = 0;
1129 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001130 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001131
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001132 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001133 if (ret)
1134 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001135
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001136 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001137 if (ret)
1138 goto out;
1139
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001140 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1141 error_str.buf,
1142 error_str.bytes);
1143
1144 if (ret_count < 0)
1145 ret = ret_count;
1146 else
1147 *pos = error_str.start + ret_count;
1148out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001149 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001150 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001151}
1152
1153static const struct file_operations i915_error_state_fops = {
1154 .owner = THIS_MODULE,
1155 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001156 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001157 .write = i915_error_state_write,
1158 .llseek = default_llseek,
1159 .release = i915_error_state_release,
1160};
1161
Kees Cook647416f2013-03-10 14:10:06 -07001162static int
1163i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001164{
Kees Cook647416f2013-03-10 14:10:06 -07001165 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001166 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001167 int ret;
1168
1169 ret = mutex_lock_interruptible(&dev->struct_mutex);
1170 if (ret)
1171 return ret;
1172
Kees Cook647416f2013-03-10 14:10:06 -07001173 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001174 mutex_unlock(&dev->struct_mutex);
1175
Kees Cook647416f2013-03-10 14:10:06 -07001176 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001177}
1178
Kees Cook647416f2013-03-10 14:10:06 -07001179static int
1180i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001181{
Kees Cook647416f2013-03-10 14:10:06 -07001182 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001183 int ret;
1184
Mika Kuoppala40633212012-12-04 15:12:00 +02001185 ret = mutex_lock_interruptible(&dev->struct_mutex);
1186 if (ret)
1187 return ret;
1188
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001189 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001190 mutex_unlock(&dev->struct_mutex);
1191
Kees Cook647416f2013-03-10 14:10:06 -07001192 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001193}
1194
Kees Cook647416f2013-03-10 14:10:06 -07001195DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1196 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001197 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001198
Deepak Sadb4bd12014-03-31 11:30:02 +05301199static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001200{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001201 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001202 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001203 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001204 int ret = 0;
1205
1206 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001207
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001208 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1209
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001210 if (IS_GEN5(dev)) {
1211 u16 rgvswctl = I915_READ16(MEMSWCTL);
1212 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1213
1214 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1215 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1216 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1217 MEMSTAT_VID_SHIFT);
1218 seq_printf(m, "Current P-state: %d\n",
1219 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Wayne Boyer666a4532015-12-09 12:29:35 -08001220 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
1221 u32 freq_sts;
1222
1223 mutex_lock(&dev_priv->rps.hw_lock);
1224 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1225 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1226 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1227
1228 seq_printf(m, "actual GPU freq: %d MHz\n",
1229 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1230
1231 seq_printf(m, "current GPU freq: %d MHz\n",
1232 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1233
1234 seq_printf(m, "max GPU freq: %d MHz\n",
1235 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1236
1237 seq_printf(m, "min GPU freq: %d MHz\n",
1238 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1239
1240 seq_printf(m, "idle GPU freq: %d MHz\n",
1241 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1242
1243 seq_printf(m,
1244 "efficient (RPe) frequency: %d MHz\n",
1245 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1246 mutex_unlock(&dev_priv->rps.hw_lock);
1247 } else if (INTEL_INFO(dev)->gen >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001248 u32 rp_state_limits;
1249 u32 gt_perf_status;
1250 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001251 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001252 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001253 u32 rpupei, rpcurup, rpprevup;
1254 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001255 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001256 int max_freq;
1257
Bob Paauwe35040562015-06-25 14:54:07 -07001258 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1259 if (IS_BROXTON(dev)) {
1260 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1261 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1262 } else {
1263 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1264 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1265 }
1266
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001267 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001268 ret = mutex_lock_interruptible(&dev->struct_mutex);
1269 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001270 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001271
Mika Kuoppala59bad942015-01-16 11:34:40 +02001272 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001273
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001274 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301275 if (IS_GEN9(dev))
1276 reqf >>= 23;
1277 else {
1278 reqf &= ~GEN6_TURBO_DISABLE;
1279 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1280 reqf >>= 24;
1281 else
1282 reqf >>= 25;
1283 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001284 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001285
Chris Wilson0d8f9492014-03-27 09:06:14 +00001286 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1287 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1288 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1289
Jesse Barnesccab5c82011-01-18 15:49:25 -08001290 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301291 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1292 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1293 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1294 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1295 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1296 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Akash Goel60260a52015-03-06 11:07:21 +05301297 if (IS_GEN9(dev))
1298 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1299 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001300 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1301 else
1302 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001303 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001304
Mika Kuoppala59bad942015-01-16 11:34:40 +02001305 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001306 mutex_unlock(&dev->struct_mutex);
1307
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001308 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1309 pm_ier = I915_READ(GEN6_PMIER);
1310 pm_imr = I915_READ(GEN6_PMIMR);
1311 pm_isr = I915_READ(GEN6_PMISR);
1312 pm_iir = I915_READ(GEN6_PMIIR);
1313 pm_mask = I915_READ(GEN6_PMINTRMSK);
1314 } else {
1315 pm_ier = I915_READ(GEN8_GT_IER(2));
1316 pm_imr = I915_READ(GEN8_GT_IMR(2));
1317 pm_isr = I915_READ(GEN8_GT_ISR(2));
1318 pm_iir = I915_READ(GEN8_GT_IIR(2));
1319 pm_mask = I915_READ(GEN6_PMINTRMSK);
1320 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001321 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 -03001322 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301323 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001324 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001325 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301326 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001327 seq_printf(m, "Render p-state VID: %d\n",
1328 gt_perf_status & 0xff);
1329 seq_printf(m, "Render p-state limit: %d\n",
1330 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001331 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1332 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1333 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1334 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001335 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001336 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301337 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1338 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1339 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1340 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1341 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1342 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001343 seq_printf(m, "Up threshold: %d%%\n",
1344 dev_priv->rps.up_threshold);
1345
Akash Goeld6cda9c2016-04-23 00:05:46 +05301346 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1347 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1348 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1349 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1350 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1351 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001352 seq_printf(m, "Down threshold: %d%%\n",
1353 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001354
Bob Paauwe35040562015-06-25 14:54:07 -07001355 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1356 rp_state_cap >> 16) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001357 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1358 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001359 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001360 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001361
1362 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001363 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1364 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001365 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001366 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001367
Bob Paauwe35040562015-06-25 14:54:07 -07001368 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1369 rp_state_cap >> 0) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001370 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1371 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001372 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001373 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001374 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001375 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001376
Chris Wilsond86ed342015-04-27 13:41:19 +01001377 seq_printf(m, "Current freq: %d MHz\n",
1378 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1379 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001380 seq_printf(m, "Idle freq: %d MHz\n",
1381 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001382 seq_printf(m, "Min freq: %d MHz\n",
1383 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1384 seq_printf(m, "Max freq: %d MHz\n",
1385 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1386 seq_printf(m,
1387 "efficient (RPe) frequency: %d MHz\n",
1388 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001389 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001390 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001391 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001392
Mika Kahola1170f282015-09-25 14:00:32 +03001393 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1394 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1395 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1396
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001397out:
1398 intel_runtime_pm_put(dev_priv);
1399 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001400}
1401
Chris Wilsonf6544492015-01-26 18:03:04 +02001402static int i915_hangcheck_info(struct seq_file *m, void *unused)
1403{
1404 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001405 struct drm_device *dev = node->minor->dev;
1406 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001407 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001408 u64 acthd[I915_NUM_ENGINES];
1409 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001410 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001411 enum intel_engine_id id;
1412 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001413
1414 if (!i915.enable_hangcheck) {
1415 seq_printf(m, "Hangcheck disabled\n");
1416 return 0;
1417 }
1418
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001419 intel_runtime_pm_get(dev_priv);
1420
Dave Gordonc3232b12016-03-23 18:19:53 +00001421 for_each_engine_id(engine, dev_priv, id) {
Dave Gordonc3232b12016-03-23 18:19:53 +00001422 acthd[id] = intel_ring_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01001423 seqno[id] = intel_engine_get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001424 }
1425
Chris Wilsonc0336662016-05-06 15:40:21 +01001426 i915_get_extra_instdone(dev_priv, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001427
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001428 intel_runtime_pm_put(dev_priv);
1429
Chris Wilsonf6544492015-01-26 18:03:04 +02001430 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1431 seq_printf(m, "Hangcheck active, fires in %dms\n",
1432 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1433 jiffies));
1434 } else
1435 seq_printf(m, "Hangcheck inactive\n");
1436
Dave Gordonc3232b12016-03-23 18:19:53 +00001437 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001438 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001439 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1440 engine->hangcheck.seqno,
1441 seqno[id],
1442 engine->last_submitted_seqno);
Chris Wilson688e6c72016-07-01 17:23:15 +01001443 seq_printf(m, "\twaiters? %d\n",
1444 intel_engine_has_waiter(engine));
Chris Wilson12471ba2016-04-09 10:57:55 +01001445 seq_printf(m, "\tuser interrupts = %x [current %x]\n",
1446 engine->hangcheck.user_interrupts,
1447 READ_ONCE(engine->user_interrupts));
Chris Wilsonf6544492015-01-26 18:03:04 +02001448 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001449 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001450 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001451 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1452 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001453
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001454 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001455 seq_puts(m, "\tinstdone read =");
1456
1457 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1458 seq_printf(m, " 0x%08x", instdone[j]);
1459
1460 seq_puts(m, "\n\tinstdone accu =");
1461
1462 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1463 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001464 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001465
1466 seq_puts(m, "\n");
1467 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001468 }
1469
1470 return 0;
1471}
1472
Ben Widawsky4d855292011-12-12 19:34:16 -08001473static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001474{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001475 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001476 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001477 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001478 u32 rgvmodectl, rstdbyctl;
1479 u16 crstandvid;
1480 int ret;
1481
1482 ret = mutex_lock_interruptible(&dev->struct_mutex);
1483 if (ret)
1484 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001485 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001486
1487 rgvmodectl = I915_READ(MEMMODECTL);
1488 rstdbyctl = I915_READ(RSTDBYCTL);
1489 crstandvid = I915_READ16(CRSTANDVID);
1490
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001491 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001492 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001493
Jani Nikula742f4912015-09-03 11:16:09 +03001494 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001495 seq_printf(m, "Boost freq: %d\n",
1496 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1497 MEMMODE_BOOST_FREQ_SHIFT);
1498 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001499 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001500 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001501 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001502 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001503 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001504 seq_printf(m, "Starting frequency: P%d\n",
1505 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001506 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001507 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001508 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1509 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1510 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1511 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001512 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001513 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001514 switch (rstdbyctl & RSX_STATUS_MASK) {
1515 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001516 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001517 break;
1518 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001519 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001520 break;
1521 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001522 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001523 break;
1524 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001525 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001526 break;
1527 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001528 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001529 break;
1530 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001531 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001532 break;
1533 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001534 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001535 break;
1536 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001537
1538 return 0;
1539}
1540
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001541static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001542{
1543 struct drm_info_node *node = m->private;
1544 struct drm_device *dev = node->minor->dev;
1545 struct drm_i915_private *dev_priv = dev->dev_private;
1546 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001547
1548 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001549 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001550 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001551 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001552 fw_domain->wake_count);
1553 }
1554 spin_unlock_irq(&dev_priv->uncore.lock);
1555
1556 return 0;
1557}
1558
Deepak S669ab5a2014-01-10 15:18:26 +05301559static int vlv_drpc_info(struct seq_file *m)
1560{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001561 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301562 struct drm_device *dev = node->minor->dev;
1563 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001564 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301565
Imre Deakd46c0512014-04-14 20:24:27 +03001566 intel_runtime_pm_get(dev_priv);
1567
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001568 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301569 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1570 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1571
Imre Deakd46c0512014-04-14 20:24:27 +03001572 intel_runtime_pm_put(dev_priv);
1573
Deepak S669ab5a2014-01-10 15:18:26 +05301574 seq_printf(m, "Video Turbo Mode: %s\n",
1575 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1576 seq_printf(m, "Turbo enabled: %s\n",
1577 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1578 seq_printf(m, "HW control enabled: %s\n",
1579 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1580 seq_printf(m, "SW control enabled: %s\n",
1581 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1582 GEN6_RP_MEDIA_SW_MODE));
1583 seq_printf(m, "RC6 Enabled: %s\n",
1584 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1585 GEN6_RC_CTL_EI_MODE(1))));
1586 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001587 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301588 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001589 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301590
Imre Deak9cc19be2014-04-14 20:24:24 +03001591 seq_printf(m, "Render RC6 residency since boot: %u\n",
1592 I915_READ(VLV_GT_RENDER_RC6));
1593 seq_printf(m, "Media RC6 residency since boot: %u\n",
1594 I915_READ(VLV_GT_MEDIA_RC6));
1595
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001596 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301597}
1598
Ben Widawsky4d855292011-12-12 19:34:16 -08001599static int gen6_drpc_info(struct seq_file *m)
1600{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001601 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001602 struct drm_device *dev = node->minor->dev;
1603 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001604 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001605 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001606 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001607
1608 ret = mutex_lock_interruptible(&dev->struct_mutex);
1609 if (ret)
1610 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001611 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001612
Chris Wilson907b28c2013-07-19 20:36:52 +01001613 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001614 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001615 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001616
1617 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001618 seq_puts(m, "RC information inaccurate because somebody "
1619 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001620 } else {
1621 /* NB: we cannot use forcewake, else we read the wrong values */
1622 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1623 udelay(10);
1624 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1625 }
1626
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001627 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001628 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001629
1630 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1631 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1632 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001633 mutex_lock(&dev_priv->rps.hw_lock);
1634 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1635 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001636
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001637 intel_runtime_pm_put(dev_priv);
1638
Ben Widawsky4d855292011-12-12 19:34:16 -08001639 seq_printf(m, "Video Turbo Mode: %s\n",
1640 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1641 seq_printf(m, "HW control enabled: %s\n",
1642 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1643 seq_printf(m, "SW control enabled: %s\n",
1644 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1645 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001646 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001647 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1648 seq_printf(m, "RC6 Enabled: %s\n",
1649 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1650 seq_printf(m, "Deep RC6 Enabled: %s\n",
1651 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1652 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1653 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001654 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001655 switch (gt_core_status & GEN6_RCn_MASK) {
1656 case GEN6_RC0:
1657 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001658 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001659 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001660 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001661 break;
1662 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001663 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001664 break;
1665 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001666 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001667 break;
1668 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001669 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001670 break;
1671 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001672 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001673 break;
1674 }
1675
1676 seq_printf(m, "Core Power Down: %s\n",
1677 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001678
1679 /* Not exactly sure what this is */
1680 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1681 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1682 seq_printf(m, "RC6 residency since boot: %u\n",
1683 I915_READ(GEN6_GT_GFX_RC6));
1684 seq_printf(m, "RC6+ residency since boot: %u\n",
1685 I915_READ(GEN6_GT_GFX_RC6p));
1686 seq_printf(m, "RC6++ residency since boot: %u\n",
1687 I915_READ(GEN6_GT_GFX_RC6pp));
1688
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001689 seq_printf(m, "RC6 voltage: %dmV\n",
1690 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1691 seq_printf(m, "RC6+ voltage: %dmV\n",
1692 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1693 seq_printf(m, "RC6++ voltage: %dmV\n",
1694 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001695 return 0;
1696}
1697
1698static int i915_drpc_info(struct seq_file *m, void *unused)
1699{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001700 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001701 struct drm_device *dev = node->minor->dev;
1702
Wayne Boyer666a4532015-12-09 12:29:35 -08001703 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Deepak S669ab5a2014-01-10 15:18:26 +05301704 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001705 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001706 return gen6_drpc_info(m);
1707 else
1708 return ironlake_drpc_info(m);
1709}
1710
Daniel Vetter9a851782015-06-18 10:30:22 +02001711static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1712{
1713 struct drm_info_node *node = m->private;
1714 struct drm_device *dev = node->minor->dev;
1715 struct drm_i915_private *dev_priv = dev->dev_private;
1716
1717 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1718 dev_priv->fb_tracking.busy_bits);
1719
1720 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1721 dev_priv->fb_tracking.flip_bits);
1722
1723 return 0;
1724}
1725
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001726static int i915_fbc_status(struct seq_file *m, void *unused)
1727{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001728 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001729 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001730 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001731
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001732 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001733 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001734 return 0;
1735 }
1736
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001737 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001738 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001739
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001740 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001741 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001742 else
1743 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001744 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001745
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001746 if (INTEL_INFO(dev_priv)->gen >= 7)
1747 seq_printf(m, "Compressing: %s\n",
1748 yesno(I915_READ(FBC_STATUS2) &
1749 FBC_COMPRESSION_MASK));
1750
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001751 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001752 intel_runtime_pm_put(dev_priv);
1753
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001754 return 0;
1755}
1756
Rodrigo Vivida46f932014-08-01 02:04:45 -07001757static int i915_fbc_fc_get(void *data, u64 *val)
1758{
1759 struct drm_device *dev = data;
1760 struct drm_i915_private *dev_priv = dev->dev_private;
1761
1762 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1763 return -ENODEV;
1764
Rodrigo Vivida46f932014-08-01 02:04:45 -07001765 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001766
1767 return 0;
1768}
1769
1770static int i915_fbc_fc_set(void *data, u64 val)
1771{
1772 struct drm_device *dev = data;
1773 struct drm_i915_private *dev_priv = dev->dev_private;
1774 u32 reg;
1775
1776 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1777 return -ENODEV;
1778
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001779 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001780
1781 reg = I915_READ(ILK_DPFC_CONTROL);
1782 dev_priv->fbc.false_color = val;
1783
1784 I915_WRITE(ILK_DPFC_CONTROL, val ?
1785 (reg | FBC_CTL_FALSE_COLOR) :
1786 (reg & ~FBC_CTL_FALSE_COLOR));
1787
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001788 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001789 return 0;
1790}
1791
1792DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1793 i915_fbc_fc_get, i915_fbc_fc_set,
1794 "%llu\n");
1795
Paulo Zanoni92d44622013-05-31 16:33:24 -03001796static int i915_ips_status(struct seq_file *m, void *unused)
1797{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001798 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001799 struct drm_device *dev = node->minor->dev;
1800 struct drm_i915_private *dev_priv = dev->dev_private;
1801
Damien Lespiauf5adf942013-06-24 18:29:34 +01001802 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001803 seq_puts(m, "not supported\n");
1804 return 0;
1805 }
1806
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001807 intel_runtime_pm_get(dev_priv);
1808
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001809 seq_printf(m, "Enabled by kernel parameter: %s\n",
1810 yesno(i915.enable_ips));
1811
1812 if (INTEL_INFO(dev)->gen >= 8) {
1813 seq_puts(m, "Currently: unknown\n");
1814 } else {
1815 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1816 seq_puts(m, "Currently: enabled\n");
1817 else
1818 seq_puts(m, "Currently: disabled\n");
1819 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001820
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001821 intel_runtime_pm_put(dev_priv);
1822
Paulo Zanoni92d44622013-05-31 16:33:24 -03001823 return 0;
1824}
1825
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001826static int i915_sr_status(struct seq_file *m, void *unused)
1827{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001828 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001829 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001830 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001831 bool sr_enabled = false;
1832
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001833 intel_runtime_pm_get(dev_priv);
1834
Yuanhan Liu13982612010-12-15 15:42:31 +08001835 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001836 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001837 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1838 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001839 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1840 else if (IS_I915GM(dev))
1841 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1842 else if (IS_PINEVIEW(dev))
1843 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Wayne Boyer666a4532015-12-09 12:29:35 -08001844 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001845 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001846
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001847 intel_runtime_pm_put(dev_priv);
1848
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001849 seq_printf(m, "self-refresh: %s\n",
1850 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001851
1852 return 0;
1853}
1854
Jesse Barnes7648fa92010-05-20 14:28:11 -07001855static int i915_emon_status(struct seq_file *m, void *unused)
1856{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001857 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001858 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001859 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001860 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001861 int ret;
1862
Chris Wilson582be6b2012-04-30 19:35:02 +01001863 if (!IS_GEN5(dev))
1864 return -ENODEV;
1865
Chris Wilsonde227ef2010-07-03 07:58:38 +01001866 ret = mutex_lock_interruptible(&dev->struct_mutex);
1867 if (ret)
1868 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001869
1870 temp = i915_mch_val(dev_priv);
1871 chipset = i915_chipset_val(dev_priv);
1872 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001873 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001874
1875 seq_printf(m, "GMCH temp: %ld\n", temp);
1876 seq_printf(m, "Chipset power: %ld\n", chipset);
1877 seq_printf(m, "GFX power: %ld\n", gfx);
1878 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1879
1880 return 0;
1881}
1882
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001883static int i915_ring_freq_table(struct seq_file *m, void *unused)
1884{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001885 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001886 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001887 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001888 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001889 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301890 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001891
Akash Goel97d33082015-06-29 14:50:23 +05301892 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001893 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001894 return 0;
1895 }
1896
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001897 intel_runtime_pm_get(dev_priv);
1898
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001899 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1900
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001901 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001902 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001903 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001904
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001905 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301906 /* Convert GT frequency to 50 HZ units */
1907 min_gpu_freq =
1908 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1909 max_gpu_freq =
1910 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1911 } else {
1912 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1913 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1914 }
1915
Damien Lespiau267f0c92013-06-24 22:59:48 +01001916 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001917
Akash Goelf936ec32015-06-29 14:50:22 +05301918 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001919 ia_freq = gpu_freq;
1920 sandybridge_pcode_read(dev_priv,
1921 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1922 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001923 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301924 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001925 (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1926 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001927 ((ia_freq >> 0) & 0xff) * 100,
1928 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001929 }
1930
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001931 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001932
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001933out:
1934 intel_runtime_pm_put(dev_priv);
1935 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001936}
1937
Chris Wilson44834a62010-08-19 16:09:23 +01001938static int i915_opregion(struct seq_file *m, void *unused)
1939{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001940 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001941 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001942 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001943 struct intel_opregion *opregion = &dev_priv->opregion;
1944 int ret;
1945
1946 ret = mutex_lock_interruptible(&dev->struct_mutex);
1947 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001948 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001949
Jani Nikula2455a8e2015-12-14 12:50:53 +02001950 if (opregion->header)
1951 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001952
1953 mutex_unlock(&dev->struct_mutex);
1954
Daniel Vetter0d38f002012-04-21 22:49:10 +02001955out:
Chris Wilson44834a62010-08-19 16:09:23 +01001956 return 0;
1957}
1958
Jani Nikulaada8f952015-12-15 13:17:12 +02001959static int i915_vbt(struct seq_file *m, void *unused)
1960{
1961 struct drm_info_node *node = m->private;
1962 struct drm_device *dev = node->minor->dev;
1963 struct drm_i915_private *dev_priv = dev->dev_private;
1964 struct intel_opregion *opregion = &dev_priv->opregion;
1965
1966 if (opregion->vbt)
1967 seq_write(m, opregion->vbt, opregion->vbt_size);
1968
1969 return 0;
1970}
1971
Chris Wilson37811fc2010-08-25 22:45:57 +01001972static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1973{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001974 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001975 struct drm_device *dev = node->minor->dev;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301976 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001977 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001978 int ret;
1979
1980 ret = mutex_lock_interruptible(&dev->struct_mutex);
1981 if (ret)
1982 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001983
Daniel Vetter06957262015-08-10 13:34:08 +02001984#ifdef CONFIG_DRM_FBDEV_EMULATION
Namrta Salonieb13b8402015-11-27 13:43:11 +05301985 if (to_i915(dev)->fbdev) {
1986 fbdev_fb = to_intel_framebuffer(to_i915(dev)->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001987
Namrta Salonieb13b8402015-11-27 13:43:11 +05301988 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1989 fbdev_fb->base.width,
1990 fbdev_fb->base.height,
1991 fbdev_fb->base.depth,
1992 fbdev_fb->base.bits_per_pixel,
1993 fbdev_fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001994 drm_framebuffer_read_refcount(&fbdev_fb->base));
Namrta Salonieb13b8402015-11-27 13:43:11 +05301995 describe_obj(m, fbdev_fb->obj);
1996 seq_putc(m, '\n');
1997 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001998#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001999
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002000 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02002001 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05302002 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
2003 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01002004 continue;
2005
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00002006 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 +01002007 fb->base.width,
2008 fb->base.height,
2009 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01002010 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00002011 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10002012 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00002013 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01002014 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01002015 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002016 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01002017 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01002018
2019 return 0;
2020}
2021
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002022static void describe_ctx_ringbuf(struct seq_file *m,
2023 struct intel_ringbuffer *ringbuf)
2024{
2025 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
2026 ringbuf->space, ringbuf->head, ringbuf->tail,
2027 ringbuf->last_retired_head);
2028}
2029
Ben Widawskye76d3632011-03-19 18:14:29 -07002030static int i915_context_status(struct seq_file *m, void *unused)
2031{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002032 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07002033 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03002034 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002035 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002036 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00002037 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07002038
Daniel Vetterf3d28872014-05-29 23:23:08 +02002039 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002040 if (ret)
2041 return ret;
2042
Ben Widawskya33afea2013-09-17 21:12:45 -07002043 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01002044 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsond28b99a2016-05-24 14:53:39 +01002045 if (IS_ERR(ctx->file_priv)) {
2046 seq_puts(m, "(deleted) ");
2047 } else if (ctx->file_priv) {
2048 struct pid *pid = ctx->file_priv->file->pid;
2049 struct task_struct *task;
2050
2051 task = get_pid_task(pid, PIDTYPE_PID);
2052 if (task) {
2053 seq_printf(m, "(%s [%d]) ",
2054 task->comm, task->pid);
2055 put_task_struct(task);
2056 }
2057 } else {
2058 seq_puts(m, "(kernel) ");
2059 }
2060
Chris Wilsonbca44d82016-05-24 14:53:41 +01002061 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
2062 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07002063
Chris Wilsonbca44d82016-05-24 14:53:41 +01002064 for_each_engine(engine, dev_priv) {
2065 struct intel_context *ce = &ctx->engine[engine->id];
2066
2067 seq_printf(m, "%s: ", engine->name);
2068 seq_putc(m, ce->initialised ? 'I' : 'i');
2069 if (ce->state)
2070 describe_obj(m, ce->state);
2071 if (ce->ringbuf)
2072 describe_ctx_ringbuf(m, ce->ringbuf);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002073 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002074 }
2075
Ben Widawskya33afea2013-09-17 21:12:45 -07002076 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002077 }
2078
Daniel Vetterf3d28872014-05-29 23:23:08 +02002079 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002080
2081 return 0;
2082}
2083
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002084static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002085 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002086 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002087{
Chris Wilsonbca44d82016-05-24 14:53:41 +01002088 struct drm_i915_gem_object *ctx_obj = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002089 struct page *page;
2090 uint32_t *reg_state;
2091 int j;
2092 unsigned long ggtt_offset = 0;
2093
Chris Wilson7069b142016-04-28 09:56:52 +01002094 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2095
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002096 if (ctx_obj == NULL) {
Chris Wilson7069b142016-04-28 09:56:52 +01002097 seq_puts(m, "\tNot allocated\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002098 return;
2099 }
2100
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002101 if (!i915_gem_obj_ggtt_bound(ctx_obj))
2102 seq_puts(m, "\tNot bound in GGTT\n");
2103 else
2104 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
2105
2106 if (i915_gem_object_get_pages(ctx_obj)) {
2107 seq_puts(m, "\tFailed to get pages for context object\n");
2108 return;
2109 }
2110
Alex Daid1675192015-08-12 15:43:43 +01002111 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002112 if (!WARN_ON(page == NULL)) {
2113 reg_state = kmap_atomic(page);
2114
2115 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2116 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2117 ggtt_offset + 4096 + (j * 4),
2118 reg_state[j], reg_state[j + 1],
2119 reg_state[j + 2], reg_state[j + 3]);
2120 }
2121 kunmap_atomic(reg_state);
2122 }
2123
2124 seq_putc(m, '\n');
2125}
2126
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002127static int i915_dump_lrc(struct seq_file *m, void *unused)
2128{
2129 struct drm_info_node *node = (struct drm_info_node *) m->private;
2130 struct drm_device *dev = node->minor->dev;
2131 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002132 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002133 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002134 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002135
2136 if (!i915.enable_execlists) {
2137 seq_printf(m, "Logical Ring Contexts are disabled\n");
2138 return 0;
2139 }
2140
2141 ret = mutex_lock_interruptible(&dev->struct_mutex);
2142 if (ret)
2143 return ret;
2144
Dave Gordone28e4042016-01-19 19:02:55 +00002145 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002146 for_each_engine(engine, dev_priv)
2147 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002148
2149 mutex_unlock(&dev->struct_mutex);
2150
2151 return 0;
2152}
2153
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002154static int i915_execlists(struct seq_file *m, void *data)
2155{
2156 struct drm_info_node *node = (struct drm_info_node *)m->private;
2157 struct drm_device *dev = node->minor->dev;
2158 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002159 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002160 u32 status_pointer;
2161 u8 read_pointer;
2162 u8 write_pointer;
2163 u32 status;
2164 u32 ctx_id;
2165 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002166 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002167
2168 if (!i915.enable_execlists) {
2169 seq_puts(m, "Logical Ring Contexts are disabled\n");
2170 return 0;
2171 }
2172
2173 ret = mutex_lock_interruptible(&dev->struct_mutex);
2174 if (ret)
2175 return ret;
2176
Michel Thierryfc0412e2014-10-16 16:13:38 +01002177 intel_runtime_pm_get(dev_priv);
2178
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002179 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002180 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002181 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002182
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002183 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002184
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002185 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2186 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002187 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2188 status, ctx_id);
2189
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002190 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002191 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2192
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002193 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002194 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002195 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002196 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002197 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2198 read_pointer, write_pointer);
2199
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002200 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002201 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2202 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002203
2204 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2205 i, status, ctx_id);
2206 }
2207
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002208 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002209 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002210 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002211 head_req = list_first_entry_or_null(&engine->execlist_queue,
2212 struct drm_i915_gem_request,
2213 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002214 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002215
2216 seq_printf(m, "\t%d requests in queue\n", count);
2217 if (head_req) {
Chris Wilson7069b142016-04-28 09:56:52 +01002218 seq_printf(m, "\tHead request context: %u\n",
2219 head_req->ctx->hw_id);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002220 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002221 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002222 }
2223
2224 seq_putc(m, '\n');
2225 }
2226
Michel Thierryfc0412e2014-10-16 16:13:38 +01002227 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002228 mutex_unlock(&dev->struct_mutex);
2229
2230 return 0;
2231}
2232
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002233static const char *swizzle_string(unsigned swizzle)
2234{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002235 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002236 case I915_BIT_6_SWIZZLE_NONE:
2237 return "none";
2238 case I915_BIT_6_SWIZZLE_9:
2239 return "bit9";
2240 case I915_BIT_6_SWIZZLE_9_10:
2241 return "bit9/bit10";
2242 case I915_BIT_6_SWIZZLE_9_11:
2243 return "bit9/bit11";
2244 case I915_BIT_6_SWIZZLE_9_10_11:
2245 return "bit9/bit10/bit11";
2246 case I915_BIT_6_SWIZZLE_9_17:
2247 return "bit9/bit17";
2248 case I915_BIT_6_SWIZZLE_9_10_17:
2249 return "bit9/bit10/bit17";
2250 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002251 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002252 }
2253
2254 return "bug";
2255}
2256
2257static int i915_swizzle_info(struct seq_file *m, void *data)
2258{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002259 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002260 struct drm_device *dev = node->minor->dev;
2261 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002262 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002263
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002264 ret = mutex_lock_interruptible(&dev->struct_mutex);
2265 if (ret)
2266 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002267 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002268
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002269 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2270 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2271 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2272 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2273
2274 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2275 seq_printf(m, "DDC = 0x%08x\n",
2276 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002277 seq_printf(m, "DDC2 = 0x%08x\n",
2278 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002279 seq_printf(m, "C0DRB3 = 0x%04x\n",
2280 I915_READ16(C0DRB3));
2281 seq_printf(m, "C1DRB3 = 0x%04x\n",
2282 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002283 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002284 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2285 I915_READ(MAD_DIMM_C0));
2286 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2287 I915_READ(MAD_DIMM_C1));
2288 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2289 I915_READ(MAD_DIMM_C2));
2290 seq_printf(m, "TILECTL = 0x%08x\n",
2291 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002292 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002293 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2294 I915_READ(GAMTARBMODE));
2295 else
2296 seq_printf(m, "ARB_MODE = 0x%08x\n",
2297 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002298 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2299 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002300 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002301
2302 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2303 seq_puts(m, "L-shaped memory detected\n");
2304
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002305 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002306 mutex_unlock(&dev->struct_mutex);
2307
2308 return 0;
2309}
2310
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002311static int per_file_ctx(int id, void *ptr, void *data)
2312{
Chris Wilsone2efd132016-05-24 14:53:34 +01002313 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002314 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002315 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2316
2317 if (!ppgtt) {
2318 seq_printf(m, " no ppgtt for context %d\n",
2319 ctx->user_handle);
2320 return 0;
2321 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002322
Oscar Mateof83d6512014-05-22 14:13:38 +01002323 if (i915_gem_context_is_default(ctx))
2324 seq_puts(m, " default context:\n");
2325 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002326 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002327 ppgtt->debug_dump(ppgtt, m);
2328
2329 return 0;
2330}
2331
Ben Widawsky77df6772013-11-02 21:07:30 -07002332static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002333{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002334 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002335 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002336 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002337 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002338
Ben Widawsky77df6772013-11-02 21:07:30 -07002339 if (!ppgtt)
2340 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002341
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002342 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002343 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002344 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002345 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002346 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002347 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002348 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002349 }
2350 }
2351}
2352
2353static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2354{
2355 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002356 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002357
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002358 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002359 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2360
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002361 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002362 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002363 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002364 seq_printf(m, "GFX_MODE: 0x%08x\n",
2365 I915_READ(RING_MODE_GEN7(engine)));
2366 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2367 I915_READ(RING_PP_DIR_BASE(engine)));
2368 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2369 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2370 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2371 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002372 }
2373 if (dev_priv->mm.aliasing_ppgtt) {
2374 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2375
Damien Lespiau267f0c92013-06-24 22:59:48 +01002376 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002377 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002378
Ben Widawsky87d60b62013-12-06 14:11:29 -08002379 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002380 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002381
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002382 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002383}
2384
2385static int i915_ppgtt_info(struct seq_file *m, void *data)
2386{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002387 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002388 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002389 struct drm_i915_private *dev_priv = dev->dev_private;
Michel Thierryea91e402015-07-29 17:23:57 +01002390 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002391
2392 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2393 if (ret)
2394 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002395 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002396
2397 if (INTEL_INFO(dev)->gen >= 8)
2398 gen8_ppgtt_info(m, dev);
2399 else if (INTEL_INFO(dev)->gen >= 6)
2400 gen6_ppgtt_info(m, dev);
2401
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002402 mutex_lock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002403 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2404 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002405 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002406
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002407 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002408 if (!task) {
2409 ret = -ESRCH;
Wei Yongjunb0212482016-06-13 23:42:00 +00002410 goto out_unlock;
Dan Carpenter06812762015-10-02 18:14:22 +03002411 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002412 seq_printf(m, "\nproc: %s\n", task->comm);
2413 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002414 idr_for_each(&file_priv->context_idr, per_file_ctx,
2415 (void *)(unsigned long)m);
2416 }
Wei Yongjunb0212482016-06-13 23:42:00 +00002417out_unlock:
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002418 mutex_unlock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002419
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002420 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002421 mutex_unlock(&dev->struct_mutex);
2422
Dan Carpenter06812762015-10-02 18:14:22 +03002423 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002424}
2425
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002426static int count_irq_waiters(struct drm_i915_private *i915)
2427{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002428 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002429 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002430
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002431 for_each_engine(engine, i915)
Chris Wilson688e6c72016-07-01 17:23:15 +01002432 count += intel_engine_has_waiter(engine);
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002433
2434 return count;
2435}
2436
Chris Wilson1854d5c2015-04-07 16:20:32 +01002437static int i915_rps_boost_info(struct seq_file *m, void *data)
2438{
2439 struct drm_info_node *node = m->private;
2440 struct drm_device *dev = node->minor->dev;
2441 struct drm_i915_private *dev_priv = dev->dev_private;
2442 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002443
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002444 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2445 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2446 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2447 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2448 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2449 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2450 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2451 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2452 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002453
2454 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002455 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002456 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2457 struct drm_i915_file_private *file_priv = file->driver_priv;
2458 struct task_struct *task;
2459
2460 rcu_read_lock();
2461 task = pid_task(file->pid, PIDTYPE_PID);
2462 seq_printf(m, "%s [%d]: %d boosts%s\n",
2463 task ? task->comm : "<unknown>",
2464 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002465 file_priv->rps.boosts,
2466 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002467 rcu_read_unlock();
2468 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002469 seq_printf(m, "Semaphore boosts: %d%s\n",
2470 dev_priv->rps.semaphores.boosts,
2471 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2472 seq_printf(m, "MMIO flip boosts: %d%s\n",
2473 dev_priv->rps.mmioflips.boosts,
2474 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002475 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002476 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002477 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002478
Chris Wilson8d3afd72015-05-21 21:01:47 +01002479 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002480}
2481
Ben Widawsky63573eb2013-07-04 11:02:07 -07002482static int i915_llc(struct seq_file *m, void *data)
2483{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002484 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002485 struct drm_device *dev = node->minor->dev;
2486 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002487 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002488
Ben Widawsky63573eb2013-07-04 11:02:07 -07002489 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002490 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2491 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002492
2493 return 0;
2494}
2495
Alex Daifdf5d352015-08-12 15:43:37 +01002496static int i915_guc_load_status_info(struct seq_file *m, void *data)
2497{
2498 struct drm_info_node *node = m->private;
2499 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2500 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2501 u32 tmp, i;
2502
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002503 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002504 return 0;
2505
2506 seq_printf(m, "GuC firmware status:\n");
2507 seq_printf(m, "\tpath: %s\n",
2508 guc_fw->guc_fw_path);
2509 seq_printf(m, "\tfetch: %s\n",
2510 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2511 seq_printf(m, "\tload: %s\n",
2512 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2513 seq_printf(m, "\tversion wanted: %d.%d\n",
2514 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2515 seq_printf(m, "\tversion found: %d.%d\n",
2516 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002517 seq_printf(m, "\theader: offset is %d; size = %d\n",
2518 guc_fw->header_offset, guc_fw->header_size);
2519 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2520 guc_fw->ucode_offset, guc_fw->ucode_size);
2521 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2522 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002523
2524 tmp = I915_READ(GUC_STATUS);
2525
2526 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2527 seq_printf(m, "\tBootrom status = 0x%x\n",
2528 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2529 seq_printf(m, "\tuKernel status = 0x%x\n",
2530 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2531 seq_printf(m, "\tMIA Core status = 0x%x\n",
2532 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2533 seq_puts(m, "\nScratch registers:\n");
2534 for (i = 0; i < 16; i++)
2535 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2536
2537 return 0;
2538}
2539
Dave Gordon8b417c22015-08-12 15:43:44 +01002540static void i915_guc_client_info(struct seq_file *m,
2541 struct drm_i915_private *dev_priv,
2542 struct i915_guc_client *client)
2543{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002544 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002545 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002546
2547 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2548 client->priority, client->ctx_index, client->proc_desc_offset);
2549 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2550 client->doorbell_id, client->doorbell_offset, client->cookie);
2551 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2552 client->wq_size, client->wq_offset, client->wq_tail);
2553
Dave Gordon551aaec2016-05-13 15:36:33 +01002554 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002555 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2556 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2557 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2558
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002559 for_each_engine(engine, dev_priv) {
Dave Gordon8b417c22015-08-12 15:43:44 +01002560 seq_printf(m, "\tSubmissions: %llu %s\n",
Dave Gordon0b63bb12016-06-20 15:18:07 +01002561 client->submissions[engine->id],
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002562 engine->name);
Dave Gordon0b63bb12016-06-20 15:18:07 +01002563 tot += client->submissions[engine->id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002564 }
2565 seq_printf(m, "\tTotal: %llu\n", tot);
2566}
2567
2568static int i915_guc_info(struct seq_file *m, void *data)
2569{
2570 struct drm_info_node *node = m->private;
2571 struct drm_device *dev = node->minor->dev;
2572 struct drm_i915_private *dev_priv = dev->dev_private;
2573 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002574 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002575 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002576 u64 total = 0;
2577
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002578 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002579 return 0;
2580
Alex Dai5a843302015-12-02 16:56:29 -08002581 if (mutex_lock_interruptible(&dev->struct_mutex))
2582 return 0;
2583
Dave Gordon8b417c22015-08-12 15:43:44 +01002584 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002585 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002586 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002587 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002588
2589 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002590
Dave Gordon9636f6d2016-06-13 17:57:28 +01002591 seq_printf(m, "Doorbell map:\n");
2592 seq_printf(m, "\t%*pb\n", GUC_MAX_DOORBELLS, guc.doorbell_bitmap);
2593 seq_printf(m, "Doorbell next cacheline: 0x%x\n\n", guc.db_cacheline);
2594
Dave Gordon8b417c22015-08-12 15:43:44 +01002595 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2596 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2597 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2598 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2599 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2600
2601 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002602 for_each_engine(engine, dev_priv) {
Alex Dai397097b2016-01-23 11:58:14 -08002603 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Dave Gordon0b63bb12016-06-20 15:18:07 +01002604 engine->name, guc.submissions[engine->id],
2605 guc.last_seqno[engine->id]);
2606 total += guc.submissions[engine->id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002607 }
2608 seq_printf(m, "\t%s: %llu\n", "Total", total);
2609
2610 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2611 i915_guc_client_info(m, dev_priv, &client);
2612
2613 /* Add more as required ... */
2614
2615 return 0;
2616}
2617
Alex Dai4c7e77f2015-08-12 15:43:40 +01002618static int i915_guc_log_dump(struct seq_file *m, void *data)
2619{
2620 struct drm_info_node *node = m->private;
2621 struct drm_device *dev = node->minor->dev;
2622 struct drm_i915_private *dev_priv = dev->dev_private;
2623 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2624 u32 *log;
2625 int i = 0, pg;
2626
2627 if (!log_obj)
2628 return 0;
2629
2630 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2631 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2632
2633 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2634 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2635 *(log + i), *(log + i + 1),
2636 *(log + i + 2), *(log + i + 3));
2637
2638 kunmap_atomic(log);
2639 }
2640
2641 seq_putc(m, '\n');
2642
2643 return 0;
2644}
2645
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002646static int i915_edp_psr_status(struct seq_file *m, void *data)
2647{
2648 struct drm_info_node *node = m->private;
2649 struct drm_device *dev = node->minor->dev;
2650 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002651 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002652 u32 stat[3];
2653 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002654 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002655
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002656 if (!HAS_PSR(dev)) {
2657 seq_puts(m, "PSR not supported\n");
2658 return 0;
2659 }
2660
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002661 intel_runtime_pm_get(dev_priv);
2662
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002663 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002664 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2665 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002666 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002667 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002668 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2669 dev_priv->psr.busy_frontbuffer_bits);
2670 seq_printf(m, "Re-enable work scheduled: %s\n",
2671 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002672
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002673 if (HAS_DDI(dev))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002674 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002675 else {
2676 for_each_pipe(dev_priv, pipe) {
2677 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2678 VLV_EDP_PSR_CURR_STATE_MASK;
2679 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2680 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2681 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002682 }
2683 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002684
2685 seq_printf(m, "Main link in standby mode: %s\n",
2686 yesno(dev_priv->psr.link_standby));
2687
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002688 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002689
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002690 if (!HAS_DDI(dev))
2691 for_each_pipe(dev_priv, pipe) {
2692 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2693 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2694 seq_printf(m, " pipe %c", pipe_name(pipe));
2695 }
2696 seq_puts(m, "\n");
2697
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002698 /*
2699 * VLV/CHV PSR has no kind of performance counter
2700 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2701 */
2702 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002703 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002704 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002705
2706 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2707 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002708 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002709
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002710 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002711 return 0;
2712}
2713
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002714static int i915_sink_crc(struct seq_file *m, void *data)
2715{
2716 struct drm_info_node *node = m->private;
2717 struct drm_device *dev = node->minor->dev;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002718 struct intel_connector *connector;
2719 struct intel_dp *intel_dp = NULL;
2720 int ret;
2721 u8 crc[6];
2722
2723 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002724 for_each_intel_connector(dev, connector) {
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002725 struct drm_crtc *crtc;
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002726
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002727 if (!connector->base.state->best_encoder)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002728 continue;
2729
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002730 crtc = connector->base.state->crtc;
2731 if (!crtc->state->active)
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002732 continue;
2733
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002734 if (connector->base.connector_type != DRM_MODE_CONNECTOR_eDP)
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002735 continue;
2736
Maarten Lankhorst26c17cf2016-06-20 15:57:38 +02002737 intel_dp = enc_to_intel_dp(connector->base.state->best_encoder);
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002738
2739 ret = intel_dp_sink_crc(intel_dp, crc);
2740 if (ret)
2741 goto out;
2742
2743 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2744 crc[0], crc[1], crc[2],
2745 crc[3], crc[4], crc[5]);
2746 goto out;
2747 }
2748 ret = -ENODEV;
2749out:
2750 drm_modeset_unlock_all(dev);
2751 return ret;
2752}
2753
Jesse Barnesec013e72013-08-20 10:29:23 +01002754static int i915_energy_uJ(struct seq_file *m, void *data)
2755{
2756 struct drm_info_node *node = m->private;
2757 struct drm_device *dev = node->minor->dev;
2758 struct drm_i915_private *dev_priv = dev->dev_private;
2759 u64 power;
2760 u32 units;
2761
2762 if (INTEL_INFO(dev)->gen < 6)
2763 return -ENODEV;
2764
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002765 intel_runtime_pm_get(dev_priv);
2766
Jesse Barnesec013e72013-08-20 10:29:23 +01002767 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2768 power = (power & 0x1f00) >> 8;
2769 units = 1000000 / (1 << power); /* convert to uJ */
2770 power = I915_READ(MCH_SECP_NRG_STTS);
2771 power *= units;
2772
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002773 intel_runtime_pm_put(dev_priv);
2774
Jesse Barnesec013e72013-08-20 10:29:23 +01002775 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002776
2777 return 0;
2778}
2779
Damien Lespiau6455c872015-06-04 18:23:57 +01002780static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002781{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002782 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002783 struct drm_device *dev = node->minor->dev;
2784 struct drm_i915_private *dev_priv = dev->dev_private;
2785
Chris Wilsona156e642016-04-03 14:14:21 +01002786 if (!HAS_RUNTIME_PM(dev_priv))
2787 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002788
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002789 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002790 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002791 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002792#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002793 seq_printf(m, "Usage count: %d\n",
2794 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002795#else
2796 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2797#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002798 seq_printf(m, "PCI device power state: %s [%d]\n",
2799 pci_power_name(dev_priv->dev->pdev->current_state),
2800 dev_priv->dev->pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002801
Jesse Barnesec013e72013-08-20 10:29:23 +01002802 return 0;
2803}
2804
Imre Deak1da51582013-11-25 17:15:35 +02002805static int i915_power_domain_info(struct seq_file *m, void *unused)
2806{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002807 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002808 struct drm_device *dev = node->minor->dev;
2809 struct drm_i915_private *dev_priv = dev->dev_private;
2810 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2811 int i;
2812
2813 mutex_lock(&power_domains->lock);
2814
2815 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2816 for (i = 0; i < power_domains->power_well_count; i++) {
2817 struct i915_power_well *power_well;
2818 enum intel_display_power_domain power_domain;
2819
2820 power_well = &power_domains->power_wells[i];
2821 seq_printf(m, "%-25s %d\n", power_well->name,
2822 power_well->count);
2823
2824 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2825 power_domain++) {
2826 if (!(BIT(power_domain) & power_well->domains))
2827 continue;
2828
2829 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002830 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002831 power_domains->domain_use_count[power_domain]);
2832 }
2833 }
2834
2835 mutex_unlock(&power_domains->lock);
2836
2837 return 0;
2838}
2839
Damien Lespiaub7cec662015-10-27 14:47:01 +02002840static int i915_dmc_info(struct seq_file *m, void *unused)
2841{
2842 struct drm_info_node *node = m->private;
2843 struct drm_device *dev = node->minor->dev;
2844 struct drm_i915_private *dev_priv = dev->dev_private;
2845 struct intel_csr *csr;
2846
2847 if (!HAS_CSR(dev)) {
2848 seq_puts(m, "not supported\n");
2849 return 0;
2850 }
2851
2852 csr = &dev_priv->csr;
2853
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002854 intel_runtime_pm_get(dev_priv);
2855
Damien Lespiaub7cec662015-10-27 14:47:01 +02002856 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2857 seq_printf(m, "path: %s\n", csr->fw_path);
2858
2859 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002860 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002861
2862 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2863 CSR_VERSION_MINOR(csr->version));
2864
Damien Lespiau83372062015-10-30 17:53:32 +02002865 if (IS_SKYLAKE(dev) && csr->version >= CSR_VERSION(1, 6)) {
2866 seq_printf(m, "DC3 -> DC5 count: %d\n",
2867 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2868 seq_printf(m, "DC5 -> DC6 count: %d\n",
2869 I915_READ(SKL_CSR_DC5_DC6_COUNT));
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002870 } else if (IS_BROXTON(dev) && csr->version >= CSR_VERSION(1, 4)) {
2871 seq_printf(m, "DC3 -> DC5 count: %d\n",
2872 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002873 }
2874
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002875out:
2876 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2877 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2878 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2879
Damien Lespiau83372062015-10-30 17:53:32 +02002880 intel_runtime_pm_put(dev_priv);
2881
Damien Lespiaub7cec662015-10-27 14:47:01 +02002882 return 0;
2883}
2884
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002885static void intel_seq_print_mode(struct seq_file *m, int tabs,
2886 struct drm_display_mode *mode)
2887{
2888 int i;
2889
2890 for (i = 0; i < tabs; i++)
2891 seq_putc(m, '\t');
2892
2893 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",
2894 mode->base.id, mode->name,
2895 mode->vrefresh, mode->clock,
2896 mode->hdisplay, mode->hsync_start,
2897 mode->hsync_end, mode->htotal,
2898 mode->vdisplay, mode->vsync_start,
2899 mode->vsync_end, mode->vtotal,
2900 mode->type, mode->flags);
2901}
2902
2903static void intel_encoder_info(struct seq_file *m,
2904 struct intel_crtc *intel_crtc,
2905 struct intel_encoder *intel_encoder)
2906{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002907 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002908 struct drm_device *dev = node->minor->dev;
2909 struct drm_crtc *crtc = &intel_crtc->base;
2910 struct intel_connector *intel_connector;
2911 struct drm_encoder *encoder;
2912
2913 encoder = &intel_encoder->base;
2914 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002915 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002916 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2917 struct drm_connector *connector = &intel_connector->base;
2918 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2919 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002920 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002921 drm_get_connector_status_name(connector->status));
2922 if (connector->status == connector_status_connected) {
2923 struct drm_display_mode *mode = &crtc->mode;
2924 seq_printf(m, ", mode:\n");
2925 intel_seq_print_mode(m, 2, mode);
2926 } else {
2927 seq_putc(m, '\n');
2928 }
2929 }
2930}
2931
2932static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2933{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002934 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002935 struct drm_device *dev = node->minor->dev;
2936 struct drm_crtc *crtc = &intel_crtc->base;
2937 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002938 struct drm_plane_state *plane_state = crtc->primary->state;
2939 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002940
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002941 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002942 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002943 fb->base.id, plane_state->src_x >> 16,
2944 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002945 else
2946 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002947 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2948 intel_encoder_info(m, intel_crtc, intel_encoder);
2949}
2950
2951static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2952{
2953 struct drm_display_mode *mode = panel->fixed_mode;
2954
2955 seq_printf(m, "\tfixed mode:\n");
2956 intel_seq_print_mode(m, 2, mode);
2957}
2958
2959static void intel_dp_info(struct seq_file *m,
2960 struct intel_connector *intel_connector)
2961{
2962 struct intel_encoder *intel_encoder = intel_connector->encoder;
2963 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2964
2965 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002966 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02002967 if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002968 intel_panel_info(m, &intel_connector->panel);
2969}
2970
2971static void intel_hdmi_info(struct seq_file *m,
2972 struct intel_connector *intel_connector)
2973{
2974 struct intel_encoder *intel_encoder = intel_connector->encoder;
2975 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2976
Jani Nikula742f4912015-09-03 11:16:09 +03002977 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002978}
2979
2980static void intel_lvds_info(struct seq_file *m,
2981 struct intel_connector *intel_connector)
2982{
2983 intel_panel_info(m, &intel_connector->panel);
2984}
2985
2986static void intel_connector_info(struct seq_file *m,
2987 struct drm_connector *connector)
2988{
2989 struct intel_connector *intel_connector = to_intel_connector(connector);
2990 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002991 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002992
2993 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002994 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002995 drm_get_connector_status_name(connector->status));
2996 if (connector->status == connector_status_connected) {
2997 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2998 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2999 connector->display_info.width_mm,
3000 connector->display_info.height_mm);
3001 seq_printf(m, "\tsubpixel order: %s\n",
3002 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
3003 seq_printf(m, "\tCEA rev: %d\n",
3004 connector->display_info.cea_rev);
3005 }
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003006
3007 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3008 return;
3009
3010 switch (connector->connector_type) {
3011 case DRM_MODE_CONNECTOR_DisplayPort:
3012 case DRM_MODE_CONNECTOR_eDP:
3013 intel_dp_info(m, intel_connector);
3014 break;
3015 case DRM_MODE_CONNECTOR_LVDS:
3016 if (intel_encoder->type == INTEL_OUTPUT_LVDS)
Dave Airlie36cd7442014-05-02 13:44:18 +10003017 intel_lvds_info(m, intel_connector);
Maarten Lankhorstee648a72016-06-21 12:00:38 +02003018 break;
3019 case DRM_MODE_CONNECTOR_HDMIA:
3020 if (intel_encoder->type == INTEL_OUTPUT_HDMI ||
3021 intel_encoder->type == INTEL_OUTPUT_UNKNOWN)
3022 intel_hdmi_info(m, intel_connector);
3023 break;
3024 default:
3025 break;
Dave Airlie36cd7442014-05-02 13:44:18 +10003026 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003027
Jesse Barnesf103fc72014-02-20 12:39:57 -08003028 seq_printf(m, "\tmodes:\n");
3029 list_for_each_entry(mode, &connector->modes, head)
3030 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003031}
3032
Chris Wilson065f2ec2014-03-12 09:13:13 +00003033static bool cursor_active(struct drm_device *dev, int pipe)
3034{
3035 struct drm_i915_private *dev_priv = dev->dev_private;
3036 u32 state;
3037
3038 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03003039 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003040 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003041 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003042
3043 return state;
3044}
3045
3046static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
3047{
3048 struct drm_i915_private *dev_priv = dev->dev_private;
3049 u32 pos;
3050
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003051 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00003052
3053 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3054 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3055 *x = -*x;
3056
3057 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3058 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3059 *y = -*y;
3060
3061 return cursor_active(dev, pipe);
3062}
3063
Robert Fekete3abc4e02015-10-27 16:58:32 +01003064static const char *plane_type(enum drm_plane_type type)
3065{
3066 switch (type) {
3067 case DRM_PLANE_TYPE_OVERLAY:
3068 return "OVL";
3069 case DRM_PLANE_TYPE_PRIMARY:
3070 return "PRI";
3071 case DRM_PLANE_TYPE_CURSOR:
3072 return "CUR";
3073 /*
3074 * Deliberately omitting default: to generate compiler warnings
3075 * when a new drm_plane_type gets added.
3076 */
3077 }
3078
3079 return "unknown";
3080}
3081
3082static const char *plane_rotation(unsigned int rotation)
3083{
3084 static char buf[48];
3085 /*
3086 * According to doc only one DRM_ROTATE_ is allowed but this
3087 * will print them all to visualize if the values are misused
3088 */
3089 snprintf(buf, sizeof(buf),
3090 "%s%s%s%s%s%s(0x%08x)",
3091 (rotation & BIT(DRM_ROTATE_0)) ? "0 " : "",
3092 (rotation & BIT(DRM_ROTATE_90)) ? "90 " : "",
3093 (rotation & BIT(DRM_ROTATE_180)) ? "180 " : "",
3094 (rotation & BIT(DRM_ROTATE_270)) ? "270 " : "",
3095 (rotation & BIT(DRM_REFLECT_X)) ? "FLIPX " : "",
3096 (rotation & BIT(DRM_REFLECT_Y)) ? "FLIPY " : "",
3097 rotation);
3098
3099 return buf;
3100}
3101
3102static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3103{
3104 struct drm_info_node *node = m->private;
3105 struct drm_device *dev = node->minor->dev;
3106 struct intel_plane *intel_plane;
3107
3108 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3109 struct drm_plane_state *state;
3110 struct drm_plane *plane = &intel_plane->base;
3111
3112 if (!plane->state) {
3113 seq_puts(m, "plane->state is NULL!\n");
3114 continue;
3115 }
3116
3117 state = plane->state;
3118
3119 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",
3120 plane->base.id,
3121 plane_type(intel_plane->base.type),
3122 state->crtc_x, state->crtc_y,
3123 state->crtc_w, state->crtc_h,
3124 (state->src_x >> 16),
3125 ((state->src_x & 0xffff) * 15625) >> 10,
3126 (state->src_y >> 16),
3127 ((state->src_y & 0xffff) * 15625) >> 10,
3128 (state->src_w >> 16),
3129 ((state->src_w & 0xffff) * 15625) >> 10,
3130 (state->src_h >> 16),
3131 ((state->src_h & 0xffff) * 15625) >> 10,
3132 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3133 plane_rotation(state->rotation));
3134 }
3135}
3136
3137static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3138{
3139 struct intel_crtc_state *pipe_config;
3140 int num_scalers = intel_crtc->num_scalers;
3141 int i;
3142
3143 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3144
3145 /* Not all platformas have a scaler */
3146 if (num_scalers) {
3147 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3148 num_scalers,
3149 pipe_config->scaler_state.scaler_users,
3150 pipe_config->scaler_state.scaler_id);
3151
3152 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3153 struct intel_scaler *sc =
3154 &pipe_config->scaler_state.scalers[i];
3155
3156 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3157 i, yesno(sc->in_use), sc->mode);
3158 }
3159 seq_puts(m, "\n");
3160 } else {
3161 seq_puts(m, "\tNo scalers available on this platform\n");
3162 }
3163}
3164
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003165static int i915_display_info(struct seq_file *m, void *unused)
3166{
Damien Lespiau9f25d002014-05-13 15:30:28 +01003167 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003168 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003169 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003170 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003171 struct drm_connector *connector;
3172
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003173 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003174 drm_modeset_lock_all(dev);
3175 seq_printf(m, "CRTC info\n");
3176 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003177 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003178 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003179 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003180 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003181
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003182 pipe_config = to_intel_crtc_state(crtc->base.state);
3183
Robert Fekete3abc4e02015-10-27 16:58:32 +01003184 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003185 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003186 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003187 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3188 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3189
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003190 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003191 intel_crtc_info(m, crtc);
3192
Paulo Zanonia23dc652014-04-01 14:55:11 -03003193 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003194 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 +03003195 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003196 x, y, crtc->base.cursor->state->crtc_w,
3197 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003198 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003199 intel_scaler_info(m, crtc);
3200 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003201 }
Daniel Vettercace8412014-05-22 17:56:31 +02003202
3203 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3204 yesno(!crtc->cpu_fifo_underrun_disabled),
3205 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003206 }
3207
3208 seq_printf(m, "\n");
3209 seq_printf(m, "Connector info\n");
3210 seq_printf(m, "--------------\n");
3211 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3212 intel_connector_info(m, connector);
3213 }
3214 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003215 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003216
3217 return 0;
3218}
3219
Ben Widawskye04934c2014-06-30 09:53:42 -07003220static int i915_semaphore_status(struct seq_file *m, void *unused)
3221{
3222 struct drm_info_node *node = (struct drm_info_node *) m->private;
3223 struct drm_device *dev = node->minor->dev;
3224 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003225 struct intel_engine_cs *engine;
Ben Widawskye04934c2014-06-30 09:53:42 -07003226 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
Dave Gordonc3232b12016-03-23 18:19:53 +00003227 enum intel_engine_id id;
3228 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003229
Chris Wilsonc0336662016-05-06 15:40:21 +01003230 if (!i915_semaphore_is_enabled(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003231 seq_puts(m, "Semaphores are disabled\n");
3232 return 0;
3233 }
3234
3235 ret = mutex_lock_interruptible(&dev->struct_mutex);
3236 if (ret)
3237 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003238 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003239
3240 if (IS_BROADWELL(dev)) {
3241 struct page *page;
3242 uint64_t *seqno;
3243
3244 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3245
3246 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003247 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003248 uint64_t offset;
3249
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003250 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003251
3252 seq_puts(m, " Last signal:");
3253 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003254 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003255 seq_printf(m, "0x%08llx (0x%02llx) ",
3256 seqno[offset], offset * 8);
3257 }
3258 seq_putc(m, '\n');
3259
3260 seq_puts(m, " Last wait: ");
3261 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003262 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003263 seq_printf(m, "0x%08llx (0x%02llx) ",
3264 seqno[offset], offset * 8);
3265 }
3266 seq_putc(m, '\n');
3267
3268 }
3269 kunmap_atomic(seqno);
3270 } else {
3271 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003272 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003273 for (j = 0; j < num_rings; j++)
3274 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003275 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003276 seq_putc(m, '\n');
3277 }
3278
3279 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003280 for_each_engine(engine, dev_priv) {
3281 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003282 seq_printf(m, " 0x%08x ",
3283 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003284 seq_putc(m, '\n');
3285 }
3286 seq_putc(m, '\n');
3287
Paulo Zanoni03872062014-07-09 14:31:57 -03003288 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003289 mutex_unlock(&dev->struct_mutex);
3290 return 0;
3291}
3292
Daniel Vetter728e29d2014-06-25 22:01:53 +03003293static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3294{
3295 struct drm_info_node *node = (struct drm_info_node *) m->private;
3296 struct drm_device *dev = node->minor->dev;
3297 struct drm_i915_private *dev_priv = dev->dev_private;
3298 int i;
3299
3300 drm_modeset_lock_all(dev);
3301 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3302 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3303
3304 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003305 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3306 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003307 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003308 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3309 seq_printf(m, " dpll_md: 0x%08x\n",
3310 pll->config.hw_state.dpll_md);
3311 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3312 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3313 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003314 }
3315 drm_modeset_unlock_all(dev);
3316
3317 return 0;
3318}
3319
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003320static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003321{
3322 int i;
3323 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003324 struct intel_engine_cs *engine;
Arun Siluvery888b5992014-08-26 14:44:51 +01003325 struct drm_info_node *node = (struct drm_info_node *) m->private;
3326 struct drm_device *dev = node->minor->dev;
3327 struct drm_i915_private *dev_priv = dev->dev_private;
Arun Siluvery33136b02016-01-21 21:43:47 +00003328 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003329 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003330
Arun Siluvery888b5992014-08-26 14:44:51 +01003331 ret = mutex_lock_interruptible(&dev->struct_mutex);
3332 if (ret)
3333 return ret;
3334
3335 intel_runtime_pm_get(dev_priv);
3336
Arun Siluvery33136b02016-01-21 21:43:47 +00003337 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003338 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003339 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003340 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003341 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003342 i915_reg_t addr;
3343 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003344 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003345
Arun Siluvery33136b02016-01-21 21:43:47 +00003346 addr = workarounds->reg[i].addr;
3347 mask = workarounds->reg[i].mask;
3348 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003349 read = I915_READ(addr);
3350 ok = (value & mask) == (read & mask);
3351 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 +02003352 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003353 }
3354
3355 intel_runtime_pm_put(dev_priv);
3356 mutex_unlock(&dev->struct_mutex);
3357
3358 return 0;
3359}
3360
Damien Lespiauc5511e42014-11-04 17:06:51 +00003361static int i915_ddb_info(struct seq_file *m, void *unused)
3362{
3363 struct drm_info_node *node = m->private;
3364 struct drm_device *dev = node->minor->dev;
3365 struct drm_i915_private *dev_priv = dev->dev_private;
3366 struct skl_ddb_allocation *ddb;
3367 struct skl_ddb_entry *entry;
3368 enum pipe pipe;
3369 int plane;
3370
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003371 if (INTEL_INFO(dev)->gen < 9)
3372 return 0;
3373
Damien Lespiauc5511e42014-11-04 17:06:51 +00003374 drm_modeset_lock_all(dev);
3375
3376 ddb = &dev_priv->wm.skl_hw.ddb;
3377
3378 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3379
3380 for_each_pipe(dev_priv, pipe) {
3381 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3382
Damien Lespiaudd740782015-02-28 14:54:08 +00003383 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003384 entry = &ddb->plane[pipe][plane];
3385 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3386 entry->start, entry->end,
3387 skl_ddb_entry_size(entry));
3388 }
3389
Matt Roper4969d332015-09-24 15:53:10 -07003390 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003391 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3392 entry->end, skl_ddb_entry_size(entry));
3393 }
3394
3395 drm_modeset_unlock_all(dev);
3396
3397 return 0;
3398}
3399
Vandana Kannana54746e2015-03-03 20:53:10 +05303400static void drrs_status_per_crtc(struct seq_file *m,
3401 struct drm_device *dev, struct intel_crtc *intel_crtc)
3402{
Vandana Kannana54746e2015-03-03 20:53:10 +05303403 struct drm_i915_private *dev_priv = dev->dev_private;
3404 struct i915_drrs *drrs = &dev_priv->drrs;
3405 int vrefresh = 0;
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003406 struct drm_connector *connector;
Vandana Kannana54746e2015-03-03 20:53:10 +05303407
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003408 drm_for_each_connector(connector, dev) {
3409 if (connector->state->crtc != &intel_crtc->base)
3410 continue;
3411
3412 seq_printf(m, "%s:\n", connector->name);
Vandana Kannana54746e2015-03-03 20:53:10 +05303413 }
3414
3415 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3416 seq_puts(m, "\tVBT: DRRS_type: Static");
3417 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3418 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3419 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3420 seq_puts(m, "\tVBT: DRRS_type: None");
3421 else
3422 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3423
3424 seq_puts(m, "\n\n");
3425
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003426 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303427 struct intel_panel *panel;
3428
3429 mutex_lock(&drrs->mutex);
3430 /* DRRS Supported */
3431 seq_puts(m, "\tDRRS Supported: Yes\n");
3432
3433 /* disable_drrs() will make drrs->dp NULL */
3434 if (!drrs->dp) {
3435 seq_puts(m, "Idleness DRRS: Disabled");
3436 mutex_unlock(&drrs->mutex);
3437 return;
3438 }
3439
3440 panel = &drrs->dp->attached_connector->panel;
3441 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3442 drrs->busy_frontbuffer_bits);
3443
3444 seq_puts(m, "\n\t\t");
3445 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3446 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3447 vrefresh = panel->fixed_mode->vrefresh;
3448 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3449 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3450 vrefresh = panel->downclock_mode->vrefresh;
3451 } else {
3452 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3453 drrs->refresh_rate_type);
3454 mutex_unlock(&drrs->mutex);
3455 return;
3456 }
3457 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3458
3459 seq_puts(m, "\n\t\t");
3460 mutex_unlock(&drrs->mutex);
3461 } else {
3462 /* DRRS not supported. Print the VBT parameter*/
3463 seq_puts(m, "\tDRRS Supported : No");
3464 }
3465 seq_puts(m, "\n");
3466}
3467
3468static int i915_drrs_status(struct seq_file *m, void *unused)
3469{
3470 struct drm_info_node *node = m->private;
3471 struct drm_device *dev = node->minor->dev;
3472 struct intel_crtc *intel_crtc;
3473 int active_crtc_cnt = 0;
3474
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003475 drm_modeset_lock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303476 for_each_intel_crtc(dev, intel_crtc) {
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003477 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303478 active_crtc_cnt++;
3479 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3480
3481 drrs_status_per_crtc(m, dev, intel_crtc);
3482 }
Vandana Kannana54746e2015-03-03 20:53:10 +05303483 }
Maarten Lankhorst26875fe2016-06-20 15:57:36 +02003484 drm_modeset_unlock_all(dev);
Vandana Kannana54746e2015-03-03 20:53:10 +05303485
3486 if (!active_crtc_cnt)
3487 seq_puts(m, "No active crtc found\n");
3488
3489 return 0;
3490}
3491
Damien Lespiau07144422013-10-15 18:55:40 +01003492struct pipe_crc_info {
3493 const char *name;
3494 struct drm_device *dev;
3495 enum pipe pipe;
3496};
3497
Dave Airlie11bed952014-05-12 15:22:27 +10003498static int i915_dp_mst_info(struct seq_file *m, void *unused)
3499{
3500 struct drm_info_node *node = (struct drm_info_node *) m->private;
3501 struct drm_device *dev = node->minor->dev;
Dave Airlie11bed952014-05-12 15:22:27 +10003502 struct intel_encoder *intel_encoder;
3503 struct intel_digital_port *intel_dig_port;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003504 struct drm_connector *connector;
3505
Dave Airlie11bed952014-05-12 15:22:27 +10003506 drm_modeset_lock_all(dev);
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003507 drm_for_each_connector(connector, dev) {
3508 if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
Dave Airlie11bed952014-05-12 15:22:27 +10003509 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003510
3511 intel_encoder = intel_attached_encoder(connector);
3512 if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
3513 continue;
3514
3515 intel_dig_port = enc_to_dig_port(&intel_encoder->base);
Dave Airlie11bed952014-05-12 15:22:27 +10003516 if (!intel_dig_port->dp.can_mst)
3517 continue;
Maarten Lankhorstb6dabe32016-06-20 15:57:37 +02003518
Jim Bride40ae80c2016-04-14 10:18:37 -07003519 seq_printf(m, "MST Source Port %c\n",
3520 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003521 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3522 }
3523 drm_modeset_unlock_all(dev);
3524 return 0;
3525}
3526
Damien Lespiau07144422013-10-15 18:55:40 +01003527static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003528{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003529 struct pipe_crc_info *info = inode->i_private;
3530 struct drm_i915_private *dev_priv = info->dev->dev_private;
3531 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3532
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003533 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3534 return -ENODEV;
3535
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003536 spin_lock_irq(&pipe_crc->lock);
3537
3538 if (pipe_crc->opened) {
3539 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003540 return -EBUSY; /* already open */
3541 }
3542
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003543 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003544 filep->private_data = inode->i_private;
3545
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003546 spin_unlock_irq(&pipe_crc->lock);
3547
Damien Lespiau07144422013-10-15 18:55:40 +01003548 return 0;
3549}
3550
3551static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3552{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003553 struct pipe_crc_info *info = inode->i_private;
3554 struct drm_i915_private *dev_priv = info->dev->dev_private;
3555 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3556
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003557 spin_lock_irq(&pipe_crc->lock);
3558 pipe_crc->opened = false;
3559 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003560
Damien Lespiau07144422013-10-15 18:55:40 +01003561 return 0;
3562}
3563
3564/* (6 fields, 8 chars each, space separated (5) + '\n') */
3565#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3566/* account for \'0' */
3567#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3568
3569static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3570{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003571 assert_spin_locked(&pipe_crc->lock);
3572 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3573 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003574}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003575
Damien Lespiau07144422013-10-15 18:55:40 +01003576static ssize_t
3577i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3578 loff_t *pos)
3579{
3580 struct pipe_crc_info *info = filep->private_data;
3581 struct drm_device *dev = info->dev;
3582 struct drm_i915_private *dev_priv = dev->dev_private;
3583 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3584 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003585 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003586 ssize_t bytes_read;
3587
3588 /*
3589 * Don't allow user space to provide buffers not big enough to hold
3590 * a line of data.
3591 */
3592 if (count < PIPE_CRC_LINE_LEN)
3593 return -EINVAL;
3594
3595 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3596 return 0;
3597
3598 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003599 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003600 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003601 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003602
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003603 if (filep->f_flags & O_NONBLOCK) {
3604 spin_unlock_irq(&pipe_crc->lock);
3605 return -EAGAIN;
3606 }
3607
3608 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3609 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3610 if (ret) {
3611 spin_unlock_irq(&pipe_crc->lock);
3612 return ret;
3613 }
Damien Lespiau07144422013-10-15 18:55:40 +01003614 }
3615
3616 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003617 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003618
Damien Lespiau07144422013-10-15 18:55:40 +01003619 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003620 while (n_entries > 0) {
3621 struct intel_pipe_crc_entry *entry =
3622 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003623 int ret;
3624
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003625 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3626 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3627 break;
3628
3629 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3630 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3631
Damien Lespiau07144422013-10-15 18:55:40 +01003632 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3633 "%8u %8x %8x %8x %8x %8x\n",
3634 entry->frame, entry->crc[0],
3635 entry->crc[1], entry->crc[2],
3636 entry->crc[3], entry->crc[4]);
3637
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003638 spin_unlock_irq(&pipe_crc->lock);
3639
3640 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003641 if (ret == PIPE_CRC_LINE_LEN)
3642 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003643
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003644 user_buf += PIPE_CRC_LINE_LEN;
3645 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003646
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003647 spin_lock_irq(&pipe_crc->lock);
3648 }
3649
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003650 spin_unlock_irq(&pipe_crc->lock);
3651
Damien Lespiau07144422013-10-15 18:55:40 +01003652 return bytes_read;
3653}
3654
3655static const struct file_operations i915_pipe_crc_fops = {
3656 .owner = THIS_MODULE,
3657 .open = i915_pipe_crc_open,
3658 .read = i915_pipe_crc_read,
3659 .release = i915_pipe_crc_release,
3660};
3661
3662static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3663 {
3664 .name = "i915_pipe_A_crc",
3665 .pipe = PIPE_A,
3666 },
3667 {
3668 .name = "i915_pipe_B_crc",
3669 .pipe = PIPE_B,
3670 },
3671 {
3672 .name = "i915_pipe_C_crc",
3673 .pipe = PIPE_C,
3674 },
3675};
3676
3677static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3678 enum pipe pipe)
3679{
3680 struct drm_device *dev = minor->dev;
3681 struct dentry *ent;
3682 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3683
3684 info->dev = dev;
3685 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3686 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003687 if (!ent)
3688 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003689
3690 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003691}
3692
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003693static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003694 "none",
3695 "plane1",
3696 "plane2",
3697 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003698 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003699 "TV",
3700 "DP-B",
3701 "DP-C",
3702 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003703 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003704};
3705
3706static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3707{
3708 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3709 return pipe_crc_sources[source];
3710}
3711
Damien Lespiaubd9db022013-10-15 18:55:36 +01003712static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003713{
3714 struct drm_device *dev = m->private;
3715 struct drm_i915_private *dev_priv = dev->dev_private;
3716 int i;
3717
3718 for (i = 0; i < I915_MAX_PIPES; i++)
3719 seq_printf(m, "%c %s\n", pipe_name(i),
3720 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3721
3722 return 0;
3723}
3724
Damien Lespiaubd9db022013-10-15 18:55:36 +01003725static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003726{
3727 struct drm_device *dev = inode->i_private;
3728
Damien Lespiaubd9db022013-10-15 18:55:36 +01003729 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003730}
3731
Daniel Vetter46a19182013-11-01 10:50:20 +01003732static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003733 uint32_t *val)
3734{
Daniel Vetter46a19182013-11-01 10:50:20 +01003735 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3736 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3737
3738 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003739 case INTEL_PIPE_CRC_SOURCE_PIPE:
3740 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3741 break;
3742 case INTEL_PIPE_CRC_SOURCE_NONE:
3743 *val = 0;
3744 break;
3745 default:
3746 return -EINVAL;
3747 }
3748
3749 return 0;
3750}
3751
Daniel Vetter46a19182013-11-01 10:50:20 +01003752static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3753 enum intel_pipe_crc_source *source)
3754{
3755 struct intel_encoder *encoder;
3756 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003757 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003758 int ret = 0;
3759
3760 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3761
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003762 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003763 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003764 if (!encoder->base.crtc)
3765 continue;
3766
3767 crtc = to_intel_crtc(encoder->base.crtc);
3768
3769 if (crtc->pipe != pipe)
3770 continue;
3771
3772 switch (encoder->type) {
3773 case INTEL_OUTPUT_TVOUT:
3774 *source = INTEL_PIPE_CRC_SOURCE_TV;
3775 break;
3776 case INTEL_OUTPUT_DISPLAYPORT:
3777 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003778 dig_port = enc_to_dig_port(&encoder->base);
3779 switch (dig_port->port) {
3780 case PORT_B:
3781 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3782 break;
3783 case PORT_C:
3784 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3785 break;
3786 case PORT_D:
3787 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3788 break;
3789 default:
3790 WARN(1, "nonexisting DP port %c\n",
3791 port_name(dig_port->port));
3792 break;
3793 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003794 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003795 default:
3796 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003797 }
3798 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003799 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003800
3801 return ret;
3802}
3803
3804static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3805 enum pipe pipe,
3806 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003807 uint32_t *val)
3808{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003809 struct drm_i915_private *dev_priv = dev->dev_private;
3810 bool need_stable_symbols = false;
3811
Daniel Vetter46a19182013-11-01 10:50:20 +01003812 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3813 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3814 if (ret)
3815 return ret;
3816 }
3817
3818 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003819 case INTEL_PIPE_CRC_SOURCE_PIPE:
3820 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3821 break;
3822 case INTEL_PIPE_CRC_SOURCE_DP_B:
3823 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003824 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003825 break;
3826 case INTEL_PIPE_CRC_SOURCE_DP_C:
3827 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003828 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003829 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003830 case INTEL_PIPE_CRC_SOURCE_DP_D:
3831 if (!IS_CHERRYVIEW(dev))
3832 return -EINVAL;
3833 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3834 need_stable_symbols = true;
3835 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003836 case INTEL_PIPE_CRC_SOURCE_NONE:
3837 *val = 0;
3838 break;
3839 default:
3840 return -EINVAL;
3841 }
3842
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003843 /*
3844 * When the pipe CRC tap point is after the transcoders we need
3845 * to tweak symbol-level features to produce a deterministic series of
3846 * symbols for a given frame. We need to reset those features only once
3847 * a frame (instead of every nth symbol):
3848 * - DC-balance: used to ensure a better clock recovery from the data
3849 * link (SDVO)
3850 * - DisplayPort scrambling: used for EMI reduction
3851 */
3852 if (need_stable_symbols) {
3853 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3854
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003855 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003856 switch (pipe) {
3857 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003858 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003859 break;
3860 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003861 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003862 break;
3863 case PIPE_C:
3864 tmp |= PIPE_C_SCRAMBLE_RESET;
3865 break;
3866 default:
3867 return -EINVAL;
3868 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003869 I915_WRITE(PORT_DFT2_G4X, tmp);
3870 }
3871
Daniel Vetter7ac01292013-10-18 16:37:06 +02003872 return 0;
3873}
3874
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003875static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003876 enum pipe pipe,
3877 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003878 uint32_t *val)
3879{
Daniel Vetter84093602013-11-01 10:50:21 +01003880 struct drm_i915_private *dev_priv = dev->dev_private;
3881 bool need_stable_symbols = false;
3882
Daniel Vetter46a19182013-11-01 10:50:20 +01003883 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3884 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3885 if (ret)
3886 return ret;
3887 }
3888
3889 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003890 case INTEL_PIPE_CRC_SOURCE_PIPE:
3891 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3892 break;
3893 case INTEL_PIPE_CRC_SOURCE_TV:
3894 if (!SUPPORTS_TV(dev))
3895 return -EINVAL;
3896 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3897 break;
3898 case INTEL_PIPE_CRC_SOURCE_DP_B:
3899 if (!IS_G4X(dev))
3900 return -EINVAL;
3901 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003902 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003903 break;
3904 case INTEL_PIPE_CRC_SOURCE_DP_C:
3905 if (!IS_G4X(dev))
3906 return -EINVAL;
3907 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003908 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003909 break;
3910 case INTEL_PIPE_CRC_SOURCE_DP_D:
3911 if (!IS_G4X(dev))
3912 return -EINVAL;
3913 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003914 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003915 break;
3916 case INTEL_PIPE_CRC_SOURCE_NONE:
3917 *val = 0;
3918 break;
3919 default:
3920 return -EINVAL;
3921 }
3922
Daniel Vetter84093602013-11-01 10:50:21 +01003923 /*
3924 * When the pipe CRC tap point is after the transcoders we need
3925 * to tweak symbol-level features to produce a deterministic series of
3926 * symbols for a given frame. We need to reset those features only once
3927 * a frame (instead of every nth symbol):
3928 * - DC-balance: used to ensure a better clock recovery from the data
3929 * link (SDVO)
3930 * - DisplayPort scrambling: used for EMI reduction
3931 */
3932 if (need_stable_symbols) {
3933 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3934
3935 WARN_ON(!IS_G4X(dev));
3936
3937 I915_WRITE(PORT_DFT_I9XX,
3938 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3939
3940 if (pipe == PIPE_A)
3941 tmp |= PIPE_A_SCRAMBLE_RESET;
3942 else
3943 tmp |= PIPE_B_SCRAMBLE_RESET;
3944
3945 I915_WRITE(PORT_DFT2_G4X, tmp);
3946 }
3947
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003948 return 0;
3949}
3950
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003951static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3952 enum pipe pipe)
3953{
3954 struct drm_i915_private *dev_priv = dev->dev_private;
3955 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3956
Ville Syrjäläeb736672014-12-09 21:28:28 +02003957 switch (pipe) {
3958 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003959 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003960 break;
3961 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003962 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003963 break;
3964 case PIPE_C:
3965 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3966 break;
3967 default:
3968 return;
3969 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003970 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3971 tmp &= ~DC_BALANCE_RESET_VLV;
3972 I915_WRITE(PORT_DFT2_G4X, tmp);
3973
3974}
3975
Daniel Vetter84093602013-11-01 10:50:21 +01003976static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3977 enum pipe pipe)
3978{
3979 struct drm_i915_private *dev_priv = dev->dev_private;
3980 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3981
3982 if (pipe == PIPE_A)
3983 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3984 else
3985 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3986 I915_WRITE(PORT_DFT2_G4X, tmp);
3987
3988 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3989 I915_WRITE(PORT_DFT_I9XX,
3990 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3991 }
3992}
3993
Daniel Vetter46a19182013-11-01 10:50:20 +01003994static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003995 uint32_t *val)
3996{
Daniel Vetter46a19182013-11-01 10:50:20 +01003997 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3998 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3999
4000 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004001 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4002 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
4003 break;
4004 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4005 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
4006 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004007 case INTEL_PIPE_CRC_SOURCE_PIPE:
4008 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
4009 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004010 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004011 *val = 0;
4012 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004013 default:
4014 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004015 }
4016
4017 return 0;
4018}
4019
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004020static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004021{
4022 struct drm_i915_private *dev_priv = dev->dev_private;
4023 struct intel_crtc *crtc =
4024 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004025 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004026 struct drm_atomic_state *state;
4027 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004028
4029 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004030 state = drm_atomic_state_alloc(dev);
4031 if (!state) {
4032 ret = -ENOMEM;
4033 goto out;
4034 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004035
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004036 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4037 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4038 if (IS_ERR(pipe_config)) {
4039 ret = PTR_ERR(pipe_config);
4040 goto out;
4041 }
4042
4043 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004044 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004045 pipe_config->pch_pfit.enabled != enable)
4046 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004047
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004048 ret = drm_atomic_commit(state);
4049out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004050 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004051 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
4052 if (ret)
4053 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004054}
4055
4056static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
4057 enum pipe pipe,
4058 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004059 uint32_t *val)
4060{
Daniel Vetter46a19182013-11-01 10:50:20 +01004061 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4062 *source = INTEL_PIPE_CRC_SOURCE_PF;
4063
4064 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004065 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4066 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4067 break;
4068 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4069 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4070 break;
4071 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004072 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004073 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004074
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004075 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4076 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004077 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004078 *val = 0;
4079 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004080 default:
4081 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004082 }
4083
4084 return 0;
4085}
4086
Daniel Vetter926321d2013-10-16 13:30:34 +02004087static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
4088 enum intel_pipe_crc_source source)
4089{
4090 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004091 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004092 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
4093 pipe));
Imre Deake1296492016-02-12 18:55:17 +02004094 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004095 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004096 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004097
Damien Lespiaucc3da172013-10-15 18:55:31 +01004098 if (pipe_crc->source == source)
4099 return 0;
4100
Damien Lespiauae676fc2013-10-15 18:55:32 +01004101 /* forbid changing the source without going back to 'none' */
4102 if (pipe_crc->source && source)
4103 return -EINVAL;
4104
Imre Deake1296492016-02-12 18:55:17 +02004105 power_domain = POWER_DOMAIN_PIPE(pipe);
4106 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004107 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4108 return -EIO;
4109 }
4110
Daniel Vetter52f843f2013-10-21 17:26:38 +02004111 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004112 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02004113 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01004114 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Wayne Boyer666a4532015-12-09 12:29:35 -08004115 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004116 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004117 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004118 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004119 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004120 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004121
4122 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004123 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004124
Damien Lespiau4b584362013-10-15 18:55:33 +01004125 /* none -> real source transition */
4126 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004127 struct intel_pipe_crc_entry *entries;
4128
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004129 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4130 pipe_name(pipe), pipe_crc_source_name(source));
4131
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004132 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4133 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004134 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004135 if (!entries) {
4136 ret = -ENOMEM;
4137 goto out;
4138 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004139
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004140 /*
4141 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4142 * enabled and disabled dynamically based on package C states,
4143 * user space can't make reliable use of the CRCs, so let's just
4144 * completely disable it.
4145 */
4146 hsw_disable_ips(crtc);
4147
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004148 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004149 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004150 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004151 pipe_crc->head = 0;
4152 pipe_crc->tail = 0;
4153 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004154 }
4155
Damien Lespiaucc3da172013-10-15 18:55:31 +01004156 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004157
Daniel Vetter926321d2013-10-16 13:30:34 +02004158 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4159 POSTING_READ(PIPE_CRC_CTL(pipe));
4160
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004161 /* real source -> none transition */
4162 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004163 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004164 struct intel_crtc *crtc =
4165 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004166
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004167 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4168 pipe_name(pipe));
4169
Daniel Vettera33d7102014-06-06 08:22:08 +02004170 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004171 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004172 intel_wait_for_vblank(dev, pipe);
4173 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004174
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004175 spin_lock_irq(&pipe_crc->lock);
4176 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004177 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004178 pipe_crc->head = 0;
4179 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004180 spin_unlock_irq(&pipe_crc->lock);
4181
4182 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004183
4184 if (IS_G4X(dev))
4185 g4x_undo_pipe_scramble_reset(dev, pipe);
Wayne Boyer666a4532015-12-09 12:29:35 -08004186 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004187 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004188 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004189 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004190
4191 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004192 }
4193
Imre Deake1296492016-02-12 18:55:17 +02004194 ret = 0;
4195
4196out:
4197 intel_display_power_put(dev_priv, power_domain);
4198
4199 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004200}
4201
4202/*
4203 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004204 * command: wsp* object wsp+ name wsp+ source wsp*
4205 * object: 'pipe'
4206 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004207 * source: (none | plane1 | plane2 | pf)
4208 * wsp: (#0x20 | #0x9 | #0xA)+
4209 *
4210 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004211 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4212 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004213 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004214static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004215{
4216 int n_words = 0;
4217
4218 while (*buf) {
4219 char *end;
4220
4221 /* skip leading white space */
4222 buf = skip_spaces(buf);
4223 if (!*buf)
4224 break; /* end of buffer */
4225
4226 /* find end of word */
4227 for (end = buf; *end && !isspace(*end); end++)
4228 ;
4229
4230 if (n_words == max_words) {
4231 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4232 max_words);
4233 return -EINVAL; /* ran out of words[] before bytes */
4234 }
4235
4236 if (*end)
4237 *end++ = '\0';
4238 words[n_words++] = buf;
4239 buf = end;
4240 }
4241
4242 return n_words;
4243}
4244
Damien Lespiaub94dec82013-10-15 18:55:35 +01004245enum intel_pipe_crc_object {
4246 PIPE_CRC_OBJECT_PIPE,
4247};
4248
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004249static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004250 "pipe",
4251};
4252
4253static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004254display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004255{
4256 int i;
4257
4258 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4259 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004260 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004261 return 0;
4262 }
4263
4264 return -EINVAL;
4265}
4266
Damien Lespiaubd9db022013-10-15 18:55:36 +01004267static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004268{
4269 const char name = buf[0];
4270
4271 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4272 return -EINVAL;
4273
4274 *pipe = name - 'A';
4275
4276 return 0;
4277}
4278
4279static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004280display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004281{
4282 int i;
4283
4284 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4285 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004286 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004287 return 0;
4288 }
4289
4290 return -EINVAL;
4291}
4292
Damien Lespiaubd9db022013-10-15 18:55:36 +01004293static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004294{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004295#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004296 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004297 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004298 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004299 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004300 enum intel_pipe_crc_source source;
4301
Damien Lespiaubd9db022013-10-15 18:55:36 +01004302 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004303 if (n_words != N_WORDS) {
4304 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4305 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004306 return -EINVAL;
4307 }
4308
Damien Lespiaubd9db022013-10-15 18:55:36 +01004309 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004310 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004311 return -EINVAL;
4312 }
4313
Damien Lespiaubd9db022013-10-15 18:55:36 +01004314 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004315 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4316 return -EINVAL;
4317 }
4318
Damien Lespiaubd9db022013-10-15 18:55:36 +01004319 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004320 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004321 return -EINVAL;
4322 }
4323
4324 return pipe_crc_set_source(dev, pipe, source);
4325}
4326
Damien Lespiaubd9db022013-10-15 18:55:36 +01004327static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4328 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004329{
4330 struct seq_file *m = file->private_data;
4331 struct drm_device *dev = m->private;
4332 char *tmpbuf;
4333 int ret;
4334
4335 if (len == 0)
4336 return 0;
4337
4338 if (len > PAGE_SIZE - 1) {
4339 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4340 PAGE_SIZE);
4341 return -E2BIG;
4342 }
4343
4344 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4345 if (!tmpbuf)
4346 return -ENOMEM;
4347
4348 if (copy_from_user(tmpbuf, ubuf, len)) {
4349 ret = -EFAULT;
4350 goto out;
4351 }
4352 tmpbuf[len] = '\0';
4353
Damien Lespiaubd9db022013-10-15 18:55:36 +01004354 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004355
4356out:
4357 kfree(tmpbuf);
4358 if (ret < 0)
4359 return ret;
4360
4361 *offp += len;
4362 return len;
4363}
4364
Damien Lespiaubd9db022013-10-15 18:55:36 +01004365static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004366 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004367 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004368 .read = seq_read,
4369 .llseek = seq_lseek,
4370 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004371 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004372};
4373
Todd Previteeb3394fa2015-04-18 00:04:19 -07004374static ssize_t i915_displayport_test_active_write(struct file *file,
4375 const char __user *ubuf,
4376 size_t len, loff_t *offp)
4377{
4378 char *input_buffer;
4379 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004380 struct drm_device *dev;
4381 struct drm_connector *connector;
4382 struct list_head *connector_list;
4383 struct intel_dp *intel_dp;
4384 int val = 0;
4385
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304386 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004387
Todd Previteeb3394fa2015-04-18 00:04:19 -07004388 connector_list = &dev->mode_config.connector_list;
4389
4390 if (len == 0)
4391 return 0;
4392
4393 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4394 if (!input_buffer)
4395 return -ENOMEM;
4396
4397 if (copy_from_user(input_buffer, ubuf, len)) {
4398 status = -EFAULT;
4399 goto out;
4400 }
4401
4402 input_buffer[len] = '\0';
4403 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4404
4405 list_for_each_entry(connector, connector_list, head) {
4406
4407 if (connector->connector_type !=
4408 DRM_MODE_CONNECTOR_DisplayPort)
4409 continue;
4410
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304411 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004412 connector->encoder != NULL) {
4413 intel_dp = enc_to_intel_dp(connector->encoder);
4414 status = kstrtoint(input_buffer, 10, &val);
4415 if (status < 0)
4416 goto out;
4417 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4418 /* To prevent erroneous activation of the compliance
4419 * testing code, only accept an actual value of 1 here
4420 */
4421 if (val == 1)
4422 intel_dp->compliance_test_active = 1;
4423 else
4424 intel_dp->compliance_test_active = 0;
4425 }
4426 }
4427out:
4428 kfree(input_buffer);
4429 if (status < 0)
4430 return status;
4431
4432 *offp += len;
4433 return len;
4434}
4435
4436static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4437{
4438 struct drm_device *dev = m->private;
4439 struct drm_connector *connector;
4440 struct list_head *connector_list = &dev->mode_config.connector_list;
4441 struct intel_dp *intel_dp;
4442
Todd Previteeb3394fa2015-04-18 00:04:19 -07004443 list_for_each_entry(connector, connector_list, head) {
4444
4445 if (connector->connector_type !=
4446 DRM_MODE_CONNECTOR_DisplayPort)
4447 continue;
4448
4449 if (connector->status == connector_status_connected &&
4450 connector->encoder != NULL) {
4451 intel_dp = enc_to_intel_dp(connector->encoder);
4452 if (intel_dp->compliance_test_active)
4453 seq_puts(m, "1");
4454 else
4455 seq_puts(m, "0");
4456 } else
4457 seq_puts(m, "0");
4458 }
4459
4460 return 0;
4461}
4462
4463static int i915_displayport_test_active_open(struct inode *inode,
4464 struct file *file)
4465{
4466 struct drm_device *dev = inode->i_private;
4467
4468 return single_open(file, i915_displayport_test_active_show, dev);
4469}
4470
4471static const struct file_operations i915_displayport_test_active_fops = {
4472 .owner = THIS_MODULE,
4473 .open = i915_displayport_test_active_open,
4474 .read = seq_read,
4475 .llseek = seq_lseek,
4476 .release = single_release,
4477 .write = i915_displayport_test_active_write
4478};
4479
4480static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4481{
4482 struct drm_device *dev = m->private;
4483 struct drm_connector *connector;
4484 struct list_head *connector_list = &dev->mode_config.connector_list;
4485 struct intel_dp *intel_dp;
4486
Todd Previteeb3394fa2015-04-18 00:04:19 -07004487 list_for_each_entry(connector, connector_list, head) {
4488
4489 if (connector->connector_type !=
4490 DRM_MODE_CONNECTOR_DisplayPort)
4491 continue;
4492
4493 if (connector->status == connector_status_connected &&
4494 connector->encoder != NULL) {
4495 intel_dp = enc_to_intel_dp(connector->encoder);
4496 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4497 } else
4498 seq_puts(m, "0");
4499 }
4500
4501 return 0;
4502}
4503static int i915_displayport_test_data_open(struct inode *inode,
4504 struct file *file)
4505{
4506 struct drm_device *dev = inode->i_private;
4507
4508 return single_open(file, i915_displayport_test_data_show, dev);
4509}
4510
4511static const struct file_operations i915_displayport_test_data_fops = {
4512 .owner = THIS_MODULE,
4513 .open = i915_displayport_test_data_open,
4514 .read = seq_read,
4515 .llseek = seq_lseek,
4516 .release = single_release
4517};
4518
4519static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4520{
4521 struct drm_device *dev = m->private;
4522 struct drm_connector *connector;
4523 struct list_head *connector_list = &dev->mode_config.connector_list;
4524 struct intel_dp *intel_dp;
4525
Todd Previteeb3394fa2015-04-18 00:04:19 -07004526 list_for_each_entry(connector, connector_list, head) {
4527
4528 if (connector->connector_type !=
4529 DRM_MODE_CONNECTOR_DisplayPort)
4530 continue;
4531
4532 if (connector->status == connector_status_connected &&
4533 connector->encoder != NULL) {
4534 intel_dp = enc_to_intel_dp(connector->encoder);
4535 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4536 } else
4537 seq_puts(m, "0");
4538 }
4539
4540 return 0;
4541}
4542
4543static int i915_displayport_test_type_open(struct inode *inode,
4544 struct file *file)
4545{
4546 struct drm_device *dev = inode->i_private;
4547
4548 return single_open(file, i915_displayport_test_type_show, dev);
4549}
4550
4551static const struct file_operations i915_displayport_test_type_fops = {
4552 .owner = THIS_MODULE,
4553 .open = i915_displayport_test_type_open,
4554 .read = seq_read,
4555 .llseek = seq_lseek,
4556 .release = single_release
4557};
4558
Damien Lespiau97e94b22014-11-04 17:06:50 +00004559static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004560{
4561 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004562 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004563 int num_levels;
4564
4565 if (IS_CHERRYVIEW(dev))
4566 num_levels = 3;
4567 else if (IS_VALLEYVIEW(dev))
4568 num_levels = 1;
4569 else
4570 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004571
4572 drm_modeset_lock_all(dev);
4573
4574 for (level = 0; level < num_levels; level++) {
4575 unsigned int latency = wm[level];
4576
Damien Lespiau97e94b22014-11-04 17:06:50 +00004577 /*
4578 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004579 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004580 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004581 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev) ||
4582 IS_CHERRYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004583 latency *= 10;
4584 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004585 latency *= 5;
4586
4587 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004588 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004589 }
4590
4591 drm_modeset_unlock_all(dev);
4592}
4593
4594static int pri_wm_latency_show(struct seq_file *m, void *data)
4595{
4596 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004597 struct drm_i915_private *dev_priv = dev->dev_private;
4598 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004599
Damien Lespiau97e94b22014-11-04 17:06:50 +00004600 if (INTEL_INFO(dev)->gen >= 9)
4601 latencies = dev_priv->wm.skl_latency;
4602 else
4603 latencies = to_i915(dev)->wm.pri_latency;
4604
4605 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004606
4607 return 0;
4608}
4609
4610static int spr_wm_latency_show(struct seq_file *m, void *data)
4611{
4612 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004613 struct drm_i915_private *dev_priv = dev->dev_private;
4614 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004615
Damien Lespiau97e94b22014-11-04 17:06:50 +00004616 if (INTEL_INFO(dev)->gen >= 9)
4617 latencies = dev_priv->wm.skl_latency;
4618 else
4619 latencies = to_i915(dev)->wm.spr_latency;
4620
4621 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004622
4623 return 0;
4624}
4625
4626static int cur_wm_latency_show(struct seq_file *m, void *data)
4627{
4628 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004629 struct drm_i915_private *dev_priv = dev->dev_private;
4630 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004631
Damien Lespiau97e94b22014-11-04 17:06:50 +00004632 if (INTEL_INFO(dev)->gen >= 9)
4633 latencies = dev_priv->wm.skl_latency;
4634 else
4635 latencies = to_i915(dev)->wm.cur_latency;
4636
4637 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004638
4639 return 0;
4640}
4641
4642static int pri_wm_latency_open(struct inode *inode, struct file *file)
4643{
4644 struct drm_device *dev = inode->i_private;
4645
Ville Syrjäläde38b952015-06-24 22:00:09 +03004646 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004647 return -ENODEV;
4648
4649 return single_open(file, pri_wm_latency_show, dev);
4650}
4651
4652static int spr_wm_latency_open(struct inode *inode, struct file *file)
4653{
4654 struct drm_device *dev = inode->i_private;
4655
Sonika Jindal9ad02572014-07-21 15:23:39 +05304656 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004657 return -ENODEV;
4658
4659 return single_open(file, spr_wm_latency_show, dev);
4660}
4661
4662static int cur_wm_latency_open(struct inode *inode, struct file *file)
4663{
4664 struct drm_device *dev = inode->i_private;
4665
Sonika Jindal9ad02572014-07-21 15:23:39 +05304666 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004667 return -ENODEV;
4668
4669 return single_open(file, cur_wm_latency_show, dev);
4670}
4671
4672static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004673 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004674{
4675 struct seq_file *m = file->private_data;
4676 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004677 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004678 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004679 int level;
4680 int ret;
4681 char tmp[32];
4682
Ville Syrjäläde38b952015-06-24 22:00:09 +03004683 if (IS_CHERRYVIEW(dev))
4684 num_levels = 3;
4685 else if (IS_VALLEYVIEW(dev))
4686 num_levels = 1;
4687 else
4688 num_levels = ilk_wm_max_level(dev) + 1;
4689
Ville Syrjälä369a1342014-01-22 14:36:08 +02004690 if (len >= sizeof(tmp))
4691 return -EINVAL;
4692
4693 if (copy_from_user(tmp, ubuf, len))
4694 return -EFAULT;
4695
4696 tmp[len] = '\0';
4697
Damien Lespiau97e94b22014-11-04 17:06:50 +00004698 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4699 &new[0], &new[1], &new[2], &new[3],
4700 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004701 if (ret != num_levels)
4702 return -EINVAL;
4703
4704 drm_modeset_lock_all(dev);
4705
4706 for (level = 0; level < num_levels; level++)
4707 wm[level] = new[level];
4708
4709 drm_modeset_unlock_all(dev);
4710
4711 return len;
4712}
4713
4714
4715static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4716 size_t len, loff_t *offp)
4717{
4718 struct seq_file *m = file->private_data;
4719 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004720 struct drm_i915_private *dev_priv = dev->dev_private;
4721 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004722
Damien Lespiau97e94b22014-11-04 17:06:50 +00004723 if (INTEL_INFO(dev)->gen >= 9)
4724 latencies = dev_priv->wm.skl_latency;
4725 else
4726 latencies = to_i915(dev)->wm.pri_latency;
4727
4728 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004729}
4730
4731static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4732 size_t len, loff_t *offp)
4733{
4734 struct seq_file *m = file->private_data;
4735 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004736 struct drm_i915_private *dev_priv = dev->dev_private;
4737 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004738
Damien Lespiau97e94b22014-11-04 17:06:50 +00004739 if (INTEL_INFO(dev)->gen >= 9)
4740 latencies = dev_priv->wm.skl_latency;
4741 else
4742 latencies = to_i915(dev)->wm.spr_latency;
4743
4744 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004745}
4746
4747static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4748 size_t len, loff_t *offp)
4749{
4750 struct seq_file *m = file->private_data;
4751 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004752 struct drm_i915_private *dev_priv = dev->dev_private;
4753 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004754
Damien Lespiau97e94b22014-11-04 17:06:50 +00004755 if (INTEL_INFO(dev)->gen >= 9)
4756 latencies = dev_priv->wm.skl_latency;
4757 else
4758 latencies = to_i915(dev)->wm.cur_latency;
4759
4760 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004761}
4762
4763static const struct file_operations i915_pri_wm_latency_fops = {
4764 .owner = THIS_MODULE,
4765 .open = pri_wm_latency_open,
4766 .read = seq_read,
4767 .llseek = seq_lseek,
4768 .release = single_release,
4769 .write = pri_wm_latency_write
4770};
4771
4772static const struct file_operations i915_spr_wm_latency_fops = {
4773 .owner = THIS_MODULE,
4774 .open = spr_wm_latency_open,
4775 .read = seq_read,
4776 .llseek = seq_lseek,
4777 .release = single_release,
4778 .write = spr_wm_latency_write
4779};
4780
4781static const struct file_operations i915_cur_wm_latency_fops = {
4782 .owner = THIS_MODULE,
4783 .open = cur_wm_latency_open,
4784 .read = seq_read,
4785 .llseek = seq_lseek,
4786 .release = single_release,
4787 .write = cur_wm_latency_write
4788};
4789
Kees Cook647416f2013-03-10 14:10:06 -07004790static int
4791i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004792{
Kees Cook647416f2013-03-10 14:10:06 -07004793 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004794 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004795
Chris Wilsond98c52c2016-04-13 17:35:05 +01004796 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004797
Kees Cook647416f2013-03-10 14:10:06 -07004798 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004799}
4800
Kees Cook647416f2013-03-10 14:10:06 -07004801static int
4802i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004803{
Kees Cook647416f2013-03-10 14:10:06 -07004804 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004805 struct drm_i915_private *dev_priv = dev->dev_private;
4806
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004807 /*
4808 * There is no safeguard against this debugfs entry colliding
4809 * with the hangcheck calling same i915_handle_error() in
4810 * parallel, causing an explosion. For now we assume that the
4811 * test harness is responsible enough not to inject gpu hangs
4812 * while it is writing to 'i915_wedged'
4813 */
4814
Chris Wilsond98c52c2016-04-13 17:35:05 +01004815 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004816 return -EAGAIN;
4817
Imre Deakd46c0512014-04-14 20:24:27 +03004818 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004819
Chris Wilsonc0336662016-05-06 15:40:21 +01004820 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004821 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004822
4823 intel_runtime_pm_put(dev_priv);
4824
Kees Cook647416f2013-03-10 14:10:06 -07004825 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004826}
4827
Kees Cook647416f2013-03-10 14:10:06 -07004828DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4829 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004830 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004831
Kees Cook647416f2013-03-10 14:10:06 -07004832static int
4833i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004834{
Kees Cook647416f2013-03-10 14:10:06 -07004835 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004836 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004837
Kees Cook647416f2013-03-10 14:10:06 -07004838 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004839
Kees Cook647416f2013-03-10 14:10:06 -07004840 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004841}
4842
Kees Cook647416f2013-03-10 14:10:06 -07004843static int
4844i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004845{
Kees Cook647416f2013-03-10 14:10:06 -07004846 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004847 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004848 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004849
Kees Cook647416f2013-03-10 14:10:06 -07004850 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004851
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004852 ret = mutex_lock_interruptible(&dev->struct_mutex);
4853 if (ret)
4854 return ret;
4855
Daniel Vetter99584db2012-11-14 17:14:04 +01004856 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004857 mutex_unlock(&dev->struct_mutex);
4858
Kees Cook647416f2013-03-10 14:10:06 -07004859 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004860}
4861
Kees Cook647416f2013-03-10 14:10:06 -07004862DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4863 i915_ring_stop_get, i915_ring_stop_set,
4864 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004865
Chris Wilson094f9a52013-09-25 17:34:55 +01004866static int
4867i915_ring_missed_irq_get(void *data, u64 *val)
4868{
4869 struct drm_device *dev = data;
4870 struct drm_i915_private *dev_priv = dev->dev_private;
4871
4872 *val = dev_priv->gpu_error.missed_irq_rings;
4873 return 0;
4874}
4875
4876static int
4877i915_ring_missed_irq_set(void *data, u64 val)
4878{
4879 struct drm_device *dev = data;
4880 struct drm_i915_private *dev_priv = dev->dev_private;
4881 int ret;
4882
4883 /* Lock against concurrent debugfs callers */
4884 ret = mutex_lock_interruptible(&dev->struct_mutex);
4885 if (ret)
4886 return ret;
4887 dev_priv->gpu_error.missed_irq_rings = val;
4888 mutex_unlock(&dev->struct_mutex);
4889
4890 return 0;
4891}
4892
4893DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4894 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4895 "0x%08llx\n");
4896
4897static int
4898i915_ring_test_irq_get(void *data, u64 *val)
4899{
4900 struct drm_device *dev = data;
4901 struct drm_i915_private *dev_priv = dev->dev_private;
4902
4903 *val = dev_priv->gpu_error.test_irq_rings;
4904
4905 return 0;
4906}
4907
4908static int
4909i915_ring_test_irq_set(void *data, u64 val)
4910{
4911 struct drm_device *dev = data;
4912 struct drm_i915_private *dev_priv = dev->dev_private;
4913 int ret;
4914
4915 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4916
4917 /* Lock against concurrent debugfs callers */
4918 ret = mutex_lock_interruptible(&dev->struct_mutex);
4919 if (ret)
4920 return ret;
4921
4922 dev_priv->gpu_error.test_irq_rings = val;
4923 mutex_unlock(&dev->struct_mutex);
4924
4925 return 0;
4926}
4927
4928DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4929 i915_ring_test_irq_get, i915_ring_test_irq_set,
4930 "0x%08llx\n");
4931
Chris Wilsondd624af2013-01-15 12:39:35 +00004932#define DROP_UNBOUND 0x1
4933#define DROP_BOUND 0x2
4934#define DROP_RETIRE 0x4
4935#define DROP_ACTIVE 0x8
4936#define DROP_ALL (DROP_UNBOUND | \
4937 DROP_BOUND | \
4938 DROP_RETIRE | \
4939 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004940static int
4941i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004942{
Kees Cook647416f2013-03-10 14:10:06 -07004943 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004944
Kees Cook647416f2013-03-10 14:10:06 -07004945 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004946}
4947
Kees Cook647416f2013-03-10 14:10:06 -07004948static int
4949i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004950{
Kees Cook647416f2013-03-10 14:10:06 -07004951 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004952 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004953 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004954
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004955 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004956
4957 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4958 * on ioctls on -EAGAIN. */
4959 ret = mutex_lock_interruptible(&dev->struct_mutex);
4960 if (ret)
4961 return ret;
4962
4963 if (val & DROP_ACTIVE) {
Chris Wilson6e5a5be2016-06-24 14:55:57 +01004964 ret = i915_gem_wait_for_idle(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004965 if (ret)
4966 goto unlock;
4967 }
4968
4969 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004970 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004971
Chris Wilson21ab4e72014-09-09 11:16:08 +01004972 if (val & DROP_BOUND)
4973 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004974
Chris Wilson21ab4e72014-09-09 11:16:08 +01004975 if (val & DROP_UNBOUND)
4976 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004977
4978unlock:
4979 mutex_unlock(&dev->struct_mutex);
4980
Kees Cook647416f2013-03-10 14:10:06 -07004981 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004982}
4983
Kees Cook647416f2013-03-10 14:10:06 -07004984DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4985 i915_drop_caches_get, i915_drop_caches_set,
4986 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004987
Kees Cook647416f2013-03-10 14:10:06 -07004988static int
4989i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004990{
Kees Cook647416f2013-03-10 14:10:06 -07004991 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004992 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004993 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004994
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004995 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004996 return -ENODEV;
4997
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004998 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4999
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005000 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005001 if (ret)
5002 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07005003
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005004 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005005 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005006
Kees Cook647416f2013-03-10 14:10:06 -07005007 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005008}
5009
Kees Cook647416f2013-03-10 14:10:06 -07005010static int
5011i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07005012{
Kees Cook647416f2013-03-10 14:10:06 -07005013 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07005014 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305015 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005016 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005017
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005018 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005019 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07005020
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005021 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5022
Kees Cook647416f2013-03-10 14:10:06 -07005023 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07005024
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005025 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005026 if (ret)
5027 return ret;
5028
Jesse Barnes358733e2011-07-27 11:53:01 -07005029 /*
5030 * Turbo will still be enabled, but won't go above the set value.
5031 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305032 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005033
Akash Goelbc4d91f2015-02-26 16:09:47 +05305034 hw_max = dev_priv->rps.max_freq;
5035 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07005036
Ben Widawskyb39fb292014-03-19 18:31:11 -07005037 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005038 mutex_unlock(&dev_priv->rps.hw_lock);
5039 return -EINVAL;
5040 }
5041
Ben Widawskyb39fb292014-03-19 18:31:11 -07005042 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005043
Chris Wilsondc979972016-05-10 14:10:04 +01005044 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005045
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005046 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005047
Kees Cook647416f2013-03-10 14:10:06 -07005048 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005049}
5050
Kees Cook647416f2013-03-10 14:10:06 -07005051DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5052 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005053 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005054
Kees Cook647416f2013-03-10 14:10:06 -07005055static int
5056i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005057{
Kees Cook647416f2013-03-10 14:10:06 -07005058 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03005059 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07005060 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005061
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005062 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005063 return -ENODEV;
5064
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005065 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5066
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005067 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005068 if (ret)
5069 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07005070
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005071 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005072 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005073
Kees Cook647416f2013-03-10 14:10:06 -07005074 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005075}
5076
Kees Cook647416f2013-03-10 14:10:06 -07005077static int
5078i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005079{
Kees Cook647416f2013-03-10 14:10:06 -07005080 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07005081 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305082 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005083 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005084
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005085 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005086 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005087
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005088 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5089
Kees Cook647416f2013-03-10 14:10:06 -07005090 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005091
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005092 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005093 if (ret)
5094 return ret;
5095
Jesse Barnes1523c312012-05-25 12:34:54 -07005096 /*
5097 * Turbo will still be enabled, but won't go below the set value.
5098 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305099 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005100
Akash Goelbc4d91f2015-02-26 16:09:47 +05305101 hw_max = dev_priv->rps.max_freq;
5102 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005103
Ben Widawskyb39fb292014-03-19 18:31:11 -07005104 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005105 mutex_unlock(&dev_priv->rps.hw_lock);
5106 return -EINVAL;
5107 }
5108
Ben Widawskyb39fb292014-03-19 18:31:11 -07005109 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005110
Chris Wilsondc979972016-05-10 14:10:04 +01005111 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005112
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005113 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005114
Kees Cook647416f2013-03-10 14:10:06 -07005115 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005116}
5117
Kees Cook647416f2013-03-10 14:10:06 -07005118DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5119 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005120 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005121
Kees Cook647416f2013-03-10 14:10:06 -07005122static int
5123i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005124{
Kees Cook647416f2013-03-10 14:10:06 -07005125 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03005126 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005127 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005128 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005129
Daniel Vetter004777c2012-08-09 15:07:01 +02005130 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5131 return -ENODEV;
5132
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005133 ret = mutex_lock_interruptible(&dev->struct_mutex);
5134 if (ret)
5135 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005136 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005137
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005138 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005139
5140 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005141 mutex_unlock(&dev_priv->dev->struct_mutex);
5142
Kees Cook647416f2013-03-10 14:10:06 -07005143 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005144
Kees Cook647416f2013-03-10 14:10:06 -07005145 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005146}
5147
Kees Cook647416f2013-03-10 14:10:06 -07005148static int
5149i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005150{
Kees Cook647416f2013-03-10 14:10:06 -07005151 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005152 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005153 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005154
Daniel Vetter004777c2012-08-09 15:07:01 +02005155 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5156 return -ENODEV;
5157
Kees Cook647416f2013-03-10 14:10:06 -07005158 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005159 return -EINVAL;
5160
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005161 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005162 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005163
5164 /* Update the cache sharing policy here as well */
5165 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5166 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5167 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5168 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5169
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005170 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005171 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005172}
5173
Kees Cook647416f2013-03-10 14:10:06 -07005174DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5175 i915_cache_sharing_get, i915_cache_sharing_set,
5176 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005177
Jeff McGee5d395252015-04-03 18:13:17 -07005178struct sseu_dev_status {
5179 unsigned int slice_total;
5180 unsigned int subslice_total;
5181 unsigned int subslice_per_slice;
5182 unsigned int eu_total;
5183 unsigned int eu_per_subslice;
5184};
5185
5186static void cherryview_sseu_device_status(struct drm_device *dev,
5187 struct sseu_dev_status *stat)
5188{
5189 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005190 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005191 int ss;
5192 u32 sig1[ss_max], sig2[ss_max];
5193
5194 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5195 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5196 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5197 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5198
5199 for (ss = 0; ss < ss_max; ss++) {
5200 unsigned int eu_cnt;
5201
5202 if (sig1[ss] & CHV_SS_PG_ENABLE)
5203 /* skip disabled subslice */
5204 continue;
5205
5206 stat->slice_total = 1;
5207 stat->subslice_per_slice++;
5208 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5209 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5210 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5211 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
5212 stat->eu_total += eu_cnt;
5213 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
5214 }
5215 stat->subslice_total = stat->subslice_per_slice;
5216}
5217
5218static void gen9_sseu_device_status(struct drm_device *dev,
5219 struct sseu_dev_status *stat)
5220{
5221 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005222 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005223 int s, ss;
5224 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5225
Jeff McGee1c046bc2015-04-03 18:13:18 -07005226 /* BXT has a single slice and at most 3 subslices. */
5227 if (IS_BROXTON(dev)) {
5228 s_max = 1;
5229 ss_max = 3;
5230 }
5231
5232 for (s = 0; s < s_max; s++) {
5233 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5234 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5235 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5236 }
5237
Jeff McGee5d395252015-04-03 18:13:17 -07005238 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5239 GEN9_PGCTL_SSA_EU19_ACK |
5240 GEN9_PGCTL_SSA_EU210_ACK |
5241 GEN9_PGCTL_SSA_EU311_ACK;
5242 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5243 GEN9_PGCTL_SSB_EU19_ACK |
5244 GEN9_PGCTL_SSB_EU210_ACK |
5245 GEN9_PGCTL_SSB_EU311_ACK;
5246
5247 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005248 unsigned int ss_cnt = 0;
5249
Jeff McGee5d395252015-04-03 18:13:17 -07005250 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5251 /* skip disabled slice */
5252 continue;
5253
5254 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005255
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07005256 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Jeff McGee1c046bc2015-04-03 18:13:18 -07005257 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5258
Jeff McGee5d395252015-04-03 18:13:17 -07005259 for (ss = 0; ss < ss_max; ss++) {
5260 unsigned int eu_cnt;
5261
Jeff McGee1c046bc2015-04-03 18:13:18 -07005262 if (IS_BROXTON(dev) &&
5263 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5264 /* skip disabled subslice */
5265 continue;
5266
5267 if (IS_BROXTON(dev))
5268 ss_cnt++;
5269
Jeff McGee5d395252015-04-03 18:13:17 -07005270 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5271 eu_mask[ss%2]);
5272 stat->eu_total += eu_cnt;
5273 stat->eu_per_subslice = max(stat->eu_per_subslice,
5274 eu_cnt);
5275 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005276
5277 stat->subslice_total += ss_cnt;
5278 stat->subslice_per_slice = max(stat->subslice_per_slice,
5279 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005280 }
5281}
5282
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005283static void broadwell_sseu_device_status(struct drm_device *dev,
5284 struct sseu_dev_status *stat)
5285{
5286 struct drm_i915_private *dev_priv = dev->dev_private;
5287 int s;
5288 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
5289
5290 stat->slice_total = hweight32(slice_info & GEN8_LSLICESTAT_MASK);
5291
5292 if (stat->slice_total) {
5293 stat->subslice_per_slice = INTEL_INFO(dev)->subslice_per_slice;
5294 stat->subslice_total = stat->slice_total *
5295 stat->subslice_per_slice;
5296 stat->eu_per_subslice = INTEL_INFO(dev)->eu_per_subslice;
5297 stat->eu_total = stat->eu_per_subslice * stat->subslice_total;
5298
5299 /* subtract fused off EU(s) from enabled slice(s) */
5300 for (s = 0; s < stat->slice_total; s++) {
5301 u8 subslice_7eu = INTEL_INFO(dev)->subslice_7eu[s];
5302
5303 stat->eu_total -= hweight8(subslice_7eu);
5304 }
5305 }
5306}
5307
Jeff McGee38732182015-02-13 10:27:54 -06005308static int i915_sseu_status(struct seq_file *m, void *unused)
5309{
5310 struct drm_info_node *node = (struct drm_info_node *) m->private;
5311 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07005312 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005313
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005314 if (INTEL_INFO(dev)->gen < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005315 return -ENODEV;
5316
5317 seq_puts(m, "SSEU Device Info\n");
5318 seq_printf(m, " Available Slice Total: %u\n",
5319 INTEL_INFO(dev)->slice_total);
5320 seq_printf(m, " Available Subslice Total: %u\n",
5321 INTEL_INFO(dev)->subslice_total);
5322 seq_printf(m, " Available Subslice Per Slice: %u\n",
5323 INTEL_INFO(dev)->subslice_per_slice);
5324 seq_printf(m, " Available EU Total: %u\n",
5325 INTEL_INFO(dev)->eu_total);
5326 seq_printf(m, " Available EU Per Subslice: %u\n",
5327 INTEL_INFO(dev)->eu_per_subslice);
arun.siluvery@linux.intel.com33e141e2016-06-03 06:34:33 +01005328 seq_printf(m, " Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev)));
5329 if (HAS_POOLED_EU(dev))
5330 seq_printf(m, " Min EU in pool: %u\n",
5331 INTEL_INFO(dev)->min_eu_in_pool);
Jeff McGee38732182015-02-13 10:27:54 -06005332 seq_printf(m, " Has Slice Power Gating: %s\n",
5333 yesno(INTEL_INFO(dev)->has_slice_pg));
5334 seq_printf(m, " Has Subslice Power Gating: %s\n",
5335 yesno(INTEL_INFO(dev)->has_subslice_pg));
5336 seq_printf(m, " Has EU Power Gating: %s\n",
5337 yesno(INTEL_INFO(dev)->has_eu_pg));
5338
Jeff McGee7f992ab2015-02-13 10:27:55 -06005339 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005340 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08005341 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005342 cherryview_sseu_device_status(dev, &stat);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005343 } else if (IS_BROADWELL(dev)) {
5344 broadwell_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005345 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005346 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005347 }
Jeff McGee5d395252015-04-03 18:13:17 -07005348 seq_printf(m, " Enabled Slice Total: %u\n",
5349 stat.slice_total);
5350 seq_printf(m, " Enabled Subslice Total: %u\n",
5351 stat.subslice_total);
5352 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5353 stat.subslice_per_slice);
5354 seq_printf(m, " Enabled EU Total: %u\n",
5355 stat.eu_total);
5356 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5357 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005358
Jeff McGee38732182015-02-13 10:27:54 -06005359 return 0;
5360}
5361
Ben Widawsky6d794d42011-04-25 11:25:56 -07005362static int i915_forcewake_open(struct inode *inode, struct file *file)
5363{
5364 struct drm_device *dev = inode->i_private;
5365 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005366
Daniel Vetter075edca2012-01-24 09:44:28 +01005367 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005368 return 0;
5369
Chris Wilson6daccb02015-01-16 11:34:35 +02005370 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005371 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005372
5373 return 0;
5374}
5375
Ben Widawskyc43b5632012-04-16 14:07:40 -07005376static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005377{
5378 struct drm_device *dev = inode->i_private;
5379 struct drm_i915_private *dev_priv = dev->dev_private;
5380
Daniel Vetter075edca2012-01-24 09:44:28 +01005381 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005382 return 0;
5383
Mika Kuoppala59bad942015-01-16 11:34:40 +02005384 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005385 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005386
5387 return 0;
5388}
5389
5390static const struct file_operations i915_forcewake_fops = {
5391 .owner = THIS_MODULE,
5392 .open = i915_forcewake_open,
5393 .release = i915_forcewake_release,
5394};
5395
5396static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5397{
5398 struct drm_device *dev = minor->dev;
5399 struct dentry *ent;
5400
5401 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005402 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005403 root, dev,
5404 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005405 if (!ent)
5406 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005407
Ben Widawsky8eb57292011-05-11 15:10:58 -07005408 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005409}
5410
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005411static int i915_debugfs_create(struct dentry *root,
5412 struct drm_minor *minor,
5413 const char *name,
5414 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005415{
5416 struct drm_device *dev = minor->dev;
5417 struct dentry *ent;
5418
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005419 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005420 S_IRUGO | S_IWUSR,
5421 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005422 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005423 if (!ent)
5424 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005425
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005426 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005427}
5428
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005429static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005430 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005431 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005432 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005433 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005434 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005435 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005436 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005437 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005438 {"i915_gem_request", i915_gem_request_info, 0},
5439 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005440 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005441 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005442 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5443 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5444 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005445 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005446 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005447 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005448 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005449 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305450 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005451 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005452 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005453 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005454 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005455 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005456 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005457 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005458 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005459 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005460 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005461 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005462 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005463 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005464 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005465 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005466 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005467 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005468 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005469 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005470 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005471 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005472 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005473 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005474 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005475 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005476 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005477 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005478 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005479 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005480 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005481 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305482 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005483 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005484};
Ben Gamari27c202a2009-07-01 22:26:52 -04005485#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005486
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005487static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005488 const char *name;
5489 const struct file_operations *fops;
5490} i915_debugfs_files[] = {
5491 {"i915_wedged", &i915_wedged_fops},
5492 {"i915_max_freq", &i915_max_freq_fops},
5493 {"i915_min_freq", &i915_min_freq_fops},
5494 {"i915_cache_sharing", &i915_cache_sharing_fops},
5495 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005496 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5497 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005498 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5499 {"i915_error_state", &i915_error_state_fops},
5500 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005501 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005502 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5503 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5504 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005505 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005506 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5507 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5508 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005509};
5510
Damien Lespiau07144422013-10-15 18:55:40 +01005511void intel_display_crc_init(struct drm_device *dev)
5512{
5513 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005514 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005515
Damien Lespiau055e3932014-08-18 13:49:10 +01005516 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005517 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005518
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005519 pipe_crc->opened = false;
5520 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005521 init_waitqueue_head(&pipe_crc->wq);
5522 }
5523}
5524
Chris Wilson1dac8912016-06-24 14:00:17 +01005525int i915_debugfs_register(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005526{
Chris Wilson1dac8912016-06-24 14:00:17 +01005527 struct drm_minor *minor = dev_priv->dev->primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005528 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005529
Ben Widawsky6d794d42011-04-25 11:25:56 -07005530 ret = i915_forcewake_create(minor->debugfs_root, minor);
5531 if (ret)
5532 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005533
Damien Lespiau07144422013-10-15 18:55:40 +01005534 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5535 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5536 if (ret)
5537 return ret;
5538 }
5539
Daniel Vetter34b96742013-07-04 20:49:44 +02005540 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5541 ret = i915_debugfs_create(minor->debugfs_root, minor,
5542 i915_debugfs_files[i].name,
5543 i915_debugfs_files[i].fops);
5544 if (ret)
5545 return ret;
5546 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005547
Ben Gamari27c202a2009-07-01 22:26:52 -04005548 return drm_debugfs_create_files(i915_debugfs_list,
5549 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005550 minor->debugfs_root, minor);
5551}
5552
Chris Wilson1dac8912016-06-24 14:00:17 +01005553void i915_debugfs_unregister(struct drm_i915_private *dev_priv)
Ben Gamari20172632009-02-17 20:08:50 -05005554{
Chris Wilson1dac8912016-06-24 14:00:17 +01005555 struct drm_minor *minor = dev_priv->dev->primary;
Daniel Vetter34b96742013-07-04 20:49:44 +02005556 int i;
5557
Ben Gamari27c202a2009-07-01 22:26:52 -04005558 drm_debugfs_remove_files(i915_debugfs_list,
5559 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005560
Ben Widawsky6d794d42011-04-25 11:25:56 -07005561 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5562 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005563
Daniel Vettere309a992013-10-16 22:55:51 +02005564 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005565 struct drm_info_list *info_list =
5566 (struct drm_info_list *)&i915_pipe_crc_data[i];
5567
5568 drm_debugfs_remove_files(info_list, 1, minor);
5569 }
5570
Daniel Vetter34b96742013-07-04 20:49:44 +02005571 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5572 struct drm_info_list *info_list =
5573 (struct drm_info_list *) i915_debugfs_files[i].fops;
5574
5575 drm_debugfs_remove_files(info_list, 1, minor);
5576 }
Ben Gamari20172632009-02-17 20:08:50 -05005577}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005578
5579struct dpcd_block {
5580 /* DPCD dump start address. */
5581 unsigned int offset;
5582 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5583 unsigned int end;
5584 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5585 size_t size;
5586 /* Only valid for eDP. */
5587 bool edp;
5588};
5589
5590static const struct dpcd_block i915_dpcd_debug[] = {
5591 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5592 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5593 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5594 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5595 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5596 { .offset = DP_SET_POWER },
5597 { .offset = DP_EDP_DPCD_REV },
5598 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5599 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5600 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5601};
5602
5603static int i915_dpcd_show(struct seq_file *m, void *data)
5604{
5605 struct drm_connector *connector = m->private;
5606 struct intel_dp *intel_dp =
5607 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5608 uint8_t buf[16];
5609 ssize_t err;
5610 int i;
5611
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005612 if (connector->status != connector_status_connected)
5613 return -ENODEV;
5614
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005615 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5616 const struct dpcd_block *b = &i915_dpcd_debug[i];
5617 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5618
5619 if (b->edp &&
5620 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5621 continue;
5622
5623 /* low tech for now */
5624 if (WARN_ON(size > sizeof(buf)))
5625 continue;
5626
5627 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5628 if (err <= 0) {
5629 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5630 size, b->offset, err);
5631 continue;
5632 }
5633
5634 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005635 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005636
5637 return 0;
5638}
5639
5640static int i915_dpcd_open(struct inode *inode, struct file *file)
5641{
5642 return single_open(file, i915_dpcd_show, inode->i_private);
5643}
5644
5645static const struct file_operations i915_dpcd_fops = {
5646 .owner = THIS_MODULE,
5647 .open = i915_dpcd_open,
5648 .read = seq_read,
5649 .llseek = seq_lseek,
5650 .release = single_release,
5651};
5652
5653/**
5654 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5655 * @connector: pointer to a registered drm_connector
5656 *
5657 * Cleanup will be done by drm_connector_unregister() through a call to
5658 * drm_debugfs_connector_remove().
5659 *
5660 * Returns 0 on success, negative error codes on error.
5661 */
5662int i915_debugfs_connector_add(struct drm_connector *connector)
5663{
5664 struct dentry *root = connector->debugfs_entry;
5665
5666 /* The connector must have been registered beforehands. */
5667 if (!root)
5668 return -ENODEV;
5669
5670 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5671 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5672 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5673 &i915_dpcd_fops);
5674
5675 return 0;
5676}