blob: 9640738aabf27d5e2cb00140857bffd0af6b5390 [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
Chris Wilson05394f32010-11-08 19:18:58 +000092static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000093{
Chris Wilsonbaaa5cf2015-04-15 16:42:46 +010094 if (obj->pin_display)
Chris Wilsona6172a82009-02-11 14:26:38 +000095 return "p";
96 else
97 return " ";
98}
99
Chris Wilson05394f32010-11-08 19:18:58 +0000100static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000101{
Akshay Joshi0206e352011-08-16 15:34:10 -0400102 switch (obj->tiling_mode) {
103 default:
104 case I915_TILING_NONE: return " ";
105 case I915_TILING_X: return "X";
106 case I915_TILING_Y: return "Y";
107 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000108}
109
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700110static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
111{
Tvrtko Ursulinaff43762014-10-24 12:42:33 +0100112 return i915_gem_obj_to_ggtt(obj) ? "g" : " ";
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700113}
114
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100115static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
116{
117 u64 size = 0;
118 struct i915_vma *vma;
119
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000120 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson596c5922016-02-26 11:03:20 +0000121 if (vma->is_ggtt && drm_mm_node_allocated(&vma->node))
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100122 size += vma->node.size;
123 }
124
125 return size;
126}
127
Chris Wilson37811fc2010-08-25 22:45:57 +0100128static void
129describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
130{
Chris Wilsonb4716182015-04-27 13:41:17 +0100131 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000132 struct intel_engine_cs *engine;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700133 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800134 int pin_count = 0;
Dave Gordonc3232b12016-03-23 18:19:53 +0000135 enum intel_engine_id id;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800136
Chris Wilson188c1ab2016-04-03 14:14:20 +0100137 lockdep_assert_held(&obj->base.dev->struct_mutex);
138
Chris Wilsonb4716182015-04-27 13:41:17 +0100139 seq_printf(m, "%pK: %s%s%s%s %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100140 &obj->base,
Chris Wilson481a3d42015-04-07 16:20:39 +0100141 obj->active ? "*" : " ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100142 get_pin_flag(obj),
143 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700144 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800145 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100146 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100147 obj->base.write_domain);
Dave Gordonc3232b12016-03-23 18:19:53 +0000148 for_each_engine_id(engine, dev_priv, id)
Chris Wilsonb4716182015-04-27 13:41:17 +0100149 seq_printf(m, "%x ",
Dave Gordonc3232b12016-03-23 18:19:53 +0000150 i915_gem_request_get_seqno(obj->last_read_req[id]));
Chris Wilsonb4716182015-04-27 13:41:17 +0100151 seq_printf(m, "] %x %x%s%s%s",
John Harrison97b2a6a2014-11-24 18:49:26 +0000152 i915_gem_request_get_seqno(obj->last_write_req),
153 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100154 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100155 obj->dirty ? " dirty" : "",
156 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
157 if (obj->base.name)
158 seq_printf(m, " (name: %d)", obj->base.name);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000159 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800160 if (vma->pin_count > 0)
161 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300162 }
163 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100164 if (obj->pin_display)
165 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100166 if (obj->fence_reg != I915_FENCE_REG_NONE)
167 seq_printf(m, " (fence: %d)", obj->fence_reg);
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000168 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100169 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
Chris Wilson596c5922016-02-26 11:03:20 +0000170 vma->is_ggtt ? "g" : "pp",
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100171 vma->node.start, vma->node.size);
Chris Wilson596c5922016-02-26 11:03:20 +0000172 if (vma->is_ggtt)
173 seq_printf(m, ", type: %u", vma->ggtt_view.type);
174 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700175 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000176 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100177 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100178 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000179 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100180 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000181 *t++ = 'p';
182 if (obj->fault_mappable)
183 *t++ = 'f';
184 *t = '\0';
185 seq_printf(m, " (%s mappable)", s);
186 }
Chris Wilsonb4716182015-04-27 13:41:17 +0100187 if (obj->last_write_req != NULL)
John Harrison41c52412014-11-24 18:49:43 +0000188 seq_printf(m, " (%s)",
Tvrtko Ursulin666796d2016-03-16 11:00:39 +0000189 i915_gem_request_get_engine(obj->last_write_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200190 if (obj->frontbuffer_bits)
191 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100192}
193
Oscar Mateo273497e2014-05-22 14:13:37 +0100194static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700195{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100196 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700197 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
198 seq_putc(m, ' ');
199}
200
Ben Gamari433e12f2009-02-17 20:08:51 -0500201static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500202{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100203 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500204 uintptr_t list = (uintptr_t) node->info_ent->data;
205 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500206 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300207 struct drm_i915_private *dev_priv = to_i915(dev);
208 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Ben Widawskyca191b12013-07-31 17:00:14 -0700209 struct i915_vma *vma;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300210 u64 total_obj_size, total_gtt_size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100211 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100212
213 ret = mutex_lock_interruptible(&dev->struct_mutex);
214 if (ret)
215 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500216
Ben Widawskyca191b12013-07-31 17:00:14 -0700217 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500218 switch (list) {
219 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100220 seq_puts(m, "Active:\n");
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300221 head = &ggtt->base.active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500222 break;
223 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100224 seq_puts(m, "Inactive:\n");
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300225 head = &ggtt->base.inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500226 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500227 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100228 mutex_unlock(&dev->struct_mutex);
229 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500230 }
231
Chris Wilson8f2480f2010-09-26 11:44:19 +0100232 total_obj_size = total_gtt_size = count = 0;
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000233 list_for_each_entry(vma, head, vm_link) {
Ben Widawskyca191b12013-07-31 17:00:14 -0700234 seq_printf(m, " ");
235 describe_obj(m, vma->obj);
236 seq_printf(m, "\n");
237 total_obj_size += vma->obj->base.size;
238 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100239 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500240 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100241 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700242
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300243 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson8f2480f2010-09-26 11:44:19 +0100244 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500245 return 0;
246}
247
Chris Wilson6d2b88852013-08-07 18:30:54 +0100248static int obj_rank_by_stolen(void *priv,
249 struct list_head *A, struct list_head *B)
250{
251 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200252 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100253 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200254 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100255
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200256 if (a->stolen->start < b->stolen->start)
257 return -1;
258 if (a->stolen->start > b->stolen->start)
259 return 1;
260 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100261}
262
263static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
264{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100265 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100266 struct drm_device *dev = node->minor->dev;
267 struct drm_i915_private *dev_priv = dev->dev_private;
268 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300269 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100270 LIST_HEAD(stolen);
271 int count, ret;
272
273 ret = mutex_lock_interruptible(&dev->struct_mutex);
274 if (ret)
275 return ret;
276
277 total_obj_size = total_gtt_size = count = 0;
278 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
279 if (obj->stolen == NULL)
280 continue;
281
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200282 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100283
284 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100285 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100286 count++;
287 }
288 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
289 if (obj->stolen == NULL)
290 continue;
291
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200292 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100293
294 total_obj_size += obj->base.size;
295 count++;
296 }
297 list_sort(NULL, &stolen, obj_rank_by_stolen);
298 seq_puts(m, "Stolen:\n");
299 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200300 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100301 seq_puts(m, " ");
302 describe_obj(m, obj);
303 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200304 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100305 }
306 mutex_unlock(&dev->struct_mutex);
307
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300308 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100309 count, total_obj_size, total_gtt_size);
310 return 0;
311}
312
Chris Wilson6299f992010-11-24 12:23:44 +0000313#define count_objects(list, member) do { \
314 list_for_each_entry(obj, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100315 size += i915_gem_obj_total_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000316 ++count; \
317 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700318 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000319 ++mappable_count; \
320 } \
321 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400322} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000323
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100324struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000325 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300326 unsigned long count;
327 u64 total, unbound;
328 u64 global, shared;
329 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100330};
331
332static int per_file_stats(int id, void *ptr, void *data)
333{
334 struct drm_i915_gem_object *obj = ptr;
335 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000336 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100337
338 stats->count++;
339 stats->total += obj->base.size;
340
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000341 if (obj->base.name || obj->base.dma_buf)
342 stats->shared += obj->base.size;
343
Chris Wilson6313c202014-03-19 13:45:45 +0000344 if (USES_FULL_PPGTT(obj->base.dev)) {
Chris Wilson1c7f4bc2016-02-26 11:03:19 +0000345 list_for_each_entry(vma, &obj->vma_list, obj_link) {
Chris Wilson6313c202014-03-19 13:45:45 +0000346 struct i915_hw_ppgtt *ppgtt;
347
348 if (!drm_mm_node_allocated(&vma->node))
349 continue;
350
Chris Wilson596c5922016-02-26 11:03:20 +0000351 if (vma->is_ggtt) {
Chris Wilson6313c202014-03-19 13:45:45 +0000352 stats->global += obj->base.size;
353 continue;
354 }
355
356 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200357 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000358 continue;
359
John Harrison41c52412014-11-24 18:49:43 +0000360 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000361 stats->active += obj->base.size;
362 else
363 stats->inactive += obj->base.size;
364
365 return 0;
366 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100367 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000368 if (i915_gem_obj_ggtt_bound(obj)) {
369 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000370 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000371 stats->active += obj->base.size;
372 else
373 stats->inactive += obj->base.size;
374 return 0;
375 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100376 }
377
Chris Wilson6313c202014-03-19 13:45:45 +0000378 if (!list_empty(&obj->global_list))
379 stats->unbound += obj->base.size;
380
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100381 return 0;
382}
383
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100384#define print_file_stats(m, name, stats) do { \
385 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300386 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 +0100387 name, \
388 stats.count, \
389 stats.total, \
390 stats.active, \
391 stats.inactive, \
392 stats.global, \
393 stats.shared, \
394 stats.unbound); \
395} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800396
397static void print_batch_pool_stats(struct seq_file *m,
398 struct drm_i915_private *dev_priv)
399{
400 struct drm_i915_gem_object *obj;
401 struct file_stats stats;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000402 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000403 int j;
Brad Volkin493018d2014-12-11 12:13:08 -0800404
405 memset(&stats, 0, sizeof(stats));
406
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000407 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000408 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100409 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000410 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100411 batch_pool_link)
412 per_file_stats(0, obj, &stats);
413 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100414 }
Brad Volkin493018d2014-12-11 12:13:08 -0800415
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100416 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800417}
418
Ben Widawskyca191b12013-07-31 17:00:14 -0700419#define count_vmas(list, member) do { \
420 list_for_each_entry(vma, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100421 size += i915_gem_obj_total_ggtt_size(vma->obj); \
Ben Widawskyca191b12013-07-31 17:00:14 -0700422 ++count; \
423 if (vma->obj->map_and_fenceable) { \
424 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
425 ++mappable_count; \
426 } \
427 } \
428} while (0)
429
430static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100431{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100432 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100433 struct drm_device *dev = node->minor->dev;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300434 struct drm_i915_private *dev_priv = to_i915(dev);
435 struct i915_ggtt *ggtt = &dev_priv->ggtt;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200436 u32 count, mappable_count, purgeable_count;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300437 u64 size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000438 struct drm_i915_gem_object *obj;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100439 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700440 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100441 int ret;
442
443 ret = mutex_lock_interruptible(&dev->struct_mutex);
444 if (ret)
445 return ret;
446
Chris Wilson6299f992010-11-24 12:23:44 +0000447 seq_printf(m, "%u objects, %zu bytes\n",
448 dev_priv->mm.object_count,
449 dev_priv->mm.object_memory);
450
451 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700452 count_objects(&dev_priv->mm.bound_list, global_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300453 seq_printf(m, "%u [%u] objects, %llu [%llu] bytes in gtt\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000454 count, mappable_count, size, mappable_size);
455
456 size = count = mappable_size = mappable_count = 0;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300457 count_vmas(&ggtt->base.active_list, vm_link);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300458 seq_printf(m, " %u [%u] active objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000459 count, mappable_count, size, mappable_size);
460
461 size = count = mappable_size = mappable_count = 0;
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300462 count_vmas(&ggtt->base.inactive_list, vm_link);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300463 seq_printf(m, " %u [%u] inactive objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000464 count, mappable_count, size, mappable_size);
465
Chris Wilsonb7abb712012-08-20 11:33:30 +0200466 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700467 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200468 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200469 if (obj->madv == I915_MADV_DONTNEED)
470 purgeable_size += obj->base.size, ++purgeable_count;
471 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300472 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
Chris Wilson6c085a72012-08-20 11:40:46 +0200473
Chris Wilson6299f992010-11-24 12:23:44 +0000474 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700475 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000476 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700477 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000478 ++count;
479 }
Chris Wilson30154652015-04-07 17:28:24 +0100480 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700481 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000482 ++mappable_count;
483 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200484 if (obj->madv == I915_MADV_DONTNEED) {
485 purgeable_size += obj->base.size;
486 ++purgeable_count;
487 }
Chris Wilson6299f992010-11-24 12:23:44 +0000488 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300489 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200490 purgeable_count, purgeable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300491 seq_printf(m, "%u pinned mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000492 mappable_count, mappable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300493 seq_printf(m, "%u fault mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000494 count, size);
495
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300496 seq_printf(m, "%llu [%llu] gtt total\n",
Joonas Lahtinen72e96d62016-03-30 16:57:10 +0300497 ggtt->base.total, ggtt->mappable_end - ggtt->base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100498
Damien Lespiau267f0c92013-06-24 22:59:48 +0100499 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800500 print_batch_pool_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100501 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
502 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900503 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100504
505 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000506 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100507 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100508 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100509 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900510 /*
511 * Although we have a valid reference on file->pid, that does
512 * not guarantee that the task_struct who called get_pid() is
513 * still alive (e.g. get_pid(current) => fork() => exit()).
514 * Therefore, we need to protect this ->comm access using RCU.
515 */
516 rcu_read_lock();
517 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800518 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900519 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100520 }
521
Chris Wilson73aa8082010-09-30 11:46:12 +0100522 mutex_unlock(&dev->struct_mutex);
523
524 return 0;
525}
526
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100527static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000528{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100529 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000530 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100531 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000532 struct drm_i915_private *dev_priv = dev->dev_private;
533 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300534 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000535 int count, ret;
536
537 ret = mutex_lock_interruptible(&dev->struct_mutex);
538 if (ret)
539 return ret;
540
541 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700542 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800543 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100544 continue;
545
Damien Lespiau267f0c92013-06-24 22:59:48 +0100546 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000547 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100548 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000549 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100550 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000551 count++;
552 }
553
554 mutex_unlock(&dev->struct_mutex);
555
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300556 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000557 count, total_obj_size, total_gtt_size);
558
559 return 0;
560}
561
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100562static int i915_gem_pageflip_info(struct seq_file *m, void *data)
563{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100564 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100565 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100566 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100567 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200568 int ret;
569
570 ret = mutex_lock_interruptible(&dev->struct_mutex);
571 if (ret)
572 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100573
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100574 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800575 const char pipe = pipe_name(crtc->pipe);
576 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100577 struct intel_unpin_work *work;
578
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200579 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100580 work = crtc->unpin_work;
581 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800582 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100583 pipe, plane);
584 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100585 u32 addr;
586
Chris Wilsone7d841c2012-12-03 11:36:30 +0000587 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800588 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100589 pipe, plane);
590 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800591 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100592 pipe, plane);
593 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100594 if (work->flip_queued_req) {
Tvrtko Ursulin666796d2016-03-16 11:00:39 +0000595 struct intel_engine_cs *engine = i915_gem_request_get_engine(work->flip_queued_req);
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100596
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200597 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000598 engine->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000599 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100600 dev_priv->next_seqno,
Chris Wilsonc04e0f32016-04-09 10:57:54 +0100601 engine->get_seqno(engine),
John Harrison1b5a4332014-11-24 18:49:42 +0000602 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100603 } else
604 seq_printf(m, "Flip not associated with any ring\n");
605 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
606 work->flip_queued_vblank,
607 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100608 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100609 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100610 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100611 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100612 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000613 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100614
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100615 if (INTEL_INFO(dev)->gen >= 4)
616 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
617 else
618 addr = I915_READ(DSPADDR(crtc->plane));
619 seq_printf(m, "Current scanout address 0x%08x\n", addr);
620
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100621 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100622 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
623 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100624 }
625 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200626 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100627 }
628
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200629 mutex_unlock(&dev->struct_mutex);
630
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100631 return 0;
632}
633
Brad Volkin493018d2014-12-11 12:13:08 -0800634static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
635{
636 struct drm_info_node *node = m->private;
637 struct drm_device *dev = node->minor->dev;
638 struct drm_i915_private *dev_priv = dev->dev_private;
639 struct drm_i915_gem_object *obj;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000640 struct intel_engine_cs *engine;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100641 int total = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000642 int ret, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800643
644 ret = mutex_lock_interruptible(&dev->struct_mutex);
645 if (ret)
646 return ret;
647
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000648 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000649 for (j = 0; j < ARRAY_SIZE(engine->batch_pool.cache_list); j++) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100650 int count;
651
652 count = 0;
653 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000654 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100655 batch_pool_link)
656 count++;
657 seq_printf(m, "%s cache[%d]: %d objects\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000658 engine->name, j, count);
Chris Wilson8d9d5742015-04-07 16:20:38 +0100659
660 list_for_each_entry(obj,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000661 &engine->batch_pool.cache_list[j],
Chris Wilson8d9d5742015-04-07 16:20:38 +0100662 batch_pool_link) {
663 seq_puts(m, " ");
664 describe_obj(m, obj);
665 seq_putc(m, '\n');
666 }
667
668 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100669 }
Brad Volkin493018d2014-12-11 12:13:08 -0800670 }
671
Chris Wilson8d9d5742015-04-07 16:20:38 +0100672 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800673
674 mutex_unlock(&dev->struct_mutex);
675
676 return 0;
677}
678
Ben Gamari20172632009-02-17 20:08:50 -0500679static int i915_gem_request_info(struct seq_file *m, void *data)
680{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100681 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500682 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300683 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000684 struct intel_engine_cs *engine;
Daniel Vettereed29a52015-05-21 14:21:25 +0200685 struct drm_i915_gem_request *req;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000686 int ret, any;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100687
688 ret = mutex_lock_interruptible(&dev->struct_mutex);
689 if (ret)
690 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500691
Chris Wilson2d1070b2015-04-01 10:36:56 +0100692 any = 0;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000693 for_each_engine(engine, dev_priv) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100694 int count;
695
696 count = 0;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000697 list_for_each_entry(req, &engine->request_list, list)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100698 count++;
699 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100700 continue;
701
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000702 seq_printf(m, "%s requests: %d\n", engine->name, count);
703 list_for_each_entry(req, &engine->request_list, list) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100704 struct task_struct *task;
705
706 rcu_read_lock();
707 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200708 if (req->pid)
709 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100710 seq_printf(m, " %x @ %d: %s [%d]\n",
Daniel Vettereed29a52015-05-21 14:21:25 +0200711 req->seqno,
712 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100713 task ? task->comm : "<unknown>",
714 task ? task->pid : -1);
715 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100716 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100717
718 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500719 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100720 mutex_unlock(&dev->struct_mutex);
721
Chris Wilson2d1070b2015-04-01 10:36:56 +0100722 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100723 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100724
Ben Gamari20172632009-02-17 20:08:50 -0500725 return 0;
726}
727
Chris Wilsonb2223492010-10-27 15:27:33 +0100728static void i915_ring_seqno_info(struct seq_file *m,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000729 struct intel_engine_cs *engine)
Chris Wilsonb2223492010-10-27 15:27:33 +0100730{
Chris Wilson12471ba2016-04-09 10:57:55 +0100731 seq_printf(m, "Current sequence (%s): %x\n",
732 engine->name, engine->get_seqno(engine));
733 seq_printf(m, "Current user interrupts (%s): %x\n",
734 engine->name, READ_ONCE(engine->user_interrupts));
Chris Wilsonb2223492010-10-27 15:27:33 +0100735}
736
Ben Gamari20172632009-02-17 20:08:50 -0500737static int i915_gem_seqno_info(struct seq_file *m, void *data)
738{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100739 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500740 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300741 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000742 struct intel_engine_cs *engine;
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000743 int ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100744
745 ret = mutex_lock_interruptible(&dev->struct_mutex);
746 if (ret)
747 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200748 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500749
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000750 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000751 i915_ring_seqno_info(m, engine);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100752
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200753 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100754 mutex_unlock(&dev->struct_mutex);
755
Ben Gamari20172632009-02-17 20:08:50 -0500756 return 0;
757}
758
759
760static int i915_interrupt_info(struct seq_file *m, void *data)
761{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100762 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500763 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300764 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000765 struct intel_engine_cs *engine;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800766 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100767
768 ret = mutex_lock_interruptible(&dev->struct_mutex);
769 if (ret)
770 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200771 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500772
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300773 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300774 seq_printf(m, "Master Interrupt Control:\t%08x\n",
775 I915_READ(GEN8_MASTER_IRQ));
776
777 seq_printf(m, "Display IER:\t%08x\n",
778 I915_READ(VLV_IER));
779 seq_printf(m, "Display IIR:\t%08x\n",
780 I915_READ(VLV_IIR));
781 seq_printf(m, "Display IIR_RW:\t%08x\n",
782 I915_READ(VLV_IIR_RW));
783 seq_printf(m, "Display IMR:\t%08x\n",
784 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100785 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300786 seq_printf(m, "Pipe %c stat:\t%08x\n",
787 pipe_name(pipe),
788 I915_READ(PIPESTAT(pipe)));
789
790 seq_printf(m, "Port hotplug:\t%08x\n",
791 I915_READ(PORT_HOTPLUG_EN));
792 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
793 I915_READ(VLV_DPFLIPSTAT));
794 seq_printf(m, "DPINVGTT:\t%08x\n",
795 I915_READ(DPINVGTT));
796
797 for (i = 0; i < 4; i++) {
798 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
799 i, I915_READ(GEN8_GT_IMR(i)));
800 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
801 i, I915_READ(GEN8_GT_IIR(i)));
802 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
803 i, I915_READ(GEN8_GT_IER(i)));
804 }
805
806 seq_printf(m, "PCU interrupt mask:\t%08x\n",
807 I915_READ(GEN8_PCU_IMR));
808 seq_printf(m, "PCU interrupt identity:\t%08x\n",
809 I915_READ(GEN8_PCU_IIR));
810 seq_printf(m, "PCU interrupt enable:\t%08x\n",
811 I915_READ(GEN8_PCU_IER));
812 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700813 seq_printf(m, "Master Interrupt Control:\t%08x\n",
814 I915_READ(GEN8_MASTER_IRQ));
815
816 for (i = 0; i < 4; i++) {
817 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
818 i, I915_READ(GEN8_GT_IMR(i)));
819 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
820 i, I915_READ(GEN8_GT_IIR(i)));
821 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
822 i, I915_READ(GEN8_GT_IER(i)));
823 }
824
Damien Lespiau055e3932014-08-18 13:49:10 +0100825 for_each_pipe(dev_priv, pipe) {
Imre Deake1296492016-02-12 18:55:17 +0200826 enum intel_display_power_domain power_domain;
827
828 power_domain = POWER_DOMAIN_PIPE(pipe);
829 if (!intel_display_power_get_if_enabled(dev_priv,
830 power_domain)) {
Paulo Zanoni22c59962014-08-08 17:45:32 -0300831 seq_printf(m, "Pipe %c power disabled\n",
832 pipe_name(pipe));
833 continue;
834 }
Ben Widawskya123f152013-11-02 21:07:10 -0700835 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000836 pipe_name(pipe),
837 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700838 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000839 pipe_name(pipe),
840 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700841 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000842 pipe_name(pipe),
843 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Imre Deake1296492016-02-12 18:55:17 +0200844
845 intel_display_power_put(dev_priv, power_domain);
Ben Widawskya123f152013-11-02 21:07:10 -0700846 }
847
848 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
849 I915_READ(GEN8_DE_PORT_IMR));
850 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
851 I915_READ(GEN8_DE_PORT_IIR));
852 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
853 I915_READ(GEN8_DE_PORT_IER));
854
855 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
856 I915_READ(GEN8_DE_MISC_IMR));
857 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
858 I915_READ(GEN8_DE_MISC_IIR));
859 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
860 I915_READ(GEN8_DE_MISC_IER));
861
862 seq_printf(m, "PCU interrupt mask:\t%08x\n",
863 I915_READ(GEN8_PCU_IMR));
864 seq_printf(m, "PCU interrupt identity:\t%08x\n",
865 I915_READ(GEN8_PCU_IIR));
866 seq_printf(m, "PCU interrupt enable:\t%08x\n",
867 I915_READ(GEN8_PCU_IER));
868 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700869 seq_printf(m, "Display IER:\t%08x\n",
870 I915_READ(VLV_IER));
871 seq_printf(m, "Display IIR:\t%08x\n",
872 I915_READ(VLV_IIR));
873 seq_printf(m, "Display IIR_RW:\t%08x\n",
874 I915_READ(VLV_IIR_RW));
875 seq_printf(m, "Display IMR:\t%08x\n",
876 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100877 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700878 seq_printf(m, "Pipe %c stat:\t%08x\n",
879 pipe_name(pipe),
880 I915_READ(PIPESTAT(pipe)));
881
882 seq_printf(m, "Master IER:\t%08x\n",
883 I915_READ(VLV_MASTER_IER));
884
885 seq_printf(m, "Render IER:\t%08x\n",
886 I915_READ(GTIER));
887 seq_printf(m, "Render IIR:\t%08x\n",
888 I915_READ(GTIIR));
889 seq_printf(m, "Render IMR:\t%08x\n",
890 I915_READ(GTIMR));
891
892 seq_printf(m, "PM IER:\t\t%08x\n",
893 I915_READ(GEN6_PMIER));
894 seq_printf(m, "PM IIR:\t\t%08x\n",
895 I915_READ(GEN6_PMIIR));
896 seq_printf(m, "PM IMR:\t\t%08x\n",
897 I915_READ(GEN6_PMIMR));
898
899 seq_printf(m, "Port hotplug:\t%08x\n",
900 I915_READ(PORT_HOTPLUG_EN));
901 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
902 I915_READ(VLV_DPFLIPSTAT));
903 seq_printf(m, "DPINVGTT:\t%08x\n",
904 I915_READ(DPINVGTT));
905
906 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800907 seq_printf(m, "Interrupt enable: %08x\n",
908 I915_READ(IER));
909 seq_printf(m, "Interrupt identity: %08x\n",
910 I915_READ(IIR));
911 seq_printf(m, "Interrupt mask: %08x\n",
912 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100913 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800914 seq_printf(m, "Pipe %c stat: %08x\n",
915 pipe_name(pipe),
916 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800917 } else {
918 seq_printf(m, "North Display Interrupt enable: %08x\n",
919 I915_READ(DEIER));
920 seq_printf(m, "North Display Interrupt identity: %08x\n",
921 I915_READ(DEIIR));
922 seq_printf(m, "North Display Interrupt mask: %08x\n",
923 I915_READ(DEIMR));
924 seq_printf(m, "South Display Interrupt enable: %08x\n",
925 I915_READ(SDEIER));
926 seq_printf(m, "South Display Interrupt identity: %08x\n",
927 I915_READ(SDEIIR));
928 seq_printf(m, "South Display Interrupt mask: %08x\n",
929 I915_READ(SDEIMR));
930 seq_printf(m, "Graphics Interrupt enable: %08x\n",
931 I915_READ(GTIER));
932 seq_printf(m, "Graphics Interrupt identity: %08x\n",
933 I915_READ(GTIIR));
934 seq_printf(m, "Graphics Interrupt mask: %08x\n",
935 I915_READ(GTIMR));
936 }
Dave Gordonb4ac5af2016-03-24 11:20:38 +0000937 for_each_engine(engine, dev_priv) {
Ben Widawskya123f152013-11-02 21:07:10 -0700938 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100939 seq_printf(m,
940 "Graphics Interrupt mask (%s): %08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000941 engine->name, I915_READ_IMR(engine));
Chris Wilson9862e602011-01-04 22:22:17 +0000942 }
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000943 i915_ring_seqno_info(m, engine);
Chris Wilson9862e602011-01-04 22:22:17 +0000944 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200945 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100946 mutex_unlock(&dev->struct_mutex);
947
Ben Gamari20172632009-02-17 20:08:50 -0500948 return 0;
949}
950
Chris Wilsona6172a82009-02-11 14:26:38 +0000951static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
952{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100953 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000954 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300955 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100956 int i, ret;
957
958 ret = mutex_lock_interruptible(&dev->struct_mutex);
959 if (ret)
960 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000961
Chris Wilsona6172a82009-02-11 14:26:38 +0000962 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
963 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000964 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000965
Chris Wilson6c085a72012-08-20 11:40:46 +0200966 seq_printf(m, "Fence %d, pin count = %d, object = ",
967 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100968 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100969 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100970 else
Chris Wilson05394f32010-11-08 19:18:58 +0000971 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100972 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000973 }
974
Chris Wilson05394f32010-11-08 19:18:58 +0000975 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000976 return 0;
977}
978
Ben Gamari20172632009-02-17 20:08:50 -0500979static int i915_hws_info(struct seq_file *m, void *data)
980{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100981 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500982 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300983 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000984 struct intel_engine_cs *engine;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100985 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100986 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500987
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +0000988 engine = &dev_priv->engine[(uintptr_t)node->info_ent->data];
Tvrtko Ursuline2f80392016-03-16 11:00:36 +0000989 hws = engine->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500990 if (hws == NULL)
991 return 0;
992
993 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
994 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
995 i * 4,
996 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
997 }
998 return 0;
999}
1000
Daniel Vetterd5442302012-04-27 15:17:40 +02001001static ssize_t
1002i915_error_state_write(struct file *filp,
1003 const char __user *ubuf,
1004 size_t cnt,
1005 loff_t *ppos)
1006{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001007 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001008 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001009 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001010
1011 DRM_DEBUG_DRIVER("Resetting error state\n");
1012
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001013 ret = mutex_lock_interruptible(&dev->struct_mutex);
1014 if (ret)
1015 return ret;
1016
Daniel Vetterd5442302012-04-27 15:17:40 +02001017 i915_destroy_error_state(dev);
1018 mutex_unlock(&dev->struct_mutex);
1019
1020 return cnt;
1021}
1022
1023static int i915_error_state_open(struct inode *inode, struct file *file)
1024{
1025 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001026 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001027
1028 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1029 if (!error_priv)
1030 return -ENOMEM;
1031
1032 error_priv->dev = dev;
1033
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001034 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001035
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001036 file->private_data = error_priv;
1037
1038 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001039}
1040
1041static int i915_error_state_release(struct inode *inode, struct file *file)
1042{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001043 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001044
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001045 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001046 kfree(error_priv);
1047
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001048 return 0;
1049}
1050
1051static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1052 size_t count, loff_t *pos)
1053{
1054 struct i915_error_state_file_priv *error_priv = file->private_data;
1055 struct drm_i915_error_state_buf error_str;
1056 loff_t tmp_pos = 0;
1057 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001058 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001059
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001060 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001061 if (ret)
1062 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001063
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001064 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001065 if (ret)
1066 goto out;
1067
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001068 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1069 error_str.buf,
1070 error_str.bytes);
1071
1072 if (ret_count < 0)
1073 ret = ret_count;
1074 else
1075 *pos = error_str.start + ret_count;
1076out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001077 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001078 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001079}
1080
1081static const struct file_operations i915_error_state_fops = {
1082 .owner = THIS_MODULE,
1083 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001084 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001085 .write = i915_error_state_write,
1086 .llseek = default_llseek,
1087 .release = i915_error_state_release,
1088};
1089
Kees Cook647416f2013-03-10 14:10:06 -07001090static int
1091i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001092{
Kees Cook647416f2013-03-10 14:10:06 -07001093 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001094 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001095 int ret;
1096
1097 ret = mutex_lock_interruptible(&dev->struct_mutex);
1098 if (ret)
1099 return ret;
1100
Kees Cook647416f2013-03-10 14:10:06 -07001101 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001102 mutex_unlock(&dev->struct_mutex);
1103
Kees Cook647416f2013-03-10 14:10:06 -07001104 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001105}
1106
Kees Cook647416f2013-03-10 14:10:06 -07001107static int
1108i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001109{
Kees Cook647416f2013-03-10 14:10:06 -07001110 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001111 int ret;
1112
Mika Kuoppala40633212012-12-04 15:12:00 +02001113 ret = mutex_lock_interruptible(&dev->struct_mutex);
1114 if (ret)
1115 return ret;
1116
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001117 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001118 mutex_unlock(&dev->struct_mutex);
1119
Kees Cook647416f2013-03-10 14:10:06 -07001120 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001121}
1122
Kees Cook647416f2013-03-10 14:10:06 -07001123DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1124 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001125 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001126
Deepak Sadb4bd12014-03-31 11:30:02 +05301127static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001128{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001129 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001130 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001131 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001132 int ret = 0;
1133
1134 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001135
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001136 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1137
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001138 if (IS_GEN5(dev)) {
1139 u16 rgvswctl = I915_READ16(MEMSWCTL);
1140 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1141
1142 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1143 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1144 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1145 MEMSTAT_VID_SHIFT);
1146 seq_printf(m, "Current P-state: %d\n",
1147 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Wayne Boyer666a4532015-12-09 12:29:35 -08001148 } else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev)) {
1149 u32 freq_sts;
1150
1151 mutex_lock(&dev_priv->rps.hw_lock);
1152 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
1153 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1154 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1155
1156 seq_printf(m, "actual GPU freq: %d MHz\n",
1157 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1158
1159 seq_printf(m, "current GPU freq: %d MHz\n",
1160 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1161
1162 seq_printf(m, "max GPU freq: %d MHz\n",
1163 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1164
1165 seq_printf(m, "min GPU freq: %d MHz\n",
1166 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1167
1168 seq_printf(m, "idle GPU freq: %d MHz\n",
1169 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1170
1171 seq_printf(m,
1172 "efficient (RPe) frequency: %d MHz\n",
1173 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
1174 mutex_unlock(&dev_priv->rps.hw_lock);
1175 } else if (INTEL_INFO(dev)->gen >= 6) {
Bob Paauwe35040562015-06-25 14:54:07 -07001176 u32 rp_state_limits;
1177 u32 gt_perf_status;
1178 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001179 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001180 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001181 u32 rpupei, rpcurup, rpprevup;
1182 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001183 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001184 int max_freq;
1185
Bob Paauwe35040562015-06-25 14:54:07 -07001186 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1187 if (IS_BROXTON(dev)) {
1188 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1189 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1190 } else {
1191 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1192 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1193 }
1194
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001195 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001196 ret = mutex_lock_interruptible(&dev->struct_mutex);
1197 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001198 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001199
Mika Kuoppala59bad942015-01-16 11:34:40 +02001200 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001201
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001202 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301203 if (IS_GEN9(dev))
1204 reqf >>= 23;
1205 else {
1206 reqf &= ~GEN6_TURBO_DISABLE;
1207 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1208 reqf >>= 24;
1209 else
1210 reqf >>= 25;
1211 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001212 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001213
Chris Wilson0d8f9492014-03-27 09:06:14 +00001214 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1215 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1216 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1217
Jesse Barnesccab5c82011-01-18 15:49:25 -08001218 rpstat = I915_READ(GEN6_RPSTAT1);
1219 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1220 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1221 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1222 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1223 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1224 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Akash Goel60260a52015-03-06 11:07:21 +05301225 if (IS_GEN9(dev))
1226 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1227 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001228 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1229 else
1230 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001231 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001232
Mika Kuoppala59bad942015-01-16 11:34:40 +02001233 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001234 mutex_unlock(&dev->struct_mutex);
1235
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001236 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1237 pm_ier = I915_READ(GEN6_PMIER);
1238 pm_imr = I915_READ(GEN6_PMIMR);
1239 pm_isr = I915_READ(GEN6_PMISR);
1240 pm_iir = I915_READ(GEN6_PMIIR);
1241 pm_mask = I915_READ(GEN6_PMINTRMSK);
1242 } else {
1243 pm_ier = I915_READ(GEN8_GT_IER(2));
1244 pm_imr = I915_READ(GEN8_GT_IMR(2));
1245 pm_isr = I915_READ(GEN8_GT_ISR(2));
1246 pm_iir = I915_READ(GEN8_GT_IIR(2));
1247 pm_mask = I915_READ(GEN6_PMINTRMSK);
1248 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001249 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 -03001250 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001251 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001252 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301253 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001254 seq_printf(m, "Render p-state VID: %d\n",
1255 gt_perf_status & 0xff);
1256 seq_printf(m, "Render p-state limit: %d\n",
1257 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001258 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1259 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1260 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1261 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001262 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001263 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001264 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1265 GEN6_CURICONT_MASK);
1266 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1267 GEN6_CURBSYTAVG_MASK);
1268 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1269 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001270 seq_printf(m, "Up threshold: %d%%\n",
1271 dev_priv->rps.up_threshold);
1272
Jesse Barnesccab5c82011-01-18 15:49:25 -08001273 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1274 GEN6_CURIAVG_MASK);
1275 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1276 GEN6_CURBSYTAVG_MASK);
1277 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1278 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001279 seq_printf(m, "Down threshold: %d%%\n",
1280 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001281
Bob Paauwe35040562015-06-25 14:54:07 -07001282 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1283 rp_state_cap >> 16) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001284 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1285 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001286 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001287 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001288
1289 max_freq = (rp_state_cap & 0xff00) >> 8;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001290 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1291 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001292 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001293 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001294
Bob Paauwe35040562015-06-25 14:54:07 -07001295 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1296 rp_state_cap >> 0) & 0xff;
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001297 max_freq *= (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1298 GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001299 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001300 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001301 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001302 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001303
Chris Wilsond86ed342015-04-27 13:41:19 +01001304 seq_printf(m, "Current freq: %d MHz\n",
1305 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1306 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001307 seq_printf(m, "Idle freq: %d MHz\n",
1308 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001309 seq_printf(m, "Min freq: %d MHz\n",
1310 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1311 seq_printf(m, "Max freq: %d MHz\n",
1312 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1313 seq_printf(m,
1314 "efficient (RPe) frequency: %d MHz\n",
1315 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001316 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001317 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001318 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001319
Mika Kahola1170f282015-09-25 14:00:32 +03001320 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1321 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1322 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1323
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001324out:
1325 intel_runtime_pm_put(dev_priv);
1326 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001327}
1328
Chris Wilsonf6544492015-01-26 18:03:04 +02001329static int i915_hangcheck_info(struct seq_file *m, void *unused)
1330{
1331 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001332 struct drm_device *dev = node->minor->dev;
1333 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001334 struct intel_engine_cs *engine;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00001335 u64 acthd[I915_NUM_ENGINES];
1336 u32 seqno[I915_NUM_ENGINES];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001337 u32 instdone[I915_NUM_INSTDONE_REG];
Dave Gordonc3232b12016-03-23 18:19:53 +00001338 enum intel_engine_id id;
1339 int j;
Chris Wilsonf6544492015-01-26 18:03:04 +02001340
1341 if (!i915.enable_hangcheck) {
1342 seq_printf(m, "Hangcheck disabled\n");
1343 return 0;
1344 }
1345
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001346 intel_runtime_pm_get(dev_priv);
1347
Dave Gordonc3232b12016-03-23 18:19:53 +00001348 for_each_engine_id(engine, dev_priv, id) {
Dave Gordonc3232b12016-03-23 18:19:53 +00001349 acthd[id] = intel_ring_get_active_head(engine);
Chris Wilsonc04e0f32016-04-09 10:57:54 +01001350 seqno[id] = engine->get_seqno(engine);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001351 }
1352
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001353 i915_get_extra_instdone(dev, instdone);
1354
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001355 intel_runtime_pm_put(dev_priv);
1356
Chris Wilsonf6544492015-01-26 18:03:04 +02001357 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1358 seq_printf(m, "Hangcheck active, fires in %dms\n",
1359 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1360 jiffies));
1361 } else
1362 seq_printf(m, "Hangcheck inactive\n");
1363
Dave Gordonc3232b12016-03-23 18:19:53 +00001364 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001365 seq_printf(m, "%s:\n", engine->name);
Chris Wilson14fd0d62016-04-07 07:29:10 +01001366 seq_printf(m, "\tseqno = %x [current %x, last %x]\n",
1367 engine->hangcheck.seqno,
1368 seqno[id],
1369 engine->last_submitted_seqno);
Chris Wilson12471ba2016-04-09 10:57:55 +01001370 seq_printf(m, "\tuser interrupts = %x [current %x]\n",
1371 engine->hangcheck.user_interrupts,
1372 READ_ONCE(engine->user_interrupts));
Chris Wilsonf6544492015-01-26 18:03:04 +02001373 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001374 (long long)engine->hangcheck.acthd,
Dave Gordonc3232b12016-03-23 18:19:53 +00001375 (long long)acthd[id]);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001376 seq_printf(m, "\tscore = %d\n", engine->hangcheck.score);
1377 seq_printf(m, "\taction = %d\n", engine->hangcheck.action);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001378
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001379 if (engine->id == RCS) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001380 seq_puts(m, "\tinstdone read =");
1381
1382 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1383 seq_printf(m, " 0x%08x", instdone[j]);
1384
1385 seq_puts(m, "\n\tinstdone accu =");
1386
1387 for (j = 0; j < I915_NUM_INSTDONE_REG; j++)
1388 seq_printf(m, " 0x%08x",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001389 engine->hangcheck.instdone[j]);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02001390
1391 seq_puts(m, "\n");
1392 }
Chris Wilsonf6544492015-01-26 18:03:04 +02001393 }
1394
1395 return 0;
1396}
1397
Ben Widawsky4d855292011-12-12 19:34:16 -08001398static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001399{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001400 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001401 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001402 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001403 u32 rgvmodectl, rstdbyctl;
1404 u16 crstandvid;
1405 int ret;
1406
1407 ret = mutex_lock_interruptible(&dev->struct_mutex);
1408 if (ret)
1409 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001410 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001411
1412 rgvmodectl = I915_READ(MEMMODECTL);
1413 rstdbyctl = I915_READ(RSTDBYCTL);
1414 crstandvid = I915_READ16(CRSTANDVID);
1415
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001416 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001417 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001418
Jani Nikula742f4912015-09-03 11:16:09 +03001419 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001420 seq_printf(m, "Boost freq: %d\n",
1421 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1422 MEMMODE_BOOST_FREQ_SHIFT);
1423 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001424 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001425 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001426 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001427 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001428 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001429 seq_printf(m, "Starting frequency: P%d\n",
1430 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001431 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001432 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001433 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1434 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1435 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1436 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001437 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001438 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001439 switch (rstdbyctl & RSX_STATUS_MASK) {
1440 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001441 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001442 break;
1443 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001444 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001445 break;
1446 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001448 break;
1449 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001451 break;
1452 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001453 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001454 break;
1455 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001456 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001457 break;
1458 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001459 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001460 break;
1461 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001462
1463 return 0;
1464}
1465
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001466static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001467{
1468 struct drm_info_node *node = m->private;
1469 struct drm_device *dev = node->minor->dev;
1470 struct drm_i915_private *dev_priv = dev->dev_private;
1471 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001472 int i;
1473
1474 spin_lock_irq(&dev_priv->uncore.lock);
1475 for_each_fw_domain(fw_domain, dev_priv, i) {
1476 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001477 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001478 fw_domain->wake_count);
1479 }
1480 spin_unlock_irq(&dev_priv->uncore.lock);
1481
1482 return 0;
1483}
1484
Deepak S669ab5a2014-01-10 15:18:26 +05301485static int vlv_drpc_info(struct seq_file *m)
1486{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001487 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301488 struct drm_device *dev = node->minor->dev;
1489 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001490 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301491
Imre Deakd46c0512014-04-14 20:24:27 +03001492 intel_runtime_pm_get(dev_priv);
1493
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001494 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301495 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1496 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1497
Imre Deakd46c0512014-04-14 20:24:27 +03001498 intel_runtime_pm_put(dev_priv);
1499
Deepak S669ab5a2014-01-10 15:18:26 +05301500 seq_printf(m, "Video Turbo Mode: %s\n",
1501 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1502 seq_printf(m, "Turbo enabled: %s\n",
1503 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1504 seq_printf(m, "HW control enabled: %s\n",
1505 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1506 seq_printf(m, "SW control enabled: %s\n",
1507 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1508 GEN6_RP_MEDIA_SW_MODE));
1509 seq_printf(m, "RC6 Enabled: %s\n",
1510 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1511 GEN6_RC_CTL_EI_MODE(1))));
1512 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001513 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301514 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001515 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301516
Imre Deak9cc19be2014-04-14 20:24:24 +03001517 seq_printf(m, "Render RC6 residency since boot: %u\n",
1518 I915_READ(VLV_GT_RENDER_RC6));
1519 seq_printf(m, "Media RC6 residency since boot: %u\n",
1520 I915_READ(VLV_GT_MEDIA_RC6));
1521
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001522 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301523}
1524
Ben Widawsky4d855292011-12-12 19:34:16 -08001525static int gen6_drpc_info(struct seq_file *m)
1526{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001527 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001528 struct drm_device *dev = node->minor->dev;
1529 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001530 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001531 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001532 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001533
1534 ret = mutex_lock_interruptible(&dev->struct_mutex);
1535 if (ret)
1536 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001537 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001538
Chris Wilson907b28c2013-07-19 20:36:52 +01001539 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001540 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001541 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001542
1543 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001544 seq_puts(m, "RC information inaccurate because somebody "
1545 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001546 } else {
1547 /* NB: we cannot use forcewake, else we read the wrong values */
1548 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1549 udelay(10);
1550 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1551 }
1552
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001553 gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001554 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001555
1556 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1557 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1558 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001559 mutex_lock(&dev_priv->rps.hw_lock);
1560 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1561 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001562
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001563 intel_runtime_pm_put(dev_priv);
1564
Ben Widawsky4d855292011-12-12 19:34:16 -08001565 seq_printf(m, "Video Turbo Mode: %s\n",
1566 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1567 seq_printf(m, "HW control enabled: %s\n",
1568 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1569 seq_printf(m, "SW control enabled: %s\n",
1570 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1571 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001572 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001573 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1574 seq_printf(m, "RC6 Enabled: %s\n",
1575 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1576 seq_printf(m, "Deep RC6 Enabled: %s\n",
1577 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1578 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1579 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001580 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001581 switch (gt_core_status & GEN6_RCn_MASK) {
1582 case GEN6_RC0:
1583 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001584 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001585 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001586 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001587 break;
1588 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001589 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001590 break;
1591 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001592 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001593 break;
1594 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001595 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001596 break;
1597 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001598 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001599 break;
1600 }
1601
1602 seq_printf(m, "Core Power Down: %s\n",
1603 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001604
1605 /* Not exactly sure what this is */
1606 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1607 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1608 seq_printf(m, "RC6 residency since boot: %u\n",
1609 I915_READ(GEN6_GT_GFX_RC6));
1610 seq_printf(m, "RC6+ residency since boot: %u\n",
1611 I915_READ(GEN6_GT_GFX_RC6p));
1612 seq_printf(m, "RC6++ residency since boot: %u\n",
1613 I915_READ(GEN6_GT_GFX_RC6pp));
1614
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001615 seq_printf(m, "RC6 voltage: %dmV\n",
1616 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1617 seq_printf(m, "RC6+ voltage: %dmV\n",
1618 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1619 seq_printf(m, "RC6++ voltage: %dmV\n",
1620 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001621 return 0;
1622}
1623
1624static int i915_drpc_info(struct seq_file *m, void *unused)
1625{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001626 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001627 struct drm_device *dev = node->minor->dev;
1628
Wayne Boyer666a4532015-12-09 12:29:35 -08001629 if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Deepak S669ab5a2014-01-10 15:18:26 +05301630 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001631 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001632 return gen6_drpc_info(m);
1633 else
1634 return ironlake_drpc_info(m);
1635}
1636
Daniel Vetter9a851782015-06-18 10:30:22 +02001637static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1638{
1639 struct drm_info_node *node = m->private;
1640 struct drm_device *dev = node->minor->dev;
1641 struct drm_i915_private *dev_priv = dev->dev_private;
1642
1643 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1644 dev_priv->fb_tracking.busy_bits);
1645
1646 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1647 dev_priv->fb_tracking.flip_bits);
1648
1649 return 0;
1650}
1651
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001652static int i915_fbc_status(struct seq_file *m, void *unused)
1653{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001654 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001655 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001656 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001657
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001658 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001659 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001660 return 0;
1661 }
1662
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001663 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001664 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001665
Paulo Zanoni0e631ad2015-10-14 17:45:36 -03001666 if (intel_fbc_is_active(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001667 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001668 else
1669 seq_printf(m, "FBC disabled: %s\n",
Paulo Zanonibf6189c2015-10-27 14:50:03 -02001670 dev_priv->fbc.no_fbc_reason);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001671
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001672 if (INTEL_INFO(dev_priv)->gen >= 7)
1673 seq_printf(m, "Compressing: %s\n",
1674 yesno(I915_READ(FBC_STATUS2) &
1675 FBC_COMPRESSION_MASK));
1676
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001677 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001678 intel_runtime_pm_put(dev_priv);
1679
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001680 return 0;
1681}
1682
Rodrigo Vivida46f932014-08-01 02:04:45 -07001683static int i915_fbc_fc_get(void *data, u64 *val)
1684{
1685 struct drm_device *dev = data;
1686 struct drm_i915_private *dev_priv = dev->dev_private;
1687
1688 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1689 return -ENODEV;
1690
Rodrigo Vivida46f932014-08-01 02:04:45 -07001691 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001692
1693 return 0;
1694}
1695
1696static int i915_fbc_fc_set(void *data, u64 val)
1697{
1698 struct drm_device *dev = data;
1699 struct drm_i915_private *dev_priv = dev->dev_private;
1700 u32 reg;
1701
1702 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1703 return -ENODEV;
1704
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001705 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001706
1707 reg = I915_READ(ILK_DPFC_CONTROL);
1708 dev_priv->fbc.false_color = val;
1709
1710 I915_WRITE(ILK_DPFC_CONTROL, val ?
1711 (reg | FBC_CTL_FALSE_COLOR) :
1712 (reg & ~FBC_CTL_FALSE_COLOR));
1713
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001714 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001715 return 0;
1716}
1717
1718DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1719 i915_fbc_fc_get, i915_fbc_fc_set,
1720 "%llu\n");
1721
Paulo Zanoni92d44622013-05-31 16:33:24 -03001722static int i915_ips_status(struct seq_file *m, void *unused)
1723{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001724 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001725 struct drm_device *dev = node->minor->dev;
1726 struct drm_i915_private *dev_priv = dev->dev_private;
1727
Damien Lespiauf5adf942013-06-24 18:29:34 +01001728 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001729 seq_puts(m, "not supported\n");
1730 return 0;
1731 }
1732
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001733 intel_runtime_pm_get(dev_priv);
1734
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001735 seq_printf(m, "Enabled by kernel parameter: %s\n",
1736 yesno(i915.enable_ips));
1737
1738 if (INTEL_INFO(dev)->gen >= 8) {
1739 seq_puts(m, "Currently: unknown\n");
1740 } else {
1741 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1742 seq_puts(m, "Currently: enabled\n");
1743 else
1744 seq_puts(m, "Currently: disabled\n");
1745 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001746
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001747 intel_runtime_pm_put(dev_priv);
1748
Paulo Zanoni92d44622013-05-31 16:33:24 -03001749 return 0;
1750}
1751
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001752static int i915_sr_status(struct seq_file *m, void *unused)
1753{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001754 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001755 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001756 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001757 bool sr_enabled = false;
1758
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001759 intel_runtime_pm_get(dev_priv);
1760
Yuanhan Liu13982612010-12-15 15:42:31 +08001761 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001762 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001763 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1764 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001765 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1766 else if (IS_I915GM(dev))
1767 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1768 else if (IS_PINEVIEW(dev))
1769 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Wayne Boyer666a4532015-12-09 12:29:35 -08001770 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001771 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001772
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001773 intel_runtime_pm_put(dev_priv);
1774
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001775 seq_printf(m, "self-refresh: %s\n",
1776 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001777
1778 return 0;
1779}
1780
Jesse Barnes7648fa92010-05-20 14:28:11 -07001781static int i915_emon_status(struct seq_file *m, void *unused)
1782{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001783 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001784 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001785 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001786 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001787 int ret;
1788
Chris Wilson582be6b2012-04-30 19:35:02 +01001789 if (!IS_GEN5(dev))
1790 return -ENODEV;
1791
Chris Wilsonde227ef2010-07-03 07:58:38 +01001792 ret = mutex_lock_interruptible(&dev->struct_mutex);
1793 if (ret)
1794 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001795
1796 temp = i915_mch_val(dev_priv);
1797 chipset = i915_chipset_val(dev_priv);
1798 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001799 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001800
1801 seq_printf(m, "GMCH temp: %ld\n", temp);
1802 seq_printf(m, "Chipset power: %ld\n", chipset);
1803 seq_printf(m, "GFX power: %ld\n", gfx);
1804 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1805
1806 return 0;
1807}
1808
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001809static int i915_ring_freq_table(struct seq_file *m, void *unused)
1810{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001811 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001812 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001813 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001814 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001815 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301816 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001817
Akash Goel97d33082015-06-29 14:50:23 +05301818 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001819 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001820 return 0;
1821 }
1822
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001823 intel_runtime_pm_get(dev_priv);
1824
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001825 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1826
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001827 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001828 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001829 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001830
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001831 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev)) {
Akash Goelf936ec32015-06-29 14:50:22 +05301832 /* Convert GT frequency to 50 HZ units */
1833 min_gpu_freq =
1834 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1835 max_gpu_freq =
1836 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1837 } else {
1838 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1839 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1840 }
1841
Damien Lespiau267f0c92013-06-24 22:59:48 +01001842 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001843
Akash Goelf936ec32015-06-29 14:50:22 +05301844 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001845 ia_freq = gpu_freq;
1846 sandybridge_pcode_read(dev_priv,
1847 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1848 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001849 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301850 intel_gpu_freq(dev_priv, (gpu_freq *
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07001851 (IS_SKYLAKE(dev) || IS_KABYLAKE(dev) ?
1852 GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001853 ((ia_freq >> 0) & 0xff) * 100,
1854 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001855 }
1856
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001857 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001858
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001859out:
1860 intel_runtime_pm_put(dev_priv);
1861 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001862}
1863
Chris Wilson44834a62010-08-19 16:09:23 +01001864static int i915_opregion(struct seq_file *m, void *unused)
1865{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001866 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001867 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001868 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001869 struct intel_opregion *opregion = &dev_priv->opregion;
1870 int ret;
1871
1872 ret = mutex_lock_interruptible(&dev->struct_mutex);
1873 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001874 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001875
Jani Nikula2455a8e2015-12-14 12:50:53 +02001876 if (opregion->header)
1877 seq_write(m, opregion->header, OPREGION_SIZE);
Chris Wilson44834a62010-08-19 16:09:23 +01001878
1879 mutex_unlock(&dev->struct_mutex);
1880
Daniel Vetter0d38f002012-04-21 22:49:10 +02001881out:
Chris Wilson44834a62010-08-19 16:09:23 +01001882 return 0;
1883}
1884
Jani Nikulaada8f952015-12-15 13:17:12 +02001885static int i915_vbt(struct seq_file *m, void *unused)
1886{
1887 struct drm_info_node *node = m->private;
1888 struct drm_device *dev = node->minor->dev;
1889 struct drm_i915_private *dev_priv = dev->dev_private;
1890 struct intel_opregion *opregion = &dev_priv->opregion;
1891
1892 if (opregion->vbt)
1893 seq_write(m, opregion->vbt, opregion->vbt_size);
1894
1895 return 0;
1896}
1897
Chris Wilson37811fc2010-08-25 22:45:57 +01001898static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1899{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001900 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001901 struct drm_device *dev = node->minor->dev;
Namrta Salonieb13b8402015-11-27 13:43:11 +05301902 struct intel_framebuffer *fbdev_fb = NULL;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001903 struct drm_framebuffer *drm_fb;
Chris Wilson188c1ab2016-04-03 14:14:20 +01001904 int ret;
1905
1906 ret = mutex_lock_interruptible(&dev->struct_mutex);
1907 if (ret)
1908 return ret;
Chris Wilson37811fc2010-08-25 22:45:57 +01001909
Daniel Vetter06957262015-08-10 13:34:08 +02001910#ifdef CONFIG_DRM_FBDEV_EMULATION
Namrta Salonieb13b8402015-11-27 13:43:11 +05301911 if (to_i915(dev)->fbdev) {
1912 fbdev_fb = to_intel_framebuffer(to_i915(dev)->fbdev->helper.fb);
Chris Wilson37811fc2010-08-25 22:45:57 +01001913
Namrta Salonieb13b8402015-11-27 13:43:11 +05301914 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
1915 fbdev_fb->base.width,
1916 fbdev_fb->base.height,
1917 fbdev_fb->base.depth,
1918 fbdev_fb->base.bits_per_pixel,
1919 fbdev_fb->base.modifier[0],
1920 atomic_read(&fbdev_fb->base.refcount.refcount));
1921 describe_obj(m, fbdev_fb->obj);
1922 seq_putc(m, '\n');
1923 }
Daniel Vetter4520f532013-10-09 09:18:51 +02001924#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001925
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001926 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001927 drm_for_each_fb(drm_fb, dev) {
Namrta Salonieb13b8402015-11-27 13:43:11 +05301928 struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
1929 if (fb == fbdev_fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001930 continue;
1931
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001932 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 +01001933 fb->base.width,
1934 fb->base.height,
1935 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001936 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001937 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001938 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001939 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001940 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001941 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001942 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson188c1ab2016-04-03 14:14:20 +01001943 mutex_unlock(&dev->struct_mutex);
Chris Wilson37811fc2010-08-25 22:45:57 +01001944
1945 return 0;
1946}
1947
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001948static void describe_ctx_ringbuf(struct seq_file *m,
1949 struct intel_ringbuffer *ringbuf)
1950{
1951 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1952 ringbuf->space, ringbuf->head, ringbuf->tail,
1953 ringbuf->last_retired_head);
1954}
1955
Ben Widawskye76d3632011-03-19 18:14:29 -07001956static int i915_context_status(struct seq_file *m, void *unused)
1957{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001958 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001959 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001960 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001961 struct intel_engine_cs *engine;
Oscar Mateo273497e2014-05-22 14:13:37 +01001962 struct intel_context *ctx;
Dave Gordonc3232b12016-03-23 18:19:53 +00001963 enum intel_engine_id id;
1964 int ret;
Ben Widawskye76d3632011-03-19 18:14:29 -07001965
Daniel Vetterf3d28872014-05-29 23:23:08 +02001966 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001967 if (ret)
1968 return ret;
1969
Ben Widawskya33afea2013-09-17 21:12:45 -07001970 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001971 if (!i915.enable_execlists &&
1972 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001973 continue;
1974
Ben Widawskya33afea2013-09-17 21:12:45 -07001975 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001976 describe_ctx(m, ctx);
Dave Gordone28e4042016-01-19 19:02:55 +00001977 if (ctx == dev_priv->kernel_context)
1978 seq_printf(m, "(kernel context) ");
Ben Widawskya33afea2013-09-17 21:12:45 -07001979
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001980 if (i915.enable_execlists) {
1981 seq_putc(m, '\n');
Dave Gordonc3232b12016-03-23 18:19:53 +00001982 for_each_engine_id(engine, dev_priv, id) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001983 struct drm_i915_gem_object *ctx_obj =
Dave Gordonc3232b12016-03-23 18:19:53 +00001984 ctx->engine[id].state;
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001985 struct intel_ringbuffer *ringbuf =
Dave Gordonc3232b12016-03-23 18:19:53 +00001986 ctx->engine[id].ringbuf;
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001987
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001988 seq_printf(m, "%s: ", engine->name);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001989 if (ctx_obj)
1990 describe_obj(m, ctx_obj);
1991 if (ringbuf)
1992 describe_ctx_ringbuf(m, ringbuf);
1993 seq_putc(m, '\n');
1994 }
1995 } else {
1996 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1997 }
1998
Ben Widawskya33afea2013-09-17 21:12:45 -07001999 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08002000 }
2001
Daniel Vetterf3d28872014-05-29 23:23:08 +02002002 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07002003
2004 return 0;
2005}
2006
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002007static void i915_dump_lrc_obj(struct seq_file *m,
Tvrtko Ursulinca825802016-01-15 15:10:27 +00002008 struct intel_context *ctx,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002009 struct intel_engine_cs *engine)
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002010{
2011 struct page *page;
2012 uint32_t *reg_state;
2013 int j;
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002014 struct drm_i915_gem_object *ctx_obj = ctx->engine[engine->id].state;
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002015 unsigned long ggtt_offset = 0;
2016
2017 if (ctx_obj == NULL) {
2018 seq_printf(m, "Context on %s with no gem object\n",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002019 engine->name);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002020 return;
2021 }
2022
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002023 seq_printf(m, "CONTEXT: %s %u\n", engine->name,
2024 intel_execlists_ctx_id(ctx, engine));
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002025
2026 if (!i915_gem_obj_ggtt_bound(ctx_obj))
2027 seq_puts(m, "\tNot bound in GGTT\n");
2028 else
2029 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
2030
2031 if (i915_gem_object_get_pages(ctx_obj)) {
2032 seq_puts(m, "\tFailed to get pages for context object\n");
2033 return;
2034 }
2035
Alex Daid1675192015-08-12 15:43:43 +01002036 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002037 if (!WARN_ON(page == NULL)) {
2038 reg_state = kmap_atomic(page);
2039
2040 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2041 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2042 ggtt_offset + 4096 + (j * 4),
2043 reg_state[j], reg_state[j + 1],
2044 reg_state[j + 2], reg_state[j + 3]);
2045 }
2046 kunmap_atomic(reg_state);
2047 }
2048
2049 seq_putc(m, '\n');
2050}
2051
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002052static int i915_dump_lrc(struct seq_file *m, void *unused)
2053{
2054 struct drm_info_node *node = (struct drm_info_node *) m->private;
2055 struct drm_device *dev = node->minor->dev;
2056 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002057 struct intel_engine_cs *engine;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002058 struct intel_context *ctx;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002059 int ret;
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002060
2061 if (!i915.enable_execlists) {
2062 seq_printf(m, "Logical Ring Contexts are disabled\n");
2063 return 0;
2064 }
2065
2066 ret = mutex_lock_interruptible(&dev->struct_mutex);
2067 if (ret)
2068 return ret;
2069
Dave Gordone28e4042016-01-19 19:02:55 +00002070 list_for_each_entry(ctx, &dev_priv->context_list, link)
2071 if (ctx != dev_priv->kernel_context)
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002072 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002073 i915_dump_lrc_obj(m, ctx, engine);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002074
2075 mutex_unlock(&dev->struct_mutex);
2076
2077 return 0;
2078}
2079
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002080static int i915_execlists(struct seq_file *m, void *data)
2081{
2082 struct drm_info_node *node = (struct drm_info_node *)m->private;
2083 struct drm_device *dev = node->minor->dev;
2084 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002085 struct intel_engine_cs *engine;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002086 u32 status_pointer;
2087 u8 read_pointer;
2088 u8 write_pointer;
2089 u32 status;
2090 u32 ctx_id;
2091 struct list_head *cursor;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002092 int i, ret;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002093
2094 if (!i915.enable_execlists) {
2095 seq_puts(m, "Logical Ring Contexts are disabled\n");
2096 return 0;
2097 }
2098
2099 ret = mutex_lock_interruptible(&dev->struct_mutex);
2100 if (ret)
2101 return ret;
2102
Michel Thierryfc0412e2014-10-16 16:13:38 +01002103 intel_runtime_pm_get(dev_priv);
2104
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002105 for_each_engine(engine, dev_priv) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002106 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002107 int count = 0;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002108
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002109 seq_printf(m, "%s\n", engine->name);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002110
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002111 status = I915_READ(RING_EXECLIST_STATUS_LO(engine));
2112 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002113 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2114 status, ctx_id);
2115
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002116 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002117 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2118
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002119 read_pointer = engine->next_context_status_buffer;
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002120 write_pointer = GEN8_CSB_WRITE_PTR(status_pointer);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002121 if (read_pointer > write_pointer)
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002122 write_pointer += GEN8_CSB_ENTRIES;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002123 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2124 read_pointer, write_pointer);
2125
Ben Widawsky5590a5f2016-01-05 10:30:05 -08002126 for (i = 0; i < GEN8_CSB_ENTRIES; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002127 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, i));
2128 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002129
2130 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2131 i, status, ctx_id);
2132 }
2133
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002134 spin_lock_bh(&engine->execlist_lock);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002135 list_for_each(cursor, &engine->execlist_queue)
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002136 count++;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002137 head_req = list_first_entry_or_null(&engine->execlist_queue,
2138 struct drm_i915_gem_request,
2139 execlist_link);
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01002140 spin_unlock_bh(&engine->execlist_lock);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002141
2142 seq_printf(m, "\t%d requests in queue\n", count);
2143 if (head_req) {
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002144 seq_printf(m, "\tHead request id: %u\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002145 intel_execlists_ctx_id(head_req->ctx, engine));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002146 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002147 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002148 }
2149
2150 seq_putc(m, '\n');
2151 }
2152
Michel Thierryfc0412e2014-10-16 16:13:38 +01002153 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002154 mutex_unlock(&dev->struct_mutex);
2155
2156 return 0;
2157}
2158
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002159static const char *swizzle_string(unsigned swizzle)
2160{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002161 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002162 case I915_BIT_6_SWIZZLE_NONE:
2163 return "none";
2164 case I915_BIT_6_SWIZZLE_9:
2165 return "bit9";
2166 case I915_BIT_6_SWIZZLE_9_10:
2167 return "bit9/bit10";
2168 case I915_BIT_6_SWIZZLE_9_11:
2169 return "bit9/bit11";
2170 case I915_BIT_6_SWIZZLE_9_10_11:
2171 return "bit9/bit10/bit11";
2172 case I915_BIT_6_SWIZZLE_9_17:
2173 return "bit9/bit17";
2174 case I915_BIT_6_SWIZZLE_9_10_17:
2175 return "bit9/bit10/bit17";
2176 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002177 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002178 }
2179
2180 return "bug";
2181}
2182
2183static int i915_swizzle_info(struct seq_file *m, void *data)
2184{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002185 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002186 struct drm_device *dev = node->minor->dev;
2187 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002188 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002189
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002190 ret = mutex_lock_interruptible(&dev->struct_mutex);
2191 if (ret)
2192 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002193 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002194
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002195 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2196 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2197 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2198 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2199
2200 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2201 seq_printf(m, "DDC = 0x%08x\n",
2202 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002203 seq_printf(m, "DDC2 = 0x%08x\n",
2204 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002205 seq_printf(m, "C0DRB3 = 0x%04x\n",
2206 I915_READ16(C0DRB3));
2207 seq_printf(m, "C1DRB3 = 0x%04x\n",
2208 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002209 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002210 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2211 I915_READ(MAD_DIMM_C0));
2212 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2213 I915_READ(MAD_DIMM_C1));
2214 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2215 I915_READ(MAD_DIMM_C2));
2216 seq_printf(m, "TILECTL = 0x%08x\n",
2217 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002218 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002219 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2220 I915_READ(GAMTARBMODE));
2221 else
2222 seq_printf(m, "ARB_MODE = 0x%08x\n",
2223 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002224 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2225 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002226 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002227
2228 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2229 seq_puts(m, "L-shaped memory detected\n");
2230
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002231 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002232 mutex_unlock(&dev->struct_mutex);
2233
2234 return 0;
2235}
2236
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002237static int per_file_ctx(int id, void *ptr, void *data)
2238{
Oscar Mateo273497e2014-05-22 14:13:37 +01002239 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002240 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002241 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2242
2243 if (!ppgtt) {
2244 seq_printf(m, " no ppgtt for context %d\n",
2245 ctx->user_handle);
2246 return 0;
2247 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002248
Oscar Mateof83d6512014-05-22 14:13:38 +01002249 if (i915_gem_context_is_default(ctx))
2250 seq_puts(m, " default context:\n");
2251 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002252 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002253 ppgtt->debug_dump(ppgtt, m);
2254
2255 return 0;
2256}
2257
Ben Widawsky77df6772013-11-02 21:07:30 -07002258static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002259{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002260 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002261 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002262 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002263 int i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002264
Ben Widawsky77df6772013-11-02 21:07:30 -07002265 if (!ppgtt)
2266 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002267
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002268 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002269 seq_printf(m, "%s\n", engine->name);
Ben Widawsky77df6772013-11-02 21:07:30 -07002270 for (i = 0; i < 4; i++) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002271 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(engine, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002272 pdp <<= 32;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002273 pdp |= I915_READ(GEN8_RING_PDP_LDW(engine, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002274 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002275 }
2276 }
2277}
2278
2279static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2280{
2281 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002282 struct intel_engine_cs *engine;
Ben Widawsky77df6772013-11-02 21:07:30 -07002283
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002284 if (INTEL_INFO(dev)->gen == 6)
2285 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2286
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002287 for_each_engine(engine, dev_priv) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002288 seq_printf(m, "%s\n", engine->name);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002289 if (INTEL_INFO(dev)->gen == 7)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002290 seq_printf(m, "GFX_MODE: 0x%08x\n",
2291 I915_READ(RING_MODE_GEN7(engine)));
2292 seq_printf(m, "PP_DIR_BASE: 0x%08x\n",
2293 I915_READ(RING_PP_DIR_BASE(engine)));
2294 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n",
2295 I915_READ(RING_PP_DIR_BASE_READ(engine)));
2296 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n",
2297 I915_READ(RING_PP_DIR_DCLV(engine)));
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002298 }
2299 if (dev_priv->mm.aliasing_ppgtt) {
2300 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2301
Damien Lespiau267f0c92013-06-24 22:59:48 +01002302 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002303 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002304
Ben Widawsky87d60b62013-12-06 14:11:29 -08002305 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002306 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002307
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002308 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002309}
2310
2311static int i915_ppgtt_info(struct seq_file *m, void *data)
2312{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002313 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002314 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002315 struct drm_i915_private *dev_priv = dev->dev_private;
Michel Thierryea91e402015-07-29 17:23:57 +01002316 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002317
2318 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2319 if (ret)
2320 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002321 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002322
2323 if (INTEL_INFO(dev)->gen >= 8)
2324 gen8_ppgtt_info(m, dev);
2325 else if (INTEL_INFO(dev)->gen >= 6)
2326 gen6_ppgtt_info(m, dev);
2327
Michel Thierryea91e402015-07-29 17:23:57 +01002328 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2329 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002330 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002331
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002332 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002333 if (!task) {
2334 ret = -ESRCH;
2335 goto out_put;
2336 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002337 seq_printf(m, "\nproc: %s\n", task->comm);
2338 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002339 idr_for_each(&file_priv->context_idr, per_file_ctx,
2340 (void *)(unsigned long)m);
2341 }
2342
Dan Carpenter06812762015-10-02 18:14:22 +03002343out_put:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002344 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002345 mutex_unlock(&dev->struct_mutex);
2346
Dan Carpenter06812762015-10-02 18:14:22 +03002347 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002348}
2349
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002350static int count_irq_waiters(struct drm_i915_private *i915)
2351{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002352 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002353 int count = 0;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002354
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002355 for_each_engine(engine, i915)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002356 count += engine->irq_refcount;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002357
2358 return count;
2359}
2360
Chris Wilson1854d5c2015-04-07 16:20:32 +01002361static int i915_rps_boost_info(struct seq_file *m, void *data)
2362{
2363 struct drm_info_node *node = m->private;
2364 struct drm_device *dev = node->minor->dev;
2365 struct drm_i915_private *dev_priv = dev->dev_private;
2366 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002367
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002368 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2369 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2370 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2371 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2372 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2373 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2374 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2375 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2376 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson8d3afd72015-05-21 21:01:47 +01002377 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002378 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2379 struct drm_i915_file_private *file_priv = file->driver_priv;
2380 struct task_struct *task;
2381
2382 rcu_read_lock();
2383 task = pid_task(file->pid, PIDTYPE_PID);
2384 seq_printf(m, "%s [%d]: %d boosts%s\n",
2385 task ? task->comm : "<unknown>",
2386 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002387 file_priv->rps.boosts,
2388 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002389 rcu_read_unlock();
2390 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002391 seq_printf(m, "Semaphore boosts: %d%s\n",
2392 dev_priv->rps.semaphores.boosts,
2393 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2394 seq_printf(m, "MMIO flip boosts: %d%s\n",
2395 dev_priv->rps.mmioflips.boosts,
2396 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002397 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002398 spin_unlock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002399
Chris Wilson8d3afd72015-05-21 21:01:47 +01002400 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002401}
2402
Ben Widawsky63573eb2013-07-04 11:02:07 -07002403static int i915_llc(struct seq_file *m, void *data)
2404{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002405 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002406 struct drm_device *dev = node->minor->dev;
2407 struct drm_i915_private *dev_priv = dev->dev_private;
2408
2409 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2410 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2411 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2412
2413 return 0;
2414}
2415
Alex Daifdf5d352015-08-12 15:43:37 +01002416static int i915_guc_load_status_info(struct seq_file *m, void *data)
2417{
2418 struct drm_info_node *node = m->private;
2419 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2420 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2421 u32 tmp, i;
2422
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002423 if (!HAS_GUC_UCODE(dev_priv))
Alex Daifdf5d352015-08-12 15:43:37 +01002424 return 0;
2425
2426 seq_printf(m, "GuC firmware status:\n");
2427 seq_printf(m, "\tpath: %s\n",
2428 guc_fw->guc_fw_path);
2429 seq_printf(m, "\tfetch: %s\n",
2430 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2431 seq_printf(m, "\tload: %s\n",
2432 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2433 seq_printf(m, "\tversion wanted: %d.%d\n",
2434 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2435 seq_printf(m, "\tversion found: %d.%d\n",
2436 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
Alex Daifeda33e2015-10-19 16:10:54 -07002437 seq_printf(m, "\theader: offset is %d; size = %d\n",
2438 guc_fw->header_offset, guc_fw->header_size);
2439 seq_printf(m, "\tuCode: offset is %d; size = %d\n",
2440 guc_fw->ucode_offset, guc_fw->ucode_size);
2441 seq_printf(m, "\tRSA: offset is %d; size = %d\n",
2442 guc_fw->rsa_offset, guc_fw->rsa_size);
Alex Daifdf5d352015-08-12 15:43:37 +01002443
2444 tmp = I915_READ(GUC_STATUS);
2445
2446 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2447 seq_printf(m, "\tBootrom status = 0x%x\n",
2448 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2449 seq_printf(m, "\tuKernel status = 0x%x\n",
2450 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2451 seq_printf(m, "\tMIA Core status = 0x%x\n",
2452 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2453 seq_puts(m, "\nScratch registers:\n");
2454 for (i = 0; i < 16; i++)
2455 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2456
2457 return 0;
2458}
2459
Dave Gordon8b417c22015-08-12 15:43:44 +01002460static void i915_guc_client_info(struct seq_file *m,
2461 struct drm_i915_private *dev_priv,
2462 struct i915_guc_client *client)
2463{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002464 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002465 uint64_t tot = 0;
Dave Gordon8b417c22015-08-12 15:43:44 +01002466
2467 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2468 client->priority, client->ctx_index, client->proc_desc_offset);
2469 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2470 client->doorbell_id, client->doorbell_offset, client->cookie);
2471 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2472 client->wq_size, client->wq_offset, client->wq_tail);
2473
2474 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2475 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2476 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2477
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002478 for_each_engine(engine, dev_priv) {
Dave Gordon8b417c22015-08-12 15:43:44 +01002479 seq_printf(m, "\tSubmissions: %llu %s\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002480 client->submissions[engine->guc_id],
2481 engine->name);
2482 tot += client->submissions[engine->guc_id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002483 }
2484 seq_printf(m, "\tTotal: %llu\n", tot);
2485}
2486
2487static int i915_guc_info(struct seq_file *m, void *data)
2488{
2489 struct drm_info_node *node = m->private;
2490 struct drm_device *dev = node->minor->dev;
2491 struct drm_i915_private *dev_priv = dev->dev_private;
2492 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002493 struct i915_guc_client client = {};
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002494 struct intel_engine_cs *engine;
Dave Gordon8b417c22015-08-12 15:43:44 +01002495 u64 total = 0;
2496
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03002497 if (!HAS_GUC_SCHED(dev_priv))
Dave Gordon8b417c22015-08-12 15:43:44 +01002498 return 0;
2499
Alex Dai5a843302015-12-02 16:56:29 -08002500 if (mutex_lock_interruptible(&dev->struct_mutex))
2501 return 0;
2502
Dave Gordon8b417c22015-08-12 15:43:44 +01002503 /* Take a local copy of the GuC data, so we can dump it at leisure */
Dave Gordon8b417c22015-08-12 15:43:44 +01002504 guc = dev_priv->guc;
Alex Dai5a843302015-12-02 16:56:29 -08002505 if (guc.execbuf_client)
Dave Gordon8b417c22015-08-12 15:43:44 +01002506 client = *guc.execbuf_client;
Alex Dai5a843302015-12-02 16:56:29 -08002507
2508 mutex_unlock(&dev->struct_mutex);
Dave Gordon8b417c22015-08-12 15:43:44 +01002509
2510 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2511 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2512 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2513 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2514 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2515
2516 seq_printf(m, "\nGuC submissions:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002517 for_each_engine(engine, dev_priv) {
Alex Dai397097b2016-01-23 11:58:14 -08002518 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002519 engine->name, guc.submissions[engine->guc_id],
2520 guc.last_seqno[engine->guc_id]);
2521 total += guc.submissions[engine->guc_id];
Dave Gordon8b417c22015-08-12 15:43:44 +01002522 }
2523 seq_printf(m, "\t%s: %llu\n", "Total", total);
2524
2525 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2526 i915_guc_client_info(m, dev_priv, &client);
2527
2528 /* Add more as required ... */
2529
2530 return 0;
2531}
2532
Alex Dai4c7e77f2015-08-12 15:43:40 +01002533static int i915_guc_log_dump(struct seq_file *m, void *data)
2534{
2535 struct drm_info_node *node = m->private;
2536 struct drm_device *dev = node->minor->dev;
2537 struct drm_i915_private *dev_priv = dev->dev_private;
2538 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2539 u32 *log;
2540 int i = 0, pg;
2541
2542 if (!log_obj)
2543 return 0;
2544
2545 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2546 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2547
2548 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2549 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2550 *(log + i), *(log + i + 1),
2551 *(log + i + 2), *(log + i + 3));
2552
2553 kunmap_atomic(log);
2554 }
2555
2556 seq_putc(m, '\n');
2557
2558 return 0;
2559}
2560
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002561static int i915_edp_psr_status(struct seq_file *m, void *data)
2562{
2563 struct drm_info_node *node = m->private;
2564 struct drm_device *dev = node->minor->dev;
2565 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002566 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002567 u32 stat[3];
2568 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002569 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002570
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002571 if (!HAS_PSR(dev)) {
2572 seq_puts(m, "PSR not supported\n");
2573 return 0;
2574 }
2575
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002576 intel_runtime_pm_get(dev_priv);
2577
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002578 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002579 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2580 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002581 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002582 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002583 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2584 dev_priv->psr.busy_frontbuffer_bits);
2585 seq_printf(m, "Re-enable work scheduled: %s\n",
2586 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002587
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002588 if (HAS_DDI(dev))
Ville Syrjälä443a3892015-11-11 20:34:15 +02002589 enabled = I915_READ(EDP_PSR_CTL) & EDP_PSR_ENABLE;
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002590 else {
2591 for_each_pipe(dev_priv, pipe) {
2592 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2593 VLV_EDP_PSR_CURR_STATE_MASK;
2594 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2595 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2596 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002597 }
2598 }
Rodrigo Vivi60e5ffe2016-02-01 12:02:07 -08002599
2600 seq_printf(m, "Main link in standby mode: %s\n",
2601 yesno(dev_priv->psr.link_standby));
2602
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002603 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002604
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002605 if (!HAS_DDI(dev))
2606 for_each_pipe(dev_priv, pipe) {
2607 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2608 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2609 seq_printf(m, " pipe %c", pipe_name(pipe));
2610 }
2611 seq_puts(m, "\n");
2612
Rodrigo Vivi05eec3c2015-11-23 14:16:40 -08002613 /*
2614 * VLV/CHV PSR has no kind of performance counter
2615 * SKL+ Perf counter is reset to 0 everytime DC state is entered
2616 */
2617 if (IS_HASWELL(dev) || IS_BROADWELL(dev)) {
Ville Syrjälä443a3892015-11-11 20:34:15 +02002618 psrperf = I915_READ(EDP_PSR_PERF_CNT) &
Rodrigo Vivia031d702013-10-03 16:15:06 -03002619 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002620
2621 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2622 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002623 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002624
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002625 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002626 return 0;
2627}
2628
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002629static int i915_sink_crc(struct seq_file *m, void *data)
2630{
2631 struct drm_info_node *node = m->private;
2632 struct drm_device *dev = node->minor->dev;
2633 struct intel_encoder *encoder;
2634 struct intel_connector *connector;
2635 struct intel_dp *intel_dp = NULL;
2636 int ret;
2637 u8 crc[6];
2638
2639 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002640 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002641
2642 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2643 continue;
2644
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002645 if (!connector->base.encoder)
2646 continue;
2647
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002648 encoder = to_intel_encoder(connector->base.encoder);
2649 if (encoder->type != INTEL_OUTPUT_EDP)
2650 continue;
2651
2652 intel_dp = enc_to_intel_dp(&encoder->base);
2653
2654 ret = intel_dp_sink_crc(intel_dp, crc);
2655 if (ret)
2656 goto out;
2657
2658 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2659 crc[0], crc[1], crc[2],
2660 crc[3], crc[4], crc[5]);
2661 goto out;
2662 }
2663 ret = -ENODEV;
2664out:
2665 drm_modeset_unlock_all(dev);
2666 return ret;
2667}
2668
Jesse Barnesec013e72013-08-20 10:29:23 +01002669static int i915_energy_uJ(struct seq_file *m, void *data)
2670{
2671 struct drm_info_node *node = m->private;
2672 struct drm_device *dev = node->minor->dev;
2673 struct drm_i915_private *dev_priv = dev->dev_private;
2674 u64 power;
2675 u32 units;
2676
2677 if (INTEL_INFO(dev)->gen < 6)
2678 return -ENODEV;
2679
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002680 intel_runtime_pm_get(dev_priv);
2681
Jesse Barnesec013e72013-08-20 10:29:23 +01002682 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2683 power = (power & 0x1f00) >> 8;
2684 units = 1000000 / (1 << power); /* convert to uJ */
2685 power = I915_READ(MCH_SECP_NRG_STTS);
2686 power *= units;
2687
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002688 intel_runtime_pm_put(dev_priv);
2689
Jesse Barnesec013e72013-08-20 10:29:23 +01002690 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002691
2692 return 0;
2693}
2694
Damien Lespiau6455c872015-06-04 18:23:57 +01002695static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002696{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002697 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002698 struct drm_device *dev = node->minor->dev;
2699 struct drm_i915_private *dev_priv = dev->dev_private;
2700
Chris Wilsona156e642016-04-03 14:14:21 +01002701 if (!HAS_RUNTIME_PM(dev_priv))
2702 seq_puts(m, "Runtime power management not supported\n");
Paulo Zanoni371db662013-08-19 13:18:10 -03002703
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002704 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002705 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002706 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002707#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002708 seq_printf(m, "Usage count: %d\n",
2709 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002710#else
2711 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2712#endif
Chris Wilsona156e642016-04-03 14:14:21 +01002713 seq_printf(m, "PCI device power state: %s [%d]\n",
2714 pci_power_name(dev_priv->dev->pdev->current_state),
2715 dev_priv->dev->pdev->current_state);
Paulo Zanoni371db662013-08-19 13:18:10 -03002716
Jesse Barnesec013e72013-08-20 10:29:23 +01002717 return 0;
2718}
2719
Imre Deak1da51582013-11-25 17:15:35 +02002720static int i915_power_domain_info(struct seq_file *m, void *unused)
2721{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002722 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002723 struct drm_device *dev = node->minor->dev;
2724 struct drm_i915_private *dev_priv = dev->dev_private;
2725 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2726 int i;
2727
2728 mutex_lock(&power_domains->lock);
2729
2730 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2731 for (i = 0; i < power_domains->power_well_count; i++) {
2732 struct i915_power_well *power_well;
2733 enum intel_display_power_domain power_domain;
2734
2735 power_well = &power_domains->power_wells[i];
2736 seq_printf(m, "%-25s %d\n", power_well->name,
2737 power_well->count);
2738
2739 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2740 power_domain++) {
2741 if (!(BIT(power_domain) & power_well->domains))
2742 continue;
2743
2744 seq_printf(m, " %-23s %d\n",
Daniel Stone9895ad02015-11-20 15:55:33 +00002745 intel_display_power_domain_str(power_domain),
Imre Deak1da51582013-11-25 17:15:35 +02002746 power_domains->domain_use_count[power_domain]);
2747 }
2748 }
2749
2750 mutex_unlock(&power_domains->lock);
2751
2752 return 0;
2753}
2754
Damien Lespiaub7cec662015-10-27 14:47:01 +02002755static int i915_dmc_info(struct seq_file *m, void *unused)
2756{
2757 struct drm_info_node *node = m->private;
2758 struct drm_device *dev = node->minor->dev;
2759 struct drm_i915_private *dev_priv = dev->dev_private;
2760 struct intel_csr *csr;
2761
2762 if (!HAS_CSR(dev)) {
2763 seq_puts(m, "not supported\n");
2764 return 0;
2765 }
2766
2767 csr = &dev_priv->csr;
2768
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002769 intel_runtime_pm_get(dev_priv);
2770
Damien Lespiaub7cec662015-10-27 14:47:01 +02002771 seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
2772 seq_printf(m, "path: %s\n", csr->fw_path);
2773
2774 if (!csr->dmc_payload)
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002775 goto out;
Damien Lespiaub7cec662015-10-27 14:47:01 +02002776
2777 seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
2778 CSR_VERSION_MINOR(csr->version));
2779
Damien Lespiau83372062015-10-30 17:53:32 +02002780 if (IS_SKYLAKE(dev) && csr->version >= CSR_VERSION(1, 6)) {
2781 seq_printf(m, "DC3 -> DC5 count: %d\n",
2782 I915_READ(SKL_CSR_DC3_DC5_COUNT));
2783 seq_printf(m, "DC5 -> DC6 count: %d\n",
2784 I915_READ(SKL_CSR_DC5_DC6_COUNT));
Mika Kuoppala16e11b92015-10-27 14:47:03 +02002785 } else if (IS_BROXTON(dev) && csr->version >= CSR_VERSION(1, 4)) {
2786 seq_printf(m, "DC3 -> DC5 count: %d\n",
2787 I915_READ(BXT_CSR_DC3_DC5_COUNT));
Damien Lespiau83372062015-10-30 17:53:32 +02002788 }
2789
Mika Kuoppala6fb403d2015-10-30 17:54:47 +02002790out:
2791 seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
2792 seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
2793 seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
2794
Damien Lespiau83372062015-10-30 17:53:32 +02002795 intel_runtime_pm_put(dev_priv);
2796
Damien Lespiaub7cec662015-10-27 14:47:01 +02002797 return 0;
2798}
2799
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002800static void intel_seq_print_mode(struct seq_file *m, int tabs,
2801 struct drm_display_mode *mode)
2802{
2803 int i;
2804
2805 for (i = 0; i < tabs; i++)
2806 seq_putc(m, '\t');
2807
2808 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",
2809 mode->base.id, mode->name,
2810 mode->vrefresh, mode->clock,
2811 mode->hdisplay, mode->hsync_start,
2812 mode->hsync_end, mode->htotal,
2813 mode->vdisplay, mode->vsync_start,
2814 mode->vsync_end, mode->vtotal,
2815 mode->type, mode->flags);
2816}
2817
2818static void intel_encoder_info(struct seq_file *m,
2819 struct intel_crtc *intel_crtc,
2820 struct intel_encoder *intel_encoder)
2821{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002822 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002823 struct drm_device *dev = node->minor->dev;
2824 struct drm_crtc *crtc = &intel_crtc->base;
2825 struct intel_connector *intel_connector;
2826 struct drm_encoder *encoder;
2827
2828 encoder = &intel_encoder->base;
2829 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002830 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002831 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2832 struct drm_connector *connector = &intel_connector->base;
2833 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2834 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002835 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002836 drm_get_connector_status_name(connector->status));
2837 if (connector->status == connector_status_connected) {
2838 struct drm_display_mode *mode = &crtc->mode;
2839 seq_printf(m, ", mode:\n");
2840 intel_seq_print_mode(m, 2, mode);
2841 } else {
2842 seq_putc(m, '\n');
2843 }
2844 }
2845}
2846
2847static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2848{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002849 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002850 struct drm_device *dev = node->minor->dev;
2851 struct drm_crtc *crtc = &intel_crtc->base;
2852 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002853 struct drm_plane_state *plane_state = crtc->primary->state;
2854 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002855
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002856 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002857 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002858 fb->base.id, plane_state->src_x >> 16,
2859 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002860 else
2861 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002862 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2863 intel_encoder_info(m, intel_crtc, intel_encoder);
2864}
2865
2866static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2867{
2868 struct drm_display_mode *mode = panel->fixed_mode;
2869
2870 seq_printf(m, "\tfixed mode:\n");
2871 intel_seq_print_mode(m, 2, mode);
2872}
2873
2874static void intel_dp_info(struct seq_file *m,
2875 struct intel_connector *intel_connector)
2876{
2877 struct intel_encoder *intel_encoder = intel_connector->encoder;
2878 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2879
2880 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002881 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002882 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2883 intel_panel_info(m, &intel_connector->panel);
2884}
2885
Libin Yang3d52ccf2015-12-02 14:09:44 +08002886static void intel_dp_mst_info(struct seq_file *m,
2887 struct intel_connector *intel_connector)
2888{
2889 struct intel_encoder *intel_encoder = intel_connector->encoder;
2890 struct intel_dp_mst_encoder *intel_mst =
2891 enc_to_mst(&intel_encoder->base);
2892 struct intel_digital_port *intel_dig_port = intel_mst->primary;
2893 struct intel_dp *intel_dp = &intel_dig_port->dp;
2894 bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
2895 intel_connector->port);
2896
2897 seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
2898}
2899
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002900static void intel_hdmi_info(struct seq_file *m,
2901 struct intel_connector *intel_connector)
2902{
2903 struct intel_encoder *intel_encoder = intel_connector->encoder;
2904 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2905
Jani Nikula742f4912015-09-03 11:16:09 +03002906 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002907}
2908
2909static void intel_lvds_info(struct seq_file *m,
2910 struct intel_connector *intel_connector)
2911{
2912 intel_panel_info(m, &intel_connector->panel);
2913}
2914
2915static void intel_connector_info(struct seq_file *m,
2916 struct drm_connector *connector)
2917{
2918 struct intel_connector *intel_connector = to_intel_connector(connector);
2919 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002920 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002921
2922 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002923 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002924 drm_get_connector_status_name(connector->status));
2925 if (connector->status == connector_status_connected) {
2926 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2927 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2928 connector->display_info.width_mm,
2929 connector->display_info.height_mm);
2930 seq_printf(m, "\tsubpixel order: %s\n",
2931 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2932 seq_printf(m, "\tCEA rev: %d\n",
2933 connector->display_info.cea_rev);
2934 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002935 if (intel_encoder) {
2936 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2937 intel_encoder->type == INTEL_OUTPUT_EDP)
2938 intel_dp_info(m, intel_connector);
2939 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2940 intel_hdmi_info(m, intel_connector);
2941 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2942 intel_lvds_info(m, intel_connector);
Libin Yang3d52ccf2015-12-02 14:09:44 +08002943 else if (intel_encoder->type == INTEL_OUTPUT_DP_MST)
2944 intel_dp_mst_info(m, intel_connector);
Dave Airlie36cd7442014-05-02 13:44:18 +10002945 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002946
Jesse Barnesf103fc72014-02-20 12:39:57 -08002947 seq_printf(m, "\tmodes:\n");
2948 list_for_each_entry(mode, &connector->modes, head)
2949 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002950}
2951
Chris Wilson065f2ec22014-03-12 09:13:13 +00002952static bool cursor_active(struct drm_device *dev, int pipe)
2953{
2954 struct drm_i915_private *dev_priv = dev->dev_private;
2955 u32 state;
2956
2957 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002958 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002959 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002960 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002961
2962 return state;
2963}
2964
2965static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2966{
2967 struct drm_i915_private *dev_priv = dev->dev_private;
2968 u32 pos;
2969
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002970 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00002971
2972 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2973 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2974 *x = -*x;
2975
2976 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2977 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2978 *y = -*y;
2979
2980 return cursor_active(dev, pipe);
2981}
2982
Robert Fekete3abc4e02015-10-27 16:58:32 +01002983static const char *plane_type(enum drm_plane_type type)
2984{
2985 switch (type) {
2986 case DRM_PLANE_TYPE_OVERLAY:
2987 return "OVL";
2988 case DRM_PLANE_TYPE_PRIMARY:
2989 return "PRI";
2990 case DRM_PLANE_TYPE_CURSOR:
2991 return "CUR";
2992 /*
2993 * Deliberately omitting default: to generate compiler warnings
2994 * when a new drm_plane_type gets added.
2995 */
2996 }
2997
2998 return "unknown";
2999}
3000
3001static const char *plane_rotation(unsigned int rotation)
3002{
3003 static char buf[48];
3004 /*
3005 * According to doc only one DRM_ROTATE_ is allowed but this
3006 * will print them all to visualize if the values are misused
3007 */
3008 snprintf(buf, sizeof(buf),
3009 "%s%s%s%s%s%s(0x%08x)",
3010 (rotation & BIT(DRM_ROTATE_0)) ? "0 " : "",
3011 (rotation & BIT(DRM_ROTATE_90)) ? "90 " : "",
3012 (rotation & BIT(DRM_ROTATE_180)) ? "180 " : "",
3013 (rotation & BIT(DRM_ROTATE_270)) ? "270 " : "",
3014 (rotation & BIT(DRM_REFLECT_X)) ? "FLIPX " : "",
3015 (rotation & BIT(DRM_REFLECT_Y)) ? "FLIPY " : "",
3016 rotation);
3017
3018 return buf;
3019}
3020
3021static void intel_plane_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3022{
3023 struct drm_info_node *node = m->private;
3024 struct drm_device *dev = node->minor->dev;
3025 struct intel_plane *intel_plane;
3026
3027 for_each_intel_plane_on_crtc(dev, intel_crtc, intel_plane) {
3028 struct drm_plane_state *state;
3029 struct drm_plane *plane = &intel_plane->base;
3030
3031 if (!plane->state) {
3032 seq_puts(m, "plane->state is NULL!\n");
3033 continue;
3034 }
3035
3036 state = plane->state;
3037
3038 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",
3039 plane->base.id,
3040 plane_type(intel_plane->base.type),
3041 state->crtc_x, state->crtc_y,
3042 state->crtc_w, state->crtc_h,
3043 (state->src_x >> 16),
3044 ((state->src_x & 0xffff) * 15625) >> 10,
3045 (state->src_y >> 16),
3046 ((state->src_y & 0xffff) * 15625) >> 10,
3047 (state->src_w >> 16),
3048 ((state->src_w & 0xffff) * 15625) >> 10,
3049 (state->src_h >> 16),
3050 ((state->src_h & 0xffff) * 15625) >> 10,
3051 state->fb ? drm_get_format_name(state->fb->pixel_format) : "N/A",
3052 plane_rotation(state->rotation));
3053 }
3054}
3055
3056static void intel_scaler_info(struct seq_file *m, struct intel_crtc *intel_crtc)
3057{
3058 struct intel_crtc_state *pipe_config;
3059 int num_scalers = intel_crtc->num_scalers;
3060 int i;
3061
3062 pipe_config = to_intel_crtc_state(intel_crtc->base.state);
3063
3064 /* Not all platformas have a scaler */
3065 if (num_scalers) {
3066 seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
3067 num_scalers,
3068 pipe_config->scaler_state.scaler_users,
3069 pipe_config->scaler_state.scaler_id);
3070
3071 for (i = 0; i < SKL_NUM_SCALERS; i++) {
3072 struct intel_scaler *sc =
3073 &pipe_config->scaler_state.scalers[i];
3074
3075 seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
3076 i, yesno(sc->in_use), sc->mode);
3077 }
3078 seq_puts(m, "\n");
3079 } else {
3080 seq_puts(m, "\tNo scalers available on this platform\n");
3081 }
3082}
3083
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003084static int i915_display_info(struct seq_file *m, void *unused)
3085{
Damien Lespiau9f25d002014-05-13 15:30:28 +01003086 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003087 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003088 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003089 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003090 struct drm_connector *connector;
3091
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003092 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003093 drm_modeset_lock_all(dev);
3094 seq_printf(m, "CRTC info\n");
3095 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01003096 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003097 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003098 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec22014-03-12 09:13:13 +00003099 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003100
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003101 pipe_config = to_intel_crtc_state(crtc->base.state);
3102
Robert Fekete3abc4e02015-10-27 16:58:32 +01003103 seq_printf(m, "CRTC %d: pipe: %c, active=%s, (size=%dx%d), dither=%s, bpp=%d\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00003104 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003105 yesno(pipe_config->base.active),
Robert Fekete3abc4e02015-10-27 16:58:32 +01003106 pipe_config->pipe_src_w, pipe_config->pipe_src_h,
3107 yesno(pipe_config->dither), pipe_config->pipe_bpp);
3108
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003109 if (pipe_config->base.active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00003110 intel_crtc_info(m, crtc);
3111
Paulo Zanonia23dc652014-04-01 14:55:11 -03003112 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01003113 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 +03003114 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08003115 x, y, crtc->base.cursor->state->crtc_w,
3116 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01003117 crtc->cursor_addr, yesno(active));
Robert Fekete3abc4e02015-10-27 16:58:32 +01003118 intel_scaler_info(m, crtc);
3119 intel_plane_info(m, crtc);
Paulo Zanonia23dc652014-04-01 14:55:11 -03003120 }
Daniel Vettercace8412014-05-22 17:56:31 +02003121
3122 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
3123 yesno(!crtc->cpu_fifo_underrun_disabled),
3124 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003125 }
3126
3127 seq_printf(m, "\n");
3128 seq_printf(m, "Connector info\n");
3129 seq_printf(m, "--------------\n");
3130 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
3131 intel_connector_info(m, connector);
3132 }
3133 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03003134 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003135
3136 return 0;
3137}
3138
Ben Widawskye04934c2014-06-30 09:53:42 -07003139static int i915_semaphore_status(struct seq_file *m, void *unused)
3140{
3141 struct drm_info_node *node = (struct drm_info_node *) m->private;
3142 struct drm_device *dev = node->minor->dev;
3143 struct drm_i915_private *dev_priv = dev->dev_private;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003144 struct intel_engine_cs *engine;
Ben Widawskye04934c2014-06-30 09:53:42 -07003145 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
Dave Gordonc3232b12016-03-23 18:19:53 +00003146 enum intel_engine_id id;
3147 int j, ret;
Ben Widawskye04934c2014-06-30 09:53:42 -07003148
3149 if (!i915_semaphore_is_enabled(dev)) {
3150 seq_puts(m, "Semaphores are disabled\n");
3151 return 0;
3152 }
3153
3154 ret = mutex_lock_interruptible(&dev->struct_mutex);
3155 if (ret)
3156 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003157 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003158
3159 if (IS_BROADWELL(dev)) {
3160 struct page *page;
3161 uint64_t *seqno;
3162
3163 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3164
3165 seqno = (uint64_t *)kmap_atomic(page);
Dave Gordonc3232b12016-03-23 18:19:53 +00003166 for_each_engine_id(engine, dev_priv, id) {
Ben Widawskye04934c2014-06-30 09:53:42 -07003167 uint64_t offset;
3168
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003169 seq_printf(m, "%s\n", engine->name);
Ben Widawskye04934c2014-06-30 09:53:42 -07003170
3171 seq_puts(m, " Last signal:");
3172 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003173 offset = id * I915_NUM_ENGINES + j;
Ben Widawskye04934c2014-06-30 09:53:42 -07003174 seq_printf(m, "0x%08llx (0x%02llx) ",
3175 seqno[offset], offset * 8);
3176 }
3177 seq_putc(m, '\n');
3178
3179 seq_puts(m, " Last wait: ");
3180 for (j = 0; j < num_rings; j++) {
Dave Gordonc3232b12016-03-23 18:19:53 +00003181 offset = id + (j * I915_NUM_ENGINES);
Ben Widawskye04934c2014-06-30 09:53:42 -07003182 seq_printf(m, "0x%08llx (0x%02llx) ",
3183 seqno[offset], offset * 8);
3184 }
3185 seq_putc(m, '\n');
3186
3187 }
3188 kunmap_atomic(seqno);
3189 } else {
3190 seq_puts(m, " Last signal:");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003191 for_each_engine(engine, dev_priv)
Ben Widawskye04934c2014-06-30 09:53:42 -07003192 for (j = 0; j < num_rings; j++)
3193 seq_printf(m, "0x%08x\n",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003194 I915_READ(engine->semaphore.mbox.signal[j]));
Ben Widawskye04934c2014-06-30 09:53:42 -07003195 seq_putc(m, '\n');
3196 }
3197
3198 seq_puts(m, "\nSync seqno:\n");
Dave Gordonb4ac5af2016-03-24 11:20:38 +00003199 for_each_engine(engine, dev_priv) {
3200 for (j = 0; j < num_rings; j++)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003201 seq_printf(m, " 0x%08x ",
3202 engine->semaphore.sync_seqno[j]);
Ben Widawskye04934c2014-06-30 09:53:42 -07003203 seq_putc(m, '\n');
3204 }
3205 seq_putc(m, '\n');
3206
Paulo Zanoni03872062014-07-09 14:31:57 -03003207 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003208 mutex_unlock(&dev->struct_mutex);
3209 return 0;
3210}
3211
Daniel Vetter728e29d2014-06-25 22:01:53 +03003212static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3213{
3214 struct drm_info_node *node = (struct drm_info_node *) m->private;
3215 struct drm_device *dev = node->minor->dev;
3216 struct drm_i915_private *dev_priv = dev->dev_private;
3217 int i;
3218
3219 drm_modeset_lock_all(dev);
3220 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3221 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3222
3223 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Maarten Lankhorst2dd66ebd2016-03-14 09:27:52 +01003224 seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
3225 pll->config.crtc_mask, pll->active_mask, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003226 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003227 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3228 seq_printf(m, " dpll_md: 0x%08x\n",
3229 pll->config.hw_state.dpll_md);
3230 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3231 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3232 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003233 }
3234 drm_modeset_unlock_all(dev);
3235
3236 return 0;
3237}
3238
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003239static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003240{
3241 int i;
3242 int ret;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003243 struct intel_engine_cs *engine;
Arun Siluvery888b5992014-08-26 14:44:51 +01003244 struct drm_info_node *node = (struct drm_info_node *) m->private;
3245 struct drm_device *dev = node->minor->dev;
3246 struct drm_i915_private *dev_priv = dev->dev_private;
Arun Siluvery33136b02016-01-21 21:43:47 +00003247 struct i915_workarounds *workarounds = &dev_priv->workarounds;
Dave Gordonc3232b12016-03-23 18:19:53 +00003248 enum intel_engine_id id;
Arun Siluvery888b5992014-08-26 14:44:51 +01003249
Arun Siluvery888b5992014-08-26 14:44:51 +01003250 ret = mutex_lock_interruptible(&dev->struct_mutex);
3251 if (ret)
3252 return ret;
3253
3254 intel_runtime_pm_get(dev_priv);
3255
Arun Siluvery33136b02016-01-21 21:43:47 +00003256 seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
Dave Gordonc3232b12016-03-23 18:19:53 +00003257 for_each_engine_id(engine, dev_priv, id)
Arun Siluvery33136b02016-01-21 21:43:47 +00003258 seq_printf(m, "HW whitelist count for %s: %d\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003259 engine->name, workarounds->hw_whitelist_count[id]);
Arun Siluvery33136b02016-01-21 21:43:47 +00003260 for (i = 0; i < workarounds->count; ++i) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003261 i915_reg_t addr;
3262 u32 mask, value, read;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003263 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003264
Arun Siluvery33136b02016-01-21 21:43:47 +00003265 addr = workarounds->reg[i].addr;
3266 mask = workarounds->reg[i].mask;
3267 value = workarounds->reg[i].value;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003268 read = I915_READ(addr);
3269 ok = (value & mask) == (read & mask);
3270 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 +02003271 i915_mmio_reg_offset(addr), value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003272 }
3273
3274 intel_runtime_pm_put(dev_priv);
3275 mutex_unlock(&dev->struct_mutex);
3276
3277 return 0;
3278}
3279
Damien Lespiauc5511e42014-11-04 17:06:51 +00003280static int i915_ddb_info(struct seq_file *m, void *unused)
3281{
3282 struct drm_info_node *node = m->private;
3283 struct drm_device *dev = node->minor->dev;
3284 struct drm_i915_private *dev_priv = dev->dev_private;
3285 struct skl_ddb_allocation *ddb;
3286 struct skl_ddb_entry *entry;
3287 enum pipe pipe;
3288 int plane;
3289
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003290 if (INTEL_INFO(dev)->gen < 9)
3291 return 0;
3292
Damien Lespiauc5511e42014-11-04 17:06:51 +00003293 drm_modeset_lock_all(dev);
3294
3295 ddb = &dev_priv->wm.skl_hw.ddb;
3296
3297 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3298
3299 for_each_pipe(dev_priv, pipe) {
3300 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3301
Damien Lespiaudd740782015-02-28 14:54:08 +00003302 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003303 entry = &ddb->plane[pipe][plane];
3304 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3305 entry->start, entry->end,
3306 skl_ddb_entry_size(entry));
3307 }
3308
Matt Roper4969d332015-09-24 15:53:10 -07003309 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003310 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3311 entry->end, skl_ddb_entry_size(entry));
3312 }
3313
3314 drm_modeset_unlock_all(dev);
3315
3316 return 0;
3317}
3318
Vandana Kannana54746e2015-03-03 20:53:10 +05303319static void drrs_status_per_crtc(struct seq_file *m,
3320 struct drm_device *dev, struct intel_crtc *intel_crtc)
3321{
3322 struct intel_encoder *intel_encoder;
3323 struct drm_i915_private *dev_priv = dev->dev_private;
3324 struct i915_drrs *drrs = &dev_priv->drrs;
3325 int vrefresh = 0;
3326
3327 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3328 /* Encoder connected on this CRTC */
3329 switch (intel_encoder->type) {
3330 case INTEL_OUTPUT_EDP:
3331 seq_puts(m, "eDP:\n");
3332 break;
3333 case INTEL_OUTPUT_DSI:
3334 seq_puts(m, "DSI:\n");
3335 break;
3336 case INTEL_OUTPUT_HDMI:
3337 seq_puts(m, "HDMI:\n");
3338 break;
3339 case INTEL_OUTPUT_DISPLAYPORT:
3340 seq_puts(m, "DP:\n");
3341 break;
3342 default:
3343 seq_printf(m, "Other encoder (id=%d).\n",
3344 intel_encoder->type);
3345 return;
3346 }
3347 }
3348
3349 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3350 seq_puts(m, "\tVBT: DRRS_type: Static");
3351 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3352 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3353 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3354 seq_puts(m, "\tVBT: DRRS_type: None");
3355 else
3356 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3357
3358 seq_puts(m, "\n\n");
3359
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003360 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303361 struct intel_panel *panel;
3362
3363 mutex_lock(&drrs->mutex);
3364 /* DRRS Supported */
3365 seq_puts(m, "\tDRRS Supported: Yes\n");
3366
3367 /* disable_drrs() will make drrs->dp NULL */
3368 if (!drrs->dp) {
3369 seq_puts(m, "Idleness DRRS: Disabled");
3370 mutex_unlock(&drrs->mutex);
3371 return;
3372 }
3373
3374 panel = &drrs->dp->attached_connector->panel;
3375 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3376 drrs->busy_frontbuffer_bits);
3377
3378 seq_puts(m, "\n\t\t");
3379 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3380 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3381 vrefresh = panel->fixed_mode->vrefresh;
3382 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3383 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3384 vrefresh = panel->downclock_mode->vrefresh;
3385 } else {
3386 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3387 drrs->refresh_rate_type);
3388 mutex_unlock(&drrs->mutex);
3389 return;
3390 }
3391 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3392
3393 seq_puts(m, "\n\t\t");
3394 mutex_unlock(&drrs->mutex);
3395 } else {
3396 /* DRRS not supported. Print the VBT parameter*/
3397 seq_puts(m, "\tDRRS Supported : No");
3398 }
3399 seq_puts(m, "\n");
3400}
3401
3402static int i915_drrs_status(struct seq_file *m, void *unused)
3403{
3404 struct drm_info_node *node = m->private;
3405 struct drm_device *dev = node->minor->dev;
3406 struct intel_crtc *intel_crtc;
3407 int active_crtc_cnt = 0;
3408
3409 for_each_intel_crtc(dev, intel_crtc) {
3410 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3411
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003412 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303413 active_crtc_cnt++;
3414 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3415
3416 drrs_status_per_crtc(m, dev, intel_crtc);
3417 }
3418
3419 drm_modeset_unlock(&intel_crtc->base.mutex);
3420 }
3421
3422 if (!active_crtc_cnt)
3423 seq_puts(m, "No active crtc found\n");
3424
3425 return 0;
3426}
3427
Damien Lespiau07144422013-10-15 18:55:40 +01003428struct pipe_crc_info {
3429 const char *name;
3430 struct drm_device *dev;
3431 enum pipe pipe;
3432};
3433
Dave Airlie11bed952014-05-12 15:22:27 +10003434static int i915_dp_mst_info(struct seq_file *m, void *unused)
3435{
3436 struct drm_info_node *node = (struct drm_info_node *) m->private;
3437 struct drm_device *dev = node->minor->dev;
3438 struct drm_encoder *encoder;
3439 struct intel_encoder *intel_encoder;
3440 struct intel_digital_port *intel_dig_port;
3441 drm_modeset_lock_all(dev);
3442 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3443 intel_encoder = to_intel_encoder(encoder);
3444 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3445 continue;
3446 intel_dig_port = enc_to_dig_port(encoder);
3447 if (!intel_dig_port->dp.can_mst)
3448 continue;
3449
3450 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3451 }
3452 drm_modeset_unlock_all(dev);
3453 return 0;
3454}
3455
Damien Lespiau07144422013-10-15 18:55:40 +01003456static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003457{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003458 struct pipe_crc_info *info = inode->i_private;
3459 struct drm_i915_private *dev_priv = info->dev->dev_private;
3460 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3461
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003462 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3463 return -ENODEV;
3464
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003465 spin_lock_irq(&pipe_crc->lock);
3466
3467 if (pipe_crc->opened) {
3468 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003469 return -EBUSY; /* already open */
3470 }
3471
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003472 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003473 filep->private_data = inode->i_private;
3474
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003475 spin_unlock_irq(&pipe_crc->lock);
3476
Damien Lespiau07144422013-10-15 18:55:40 +01003477 return 0;
3478}
3479
3480static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3481{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003482 struct pipe_crc_info *info = inode->i_private;
3483 struct drm_i915_private *dev_priv = info->dev->dev_private;
3484 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3485
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003486 spin_lock_irq(&pipe_crc->lock);
3487 pipe_crc->opened = false;
3488 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003489
Damien Lespiau07144422013-10-15 18:55:40 +01003490 return 0;
3491}
3492
3493/* (6 fields, 8 chars each, space separated (5) + '\n') */
3494#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3495/* account for \'0' */
3496#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3497
3498static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3499{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003500 assert_spin_locked(&pipe_crc->lock);
3501 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3502 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003503}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003504
Damien Lespiau07144422013-10-15 18:55:40 +01003505static ssize_t
3506i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3507 loff_t *pos)
3508{
3509 struct pipe_crc_info *info = filep->private_data;
3510 struct drm_device *dev = info->dev;
3511 struct drm_i915_private *dev_priv = dev->dev_private;
3512 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3513 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003514 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003515 ssize_t bytes_read;
3516
3517 /*
3518 * Don't allow user space to provide buffers not big enough to hold
3519 * a line of data.
3520 */
3521 if (count < PIPE_CRC_LINE_LEN)
3522 return -EINVAL;
3523
3524 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3525 return 0;
3526
3527 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003528 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003529 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003530 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003531
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003532 if (filep->f_flags & O_NONBLOCK) {
3533 spin_unlock_irq(&pipe_crc->lock);
3534 return -EAGAIN;
3535 }
3536
3537 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3538 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3539 if (ret) {
3540 spin_unlock_irq(&pipe_crc->lock);
3541 return ret;
3542 }
Damien Lespiau07144422013-10-15 18:55:40 +01003543 }
3544
3545 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003546 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003547
Damien Lespiau07144422013-10-15 18:55:40 +01003548 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003549 while (n_entries > 0) {
3550 struct intel_pipe_crc_entry *entry =
3551 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003552 int ret;
3553
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003554 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3555 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3556 break;
3557
3558 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3559 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3560
Damien Lespiau07144422013-10-15 18:55:40 +01003561 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3562 "%8u %8x %8x %8x %8x %8x\n",
3563 entry->frame, entry->crc[0],
3564 entry->crc[1], entry->crc[2],
3565 entry->crc[3], entry->crc[4]);
3566
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003567 spin_unlock_irq(&pipe_crc->lock);
3568
3569 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003570 if (ret == PIPE_CRC_LINE_LEN)
3571 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003572
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003573 user_buf += PIPE_CRC_LINE_LEN;
3574 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003575
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003576 spin_lock_irq(&pipe_crc->lock);
3577 }
3578
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003579 spin_unlock_irq(&pipe_crc->lock);
3580
Damien Lespiau07144422013-10-15 18:55:40 +01003581 return bytes_read;
3582}
3583
3584static const struct file_operations i915_pipe_crc_fops = {
3585 .owner = THIS_MODULE,
3586 .open = i915_pipe_crc_open,
3587 .read = i915_pipe_crc_read,
3588 .release = i915_pipe_crc_release,
3589};
3590
3591static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3592 {
3593 .name = "i915_pipe_A_crc",
3594 .pipe = PIPE_A,
3595 },
3596 {
3597 .name = "i915_pipe_B_crc",
3598 .pipe = PIPE_B,
3599 },
3600 {
3601 .name = "i915_pipe_C_crc",
3602 .pipe = PIPE_C,
3603 },
3604};
3605
3606static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3607 enum pipe pipe)
3608{
3609 struct drm_device *dev = minor->dev;
3610 struct dentry *ent;
3611 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3612
3613 info->dev = dev;
3614 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3615 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003616 if (!ent)
3617 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003618
3619 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003620}
3621
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003622static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003623 "none",
3624 "plane1",
3625 "plane2",
3626 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003627 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003628 "TV",
3629 "DP-B",
3630 "DP-C",
3631 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003632 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003633};
3634
3635static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3636{
3637 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3638 return pipe_crc_sources[source];
3639}
3640
Damien Lespiaubd9db022013-10-15 18:55:36 +01003641static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003642{
3643 struct drm_device *dev = m->private;
3644 struct drm_i915_private *dev_priv = dev->dev_private;
3645 int i;
3646
3647 for (i = 0; i < I915_MAX_PIPES; i++)
3648 seq_printf(m, "%c %s\n", pipe_name(i),
3649 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3650
3651 return 0;
3652}
3653
Damien Lespiaubd9db022013-10-15 18:55:36 +01003654static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003655{
3656 struct drm_device *dev = inode->i_private;
3657
Damien Lespiaubd9db022013-10-15 18:55:36 +01003658 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003659}
3660
Daniel Vetter46a19182013-11-01 10:50:20 +01003661static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003662 uint32_t *val)
3663{
Daniel Vetter46a19182013-11-01 10:50:20 +01003664 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3665 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3666
3667 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003668 case INTEL_PIPE_CRC_SOURCE_PIPE:
3669 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3670 break;
3671 case INTEL_PIPE_CRC_SOURCE_NONE:
3672 *val = 0;
3673 break;
3674 default:
3675 return -EINVAL;
3676 }
3677
3678 return 0;
3679}
3680
Daniel Vetter46a19182013-11-01 10:50:20 +01003681static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3682 enum intel_pipe_crc_source *source)
3683{
3684 struct intel_encoder *encoder;
3685 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003686 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003687 int ret = 0;
3688
3689 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3690
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003691 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003692 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003693 if (!encoder->base.crtc)
3694 continue;
3695
3696 crtc = to_intel_crtc(encoder->base.crtc);
3697
3698 if (crtc->pipe != pipe)
3699 continue;
3700
3701 switch (encoder->type) {
3702 case INTEL_OUTPUT_TVOUT:
3703 *source = INTEL_PIPE_CRC_SOURCE_TV;
3704 break;
3705 case INTEL_OUTPUT_DISPLAYPORT:
3706 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003707 dig_port = enc_to_dig_port(&encoder->base);
3708 switch (dig_port->port) {
3709 case PORT_B:
3710 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3711 break;
3712 case PORT_C:
3713 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3714 break;
3715 case PORT_D:
3716 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3717 break;
3718 default:
3719 WARN(1, "nonexisting DP port %c\n",
3720 port_name(dig_port->port));
3721 break;
3722 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003723 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003724 default:
3725 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003726 }
3727 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003728 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003729
3730 return ret;
3731}
3732
3733static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3734 enum pipe pipe,
3735 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003736 uint32_t *val)
3737{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003738 struct drm_i915_private *dev_priv = dev->dev_private;
3739 bool need_stable_symbols = false;
3740
Daniel Vetter46a19182013-11-01 10:50:20 +01003741 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3742 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3743 if (ret)
3744 return ret;
3745 }
3746
3747 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003748 case INTEL_PIPE_CRC_SOURCE_PIPE:
3749 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3750 break;
3751 case INTEL_PIPE_CRC_SOURCE_DP_B:
3752 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003753 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003754 break;
3755 case INTEL_PIPE_CRC_SOURCE_DP_C:
3756 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003757 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003758 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003759 case INTEL_PIPE_CRC_SOURCE_DP_D:
3760 if (!IS_CHERRYVIEW(dev))
3761 return -EINVAL;
3762 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3763 need_stable_symbols = true;
3764 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003765 case INTEL_PIPE_CRC_SOURCE_NONE:
3766 *val = 0;
3767 break;
3768 default:
3769 return -EINVAL;
3770 }
3771
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003772 /*
3773 * When the pipe CRC tap point is after the transcoders we need
3774 * to tweak symbol-level features to produce a deterministic series of
3775 * symbols for a given frame. We need to reset those features only once
3776 * a frame (instead of every nth symbol):
3777 * - DC-balance: used to ensure a better clock recovery from the data
3778 * link (SDVO)
3779 * - DisplayPort scrambling: used for EMI reduction
3780 */
3781 if (need_stable_symbols) {
3782 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3783
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003784 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003785 switch (pipe) {
3786 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003787 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003788 break;
3789 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003790 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003791 break;
3792 case PIPE_C:
3793 tmp |= PIPE_C_SCRAMBLE_RESET;
3794 break;
3795 default:
3796 return -EINVAL;
3797 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003798 I915_WRITE(PORT_DFT2_G4X, tmp);
3799 }
3800
Daniel Vetter7ac01292013-10-18 16:37:06 +02003801 return 0;
3802}
3803
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003804static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003805 enum pipe pipe,
3806 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003807 uint32_t *val)
3808{
Daniel Vetter84093602013-11-01 10:50:21 +01003809 struct drm_i915_private *dev_priv = dev->dev_private;
3810 bool need_stable_symbols = false;
3811
Daniel Vetter46a19182013-11-01 10:50:20 +01003812 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3813 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3814 if (ret)
3815 return ret;
3816 }
3817
3818 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003819 case INTEL_PIPE_CRC_SOURCE_PIPE:
3820 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3821 break;
3822 case INTEL_PIPE_CRC_SOURCE_TV:
3823 if (!SUPPORTS_TV(dev))
3824 return -EINVAL;
3825 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3826 break;
3827 case INTEL_PIPE_CRC_SOURCE_DP_B:
3828 if (!IS_G4X(dev))
3829 return -EINVAL;
3830 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003831 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003832 break;
3833 case INTEL_PIPE_CRC_SOURCE_DP_C:
3834 if (!IS_G4X(dev))
3835 return -EINVAL;
3836 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003837 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003838 break;
3839 case INTEL_PIPE_CRC_SOURCE_DP_D:
3840 if (!IS_G4X(dev))
3841 return -EINVAL;
3842 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003843 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003844 break;
3845 case INTEL_PIPE_CRC_SOURCE_NONE:
3846 *val = 0;
3847 break;
3848 default:
3849 return -EINVAL;
3850 }
3851
Daniel Vetter84093602013-11-01 10:50:21 +01003852 /*
3853 * When the pipe CRC tap point is after the transcoders we need
3854 * to tweak symbol-level features to produce a deterministic series of
3855 * symbols for a given frame. We need to reset those features only once
3856 * a frame (instead of every nth symbol):
3857 * - DC-balance: used to ensure a better clock recovery from the data
3858 * link (SDVO)
3859 * - DisplayPort scrambling: used for EMI reduction
3860 */
3861 if (need_stable_symbols) {
3862 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3863
3864 WARN_ON(!IS_G4X(dev));
3865
3866 I915_WRITE(PORT_DFT_I9XX,
3867 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3868
3869 if (pipe == PIPE_A)
3870 tmp |= PIPE_A_SCRAMBLE_RESET;
3871 else
3872 tmp |= PIPE_B_SCRAMBLE_RESET;
3873
3874 I915_WRITE(PORT_DFT2_G4X, tmp);
3875 }
3876
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003877 return 0;
3878}
3879
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003880static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3881 enum pipe pipe)
3882{
3883 struct drm_i915_private *dev_priv = dev->dev_private;
3884 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3885
Ville Syrjäläeb736672014-12-09 21:28:28 +02003886 switch (pipe) {
3887 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003888 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003889 break;
3890 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003891 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003892 break;
3893 case PIPE_C:
3894 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3895 break;
3896 default:
3897 return;
3898 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003899 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3900 tmp &= ~DC_BALANCE_RESET_VLV;
3901 I915_WRITE(PORT_DFT2_G4X, tmp);
3902
3903}
3904
Daniel Vetter84093602013-11-01 10:50:21 +01003905static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3906 enum pipe pipe)
3907{
3908 struct drm_i915_private *dev_priv = dev->dev_private;
3909 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3910
3911 if (pipe == PIPE_A)
3912 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3913 else
3914 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3915 I915_WRITE(PORT_DFT2_G4X, tmp);
3916
3917 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3918 I915_WRITE(PORT_DFT_I9XX,
3919 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3920 }
3921}
3922
Daniel Vetter46a19182013-11-01 10:50:20 +01003923static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003924 uint32_t *val)
3925{
Daniel Vetter46a19182013-11-01 10:50:20 +01003926 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3927 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3928
3929 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003930 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3931 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3932 break;
3933 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3934 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3935 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003936 case INTEL_PIPE_CRC_SOURCE_PIPE:
3937 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3938 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003939 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003940 *val = 0;
3941 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003942 default:
3943 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003944 }
3945
3946 return 0;
3947}
3948
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003949static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003950{
3951 struct drm_i915_private *dev_priv = dev->dev_private;
3952 struct intel_crtc *crtc =
3953 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003954 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003955 struct drm_atomic_state *state;
3956 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003957
3958 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003959 state = drm_atomic_state_alloc(dev);
3960 if (!state) {
3961 ret = -ENOMEM;
3962 goto out;
3963 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003964
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003965 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
3966 pipe_config = intel_atomic_get_crtc_state(state, crtc);
3967 if (IS_ERR(pipe_config)) {
3968 ret = PTR_ERR(pipe_config);
3969 goto out;
3970 }
3971
3972 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003973 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003974 pipe_config->pch_pfit.enabled != enable)
3975 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003976
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003977 ret = drm_atomic_commit(state);
3978out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003979 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003980 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
3981 if (ret)
3982 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003983}
3984
3985static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3986 enum pipe pipe,
3987 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003988 uint32_t *val)
3989{
Daniel Vetter46a19182013-11-01 10:50:20 +01003990 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3991 *source = INTEL_PIPE_CRC_SOURCE_PF;
3992
3993 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003994 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3995 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3996 break;
3997 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3998 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3999 break;
4000 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004001 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004002 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004003
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004004 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
4005 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004006 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004007 *val = 0;
4008 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02004009 default:
4010 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004011 }
4012
4013 return 0;
4014}
4015
Daniel Vetter926321d2013-10-16 13:30:34 +02004016static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
4017 enum intel_pipe_crc_source source)
4018{
4019 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01004020 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004021 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
4022 pipe));
Imre Deake1296492016-02-12 18:55:17 +02004023 enum intel_display_power_domain power_domain;
Borislav Petkov432f3342013-11-21 16:49:46 +01004024 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004025 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004026
Damien Lespiaucc3da172013-10-15 18:55:31 +01004027 if (pipe_crc->source == source)
4028 return 0;
4029
Damien Lespiauae676fc2013-10-15 18:55:32 +01004030 /* forbid changing the source without going back to 'none' */
4031 if (pipe_crc->source && source)
4032 return -EINVAL;
4033
Imre Deake1296492016-02-12 18:55:17 +02004034 power_domain = POWER_DOMAIN_PIPE(pipe);
4035 if (!intel_display_power_get_if_enabled(dev_priv, power_domain)) {
Daniel Vetter9d8b0582014-11-25 14:00:40 +01004036 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
4037 return -EIO;
4038 }
4039
Daniel Vetter52f843f2013-10-21 17:26:38 +02004040 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004041 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02004042 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01004043 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Wayne Boyer666a4532015-12-09 12:29:35 -08004044 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004045 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02004046 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01004047 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004048 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004049 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004050
4051 if (ret != 0)
Imre Deake1296492016-02-12 18:55:17 +02004052 goto out;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02004053
Damien Lespiau4b584362013-10-15 18:55:33 +01004054 /* none -> real source transition */
4055 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004056 struct intel_pipe_crc_entry *entries;
4057
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004058 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
4059 pipe_name(pipe), pipe_crc_source_name(source));
4060
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02004061 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
4062 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004063 GFP_KERNEL);
Imre Deake1296492016-02-12 18:55:17 +02004064 if (!entries) {
4065 ret = -ENOMEM;
4066 goto out;
4067 }
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004068
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004069 /*
4070 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
4071 * enabled and disabled dynamically based on package C states,
4072 * user space can't make reliable use of the CRCs, so let's just
4073 * completely disable it.
4074 */
4075 hsw_disable_ips(crtc);
4076
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004077 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01004078 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02004079 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004080 pipe_crc->head = 0;
4081 pipe_crc->tail = 0;
4082 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01004083 }
4084
Damien Lespiaucc3da172013-10-15 18:55:31 +01004085 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02004086
Daniel Vetter926321d2013-10-16 13:30:34 +02004087 I915_WRITE(PIPE_CRC_CTL(pipe), val);
4088 POSTING_READ(PIPE_CRC_CTL(pipe));
4089
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004090 /* real source -> none transition */
4091 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004092 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02004093 struct intel_crtc *crtc =
4094 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004095
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01004096 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
4097 pipe_name(pipe));
4098
Daniel Vettera33d7102014-06-06 08:22:08 +02004099 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02004100 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02004101 intel_wait_for_vblank(dev, pipe);
4102 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02004103
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004104 spin_lock_irq(&pipe_crc->lock);
4105 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004106 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02004107 pipe_crc->head = 0;
4108 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004109 spin_unlock_irq(&pipe_crc->lock);
4110
4111 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01004112
4113 if (IS_G4X(dev))
4114 g4x_undo_pipe_scramble_reset(dev, pipe);
Wayne Boyer666a4532015-12-09 12:29:35 -08004115 else if (IS_VALLEYVIEW(dev) || IS_CHERRYVIEW(dev))
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01004116 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02004117 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02004118 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03004119
4120 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01004121 }
4122
Imre Deake1296492016-02-12 18:55:17 +02004123 ret = 0;
4124
4125out:
4126 intel_display_power_put(dev_priv, power_domain);
4127
4128 return ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02004129}
4130
4131/*
4132 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004133 * command: wsp* object wsp+ name wsp+ source wsp*
4134 * object: 'pipe'
4135 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02004136 * source: (none | plane1 | plane2 | pf)
4137 * wsp: (#0x20 | #0x9 | #0xA)+
4138 *
4139 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01004140 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
4141 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02004142 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01004143static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02004144{
4145 int n_words = 0;
4146
4147 while (*buf) {
4148 char *end;
4149
4150 /* skip leading white space */
4151 buf = skip_spaces(buf);
4152 if (!*buf)
4153 break; /* end of buffer */
4154
4155 /* find end of word */
4156 for (end = buf; *end && !isspace(*end); end++)
4157 ;
4158
4159 if (n_words == max_words) {
4160 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4161 max_words);
4162 return -EINVAL; /* ran out of words[] before bytes */
4163 }
4164
4165 if (*end)
4166 *end++ = '\0';
4167 words[n_words++] = buf;
4168 buf = end;
4169 }
4170
4171 return n_words;
4172}
4173
Damien Lespiaub94dec82013-10-15 18:55:35 +01004174enum intel_pipe_crc_object {
4175 PIPE_CRC_OBJECT_PIPE,
4176};
4177
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004178static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004179 "pipe",
4180};
4181
4182static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004183display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004184{
4185 int i;
4186
4187 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4188 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004189 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004190 return 0;
4191 }
4192
4193 return -EINVAL;
4194}
4195
Damien Lespiaubd9db022013-10-15 18:55:36 +01004196static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004197{
4198 const char name = buf[0];
4199
4200 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4201 return -EINVAL;
4202
4203 *pipe = name - 'A';
4204
4205 return 0;
4206}
4207
4208static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004209display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004210{
4211 int i;
4212
4213 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4214 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004215 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004216 return 0;
4217 }
4218
4219 return -EINVAL;
4220}
4221
Damien Lespiaubd9db022013-10-15 18:55:36 +01004222static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004223{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004224#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004225 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004226 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004227 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004228 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004229 enum intel_pipe_crc_source source;
4230
Damien Lespiaubd9db022013-10-15 18:55:36 +01004231 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004232 if (n_words != N_WORDS) {
4233 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4234 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004235 return -EINVAL;
4236 }
4237
Damien Lespiaubd9db022013-10-15 18:55:36 +01004238 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004239 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004240 return -EINVAL;
4241 }
4242
Damien Lespiaubd9db022013-10-15 18:55:36 +01004243 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004244 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4245 return -EINVAL;
4246 }
4247
Damien Lespiaubd9db022013-10-15 18:55:36 +01004248 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004249 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004250 return -EINVAL;
4251 }
4252
4253 return pipe_crc_set_source(dev, pipe, source);
4254}
4255
Damien Lespiaubd9db022013-10-15 18:55:36 +01004256static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4257 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004258{
4259 struct seq_file *m = file->private_data;
4260 struct drm_device *dev = m->private;
4261 char *tmpbuf;
4262 int ret;
4263
4264 if (len == 0)
4265 return 0;
4266
4267 if (len > PAGE_SIZE - 1) {
4268 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4269 PAGE_SIZE);
4270 return -E2BIG;
4271 }
4272
4273 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4274 if (!tmpbuf)
4275 return -ENOMEM;
4276
4277 if (copy_from_user(tmpbuf, ubuf, len)) {
4278 ret = -EFAULT;
4279 goto out;
4280 }
4281 tmpbuf[len] = '\0';
4282
Damien Lespiaubd9db022013-10-15 18:55:36 +01004283 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004284
4285out:
4286 kfree(tmpbuf);
4287 if (ret < 0)
4288 return ret;
4289
4290 *offp += len;
4291 return len;
4292}
4293
Damien Lespiaubd9db022013-10-15 18:55:36 +01004294static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004295 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004296 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004297 .read = seq_read,
4298 .llseek = seq_lseek,
4299 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004300 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004301};
4302
Todd Previteeb3394fa2015-04-18 00:04:19 -07004303static ssize_t i915_displayport_test_active_write(struct file *file,
4304 const char __user *ubuf,
4305 size_t len, loff_t *offp)
4306{
4307 char *input_buffer;
4308 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004309 struct drm_device *dev;
4310 struct drm_connector *connector;
4311 struct list_head *connector_list;
4312 struct intel_dp *intel_dp;
4313 int val = 0;
4314
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304315 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004316
Todd Previteeb3394fa2015-04-18 00:04:19 -07004317 connector_list = &dev->mode_config.connector_list;
4318
4319 if (len == 0)
4320 return 0;
4321
4322 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4323 if (!input_buffer)
4324 return -ENOMEM;
4325
4326 if (copy_from_user(input_buffer, ubuf, len)) {
4327 status = -EFAULT;
4328 goto out;
4329 }
4330
4331 input_buffer[len] = '\0';
4332 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4333
4334 list_for_each_entry(connector, connector_list, head) {
4335
4336 if (connector->connector_type !=
4337 DRM_MODE_CONNECTOR_DisplayPort)
4338 continue;
4339
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304340 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004341 connector->encoder != NULL) {
4342 intel_dp = enc_to_intel_dp(connector->encoder);
4343 status = kstrtoint(input_buffer, 10, &val);
4344 if (status < 0)
4345 goto out;
4346 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4347 /* To prevent erroneous activation of the compliance
4348 * testing code, only accept an actual value of 1 here
4349 */
4350 if (val == 1)
4351 intel_dp->compliance_test_active = 1;
4352 else
4353 intel_dp->compliance_test_active = 0;
4354 }
4355 }
4356out:
4357 kfree(input_buffer);
4358 if (status < 0)
4359 return status;
4360
4361 *offp += len;
4362 return len;
4363}
4364
4365static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4366{
4367 struct drm_device *dev = m->private;
4368 struct drm_connector *connector;
4369 struct list_head *connector_list = &dev->mode_config.connector_list;
4370 struct intel_dp *intel_dp;
4371
Todd Previteeb3394fa2015-04-18 00:04:19 -07004372 list_for_each_entry(connector, connector_list, head) {
4373
4374 if (connector->connector_type !=
4375 DRM_MODE_CONNECTOR_DisplayPort)
4376 continue;
4377
4378 if (connector->status == connector_status_connected &&
4379 connector->encoder != NULL) {
4380 intel_dp = enc_to_intel_dp(connector->encoder);
4381 if (intel_dp->compliance_test_active)
4382 seq_puts(m, "1");
4383 else
4384 seq_puts(m, "0");
4385 } else
4386 seq_puts(m, "0");
4387 }
4388
4389 return 0;
4390}
4391
4392static int i915_displayport_test_active_open(struct inode *inode,
4393 struct file *file)
4394{
4395 struct drm_device *dev = inode->i_private;
4396
4397 return single_open(file, i915_displayport_test_active_show, dev);
4398}
4399
4400static const struct file_operations i915_displayport_test_active_fops = {
4401 .owner = THIS_MODULE,
4402 .open = i915_displayport_test_active_open,
4403 .read = seq_read,
4404 .llseek = seq_lseek,
4405 .release = single_release,
4406 .write = i915_displayport_test_active_write
4407};
4408
4409static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4410{
4411 struct drm_device *dev = m->private;
4412 struct drm_connector *connector;
4413 struct list_head *connector_list = &dev->mode_config.connector_list;
4414 struct intel_dp *intel_dp;
4415
Todd Previteeb3394fa2015-04-18 00:04:19 -07004416 list_for_each_entry(connector, connector_list, head) {
4417
4418 if (connector->connector_type !=
4419 DRM_MODE_CONNECTOR_DisplayPort)
4420 continue;
4421
4422 if (connector->status == connector_status_connected &&
4423 connector->encoder != NULL) {
4424 intel_dp = enc_to_intel_dp(connector->encoder);
4425 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4426 } else
4427 seq_puts(m, "0");
4428 }
4429
4430 return 0;
4431}
4432static int i915_displayport_test_data_open(struct inode *inode,
4433 struct file *file)
4434{
4435 struct drm_device *dev = inode->i_private;
4436
4437 return single_open(file, i915_displayport_test_data_show, dev);
4438}
4439
4440static const struct file_operations i915_displayport_test_data_fops = {
4441 .owner = THIS_MODULE,
4442 .open = i915_displayport_test_data_open,
4443 .read = seq_read,
4444 .llseek = seq_lseek,
4445 .release = single_release
4446};
4447
4448static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4449{
4450 struct drm_device *dev = m->private;
4451 struct drm_connector *connector;
4452 struct list_head *connector_list = &dev->mode_config.connector_list;
4453 struct intel_dp *intel_dp;
4454
Todd Previteeb3394fa2015-04-18 00:04:19 -07004455 list_for_each_entry(connector, connector_list, head) {
4456
4457 if (connector->connector_type !=
4458 DRM_MODE_CONNECTOR_DisplayPort)
4459 continue;
4460
4461 if (connector->status == connector_status_connected &&
4462 connector->encoder != NULL) {
4463 intel_dp = enc_to_intel_dp(connector->encoder);
4464 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4465 } else
4466 seq_puts(m, "0");
4467 }
4468
4469 return 0;
4470}
4471
4472static int i915_displayport_test_type_open(struct inode *inode,
4473 struct file *file)
4474{
4475 struct drm_device *dev = inode->i_private;
4476
4477 return single_open(file, i915_displayport_test_type_show, dev);
4478}
4479
4480static const struct file_operations i915_displayport_test_type_fops = {
4481 .owner = THIS_MODULE,
4482 .open = i915_displayport_test_type_open,
4483 .read = seq_read,
4484 .llseek = seq_lseek,
4485 .release = single_release
4486};
4487
Damien Lespiau97e94b22014-11-04 17:06:50 +00004488static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004489{
4490 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004491 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004492 int num_levels;
4493
4494 if (IS_CHERRYVIEW(dev))
4495 num_levels = 3;
4496 else if (IS_VALLEYVIEW(dev))
4497 num_levels = 1;
4498 else
4499 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004500
4501 drm_modeset_lock_all(dev);
4502
4503 for (level = 0; level < num_levels; level++) {
4504 unsigned int latency = wm[level];
4505
Damien Lespiau97e94b22014-11-04 17:06:50 +00004506 /*
4507 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004508 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004509 */
Wayne Boyer666a4532015-12-09 12:29:35 -08004510 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev) ||
4511 IS_CHERRYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004512 latency *= 10;
4513 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004514 latency *= 5;
4515
4516 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004517 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004518 }
4519
4520 drm_modeset_unlock_all(dev);
4521}
4522
4523static int pri_wm_latency_show(struct seq_file *m, void *data)
4524{
4525 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004526 struct drm_i915_private *dev_priv = dev->dev_private;
4527 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004528
Damien Lespiau97e94b22014-11-04 17:06:50 +00004529 if (INTEL_INFO(dev)->gen >= 9)
4530 latencies = dev_priv->wm.skl_latency;
4531 else
4532 latencies = to_i915(dev)->wm.pri_latency;
4533
4534 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004535
4536 return 0;
4537}
4538
4539static int spr_wm_latency_show(struct seq_file *m, void *data)
4540{
4541 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004542 struct drm_i915_private *dev_priv = dev->dev_private;
4543 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004544
Damien Lespiau97e94b22014-11-04 17:06:50 +00004545 if (INTEL_INFO(dev)->gen >= 9)
4546 latencies = dev_priv->wm.skl_latency;
4547 else
4548 latencies = to_i915(dev)->wm.spr_latency;
4549
4550 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004551
4552 return 0;
4553}
4554
4555static int cur_wm_latency_show(struct seq_file *m, void *data)
4556{
4557 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004558 struct drm_i915_private *dev_priv = dev->dev_private;
4559 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004560
Damien Lespiau97e94b22014-11-04 17:06:50 +00004561 if (INTEL_INFO(dev)->gen >= 9)
4562 latencies = dev_priv->wm.skl_latency;
4563 else
4564 latencies = to_i915(dev)->wm.cur_latency;
4565
4566 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004567
4568 return 0;
4569}
4570
4571static int pri_wm_latency_open(struct inode *inode, struct file *file)
4572{
4573 struct drm_device *dev = inode->i_private;
4574
Ville Syrjäläde38b952015-06-24 22:00:09 +03004575 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004576 return -ENODEV;
4577
4578 return single_open(file, pri_wm_latency_show, dev);
4579}
4580
4581static int spr_wm_latency_open(struct inode *inode, struct file *file)
4582{
4583 struct drm_device *dev = inode->i_private;
4584
Sonika Jindal9ad02572014-07-21 15:23:39 +05304585 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004586 return -ENODEV;
4587
4588 return single_open(file, spr_wm_latency_show, dev);
4589}
4590
4591static int cur_wm_latency_open(struct inode *inode, struct file *file)
4592{
4593 struct drm_device *dev = inode->i_private;
4594
Sonika Jindal9ad02572014-07-21 15:23:39 +05304595 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004596 return -ENODEV;
4597
4598 return single_open(file, cur_wm_latency_show, dev);
4599}
4600
4601static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004602 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004603{
4604 struct seq_file *m = file->private_data;
4605 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004606 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004607 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004608 int level;
4609 int ret;
4610 char tmp[32];
4611
Ville Syrjäläde38b952015-06-24 22:00:09 +03004612 if (IS_CHERRYVIEW(dev))
4613 num_levels = 3;
4614 else if (IS_VALLEYVIEW(dev))
4615 num_levels = 1;
4616 else
4617 num_levels = ilk_wm_max_level(dev) + 1;
4618
Ville Syrjälä369a1342014-01-22 14:36:08 +02004619 if (len >= sizeof(tmp))
4620 return -EINVAL;
4621
4622 if (copy_from_user(tmp, ubuf, len))
4623 return -EFAULT;
4624
4625 tmp[len] = '\0';
4626
Damien Lespiau97e94b22014-11-04 17:06:50 +00004627 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4628 &new[0], &new[1], &new[2], &new[3],
4629 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004630 if (ret != num_levels)
4631 return -EINVAL;
4632
4633 drm_modeset_lock_all(dev);
4634
4635 for (level = 0; level < num_levels; level++)
4636 wm[level] = new[level];
4637
4638 drm_modeset_unlock_all(dev);
4639
4640 return len;
4641}
4642
4643
4644static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4645 size_t len, loff_t *offp)
4646{
4647 struct seq_file *m = file->private_data;
4648 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004649 struct drm_i915_private *dev_priv = dev->dev_private;
4650 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004651
Damien Lespiau97e94b22014-11-04 17:06:50 +00004652 if (INTEL_INFO(dev)->gen >= 9)
4653 latencies = dev_priv->wm.skl_latency;
4654 else
4655 latencies = to_i915(dev)->wm.pri_latency;
4656
4657 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004658}
4659
4660static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4661 size_t len, loff_t *offp)
4662{
4663 struct seq_file *m = file->private_data;
4664 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004665 struct drm_i915_private *dev_priv = dev->dev_private;
4666 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004667
Damien Lespiau97e94b22014-11-04 17:06:50 +00004668 if (INTEL_INFO(dev)->gen >= 9)
4669 latencies = dev_priv->wm.skl_latency;
4670 else
4671 latencies = to_i915(dev)->wm.spr_latency;
4672
4673 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004674}
4675
4676static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4677 size_t len, loff_t *offp)
4678{
4679 struct seq_file *m = file->private_data;
4680 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004681 struct drm_i915_private *dev_priv = dev->dev_private;
4682 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004683
Damien Lespiau97e94b22014-11-04 17:06:50 +00004684 if (INTEL_INFO(dev)->gen >= 9)
4685 latencies = dev_priv->wm.skl_latency;
4686 else
4687 latencies = to_i915(dev)->wm.cur_latency;
4688
4689 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004690}
4691
4692static const struct file_operations i915_pri_wm_latency_fops = {
4693 .owner = THIS_MODULE,
4694 .open = pri_wm_latency_open,
4695 .read = seq_read,
4696 .llseek = seq_lseek,
4697 .release = single_release,
4698 .write = pri_wm_latency_write
4699};
4700
4701static const struct file_operations i915_spr_wm_latency_fops = {
4702 .owner = THIS_MODULE,
4703 .open = spr_wm_latency_open,
4704 .read = seq_read,
4705 .llseek = seq_lseek,
4706 .release = single_release,
4707 .write = spr_wm_latency_write
4708};
4709
4710static const struct file_operations i915_cur_wm_latency_fops = {
4711 .owner = THIS_MODULE,
4712 .open = cur_wm_latency_open,
4713 .read = seq_read,
4714 .llseek = seq_lseek,
4715 .release = single_release,
4716 .write = cur_wm_latency_write
4717};
4718
Kees Cook647416f2013-03-10 14:10:06 -07004719static int
4720i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004721{
Kees Cook647416f2013-03-10 14:10:06 -07004722 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004723 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004724
Kees Cook647416f2013-03-10 14:10:06 -07004725 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004726
Kees Cook647416f2013-03-10 14:10:06 -07004727 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004728}
4729
Kees Cook647416f2013-03-10 14:10:06 -07004730static int
4731i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004732{
Kees Cook647416f2013-03-10 14:10:06 -07004733 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004734 struct drm_i915_private *dev_priv = dev->dev_private;
4735
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004736 /*
4737 * There is no safeguard against this debugfs entry colliding
4738 * with the hangcheck calling same i915_handle_error() in
4739 * parallel, causing an explosion. For now we assume that the
4740 * test harness is responsible enough not to inject gpu hangs
4741 * while it is writing to 'i915_wedged'
4742 */
4743
4744 if (i915_reset_in_progress(&dev_priv->gpu_error))
4745 return -EAGAIN;
4746
Imre Deakd46c0512014-04-14 20:24:27 +03004747 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004748
Mika Kuoppala58174462014-02-25 17:11:26 +02004749 i915_handle_error(dev, val,
4750 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004751
4752 intel_runtime_pm_put(dev_priv);
4753
Kees Cook647416f2013-03-10 14:10:06 -07004754 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004755}
4756
Kees Cook647416f2013-03-10 14:10:06 -07004757DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4758 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004759 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004760
Kees Cook647416f2013-03-10 14:10:06 -07004761static int
4762i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004763{
Kees Cook647416f2013-03-10 14:10:06 -07004764 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004765 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004766
Kees Cook647416f2013-03-10 14:10:06 -07004767 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004768
Kees Cook647416f2013-03-10 14:10:06 -07004769 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004770}
4771
Kees Cook647416f2013-03-10 14:10:06 -07004772static int
4773i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004774{
Kees Cook647416f2013-03-10 14:10:06 -07004775 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004776 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004777 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004778
Kees Cook647416f2013-03-10 14:10:06 -07004779 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004780
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004781 ret = mutex_lock_interruptible(&dev->struct_mutex);
4782 if (ret)
4783 return ret;
4784
Daniel Vetter99584db2012-11-14 17:14:04 +01004785 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004786 mutex_unlock(&dev->struct_mutex);
4787
Kees Cook647416f2013-03-10 14:10:06 -07004788 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004789}
4790
Kees Cook647416f2013-03-10 14:10:06 -07004791DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4792 i915_ring_stop_get, i915_ring_stop_set,
4793 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004794
Chris Wilson094f9a52013-09-25 17:34:55 +01004795static int
4796i915_ring_missed_irq_get(void *data, u64 *val)
4797{
4798 struct drm_device *dev = data;
4799 struct drm_i915_private *dev_priv = dev->dev_private;
4800
4801 *val = dev_priv->gpu_error.missed_irq_rings;
4802 return 0;
4803}
4804
4805static int
4806i915_ring_missed_irq_set(void *data, u64 val)
4807{
4808 struct drm_device *dev = data;
4809 struct drm_i915_private *dev_priv = dev->dev_private;
4810 int ret;
4811
4812 /* Lock against concurrent debugfs callers */
4813 ret = mutex_lock_interruptible(&dev->struct_mutex);
4814 if (ret)
4815 return ret;
4816 dev_priv->gpu_error.missed_irq_rings = val;
4817 mutex_unlock(&dev->struct_mutex);
4818
4819 return 0;
4820}
4821
4822DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4823 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4824 "0x%08llx\n");
4825
4826static int
4827i915_ring_test_irq_get(void *data, u64 *val)
4828{
4829 struct drm_device *dev = data;
4830 struct drm_i915_private *dev_priv = dev->dev_private;
4831
4832 *val = dev_priv->gpu_error.test_irq_rings;
4833
4834 return 0;
4835}
4836
4837static int
4838i915_ring_test_irq_set(void *data, u64 val)
4839{
4840 struct drm_device *dev = data;
4841 struct drm_i915_private *dev_priv = dev->dev_private;
4842 int ret;
4843
4844 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4845
4846 /* Lock against concurrent debugfs callers */
4847 ret = mutex_lock_interruptible(&dev->struct_mutex);
4848 if (ret)
4849 return ret;
4850
4851 dev_priv->gpu_error.test_irq_rings = val;
4852 mutex_unlock(&dev->struct_mutex);
4853
4854 return 0;
4855}
4856
4857DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4858 i915_ring_test_irq_get, i915_ring_test_irq_set,
4859 "0x%08llx\n");
4860
Chris Wilsondd624af2013-01-15 12:39:35 +00004861#define DROP_UNBOUND 0x1
4862#define DROP_BOUND 0x2
4863#define DROP_RETIRE 0x4
4864#define DROP_ACTIVE 0x8
4865#define DROP_ALL (DROP_UNBOUND | \
4866 DROP_BOUND | \
4867 DROP_RETIRE | \
4868 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004869static int
4870i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004871{
Kees Cook647416f2013-03-10 14:10:06 -07004872 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004873
Kees Cook647416f2013-03-10 14:10:06 -07004874 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004875}
4876
Kees Cook647416f2013-03-10 14:10:06 -07004877static int
4878i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004879{
Kees Cook647416f2013-03-10 14:10:06 -07004880 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004881 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004882 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004883
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004884 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004885
4886 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4887 * on ioctls on -EAGAIN. */
4888 ret = mutex_lock_interruptible(&dev->struct_mutex);
4889 if (ret)
4890 return ret;
4891
4892 if (val & DROP_ACTIVE) {
4893 ret = i915_gpu_idle(dev);
4894 if (ret)
4895 goto unlock;
4896 }
4897
4898 if (val & (DROP_RETIRE | DROP_ACTIVE))
4899 i915_gem_retire_requests(dev);
4900
Chris Wilson21ab4e72014-09-09 11:16:08 +01004901 if (val & DROP_BOUND)
4902 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004903
Chris Wilson21ab4e72014-09-09 11:16:08 +01004904 if (val & DROP_UNBOUND)
4905 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004906
4907unlock:
4908 mutex_unlock(&dev->struct_mutex);
4909
Kees Cook647416f2013-03-10 14:10:06 -07004910 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004911}
4912
Kees Cook647416f2013-03-10 14:10:06 -07004913DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4914 i915_drop_caches_get, i915_drop_caches_set,
4915 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004916
Kees Cook647416f2013-03-10 14:10:06 -07004917static int
4918i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004919{
Kees Cook647416f2013-03-10 14:10:06 -07004920 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004921 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004922 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004923
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004924 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004925 return -ENODEV;
4926
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004927 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4928
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004929 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004930 if (ret)
4931 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004932
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004933 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004934 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004935
Kees Cook647416f2013-03-10 14:10:06 -07004936 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004937}
4938
Kees Cook647416f2013-03-10 14:10:06 -07004939static int
4940i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004941{
Kees Cook647416f2013-03-10 14:10:06 -07004942 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004943 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304944 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004945 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004946
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004947 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004948 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004949
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004950 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4951
Kees Cook647416f2013-03-10 14:10:06 -07004952 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004953
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004954 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004955 if (ret)
4956 return ret;
4957
Jesse Barnes358733e2011-07-27 11:53:01 -07004958 /*
4959 * Turbo will still be enabled, but won't go above the set value.
4960 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304961 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004962
Akash Goelbc4d91f2015-02-26 16:09:47 +05304963 hw_max = dev_priv->rps.max_freq;
4964 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004965
Ben Widawskyb39fb292014-03-19 18:31:11 -07004966 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004967 mutex_unlock(&dev_priv->rps.hw_lock);
4968 return -EINVAL;
4969 }
4970
Ben Widawskyb39fb292014-03-19 18:31:11 -07004971 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004972
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004973 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004974
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004975 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004976
Kees Cook647416f2013-03-10 14:10:06 -07004977 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004978}
4979
Kees Cook647416f2013-03-10 14:10:06 -07004980DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4981 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004982 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004983
Kees Cook647416f2013-03-10 14:10:06 -07004984static int
4985i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004986{
Kees Cook647416f2013-03-10 14:10:06 -07004987 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004988 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004989 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004990
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004991 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004992 return -ENODEV;
4993
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004994 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4995
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004996 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004997 if (ret)
4998 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004999
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02005000 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005001 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005002
Kees Cook647416f2013-03-10 14:10:06 -07005003 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005004}
5005
Kees Cook647416f2013-03-10 14:10:06 -07005006static int
5007i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07005008{
Kees Cook647416f2013-03-10 14:10:06 -07005009 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07005010 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05305011 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07005012 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02005013
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07005014 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02005015 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07005016
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07005017 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
5018
Kees Cook647416f2013-03-10 14:10:06 -07005019 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07005020
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005021 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02005022 if (ret)
5023 return ret;
5024
Jesse Barnes1523c312012-05-25 12:34:54 -07005025 /*
5026 * Turbo will still be enabled, but won't go below the set value.
5027 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05305028 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005029
Akash Goelbc4d91f2015-02-26 16:09:47 +05305030 hw_max = dev_priv->rps.max_freq;
5031 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005032
Ben Widawskyb39fb292014-03-19 18:31:11 -07005033 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005034 mutex_unlock(&dev_priv->rps.hw_lock);
5035 return -EINVAL;
5036 }
5037
Ben Widawskyb39fb292014-03-19 18:31:11 -07005038 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005039
Ville Syrjäläffe02b42015-02-02 19:09:50 +02005040 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06005041
Jesse Barnes4fc688c2012-11-02 11:14:01 -07005042 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07005043
Kees Cook647416f2013-03-10 14:10:06 -07005044 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07005045}
5046
Kees Cook647416f2013-03-10 14:10:06 -07005047DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
5048 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03005049 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07005050
Kees Cook647416f2013-03-10 14:10:06 -07005051static int
5052i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005053{
Kees Cook647416f2013-03-10 14:10:06 -07005054 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03005055 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005056 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07005057 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005058
Daniel Vetter004777c2012-08-09 15:07:01 +02005059 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5060 return -ENODEV;
5061
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005062 ret = mutex_lock_interruptible(&dev->struct_mutex);
5063 if (ret)
5064 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005065 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02005066
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005067 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005068
5069 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005070 mutex_unlock(&dev_priv->dev->struct_mutex);
5071
Kees Cook647416f2013-03-10 14:10:06 -07005072 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005073
Kees Cook647416f2013-03-10 14:10:06 -07005074 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005075}
5076
Kees Cook647416f2013-03-10 14:10:06 -07005077static int
5078i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005079{
Kees Cook647416f2013-03-10 14:10:06 -07005080 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005081 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005082 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005083
Daniel Vetter004777c2012-08-09 15:07:01 +02005084 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
5085 return -ENODEV;
5086
Kees Cook647416f2013-03-10 14:10:06 -07005087 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005088 return -EINVAL;
5089
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005090 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005091 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005092
5093 /* Update the cache sharing policy here as well */
5094 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
5095 snpcr &= ~GEN6_MBC_SNPCR_MASK;
5096 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
5097 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
5098
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02005099 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07005100 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005101}
5102
Kees Cook647416f2013-03-10 14:10:06 -07005103DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
5104 i915_cache_sharing_get, i915_cache_sharing_set,
5105 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005106
Jeff McGee5d395252015-04-03 18:13:17 -07005107struct sseu_dev_status {
5108 unsigned int slice_total;
5109 unsigned int subslice_total;
5110 unsigned int subslice_per_slice;
5111 unsigned int eu_total;
5112 unsigned int eu_per_subslice;
5113};
5114
5115static void cherryview_sseu_device_status(struct drm_device *dev,
5116 struct sseu_dev_status *stat)
5117{
5118 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03005119 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07005120 int ss;
5121 u32 sig1[ss_max], sig2[ss_max];
5122
5123 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
5124 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
5125 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
5126 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
5127
5128 for (ss = 0; ss < ss_max; ss++) {
5129 unsigned int eu_cnt;
5130
5131 if (sig1[ss] & CHV_SS_PG_ENABLE)
5132 /* skip disabled subslice */
5133 continue;
5134
5135 stat->slice_total = 1;
5136 stat->subslice_per_slice++;
5137 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
5138 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
5139 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
5140 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
5141 stat->eu_total += eu_cnt;
5142 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
5143 }
5144 stat->subslice_total = stat->subslice_per_slice;
5145}
5146
5147static void gen9_sseu_device_status(struct drm_device *dev,
5148 struct sseu_dev_status *stat)
5149{
5150 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005151 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07005152 int s, ss;
5153 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
5154
Jeff McGee1c046bc2015-04-03 18:13:18 -07005155 /* BXT has a single slice and at most 3 subslices. */
5156 if (IS_BROXTON(dev)) {
5157 s_max = 1;
5158 ss_max = 3;
5159 }
5160
5161 for (s = 0; s < s_max; s++) {
5162 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5163 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5164 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5165 }
5166
Jeff McGee5d395252015-04-03 18:13:17 -07005167 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5168 GEN9_PGCTL_SSA_EU19_ACK |
5169 GEN9_PGCTL_SSA_EU210_ACK |
5170 GEN9_PGCTL_SSA_EU311_ACK;
5171 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5172 GEN9_PGCTL_SSB_EU19_ACK |
5173 GEN9_PGCTL_SSB_EU210_ACK |
5174 GEN9_PGCTL_SSB_EU311_ACK;
5175
5176 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005177 unsigned int ss_cnt = 0;
5178
Jeff McGee5d395252015-04-03 18:13:17 -07005179 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5180 /* skip disabled slice */
5181 continue;
5182
5183 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005184
Rodrigo Vivief11bdb2015-10-28 04:16:45 -07005185 if (IS_SKYLAKE(dev) || IS_KABYLAKE(dev))
Jeff McGee1c046bc2015-04-03 18:13:18 -07005186 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5187
Jeff McGee5d395252015-04-03 18:13:17 -07005188 for (ss = 0; ss < ss_max; ss++) {
5189 unsigned int eu_cnt;
5190
Jeff McGee1c046bc2015-04-03 18:13:18 -07005191 if (IS_BROXTON(dev) &&
5192 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5193 /* skip disabled subslice */
5194 continue;
5195
5196 if (IS_BROXTON(dev))
5197 ss_cnt++;
5198
Jeff McGee5d395252015-04-03 18:13:17 -07005199 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5200 eu_mask[ss%2]);
5201 stat->eu_total += eu_cnt;
5202 stat->eu_per_subslice = max(stat->eu_per_subslice,
5203 eu_cnt);
5204 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005205
5206 stat->subslice_total += ss_cnt;
5207 stat->subslice_per_slice = max(stat->subslice_per_slice,
5208 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005209 }
5210}
5211
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005212static void broadwell_sseu_device_status(struct drm_device *dev,
5213 struct sseu_dev_status *stat)
5214{
5215 struct drm_i915_private *dev_priv = dev->dev_private;
5216 int s;
5217 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
5218
5219 stat->slice_total = hweight32(slice_info & GEN8_LSLICESTAT_MASK);
5220
5221 if (stat->slice_total) {
5222 stat->subslice_per_slice = INTEL_INFO(dev)->subslice_per_slice;
5223 stat->subslice_total = stat->slice_total *
5224 stat->subslice_per_slice;
5225 stat->eu_per_subslice = INTEL_INFO(dev)->eu_per_subslice;
5226 stat->eu_total = stat->eu_per_subslice * stat->subslice_total;
5227
5228 /* subtract fused off EU(s) from enabled slice(s) */
5229 for (s = 0; s < stat->slice_total; s++) {
5230 u8 subslice_7eu = INTEL_INFO(dev)->subslice_7eu[s];
5231
5232 stat->eu_total -= hweight8(subslice_7eu);
5233 }
5234 }
5235}
5236
Jeff McGee38732182015-02-13 10:27:54 -06005237static int i915_sseu_status(struct seq_file *m, void *unused)
5238{
5239 struct drm_info_node *node = (struct drm_info_node *) m->private;
5240 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07005241 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005242
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005243 if (INTEL_INFO(dev)->gen < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005244 return -ENODEV;
5245
5246 seq_puts(m, "SSEU Device Info\n");
5247 seq_printf(m, " Available Slice Total: %u\n",
5248 INTEL_INFO(dev)->slice_total);
5249 seq_printf(m, " Available Subslice Total: %u\n",
5250 INTEL_INFO(dev)->subslice_total);
5251 seq_printf(m, " Available Subslice Per Slice: %u\n",
5252 INTEL_INFO(dev)->subslice_per_slice);
5253 seq_printf(m, " Available EU Total: %u\n",
5254 INTEL_INFO(dev)->eu_total);
5255 seq_printf(m, " Available EU Per Subslice: %u\n",
5256 INTEL_INFO(dev)->eu_per_subslice);
5257 seq_printf(m, " Has Slice Power Gating: %s\n",
5258 yesno(INTEL_INFO(dev)->has_slice_pg));
5259 seq_printf(m, " Has Subslice Power Gating: %s\n",
5260 yesno(INTEL_INFO(dev)->has_subslice_pg));
5261 seq_printf(m, " Has EU Power Gating: %s\n",
5262 yesno(INTEL_INFO(dev)->has_eu_pg));
5263
Jeff McGee7f992ab2015-02-13 10:27:55 -06005264 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005265 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08005266 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005267 cherryview_sseu_device_status(dev, &stat);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005268 } else if (IS_BROADWELL(dev)) {
5269 broadwell_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005270 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005271 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005272 }
Jeff McGee5d395252015-04-03 18:13:17 -07005273 seq_printf(m, " Enabled Slice Total: %u\n",
5274 stat.slice_total);
5275 seq_printf(m, " Enabled Subslice Total: %u\n",
5276 stat.subslice_total);
5277 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5278 stat.subslice_per_slice);
5279 seq_printf(m, " Enabled EU Total: %u\n",
5280 stat.eu_total);
5281 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5282 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005283
Jeff McGee38732182015-02-13 10:27:54 -06005284 return 0;
5285}
5286
Ben Widawsky6d794d42011-04-25 11:25:56 -07005287static int i915_forcewake_open(struct inode *inode, struct file *file)
5288{
5289 struct drm_device *dev = inode->i_private;
5290 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005291
Daniel Vetter075edca2012-01-24 09:44:28 +01005292 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005293 return 0;
5294
Chris Wilson6daccb02015-01-16 11:34:35 +02005295 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005296 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005297
5298 return 0;
5299}
5300
Ben Widawskyc43b5632012-04-16 14:07:40 -07005301static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005302{
5303 struct drm_device *dev = inode->i_private;
5304 struct drm_i915_private *dev_priv = dev->dev_private;
5305
Daniel Vetter075edca2012-01-24 09:44:28 +01005306 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005307 return 0;
5308
Mika Kuoppala59bad942015-01-16 11:34:40 +02005309 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005310 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005311
5312 return 0;
5313}
5314
5315static const struct file_operations i915_forcewake_fops = {
5316 .owner = THIS_MODULE,
5317 .open = i915_forcewake_open,
5318 .release = i915_forcewake_release,
5319};
5320
5321static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5322{
5323 struct drm_device *dev = minor->dev;
5324 struct dentry *ent;
5325
5326 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005327 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005328 root, dev,
5329 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005330 if (!ent)
5331 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005332
Ben Widawsky8eb57292011-05-11 15:10:58 -07005333 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005334}
5335
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005336static int i915_debugfs_create(struct dentry *root,
5337 struct drm_minor *minor,
5338 const char *name,
5339 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005340{
5341 struct drm_device *dev = minor->dev;
5342 struct dentry *ent;
5343
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005344 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005345 S_IRUGO | S_IWUSR,
5346 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005347 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005348 if (!ent)
5349 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005350
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005351 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005352}
5353
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005354static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005355 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005356 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005357 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005358 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005359 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005360 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005361 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005362 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005363 {"i915_gem_request", i915_gem_request_info, 0},
5364 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005365 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005366 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005367 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5368 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5369 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005370 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005371 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005372 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005373 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005374 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305375 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005376 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005377 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005378 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005379 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005380 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005381 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005382 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005383 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005384 {"i915_opregion", i915_opregion, 0},
Jani Nikulaada8f952015-12-15 13:17:12 +02005385 {"i915_vbt", i915_vbt, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005386 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005387 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005388 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005389 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005390 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005391 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005392 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005393 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005394 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005395 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005396 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005397 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005398 {"i915_power_domain_info", i915_power_domain_info, 0},
Damien Lespiaub7cec662015-10-27 14:47:01 +02005399 {"i915_dmc_info", i915_dmc_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005400 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005401 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005402 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005403 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005404 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005405 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005406 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305407 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005408 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005409};
Ben Gamari27c202a2009-07-01 22:26:52 -04005410#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005411
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005412static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005413 const char *name;
5414 const struct file_operations *fops;
5415} i915_debugfs_files[] = {
5416 {"i915_wedged", &i915_wedged_fops},
5417 {"i915_max_freq", &i915_max_freq_fops},
5418 {"i915_min_freq", &i915_min_freq_fops},
5419 {"i915_cache_sharing", &i915_cache_sharing_fops},
5420 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005421 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5422 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005423 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5424 {"i915_error_state", &i915_error_state_fops},
5425 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005426 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005427 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5428 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5429 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005430 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005431 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5432 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5433 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005434};
5435
Damien Lespiau07144422013-10-15 18:55:40 +01005436void intel_display_crc_init(struct drm_device *dev)
5437{
5438 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005439 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005440
Damien Lespiau055e3932014-08-18 13:49:10 +01005441 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005442 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005443
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005444 pipe_crc->opened = false;
5445 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005446 init_waitqueue_head(&pipe_crc->wq);
5447 }
5448}
5449
Ben Gamari27c202a2009-07-01 22:26:52 -04005450int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005451{
Daniel Vetter34b96742013-07-04 20:49:44 +02005452 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005453
Ben Widawsky6d794d42011-04-25 11:25:56 -07005454 ret = i915_forcewake_create(minor->debugfs_root, minor);
5455 if (ret)
5456 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005457
Damien Lespiau07144422013-10-15 18:55:40 +01005458 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5459 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5460 if (ret)
5461 return ret;
5462 }
5463
Daniel Vetter34b96742013-07-04 20:49:44 +02005464 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5465 ret = i915_debugfs_create(minor->debugfs_root, minor,
5466 i915_debugfs_files[i].name,
5467 i915_debugfs_files[i].fops);
5468 if (ret)
5469 return ret;
5470 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005471
Ben Gamari27c202a2009-07-01 22:26:52 -04005472 return drm_debugfs_create_files(i915_debugfs_list,
5473 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005474 minor->debugfs_root, minor);
5475}
5476
Ben Gamari27c202a2009-07-01 22:26:52 -04005477void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005478{
Daniel Vetter34b96742013-07-04 20:49:44 +02005479 int i;
5480
Ben Gamari27c202a2009-07-01 22:26:52 -04005481 drm_debugfs_remove_files(i915_debugfs_list,
5482 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005483
Ben Widawsky6d794d42011-04-25 11:25:56 -07005484 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5485 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005486
Daniel Vettere309a992013-10-16 22:55:51 +02005487 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005488 struct drm_info_list *info_list =
5489 (struct drm_info_list *)&i915_pipe_crc_data[i];
5490
5491 drm_debugfs_remove_files(info_list, 1, minor);
5492 }
5493
Daniel Vetter34b96742013-07-04 20:49:44 +02005494 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5495 struct drm_info_list *info_list =
5496 (struct drm_info_list *) i915_debugfs_files[i].fops;
5497
5498 drm_debugfs_remove_files(info_list, 1, minor);
5499 }
Ben Gamari20172632009-02-17 20:08:50 -05005500}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005501
5502struct dpcd_block {
5503 /* DPCD dump start address. */
5504 unsigned int offset;
5505 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5506 unsigned int end;
5507 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5508 size_t size;
5509 /* Only valid for eDP. */
5510 bool edp;
5511};
5512
5513static const struct dpcd_block i915_dpcd_debug[] = {
5514 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5515 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5516 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5517 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5518 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5519 { .offset = DP_SET_POWER },
5520 { .offset = DP_EDP_DPCD_REV },
5521 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5522 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5523 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5524};
5525
5526static int i915_dpcd_show(struct seq_file *m, void *data)
5527{
5528 struct drm_connector *connector = m->private;
5529 struct intel_dp *intel_dp =
5530 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5531 uint8_t buf[16];
5532 ssize_t err;
5533 int i;
5534
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005535 if (connector->status != connector_status_connected)
5536 return -ENODEV;
5537
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005538 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5539 const struct dpcd_block *b = &i915_dpcd_debug[i];
5540 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5541
5542 if (b->edp &&
5543 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5544 continue;
5545
5546 /* low tech for now */
5547 if (WARN_ON(size > sizeof(buf)))
5548 continue;
5549
5550 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5551 if (err <= 0) {
5552 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5553 size, b->offset, err);
5554 continue;
5555 }
5556
5557 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005558 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005559
5560 return 0;
5561}
5562
5563static int i915_dpcd_open(struct inode *inode, struct file *file)
5564{
5565 return single_open(file, i915_dpcd_show, inode->i_private);
5566}
5567
5568static const struct file_operations i915_dpcd_fops = {
5569 .owner = THIS_MODULE,
5570 .open = i915_dpcd_open,
5571 .read = seq_read,
5572 .llseek = seq_lseek,
5573 .release = single_release,
5574};
5575
5576/**
5577 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5578 * @connector: pointer to a registered drm_connector
5579 *
5580 * Cleanup will be done by drm_connector_unregister() through a call to
5581 * drm_debugfs_connector_remove().
5582 *
5583 * Returns 0 on success, negative error codes on error.
5584 */
5585int i915_debugfs_connector_add(struct drm_connector *connector)
5586{
5587 struct dentry *root = connector->debugfs_entry;
5588
5589 /* The connector must have been registered beforehands. */
5590 if (!root)
5591 return -ENODEV;
5592
5593 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5594 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5595 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5596 &i915_dpcd_fops);
5597
5598 return 0;
5599}