blob: 72ae3472ddbec66190fa02002216ac0767d9eb31 [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
120 list_for_each_entry(vma, &obj->vma_list, vma_link) {
121 if (i915_is_ggtt(vma->vm) &&
122 drm_mm_node_allocated(&vma->node))
123 size += vma->node.size;
124 }
125
126 return size;
127}
128
Chris Wilson37811fc2010-08-25 22:45:57 +0100129static void
130describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
131{
Chris Wilsonb4716182015-04-27 13:41:17 +0100132 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
133 struct intel_engine_cs *ring;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700134 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800135 int pin_count = 0;
Chris Wilsonb4716182015-04-27 13:41:17 +0100136 int i;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800137
Chris Wilsonb4716182015-04-27 13:41:17 +0100138 seq_printf(m, "%pK: %s%s%s%s %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100139 &obj->base,
Chris Wilson481a3d42015-04-07 16:20:39 +0100140 obj->active ? "*" : " ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100141 get_pin_flag(obj),
142 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700143 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800144 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100145 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100146 obj->base.write_domain);
147 for_each_ring(ring, dev_priv, i)
148 seq_printf(m, "%x ",
149 i915_gem_request_get_seqno(obj->last_read_req[i]));
150 seq_printf(m, "] %x %x%s%s%s",
John Harrison97b2a6a2014-11-24 18:49:26 +0000151 i915_gem_request_get_seqno(obj->last_write_req),
152 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100153 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100154 obj->dirty ? " dirty" : "",
155 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
156 if (obj->base.name)
157 seq_printf(m, " (name: %d)", obj->base.name);
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300158 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800159 if (vma->pin_count > 0)
160 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300161 }
162 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100163 if (obj->pin_display)
164 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100165 if (obj->fence_reg != I915_FENCE_REG_NONE)
166 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700167 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100168 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
169 i915_is_ggtt(vma->vm) ? "g" : "pp",
170 vma->node.start, vma->node.size);
171 if (i915_is_ggtt(vma->vm))
172 seq_printf(m, ", type: %u)", vma->ggtt_view.type);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700173 else
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100174 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)",
Chris Wilsonb4716182015-04-27 13:41:17 +0100189 i915_gem_request_get_ring(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;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700207 struct drm_i915_private *dev_priv = dev->dev_private;
208 struct i915_address_space *vm = &dev_priv->gtt.base;
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");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700221 head = &vm->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");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700225 head = &vm->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;
Ben Widawskyca191b12013-07-31 17:00:14 -0700233 list_for_each_entry(vma, head, mm_list) {
234 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
256 return a->stolen->start - b->stolen->start;
257}
258
259static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
260{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100261 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100262 struct drm_device *dev = node->minor->dev;
263 struct drm_i915_private *dev_priv = dev->dev_private;
264 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300265 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100266 LIST_HEAD(stolen);
267 int count, ret;
268
269 ret = mutex_lock_interruptible(&dev->struct_mutex);
270 if (ret)
271 return ret;
272
273 total_obj_size = total_gtt_size = count = 0;
274 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
275 if (obj->stolen == NULL)
276 continue;
277
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200278 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100279
280 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100281 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100282 count++;
283 }
284 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
285 if (obj->stolen == NULL)
286 continue;
287
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200288 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100289
290 total_obj_size += obj->base.size;
291 count++;
292 }
293 list_sort(NULL, &stolen, obj_rank_by_stolen);
294 seq_puts(m, "Stolen:\n");
295 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200296 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100297 seq_puts(m, " ");
298 describe_obj(m, obj);
299 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200300 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100301 }
302 mutex_unlock(&dev->struct_mutex);
303
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300304 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100305 count, total_obj_size, total_gtt_size);
306 return 0;
307}
308
Chris Wilson6299f992010-11-24 12:23:44 +0000309#define count_objects(list, member) do { \
310 list_for_each_entry(obj, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100311 size += i915_gem_obj_total_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000312 ++count; \
313 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700314 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000315 ++mappable_count; \
316 } \
317 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400318} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000319
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100320struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000321 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300322 unsigned long count;
323 u64 total, unbound;
324 u64 global, shared;
325 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100326};
327
328static int per_file_stats(int id, void *ptr, void *data)
329{
330 struct drm_i915_gem_object *obj = ptr;
331 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000332 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100333
334 stats->count++;
335 stats->total += obj->base.size;
336
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000337 if (obj->base.name || obj->base.dma_buf)
338 stats->shared += obj->base.size;
339
Chris Wilson6313c202014-03-19 13:45:45 +0000340 if (USES_FULL_PPGTT(obj->base.dev)) {
341 list_for_each_entry(vma, &obj->vma_list, vma_link) {
342 struct i915_hw_ppgtt *ppgtt;
343
344 if (!drm_mm_node_allocated(&vma->node))
345 continue;
346
347 if (i915_is_ggtt(vma->vm)) {
348 stats->global += obj->base.size;
349 continue;
350 }
351
352 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200353 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000354 continue;
355
John Harrison41c52412014-11-24 18:49:43 +0000356 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000357 stats->active += obj->base.size;
358 else
359 stats->inactive += obj->base.size;
360
361 return 0;
362 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100363 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000364 if (i915_gem_obj_ggtt_bound(obj)) {
365 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000366 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000367 stats->active += obj->base.size;
368 else
369 stats->inactive += obj->base.size;
370 return 0;
371 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100372 }
373
Chris Wilson6313c202014-03-19 13:45:45 +0000374 if (!list_empty(&obj->global_list))
375 stats->unbound += obj->base.size;
376
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100377 return 0;
378}
379
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100380#define print_file_stats(m, name, stats) do { \
381 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300382 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 +0100383 name, \
384 stats.count, \
385 stats.total, \
386 stats.active, \
387 stats.inactive, \
388 stats.global, \
389 stats.shared, \
390 stats.unbound); \
391} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800392
393static void print_batch_pool_stats(struct seq_file *m,
394 struct drm_i915_private *dev_priv)
395{
396 struct drm_i915_gem_object *obj;
397 struct file_stats stats;
Chris Wilson06fbca72015-04-07 16:20:36 +0100398 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100399 int i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800400
401 memset(&stats, 0, sizeof(stats));
402
Chris Wilson06fbca72015-04-07 16:20:36 +0100403 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100404 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
405 list_for_each_entry(obj,
406 &ring->batch_pool.cache_list[j],
407 batch_pool_link)
408 per_file_stats(0, obj, &stats);
409 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100410 }
Brad Volkin493018d2014-12-11 12:13:08 -0800411
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100412 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800413}
414
Ben Widawskyca191b12013-07-31 17:00:14 -0700415#define count_vmas(list, member) do { \
416 list_for_each_entry(vma, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100417 size += i915_gem_obj_total_ggtt_size(vma->obj); \
Ben Widawskyca191b12013-07-31 17:00:14 -0700418 ++count; \
419 if (vma->obj->map_and_fenceable) { \
420 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
421 ++mappable_count; \
422 } \
423 } \
424} while (0)
425
426static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100427{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100428 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100429 struct drm_device *dev = node->minor->dev;
430 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200431 u32 count, mappable_count, purgeable_count;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300432 u64 size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000433 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700434 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100435 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700436 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100437 int ret;
438
439 ret = mutex_lock_interruptible(&dev->struct_mutex);
440 if (ret)
441 return ret;
442
Chris Wilson6299f992010-11-24 12:23:44 +0000443 seq_printf(m, "%u objects, %zu bytes\n",
444 dev_priv->mm.object_count,
445 dev_priv->mm.object_memory);
446
447 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700448 count_objects(&dev_priv->mm.bound_list, global_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300449 seq_printf(m, "%u [%u] objects, %llu [%llu] bytes in gtt\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000450 count, mappable_count, size, mappable_size);
451
452 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700453 count_vmas(&vm->active_list, mm_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300454 seq_printf(m, " %u [%u] active objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000455 count, mappable_count, size, mappable_size);
456
457 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700458 count_vmas(&vm->inactive_list, mm_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300459 seq_printf(m, " %u [%u] inactive objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000460 count, mappable_count, size, mappable_size);
461
Chris Wilsonb7abb712012-08-20 11:33:30 +0200462 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700463 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200464 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200465 if (obj->madv == I915_MADV_DONTNEED)
466 purgeable_size += obj->base.size, ++purgeable_count;
467 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300468 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
Chris Wilson6c085a72012-08-20 11:40:46 +0200469
Chris Wilson6299f992010-11-24 12:23:44 +0000470 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700471 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000472 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700473 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000474 ++count;
475 }
Chris Wilson30154652015-04-07 17:28:24 +0100476 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700477 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000478 ++mappable_count;
479 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200480 if (obj->madv == I915_MADV_DONTNEED) {
481 purgeable_size += obj->base.size;
482 ++purgeable_count;
483 }
Chris Wilson6299f992010-11-24 12:23:44 +0000484 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300485 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200486 purgeable_count, purgeable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300487 seq_printf(m, "%u pinned mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000488 mappable_count, mappable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300489 seq_printf(m, "%u fault mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000490 count, size);
491
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300492 seq_printf(m, "%llu [%llu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700493 dev_priv->gtt.base.total,
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300494 (u64)dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100495
Damien Lespiau267f0c92013-06-24 22:59:48 +0100496 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800497 print_batch_pool_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100498 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
499 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900500 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100501
502 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000503 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100504 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100505 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100506 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900507 /*
508 * Although we have a valid reference on file->pid, that does
509 * not guarantee that the task_struct who called get_pid() is
510 * still alive (e.g. get_pid(current) => fork() => exit()).
511 * Therefore, we need to protect this ->comm access using RCU.
512 */
513 rcu_read_lock();
514 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800515 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900516 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100517 }
518
Chris Wilson73aa8082010-09-30 11:46:12 +0100519 mutex_unlock(&dev->struct_mutex);
520
521 return 0;
522}
523
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100524static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000525{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100526 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000527 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100528 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000529 struct drm_i915_private *dev_priv = dev->dev_private;
530 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300531 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000532 int count, ret;
533
534 ret = mutex_lock_interruptible(&dev->struct_mutex);
535 if (ret)
536 return ret;
537
538 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700539 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800540 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100541 continue;
542
Damien Lespiau267f0c92013-06-24 22:59:48 +0100543 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000544 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100545 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000546 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100547 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000548 count++;
549 }
550
551 mutex_unlock(&dev->struct_mutex);
552
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300553 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000554 count, total_obj_size, total_gtt_size);
555
556 return 0;
557}
558
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100559static int i915_gem_pageflip_info(struct seq_file *m, void *data)
560{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100561 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100562 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100563 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100564 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200565 int ret;
566
567 ret = mutex_lock_interruptible(&dev->struct_mutex);
568 if (ret)
569 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100570
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100571 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800572 const char pipe = pipe_name(crtc->pipe);
573 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100574 struct intel_unpin_work *work;
575
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200576 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100577 work = crtc->unpin_work;
578 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800579 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100580 pipe, plane);
581 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100582 u32 addr;
583
Chris Wilsone7d841c2012-12-03 11:36:30 +0000584 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800585 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100586 pipe, plane);
587 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800588 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100589 pipe, plane);
590 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100591 if (work->flip_queued_req) {
592 struct intel_engine_cs *ring =
593 i915_gem_request_get_ring(work->flip_queued_req);
594
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200595 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100596 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000597 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100598 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100599 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000600 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100601 } else
602 seq_printf(m, "Flip not associated with any ring\n");
603 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
604 work->flip_queued_vblank,
605 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100606 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100607 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100608 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100609 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100610 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000611 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100612
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100613 if (INTEL_INFO(dev)->gen >= 4)
614 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
615 else
616 addr = I915_READ(DSPADDR(crtc->plane));
617 seq_printf(m, "Current scanout address 0x%08x\n", addr);
618
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100619 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100620 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
621 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100622 }
623 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200624 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100625 }
626
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200627 mutex_unlock(&dev->struct_mutex);
628
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100629 return 0;
630}
631
Brad Volkin493018d2014-12-11 12:13:08 -0800632static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
633{
634 struct drm_info_node *node = m->private;
635 struct drm_device *dev = node->minor->dev;
636 struct drm_i915_private *dev_priv = dev->dev_private;
637 struct drm_i915_gem_object *obj;
Chris Wilson06fbca72015-04-07 16:20:36 +0100638 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100639 int total = 0;
640 int ret, i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800641
642 ret = mutex_lock_interruptible(&dev->struct_mutex);
643 if (ret)
644 return ret;
645
Chris Wilson06fbca72015-04-07 16:20:36 +0100646 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100647 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
648 int count;
649
650 count = 0;
651 list_for_each_entry(obj,
652 &ring->batch_pool.cache_list[j],
653 batch_pool_link)
654 count++;
655 seq_printf(m, "%s cache[%d]: %d objects\n",
656 ring->name, j, count);
657
658 list_for_each_entry(obj,
659 &ring->batch_pool.cache_list[j],
660 batch_pool_link) {
661 seq_puts(m, " ");
662 describe_obj(m, obj);
663 seq_putc(m, '\n');
664 }
665
666 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100667 }
Brad Volkin493018d2014-12-11 12:13:08 -0800668 }
669
Chris Wilson8d9d5742015-04-07 16:20:38 +0100670 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800671
672 mutex_unlock(&dev->struct_mutex);
673
674 return 0;
675}
676
Ben Gamari20172632009-02-17 20:08:50 -0500677static int i915_gem_request_info(struct seq_file *m, void *data)
678{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100679 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500680 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300681 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100682 struct intel_engine_cs *ring;
Daniel Vettereed29a52015-05-21 14:21:25 +0200683 struct drm_i915_gem_request *req;
Chris Wilson2d1070b2015-04-01 10:36:56 +0100684 int ret, any, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100685
686 ret = mutex_lock_interruptible(&dev->struct_mutex);
687 if (ret)
688 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500689
Chris Wilson2d1070b2015-04-01 10:36:56 +0100690 any = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100691 for_each_ring(ring, dev_priv, i) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100692 int count;
693
694 count = 0;
Daniel Vettereed29a52015-05-21 14:21:25 +0200695 list_for_each_entry(req, &ring->request_list, list)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100696 count++;
697 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100698 continue;
699
Chris Wilson2d1070b2015-04-01 10:36:56 +0100700 seq_printf(m, "%s requests: %d\n", ring->name, count);
Daniel Vettereed29a52015-05-21 14:21:25 +0200701 list_for_each_entry(req, &ring->request_list, list) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100702 struct task_struct *task;
703
704 rcu_read_lock();
705 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200706 if (req->pid)
707 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100708 seq_printf(m, " %x @ %d: %s [%d]\n",
Daniel Vettereed29a52015-05-21 14:21:25 +0200709 req->seqno,
710 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100711 task ? task->comm : "<unknown>",
712 task ? task->pid : -1);
713 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100714 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100715
716 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500717 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100718 mutex_unlock(&dev->struct_mutex);
719
Chris Wilson2d1070b2015-04-01 10:36:56 +0100720 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100721 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100722
Ben Gamari20172632009-02-17 20:08:50 -0500723 return 0;
724}
725
Chris Wilsonb2223492010-10-27 15:27:33 +0100726static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100727 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100728{
729 if (ring->get_seqno) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200730 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100731 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100732 }
733}
734
Ben Gamari20172632009-02-17 20:08:50 -0500735static int i915_gem_seqno_info(struct seq_file *m, void *data)
736{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100737 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500738 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300739 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100740 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000741 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100742
743 ret = mutex_lock_interruptible(&dev->struct_mutex);
744 if (ret)
745 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200746 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500747
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100748 for_each_ring(ring, dev_priv, i)
749 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100750
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200751 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100752 mutex_unlock(&dev->struct_mutex);
753
Ben Gamari20172632009-02-17 20:08:50 -0500754 return 0;
755}
756
757
758static int i915_interrupt_info(struct seq_file *m, void *data)
759{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100760 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500761 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300762 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100763 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800764 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100765
766 ret = mutex_lock_interruptible(&dev->struct_mutex);
767 if (ret)
768 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200769 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500770
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300771 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300772 seq_printf(m, "Master Interrupt Control:\t%08x\n",
773 I915_READ(GEN8_MASTER_IRQ));
774
775 seq_printf(m, "Display IER:\t%08x\n",
776 I915_READ(VLV_IER));
777 seq_printf(m, "Display IIR:\t%08x\n",
778 I915_READ(VLV_IIR));
779 seq_printf(m, "Display IIR_RW:\t%08x\n",
780 I915_READ(VLV_IIR_RW));
781 seq_printf(m, "Display IMR:\t%08x\n",
782 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100783 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300784 seq_printf(m, "Pipe %c stat:\t%08x\n",
785 pipe_name(pipe),
786 I915_READ(PIPESTAT(pipe)));
787
788 seq_printf(m, "Port hotplug:\t%08x\n",
789 I915_READ(PORT_HOTPLUG_EN));
790 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
791 I915_READ(VLV_DPFLIPSTAT));
792 seq_printf(m, "DPINVGTT:\t%08x\n",
793 I915_READ(DPINVGTT));
794
795 for (i = 0; i < 4; i++) {
796 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
797 i, I915_READ(GEN8_GT_IMR(i)));
798 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
799 i, I915_READ(GEN8_GT_IIR(i)));
800 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
801 i, I915_READ(GEN8_GT_IER(i)));
802 }
803
804 seq_printf(m, "PCU interrupt mask:\t%08x\n",
805 I915_READ(GEN8_PCU_IMR));
806 seq_printf(m, "PCU interrupt identity:\t%08x\n",
807 I915_READ(GEN8_PCU_IIR));
808 seq_printf(m, "PCU interrupt enable:\t%08x\n",
809 I915_READ(GEN8_PCU_IER));
810 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700811 seq_printf(m, "Master Interrupt Control:\t%08x\n",
812 I915_READ(GEN8_MASTER_IRQ));
813
814 for (i = 0; i < 4; i++) {
815 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
816 i, I915_READ(GEN8_GT_IMR(i)));
817 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
818 i, I915_READ(GEN8_GT_IIR(i)));
819 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
820 i, I915_READ(GEN8_GT_IER(i)));
821 }
822
Damien Lespiau055e3932014-08-18 13:49:10 +0100823 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200824 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300825 POWER_DOMAIN_PIPE(pipe))) {
826 seq_printf(m, "Pipe %c power disabled\n",
827 pipe_name(pipe));
828 continue;
829 }
Ben Widawskya123f152013-11-02 21:07:10 -0700830 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000831 pipe_name(pipe),
832 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700833 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000834 pipe_name(pipe),
835 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700836 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000837 pipe_name(pipe),
838 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700839 }
840
841 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
842 I915_READ(GEN8_DE_PORT_IMR));
843 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
844 I915_READ(GEN8_DE_PORT_IIR));
845 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
846 I915_READ(GEN8_DE_PORT_IER));
847
848 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
849 I915_READ(GEN8_DE_MISC_IMR));
850 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
851 I915_READ(GEN8_DE_MISC_IIR));
852 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
853 I915_READ(GEN8_DE_MISC_IER));
854
855 seq_printf(m, "PCU interrupt mask:\t%08x\n",
856 I915_READ(GEN8_PCU_IMR));
857 seq_printf(m, "PCU interrupt identity:\t%08x\n",
858 I915_READ(GEN8_PCU_IIR));
859 seq_printf(m, "PCU interrupt enable:\t%08x\n",
860 I915_READ(GEN8_PCU_IER));
861 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700862 seq_printf(m, "Display IER:\t%08x\n",
863 I915_READ(VLV_IER));
864 seq_printf(m, "Display IIR:\t%08x\n",
865 I915_READ(VLV_IIR));
866 seq_printf(m, "Display IIR_RW:\t%08x\n",
867 I915_READ(VLV_IIR_RW));
868 seq_printf(m, "Display IMR:\t%08x\n",
869 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100870 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700871 seq_printf(m, "Pipe %c stat:\t%08x\n",
872 pipe_name(pipe),
873 I915_READ(PIPESTAT(pipe)));
874
875 seq_printf(m, "Master IER:\t%08x\n",
876 I915_READ(VLV_MASTER_IER));
877
878 seq_printf(m, "Render IER:\t%08x\n",
879 I915_READ(GTIER));
880 seq_printf(m, "Render IIR:\t%08x\n",
881 I915_READ(GTIIR));
882 seq_printf(m, "Render IMR:\t%08x\n",
883 I915_READ(GTIMR));
884
885 seq_printf(m, "PM IER:\t\t%08x\n",
886 I915_READ(GEN6_PMIER));
887 seq_printf(m, "PM IIR:\t\t%08x\n",
888 I915_READ(GEN6_PMIIR));
889 seq_printf(m, "PM IMR:\t\t%08x\n",
890 I915_READ(GEN6_PMIMR));
891
892 seq_printf(m, "Port hotplug:\t%08x\n",
893 I915_READ(PORT_HOTPLUG_EN));
894 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
895 I915_READ(VLV_DPFLIPSTAT));
896 seq_printf(m, "DPINVGTT:\t%08x\n",
897 I915_READ(DPINVGTT));
898
899 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800900 seq_printf(m, "Interrupt enable: %08x\n",
901 I915_READ(IER));
902 seq_printf(m, "Interrupt identity: %08x\n",
903 I915_READ(IIR));
904 seq_printf(m, "Interrupt mask: %08x\n",
905 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100906 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800907 seq_printf(m, "Pipe %c stat: %08x\n",
908 pipe_name(pipe),
909 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800910 } else {
911 seq_printf(m, "North Display Interrupt enable: %08x\n",
912 I915_READ(DEIER));
913 seq_printf(m, "North Display Interrupt identity: %08x\n",
914 I915_READ(DEIIR));
915 seq_printf(m, "North Display Interrupt mask: %08x\n",
916 I915_READ(DEIMR));
917 seq_printf(m, "South Display Interrupt enable: %08x\n",
918 I915_READ(SDEIER));
919 seq_printf(m, "South Display Interrupt identity: %08x\n",
920 I915_READ(SDEIIR));
921 seq_printf(m, "South Display Interrupt mask: %08x\n",
922 I915_READ(SDEIMR));
923 seq_printf(m, "Graphics Interrupt enable: %08x\n",
924 I915_READ(GTIER));
925 seq_printf(m, "Graphics Interrupt identity: %08x\n",
926 I915_READ(GTIIR));
927 seq_printf(m, "Graphics Interrupt mask: %08x\n",
928 I915_READ(GTIMR));
929 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100930 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700931 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100932 seq_printf(m,
933 "Graphics Interrupt mask (%s): %08x\n",
934 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000935 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100936 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000937 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200938 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100939 mutex_unlock(&dev->struct_mutex);
940
Ben Gamari20172632009-02-17 20:08:50 -0500941 return 0;
942}
943
Chris Wilsona6172a82009-02-11 14:26:38 +0000944static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
945{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100946 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000947 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300948 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100949 int i, ret;
950
951 ret = mutex_lock_interruptible(&dev->struct_mutex);
952 if (ret)
953 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000954
955 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
956 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
957 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000958 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000959
Chris Wilson6c085a72012-08-20 11:40:46 +0200960 seq_printf(m, "Fence %d, pin count = %d, object = ",
961 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100962 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100963 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100964 else
Chris Wilson05394f32010-11-08 19:18:58 +0000965 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100966 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000967 }
968
Chris Wilson05394f32010-11-08 19:18:58 +0000969 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000970 return 0;
971}
972
Ben Gamari20172632009-02-17 20:08:50 -0500973static int i915_hws_info(struct seq_file *m, void *data)
974{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100975 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500976 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300977 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100978 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100979 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100980 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500981
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000982 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100983 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500984 if (hws == NULL)
985 return 0;
986
987 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
988 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
989 i * 4,
990 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
991 }
992 return 0;
993}
994
Daniel Vetterd5442302012-04-27 15:17:40 +0200995static ssize_t
996i915_error_state_write(struct file *filp,
997 const char __user *ubuf,
998 size_t cnt,
999 loff_t *ppos)
1000{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001001 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001002 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001003 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001004
1005 DRM_DEBUG_DRIVER("Resetting error state\n");
1006
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001007 ret = mutex_lock_interruptible(&dev->struct_mutex);
1008 if (ret)
1009 return ret;
1010
Daniel Vetterd5442302012-04-27 15:17:40 +02001011 i915_destroy_error_state(dev);
1012 mutex_unlock(&dev->struct_mutex);
1013
1014 return cnt;
1015}
1016
1017static int i915_error_state_open(struct inode *inode, struct file *file)
1018{
1019 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001020 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001021
1022 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1023 if (!error_priv)
1024 return -ENOMEM;
1025
1026 error_priv->dev = dev;
1027
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001028 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001029
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001030 file->private_data = error_priv;
1031
1032 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001033}
1034
1035static int i915_error_state_release(struct inode *inode, struct file *file)
1036{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001037 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001038
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001039 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001040 kfree(error_priv);
1041
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001042 return 0;
1043}
1044
1045static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1046 size_t count, loff_t *pos)
1047{
1048 struct i915_error_state_file_priv *error_priv = file->private_data;
1049 struct drm_i915_error_state_buf error_str;
1050 loff_t tmp_pos = 0;
1051 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001052 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001053
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001054 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001055 if (ret)
1056 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001057
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001058 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001059 if (ret)
1060 goto out;
1061
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001062 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1063 error_str.buf,
1064 error_str.bytes);
1065
1066 if (ret_count < 0)
1067 ret = ret_count;
1068 else
1069 *pos = error_str.start + ret_count;
1070out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001071 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001072 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001073}
1074
1075static const struct file_operations i915_error_state_fops = {
1076 .owner = THIS_MODULE,
1077 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001078 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001079 .write = i915_error_state_write,
1080 .llseek = default_llseek,
1081 .release = i915_error_state_release,
1082};
1083
Kees Cook647416f2013-03-10 14:10:06 -07001084static int
1085i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001086{
Kees Cook647416f2013-03-10 14:10:06 -07001087 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001088 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001089 int ret;
1090
1091 ret = mutex_lock_interruptible(&dev->struct_mutex);
1092 if (ret)
1093 return ret;
1094
Kees Cook647416f2013-03-10 14:10:06 -07001095 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001096 mutex_unlock(&dev->struct_mutex);
1097
Kees Cook647416f2013-03-10 14:10:06 -07001098 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001099}
1100
Kees Cook647416f2013-03-10 14:10:06 -07001101static int
1102i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001103{
Kees Cook647416f2013-03-10 14:10:06 -07001104 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001105 int ret;
1106
Mika Kuoppala40633212012-12-04 15:12:00 +02001107 ret = mutex_lock_interruptible(&dev->struct_mutex);
1108 if (ret)
1109 return ret;
1110
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001111 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001112 mutex_unlock(&dev->struct_mutex);
1113
Kees Cook647416f2013-03-10 14:10:06 -07001114 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001115}
1116
Kees Cook647416f2013-03-10 14:10:06 -07001117DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1118 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001119 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001120
Deepak Sadb4bd12014-03-31 11:30:02 +05301121static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001122{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001123 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001124 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001125 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001126 int ret = 0;
1127
1128 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001129
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001130 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1131
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001132 if (IS_GEN5(dev)) {
1133 u16 rgvswctl = I915_READ16(MEMSWCTL);
1134 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1135
1136 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1137 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1138 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1139 MEMSTAT_VID_SHIFT);
1140 seq_printf(m, "Current P-state: %d\n",
1141 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001142 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
Akash Goel60260a52015-03-06 11:07:21 +05301143 IS_BROADWELL(dev) || IS_GEN9(dev)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001144 u32 rp_state_limits;
1145 u32 gt_perf_status;
1146 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001147 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001148 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001149 u32 rpupei, rpcurup, rpprevup;
1150 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001151 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001152 int max_freq;
1153
Bob Paauwe35040562015-06-25 14:54:07 -07001154 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1155 if (IS_BROXTON(dev)) {
1156 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1157 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1158 } else {
1159 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1160 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1161 }
1162
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001163 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001164 ret = mutex_lock_interruptible(&dev->struct_mutex);
1165 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001166 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001167
Mika Kuoppala59bad942015-01-16 11:34:40 +02001168 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001169
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001170 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301171 if (IS_GEN9(dev))
1172 reqf >>= 23;
1173 else {
1174 reqf &= ~GEN6_TURBO_DISABLE;
1175 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1176 reqf >>= 24;
1177 else
1178 reqf >>= 25;
1179 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001180 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001181
Chris Wilson0d8f9492014-03-27 09:06:14 +00001182 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1183 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1184 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1185
Jesse Barnesccab5c82011-01-18 15:49:25 -08001186 rpstat = I915_READ(GEN6_RPSTAT1);
1187 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1188 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1189 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1190 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1191 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1192 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Akash Goel60260a52015-03-06 11:07:21 +05301193 if (IS_GEN9(dev))
1194 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1195 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001196 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1197 else
1198 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001199 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001200
Mika Kuoppala59bad942015-01-16 11:34:40 +02001201 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001202 mutex_unlock(&dev->struct_mutex);
1203
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001204 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1205 pm_ier = I915_READ(GEN6_PMIER);
1206 pm_imr = I915_READ(GEN6_PMIMR);
1207 pm_isr = I915_READ(GEN6_PMISR);
1208 pm_iir = I915_READ(GEN6_PMIIR);
1209 pm_mask = I915_READ(GEN6_PMINTRMSK);
1210 } else {
1211 pm_ier = I915_READ(GEN8_GT_IER(2));
1212 pm_imr = I915_READ(GEN8_GT_IMR(2));
1213 pm_isr = I915_READ(GEN8_GT_ISR(2));
1214 pm_iir = I915_READ(GEN8_GT_IIR(2));
1215 pm_mask = I915_READ(GEN6_PMINTRMSK);
1216 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001217 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 -03001218 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001219 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001220 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301221 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001222 seq_printf(m, "Render p-state VID: %d\n",
1223 gt_perf_status & 0xff);
1224 seq_printf(m, "Render p-state limit: %d\n",
1225 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001226 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1227 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1228 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1229 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001230 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001231 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001232 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1233 GEN6_CURICONT_MASK);
1234 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1235 GEN6_CURBSYTAVG_MASK);
1236 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1237 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001238 seq_printf(m, "Up threshold: %d%%\n",
1239 dev_priv->rps.up_threshold);
1240
Jesse Barnesccab5c82011-01-18 15:49:25 -08001241 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1242 GEN6_CURIAVG_MASK);
1243 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1244 GEN6_CURBSYTAVG_MASK);
1245 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1246 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001247 seq_printf(m, "Down threshold: %d%%\n",
1248 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001249
Bob Paauwe35040562015-06-25 14:54:07 -07001250 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1251 rp_state_cap >> 16) & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301252 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001253 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001254 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001255
1256 max_freq = (rp_state_cap & 0xff00) >> 8;
Akash Goel60260a52015-03-06 11:07:21 +05301257 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001258 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001259 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001260
Bob Paauwe35040562015-06-25 14:54:07 -07001261 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1262 rp_state_cap >> 0) & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301263 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001264 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001265 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001266 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001267 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001268
Chris Wilsond86ed342015-04-27 13:41:19 +01001269 seq_printf(m, "Current freq: %d MHz\n",
1270 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1271 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001272 seq_printf(m, "Idle freq: %d MHz\n",
1273 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001274 seq_printf(m, "Min freq: %d MHz\n",
1275 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1276 seq_printf(m, "Max freq: %d MHz\n",
1277 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1278 seq_printf(m,
1279 "efficient (RPe) frequency: %d MHz\n",
1280 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001281 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001282 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001283
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001284 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001285 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001286 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1287 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1288
Chris Wilsond86ed342015-04-27 13:41:19 +01001289 seq_printf(m, "actual GPU freq: %d MHz\n",
1290 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1291
1292 seq_printf(m, "current GPU freq: %d MHz\n",
1293 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1294
Jesse Barnes0a073b82013-04-17 15:54:58 -07001295 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001296 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001297
Jesse Barnes0a073b82013-04-17 15:54:58 -07001298 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001299 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001300
Chris Wilsonaed242f2015-03-18 09:48:21 +00001301 seq_printf(m, "idle GPU freq: %d MHz\n",
1302 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1303
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001304 seq_printf(m,
1305 "efficient (RPe) frequency: %d MHz\n",
1306 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001307 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001308 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001309 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001310 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001311
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001312out:
1313 intel_runtime_pm_put(dev_priv);
1314 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001315}
1316
Chris Wilsonf6544492015-01-26 18:03:04 +02001317static int i915_hangcheck_info(struct seq_file *m, void *unused)
1318{
1319 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001320 struct drm_device *dev = node->minor->dev;
1321 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf6544492015-01-26 18:03:04 +02001322 struct intel_engine_cs *ring;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001323 u64 acthd[I915_NUM_RINGS];
1324 u32 seqno[I915_NUM_RINGS];
Chris Wilsonf6544492015-01-26 18:03:04 +02001325 int i;
1326
1327 if (!i915.enable_hangcheck) {
1328 seq_printf(m, "Hangcheck disabled\n");
1329 return 0;
1330 }
1331
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001332 intel_runtime_pm_get(dev_priv);
1333
1334 for_each_ring(ring, dev_priv, i) {
1335 seqno[i] = ring->get_seqno(ring, false);
1336 acthd[i] = intel_ring_get_active_head(ring);
1337 }
1338
1339 intel_runtime_pm_put(dev_priv);
1340
Chris Wilsonf6544492015-01-26 18:03:04 +02001341 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1342 seq_printf(m, "Hangcheck active, fires in %dms\n",
1343 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1344 jiffies));
1345 } else
1346 seq_printf(m, "Hangcheck inactive\n");
1347
1348 for_each_ring(ring, dev_priv, i) {
1349 seq_printf(m, "%s:\n", ring->name);
1350 seq_printf(m, "\tseqno = %x [current %x]\n",
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001351 ring->hangcheck.seqno, seqno[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001352 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1353 (long long)ring->hangcheck.acthd,
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001354 (long long)acthd[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001355 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1356 (long long)ring->hangcheck.max_acthd);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001357 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1358 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
Chris Wilsonf6544492015-01-26 18:03:04 +02001359 }
1360
1361 return 0;
1362}
1363
Ben Widawsky4d855292011-12-12 19:34:16 -08001364static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001365{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001366 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001367 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001368 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001369 u32 rgvmodectl, rstdbyctl;
1370 u16 crstandvid;
1371 int ret;
1372
1373 ret = mutex_lock_interruptible(&dev->struct_mutex);
1374 if (ret)
1375 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001376 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001377
1378 rgvmodectl = I915_READ(MEMMODECTL);
1379 rstdbyctl = I915_READ(RSTDBYCTL);
1380 crstandvid = I915_READ16(CRSTANDVID);
1381
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001382 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001383 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001384
Jani Nikula742f4912015-09-03 11:16:09 +03001385 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001386 seq_printf(m, "Boost freq: %d\n",
1387 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1388 MEMMODE_BOOST_FREQ_SHIFT);
1389 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001390 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001391 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001392 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001393 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001394 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001395 seq_printf(m, "Starting frequency: P%d\n",
1396 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001397 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001398 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001399 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1400 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1401 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1402 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001403 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001404 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001405 switch (rstdbyctl & RSX_STATUS_MASK) {
1406 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001407 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001408 break;
1409 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001410 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001411 break;
1412 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001413 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001414 break;
1415 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001416 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001417 break;
1418 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001419 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001420 break;
1421 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001422 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001423 break;
1424 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001425 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001426 break;
1427 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001428
1429 return 0;
1430}
1431
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001432static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001433{
1434 struct drm_info_node *node = m->private;
1435 struct drm_device *dev = node->minor->dev;
1436 struct drm_i915_private *dev_priv = dev->dev_private;
1437 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001438 int i;
1439
1440 spin_lock_irq(&dev_priv->uncore.lock);
1441 for_each_fw_domain(fw_domain, dev_priv, i) {
1442 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001443 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001444 fw_domain->wake_count);
1445 }
1446 spin_unlock_irq(&dev_priv->uncore.lock);
1447
1448 return 0;
1449}
1450
Deepak S669ab5a2014-01-10 15:18:26 +05301451static int vlv_drpc_info(struct seq_file *m)
1452{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001453 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301454 struct drm_device *dev = node->minor->dev;
1455 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001456 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301457
Imre Deakd46c0512014-04-14 20:24:27 +03001458 intel_runtime_pm_get(dev_priv);
1459
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001460 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301461 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1462 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1463
Imre Deakd46c0512014-04-14 20:24:27 +03001464 intel_runtime_pm_put(dev_priv);
1465
Deepak S669ab5a2014-01-10 15:18:26 +05301466 seq_printf(m, "Video Turbo Mode: %s\n",
1467 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1468 seq_printf(m, "Turbo enabled: %s\n",
1469 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1470 seq_printf(m, "HW control enabled: %s\n",
1471 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1472 seq_printf(m, "SW control enabled: %s\n",
1473 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1474 GEN6_RP_MEDIA_SW_MODE));
1475 seq_printf(m, "RC6 Enabled: %s\n",
1476 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1477 GEN6_RC_CTL_EI_MODE(1))));
1478 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001479 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301480 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001481 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301482
Imre Deak9cc19be2014-04-14 20:24:24 +03001483 seq_printf(m, "Render RC6 residency since boot: %u\n",
1484 I915_READ(VLV_GT_RENDER_RC6));
1485 seq_printf(m, "Media RC6 residency since boot: %u\n",
1486 I915_READ(VLV_GT_MEDIA_RC6));
1487
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001488 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301489}
1490
Ben Widawsky4d855292011-12-12 19:34:16 -08001491static int gen6_drpc_info(struct seq_file *m)
1492{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001493 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001494 struct drm_device *dev = node->minor->dev;
1495 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001496 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001497 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001498 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001499
1500 ret = mutex_lock_interruptible(&dev->struct_mutex);
1501 if (ret)
1502 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001503 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001504
Chris Wilson907b28c2013-07-19 20:36:52 +01001505 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001506 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001507 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001508
1509 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001510 seq_puts(m, "RC information inaccurate because somebody "
1511 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001512 } else {
1513 /* NB: we cannot use forcewake, else we read the wrong values */
1514 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1515 udelay(10);
1516 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1517 }
1518
1519 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001520 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001521
1522 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1523 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1524 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001525 mutex_lock(&dev_priv->rps.hw_lock);
1526 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1527 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001528
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001529 intel_runtime_pm_put(dev_priv);
1530
Ben Widawsky4d855292011-12-12 19:34:16 -08001531 seq_printf(m, "Video Turbo Mode: %s\n",
1532 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1533 seq_printf(m, "HW control enabled: %s\n",
1534 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1535 seq_printf(m, "SW control enabled: %s\n",
1536 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1537 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001538 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001539 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1540 seq_printf(m, "RC6 Enabled: %s\n",
1541 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1542 seq_printf(m, "Deep RC6 Enabled: %s\n",
1543 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1544 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1545 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001546 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001547 switch (gt_core_status & GEN6_RCn_MASK) {
1548 case GEN6_RC0:
1549 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001550 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001551 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001552 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001553 break;
1554 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001555 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001556 break;
1557 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001558 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001559 break;
1560 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001561 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001562 break;
1563 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001564 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001565 break;
1566 }
1567
1568 seq_printf(m, "Core Power Down: %s\n",
1569 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001570
1571 /* Not exactly sure what this is */
1572 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1573 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1574 seq_printf(m, "RC6 residency since boot: %u\n",
1575 I915_READ(GEN6_GT_GFX_RC6));
1576 seq_printf(m, "RC6+ residency since boot: %u\n",
1577 I915_READ(GEN6_GT_GFX_RC6p));
1578 seq_printf(m, "RC6++ residency since boot: %u\n",
1579 I915_READ(GEN6_GT_GFX_RC6pp));
1580
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001581 seq_printf(m, "RC6 voltage: %dmV\n",
1582 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1583 seq_printf(m, "RC6+ voltage: %dmV\n",
1584 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1585 seq_printf(m, "RC6++ voltage: %dmV\n",
1586 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001587 return 0;
1588}
1589
1590static int i915_drpc_info(struct seq_file *m, void *unused)
1591{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001592 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001593 struct drm_device *dev = node->minor->dev;
1594
Deepak S669ab5a2014-01-10 15:18:26 +05301595 if (IS_VALLEYVIEW(dev))
1596 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001597 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001598 return gen6_drpc_info(m);
1599 else
1600 return ironlake_drpc_info(m);
1601}
1602
Daniel Vetter9a851782015-06-18 10:30:22 +02001603static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1604{
1605 struct drm_info_node *node = m->private;
1606 struct drm_device *dev = node->minor->dev;
1607 struct drm_i915_private *dev_priv = dev->dev_private;
1608
1609 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1610 dev_priv->fb_tracking.busy_bits);
1611
1612 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1613 dev_priv->fb_tracking.flip_bits);
1614
1615 return 0;
1616}
1617
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001618static int i915_fbc_status(struct seq_file *m, void *unused)
1619{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001620 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001621 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001622 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001623
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001624 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001625 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001626 return 0;
1627 }
1628
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001629 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001630 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001631
Paulo Zanoni7733b492015-07-07 15:26:04 -03001632 if (intel_fbc_enabled(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001633 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001634 else
1635 seq_printf(m, "FBC disabled: %s\n",
1636 intel_no_fbc_reason_str(dev_priv->fbc.no_fbc_reason));
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001637
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001638 if (INTEL_INFO(dev_priv)->gen >= 7)
1639 seq_printf(m, "Compressing: %s\n",
1640 yesno(I915_READ(FBC_STATUS2) &
1641 FBC_COMPRESSION_MASK));
1642
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001643 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001644 intel_runtime_pm_put(dev_priv);
1645
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001646 return 0;
1647}
1648
Rodrigo Vivida46f932014-08-01 02:04:45 -07001649static int i915_fbc_fc_get(void *data, u64 *val)
1650{
1651 struct drm_device *dev = data;
1652 struct drm_i915_private *dev_priv = dev->dev_private;
1653
1654 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1655 return -ENODEV;
1656
Rodrigo Vivida46f932014-08-01 02:04:45 -07001657 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001658
1659 return 0;
1660}
1661
1662static int i915_fbc_fc_set(void *data, u64 val)
1663{
1664 struct drm_device *dev = data;
1665 struct drm_i915_private *dev_priv = dev->dev_private;
1666 u32 reg;
1667
1668 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1669 return -ENODEV;
1670
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001671 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001672
1673 reg = I915_READ(ILK_DPFC_CONTROL);
1674 dev_priv->fbc.false_color = val;
1675
1676 I915_WRITE(ILK_DPFC_CONTROL, val ?
1677 (reg | FBC_CTL_FALSE_COLOR) :
1678 (reg & ~FBC_CTL_FALSE_COLOR));
1679
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001680 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001681 return 0;
1682}
1683
1684DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1685 i915_fbc_fc_get, i915_fbc_fc_set,
1686 "%llu\n");
1687
Paulo Zanoni92d44622013-05-31 16:33:24 -03001688static int i915_ips_status(struct seq_file *m, void *unused)
1689{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001690 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001691 struct drm_device *dev = node->minor->dev;
1692 struct drm_i915_private *dev_priv = dev->dev_private;
1693
Damien Lespiauf5adf942013-06-24 18:29:34 +01001694 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001695 seq_puts(m, "not supported\n");
1696 return 0;
1697 }
1698
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001699 intel_runtime_pm_get(dev_priv);
1700
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001701 seq_printf(m, "Enabled by kernel parameter: %s\n",
1702 yesno(i915.enable_ips));
1703
1704 if (INTEL_INFO(dev)->gen >= 8) {
1705 seq_puts(m, "Currently: unknown\n");
1706 } else {
1707 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1708 seq_puts(m, "Currently: enabled\n");
1709 else
1710 seq_puts(m, "Currently: disabled\n");
1711 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001712
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001713 intel_runtime_pm_put(dev_priv);
1714
Paulo Zanoni92d44622013-05-31 16:33:24 -03001715 return 0;
1716}
1717
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001718static int i915_sr_status(struct seq_file *m, void *unused)
1719{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001720 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001721 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001722 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001723 bool sr_enabled = false;
1724
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001725 intel_runtime_pm_get(dev_priv);
1726
Yuanhan Liu13982612010-12-15 15:42:31 +08001727 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001728 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001729 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1730 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001731 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1732 else if (IS_I915GM(dev))
1733 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1734 else if (IS_PINEVIEW(dev))
1735 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001736 else if (IS_VALLEYVIEW(dev))
1737 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001738
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001739 intel_runtime_pm_put(dev_priv);
1740
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001741 seq_printf(m, "self-refresh: %s\n",
1742 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001743
1744 return 0;
1745}
1746
Jesse Barnes7648fa92010-05-20 14:28:11 -07001747static int i915_emon_status(struct seq_file *m, void *unused)
1748{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001749 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001750 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001751 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001752 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001753 int ret;
1754
Chris Wilson582be6b2012-04-30 19:35:02 +01001755 if (!IS_GEN5(dev))
1756 return -ENODEV;
1757
Chris Wilsonde227ef2010-07-03 07:58:38 +01001758 ret = mutex_lock_interruptible(&dev->struct_mutex);
1759 if (ret)
1760 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001761
1762 temp = i915_mch_val(dev_priv);
1763 chipset = i915_chipset_val(dev_priv);
1764 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001765 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001766
1767 seq_printf(m, "GMCH temp: %ld\n", temp);
1768 seq_printf(m, "Chipset power: %ld\n", chipset);
1769 seq_printf(m, "GFX power: %ld\n", gfx);
1770 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1771
1772 return 0;
1773}
1774
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001775static int i915_ring_freq_table(struct seq_file *m, void *unused)
1776{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001777 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001778 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001779 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001780 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001781 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301782 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001783
Akash Goel97d33082015-06-29 14:50:23 +05301784 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001785 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001786 return 0;
1787 }
1788
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001789 intel_runtime_pm_get(dev_priv);
1790
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001791 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1792
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001793 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001794 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001795 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001796
Akash Goelf936ec32015-06-29 14:50:22 +05301797 if (IS_SKYLAKE(dev)) {
1798 /* Convert GT frequency to 50 HZ units */
1799 min_gpu_freq =
1800 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1801 max_gpu_freq =
1802 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1803 } else {
1804 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1805 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1806 }
1807
Damien Lespiau267f0c92013-06-24 22:59:48 +01001808 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001809
Akash Goelf936ec32015-06-29 14:50:22 +05301810 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001811 ia_freq = gpu_freq;
1812 sandybridge_pcode_read(dev_priv,
1813 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1814 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001815 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301816 intel_gpu_freq(dev_priv, (gpu_freq *
1817 (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001818 ((ia_freq >> 0) & 0xff) * 100,
1819 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001820 }
1821
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001822 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001823
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001824out:
1825 intel_runtime_pm_put(dev_priv);
1826 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001827}
1828
Chris Wilson44834a62010-08-19 16:09:23 +01001829static int i915_opregion(struct seq_file *m, void *unused)
1830{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001831 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001832 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001833 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001834 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001835 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001836 int ret;
1837
Daniel Vetter0d38f002012-04-21 22:49:10 +02001838 if (data == NULL)
1839 return -ENOMEM;
1840
Chris Wilson44834a62010-08-19 16:09:23 +01001841 ret = mutex_lock_interruptible(&dev->struct_mutex);
1842 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001843 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001844
Daniel Vetter0d38f002012-04-21 22:49:10 +02001845 if (opregion->header) {
1846 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1847 seq_write(m, data, OPREGION_SIZE);
1848 }
Chris Wilson44834a62010-08-19 16:09:23 +01001849
1850 mutex_unlock(&dev->struct_mutex);
1851
Daniel Vetter0d38f002012-04-21 22:49:10 +02001852out:
1853 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001854 return 0;
1855}
1856
Chris Wilson37811fc2010-08-25 22:45:57 +01001857static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1858{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001859 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001860 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001861 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001862 struct intel_framebuffer *fb;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001863 struct drm_framebuffer *drm_fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001864
Daniel Vetter06957262015-08-10 13:34:08 +02001865#ifdef CONFIG_DRM_FBDEV_EMULATION
Daniel Vetter4520f532013-10-09 09:18:51 +02001866 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001867
1868 ifbdev = dev_priv->fbdev;
1869 fb = to_intel_framebuffer(ifbdev->helper.fb);
1870
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001871 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001872 fb->base.width,
1873 fb->base.height,
1874 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001875 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001876 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001877 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001878 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001879 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001880#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001881
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001882 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001883 drm_for_each_fb(drm_fb, dev) {
1884 fb = to_intel_framebuffer(drm_fb);
Daniel Vetter131a56d2013-10-17 14:35:31 +02001885 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001886 continue;
1887
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001888 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 +01001889 fb->base.width,
1890 fb->base.height,
1891 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001892 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001893 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001894 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001895 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001896 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001897 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001898 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001899
1900 return 0;
1901}
1902
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001903static void describe_ctx_ringbuf(struct seq_file *m,
1904 struct intel_ringbuffer *ringbuf)
1905{
1906 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1907 ringbuf->space, ringbuf->head, ringbuf->tail,
1908 ringbuf->last_retired_head);
1909}
1910
Ben Widawskye76d3632011-03-19 18:14:29 -07001911static int i915_context_status(struct seq_file *m, void *unused)
1912{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001913 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001914 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001915 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001916 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001917 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001918 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001919
Daniel Vetterf3d28872014-05-29 23:23:08 +02001920 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001921 if (ret)
1922 return ret;
1923
Ben Widawskya33afea2013-09-17 21:12:45 -07001924 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001925 if (!i915.enable_execlists &&
1926 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001927 continue;
1928
Ben Widawskya33afea2013-09-17 21:12:45 -07001929 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001930 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001931 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001932 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001933 seq_printf(m, "(default context %s) ",
1934 ring->name);
1935 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001936
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001937 if (i915.enable_execlists) {
1938 seq_putc(m, '\n');
1939 for_each_ring(ring, dev_priv, i) {
1940 struct drm_i915_gem_object *ctx_obj =
1941 ctx->engine[i].state;
1942 struct intel_ringbuffer *ringbuf =
1943 ctx->engine[i].ringbuf;
1944
1945 seq_printf(m, "%s: ", ring->name);
1946 if (ctx_obj)
1947 describe_obj(m, ctx_obj);
1948 if (ringbuf)
1949 describe_ctx_ringbuf(m, ringbuf);
1950 seq_putc(m, '\n');
1951 }
1952 } else {
1953 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1954 }
1955
Ben Widawskya33afea2013-09-17 21:12:45 -07001956 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001957 }
1958
Daniel Vetterf3d28872014-05-29 23:23:08 +02001959 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001960
1961 return 0;
1962}
1963
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001964static void i915_dump_lrc_obj(struct seq_file *m,
1965 struct intel_engine_cs *ring,
1966 struct drm_i915_gem_object *ctx_obj)
1967{
1968 struct page *page;
1969 uint32_t *reg_state;
1970 int j;
1971 unsigned long ggtt_offset = 0;
1972
1973 if (ctx_obj == NULL) {
1974 seq_printf(m, "Context on %s with no gem object\n",
1975 ring->name);
1976 return;
1977 }
1978
1979 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1980 intel_execlists_ctx_id(ctx_obj));
1981
1982 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1983 seq_puts(m, "\tNot bound in GGTT\n");
1984 else
1985 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1986
1987 if (i915_gem_object_get_pages(ctx_obj)) {
1988 seq_puts(m, "\tFailed to get pages for context object\n");
1989 return;
1990 }
1991
Alex Daid1675192015-08-12 15:43:43 +01001992 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001993 if (!WARN_ON(page == NULL)) {
1994 reg_state = kmap_atomic(page);
1995
1996 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
1997 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1998 ggtt_offset + 4096 + (j * 4),
1999 reg_state[j], reg_state[j + 1],
2000 reg_state[j + 2], reg_state[j + 3]);
2001 }
2002 kunmap_atomic(reg_state);
2003 }
2004
2005 seq_putc(m, '\n');
2006}
2007
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002008static int i915_dump_lrc(struct seq_file *m, void *unused)
2009{
2010 struct drm_info_node *node = (struct drm_info_node *) m->private;
2011 struct drm_device *dev = node->minor->dev;
2012 struct drm_i915_private *dev_priv = dev->dev_private;
2013 struct intel_engine_cs *ring;
2014 struct intel_context *ctx;
2015 int ret, i;
2016
2017 if (!i915.enable_execlists) {
2018 seq_printf(m, "Logical Ring Contexts are disabled\n");
2019 return 0;
2020 }
2021
2022 ret = mutex_lock_interruptible(&dev->struct_mutex);
2023 if (ret)
2024 return ret;
2025
2026 list_for_each_entry(ctx, &dev_priv->context_list, link) {
2027 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002028 if (ring->default_context != ctx)
2029 i915_dump_lrc_obj(m, ring,
2030 ctx->engine[i].state);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002031 }
2032 }
2033
2034 mutex_unlock(&dev->struct_mutex);
2035
2036 return 0;
2037}
2038
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002039static int i915_execlists(struct seq_file *m, void *data)
2040{
2041 struct drm_info_node *node = (struct drm_info_node *)m->private;
2042 struct drm_device *dev = node->minor->dev;
2043 struct drm_i915_private *dev_priv = dev->dev_private;
2044 struct intel_engine_cs *ring;
2045 u32 status_pointer;
2046 u8 read_pointer;
2047 u8 write_pointer;
2048 u32 status;
2049 u32 ctx_id;
2050 struct list_head *cursor;
2051 int ring_id, i;
2052 int ret;
2053
2054 if (!i915.enable_execlists) {
2055 seq_puts(m, "Logical Ring Contexts are disabled\n");
2056 return 0;
2057 }
2058
2059 ret = mutex_lock_interruptible(&dev->struct_mutex);
2060 if (ret)
2061 return ret;
2062
Michel Thierryfc0412e2014-10-16 16:13:38 +01002063 intel_runtime_pm_get(dev_priv);
2064
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002065 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002066 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002067 int count = 0;
2068 unsigned long flags;
2069
2070 seq_printf(m, "%s\n", ring->name);
2071
2072 status = I915_READ(RING_EXECLIST_STATUS(ring));
2073 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
2074 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2075 status, ctx_id);
2076
2077 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2078 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2079
2080 read_pointer = ring->next_context_status_buffer;
2081 write_pointer = status_pointer & 0x07;
2082 if (read_pointer > write_pointer)
2083 write_pointer += 6;
2084 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2085 read_pointer, write_pointer);
2086
2087 for (i = 0; i < 6; i++) {
2088 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
2089 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
2090
2091 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2092 i, status, ctx_id);
2093 }
2094
2095 spin_lock_irqsave(&ring->execlist_lock, flags);
2096 list_for_each(cursor, &ring->execlist_queue)
2097 count++;
2098 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002099 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002100 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2101
2102 seq_printf(m, "\t%d requests in queue\n", count);
2103 if (head_req) {
2104 struct drm_i915_gem_object *ctx_obj;
2105
Nick Hoath6d3d8272015-01-15 13:10:39 +00002106 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002107 seq_printf(m, "\tHead request id: %u\n",
2108 intel_execlists_ctx_id(ctx_obj));
2109 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002110 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002111 }
2112
2113 seq_putc(m, '\n');
2114 }
2115
Michel Thierryfc0412e2014-10-16 16:13:38 +01002116 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002117 mutex_unlock(&dev->struct_mutex);
2118
2119 return 0;
2120}
2121
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002122static const char *swizzle_string(unsigned swizzle)
2123{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002124 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002125 case I915_BIT_6_SWIZZLE_NONE:
2126 return "none";
2127 case I915_BIT_6_SWIZZLE_9:
2128 return "bit9";
2129 case I915_BIT_6_SWIZZLE_9_10:
2130 return "bit9/bit10";
2131 case I915_BIT_6_SWIZZLE_9_11:
2132 return "bit9/bit11";
2133 case I915_BIT_6_SWIZZLE_9_10_11:
2134 return "bit9/bit10/bit11";
2135 case I915_BIT_6_SWIZZLE_9_17:
2136 return "bit9/bit17";
2137 case I915_BIT_6_SWIZZLE_9_10_17:
2138 return "bit9/bit10/bit17";
2139 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002140 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002141 }
2142
2143 return "bug";
2144}
2145
2146static int i915_swizzle_info(struct seq_file *m, void *data)
2147{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002148 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002149 struct drm_device *dev = node->minor->dev;
2150 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002151 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002152
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002153 ret = mutex_lock_interruptible(&dev->struct_mutex);
2154 if (ret)
2155 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002156 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002157
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002158 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2159 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2160 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2161 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2162
2163 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2164 seq_printf(m, "DDC = 0x%08x\n",
2165 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002166 seq_printf(m, "DDC2 = 0x%08x\n",
2167 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002168 seq_printf(m, "C0DRB3 = 0x%04x\n",
2169 I915_READ16(C0DRB3));
2170 seq_printf(m, "C1DRB3 = 0x%04x\n",
2171 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002172 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002173 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2174 I915_READ(MAD_DIMM_C0));
2175 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2176 I915_READ(MAD_DIMM_C1));
2177 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2178 I915_READ(MAD_DIMM_C2));
2179 seq_printf(m, "TILECTL = 0x%08x\n",
2180 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002181 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002182 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2183 I915_READ(GAMTARBMODE));
2184 else
2185 seq_printf(m, "ARB_MODE = 0x%08x\n",
2186 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002187 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2188 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002189 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002190
2191 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2192 seq_puts(m, "L-shaped memory detected\n");
2193
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002194 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002195 mutex_unlock(&dev->struct_mutex);
2196
2197 return 0;
2198}
2199
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002200static int per_file_ctx(int id, void *ptr, void *data)
2201{
Oscar Mateo273497e2014-05-22 14:13:37 +01002202 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002203 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002204 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2205
2206 if (!ppgtt) {
2207 seq_printf(m, " no ppgtt for context %d\n",
2208 ctx->user_handle);
2209 return 0;
2210 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002211
Oscar Mateof83d6512014-05-22 14:13:38 +01002212 if (i915_gem_context_is_default(ctx))
2213 seq_puts(m, " default context:\n");
2214 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002215 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002216 ppgtt->debug_dump(ppgtt, m);
2217
2218 return 0;
2219}
2220
Ben Widawsky77df6772013-11-02 21:07:30 -07002221static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002222{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002223 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002224 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002225 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2226 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002227
Ben Widawsky77df6772013-11-02 21:07:30 -07002228 if (!ppgtt)
2229 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002230
Ben Widawsky77df6772013-11-02 21:07:30 -07002231 for_each_ring(ring, dev_priv, unused) {
2232 seq_printf(m, "%s\n", ring->name);
2233 for (i = 0; i < 4; i++) {
2234 u32 offset = 0x270 + i * 8;
2235 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2236 pdp <<= 32;
2237 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002238 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002239 }
2240 }
2241}
2242
2243static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2244{
2245 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002246 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002247 int i;
2248
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002249 if (INTEL_INFO(dev)->gen == 6)
2250 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2251
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002252 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002253 seq_printf(m, "%s\n", ring->name);
2254 if (INTEL_INFO(dev)->gen == 7)
2255 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2256 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2257 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2258 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2259 }
2260 if (dev_priv->mm.aliasing_ppgtt) {
2261 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2262
Damien Lespiau267f0c92013-06-24 22:59:48 +01002263 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002264 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002265
Ben Widawsky87d60b62013-12-06 14:11:29 -08002266 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002267 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002268
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002269 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002270}
2271
2272static int i915_ppgtt_info(struct seq_file *m, void *data)
2273{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002274 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002275 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002276 struct drm_i915_private *dev_priv = dev->dev_private;
Michel Thierryea91e402015-07-29 17:23:57 +01002277 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002278
2279 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2280 if (ret)
2281 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002282 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002283
2284 if (INTEL_INFO(dev)->gen >= 8)
2285 gen8_ppgtt_info(m, dev);
2286 else if (INTEL_INFO(dev)->gen >= 6)
2287 gen6_ppgtt_info(m, dev);
2288
Michel Thierryea91e402015-07-29 17:23:57 +01002289 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2290 struct drm_i915_file_private *file_priv = file->driver_priv;
2291
2292 seq_printf(m, "\nproc: %s\n",
2293 get_pid_task(file->pid, PIDTYPE_PID)->comm);
2294 idr_for_each(&file_priv->context_idr, per_file_ctx,
2295 (void *)(unsigned long)m);
2296 }
2297
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002298 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002299 mutex_unlock(&dev->struct_mutex);
2300
2301 return 0;
2302}
2303
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002304static int count_irq_waiters(struct drm_i915_private *i915)
2305{
2306 struct intel_engine_cs *ring;
2307 int count = 0;
2308 int i;
2309
2310 for_each_ring(ring, i915, i)
2311 count += ring->irq_refcount;
2312
2313 return count;
2314}
2315
Chris Wilson1854d5c2015-04-07 16:20:32 +01002316static int i915_rps_boost_info(struct seq_file *m, void *data)
2317{
2318 struct drm_info_node *node = m->private;
2319 struct drm_device *dev = node->minor->dev;
2320 struct drm_i915_private *dev_priv = dev->dev_private;
2321 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002322
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002323 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2324 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2325 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2326 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2327 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2328 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2329 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2330 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2331 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson8d3afd72015-05-21 21:01:47 +01002332 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002333 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2334 struct drm_i915_file_private *file_priv = file->driver_priv;
2335 struct task_struct *task;
2336
2337 rcu_read_lock();
2338 task = pid_task(file->pid, PIDTYPE_PID);
2339 seq_printf(m, "%s [%d]: %d boosts%s\n",
2340 task ? task->comm : "<unknown>",
2341 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002342 file_priv->rps.boosts,
2343 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002344 rcu_read_unlock();
2345 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002346 seq_printf(m, "Semaphore boosts: %d%s\n",
2347 dev_priv->rps.semaphores.boosts,
2348 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2349 seq_printf(m, "MMIO flip boosts: %d%s\n",
2350 dev_priv->rps.mmioflips.boosts,
2351 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002352 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002353 spin_unlock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002354
Chris Wilson8d3afd72015-05-21 21:01:47 +01002355 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002356}
2357
Ben Widawsky63573eb2013-07-04 11:02:07 -07002358static int i915_llc(struct seq_file *m, void *data)
2359{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002360 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002361 struct drm_device *dev = node->minor->dev;
2362 struct drm_i915_private *dev_priv = dev->dev_private;
2363
2364 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2365 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2366 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2367
2368 return 0;
2369}
2370
Alex Daifdf5d352015-08-12 15:43:37 +01002371static int i915_guc_load_status_info(struct seq_file *m, void *data)
2372{
2373 struct drm_info_node *node = m->private;
2374 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2375 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2376 u32 tmp, i;
2377
2378 if (!HAS_GUC_UCODE(dev_priv->dev))
2379 return 0;
2380
2381 seq_printf(m, "GuC firmware status:\n");
2382 seq_printf(m, "\tpath: %s\n",
2383 guc_fw->guc_fw_path);
2384 seq_printf(m, "\tfetch: %s\n",
2385 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2386 seq_printf(m, "\tload: %s\n",
2387 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2388 seq_printf(m, "\tversion wanted: %d.%d\n",
2389 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2390 seq_printf(m, "\tversion found: %d.%d\n",
2391 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
2392
2393 tmp = I915_READ(GUC_STATUS);
2394
2395 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2396 seq_printf(m, "\tBootrom status = 0x%x\n",
2397 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2398 seq_printf(m, "\tuKernel status = 0x%x\n",
2399 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2400 seq_printf(m, "\tMIA Core status = 0x%x\n",
2401 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2402 seq_puts(m, "\nScratch registers:\n");
2403 for (i = 0; i < 16; i++)
2404 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2405
2406 return 0;
2407}
2408
Dave Gordon8b417c22015-08-12 15:43:44 +01002409static void i915_guc_client_info(struct seq_file *m,
2410 struct drm_i915_private *dev_priv,
2411 struct i915_guc_client *client)
2412{
2413 struct intel_engine_cs *ring;
2414 uint64_t tot = 0;
2415 uint32_t i;
2416
2417 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2418 client->priority, client->ctx_index, client->proc_desc_offset);
2419 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2420 client->doorbell_id, client->doorbell_offset, client->cookie);
2421 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2422 client->wq_size, client->wq_offset, client->wq_tail);
2423
2424 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2425 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2426 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2427
2428 for_each_ring(ring, dev_priv, i) {
2429 seq_printf(m, "\tSubmissions: %llu %s\n",
2430 client->submissions[i],
2431 ring->name);
2432 tot += client->submissions[i];
2433 }
2434 seq_printf(m, "\tTotal: %llu\n", tot);
2435}
2436
2437static int i915_guc_info(struct seq_file *m, void *data)
2438{
2439 struct drm_info_node *node = m->private;
2440 struct drm_device *dev = node->minor->dev;
2441 struct drm_i915_private *dev_priv = dev->dev_private;
2442 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002443 struct i915_guc_client client = {};
Dave Gordon8b417c22015-08-12 15:43:44 +01002444 struct intel_engine_cs *ring;
2445 enum intel_ring_id i;
2446 u64 total = 0;
2447
2448 if (!HAS_GUC_SCHED(dev_priv->dev))
2449 return 0;
2450
2451 /* Take a local copy of the GuC data, so we can dump it at leisure */
2452 spin_lock(&dev_priv->guc.host2guc_lock);
2453 guc = dev_priv->guc;
2454 if (guc.execbuf_client) {
2455 spin_lock(&guc.execbuf_client->wq_lock);
2456 client = *guc.execbuf_client;
2457 spin_unlock(&guc.execbuf_client->wq_lock);
2458 }
2459 spin_unlock(&dev_priv->guc.host2guc_lock);
2460
2461 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2462 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2463 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2464 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2465 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2466
2467 seq_printf(m, "\nGuC submissions:\n");
2468 for_each_ring(ring, dev_priv, i) {
2469 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x %9d\n",
2470 ring->name, guc.submissions[i],
2471 guc.last_seqno[i], guc.last_seqno[i]);
2472 total += guc.submissions[i];
2473 }
2474 seq_printf(m, "\t%s: %llu\n", "Total", total);
2475
2476 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2477 i915_guc_client_info(m, dev_priv, &client);
2478
2479 /* Add more as required ... */
2480
2481 return 0;
2482}
2483
Alex Dai4c7e77f2015-08-12 15:43:40 +01002484static int i915_guc_log_dump(struct seq_file *m, void *data)
2485{
2486 struct drm_info_node *node = m->private;
2487 struct drm_device *dev = node->minor->dev;
2488 struct drm_i915_private *dev_priv = dev->dev_private;
2489 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2490 u32 *log;
2491 int i = 0, pg;
2492
2493 if (!log_obj)
2494 return 0;
2495
2496 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2497 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2498
2499 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2500 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2501 *(log + i), *(log + i + 1),
2502 *(log + i + 2), *(log + i + 3));
2503
2504 kunmap_atomic(log);
2505 }
2506
2507 seq_putc(m, '\n');
2508
2509 return 0;
2510}
2511
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002512static int i915_edp_psr_status(struct seq_file *m, void *data)
2513{
2514 struct drm_info_node *node = m->private;
2515 struct drm_device *dev = node->minor->dev;
2516 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002517 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002518 u32 stat[3];
2519 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002520 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002521
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002522 if (!HAS_PSR(dev)) {
2523 seq_puts(m, "PSR not supported\n");
2524 return 0;
2525 }
2526
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002527 intel_runtime_pm_get(dev_priv);
2528
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002529 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002530 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2531 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002532 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002533 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002534 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2535 dev_priv->psr.busy_frontbuffer_bits);
2536 seq_printf(m, "Re-enable work scheduled: %s\n",
2537 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002538
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002539 if (HAS_DDI(dev))
2540 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2541 else {
2542 for_each_pipe(dev_priv, pipe) {
2543 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2544 VLV_EDP_PSR_CURR_STATE_MASK;
2545 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2546 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2547 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002548 }
2549 }
2550 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002551
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002552 if (!HAS_DDI(dev))
2553 for_each_pipe(dev_priv, pipe) {
2554 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2555 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2556 seq_printf(m, " pipe %c", pipe_name(pipe));
2557 }
2558 seq_puts(m, "\n");
2559
2560 /* CHV PSR has no kind of performance counter */
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002561 if (HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002562 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2563 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002564
2565 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2566 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002567 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002568
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002569 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002570 return 0;
2571}
2572
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002573static int i915_sink_crc(struct seq_file *m, void *data)
2574{
2575 struct drm_info_node *node = m->private;
2576 struct drm_device *dev = node->minor->dev;
2577 struct intel_encoder *encoder;
2578 struct intel_connector *connector;
2579 struct intel_dp *intel_dp = NULL;
2580 int ret;
2581 u8 crc[6];
2582
2583 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002584 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002585
2586 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2587 continue;
2588
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002589 if (!connector->base.encoder)
2590 continue;
2591
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002592 encoder = to_intel_encoder(connector->base.encoder);
2593 if (encoder->type != INTEL_OUTPUT_EDP)
2594 continue;
2595
2596 intel_dp = enc_to_intel_dp(&encoder->base);
2597
2598 ret = intel_dp_sink_crc(intel_dp, crc);
2599 if (ret)
2600 goto out;
2601
2602 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2603 crc[0], crc[1], crc[2],
2604 crc[3], crc[4], crc[5]);
2605 goto out;
2606 }
2607 ret = -ENODEV;
2608out:
2609 drm_modeset_unlock_all(dev);
2610 return ret;
2611}
2612
Jesse Barnesec013e72013-08-20 10:29:23 +01002613static int i915_energy_uJ(struct seq_file *m, void *data)
2614{
2615 struct drm_info_node *node = m->private;
2616 struct drm_device *dev = node->minor->dev;
2617 struct drm_i915_private *dev_priv = dev->dev_private;
2618 u64 power;
2619 u32 units;
2620
2621 if (INTEL_INFO(dev)->gen < 6)
2622 return -ENODEV;
2623
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002624 intel_runtime_pm_get(dev_priv);
2625
Jesse Barnesec013e72013-08-20 10:29:23 +01002626 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2627 power = (power & 0x1f00) >> 8;
2628 units = 1000000 / (1 << power); /* convert to uJ */
2629 power = I915_READ(MCH_SECP_NRG_STTS);
2630 power *= units;
2631
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002632 intel_runtime_pm_put(dev_priv);
2633
Jesse Barnesec013e72013-08-20 10:29:23 +01002634 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002635
2636 return 0;
2637}
2638
Damien Lespiau6455c872015-06-04 18:23:57 +01002639static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002640{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002641 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002642 struct drm_device *dev = node->minor->dev;
2643 struct drm_i915_private *dev_priv = dev->dev_private;
2644
Damien Lespiau6455c872015-06-04 18:23:57 +01002645 if (!HAS_RUNTIME_PM(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002646 seq_puts(m, "not supported\n");
2647 return 0;
2648 }
2649
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002650 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002651 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002652 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002653#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002654 seq_printf(m, "Usage count: %d\n",
2655 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002656#else
2657 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2658#endif
Paulo Zanoni371db662013-08-19 13:18:10 -03002659
Jesse Barnesec013e72013-08-20 10:29:23 +01002660 return 0;
2661}
2662
Imre Deak1da51582013-11-25 17:15:35 +02002663static const char *power_domain_str(enum intel_display_power_domain domain)
2664{
2665 switch (domain) {
2666 case POWER_DOMAIN_PIPE_A:
2667 return "PIPE_A";
2668 case POWER_DOMAIN_PIPE_B:
2669 return "PIPE_B";
2670 case POWER_DOMAIN_PIPE_C:
2671 return "PIPE_C";
2672 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2673 return "PIPE_A_PANEL_FITTER";
2674 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2675 return "PIPE_B_PANEL_FITTER";
2676 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2677 return "PIPE_C_PANEL_FITTER";
2678 case POWER_DOMAIN_TRANSCODER_A:
2679 return "TRANSCODER_A";
2680 case POWER_DOMAIN_TRANSCODER_B:
2681 return "TRANSCODER_B";
2682 case POWER_DOMAIN_TRANSCODER_C:
2683 return "TRANSCODER_C";
2684 case POWER_DOMAIN_TRANSCODER_EDP:
2685 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002686 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2687 return "PORT_DDI_A_2_LANES";
2688 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2689 return "PORT_DDI_A_4_LANES";
2690 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2691 return "PORT_DDI_B_2_LANES";
2692 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2693 return "PORT_DDI_B_4_LANES";
2694 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2695 return "PORT_DDI_C_2_LANES";
2696 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2697 return "PORT_DDI_C_4_LANES";
2698 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2699 return "PORT_DDI_D_2_LANES";
2700 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2701 return "PORT_DDI_D_4_LANES";
Xiong Zhangd8e19f92015-08-13 18:00:12 +08002702 case POWER_DOMAIN_PORT_DDI_E_2_LANES:
2703 return "PORT_DDI_E_2_LANES";
Imre Deak319be8a2014-03-04 19:22:57 +02002704 case POWER_DOMAIN_PORT_DSI:
2705 return "PORT_DSI";
2706 case POWER_DOMAIN_PORT_CRT:
2707 return "PORT_CRT";
2708 case POWER_DOMAIN_PORT_OTHER:
2709 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002710 case POWER_DOMAIN_VGA:
2711 return "VGA";
2712 case POWER_DOMAIN_AUDIO:
2713 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002714 case POWER_DOMAIN_PLLS:
2715 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002716 case POWER_DOMAIN_AUX_A:
2717 return "AUX_A";
2718 case POWER_DOMAIN_AUX_B:
2719 return "AUX_B";
2720 case POWER_DOMAIN_AUX_C:
2721 return "AUX_C";
2722 case POWER_DOMAIN_AUX_D:
2723 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002724 case POWER_DOMAIN_INIT:
2725 return "INIT";
2726 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002727 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002728 return "?";
2729 }
2730}
2731
2732static int i915_power_domain_info(struct seq_file *m, void *unused)
2733{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002734 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002735 struct drm_device *dev = node->minor->dev;
2736 struct drm_i915_private *dev_priv = dev->dev_private;
2737 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2738 int i;
2739
2740 mutex_lock(&power_domains->lock);
2741
2742 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2743 for (i = 0; i < power_domains->power_well_count; i++) {
2744 struct i915_power_well *power_well;
2745 enum intel_display_power_domain power_domain;
2746
2747 power_well = &power_domains->power_wells[i];
2748 seq_printf(m, "%-25s %d\n", power_well->name,
2749 power_well->count);
2750
2751 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2752 power_domain++) {
2753 if (!(BIT(power_domain) & power_well->domains))
2754 continue;
2755
2756 seq_printf(m, " %-23s %d\n",
2757 power_domain_str(power_domain),
2758 power_domains->domain_use_count[power_domain]);
2759 }
2760 }
2761
2762 mutex_unlock(&power_domains->lock);
2763
2764 return 0;
2765}
2766
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002767static void intel_seq_print_mode(struct seq_file *m, int tabs,
2768 struct drm_display_mode *mode)
2769{
2770 int i;
2771
2772 for (i = 0; i < tabs; i++)
2773 seq_putc(m, '\t');
2774
2775 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",
2776 mode->base.id, mode->name,
2777 mode->vrefresh, mode->clock,
2778 mode->hdisplay, mode->hsync_start,
2779 mode->hsync_end, mode->htotal,
2780 mode->vdisplay, mode->vsync_start,
2781 mode->vsync_end, mode->vtotal,
2782 mode->type, mode->flags);
2783}
2784
2785static void intel_encoder_info(struct seq_file *m,
2786 struct intel_crtc *intel_crtc,
2787 struct intel_encoder *intel_encoder)
2788{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002789 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002790 struct drm_device *dev = node->minor->dev;
2791 struct drm_crtc *crtc = &intel_crtc->base;
2792 struct intel_connector *intel_connector;
2793 struct drm_encoder *encoder;
2794
2795 encoder = &intel_encoder->base;
2796 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002797 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002798 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2799 struct drm_connector *connector = &intel_connector->base;
2800 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2801 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002802 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002803 drm_get_connector_status_name(connector->status));
2804 if (connector->status == connector_status_connected) {
2805 struct drm_display_mode *mode = &crtc->mode;
2806 seq_printf(m, ", mode:\n");
2807 intel_seq_print_mode(m, 2, mode);
2808 } else {
2809 seq_putc(m, '\n');
2810 }
2811 }
2812}
2813
2814static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2815{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002816 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002817 struct drm_device *dev = node->minor->dev;
2818 struct drm_crtc *crtc = &intel_crtc->base;
2819 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002820 struct drm_plane_state *plane_state = crtc->primary->state;
2821 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002822
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002823 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002824 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002825 fb->base.id, plane_state->src_x >> 16,
2826 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002827 else
2828 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002829 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2830 intel_encoder_info(m, intel_crtc, intel_encoder);
2831}
2832
2833static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2834{
2835 struct drm_display_mode *mode = panel->fixed_mode;
2836
2837 seq_printf(m, "\tfixed mode:\n");
2838 intel_seq_print_mode(m, 2, mode);
2839}
2840
2841static void intel_dp_info(struct seq_file *m,
2842 struct intel_connector *intel_connector)
2843{
2844 struct intel_encoder *intel_encoder = intel_connector->encoder;
2845 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2846
2847 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002848 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002849 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2850 intel_panel_info(m, &intel_connector->panel);
2851}
2852
2853static void intel_hdmi_info(struct seq_file *m,
2854 struct intel_connector *intel_connector)
2855{
2856 struct intel_encoder *intel_encoder = intel_connector->encoder;
2857 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2858
Jani Nikula742f4912015-09-03 11:16:09 +03002859 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002860}
2861
2862static void intel_lvds_info(struct seq_file *m,
2863 struct intel_connector *intel_connector)
2864{
2865 intel_panel_info(m, &intel_connector->panel);
2866}
2867
2868static void intel_connector_info(struct seq_file *m,
2869 struct drm_connector *connector)
2870{
2871 struct intel_connector *intel_connector = to_intel_connector(connector);
2872 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002873 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002874
2875 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002876 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002877 drm_get_connector_status_name(connector->status));
2878 if (connector->status == connector_status_connected) {
2879 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2880 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2881 connector->display_info.width_mm,
2882 connector->display_info.height_mm);
2883 seq_printf(m, "\tsubpixel order: %s\n",
2884 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2885 seq_printf(m, "\tCEA rev: %d\n",
2886 connector->display_info.cea_rev);
2887 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002888 if (intel_encoder) {
2889 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2890 intel_encoder->type == INTEL_OUTPUT_EDP)
2891 intel_dp_info(m, intel_connector);
2892 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2893 intel_hdmi_info(m, intel_connector);
2894 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2895 intel_lvds_info(m, intel_connector);
2896 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002897
Jesse Barnesf103fc72014-02-20 12:39:57 -08002898 seq_printf(m, "\tmodes:\n");
2899 list_for_each_entry(mode, &connector->modes, head)
2900 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002901}
2902
Chris Wilson065f2ec22014-03-12 09:13:13 +00002903static bool cursor_active(struct drm_device *dev, int pipe)
2904{
2905 struct drm_i915_private *dev_priv = dev->dev_private;
2906 u32 state;
2907
2908 if (IS_845G(dev) || IS_I865G(dev))
2909 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002910 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002911 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002912
2913 return state;
2914}
2915
2916static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2917{
2918 struct drm_i915_private *dev_priv = dev->dev_private;
2919 u32 pos;
2920
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002921 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00002922
2923 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2924 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2925 *x = -*x;
2926
2927 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2928 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2929 *y = -*y;
2930
2931 return cursor_active(dev, pipe);
2932}
2933
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002934static int i915_display_info(struct seq_file *m, void *unused)
2935{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002936 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002937 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002938 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002939 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002940 struct drm_connector *connector;
2941
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002942 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002943 drm_modeset_lock_all(dev);
2944 seq_printf(m, "CRTC info\n");
2945 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002946 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002947 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002948 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002949 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002950
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002951 pipe_config = to_intel_crtc_state(crtc->base.state);
2952
Chris Wilson57127ef2014-07-04 08:20:11 +01002953 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00002954 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002955 yesno(pipe_config->base.active),
2956 pipe_config->pipe_src_w, pipe_config->pipe_src_h);
2957 if (pipe_config->base.active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002958 intel_crtc_info(m, crtc);
2959
Paulo Zanonia23dc652014-04-01 14:55:11 -03002960 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002961 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 +03002962 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08002963 x, y, crtc->base.cursor->state->crtc_w,
2964 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01002965 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002966 }
Daniel Vettercace8412014-05-22 17:56:31 +02002967
2968 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2969 yesno(!crtc->cpu_fifo_underrun_disabled),
2970 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002971 }
2972
2973 seq_printf(m, "\n");
2974 seq_printf(m, "Connector info\n");
2975 seq_printf(m, "--------------\n");
2976 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2977 intel_connector_info(m, connector);
2978 }
2979 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002980 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002981
2982 return 0;
2983}
2984
Ben Widawskye04934c2014-06-30 09:53:42 -07002985static int i915_semaphore_status(struct seq_file *m, void *unused)
2986{
2987 struct drm_info_node *node = (struct drm_info_node *) m->private;
2988 struct drm_device *dev = node->minor->dev;
2989 struct drm_i915_private *dev_priv = dev->dev_private;
2990 struct intel_engine_cs *ring;
2991 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2992 int i, j, ret;
2993
2994 if (!i915_semaphore_is_enabled(dev)) {
2995 seq_puts(m, "Semaphores are disabled\n");
2996 return 0;
2997 }
2998
2999 ret = mutex_lock_interruptible(&dev->struct_mutex);
3000 if (ret)
3001 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003002 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003003
3004 if (IS_BROADWELL(dev)) {
3005 struct page *page;
3006 uint64_t *seqno;
3007
3008 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3009
3010 seqno = (uint64_t *)kmap_atomic(page);
3011 for_each_ring(ring, dev_priv, i) {
3012 uint64_t offset;
3013
3014 seq_printf(m, "%s\n", ring->name);
3015
3016 seq_puts(m, " Last signal:");
3017 for (j = 0; j < num_rings; j++) {
3018 offset = i * I915_NUM_RINGS + j;
3019 seq_printf(m, "0x%08llx (0x%02llx) ",
3020 seqno[offset], offset * 8);
3021 }
3022 seq_putc(m, '\n');
3023
3024 seq_puts(m, " Last wait: ");
3025 for (j = 0; j < num_rings; j++) {
3026 offset = i + (j * I915_NUM_RINGS);
3027 seq_printf(m, "0x%08llx (0x%02llx) ",
3028 seqno[offset], offset * 8);
3029 }
3030 seq_putc(m, '\n');
3031
3032 }
3033 kunmap_atomic(seqno);
3034 } else {
3035 seq_puts(m, " Last signal:");
3036 for_each_ring(ring, dev_priv, i)
3037 for (j = 0; j < num_rings; j++)
3038 seq_printf(m, "0x%08x\n",
3039 I915_READ(ring->semaphore.mbox.signal[j]));
3040 seq_putc(m, '\n');
3041 }
3042
3043 seq_puts(m, "\nSync seqno:\n");
3044 for_each_ring(ring, dev_priv, i) {
3045 for (j = 0; j < num_rings; j++) {
3046 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
3047 }
3048 seq_putc(m, '\n');
3049 }
3050 seq_putc(m, '\n');
3051
Paulo Zanoni03872062014-07-09 14:31:57 -03003052 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003053 mutex_unlock(&dev->struct_mutex);
3054 return 0;
3055}
3056
Daniel Vetter728e29d2014-06-25 22:01:53 +03003057static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3058{
3059 struct drm_info_node *node = (struct drm_info_node *) m->private;
3060 struct drm_device *dev = node->minor->dev;
3061 struct drm_i915_private *dev_priv = dev->dev_private;
3062 int i;
3063
3064 drm_modeset_lock_all(dev);
3065 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3066 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3067
3068 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02003069 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003070 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003071 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003072 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3073 seq_printf(m, " dpll_md: 0x%08x\n",
3074 pll->config.hw_state.dpll_md);
3075 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3076 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3077 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003078 }
3079 drm_modeset_unlock_all(dev);
3080
3081 return 0;
3082}
3083
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003084static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003085{
3086 int i;
3087 int ret;
3088 struct drm_info_node *node = (struct drm_info_node *) m->private;
3089 struct drm_device *dev = node->minor->dev;
3090 struct drm_i915_private *dev_priv = dev->dev_private;
3091
Arun Siluvery888b5992014-08-26 14:44:51 +01003092 ret = mutex_lock_interruptible(&dev->struct_mutex);
3093 if (ret)
3094 return ret;
3095
3096 intel_runtime_pm_get(dev_priv);
3097
Mika Kuoppala72253422014-10-07 17:21:26 +03003098 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
3099 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003100 u32 addr, mask, value, read;
3101 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003102
Mika Kuoppala72253422014-10-07 17:21:26 +03003103 addr = dev_priv->workarounds.reg[i].addr;
3104 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003105 value = dev_priv->workarounds.reg[i].value;
3106 read = I915_READ(addr);
3107 ok = (value & mask) == (read & mask);
3108 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
3109 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003110 }
3111
3112 intel_runtime_pm_put(dev_priv);
3113 mutex_unlock(&dev->struct_mutex);
3114
3115 return 0;
3116}
3117
Damien Lespiauc5511e42014-11-04 17:06:51 +00003118static int i915_ddb_info(struct seq_file *m, void *unused)
3119{
3120 struct drm_info_node *node = m->private;
3121 struct drm_device *dev = node->minor->dev;
3122 struct drm_i915_private *dev_priv = dev->dev_private;
3123 struct skl_ddb_allocation *ddb;
3124 struct skl_ddb_entry *entry;
3125 enum pipe pipe;
3126 int plane;
3127
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003128 if (INTEL_INFO(dev)->gen < 9)
3129 return 0;
3130
Damien Lespiauc5511e42014-11-04 17:06:51 +00003131 drm_modeset_lock_all(dev);
3132
3133 ddb = &dev_priv->wm.skl_hw.ddb;
3134
3135 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3136
3137 for_each_pipe(dev_priv, pipe) {
3138 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3139
Damien Lespiaudd740782015-02-28 14:54:08 +00003140 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003141 entry = &ddb->plane[pipe][plane];
3142 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3143 entry->start, entry->end,
3144 skl_ddb_entry_size(entry));
3145 }
3146
3147 entry = &ddb->cursor[pipe];
3148 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3149 entry->end, skl_ddb_entry_size(entry));
3150 }
3151
3152 drm_modeset_unlock_all(dev);
3153
3154 return 0;
3155}
3156
Vandana Kannana54746e2015-03-03 20:53:10 +05303157static void drrs_status_per_crtc(struct seq_file *m,
3158 struct drm_device *dev, struct intel_crtc *intel_crtc)
3159{
3160 struct intel_encoder *intel_encoder;
3161 struct drm_i915_private *dev_priv = dev->dev_private;
3162 struct i915_drrs *drrs = &dev_priv->drrs;
3163 int vrefresh = 0;
3164
3165 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3166 /* Encoder connected on this CRTC */
3167 switch (intel_encoder->type) {
3168 case INTEL_OUTPUT_EDP:
3169 seq_puts(m, "eDP:\n");
3170 break;
3171 case INTEL_OUTPUT_DSI:
3172 seq_puts(m, "DSI:\n");
3173 break;
3174 case INTEL_OUTPUT_HDMI:
3175 seq_puts(m, "HDMI:\n");
3176 break;
3177 case INTEL_OUTPUT_DISPLAYPORT:
3178 seq_puts(m, "DP:\n");
3179 break;
3180 default:
3181 seq_printf(m, "Other encoder (id=%d).\n",
3182 intel_encoder->type);
3183 return;
3184 }
3185 }
3186
3187 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3188 seq_puts(m, "\tVBT: DRRS_type: Static");
3189 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3190 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3191 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3192 seq_puts(m, "\tVBT: DRRS_type: None");
3193 else
3194 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3195
3196 seq_puts(m, "\n\n");
3197
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003198 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303199 struct intel_panel *panel;
3200
3201 mutex_lock(&drrs->mutex);
3202 /* DRRS Supported */
3203 seq_puts(m, "\tDRRS Supported: Yes\n");
3204
3205 /* disable_drrs() will make drrs->dp NULL */
3206 if (!drrs->dp) {
3207 seq_puts(m, "Idleness DRRS: Disabled");
3208 mutex_unlock(&drrs->mutex);
3209 return;
3210 }
3211
3212 panel = &drrs->dp->attached_connector->panel;
3213 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3214 drrs->busy_frontbuffer_bits);
3215
3216 seq_puts(m, "\n\t\t");
3217 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3218 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3219 vrefresh = panel->fixed_mode->vrefresh;
3220 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3221 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3222 vrefresh = panel->downclock_mode->vrefresh;
3223 } else {
3224 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3225 drrs->refresh_rate_type);
3226 mutex_unlock(&drrs->mutex);
3227 return;
3228 }
3229 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3230
3231 seq_puts(m, "\n\t\t");
3232 mutex_unlock(&drrs->mutex);
3233 } else {
3234 /* DRRS not supported. Print the VBT parameter*/
3235 seq_puts(m, "\tDRRS Supported : No");
3236 }
3237 seq_puts(m, "\n");
3238}
3239
3240static int i915_drrs_status(struct seq_file *m, void *unused)
3241{
3242 struct drm_info_node *node = m->private;
3243 struct drm_device *dev = node->minor->dev;
3244 struct intel_crtc *intel_crtc;
3245 int active_crtc_cnt = 0;
3246
3247 for_each_intel_crtc(dev, intel_crtc) {
3248 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3249
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003250 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303251 active_crtc_cnt++;
3252 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3253
3254 drrs_status_per_crtc(m, dev, intel_crtc);
3255 }
3256
3257 drm_modeset_unlock(&intel_crtc->base.mutex);
3258 }
3259
3260 if (!active_crtc_cnt)
3261 seq_puts(m, "No active crtc found\n");
3262
3263 return 0;
3264}
3265
Damien Lespiau07144422013-10-15 18:55:40 +01003266struct pipe_crc_info {
3267 const char *name;
3268 struct drm_device *dev;
3269 enum pipe pipe;
3270};
3271
Dave Airlie11bed952014-05-12 15:22:27 +10003272static int i915_dp_mst_info(struct seq_file *m, void *unused)
3273{
3274 struct drm_info_node *node = (struct drm_info_node *) m->private;
3275 struct drm_device *dev = node->minor->dev;
3276 struct drm_encoder *encoder;
3277 struct intel_encoder *intel_encoder;
3278 struct intel_digital_port *intel_dig_port;
3279 drm_modeset_lock_all(dev);
3280 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3281 intel_encoder = to_intel_encoder(encoder);
3282 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3283 continue;
3284 intel_dig_port = enc_to_dig_port(encoder);
3285 if (!intel_dig_port->dp.can_mst)
3286 continue;
3287
3288 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3289 }
3290 drm_modeset_unlock_all(dev);
3291 return 0;
3292}
3293
Damien Lespiau07144422013-10-15 18:55:40 +01003294static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003295{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003296 struct pipe_crc_info *info = inode->i_private;
3297 struct drm_i915_private *dev_priv = info->dev->dev_private;
3298 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3299
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003300 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3301 return -ENODEV;
3302
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003303 spin_lock_irq(&pipe_crc->lock);
3304
3305 if (pipe_crc->opened) {
3306 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003307 return -EBUSY; /* already open */
3308 }
3309
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003310 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003311 filep->private_data = inode->i_private;
3312
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003313 spin_unlock_irq(&pipe_crc->lock);
3314
Damien Lespiau07144422013-10-15 18:55:40 +01003315 return 0;
3316}
3317
3318static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3319{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003320 struct pipe_crc_info *info = inode->i_private;
3321 struct drm_i915_private *dev_priv = info->dev->dev_private;
3322 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3323
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003324 spin_lock_irq(&pipe_crc->lock);
3325 pipe_crc->opened = false;
3326 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003327
Damien Lespiau07144422013-10-15 18:55:40 +01003328 return 0;
3329}
3330
3331/* (6 fields, 8 chars each, space separated (5) + '\n') */
3332#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3333/* account for \'0' */
3334#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3335
3336static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3337{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003338 assert_spin_locked(&pipe_crc->lock);
3339 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3340 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003341}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003342
Damien Lespiau07144422013-10-15 18:55:40 +01003343static ssize_t
3344i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3345 loff_t *pos)
3346{
3347 struct pipe_crc_info *info = filep->private_data;
3348 struct drm_device *dev = info->dev;
3349 struct drm_i915_private *dev_priv = dev->dev_private;
3350 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3351 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003352 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003353 ssize_t bytes_read;
3354
3355 /*
3356 * Don't allow user space to provide buffers not big enough to hold
3357 * a line of data.
3358 */
3359 if (count < PIPE_CRC_LINE_LEN)
3360 return -EINVAL;
3361
3362 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3363 return 0;
3364
3365 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003366 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003367 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003368 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003369
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003370 if (filep->f_flags & O_NONBLOCK) {
3371 spin_unlock_irq(&pipe_crc->lock);
3372 return -EAGAIN;
3373 }
3374
3375 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3376 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3377 if (ret) {
3378 spin_unlock_irq(&pipe_crc->lock);
3379 return ret;
3380 }
Damien Lespiau07144422013-10-15 18:55:40 +01003381 }
3382
3383 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003384 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003385
Damien Lespiau07144422013-10-15 18:55:40 +01003386 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003387 while (n_entries > 0) {
3388 struct intel_pipe_crc_entry *entry =
3389 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003390 int ret;
3391
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003392 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3393 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3394 break;
3395
3396 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3397 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3398
Damien Lespiau07144422013-10-15 18:55:40 +01003399 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3400 "%8u %8x %8x %8x %8x %8x\n",
3401 entry->frame, entry->crc[0],
3402 entry->crc[1], entry->crc[2],
3403 entry->crc[3], entry->crc[4]);
3404
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003405 spin_unlock_irq(&pipe_crc->lock);
3406
3407 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003408 if (ret == PIPE_CRC_LINE_LEN)
3409 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003410
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003411 user_buf += PIPE_CRC_LINE_LEN;
3412 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003413
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003414 spin_lock_irq(&pipe_crc->lock);
3415 }
3416
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003417 spin_unlock_irq(&pipe_crc->lock);
3418
Damien Lespiau07144422013-10-15 18:55:40 +01003419 return bytes_read;
3420}
3421
3422static const struct file_operations i915_pipe_crc_fops = {
3423 .owner = THIS_MODULE,
3424 .open = i915_pipe_crc_open,
3425 .read = i915_pipe_crc_read,
3426 .release = i915_pipe_crc_release,
3427};
3428
3429static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3430 {
3431 .name = "i915_pipe_A_crc",
3432 .pipe = PIPE_A,
3433 },
3434 {
3435 .name = "i915_pipe_B_crc",
3436 .pipe = PIPE_B,
3437 },
3438 {
3439 .name = "i915_pipe_C_crc",
3440 .pipe = PIPE_C,
3441 },
3442};
3443
3444static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3445 enum pipe pipe)
3446{
3447 struct drm_device *dev = minor->dev;
3448 struct dentry *ent;
3449 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3450
3451 info->dev = dev;
3452 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3453 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003454 if (!ent)
3455 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003456
3457 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003458}
3459
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003460static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003461 "none",
3462 "plane1",
3463 "plane2",
3464 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003465 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003466 "TV",
3467 "DP-B",
3468 "DP-C",
3469 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003470 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003471};
3472
3473static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3474{
3475 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3476 return pipe_crc_sources[source];
3477}
3478
Damien Lespiaubd9db022013-10-15 18:55:36 +01003479static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003480{
3481 struct drm_device *dev = m->private;
3482 struct drm_i915_private *dev_priv = dev->dev_private;
3483 int i;
3484
3485 for (i = 0; i < I915_MAX_PIPES; i++)
3486 seq_printf(m, "%c %s\n", pipe_name(i),
3487 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3488
3489 return 0;
3490}
3491
Damien Lespiaubd9db022013-10-15 18:55:36 +01003492static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003493{
3494 struct drm_device *dev = inode->i_private;
3495
Damien Lespiaubd9db022013-10-15 18:55:36 +01003496 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003497}
3498
Daniel Vetter46a19182013-11-01 10:50:20 +01003499static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003500 uint32_t *val)
3501{
Daniel Vetter46a19182013-11-01 10:50:20 +01003502 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3503 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3504
3505 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003506 case INTEL_PIPE_CRC_SOURCE_PIPE:
3507 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3508 break;
3509 case INTEL_PIPE_CRC_SOURCE_NONE:
3510 *val = 0;
3511 break;
3512 default:
3513 return -EINVAL;
3514 }
3515
3516 return 0;
3517}
3518
Daniel Vetter46a19182013-11-01 10:50:20 +01003519static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3520 enum intel_pipe_crc_source *source)
3521{
3522 struct intel_encoder *encoder;
3523 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003524 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003525 int ret = 0;
3526
3527 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3528
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003529 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003530 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003531 if (!encoder->base.crtc)
3532 continue;
3533
3534 crtc = to_intel_crtc(encoder->base.crtc);
3535
3536 if (crtc->pipe != pipe)
3537 continue;
3538
3539 switch (encoder->type) {
3540 case INTEL_OUTPUT_TVOUT:
3541 *source = INTEL_PIPE_CRC_SOURCE_TV;
3542 break;
3543 case INTEL_OUTPUT_DISPLAYPORT:
3544 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003545 dig_port = enc_to_dig_port(&encoder->base);
3546 switch (dig_port->port) {
3547 case PORT_B:
3548 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3549 break;
3550 case PORT_C:
3551 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3552 break;
3553 case PORT_D:
3554 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3555 break;
3556 default:
3557 WARN(1, "nonexisting DP port %c\n",
3558 port_name(dig_port->port));
3559 break;
3560 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003561 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003562 default:
3563 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003564 }
3565 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003566 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003567
3568 return ret;
3569}
3570
3571static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3572 enum pipe pipe,
3573 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003574 uint32_t *val)
3575{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003576 struct drm_i915_private *dev_priv = dev->dev_private;
3577 bool need_stable_symbols = false;
3578
Daniel Vetter46a19182013-11-01 10:50:20 +01003579 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3580 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3581 if (ret)
3582 return ret;
3583 }
3584
3585 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003586 case INTEL_PIPE_CRC_SOURCE_PIPE:
3587 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3588 break;
3589 case INTEL_PIPE_CRC_SOURCE_DP_B:
3590 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003591 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003592 break;
3593 case INTEL_PIPE_CRC_SOURCE_DP_C:
3594 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003595 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003596 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003597 case INTEL_PIPE_CRC_SOURCE_DP_D:
3598 if (!IS_CHERRYVIEW(dev))
3599 return -EINVAL;
3600 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3601 need_stable_symbols = true;
3602 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003603 case INTEL_PIPE_CRC_SOURCE_NONE:
3604 *val = 0;
3605 break;
3606 default:
3607 return -EINVAL;
3608 }
3609
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003610 /*
3611 * When the pipe CRC tap point is after the transcoders we need
3612 * to tweak symbol-level features to produce a deterministic series of
3613 * symbols for a given frame. We need to reset those features only once
3614 * a frame (instead of every nth symbol):
3615 * - DC-balance: used to ensure a better clock recovery from the data
3616 * link (SDVO)
3617 * - DisplayPort scrambling: used for EMI reduction
3618 */
3619 if (need_stable_symbols) {
3620 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3621
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003622 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003623 switch (pipe) {
3624 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003625 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003626 break;
3627 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003628 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003629 break;
3630 case PIPE_C:
3631 tmp |= PIPE_C_SCRAMBLE_RESET;
3632 break;
3633 default:
3634 return -EINVAL;
3635 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003636 I915_WRITE(PORT_DFT2_G4X, tmp);
3637 }
3638
Daniel Vetter7ac01292013-10-18 16:37:06 +02003639 return 0;
3640}
3641
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003642static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003643 enum pipe pipe,
3644 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003645 uint32_t *val)
3646{
Daniel Vetter84093602013-11-01 10:50:21 +01003647 struct drm_i915_private *dev_priv = dev->dev_private;
3648 bool need_stable_symbols = false;
3649
Daniel Vetter46a19182013-11-01 10:50:20 +01003650 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3651 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3652 if (ret)
3653 return ret;
3654 }
3655
3656 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003657 case INTEL_PIPE_CRC_SOURCE_PIPE:
3658 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3659 break;
3660 case INTEL_PIPE_CRC_SOURCE_TV:
3661 if (!SUPPORTS_TV(dev))
3662 return -EINVAL;
3663 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3664 break;
3665 case INTEL_PIPE_CRC_SOURCE_DP_B:
3666 if (!IS_G4X(dev))
3667 return -EINVAL;
3668 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003669 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003670 break;
3671 case INTEL_PIPE_CRC_SOURCE_DP_C:
3672 if (!IS_G4X(dev))
3673 return -EINVAL;
3674 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003675 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003676 break;
3677 case INTEL_PIPE_CRC_SOURCE_DP_D:
3678 if (!IS_G4X(dev))
3679 return -EINVAL;
3680 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003681 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003682 break;
3683 case INTEL_PIPE_CRC_SOURCE_NONE:
3684 *val = 0;
3685 break;
3686 default:
3687 return -EINVAL;
3688 }
3689
Daniel Vetter84093602013-11-01 10:50:21 +01003690 /*
3691 * When the pipe CRC tap point is after the transcoders we need
3692 * to tweak symbol-level features to produce a deterministic series of
3693 * symbols for a given frame. We need to reset those features only once
3694 * a frame (instead of every nth symbol):
3695 * - DC-balance: used to ensure a better clock recovery from the data
3696 * link (SDVO)
3697 * - DisplayPort scrambling: used for EMI reduction
3698 */
3699 if (need_stable_symbols) {
3700 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3701
3702 WARN_ON(!IS_G4X(dev));
3703
3704 I915_WRITE(PORT_DFT_I9XX,
3705 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3706
3707 if (pipe == PIPE_A)
3708 tmp |= PIPE_A_SCRAMBLE_RESET;
3709 else
3710 tmp |= PIPE_B_SCRAMBLE_RESET;
3711
3712 I915_WRITE(PORT_DFT2_G4X, tmp);
3713 }
3714
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003715 return 0;
3716}
3717
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003718static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3719 enum pipe pipe)
3720{
3721 struct drm_i915_private *dev_priv = dev->dev_private;
3722 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3723
Ville Syrjäläeb736672014-12-09 21:28:28 +02003724 switch (pipe) {
3725 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003726 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003727 break;
3728 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003729 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003730 break;
3731 case PIPE_C:
3732 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3733 break;
3734 default:
3735 return;
3736 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003737 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3738 tmp &= ~DC_BALANCE_RESET_VLV;
3739 I915_WRITE(PORT_DFT2_G4X, tmp);
3740
3741}
3742
Daniel Vetter84093602013-11-01 10:50:21 +01003743static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3744 enum pipe pipe)
3745{
3746 struct drm_i915_private *dev_priv = dev->dev_private;
3747 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3748
3749 if (pipe == PIPE_A)
3750 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3751 else
3752 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3753 I915_WRITE(PORT_DFT2_G4X, tmp);
3754
3755 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3756 I915_WRITE(PORT_DFT_I9XX,
3757 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3758 }
3759}
3760
Daniel Vetter46a19182013-11-01 10:50:20 +01003761static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003762 uint32_t *val)
3763{
Daniel Vetter46a19182013-11-01 10:50:20 +01003764 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3765 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3766
3767 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003768 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3769 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3770 break;
3771 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3772 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3773 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003774 case INTEL_PIPE_CRC_SOURCE_PIPE:
3775 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3776 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003777 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003778 *val = 0;
3779 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003780 default:
3781 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003782 }
3783
3784 return 0;
3785}
3786
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003787static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003788{
3789 struct drm_i915_private *dev_priv = dev->dev_private;
3790 struct intel_crtc *crtc =
3791 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003792 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003793 struct drm_atomic_state *state;
3794 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003795
3796 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003797 state = drm_atomic_state_alloc(dev);
3798 if (!state) {
3799 ret = -ENOMEM;
3800 goto out;
3801 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003802
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003803 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
3804 pipe_config = intel_atomic_get_crtc_state(state, crtc);
3805 if (IS_ERR(pipe_config)) {
3806 ret = PTR_ERR(pipe_config);
3807 goto out;
3808 }
3809
3810 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003811 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003812 pipe_config->pch_pfit.enabled != enable)
3813 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003814
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003815 ret = drm_atomic_commit(state);
3816out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003817 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003818 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
3819 if (ret)
3820 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003821}
3822
3823static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3824 enum pipe pipe,
3825 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003826 uint32_t *val)
3827{
Daniel Vetter46a19182013-11-01 10:50:20 +01003828 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3829 *source = INTEL_PIPE_CRC_SOURCE_PF;
3830
3831 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003832 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3833 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3834 break;
3835 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3836 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3837 break;
3838 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003839 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003840 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003841
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003842 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3843 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003844 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003845 *val = 0;
3846 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003847 default:
3848 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003849 }
3850
3851 return 0;
3852}
3853
Daniel Vetter926321d2013-10-16 13:30:34 +02003854static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3855 enum intel_pipe_crc_source source)
3856{
3857 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003858 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003859 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3860 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003861 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003862 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003863
Damien Lespiaucc3da172013-10-15 18:55:31 +01003864 if (pipe_crc->source == source)
3865 return 0;
3866
Damien Lespiauae676fc2013-10-15 18:55:32 +01003867 /* forbid changing the source without going back to 'none' */
3868 if (pipe_crc->source && source)
3869 return -EINVAL;
3870
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003871 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3872 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3873 return -EIO;
3874 }
3875
Daniel Vetter52f843f2013-10-21 17:26:38 +02003876 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003877 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003878 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003879 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003880 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003881 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003882 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003883 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003884 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003885 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003886
3887 if (ret != 0)
3888 return ret;
3889
Damien Lespiau4b584362013-10-15 18:55:33 +01003890 /* none -> real source transition */
3891 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003892 struct intel_pipe_crc_entry *entries;
3893
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003894 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3895 pipe_name(pipe), pipe_crc_source_name(source));
3896
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003897 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3898 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003899 GFP_KERNEL);
3900 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003901 return -ENOMEM;
3902
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003903 /*
3904 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3905 * enabled and disabled dynamically based on package C states,
3906 * user space can't make reliable use of the CRCs, so let's just
3907 * completely disable it.
3908 */
3909 hsw_disable_ips(crtc);
3910
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003911 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003912 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003913 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003914 pipe_crc->head = 0;
3915 pipe_crc->tail = 0;
3916 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003917 }
3918
Damien Lespiaucc3da172013-10-15 18:55:31 +01003919 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003920
Daniel Vetter926321d2013-10-16 13:30:34 +02003921 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3922 POSTING_READ(PIPE_CRC_CTL(pipe));
3923
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003924 /* real source -> none transition */
3925 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003926 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003927 struct intel_crtc *crtc =
3928 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003929
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003930 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3931 pipe_name(pipe));
3932
Daniel Vettera33d7102014-06-06 08:22:08 +02003933 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003934 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02003935 intel_wait_for_vblank(dev, pipe);
3936 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003937
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003938 spin_lock_irq(&pipe_crc->lock);
3939 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003940 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003941 pipe_crc->head = 0;
3942 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003943 spin_unlock_irq(&pipe_crc->lock);
3944
3945 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003946
3947 if (IS_G4X(dev))
3948 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003949 else if (IS_VALLEYVIEW(dev))
3950 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003951 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003952 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003953
3954 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003955 }
3956
Daniel Vetter926321d2013-10-16 13:30:34 +02003957 return 0;
3958}
3959
3960/*
3961 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003962 * command: wsp* object wsp+ name wsp+ source wsp*
3963 * object: 'pipe'
3964 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003965 * source: (none | plane1 | plane2 | pf)
3966 * wsp: (#0x20 | #0x9 | #0xA)+
3967 *
3968 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003969 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3970 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003971 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003972static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003973{
3974 int n_words = 0;
3975
3976 while (*buf) {
3977 char *end;
3978
3979 /* skip leading white space */
3980 buf = skip_spaces(buf);
3981 if (!*buf)
3982 break; /* end of buffer */
3983
3984 /* find end of word */
3985 for (end = buf; *end && !isspace(*end); end++)
3986 ;
3987
3988 if (n_words == max_words) {
3989 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3990 max_words);
3991 return -EINVAL; /* ran out of words[] before bytes */
3992 }
3993
3994 if (*end)
3995 *end++ = '\0';
3996 words[n_words++] = buf;
3997 buf = end;
3998 }
3999
4000 return n_words;
4001}
4002
Damien Lespiaub94dec82013-10-15 18:55:35 +01004003enum intel_pipe_crc_object {
4004 PIPE_CRC_OBJECT_PIPE,
4005};
4006
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004007static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004008 "pipe",
4009};
4010
4011static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004012display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004013{
4014 int i;
4015
4016 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4017 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004018 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004019 return 0;
4020 }
4021
4022 return -EINVAL;
4023}
4024
Damien Lespiaubd9db022013-10-15 18:55:36 +01004025static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004026{
4027 const char name = buf[0];
4028
4029 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4030 return -EINVAL;
4031
4032 *pipe = name - 'A';
4033
4034 return 0;
4035}
4036
4037static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004038display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004039{
4040 int i;
4041
4042 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4043 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004044 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004045 return 0;
4046 }
4047
4048 return -EINVAL;
4049}
4050
Damien Lespiaubd9db022013-10-15 18:55:36 +01004051static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004052{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004053#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004054 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004055 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004056 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004057 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004058 enum intel_pipe_crc_source source;
4059
Damien Lespiaubd9db022013-10-15 18:55:36 +01004060 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004061 if (n_words != N_WORDS) {
4062 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4063 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004064 return -EINVAL;
4065 }
4066
Damien Lespiaubd9db022013-10-15 18:55:36 +01004067 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004068 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004069 return -EINVAL;
4070 }
4071
Damien Lespiaubd9db022013-10-15 18:55:36 +01004072 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004073 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4074 return -EINVAL;
4075 }
4076
Damien Lespiaubd9db022013-10-15 18:55:36 +01004077 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004078 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004079 return -EINVAL;
4080 }
4081
4082 return pipe_crc_set_source(dev, pipe, source);
4083}
4084
Damien Lespiaubd9db022013-10-15 18:55:36 +01004085static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4086 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004087{
4088 struct seq_file *m = file->private_data;
4089 struct drm_device *dev = m->private;
4090 char *tmpbuf;
4091 int ret;
4092
4093 if (len == 0)
4094 return 0;
4095
4096 if (len > PAGE_SIZE - 1) {
4097 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4098 PAGE_SIZE);
4099 return -E2BIG;
4100 }
4101
4102 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4103 if (!tmpbuf)
4104 return -ENOMEM;
4105
4106 if (copy_from_user(tmpbuf, ubuf, len)) {
4107 ret = -EFAULT;
4108 goto out;
4109 }
4110 tmpbuf[len] = '\0';
4111
Damien Lespiaubd9db022013-10-15 18:55:36 +01004112 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004113
4114out:
4115 kfree(tmpbuf);
4116 if (ret < 0)
4117 return ret;
4118
4119 *offp += len;
4120 return len;
4121}
4122
Damien Lespiaubd9db022013-10-15 18:55:36 +01004123static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004124 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004125 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004126 .read = seq_read,
4127 .llseek = seq_lseek,
4128 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004129 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004130};
4131
Todd Previteeb3394fa2015-04-18 00:04:19 -07004132static ssize_t i915_displayport_test_active_write(struct file *file,
4133 const char __user *ubuf,
4134 size_t len, loff_t *offp)
4135{
4136 char *input_buffer;
4137 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004138 struct drm_device *dev;
4139 struct drm_connector *connector;
4140 struct list_head *connector_list;
4141 struct intel_dp *intel_dp;
4142 int val = 0;
4143
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304144 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004145
Todd Previteeb3394fa2015-04-18 00:04:19 -07004146 connector_list = &dev->mode_config.connector_list;
4147
4148 if (len == 0)
4149 return 0;
4150
4151 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4152 if (!input_buffer)
4153 return -ENOMEM;
4154
4155 if (copy_from_user(input_buffer, ubuf, len)) {
4156 status = -EFAULT;
4157 goto out;
4158 }
4159
4160 input_buffer[len] = '\0';
4161 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4162
4163 list_for_each_entry(connector, connector_list, head) {
4164
4165 if (connector->connector_type !=
4166 DRM_MODE_CONNECTOR_DisplayPort)
4167 continue;
4168
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304169 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004170 connector->encoder != NULL) {
4171 intel_dp = enc_to_intel_dp(connector->encoder);
4172 status = kstrtoint(input_buffer, 10, &val);
4173 if (status < 0)
4174 goto out;
4175 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4176 /* To prevent erroneous activation of the compliance
4177 * testing code, only accept an actual value of 1 here
4178 */
4179 if (val == 1)
4180 intel_dp->compliance_test_active = 1;
4181 else
4182 intel_dp->compliance_test_active = 0;
4183 }
4184 }
4185out:
4186 kfree(input_buffer);
4187 if (status < 0)
4188 return status;
4189
4190 *offp += len;
4191 return len;
4192}
4193
4194static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4195{
4196 struct drm_device *dev = m->private;
4197 struct drm_connector *connector;
4198 struct list_head *connector_list = &dev->mode_config.connector_list;
4199 struct intel_dp *intel_dp;
4200
Todd Previteeb3394fa2015-04-18 00:04:19 -07004201 list_for_each_entry(connector, connector_list, head) {
4202
4203 if (connector->connector_type !=
4204 DRM_MODE_CONNECTOR_DisplayPort)
4205 continue;
4206
4207 if (connector->status == connector_status_connected &&
4208 connector->encoder != NULL) {
4209 intel_dp = enc_to_intel_dp(connector->encoder);
4210 if (intel_dp->compliance_test_active)
4211 seq_puts(m, "1");
4212 else
4213 seq_puts(m, "0");
4214 } else
4215 seq_puts(m, "0");
4216 }
4217
4218 return 0;
4219}
4220
4221static int i915_displayport_test_active_open(struct inode *inode,
4222 struct file *file)
4223{
4224 struct drm_device *dev = inode->i_private;
4225
4226 return single_open(file, i915_displayport_test_active_show, dev);
4227}
4228
4229static const struct file_operations i915_displayport_test_active_fops = {
4230 .owner = THIS_MODULE,
4231 .open = i915_displayport_test_active_open,
4232 .read = seq_read,
4233 .llseek = seq_lseek,
4234 .release = single_release,
4235 .write = i915_displayport_test_active_write
4236};
4237
4238static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4239{
4240 struct drm_device *dev = m->private;
4241 struct drm_connector *connector;
4242 struct list_head *connector_list = &dev->mode_config.connector_list;
4243 struct intel_dp *intel_dp;
4244
Todd Previteeb3394fa2015-04-18 00:04:19 -07004245 list_for_each_entry(connector, connector_list, head) {
4246
4247 if (connector->connector_type !=
4248 DRM_MODE_CONNECTOR_DisplayPort)
4249 continue;
4250
4251 if (connector->status == connector_status_connected &&
4252 connector->encoder != NULL) {
4253 intel_dp = enc_to_intel_dp(connector->encoder);
4254 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4255 } else
4256 seq_puts(m, "0");
4257 }
4258
4259 return 0;
4260}
4261static int i915_displayport_test_data_open(struct inode *inode,
4262 struct file *file)
4263{
4264 struct drm_device *dev = inode->i_private;
4265
4266 return single_open(file, i915_displayport_test_data_show, dev);
4267}
4268
4269static const struct file_operations i915_displayport_test_data_fops = {
4270 .owner = THIS_MODULE,
4271 .open = i915_displayport_test_data_open,
4272 .read = seq_read,
4273 .llseek = seq_lseek,
4274 .release = single_release
4275};
4276
4277static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4278{
4279 struct drm_device *dev = m->private;
4280 struct drm_connector *connector;
4281 struct list_head *connector_list = &dev->mode_config.connector_list;
4282 struct intel_dp *intel_dp;
4283
Todd Previteeb3394fa2015-04-18 00:04:19 -07004284 list_for_each_entry(connector, connector_list, head) {
4285
4286 if (connector->connector_type !=
4287 DRM_MODE_CONNECTOR_DisplayPort)
4288 continue;
4289
4290 if (connector->status == connector_status_connected &&
4291 connector->encoder != NULL) {
4292 intel_dp = enc_to_intel_dp(connector->encoder);
4293 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4294 } else
4295 seq_puts(m, "0");
4296 }
4297
4298 return 0;
4299}
4300
4301static int i915_displayport_test_type_open(struct inode *inode,
4302 struct file *file)
4303{
4304 struct drm_device *dev = inode->i_private;
4305
4306 return single_open(file, i915_displayport_test_type_show, dev);
4307}
4308
4309static const struct file_operations i915_displayport_test_type_fops = {
4310 .owner = THIS_MODULE,
4311 .open = i915_displayport_test_type_open,
4312 .read = seq_read,
4313 .llseek = seq_lseek,
4314 .release = single_release
4315};
4316
Damien Lespiau97e94b22014-11-04 17:06:50 +00004317static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004318{
4319 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004320 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004321 int num_levels;
4322
4323 if (IS_CHERRYVIEW(dev))
4324 num_levels = 3;
4325 else if (IS_VALLEYVIEW(dev))
4326 num_levels = 1;
4327 else
4328 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004329
4330 drm_modeset_lock_all(dev);
4331
4332 for (level = 0; level < num_levels; level++) {
4333 unsigned int latency = wm[level];
4334
Damien Lespiau97e94b22014-11-04 17:06:50 +00004335 /*
4336 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004337 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004338 */
Ville Syrjäläde38b952015-06-24 22:00:09 +03004339 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004340 latency *= 10;
4341 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004342 latency *= 5;
4343
4344 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004345 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004346 }
4347
4348 drm_modeset_unlock_all(dev);
4349}
4350
4351static int pri_wm_latency_show(struct seq_file *m, void *data)
4352{
4353 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004354 struct drm_i915_private *dev_priv = dev->dev_private;
4355 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004356
Damien Lespiau97e94b22014-11-04 17:06:50 +00004357 if (INTEL_INFO(dev)->gen >= 9)
4358 latencies = dev_priv->wm.skl_latency;
4359 else
4360 latencies = to_i915(dev)->wm.pri_latency;
4361
4362 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004363
4364 return 0;
4365}
4366
4367static int spr_wm_latency_show(struct seq_file *m, void *data)
4368{
4369 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004370 struct drm_i915_private *dev_priv = dev->dev_private;
4371 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004372
Damien Lespiau97e94b22014-11-04 17:06:50 +00004373 if (INTEL_INFO(dev)->gen >= 9)
4374 latencies = dev_priv->wm.skl_latency;
4375 else
4376 latencies = to_i915(dev)->wm.spr_latency;
4377
4378 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004379
4380 return 0;
4381}
4382
4383static int cur_wm_latency_show(struct seq_file *m, void *data)
4384{
4385 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004386 struct drm_i915_private *dev_priv = dev->dev_private;
4387 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004388
Damien Lespiau97e94b22014-11-04 17:06:50 +00004389 if (INTEL_INFO(dev)->gen >= 9)
4390 latencies = dev_priv->wm.skl_latency;
4391 else
4392 latencies = to_i915(dev)->wm.cur_latency;
4393
4394 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004395
4396 return 0;
4397}
4398
4399static int pri_wm_latency_open(struct inode *inode, struct file *file)
4400{
4401 struct drm_device *dev = inode->i_private;
4402
Ville Syrjäläde38b952015-06-24 22:00:09 +03004403 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004404 return -ENODEV;
4405
4406 return single_open(file, pri_wm_latency_show, dev);
4407}
4408
4409static int spr_wm_latency_open(struct inode *inode, struct file *file)
4410{
4411 struct drm_device *dev = inode->i_private;
4412
Sonika Jindal9ad02572014-07-21 15:23:39 +05304413 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004414 return -ENODEV;
4415
4416 return single_open(file, spr_wm_latency_show, dev);
4417}
4418
4419static int cur_wm_latency_open(struct inode *inode, struct file *file)
4420{
4421 struct drm_device *dev = inode->i_private;
4422
Sonika Jindal9ad02572014-07-21 15:23:39 +05304423 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004424 return -ENODEV;
4425
4426 return single_open(file, cur_wm_latency_show, dev);
4427}
4428
4429static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004430 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004431{
4432 struct seq_file *m = file->private_data;
4433 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004434 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004435 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004436 int level;
4437 int ret;
4438 char tmp[32];
4439
Ville Syrjäläde38b952015-06-24 22:00:09 +03004440 if (IS_CHERRYVIEW(dev))
4441 num_levels = 3;
4442 else if (IS_VALLEYVIEW(dev))
4443 num_levels = 1;
4444 else
4445 num_levels = ilk_wm_max_level(dev) + 1;
4446
Ville Syrjälä369a1342014-01-22 14:36:08 +02004447 if (len >= sizeof(tmp))
4448 return -EINVAL;
4449
4450 if (copy_from_user(tmp, ubuf, len))
4451 return -EFAULT;
4452
4453 tmp[len] = '\0';
4454
Damien Lespiau97e94b22014-11-04 17:06:50 +00004455 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4456 &new[0], &new[1], &new[2], &new[3],
4457 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004458 if (ret != num_levels)
4459 return -EINVAL;
4460
4461 drm_modeset_lock_all(dev);
4462
4463 for (level = 0; level < num_levels; level++)
4464 wm[level] = new[level];
4465
4466 drm_modeset_unlock_all(dev);
4467
4468 return len;
4469}
4470
4471
4472static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4473 size_t len, loff_t *offp)
4474{
4475 struct seq_file *m = file->private_data;
4476 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004477 struct drm_i915_private *dev_priv = dev->dev_private;
4478 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004479
Damien Lespiau97e94b22014-11-04 17:06:50 +00004480 if (INTEL_INFO(dev)->gen >= 9)
4481 latencies = dev_priv->wm.skl_latency;
4482 else
4483 latencies = to_i915(dev)->wm.pri_latency;
4484
4485 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004486}
4487
4488static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4489 size_t len, loff_t *offp)
4490{
4491 struct seq_file *m = file->private_data;
4492 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004493 struct drm_i915_private *dev_priv = dev->dev_private;
4494 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004495
Damien Lespiau97e94b22014-11-04 17:06:50 +00004496 if (INTEL_INFO(dev)->gen >= 9)
4497 latencies = dev_priv->wm.skl_latency;
4498 else
4499 latencies = to_i915(dev)->wm.spr_latency;
4500
4501 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004502}
4503
4504static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4505 size_t len, loff_t *offp)
4506{
4507 struct seq_file *m = file->private_data;
4508 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004509 struct drm_i915_private *dev_priv = dev->dev_private;
4510 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004511
Damien Lespiau97e94b22014-11-04 17:06:50 +00004512 if (INTEL_INFO(dev)->gen >= 9)
4513 latencies = dev_priv->wm.skl_latency;
4514 else
4515 latencies = to_i915(dev)->wm.cur_latency;
4516
4517 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004518}
4519
4520static const struct file_operations i915_pri_wm_latency_fops = {
4521 .owner = THIS_MODULE,
4522 .open = pri_wm_latency_open,
4523 .read = seq_read,
4524 .llseek = seq_lseek,
4525 .release = single_release,
4526 .write = pri_wm_latency_write
4527};
4528
4529static const struct file_operations i915_spr_wm_latency_fops = {
4530 .owner = THIS_MODULE,
4531 .open = spr_wm_latency_open,
4532 .read = seq_read,
4533 .llseek = seq_lseek,
4534 .release = single_release,
4535 .write = spr_wm_latency_write
4536};
4537
4538static const struct file_operations i915_cur_wm_latency_fops = {
4539 .owner = THIS_MODULE,
4540 .open = cur_wm_latency_open,
4541 .read = seq_read,
4542 .llseek = seq_lseek,
4543 .release = single_release,
4544 .write = cur_wm_latency_write
4545};
4546
Kees Cook647416f2013-03-10 14:10:06 -07004547static int
4548i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004549{
Kees Cook647416f2013-03-10 14:10:06 -07004550 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004551 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004552
Kees Cook647416f2013-03-10 14:10:06 -07004553 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004554
Kees Cook647416f2013-03-10 14:10:06 -07004555 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004556}
4557
Kees Cook647416f2013-03-10 14:10:06 -07004558static int
4559i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004560{
Kees Cook647416f2013-03-10 14:10:06 -07004561 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004562 struct drm_i915_private *dev_priv = dev->dev_private;
4563
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004564 /*
4565 * There is no safeguard against this debugfs entry colliding
4566 * with the hangcheck calling same i915_handle_error() in
4567 * parallel, causing an explosion. For now we assume that the
4568 * test harness is responsible enough not to inject gpu hangs
4569 * while it is writing to 'i915_wedged'
4570 */
4571
4572 if (i915_reset_in_progress(&dev_priv->gpu_error))
4573 return -EAGAIN;
4574
Imre Deakd46c0512014-04-14 20:24:27 +03004575 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004576
Mika Kuoppala58174462014-02-25 17:11:26 +02004577 i915_handle_error(dev, val,
4578 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004579
4580 intel_runtime_pm_put(dev_priv);
4581
Kees Cook647416f2013-03-10 14:10:06 -07004582 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004583}
4584
Kees Cook647416f2013-03-10 14:10:06 -07004585DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4586 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004587 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004588
Kees Cook647416f2013-03-10 14:10:06 -07004589static int
4590i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004591{
Kees Cook647416f2013-03-10 14:10:06 -07004592 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004593 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004594
Kees Cook647416f2013-03-10 14:10:06 -07004595 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004596
Kees Cook647416f2013-03-10 14:10:06 -07004597 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004598}
4599
Kees Cook647416f2013-03-10 14:10:06 -07004600static int
4601i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004602{
Kees Cook647416f2013-03-10 14:10:06 -07004603 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004604 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004605 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004606
Kees Cook647416f2013-03-10 14:10:06 -07004607 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004608
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004609 ret = mutex_lock_interruptible(&dev->struct_mutex);
4610 if (ret)
4611 return ret;
4612
Daniel Vetter99584db2012-11-14 17:14:04 +01004613 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004614 mutex_unlock(&dev->struct_mutex);
4615
Kees Cook647416f2013-03-10 14:10:06 -07004616 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004617}
4618
Kees Cook647416f2013-03-10 14:10:06 -07004619DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4620 i915_ring_stop_get, i915_ring_stop_set,
4621 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004622
Chris Wilson094f9a52013-09-25 17:34:55 +01004623static int
4624i915_ring_missed_irq_get(void *data, u64 *val)
4625{
4626 struct drm_device *dev = data;
4627 struct drm_i915_private *dev_priv = dev->dev_private;
4628
4629 *val = dev_priv->gpu_error.missed_irq_rings;
4630 return 0;
4631}
4632
4633static int
4634i915_ring_missed_irq_set(void *data, u64 val)
4635{
4636 struct drm_device *dev = data;
4637 struct drm_i915_private *dev_priv = dev->dev_private;
4638 int ret;
4639
4640 /* Lock against concurrent debugfs callers */
4641 ret = mutex_lock_interruptible(&dev->struct_mutex);
4642 if (ret)
4643 return ret;
4644 dev_priv->gpu_error.missed_irq_rings = val;
4645 mutex_unlock(&dev->struct_mutex);
4646
4647 return 0;
4648}
4649
4650DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4651 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4652 "0x%08llx\n");
4653
4654static int
4655i915_ring_test_irq_get(void *data, u64 *val)
4656{
4657 struct drm_device *dev = data;
4658 struct drm_i915_private *dev_priv = dev->dev_private;
4659
4660 *val = dev_priv->gpu_error.test_irq_rings;
4661
4662 return 0;
4663}
4664
4665static int
4666i915_ring_test_irq_set(void *data, u64 val)
4667{
4668 struct drm_device *dev = data;
4669 struct drm_i915_private *dev_priv = dev->dev_private;
4670 int ret;
4671
4672 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4673
4674 /* Lock against concurrent debugfs callers */
4675 ret = mutex_lock_interruptible(&dev->struct_mutex);
4676 if (ret)
4677 return ret;
4678
4679 dev_priv->gpu_error.test_irq_rings = val;
4680 mutex_unlock(&dev->struct_mutex);
4681
4682 return 0;
4683}
4684
4685DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4686 i915_ring_test_irq_get, i915_ring_test_irq_set,
4687 "0x%08llx\n");
4688
Chris Wilsondd624af2013-01-15 12:39:35 +00004689#define DROP_UNBOUND 0x1
4690#define DROP_BOUND 0x2
4691#define DROP_RETIRE 0x4
4692#define DROP_ACTIVE 0x8
4693#define DROP_ALL (DROP_UNBOUND | \
4694 DROP_BOUND | \
4695 DROP_RETIRE | \
4696 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004697static int
4698i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004699{
Kees Cook647416f2013-03-10 14:10:06 -07004700 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004701
Kees Cook647416f2013-03-10 14:10:06 -07004702 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004703}
4704
Kees Cook647416f2013-03-10 14:10:06 -07004705static int
4706i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004707{
Kees Cook647416f2013-03-10 14:10:06 -07004708 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004709 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004710 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004711
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004712 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004713
4714 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4715 * on ioctls on -EAGAIN. */
4716 ret = mutex_lock_interruptible(&dev->struct_mutex);
4717 if (ret)
4718 return ret;
4719
4720 if (val & DROP_ACTIVE) {
4721 ret = i915_gpu_idle(dev);
4722 if (ret)
4723 goto unlock;
4724 }
4725
4726 if (val & (DROP_RETIRE | DROP_ACTIVE))
4727 i915_gem_retire_requests(dev);
4728
Chris Wilson21ab4e72014-09-09 11:16:08 +01004729 if (val & DROP_BOUND)
4730 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004731
Chris Wilson21ab4e72014-09-09 11:16:08 +01004732 if (val & DROP_UNBOUND)
4733 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004734
4735unlock:
4736 mutex_unlock(&dev->struct_mutex);
4737
Kees Cook647416f2013-03-10 14:10:06 -07004738 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004739}
4740
Kees Cook647416f2013-03-10 14:10:06 -07004741DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4742 i915_drop_caches_get, i915_drop_caches_set,
4743 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004744
Kees Cook647416f2013-03-10 14:10:06 -07004745static int
4746i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004747{
Kees Cook647416f2013-03-10 14:10:06 -07004748 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004749 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004750 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004751
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004752 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004753 return -ENODEV;
4754
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004755 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4756
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004757 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004758 if (ret)
4759 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004760
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004761 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004762 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004763
Kees Cook647416f2013-03-10 14:10:06 -07004764 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004765}
4766
Kees Cook647416f2013-03-10 14:10:06 -07004767static int
4768i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004769{
Kees Cook647416f2013-03-10 14:10:06 -07004770 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004771 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304772 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004773 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004774
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004775 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004776 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004777
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004778 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4779
Kees Cook647416f2013-03-10 14:10:06 -07004780 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004781
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004782 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004783 if (ret)
4784 return ret;
4785
Jesse Barnes358733e2011-07-27 11:53:01 -07004786 /*
4787 * Turbo will still be enabled, but won't go above the set value.
4788 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304789 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004790
Akash Goelbc4d91f2015-02-26 16:09:47 +05304791 hw_max = dev_priv->rps.max_freq;
4792 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004793
Ben Widawskyb39fb292014-03-19 18:31:11 -07004794 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004795 mutex_unlock(&dev_priv->rps.hw_lock);
4796 return -EINVAL;
4797 }
4798
Ben Widawskyb39fb292014-03-19 18:31:11 -07004799 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004800
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004801 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004802
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004803 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004804
Kees Cook647416f2013-03-10 14:10:06 -07004805 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004806}
4807
Kees Cook647416f2013-03-10 14:10:06 -07004808DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4809 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004810 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004811
Kees Cook647416f2013-03-10 14:10:06 -07004812static int
4813i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004814{
Kees Cook647416f2013-03-10 14:10:06 -07004815 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004816 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004817 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004818
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004819 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004820 return -ENODEV;
4821
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004822 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4823
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004824 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004825 if (ret)
4826 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004827
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004828 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004829 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004830
Kees Cook647416f2013-03-10 14:10:06 -07004831 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004832}
4833
Kees Cook647416f2013-03-10 14:10:06 -07004834static int
4835i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004836{
Kees Cook647416f2013-03-10 14:10:06 -07004837 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004838 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304839 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004840 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004841
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004842 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004843 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004844
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004845 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4846
Kees Cook647416f2013-03-10 14:10:06 -07004847 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004848
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004849 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004850 if (ret)
4851 return ret;
4852
Jesse Barnes1523c312012-05-25 12:34:54 -07004853 /*
4854 * Turbo will still be enabled, but won't go below the set value.
4855 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304856 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004857
Akash Goelbc4d91f2015-02-26 16:09:47 +05304858 hw_max = dev_priv->rps.max_freq;
4859 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004860
Ben Widawskyb39fb292014-03-19 18:31:11 -07004861 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004862 mutex_unlock(&dev_priv->rps.hw_lock);
4863 return -EINVAL;
4864 }
4865
Ben Widawskyb39fb292014-03-19 18:31:11 -07004866 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004867
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004868 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004869
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004870 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004871
Kees Cook647416f2013-03-10 14:10:06 -07004872 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004873}
4874
Kees Cook647416f2013-03-10 14:10:06 -07004875DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4876 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004877 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004878
Kees Cook647416f2013-03-10 14:10:06 -07004879static int
4880i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004881{
Kees Cook647416f2013-03-10 14:10:06 -07004882 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004883 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004884 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004885 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004886
Daniel Vetter004777c2012-08-09 15:07:01 +02004887 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4888 return -ENODEV;
4889
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004890 ret = mutex_lock_interruptible(&dev->struct_mutex);
4891 if (ret)
4892 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004893 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004894
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004895 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004896
4897 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004898 mutex_unlock(&dev_priv->dev->struct_mutex);
4899
Kees Cook647416f2013-03-10 14:10:06 -07004900 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004901
Kees Cook647416f2013-03-10 14:10:06 -07004902 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004903}
4904
Kees Cook647416f2013-03-10 14:10:06 -07004905static int
4906i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004907{
Kees Cook647416f2013-03-10 14:10:06 -07004908 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004909 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004910 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004911
Daniel Vetter004777c2012-08-09 15:07:01 +02004912 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4913 return -ENODEV;
4914
Kees Cook647416f2013-03-10 14:10:06 -07004915 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004916 return -EINVAL;
4917
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004918 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004919 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004920
4921 /* Update the cache sharing policy here as well */
4922 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4923 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4924 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4925 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4926
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004927 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004928 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004929}
4930
Kees Cook647416f2013-03-10 14:10:06 -07004931DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4932 i915_cache_sharing_get, i915_cache_sharing_set,
4933 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004934
Jeff McGee5d395252015-04-03 18:13:17 -07004935struct sseu_dev_status {
4936 unsigned int slice_total;
4937 unsigned int subslice_total;
4938 unsigned int subslice_per_slice;
4939 unsigned int eu_total;
4940 unsigned int eu_per_subslice;
4941};
4942
4943static void cherryview_sseu_device_status(struct drm_device *dev,
4944 struct sseu_dev_status *stat)
4945{
4946 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004947 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004948 int ss;
4949 u32 sig1[ss_max], sig2[ss_max];
4950
4951 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4952 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4953 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4954 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4955
4956 for (ss = 0; ss < ss_max; ss++) {
4957 unsigned int eu_cnt;
4958
4959 if (sig1[ss] & CHV_SS_PG_ENABLE)
4960 /* skip disabled subslice */
4961 continue;
4962
4963 stat->slice_total = 1;
4964 stat->subslice_per_slice++;
4965 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4966 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4967 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4968 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
4969 stat->eu_total += eu_cnt;
4970 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
4971 }
4972 stat->subslice_total = stat->subslice_per_slice;
4973}
4974
4975static void gen9_sseu_device_status(struct drm_device *dev,
4976 struct sseu_dev_status *stat)
4977{
4978 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004979 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004980 int s, ss;
4981 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4982
Jeff McGee1c046bc2015-04-03 18:13:18 -07004983 /* BXT has a single slice and at most 3 subslices. */
4984 if (IS_BROXTON(dev)) {
4985 s_max = 1;
4986 ss_max = 3;
4987 }
4988
4989 for (s = 0; s < s_max; s++) {
4990 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4991 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4992 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4993 }
4994
Jeff McGee5d395252015-04-03 18:13:17 -07004995 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4996 GEN9_PGCTL_SSA_EU19_ACK |
4997 GEN9_PGCTL_SSA_EU210_ACK |
4998 GEN9_PGCTL_SSA_EU311_ACK;
4999 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5000 GEN9_PGCTL_SSB_EU19_ACK |
5001 GEN9_PGCTL_SSB_EU210_ACK |
5002 GEN9_PGCTL_SSB_EU311_ACK;
5003
5004 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005005 unsigned int ss_cnt = 0;
5006
Jeff McGee5d395252015-04-03 18:13:17 -07005007 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5008 /* skip disabled slice */
5009 continue;
5010
5011 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005012
5013 if (IS_SKYLAKE(dev))
5014 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5015
Jeff McGee5d395252015-04-03 18:13:17 -07005016 for (ss = 0; ss < ss_max; ss++) {
5017 unsigned int eu_cnt;
5018
Jeff McGee1c046bc2015-04-03 18:13:18 -07005019 if (IS_BROXTON(dev) &&
5020 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5021 /* skip disabled subslice */
5022 continue;
5023
5024 if (IS_BROXTON(dev))
5025 ss_cnt++;
5026
Jeff McGee5d395252015-04-03 18:13:17 -07005027 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5028 eu_mask[ss%2]);
5029 stat->eu_total += eu_cnt;
5030 stat->eu_per_subslice = max(stat->eu_per_subslice,
5031 eu_cnt);
5032 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005033
5034 stat->subslice_total += ss_cnt;
5035 stat->subslice_per_slice = max(stat->subslice_per_slice,
5036 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005037 }
5038}
5039
Jeff McGee38732182015-02-13 10:27:54 -06005040static int i915_sseu_status(struct seq_file *m, void *unused)
5041{
5042 struct drm_info_node *node = (struct drm_info_node *) m->private;
5043 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07005044 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005045
Jeff McGee5575f032015-02-27 10:22:32 -08005046 if ((INTEL_INFO(dev)->gen < 8) || IS_BROADWELL(dev))
Jeff McGee38732182015-02-13 10:27:54 -06005047 return -ENODEV;
5048
5049 seq_puts(m, "SSEU Device Info\n");
5050 seq_printf(m, " Available Slice Total: %u\n",
5051 INTEL_INFO(dev)->slice_total);
5052 seq_printf(m, " Available Subslice Total: %u\n",
5053 INTEL_INFO(dev)->subslice_total);
5054 seq_printf(m, " Available Subslice Per Slice: %u\n",
5055 INTEL_INFO(dev)->subslice_per_slice);
5056 seq_printf(m, " Available EU Total: %u\n",
5057 INTEL_INFO(dev)->eu_total);
5058 seq_printf(m, " Available EU Per Subslice: %u\n",
5059 INTEL_INFO(dev)->eu_per_subslice);
5060 seq_printf(m, " Has Slice Power Gating: %s\n",
5061 yesno(INTEL_INFO(dev)->has_slice_pg));
5062 seq_printf(m, " Has Subslice Power Gating: %s\n",
5063 yesno(INTEL_INFO(dev)->has_subslice_pg));
5064 seq_printf(m, " Has EU Power Gating: %s\n",
5065 yesno(INTEL_INFO(dev)->has_eu_pg));
5066
Jeff McGee7f992ab2015-02-13 10:27:55 -06005067 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005068 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08005069 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005070 cherryview_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005071 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005072 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005073 }
Jeff McGee5d395252015-04-03 18:13:17 -07005074 seq_printf(m, " Enabled Slice Total: %u\n",
5075 stat.slice_total);
5076 seq_printf(m, " Enabled Subslice Total: %u\n",
5077 stat.subslice_total);
5078 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5079 stat.subslice_per_slice);
5080 seq_printf(m, " Enabled EU Total: %u\n",
5081 stat.eu_total);
5082 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5083 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005084
Jeff McGee38732182015-02-13 10:27:54 -06005085 return 0;
5086}
5087
Ben Widawsky6d794d42011-04-25 11:25:56 -07005088static int i915_forcewake_open(struct inode *inode, struct file *file)
5089{
5090 struct drm_device *dev = inode->i_private;
5091 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005092
Daniel Vetter075edca2012-01-24 09:44:28 +01005093 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005094 return 0;
5095
Chris Wilson6daccb02015-01-16 11:34:35 +02005096 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005097 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005098
5099 return 0;
5100}
5101
Ben Widawskyc43b5632012-04-16 14:07:40 -07005102static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005103{
5104 struct drm_device *dev = inode->i_private;
5105 struct drm_i915_private *dev_priv = dev->dev_private;
5106
Daniel Vetter075edca2012-01-24 09:44:28 +01005107 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005108 return 0;
5109
Mika Kuoppala59bad942015-01-16 11:34:40 +02005110 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005111 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005112
5113 return 0;
5114}
5115
5116static const struct file_operations i915_forcewake_fops = {
5117 .owner = THIS_MODULE,
5118 .open = i915_forcewake_open,
5119 .release = i915_forcewake_release,
5120};
5121
5122static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5123{
5124 struct drm_device *dev = minor->dev;
5125 struct dentry *ent;
5126
5127 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005128 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005129 root, dev,
5130 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005131 if (!ent)
5132 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005133
Ben Widawsky8eb57292011-05-11 15:10:58 -07005134 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005135}
5136
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005137static int i915_debugfs_create(struct dentry *root,
5138 struct drm_minor *minor,
5139 const char *name,
5140 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005141{
5142 struct drm_device *dev = minor->dev;
5143 struct dentry *ent;
5144
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005145 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005146 S_IRUGO | S_IWUSR,
5147 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005148 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005149 if (!ent)
5150 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005151
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005152 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005153}
5154
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005155static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005156 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005157 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005158 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005159 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005160 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005161 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005162 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005163 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005164 {"i915_gem_request", i915_gem_request_info, 0},
5165 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005166 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005167 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005168 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5169 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5170 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005171 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005172 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005173 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005174 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005175 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305176 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005177 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005178 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005179 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005180 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005181 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005182 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005183 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005184 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005185 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005186 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005187 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005188 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005189 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005190 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005191 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005192 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005193 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005194 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005195 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005196 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005197 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005198 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005199 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005200 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005201 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005202 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005203 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005204 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005205 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305206 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005207 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005208};
Ben Gamari27c202a2009-07-01 22:26:52 -04005209#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005210
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005211static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005212 const char *name;
5213 const struct file_operations *fops;
5214} i915_debugfs_files[] = {
5215 {"i915_wedged", &i915_wedged_fops},
5216 {"i915_max_freq", &i915_max_freq_fops},
5217 {"i915_min_freq", &i915_min_freq_fops},
5218 {"i915_cache_sharing", &i915_cache_sharing_fops},
5219 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005220 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5221 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005222 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5223 {"i915_error_state", &i915_error_state_fops},
5224 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005225 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005226 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5227 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5228 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005229 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005230 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5231 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5232 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005233};
5234
Damien Lespiau07144422013-10-15 18:55:40 +01005235void intel_display_crc_init(struct drm_device *dev)
5236{
5237 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005238 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005239
Damien Lespiau055e3932014-08-18 13:49:10 +01005240 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005241 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005242
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005243 pipe_crc->opened = false;
5244 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005245 init_waitqueue_head(&pipe_crc->wq);
5246 }
5247}
5248
Ben Gamari27c202a2009-07-01 22:26:52 -04005249int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005250{
Daniel Vetter34b96742013-07-04 20:49:44 +02005251 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005252
Ben Widawsky6d794d42011-04-25 11:25:56 -07005253 ret = i915_forcewake_create(minor->debugfs_root, minor);
5254 if (ret)
5255 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005256
Damien Lespiau07144422013-10-15 18:55:40 +01005257 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5258 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5259 if (ret)
5260 return ret;
5261 }
5262
Daniel Vetter34b96742013-07-04 20:49:44 +02005263 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5264 ret = i915_debugfs_create(minor->debugfs_root, minor,
5265 i915_debugfs_files[i].name,
5266 i915_debugfs_files[i].fops);
5267 if (ret)
5268 return ret;
5269 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005270
Ben Gamari27c202a2009-07-01 22:26:52 -04005271 return drm_debugfs_create_files(i915_debugfs_list,
5272 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005273 minor->debugfs_root, minor);
5274}
5275
Ben Gamari27c202a2009-07-01 22:26:52 -04005276void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005277{
Daniel Vetter34b96742013-07-04 20:49:44 +02005278 int i;
5279
Ben Gamari27c202a2009-07-01 22:26:52 -04005280 drm_debugfs_remove_files(i915_debugfs_list,
5281 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005282
Ben Widawsky6d794d42011-04-25 11:25:56 -07005283 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5284 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005285
Daniel Vettere309a992013-10-16 22:55:51 +02005286 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005287 struct drm_info_list *info_list =
5288 (struct drm_info_list *)&i915_pipe_crc_data[i];
5289
5290 drm_debugfs_remove_files(info_list, 1, minor);
5291 }
5292
Daniel Vetter34b96742013-07-04 20:49:44 +02005293 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5294 struct drm_info_list *info_list =
5295 (struct drm_info_list *) i915_debugfs_files[i].fops;
5296
5297 drm_debugfs_remove_files(info_list, 1, minor);
5298 }
Ben Gamari20172632009-02-17 20:08:50 -05005299}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005300
5301struct dpcd_block {
5302 /* DPCD dump start address. */
5303 unsigned int offset;
5304 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5305 unsigned int end;
5306 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5307 size_t size;
5308 /* Only valid for eDP. */
5309 bool edp;
5310};
5311
5312static const struct dpcd_block i915_dpcd_debug[] = {
5313 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5314 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5315 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5316 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5317 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5318 { .offset = DP_SET_POWER },
5319 { .offset = DP_EDP_DPCD_REV },
5320 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5321 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5322 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5323};
5324
5325static int i915_dpcd_show(struct seq_file *m, void *data)
5326{
5327 struct drm_connector *connector = m->private;
5328 struct intel_dp *intel_dp =
5329 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5330 uint8_t buf[16];
5331 ssize_t err;
5332 int i;
5333
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005334 if (connector->status != connector_status_connected)
5335 return -ENODEV;
5336
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005337 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5338 const struct dpcd_block *b = &i915_dpcd_debug[i];
5339 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5340
5341 if (b->edp &&
5342 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5343 continue;
5344
5345 /* low tech for now */
5346 if (WARN_ON(size > sizeof(buf)))
5347 continue;
5348
5349 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5350 if (err <= 0) {
5351 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5352 size, b->offset, err);
5353 continue;
5354 }
5355
5356 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005357 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005358
5359 return 0;
5360}
5361
5362static int i915_dpcd_open(struct inode *inode, struct file *file)
5363{
5364 return single_open(file, i915_dpcd_show, inode->i_private);
5365}
5366
5367static const struct file_operations i915_dpcd_fops = {
5368 .owner = THIS_MODULE,
5369 .open = i915_dpcd_open,
5370 .read = seq_read,
5371 .llseek = seq_lseek,
5372 .release = single_release,
5373};
5374
5375/**
5376 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5377 * @connector: pointer to a registered drm_connector
5378 *
5379 * Cleanup will be done by drm_connector_unregister() through a call to
5380 * drm_debugfs_connector_remove().
5381 *
5382 * Returns 0 on success, negative error codes on error.
5383 */
5384int i915_debugfs_connector_add(struct drm_connector *connector)
5385{
5386 struct dentry *root = connector->debugfs_entry;
5387
5388 /* The connector must have been registered beforehands. */
5389 if (!root)
5390 return -ENODEV;
5391
5392 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5393 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5394 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5395 &i915_dpcd_fops);
5396
5397 return 0;
5398}