blob: 614ac085e51fdbebb104a9617fab379093718342 [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,
665 engine->get_seqno(engine),
666 i915_gem_request_completed(work->flip_queued_req, true));
667 } 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 Wilson12471ba2016-04-09 10:57:55 +0100791 seq_printf(m, "Current sequence (%s): %x\n",
792 engine->name, engine->get_seqno(engine));
793 seq_printf(m, "Current user interrupts (%s): %x\n",
794 engine->name, READ_ONCE(engine->user_interrupts));
Chris Wilsonb2223492010-10-27 15:27:33 +0100795}
796
Ben Gamari20172632009-02-17 20:08:50 -0500797static int i915_gem_seqno_info(struct seq_file *m, void *data)
798{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100799 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500800 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300801 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000802 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000803 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100804
805 ret = mutex_lock_interruptible(&dev->struct_mutex);
806 if (ret)
807 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200808 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500809
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000810 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000811 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100812
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200813 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100814 mutex_unlock(&dev->struct_mutex);
815
Ben Gamari20172632009-02-17 20:08:50 -0500816 return 0;
817}
818
819
820static int i915_interrupt_info(struct seq_file *m, void *data)
821{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100822 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500823 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300824 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000825 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800826 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100827
828 ret = mutex_lock_interruptible(&dev->struct_mutex);
829 if (ret)
830 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200831 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500832
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300833 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300834 seq_printf(m, "Master Interrupt Control:\t%08x\n",
835 I915_READ(GEN8_MASTER_IRQ));
836
837 seq_printf(m, "Display IER:\t%08x\n",
838 I915_READ(VLV_IER));
839 seq_printf(m, "Display IIR:\t%08x\n",
840 I915_READ(VLV_IIR));
841 seq_printf(m, "Display IIR_RW:\t%08x\n",
842 I915_READ(VLV_IIR_RW));
843 seq_printf(m, "Display IMR:\t%08x\n",
844 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100845 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300846 seq_printf(m, "Pipe %c stat:\t%08x\n",
847 pipe_name(pipe),
848 I915_READ(PIPESTAT(pipe)));
849
850 seq_printf(m, "Port hotplug:\t%08x\n",
851 I915_READ(PORT_HOTPLUG_EN));
852 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
853 I915_READ(VLV_DPFLIPSTAT));
854 seq_printf(m, "DPINVGTT:\t%08x\n",
855 I915_READ(DPINVGTT));
856
857 for (i = 0; i < 4; i++) {
858 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
859 i, I915_READ(GEN8_GT_IMR(i)));
860 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
861 i, I915_READ(GEN8_GT_IIR(i)));
862 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
863 i, I915_READ(GEN8_GT_IER(i)));
864 }
865
866 seq_printf(m, "PCU interrupt mask:\t%08x\n",
867 I915_READ(GEN8_PCU_IMR));
868 seq_printf(m, "PCU interrupt identity:\t%08x\n",
869 I915_READ(GEN8_PCU_IIR));
870 seq_printf(m, "PCU interrupt enable:\t%08x\n",
871 I915_READ(GEN8_PCU_IER));
872 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700873 seq_printf(m, "Master Interrupt Control:\t%08x\n",
874 I915_READ(GEN8_MASTER_IRQ));
875
876 for (i = 0; i < 4; i++) {
877 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
878 i, I915_READ(GEN8_GT_IMR(i)));
879 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
880 i, I915_READ(GEN8_GT_IIR(i)));
881 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
882 i, I915_READ(GEN8_GT_IER(i)));
883 }
884
Damien Lespiau055e3932014-08-18 13:49:10 +0100885 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200886 enum intel_display_power_domain power_domain;
887
888 power_domain = POWER_DOMAIN_PIPE(pipe);
889 if (!intel_display_power_get_if_enabled(dev_priv,
890 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300891 seq_printf(m, "Pipe %c power disabled\n",
892 pipe_name(pipe));
893 continue;
894 }
Ben Widawskya123f152013-11-02 21:07:10 -0700895 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000896 pipe_name(pipe),
897 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700898 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000899 pipe_name(pipe),
900 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700901 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000902 pipe_name(pipe),
903 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200904
905 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700906 }
907
908 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
909 I915_READ(GEN8_DE_PORT_IMR));
910 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
911 I915_READ(GEN8_DE_PORT_IIR));
912 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
913 I915_READ(GEN8_DE_PORT_IER));
914
915 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
916 I915_READ(GEN8_DE_MISC_IMR));
917 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
918 I915_READ(GEN8_DE_MISC_IIR));
919 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
920 I915_READ(GEN8_DE_MISC_IER));
921
922 seq_printf(m, "PCU interrupt mask:\t%08x\n",
923 I915_READ(GEN8_PCU_IMR));
924 seq_printf(m, "PCU interrupt identity:\t%08x\n",
925 I915_READ(GEN8_PCU_IIR));
926 seq_printf(m, "PCU interrupt enable:\t%08x\n",
927 I915_READ(GEN8_PCU_IER));
928 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700929 seq_printf(m, "Display IER:\t%08x\n",
930 I915_READ(VLV_IER));
931 seq_printf(m, "Display IIR:\t%08x\n",
932 I915_READ(VLV_IIR));
933 seq_printf(m, "Display IIR_RW:\t%08x\n",
934 I915_READ(VLV_IIR_RW));
935 seq_printf(m, "Display IMR:\t%08x\n",
936 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100937 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700938 seq_printf(m, "Pipe %c stat:\t%08x\n",
939 pipe_name(pipe),
940 I915_READ(PIPESTAT(pipe)));
941
942 seq_printf(m, "Master IER:\t%08x\n",
943 I915_READ(VLV_MASTER_IER));
944
945 seq_printf(m, "Render IER:\t%08x\n",
946 I915_READ(GTIER));
947 seq_printf(m, "Render IIR:\t%08x\n",
948 I915_READ(GTIIR));
949 seq_printf(m, "Render IMR:\t%08x\n",
950 I915_READ(GTIMR));
951
952 seq_printf(m, "PM IER:\t\t%08x\n",
953 I915_READ(GEN6_PMIER));
954 seq_printf(m, "PM IIR:\t\t%08x\n",
955 I915_READ(GEN6_PMIIR));
956 seq_printf(m, "PM IMR:\t\t%08x\n",
957 I915_READ(GEN6_PMIMR));
958
959 seq_printf(m, "Port hotplug:\t%08x\n",
960 I915_READ(PORT_HOTPLUG_EN));
961 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
962 I915_READ(VLV_DPFLIPSTAT));
963 seq_printf(m, "DPINVGTT:\t%08x\n",
964 I915_READ(DPINVGTT));
965
966 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800967 seq_printf(m, "Interrupt enable: %08x\n",
968 I915_READ(IER));
969 seq_printf(m, "Interrupt identity: %08x\n",
970 I915_READ(IIR));
971 seq_printf(m, "Interrupt mask: %08x\n",
972 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100973 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800974 seq_printf(m, "Pipe %c stat: %08x\n",
975 pipe_name(pipe),
976 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800977 } else {
978 seq_printf(m, "North Display Interrupt enable: %08x\n",
979 I915_READ(DEIER));
980 seq_printf(m, "North Display Interrupt identity: %08x\n",
981 I915_READ(DEIIR));
982 seq_printf(m, "North Display Interrupt mask: %08x\n",
983 I915_READ(DEIMR));
984 seq_printf(m, "South Display Interrupt enable: %08x\n",
985 I915_READ(SDEIER));
986 seq_printf(m, "South Display Interrupt identity: %08x\n",
987 I915_READ(SDEIIR));
988 seq_printf(m, "South Display Interrupt mask: %08x\n",
989 I915_READ(SDEIMR));
990 seq_printf(m, "Graphics Interrupt enable: %08x\n",
991 I915_READ(GTIER));
992 seq_printf(m, "Graphics Interrupt identity: %08x\n",
993 I915_READ(GTIIR));
994 seq_printf(m, "Graphics Interrupt mask: %08x\n",
995 I915_READ(GTIMR));
996 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000997 for_each_engine(engine, dev_priv) {
Ben Widawskya123f152013-11-02 21:07:10 -0700998 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100999 seq_printf(m,
1000 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001001 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +00001002 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001003 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +00001004 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001005 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001006 mutex_unlock(&dev->struct_mutex);
1007
Ben Gamari20172632009-02-17 20:08:50 -05001008 return 0;
1009}
1010
Chris Wilsona6172a82009-02-11 14:26:38 +00001011static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
1012{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001013 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +00001014 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001015 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001016 int i, ret;
1017
1018 ret = mutex_lock_interruptible(&dev->struct_mutex);
1019 if (ret)
1020 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +00001021
Chris Wilsona6172a82009-02-11 14:26:38 +00001022 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
1023 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +00001024 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +00001025
Chris Wilson6c085a72012-08-20 11:40:46 +02001026 seq_printf(m, "Fence %d, pin count = %d, object = ",
1027 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001028 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001029 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +01001030 else
Chris Wilson05394f32010-11-08 19:18:58 +00001031 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001032 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +00001033 }
1034
Chris Wilson05394f32010-11-08 19:18:58 +00001035 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +00001036 return 0;
1037}
1038
Ben Gamari20172632009-02-17 20:08:50 -05001039static int i915_hws_info(struct seq_file *m, void *data)
1040{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001041 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -05001042 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001043 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001044 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +01001045 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +01001046 int i;
Ben Gamari20172632009-02-17 20:08:50 -05001047
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001048 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001049 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -05001050 if (hws == NULL)
1051 return 0;
1052
1053 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
1054 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
1055 i * 4,
1056 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
1057 }
1058 return 0;
1059}
1060
Daniel Vetterd5442302012-04-27 15:17:40 +02001061static ssize_t
1062i915_error_state_write(struct file *filp,
1063 const char __user *ubuf,
1064 size_t cnt,
1065 loff_t *ppos)
1066{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001067 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001068 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001069 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001070
1071 DRM_DEBUG_DRIVER("Resetting error state\n");
1072
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001073 ret = mutex_lock_interruptible(&dev->struct_mutex);
1074 if (ret)
1075 return ret;
1076
Daniel Vetterd5442302012-04-27 15:17:40 +02001077 i915_destroy_error_state(dev);
1078 mutex_unlock(&dev->struct_mutex);
1079
1080 return cnt;
1081}
1082
1083static int i915_error_state_open(struct inode *inode, struct file *file)
1084{
1085 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001086 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001087
1088 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1089 if (!error_priv)
1090 return -ENOMEM;
1091
1092 error_priv->dev = dev;
1093
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001094 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001095
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001096 file->private_data = error_priv;
1097
1098 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001099}
1100
1101static int i915_error_state_release(struct inode *inode, struct file *file)
1102{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001103 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001104
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001105 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001106 kfree(error_priv);
1107
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001108 return 0;
1109}
1110
1111static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1112 size_t count, loff_t *pos)
1113{
1114 struct i915_error_state_file_priv *error_priv = file->private_data;
1115 struct drm_i915_error_state_buf error_str;
1116 loff_t tmp_pos = 0;
1117 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001118 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001119
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001120 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001121 if (ret)
1122 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001123
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001124 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001125 if (ret)
1126 goto out;
1127
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001128 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1129 error_str.buf,
1130 error_str.bytes);
1131
1132 if (ret_count < 0)
1133 ret = ret_count;
1134 else
1135 *pos = error_str.start + ret_count;
1136out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001137 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001138 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001139}
1140
1141static const struct file_operations i915_error_state_fops = {
1142 .owner = THIS_MODULE,
1143 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001144 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001145 .write = i915_error_state_write,
1146 .llseek = default_llseek,
1147 .release = i915_error_state_release,
1148};
1149
Kees Cook647416f2013-03-10 14:10:06 -07001150static int
1151i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001152{
Kees Cook647416f2013-03-10 14:10:06 -07001153 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001154 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001155 int ret;
1156
1157 ret = mutex_lock_interruptible(&dev->struct_mutex);
1158 if (ret)
1159 return ret;
1160
Kees Cook647416f2013-03-10 14:10:06 -07001161 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001162 mutex_unlock(&dev->struct_mutex);
1163
Kees Cook647416f2013-03-10 14:10:06 -07001164 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001165}
1166
Kees Cook647416f2013-03-10 14:10:06 -07001167static int
1168i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001169{
Kees Cook647416f2013-03-10 14:10:06 -07001170 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001171 int ret;
1172
Mika Kuoppala40633212012-12-04 15:12:00 +02001173 ret = mutex_lock_interruptible(&dev->struct_mutex);
1174 if (ret)
1175 return ret;
1176
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001177 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001178 mutex_unlock(&dev->struct_mutex);
1179
Kees Cook647416f2013-03-10 14:10:06 -07001180 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001181}
1182
Kees Cook647416f2013-03-10 14:10:06 -07001183DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1184 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001185 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001186
Deepak Sadb4bd12014-03-31 11:30:02 +05301187static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001188{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001189 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001190 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001191 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001192 int ret = 0;
1193
1194 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001195
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001196 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1197
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001198 if (IS_GEN5(dev)) {
1199 u16 rgvswctl = I915_READ16(MEMSWCTL);
1200 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1201
1202 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1203 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1204 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1205 MEMSTAT_VID_SHIFT);
1206 seq_printf(m, "Current P-state: %d\n",
1207 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Wayne Boyer666a4532015-12-09 12:29:35 -08001208 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
1209 u32 freq_sts;
1210
1211 mutex_lock(&dev_priv->rps.hw_lock);
1212 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1213 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1214 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1215
1216 seq_printf(m, "actual GPU freq: %d MHz\n",
1217 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1218
1219 seq_printf(m, "current GPU freq: %d MHz\n",
1220 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1221
1222 seq_printf(m, "max GPU freq: %d MHz\n",
1223 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1224
1225 seq_printf(m, "min GPU freq: %d MHz\n",
1226 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1227
1228 seq_printf(m, "idle GPU freq: %d MHz\n",
1229 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1230
1231 seq_printf(m,
1232 "efficient (RPe) frequency: %d MHz\n",
1233 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1234 mutex_unlock(&dev_priv->rps.hw_lock);
1235 } else if (INTEL_INFO(dev)->gen >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001236 u32 rp_state_limits;
1237 u32 gt_perf_status;
1238 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001239 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001240 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001241 u32 rpupei, rpcurup, rpprevup;
1242 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001243 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001244 int max_freq;
1245
Bob Paauwe35040562015-06-25 14:54:07 -07001246 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1247 if (IS_BROXTON(dev)) {
1248 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1249 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1250 } else {
1251 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1252 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1253 }
1254
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001255 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001256 ret = mutex_lock_interruptible(&dev->struct_mutex);
1257 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001258 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001259
Mika Kuoppala59bad942015-01-16 11:34:40 +02001260 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001261
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001262 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301263 if (IS_GEN9(dev))
1264 reqf >>= 23;
1265 else {
1266 reqf &= ~GEN6_TURBO_DISABLE;
1267 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1268 reqf >>= 24;
1269 else
1270 reqf >>= 25;
1271 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001272 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001273
Chris Wilson0d8f9492014-03-27 09:06:14 +00001274 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1275 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1276 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1277
Jesse Barnesccab5c82011-01-18 15:49:25 -08001278 rpstat = I915_READ(GEN6_RPSTAT1);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301279 rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
1280 rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
1281 rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
1282 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
1283 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
1284 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
Akash Goel60260a52015-03-06 11:07:21 +05301285 if (IS_GEN9(dev))
1286 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1287 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001288 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1289 else
1290 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001291 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001292
Mika Kuoppala59bad942015-01-16 11:34:40 +02001293 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001294 mutex_unlock(&dev->struct_mutex);
1295
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001296 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1297 pm_ier = I915_READ(GEN6_PMIER);
1298 pm_imr = I915_READ(GEN6_PMIMR);
1299 pm_isr = I915_READ(GEN6_PMISR);
1300 pm_iir = I915_READ(GEN6_PMIIR);
1301 pm_mask = I915_READ(GEN6_PMINTRMSK);
1302 } else {
1303 pm_ier = I915_READ(GEN8_GT_IER(2));
1304 pm_imr = I915_READ(GEN8_GT_IMR(2));
1305 pm_isr = I915_READ(GEN8_GT_ISR(2));
1306 pm_iir = I915_READ(GEN8_GT_IIR(2));
1307 pm_mask = I915_READ(GEN6_PMINTRMSK);
1308 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001309 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 -03001310 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05301311 seq_printf(m, "pm_intr_keep: 0x%08x\n", dev_priv->rps.pm_intr_keep);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001312 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001313 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301314 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001315 seq_printf(m, "Render p-state VID: %d\n",
1316 gt_perf_status & 0xff);
1317 seq_printf(m, "Render p-state limit: %d\n",
1318 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001319 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1320 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1321 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1322 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001323 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001324 seq_printf(m, "CAGF: %dMHz\n", cagf);
Akash Goeld6cda9c2016-04-23 00:05:46 +05301325 seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
1326 rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
1327 seq_printf(m, "RP CUR UP: %d (%dus)\n",
1328 rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
1329 seq_printf(m, "RP PREV UP: %d (%dus)\n",
1330 rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
Chris Wilsond86ed342015-04-27 13:41:19 +01001331 seq_printf(m, "Up threshold: %d%%\n",
1332 dev_priv->rps.up_threshold);
1333
Akash Goeld6cda9c2016-04-23 00:05:46 +05301334 seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
1335 rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
1336 seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
1337 rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
1338 seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
1339 rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
Chris Wilsond86ed342015-04-27 13:41:19 +01001340 seq_printf(m, "Down threshold: %d%%\n",
1341 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001342
Bob Paauwe35040562015-06-25 14:54:07 -07001343 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1344 rp_state_cap >> 16) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001345 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1346 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001347 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001348 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001349
1350 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001351 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1352 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001353 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001354 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001355
Bob Paauwe35040562015-06-25 14:54:07 -07001356 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1357 rp_state_cap >> 0) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001358 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1359 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001360 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001361 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001362 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001363 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001364
Chris Wilsond86ed342015-04-27 13:41:19 +01001365 seq_printf(m, "Current freq: %d MHz\n",
1366 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1367 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001368 seq_printf(m, "Idle freq: %d MHz\n",
1369 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001370 seq_printf(m, "Min freq: %d MHz\n",
1371 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1372 seq_printf(m, "Max freq: %d MHz\n",
1373 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1374 seq_printf(m,
1375 "efficient (RPe) frequency: %d MHz\n",
1376 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001377 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001378 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001379 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001380
Mika Kahola1170f282015-09-25 14:00:32 +03001381 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1382 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1383 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1384
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001385out:
1386 intel_runtime_pm_put(dev_priv);
1387 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001388}
1389
Chris Wilsonf6544492015-01-26 18:03:04 +02001390static int i915_hangcheck_info(struct seq_file *m, void *unused)
1391{
1392 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001393 struct drm_device *dev = node->minor->dev;
1394 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001395 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001396 u64 acthd[I915_NUM_ENGINES];
1397 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001398 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001399 enum intel_engine_id id;
1400 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001401
1402 if (!i915.enable_hangcheck) {
1403 seq_printf(m, "Hangcheck disabled\n");
1404 return 0;
1405 }
1406
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001407 intel_runtime_pm_get(dev_priv);
1408
Dave Gordonc3232b12016-03-23 18:19:53 +00001409 for_each_engine_id(engine, dev_priv, id) {
Dave Gordonc3232b12016-03-23 18:19:53 +00001410 acthd[id] = intel_ring_get_active_head(engine);
Chris Wilsonc04e0f32016-04-09 10:57:54 +01001411 seqno[id] = engine->get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001412 }
1413
Chris Wilsonc0336662016-05-06 15:40:21 +01001414 i915_get_extra_instdone(dev_priv, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001415
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001416 intel_runtime_pm_put(dev_priv);
1417
Chris Wilsonf6544492015-01-26 18:03:04 +02001418 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1419 seq_printf(m, "Hangcheck active, fires in %dms\n",
1420 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1421 jiffies));
1422 } else
1423 seq_printf(m, "Hangcheck inactive\n");
1424
Dave Gordonc3232b12016-03-23 18:19:53 +00001425 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001426 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001427 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1428 engine->hangcheck.seqno,
1429 seqno[id],
1430 engine->last_submitted_seqno);
Chris Wilson12471ba2016-04-09 10:57:55 +01001431 seq_printf(m, "\tuser interrupts = %x [current %x]\n",
1432 engine->hangcheck.user_interrupts,
1433 READ_ONCE(engine->user_interrupts));
Chris Wilsonf6544492015-01-26 18:03:04 +02001434 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001435 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001436 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001437 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1438 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001439
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001440 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001441 seq_puts(m, "\tinstdone read =");
1442
1443 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1444 seq_printf(m, " 0x%08x", instdone[j]);
1445
1446 seq_puts(m, "\n\tinstdone accu =");
1447
1448 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1449 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001450 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001451
1452 seq_puts(m, "\n");
1453 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001454 }
1455
1456 return 0;
1457}
1458
Ben Widawsky4d855292011-12-12 19:34:16 -08001459static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001460{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001461 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001462 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001463 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001464 u32 rgvmodectl, rstdbyctl;
1465 u16 crstandvid;
1466 int ret;
1467
1468 ret = mutex_lock_interruptible(&dev->struct_mutex);
1469 if (ret)
1470 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001471 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001472
1473 rgvmodectl = I915_READ(MEMMODECTL);
1474 rstdbyctl = I915_READ(RSTDBYCTL);
1475 crstandvid = I915_READ16(CRSTANDVID);
1476
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001477 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001478 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001479
Jani Nikula742f4912015-09-03 11:16:09 +03001480 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001481 seq_printf(m, "Boost freq: %d\n",
1482 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1483 MEMMODE_BOOST_FREQ_SHIFT);
1484 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001485 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001486 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001487 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001488 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001489 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001490 seq_printf(m, "Starting frequency: P%d\n",
1491 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001492 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001493 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001494 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1495 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1496 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1497 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001498 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001499 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001500 switch (rstdbyctl & RSX_STATUS_MASK) {
1501 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001502 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001503 break;
1504 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001505 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001506 break;
1507 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001508 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001509 break;
1510 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001511 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001512 break;
1513 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001514 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001515 break;
1516 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001517 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001518 break;
1519 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001520 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001521 break;
1522 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001523
1524 return 0;
1525}
1526
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001527static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001528{
1529 struct drm_info_node *node = m->private;
1530 struct drm_device *dev = node->minor->dev;
1531 struct drm_i915_private *dev_priv = dev->dev_private;
1532 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001533
1534 spin_lock_irq(&dev_priv->uncore.lock);
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001535 for_each_fw_domain(fw_domain, dev_priv) {
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001536 seq_printf(m, "%s.wake_count = %u\n",
Tvrtko Ursulin33c582c2016-04-07 17:04:33 +01001537 intel_uncore_forcewake_domain_to_str(fw_domain->id),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001538 fw_domain->wake_count);
1539 }
1540 spin_unlock_irq(&dev_priv->uncore.lock);
1541
1542 return 0;
1543}
1544
Deepak S669ab5a2014-01-10 15:18:26 +05301545static int vlv_drpc_info(struct seq_file *m)
1546{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001547 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301548 struct drm_device *dev = node->minor->dev;
1549 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001550 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301551
Imre Deakd46c0512014-04-14 20:24:27 +03001552 intel_runtime_pm_get(dev_priv);
1553
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001554 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301555 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1556 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1557
Imre Deakd46c0512014-04-14 20:24:27 +03001558 intel_runtime_pm_put(dev_priv);
1559
Deepak S669ab5a2014-01-10 15:18:26 +05301560 seq_printf(m, "Video Turbo Mode: %s\n",
1561 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1562 seq_printf(m, "Turbo enabled: %s\n",
1563 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1564 seq_printf(m, "HW control enabled: %s\n",
1565 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1566 seq_printf(m, "SW control enabled: %s\n",
1567 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1568 GEN6_RP_MEDIA_SW_MODE));
1569 seq_printf(m, "RC6 Enabled: %s\n",
1570 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1571 GEN6_RC_CTL_EI_MODE(1))));
1572 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001573 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301574 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001575 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301576
Imre Deak9cc19be2014-04-14 20:24:24 +03001577 seq_printf(m, "Render RC6 residency since boot: %u\n",
1578 I915_READ(VLV_GT_RENDER_RC6));
1579 seq_printf(m, "Media RC6 residency since boot: %u\n",
1580 I915_READ(VLV_GT_MEDIA_RC6));
1581
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001582 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301583}
1584
Ben Widawsky4d855292011-12-12 19:34:16 -08001585static int gen6_drpc_info(struct seq_file *m)
1586{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001587 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001588 struct drm_device *dev = node->minor->dev;
1589 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001590 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001591 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001592 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001593
1594 ret = mutex_lock_interruptible(&dev->struct_mutex);
1595 if (ret)
1596 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001597 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001598
Chris Wilson907b28c2013-07-19 20:36:52 +01001599 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001600 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001601 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001602
1603 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001604 seq_puts(m, "RC information inaccurate because somebody "
1605 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001606 } else {
1607 /* NB: we cannot use forcewake, else we read the wrong values */
1608 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1609 udelay(10);
1610 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1611 }
1612
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001613 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001614 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001615
1616 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1617 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1618 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001619 mutex_lock(&dev_priv->rps.hw_lock);
1620 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1621 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001622
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001623 intel_runtime_pm_put(dev_priv);
1624
Ben Widawsky4d855292011-12-12 19:34:16 -08001625 seq_printf(m, "Video Turbo Mode: %s\n",
1626 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1627 seq_printf(m, "HW control enabled: %s\n",
1628 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1629 seq_printf(m, "SW control enabled: %s\n",
1630 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1631 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001632 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001633 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1634 seq_printf(m, "RC6 Enabled: %s\n",
1635 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1636 seq_printf(m, "Deep RC6 Enabled: %s\n",
1637 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1638 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1639 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001640 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001641 switch (gt_core_status & GEN6_RCn_MASK) {
1642 case GEN6_RC0:
1643 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001644 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001645 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001646 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001647 break;
1648 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001649 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001650 break;
1651 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001652 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001653 break;
1654 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001655 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001656 break;
1657 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001658 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001659 break;
1660 }
1661
1662 seq_printf(m, "Core Power Down: %s\n",
1663 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001664
1665 /* Not exactly sure what this is */
1666 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1667 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1668 seq_printf(m, "RC6 residency since boot: %u\n",
1669 I915_READ(GEN6_GT_GFX_RC6));
1670 seq_printf(m, "RC6+ residency since boot: %u\n",
1671 I915_READ(GEN6_GT_GFX_RC6p));
1672 seq_printf(m, "RC6++ residency since boot: %u\n",
1673 I915_READ(GEN6_GT_GFX_RC6pp));
1674
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001675 seq_printf(m, "RC6 voltage: %dmV\n",
1676 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1677 seq_printf(m, "RC6+ voltage: %dmV\n",
1678 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1679 seq_printf(m, "RC6++ voltage: %dmV\n",
1680 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001681 return 0;
1682}
1683
1684static int i915_drpc_info(struct seq_file *m, void *unused)
1685{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001686 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001687 struct drm_device *dev = node->minor->dev;
1688
Wayne Boyer666a4532015-12-09 12:29:35 -08001689 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Deepak S669ab5a2014-01-10 15:18:26 +05301690 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001691 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001692 return gen6_drpc_info(m);
1693 else
1694 return ironlake_drpc_info(m);
1695}
1696
Daniel Vetter9a851782015-06-18 10:30:22 +02001697static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1698{
1699 struct drm_info_node *node = m->private;
1700 struct drm_device *dev = node->minor->dev;
1701 struct drm_i915_private *dev_priv = dev->dev_private;
1702
1703 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1704 dev_priv->fb_tracking.busy_bits);
1705
1706 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1707 dev_priv->fb_tracking.flip_bits);
1708
1709 return 0;
1710}
1711
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001712static int i915_fbc_status(struct seq_file *m, void *unused)
1713{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001714 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001715 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001716 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001717
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001718 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001719 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001720 return 0;
1721 }
1722
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001723 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001724 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001725
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001726 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001727 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001728 else
1729 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001730 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001731
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001732 if (INTEL_INFO(dev_priv)->gen >= 7)
1733 seq_printf(m, "Compressing: %s\n",
1734 yesno(I915_READ(FBC_STATUS2) &
1735 FBC_COMPRESSION_MASK));
1736
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001737 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001738 intel_runtime_pm_put(dev_priv);
1739
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001740 return 0;
1741}
1742
Rodrigo Vivida46f932014-08-01 02:04:45 -07001743static int i915_fbc_fc_get(void *data, u64 *val)
1744{
1745 struct drm_device *dev = data;
1746 struct drm_i915_private *dev_priv = dev->dev_private;
1747
1748 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1749 return -ENODEV;
1750
Rodrigo Vivida46f932014-08-01 02:04:45 -07001751 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001752
1753 return 0;
1754}
1755
1756static int i915_fbc_fc_set(void *data, u64 val)
1757{
1758 struct drm_device *dev = data;
1759 struct drm_i915_private *dev_priv = dev->dev_private;
1760 u32 reg;
1761
1762 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1763 return -ENODEV;
1764
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001765 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001766
1767 reg = I915_READ(ILK_DPFC_CONTROL);
1768 dev_priv->fbc.false_color = val;
1769
1770 I915_WRITE(ILK_DPFC_CONTROL, val ?
1771 (reg | FBC_CTL_FALSE_COLOR) :
1772 (reg & ~FBC_CTL_FALSE_COLOR));
1773
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001774 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001775 return 0;
1776}
1777
1778DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1779 i915_fbc_fc_get, i915_fbc_fc_set,
1780 "%llu\n");
1781
Paulo Zanoni92d44622013-05-31 16:33:24 -03001782static int i915_ips_status(struct seq_file *m, void *unused)
1783{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001784 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001785 struct drm_device *dev = node->minor->dev;
1786 struct drm_i915_private *dev_priv = dev->dev_private;
1787
Damien Lespiauf5adf942013-06-24 18:29:34 +01001788 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001789 seq_puts(m, "not supported\n");
1790 return 0;
1791 }
1792
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001793 intel_runtime_pm_get(dev_priv);
1794
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001795 seq_printf(m, "Enabled by kernel parameter: %s\n",
1796 yesno(i915.enable_ips));
1797
1798 if (INTEL_INFO(dev)->gen >= 8) {
1799 seq_puts(m, "Currently: unknown\n");
1800 } else {
1801 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1802 seq_puts(m, "Currently: enabled\n");
1803 else
1804 seq_puts(m, "Currently: disabled\n");
1805 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001806
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001807 intel_runtime_pm_put(dev_priv);
1808
Paulo Zanoni92d44622013-05-31 16:33:24 -03001809 return 0;
1810}
1811
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001812static int i915_sr_status(struct seq_file *m, void *unused)
1813{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001814 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001815 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001816 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001817 bool sr_enabled = false;
1818
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001819 intel_runtime_pm_get(dev_priv);
1820
Yuanhan Liu13982612010-12-15 15:42:31 +08001821 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001822 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001823 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1824 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001825 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1826 else if (IS_I915GM(dev))
1827 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1828 else if (IS_PINEVIEW(dev))
1829 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Wayne Boyer666a4532015-12-09 12:29:35 -08001830 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001831 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001832
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001833 intel_runtime_pm_put(dev_priv);
1834
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001835 seq_printf(m, "self-refresh: %s\n",
1836 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001837
1838 return 0;
1839}
1840
Jesse Barnes7648fa92010-05-20 14:28:11 -07001841static int i915_emon_status(struct seq_file *m, void *unused)
1842{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001843 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001844 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001845 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001846 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001847 int ret;
1848
Chris Wilson582be6b2012-04-30 19:35:02 +01001849 if (!IS_GEN5(dev))
1850 return -ENODEV;
1851
Chris Wilsonde227ef2010-07-03 07:58:38 +01001852 ret = mutex_lock_interruptible(&dev->struct_mutex);
1853 if (ret)
1854 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001855
1856 temp = i915_mch_val(dev_priv);
1857 chipset = i915_chipset_val(dev_priv);
1858 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001859 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001860
1861 seq_printf(m, "GMCH temp: %ld\n", temp);
1862 seq_printf(m, "Chipset power: %ld\n", chipset);
1863 seq_printf(m, "GFX power: %ld\n", gfx);
1864 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1865
1866 return 0;
1867}
1868
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001869static int i915_ring_freq_table(struct seq_file *m, void *unused)
1870{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001871 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001872 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001873 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001874 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001875 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301876 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001877
Akash Goel97d33082015-06-29 14:50:23 +05301878 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001879 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001880 return 0;
1881 }
1882
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001883 intel_runtime_pm_get(dev_priv);
1884
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001885 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1886
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001887 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001888 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001889 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001890
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001891 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301892 /* Convert GT frequency to 50 HZ units */
1893 min_gpu_freq =
1894 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1895 max_gpu_freq =
1896 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1897 } else {
1898 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1899 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1900 }
1901
Damien Lespiau267f0c92013-06-24 22:59:48 +01001902 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001903
Akash Goelf936ec32015-06-29 14:50:22 +05301904 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001905 ia_freq = gpu_freq;
1906 sandybridge_pcode_read(dev_priv,
1907 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1908 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001909 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301910 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001911 (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1912 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001913 ((ia_freq >> 0) & 0xff) * 100,
1914 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001915 }
1916
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001917 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001918
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001919out:
1920 intel_runtime_pm_put(dev_priv);
1921 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001922}
1923
Chris Wilson44834a62010-08-19 16:09:23 +01001924static int i915_opregion(struct seq_file *m, void *unused)
1925{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001926 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001927 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001928 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001929 struct intel_opregion *opregion = &dev_priv->opregion;
1930 int ret;
1931
1932 ret = mutex_lock_interruptible(&dev->struct_mutex);
1933 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001934 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001935
Jani Nikula2455a8e2015-12-14 12:50:53 +02001936 if (opregion->header)
1937 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001938
1939 mutex_unlock(&dev->struct_mutex);
1940
Daniel Vetter0d38f002012-04-21 22:49:10 +02001941out:
Chris Wilson44834a62010-08-19 16:09:23 +01001942 return 0;
1943}
1944
Jani Nikulaada8f952015-12-15 13:17:12 +02001945static int i915_vbt(struct seq_file *m, void *unused)
1946{
1947 struct drm_info_node *node = m->private;
1948 struct drm_device *dev = node->minor->dev;
1949 struct drm_i915_private *dev_priv = dev->dev_private;
1950 struct intel_opregion *opregion = &dev_priv->opregion;
1951
1952 if (opregion->vbt)
1953 seq_write(m, opregion->vbt, opregion->vbt_size);
1954
1955 return 0;
1956}
1957
Chris Wilson37811fc2010-08-25 22:45:57 +01001958static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1959{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001960 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001961 struct drm_device *dev = node->minor->dev;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301962 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001963 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001964 int ret;
1965
1966 ret = mutex_lock_interruptible(&dev->struct_mutex);
1967 if (ret)
1968 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001969
Daniel Vetter06957262015-08-10 13:34:08 +02001970#ifdef CONFIG_DRM_FBDEV_EMULATION
Namrta Salonieb13b8402015-11-27 13:43:11 +05301971 if (to_i915(dev)->fbdev) {
1972 fbdev_fb = to_intel_framebuffer(to_i915(dev)->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001973
Namrta Salonieb13b8402015-11-27 13:43:11 +05301974 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1975 fbdev_fb->base.width,
1976 fbdev_fb->base.height,
1977 fbdev_fb->base.depth,
1978 fbdev_fb->base.bits_per_pixel,
1979 fbdev_fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001980 drm_framebuffer_read_refcount(&fbdev_fb->base));
Namrta Salonieb13b8402015-11-27 13:43:11 +05301981 describe_obj(m, fbdev_fb->obj);
1982 seq_putc(m, '\n');
1983 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001984#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001985
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001986 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001987 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301988 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1989 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001990 continue;
1991
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001992 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 +01001993 fb->base.width,
1994 fb->base.height,
1995 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001996 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001997 fb->base.modifier[0],
Dave Airlie747a5982016-04-15 15:10:35 +10001998 drm_framebuffer_read_refcount(&fb->base));
Chris Wilson05394f32010-11-08 19:18:58 +00001999 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01002000 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01002001 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002002 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01002003 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01002004
2005 return 0;
2006}
2007
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002008static void describe_ctx_ringbuf(struct seq_file *m,
2009 struct intel_ringbuffer *ringbuf)
2010{
2011 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
2012 ringbuf->space, ringbuf->head, ringbuf->tail,
2013 ringbuf->last_retired_head);
2014}
2015
Ben Widawskye76d3632011-03-19 18:14:29 -07002016static int i915_context_status(struct seq_file *m, void *unused)
2017{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002018 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07002019 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03002020 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002021 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002022 struct i915_gem_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00002023 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07002024
Daniel Vetterf3d28872014-05-29 23:23:08 +02002025 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002026 if (ret)
2027 return ret;
2028
Ben Widawskya33afea2013-09-17 21:12:45 -07002029 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilson5d1808e2016-04-28 09:56:51 +01002030 seq_printf(m, "HW context %u ", ctx->hw_id);
Chris Wilsond28b99a2016-05-24 14:53:39 +01002031 if (IS_ERR(ctx->file_priv)) {
2032 seq_puts(m, "(deleted) ");
2033 } else if (ctx->file_priv) {
2034 struct pid *pid = ctx->file_priv->file->pid;
2035 struct task_struct *task;
2036
2037 task = get_pid_task(pid, PIDTYPE_PID);
2038 if (task) {
2039 seq_printf(m, "(%s [%d]) ",
2040 task->comm, task->pid);
2041 put_task_struct(task);
2042 }
2043 } else {
2044 seq_puts(m, "(kernel) ");
2045 }
2046
Chris Wilsonbca44d82016-05-24 14:53:41 +01002047 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
2048 seq_putc(m, '\n');
Ben Widawskya33afea2013-09-17 21:12:45 -07002049
Chris Wilsonbca44d82016-05-24 14:53:41 +01002050 for_each_engine(engine, dev_priv) {
2051 struct intel_context *ce = &ctx->engine[engine->id];
2052
2053 seq_printf(m, "%s: ", engine->name);
2054 seq_putc(m, ce->initialised ? 'I' : 'i');
2055 if (ce->state)
2056 describe_obj(m, ce->state);
2057 if (ce->ringbuf)
2058 describe_ctx_ringbuf(m, ce->ringbuf);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002059 seq_putc(m, '\n');
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01002060 }
2061
Ben Widawskya33afea2013-09-17 21:12:45 -07002062 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002063 }
2064
Daniel Vetterf3d28872014-05-29 23:23:08 +02002065 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002066
2067 return 0;
2068}
2069
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002070static void i915_dump_lrc_obj(struct seq_file *m,
Chris Wilsone2efd132016-05-24 14:53:34 +01002071 struct i915_gem_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002072 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002073{
Chris Wilsonbca44d82016-05-24 14:53:41 +01002074 struct drm_i915_gem_object *ctx_obj = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002075 struct page *page;
2076 uint32_t *reg_state;
2077 int j;
2078 unsigned long ggtt_offset = 0;
2079
Chris Wilson7069b142016-04-28 09:56:52 +01002080 seq_printf(m, "CONTEXT: %s %u\n", engine->name, ctx->hw_id);
2081
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002082 if (ctx_obj == NULL) {
Chris Wilson7069b142016-04-28 09:56:52 +01002083 seq_puts(m, "\tNot allocated\n");
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002084 return;
2085 }
2086
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002087 if (!i915_gem_obj_ggtt_bound(ctx_obj))
2088 seq_puts(m, "\tNot bound in GGTT\n");
2089 else
2090 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
2091
2092 if (i915_gem_object_get_pages(ctx_obj)) {
2093 seq_puts(m, "\tFailed to get pages for context object\n");
2094 return;
2095 }
2096
Alex Daid1675192015-08-12 15:43:43 +01002097 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002098 if (!WARN_ON(page == NULL)) {
2099 reg_state = kmap_atomic(page);
2100
2101 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2102 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2103 ggtt_offset + 4096 + (j * 4),
2104 reg_state[j], reg_state[j + 1],
2105 reg_state[j + 2], reg_state[j + 3]);
2106 }
2107 kunmap_atomic(reg_state);
2108 }
2109
2110 seq_putc(m, '\n');
2111}
2112
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002113static int i915_dump_lrc(struct seq_file *m, void *unused)
2114{
2115 struct drm_info_node *node = (struct drm_info_node *) m->private;
2116 struct drm_device *dev = node->minor->dev;
2117 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002118 struct intel_engine_cs *engine;
Chris Wilsone2efd132016-05-24 14:53:34 +01002119 struct i915_gem_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002120 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002121
2122 if (!i915.enable_execlists) {
2123 seq_printf(m, "Logical Ring Contexts are disabled\n");
2124 return 0;
2125 }
2126
2127 ret = mutex_lock_interruptible(&dev->struct_mutex);
2128 if (ret)
2129 return ret;
2130
Dave Gordone28e4042016-01-19 19:02:55 +00002131 list_for_each_entry(ctx, &dev_priv->context_list, link)
Chris Wilson24f1d3c2016-04-28 09:56:53 +01002132 for_each_engine(engine, dev_priv)
2133 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002134
2135 mutex_unlock(&dev->struct_mutex);
2136
2137 return 0;
2138}
2139
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002140static int i915_execlists(struct seq_file *m, void *data)
2141{
2142 struct drm_info_node *node = (struct drm_info_node *)m->private;
2143 struct drm_device *dev = node->minor->dev;
2144 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002145 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002146 u32 status_pointer;
2147 u8 read_pointer;
2148 u8 write_pointer;
2149 u32 status;
2150 u32 ctx_id;
2151 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002152 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002153
2154 if (!i915.enable_execlists) {
2155 seq_puts(m, "Logical Ring Contexts are disabled\n");
2156 return 0;
2157 }
2158
2159 ret = mutex_lock_interruptible(&dev->struct_mutex);
2160 if (ret)
2161 return ret;
2162
Michel Thierryfc0412e2014-10-16 16:13:38 +01002163 intel_runtime_pm_get(dev_priv);
2164
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002165 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002166 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002167 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002168
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002169 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002170
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002171 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2172 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002173 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2174 status, ctx_id);
2175
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002176 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002177 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2178
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002179 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002180 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002181 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002182 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002183 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2184 read_pointer, write_pointer);
2185
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002186 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002187 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2188 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002189
2190 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2191 i, status, ctx_id);
2192 }
2193
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002194 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002195 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002196 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002197 head_req = list_first_entry_or_null(&engine->execlist_queue,
2198 struct drm_i915_gem_request,
2199 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002200 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002201
2202 seq_printf(m, "\t%d requests in queue\n", count);
2203 if (head_req) {
Chris Wilson7069b142016-04-28 09:56:52 +01002204 seq_printf(m, "\tHead request context: %u\n",
2205 head_req->ctx->hw_id);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002206 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002207 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002208 }
2209
2210 seq_putc(m, '\n');
2211 }
2212
Michel Thierryfc0412e2014-10-16 16:13:38 +01002213 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002214 mutex_unlock(&dev->struct_mutex);
2215
2216 return 0;
2217}
2218
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002219static const char *swizzle_string(unsigned swizzle)
2220{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002221 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002222 case I915_BIT_6_SWIZZLE_NONE:
2223 return "none";
2224 case I915_BIT_6_SWIZZLE_9:
2225 return "bit9";
2226 case I915_BIT_6_SWIZZLE_9_10:
2227 return "bit9/bit10";
2228 case I915_BIT_6_SWIZZLE_9_11:
2229 return "bit9/bit11";
2230 case I915_BIT_6_SWIZZLE_9_10_11:
2231 return "bit9/bit10/bit11";
2232 case I915_BIT_6_SWIZZLE_9_17:
2233 return "bit9/bit17";
2234 case I915_BIT_6_SWIZZLE_9_10_17:
2235 return "bit9/bit10/bit17";
2236 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002237 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002238 }
2239
2240 return "bug";
2241}
2242
2243static int i915_swizzle_info(struct seq_file *m, void *data)
2244{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002245 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002246 struct drm_device *dev = node->minor->dev;
2247 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002248 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002249
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002250 ret = mutex_lock_interruptible(&dev->struct_mutex);
2251 if (ret)
2252 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002253 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002254
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002255 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2256 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2257 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2258 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2259
2260 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2261 seq_printf(m, "DDC = 0x%08x\n",
2262 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002263 seq_printf(m, "DDC2 = 0x%08x\n",
2264 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002265 seq_printf(m, "C0DRB3 = 0x%04x\n",
2266 I915_READ16(C0DRB3));
2267 seq_printf(m, "C1DRB3 = 0x%04x\n",
2268 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002269 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002270 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2271 I915_READ(MAD_DIMM_C0));
2272 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2273 I915_READ(MAD_DIMM_C1));
2274 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2275 I915_READ(MAD_DIMM_C2));
2276 seq_printf(m, "TILECTL = 0x%08x\n",
2277 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002278 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002279 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2280 I915_READ(GAMTARBMODE));
2281 else
2282 seq_printf(m, "ARB_MODE = 0x%08x\n",
2283 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002284 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2285 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002286 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002287
2288 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2289 seq_puts(m, "L-shaped memory detected\n");
2290
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002291 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002292 mutex_unlock(&dev->struct_mutex);
2293
2294 return 0;
2295}
2296
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002297static int per_file_ctx(int id, void *ptr, void *data)
2298{
Chris Wilsone2efd132016-05-24 14:53:34 +01002299 struct i915_gem_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002300 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002301 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2302
2303 if (!ppgtt) {
2304 seq_printf(m, " no ppgtt for context %d\n",
2305 ctx->user_handle);
2306 return 0;
2307 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002308
Oscar Mateof83d6512014-05-22 14:13:38 +01002309 if (i915_gem_context_is_default(ctx))
2310 seq_puts(m, " default context:\n");
2311 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002312 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002313 ppgtt->debug_dump(ppgtt, m);
2314
2315 return 0;
2316}
2317
Ben Widawsky77df6772013-11-02 21:07:30 -07002318static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002319{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002320 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002321 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002322 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002323 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002324
Ben Widawsky77df6772013-11-02 21:07:30 -07002325 if (!ppgtt)
2326 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002327
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002328 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002329 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002330 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002331 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002332 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002333 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002334 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002335 }
2336 }
2337}
2338
2339static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2340{
2341 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002342 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002343
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002344 if (IS_GEN6(dev_priv))
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002345 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2346
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002347 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002348 seq_printf(m, "%s\n", engine->name);
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01002349 if (IS_GEN7(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002350 seq_printf(m, "GFX_MODE: 0x%08x\n",
2351 I915_READ(RING_MODE_GEN7(engine)));
2352 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2353 I915_READ(RING_PP_DIR_BASE(engine)));
2354 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2355 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2356 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2357 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002358 }
2359 if (dev_priv->mm.aliasing_ppgtt) {
2360 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2361
Damien Lespiau267f0c92013-06-24 22:59:48 +01002362 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002363 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002364
Ben Widawsky87d60b62013-12-06 14:11:29 -08002365 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002366 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002367
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002368 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002369}
2370
2371static int i915_ppgtt_info(struct seq_file *m, void *data)
2372{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002373 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002374 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002375 struct drm_i915_private *dev_priv = dev->dev_private;
Michel Thierryea91e402015-07-29 17:23:57 +01002376 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002377
2378 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2379 if (ret)
2380 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002381 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002382
2383 if (INTEL_INFO(dev)->gen >= 8)
2384 gen8_ppgtt_info(m, dev);
2385 else if (INTEL_INFO(dev)->gen >= 6)
2386 gen6_ppgtt_info(m, dev);
2387
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002388 mutex_lock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002389 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2390 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002391 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002392
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002393 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002394 if (!task) {
2395 ret = -ESRCH;
Wei Yongjunb0212482016-06-13 23:42:00 +00002396 goto out_unlock;
Dan Carpenter06812762015-10-02 18:14:22 +03002397 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002398 seq_printf(m, "\nproc: %s\n", task->comm);
2399 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002400 idr_for_each(&file_priv->context_idr, per_file_ctx,
2401 (void *)(unsigned long)m);
2402 }
Wei Yongjunb0212482016-06-13 23:42:00 +00002403out_unlock:
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002404 mutex_unlock(&dev->filelist_mutex);
Michel Thierryea91e402015-07-29 17:23:57 +01002405
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002406 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002407 mutex_unlock(&dev->struct_mutex);
2408
Dan Carpenter06812762015-10-02 18:14:22 +03002409 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002410}
2411
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002412static int count_irq_waiters(struct drm_i915_private *i915)
2413{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002414 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002415 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002416
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002417 for_each_engine(engine, i915)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002418 count += engine->irq_refcount;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002419
2420 return count;
2421}
2422
Chris Wilson1854d5c2015-04-07 16:20:32 +01002423static int i915_rps_boost_info(struct seq_file *m, void *data)
2424{
2425 struct drm_info_node *node = m->private;
2426 struct drm_device *dev = node->minor->dev;
2427 struct drm_i915_private *dev_priv = dev->dev_private;
2428 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002429
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002430 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2431 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2432 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2433 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2434 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2435 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2436 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2437 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2438 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002439
2440 mutex_lock(&dev->filelist_mutex);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002441 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002442 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2443 struct drm_i915_file_private *file_priv = file->driver_priv;
2444 struct task_struct *task;
2445
2446 rcu_read_lock();
2447 task = pid_task(file->pid, PIDTYPE_PID);
2448 seq_printf(m, "%s [%d]: %d boosts%s\n",
2449 task ? task->comm : "<unknown>",
2450 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002451 file_priv->rps.boosts,
2452 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002453 rcu_read_unlock();
2454 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002455 seq_printf(m, "Semaphore boosts: %d%s\n",
2456 dev_priv->rps.semaphores.boosts,
2457 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2458 seq_printf(m, "MMIO flip boosts: %d%s\n",
2459 dev_priv->rps.mmioflips.boosts,
2460 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002461 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002462 spin_unlock(&dev_priv->rps.client_lock);
Daniel Vetter1d2ac402016-04-26 19:29:41 +02002463 mutex_unlock(&dev->filelist_mutex);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002464
Chris Wilson8d3afd72015-05-21 21:01:47 +01002465 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002466}
2467
Ben Widawsky63573eb2013-07-04 11:02:07 -07002468static int i915_llc(struct seq_file *m, void *data)
2469{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002470 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002471 struct drm_device *dev = node->minor->dev;
2472 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002473 const bool edram = INTEL_GEN(dev_priv) > 8;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002474
Ben Widawsky63573eb2013-07-04 11:02:07 -07002475 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
Mika Kuoppala3accaf72016-04-13 17:26:43 +03002476 seq_printf(m, "%s: %lluMB\n", edram ? "eDRAM" : "eLLC",
2477 intel_uncore_edram_size(dev_priv)/1024/1024);
Ben Widawsky63573eb2013-07-04 11:02:07 -07002478
2479 return 0;
2480}
2481
Alex Daifdf5d352015-08-12 15:43:37 +01002482static int i915_guc_load_status_info(struct seq_file *m, void *data)
2483{
2484 struct drm_info_node *node = m->private;
2485 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2486 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2487 u32 tmp, i;
2488
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002489 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002490 return 0;
2491
2492 seq_printf(m, "GuC firmware status:\n");
2493 seq_printf(m, "\tpath: %s\n",
2494 guc_fw->guc_fw_path);
2495 seq_printf(m, "\tfetch: %s\n",
2496 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2497 seq_printf(m, "\tload: %s\n",
2498 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2499 seq_printf(m, "\tversion wanted: %d.%d\n",
2500 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2501 seq_printf(m, "\tversion found: %d.%d\n",
2502 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002503 seq_printf(m, "\theader: offset is %d; size = %d\n",
2504 guc_fw->header_offset, guc_fw->header_size);
2505 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2506 guc_fw->ucode_offset, guc_fw->ucode_size);
2507 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2508 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002509
2510 tmp = I915_READ(GUC_STATUS);
2511
2512 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2513 seq_printf(m, "\tBootrom status = 0x%x\n",
2514 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2515 seq_printf(m, "\tuKernel status = 0x%x\n",
2516 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2517 seq_printf(m, "\tMIA Core status = 0x%x\n",
2518 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2519 seq_puts(m, "\nScratch registers:\n");
2520 for (i = 0; i < 16; i++)
2521 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2522
2523 return 0;
2524}
2525
Dave Gordon8b417c22015-08-12 15:43:44 +01002526static void i915_guc_client_info(struct seq_file *m,
2527 struct drm_i915_private *dev_priv,
2528 struct i915_guc_client *client)
2529{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002530 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002531 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002532
2533 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2534 client->priority, client->ctx_index, client->proc_desc_offset);
2535 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2536 client->doorbell_id, client->doorbell_offset, client->cookie);
2537 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2538 client->wq_size, client->wq_offset, client->wq_tail);
2539
Dave Gordon551aaec2016-05-13 15:36:33 +01002540 seq_printf(m, "\tWork queue full: %u\n", client->no_wq_space);
Dave Gordon8b417c22015-08-12 15:43:44 +01002541 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2542 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2543 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2544
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002545 for_each_engine(engine, dev_priv) {
Dave Gordon8b417c22015-08-12 15:43:44 +01002546 seq_printf(m, "\tSubmissions: %llu %s\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002547 client->submissions[engine->guc_id],
2548 engine->name);
2549 tot += client->submissions[engine->guc_id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002550 }
2551 seq_printf(m, "\tTotal: %llu\n", tot);
2552}
2553
2554static int i915_guc_info(struct seq_file *m, void *data)
2555{
2556 struct drm_info_node *node = m->private;
2557 struct drm_device *dev = node->minor->dev;
2558 struct drm_i915_private *dev_priv = dev->dev_private;
2559 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002560 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002561 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002562 u64 total = 0;
2563
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002564 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002565 return 0;
2566
Alex Dai5a843302015-12-02 16:56:29 -08002567 if (mutex_lock_interruptible(&dev->struct_mutex))
2568 return 0;
2569
Dave Gordon8b417c22015-08-12 15:43:44 +01002570 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002571 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002572 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002573 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002574
2575 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002576
2577 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2578 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2579 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2580 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2581 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2582
2583 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002584 for_each_engine(engine, dev_priv) {
Alex Dai397097b2016-01-23 11:58:14 -08002585 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002586 engine->name, guc.submissions[engine->guc_id],
2587 guc.last_seqno[engine->guc_id]);
2588 total += guc.submissions[engine->guc_id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002589 }
2590 seq_printf(m, "\t%s: %llu\n", "Total", total);
2591
2592 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2593 i915_guc_client_info(m, dev_priv, &client);
2594
2595 /* Add more as required ... */
2596
2597 return 0;
2598}
2599
Alex Dai4c7e77f2015-08-12 15:43:40 +01002600static int i915_guc_log_dump(struct seq_file *m, void *data)
2601{
2602 struct drm_info_node *node = m->private;
2603 struct drm_device *dev = node->minor->dev;
2604 struct drm_i915_private *dev_priv = dev->dev_private;
2605 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2606 u32 *log;
2607 int i = 0, pg;
2608
2609 if (!log_obj)
2610 return 0;
2611
2612 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2613 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2614
2615 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2616 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2617 *(log + i), *(log + i + 1),
2618 *(log + i + 2), *(log + i + 3));
2619
2620 kunmap_atomic(log);
2621 }
2622
2623 seq_putc(m, '\n');
2624
2625 return 0;
2626}
2627
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002628static int i915_edp_psr_status(struct seq_file *m, void *data)
2629{
2630 struct drm_info_node *node = m->private;
2631 struct drm_device *dev = node->minor->dev;
2632 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002633 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002634 u32 stat[3];
2635 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002636 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002637
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002638 if (!HAS_PSR(dev)) {
2639 seq_puts(m, "PSR not supported\n");
2640 return 0;
2641 }
2642
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002643 intel_runtime_pm_get(dev_priv);
2644
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002645 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002646 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2647 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002648 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002649 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002650 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2651 dev_priv->psr.busy_frontbuffer_bits);
2652 seq_printf(m, "Re-enable work scheduled: %s\n",
2653 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002654
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002655 if (HAS_DDI(dev))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002656 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002657 else {
2658 for_each_pipe(dev_priv, pipe) {
2659 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2660 VLV_EDP_PSR_CURR_STATE_MASK;
2661 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2662 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2663 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002664 }
2665 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002666
2667 seq_printf(m, "Main link in standby mode: %s\n",
2668 yesno(dev_priv->psr.link_standby));
2669
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002670 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002671
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002672 if (!HAS_DDI(dev))
2673 for_each_pipe(dev_priv, pipe) {
2674 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2675 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2676 seq_printf(m, " pipe %c", pipe_name(pipe));
2677 }
2678 seq_puts(m, "\n");
2679
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002680 /*
2681 * VLV/CHV PSR has no kind of performance counter
2682 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2683 */
2684 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002685 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002686 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002687
2688 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2689 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002690 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002691
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002692 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002693 return 0;
2694}
2695
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002696static int i915_sink_crc(struct seq_file *m, void *data)
2697{
2698 struct drm_info_node *node = m->private;
2699 struct drm_device *dev = node->minor->dev;
2700 struct intel_encoder *encoder;
2701 struct intel_connector *connector;
2702 struct intel_dp *intel_dp = NULL;
2703 int ret;
2704 u8 crc[6];
2705
2706 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002707 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002708
2709 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2710 continue;
2711
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002712 if (!connector->base.encoder)
2713 continue;
2714
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002715 encoder = to_intel_encoder(connector->base.encoder);
2716 if (encoder->type != INTEL_OUTPUT_EDP)
2717 continue;
2718
2719 intel_dp = enc_to_intel_dp(&encoder->base);
2720
2721 ret = intel_dp_sink_crc(intel_dp, crc);
2722 if (ret)
2723 goto out;
2724
2725 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2726 crc[0], crc[1], crc[2],
2727 crc[3], crc[4], crc[5]);
2728 goto out;
2729 }
2730 ret = -ENODEV;
2731out:
2732 drm_modeset_unlock_all(dev);
2733 return ret;
2734}
2735
Jesse Barnesec013e72013-08-20 10:29:23 +01002736static int i915_energy_uJ(struct seq_file *m, void *data)
2737{
2738 struct drm_info_node *node = m->private;
2739 struct drm_device *dev = node->minor->dev;
2740 struct drm_i915_private *dev_priv = dev->dev_private;
2741 u64 power;
2742 u32 units;
2743
2744 if (INTEL_INFO(dev)->gen < 6)
2745 return -ENODEV;
2746
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002747 intel_runtime_pm_get(dev_priv);
2748
Jesse Barnesec013e72013-08-20 10:29:23 +01002749 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2750 power = (power & 0x1f00) >> 8;
2751 units = 1000000 / (1 << power); /* convert to uJ */
2752 power = I915_READ(MCH_SECP_NRG_STTS);
2753 power *= units;
2754
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002755 intel_runtime_pm_put(dev_priv);
2756
Jesse Barnesec013e72013-08-20 10:29:23 +01002757 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002758
2759 return 0;
2760}
2761
Damien Lespiau6455c872015-06-04 18:23:57 +01002762static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002763{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002764 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002765 struct drm_device *dev = node->minor->dev;
2766 struct drm_i915_private *dev_priv = dev->dev_private;
2767
Chris Wilsona156e642016-04-03 14:14:21 +01002768 if (!HAS_RUNTIME_PM(dev_priv))
2769 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002770
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002771 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002772 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002773 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002774#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002775 seq_printf(m, "Usage count: %d\n",
2776 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002777#else
2778 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2779#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002780 seq_printf(m, "PCI device power state: %s [%d]\n",
2781 pci_power_name(dev_priv->dev->pdev->current_state),
2782 dev_priv->dev->pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002783
Jesse Barnesec013e72013-08-20 10:29:23 +01002784 return 0;
2785}
2786
Imre Deak1da51582013-11-25 17:15:35 +02002787static int i915_power_domain_info(struct seq_file *m, void *unused)
2788{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002789 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002790 struct drm_device *dev = node->minor->dev;
2791 struct drm_i915_private *dev_priv = dev->dev_private;
2792 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2793 int i;
2794
2795 mutex_lock(&power_domains->lock);
2796
2797 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2798 for (i = 0; i < power_domains->power_well_count; i++) {
2799 struct i915_power_well *power_well;
2800 enum intel_display_power_domain power_domain;
2801
2802 power_well = &power_domains->power_wells[i];
2803 seq_printf(m, "%-25s %d\n", power_well->name,
2804 power_well->count);
2805
2806 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2807 power_domain++) {
2808 if (!(BIT(power_domain) & power_well->domains))
2809 continue;
2810
2811 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002812 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002813 power_domains->domain_use_count[power_domain]);
2814 }
2815 }
2816
2817 mutex_unlock(&power_domains->lock);
2818
2819 return 0;
2820}
2821
Damien Lespiaub7cec662015-10-27 14:47:01 +02002822static int i915_dmc_info(struct seq_file *m, void *unused)
2823{
2824 struct drm_info_node *node = m->private;
2825 struct drm_device *dev = node->minor->dev;
2826 struct drm_i915_private *dev_priv = dev->dev_private;
2827 struct intel_csr *csr;
2828
2829 if (!HAS_CSR(dev)) {
2830 seq_puts(m, "not supported\n");
2831 return 0;
2832 }
2833
2834 csr = &dev_priv->csr;
2835
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002836 intel_runtime_pm_get(dev_priv);
2837
Damien Lespiaub7cec662015-10-27 14:47:01 +02002838 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2839 seq_printf(m, "path: %s\n", csr->fw_path);
2840
2841 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002842 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002843
2844 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2845 CSR_VERSION_MINOR(csr->version));
2846
Damien Lespiau83372062015-10-30 17:53:32 +02002847 if (IS_SKYLAKE(dev) && csr->version >= CSR_VERSION(1, 6)) {
2848 seq_printf(m, "DC3 -> DC5 count: %d\n",
2849 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2850 seq_printf(m, "DC5 -> DC6 count: %d\n",
2851 I915_READ(SKL_CSR_DC5_DC6_COUNT));
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002852 } else if (IS_BROXTON(dev) && csr->version >= CSR_VERSION(1, 4)) {
2853 seq_printf(m, "DC3 -> DC5 count: %d\n",
2854 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002855 }
2856
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002857out:
2858 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2859 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2860 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2861
Damien Lespiau83372062015-10-30 17:53:32 +02002862 intel_runtime_pm_put(dev_priv);
2863
Damien Lespiaub7cec662015-10-27 14:47:01 +02002864 return 0;
2865}
2866
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002867static void intel_seq_print_mode(struct seq_file *m, int tabs,
2868 struct drm_display_mode *mode)
2869{
2870 int i;
2871
2872 for (i = 0; i < tabs; i++)
2873 seq_putc(m, '\t');
2874
2875 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",
2876 mode->base.id, mode->name,
2877 mode->vrefresh, mode->clock,
2878 mode->hdisplay, mode->hsync_start,
2879 mode->hsync_end, mode->htotal,
2880 mode->vdisplay, mode->vsync_start,
2881 mode->vsync_end, mode->vtotal,
2882 mode->type, mode->flags);
2883}
2884
2885static void intel_encoder_info(struct seq_file *m,
2886 struct intel_crtc *intel_crtc,
2887 struct intel_encoder *intel_encoder)
2888{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002889 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002890 struct drm_device *dev = node->minor->dev;
2891 struct drm_crtc *crtc = &intel_crtc->base;
2892 struct intel_connector *intel_connector;
2893 struct drm_encoder *encoder;
2894
2895 encoder = &intel_encoder->base;
2896 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002897 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002898 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2899 struct drm_connector *connector = &intel_connector->base;
2900 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2901 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002902 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002903 drm_get_connector_status_name(connector->status));
2904 if (connector->status == connector_status_connected) {
2905 struct drm_display_mode *mode = &crtc->mode;
2906 seq_printf(m, ", mode:\n");
2907 intel_seq_print_mode(m, 2, mode);
2908 } else {
2909 seq_putc(m, '\n');
2910 }
2911 }
2912}
2913
2914static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2915{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002916 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002917 struct drm_device *dev = node->minor->dev;
2918 struct drm_crtc *crtc = &intel_crtc->base;
2919 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002920 struct drm_plane_state *plane_state = crtc->primary->state;
2921 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002922
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002923 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002924 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002925 fb->base.id, plane_state->src_x >> 16,
2926 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002927 else
2928 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002929 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2930 intel_encoder_info(m, intel_crtc, intel_encoder);
2931}
2932
2933static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2934{
2935 struct drm_display_mode *mode = panel->fixed_mode;
2936
2937 seq_printf(m, "\tfixed mode:\n");
2938 intel_seq_print_mode(m, 2, mode);
2939}
2940
2941static void intel_dp_info(struct seq_file *m,
2942 struct intel_connector *intel_connector)
2943{
2944 struct intel_encoder *intel_encoder = intel_connector->encoder;
2945 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2946
2947 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002948 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002949 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2950 intel_panel_info(m, &intel_connector->panel);
2951}
2952
2953static void intel_hdmi_info(struct seq_file *m,
2954 struct intel_connector *intel_connector)
2955{
2956 struct intel_encoder *intel_encoder = intel_connector->encoder;
2957 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2958
Jani Nikula742f4912015-09-03 11:16:09 +03002959 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002960}
2961
2962static void intel_lvds_info(struct seq_file *m,
2963 struct intel_connector *intel_connector)
2964{
2965 intel_panel_info(m, &intel_connector->panel);
2966}
2967
2968static void intel_connector_info(struct seq_file *m,
2969 struct drm_connector *connector)
2970{
2971 struct intel_connector *intel_connector = to_intel_connector(connector);
2972 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002973 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002974
2975 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002976 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002977 drm_get_connector_status_name(connector->status));
2978 if (connector->status == connector_status_connected) {
2979 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2980 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2981 connector->display_info.width_mm,
2982 connector->display_info.height_mm);
2983 seq_printf(m, "\tsubpixel order: %s\n",
2984 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2985 seq_printf(m, "\tCEA rev: %d\n",
2986 connector->display_info.cea_rev);
2987 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002988 if (intel_encoder) {
2989 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2990 intel_encoder->type == INTEL_OUTPUT_EDP)
2991 intel_dp_info(m, intel_connector);
2992 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2993 intel_hdmi_info(m, intel_connector);
2994 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2995 intel_lvds_info(m, intel_connector);
2996 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002997
Jesse Barnesf103fc72014-02-20 12:39:57 -08002998 seq_printf(m, "\tmodes:\n");
2999 list_for_each_entry(mode, &connector->modes, head)
3000 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003001}
3002
Chris Wilson065f2ec2014-03-12 09:13:13 +00003003static bool cursor_active(struct drm_device *dev, int pipe)
3004{
3005 struct drm_i915_private *dev_priv = dev->dev_private;
3006 u32 state;
3007
3008 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03003009 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003010 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003011 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003012
3013 return state;
3014}
3015
3016static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
3017{
3018 struct drm_i915_private *dev_priv = dev->dev_private;
3019 u32 pos;
3020
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03003021 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00003022
3023 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
3024 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
3025 *x = -*x;
3026
3027 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
3028 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
3029 *y = -*y;
3030
3031 return cursor_active(dev, pipe);
3032}
3033
Robert Fekete3abc4e02015-10-27 16:58:32 +01003034static const char *plane_type(enum drm_plane_type type)
3035{
3036 switch (type) {
3037 case DRM_PLANE_TYPE_OVERLAY:
3038 return "OVL";
3039 case DRM_PLANE_TYPE_PRIMARY:
3040 return "PRI";
3041 case DRM_PLANE_TYPE_CURSOR:
3042 return "CUR";
3043 /*
3044 * Deliberately omitting default: to generate compiler warnings
3045 * when a new drm_plane_type gets added.
3046 */
3047 }
3048
3049 return "unknown";
3050}
3051
3052static const char *plane_rotation(unsigned int rotation)
3053{
3054 static char buf[48];
3055 /*
3056 * According to doc only one DRM_ROTATE_ is allowed but this
3057 * will print them all to visualize if the values are misused
3058 */
3059 snprintf(buf, sizeof(buf),
3060 "%s%s%s%s%s%s(0x%08x)",
3061 (rotation & BIT(DRM_ROTATE_0)) ? "0 " : "",
3062 (rotation & BIT(DRM_ROTATE_90)) ? "90 " : "",
3063 (rotation & BIT(DRM_ROTATE_180)) ? "180 " : "",
3064 (rotation & BIT(DRM_ROTATE_270)) ? "270 " : "",
3065 (rotation & BIT(DRM_REFLECT_X)) ? "FLIPX " : "",
3066 (rotation & BIT(DRM_REFLECT_Y)) ? "FLIPY " : "",
3067 rotation);
3068
3069 return buf;
3070}
3071
3072static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3073{
3074 struct drm_info_node *node = m->private;
3075 struct drm_device *dev = node->minor->dev;
3076 struct intel_plane *intel_plane;
3077
3078 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3079 struct drm_plane_state *state;
3080 struct drm_plane *plane = &intel_plane->base;
3081
3082 if (!plane->state) {
3083 seq_puts(m, "plane->state is NULL!\n");
3084 continue;
3085 }
3086
3087 state = plane->state;
3088
3089 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",
3090 plane->base.id,
3091 plane_type(intel_plane->base.type),
3092 state->crtc_x, state->crtc_y,
3093 state->crtc_w, state->crtc_h,
3094 (state->src_x >> 16),
3095 ((state->src_x & 0xffff) * 15625) >> 10,
3096 (state->src_y >> 16),
3097 ((state->src_y & 0xffff) * 15625) >> 10,
3098 (state->src_w >> 16),
3099 ((state->src_w & 0xffff) * 15625) >> 10,
3100 (state->src_h >> 16),
3101 ((state->src_h & 0xffff) * 15625) >> 10,
3102 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3103 plane_rotation(state->rotation));
3104 }
3105}
3106
3107static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3108{
3109 struct intel_crtc_state *pipe_config;
3110 int num_scalers = intel_crtc->num_scalers;
3111 int i;
3112
3113 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3114
3115 /* Not all platformas have a scaler */
3116 if (num_scalers) {
3117 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3118 num_scalers,
3119 pipe_config->scaler_state.scaler_users,
3120 pipe_config->scaler_state.scaler_id);
3121
3122 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3123 struct intel_scaler *sc =
3124 &pipe_config->scaler_state.scalers[i];
3125
3126 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3127 i, yesno(sc->in_use), sc->mode);
3128 }
3129 seq_puts(m, "\n");
3130 } else {
3131 seq_puts(m, "\tNo scalers available on this platform\n");
3132 }
3133}
3134
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003135static int i915_display_info(struct seq_file *m, void *unused)
3136{
Damien Lespiau9f25d002014-05-13 15:30:28 +01003137 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003138 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003139 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003140 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003141 struct drm_connector *connector;
3142
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003143 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003144 drm_modeset_lock_all(dev);
3145 seq_printf(m, "CRTC info\n");
3146 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003147 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003148 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003149 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00003150 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003151
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003152 pipe_config = to_intel_crtc_state(crtc->base.state);
3153
Robert Fekete3abc4e02015-10-27 16:58:32 +01003154 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00003155 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003156 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003157 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3158 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3159
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003160 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00003161 intel_crtc_info(m, crtc);
3162
Paulo Zanonia23dc652014-04-01 14:55:11 -03003163 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003164 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 +03003165 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003166 x, y, crtc->base.cursor->state->crtc_w,
3167 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003168 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003169 intel_scaler_info(m, crtc);
3170 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003171 }
Daniel Vettercace8412014-05-22 17:56:31 +02003172
3173 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3174 yesno(!crtc->cpu_fifo_underrun_disabled),
3175 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003176 }
3177
3178 seq_printf(m, "\n");
3179 seq_printf(m, "Connector info\n");
3180 seq_printf(m, "--------------\n");
3181 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3182 intel_connector_info(m, connector);
3183 }
3184 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003185 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003186
3187 return 0;
3188}
3189
Ben Widawskye04934c2014-06-30 09:53:42 -07003190static int i915_semaphore_status(struct seq_file *m, void *unused)
3191{
3192 struct drm_info_node *node = (struct drm_info_node *) m->private;
3193 struct drm_device *dev = node->minor->dev;
3194 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003195 struct intel_engine_cs *engine;
Ben Widawskye04934c2014-06-30 09:53:42 -07003196 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
Dave Gordonc3232b12016-03-23 18:19:53 +00003197 enum intel_engine_id id;
3198 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003199
Chris Wilsonc0336662016-05-06 15:40:21 +01003200 if (!i915_semaphore_is_enabled(dev_priv)) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003201 seq_puts(m, "Semaphores are disabled\n");
3202 return 0;
3203 }
3204
3205 ret = mutex_lock_interruptible(&dev->struct_mutex);
3206 if (ret)
3207 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003208 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003209
3210 if (IS_BROADWELL(dev)) {
3211 struct page *page;
3212 uint64_t *seqno;
3213
3214 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3215
3216 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003217 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003218 uint64_t offset;
3219
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003220 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003221
3222 seq_puts(m, " Last signal:");
3223 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003224 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003225 seq_printf(m, "0x%08llx (0x%02llx) ",
3226 seqno[offset], offset * 8);
3227 }
3228 seq_putc(m, '\n');
3229
3230 seq_puts(m, " Last wait: ");
3231 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003232 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003233 seq_printf(m, "0x%08llx (0x%02llx) ",
3234 seqno[offset], offset * 8);
3235 }
3236 seq_putc(m, '\n');
3237
3238 }
3239 kunmap_atomic(seqno);
3240 } else {
3241 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003242 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003243 for (j = 0; j < num_rings; j++)
3244 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003245 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003246 seq_putc(m, '\n');
3247 }
3248
3249 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003250 for_each_engine(engine, dev_priv) {
3251 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003252 seq_printf(m, " 0x%08x ",
3253 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003254 seq_putc(m, '\n');
3255 }
3256 seq_putc(m, '\n');
3257
Paulo Zanoni03872062014-07-09 14:31:57 -03003258 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003259 mutex_unlock(&dev->struct_mutex);
3260 return 0;
3261}
3262
Daniel Vetter728e29d2014-06-25 22:01:53 +03003263static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3264{
3265 struct drm_info_node *node = (struct drm_info_node *) m->private;
3266 struct drm_device *dev = node->minor->dev;
3267 struct drm_i915_private *dev_priv = dev->dev_private;
3268 int i;
3269
3270 drm_modeset_lock_all(dev);
3271 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3272 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3273
3274 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003275 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3276 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003277 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003278 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3279 seq_printf(m, " dpll_md: 0x%08x\n",
3280 pll->config.hw_state.dpll_md);
3281 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3282 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3283 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003284 }
3285 drm_modeset_unlock_all(dev);
3286
3287 return 0;
3288}
3289
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003290static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003291{
3292 int i;
3293 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003294 struct intel_engine_cs *engine;
Arun Siluvery888b5992014-08-26 14:44:51 +01003295 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;
Arun Siluvery33136b02016-01-21 21:43:47 +00003298 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003299 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003300
Arun Siluvery888b5992014-08-26 14:44:51 +01003301 ret = mutex_lock_interruptible(&dev->struct_mutex);
3302 if (ret)
3303 return ret;
3304
3305 intel_runtime_pm_get(dev_priv);
3306
Arun Siluvery33136b02016-01-21 21:43:47 +00003307 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003308 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003309 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003310 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003311 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003312 i915_reg_t addr;
3313 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003314 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003315
Arun Siluvery33136b02016-01-21 21:43:47 +00003316 addr = workarounds->reg[i].addr;
3317 mask = workarounds->reg[i].mask;
3318 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003319 read = I915_READ(addr);
3320 ok = (value & mask) == (read & mask);
3321 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 +02003322 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003323 }
3324
3325 intel_runtime_pm_put(dev_priv);
3326 mutex_unlock(&dev->struct_mutex);
3327
3328 return 0;
3329}
3330
Damien Lespiauc5511e42014-11-04 17:06:51 +00003331static int i915_ddb_info(struct seq_file *m, void *unused)
3332{
3333 struct drm_info_node *node = m->private;
3334 struct drm_device *dev = node->minor->dev;
3335 struct drm_i915_private *dev_priv = dev->dev_private;
3336 struct skl_ddb_allocation *ddb;
3337 struct skl_ddb_entry *entry;
3338 enum pipe pipe;
3339 int plane;
3340
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003341 if (INTEL_INFO(dev)->gen < 9)
3342 return 0;
3343
Damien Lespiauc5511e42014-11-04 17:06:51 +00003344 drm_modeset_lock_all(dev);
3345
3346 ddb = &dev_priv->wm.skl_hw.ddb;
3347
3348 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3349
3350 for_each_pipe(dev_priv, pipe) {
3351 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3352
Damien Lespiaudd740782015-02-28 14:54:08 +00003353 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003354 entry = &ddb->plane[pipe][plane];
3355 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3356 entry->start, entry->end,
3357 skl_ddb_entry_size(entry));
3358 }
3359
Matt Roper4969d332015-09-24 15:53:10 -07003360 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003361 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3362 entry->end, skl_ddb_entry_size(entry));
3363 }
3364
3365 drm_modeset_unlock_all(dev);
3366
3367 return 0;
3368}
3369
Vandana Kannana54746e2015-03-03 20:53:10 +05303370static void drrs_status_per_crtc(struct seq_file *m,
3371 struct drm_device *dev, struct intel_crtc *intel_crtc)
3372{
3373 struct intel_encoder *intel_encoder;
3374 struct drm_i915_private *dev_priv = dev->dev_private;
3375 struct i915_drrs *drrs = &dev_priv->drrs;
3376 int vrefresh = 0;
3377
3378 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3379 /* Encoder connected on this CRTC */
3380 switch (intel_encoder->type) {
3381 case INTEL_OUTPUT_EDP:
3382 seq_puts(m, "eDP:\n");
3383 break;
3384 case INTEL_OUTPUT_DSI:
3385 seq_puts(m, "DSI:\n");
3386 break;
3387 case INTEL_OUTPUT_HDMI:
3388 seq_puts(m, "HDMI:\n");
3389 break;
3390 case INTEL_OUTPUT_DISPLAYPORT:
3391 seq_puts(m, "DP:\n");
3392 break;
3393 default:
3394 seq_printf(m, "Other encoder (id=%d).\n",
3395 intel_encoder->type);
3396 return;
3397 }
3398 }
3399
3400 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3401 seq_puts(m, "\tVBT: DRRS_type: Static");
3402 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3403 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3404 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3405 seq_puts(m, "\tVBT: DRRS_type: None");
3406 else
3407 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3408
3409 seq_puts(m, "\n\n");
3410
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003411 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303412 struct intel_panel *panel;
3413
3414 mutex_lock(&drrs->mutex);
3415 /* DRRS Supported */
3416 seq_puts(m, "\tDRRS Supported: Yes\n");
3417
3418 /* disable_drrs() will make drrs->dp NULL */
3419 if (!drrs->dp) {
3420 seq_puts(m, "Idleness DRRS: Disabled");
3421 mutex_unlock(&drrs->mutex);
3422 return;
3423 }
3424
3425 panel = &drrs->dp->attached_connector->panel;
3426 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3427 drrs->busy_frontbuffer_bits);
3428
3429 seq_puts(m, "\n\t\t");
3430 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3431 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3432 vrefresh = panel->fixed_mode->vrefresh;
3433 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3434 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3435 vrefresh = panel->downclock_mode->vrefresh;
3436 } else {
3437 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3438 drrs->refresh_rate_type);
3439 mutex_unlock(&drrs->mutex);
3440 return;
3441 }
3442 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3443
3444 seq_puts(m, "\n\t\t");
3445 mutex_unlock(&drrs->mutex);
3446 } else {
3447 /* DRRS not supported. Print the VBT parameter*/
3448 seq_puts(m, "\tDRRS Supported : No");
3449 }
3450 seq_puts(m, "\n");
3451}
3452
3453static int i915_drrs_status(struct seq_file *m, void *unused)
3454{
3455 struct drm_info_node *node = m->private;
3456 struct drm_device *dev = node->minor->dev;
3457 struct intel_crtc *intel_crtc;
3458 int active_crtc_cnt = 0;
3459
3460 for_each_intel_crtc(dev, intel_crtc) {
3461 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3462
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003463 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303464 active_crtc_cnt++;
3465 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3466
3467 drrs_status_per_crtc(m, dev, intel_crtc);
3468 }
3469
3470 drm_modeset_unlock(&intel_crtc->base.mutex);
3471 }
3472
3473 if (!active_crtc_cnt)
3474 seq_puts(m, "No active crtc found\n");
3475
3476 return 0;
3477}
3478
Damien Lespiau07144422013-10-15 18:55:40 +01003479struct pipe_crc_info {
3480 const char *name;
3481 struct drm_device *dev;
3482 enum pipe pipe;
3483};
3484
Dave Airlie11bed952014-05-12 15:22:27 +10003485static int i915_dp_mst_info(struct seq_file *m, void *unused)
3486{
3487 struct drm_info_node *node = (struct drm_info_node *) m->private;
3488 struct drm_device *dev = node->minor->dev;
3489 struct drm_encoder *encoder;
3490 struct intel_encoder *intel_encoder;
3491 struct intel_digital_port *intel_dig_port;
3492 drm_modeset_lock_all(dev);
3493 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3494 intel_encoder = to_intel_encoder(encoder);
3495 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3496 continue;
3497 intel_dig_port = enc_to_dig_port(encoder);
3498 if (!intel_dig_port->dp.can_mst)
3499 continue;
Jim Bride40ae80c2016-04-14 10:18:37 -07003500 seq_printf(m, "MST Source Port %c\n",
3501 port_name(intel_dig_port->port));
Dave Airlie11bed952014-05-12 15:22:27 +10003502 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3503 }
3504 drm_modeset_unlock_all(dev);
3505 return 0;
3506}
3507
Damien Lespiau07144422013-10-15 18:55:40 +01003508static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003509{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003510 struct pipe_crc_info *info = inode->i_private;
3511 struct drm_i915_private *dev_priv = info->dev->dev_private;
3512 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3513
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003514 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3515 return -ENODEV;
3516
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003517 spin_lock_irq(&pipe_crc->lock);
3518
3519 if (pipe_crc->opened) {
3520 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003521 return -EBUSY; /* already open */
3522 }
3523
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003524 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003525 filep->private_data = inode->i_private;
3526
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003527 spin_unlock_irq(&pipe_crc->lock);
3528
Damien Lespiau07144422013-10-15 18:55:40 +01003529 return 0;
3530}
3531
3532static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3533{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003534 struct pipe_crc_info *info = inode->i_private;
3535 struct drm_i915_private *dev_priv = info->dev->dev_private;
3536 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3537
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003538 spin_lock_irq(&pipe_crc->lock);
3539 pipe_crc->opened = false;
3540 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003541
Damien Lespiau07144422013-10-15 18:55:40 +01003542 return 0;
3543}
3544
3545/* (6 fields, 8 chars each, space separated (5) + '\n') */
3546#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3547/* account for \'0' */
3548#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3549
3550static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3551{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003552 assert_spin_locked(&pipe_crc->lock);
3553 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3554 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003555}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003556
Damien Lespiau07144422013-10-15 18:55:40 +01003557static ssize_t
3558i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3559 loff_t *pos)
3560{
3561 struct pipe_crc_info *info = filep->private_data;
3562 struct drm_device *dev = info->dev;
3563 struct drm_i915_private *dev_priv = dev->dev_private;
3564 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3565 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003566 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003567 ssize_t bytes_read;
3568
3569 /*
3570 * Don't allow user space to provide buffers not big enough to hold
3571 * a line of data.
3572 */
3573 if (count < PIPE_CRC_LINE_LEN)
3574 return -EINVAL;
3575
3576 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3577 return 0;
3578
3579 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003580 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003581 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003582 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003583
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003584 if (filep->f_flags & O_NONBLOCK) {
3585 spin_unlock_irq(&pipe_crc->lock);
3586 return -EAGAIN;
3587 }
3588
3589 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3590 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3591 if (ret) {
3592 spin_unlock_irq(&pipe_crc->lock);
3593 return ret;
3594 }
Damien Lespiau07144422013-10-15 18:55:40 +01003595 }
3596
3597 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003598 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003599
Damien Lespiau07144422013-10-15 18:55:40 +01003600 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003601 while (n_entries > 0) {
3602 struct intel_pipe_crc_entry *entry =
3603 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003604 int ret;
3605
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003606 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3607 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3608 break;
3609
3610 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3611 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3612
Damien Lespiau07144422013-10-15 18:55:40 +01003613 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3614 "%8u %8x %8x %8x %8x %8x\n",
3615 entry->frame, entry->crc[0],
3616 entry->crc[1], entry->crc[2],
3617 entry->crc[3], entry->crc[4]);
3618
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003619 spin_unlock_irq(&pipe_crc->lock);
3620
3621 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003622 if (ret == PIPE_CRC_LINE_LEN)
3623 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003624
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003625 user_buf += PIPE_CRC_LINE_LEN;
3626 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003627
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003628 spin_lock_irq(&pipe_crc->lock);
3629 }
3630
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003631 spin_unlock_irq(&pipe_crc->lock);
3632
Damien Lespiau07144422013-10-15 18:55:40 +01003633 return bytes_read;
3634}
3635
3636static const struct file_operations i915_pipe_crc_fops = {
3637 .owner = THIS_MODULE,
3638 .open = i915_pipe_crc_open,
3639 .read = i915_pipe_crc_read,
3640 .release = i915_pipe_crc_release,
3641};
3642
3643static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3644 {
3645 .name = "i915_pipe_A_crc",
3646 .pipe = PIPE_A,
3647 },
3648 {
3649 .name = "i915_pipe_B_crc",
3650 .pipe = PIPE_B,
3651 },
3652 {
3653 .name = "i915_pipe_C_crc",
3654 .pipe = PIPE_C,
3655 },
3656};
3657
3658static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3659 enum pipe pipe)
3660{
3661 struct drm_device *dev = minor->dev;
3662 struct dentry *ent;
3663 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3664
3665 info->dev = dev;
3666 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3667 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003668 if (!ent)
3669 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003670
3671 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003672}
3673
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003674static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003675 "none",
3676 "plane1",
3677 "plane2",
3678 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003679 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003680 "TV",
3681 "DP-B",
3682 "DP-C",
3683 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003684 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003685};
3686
3687static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3688{
3689 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3690 return pipe_crc_sources[source];
3691}
3692
Damien Lespiaubd9db022013-10-15 18:55:36 +01003693static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003694{
3695 struct drm_device *dev = m->private;
3696 struct drm_i915_private *dev_priv = dev->dev_private;
3697 int i;
3698
3699 for (i = 0; i < I915_MAX_PIPES; i++)
3700 seq_printf(m, "%c %s\n", pipe_name(i),
3701 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3702
3703 return 0;
3704}
3705
Damien Lespiaubd9db022013-10-15 18:55:36 +01003706static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003707{
3708 struct drm_device *dev = inode->i_private;
3709
Damien Lespiaubd9db022013-10-15 18:55:36 +01003710 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003711}
3712
Daniel Vetter46a19182013-11-01 10:50:20 +01003713static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003714 uint32_t *val)
3715{
Daniel Vetter46a19182013-11-01 10:50:20 +01003716 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3717 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3718
3719 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003720 case INTEL_PIPE_CRC_SOURCE_PIPE:
3721 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3722 break;
3723 case INTEL_PIPE_CRC_SOURCE_NONE:
3724 *val = 0;
3725 break;
3726 default:
3727 return -EINVAL;
3728 }
3729
3730 return 0;
3731}
3732
Daniel Vetter46a19182013-11-01 10:50:20 +01003733static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3734 enum intel_pipe_crc_source *source)
3735{
3736 struct intel_encoder *encoder;
3737 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003738 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003739 int ret = 0;
3740
3741 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3742
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003743 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003744 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003745 if (!encoder->base.crtc)
3746 continue;
3747
3748 crtc = to_intel_crtc(encoder->base.crtc);
3749
3750 if (crtc->pipe != pipe)
3751 continue;
3752
3753 switch (encoder->type) {
3754 case INTEL_OUTPUT_TVOUT:
3755 *source = INTEL_PIPE_CRC_SOURCE_TV;
3756 break;
3757 case INTEL_OUTPUT_DISPLAYPORT:
3758 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003759 dig_port = enc_to_dig_port(&encoder->base);
3760 switch (dig_port->port) {
3761 case PORT_B:
3762 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3763 break;
3764 case PORT_C:
3765 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3766 break;
3767 case PORT_D:
3768 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3769 break;
3770 default:
3771 WARN(1, "nonexisting DP port %c\n",
3772 port_name(dig_port->port));
3773 break;
3774 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003775 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003776 default:
3777 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003778 }
3779 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003780 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003781
3782 return ret;
3783}
3784
3785static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3786 enum pipe pipe,
3787 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003788 uint32_t *val)
3789{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003790 struct drm_i915_private *dev_priv = dev->dev_private;
3791 bool need_stable_symbols = false;
3792
Daniel Vetter46a19182013-11-01 10:50:20 +01003793 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3794 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3795 if (ret)
3796 return ret;
3797 }
3798
3799 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003800 case INTEL_PIPE_CRC_SOURCE_PIPE:
3801 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3802 break;
3803 case INTEL_PIPE_CRC_SOURCE_DP_B:
3804 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003805 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003806 break;
3807 case INTEL_PIPE_CRC_SOURCE_DP_C:
3808 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003809 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003810 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003811 case INTEL_PIPE_CRC_SOURCE_DP_D:
3812 if (!IS_CHERRYVIEW(dev))
3813 return -EINVAL;
3814 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3815 need_stable_symbols = true;
3816 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003817 case INTEL_PIPE_CRC_SOURCE_NONE:
3818 *val = 0;
3819 break;
3820 default:
3821 return -EINVAL;
3822 }
3823
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003824 /*
3825 * When the pipe CRC tap point is after the transcoders we need
3826 * to tweak symbol-level features to produce a deterministic series of
3827 * symbols for a given frame. We need to reset those features only once
3828 * a frame (instead of every nth symbol):
3829 * - DC-balance: used to ensure a better clock recovery from the data
3830 * link (SDVO)
3831 * - DisplayPort scrambling: used for EMI reduction
3832 */
3833 if (need_stable_symbols) {
3834 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3835
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003836 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003837 switch (pipe) {
3838 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003839 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003840 break;
3841 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003842 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003843 break;
3844 case PIPE_C:
3845 tmp |= PIPE_C_SCRAMBLE_RESET;
3846 break;
3847 default:
3848 return -EINVAL;
3849 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003850 I915_WRITE(PORT_DFT2_G4X, tmp);
3851 }
3852
Daniel Vetter7ac01292013-10-18 16:37:06 +02003853 return 0;
3854}
3855
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003856static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003857 enum pipe pipe,
3858 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003859 uint32_t *val)
3860{
Daniel Vetter84093602013-11-01 10:50:21 +01003861 struct drm_i915_private *dev_priv = dev->dev_private;
3862 bool need_stable_symbols = false;
3863
Daniel Vetter46a19182013-11-01 10:50:20 +01003864 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3865 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3866 if (ret)
3867 return ret;
3868 }
3869
3870 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003871 case INTEL_PIPE_CRC_SOURCE_PIPE:
3872 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3873 break;
3874 case INTEL_PIPE_CRC_SOURCE_TV:
3875 if (!SUPPORTS_TV(dev))
3876 return -EINVAL;
3877 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3878 break;
3879 case INTEL_PIPE_CRC_SOURCE_DP_B:
3880 if (!IS_G4X(dev))
3881 return -EINVAL;
3882 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003883 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003884 break;
3885 case INTEL_PIPE_CRC_SOURCE_DP_C:
3886 if (!IS_G4X(dev))
3887 return -EINVAL;
3888 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003889 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003890 break;
3891 case INTEL_PIPE_CRC_SOURCE_DP_D:
3892 if (!IS_G4X(dev))
3893 return -EINVAL;
3894 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003895 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003896 break;
3897 case INTEL_PIPE_CRC_SOURCE_NONE:
3898 *val = 0;
3899 break;
3900 default:
3901 return -EINVAL;
3902 }
3903
Daniel Vetter84093602013-11-01 10:50:21 +01003904 /*
3905 * When the pipe CRC tap point is after the transcoders we need
3906 * to tweak symbol-level features to produce a deterministic series of
3907 * symbols for a given frame. We need to reset those features only once
3908 * a frame (instead of every nth symbol):
3909 * - DC-balance: used to ensure a better clock recovery from the data
3910 * link (SDVO)
3911 * - DisplayPort scrambling: used for EMI reduction
3912 */
3913 if (need_stable_symbols) {
3914 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3915
3916 WARN_ON(!IS_G4X(dev));
3917
3918 I915_WRITE(PORT_DFT_I9XX,
3919 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3920
3921 if (pipe == PIPE_A)
3922 tmp |= PIPE_A_SCRAMBLE_RESET;
3923 else
3924 tmp |= PIPE_B_SCRAMBLE_RESET;
3925
3926 I915_WRITE(PORT_DFT2_G4X, tmp);
3927 }
3928
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003929 return 0;
3930}
3931
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003932static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3933 enum pipe pipe)
3934{
3935 struct drm_i915_private *dev_priv = dev->dev_private;
3936 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3937
Ville Syrjäläeb736672014-12-09 21:28:28 +02003938 switch (pipe) {
3939 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003940 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003941 break;
3942 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003943 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003944 break;
3945 case PIPE_C:
3946 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3947 break;
3948 default:
3949 return;
3950 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003951 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3952 tmp &= ~DC_BALANCE_RESET_VLV;
3953 I915_WRITE(PORT_DFT2_G4X, tmp);
3954
3955}
3956
Daniel Vetter84093602013-11-01 10:50:21 +01003957static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3958 enum pipe pipe)
3959{
3960 struct drm_i915_private *dev_priv = dev->dev_private;
3961 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3962
3963 if (pipe == PIPE_A)
3964 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3965 else
3966 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3967 I915_WRITE(PORT_DFT2_G4X, tmp);
3968
3969 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3970 I915_WRITE(PORT_DFT_I9XX,
3971 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3972 }
3973}
3974
Daniel Vetter46a19182013-11-01 10:50:20 +01003975static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003976 uint32_t *val)
3977{
Daniel Vetter46a19182013-11-01 10:50:20 +01003978 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3979 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3980
3981 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003982 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3983 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3984 break;
3985 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3986 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3987 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003988 case INTEL_PIPE_CRC_SOURCE_PIPE:
3989 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3990 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003991 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003992 *val = 0;
3993 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003994 default:
3995 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003996 }
3997
3998 return 0;
3999}
4000
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004001static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004002{
4003 struct drm_i915_private *dev_priv = dev->dev_private;
4004 struct intel_crtc *crtc =
4005 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004006 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004007 struct drm_atomic_state *state;
4008 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004009
4010 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004011 state = drm_atomic_state_alloc(dev);
4012 if (!state) {
4013 ret = -ENOMEM;
4014 goto out;
4015 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004016
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004017 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
4018 pipe_config = intel_atomic_get_crtc_state(state, crtc);
4019 if (IS_ERR(pipe_config)) {
4020 ret = PTR_ERR(pipe_config);
4021 goto out;
4022 }
4023
4024 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004025 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004026 pipe_config->pch_pfit.enabled != enable)
4027 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02004028
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004029 ret = drm_atomic_commit(state);
4030out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004031 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004032 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
4033 if (ret)
4034 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004035}
4036
4037static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
4038 enum pipe pipe,
4039 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004040 uint32_t *val)
4041{
Daniel Vetter46a19182013-11-01 10:50:20 +01004042 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
4043 *source = INTEL_PIPE_CRC_SOURCE_PF;
4044
4045 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004046 case INTEL_PIPE_CRC_SOURCE_PLANE1:
4047 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
4048 break;
4049 case INTEL_PIPE_CRC_SOURCE_PLANE2:
4050 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
4051 break;
4052 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004053 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004054 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004055
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004056 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4057 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004058 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004059 *val = 0;
4060 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004061 default:
4062 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004063 }
4064
4065 return 0;
4066}
4067
Daniel Vetter926321d2013-10-16 13:30:34 +02004068static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
4069 enum intel_pipe_crc_source source)
4070{
4071 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004072 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004073 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
4074 pipe));
Imre Deake1296492016-02-12 18:55:17 +02004075 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004076 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004077 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004078
Damien Lespiaucc3da172013-10-15 18:55:31 +01004079 if (pipe_crc->source == source)
4080 return 0;
4081
Damien Lespiauae676fc2013-10-15 18:55:32 +01004082 /* forbid changing the source without going back to 'none' */
4083 if (pipe_crc->source && source)
4084 return -EINVAL;
4085
Imre Deake1296492016-02-12 18:55:17 +02004086 power_domain = POWER_DOMAIN_PIPE(pipe);
4087 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004088 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4089 return -EIO;
4090 }
4091
Daniel Vetter52f843f2013-10-21 17:26:38 +02004092 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004093 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02004094 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01004095 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Wayne Boyer666a4532015-12-09 12:29:35 -08004096 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004097 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004098 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004099 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004100 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004101 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004102
4103 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004104 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004105
Damien Lespiau4b584362013-10-15 18:55:33 +01004106 /* none -> real source transition */
4107 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004108 struct intel_pipe_crc_entry *entries;
4109
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004110 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4111 pipe_name(pipe), pipe_crc_source_name(source));
4112
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004113 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4114 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004115 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004116 if (!entries) {
4117 ret = -ENOMEM;
4118 goto out;
4119 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004120
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004121 /*
4122 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4123 * enabled and disabled dynamically based on package C states,
4124 * user space can't make reliable use of the CRCs, so let's just
4125 * completely disable it.
4126 */
4127 hsw_disable_ips(crtc);
4128
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004129 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004130 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004131 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004132 pipe_crc->head = 0;
4133 pipe_crc->tail = 0;
4134 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004135 }
4136
Damien Lespiaucc3da172013-10-15 18:55:31 +01004137 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004138
Daniel Vetter926321d2013-10-16 13:30:34 +02004139 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4140 POSTING_READ(PIPE_CRC_CTL(pipe));
4141
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004142 /* real source -> none transition */
4143 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004144 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004145 struct intel_crtc *crtc =
4146 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004147
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004148 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4149 pipe_name(pipe));
4150
Daniel Vettera33d7102014-06-06 08:22:08 +02004151 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004152 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004153 intel_wait_for_vblank(dev, pipe);
4154 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004155
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004156 spin_lock_irq(&pipe_crc->lock);
4157 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004158 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004159 pipe_crc->head = 0;
4160 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004161 spin_unlock_irq(&pipe_crc->lock);
4162
4163 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004164
4165 if (IS_G4X(dev))
4166 g4x_undo_pipe_scramble_reset(dev, pipe);
Wayne Boyer666a4532015-12-09 12:29:35 -08004167 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004168 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004169 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004170 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004171
4172 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004173 }
4174
Imre Deake1296492016-02-12 18:55:17 +02004175 ret = 0;
4176
4177out:
4178 intel_display_power_put(dev_priv, power_domain);
4179
4180 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004181}
4182
4183/*
4184 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004185 * command: wsp* object wsp+ name wsp+ source wsp*
4186 * object: 'pipe'
4187 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004188 * source: (none | plane1 | plane2 | pf)
4189 * wsp: (#0x20 | #0x9 | #0xA)+
4190 *
4191 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004192 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4193 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004194 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004195static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004196{
4197 int n_words = 0;
4198
4199 while (*buf) {
4200 char *end;
4201
4202 /* skip leading white space */
4203 buf = skip_spaces(buf);
4204 if (!*buf)
4205 break; /* end of buffer */
4206
4207 /* find end of word */
4208 for (end = buf; *end && !isspace(*end); end++)
4209 ;
4210
4211 if (n_words == max_words) {
4212 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4213 max_words);
4214 return -EINVAL; /* ran out of words[] before bytes */
4215 }
4216
4217 if (*end)
4218 *end++ = '\0';
4219 words[n_words++] = buf;
4220 buf = end;
4221 }
4222
4223 return n_words;
4224}
4225
Damien Lespiaub94dec82013-10-15 18:55:35 +01004226enum intel_pipe_crc_object {
4227 PIPE_CRC_OBJECT_PIPE,
4228};
4229
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004230static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004231 "pipe",
4232};
4233
4234static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004235display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004236{
4237 int i;
4238
4239 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4240 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004241 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004242 return 0;
4243 }
4244
4245 return -EINVAL;
4246}
4247
Damien Lespiaubd9db022013-10-15 18:55:36 +01004248static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004249{
4250 const char name = buf[0];
4251
4252 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4253 return -EINVAL;
4254
4255 *pipe = name - 'A';
4256
4257 return 0;
4258}
4259
4260static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004261display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004262{
4263 int i;
4264
4265 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4266 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004267 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004268 return 0;
4269 }
4270
4271 return -EINVAL;
4272}
4273
Damien Lespiaubd9db022013-10-15 18:55:36 +01004274static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004275{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004276#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004277 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004278 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004279 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004280 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004281 enum intel_pipe_crc_source source;
4282
Damien Lespiaubd9db022013-10-15 18:55:36 +01004283 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004284 if (n_words != N_WORDS) {
4285 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4286 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004287 return -EINVAL;
4288 }
4289
Damien Lespiaubd9db022013-10-15 18:55:36 +01004290 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004291 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004292 return -EINVAL;
4293 }
4294
Damien Lespiaubd9db022013-10-15 18:55:36 +01004295 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004296 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4297 return -EINVAL;
4298 }
4299
Damien Lespiaubd9db022013-10-15 18:55:36 +01004300 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004301 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004302 return -EINVAL;
4303 }
4304
4305 return pipe_crc_set_source(dev, pipe, source);
4306}
4307
Damien Lespiaubd9db022013-10-15 18:55:36 +01004308static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4309 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004310{
4311 struct seq_file *m = file->private_data;
4312 struct drm_device *dev = m->private;
4313 char *tmpbuf;
4314 int ret;
4315
4316 if (len == 0)
4317 return 0;
4318
4319 if (len > PAGE_SIZE - 1) {
4320 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4321 PAGE_SIZE);
4322 return -E2BIG;
4323 }
4324
4325 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4326 if (!tmpbuf)
4327 return -ENOMEM;
4328
4329 if (copy_from_user(tmpbuf, ubuf, len)) {
4330 ret = -EFAULT;
4331 goto out;
4332 }
4333 tmpbuf[len] = '\0';
4334
Damien Lespiaubd9db022013-10-15 18:55:36 +01004335 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004336
4337out:
4338 kfree(tmpbuf);
4339 if (ret < 0)
4340 return ret;
4341
4342 *offp += len;
4343 return len;
4344}
4345
Damien Lespiaubd9db022013-10-15 18:55:36 +01004346static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004347 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004348 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004349 .read = seq_read,
4350 .llseek = seq_lseek,
4351 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004352 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004353};
4354
Todd Previteeb3394fa2015-04-18 00:04:19 -07004355static ssize_t i915_displayport_test_active_write(struct file *file,
4356 const char __user *ubuf,
4357 size_t len, loff_t *offp)
4358{
4359 char *input_buffer;
4360 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004361 struct drm_device *dev;
4362 struct drm_connector *connector;
4363 struct list_head *connector_list;
4364 struct intel_dp *intel_dp;
4365 int val = 0;
4366
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304367 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004368
Todd Previteeb3394fa2015-04-18 00:04:19 -07004369 connector_list = &dev->mode_config.connector_list;
4370
4371 if (len == 0)
4372 return 0;
4373
4374 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4375 if (!input_buffer)
4376 return -ENOMEM;
4377
4378 if (copy_from_user(input_buffer, ubuf, len)) {
4379 status = -EFAULT;
4380 goto out;
4381 }
4382
4383 input_buffer[len] = '\0';
4384 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4385
4386 list_for_each_entry(connector, connector_list, head) {
4387
4388 if (connector->connector_type !=
4389 DRM_MODE_CONNECTOR_DisplayPort)
4390 continue;
4391
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304392 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004393 connector->encoder != NULL) {
4394 intel_dp = enc_to_intel_dp(connector->encoder);
4395 status = kstrtoint(input_buffer, 10, &val);
4396 if (status < 0)
4397 goto out;
4398 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4399 /* To prevent erroneous activation of the compliance
4400 * testing code, only accept an actual value of 1 here
4401 */
4402 if (val == 1)
4403 intel_dp->compliance_test_active = 1;
4404 else
4405 intel_dp->compliance_test_active = 0;
4406 }
4407 }
4408out:
4409 kfree(input_buffer);
4410 if (status < 0)
4411 return status;
4412
4413 *offp += len;
4414 return len;
4415}
4416
4417static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4418{
4419 struct drm_device *dev = m->private;
4420 struct drm_connector *connector;
4421 struct list_head *connector_list = &dev->mode_config.connector_list;
4422 struct intel_dp *intel_dp;
4423
Todd Previteeb3394fa2015-04-18 00:04:19 -07004424 list_for_each_entry(connector, connector_list, head) {
4425
4426 if (connector->connector_type !=
4427 DRM_MODE_CONNECTOR_DisplayPort)
4428 continue;
4429
4430 if (connector->status == connector_status_connected &&
4431 connector->encoder != NULL) {
4432 intel_dp = enc_to_intel_dp(connector->encoder);
4433 if (intel_dp->compliance_test_active)
4434 seq_puts(m, "1");
4435 else
4436 seq_puts(m, "0");
4437 } else
4438 seq_puts(m, "0");
4439 }
4440
4441 return 0;
4442}
4443
4444static int i915_displayport_test_active_open(struct inode *inode,
4445 struct file *file)
4446{
4447 struct drm_device *dev = inode->i_private;
4448
4449 return single_open(file, i915_displayport_test_active_show, dev);
4450}
4451
4452static const struct file_operations i915_displayport_test_active_fops = {
4453 .owner = THIS_MODULE,
4454 .open = i915_displayport_test_active_open,
4455 .read = seq_read,
4456 .llseek = seq_lseek,
4457 .release = single_release,
4458 .write = i915_displayport_test_active_write
4459};
4460
4461static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4462{
4463 struct drm_device *dev = m->private;
4464 struct drm_connector *connector;
4465 struct list_head *connector_list = &dev->mode_config.connector_list;
4466 struct intel_dp *intel_dp;
4467
Todd Previteeb3394fa2015-04-18 00:04:19 -07004468 list_for_each_entry(connector, connector_list, head) {
4469
4470 if (connector->connector_type !=
4471 DRM_MODE_CONNECTOR_DisplayPort)
4472 continue;
4473
4474 if (connector->status == connector_status_connected &&
4475 connector->encoder != NULL) {
4476 intel_dp = enc_to_intel_dp(connector->encoder);
4477 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4478 } else
4479 seq_puts(m, "0");
4480 }
4481
4482 return 0;
4483}
4484static int i915_displayport_test_data_open(struct inode *inode,
4485 struct file *file)
4486{
4487 struct drm_device *dev = inode->i_private;
4488
4489 return single_open(file, i915_displayport_test_data_show, dev);
4490}
4491
4492static const struct file_operations i915_displayport_test_data_fops = {
4493 .owner = THIS_MODULE,
4494 .open = i915_displayport_test_data_open,
4495 .read = seq_read,
4496 .llseek = seq_lseek,
4497 .release = single_release
4498};
4499
4500static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4501{
4502 struct drm_device *dev = m->private;
4503 struct drm_connector *connector;
4504 struct list_head *connector_list = &dev->mode_config.connector_list;
4505 struct intel_dp *intel_dp;
4506
Todd Previteeb3394fa2015-04-18 00:04:19 -07004507 list_for_each_entry(connector, connector_list, head) {
4508
4509 if (connector->connector_type !=
4510 DRM_MODE_CONNECTOR_DisplayPort)
4511 continue;
4512
4513 if (connector->status == connector_status_connected &&
4514 connector->encoder != NULL) {
4515 intel_dp = enc_to_intel_dp(connector->encoder);
4516 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4517 } else
4518 seq_puts(m, "0");
4519 }
4520
4521 return 0;
4522}
4523
4524static int i915_displayport_test_type_open(struct inode *inode,
4525 struct file *file)
4526{
4527 struct drm_device *dev = inode->i_private;
4528
4529 return single_open(file, i915_displayport_test_type_show, dev);
4530}
4531
4532static const struct file_operations i915_displayport_test_type_fops = {
4533 .owner = THIS_MODULE,
4534 .open = i915_displayport_test_type_open,
4535 .read = seq_read,
4536 .llseek = seq_lseek,
4537 .release = single_release
4538};
4539
Damien Lespiau97e94b22014-11-04 17:06:50 +00004540static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004541{
4542 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004543 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004544 int num_levels;
4545
4546 if (IS_CHERRYVIEW(dev))
4547 num_levels = 3;
4548 else if (IS_VALLEYVIEW(dev))
4549 num_levels = 1;
4550 else
4551 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004552
4553 drm_modeset_lock_all(dev);
4554
4555 for (level = 0; level < num_levels; level++) {
4556 unsigned int latency = wm[level];
4557
Damien Lespiau97e94b22014-11-04 17:06:50 +00004558 /*
4559 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004560 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004561 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004562 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev) ||
4563 IS_CHERRYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004564 latency *= 10;
4565 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004566 latency *= 5;
4567
4568 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004569 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004570 }
4571
4572 drm_modeset_unlock_all(dev);
4573}
4574
4575static int pri_wm_latency_show(struct seq_file *m, void *data)
4576{
4577 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004578 struct drm_i915_private *dev_priv = dev->dev_private;
4579 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004580
Damien Lespiau97e94b22014-11-04 17:06:50 +00004581 if (INTEL_INFO(dev)->gen >= 9)
4582 latencies = dev_priv->wm.skl_latency;
4583 else
4584 latencies = to_i915(dev)->wm.pri_latency;
4585
4586 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004587
4588 return 0;
4589}
4590
4591static int spr_wm_latency_show(struct seq_file *m, void *data)
4592{
4593 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004594 struct drm_i915_private *dev_priv = dev->dev_private;
4595 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004596
Damien Lespiau97e94b22014-11-04 17:06:50 +00004597 if (INTEL_INFO(dev)->gen >= 9)
4598 latencies = dev_priv->wm.skl_latency;
4599 else
4600 latencies = to_i915(dev)->wm.spr_latency;
4601
4602 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004603
4604 return 0;
4605}
4606
4607static int cur_wm_latency_show(struct seq_file *m, void *data)
4608{
4609 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004610 struct drm_i915_private *dev_priv = dev->dev_private;
4611 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004612
Damien Lespiau97e94b22014-11-04 17:06:50 +00004613 if (INTEL_INFO(dev)->gen >= 9)
4614 latencies = dev_priv->wm.skl_latency;
4615 else
4616 latencies = to_i915(dev)->wm.cur_latency;
4617
4618 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004619
4620 return 0;
4621}
4622
4623static int pri_wm_latency_open(struct inode *inode, struct file *file)
4624{
4625 struct drm_device *dev = inode->i_private;
4626
Ville Syrjäläde38b952015-06-24 22:00:09 +03004627 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004628 return -ENODEV;
4629
4630 return single_open(file, pri_wm_latency_show, dev);
4631}
4632
4633static int spr_wm_latency_open(struct inode *inode, struct file *file)
4634{
4635 struct drm_device *dev = inode->i_private;
4636
Sonika Jindal9ad02572014-07-21 15:23:39 +05304637 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004638 return -ENODEV;
4639
4640 return single_open(file, spr_wm_latency_show, dev);
4641}
4642
4643static int cur_wm_latency_open(struct inode *inode, struct file *file)
4644{
4645 struct drm_device *dev = inode->i_private;
4646
Sonika Jindal9ad02572014-07-21 15:23:39 +05304647 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004648 return -ENODEV;
4649
4650 return single_open(file, cur_wm_latency_show, dev);
4651}
4652
4653static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004654 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004655{
4656 struct seq_file *m = file->private_data;
4657 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004658 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004659 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004660 int level;
4661 int ret;
4662 char tmp[32];
4663
Ville Syrjäläde38b952015-06-24 22:00:09 +03004664 if (IS_CHERRYVIEW(dev))
4665 num_levels = 3;
4666 else if (IS_VALLEYVIEW(dev))
4667 num_levels = 1;
4668 else
4669 num_levels = ilk_wm_max_level(dev) + 1;
4670
Ville Syrjälä369a1342014-01-22 14:36:08 +02004671 if (len >= sizeof(tmp))
4672 return -EINVAL;
4673
4674 if (copy_from_user(tmp, ubuf, len))
4675 return -EFAULT;
4676
4677 tmp[len] = '\0';
4678
Damien Lespiau97e94b22014-11-04 17:06:50 +00004679 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4680 &new[0], &new[1], &new[2], &new[3],
4681 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004682 if (ret != num_levels)
4683 return -EINVAL;
4684
4685 drm_modeset_lock_all(dev);
4686
4687 for (level = 0; level < num_levels; level++)
4688 wm[level] = new[level];
4689
4690 drm_modeset_unlock_all(dev);
4691
4692 return len;
4693}
4694
4695
4696static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4697 size_t len, loff_t *offp)
4698{
4699 struct seq_file *m = file->private_data;
4700 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004701 struct drm_i915_private *dev_priv = dev->dev_private;
4702 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004703
Damien Lespiau97e94b22014-11-04 17:06:50 +00004704 if (INTEL_INFO(dev)->gen >= 9)
4705 latencies = dev_priv->wm.skl_latency;
4706 else
4707 latencies = to_i915(dev)->wm.pri_latency;
4708
4709 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004710}
4711
4712static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4713 size_t len, loff_t *offp)
4714{
4715 struct seq_file *m = file->private_data;
4716 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004717 struct drm_i915_private *dev_priv = dev->dev_private;
4718 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004719
Damien Lespiau97e94b22014-11-04 17:06:50 +00004720 if (INTEL_INFO(dev)->gen >= 9)
4721 latencies = dev_priv->wm.skl_latency;
4722 else
4723 latencies = to_i915(dev)->wm.spr_latency;
4724
4725 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004726}
4727
4728static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4729 size_t len, loff_t *offp)
4730{
4731 struct seq_file *m = file->private_data;
4732 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004733 struct drm_i915_private *dev_priv = dev->dev_private;
4734 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004735
Damien Lespiau97e94b22014-11-04 17:06:50 +00004736 if (INTEL_INFO(dev)->gen >= 9)
4737 latencies = dev_priv->wm.skl_latency;
4738 else
4739 latencies = to_i915(dev)->wm.cur_latency;
4740
4741 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004742}
4743
4744static const struct file_operations i915_pri_wm_latency_fops = {
4745 .owner = THIS_MODULE,
4746 .open = pri_wm_latency_open,
4747 .read = seq_read,
4748 .llseek = seq_lseek,
4749 .release = single_release,
4750 .write = pri_wm_latency_write
4751};
4752
4753static const struct file_operations i915_spr_wm_latency_fops = {
4754 .owner = THIS_MODULE,
4755 .open = spr_wm_latency_open,
4756 .read = seq_read,
4757 .llseek = seq_lseek,
4758 .release = single_release,
4759 .write = spr_wm_latency_write
4760};
4761
4762static const struct file_operations i915_cur_wm_latency_fops = {
4763 .owner = THIS_MODULE,
4764 .open = cur_wm_latency_open,
4765 .read = seq_read,
4766 .llseek = seq_lseek,
4767 .release = single_release,
4768 .write = cur_wm_latency_write
4769};
4770
Kees Cook647416f2013-03-10 14:10:06 -07004771static int
4772i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004773{
Kees Cook647416f2013-03-10 14:10:06 -07004774 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004775 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004776
Chris Wilsond98c52c2016-04-13 17:35:05 +01004777 *val = i915_terminally_wedged(&dev_priv->gpu_error);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004778
Kees Cook647416f2013-03-10 14:10:06 -07004779 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004780}
4781
Kees Cook647416f2013-03-10 14:10:06 -07004782static int
4783i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004784{
Kees Cook647416f2013-03-10 14:10:06 -07004785 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004786 struct drm_i915_private *dev_priv = dev->dev_private;
4787
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004788 /*
4789 * There is no safeguard against this debugfs entry colliding
4790 * with the hangcheck calling same i915_handle_error() in
4791 * parallel, causing an explosion. For now we assume that the
4792 * test harness is responsible enough not to inject gpu hangs
4793 * while it is writing to 'i915_wedged'
4794 */
4795
Chris Wilsond98c52c2016-04-13 17:35:05 +01004796 if (i915_reset_in_progress(&dev_priv->gpu_error))
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004797 return -EAGAIN;
4798
Imre Deakd46c0512014-04-14 20:24:27 +03004799 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004800
Chris Wilsonc0336662016-05-06 15:40:21 +01004801 i915_handle_error(dev_priv, val,
Mika Kuoppala58174462014-02-25 17:11:26 +02004802 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004803
4804 intel_runtime_pm_put(dev_priv);
4805
Kees Cook647416f2013-03-10 14:10:06 -07004806 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004807}
4808
Kees Cook647416f2013-03-10 14:10:06 -07004809DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4810 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004811 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004812
Kees Cook647416f2013-03-10 14:10:06 -07004813static int
4814i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004815{
Kees Cook647416f2013-03-10 14:10:06 -07004816 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004817 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004818
Kees Cook647416f2013-03-10 14:10:06 -07004819 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004820
Kees Cook647416f2013-03-10 14:10:06 -07004821 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004822}
4823
Kees Cook647416f2013-03-10 14:10:06 -07004824static int
4825i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004826{
Kees Cook647416f2013-03-10 14:10:06 -07004827 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004828 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004829 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004830
Kees Cook647416f2013-03-10 14:10:06 -07004831 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004832
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004833 ret = mutex_lock_interruptible(&dev->struct_mutex);
4834 if (ret)
4835 return ret;
4836
Daniel Vetter99584db2012-11-14 17:14:04 +01004837 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004838 mutex_unlock(&dev->struct_mutex);
4839
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 -07004843DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4844 i915_ring_stop_get, i915_ring_stop_set,
4845 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004846
Chris Wilson094f9a52013-09-25 17:34:55 +01004847static int
4848i915_ring_missed_irq_get(void *data, u64 *val)
4849{
4850 struct drm_device *dev = data;
4851 struct drm_i915_private *dev_priv = dev->dev_private;
4852
4853 *val = dev_priv->gpu_error.missed_irq_rings;
4854 return 0;
4855}
4856
4857static int
4858i915_ring_missed_irq_set(void *data, u64 val)
4859{
4860 struct drm_device *dev = data;
4861 struct drm_i915_private *dev_priv = dev->dev_private;
4862 int ret;
4863
4864 /* Lock against concurrent debugfs callers */
4865 ret = mutex_lock_interruptible(&dev->struct_mutex);
4866 if (ret)
4867 return ret;
4868 dev_priv->gpu_error.missed_irq_rings = val;
4869 mutex_unlock(&dev->struct_mutex);
4870
4871 return 0;
4872}
4873
4874DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4875 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4876 "0x%08llx\n");
4877
4878static int
4879i915_ring_test_irq_get(void *data, u64 *val)
4880{
4881 struct drm_device *dev = data;
4882 struct drm_i915_private *dev_priv = dev->dev_private;
4883
4884 *val = dev_priv->gpu_error.test_irq_rings;
4885
4886 return 0;
4887}
4888
4889static int
4890i915_ring_test_irq_set(void *data, u64 val)
4891{
4892 struct drm_device *dev = data;
4893 struct drm_i915_private *dev_priv = dev->dev_private;
4894 int ret;
4895
4896 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4897
4898 /* Lock against concurrent debugfs callers */
4899 ret = mutex_lock_interruptible(&dev->struct_mutex);
4900 if (ret)
4901 return ret;
4902
4903 dev_priv->gpu_error.test_irq_rings = val;
4904 mutex_unlock(&dev->struct_mutex);
4905
4906 return 0;
4907}
4908
4909DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4910 i915_ring_test_irq_get, i915_ring_test_irq_set,
4911 "0x%08llx\n");
4912
Chris Wilsondd624af2013-01-15 12:39:35 +00004913#define DROP_UNBOUND 0x1
4914#define DROP_BOUND 0x2
4915#define DROP_RETIRE 0x4
4916#define DROP_ACTIVE 0x8
4917#define DROP_ALL (DROP_UNBOUND | \
4918 DROP_BOUND | \
4919 DROP_RETIRE | \
4920 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004921static int
4922i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004923{
Kees Cook647416f2013-03-10 14:10:06 -07004924 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004925
Kees Cook647416f2013-03-10 14:10:06 -07004926 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004927}
4928
Kees Cook647416f2013-03-10 14:10:06 -07004929static int
4930i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004931{
Kees Cook647416f2013-03-10 14:10:06 -07004932 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004933 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004934 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004935
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004936 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004937
4938 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4939 * on ioctls on -EAGAIN. */
4940 ret = mutex_lock_interruptible(&dev->struct_mutex);
4941 if (ret)
4942 return ret;
4943
4944 if (val & DROP_ACTIVE) {
4945 ret = i915_gpu_idle(dev);
4946 if (ret)
4947 goto unlock;
4948 }
4949
4950 if (val & (DROP_RETIRE | DROP_ACTIVE))
Chris Wilsonc0336662016-05-06 15:40:21 +01004951 i915_gem_retire_requests(dev_priv);
Chris Wilsondd624af2013-01-15 12:39:35 +00004952
Chris Wilson21ab4e72014-09-09 11:16:08 +01004953 if (val & DROP_BOUND)
4954 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004955
Chris Wilson21ab4e72014-09-09 11:16:08 +01004956 if (val & DROP_UNBOUND)
4957 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004958
4959unlock:
4960 mutex_unlock(&dev->struct_mutex);
4961
Kees Cook647416f2013-03-10 14:10:06 -07004962 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004963}
4964
Kees Cook647416f2013-03-10 14:10:06 -07004965DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4966 i915_drop_caches_get, i915_drop_caches_set,
4967 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004968
Kees Cook647416f2013-03-10 14:10:06 -07004969static int
4970i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004971{
Kees Cook647416f2013-03-10 14:10:06 -07004972 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004973 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004974 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004975
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004976 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004977 return -ENODEV;
4978
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004979 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4980
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004981 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004982 if (ret)
4983 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004984
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004985 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004986 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004987
Kees Cook647416f2013-03-10 14:10:06 -07004988 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004989}
4990
Kees Cook647416f2013-03-10 14:10:06 -07004991static int
4992i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004993{
Kees Cook647416f2013-03-10 14:10:06 -07004994 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004995 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304996 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004997 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004998
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004999 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005000 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07005001
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005002 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5003
Kees Cook647416f2013-03-10 14:10:06 -07005004 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07005005
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005006 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005007 if (ret)
5008 return ret;
5009
Jesse Barnes358733e2011-07-27 11:53:01 -07005010 /*
5011 * Turbo will still be enabled, but won't go above the set value.
5012 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305013 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005014
Akash Goelbc4d91f2015-02-26 16:09:47 +05305015 hw_max = dev_priv->rps.max_freq;
5016 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07005017
Ben Widawskyb39fb292014-03-19 18:31:11 -07005018 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005019 mutex_unlock(&dev_priv->rps.hw_lock);
5020 return -EINVAL;
5021 }
5022
Ben Widawskyb39fb292014-03-19 18:31:11 -07005023 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005024
Chris Wilsondc979972016-05-10 14:10:04 +01005025 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005026
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005027 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07005028
Kees Cook647416f2013-03-10 14:10:06 -07005029 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07005030}
5031
Kees Cook647416f2013-03-10 14:10:06 -07005032DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
5033 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005034 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07005035
Kees Cook647416f2013-03-10 14:10:06 -07005036static int
5037i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005038{
Kees Cook647416f2013-03-10 14:10:06 -07005039 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03005040 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07005041 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005042
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005043 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005044 return -ENODEV;
5045
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005046 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5047
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005048 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005049 if (ret)
5050 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07005051
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005052 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005053 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005054
Kees Cook647416f2013-03-10 14:10:06 -07005055 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005056}
5057
Kees Cook647416f2013-03-10 14:10:06 -07005058static int
5059i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005060{
Kees Cook647416f2013-03-10 14:10:06 -07005061 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07005062 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305063 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005064 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005065
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005066 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005067 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005068
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005069 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5070
Kees Cook647416f2013-03-10 14:10:06 -07005071 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005072
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005073 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005074 if (ret)
5075 return ret;
5076
Jesse Barnes1523c312012-05-25 12:34:54 -07005077 /*
5078 * Turbo will still be enabled, but won't go below the set value.
5079 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305080 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005081
Akash Goelbc4d91f2015-02-26 16:09:47 +05305082 hw_max = dev_priv->rps.max_freq;
5083 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005084
Ben Widawskyb39fb292014-03-19 18:31:11 -07005085 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005086 mutex_unlock(&dev_priv->rps.hw_lock);
5087 return -EINVAL;
5088 }
5089
Ben Widawskyb39fb292014-03-19 18:31:11 -07005090 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005091
Chris Wilsondc979972016-05-10 14:10:04 +01005092 intel_set_rps(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005093
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005094 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005095
Kees Cook647416f2013-03-10 14:10:06 -07005096 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005097}
5098
Kees Cook647416f2013-03-10 14:10:06 -07005099DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5100 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005101 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005102
Kees Cook647416f2013-03-10 14:10:06 -07005103static int
5104i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005105{
Kees Cook647416f2013-03-10 14:10:06 -07005106 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03005107 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005108 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005109 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005110
Daniel Vetter004777c2012-08-09 15:07:01 +02005111 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5112 return -ENODEV;
5113
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005114 ret = mutex_lock_interruptible(&dev->struct_mutex);
5115 if (ret)
5116 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005117 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005118
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005119 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005120
5121 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005122 mutex_unlock(&dev_priv->dev->struct_mutex);
5123
Kees Cook647416f2013-03-10 14:10:06 -07005124 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005125
Kees Cook647416f2013-03-10 14:10:06 -07005126 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005127}
5128
Kees Cook647416f2013-03-10 14:10:06 -07005129static int
5130i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005131{
Kees Cook647416f2013-03-10 14:10:06 -07005132 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005133 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005134 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005135
Daniel Vetter004777c2012-08-09 15:07:01 +02005136 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5137 return -ENODEV;
5138
Kees Cook647416f2013-03-10 14:10:06 -07005139 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005140 return -EINVAL;
5141
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005142 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005143 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005144
5145 /* Update the cache sharing policy here as well */
5146 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5147 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5148 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5149 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5150
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005151 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005152 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005153}
5154
Kees Cook647416f2013-03-10 14:10:06 -07005155DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5156 i915_cache_sharing_get, i915_cache_sharing_set,
5157 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005158
Jeff McGee5d395252015-04-03 18:13:17 -07005159struct sseu_dev_status {
5160 unsigned int slice_total;
5161 unsigned int subslice_total;
5162 unsigned int subslice_per_slice;
5163 unsigned int eu_total;
5164 unsigned int eu_per_subslice;
5165};
5166
5167static void cherryview_sseu_device_status(struct drm_device *dev,
5168 struct sseu_dev_status *stat)
5169{
5170 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005171 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005172 int ss;
5173 u32 sig1[ss_max], sig2[ss_max];
5174
5175 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5176 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5177 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5178 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5179
5180 for (ss = 0; ss < ss_max; ss++) {
5181 unsigned int eu_cnt;
5182
5183 if (sig1[ss] & CHV_SS_PG_ENABLE)
5184 /* skip disabled subslice */
5185 continue;
5186
5187 stat->slice_total = 1;
5188 stat->subslice_per_slice++;
5189 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5190 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5191 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5192 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
5193 stat->eu_total += eu_cnt;
5194 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
5195 }
5196 stat->subslice_total = stat->subslice_per_slice;
5197}
5198
5199static void gen9_sseu_device_status(struct drm_device *dev,
5200 struct sseu_dev_status *stat)
5201{
5202 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005203 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005204 int s, ss;
5205 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5206
Jeff McGee1c046bc2015-04-03 18:13:18 -07005207 /* BXT has a single slice and at most 3 subslices. */
5208 if (IS_BROXTON(dev)) {
5209 s_max = 1;
5210 ss_max = 3;
5211 }
5212
5213 for (s = 0; s < s_max; s++) {
5214 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5215 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5216 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5217 }
5218
Jeff McGee5d395252015-04-03 18:13:17 -07005219 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5220 GEN9_PGCTL_SSA_EU19_ACK |
5221 GEN9_PGCTL_SSA_EU210_ACK |
5222 GEN9_PGCTL_SSA_EU311_ACK;
5223 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5224 GEN9_PGCTL_SSB_EU19_ACK |
5225 GEN9_PGCTL_SSB_EU210_ACK |
5226 GEN9_PGCTL_SSB_EU311_ACK;
5227
5228 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005229 unsigned int ss_cnt = 0;
5230
Jeff McGee5d395252015-04-03 18:13:17 -07005231 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5232 /* skip disabled slice */
5233 continue;
5234
5235 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005236
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07005237 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Jeff McGee1c046bc2015-04-03 18:13:18 -07005238 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5239
Jeff McGee5d395252015-04-03 18:13:17 -07005240 for (ss = 0; ss < ss_max; ss++) {
5241 unsigned int eu_cnt;
5242
Jeff McGee1c046bc2015-04-03 18:13:18 -07005243 if (IS_BROXTON(dev) &&
5244 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5245 /* skip disabled subslice */
5246 continue;
5247
5248 if (IS_BROXTON(dev))
5249 ss_cnt++;
5250
Jeff McGee5d395252015-04-03 18:13:17 -07005251 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5252 eu_mask[ss%2]);
5253 stat->eu_total += eu_cnt;
5254 stat->eu_per_subslice = max(stat->eu_per_subslice,
5255 eu_cnt);
5256 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005257
5258 stat->subslice_total += ss_cnt;
5259 stat->subslice_per_slice = max(stat->subslice_per_slice,
5260 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005261 }
5262}
5263
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005264static void broadwell_sseu_device_status(struct drm_device *dev,
5265 struct sseu_dev_status *stat)
5266{
5267 struct drm_i915_private *dev_priv = dev->dev_private;
5268 int s;
5269 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
5270
5271 stat->slice_total = hweight32(slice_info & GEN8_LSLICESTAT_MASK);
5272
5273 if (stat->slice_total) {
5274 stat->subslice_per_slice = INTEL_INFO(dev)->subslice_per_slice;
5275 stat->subslice_total = stat->slice_total *
5276 stat->subslice_per_slice;
5277 stat->eu_per_subslice = INTEL_INFO(dev)->eu_per_subslice;
5278 stat->eu_total = stat->eu_per_subslice * stat->subslice_total;
5279
5280 /* subtract fused off EU(s) from enabled slice(s) */
5281 for (s = 0; s < stat->slice_total; s++) {
5282 u8 subslice_7eu = INTEL_INFO(dev)->subslice_7eu[s];
5283
5284 stat->eu_total -= hweight8(subslice_7eu);
5285 }
5286 }
5287}
5288
Jeff McGee38732182015-02-13 10:27:54 -06005289static int i915_sseu_status(struct seq_file *m, void *unused)
5290{
5291 struct drm_info_node *node = (struct drm_info_node *) m->private;
5292 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07005293 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005294
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005295 if (INTEL_INFO(dev)->gen < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005296 return -ENODEV;
5297
5298 seq_puts(m, "SSEU Device Info\n");
5299 seq_printf(m, " Available Slice Total: %u\n",
5300 INTEL_INFO(dev)->slice_total);
5301 seq_printf(m, " Available Subslice Total: %u\n",
5302 INTEL_INFO(dev)->subslice_total);
5303 seq_printf(m, " Available Subslice Per Slice: %u\n",
5304 INTEL_INFO(dev)->subslice_per_slice);
5305 seq_printf(m, " Available EU Total: %u\n",
5306 INTEL_INFO(dev)->eu_total);
5307 seq_printf(m, " Available EU Per Subslice: %u\n",
5308 INTEL_INFO(dev)->eu_per_subslice);
5309 seq_printf(m, " Has Slice Power Gating: %s\n",
5310 yesno(INTEL_INFO(dev)->has_slice_pg));
5311 seq_printf(m, " Has Subslice Power Gating: %s\n",
5312 yesno(INTEL_INFO(dev)->has_subslice_pg));
5313 seq_printf(m, " Has EU Power Gating: %s\n",
5314 yesno(INTEL_INFO(dev)->has_eu_pg));
5315
Jeff McGee7f992ab2015-02-13 10:27:55 -06005316 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005317 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08005318 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005319 cherryview_sseu_device_status(dev, &stat);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005320 } else if (IS_BROADWELL(dev)) {
5321 broadwell_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005322 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005323 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005324 }
Jeff McGee5d395252015-04-03 18:13:17 -07005325 seq_printf(m, " Enabled Slice Total: %u\n",
5326 stat.slice_total);
5327 seq_printf(m, " Enabled Subslice Total: %u\n",
5328 stat.subslice_total);
5329 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5330 stat.subslice_per_slice);
5331 seq_printf(m, " Enabled EU Total: %u\n",
5332 stat.eu_total);
5333 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5334 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005335
Jeff McGee38732182015-02-13 10:27:54 -06005336 return 0;
5337}
5338
Ben Widawsky6d794d42011-04-25 11:25:56 -07005339static int i915_forcewake_open(struct inode *inode, struct file *file)
5340{
5341 struct drm_device *dev = inode->i_private;
5342 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005343
Daniel Vetter075edca2012-01-24 09:44:28 +01005344 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005345 return 0;
5346
Chris Wilson6daccb02015-01-16 11:34:35 +02005347 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005348 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005349
5350 return 0;
5351}
5352
Ben Widawskyc43b5632012-04-16 14:07:40 -07005353static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005354{
5355 struct drm_device *dev = inode->i_private;
5356 struct drm_i915_private *dev_priv = dev->dev_private;
5357
Daniel Vetter075edca2012-01-24 09:44:28 +01005358 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005359 return 0;
5360
Mika Kuoppala59bad942015-01-16 11:34:40 +02005361 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005362 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005363
5364 return 0;
5365}
5366
5367static const struct file_operations i915_forcewake_fops = {
5368 .owner = THIS_MODULE,
5369 .open = i915_forcewake_open,
5370 .release = i915_forcewake_release,
5371};
5372
5373static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5374{
5375 struct drm_device *dev = minor->dev;
5376 struct dentry *ent;
5377
5378 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005379 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005380 root, dev,
5381 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005382 if (!ent)
5383 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005384
Ben Widawsky8eb57292011-05-11 15:10:58 -07005385 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005386}
5387
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005388static int i915_debugfs_create(struct dentry *root,
5389 struct drm_minor *minor,
5390 const char *name,
5391 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005392{
5393 struct drm_device *dev = minor->dev;
5394 struct dentry *ent;
5395
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005396 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005397 S_IRUGO | S_IWUSR,
5398 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005399 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005400 if (!ent)
5401 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005402
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005403 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005404}
5405
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005406static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005407 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005408 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005409 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005410 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005411 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005412 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005413 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005414 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005415 {"i915_gem_request", i915_gem_request_info, 0},
5416 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005417 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005418 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005419 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5420 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5421 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005422 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005423 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005424 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005425 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005426 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305427 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005428 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005429 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005430 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005431 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005432 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005433 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005434 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005435 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005436 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005437 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005438 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005439 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005440 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005441 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005442 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005443 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005444 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005445 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005446 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005447 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005448 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005449 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005450 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005451 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005452 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005453 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005454 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005455 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005456 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005457 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005458 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305459 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005460 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005461};
Ben Gamari27c202a2009-07-01 22:26:52 -04005462#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005463
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005464static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005465 const char *name;
5466 const struct file_operations *fops;
5467} i915_debugfs_files[] = {
5468 {"i915_wedged", &i915_wedged_fops},
5469 {"i915_max_freq", &i915_max_freq_fops},
5470 {"i915_min_freq", &i915_min_freq_fops},
5471 {"i915_cache_sharing", &i915_cache_sharing_fops},
5472 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005473 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5474 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005475 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5476 {"i915_error_state", &i915_error_state_fops},
5477 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005478 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005479 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5480 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5481 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005482 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005483 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5484 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5485 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005486};
5487
Damien Lespiau07144422013-10-15 18:55:40 +01005488void intel_display_crc_init(struct drm_device *dev)
5489{
5490 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005491 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005492
Damien Lespiau055e3932014-08-18 13:49:10 +01005493 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005494 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005495
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005496 pipe_crc->opened = false;
5497 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005498 init_waitqueue_head(&pipe_crc->wq);
5499 }
5500}
5501
Ben Gamari27c202a2009-07-01 22:26:52 -04005502int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005503{
Daniel Vetter34b96742013-07-04 20:49:44 +02005504 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005505
Ben Widawsky6d794d42011-04-25 11:25:56 -07005506 ret = i915_forcewake_create(minor->debugfs_root, minor);
5507 if (ret)
5508 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005509
Damien Lespiau07144422013-10-15 18:55:40 +01005510 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5511 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5512 if (ret)
5513 return ret;
5514 }
5515
Daniel Vetter34b96742013-07-04 20:49:44 +02005516 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5517 ret = i915_debugfs_create(minor->debugfs_root, minor,
5518 i915_debugfs_files[i].name,
5519 i915_debugfs_files[i].fops);
5520 if (ret)
5521 return ret;
5522 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005523
Ben Gamari27c202a2009-07-01 22:26:52 -04005524 return drm_debugfs_create_files(i915_debugfs_list,
5525 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005526 minor->debugfs_root, minor);
5527}
5528
Ben Gamari27c202a2009-07-01 22:26:52 -04005529void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005530{
Daniel Vetter34b96742013-07-04 20:49:44 +02005531 int i;
5532
Ben Gamari27c202a2009-07-01 22:26:52 -04005533 drm_debugfs_remove_files(i915_debugfs_list,
5534 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005535
Ben Widawsky6d794d42011-04-25 11:25:56 -07005536 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5537 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005538
Daniel Vettere309a992013-10-16 22:55:51 +02005539 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005540 struct drm_info_list *info_list =
5541 (struct drm_info_list *)&i915_pipe_crc_data[i];
5542
5543 drm_debugfs_remove_files(info_list, 1, minor);
5544 }
5545
Daniel Vetter34b96742013-07-04 20:49:44 +02005546 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5547 struct drm_info_list *info_list =
5548 (struct drm_info_list *) i915_debugfs_files[i].fops;
5549
5550 drm_debugfs_remove_files(info_list, 1, minor);
5551 }
Ben Gamari20172632009-02-17 20:08:50 -05005552}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005553
5554struct dpcd_block {
5555 /* DPCD dump start address. */
5556 unsigned int offset;
5557 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5558 unsigned int end;
5559 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5560 size_t size;
5561 /* Only valid for eDP. */
5562 bool edp;
5563};
5564
5565static const struct dpcd_block i915_dpcd_debug[] = {
5566 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5567 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5568 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5569 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5570 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5571 { .offset = DP_SET_POWER },
5572 { .offset = DP_EDP_DPCD_REV },
5573 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5574 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5575 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5576};
5577
5578static int i915_dpcd_show(struct seq_file *m, void *data)
5579{
5580 struct drm_connector *connector = m->private;
5581 struct intel_dp *intel_dp =
5582 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5583 uint8_t buf[16];
5584 ssize_t err;
5585 int i;
5586
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005587 if (connector->status != connector_status_connected)
5588 return -ENODEV;
5589
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005590 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5591 const struct dpcd_block *b = &i915_dpcd_debug[i];
5592 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5593
5594 if (b->edp &&
5595 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5596 continue;
5597
5598 /* low tech for now */
5599 if (WARN_ON(size > sizeof(buf)))
5600 continue;
5601
5602 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5603 if (err <= 0) {
5604 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5605 size, b->offset, err);
5606 continue;
5607 }
5608
5609 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005610 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005611
5612 return 0;
5613}
5614
5615static int i915_dpcd_open(struct inode *inode, struct file *file)
5616{
5617 return single_open(file, i915_dpcd_show, inode->i_private);
5618}
5619
5620static const struct file_operations i915_dpcd_fops = {
5621 .owner = THIS_MODULE,
5622 .open = i915_dpcd_open,
5623 .read = seq_read,
5624 .llseek = seq_lseek,
5625 .release = single_release,
5626};
5627
5628/**
5629 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5630 * @connector: pointer to a registered drm_connector
5631 *
5632 * Cleanup will be done by drm_connector_unregister() through a call to
5633 * drm_debugfs_connector_remove().
5634 *
5635 * Returns 0 on success, negative error codes on error.
5636 */
5637int i915_debugfs_connector_add(struct drm_connector *connector)
5638{
5639 struct dentry *root = connector->debugfs_entry;
5640
5641 /* The connector must have been registered beforehands. */
5642 if (!root)
5643 return -ENODEV;
5644
5645 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5646 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5647 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5648 &i915_dpcd_fops);
5649
5650 return 0;
5651}