blob: 9839831dd6e58c0a418be2122c4a9187f0d6026a [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
Rasmus Villemoes2d05fa12015-09-28 23:08:50 +0200256 if (a->stolen->start < b->stolen->start)
257 return -1;
258 if (a->stolen->start > b->stolen->start)
259 return 1;
260 return 0;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100261}
262
263static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
264{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100265 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100266 struct drm_device *dev = node->minor->dev;
267 struct drm_i915_private *dev_priv = dev->dev_private;
268 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300269 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100270 LIST_HEAD(stolen);
271 int count, ret;
272
273 ret = mutex_lock_interruptible(&dev->struct_mutex);
274 if (ret)
275 return ret;
276
277 total_obj_size = total_gtt_size = count = 0;
278 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
279 if (obj->stolen == NULL)
280 continue;
281
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200282 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100283
284 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100285 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100286 count++;
287 }
288 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
289 if (obj->stolen == NULL)
290 continue;
291
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200292 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100293
294 total_obj_size += obj->base.size;
295 count++;
296 }
297 list_sort(NULL, &stolen, obj_rank_by_stolen);
298 seq_puts(m, "Stolen:\n");
299 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200300 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100301 seq_puts(m, " ");
302 describe_obj(m, obj);
303 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200304 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100305 }
306 mutex_unlock(&dev->struct_mutex);
307
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300308 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100309 count, total_obj_size, total_gtt_size);
310 return 0;
311}
312
Chris Wilson6299f992010-11-24 12:23:44 +0000313#define count_objects(list, member) do { \
314 list_for_each_entry(obj, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100315 size += i915_gem_obj_total_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000316 ++count; \
317 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700318 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000319 ++mappable_count; \
320 } \
321 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400322} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000323
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100324struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000325 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300326 unsigned long count;
327 u64 total, unbound;
328 u64 global, shared;
329 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100330};
331
332static int per_file_stats(int id, void *ptr, void *data)
333{
334 struct drm_i915_gem_object *obj = ptr;
335 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000336 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100337
338 stats->count++;
339 stats->total += obj->base.size;
340
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000341 if (obj->base.name || obj->base.dma_buf)
342 stats->shared += obj->base.size;
343
Chris Wilson6313c202014-03-19 13:45:45 +0000344 if (USES_FULL_PPGTT(obj->base.dev)) {
345 list_for_each_entry(vma, &obj->vma_list, vma_link) {
346 struct i915_hw_ppgtt *ppgtt;
347
348 if (!drm_mm_node_allocated(&vma->node))
349 continue;
350
351 if (i915_is_ggtt(vma->vm)) {
352 stats->global += obj->base.size;
353 continue;
354 }
355
356 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200357 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000358 continue;
359
John Harrison41c52412014-11-24 18:49:43 +0000360 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000361 stats->active += obj->base.size;
362 else
363 stats->inactive += obj->base.size;
364
365 return 0;
366 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100367 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000368 if (i915_gem_obj_ggtt_bound(obj)) {
369 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000370 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000371 stats->active += obj->base.size;
372 else
373 stats->inactive += obj->base.size;
374 return 0;
375 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100376 }
377
Chris Wilson6313c202014-03-19 13:45:45 +0000378 if (!list_empty(&obj->global_list))
379 stats->unbound += obj->base.size;
380
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100381 return 0;
382}
383
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100384#define print_file_stats(m, name, stats) do { \
385 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300386 seq_printf(m, "%s: %lu objects, %llu bytes (%llu active, %llu inactive, %llu global, %llu shared, %llu unbound)\n", \
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100387 name, \
388 stats.count, \
389 stats.total, \
390 stats.active, \
391 stats.inactive, \
392 stats.global, \
393 stats.shared, \
394 stats.unbound); \
395} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800396
397static void print_batch_pool_stats(struct seq_file *m,
398 struct drm_i915_private *dev_priv)
399{
400 struct drm_i915_gem_object *obj;
401 struct file_stats stats;
Chris Wilson06fbca72015-04-07 16:20:36 +0100402 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100403 int i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800404
405 memset(&stats, 0, sizeof(stats));
406
Chris Wilson06fbca72015-04-07 16:20:36 +0100407 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100408 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
409 list_for_each_entry(obj,
410 &ring->batch_pool.cache_list[j],
411 batch_pool_link)
412 per_file_stats(0, obj, &stats);
413 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100414 }
Brad Volkin493018d2014-12-11 12:13:08 -0800415
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100416 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800417}
418
Ben Widawskyca191b12013-07-31 17:00:14 -0700419#define count_vmas(list, member) do { \
420 list_for_each_entry(vma, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100421 size += i915_gem_obj_total_ggtt_size(vma->obj); \
Ben Widawskyca191b12013-07-31 17:00:14 -0700422 ++count; \
423 if (vma->obj->map_and_fenceable) { \
424 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
425 ++mappable_count; \
426 } \
427 } \
428} while (0)
429
430static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100431{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100432 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100433 struct drm_device *dev = node->minor->dev;
434 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200435 u32 count, mappable_count, purgeable_count;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300436 u64 size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000437 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700438 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100439 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700440 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100441 int ret;
442
443 ret = mutex_lock_interruptible(&dev->struct_mutex);
444 if (ret)
445 return ret;
446
Chris Wilson6299f992010-11-24 12:23:44 +0000447 seq_printf(m, "%u objects, %zu bytes\n",
448 dev_priv->mm.object_count,
449 dev_priv->mm.object_memory);
450
451 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700452 count_objects(&dev_priv->mm.bound_list, global_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300453 seq_printf(m, "%u [%u] objects, %llu [%llu] bytes in gtt\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000454 count, mappable_count, size, mappable_size);
455
456 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700457 count_vmas(&vm->active_list, mm_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300458 seq_printf(m, " %u [%u] active objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000459 count, mappable_count, size, mappable_size);
460
461 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700462 count_vmas(&vm->inactive_list, mm_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300463 seq_printf(m, " %u [%u] inactive objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000464 count, mappable_count, size, mappable_size);
465
Chris Wilsonb7abb712012-08-20 11:33:30 +0200466 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700467 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200468 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200469 if (obj->madv == I915_MADV_DONTNEED)
470 purgeable_size += obj->base.size, ++purgeable_count;
471 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300472 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
Chris Wilson6c085a72012-08-20 11:40:46 +0200473
Chris Wilson6299f992010-11-24 12:23:44 +0000474 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700475 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000476 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700477 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000478 ++count;
479 }
Chris Wilson30154652015-04-07 17:28:24 +0100480 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700481 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000482 ++mappable_count;
483 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200484 if (obj->madv == I915_MADV_DONTNEED) {
485 purgeable_size += obj->base.size;
486 ++purgeable_count;
487 }
Chris Wilson6299f992010-11-24 12:23:44 +0000488 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300489 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200490 purgeable_count, purgeable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300491 seq_printf(m, "%u pinned mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000492 mappable_count, mappable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300493 seq_printf(m, "%u fault mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000494 count, size);
495
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300496 seq_printf(m, "%llu [%llu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700497 dev_priv->gtt.base.total,
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300498 (u64)dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100499
Damien Lespiau267f0c92013-06-24 22:59:48 +0100500 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800501 print_batch_pool_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100502 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
503 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900504 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100505
506 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000507 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100508 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100509 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100510 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900511 /*
512 * Although we have a valid reference on file->pid, that does
513 * not guarantee that the task_struct who called get_pid() is
514 * still alive (e.g. get_pid(current) => fork() => exit()).
515 * Therefore, we need to protect this ->comm access using RCU.
516 */
517 rcu_read_lock();
518 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800519 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900520 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100521 }
522
Chris Wilson73aa8082010-09-30 11:46:12 +0100523 mutex_unlock(&dev->struct_mutex);
524
525 return 0;
526}
527
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100528static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000529{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100530 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000531 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100532 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000533 struct drm_i915_private *dev_priv = dev->dev_private;
534 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300535 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000536 int count, ret;
537
538 ret = mutex_lock_interruptible(&dev->struct_mutex);
539 if (ret)
540 return ret;
541
542 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700543 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800544 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100545 continue;
546
Damien Lespiau267f0c92013-06-24 22:59:48 +0100547 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000548 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100549 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000550 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100551 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000552 count++;
553 }
554
555 mutex_unlock(&dev->struct_mutex);
556
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300557 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000558 count, total_obj_size, total_gtt_size);
559
560 return 0;
561}
562
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100563static int i915_gem_pageflip_info(struct seq_file *m, void *data)
564{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100565 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100566 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100567 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100568 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200569 int ret;
570
571 ret = mutex_lock_interruptible(&dev->struct_mutex);
572 if (ret)
573 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100574
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100575 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800576 const char pipe = pipe_name(crtc->pipe);
577 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100578 struct intel_unpin_work *work;
579
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200580 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100581 work = crtc->unpin_work;
582 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800583 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100584 pipe, plane);
585 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100586 u32 addr;
587
Chris Wilsone7d841c2012-12-03 11:36:30 +0000588 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800589 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100590 pipe, plane);
591 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800592 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100593 pipe, plane);
594 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100595 if (work->flip_queued_req) {
596 struct intel_engine_cs *ring =
597 i915_gem_request_get_ring(work->flip_queued_req);
598
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200599 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 +0100600 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000601 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100602 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100603 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000604 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100605 } else
606 seq_printf(m, "Flip not associated with any ring\n");
607 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
608 work->flip_queued_vblank,
609 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100610 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100611 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100612 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100613 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100614 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000615 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100616
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100617 if (INTEL_INFO(dev)->gen >= 4)
618 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
619 else
620 addr = I915_READ(DSPADDR(crtc->plane));
621 seq_printf(m, "Current scanout address 0x%08x\n", addr);
622
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100623 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100624 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
625 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100626 }
627 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200628 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100629 }
630
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200631 mutex_unlock(&dev->struct_mutex);
632
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100633 return 0;
634}
635
Brad Volkin493018d2014-12-11 12:13:08 -0800636static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
637{
638 struct drm_info_node *node = m->private;
639 struct drm_device *dev = node->minor->dev;
640 struct drm_i915_private *dev_priv = dev->dev_private;
641 struct drm_i915_gem_object *obj;
Chris Wilson06fbca72015-04-07 16:20:36 +0100642 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100643 int total = 0;
644 int ret, i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800645
646 ret = mutex_lock_interruptible(&dev->struct_mutex);
647 if (ret)
648 return ret;
649
Chris Wilson06fbca72015-04-07 16:20:36 +0100650 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100651 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
652 int count;
653
654 count = 0;
655 list_for_each_entry(obj,
656 &ring->batch_pool.cache_list[j],
657 batch_pool_link)
658 count++;
659 seq_printf(m, "%s cache[%d]: %d objects\n",
660 ring->name, j, count);
661
662 list_for_each_entry(obj,
663 &ring->batch_pool.cache_list[j],
664 batch_pool_link) {
665 seq_puts(m, " ");
666 describe_obj(m, obj);
667 seq_putc(m, '\n');
668 }
669
670 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100671 }
Brad Volkin493018d2014-12-11 12:13:08 -0800672 }
673
Chris Wilson8d9d5742015-04-07 16:20:38 +0100674 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800675
676 mutex_unlock(&dev->struct_mutex);
677
678 return 0;
679}
680
Ben Gamari20172632009-02-17 20:08:50 -0500681static int i915_gem_request_info(struct seq_file *m, void *data)
682{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100683 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500684 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300685 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100686 struct intel_engine_cs *ring;
Daniel Vettereed29a52015-05-21 14:21:25 +0200687 struct drm_i915_gem_request *req;
Chris Wilson2d1070b2015-04-01 10:36:56 +0100688 int ret, any, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100689
690 ret = mutex_lock_interruptible(&dev->struct_mutex);
691 if (ret)
692 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500693
Chris Wilson2d1070b2015-04-01 10:36:56 +0100694 any = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100695 for_each_ring(ring, dev_priv, i) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100696 int count;
697
698 count = 0;
Daniel Vettereed29a52015-05-21 14:21:25 +0200699 list_for_each_entry(req, &ring->request_list, list)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100700 count++;
701 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100702 continue;
703
Chris Wilson2d1070b2015-04-01 10:36:56 +0100704 seq_printf(m, "%s requests: %d\n", ring->name, count);
Daniel Vettereed29a52015-05-21 14:21:25 +0200705 list_for_each_entry(req, &ring->request_list, list) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100706 struct task_struct *task;
707
708 rcu_read_lock();
709 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200710 if (req->pid)
711 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100712 seq_printf(m, " %x @ %d: %s [%d]\n",
Daniel Vettereed29a52015-05-21 14:21:25 +0200713 req->seqno,
714 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100715 task ? task->comm : "<unknown>",
716 task ? task->pid : -1);
717 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100718 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100719
720 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500721 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100722 mutex_unlock(&dev->struct_mutex);
723
Chris Wilson2d1070b2015-04-01 10:36:56 +0100724 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100725 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100726
Ben Gamari20172632009-02-17 20:08:50 -0500727 return 0;
728}
729
Chris Wilsonb2223492010-10-27 15:27:33 +0100730static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100731 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100732{
733 if (ring->get_seqno) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200734 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100735 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100736 }
737}
738
Ben Gamari20172632009-02-17 20:08:50 -0500739static int i915_gem_seqno_info(struct seq_file *m, void *data)
740{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100741 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500742 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300743 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100744 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000745 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100746
747 ret = mutex_lock_interruptible(&dev->struct_mutex);
748 if (ret)
749 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200750 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500751
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100752 for_each_ring(ring, dev_priv, i)
753 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100754
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200755 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100756 mutex_unlock(&dev->struct_mutex);
757
Ben Gamari20172632009-02-17 20:08:50 -0500758 return 0;
759}
760
761
762static int i915_interrupt_info(struct seq_file *m, void *data)
763{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100764 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500765 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300766 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100767 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800768 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100769
770 ret = mutex_lock_interruptible(&dev->struct_mutex);
771 if (ret)
772 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200773 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500774
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300775 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300776 seq_printf(m, "Master Interrupt Control:\t%08x\n",
777 I915_READ(GEN8_MASTER_IRQ));
778
779 seq_printf(m, "Display IER:\t%08x\n",
780 I915_READ(VLV_IER));
781 seq_printf(m, "Display IIR:\t%08x\n",
782 I915_READ(VLV_IIR));
783 seq_printf(m, "Display IIR_RW:\t%08x\n",
784 I915_READ(VLV_IIR_RW));
785 seq_printf(m, "Display IMR:\t%08x\n",
786 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100787 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300788 seq_printf(m, "Pipe %c stat:\t%08x\n",
789 pipe_name(pipe),
790 I915_READ(PIPESTAT(pipe)));
791
792 seq_printf(m, "Port hotplug:\t%08x\n",
793 I915_READ(PORT_HOTPLUG_EN));
794 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
795 I915_READ(VLV_DPFLIPSTAT));
796 seq_printf(m, "DPINVGTT:\t%08x\n",
797 I915_READ(DPINVGTT));
798
799 for (i = 0; i < 4; i++) {
800 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
801 i, I915_READ(GEN8_GT_IMR(i)));
802 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
803 i, I915_READ(GEN8_GT_IIR(i)));
804 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
805 i, I915_READ(GEN8_GT_IER(i)));
806 }
807
808 seq_printf(m, "PCU interrupt mask:\t%08x\n",
809 I915_READ(GEN8_PCU_IMR));
810 seq_printf(m, "PCU interrupt identity:\t%08x\n",
811 I915_READ(GEN8_PCU_IIR));
812 seq_printf(m, "PCU interrupt enable:\t%08x\n",
813 I915_READ(GEN8_PCU_IER));
814 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700815 seq_printf(m, "Master Interrupt Control:\t%08x\n",
816 I915_READ(GEN8_MASTER_IRQ));
817
818 for (i = 0; i < 4; i++) {
819 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
820 i, I915_READ(GEN8_GT_IMR(i)));
821 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
822 i, I915_READ(GEN8_GT_IIR(i)));
823 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
824 i, I915_READ(GEN8_GT_IER(i)));
825 }
826
Damien Lespiau055e3932014-08-18 13:49:10 +0100827 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200828 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300829 POWER_DOMAIN_PIPE(pipe))) {
830 seq_printf(m, "Pipe %c power disabled\n",
831 pipe_name(pipe));
832 continue;
833 }
Ben Widawskya123f152013-11-02 21:07:10 -0700834 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000835 pipe_name(pipe),
836 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700837 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000838 pipe_name(pipe),
839 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700840 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000841 pipe_name(pipe),
842 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700843 }
844
845 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
846 I915_READ(GEN8_DE_PORT_IMR));
847 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
848 I915_READ(GEN8_DE_PORT_IIR));
849 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
850 I915_READ(GEN8_DE_PORT_IER));
851
852 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
853 I915_READ(GEN8_DE_MISC_IMR));
854 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
855 I915_READ(GEN8_DE_MISC_IIR));
856 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
857 I915_READ(GEN8_DE_MISC_IER));
858
859 seq_printf(m, "PCU interrupt mask:\t%08x\n",
860 I915_READ(GEN8_PCU_IMR));
861 seq_printf(m, "PCU interrupt identity:\t%08x\n",
862 I915_READ(GEN8_PCU_IIR));
863 seq_printf(m, "PCU interrupt enable:\t%08x\n",
864 I915_READ(GEN8_PCU_IER));
865 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700866 seq_printf(m, "Display IER:\t%08x\n",
867 I915_READ(VLV_IER));
868 seq_printf(m, "Display IIR:\t%08x\n",
869 I915_READ(VLV_IIR));
870 seq_printf(m, "Display IIR_RW:\t%08x\n",
871 I915_READ(VLV_IIR_RW));
872 seq_printf(m, "Display IMR:\t%08x\n",
873 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100874 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700875 seq_printf(m, "Pipe %c stat:\t%08x\n",
876 pipe_name(pipe),
877 I915_READ(PIPESTAT(pipe)));
878
879 seq_printf(m, "Master IER:\t%08x\n",
880 I915_READ(VLV_MASTER_IER));
881
882 seq_printf(m, "Render IER:\t%08x\n",
883 I915_READ(GTIER));
884 seq_printf(m, "Render IIR:\t%08x\n",
885 I915_READ(GTIIR));
886 seq_printf(m, "Render IMR:\t%08x\n",
887 I915_READ(GTIMR));
888
889 seq_printf(m, "PM IER:\t\t%08x\n",
890 I915_READ(GEN6_PMIER));
891 seq_printf(m, "PM IIR:\t\t%08x\n",
892 I915_READ(GEN6_PMIIR));
893 seq_printf(m, "PM IMR:\t\t%08x\n",
894 I915_READ(GEN6_PMIMR));
895
896 seq_printf(m, "Port hotplug:\t%08x\n",
897 I915_READ(PORT_HOTPLUG_EN));
898 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
899 I915_READ(VLV_DPFLIPSTAT));
900 seq_printf(m, "DPINVGTT:\t%08x\n",
901 I915_READ(DPINVGTT));
902
903 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800904 seq_printf(m, "Interrupt enable: %08x\n",
905 I915_READ(IER));
906 seq_printf(m, "Interrupt identity: %08x\n",
907 I915_READ(IIR));
908 seq_printf(m, "Interrupt mask: %08x\n",
909 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100910 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800911 seq_printf(m, "Pipe %c stat: %08x\n",
912 pipe_name(pipe),
913 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800914 } else {
915 seq_printf(m, "North Display Interrupt enable: %08x\n",
916 I915_READ(DEIER));
917 seq_printf(m, "North Display Interrupt identity: %08x\n",
918 I915_READ(DEIIR));
919 seq_printf(m, "North Display Interrupt mask: %08x\n",
920 I915_READ(DEIMR));
921 seq_printf(m, "South Display Interrupt enable: %08x\n",
922 I915_READ(SDEIER));
923 seq_printf(m, "South Display Interrupt identity: %08x\n",
924 I915_READ(SDEIIR));
925 seq_printf(m, "South Display Interrupt mask: %08x\n",
926 I915_READ(SDEIMR));
927 seq_printf(m, "Graphics Interrupt enable: %08x\n",
928 I915_READ(GTIER));
929 seq_printf(m, "Graphics Interrupt identity: %08x\n",
930 I915_READ(GTIIR));
931 seq_printf(m, "Graphics Interrupt mask: %08x\n",
932 I915_READ(GTIMR));
933 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100934 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700935 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100936 seq_printf(m,
937 "Graphics Interrupt mask (%s): %08x\n",
938 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000939 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100940 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000941 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200942 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100943 mutex_unlock(&dev->struct_mutex);
944
Ben Gamari20172632009-02-17 20:08:50 -0500945 return 0;
946}
947
Chris Wilsona6172a82009-02-11 14:26:38 +0000948static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
949{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100950 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000951 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300952 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100953 int i, ret;
954
955 ret = mutex_lock_interruptible(&dev->struct_mutex);
956 if (ret)
957 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000958
959 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
960 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
961 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000962 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000963
Chris Wilson6c085a72012-08-20 11:40:46 +0200964 seq_printf(m, "Fence %d, pin count = %d, object = ",
965 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100966 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100967 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100968 else
Chris Wilson05394f32010-11-08 19:18:58 +0000969 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100970 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000971 }
972
Chris Wilson05394f32010-11-08 19:18:58 +0000973 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000974 return 0;
975}
976
Ben Gamari20172632009-02-17 20:08:50 -0500977static int i915_hws_info(struct seq_file *m, void *data)
978{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100979 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500980 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300981 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100982 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100983 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100984 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500985
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000986 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100987 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500988 if (hws == NULL)
989 return 0;
990
991 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
992 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
993 i * 4,
994 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
995 }
996 return 0;
997}
998
Daniel Vetterd5442302012-04-27 15:17:40 +0200999static ssize_t
1000i915_error_state_write(struct file *filp,
1001 const char __user *ubuf,
1002 size_t cnt,
1003 loff_t *ppos)
1004{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001005 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001006 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001007 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001008
1009 DRM_DEBUG_DRIVER("Resetting error state\n");
1010
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001011 ret = mutex_lock_interruptible(&dev->struct_mutex);
1012 if (ret)
1013 return ret;
1014
Daniel Vetterd5442302012-04-27 15:17:40 +02001015 i915_destroy_error_state(dev);
1016 mutex_unlock(&dev->struct_mutex);
1017
1018 return cnt;
1019}
1020
1021static int i915_error_state_open(struct inode *inode, struct file *file)
1022{
1023 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001024 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001025
1026 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1027 if (!error_priv)
1028 return -ENOMEM;
1029
1030 error_priv->dev = dev;
1031
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001032 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001033
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001034 file->private_data = error_priv;
1035
1036 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001037}
1038
1039static int i915_error_state_release(struct inode *inode, struct file *file)
1040{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001041 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001042
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001043 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001044 kfree(error_priv);
1045
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001046 return 0;
1047}
1048
1049static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1050 size_t count, loff_t *pos)
1051{
1052 struct i915_error_state_file_priv *error_priv = file->private_data;
1053 struct drm_i915_error_state_buf error_str;
1054 loff_t tmp_pos = 0;
1055 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001056 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001057
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001058 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001059 if (ret)
1060 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001061
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001062 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001063 if (ret)
1064 goto out;
1065
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001066 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1067 error_str.buf,
1068 error_str.bytes);
1069
1070 if (ret_count < 0)
1071 ret = ret_count;
1072 else
1073 *pos = error_str.start + ret_count;
1074out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001075 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001076 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001077}
1078
1079static const struct file_operations i915_error_state_fops = {
1080 .owner = THIS_MODULE,
1081 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001082 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001083 .write = i915_error_state_write,
1084 .llseek = default_llseek,
1085 .release = i915_error_state_release,
1086};
1087
Kees Cook647416f2013-03-10 14:10:06 -07001088static int
1089i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001090{
Kees Cook647416f2013-03-10 14:10:06 -07001091 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001092 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001093 int ret;
1094
1095 ret = mutex_lock_interruptible(&dev->struct_mutex);
1096 if (ret)
1097 return ret;
1098
Kees Cook647416f2013-03-10 14:10:06 -07001099 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001100 mutex_unlock(&dev->struct_mutex);
1101
Kees Cook647416f2013-03-10 14:10:06 -07001102 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001103}
1104
Kees Cook647416f2013-03-10 14:10:06 -07001105static int
1106i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001107{
Kees Cook647416f2013-03-10 14:10:06 -07001108 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001109 int ret;
1110
Mika Kuoppala40633212012-12-04 15:12:00 +02001111 ret = mutex_lock_interruptible(&dev->struct_mutex);
1112 if (ret)
1113 return ret;
1114
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001115 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001116 mutex_unlock(&dev->struct_mutex);
1117
Kees Cook647416f2013-03-10 14:10:06 -07001118 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001119}
1120
Kees Cook647416f2013-03-10 14:10:06 -07001121DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1122 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001123 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001124
Deepak Sadb4bd12014-03-31 11:30:02 +05301125static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001126{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001127 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001128 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001129 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001130 int ret = 0;
1131
1132 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001133
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001134 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1135
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001136 if (IS_GEN5(dev)) {
1137 u16 rgvswctl = I915_READ16(MEMSWCTL);
1138 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1139
1140 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1141 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1142 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1143 MEMSTAT_VID_SHIFT);
1144 seq_printf(m, "Current P-state: %d\n",
1145 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001146 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
Akash Goel60260a52015-03-06 11:07:21 +05301147 IS_BROADWELL(dev) || IS_GEN9(dev)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001148 u32 rp_state_limits;
1149 u32 gt_perf_status;
1150 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001151 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001152 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001153 u32 rpupei, rpcurup, rpprevup;
1154 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001155 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001156 int max_freq;
1157
Bob Paauwe35040562015-06-25 14:54:07 -07001158 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1159 if (IS_BROXTON(dev)) {
1160 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1161 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1162 } else {
1163 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1164 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1165 }
1166
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001167 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001168 ret = mutex_lock_interruptible(&dev->struct_mutex);
1169 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001170 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001171
Mika Kuoppala59bad942015-01-16 11:34:40 +02001172 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001173
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001174 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301175 if (IS_GEN9(dev))
1176 reqf >>= 23;
1177 else {
1178 reqf &= ~GEN6_TURBO_DISABLE;
1179 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1180 reqf >>= 24;
1181 else
1182 reqf >>= 25;
1183 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001184 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001185
Chris Wilson0d8f9492014-03-27 09:06:14 +00001186 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1187 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1188 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1189
Jesse Barnesccab5c82011-01-18 15:49:25 -08001190 rpstat = I915_READ(GEN6_RPSTAT1);
1191 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1192 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1193 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1194 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1195 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1196 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Akash Goel60260a52015-03-06 11:07:21 +05301197 if (IS_GEN9(dev))
1198 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1199 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001200 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1201 else
1202 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001203 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001204
Mika Kuoppala59bad942015-01-16 11:34:40 +02001205 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001206 mutex_unlock(&dev->struct_mutex);
1207
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001208 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1209 pm_ier = I915_READ(GEN6_PMIER);
1210 pm_imr = I915_READ(GEN6_PMIMR);
1211 pm_isr = I915_READ(GEN6_PMISR);
1212 pm_iir = I915_READ(GEN6_PMIIR);
1213 pm_mask = I915_READ(GEN6_PMINTRMSK);
1214 } else {
1215 pm_ier = I915_READ(GEN8_GT_IER(2));
1216 pm_imr = I915_READ(GEN8_GT_IMR(2));
1217 pm_isr = I915_READ(GEN8_GT_ISR(2));
1218 pm_iir = I915_READ(GEN8_GT_IIR(2));
1219 pm_mask = I915_READ(GEN6_PMINTRMSK);
1220 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001221 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 -03001222 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001223 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001224 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301225 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001226 seq_printf(m, "Render p-state VID: %d\n",
1227 gt_perf_status & 0xff);
1228 seq_printf(m, "Render p-state limit: %d\n",
1229 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001230 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1231 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1232 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1233 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001234 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001235 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001236 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1237 GEN6_CURICONT_MASK);
1238 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1239 GEN6_CURBSYTAVG_MASK);
1240 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1241 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001242 seq_printf(m, "Up threshold: %d%%\n",
1243 dev_priv->rps.up_threshold);
1244
Jesse Barnesccab5c82011-01-18 15:49:25 -08001245 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1246 GEN6_CURIAVG_MASK);
1247 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1248 GEN6_CURBSYTAVG_MASK);
1249 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1250 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001251 seq_printf(m, "Down threshold: %d%%\n",
1252 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001253
Bob Paauwe35040562015-06-25 14:54:07 -07001254 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1255 rp_state_cap >> 16) & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301256 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001257 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001258 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001259
1260 max_freq = (rp_state_cap & 0xff00) >> 8;
Akash Goel60260a52015-03-06 11:07:21 +05301261 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001262 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001263 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001264
Bob Paauwe35040562015-06-25 14:54:07 -07001265 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1266 rp_state_cap >> 0) & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301267 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001268 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001269 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001270 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001271 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001272
Chris Wilsond86ed342015-04-27 13:41:19 +01001273 seq_printf(m, "Current freq: %d MHz\n",
1274 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1275 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001276 seq_printf(m, "Idle freq: %d MHz\n",
1277 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001278 seq_printf(m, "Min freq: %d MHz\n",
1279 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1280 seq_printf(m, "Max freq: %d MHz\n",
1281 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1282 seq_printf(m,
1283 "efficient (RPe) frequency: %d MHz\n",
1284 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001285 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001286 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001287
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001288 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001289 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001290 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1291 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1292
Chris Wilsond86ed342015-04-27 13:41:19 +01001293 seq_printf(m, "actual GPU freq: %d MHz\n",
1294 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1295
1296 seq_printf(m, "current GPU freq: %d MHz\n",
1297 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1298
Jesse Barnes0a073b82013-04-17 15:54:58 -07001299 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001300 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001301
Jesse Barnes0a073b82013-04-17 15:54:58 -07001302 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001303 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001304
Chris Wilsonaed242f2015-03-18 09:48:21 +00001305 seq_printf(m, "idle GPU freq: %d MHz\n",
1306 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1307
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001308 seq_printf(m,
1309 "efficient (RPe) frequency: %d MHz\n",
1310 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001311 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001312 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001313 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001314 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001315
Mika Kahola1170f282015-09-25 14:00:32 +03001316 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1317 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1318 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1319
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001320out:
1321 intel_runtime_pm_put(dev_priv);
1322 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001323}
1324
Chris Wilsonf6544492015-01-26 18:03:04 +02001325static int i915_hangcheck_info(struct seq_file *m, void *unused)
1326{
1327 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001328 struct drm_device *dev = node->minor->dev;
1329 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf6544492015-01-26 18:03:04 +02001330 struct intel_engine_cs *ring;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001331 u64 acthd[I915_NUM_RINGS];
1332 u32 seqno[I915_NUM_RINGS];
Chris Wilsonf6544492015-01-26 18:03:04 +02001333 int i;
1334
1335 if (!i915.enable_hangcheck) {
1336 seq_printf(m, "Hangcheck disabled\n");
1337 return 0;
1338 }
1339
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001340 intel_runtime_pm_get(dev_priv);
1341
1342 for_each_ring(ring, dev_priv, i) {
1343 seqno[i] = ring->get_seqno(ring, false);
1344 acthd[i] = intel_ring_get_active_head(ring);
1345 }
1346
1347 intel_runtime_pm_put(dev_priv);
1348
Chris Wilsonf6544492015-01-26 18:03:04 +02001349 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1350 seq_printf(m, "Hangcheck active, fires in %dms\n",
1351 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1352 jiffies));
1353 } else
1354 seq_printf(m, "Hangcheck inactive\n");
1355
1356 for_each_ring(ring, dev_priv, i) {
1357 seq_printf(m, "%s:\n", ring->name);
1358 seq_printf(m, "\tseqno = %x [current %x]\n",
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001359 ring->hangcheck.seqno, seqno[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001360 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1361 (long long)ring->hangcheck.acthd,
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001362 (long long)acthd[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001363 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1364 (long long)ring->hangcheck.max_acthd);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001365 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1366 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
Chris Wilsonf6544492015-01-26 18:03:04 +02001367 }
1368
1369 return 0;
1370}
1371
Ben Widawsky4d855292011-12-12 19:34:16 -08001372static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001373{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001374 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001375 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001376 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001377 u32 rgvmodectl, rstdbyctl;
1378 u16 crstandvid;
1379 int ret;
1380
1381 ret = mutex_lock_interruptible(&dev->struct_mutex);
1382 if (ret)
1383 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001384 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001385
1386 rgvmodectl = I915_READ(MEMMODECTL);
1387 rstdbyctl = I915_READ(RSTDBYCTL);
1388 crstandvid = I915_READ16(CRSTANDVID);
1389
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001390 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001391 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001392
Jani Nikula742f4912015-09-03 11:16:09 +03001393 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001394 seq_printf(m, "Boost freq: %d\n",
1395 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1396 MEMMODE_BOOST_FREQ_SHIFT);
1397 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001398 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001399 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001400 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001401 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001402 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001403 seq_printf(m, "Starting frequency: P%d\n",
1404 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001405 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001406 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001407 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1408 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1409 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1410 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001411 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001412 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001413 switch (rstdbyctl & RSX_STATUS_MASK) {
1414 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001415 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001416 break;
1417 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001418 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001419 break;
1420 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001421 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001422 break;
1423 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001424 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001425 break;
1426 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001427 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001428 break;
1429 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001430 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001431 break;
1432 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001433 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001434 break;
1435 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001436
1437 return 0;
1438}
1439
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001440static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001441{
1442 struct drm_info_node *node = m->private;
1443 struct drm_device *dev = node->minor->dev;
1444 struct drm_i915_private *dev_priv = dev->dev_private;
1445 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001446 int i;
1447
1448 spin_lock_irq(&dev_priv->uncore.lock);
1449 for_each_fw_domain(fw_domain, dev_priv, i) {
1450 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001451 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001452 fw_domain->wake_count);
1453 }
1454 spin_unlock_irq(&dev_priv->uncore.lock);
1455
1456 return 0;
1457}
1458
Deepak S669ab5a2014-01-10 15:18:26 +05301459static int vlv_drpc_info(struct seq_file *m)
1460{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001461 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301462 struct drm_device *dev = node->minor->dev;
1463 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001464 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301465
Imre Deakd46c0512014-04-14 20:24:27 +03001466 intel_runtime_pm_get(dev_priv);
1467
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001468 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301469 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1470 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1471
Imre Deakd46c0512014-04-14 20:24:27 +03001472 intel_runtime_pm_put(dev_priv);
1473
Deepak S669ab5a2014-01-10 15:18:26 +05301474 seq_printf(m, "Video Turbo Mode: %s\n",
1475 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1476 seq_printf(m, "Turbo enabled: %s\n",
1477 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1478 seq_printf(m, "HW control enabled: %s\n",
1479 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1480 seq_printf(m, "SW control enabled: %s\n",
1481 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1482 GEN6_RP_MEDIA_SW_MODE));
1483 seq_printf(m, "RC6 Enabled: %s\n",
1484 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1485 GEN6_RC_CTL_EI_MODE(1))));
1486 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001487 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301488 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001489 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301490
Imre Deak9cc19be2014-04-14 20:24:24 +03001491 seq_printf(m, "Render RC6 residency since boot: %u\n",
1492 I915_READ(VLV_GT_RENDER_RC6));
1493 seq_printf(m, "Media RC6 residency since boot: %u\n",
1494 I915_READ(VLV_GT_MEDIA_RC6));
1495
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001496 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301497}
1498
Ben Widawsky4d855292011-12-12 19:34:16 -08001499static int gen6_drpc_info(struct seq_file *m)
1500{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001501 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001502 struct drm_device *dev = node->minor->dev;
1503 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001504 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001505 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001506 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001507
1508 ret = mutex_lock_interruptible(&dev->struct_mutex);
1509 if (ret)
1510 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001511 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001512
Chris Wilson907b28c2013-07-19 20:36:52 +01001513 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001514 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001515 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001516
1517 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001518 seq_puts(m, "RC information inaccurate because somebody "
1519 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001520 } else {
1521 /* NB: we cannot use forcewake, else we read the wrong values */
1522 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1523 udelay(10);
1524 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1525 }
1526
1527 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001528 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001529
1530 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1531 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1532 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001533 mutex_lock(&dev_priv->rps.hw_lock);
1534 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1535 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001536
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001537 intel_runtime_pm_put(dev_priv);
1538
Ben Widawsky4d855292011-12-12 19:34:16 -08001539 seq_printf(m, "Video Turbo Mode: %s\n",
1540 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1541 seq_printf(m, "HW control enabled: %s\n",
1542 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1543 seq_printf(m, "SW control enabled: %s\n",
1544 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1545 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001546 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001547 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1548 seq_printf(m, "RC6 Enabled: %s\n",
1549 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1550 seq_printf(m, "Deep RC6 Enabled: %s\n",
1551 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1552 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1553 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001554 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001555 switch (gt_core_status & GEN6_RCn_MASK) {
1556 case GEN6_RC0:
1557 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001558 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001559 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001560 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001561 break;
1562 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001563 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001564 break;
1565 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001566 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001567 break;
1568 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001569 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001570 break;
1571 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001572 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001573 break;
1574 }
1575
1576 seq_printf(m, "Core Power Down: %s\n",
1577 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001578
1579 /* Not exactly sure what this is */
1580 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1581 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1582 seq_printf(m, "RC6 residency since boot: %u\n",
1583 I915_READ(GEN6_GT_GFX_RC6));
1584 seq_printf(m, "RC6+ residency since boot: %u\n",
1585 I915_READ(GEN6_GT_GFX_RC6p));
1586 seq_printf(m, "RC6++ residency since boot: %u\n",
1587 I915_READ(GEN6_GT_GFX_RC6pp));
1588
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001589 seq_printf(m, "RC6 voltage: %dmV\n",
1590 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1591 seq_printf(m, "RC6+ voltage: %dmV\n",
1592 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1593 seq_printf(m, "RC6++ voltage: %dmV\n",
1594 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001595 return 0;
1596}
1597
1598static int i915_drpc_info(struct seq_file *m, void *unused)
1599{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001600 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001601 struct drm_device *dev = node->minor->dev;
1602
Deepak S669ab5a2014-01-10 15:18:26 +05301603 if (IS_VALLEYVIEW(dev))
1604 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001605 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001606 return gen6_drpc_info(m);
1607 else
1608 return ironlake_drpc_info(m);
1609}
1610
Daniel Vetter9a851782015-06-18 10:30:22 +02001611static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1612{
1613 struct drm_info_node *node = m->private;
1614 struct drm_device *dev = node->minor->dev;
1615 struct drm_i915_private *dev_priv = dev->dev_private;
1616
1617 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1618 dev_priv->fb_tracking.busy_bits);
1619
1620 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1621 dev_priv->fb_tracking.flip_bits);
1622
1623 return 0;
1624}
1625
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001626static int i915_fbc_status(struct seq_file *m, void *unused)
1627{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001628 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001629 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001630 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001631
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001632 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001633 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001634 return 0;
1635 }
1636
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001637 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001638 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001639
Paulo Zanoni7733b492015-07-07 15:26:04 -03001640 if (intel_fbc_enabled(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001641 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001642 else
1643 seq_printf(m, "FBC disabled: %s\n",
1644 intel_no_fbc_reason_str(dev_priv->fbc.no_fbc_reason));
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001645
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001646 if (INTEL_INFO(dev_priv)->gen >= 7)
1647 seq_printf(m, "Compressing: %s\n",
1648 yesno(I915_READ(FBC_STATUS2) &
1649 FBC_COMPRESSION_MASK));
1650
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001651 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001652 intel_runtime_pm_put(dev_priv);
1653
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001654 return 0;
1655}
1656
Rodrigo Vivida46f932014-08-01 02:04:45 -07001657static int i915_fbc_fc_get(void *data, u64 *val)
1658{
1659 struct drm_device *dev = data;
1660 struct drm_i915_private *dev_priv = dev->dev_private;
1661
1662 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1663 return -ENODEV;
1664
Rodrigo Vivida46f932014-08-01 02:04:45 -07001665 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001666
1667 return 0;
1668}
1669
1670static int i915_fbc_fc_set(void *data, u64 val)
1671{
1672 struct drm_device *dev = data;
1673 struct drm_i915_private *dev_priv = dev->dev_private;
1674 u32 reg;
1675
1676 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1677 return -ENODEV;
1678
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001679 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001680
1681 reg = I915_READ(ILK_DPFC_CONTROL);
1682 dev_priv->fbc.false_color = val;
1683
1684 I915_WRITE(ILK_DPFC_CONTROL, val ?
1685 (reg | FBC_CTL_FALSE_COLOR) :
1686 (reg & ~FBC_CTL_FALSE_COLOR));
1687
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001688 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001689 return 0;
1690}
1691
1692DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1693 i915_fbc_fc_get, i915_fbc_fc_set,
1694 "%llu\n");
1695
Paulo Zanoni92d44622013-05-31 16:33:24 -03001696static int i915_ips_status(struct seq_file *m, void *unused)
1697{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001698 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001699 struct drm_device *dev = node->minor->dev;
1700 struct drm_i915_private *dev_priv = dev->dev_private;
1701
Damien Lespiauf5adf942013-06-24 18:29:34 +01001702 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001703 seq_puts(m, "not supported\n");
1704 return 0;
1705 }
1706
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001707 intel_runtime_pm_get(dev_priv);
1708
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001709 seq_printf(m, "Enabled by kernel parameter: %s\n",
1710 yesno(i915.enable_ips));
1711
1712 if (INTEL_INFO(dev)->gen >= 8) {
1713 seq_puts(m, "Currently: unknown\n");
1714 } else {
1715 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1716 seq_puts(m, "Currently: enabled\n");
1717 else
1718 seq_puts(m, "Currently: disabled\n");
1719 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001720
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001721 intel_runtime_pm_put(dev_priv);
1722
Paulo Zanoni92d44622013-05-31 16:33:24 -03001723 return 0;
1724}
1725
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001726static int i915_sr_status(struct seq_file *m, void *unused)
1727{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001728 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001729 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001730 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001731 bool sr_enabled = false;
1732
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001733 intel_runtime_pm_get(dev_priv);
1734
Yuanhan Liu13982612010-12-15 15:42:31 +08001735 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001736 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001737 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1738 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001739 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1740 else if (IS_I915GM(dev))
1741 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1742 else if (IS_PINEVIEW(dev))
1743 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001744 else if (IS_VALLEYVIEW(dev))
1745 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001746
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001747 intel_runtime_pm_put(dev_priv);
1748
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001749 seq_printf(m, "self-refresh: %s\n",
1750 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001751
1752 return 0;
1753}
1754
Jesse Barnes7648fa92010-05-20 14:28:11 -07001755static int i915_emon_status(struct seq_file *m, void *unused)
1756{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001757 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001758 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001759 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001760 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001761 int ret;
1762
Chris Wilson582be6b2012-04-30 19:35:02 +01001763 if (!IS_GEN5(dev))
1764 return -ENODEV;
1765
Chris Wilsonde227ef2010-07-03 07:58:38 +01001766 ret = mutex_lock_interruptible(&dev->struct_mutex);
1767 if (ret)
1768 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001769
1770 temp = i915_mch_val(dev_priv);
1771 chipset = i915_chipset_val(dev_priv);
1772 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001773 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001774
1775 seq_printf(m, "GMCH temp: %ld\n", temp);
1776 seq_printf(m, "Chipset power: %ld\n", chipset);
1777 seq_printf(m, "GFX power: %ld\n", gfx);
1778 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1779
1780 return 0;
1781}
1782
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001783static int i915_ring_freq_table(struct seq_file *m, void *unused)
1784{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001785 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001786 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001787 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001788 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001789 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301790 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001791
Akash Goel97d33082015-06-29 14:50:23 +05301792 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001793 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001794 return 0;
1795 }
1796
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001797 intel_runtime_pm_get(dev_priv);
1798
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001799 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1800
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001801 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001802 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001803 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001804
Akash Goelf936ec32015-06-29 14:50:22 +05301805 if (IS_SKYLAKE(dev)) {
1806 /* Convert GT frequency to 50 HZ units */
1807 min_gpu_freq =
1808 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1809 max_gpu_freq =
1810 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1811 } else {
1812 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1813 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1814 }
1815
Damien Lespiau267f0c92013-06-24 22:59:48 +01001816 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001817
Akash Goelf936ec32015-06-29 14:50:22 +05301818 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001819 ia_freq = gpu_freq;
1820 sandybridge_pcode_read(dev_priv,
1821 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1822 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001823 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301824 intel_gpu_freq(dev_priv, (gpu_freq *
1825 (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001826 ((ia_freq >> 0) & 0xff) * 100,
1827 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001828 }
1829
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001830 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001831
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001832out:
1833 intel_runtime_pm_put(dev_priv);
1834 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001835}
1836
Chris Wilson44834a62010-08-19 16:09:23 +01001837static int i915_opregion(struct seq_file *m, void *unused)
1838{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001839 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001840 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001841 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001842 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001843 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001844 int ret;
1845
Daniel Vetter0d38f002012-04-21 22:49:10 +02001846 if (data == NULL)
1847 return -ENOMEM;
1848
Chris Wilson44834a62010-08-19 16:09:23 +01001849 ret = mutex_lock_interruptible(&dev->struct_mutex);
1850 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001851 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001852
Daniel Vetter0d38f002012-04-21 22:49:10 +02001853 if (opregion->header) {
1854 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1855 seq_write(m, data, OPREGION_SIZE);
1856 }
Chris Wilson44834a62010-08-19 16:09:23 +01001857
1858 mutex_unlock(&dev->struct_mutex);
1859
Daniel Vetter0d38f002012-04-21 22:49:10 +02001860out:
1861 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001862 return 0;
1863}
1864
Chris Wilson37811fc2010-08-25 22:45:57 +01001865static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1866{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001867 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001868 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001869 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001870 struct intel_framebuffer *fb;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001871 struct drm_framebuffer *drm_fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001872
Daniel Vetter06957262015-08-10 13:34:08 +02001873#ifdef CONFIG_DRM_FBDEV_EMULATION
Daniel Vetter4520f532013-10-09 09:18:51 +02001874 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001875
1876 ifbdev = dev_priv->fbdev;
1877 fb = to_intel_framebuffer(ifbdev->helper.fb);
1878
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001879 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 +01001880 fb->base.width,
1881 fb->base.height,
1882 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001883 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001884 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001885 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001886 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001887 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001888#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001889
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001890 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001891 drm_for_each_fb(drm_fb, dev) {
1892 fb = to_intel_framebuffer(drm_fb);
Daniel Vetter131a56d2013-10-17 14:35:31 +02001893 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001894 continue;
1895
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001896 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 +01001897 fb->base.width,
1898 fb->base.height,
1899 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001900 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001901 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001902 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001903 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001904 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001905 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001906 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001907
1908 return 0;
1909}
1910
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001911static void describe_ctx_ringbuf(struct seq_file *m,
1912 struct intel_ringbuffer *ringbuf)
1913{
1914 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1915 ringbuf->space, ringbuf->head, ringbuf->tail,
1916 ringbuf->last_retired_head);
1917}
1918
Ben Widawskye76d3632011-03-19 18:14:29 -07001919static int i915_context_status(struct seq_file *m, void *unused)
1920{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001921 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001922 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001923 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001924 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001925 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001926 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001927
Daniel Vetterf3d28872014-05-29 23:23:08 +02001928 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001929 if (ret)
1930 return ret;
1931
Ben Widawskya33afea2013-09-17 21:12:45 -07001932 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001933 if (!i915.enable_execlists &&
1934 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001935 continue;
1936
Ben Widawskya33afea2013-09-17 21:12:45 -07001937 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001938 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001939 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001940 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001941 seq_printf(m, "(default context %s) ",
1942 ring->name);
1943 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001944
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001945 if (i915.enable_execlists) {
1946 seq_putc(m, '\n');
1947 for_each_ring(ring, dev_priv, i) {
1948 struct drm_i915_gem_object *ctx_obj =
1949 ctx->engine[i].state;
1950 struct intel_ringbuffer *ringbuf =
1951 ctx->engine[i].ringbuf;
1952
1953 seq_printf(m, "%s: ", ring->name);
1954 if (ctx_obj)
1955 describe_obj(m, ctx_obj);
1956 if (ringbuf)
1957 describe_ctx_ringbuf(m, ringbuf);
1958 seq_putc(m, '\n');
1959 }
1960 } else {
1961 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1962 }
1963
Ben Widawskya33afea2013-09-17 21:12:45 -07001964 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001965 }
1966
Daniel Vetterf3d28872014-05-29 23:23:08 +02001967 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001968
1969 return 0;
1970}
1971
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001972static void i915_dump_lrc_obj(struct seq_file *m,
1973 struct intel_engine_cs *ring,
1974 struct drm_i915_gem_object *ctx_obj)
1975{
1976 struct page *page;
1977 uint32_t *reg_state;
1978 int j;
1979 unsigned long ggtt_offset = 0;
1980
1981 if (ctx_obj == NULL) {
1982 seq_printf(m, "Context on %s with no gem object\n",
1983 ring->name);
1984 return;
1985 }
1986
1987 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1988 intel_execlists_ctx_id(ctx_obj));
1989
1990 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1991 seq_puts(m, "\tNot bound in GGTT\n");
1992 else
1993 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1994
1995 if (i915_gem_object_get_pages(ctx_obj)) {
1996 seq_puts(m, "\tFailed to get pages for context object\n");
1997 return;
1998 }
1999
Alex Daid1675192015-08-12 15:43:43 +01002000 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002001 if (!WARN_ON(page == NULL)) {
2002 reg_state = kmap_atomic(page);
2003
2004 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2005 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2006 ggtt_offset + 4096 + (j * 4),
2007 reg_state[j], reg_state[j + 1],
2008 reg_state[j + 2], reg_state[j + 3]);
2009 }
2010 kunmap_atomic(reg_state);
2011 }
2012
2013 seq_putc(m, '\n');
2014}
2015
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002016static int i915_dump_lrc(struct seq_file *m, void *unused)
2017{
2018 struct drm_info_node *node = (struct drm_info_node *) m->private;
2019 struct drm_device *dev = node->minor->dev;
2020 struct drm_i915_private *dev_priv = dev->dev_private;
2021 struct intel_engine_cs *ring;
2022 struct intel_context *ctx;
2023 int ret, i;
2024
2025 if (!i915.enable_execlists) {
2026 seq_printf(m, "Logical Ring Contexts are disabled\n");
2027 return 0;
2028 }
2029
2030 ret = mutex_lock_interruptible(&dev->struct_mutex);
2031 if (ret)
2032 return ret;
2033
2034 list_for_each_entry(ctx, &dev_priv->context_list, link) {
2035 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002036 if (ring->default_context != ctx)
2037 i915_dump_lrc_obj(m, ring,
2038 ctx->engine[i].state);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002039 }
2040 }
2041
2042 mutex_unlock(&dev->struct_mutex);
2043
2044 return 0;
2045}
2046
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002047static int i915_execlists(struct seq_file *m, void *data)
2048{
2049 struct drm_info_node *node = (struct drm_info_node *)m->private;
2050 struct drm_device *dev = node->minor->dev;
2051 struct drm_i915_private *dev_priv = dev->dev_private;
2052 struct intel_engine_cs *ring;
2053 u32 status_pointer;
2054 u8 read_pointer;
2055 u8 write_pointer;
2056 u32 status;
2057 u32 ctx_id;
2058 struct list_head *cursor;
2059 int ring_id, i;
2060 int ret;
2061
2062 if (!i915.enable_execlists) {
2063 seq_puts(m, "Logical Ring Contexts are disabled\n");
2064 return 0;
2065 }
2066
2067 ret = mutex_lock_interruptible(&dev->struct_mutex);
2068 if (ret)
2069 return ret;
2070
Michel Thierryfc0412e2014-10-16 16:13:38 +01002071 intel_runtime_pm_get(dev_priv);
2072
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002073 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002074 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002075 int count = 0;
2076 unsigned long flags;
2077
2078 seq_printf(m, "%s\n", ring->name);
2079
Ville Syrjälä83843d82015-09-18 20:03:15 +03002080 status = I915_READ(RING_EXECLIST_STATUS_LO(ring));
2081 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(ring));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002082 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2083 status, ctx_id);
2084
2085 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2086 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2087
2088 read_pointer = ring->next_context_status_buffer;
2089 write_pointer = status_pointer & 0x07;
2090 if (read_pointer > write_pointer)
2091 write_pointer += 6;
2092 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2093 read_pointer, write_pointer);
2094
2095 for (i = 0; i < 6; i++) {
Ville Syrjälä83843d82015-09-18 20:03:15 +03002096 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(ring, i));
2097 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(ring, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002098
2099 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2100 i, status, ctx_id);
2101 }
2102
2103 spin_lock_irqsave(&ring->execlist_lock, flags);
2104 list_for_each(cursor, &ring->execlist_queue)
2105 count++;
2106 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002107 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002108 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2109
2110 seq_printf(m, "\t%d requests in queue\n", count);
2111 if (head_req) {
2112 struct drm_i915_gem_object *ctx_obj;
2113
Nick Hoath6d3d8272015-01-15 13:10:39 +00002114 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002115 seq_printf(m, "\tHead request id: %u\n",
2116 intel_execlists_ctx_id(ctx_obj));
2117 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002118 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002119 }
2120
2121 seq_putc(m, '\n');
2122 }
2123
Michel Thierryfc0412e2014-10-16 16:13:38 +01002124 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002125 mutex_unlock(&dev->struct_mutex);
2126
2127 return 0;
2128}
2129
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002130static const char *swizzle_string(unsigned swizzle)
2131{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002132 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002133 case I915_BIT_6_SWIZZLE_NONE:
2134 return "none";
2135 case I915_BIT_6_SWIZZLE_9:
2136 return "bit9";
2137 case I915_BIT_6_SWIZZLE_9_10:
2138 return "bit9/bit10";
2139 case I915_BIT_6_SWIZZLE_9_11:
2140 return "bit9/bit11";
2141 case I915_BIT_6_SWIZZLE_9_10_11:
2142 return "bit9/bit10/bit11";
2143 case I915_BIT_6_SWIZZLE_9_17:
2144 return "bit9/bit17";
2145 case I915_BIT_6_SWIZZLE_9_10_17:
2146 return "bit9/bit10/bit17";
2147 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002148 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002149 }
2150
2151 return "bug";
2152}
2153
2154static int i915_swizzle_info(struct seq_file *m, void *data)
2155{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002156 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002157 struct drm_device *dev = node->minor->dev;
2158 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002159 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002160
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002161 ret = mutex_lock_interruptible(&dev->struct_mutex);
2162 if (ret)
2163 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002164 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002165
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002166 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2167 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2168 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2169 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2170
2171 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2172 seq_printf(m, "DDC = 0x%08x\n",
2173 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002174 seq_printf(m, "DDC2 = 0x%08x\n",
2175 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002176 seq_printf(m, "C0DRB3 = 0x%04x\n",
2177 I915_READ16(C0DRB3));
2178 seq_printf(m, "C1DRB3 = 0x%04x\n",
2179 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002180 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002181 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2182 I915_READ(MAD_DIMM_C0));
2183 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2184 I915_READ(MAD_DIMM_C1));
2185 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2186 I915_READ(MAD_DIMM_C2));
2187 seq_printf(m, "TILECTL = 0x%08x\n",
2188 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002189 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002190 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2191 I915_READ(GAMTARBMODE));
2192 else
2193 seq_printf(m, "ARB_MODE = 0x%08x\n",
2194 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002195 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2196 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002197 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002198
2199 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2200 seq_puts(m, "L-shaped memory detected\n");
2201
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002202 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002203 mutex_unlock(&dev->struct_mutex);
2204
2205 return 0;
2206}
2207
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002208static int per_file_ctx(int id, void *ptr, void *data)
2209{
Oscar Mateo273497e2014-05-22 14:13:37 +01002210 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002211 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002212 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2213
2214 if (!ppgtt) {
2215 seq_printf(m, " no ppgtt for context %d\n",
2216 ctx->user_handle);
2217 return 0;
2218 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002219
Oscar Mateof83d6512014-05-22 14:13:38 +01002220 if (i915_gem_context_is_default(ctx))
2221 seq_puts(m, " default context:\n");
2222 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002223 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002224 ppgtt->debug_dump(ppgtt, m);
2225
2226 return 0;
2227}
2228
Ben Widawsky77df6772013-11-02 21:07:30 -07002229static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002230{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002231 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002232 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002233 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2234 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002235
Ben Widawsky77df6772013-11-02 21:07:30 -07002236 if (!ppgtt)
2237 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002238
Ben Widawsky77df6772013-11-02 21:07:30 -07002239 for_each_ring(ring, dev_priv, unused) {
2240 seq_printf(m, "%s\n", ring->name);
2241 for (i = 0; i < 4; i++) {
Ville Syrjäläd3a93cb2015-09-18 20:03:26 +03002242 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(ring, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002243 pdp <<= 32;
Ville Syrjäläd3a93cb2015-09-18 20:03:26 +03002244 pdp |= I915_READ(GEN8_RING_PDP_LDW(ring, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002245 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002246 }
2247 }
2248}
2249
2250static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2251{
2252 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002253 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002254 int i;
2255
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002256 if (INTEL_INFO(dev)->gen == 6)
2257 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2258
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002259 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002260 seq_printf(m, "%s\n", ring->name);
2261 if (INTEL_INFO(dev)->gen == 7)
2262 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2263 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2264 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2265 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2266 }
2267 if (dev_priv->mm.aliasing_ppgtt) {
2268 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2269
Damien Lespiau267f0c92013-06-24 22:59:48 +01002270 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002271 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002272
Ben Widawsky87d60b62013-12-06 14:11:29 -08002273 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002274 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002275
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002276 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002277}
2278
2279static int i915_ppgtt_info(struct seq_file *m, void *data)
2280{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002281 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002282 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002283 struct drm_i915_private *dev_priv = dev->dev_private;
Michel Thierryea91e402015-07-29 17:23:57 +01002284 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002285
2286 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2287 if (ret)
2288 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002289 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002290
2291 if (INTEL_INFO(dev)->gen >= 8)
2292 gen8_ppgtt_info(m, dev);
2293 else if (INTEL_INFO(dev)->gen >= 6)
2294 gen6_ppgtt_info(m, dev);
2295
Michel Thierryea91e402015-07-29 17:23:57 +01002296 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2297 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002298 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002299
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002300 task = get_pid_task(file->pid, PIDTYPE_PID);
2301 if (!task)
2302 return -ESRCH;
2303 seq_printf(m, "\nproc: %s\n", task->comm);
2304 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002305 idr_for_each(&file_priv->context_idr, per_file_ctx,
2306 (void *)(unsigned long)m);
2307 }
2308
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002309 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002310 mutex_unlock(&dev->struct_mutex);
2311
2312 return 0;
2313}
2314
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002315static int count_irq_waiters(struct drm_i915_private *i915)
2316{
2317 struct intel_engine_cs *ring;
2318 int count = 0;
2319 int i;
2320
2321 for_each_ring(ring, i915, i)
2322 count += ring->irq_refcount;
2323
2324 return count;
2325}
2326
Chris Wilson1854d5c2015-04-07 16:20:32 +01002327static int i915_rps_boost_info(struct seq_file *m, void *data)
2328{
2329 struct drm_info_node *node = m->private;
2330 struct drm_device *dev = node->minor->dev;
2331 struct drm_i915_private *dev_priv = dev->dev_private;
2332 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002333
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002334 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2335 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2336 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2337 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2338 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2339 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2340 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2341 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2342 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson8d3afd72015-05-21 21:01:47 +01002343 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002344 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2345 struct drm_i915_file_private *file_priv = file->driver_priv;
2346 struct task_struct *task;
2347
2348 rcu_read_lock();
2349 task = pid_task(file->pid, PIDTYPE_PID);
2350 seq_printf(m, "%s [%d]: %d boosts%s\n",
2351 task ? task->comm : "<unknown>",
2352 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002353 file_priv->rps.boosts,
2354 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002355 rcu_read_unlock();
2356 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002357 seq_printf(m, "Semaphore boosts: %d%s\n",
2358 dev_priv->rps.semaphores.boosts,
2359 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2360 seq_printf(m, "MMIO flip boosts: %d%s\n",
2361 dev_priv->rps.mmioflips.boosts,
2362 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002363 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002364 spin_unlock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002365
Chris Wilson8d3afd72015-05-21 21:01:47 +01002366 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002367}
2368
Ben Widawsky63573eb2013-07-04 11:02:07 -07002369static int i915_llc(struct seq_file *m, void *data)
2370{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002371 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002372 struct drm_device *dev = node->minor->dev;
2373 struct drm_i915_private *dev_priv = dev->dev_private;
2374
2375 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2376 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2377 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2378
2379 return 0;
2380}
2381
Alex Daifdf5d352015-08-12 15:43:37 +01002382static int i915_guc_load_status_info(struct seq_file *m, void *data)
2383{
2384 struct drm_info_node *node = m->private;
2385 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2386 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2387 u32 tmp, i;
2388
2389 if (!HAS_GUC_UCODE(dev_priv->dev))
2390 return 0;
2391
2392 seq_printf(m, "GuC firmware status:\n");
2393 seq_printf(m, "\tpath: %s\n",
2394 guc_fw->guc_fw_path);
2395 seq_printf(m, "\tfetch: %s\n",
2396 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2397 seq_printf(m, "\tload: %s\n",
2398 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2399 seq_printf(m, "\tversion wanted: %d.%d\n",
2400 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2401 seq_printf(m, "\tversion found: %d.%d\n",
2402 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
2403
2404 tmp = I915_READ(GUC_STATUS);
2405
2406 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2407 seq_printf(m, "\tBootrom status = 0x%x\n",
2408 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2409 seq_printf(m, "\tuKernel status = 0x%x\n",
2410 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2411 seq_printf(m, "\tMIA Core status = 0x%x\n",
2412 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2413 seq_puts(m, "\nScratch registers:\n");
2414 for (i = 0; i < 16; i++)
2415 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2416
2417 return 0;
2418}
2419
Dave Gordon8b417c22015-08-12 15:43:44 +01002420static void i915_guc_client_info(struct seq_file *m,
2421 struct drm_i915_private *dev_priv,
2422 struct i915_guc_client *client)
2423{
2424 struct intel_engine_cs *ring;
2425 uint64_t tot = 0;
2426 uint32_t i;
2427
2428 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2429 client->priority, client->ctx_index, client->proc_desc_offset);
2430 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2431 client->doorbell_id, client->doorbell_offset, client->cookie);
2432 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2433 client->wq_size, client->wq_offset, client->wq_tail);
2434
2435 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2436 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2437 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2438
2439 for_each_ring(ring, dev_priv, i) {
2440 seq_printf(m, "\tSubmissions: %llu %s\n",
2441 client->submissions[i],
2442 ring->name);
2443 tot += client->submissions[i];
2444 }
2445 seq_printf(m, "\tTotal: %llu\n", tot);
2446}
2447
2448static int i915_guc_info(struct seq_file *m, void *data)
2449{
2450 struct drm_info_node *node = m->private;
2451 struct drm_device *dev = node->minor->dev;
2452 struct drm_i915_private *dev_priv = dev->dev_private;
2453 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002454 struct i915_guc_client client = {};
Dave Gordon8b417c22015-08-12 15:43:44 +01002455 struct intel_engine_cs *ring;
2456 enum intel_ring_id i;
2457 u64 total = 0;
2458
2459 if (!HAS_GUC_SCHED(dev_priv->dev))
2460 return 0;
2461
2462 /* Take a local copy of the GuC data, so we can dump it at leisure */
2463 spin_lock(&dev_priv->guc.host2guc_lock);
2464 guc = dev_priv->guc;
2465 if (guc.execbuf_client) {
2466 spin_lock(&guc.execbuf_client->wq_lock);
2467 client = *guc.execbuf_client;
2468 spin_unlock(&guc.execbuf_client->wq_lock);
2469 }
2470 spin_unlock(&dev_priv->guc.host2guc_lock);
2471
2472 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2473 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2474 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2475 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2476 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2477
2478 seq_printf(m, "\nGuC submissions:\n");
2479 for_each_ring(ring, dev_priv, i) {
2480 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x %9d\n",
2481 ring->name, guc.submissions[i],
2482 guc.last_seqno[i], guc.last_seqno[i]);
2483 total += guc.submissions[i];
2484 }
2485 seq_printf(m, "\t%s: %llu\n", "Total", total);
2486
2487 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2488 i915_guc_client_info(m, dev_priv, &client);
2489
2490 /* Add more as required ... */
2491
2492 return 0;
2493}
2494
Alex Dai4c7e77f2015-08-12 15:43:40 +01002495static int i915_guc_log_dump(struct seq_file *m, void *data)
2496{
2497 struct drm_info_node *node = m->private;
2498 struct drm_device *dev = node->minor->dev;
2499 struct drm_i915_private *dev_priv = dev->dev_private;
2500 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2501 u32 *log;
2502 int i = 0, pg;
2503
2504 if (!log_obj)
2505 return 0;
2506
2507 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2508 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2509
2510 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2511 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2512 *(log + i), *(log + i + 1),
2513 *(log + i + 2), *(log + i + 3));
2514
2515 kunmap_atomic(log);
2516 }
2517
2518 seq_putc(m, '\n');
2519
2520 return 0;
2521}
2522
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002523static int i915_edp_psr_status(struct seq_file *m, void *data)
2524{
2525 struct drm_info_node *node = m->private;
2526 struct drm_device *dev = node->minor->dev;
2527 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002528 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002529 u32 stat[3];
2530 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002531 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002532
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002533 if (!HAS_PSR(dev)) {
2534 seq_puts(m, "PSR not supported\n");
2535 return 0;
2536 }
2537
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002538 intel_runtime_pm_get(dev_priv);
2539
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002540 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002541 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2542 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002543 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002544 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002545 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2546 dev_priv->psr.busy_frontbuffer_bits);
2547 seq_printf(m, "Re-enable work scheduled: %s\n",
2548 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002549
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002550 if (HAS_DDI(dev))
2551 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2552 else {
2553 for_each_pipe(dev_priv, pipe) {
2554 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2555 VLV_EDP_PSR_CURR_STATE_MASK;
2556 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2557 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2558 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002559 }
2560 }
2561 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002562
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002563 if (!HAS_DDI(dev))
2564 for_each_pipe(dev_priv, pipe) {
2565 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2566 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2567 seq_printf(m, " pipe %c", pipe_name(pipe));
2568 }
2569 seq_puts(m, "\n");
2570
2571 /* CHV PSR has no kind of performance counter */
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002572 if (HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002573 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2574 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002575
2576 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2577 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002578 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002579
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002580 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002581 return 0;
2582}
2583
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002584static int i915_sink_crc(struct seq_file *m, void *data)
2585{
2586 struct drm_info_node *node = m->private;
2587 struct drm_device *dev = node->minor->dev;
2588 struct intel_encoder *encoder;
2589 struct intel_connector *connector;
2590 struct intel_dp *intel_dp = NULL;
2591 int ret;
2592 u8 crc[6];
2593
2594 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002595 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002596
2597 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2598 continue;
2599
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002600 if (!connector->base.encoder)
2601 continue;
2602
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002603 encoder = to_intel_encoder(connector->base.encoder);
2604 if (encoder->type != INTEL_OUTPUT_EDP)
2605 continue;
2606
2607 intel_dp = enc_to_intel_dp(&encoder->base);
2608
2609 ret = intel_dp_sink_crc(intel_dp, crc);
2610 if (ret)
2611 goto out;
2612
2613 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2614 crc[0], crc[1], crc[2],
2615 crc[3], crc[4], crc[5]);
2616 goto out;
2617 }
2618 ret = -ENODEV;
2619out:
2620 drm_modeset_unlock_all(dev);
2621 return ret;
2622}
2623
Jesse Barnesec013e72013-08-20 10:29:23 +01002624static int i915_energy_uJ(struct seq_file *m, void *data)
2625{
2626 struct drm_info_node *node = m->private;
2627 struct drm_device *dev = node->minor->dev;
2628 struct drm_i915_private *dev_priv = dev->dev_private;
2629 u64 power;
2630 u32 units;
2631
2632 if (INTEL_INFO(dev)->gen < 6)
2633 return -ENODEV;
2634
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002635 intel_runtime_pm_get(dev_priv);
2636
Jesse Barnesec013e72013-08-20 10:29:23 +01002637 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2638 power = (power & 0x1f00) >> 8;
2639 units = 1000000 / (1 << power); /* convert to uJ */
2640 power = I915_READ(MCH_SECP_NRG_STTS);
2641 power *= units;
2642
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002643 intel_runtime_pm_put(dev_priv);
2644
Jesse Barnesec013e72013-08-20 10:29:23 +01002645 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002646
2647 return 0;
2648}
2649
Damien Lespiau6455c872015-06-04 18:23:57 +01002650static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002651{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002652 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002653 struct drm_device *dev = node->minor->dev;
2654 struct drm_i915_private *dev_priv = dev->dev_private;
2655
Damien Lespiau6455c872015-06-04 18:23:57 +01002656 if (!HAS_RUNTIME_PM(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002657 seq_puts(m, "not supported\n");
2658 return 0;
2659 }
2660
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002661 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002662 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002663 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002664#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002665 seq_printf(m, "Usage count: %d\n",
2666 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002667#else
2668 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2669#endif
Paulo Zanoni371db662013-08-19 13:18:10 -03002670
Jesse Barnesec013e72013-08-20 10:29:23 +01002671 return 0;
2672}
2673
Imre Deak1da51582013-11-25 17:15:35 +02002674static const char *power_domain_str(enum intel_display_power_domain domain)
2675{
2676 switch (domain) {
2677 case POWER_DOMAIN_PIPE_A:
2678 return "PIPE_A";
2679 case POWER_DOMAIN_PIPE_B:
2680 return "PIPE_B";
2681 case POWER_DOMAIN_PIPE_C:
2682 return "PIPE_C";
2683 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2684 return "PIPE_A_PANEL_FITTER";
2685 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2686 return "PIPE_B_PANEL_FITTER";
2687 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2688 return "PIPE_C_PANEL_FITTER";
2689 case POWER_DOMAIN_TRANSCODER_A:
2690 return "TRANSCODER_A";
2691 case POWER_DOMAIN_TRANSCODER_B:
2692 return "TRANSCODER_B";
2693 case POWER_DOMAIN_TRANSCODER_C:
2694 return "TRANSCODER_C";
2695 case POWER_DOMAIN_TRANSCODER_EDP:
2696 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002697 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2698 return "PORT_DDI_A_2_LANES";
2699 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2700 return "PORT_DDI_A_4_LANES";
2701 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2702 return "PORT_DDI_B_2_LANES";
2703 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2704 return "PORT_DDI_B_4_LANES";
2705 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2706 return "PORT_DDI_C_2_LANES";
2707 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2708 return "PORT_DDI_C_4_LANES";
2709 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2710 return "PORT_DDI_D_2_LANES";
2711 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2712 return "PORT_DDI_D_4_LANES";
Xiong Zhangd8e19f92015-08-13 18:00:12 +08002713 case POWER_DOMAIN_PORT_DDI_E_2_LANES:
2714 return "PORT_DDI_E_2_LANES";
Imre Deak319be8a2014-03-04 19:22:57 +02002715 case POWER_DOMAIN_PORT_DSI:
2716 return "PORT_DSI";
2717 case POWER_DOMAIN_PORT_CRT:
2718 return "PORT_CRT";
2719 case POWER_DOMAIN_PORT_OTHER:
2720 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002721 case POWER_DOMAIN_VGA:
2722 return "VGA";
2723 case POWER_DOMAIN_AUDIO:
2724 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002725 case POWER_DOMAIN_PLLS:
2726 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002727 case POWER_DOMAIN_AUX_A:
2728 return "AUX_A";
2729 case POWER_DOMAIN_AUX_B:
2730 return "AUX_B";
2731 case POWER_DOMAIN_AUX_C:
2732 return "AUX_C";
2733 case POWER_DOMAIN_AUX_D:
2734 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002735 case POWER_DOMAIN_INIT:
2736 return "INIT";
2737 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002738 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002739 return "?";
2740 }
2741}
2742
2743static int i915_power_domain_info(struct seq_file *m, void *unused)
2744{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002745 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002746 struct drm_device *dev = node->minor->dev;
2747 struct drm_i915_private *dev_priv = dev->dev_private;
2748 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2749 int i;
2750
2751 mutex_lock(&power_domains->lock);
2752
2753 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2754 for (i = 0; i < power_domains->power_well_count; i++) {
2755 struct i915_power_well *power_well;
2756 enum intel_display_power_domain power_domain;
2757
2758 power_well = &power_domains->power_wells[i];
2759 seq_printf(m, "%-25s %d\n", power_well->name,
2760 power_well->count);
2761
2762 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2763 power_domain++) {
2764 if (!(BIT(power_domain) & power_well->domains))
2765 continue;
2766
2767 seq_printf(m, " %-23s %d\n",
2768 power_domain_str(power_domain),
2769 power_domains->domain_use_count[power_domain]);
2770 }
2771 }
2772
2773 mutex_unlock(&power_domains->lock);
2774
2775 return 0;
2776}
2777
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002778static void intel_seq_print_mode(struct seq_file *m, int tabs,
2779 struct drm_display_mode *mode)
2780{
2781 int i;
2782
2783 for (i = 0; i < tabs; i++)
2784 seq_putc(m, '\t');
2785
2786 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",
2787 mode->base.id, mode->name,
2788 mode->vrefresh, mode->clock,
2789 mode->hdisplay, mode->hsync_start,
2790 mode->hsync_end, mode->htotal,
2791 mode->vdisplay, mode->vsync_start,
2792 mode->vsync_end, mode->vtotal,
2793 mode->type, mode->flags);
2794}
2795
2796static void intel_encoder_info(struct seq_file *m,
2797 struct intel_crtc *intel_crtc,
2798 struct intel_encoder *intel_encoder)
2799{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002800 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002801 struct drm_device *dev = node->minor->dev;
2802 struct drm_crtc *crtc = &intel_crtc->base;
2803 struct intel_connector *intel_connector;
2804 struct drm_encoder *encoder;
2805
2806 encoder = &intel_encoder->base;
2807 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002808 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002809 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2810 struct drm_connector *connector = &intel_connector->base;
2811 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2812 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002813 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002814 drm_get_connector_status_name(connector->status));
2815 if (connector->status == connector_status_connected) {
2816 struct drm_display_mode *mode = &crtc->mode;
2817 seq_printf(m, ", mode:\n");
2818 intel_seq_print_mode(m, 2, mode);
2819 } else {
2820 seq_putc(m, '\n');
2821 }
2822 }
2823}
2824
2825static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2826{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002827 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002828 struct drm_device *dev = node->minor->dev;
2829 struct drm_crtc *crtc = &intel_crtc->base;
2830 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002831 struct drm_plane_state *plane_state = crtc->primary->state;
2832 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002833
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002834 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002835 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002836 fb->base.id, plane_state->src_x >> 16,
2837 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002838 else
2839 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002840 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2841 intel_encoder_info(m, intel_crtc, intel_encoder);
2842}
2843
2844static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2845{
2846 struct drm_display_mode *mode = panel->fixed_mode;
2847
2848 seq_printf(m, "\tfixed mode:\n");
2849 intel_seq_print_mode(m, 2, mode);
2850}
2851
2852static void intel_dp_info(struct seq_file *m,
2853 struct intel_connector *intel_connector)
2854{
2855 struct intel_encoder *intel_encoder = intel_connector->encoder;
2856 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2857
2858 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002859 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002860 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2861 intel_panel_info(m, &intel_connector->panel);
2862}
2863
2864static void intel_hdmi_info(struct seq_file *m,
2865 struct intel_connector *intel_connector)
2866{
2867 struct intel_encoder *intel_encoder = intel_connector->encoder;
2868 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2869
Jani Nikula742f4912015-09-03 11:16:09 +03002870 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002871}
2872
2873static void intel_lvds_info(struct seq_file *m,
2874 struct intel_connector *intel_connector)
2875{
2876 intel_panel_info(m, &intel_connector->panel);
2877}
2878
2879static void intel_connector_info(struct seq_file *m,
2880 struct drm_connector *connector)
2881{
2882 struct intel_connector *intel_connector = to_intel_connector(connector);
2883 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002884 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002885
2886 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002887 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002888 drm_get_connector_status_name(connector->status));
2889 if (connector->status == connector_status_connected) {
2890 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2891 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2892 connector->display_info.width_mm,
2893 connector->display_info.height_mm);
2894 seq_printf(m, "\tsubpixel order: %s\n",
2895 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2896 seq_printf(m, "\tCEA rev: %d\n",
2897 connector->display_info.cea_rev);
2898 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002899 if (intel_encoder) {
2900 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2901 intel_encoder->type == INTEL_OUTPUT_EDP)
2902 intel_dp_info(m, intel_connector);
2903 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2904 intel_hdmi_info(m, intel_connector);
2905 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2906 intel_lvds_info(m, intel_connector);
2907 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002908
Jesse Barnesf103fc72014-02-20 12:39:57 -08002909 seq_printf(m, "\tmodes:\n");
2910 list_for_each_entry(mode, &connector->modes, head)
2911 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002912}
2913
Chris Wilson065f2ec22014-03-12 09:13:13 +00002914static bool cursor_active(struct drm_device *dev, int pipe)
2915{
2916 struct drm_i915_private *dev_priv = dev->dev_private;
2917 u32 state;
2918
2919 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002920 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002921 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002922 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002923
2924 return state;
2925}
2926
2927static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2928{
2929 struct drm_i915_private *dev_priv = dev->dev_private;
2930 u32 pos;
2931
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002932 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00002933
2934 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2935 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2936 *x = -*x;
2937
2938 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2939 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2940 *y = -*y;
2941
2942 return cursor_active(dev, pipe);
2943}
2944
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002945static int i915_display_info(struct seq_file *m, void *unused)
2946{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002947 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002948 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002949 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002950 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002951 struct drm_connector *connector;
2952
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002953 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002954 drm_modeset_lock_all(dev);
2955 seq_printf(m, "CRTC info\n");
2956 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002957 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002958 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002959 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002960 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002961
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002962 pipe_config = to_intel_crtc_state(crtc->base.state);
2963
Chris Wilson57127ef2014-07-04 08:20:11 +01002964 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00002965 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002966 yesno(pipe_config->base.active),
2967 pipe_config->pipe_src_w, pipe_config->pipe_src_h);
2968 if (pipe_config->base.active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002969 intel_crtc_info(m, crtc);
2970
Paulo Zanonia23dc652014-04-01 14:55:11 -03002971 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002972 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 +03002973 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08002974 x, y, crtc->base.cursor->state->crtc_w,
2975 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01002976 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002977 }
Daniel Vettercace8412014-05-22 17:56:31 +02002978
2979 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2980 yesno(!crtc->cpu_fifo_underrun_disabled),
2981 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002982 }
2983
2984 seq_printf(m, "\n");
2985 seq_printf(m, "Connector info\n");
2986 seq_printf(m, "--------------\n");
2987 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2988 intel_connector_info(m, connector);
2989 }
2990 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002991 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002992
2993 return 0;
2994}
2995
Ben Widawskye04934c2014-06-30 09:53:42 -07002996static int i915_semaphore_status(struct seq_file *m, void *unused)
2997{
2998 struct drm_info_node *node = (struct drm_info_node *) m->private;
2999 struct drm_device *dev = node->minor->dev;
3000 struct drm_i915_private *dev_priv = dev->dev_private;
3001 struct intel_engine_cs *ring;
3002 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
3003 int i, j, ret;
3004
3005 if (!i915_semaphore_is_enabled(dev)) {
3006 seq_puts(m, "Semaphores are disabled\n");
3007 return 0;
3008 }
3009
3010 ret = mutex_lock_interruptible(&dev->struct_mutex);
3011 if (ret)
3012 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003013 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003014
3015 if (IS_BROADWELL(dev)) {
3016 struct page *page;
3017 uint64_t *seqno;
3018
3019 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3020
3021 seqno = (uint64_t *)kmap_atomic(page);
3022 for_each_ring(ring, dev_priv, i) {
3023 uint64_t offset;
3024
3025 seq_printf(m, "%s\n", ring->name);
3026
3027 seq_puts(m, " Last signal:");
3028 for (j = 0; j < num_rings; j++) {
3029 offset = i * I915_NUM_RINGS + j;
3030 seq_printf(m, "0x%08llx (0x%02llx) ",
3031 seqno[offset], offset * 8);
3032 }
3033 seq_putc(m, '\n');
3034
3035 seq_puts(m, " Last wait: ");
3036 for (j = 0; j < num_rings; j++) {
3037 offset = i + (j * I915_NUM_RINGS);
3038 seq_printf(m, "0x%08llx (0x%02llx) ",
3039 seqno[offset], offset * 8);
3040 }
3041 seq_putc(m, '\n');
3042
3043 }
3044 kunmap_atomic(seqno);
3045 } else {
3046 seq_puts(m, " Last signal:");
3047 for_each_ring(ring, dev_priv, i)
3048 for (j = 0; j < num_rings; j++)
3049 seq_printf(m, "0x%08x\n",
3050 I915_READ(ring->semaphore.mbox.signal[j]));
3051 seq_putc(m, '\n');
3052 }
3053
3054 seq_puts(m, "\nSync seqno:\n");
3055 for_each_ring(ring, dev_priv, i) {
3056 for (j = 0; j < num_rings; j++) {
3057 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
3058 }
3059 seq_putc(m, '\n');
3060 }
3061 seq_putc(m, '\n');
3062
Paulo Zanoni03872062014-07-09 14:31:57 -03003063 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003064 mutex_unlock(&dev->struct_mutex);
3065 return 0;
3066}
3067
Daniel Vetter728e29d2014-06-25 22:01:53 +03003068static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3069{
3070 struct drm_info_node *node = (struct drm_info_node *) m->private;
3071 struct drm_device *dev = node->minor->dev;
3072 struct drm_i915_private *dev_priv = dev->dev_private;
3073 int i;
3074
3075 drm_modeset_lock_all(dev);
3076 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3077 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3078
3079 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02003080 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003081 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003082 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003083 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3084 seq_printf(m, " dpll_md: 0x%08x\n",
3085 pll->config.hw_state.dpll_md);
3086 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3087 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3088 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003089 }
3090 drm_modeset_unlock_all(dev);
3091
3092 return 0;
3093}
3094
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003095static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003096{
3097 int i;
3098 int ret;
3099 struct drm_info_node *node = (struct drm_info_node *) m->private;
3100 struct drm_device *dev = node->minor->dev;
3101 struct drm_i915_private *dev_priv = dev->dev_private;
3102
Arun Siluvery888b5992014-08-26 14:44:51 +01003103 ret = mutex_lock_interruptible(&dev->struct_mutex);
3104 if (ret)
3105 return ret;
3106
3107 intel_runtime_pm_get(dev_priv);
3108
Mika Kuoppala72253422014-10-07 17:21:26 +03003109 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
3110 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003111 u32 addr, mask, value, read;
3112 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003113
Mika Kuoppala72253422014-10-07 17:21:26 +03003114 addr = dev_priv->workarounds.reg[i].addr;
3115 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003116 value = dev_priv->workarounds.reg[i].value;
3117 read = I915_READ(addr);
3118 ok = (value & mask) == (read & mask);
3119 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
3120 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003121 }
3122
3123 intel_runtime_pm_put(dev_priv);
3124 mutex_unlock(&dev->struct_mutex);
3125
3126 return 0;
3127}
3128
Damien Lespiauc5511e42014-11-04 17:06:51 +00003129static int i915_ddb_info(struct seq_file *m, void *unused)
3130{
3131 struct drm_info_node *node = m->private;
3132 struct drm_device *dev = node->minor->dev;
3133 struct drm_i915_private *dev_priv = dev->dev_private;
3134 struct skl_ddb_allocation *ddb;
3135 struct skl_ddb_entry *entry;
3136 enum pipe pipe;
3137 int plane;
3138
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003139 if (INTEL_INFO(dev)->gen < 9)
3140 return 0;
3141
Damien Lespiauc5511e42014-11-04 17:06:51 +00003142 drm_modeset_lock_all(dev);
3143
3144 ddb = &dev_priv->wm.skl_hw.ddb;
3145
3146 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3147
3148 for_each_pipe(dev_priv, pipe) {
3149 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3150
Damien Lespiaudd740782015-02-28 14:54:08 +00003151 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003152 entry = &ddb->plane[pipe][plane];
3153 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3154 entry->start, entry->end,
3155 skl_ddb_entry_size(entry));
3156 }
3157
3158 entry = &ddb->cursor[pipe];
3159 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3160 entry->end, skl_ddb_entry_size(entry));
3161 }
3162
3163 drm_modeset_unlock_all(dev);
3164
3165 return 0;
3166}
3167
Vandana Kannana54746e2015-03-03 20:53:10 +05303168static void drrs_status_per_crtc(struct seq_file *m,
3169 struct drm_device *dev, struct intel_crtc *intel_crtc)
3170{
3171 struct intel_encoder *intel_encoder;
3172 struct drm_i915_private *dev_priv = dev->dev_private;
3173 struct i915_drrs *drrs = &dev_priv->drrs;
3174 int vrefresh = 0;
3175
3176 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3177 /* Encoder connected on this CRTC */
3178 switch (intel_encoder->type) {
3179 case INTEL_OUTPUT_EDP:
3180 seq_puts(m, "eDP:\n");
3181 break;
3182 case INTEL_OUTPUT_DSI:
3183 seq_puts(m, "DSI:\n");
3184 break;
3185 case INTEL_OUTPUT_HDMI:
3186 seq_puts(m, "HDMI:\n");
3187 break;
3188 case INTEL_OUTPUT_DISPLAYPORT:
3189 seq_puts(m, "DP:\n");
3190 break;
3191 default:
3192 seq_printf(m, "Other encoder (id=%d).\n",
3193 intel_encoder->type);
3194 return;
3195 }
3196 }
3197
3198 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3199 seq_puts(m, "\tVBT: DRRS_type: Static");
3200 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3201 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3202 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3203 seq_puts(m, "\tVBT: DRRS_type: None");
3204 else
3205 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3206
3207 seq_puts(m, "\n\n");
3208
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003209 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303210 struct intel_panel *panel;
3211
3212 mutex_lock(&drrs->mutex);
3213 /* DRRS Supported */
3214 seq_puts(m, "\tDRRS Supported: Yes\n");
3215
3216 /* disable_drrs() will make drrs->dp NULL */
3217 if (!drrs->dp) {
3218 seq_puts(m, "Idleness DRRS: Disabled");
3219 mutex_unlock(&drrs->mutex);
3220 return;
3221 }
3222
3223 panel = &drrs->dp->attached_connector->panel;
3224 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3225 drrs->busy_frontbuffer_bits);
3226
3227 seq_puts(m, "\n\t\t");
3228 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3229 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3230 vrefresh = panel->fixed_mode->vrefresh;
3231 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3232 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3233 vrefresh = panel->downclock_mode->vrefresh;
3234 } else {
3235 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3236 drrs->refresh_rate_type);
3237 mutex_unlock(&drrs->mutex);
3238 return;
3239 }
3240 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3241
3242 seq_puts(m, "\n\t\t");
3243 mutex_unlock(&drrs->mutex);
3244 } else {
3245 /* DRRS not supported. Print the VBT parameter*/
3246 seq_puts(m, "\tDRRS Supported : No");
3247 }
3248 seq_puts(m, "\n");
3249}
3250
3251static int i915_drrs_status(struct seq_file *m, void *unused)
3252{
3253 struct drm_info_node *node = m->private;
3254 struct drm_device *dev = node->minor->dev;
3255 struct intel_crtc *intel_crtc;
3256 int active_crtc_cnt = 0;
3257
3258 for_each_intel_crtc(dev, intel_crtc) {
3259 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3260
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003261 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303262 active_crtc_cnt++;
3263 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3264
3265 drrs_status_per_crtc(m, dev, intel_crtc);
3266 }
3267
3268 drm_modeset_unlock(&intel_crtc->base.mutex);
3269 }
3270
3271 if (!active_crtc_cnt)
3272 seq_puts(m, "No active crtc found\n");
3273
3274 return 0;
3275}
3276
Damien Lespiau07144422013-10-15 18:55:40 +01003277struct pipe_crc_info {
3278 const char *name;
3279 struct drm_device *dev;
3280 enum pipe pipe;
3281};
3282
Dave Airlie11bed952014-05-12 15:22:27 +10003283static int i915_dp_mst_info(struct seq_file *m, void *unused)
3284{
3285 struct drm_info_node *node = (struct drm_info_node *) m->private;
3286 struct drm_device *dev = node->minor->dev;
3287 struct drm_encoder *encoder;
3288 struct intel_encoder *intel_encoder;
3289 struct intel_digital_port *intel_dig_port;
3290 drm_modeset_lock_all(dev);
3291 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3292 intel_encoder = to_intel_encoder(encoder);
3293 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3294 continue;
3295 intel_dig_port = enc_to_dig_port(encoder);
3296 if (!intel_dig_port->dp.can_mst)
3297 continue;
3298
3299 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3300 }
3301 drm_modeset_unlock_all(dev);
3302 return 0;
3303}
3304
Damien Lespiau07144422013-10-15 18:55:40 +01003305static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003306{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003307 struct pipe_crc_info *info = inode->i_private;
3308 struct drm_i915_private *dev_priv = info->dev->dev_private;
3309 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3310
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003311 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3312 return -ENODEV;
3313
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003314 spin_lock_irq(&pipe_crc->lock);
3315
3316 if (pipe_crc->opened) {
3317 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003318 return -EBUSY; /* already open */
3319 }
3320
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003321 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003322 filep->private_data = inode->i_private;
3323
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003324 spin_unlock_irq(&pipe_crc->lock);
3325
Damien Lespiau07144422013-10-15 18:55:40 +01003326 return 0;
3327}
3328
3329static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3330{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003331 struct pipe_crc_info *info = inode->i_private;
3332 struct drm_i915_private *dev_priv = info->dev->dev_private;
3333 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3334
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003335 spin_lock_irq(&pipe_crc->lock);
3336 pipe_crc->opened = false;
3337 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003338
Damien Lespiau07144422013-10-15 18:55:40 +01003339 return 0;
3340}
3341
3342/* (6 fields, 8 chars each, space separated (5) + '\n') */
3343#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3344/* account for \'0' */
3345#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3346
3347static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3348{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003349 assert_spin_locked(&pipe_crc->lock);
3350 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3351 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003352}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003353
Damien Lespiau07144422013-10-15 18:55:40 +01003354static ssize_t
3355i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3356 loff_t *pos)
3357{
3358 struct pipe_crc_info *info = filep->private_data;
3359 struct drm_device *dev = info->dev;
3360 struct drm_i915_private *dev_priv = dev->dev_private;
3361 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3362 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003363 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003364 ssize_t bytes_read;
3365
3366 /*
3367 * Don't allow user space to provide buffers not big enough to hold
3368 * a line of data.
3369 */
3370 if (count < PIPE_CRC_LINE_LEN)
3371 return -EINVAL;
3372
3373 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3374 return 0;
3375
3376 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003377 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003378 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003379 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003380
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003381 if (filep->f_flags & O_NONBLOCK) {
3382 spin_unlock_irq(&pipe_crc->lock);
3383 return -EAGAIN;
3384 }
3385
3386 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3387 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3388 if (ret) {
3389 spin_unlock_irq(&pipe_crc->lock);
3390 return ret;
3391 }
Damien Lespiau07144422013-10-15 18:55:40 +01003392 }
3393
3394 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003395 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003396
Damien Lespiau07144422013-10-15 18:55:40 +01003397 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003398 while (n_entries > 0) {
3399 struct intel_pipe_crc_entry *entry =
3400 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003401 int ret;
3402
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003403 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3404 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3405 break;
3406
3407 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3408 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3409
Damien Lespiau07144422013-10-15 18:55:40 +01003410 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3411 "%8u %8x %8x %8x %8x %8x\n",
3412 entry->frame, entry->crc[0],
3413 entry->crc[1], entry->crc[2],
3414 entry->crc[3], entry->crc[4]);
3415
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003416 spin_unlock_irq(&pipe_crc->lock);
3417
3418 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003419 if (ret == PIPE_CRC_LINE_LEN)
3420 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003421
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003422 user_buf += PIPE_CRC_LINE_LEN;
3423 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003424
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003425 spin_lock_irq(&pipe_crc->lock);
3426 }
3427
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003428 spin_unlock_irq(&pipe_crc->lock);
3429
Damien Lespiau07144422013-10-15 18:55:40 +01003430 return bytes_read;
3431}
3432
3433static const struct file_operations i915_pipe_crc_fops = {
3434 .owner = THIS_MODULE,
3435 .open = i915_pipe_crc_open,
3436 .read = i915_pipe_crc_read,
3437 .release = i915_pipe_crc_release,
3438};
3439
3440static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3441 {
3442 .name = "i915_pipe_A_crc",
3443 .pipe = PIPE_A,
3444 },
3445 {
3446 .name = "i915_pipe_B_crc",
3447 .pipe = PIPE_B,
3448 },
3449 {
3450 .name = "i915_pipe_C_crc",
3451 .pipe = PIPE_C,
3452 },
3453};
3454
3455static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3456 enum pipe pipe)
3457{
3458 struct drm_device *dev = minor->dev;
3459 struct dentry *ent;
3460 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3461
3462 info->dev = dev;
3463 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3464 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003465 if (!ent)
3466 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003467
3468 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003469}
3470
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003471static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003472 "none",
3473 "plane1",
3474 "plane2",
3475 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003476 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003477 "TV",
3478 "DP-B",
3479 "DP-C",
3480 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003481 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003482};
3483
3484static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3485{
3486 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3487 return pipe_crc_sources[source];
3488}
3489
Damien Lespiaubd9db022013-10-15 18:55:36 +01003490static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003491{
3492 struct drm_device *dev = m->private;
3493 struct drm_i915_private *dev_priv = dev->dev_private;
3494 int i;
3495
3496 for (i = 0; i < I915_MAX_PIPES; i++)
3497 seq_printf(m, "%c %s\n", pipe_name(i),
3498 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3499
3500 return 0;
3501}
3502
Damien Lespiaubd9db022013-10-15 18:55:36 +01003503static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003504{
3505 struct drm_device *dev = inode->i_private;
3506
Damien Lespiaubd9db022013-10-15 18:55:36 +01003507 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003508}
3509
Daniel Vetter46a19182013-11-01 10:50:20 +01003510static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003511 uint32_t *val)
3512{
Daniel Vetter46a19182013-11-01 10:50:20 +01003513 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3514 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3515
3516 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003517 case INTEL_PIPE_CRC_SOURCE_PIPE:
3518 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3519 break;
3520 case INTEL_PIPE_CRC_SOURCE_NONE:
3521 *val = 0;
3522 break;
3523 default:
3524 return -EINVAL;
3525 }
3526
3527 return 0;
3528}
3529
Daniel Vetter46a19182013-11-01 10:50:20 +01003530static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3531 enum intel_pipe_crc_source *source)
3532{
3533 struct intel_encoder *encoder;
3534 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003535 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003536 int ret = 0;
3537
3538 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3539
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003540 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003541 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003542 if (!encoder->base.crtc)
3543 continue;
3544
3545 crtc = to_intel_crtc(encoder->base.crtc);
3546
3547 if (crtc->pipe != pipe)
3548 continue;
3549
3550 switch (encoder->type) {
3551 case INTEL_OUTPUT_TVOUT:
3552 *source = INTEL_PIPE_CRC_SOURCE_TV;
3553 break;
3554 case INTEL_OUTPUT_DISPLAYPORT:
3555 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003556 dig_port = enc_to_dig_port(&encoder->base);
3557 switch (dig_port->port) {
3558 case PORT_B:
3559 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3560 break;
3561 case PORT_C:
3562 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3563 break;
3564 case PORT_D:
3565 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3566 break;
3567 default:
3568 WARN(1, "nonexisting DP port %c\n",
3569 port_name(dig_port->port));
3570 break;
3571 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003572 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003573 default:
3574 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003575 }
3576 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003577 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003578
3579 return ret;
3580}
3581
3582static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3583 enum pipe pipe,
3584 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003585 uint32_t *val)
3586{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003587 struct drm_i915_private *dev_priv = dev->dev_private;
3588 bool need_stable_symbols = false;
3589
Daniel Vetter46a19182013-11-01 10:50:20 +01003590 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3591 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3592 if (ret)
3593 return ret;
3594 }
3595
3596 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003597 case INTEL_PIPE_CRC_SOURCE_PIPE:
3598 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3599 break;
3600 case INTEL_PIPE_CRC_SOURCE_DP_B:
3601 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003602 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003603 break;
3604 case INTEL_PIPE_CRC_SOURCE_DP_C:
3605 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003606 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003607 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003608 case INTEL_PIPE_CRC_SOURCE_DP_D:
3609 if (!IS_CHERRYVIEW(dev))
3610 return -EINVAL;
3611 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3612 need_stable_symbols = true;
3613 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003614 case INTEL_PIPE_CRC_SOURCE_NONE:
3615 *val = 0;
3616 break;
3617 default:
3618 return -EINVAL;
3619 }
3620
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003621 /*
3622 * When the pipe CRC tap point is after the transcoders we need
3623 * to tweak symbol-level features to produce a deterministic series of
3624 * symbols for a given frame. We need to reset those features only once
3625 * a frame (instead of every nth symbol):
3626 * - DC-balance: used to ensure a better clock recovery from the data
3627 * link (SDVO)
3628 * - DisplayPort scrambling: used for EMI reduction
3629 */
3630 if (need_stable_symbols) {
3631 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3632
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003633 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003634 switch (pipe) {
3635 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003636 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003637 break;
3638 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003639 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003640 break;
3641 case PIPE_C:
3642 tmp |= PIPE_C_SCRAMBLE_RESET;
3643 break;
3644 default:
3645 return -EINVAL;
3646 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003647 I915_WRITE(PORT_DFT2_G4X, tmp);
3648 }
3649
Daniel Vetter7ac01292013-10-18 16:37:06 +02003650 return 0;
3651}
3652
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003653static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003654 enum pipe pipe,
3655 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003656 uint32_t *val)
3657{
Daniel Vetter84093602013-11-01 10:50:21 +01003658 struct drm_i915_private *dev_priv = dev->dev_private;
3659 bool need_stable_symbols = false;
3660
Daniel Vetter46a19182013-11-01 10:50:20 +01003661 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3662 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3663 if (ret)
3664 return ret;
3665 }
3666
3667 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003668 case INTEL_PIPE_CRC_SOURCE_PIPE:
3669 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3670 break;
3671 case INTEL_PIPE_CRC_SOURCE_TV:
3672 if (!SUPPORTS_TV(dev))
3673 return -EINVAL;
3674 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3675 break;
3676 case INTEL_PIPE_CRC_SOURCE_DP_B:
3677 if (!IS_G4X(dev))
3678 return -EINVAL;
3679 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003680 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003681 break;
3682 case INTEL_PIPE_CRC_SOURCE_DP_C:
3683 if (!IS_G4X(dev))
3684 return -EINVAL;
3685 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003686 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003687 break;
3688 case INTEL_PIPE_CRC_SOURCE_DP_D:
3689 if (!IS_G4X(dev))
3690 return -EINVAL;
3691 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003692 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003693 break;
3694 case INTEL_PIPE_CRC_SOURCE_NONE:
3695 *val = 0;
3696 break;
3697 default:
3698 return -EINVAL;
3699 }
3700
Daniel Vetter84093602013-11-01 10:50:21 +01003701 /*
3702 * When the pipe CRC tap point is after the transcoders we need
3703 * to tweak symbol-level features to produce a deterministic series of
3704 * symbols for a given frame. We need to reset those features only once
3705 * a frame (instead of every nth symbol):
3706 * - DC-balance: used to ensure a better clock recovery from the data
3707 * link (SDVO)
3708 * - DisplayPort scrambling: used for EMI reduction
3709 */
3710 if (need_stable_symbols) {
3711 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3712
3713 WARN_ON(!IS_G4X(dev));
3714
3715 I915_WRITE(PORT_DFT_I9XX,
3716 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3717
3718 if (pipe == PIPE_A)
3719 tmp |= PIPE_A_SCRAMBLE_RESET;
3720 else
3721 tmp |= PIPE_B_SCRAMBLE_RESET;
3722
3723 I915_WRITE(PORT_DFT2_G4X, tmp);
3724 }
3725
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003726 return 0;
3727}
3728
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003729static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3730 enum pipe pipe)
3731{
3732 struct drm_i915_private *dev_priv = dev->dev_private;
3733 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3734
Ville Syrjäläeb736672014-12-09 21:28:28 +02003735 switch (pipe) {
3736 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003737 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003738 break;
3739 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003740 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003741 break;
3742 case PIPE_C:
3743 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3744 break;
3745 default:
3746 return;
3747 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003748 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3749 tmp &= ~DC_BALANCE_RESET_VLV;
3750 I915_WRITE(PORT_DFT2_G4X, tmp);
3751
3752}
3753
Daniel Vetter84093602013-11-01 10:50:21 +01003754static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3755 enum pipe pipe)
3756{
3757 struct drm_i915_private *dev_priv = dev->dev_private;
3758 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3759
3760 if (pipe == PIPE_A)
3761 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3762 else
3763 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3764 I915_WRITE(PORT_DFT2_G4X, tmp);
3765
3766 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3767 I915_WRITE(PORT_DFT_I9XX,
3768 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3769 }
3770}
3771
Daniel Vetter46a19182013-11-01 10:50:20 +01003772static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003773 uint32_t *val)
3774{
Daniel Vetter46a19182013-11-01 10:50:20 +01003775 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3776 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3777
3778 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003779 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3780 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3781 break;
3782 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3783 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3784 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003785 case INTEL_PIPE_CRC_SOURCE_PIPE:
3786 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3787 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003788 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003789 *val = 0;
3790 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003791 default:
3792 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003793 }
3794
3795 return 0;
3796}
3797
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003798static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003799{
3800 struct drm_i915_private *dev_priv = dev->dev_private;
3801 struct intel_crtc *crtc =
3802 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003803 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003804 struct drm_atomic_state *state;
3805 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003806
3807 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003808 state = drm_atomic_state_alloc(dev);
3809 if (!state) {
3810 ret = -ENOMEM;
3811 goto out;
3812 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003813
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003814 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
3815 pipe_config = intel_atomic_get_crtc_state(state, crtc);
3816 if (IS_ERR(pipe_config)) {
3817 ret = PTR_ERR(pipe_config);
3818 goto out;
3819 }
3820
3821 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003822 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003823 pipe_config->pch_pfit.enabled != enable)
3824 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003825
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003826 ret = drm_atomic_commit(state);
3827out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003828 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003829 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
3830 if (ret)
3831 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003832}
3833
3834static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3835 enum pipe pipe,
3836 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003837 uint32_t *val)
3838{
Daniel Vetter46a19182013-11-01 10:50:20 +01003839 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3840 *source = INTEL_PIPE_CRC_SOURCE_PF;
3841
3842 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003843 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3844 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3845 break;
3846 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3847 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3848 break;
3849 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003850 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003851 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003852
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003853 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3854 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003855 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003856 *val = 0;
3857 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003858 default:
3859 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003860 }
3861
3862 return 0;
3863}
3864
Daniel Vetter926321d2013-10-16 13:30:34 +02003865static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3866 enum intel_pipe_crc_source source)
3867{
3868 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003869 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003870 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3871 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003872 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003873 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003874
Damien Lespiaucc3da172013-10-15 18:55:31 +01003875 if (pipe_crc->source == source)
3876 return 0;
3877
Damien Lespiauae676fc2013-10-15 18:55:32 +01003878 /* forbid changing the source without going back to 'none' */
3879 if (pipe_crc->source && source)
3880 return -EINVAL;
3881
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003882 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3883 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3884 return -EIO;
3885 }
3886
Daniel Vetter52f843f2013-10-21 17:26:38 +02003887 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003888 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003889 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003890 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003891 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003892 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003893 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003894 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003895 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003896 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003897
3898 if (ret != 0)
3899 return ret;
3900
Damien Lespiau4b584362013-10-15 18:55:33 +01003901 /* none -> real source transition */
3902 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003903 struct intel_pipe_crc_entry *entries;
3904
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003905 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3906 pipe_name(pipe), pipe_crc_source_name(source));
3907
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003908 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3909 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003910 GFP_KERNEL);
3911 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003912 return -ENOMEM;
3913
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003914 /*
3915 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3916 * enabled and disabled dynamically based on package C states,
3917 * user space can't make reliable use of the CRCs, so let's just
3918 * completely disable it.
3919 */
3920 hsw_disable_ips(crtc);
3921
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003922 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003923 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003924 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003925 pipe_crc->head = 0;
3926 pipe_crc->tail = 0;
3927 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003928 }
3929
Damien Lespiaucc3da172013-10-15 18:55:31 +01003930 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003931
Daniel Vetter926321d2013-10-16 13:30:34 +02003932 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3933 POSTING_READ(PIPE_CRC_CTL(pipe));
3934
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003935 /* real source -> none transition */
3936 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003937 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003938 struct intel_crtc *crtc =
3939 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003940
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003941 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3942 pipe_name(pipe));
3943
Daniel Vettera33d7102014-06-06 08:22:08 +02003944 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003945 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02003946 intel_wait_for_vblank(dev, pipe);
3947 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003948
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003949 spin_lock_irq(&pipe_crc->lock);
3950 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003951 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003952 pipe_crc->head = 0;
3953 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003954 spin_unlock_irq(&pipe_crc->lock);
3955
3956 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003957
3958 if (IS_G4X(dev))
3959 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003960 else if (IS_VALLEYVIEW(dev))
3961 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003962 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003963 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003964
3965 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003966 }
3967
Daniel Vetter926321d2013-10-16 13:30:34 +02003968 return 0;
3969}
3970
3971/*
3972 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003973 * command: wsp* object wsp+ name wsp+ source wsp*
3974 * object: 'pipe'
3975 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003976 * source: (none | plane1 | plane2 | pf)
3977 * wsp: (#0x20 | #0x9 | #0xA)+
3978 *
3979 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003980 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3981 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003982 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003983static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003984{
3985 int n_words = 0;
3986
3987 while (*buf) {
3988 char *end;
3989
3990 /* skip leading white space */
3991 buf = skip_spaces(buf);
3992 if (!*buf)
3993 break; /* end of buffer */
3994
3995 /* find end of word */
3996 for (end = buf; *end && !isspace(*end); end++)
3997 ;
3998
3999 if (n_words == max_words) {
4000 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4001 max_words);
4002 return -EINVAL; /* ran out of words[] before bytes */
4003 }
4004
4005 if (*end)
4006 *end++ = '\0';
4007 words[n_words++] = buf;
4008 buf = end;
4009 }
4010
4011 return n_words;
4012}
4013
Damien Lespiaub94dec82013-10-15 18:55:35 +01004014enum intel_pipe_crc_object {
4015 PIPE_CRC_OBJECT_PIPE,
4016};
4017
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004018static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004019 "pipe",
4020};
4021
4022static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004023display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004024{
4025 int i;
4026
4027 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4028 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004029 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004030 return 0;
4031 }
4032
4033 return -EINVAL;
4034}
4035
Damien Lespiaubd9db022013-10-15 18:55:36 +01004036static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004037{
4038 const char name = buf[0];
4039
4040 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4041 return -EINVAL;
4042
4043 *pipe = name - 'A';
4044
4045 return 0;
4046}
4047
4048static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004049display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004050{
4051 int i;
4052
4053 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4054 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004055 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004056 return 0;
4057 }
4058
4059 return -EINVAL;
4060}
4061
Damien Lespiaubd9db022013-10-15 18:55:36 +01004062static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004063{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004064#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004065 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004066 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004067 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004068 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004069 enum intel_pipe_crc_source source;
4070
Damien Lespiaubd9db022013-10-15 18:55:36 +01004071 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004072 if (n_words != N_WORDS) {
4073 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4074 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004075 return -EINVAL;
4076 }
4077
Damien Lespiaubd9db022013-10-15 18:55:36 +01004078 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004079 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004080 return -EINVAL;
4081 }
4082
Damien Lespiaubd9db022013-10-15 18:55:36 +01004083 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004084 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4085 return -EINVAL;
4086 }
4087
Damien Lespiaubd9db022013-10-15 18:55:36 +01004088 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004089 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004090 return -EINVAL;
4091 }
4092
4093 return pipe_crc_set_source(dev, pipe, source);
4094}
4095
Damien Lespiaubd9db022013-10-15 18:55:36 +01004096static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4097 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004098{
4099 struct seq_file *m = file->private_data;
4100 struct drm_device *dev = m->private;
4101 char *tmpbuf;
4102 int ret;
4103
4104 if (len == 0)
4105 return 0;
4106
4107 if (len > PAGE_SIZE - 1) {
4108 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4109 PAGE_SIZE);
4110 return -E2BIG;
4111 }
4112
4113 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4114 if (!tmpbuf)
4115 return -ENOMEM;
4116
4117 if (copy_from_user(tmpbuf, ubuf, len)) {
4118 ret = -EFAULT;
4119 goto out;
4120 }
4121 tmpbuf[len] = '\0';
4122
Damien Lespiaubd9db022013-10-15 18:55:36 +01004123 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004124
4125out:
4126 kfree(tmpbuf);
4127 if (ret < 0)
4128 return ret;
4129
4130 *offp += len;
4131 return len;
4132}
4133
Damien Lespiaubd9db022013-10-15 18:55:36 +01004134static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004135 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004136 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004137 .read = seq_read,
4138 .llseek = seq_lseek,
4139 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004140 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004141};
4142
Todd Previteeb3394fa2015-04-18 00:04:19 -07004143static ssize_t i915_displayport_test_active_write(struct file *file,
4144 const char __user *ubuf,
4145 size_t len, loff_t *offp)
4146{
4147 char *input_buffer;
4148 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004149 struct drm_device *dev;
4150 struct drm_connector *connector;
4151 struct list_head *connector_list;
4152 struct intel_dp *intel_dp;
4153 int val = 0;
4154
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304155 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004156
Todd Previteeb3394fa2015-04-18 00:04:19 -07004157 connector_list = &dev->mode_config.connector_list;
4158
4159 if (len == 0)
4160 return 0;
4161
4162 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4163 if (!input_buffer)
4164 return -ENOMEM;
4165
4166 if (copy_from_user(input_buffer, ubuf, len)) {
4167 status = -EFAULT;
4168 goto out;
4169 }
4170
4171 input_buffer[len] = '\0';
4172 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4173
4174 list_for_each_entry(connector, connector_list, head) {
4175
4176 if (connector->connector_type !=
4177 DRM_MODE_CONNECTOR_DisplayPort)
4178 continue;
4179
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304180 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004181 connector->encoder != NULL) {
4182 intel_dp = enc_to_intel_dp(connector->encoder);
4183 status = kstrtoint(input_buffer, 10, &val);
4184 if (status < 0)
4185 goto out;
4186 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4187 /* To prevent erroneous activation of the compliance
4188 * testing code, only accept an actual value of 1 here
4189 */
4190 if (val == 1)
4191 intel_dp->compliance_test_active = 1;
4192 else
4193 intel_dp->compliance_test_active = 0;
4194 }
4195 }
4196out:
4197 kfree(input_buffer);
4198 if (status < 0)
4199 return status;
4200
4201 *offp += len;
4202 return len;
4203}
4204
4205static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4206{
4207 struct drm_device *dev = m->private;
4208 struct drm_connector *connector;
4209 struct list_head *connector_list = &dev->mode_config.connector_list;
4210 struct intel_dp *intel_dp;
4211
Todd Previteeb3394fa2015-04-18 00:04:19 -07004212 list_for_each_entry(connector, connector_list, head) {
4213
4214 if (connector->connector_type !=
4215 DRM_MODE_CONNECTOR_DisplayPort)
4216 continue;
4217
4218 if (connector->status == connector_status_connected &&
4219 connector->encoder != NULL) {
4220 intel_dp = enc_to_intel_dp(connector->encoder);
4221 if (intel_dp->compliance_test_active)
4222 seq_puts(m, "1");
4223 else
4224 seq_puts(m, "0");
4225 } else
4226 seq_puts(m, "0");
4227 }
4228
4229 return 0;
4230}
4231
4232static int i915_displayport_test_active_open(struct inode *inode,
4233 struct file *file)
4234{
4235 struct drm_device *dev = inode->i_private;
4236
4237 return single_open(file, i915_displayport_test_active_show, dev);
4238}
4239
4240static const struct file_operations i915_displayport_test_active_fops = {
4241 .owner = THIS_MODULE,
4242 .open = i915_displayport_test_active_open,
4243 .read = seq_read,
4244 .llseek = seq_lseek,
4245 .release = single_release,
4246 .write = i915_displayport_test_active_write
4247};
4248
4249static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4250{
4251 struct drm_device *dev = m->private;
4252 struct drm_connector *connector;
4253 struct list_head *connector_list = &dev->mode_config.connector_list;
4254 struct intel_dp *intel_dp;
4255
Todd Previteeb3394fa2015-04-18 00:04:19 -07004256 list_for_each_entry(connector, connector_list, head) {
4257
4258 if (connector->connector_type !=
4259 DRM_MODE_CONNECTOR_DisplayPort)
4260 continue;
4261
4262 if (connector->status == connector_status_connected &&
4263 connector->encoder != NULL) {
4264 intel_dp = enc_to_intel_dp(connector->encoder);
4265 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4266 } else
4267 seq_puts(m, "0");
4268 }
4269
4270 return 0;
4271}
4272static int i915_displayport_test_data_open(struct inode *inode,
4273 struct file *file)
4274{
4275 struct drm_device *dev = inode->i_private;
4276
4277 return single_open(file, i915_displayport_test_data_show, dev);
4278}
4279
4280static const struct file_operations i915_displayport_test_data_fops = {
4281 .owner = THIS_MODULE,
4282 .open = i915_displayport_test_data_open,
4283 .read = seq_read,
4284 .llseek = seq_lseek,
4285 .release = single_release
4286};
4287
4288static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4289{
4290 struct drm_device *dev = m->private;
4291 struct drm_connector *connector;
4292 struct list_head *connector_list = &dev->mode_config.connector_list;
4293 struct intel_dp *intel_dp;
4294
Todd Previteeb3394fa2015-04-18 00:04:19 -07004295 list_for_each_entry(connector, connector_list, head) {
4296
4297 if (connector->connector_type !=
4298 DRM_MODE_CONNECTOR_DisplayPort)
4299 continue;
4300
4301 if (connector->status == connector_status_connected &&
4302 connector->encoder != NULL) {
4303 intel_dp = enc_to_intel_dp(connector->encoder);
4304 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4305 } else
4306 seq_puts(m, "0");
4307 }
4308
4309 return 0;
4310}
4311
4312static int i915_displayport_test_type_open(struct inode *inode,
4313 struct file *file)
4314{
4315 struct drm_device *dev = inode->i_private;
4316
4317 return single_open(file, i915_displayport_test_type_show, dev);
4318}
4319
4320static const struct file_operations i915_displayport_test_type_fops = {
4321 .owner = THIS_MODULE,
4322 .open = i915_displayport_test_type_open,
4323 .read = seq_read,
4324 .llseek = seq_lseek,
4325 .release = single_release
4326};
4327
Damien Lespiau97e94b22014-11-04 17:06:50 +00004328static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004329{
4330 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004331 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004332 int num_levels;
4333
4334 if (IS_CHERRYVIEW(dev))
4335 num_levels = 3;
4336 else if (IS_VALLEYVIEW(dev))
4337 num_levels = 1;
4338 else
4339 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004340
4341 drm_modeset_lock_all(dev);
4342
4343 for (level = 0; level < num_levels; level++) {
4344 unsigned int latency = wm[level];
4345
Damien Lespiau97e94b22014-11-04 17:06:50 +00004346 /*
4347 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004348 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004349 */
Ville Syrjäläde38b952015-06-24 22:00:09 +03004350 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004351 latency *= 10;
4352 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004353 latency *= 5;
4354
4355 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004356 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004357 }
4358
4359 drm_modeset_unlock_all(dev);
4360}
4361
4362static int pri_wm_latency_show(struct seq_file *m, void *data)
4363{
4364 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004365 struct drm_i915_private *dev_priv = dev->dev_private;
4366 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004367
Damien Lespiau97e94b22014-11-04 17:06:50 +00004368 if (INTEL_INFO(dev)->gen >= 9)
4369 latencies = dev_priv->wm.skl_latency;
4370 else
4371 latencies = to_i915(dev)->wm.pri_latency;
4372
4373 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004374
4375 return 0;
4376}
4377
4378static int spr_wm_latency_show(struct seq_file *m, void *data)
4379{
4380 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004381 struct drm_i915_private *dev_priv = dev->dev_private;
4382 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004383
Damien Lespiau97e94b22014-11-04 17:06:50 +00004384 if (INTEL_INFO(dev)->gen >= 9)
4385 latencies = dev_priv->wm.skl_latency;
4386 else
4387 latencies = to_i915(dev)->wm.spr_latency;
4388
4389 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004390
4391 return 0;
4392}
4393
4394static int cur_wm_latency_show(struct seq_file *m, void *data)
4395{
4396 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004397 struct drm_i915_private *dev_priv = dev->dev_private;
4398 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004399
Damien Lespiau97e94b22014-11-04 17:06:50 +00004400 if (INTEL_INFO(dev)->gen >= 9)
4401 latencies = dev_priv->wm.skl_latency;
4402 else
4403 latencies = to_i915(dev)->wm.cur_latency;
4404
4405 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004406
4407 return 0;
4408}
4409
4410static int pri_wm_latency_open(struct inode *inode, struct file *file)
4411{
4412 struct drm_device *dev = inode->i_private;
4413
Ville Syrjäläde38b952015-06-24 22:00:09 +03004414 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004415 return -ENODEV;
4416
4417 return single_open(file, pri_wm_latency_show, dev);
4418}
4419
4420static int spr_wm_latency_open(struct inode *inode, struct file *file)
4421{
4422 struct drm_device *dev = inode->i_private;
4423
Sonika Jindal9ad02572014-07-21 15:23:39 +05304424 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004425 return -ENODEV;
4426
4427 return single_open(file, spr_wm_latency_show, dev);
4428}
4429
4430static int cur_wm_latency_open(struct inode *inode, struct file *file)
4431{
4432 struct drm_device *dev = inode->i_private;
4433
Sonika Jindal9ad02572014-07-21 15:23:39 +05304434 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004435 return -ENODEV;
4436
4437 return single_open(file, cur_wm_latency_show, dev);
4438}
4439
4440static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004441 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004442{
4443 struct seq_file *m = file->private_data;
4444 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004445 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004446 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004447 int level;
4448 int ret;
4449 char tmp[32];
4450
Ville Syrjäläde38b952015-06-24 22:00:09 +03004451 if (IS_CHERRYVIEW(dev))
4452 num_levels = 3;
4453 else if (IS_VALLEYVIEW(dev))
4454 num_levels = 1;
4455 else
4456 num_levels = ilk_wm_max_level(dev) + 1;
4457
Ville Syrjälä369a1342014-01-22 14:36:08 +02004458 if (len >= sizeof(tmp))
4459 return -EINVAL;
4460
4461 if (copy_from_user(tmp, ubuf, len))
4462 return -EFAULT;
4463
4464 tmp[len] = '\0';
4465
Damien Lespiau97e94b22014-11-04 17:06:50 +00004466 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4467 &new[0], &new[1], &new[2], &new[3],
4468 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004469 if (ret != num_levels)
4470 return -EINVAL;
4471
4472 drm_modeset_lock_all(dev);
4473
4474 for (level = 0; level < num_levels; level++)
4475 wm[level] = new[level];
4476
4477 drm_modeset_unlock_all(dev);
4478
4479 return len;
4480}
4481
4482
4483static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4484 size_t len, loff_t *offp)
4485{
4486 struct seq_file *m = file->private_data;
4487 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004488 struct drm_i915_private *dev_priv = dev->dev_private;
4489 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004490
Damien Lespiau97e94b22014-11-04 17:06:50 +00004491 if (INTEL_INFO(dev)->gen >= 9)
4492 latencies = dev_priv->wm.skl_latency;
4493 else
4494 latencies = to_i915(dev)->wm.pri_latency;
4495
4496 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004497}
4498
4499static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4500 size_t len, loff_t *offp)
4501{
4502 struct seq_file *m = file->private_data;
4503 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004504 struct drm_i915_private *dev_priv = dev->dev_private;
4505 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004506
Damien Lespiau97e94b22014-11-04 17:06:50 +00004507 if (INTEL_INFO(dev)->gen >= 9)
4508 latencies = dev_priv->wm.skl_latency;
4509 else
4510 latencies = to_i915(dev)->wm.spr_latency;
4511
4512 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004513}
4514
4515static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4516 size_t len, loff_t *offp)
4517{
4518 struct seq_file *m = file->private_data;
4519 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004520 struct drm_i915_private *dev_priv = dev->dev_private;
4521 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004522
Damien Lespiau97e94b22014-11-04 17:06:50 +00004523 if (INTEL_INFO(dev)->gen >= 9)
4524 latencies = dev_priv->wm.skl_latency;
4525 else
4526 latencies = to_i915(dev)->wm.cur_latency;
4527
4528 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004529}
4530
4531static const struct file_operations i915_pri_wm_latency_fops = {
4532 .owner = THIS_MODULE,
4533 .open = pri_wm_latency_open,
4534 .read = seq_read,
4535 .llseek = seq_lseek,
4536 .release = single_release,
4537 .write = pri_wm_latency_write
4538};
4539
4540static const struct file_operations i915_spr_wm_latency_fops = {
4541 .owner = THIS_MODULE,
4542 .open = spr_wm_latency_open,
4543 .read = seq_read,
4544 .llseek = seq_lseek,
4545 .release = single_release,
4546 .write = spr_wm_latency_write
4547};
4548
4549static const struct file_operations i915_cur_wm_latency_fops = {
4550 .owner = THIS_MODULE,
4551 .open = cur_wm_latency_open,
4552 .read = seq_read,
4553 .llseek = seq_lseek,
4554 .release = single_release,
4555 .write = cur_wm_latency_write
4556};
4557
Kees Cook647416f2013-03-10 14:10:06 -07004558static int
4559i915_wedged_get(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;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004562 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004563
Kees Cook647416f2013-03-10 14:10:06 -07004564 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004565
Kees Cook647416f2013-03-10 14:10:06 -07004566 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004567}
4568
Kees Cook647416f2013-03-10 14:10:06 -07004569static int
4570i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004571{
Kees Cook647416f2013-03-10 14:10:06 -07004572 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004573 struct drm_i915_private *dev_priv = dev->dev_private;
4574
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004575 /*
4576 * There is no safeguard against this debugfs entry colliding
4577 * with the hangcheck calling same i915_handle_error() in
4578 * parallel, causing an explosion. For now we assume that the
4579 * test harness is responsible enough not to inject gpu hangs
4580 * while it is writing to 'i915_wedged'
4581 */
4582
4583 if (i915_reset_in_progress(&dev_priv->gpu_error))
4584 return -EAGAIN;
4585
Imre Deakd46c0512014-04-14 20:24:27 +03004586 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004587
Mika Kuoppala58174462014-02-25 17:11:26 +02004588 i915_handle_error(dev, val,
4589 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004590
4591 intel_runtime_pm_put(dev_priv);
4592
Kees Cook647416f2013-03-10 14:10:06 -07004593 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004594}
4595
Kees Cook647416f2013-03-10 14:10:06 -07004596DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4597 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004598 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004599
Kees Cook647416f2013-03-10 14:10:06 -07004600static int
4601i915_ring_stop_get(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;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004604 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004605
Kees Cook647416f2013-03-10 14:10:06 -07004606 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004607
Kees Cook647416f2013-03-10 14:10:06 -07004608 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004609}
4610
Kees Cook647416f2013-03-10 14:10:06 -07004611static int
4612i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004613{
Kees Cook647416f2013-03-10 14:10:06 -07004614 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004615 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004616 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004617
Kees Cook647416f2013-03-10 14:10:06 -07004618 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004619
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004620 ret = mutex_lock_interruptible(&dev->struct_mutex);
4621 if (ret)
4622 return ret;
4623
Daniel Vetter99584db2012-11-14 17:14:04 +01004624 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004625 mutex_unlock(&dev->struct_mutex);
4626
Kees Cook647416f2013-03-10 14:10:06 -07004627 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004628}
4629
Kees Cook647416f2013-03-10 14:10:06 -07004630DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4631 i915_ring_stop_get, i915_ring_stop_set,
4632 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004633
Chris Wilson094f9a52013-09-25 17:34:55 +01004634static int
4635i915_ring_missed_irq_get(void *data, u64 *val)
4636{
4637 struct drm_device *dev = data;
4638 struct drm_i915_private *dev_priv = dev->dev_private;
4639
4640 *val = dev_priv->gpu_error.missed_irq_rings;
4641 return 0;
4642}
4643
4644static int
4645i915_ring_missed_irq_set(void *data, u64 val)
4646{
4647 struct drm_device *dev = data;
4648 struct drm_i915_private *dev_priv = dev->dev_private;
4649 int ret;
4650
4651 /* Lock against concurrent debugfs callers */
4652 ret = mutex_lock_interruptible(&dev->struct_mutex);
4653 if (ret)
4654 return ret;
4655 dev_priv->gpu_error.missed_irq_rings = val;
4656 mutex_unlock(&dev->struct_mutex);
4657
4658 return 0;
4659}
4660
4661DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4662 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4663 "0x%08llx\n");
4664
4665static int
4666i915_ring_test_irq_get(void *data, u64 *val)
4667{
4668 struct drm_device *dev = data;
4669 struct drm_i915_private *dev_priv = dev->dev_private;
4670
4671 *val = dev_priv->gpu_error.test_irq_rings;
4672
4673 return 0;
4674}
4675
4676static int
4677i915_ring_test_irq_set(void *data, u64 val)
4678{
4679 struct drm_device *dev = data;
4680 struct drm_i915_private *dev_priv = dev->dev_private;
4681 int ret;
4682
4683 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4684
4685 /* Lock against concurrent debugfs callers */
4686 ret = mutex_lock_interruptible(&dev->struct_mutex);
4687 if (ret)
4688 return ret;
4689
4690 dev_priv->gpu_error.test_irq_rings = val;
4691 mutex_unlock(&dev->struct_mutex);
4692
4693 return 0;
4694}
4695
4696DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4697 i915_ring_test_irq_get, i915_ring_test_irq_set,
4698 "0x%08llx\n");
4699
Chris Wilsondd624af2013-01-15 12:39:35 +00004700#define DROP_UNBOUND 0x1
4701#define DROP_BOUND 0x2
4702#define DROP_RETIRE 0x4
4703#define DROP_ACTIVE 0x8
4704#define DROP_ALL (DROP_UNBOUND | \
4705 DROP_BOUND | \
4706 DROP_RETIRE | \
4707 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004708static int
4709i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004710{
Kees Cook647416f2013-03-10 14:10:06 -07004711 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004712
Kees Cook647416f2013-03-10 14:10:06 -07004713 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004714}
4715
Kees Cook647416f2013-03-10 14:10:06 -07004716static int
4717i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004718{
Kees Cook647416f2013-03-10 14:10:06 -07004719 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004720 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004721 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004722
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004723 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004724
4725 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4726 * on ioctls on -EAGAIN. */
4727 ret = mutex_lock_interruptible(&dev->struct_mutex);
4728 if (ret)
4729 return ret;
4730
4731 if (val & DROP_ACTIVE) {
4732 ret = i915_gpu_idle(dev);
4733 if (ret)
4734 goto unlock;
4735 }
4736
4737 if (val & (DROP_RETIRE | DROP_ACTIVE))
4738 i915_gem_retire_requests(dev);
4739
Chris Wilson21ab4e72014-09-09 11:16:08 +01004740 if (val & DROP_BOUND)
4741 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004742
Chris Wilson21ab4e72014-09-09 11:16:08 +01004743 if (val & DROP_UNBOUND)
4744 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004745
4746unlock:
4747 mutex_unlock(&dev->struct_mutex);
4748
Kees Cook647416f2013-03-10 14:10:06 -07004749 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004750}
4751
Kees Cook647416f2013-03-10 14:10:06 -07004752DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4753 i915_drop_caches_get, i915_drop_caches_set,
4754 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004755
Kees Cook647416f2013-03-10 14:10:06 -07004756static int
4757i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004758{
Kees Cook647416f2013-03-10 14:10:06 -07004759 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004760 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004761 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004762
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004763 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004764 return -ENODEV;
4765
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004766 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4767
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004768 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004769 if (ret)
4770 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004771
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004772 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004773 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004774
Kees Cook647416f2013-03-10 14:10:06 -07004775 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004776}
4777
Kees Cook647416f2013-03-10 14:10:06 -07004778static int
4779i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004780{
Kees Cook647416f2013-03-10 14:10:06 -07004781 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004782 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304783 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004784 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004785
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004786 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004787 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004788
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004789 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4790
Kees Cook647416f2013-03-10 14:10:06 -07004791 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004792
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004793 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004794 if (ret)
4795 return ret;
4796
Jesse Barnes358733e2011-07-27 11:53:01 -07004797 /*
4798 * Turbo will still be enabled, but won't go above the set value.
4799 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304800 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004801
Akash Goelbc4d91f2015-02-26 16:09:47 +05304802 hw_max = dev_priv->rps.max_freq;
4803 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004804
Ben Widawskyb39fb292014-03-19 18:31:11 -07004805 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004806 mutex_unlock(&dev_priv->rps.hw_lock);
4807 return -EINVAL;
4808 }
4809
Ben Widawskyb39fb292014-03-19 18:31:11 -07004810 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004811
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004812 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004813
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004814 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004815
Kees Cook647416f2013-03-10 14:10:06 -07004816 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004817}
4818
Kees Cook647416f2013-03-10 14:10:06 -07004819DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4820 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004821 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004822
Kees Cook647416f2013-03-10 14:10:06 -07004823static int
4824i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004825{
Kees Cook647416f2013-03-10 14:10:06 -07004826 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004827 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004828 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004829
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004830 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004831 return -ENODEV;
4832
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004833 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4834
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004835 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004836 if (ret)
4837 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004838
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004839 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004840 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004841
Kees Cook647416f2013-03-10 14:10:06 -07004842 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004843}
4844
Kees Cook647416f2013-03-10 14:10:06 -07004845static int
4846i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004847{
Kees Cook647416f2013-03-10 14:10:06 -07004848 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004849 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304850 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004851 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004852
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004853 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004854 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004855
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004856 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4857
Kees Cook647416f2013-03-10 14:10:06 -07004858 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004859
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004860 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004861 if (ret)
4862 return ret;
4863
Jesse Barnes1523c312012-05-25 12:34:54 -07004864 /*
4865 * Turbo will still be enabled, but won't go below the set value.
4866 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304867 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004868
Akash Goelbc4d91f2015-02-26 16:09:47 +05304869 hw_max = dev_priv->rps.max_freq;
4870 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004871
Ben Widawskyb39fb292014-03-19 18:31:11 -07004872 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004873 mutex_unlock(&dev_priv->rps.hw_lock);
4874 return -EINVAL;
4875 }
4876
Ben Widawskyb39fb292014-03-19 18:31:11 -07004877 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004878
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004879 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004880
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004881 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004882
Kees Cook647416f2013-03-10 14:10:06 -07004883 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004884}
4885
Kees Cook647416f2013-03-10 14:10:06 -07004886DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4887 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004888 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004889
Kees Cook647416f2013-03-10 14:10:06 -07004890static int
4891i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004892{
Kees Cook647416f2013-03-10 14:10:06 -07004893 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004894 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004895 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004896 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004897
Daniel Vetter004777c2012-08-09 15:07:01 +02004898 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4899 return -ENODEV;
4900
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004901 ret = mutex_lock_interruptible(&dev->struct_mutex);
4902 if (ret)
4903 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004904 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004905
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004906 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004907
4908 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004909 mutex_unlock(&dev_priv->dev->struct_mutex);
4910
Kees Cook647416f2013-03-10 14:10:06 -07004911 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004912
Kees Cook647416f2013-03-10 14:10:06 -07004913 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004914}
4915
Kees Cook647416f2013-03-10 14:10:06 -07004916static int
4917i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004918{
Kees Cook647416f2013-03-10 14:10:06 -07004919 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004920 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004921 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004922
Daniel Vetter004777c2012-08-09 15:07:01 +02004923 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4924 return -ENODEV;
4925
Kees Cook647416f2013-03-10 14:10:06 -07004926 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004927 return -EINVAL;
4928
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004929 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004930 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004931
4932 /* Update the cache sharing policy here as well */
4933 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4934 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4935 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4936 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4937
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004938 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004939 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004940}
4941
Kees Cook647416f2013-03-10 14:10:06 -07004942DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4943 i915_cache_sharing_get, i915_cache_sharing_set,
4944 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004945
Jeff McGee5d395252015-04-03 18:13:17 -07004946struct sseu_dev_status {
4947 unsigned int slice_total;
4948 unsigned int subslice_total;
4949 unsigned int subslice_per_slice;
4950 unsigned int eu_total;
4951 unsigned int eu_per_subslice;
4952};
4953
4954static void cherryview_sseu_device_status(struct drm_device *dev,
4955 struct sseu_dev_status *stat)
4956{
4957 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004958 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004959 int ss;
4960 u32 sig1[ss_max], sig2[ss_max];
4961
4962 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4963 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4964 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4965 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4966
4967 for (ss = 0; ss < ss_max; ss++) {
4968 unsigned int eu_cnt;
4969
4970 if (sig1[ss] & CHV_SS_PG_ENABLE)
4971 /* skip disabled subslice */
4972 continue;
4973
4974 stat->slice_total = 1;
4975 stat->subslice_per_slice++;
4976 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4977 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4978 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4979 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
4980 stat->eu_total += eu_cnt;
4981 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
4982 }
4983 stat->subslice_total = stat->subslice_per_slice;
4984}
4985
4986static void gen9_sseu_device_status(struct drm_device *dev,
4987 struct sseu_dev_status *stat)
4988{
4989 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004990 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004991 int s, ss;
4992 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4993
Jeff McGee1c046bc2015-04-03 18:13:18 -07004994 /* BXT has a single slice and at most 3 subslices. */
4995 if (IS_BROXTON(dev)) {
4996 s_max = 1;
4997 ss_max = 3;
4998 }
4999
5000 for (s = 0; s < s_max; s++) {
5001 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5002 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5003 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5004 }
5005
Jeff McGee5d395252015-04-03 18:13:17 -07005006 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5007 GEN9_PGCTL_SSA_EU19_ACK |
5008 GEN9_PGCTL_SSA_EU210_ACK |
5009 GEN9_PGCTL_SSA_EU311_ACK;
5010 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5011 GEN9_PGCTL_SSB_EU19_ACK |
5012 GEN9_PGCTL_SSB_EU210_ACK |
5013 GEN9_PGCTL_SSB_EU311_ACK;
5014
5015 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005016 unsigned int ss_cnt = 0;
5017
Jeff McGee5d395252015-04-03 18:13:17 -07005018 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5019 /* skip disabled slice */
5020 continue;
5021
5022 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005023
5024 if (IS_SKYLAKE(dev))
5025 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5026
Jeff McGee5d395252015-04-03 18:13:17 -07005027 for (ss = 0; ss < ss_max; ss++) {
5028 unsigned int eu_cnt;
5029
Jeff McGee1c046bc2015-04-03 18:13:18 -07005030 if (IS_BROXTON(dev) &&
5031 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5032 /* skip disabled subslice */
5033 continue;
5034
5035 if (IS_BROXTON(dev))
5036 ss_cnt++;
5037
Jeff McGee5d395252015-04-03 18:13:17 -07005038 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5039 eu_mask[ss%2]);
5040 stat->eu_total += eu_cnt;
5041 stat->eu_per_subslice = max(stat->eu_per_subslice,
5042 eu_cnt);
5043 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005044
5045 stat->subslice_total += ss_cnt;
5046 stat->subslice_per_slice = max(stat->subslice_per_slice,
5047 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005048 }
5049}
5050
Jeff McGee38732182015-02-13 10:27:54 -06005051static int i915_sseu_status(struct seq_file *m, void *unused)
5052{
5053 struct drm_info_node *node = (struct drm_info_node *) m->private;
5054 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07005055 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005056
Jeff McGee5575f032015-02-27 10:22:32 -08005057 if ((INTEL_INFO(dev)->gen < 8) || IS_BROADWELL(dev))
Jeff McGee38732182015-02-13 10:27:54 -06005058 return -ENODEV;
5059
5060 seq_puts(m, "SSEU Device Info\n");
5061 seq_printf(m, " Available Slice Total: %u\n",
5062 INTEL_INFO(dev)->slice_total);
5063 seq_printf(m, " Available Subslice Total: %u\n",
5064 INTEL_INFO(dev)->subslice_total);
5065 seq_printf(m, " Available Subslice Per Slice: %u\n",
5066 INTEL_INFO(dev)->subslice_per_slice);
5067 seq_printf(m, " Available EU Total: %u\n",
5068 INTEL_INFO(dev)->eu_total);
5069 seq_printf(m, " Available EU Per Subslice: %u\n",
5070 INTEL_INFO(dev)->eu_per_subslice);
5071 seq_printf(m, " Has Slice Power Gating: %s\n",
5072 yesno(INTEL_INFO(dev)->has_slice_pg));
5073 seq_printf(m, " Has Subslice Power Gating: %s\n",
5074 yesno(INTEL_INFO(dev)->has_subslice_pg));
5075 seq_printf(m, " Has EU Power Gating: %s\n",
5076 yesno(INTEL_INFO(dev)->has_eu_pg));
5077
Jeff McGee7f992ab2015-02-13 10:27:55 -06005078 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005079 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08005080 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005081 cherryview_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005082 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005083 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005084 }
Jeff McGee5d395252015-04-03 18:13:17 -07005085 seq_printf(m, " Enabled Slice Total: %u\n",
5086 stat.slice_total);
5087 seq_printf(m, " Enabled Subslice Total: %u\n",
5088 stat.subslice_total);
5089 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5090 stat.subslice_per_slice);
5091 seq_printf(m, " Enabled EU Total: %u\n",
5092 stat.eu_total);
5093 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5094 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005095
Jeff McGee38732182015-02-13 10:27:54 -06005096 return 0;
5097}
5098
Ben Widawsky6d794d42011-04-25 11:25:56 -07005099static int i915_forcewake_open(struct inode *inode, struct file *file)
5100{
5101 struct drm_device *dev = inode->i_private;
5102 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005103
Daniel Vetter075edca2012-01-24 09:44:28 +01005104 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005105 return 0;
5106
Chris Wilson6daccb02015-01-16 11:34:35 +02005107 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005108 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005109
5110 return 0;
5111}
5112
Ben Widawskyc43b5632012-04-16 14:07:40 -07005113static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005114{
5115 struct drm_device *dev = inode->i_private;
5116 struct drm_i915_private *dev_priv = dev->dev_private;
5117
Daniel Vetter075edca2012-01-24 09:44:28 +01005118 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005119 return 0;
5120
Mika Kuoppala59bad942015-01-16 11:34:40 +02005121 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005122 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005123
5124 return 0;
5125}
5126
5127static const struct file_operations i915_forcewake_fops = {
5128 .owner = THIS_MODULE,
5129 .open = i915_forcewake_open,
5130 .release = i915_forcewake_release,
5131};
5132
5133static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5134{
5135 struct drm_device *dev = minor->dev;
5136 struct dentry *ent;
5137
5138 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005139 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005140 root, dev,
5141 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005142 if (!ent)
5143 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005144
Ben Widawsky8eb57292011-05-11 15:10:58 -07005145 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005146}
5147
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005148static int i915_debugfs_create(struct dentry *root,
5149 struct drm_minor *minor,
5150 const char *name,
5151 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005152{
5153 struct drm_device *dev = minor->dev;
5154 struct dentry *ent;
5155
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005156 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005157 S_IRUGO | S_IWUSR,
5158 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005159 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005160 if (!ent)
5161 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005162
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005163 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005164}
5165
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005166static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005167 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005168 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005169 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005170 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005171 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005172 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005173 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005174 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005175 {"i915_gem_request", i915_gem_request_info, 0},
5176 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005177 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005178 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005179 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5180 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5181 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005182 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005183 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005184 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005185 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005186 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305187 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005188 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005189 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005190 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005191 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005192 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005193 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005194 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005195 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005196 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005197 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005198 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005199 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005200 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005201 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005202 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005203 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005204 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005205 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005206 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005207 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005208 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005209 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005210 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005211 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005212 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005213 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005214 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005215 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005216 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305217 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005218 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005219};
Ben Gamari27c202a2009-07-01 22:26:52 -04005220#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005221
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005222static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005223 const char *name;
5224 const struct file_operations *fops;
5225} i915_debugfs_files[] = {
5226 {"i915_wedged", &i915_wedged_fops},
5227 {"i915_max_freq", &i915_max_freq_fops},
5228 {"i915_min_freq", &i915_min_freq_fops},
5229 {"i915_cache_sharing", &i915_cache_sharing_fops},
5230 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005231 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5232 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005233 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5234 {"i915_error_state", &i915_error_state_fops},
5235 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005236 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005237 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5238 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5239 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005240 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005241 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5242 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5243 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005244};
5245
Damien Lespiau07144422013-10-15 18:55:40 +01005246void intel_display_crc_init(struct drm_device *dev)
5247{
5248 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005249 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005250
Damien Lespiau055e3932014-08-18 13:49:10 +01005251 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005252 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005253
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005254 pipe_crc->opened = false;
5255 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005256 init_waitqueue_head(&pipe_crc->wq);
5257 }
5258}
5259
Ben Gamari27c202a2009-07-01 22:26:52 -04005260int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005261{
Daniel Vetter34b96742013-07-04 20:49:44 +02005262 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005263
Ben Widawsky6d794d42011-04-25 11:25:56 -07005264 ret = i915_forcewake_create(minor->debugfs_root, minor);
5265 if (ret)
5266 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005267
Damien Lespiau07144422013-10-15 18:55:40 +01005268 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5269 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5270 if (ret)
5271 return ret;
5272 }
5273
Daniel Vetter34b96742013-07-04 20:49:44 +02005274 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5275 ret = i915_debugfs_create(minor->debugfs_root, minor,
5276 i915_debugfs_files[i].name,
5277 i915_debugfs_files[i].fops);
5278 if (ret)
5279 return ret;
5280 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005281
Ben Gamari27c202a2009-07-01 22:26:52 -04005282 return drm_debugfs_create_files(i915_debugfs_list,
5283 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005284 minor->debugfs_root, minor);
5285}
5286
Ben Gamari27c202a2009-07-01 22:26:52 -04005287void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005288{
Daniel Vetter34b96742013-07-04 20:49:44 +02005289 int i;
5290
Ben Gamari27c202a2009-07-01 22:26:52 -04005291 drm_debugfs_remove_files(i915_debugfs_list,
5292 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005293
Ben Widawsky6d794d42011-04-25 11:25:56 -07005294 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5295 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005296
Daniel Vettere309a992013-10-16 22:55:51 +02005297 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005298 struct drm_info_list *info_list =
5299 (struct drm_info_list *)&i915_pipe_crc_data[i];
5300
5301 drm_debugfs_remove_files(info_list, 1, minor);
5302 }
5303
Daniel Vetter34b96742013-07-04 20:49:44 +02005304 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5305 struct drm_info_list *info_list =
5306 (struct drm_info_list *) i915_debugfs_files[i].fops;
5307
5308 drm_debugfs_remove_files(info_list, 1, minor);
5309 }
Ben Gamari20172632009-02-17 20:08:50 -05005310}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005311
5312struct dpcd_block {
5313 /* DPCD dump start address. */
5314 unsigned int offset;
5315 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5316 unsigned int end;
5317 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5318 size_t size;
5319 /* Only valid for eDP. */
5320 bool edp;
5321};
5322
5323static const struct dpcd_block i915_dpcd_debug[] = {
5324 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5325 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5326 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5327 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5328 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5329 { .offset = DP_SET_POWER },
5330 { .offset = DP_EDP_DPCD_REV },
5331 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5332 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5333 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5334};
5335
5336static int i915_dpcd_show(struct seq_file *m, void *data)
5337{
5338 struct drm_connector *connector = m->private;
5339 struct intel_dp *intel_dp =
5340 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5341 uint8_t buf[16];
5342 ssize_t err;
5343 int i;
5344
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005345 if (connector->status != connector_status_connected)
5346 return -ENODEV;
5347
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005348 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5349 const struct dpcd_block *b = &i915_dpcd_debug[i];
5350 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5351
5352 if (b->edp &&
5353 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5354 continue;
5355
5356 /* low tech for now */
5357 if (WARN_ON(size > sizeof(buf)))
5358 continue;
5359
5360 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5361 if (err <= 0) {
5362 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5363 size, b->offset, err);
5364 continue;
5365 }
5366
5367 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005368 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005369
5370 return 0;
5371}
5372
5373static int i915_dpcd_open(struct inode *inode, struct file *file)
5374{
5375 return single_open(file, i915_dpcd_show, inode->i_private);
5376}
5377
5378static const struct file_operations i915_dpcd_fops = {
5379 .owner = THIS_MODULE,
5380 .open = i915_dpcd_open,
5381 .read = seq_read,
5382 .llseek = seq_lseek,
5383 .release = single_release,
5384};
5385
5386/**
5387 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5388 * @connector: pointer to a registered drm_connector
5389 *
5390 * Cleanup will be done by drm_connector_unregister() through a call to
5391 * drm_debugfs_connector_remove().
5392 *
5393 * Returns 0 on success, negative error codes on error.
5394 */
5395int i915_debugfs_connector_add(struct drm_connector *connector)
5396{
5397 struct dentry *root = connector->debugfs_entry;
5398
5399 /* The connector must have been registered beforehands. */
5400 if (!root)
5401 return -ENODEV;
5402
5403 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5404 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5405 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5406 &i915_dpcd_fops);
5407
5408 return 0;
5409}