blob: a3b22bdacd44f539a81429d7e1946d86d8cb4f78 [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
Chris Wilsona6172a82009-02-11 14:26:38 +0000959 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
960 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000961 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000962
Chris Wilson6c085a72012-08-20 11:40:46 +0200963 seq_printf(m, "Fence %d, pin count = %d, object = ",
964 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100965 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100966 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100967 else
Chris Wilson05394f32010-11-08 19:18:58 +0000968 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100969 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000970 }
971
Chris Wilson05394f32010-11-08 19:18:58 +0000972 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000973 return 0;
974}
975
Ben Gamari20172632009-02-17 20:08:50 -0500976static int i915_hws_info(struct seq_file *m, void *data)
977{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100978 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500979 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300980 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100981 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100982 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100983 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500984
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000985 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100986 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500987 if (hws == NULL)
988 return 0;
989
990 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
991 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
992 i * 4,
993 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
994 }
995 return 0;
996}
997
Daniel Vetterd5442302012-04-27 15:17:40 +0200998static ssize_t
999i915_error_state_write(struct file *filp,
1000 const char __user *ubuf,
1001 size_t cnt,
1002 loff_t *ppos)
1003{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001004 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001005 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001006 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001007
1008 DRM_DEBUG_DRIVER("Resetting error state\n");
1009
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001010 ret = mutex_lock_interruptible(&dev->struct_mutex);
1011 if (ret)
1012 return ret;
1013
Daniel Vetterd5442302012-04-27 15:17:40 +02001014 i915_destroy_error_state(dev);
1015 mutex_unlock(&dev->struct_mutex);
1016
1017 return cnt;
1018}
1019
1020static int i915_error_state_open(struct inode *inode, struct file *file)
1021{
1022 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001023 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001024
1025 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1026 if (!error_priv)
1027 return -ENOMEM;
1028
1029 error_priv->dev = dev;
1030
Mika Kuoppala95d5bfb32013-06-06 15:18:40 +03001031 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001032
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001033 file->private_data = error_priv;
1034
1035 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001036}
1037
1038static int i915_error_state_release(struct inode *inode, struct file *file)
1039{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001040 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001041
Mika Kuoppala95d5bfb32013-06-06 15:18:40 +03001042 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001043 kfree(error_priv);
1044
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001045 return 0;
1046}
1047
1048static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1049 size_t count, loff_t *pos)
1050{
1051 struct i915_error_state_file_priv *error_priv = file->private_data;
1052 struct drm_i915_error_state_buf error_str;
1053 loff_t tmp_pos = 0;
1054 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001055 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001056
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001057 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001058 if (ret)
1059 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001060
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001061 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001062 if (ret)
1063 goto out;
1064
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001065 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1066 error_str.buf,
1067 error_str.bytes);
1068
1069 if (ret_count < 0)
1070 ret = ret_count;
1071 else
1072 *pos = error_str.start + ret_count;
1073out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001074 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001075 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001076}
1077
1078static const struct file_operations i915_error_state_fops = {
1079 .owner = THIS_MODULE,
1080 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001081 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001082 .write = i915_error_state_write,
1083 .llseek = default_llseek,
1084 .release = i915_error_state_release,
1085};
1086
Kees Cook647416f2013-03-10 14:10:06 -07001087static int
1088i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001089{
Kees Cook647416f2013-03-10 14:10:06 -07001090 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001091 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001092 int ret;
1093
1094 ret = mutex_lock_interruptible(&dev->struct_mutex);
1095 if (ret)
1096 return ret;
1097
Kees Cook647416f2013-03-10 14:10:06 -07001098 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001099 mutex_unlock(&dev->struct_mutex);
1100
Kees Cook647416f2013-03-10 14:10:06 -07001101 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001102}
1103
Kees Cook647416f2013-03-10 14:10:06 -07001104static int
1105i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001106{
Kees Cook647416f2013-03-10 14:10:06 -07001107 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001108 int ret;
1109
Mika Kuoppala40633212012-12-04 15:12:00 +02001110 ret = mutex_lock_interruptible(&dev->struct_mutex);
1111 if (ret)
1112 return ret;
1113
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001114 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001115 mutex_unlock(&dev->struct_mutex);
1116
Kees Cook647416f2013-03-10 14:10:06 -07001117 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001118}
1119
Kees Cook647416f2013-03-10 14:10:06 -07001120DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1121 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001122 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001123
Deepak Sadb4bd12014-03-31 11:30:02 +05301124static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001125{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001126 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001127 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001128 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001129 int ret = 0;
1130
1131 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001132
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001133 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1134
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001135 if (IS_GEN5(dev)) {
1136 u16 rgvswctl = I915_READ16(MEMSWCTL);
1137 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1138
1139 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1140 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1141 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1142 MEMSTAT_VID_SHIFT);
1143 seq_printf(m, "Current P-state: %d\n",
1144 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001145 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
Akash Goel60260a52015-03-06 11:07:21 +05301146 IS_BROADWELL(dev) || IS_GEN9(dev)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001147 u32 rp_state_limits;
1148 u32 gt_perf_status;
1149 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001150 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001151 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001152 u32 rpupei, rpcurup, rpprevup;
1153 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001154 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001155 int max_freq;
1156
Bob Paauwe35040562015-06-25 14:54:07 -07001157 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1158 if (IS_BROXTON(dev)) {
1159 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1160 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1161 } else {
1162 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1163 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1164 }
1165
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001166 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001167 ret = mutex_lock_interruptible(&dev->struct_mutex);
1168 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001169 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001170
Mika Kuoppala59bad942015-01-16 11:34:40 +02001171 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001172
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001173 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301174 if (IS_GEN9(dev))
1175 reqf >>= 23;
1176 else {
1177 reqf &= ~GEN6_TURBO_DISABLE;
1178 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1179 reqf >>= 24;
1180 else
1181 reqf >>= 25;
1182 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001183 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001184
Chris Wilson0d8f9492014-03-27 09:06:14 +00001185 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1186 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1187 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1188
Jesse Barnesccab5c82011-01-18 15:49:25 -08001189 rpstat = I915_READ(GEN6_RPSTAT1);
1190 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1191 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1192 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1193 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1194 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1195 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Akash Goel60260a52015-03-06 11:07:21 +05301196 if (IS_GEN9(dev))
1197 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1198 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001199 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1200 else
1201 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001202 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001203
Mika Kuoppala59bad942015-01-16 11:34:40 +02001204 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001205 mutex_unlock(&dev->struct_mutex);
1206
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001207 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1208 pm_ier = I915_READ(GEN6_PMIER);
1209 pm_imr = I915_READ(GEN6_PMIMR);
1210 pm_isr = I915_READ(GEN6_PMISR);
1211 pm_iir = I915_READ(GEN6_PMIIR);
1212 pm_mask = I915_READ(GEN6_PMINTRMSK);
1213 } else {
1214 pm_ier = I915_READ(GEN8_GT_IER(2));
1215 pm_imr = I915_READ(GEN8_GT_IMR(2));
1216 pm_isr = I915_READ(GEN8_GT_ISR(2));
1217 pm_iir = I915_READ(GEN8_GT_IIR(2));
1218 pm_mask = I915_READ(GEN6_PMINTRMSK);
1219 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001220 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 -03001221 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001222 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001223 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301224 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001225 seq_printf(m, "Render p-state VID: %d\n",
1226 gt_perf_status & 0xff);
1227 seq_printf(m, "Render p-state limit: %d\n",
1228 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001229 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1230 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1231 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1232 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001233 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001234 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001235 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1236 GEN6_CURICONT_MASK);
1237 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1238 GEN6_CURBSYTAVG_MASK);
1239 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1240 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001241 seq_printf(m, "Up threshold: %d%%\n",
1242 dev_priv->rps.up_threshold);
1243
Jesse Barnesccab5c82011-01-18 15:49:25 -08001244 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1245 GEN6_CURIAVG_MASK);
1246 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1247 GEN6_CURBSYTAVG_MASK);
1248 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1249 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001250 seq_printf(m, "Down threshold: %d%%\n",
1251 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001252
Bob Paauwe35040562015-06-25 14:54:07 -07001253 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1254 rp_state_cap >> 16) & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301255 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001256 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001257 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001258
1259 max_freq = (rp_state_cap & 0xff00) >> 8;
Akash Goel60260a52015-03-06 11:07:21 +05301260 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001261 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001262 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001263
Bob Paauwe35040562015-06-25 14:54:07 -07001264 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1265 rp_state_cap >> 0) & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301266 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001267 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001268 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001269 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001270 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001271
Chris Wilsond86ed342015-04-27 13:41:19 +01001272 seq_printf(m, "Current freq: %d MHz\n",
1273 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1274 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001275 seq_printf(m, "Idle freq: %d MHz\n",
1276 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001277 seq_printf(m, "Min freq: %d MHz\n",
1278 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1279 seq_printf(m, "Max freq: %d MHz\n",
1280 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1281 seq_printf(m,
1282 "efficient (RPe) frequency: %d MHz\n",
1283 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001284 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001285 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001286
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001287 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001288 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001289 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1290 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1291
Chris Wilsond86ed342015-04-27 13:41:19 +01001292 seq_printf(m, "actual GPU freq: %d MHz\n",
1293 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1294
1295 seq_printf(m, "current GPU freq: %d MHz\n",
1296 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1297
Jesse Barnes0a073b82013-04-17 15:54:58 -07001298 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001299 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001300
Jesse Barnes0a073b82013-04-17 15:54:58 -07001301 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001302 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001303
Chris Wilsonaed242f2015-03-18 09:48:21 +00001304 seq_printf(m, "idle GPU freq: %d MHz\n",
1305 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1306
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001307 seq_printf(m,
1308 "efficient (RPe) frequency: %d MHz\n",
1309 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001310 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001311 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001312 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001313 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001314
Mika Kahola1170f282015-09-25 14:00:32 +03001315 seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk_freq);
1316 seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
1317 seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
1318
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001319out:
1320 intel_runtime_pm_put(dev_priv);
1321 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001322}
1323
Chris Wilsonf6544492015-01-26 18:03:04 +02001324static int i915_hangcheck_info(struct seq_file *m, void *unused)
1325{
1326 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001327 struct drm_device *dev = node->minor->dev;
1328 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf6544492015-01-26 18:03:04 +02001329 struct intel_engine_cs *ring;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001330 u64 acthd[I915_NUM_RINGS];
1331 u32 seqno[I915_NUM_RINGS];
Chris Wilsonf6544492015-01-26 18:03:04 +02001332 int i;
1333
1334 if (!i915.enable_hangcheck) {
1335 seq_printf(m, "Hangcheck disabled\n");
1336 return 0;
1337 }
1338
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001339 intel_runtime_pm_get(dev_priv);
1340
1341 for_each_ring(ring, dev_priv, i) {
1342 seqno[i] = ring->get_seqno(ring, false);
1343 acthd[i] = intel_ring_get_active_head(ring);
1344 }
1345
1346 intel_runtime_pm_put(dev_priv);
1347
Chris Wilsonf6544492015-01-26 18:03:04 +02001348 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1349 seq_printf(m, "Hangcheck active, fires in %dms\n",
1350 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1351 jiffies));
1352 } else
1353 seq_printf(m, "Hangcheck inactive\n");
1354
1355 for_each_ring(ring, dev_priv, i) {
1356 seq_printf(m, "%s:\n", ring->name);
1357 seq_printf(m, "\tseqno = %x [current %x]\n",
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001358 ring->hangcheck.seqno, seqno[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001359 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1360 (long long)ring->hangcheck.acthd,
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001361 (long long)acthd[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001362 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1363 (long long)ring->hangcheck.max_acthd);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001364 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1365 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
Chris Wilsonf6544492015-01-26 18:03:04 +02001366 }
1367
1368 return 0;
1369}
1370
Ben Widawsky4d855292011-12-12 19:34:16 -08001371static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001372{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001373 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001374 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001375 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001376 u32 rgvmodectl, rstdbyctl;
1377 u16 crstandvid;
1378 int ret;
1379
1380 ret = mutex_lock_interruptible(&dev->struct_mutex);
1381 if (ret)
1382 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001383 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001384
1385 rgvmodectl = I915_READ(MEMMODECTL);
1386 rstdbyctl = I915_READ(RSTDBYCTL);
1387 crstandvid = I915_READ16(CRSTANDVID);
1388
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001389 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001390 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001391
Jani Nikula742f4912015-09-03 11:16:09 +03001392 seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001393 seq_printf(m, "Boost freq: %d\n",
1394 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1395 MEMMODE_BOOST_FREQ_SHIFT);
1396 seq_printf(m, "HW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001397 yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001398 seq_printf(m, "SW control enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001399 yesno(rgvmodectl & MEMMODE_SWMODE_EN));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001400 seq_printf(m, "Gated voltage change: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001401 yesno(rgvmodectl & MEMMODE_RCLK_GATE));
Jesse Barnesf97108d2010-01-29 11:27:07 -08001402 seq_printf(m, "Starting frequency: P%d\n",
1403 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001404 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001405 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001406 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1407 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1408 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1409 seq_printf(m, "Render standby enabled: %s\n",
Jani Nikula742f4912015-09-03 11:16:09 +03001410 yesno(!(rstdbyctl & RCX_SW_EXIT)));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001411 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001412 switch (rstdbyctl & RSX_STATUS_MASK) {
1413 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001414 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001415 break;
1416 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001417 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001418 break;
1419 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001420 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001421 break;
1422 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001423 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001424 break;
1425 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001426 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001427 break;
1428 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001429 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001430 break;
1431 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001432 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001433 break;
1434 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001435
1436 return 0;
1437}
1438
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001439static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001440{
1441 struct drm_info_node *node = m->private;
1442 struct drm_device *dev = node->minor->dev;
1443 struct drm_i915_private *dev_priv = dev->dev_private;
1444 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001445 int i;
1446
1447 spin_lock_irq(&dev_priv->uncore.lock);
1448 for_each_fw_domain(fw_domain, dev_priv, i) {
1449 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001450 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001451 fw_domain->wake_count);
1452 }
1453 spin_unlock_irq(&dev_priv->uncore.lock);
1454
1455 return 0;
1456}
1457
Deepak S669ab5a2014-01-10 15:18:26 +05301458static int vlv_drpc_info(struct seq_file *m)
1459{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001460 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301461 struct drm_device *dev = node->minor->dev;
1462 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001463 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301464
Imre Deakd46c0512014-04-14 20:24:27 +03001465 intel_runtime_pm_get(dev_priv);
1466
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001467 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301468 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1469 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1470
Imre Deakd46c0512014-04-14 20:24:27 +03001471 intel_runtime_pm_put(dev_priv);
1472
Deepak S669ab5a2014-01-10 15:18:26 +05301473 seq_printf(m, "Video Turbo Mode: %s\n",
1474 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1475 seq_printf(m, "Turbo enabled: %s\n",
1476 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1477 seq_printf(m, "HW control enabled: %s\n",
1478 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1479 seq_printf(m, "SW control enabled: %s\n",
1480 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1481 GEN6_RP_MEDIA_SW_MODE));
1482 seq_printf(m, "RC6 Enabled: %s\n",
1483 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1484 GEN6_RC_CTL_EI_MODE(1))));
1485 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001486 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301487 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001488 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301489
Imre Deak9cc19be2014-04-14 20:24:24 +03001490 seq_printf(m, "Render RC6 residency since boot: %u\n",
1491 I915_READ(VLV_GT_RENDER_RC6));
1492 seq_printf(m, "Media RC6 residency since boot: %u\n",
1493 I915_READ(VLV_GT_MEDIA_RC6));
1494
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001495 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301496}
1497
Ben Widawsky4d855292011-12-12 19:34:16 -08001498static int gen6_drpc_info(struct seq_file *m)
1499{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001500 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001501 struct drm_device *dev = node->minor->dev;
1502 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001503 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001504 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001505 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001506
1507 ret = mutex_lock_interruptible(&dev->struct_mutex);
1508 if (ret)
1509 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001510 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001511
Chris Wilson907b28c2013-07-19 20:36:52 +01001512 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001513 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001514 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001515
1516 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001517 seq_puts(m, "RC information inaccurate because somebody "
1518 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001519 } else {
1520 /* NB: we cannot use forcewake, else we read the wrong values */
1521 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1522 udelay(10);
1523 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1524 }
1525
1526 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001527 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001528
1529 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1530 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1531 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001532 mutex_lock(&dev_priv->rps.hw_lock);
1533 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1534 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001535
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001536 intel_runtime_pm_put(dev_priv);
1537
Ben Widawsky4d855292011-12-12 19:34:16 -08001538 seq_printf(m, "Video Turbo Mode: %s\n",
1539 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1540 seq_printf(m, "HW control enabled: %s\n",
1541 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1542 seq_printf(m, "SW control enabled: %s\n",
1543 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1544 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001545 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001546 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1547 seq_printf(m, "RC6 Enabled: %s\n",
1548 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1549 seq_printf(m, "Deep RC6 Enabled: %s\n",
1550 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1551 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1552 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001553 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001554 switch (gt_core_status & GEN6_RCn_MASK) {
1555 case GEN6_RC0:
1556 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001557 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001558 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001559 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001560 break;
1561 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001562 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001563 break;
1564 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001565 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001566 break;
1567 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001568 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001569 break;
1570 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001571 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001572 break;
1573 }
1574
1575 seq_printf(m, "Core Power Down: %s\n",
1576 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001577
1578 /* Not exactly sure what this is */
1579 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1580 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1581 seq_printf(m, "RC6 residency since boot: %u\n",
1582 I915_READ(GEN6_GT_GFX_RC6));
1583 seq_printf(m, "RC6+ residency since boot: %u\n",
1584 I915_READ(GEN6_GT_GFX_RC6p));
1585 seq_printf(m, "RC6++ residency since boot: %u\n",
1586 I915_READ(GEN6_GT_GFX_RC6pp));
1587
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001588 seq_printf(m, "RC6 voltage: %dmV\n",
1589 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1590 seq_printf(m, "RC6+ voltage: %dmV\n",
1591 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1592 seq_printf(m, "RC6++ voltage: %dmV\n",
1593 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001594 return 0;
1595}
1596
1597static int i915_drpc_info(struct seq_file *m, void *unused)
1598{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001599 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001600 struct drm_device *dev = node->minor->dev;
1601
Deepak S669ab5a2014-01-10 15:18:26 +05301602 if (IS_VALLEYVIEW(dev))
1603 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001604 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001605 return gen6_drpc_info(m);
1606 else
1607 return ironlake_drpc_info(m);
1608}
1609
Daniel Vetter9a851782015-06-18 10:30:22 +02001610static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1611{
1612 struct drm_info_node *node = m->private;
1613 struct drm_device *dev = node->minor->dev;
1614 struct drm_i915_private *dev_priv = dev->dev_private;
1615
1616 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1617 dev_priv->fb_tracking.busy_bits);
1618
1619 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1620 dev_priv->fb_tracking.flip_bits);
1621
1622 return 0;
1623}
1624
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001625static int i915_fbc_status(struct seq_file *m, void *unused)
1626{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001627 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001628 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001629 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001630
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001631 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001632 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001633 return 0;
1634 }
1635
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001636 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001637 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001638
Paulo Zanoni7733b492015-07-07 15:26:04 -03001639 if (intel_fbc_enabled(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001640 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001641 else
1642 seq_printf(m, "FBC disabled: %s\n",
1643 intel_no_fbc_reason_str(dev_priv->fbc.no_fbc_reason));
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001644
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001645 if (INTEL_INFO(dev_priv)->gen >= 7)
1646 seq_printf(m, "Compressing: %s\n",
1647 yesno(I915_READ(FBC_STATUS2) &
1648 FBC_COMPRESSION_MASK));
1649
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001650 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001651 intel_runtime_pm_put(dev_priv);
1652
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001653 return 0;
1654}
1655
Rodrigo Vivida46f932014-08-01 02:04:45 -07001656static int i915_fbc_fc_get(void *data, u64 *val)
1657{
1658 struct drm_device *dev = data;
1659 struct drm_i915_private *dev_priv = dev->dev_private;
1660
1661 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1662 return -ENODEV;
1663
Rodrigo Vivida46f932014-08-01 02:04:45 -07001664 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001665
1666 return 0;
1667}
1668
1669static int i915_fbc_fc_set(void *data, u64 val)
1670{
1671 struct drm_device *dev = data;
1672 struct drm_i915_private *dev_priv = dev->dev_private;
1673 u32 reg;
1674
1675 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1676 return -ENODEV;
1677
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001678 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001679
1680 reg = I915_READ(ILK_DPFC_CONTROL);
1681 dev_priv->fbc.false_color = val;
1682
1683 I915_WRITE(ILK_DPFC_CONTROL, val ?
1684 (reg | FBC_CTL_FALSE_COLOR) :
1685 (reg & ~FBC_CTL_FALSE_COLOR));
1686
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001687 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001688 return 0;
1689}
1690
1691DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1692 i915_fbc_fc_get, i915_fbc_fc_set,
1693 "%llu\n");
1694
Paulo Zanoni92d44622013-05-31 16:33:24 -03001695static int i915_ips_status(struct seq_file *m, void *unused)
1696{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001697 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001698 struct drm_device *dev = node->minor->dev;
1699 struct drm_i915_private *dev_priv = dev->dev_private;
1700
Damien Lespiauf5adf942013-06-24 18:29:34 +01001701 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001702 seq_puts(m, "not supported\n");
1703 return 0;
1704 }
1705
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001706 intel_runtime_pm_get(dev_priv);
1707
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001708 seq_printf(m, "Enabled by kernel parameter: %s\n",
1709 yesno(i915.enable_ips));
1710
1711 if (INTEL_INFO(dev)->gen >= 8) {
1712 seq_puts(m, "Currently: unknown\n");
1713 } else {
1714 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1715 seq_puts(m, "Currently: enabled\n");
1716 else
1717 seq_puts(m, "Currently: disabled\n");
1718 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001719
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001720 intel_runtime_pm_put(dev_priv);
1721
Paulo Zanoni92d44622013-05-31 16:33:24 -03001722 return 0;
1723}
1724
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001725static int i915_sr_status(struct seq_file *m, void *unused)
1726{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001727 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001728 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001729 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001730 bool sr_enabled = false;
1731
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001732 intel_runtime_pm_get(dev_priv);
1733
Yuanhan Liu13982612010-12-15 15:42:31 +08001734 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001735 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001736 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1737 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001738 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1739 else if (IS_I915GM(dev))
1740 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1741 else if (IS_PINEVIEW(dev))
1742 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001743 else if (IS_VALLEYVIEW(dev))
1744 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001745
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001746 intel_runtime_pm_put(dev_priv);
1747
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001748 seq_printf(m, "self-refresh: %s\n",
1749 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001750
1751 return 0;
1752}
1753
Jesse Barnes7648fa92010-05-20 14:28:11 -07001754static int i915_emon_status(struct seq_file *m, void *unused)
1755{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001756 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001757 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001758 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001759 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001760 int ret;
1761
Chris Wilson582be6b2012-04-30 19:35:02 +01001762 if (!IS_GEN5(dev))
1763 return -ENODEV;
1764
Chris Wilsonde227ef2010-07-03 07:58:38 +01001765 ret = mutex_lock_interruptible(&dev->struct_mutex);
1766 if (ret)
1767 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001768
1769 temp = i915_mch_val(dev_priv);
1770 chipset = i915_chipset_val(dev_priv);
1771 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001772 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001773
1774 seq_printf(m, "GMCH temp: %ld\n", temp);
1775 seq_printf(m, "Chipset power: %ld\n", chipset);
1776 seq_printf(m, "GFX power: %ld\n", gfx);
1777 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1778
1779 return 0;
1780}
1781
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001782static int i915_ring_freq_table(struct seq_file *m, void *unused)
1783{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001784 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001785 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001786 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001787 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001788 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301789 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001790
Akash Goel97d33082015-06-29 14:50:23 +05301791 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001792 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001793 return 0;
1794 }
1795
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001796 intel_runtime_pm_get(dev_priv);
1797
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001798 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1799
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001800 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001801 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001802 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001803
Akash Goelf936ec32015-06-29 14:50:22 +05301804 if (IS_SKYLAKE(dev)) {
1805 /* Convert GT frequency to 50 HZ units */
1806 min_gpu_freq =
1807 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1808 max_gpu_freq =
1809 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1810 } else {
1811 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1812 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1813 }
1814
Damien Lespiau267f0c92013-06-24 22:59:48 +01001815 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001816
Akash Goelf936ec32015-06-29 14:50:22 +05301817 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001818 ia_freq = gpu_freq;
1819 sandybridge_pcode_read(dev_priv,
1820 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1821 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001822 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301823 intel_gpu_freq(dev_priv, (gpu_freq *
1824 (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001825 ((ia_freq >> 0) & 0xff) * 100,
1826 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001827 }
1828
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001829 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001830
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001831out:
1832 intel_runtime_pm_put(dev_priv);
1833 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001834}
1835
Chris Wilson44834a62010-08-19 16:09:23 +01001836static int i915_opregion(struct seq_file *m, void *unused)
1837{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001838 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001839 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001840 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001841 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001842 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001843 int ret;
1844
Daniel Vetter0d38f002012-04-21 22:49:10 +02001845 if (data == NULL)
1846 return -ENOMEM;
1847
Chris Wilson44834a62010-08-19 16:09:23 +01001848 ret = mutex_lock_interruptible(&dev->struct_mutex);
1849 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001850 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001851
Daniel Vetter0d38f002012-04-21 22:49:10 +02001852 if (opregion->header) {
Williams, Dan J115719f2015-10-12 21:12:57 +00001853 memcpy(data, opregion->header, OPREGION_SIZE);
Daniel Vetter0d38f002012-04-21 22:49:10 +02001854 seq_write(m, data, OPREGION_SIZE);
1855 }
Chris Wilson44834a62010-08-19 16:09:23 +01001856
1857 mutex_unlock(&dev->struct_mutex);
1858
Daniel Vetter0d38f002012-04-21 22:49:10 +02001859out:
1860 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001861 return 0;
1862}
1863
Chris Wilson37811fc2010-08-25 22:45:57 +01001864static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1865{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001866 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001867 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001868 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001869 struct intel_framebuffer *fb;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001870 struct drm_framebuffer *drm_fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001871
Daniel Vetter06957262015-08-10 13:34:08 +02001872#ifdef CONFIG_DRM_FBDEV_EMULATION
Daniel Vetter4520f532013-10-09 09:18:51 +02001873 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001874
1875 ifbdev = dev_priv->fbdev;
1876 fb = to_intel_framebuffer(ifbdev->helper.fb);
1877
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001878 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 +01001879 fb->base.width,
1880 fb->base.height,
1881 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001882 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001883 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001884 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001885 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001886 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001887#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001888
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001889 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001890 drm_for_each_fb(drm_fb, dev) {
1891 fb = to_intel_framebuffer(drm_fb);
Daniel Vetter131a56d2013-10-17 14:35:31 +02001892 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001893 continue;
1894
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001895 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 +01001896 fb->base.width,
1897 fb->base.height,
1898 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001899 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001900 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001901 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001902 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001903 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001904 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001905 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001906
1907 return 0;
1908}
1909
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001910static void describe_ctx_ringbuf(struct seq_file *m,
1911 struct intel_ringbuffer *ringbuf)
1912{
1913 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1914 ringbuf->space, ringbuf->head, ringbuf->tail,
1915 ringbuf->last_retired_head);
1916}
1917
Ben Widawskye76d3632011-03-19 18:14:29 -07001918static int i915_context_status(struct seq_file *m, void *unused)
1919{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001920 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001921 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001922 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001923 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001924 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001925 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001926
Daniel Vetterf3d28872014-05-29 23:23:08 +02001927 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001928 if (ret)
1929 return ret;
1930
Ben Widawskya33afea2013-09-17 21:12:45 -07001931 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001932 if (!i915.enable_execlists &&
1933 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001934 continue;
1935
Ben Widawskya33afea2013-09-17 21:12:45 -07001936 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001937 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001938 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001939 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001940 seq_printf(m, "(default context %s) ",
1941 ring->name);
1942 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001943
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001944 if (i915.enable_execlists) {
1945 seq_putc(m, '\n');
1946 for_each_ring(ring, dev_priv, i) {
1947 struct drm_i915_gem_object *ctx_obj =
1948 ctx->engine[i].state;
1949 struct intel_ringbuffer *ringbuf =
1950 ctx->engine[i].ringbuf;
1951
1952 seq_printf(m, "%s: ", ring->name);
1953 if (ctx_obj)
1954 describe_obj(m, ctx_obj);
1955 if (ringbuf)
1956 describe_ctx_ringbuf(m, ringbuf);
1957 seq_putc(m, '\n');
1958 }
1959 } else {
1960 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1961 }
1962
Ben Widawskya33afea2013-09-17 21:12:45 -07001963 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001964 }
1965
Daniel Vetterf3d28872014-05-29 23:23:08 +02001966 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001967
1968 return 0;
1969}
1970
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001971static void i915_dump_lrc_obj(struct seq_file *m,
1972 struct intel_engine_cs *ring,
1973 struct drm_i915_gem_object *ctx_obj)
1974{
1975 struct page *page;
1976 uint32_t *reg_state;
1977 int j;
1978 unsigned long ggtt_offset = 0;
1979
1980 if (ctx_obj == NULL) {
1981 seq_printf(m, "Context on %s with no gem object\n",
1982 ring->name);
1983 return;
1984 }
1985
1986 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1987 intel_execlists_ctx_id(ctx_obj));
1988
1989 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1990 seq_puts(m, "\tNot bound in GGTT\n");
1991 else
1992 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1993
1994 if (i915_gem_object_get_pages(ctx_obj)) {
1995 seq_puts(m, "\tFailed to get pages for context object\n");
1996 return;
1997 }
1998
Alex Daid1675192015-08-12 15:43:43 +01001999 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002000 if (!WARN_ON(page == NULL)) {
2001 reg_state = kmap_atomic(page);
2002
2003 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2004 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2005 ggtt_offset + 4096 + (j * 4),
2006 reg_state[j], reg_state[j + 1],
2007 reg_state[j + 2], reg_state[j + 3]);
2008 }
2009 kunmap_atomic(reg_state);
2010 }
2011
2012 seq_putc(m, '\n');
2013}
2014
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002015static int i915_dump_lrc(struct seq_file *m, void *unused)
2016{
2017 struct drm_info_node *node = (struct drm_info_node *) m->private;
2018 struct drm_device *dev = node->minor->dev;
2019 struct drm_i915_private *dev_priv = dev->dev_private;
2020 struct intel_engine_cs *ring;
2021 struct intel_context *ctx;
2022 int ret, i;
2023
2024 if (!i915.enable_execlists) {
2025 seq_printf(m, "Logical Ring Contexts are disabled\n");
2026 return 0;
2027 }
2028
2029 ret = mutex_lock_interruptible(&dev->struct_mutex);
2030 if (ret)
2031 return ret;
2032
2033 list_for_each_entry(ctx, &dev_priv->context_list, link) {
2034 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002035 if (ring->default_context != ctx)
2036 i915_dump_lrc_obj(m, ring,
2037 ctx->engine[i].state);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002038 }
2039 }
2040
2041 mutex_unlock(&dev->struct_mutex);
2042
2043 return 0;
2044}
2045
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002046static int i915_execlists(struct seq_file *m, void *data)
2047{
2048 struct drm_info_node *node = (struct drm_info_node *)m->private;
2049 struct drm_device *dev = node->minor->dev;
2050 struct drm_i915_private *dev_priv = dev->dev_private;
2051 struct intel_engine_cs *ring;
2052 u32 status_pointer;
2053 u8 read_pointer;
2054 u8 write_pointer;
2055 u32 status;
2056 u32 ctx_id;
2057 struct list_head *cursor;
2058 int ring_id, i;
2059 int ret;
2060
2061 if (!i915.enable_execlists) {
2062 seq_puts(m, "Logical Ring Contexts are disabled\n");
2063 return 0;
2064 }
2065
2066 ret = mutex_lock_interruptible(&dev->struct_mutex);
2067 if (ret)
2068 return ret;
2069
Michel Thierryfc0412e2014-10-16 16:13:38 +01002070 intel_runtime_pm_get(dev_priv);
2071
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002072 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002073 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002074 int count = 0;
2075 unsigned long flags;
2076
2077 seq_printf(m, "%s\n", ring->name);
2078
Ville Syrjälä83843d82015-09-18 20:03:15 +03002079 status = I915_READ(RING_EXECLIST_STATUS_LO(ring));
2080 ctx_id = I915_READ(RING_EXECLIST_STATUS_HI(ring));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002081 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2082 status, ctx_id);
2083
2084 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2085 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2086
2087 read_pointer = ring->next_context_status_buffer;
2088 write_pointer = status_pointer & 0x07;
2089 if (read_pointer > write_pointer)
2090 write_pointer += 6;
2091 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2092 read_pointer, write_pointer);
2093
2094 for (i = 0; i < 6; i++) {
Ville Syrjälä83843d82015-09-18 20:03:15 +03002095 status = I915_READ(RING_CONTEXT_STATUS_BUF_LO(ring, i));
2096 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF_HI(ring, i));
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002097
2098 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2099 i, status, ctx_id);
2100 }
2101
2102 spin_lock_irqsave(&ring->execlist_lock, flags);
2103 list_for_each(cursor, &ring->execlist_queue)
2104 count++;
2105 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002106 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002107 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2108
2109 seq_printf(m, "\t%d requests in queue\n", count);
2110 if (head_req) {
2111 struct drm_i915_gem_object *ctx_obj;
2112
Nick Hoath6d3d8272015-01-15 13:10:39 +00002113 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002114 seq_printf(m, "\tHead request id: %u\n",
2115 intel_execlists_ctx_id(ctx_obj));
2116 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002117 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002118 }
2119
2120 seq_putc(m, '\n');
2121 }
2122
Michel Thierryfc0412e2014-10-16 16:13:38 +01002123 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002124 mutex_unlock(&dev->struct_mutex);
2125
2126 return 0;
2127}
2128
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002129static const char *swizzle_string(unsigned swizzle)
2130{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002131 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002132 case I915_BIT_6_SWIZZLE_NONE:
2133 return "none";
2134 case I915_BIT_6_SWIZZLE_9:
2135 return "bit9";
2136 case I915_BIT_6_SWIZZLE_9_10:
2137 return "bit9/bit10";
2138 case I915_BIT_6_SWIZZLE_9_11:
2139 return "bit9/bit11";
2140 case I915_BIT_6_SWIZZLE_9_10_11:
2141 return "bit9/bit10/bit11";
2142 case I915_BIT_6_SWIZZLE_9_17:
2143 return "bit9/bit17";
2144 case I915_BIT_6_SWIZZLE_9_10_17:
2145 return "bit9/bit10/bit17";
2146 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002147 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002148 }
2149
2150 return "bug";
2151}
2152
2153static int i915_swizzle_info(struct seq_file *m, void *data)
2154{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002155 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002156 struct drm_device *dev = node->minor->dev;
2157 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002158 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002159
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002160 ret = mutex_lock_interruptible(&dev->struct_mutex);
2161 if (ret)
2162 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002163 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002164
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002165 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2166 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2167 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2168 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2169
2170 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2171 seq_printf(m, "DDC = 0x%08x\n",
2172 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002173 seq_printf(m, "DDC2 = 0x%08x\n",
2174 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002175 seq_printf(m, "C0DRB3 = 0x%04x\n",
2176 I915_READ16(C0DRB3));
2177 seq_printf(m, "C1DRB3 = 0x%04x\n",
2178 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002179 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002180 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2181 I915_READ(MAD_DIMM_C0));
2182 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2183 I915_READ(MAD_DIMM_C1));
2184 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2185 I915_READ(MAD_DIMM_C2));
2186 seq_printf(m, "TILECTL = 0x%08x\n",
2187 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002188 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002189 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2190 I915_READ(GAMTARBMODE));
2191 else
2192 seq_printf(m, "ARB_MODE = 0x%08x\n",
2193 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002194 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2195 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002196 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002197
2198 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2199 seq_puts(m, "L-shaped memory detected\n");
2200
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002201 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002202 mutex_unlock(&dev->struct_mutex);
2203
2204 return 0;
2205}
2206
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002207static int per_file_ctx(int id, void *ptr, void *data)
2208{
Oscar Mateo273497e2014-05-22 14:13:37 +01002209 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002210 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002211 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2212
2213 if (!ppgtt) {
2214 seq_printf(m, " no ppgtt for context %d\n",
2215 ctx->user_handle);
2216 return 0;
2217 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002218
Oscar Mateof83d6512014-05-22 14:13:38 +01002219 if (i915_gem_context_is_default(ctx))
2220 seq_puts(m, " default context:\n");
2221 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002222 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002223 ppgtt->debug_dump(ppgtt, m);
2224
2225 return 0;
2226}
2227
Ben Widawsky77df6772013-11-02 21:07:30 -07002228static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002229{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002230 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002231 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002232 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2233 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002234
Ben Widawsky77df6772013-11-02 21:07:30 -07002235 if (!ppgtt)
2236 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002237
Ben Widawsky77df6772013-11-02 21:07:30 -07002238 for_each_ring(ring, dev_priv, unused) {
2239 seq_printf(m, "%s\n", ring->name);
2240 for (i = 0; i < 4; i++) {
Ville Syrjäläd3a93cb2015-09-18 20:03:26 +03002241 u64 pdp = I915_READ(GEN8_RING_PDP_UDW(ring, i));
Ben Widawsky77df6772013-11-02 21:07:30 -07002242 pdp <<= 32;
Ville Syrjäläd3a93cb2015-09-18 20:03:26 +03002243 pdp |= I915_READ(GEN8_RING_PDP_LDW(ring, i));
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002244 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002245 }
2246 }
2247}
2248
2249static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2250{
2251 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002252 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002253 int i;
2254
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002255 if (INTEL_INFO(dev)->gen == 6)
2256 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2257
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002258 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002259 seq_printf(m, "%s\n", ring->name);
2260 if (INTEL_INFO(dev)->gen == 7)
2261 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2262 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2263 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2264 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2265 }
2266 if (dev_priv->mm.aliasing_ppgtt) {
2267 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2268
Damien Lespiau267f0c92013-06-24 22:59:48 +01002269 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002270 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002271
Ben Widawsky87d60b62013-12-06 14:11:29 -08002272 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002273 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002274
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002275 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002276}
2277
2278static int i915_ppgtt_info(struct seq_file *m, void *data)
2279{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002280 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002281 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002282 struct drm_i915_private *dev_priv = dev->dev_private;
Michel Thierryea91e402015-07-29 17:23:57 +01002283 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002284
2285 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2286 if (ret)
2287 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002288 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002289
2290 if (INTEL_INFO(dev)->gen >= 8)
2291 gen8_ppgtt_info(m, dev);
2292 else if (INTEL_INFO(dev)->gen >= 6)
2293 gen6_ppgtt_info(m, dev);
2294
Michel Thierryea91e402015-07-29 17:23:57 +01002295 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2296 struct drm_i915_file_private *file_priv = file->driver_priv;
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002297 struct task_struct *task;
Michel Thierryea91e402015-07-29 17:23:57 +01002298
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002299 task = get_pid_task(file->pid, PIDTYPE_PID);
Dan Carpenter06812762015-10-02 18:14:22 +03002300 if (!task) {
2301 ret = -ESRCH;
2302 goto out_put;
2303 }
Geliang Tang7cb5dff2015-09-25 03:58:11 -07002304 seq_printf(m, "\nproc: %s\n", task->comm);
2305 put_task_struct(task);
Michel Thierryea91e402015-07-29 17:23:57 +01002306 idr_for_each(&file_priv->context_idr, per_file_ctx,
2307 (void *)(unsigned long)m);
2308 }
2309
Dan Carpenter06812762015-10-02 18:14:22 +03002310out_put:
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002311 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002312 mutex_unlock(&dev->struct_mutex);
2313
Dan Carpenter06812762015-10-02 18:14:22 +03002314 return ret;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002315}
2316
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002317static int count_irq_waiters(struct drm_i915_private *i915)
2318{
2319 struct intel_engine_cs *ring;
2320 int count = 0;
2321 int i;
2322
2323 for_each_ring(ring, i915, i)
2324 count += ring->irq_refcount;
2325
2326 return count;
2327}
2328
Chris Wilson1854d5c2015-04-07 16:20:32 +01002329static int i915_rps_boost_info(struct seq_file *m, void *data)
2330{
2331 struct drm_info_node *node = m->private;
2332 struct drm_device *dev = node->minor->dev;
2333 struct drm_i915_private *dev_priv = dev->dev_private;
2334 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002335
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002336 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2337 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2338 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2339 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2340 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2341 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2342 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2343 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2344 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson8d3afd72015-05-21 21:01:47 +01002345 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002346 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2347 struct drm_i915_file_private *file_priv = file->driver_priv;
2348 struct task_struct *task;
2349
2350 rcu_read_lock();
2351 task = pid_task(file->pid, PIDTYPE_PID);
2352 seq_printf(m, "%s [%d]: %d boosts%s\n",
2353 task ? task->comm : "<unknown>",
2354 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002355 file_priv->rps.boosts,
2356 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002357 rcu_read_unlock();
2358 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002359 seq_printf(m, "Semaphore boosts: %d%s\n",
2360 dev_priv->rps.semaphores.boosts,
2361 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2362 seq_printf(m, "MMIO flip boosts: %d%s\n",
2363 dev_priv->rps.mmioflips.boosts,
2364 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002365 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002366 spin_unlock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002367
Chris Wilson8d3afd72015-05-21 21:01:47 +01002368 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002369}
2370
Ben Widawsky63573eb2013-07-04 11:02:07 -07002371static int i915_llc(struct seq_file *m, void *data)
2372{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002373 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002374 struct drm_device *dev = node->minor->dev;
2375 struct drm_i915_private *dev_priv = dev->dev_private;
2376
2377 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2378 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2379 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2380
2381 return 0;
2382}
2383
Alex Daifdf5d352015-08-12 15:43:37 +01002384static int i915_guc_load_status_info(struct seq_file *m, void *data)
2385{
2386 struct drm_info_node *node = m->private;
2387 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2388 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2389 u32 tmp, i;
2390
2391 if (!HAS_GUC_UCODE(dev_priv->dev))
2392 return 0;
2393
2394 seq_printf(m, "GuC firmware status:\n");
2395 seq_printf(m, "\tpath: %s\n",
2396 guc_fw->guc_fw_path);
2397 seq_printf(m, "\tfetch: %s\n",
2398 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2399 seq_printf(m, "\tload: %s\n",
2400 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2401 seq_printf(m, "\tversion wanted: %d.%d\n",
2402 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2403 seq_printf(m, "\tversion found: %d.%d\n",
2404 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
2405
2406 tmp = I915_READ(GUC_STATUS);
2407
2408 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2409 seq_printf(m, "\tBootrom status = 0x%x\n",
2410 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2411 seq_printf(m, "\tuKernel status = 0x%x\n",
2412 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2413 seq_printf(m, "\tMIA Core status = 0x%x\n",
2414 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2415 seq_puts(m, "\nScratch registers:\n");
2416 for (i = 0; i < 16; i++)
2417 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2418
2419 return 0;
2420}
2421
Dave Gordon8b417c22015-08-12 15:43:44 +01002422static void i915_guc_client_info(struct seq_file *m,
2423 struct drm_i915_private *dev_priv,
2424 struct i915_guc_client *client)
2425{
2426 struct intel_engine_cs *ring;
2427 uint64_t tot = 0;
2428 uint32_t i;
2429
2430 seq_printf(m, "\tPriority %d, GuC ctx index: %u, PD offset 0x%x\n",
2431 client->priority, client->ctx_index, client->proc_desc_offset);
2432 seq_printf(m, "\tDoorbell id %d, offset: 0x%x, cookie 0x%x\n",
2433 client->doorbell_id, client->doorbell_offset, client->cookie);
2434 seq_printf(m, "\tWQ size %d, offset: 0x%x, tail %d\n",
2435 client->wq_size, client->wq_offset, client->wq_tail);
2436
2437 seq_printf(m, "\tFailed to queue: %u\n", client->q_fail);
2438 seq_printf(m, "\tFailed doorbell: %u\n", client->b_fail);
2439 seq_printf(m, "\tLast submission result: %d\n", client->retcode);
2440
2441 for_each_ring(ring, dev_priv, i) {
2442 seq_printf(m, "\tSubmissions: %llu %s\n",
2443 client->submissions[i],
2444 ring->name);
2445 tot += client->submissions[i];
2446 }
2447 seq_printf(m, "\tTotal: %llu\n", tot);
2448}
2449
2450static int i915_guc_info(struct seq_file *m, void *data)
2451{
2452 struct drm_info_node *node = m->private;
2453 struct drm_device *dev = node->minor->dev;
2454 struct drm_i915_private *dev_priv = dev->dev_private;
2455 struct intel_guc guc;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03002456 struct i915_guc_client client = {};
Dave Gordon8b417c22015-08-12 15:43:44 +01002457 struct intel_engine_cs *ring;
2458 enum intel_ring_id i;
2459 u64 total = 0;
2460
2461 if (!HAS_GUC_SCHED(dev_priv->dev))
2462 return 0;
2463
2464 /* Take a local copy of the GuC data, so we can dump it at leisure */
2465 spin_lock(&dev_priv->guc.host2guc_lock);
2466 guc = dev_priv->guc;
2467 if (guc.execbuf_client) {
2468 spin_lock(&guc.execbuf_client->wq_lock);
2469 client = *guc.execbuf_client;
2470 spin_unlock(&guc.execbuf_client->wq_lock);
2471 }
2472 spin_unlock(&dev_priv->guc.host2guc_lock);
2473
2474 seq_printf(m, "GuC total action count: %llu\n", guc.action_count);
2475 seq_printf(m, "GuC action failure count: %u\n", guc.action_fail);
2476 seq_printf(m, "GuC last action command: 0x%x\n", guc.action_cmd);
2477 seq_printf(m, "GuC last action status: 0x%x\n", guc.action_status);
2478 seq_printf(m, "GuC last action error code: %d\n", guc.action_err);
2479
2480 seq_printf(m, "\nGuC submissions:\n");
2481 for_each_ring(ring, dev_priv, i) {
2482 seq_printf(m, "\t%-24s: %10llu, last seqno 0x%08x %9d\n",
2483 ring->name, guc.submissions[i],
2484 guc.last_seqno[i], guc.last_seqno[i]);
2485 total += guc.submissions[i];
2486 }
2487 seq_printf(m, "\t%s: %llu\n", "Total", total);
2488
2489 seq_printf(m, "\nGuC execbuf client @ %p:\n", guc.execbuf_client);
2490 i915_guc_client_info(m, dev_priv, &client);
2491
2492 /* Add more as required ... */
2493
2494 return 0;
2495}
2496
Alex Dai4c7e77f2015-08-12 15:43:40 +01002497static int i915_guc_log_dump(struct seq_file *m, void *data)
2498{
2499 struct drm_info_node *node = m->private;
2500 struct drm_device *dev = node->minor->dev;
2501 struct drm_i915_private *dev_priv = dev->dev_private;
2502 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2503 u32 *log;
2504 int i = 0, pg;
2505
2506 if (!log_obj)
2507 return 0;
2508
2509 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2510 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2511
2512 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2513 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2514 *(log + i), *(log + i + 1),
2515 *(log + i + 2), *(log + i + 3));
2516
2517 kunmap_atomic(log);
2518 }
2519
2520 seq_putc(m, '\n');
2521
2522 return 0;
2523}
2524
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002525static int i915_edp_psr_status(struct seq_file *m, void *data)
2526{
2527 struct drm_info_node *node = m->private;
2528 struct drm_device *dev = node->minor->dev;
2529 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002530 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002531 u32 stat[3];
2532 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002533 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002534
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002535 if (!HAS_PSR(dev)) {
2536 seq_puts(m, "PSR not supported\n");
2537 return 0;
2538 }
2539
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002540 intel_runtime_pm_get(dev_priv);
2541
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002542 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002543 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2544 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002545 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002546 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002547 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2548 dev_priv->psr.busy_frontbuffer_bits);
2549 seq_printf(m, "Re-enable work scheduled: %s\n",
2550 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002551
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002552 if (HAS_DDI(dev))
2553 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2554 else {
2555 for_each_pipe(dev_priv, pipe) {
2556 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2557 VLV_EDP_PSR_CURR_STATE_MASK;
2558 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2559 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2560 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002561 }
2562 }
2563 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002564
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002565 if (!HAS_DDI(dev))
2566 for_each_pipe(dev_priv, pipe) {
2567 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2568 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2569 seq_printf(m, " pipe %c", pipe_name(pipe));
2570 }
2571 seq_puts(m, "\n");
2572
2573 /* CHV PSR has no kind of performance counter */
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002574 if (HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002575 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2576 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002577
2578 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2579 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002580 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002581
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002582 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002583 return 0;
2584}
2585
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002586static int i915_sink_crc(struct seq_file *m, void *data)
2587{
2588 struct drm_info_node *node = m->private;
2589 struct drm_device *dev = node->minor->dev;
2590 struct intel_encoder *encoder;
2591 struct intel_connector *connector;
2592 struct intel_dp *intel_dp = NULL;
2593 int ret;
2594 u8 crc[6];
2595
2596 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002597 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002598
2599 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2600 continue;
2601
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002602 if (!connector->base.encoder)
2603 continue;
2604
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002605 encoder = to_intel_encoder(connector->base.encoder);
2606 if (encoder->type != INTEL_OUTPUT_EDP)
2607 continue;
2608
2609 intel_dp = enc_to_intel_dp(&encoder->base);
2610
2611 ret = intel_dp_sink_crc(intel_dp, crc);
2612 if (ret)
2613 goto out;
2614
2615 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2616 crc[0], crc[1], crc[2],
2617 crc[3], crc[4], crc[5]);
2618 goto out;
2619 }
2620 ret = -ENODEV;
2621out:
2622 drm_modeset_unlock_all(dev);
2623 return ret;
2624}
2625
Jesse Barnesec013e72013-08-20 10:29:23 +01002626static int i915_energy_uJ(struct seq_file *m, void *data)
2627{
2628 struct drm_info_node *node = m->private;
2629 struct drm_device *dev = node->minor->dev;
2630 struct drm_i915_private *dev_priv = dev->dev_private;
2631 u64 power;
2632 u32 units;
2633
2634 if (INTEL_INFO(dev)->gen < 6)
2635 return -ENODEV;
2636
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002637 intel_runtime_pm_get(dev_priv);
2638
Jesse Barnesec013e72013-08-20 10:29:23 +01002639 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2640 power = (power & 0x1f00) >> 8;
2641 units = 1000000 / (1 << power); /* convert to uJ */
2642 power = I915_READ(MCH_SECP_NRG_STTS);
2643 power *= units;
2644
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002645 intel_runtime_pm_put(dev_priv);
2646
Jesse Barnesec013e72013-08-20 10:29:23 +01002647 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002648
2649 return 0;
2650}
2651
Damien Lespiau6455c872015-06-04 18:23:57 +01002652static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002653{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002654 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002655 struct drm_device *dev = node->minor->dev;
2656 struct drm_i915_private *dev_priv = dev->dev_private;
2657
Damien Lespiau6455c872015-06-04 18:23:57 +01002658 if (!HAS_RUNTIME_PM(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002659 seq_puts(m, "not supported\n");
2660 return 0;
2661 }
2662
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002663 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002664 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002665 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002666#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002667 seq_printf(m, "Usage count: %d\n",
2668 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002669#else
2670 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2671#endif
Paulo Zanoni371db662013-08-19 13:18:10 -03002672
Jesse Barnesec013e72013-08-20 10:29:23 +01002673 return 0;
2674}
2675
Imre Deak1da51582013-11-25 17:15:35 +02002676static const char *power_domain_str(enum intel_display_power_domain domain)
2677{
2678 switch (domain) {
2679 case POWER_DOMAIN_PIPE_A:
2680 return "PIPE_A";
2681 case POWER_DOMAIN_PIPE_B:
2682 return "PIPE_B";
2683 case POWER_DOMAIN_PIPE_C:
2684 return "PIPE_C";
2685 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2686 return "PIPE_A_PANEL_FITTER";
2687 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2688 return "PIPE_B_PANEL_FITTER";
2689 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2690 return "PIPE_C_PANEL_FITTER";
2691 case POWER_DOMAIN_TRANSCODER_A:
2692 return "TRANSCODER_A";
2693 case POWER_DOMAIN_TRANSCODER_B:
2694 return "TRANSCODER_B";
2695 case POWER_DOMAIN_TRANSCODER_C:
2696 return "TRANSCODER_C";
2697 case POWER_DOMAIN_TRANSCODER_EDP:
2698 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002699 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2700 return "PORT_DDI_A_2_LANES";
2701 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2702 return "PORT_DDI_A_4_LANES";
2703 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2704 return "PORT_DDI_B_2_LANES";
2705 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2706 return "PORT_DDI_B_4_LANES";
2707 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2708 return "PORT_DDI_C_2_LANES";
2709 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2710 return "PORT_DDI_C_4_LANES";
2711 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2712 return "PORT_DDI_D_2_LANES";
2713 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2714 return "PORT_DDI_D_4_LANES";
Xiong Zhangd8e19f92015-08-13 18:00:12 +08002715 case POWER_DOMAIN_PORT_DDI_E_2_LANES:
2716 return "PORT_DDI_E_2_LANES";
Imre Deak319be8a2014-03-04 19:22:57 +02002717 case POWER_DOMAIN_PORT_DSI:
2718 return "PORT_DSI";
2719 case POWER_DOMAIN_PORT_CRT:
2720 return "PORT_CRT";
2721 case POWER_DOMAIN_PORT_OTHER:
2722 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002723 case POWER_DOMAIN_VGA:
2724 return "VGA";
2725 case POWER_DOMAIN_AUDIO:
2726 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002727 case POWER_DOMAIN_PLLS:
2728 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002729 case POWER_DOMAIN_AUX_A:
2730 return "AUX_A";
2731 case POWER_DOMAIN_AUX_B:
2732 return "AUX_B";
2733 case POWER_DOMAIN_AUX_C:
2734 return "AUX_C";
2735 case POWER_DOMAIN_AUX_D:
2736 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002737 case POWER_DOMAIN_INIT:
2738 return "INIT";
2739 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002740 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002741 return "?";
2742 }
2743}
2744
2745static int i915_power_domain_info(struct seq_file *m, void *unused)
2746{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002747 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002748 struct drm_device *dev = node->minor->dev;
2749 struct drm_i915_private *dev_priv = dev->dev_private;
2750 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2751 int i;
2752
2753 mutex_lock(&power_domains->lock);
2754
2755 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2756 for (i = 0; i < power_domains->power_well_count; i++) {
2757 struct i915_power_well *power_well;
2758 enum intel_display_power_domain power_domain;
2759
2760 power_well = &power_domains->power_wells[i];
2761 seq_printf(m, "%-25s %d\n", power_well->name,
2762 power_well->count);
2763
2764 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2765 power_domain++) {
2766 if (!(BIT(power_domain) & power_well->domains))
2767 continue;
2768
2769 seq_printf(m, " %-23s %d\n",
2770 power_domain_str(power_domain),
2771 power_domains->domain_use_count[power_domain]);
2772 }
2773 }
2774
2775 mutex_unlock(&power_domains->lock);
2776
2777 return 0;
2778}
2779
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002780static void intel_seq_print_mode(struct seq_file *m, int tabs,
2781 struct drm_display_mode *mode)
2782{
2783 int i;
2784
2785 for (i = 0; i < tabs; i++)
2786 seq_putc(m, '\t');
2787
2788 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",
2789 mode->base.id, mode->name,
2790 mode->vrefresh, mode->clock,
2791 mode->hdisplay, mode->hsync_start,
2792 mode->hsync_end, mode->htotal,
2793 mode->vdisplay, mode->vsync_start,
2794 mode->vsync_end, mode->vtotal,
2795 mode->type, mode->flags);
2796}
2797
2798static void intel_encoder_info(struct seq_file *m,
2799 struct intel_crtc *intel_crtc,
2800 struct intel_encoder *intel_encoder)
2801{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002802 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002803 struct drm_device *dev = node->minor->dev;
2804 struct drm_crtc *crtc = &intel_crtc->base;
2805 struct intel_connector *intel_connector;
2806 struct drm_encoder *encoder;
2807
2808 encoder = &intel_encoder->base;
2809 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a02014-06-03 14:56:21 +03002810 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002811 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2812 struct drm_connector *connector = &intel_connector->base;
2813 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2814 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002815 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002816 drm_get_connector_status_name(connector->status));
2817 if (connector->status == connector_status_connected) {
2818 struct drm_display_mode *mode = &crtc->mode;
2819 seq_printf(m, ", mode:\n");
2820 intel_seq_print_mode(m, 2, mode);
2821 } else {
2822 seq_putc(m, '\n');
2823 }
2824 }
2825}
2826
2827static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2828{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002829 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002830 struct drm_device *dev = node->minor->dev;
2831 struct drm_crtc *crtc = &intel_crtc->base;
2832 struct intel_encoder *intel_encoder;
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002833 struct drm_plane_state *plane_state = crtc->primary->state;
2834 struct drm_framebuffer *fb = plane_state->fb;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002835
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002836 if (fb)
Matt Roper5aa8a932014-06-16 10:12:55 -07002837 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
Maarten Lankhorst23a48d52015-09-10 16:07:57 +02002838 fb->base.id, plane_state->src_x >> 16,
2839 plane_state->src_y >> 16, fb->width, fb->height);
Matt Roper5aa8a932014-06-16 10:12:55 -07002840 else
2841 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002842 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2843 intel_encoder_info(m, intel_crtc, intel_encoder);
2844}
2845
2846static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2847{
2848 struct drm_display_mode *mode = panel->fixed_mode;
2849
2850 seq_printf(m, "\tfixed mode:\n");
2851 intel_seq_print_mode(m, 2, mode);
2852}
2853
2854static void intel_dp_info(struct seq_file *m,
2855 struct intel_connector *intel_connector)
2856{
2857 struct intel_encoder *intel_encoder = intel_connector->encoder;
2858 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2859
2860 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
Jani Nikula742f4912015-09-03 11:16:09 +03002861 seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002862 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2863 intel_panel_info(m, &intel_connector->panel);
2864}
2865
2866static void intel_hdmi_info(struct seq_file *m,
2867 struct intel_connector *intel_connector)
2868{
2869 struct intel_encoder *intel_encoder = intel_connector->encoder;
2870 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2871
Jani Nikula742f4912015-09-03 11:16:09 +03002872 seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002873}
2874
2875static void intel_lvds_info(struct seq_file *m,
2876 struct intel_connector *intel_connector)
2877{
2878 intel_panel_info(m, &intel_connector->panel);
2879}
2880
2881static void intel_connector_info(struct seq_file *m,
2882 struct drm_connector *connector)
2883{
2884 struct intel_connector *intel_connector = to_intel_connector(connector);
2885 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002886 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002887
2888 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002889 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002890 drm_get_connector_status_name(connector->status));
2891 if (connector->status == connector_status_connected) {
2892 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2893 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2894 connector->display_info.width_mm,
2895 connector->display_info.height_mm);
2896 seq_printf(m, "\tsubpixel order: %s\n",
2897 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2898 seq_printf(m, "\tCEA rev: %d\n",
2899 connector->display_info.cea_rev);
2900 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002901 if (intel_encoder) {
2902 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2903 intel_encoder->type == INTEL_OUTPUT_EDP)
2904 intel_dp_info(m, intel_connector);
2905 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2906 intel_hdmi_info(m, intel_connector);
2907 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2908 intel_lvds_info(m, intel_connector);
2909 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002910
Jesse Barnesf103fc72014-02-20 12:39:57 -08002911 seq_printf(m, "\tmodes:\n");
2912 list_for_each_entry(mode, &connector->modes, head)
2913 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002914}
2915
Chris Wilson065f2ec2014-03-12 09:13:13 +00002916static bool cursor_active(struct drm_device *dev, int pipe)
2917{
2918 struct drm_i915_private *dev_priv = dev->dev_private;
2919 u32 state;
2920
2921 if (IS_845G(dev) || IS_I865G(dev))
Ville Syrjälä0b87c242015-09-22 19:47:51 +03002922 state = I915_READ(CURCNTR(PIPE_A)) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002923 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002924 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002925
2926 return state;
2927}
2928
2929static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2930{
2931 struct drm_i915_private *dev_priv = dev->dev_private;
2932 u32 pos;
2933
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002934 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002935
2936 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2937 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2938 *x = -*x;
2939
2940 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2941 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2942 *y = -*y;
2943
2944 return cursor_active(dev, pipe);
2945}
2946
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002947static int i915_display_info(struct seq_file *m, void *unused)
2948{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002949 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002950 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002951 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002952 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002953 struct drm_connector *connector;
2954
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002955 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002956 drm_modeset_lock_all(dev);
2957 seq_printf(m, "CRTC info\n");
2958 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002959 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002960 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002961 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002962 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002963
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002964 pipe_config = to_intel_crtc_state(crtc->base.state);
2965
Chris Wilson57127ef2014-07-04 08:20:11 +01002966 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002967 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002968 yesno(pipe_config->base.active),
2969 pipe_config->pipe_src_w, pipe_config->pipe_src_h);
2970 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002971 intel_crtc_info(m, crtc);
2972
Paulo Zanonia23dc652014-04-01 14:55:11 -03002973 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002974 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 +03002975 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08002976 x, y, crtc->base.cursor->state->crtc_w,
2977 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01002978 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002979 }
Daniel Vettercace8412014-05-22 17:56:31 +02002980
2981 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2982 yesno(!crtc->cpu_fifo_underrun_disabled),
2983 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002984 }
2985
2986 seq_printf(m, "\n");
2987 seq_printf(m, "Connector info\n");
2988 seq_printf(m, "--------------\n");
2989 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2990 intel_connector_info(m, connector);
2991 }
2992 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002993 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002994
2995 return 0;
2996}
2997
Ben Widawskye04934c2014-06-30 09:53:42 -07002998static int i915_semaphore_status(struct seq_file *m, void *unused)
2999{
3000 struct drm_info_node *node = (struct drm_info_node *) m->private;
3001 struct drm_device *dev = node->minor->dev;
3002 struct drm_i915_private *dev_priv = dev->dev_private;
3003 struct intel_engine_cs *ring;
3004 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
3005 int i, j, ret;
3006
3007 if (!i915_semaphore_is_enabled(dev)) {
3008 seq_puts(m, "Semaphores are disabled\n");
3009 return 0;
3010 }
3011
3012 ret = mutex_lock_interruptible(&dev->struct_mutex);
3013 if (ret)
3014 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03003015 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003016
3017 if (IS_BROADWELL(dev)) {
3018 struct page *page;
3019 uint64_t *seqno;
3020
3021 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
3022
3023 seqno = (uint64_t *)kmap_atomic(page);
3024 for_each_ring(ring, dev_priv, i) {
3025 uint64_t offset;
3026
3027 seq_printf(m, "%s\n", ring->name);
3028
3029 seq_puts(m, " Last signal:");
3030 for (j = 0; j < num_rings; j++) {
3031 offset = i * I915_NUM_RINGS + j;
3032 seq_printf(m, "0x%08llx (0x%02llx) ",
3033 seqno[offset], offset * 8);
3034 }
3035 seq_putc(m, '\n');
3036
3037 seq_puts(m, " Last wait: ");
3038 for (j = 0; j < num_rings; j++) {
3039 offset = i + (j * I915_NUM_RINGS);
3040 seq_printf(m, "0x%08llx (0x%02llx) ",
3041 seqno[offset], offset * 8);
3042 }
3043 seq_putc(m, '\n');
3044
3045 }
3046 kunmap_atomic(seqno);
3047 } else {
3048 seq_puts(m, " Last signal:");
3049 for_each_ring(ring, dev_priv, i)
3050 for (j = 0; j < num_rings; j++)
3051 seq_printf(m, "0x%08x\n",
3052 I915_READ(ring->semaphore.mbox.signal[j]));
3053 seq_putc(m, '\n');
3054 }
3055
3056 seq_puts(m, "\nSync seqno:\n");
3057 for_each_ring(ring, dev_priv, i) {
3058 for (j = 0; j < num_rings; j++) {
3059 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
3060 }
3061 seq_putc(m, '\n');
3062 }
3063 seq_putc(m, '\n');
3064
Paulo Zanoni03872062014-07-09 14:31:57 -03003065 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07003066 mutex_unlock(&dev->struct_mutex);
3067 return 0;
3068}
3069
Daniel Vetter728e29d2014-06-25 22:01:53 +03003070static int i915_shared_dplls_info(struct seq_file *m, void *unused)
3071{
3072 struct drm_info_node *node = (struct drm_info_node *) m->private;
3073 struct drm_device *dev = node->minor->dev;
3074 struct drm_i915_private *dev_priv = dev->dev_private;
3075 int i;
3076
3077 drm_modeset_lock_all(dev);
3078 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
3079 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
3080
3081 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02003082 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003083 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003084 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003085 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3086 seq_printf(m, " dpll_md: 0x%08x\n",
3087 pll->config.hw_state.dpll_md);
3088 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3089 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3090 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003091 }
3092 drm_modeset_unlock_all(dev);
3093
3094 return 0;
3095}
3096
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003097static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003098{
3099 int i;
3100 int ret;
3101 struct drm_info_node *node = (struct drm_info_node *) m->private;
3102 struct drm_device *dev = node->minor->dev;
3103 struct drm_i915_private *dev_priv = dev->dev_private;
3104
Arun Siluvery888b5992014-08-26 14:44:51 +01003105 ret = mutex_lock_interruptible(&dev->struct_mutex);
3106 if (ret)
3107 return ret;
3108
3109 intel_runtime_pm_get(dev_priv);
3110
Mika Kuoppala72253422014-10-07 17:21:26 +03003111 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
3112 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003113 u32 addr, mask, value, read;
3114 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003115
Mika Kuoppala72253422014-10-07 17:21:26 +03003116 addr = dev_priv->workarounds.reg[i].addr;
3117 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003118 value = dev_priv->workarounds.reg[i].value;
3119 read = I915_READ(addr);
3120 ok = (value & mask) == (read & mask);
3121 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
3122 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003123 }
3124
3125 intel_runtime_pm_put(dev_priv);
3126 mutex_unlock(&dev->struct_mutex);
3127
3128 return 0;
3129}
3130
Damien Lespiauc5511e42014-11-04 17:06:51 +00003131static int i915_ddb_info(struct seq_file *m, void *unused)
3132{
3133 struct drm_info_node *node = m->private;
3134 struct drm_device *dev = node->minor->dev;
3135 struct drm_i915_private *dev_priv = dev->dev_private;
3136 struct skl_ddb_allocation *ddb;
3137 struct skl_ddb_entry *entry;
3138 enum pipe pipe;
3139 int plane;
3140
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003141 if (INTEL_INFO(dev)->gen < 9)
3142 return 0;
3143
Damien Lespiauc5511e42014-11-04 17:06:51 +00003144 drm_modeset_lock_all(dev);
3145
3146 ddb = &dev_priv->wm.skl_hw.ddb;
3147
3148 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3149
3150 for_each_pipe(dev_priv, pipe) {
3151 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3152
Damien Lespiaudd740782015-02-28 14:54:08 +00003153 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003154 entry = &ddb->plane[pipe][plane];
3155 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3156 entry->start, entry->end,
3157 skl_ddb_entry_size(entry));
3158 }
3159
Matt Roper4969d332015-09-24 15:53:10 -07003160 entry = &ddb->plane[pipe][PLANE_CURSOR];
Damien Lespiauc5511e42014-11-04 17:06:51 +00003161 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3162 entry->end, skl_ddb_entry_size(entry));
3163 }
3164
3165 drm_modeset_unlock_all(dev);
3166
3167 return 0;
3168}
3169
Vandana Kannana54746e2015-03-03 20:53:10 +05303170static void drrs_status_per_crtc(struct seq_file *m,
3171 struct drm_device *dev, struct intel_crtc *intel_crtc)
3172{
3173 struct intel_encoder *intel_encoder;
3174 struct drm_i915_private *dev_priv = dev->dev_private;
3175 struct i915_drrs *drrs = &dev_priv->drrs;
3176 int vrefresh = 0;
3177
3178 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3179 /* Encoder connected on this CRTC */
3180 switch (intel_encoder->type) {
3181 case INTEL_OUTPUT_EDP:
3182 seq_puts(m, "eDP:\n");
3183 break;
3184 case INTEL_OUTPUT_DSI:
3185 seq_puts(m, "DSI:\n");
3186 break;
3187 case INTEL_OUTPUT_HDMI:
3188 seq_puts(m, "HDMI:\n");
3189 break;
3190 case INTEL_OUTPUT_DISPLAYPORT:
3191 seq_puts(m, "DP:\n");
3192 break;
3193 default:
3194 seq_printf(m, "Other encoder (id=%d).\n",
3195 intel_encoder->type);
3196 return;
3197 }
3198 }
3199
3200 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3201 seq_puts(m, "\tVBT: DRRS_type: Static");
3202 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3203 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3204 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3205 seq_puts(m, "\tVBT: DRRS_type: None");
3206 else
3207 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3208
3209 seq_puts(m, "\n\n");
3210
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003211 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303212 struct intel_panel *panel;
3213
3214 mutex_lock(&drrs->mutex);
3215 /* DRRS Supported */
3216 seq_puts(m, "\tDRRS Supported: Yes\n");
3217
3218 /* disable_drrs() will make drrs->dp NULL */
3219 if (!drrs->dp) {
3220 seq_puts(m, "Idleness DRRS: Disabled");
3221 mutex_unlock(&drrs->mutex);
3222 return;
3223 }
3224
3225 panel = &drrs->dp->attached_connector->panel;
3226 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3227 drrs->busy_frontbuffer_bits);
3228
3229 seq_puts(m, "\n\t\t");
3230 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3231 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3232 vrefresh = panel->fixed_mode->vrefresh;
3233 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3234 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3235 vrefresh = panel->downclock_mode->vrefresh;
3236 } else {
3237 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3238 drrs->refresh_rate_type);
3239 mutex_unlock(&drrs->mutex);
3240 return;
3241 }
3242 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3243
3244 seq_puts(m, "\n\t\t");
3245 mutex_unlock(&drrs->mutex);
3246 } else {
3247 /* DRRS not supported. Print the VBT parameter*/
3248 seq_puts(m, "\tDRRS Supported : No");
3249 }
3250 seq_puts(m, "\n");
3251}
3252
3253static int i915_drrs_status(struct seq_file *m, void *unused)
3254{
3255 struct drm_info_node *node = m->private;
3256 struct drm_device *dev = node->minor->dev;
3257 struct intel_crtc *intel_crtc;
3258 int active_crtc_cnt = 0;
3259
3260 for_each_intel_crtc(dev, intel_crtc) {
3261 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3262
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003263 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303264 active_crtc_cnt++;
3265 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3266
3267 drrs_status_per_crtc(m, dev, intel_crtc);
3268 }
3269
3270 drm_modeset_unlock(&intel_crtc->base.mutex);
3271 }
3272
3273 if (!active_crtc_cnt)
3274 seq_puts(m, "No active crtc found\n");
3275
3276 return 0;
3277}
3278
Damien Lespiau07144422013-10-15 18:55:40 +01003279struct pipe_crc_info {
3280 const char *name;
3281 struct drm_device *dev;
3282 enum pipe pipe;
3283};
3284
Dave Airlie11bed952014-05-12 15:22:27 +10003285static int i915_dp_mst_info(struct seq_file *m, void *unused)
3286{
3287 struct drm_info_node *node = (struct drm_info_node *) m->private;
3288 struct drm_device *dev = node->minor->dev;
3289 struct drm_encoder *encoder;
3290 struct intel_encoder *intel_encoder;
3291 struct intel_digital_port *intel_dig_port;
3292 drm_modeset_lock_all(dev);
3293 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3294 intel_encoder = to_intel_encoder(encoder);
3295 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3296 continue;
3297 intel_dig_port = enc_to_dig_port(encoder);
3298 if (!intel_dig_port->dp.can_mst)
3299 continue;
3300
3301 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3302 }
3303 drm_modeset_unlock_all(dev);
3304 return 0;
3305}
3306
Damien Lespiau07144422013-10-15 18:55:40 +01003307static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003308{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003309 struct pipe_crc_info *info = inode->i_private;
3310 struct drm_i915_private *dev_priv = info->dev->dev_private;
3311 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3312
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003313 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3314 return -ENODEV;
3315
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003316 spin_lock_irq(&pipe_crc->lock);
3317
3318 if (pipe_crc->opened) {
3319 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003320 return -EBUSY; /* already open */
3321 }
3322
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003323 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003324 filep->private_data = inode->i_private;
3325
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003326 spin_unlock_irq(&pipe_crc->lock);
3327
Damien Lespiau07144422013-10-15 18:55:40 +01003328 return 0;
3329}
3330
3331static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3332{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003333 struct pipe_crc_info *info = inode->i_private;
3334 struct drm_i915_private *dev_priv = info->dev->dev_private;
3335 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3336
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003337 spin_lock_irq(&pipe_crc->lock);
3338 pipe_crc->opened = false;
3339 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003340
Damien Lespiau07144422013-10-15 18:55:40 +01003341 return 0;
3342}
3343
3344/* (6 fields, 8 chars each, space separated (5) + '\n') */
3345#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3346/* account for \'0' */
3347#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3348
3349static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3350{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003351 assert_spin_locked(&pipe_crc->lock);
3352 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3353 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003354}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003355
Damien Lespiau07144422013-10-15 18:55:40 +01003356static ssize_t
3357i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3358 loff_t *pos)
3359{
3360 struct pipe_crc_info *info = filep->private_data;
3361 struct drm_device *dev = info->dev;
3362 struct drm_i915_private *dev_priv = dev->dev_private;
3363 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3364 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003365 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003366 ssize_t bytes_read;
3367
3368 /*
3369 * Don't allow user space to provide buffers not big enough to hold
3370 * a line of data.
3371 */
3372 if (count < PIPE_CRC_LINE_LEN)
3373 return -EINVAL;
3374
3375 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3376 return 0;
3377
3378 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003379 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003380 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003381 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003382
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003383 if (filep->f_flags & O_NONBLOCK) {
3384 spin_unlock_irq(&pipe_crc->lock);
3385 return -EAGAIN;
3386 }
3387
3388 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3389 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3390 if (ret) {
3391 spin_unlock_irq(&pipe_crc->lock);
3392 return ret;
3393 }
Damien Lespiau07144422013-10-15 18:55:40 +01003394 }
3395
3396 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003397 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003398
Damien Lespiau07144422013-10-15 18:55:40 +01003399 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003400 while (n_entries > 0) {
3401 struct intel_pipe_crc_entry *entry =
3402 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003403 int ret;
3404
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003405 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3406 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3407 break;
3408
3409 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3410 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3411
Damien Lespiau07144422013-10-15 18:55:40 +01003412 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3413 "%8u %8x %8x %8x %8x %8x\n",
3414 entry->frame, entry->crc[0],
3415 entry->crc[1], entry->crc[2],
3416 entry->crc[3], entry->crc[4]);
3417
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003418 spin_unlock_irq(&pipe_crc->lock);
3419
3420 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003421 if (ret == PIPE_CRC_LINE_LEN)
3422 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003423
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003424 user_buf += PIPE_CRC_LINE_LEN;
3425 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003426
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003427 spin_lock_irq(&pipe_crc->lock);
3428 }
3429
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003430 spin_unlock_irq(&pipe_crc->lock);
3431
Damien Lespiau07144422013-10-15 18:55:40 +01003432 return bytes_read;
3433}
3434
3435static const struct file_operations i915_pipe_crc_fops = {
3436 .owner = THIS_MODULE,
3437 .open = i915_pipe_crc_open,
3438 .read = i915_pipe_crc_read,
3439 .release = i915_pipe_crc_release,
3440};
3441
3442static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3443 {
3444 .name = "i915_pipe_A_crc",
3445 .pipe = PIPE_A,
3446 },
3447 {
3448 .name = "i915_pipe_B_crc",
3449 .pipe = PIPE_B,
3450 },
3451 {
3452 .name = "i915_pipe_C_crc",
3453 .pipe = PIPE_C,
3454 },
3455};
3456
3457static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3458 enum pipe pipe)
3459{
3460 struct drm_device *dev = minor->dev;
3461 struct dentry *ent;
3462 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3463
3464 info->dev = dev;
3465 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3466 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003467 if (!ent)
3468 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003469
3470 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003471}
3472
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003473static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003474 "none",
3475 "plane1",
3476 "plane2",
3477 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003478 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003479 "TV",
3480 "DP-B",
3481 "DP-C",
3482 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003483 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003484};
3485
3486static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3487{
3488 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3489 return pipe_crc_sources[source];
3490}
3491
Damien Lespiaubd9db022013-10-15 18:55:36 +01003492static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003493{
3494 struct drm_device *dev = m->private;
3495 struct drm_i915_private *dev_priv = dev->dev_private;
3496 int i;
3497
3498 for (i = 0; i < I915_MAX_PIPES; i++)
3499 seq_printf(m, "%c %s\n", pipe_name(i),
3500 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3501
3502 return 0;
3503}
3504
Damien Lespiaubd9db022013-10-15 18:55:36 +01003505static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003506{
3507 struct drm_device *dev = inode->i_private;
3508
Damien Lespiaubd9db022013-10-15 18:55:36 +01003509 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003510}
3511
Daniel Vetter46a19182013-11-01 10:50:20 +01003512static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003513 uint32_t *val)
3514{
Daniel Vetter46a19182013-11-01 10:50:20 +01003515 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3516 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3517
3518 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003519 case INTEL_PIPE_CRC_SOURCE_PIPE:
3520 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3521 break;
3522 case INTEL_PIPE_CRC_SOURCE_NONE:
3523 *val = 0;
3524 break;
3525 default:
3526 return -EINVAL;
3527 }
3528
3529 return 0;
3530}
3531
Daniel Vetter46a19182013-11-01 10:50:20 +01003532static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3533 enum intel_pipe_crc_source *source)
3534{
3535 struct intel_encoder *encoder;
3536 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003537 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003538 int ret = 0;
3539
3540 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3541
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003542 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003543 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003544 if (!encoder->base.crtc)
3545 continue;
3546
3547 crtc = to_intel_crtc(encoder->base.crtc);
3548
3549 if (crtc->pipe != pipe)
3550 continue;
3551
3552 switch (encoder->type) {
3553 case INTEL_OUTPUT_TVOUT:
3554 *source = INTEL_PIPE_CRC_SOURCE_TV;
3555 break;
3556 case INTEL_OUTPUT_DISPLAYPORT:
3557 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003558 dig_port = enc_to_dig_port(&encoder->base);
3559 switch (dig_port->port) {
3560 case PORT_B:
3561 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3562 break;
3563 case PORT_C:
3564 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3565 break;
3566 case PORT_D:
3567 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3568 break;
3569 default:
3570 WARN(1, "nonexisting DP port %c\n",
3571 port_name(dig_port->port));
3572 break;
3573 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003574 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003575 default:
3576 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003577 }
3578 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003579 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003580
3581 return ret;
3582}
3583
3584static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3585 enum pipe pipe,
3586 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003587 uint32_t *val)
3588{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003589 struct drm_i915_private *dev_priv = dev->dev_private;
3590 bool need_stable_symbols = false;
3591
Daniel Vetter46a19182013-11-01 10:50:20 +01003592 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3593 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3594 if (ret)
3595 return ret;
3596 }
3597
3598 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003599 case INTEL_PIPE_CRC_SOURCE_PIPE:
3600 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3601 break;
3602 case INTEL_PIPE_CRC_SOURCE_DP_B:
3603 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003604 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003605 break;
3606 case INTEL_PIPE_CRC_SOURCE_DP_C:
3607 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003608 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003609 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003610 case INTEL_PIPE_CRC_SOURCE_DP_D:
3611 if (!IS_CHERRYVIEW(dev))
3612 return -EINVAL;
3613 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3614 need_stable_symbols = true;
3615 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003616 case INTEL_PIPE_CRC_SOURCE_NONE:
3617 *val = 0;
3618 break;
3619 default:
3620 return -EINVAL;
3621 }
3622
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003623 /*
3624 * When the pipe CRC tap point is after the transcoders we need
3625 * to tweak symbol-level features to produce a deterministic series of
3626 * symbols for a given frame. We need to reset those features only once
3627 * a frame (instead of every nth symbol):
3628 * - DC-balance: used to ensure a better clock recovery from the data
3629 * link (SDVO)
3630 * - DisplayPort scrambling: used for EMI reduction
3631 */
3632 if (need_stable_symbols) {
3633 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3634
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003635 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003636 switch (pipe) {
3637 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003638 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003639 break;
3640 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003641 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003642 break;
3643 case PIPE_C:
3644 tmp |= PIPE_C_SCRAMBLE_RESET;
3645 break;
3646 default:
3647 return -EINVAL;
3648 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003649 I915_WRITE(PORT_DFT2_G4X, tmp);
3650 }
3651
Daniel Vetter7ac01292013-10-18 16:37:06 +02003652 return 0;
3653}
3654
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003655static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003656 enum pipe pipe,
3657 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003658 uint32_t *val)
3659{
Daniel Vetter84093602013-11-01 10:50:21 +01003660 struct drm_i915_private *dev_priv = dev->dev_private;
3661 bool need_stable_symbols = false;
3662
Daniel Vetter46a19182013-11-01 10:50:20 +01003663 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3664 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3665 if (ret)
3666 return ret;
3667 }
3668
3669 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003670 case INTEL_PIPE_CRC_SOURCE_PIPE:
3671 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3672 break;
3673 case INTEL_PIPE_CRC_SOURCE_TV:
3674 if (!SUPPORTS_TV(dev))
3675 return -EINVAL;
3676 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3677 break;
3678 case INTEL_PIPE_CRC_SOURCE_DP_B:
3679 if (!IS_G4X(dev))
3680 return -EINVAL;
3681 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003682 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003683 break;
3684 case INTEL_PIPE_CRC_SOURCE_DP_C:
3685 if (!IS_G4X(dev))
3686 return -EINVAL;
3687 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003688 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003689 break;
3690 case INTEL_PIPE_CRC_SOURCE_DP_D:
3691 if (!IS_G4X(dev))
3692 return -EINVAL;
3693 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003694 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003695 break;
3696 case INTEL_PIPE_CRC_SOURCE_NONE:
3697 *val = 0;
3698 break;
3699 default:
3700 return -EINVAL;
3701 }
3702
Daniel Vetter84093602013-11-01 10:50:21 +01003703 /*
3704 * When the pipe CRC tap point is after the transcoders we need
3705 * to tweak symbol-level features to produce a deterministic series of
3706 * symbols for a given frame. We need to reset those features only once
3707 * a frame (instead of every nth symbol):
3708 * - DC-balance: used to ensure a better clock recovery from the data
3709 * link (SDVO)
3710 * - DisplayPort scrambling: used for EMI reduction
3711 */
3712 if (need_stable_symbols) {
3713 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3714
3715 WARN_ON(!IS_G4X(dev));
3716
3717 I915_WRITE(PORT_DFT_I9XX,
3718 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3719
3720 if (pipe == PIPE_A)
3721 tmp |= PIPE_A_SCRAMBLE_RESET;
3722 else
3723 tmp |= PIPE_B_SCRAMBLE_RESET;
3724
3725 I915_WRITE(PORT_DFT2_G4X, tmp);
3726 }
3727
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003728 return 0;
3729}
3730
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003731static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3732 enum pipe pipe)
3733{
3734 struct drm_i915_private *dev_priv = dev->dev_private;
3735 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3736
Ville Syrjäläeb736672014-12-09 21:28:28 +02003737 switch (pipe) {
3738 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003739 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003740 break;
3741 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003742 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003743 break;
3744 case PIPE_C:
3745 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3746 break;
3747 default:
3748 return;
3749 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003750 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3751 tmp &= ~DC_BALANCE_RESET_VLV;
3752 I915_WRITE(PORT_DFT2_G4X, tmp);
3753
3754}
3755
Daniel Vetter84093602013-11-01 10:50:21 +01003756static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3757 enum pipe pipe)
3758{
3759 struct drm_i915_private *dev_priv = dev->dev_private;
3760 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3761
3762 if (pipe == PIPE_A)
3763 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3764 else
3765 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3766 I915_WRITE(PORT_DFT2_G4X, tmp);
3767
3768 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3769 I915_WRITE(PORT_DFT_I9XX,
3770 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3771 }
3772}
3773
Daniel Vetter46a19182013-11-01 10:50:20 +01003774static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003775 uint32_t *val)
3776{
Daniel Vetter46a19182013-11-01 10:50:20 +01003777 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3778 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3779
3780 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003781 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3782 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3783 break;
3784 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3785 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3786 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003787 case INTEL_PIPE_CRC_SOURCE_PIPE:
3788 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3789 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003790 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003791 *val = 0;
3792 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003793 default:
3794 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003795 }
3796
3797 return 0;
3798}
3799
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003800static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003801{
3802 struct drm_i915_private *dev_priv = dev->dev_private;
3803 struct intel_crtc *crtc =
3804 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003805 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003806 struct drm_atomic_state *state;
3807 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003808
3809 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003810 state = drm_atomic_state_alloc(dev);
3811 if (!state) {
3812 ret = -ENOMEM;
3813 goto out;
3814 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003815
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003816 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
3817 pipe_config = intel_atomic_get_crtc_state(state, crtc);
3818 if (IS_ERR(pipe_config)) {
3819 ret = PTR_ERR(pipe_config);
3820 goto out;
3821 }
3822
3823 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003824 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003825 pipe_config->pch_pfit.enabled != enable)
3826 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003827
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003828 ret = drm_atomic_commit(state);
3829out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003830 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003831 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
3832 if (ret)
3833 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003834}
3835
3836static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3837 enum pipe pipe,
3838 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003839 uint32_t *val)
3840{
Daniel Vetter46a19182013-11-01 10:50:20 +01003841 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3842 *source = INTEL_PIPE_CRC_SOURCE_PF;
3843
3844 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003845 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3846 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3847 break;
3848 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3849 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3850 break;
3851 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003852 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003853 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003854
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003855 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3856 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003857 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003858 *val = 0;
3859 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003860 default:
3861 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003862 }
3863
3864 return 0;
3865}
3866
Daniel Vetter926321d2013-10-16 13:30:34 +02003867static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3868 enum intel_pipe_crc_source source)
3869{
3870 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003871 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003872 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3873 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003874 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003875 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003876
Damien Lespiaucc3da172013-10-15 18:55:31 +01003877 if (pipe_crc->source == source)
3878 return 0;
3879
Damien Lespiauae676fc2013-10-15 18:55:32 +01003880 /* forbid changing the source without going back to 'none' */
3881 if (pipe_crc->source && source)
3882 return -EINVAL;
3883
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003884 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3885 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3886 return -EIO;
3887 }
3888
Daniel Vetter52f843f2013-10-21 17:26:38 +02003889 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003890 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003891 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003892 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003893 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003894 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003895 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003896 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003897 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003898 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003899
3900 if (ret != 0)
3901 return ret;
3902
Damien Lespiau4b584362013-10-15 18:55:33 +01003903 /* none -> real source transition */
3904 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003905 struct intel_pipe_crc_entry *entries;
3906
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003907 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3908 pipe_name(pipe), pipe_crc_source_name(source));
3909
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003910 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3911 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003912 GFP_KERNEL);
3913 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003914 return -ENOMEM;
3915
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003916 /*
3917 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3918 * enabled and disabled dynamically based on package C states,
3919 * user space can't make reliable use of the CRCs, so let's just
3920 * completely disable it.
3921 */
3922 hsw_disable_ips(crtc);
3923
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003924 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003925 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003926 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003927 pipe_crc->head = 0;
3928 pipe_crc->tail = 0;
3929 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003930 }
3931
Damien Lespiaucc3da172013-10-15 18:55:31 +01003932 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003933
Daniel Vetter926321d2013-10-16 13:30:34 +02003934 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3935 POSTING_READ(PIPE_CRC_CTL(pipe));
3936
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003937 /* real source -> none transition */
3938 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003939 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003940 struct intel_crtc *crtc =
3941 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003942
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003943 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3944 pipe_name(pipe));
3945
Daniel Vettera33d7102014-06-06 08:22:08 +02003946 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003947 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02003948 intel_wait_for_vblank(dev, pipe);
3949 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003950
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003951 spin_lock_irq(&pipe_crc->lock);
3952 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003953 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003954 pipe_crc->head = 0;
3955 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003956 spin_unlock_irq(&pipe_crc->lock);
3957
3958 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003959
3960 if (IS_G4X(dev))
3961 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003962 else if (IS_VALLEYVIEW(dev))
3963 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003964 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003965 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003966
3967 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003968 }
3969
Daniel Vetter926321d2013-10-16 13:30:34 +02003970 return 0;
3971}
3972
3973/*
3974 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003975 * command: wsp* object wsp+ name wsp+ source wsp*
3976 * object: 'pipe'
3977 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003978 * source: (none | plane1 | plane2 | pf)
3979 * wsp: (#0x20 | #0x9 | #0xA)+
3980 *
3981 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003982 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3983 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003984 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003985static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003986{
3987 int n_words = 0;
3988
3989 while (*buf) {
3990 char *end;
3991
3992 /* skip leading white space */
3993 buf = skip_spaces(buf);
3994 if (!*buf)
3995 break; /* end of buffer */
3996
3997 /* find end of word */
3998 for (end = buf; *end && !isspace(*end); end++)
3999 ;
4000
4001 if (n_words == max_words) {
4002 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
4003 max_words);
4004 return -EINVAL; /* ran out of words[] before bytes */
4005 }
4006
4007 if (*end)
4008 *end++ = '\0';
4009 words[n_words++] = buf;
4010 buf = end;
4011 }
4012
4013 return n_words;
4014}
4015
Damien Lespiaub94dec82013-10-15 18:55:35 +01004016enum intel_pipe_crc_object {
4017 PIPE_CRC_OBJECT_PIPE,
4018};
4019
Daniel Vettere8dfcf72013-10-16 11:51:54 +02004020static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004021 "pipe",
4022};
4023
4024static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004025display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01004026{
4027 int i;
4028
4029 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
4030 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004031 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004032 return 0;
4033 }
4034
4035 return -EINVAL;
4036}
4037
Damien Lespiaubd9db022013-10-15 18:55:36 +01004038static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02004039{
4040 const char name = buf[0];
4041
4042 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
4043 return -EINVAL;
4044
4045 *pipe = name - 'A';
4046
4047 return 0;
4048}
4049
4050static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01004051display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02004052{
4053 int i;
4054
4055 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
4056 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01004057 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02004058 return 0;
4059 }
4060
4061 return -EINVAL;
4062}
4063
Damien Lespiaubd9db022013-10-15 18:55:36 +01004064static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02004065{
Damien Lespiaub94dec82013-10-15 18:55:35 +01004066#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02004067 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004068 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02004069 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01004070 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02004071 enum intel_pipe_crc_source source;
4072
Damien Lespiaubd9db022013-10-15 18:55:36 +01004073 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01004074 if (n_words != N_WORDS) {
4075 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
4076 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02004077 return -EINVAL;
4078 }
4079
Damien Lespiaubd9db022013-10-15 18:55:36 +01004080 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004081 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004082 return -EINVAL;
4083 }
4084
Damien Lespiaubd9db022013-10-15 18:55:36 +01004085 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004086 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4087 return -EINVAL;
4088 }
4089
Damien Lespiaubd9db022013-10-15 18:55:36 +01004090 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004091 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004092 return -EINVAL;
4093 }
4094
4095 return pipe_crc_set_source(dev, pipe, source);
4096}
4097
Damien Lespiaubd9db022013-10-15 18:55:36 +01004098static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4099 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004100{
4101 struct seq_file *m = file->private_data;
4102 struct drm_device *dev = m->private;
4103 char *tmpbuf;
4104 int ret;
4105
4106 if (len == 0)
4107 return 0;
4108
4109 if (len > PAGE_SIZE - 1) {
4110 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4111 PAGE_SIZE);
4112 return -E2BIG;
4113 }
4114
4115 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4116 if (!tmpbuf)
4117 return -ENOMEM;
4118
4119 if (copy_from_user(tmpbuf, ubuf, len)) {
4120 ret = -EFAULT;
4121 goto out;
4122 }
4123 tmpbuf[len] = '\0';
4124
Damien Lespiaubd9db022013-10-15 18:55:36 +01004125 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004126
4127out:
4128 kfree(tmpbuf);
4129 if (ret < 0)
4130 return ret;
4131
4132 *offp += len;
4133 return len;
4134}
4135
Damien Lespiaubd9db022013-10-15 18:55:36 +01004136static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004137 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004138 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004139 .read = seq_read,
4140 .llseek = seq_lseek,
4141 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004142 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004143};
4144
Todd Previteeb3394fa2015-04-18 00:04:19 -07004145static ssize_t i915_displayport_test_active_write(struct file *file,
4146 const char __user *ubuf,
4147 size_t len, loff_t *offp)
4148{
4149 char *input_buffer;
4150 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004151 struct drm_device *dev;
4152 struct drm_connector *connector;
4153 struct list_head *connector_list;
4154 struct intel_dp *intel_dp;
4155 int val = 0;
4156
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304157 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004158
Todd Previteeb3394fa2015-04-18 00:04:19 -07004159 connector_list = &dev->mode_config.connector_list;
4160
4161 if (len == 0)
4162 return 0;
4163
4164 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4165 if (!input_buffer)
4166 return -ENOMEM;
4167
4168 if (copy_from_user(input_buffer, ubuf, len)) {
4169 status = -EFAULT;
4170 goto out;
4171 }
4172
4173 input_buffer[len] = '\0';
4174 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4175
4176 list_for_each_entry(connector, connector_list, head) {
4177
4178 if (connector->connector_type !=
4179 DRM_MODE_CONNECTOR_DisplayPort)
4180 continue;
4181
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304182 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004183 connector->encoder != NULL) {
4184 intel_dp = enc_to_intel_dp(connector->encoder);
4185 status = kstrtoint(input_buffer, 10, &val);
4186 if (status < 0)
4187 goto out;
4188 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4189 /* To prevent erroneous activation of the compliance
4190 * testing code, only accept an actual value of 1 here
4191 */
4192 if (val == 1)
4193 intel_dp->compliance_test_active = 1;
4194 else
4195 intel_dp->compliance_test_active = 0;
4196 }
4197 }
4198out:
4199 kfree(input_buffer);
4200 if (status < 0)
4201 return status;
4202
4203 *offp += len;
4204 return len;
4205}
4206
4207static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4208{
4209 struct drm_device *dev = m->private;
4210 struct drm_connector *connector;
4211 struct list_head *connector_list = &dev->mode_config.connector_list;
4212 struct intel_dp *intel_dp;
4213
Todd Previteeb3394fa2015-04-18 00:04:19 -07004214 list_for_each_entry(connector, connector_list, head) {
4215
4216 if (connector->connector_type !=
4217 DRM_MODE_CONNECTOR_DisplayPort)
4218 continue;
4219
4220 if (connector->status == connector_status_connected &&
4221 connector->encoder != NULL) {
4222 intel_dp = enc_to_intel_dp(connector->encoder);
4223 if (intel_dp->compliance_test_active)
4224 seq_puts(m, "1");
4225 else
4226 seq_puts(m, "0");
4227 } else
4228 seq_puts(m, "0");
4229 }
4230
4231 return 0;
4232}
4233
4234static int i915_displayport_test_active_open(struct inode *inode,
4235 struct file *file)
4236{
4237 struct drm_device *dev = inode->i_private;
4238
4239 return single_open(file, i915_displayport_test_active_show, dev);
4240}
4241
4242static const struct file_operations i915_displayport_test_active_fops = {
4243 .owner = THIS_MODULE,
4244 .open = i915_displayport_test_active_open,
4245 .read = seq_read,
4246 .llseek = seq_lseek,
4247 .release = single_release,
4248 .write = i915_displayport_test_active_write
4249};
4250
4251static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4252{
4253 struct drm_device *dev = m->private;
4254 struct drm_connector *connector;
4255 struct list_head *connector_list = &dev->mode_config.connector_list;
4256 struct intel_dp *intel_dp;
4257
Todd Previteeb3394fa2015-04-18 00:04:19 -07004258 list_for_each_entry(connector, connector_list, head) {
4259
4260 if (connector->connector_type !=
4261 DRM_MODE_CONNECTOR_DisplayPort)
4262 continue;
4263
4264 if (connector->status == connector_status_connected &&
4265 connector->encoder != NULL) {
4266 intel_dp = enc_to_intel_dp(connector->encoder);
4267 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4268 } else
4269 seq_puts(m, "0");
4270 }
4271
4272 return 0;
4273}
4274static int i915_displayport_test_data_open(struct inode *inode,
4275 struct file *file)
4276{
4277 struct drm_device *dev = inode->i_private;
4278
4279 return single_open(file, i915_displayport_test_data_show, dev);
4280}
4281
4282static const struct file_operations i915_displayport_test_data_fops = {
4283 .owner = THIS_MODULE,
4284 .open = i915_displayport_test_data_open,
4285 .read = seq_read,
4286 .llseek = seq_lseek,
4287 .release = single_release
4288};
4289
4290static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4291{
4292 struct drm_device *dev = m->private;
4293 struct drm_connector *connector;
4294 struct list_head *connector_list = &dev->mode_config.connector_list;
4295 struct intel_dp *intel_dp;
4296
Todd Previteeb3394fa2015-04-18 00:04:19 -07004297 list_for_each_entry(connector, connector_list, head) {
4298
4299 if (connector->connector_type !=
4300 DRM_MODE_CONNECTOR_DisplayPort)
4301 continue;
4302
4303 if (connector->status == connector_status_connected &&
4304 connector->encoder != NULL) {
4305 intel_dp = enc_to_intel_dp(connector->encoder);
4306 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4307 } else
4308 seq_puts(m, "0");
4309 }
4310
4311 return 0;
4312}
4313
4314static int i915_displayport_test_type_open(struct inode *inode,
4315 struct file *file)
4316{
4317 struct drm_device *dev = inode->i_private;
4318
4319 return single_open(file, i915_displayport_test_type_show, dev);
4320}
4321
4322static const struct file_operations i915_displayport_test_type_fops = {
4323 .owner = THIS_MODULE,
4324 .open = i915_displayport_test_type_open,
4325 .read = seq_read,
4326 .llseek = seq_lseek,
4327 .release = single_release
4328};
4329
Damien Lespiau97e94b22014-11-04 17:06:50 +00004330static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004331{
4332 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004333 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004334 int num_levels;
4335
4336 if (IS_CHERRYVIEW(dev))
4337 num_levels = 3;
4338 else if (IS_VALLEYVIEW(dev))
4339 num_levels = 1;
4340 else
4341 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004342
4343 drm_modeset_lock_all(dev);
4344
4345 for (level = 0; level < num_levels; level++) {
4346 unsigned int latency = wm[level];
4347
Damien Lespiau97e94b22014-11-04 17:06:50 +00004348 /*
4349 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004350 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004351 */
Ville Syrjäläde38b952015-06-24 22:00:09 +03004352 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004353 latency *= 10;
4354 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004355 latency *= 5;
4356
4357 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004358 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004359 }
4360
4361 drm_modeset_unlock_all(dev);
4362}
4363
4364static int pri_wm_latency_show(struct seq_file *m, void *data)
4365{
4366 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004367 struct drm_i915_private *dev_priv = dev->dev_private;
4368 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004369
Damien Lespiau97e94b22014-11-04 17:06:50 +00004370 if (INTEL_INFO(dev)->gen >= 9)
4371 latencies = dev_priv->wm.skl_latency;
4372 else
4373 latencies = to_i915(dev)->wm.pri_latency;
4374
4375 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004376
4377 return 0;
4378}
4379
4380static int spr_wm_latency_show(struct seq_file *m, void *data)
4381{
4382 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004383 struct drm_i915_private *dev_priv = dev->dev_private;
4384 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004385
Damien Lespiau97e94b22014-11-04 17:06:50 +00004386 if (INTEL_INFO(dev)->gen >= 9)
4387 latencies = dev_priv->wm.skl_latency;
4388 else
4389 latencies = to_i915(dev)->wm.spr_latency;
4390
4391 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004392
4393 return 0;
4394}
4395
4396static int cur_wm_latency_show(struct seq_file *m, void *data)
4397{
4398 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004399 struct drm_i915_private *dev_priv = dev->dev_private;
4400 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004401
Damien Lespiau97e94b22014-11-04 17:06:50 +00004402 if (INTEL_INFO(dev)->gen >= 9)
4403 latencies = dev_priv->wm.skl_latency;
4404 else
4405 latencies = to_i915(dev)->wm.cur_latency;
4406
4407 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004408
4409 return 0;
4410}
4411
4412static int pri_wm_latency_open(struct inode *inode, struct file *file)
4413{
4414 struct drm_device *dev = inode->i_private;
4415
Ville Syrjäläde38b952015-06-24 22:00:09 +03004416 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004417 return -ENODEV;
4418
4419 return single_open(file, pri_wm_latency_show, dev);
4420}
4421
4422static int spr_wm_latency_open(struct inode *inode, struct file *file)
4423{
4424 struct drm_device *dev = inode->i_private;
4425
Sonika Jindal9ad02572014-07-21 15:23:39 +05304426 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004427 return -ENODEV;
4428
4429 return single_open(file, spr_wm_latency_show, dev);
4430}
4431
4432static int cur_wm_latency_open(struct inode *inode, struct file *file)
4433{
4434 struct drm_device *dev = inode->i_private;
4435
Sonika Jindal9ad02572014-07-21 15:23:39 +05304436 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004437 return -ENODEV;
4438
4439 return single_open(file, cur_wm_latency_show, dev);
4440}
4441
4442static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004443 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004444{
4445 struct seq_file *m = file->private_data;
4446 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004447 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004448 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004449 int level;
4450 int ret;
4451 char tmp[32];
4452
Ville Syrjäläde38b952015-06-24 22:00:09 +03004453 if (IS_CHERRYVIEW(dev))
4454 num_levels = 3;
4455 else if (IS_VALLEYVIEW(dev))
4456 num_levels = 1;
4457 else
4458 num_levels = ilk_wm_max_level(dev) + 1;
4459
Ville Syrjälä369a1342014-01-22 14:36:08 +02004460 if (len >= sizeof(tmp))
4461 return -EINVAL;
4462
4463 if (copy_from_user(tmp, ubuf, len))
4464 return -EFAULT;
4465
4466 tmp[len] = '\0';
4467
Damien Lespiau97e94b22014-11-04 17:06:50 +00004468 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4469 &new[0], &new[1], &new[2], &new[3],
4470 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004471 if (ret != num_levels)
4472 return -EINVAL;
4473
4474 drm_modeset_lock_all(dev);
4475
4476 for (level = 0; level < num_levels; level++)
4477 wm[level] = new[level];
4478
4479 drm_modeset_unlock_all(dev);
4480
4481 return len;
4482}
4483
4484
4485static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4486 size_t len, loff_t *offp)
4487{
4488 struct seq_file *m = file->private_data;
4489 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004490 struct drm_i915_private *dev_priv = dev->dev_private;
4491 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004492
Damien Lespiau97e94b22014-11-04 17:06:50 +00004493 if (INTEL_INFO(dev)->gen >= 9)
4494 latencies = dev_priv->wm.skl_latency;
4495 else
4496 latencies = to_i915(dev)->wm.pri_latency;
4497
4498 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004499}
4500
4501static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4502 size_t len, loff_t *offp)
4503{
4504 struct seq_file *m = file->private_data;
4505 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004506 struct drm_i915_private *dev_priv = dev->dev_private;
4507 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004508
Damien Lespiau97e94b22014-11-04 17:06:50 +00004509 if (INTEL_INFO(dev)->gen >= 9)
4510 latencies = dev_priv->wm.skl_latency;
4511 else
4512 latencies = to_i915(dev)->wm.spr_latency;
4513
4514 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004515}
4516
4517static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4518 size_t len, loff_t *offp)
4519{
4520 struct seq_file *m = file->private_data;
4521 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004522 struct drm_i915_private *dev_priv = dev->dev_private;
4523 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004524
Damien Lespiau97e94b22014-11-04 17:06:50 +00004525 if (INTEL_INFO(dev)->gen >= 9)
4526 latencies = dev_priv->wm.skl_latency;
4527 else
4528 latencies = to_i915(dev)->wm.cur_latency;
4529
4530 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004531}
4532
4533static const struct file_operations i915_pri_wm_latency_fops = {
4534 .owner = THIS_MODULE,
4535 .open = pri_wm_latency_open,
4536 .read = seq_read,
4537 .llseek = seq_lseek,
4538 .release = single_release,
4539 .write = pri_wm_latency_write
4540};
4541
4542static const struct file_operations i915_spr_wm_latency_fops = {
4543 .owner = THIS_MODULE,
4544 .open = spr_wm_latency_open,
4545 .read = seq_read,
4546 .llseek = seq_lseek,
4547 .release = single_release,
4548 .write = spr_wm_latency_write
4549};
4550
4551static const struct file_operations i915_cur_wm_latency_fops = {
4552 .owner = THIS_MODULE,
4553 .open = cur_wm_latency_open,
4554 .read = seq_read,
4555 .llseek = seq_lseek,
4556 .release = single_release,
4557 .write = cur_wm_latency_write
4558};
4559
Kees Cook647416f2013-03-10 14:10:06 -07004560static int
4561i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004562{
Kees Cook647416f2013-03-10 14:10:06 -07004563 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004564 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004565
Kees Cook647416f2013-03-10 14:10:06 -07004566 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004567
Kees Cook647416f2013-03-10 14:10:06 -07004568 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004569}
4570
Kees Cook647416f2013-03-10 14:10:06 -07004571static int
4572i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004573{
Kees Cook647416f2013-03-10 14:10:06 -07004574 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004575 struct drm_i915_private *dev_priv = dev->dev_private;
4576
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004577 /*
4578 * There is no safeguard against this debugfs entry colliding
4579 * with the hangcheck calling same i915_handle_error() in
4580 * parallel, causing an explosion. For now we assume that the
4581 * test harness is responsible enough not to inject gpu hangs
4582 * while it is writing to 'i915_wedged'
4583 */
4584
4585 if (i915_reset_in_progress(&dev_priv->gpu_error))
4586 return -EAGAIN;
4587
Imre Deakd46c0512014-04-14 20:24:27 +03004588 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004589
Mika Kuoppala58174462014-02-25 17:11:26 +02004590 i915_handle_error(dev, val,
4591 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004592
4593 intel_runtime_pm_put(dev_priv);
4594
Kees Cook647416f2013-03-10 14:10:06 -07004595 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004596}
4597
Kees Cook647416f2013-03-10 14:10:06 -07004598DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4599 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004600 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004601
Kees Cook647416f2013-03-10 14:10:06 -07004602static int
4603i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004604{
Kees Cook647416f2013-03-10 14:10:06 -07004605 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004606 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004607
Kees Cook647416f2013-03-10 14:10:06 -07004608 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004609
Kees Cook647416f2013-03-10 14:10:06 -07004610 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004611}
4612
Kees Cook647416f2013-03-10 14:10:06 -07004613static int
4614i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004615{
Kees Cook647416f2013-03-10 14:10:06 -07004616 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004617 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004618 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004619
Kees Cook647416f2013-03-10 14:10:06 -07004620 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004621
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004622 ret = mutex_lock_interruptible(&dev->struct_mutex);
4623 if (ret)
4624 return ret;
4625
Daniel Vetter99584db2012-11-14 17:14:04 +01004626 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004627 mutex_unlock(&dev->struct_mutex);
4628
Kees Cook647416f2013-03-10 14:10:06 -07004629 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004630}
4631
Kees Cook647416f2013-03-10 14:10:06 -07004632DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4633 i915_ring_stop_get, i915_ring_stop_set,
4634 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004635
Chris Wilson094f9a52013-09-25 17:34:55 +01004636static int
4637i915_ring_missed_irq_get(void *data, u64 *val)
4638{
4639 struct drm_device *dev = data;
4640 struct drm_i915_private *dev_priv = dev->dev_private;
4641
4642 *val = dev_priv->gpu_error.missed_irq_rings;
4643 return 0;
4644}
4645
4646static int
4647i915_ring_missed_irq_set(void *data, u64 val)
4648{
4649 struct drm_device *dev = data;
4650 struct drm_i915_private *dev_priv = dev->dev_private;
4651 int ret;
4652
4653 /* Lock against concurrent debugfs callers */
4654 ret = mutex_lock_interruptible(&dev->struct_mutex);
4655 if (ret)
4656 return ret;
4657 dev_priv->gpu_error.missed_irq_rings = val;
4658 mutex_unlock(&dev->struct_mutex);
4659
4660 return 0;
4661}
4662
4663DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4664 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4665 "0x%08llx\n");
4666
4667static int
4668i915_ring_test_irq_get(void *data, u64 *val)
4669{
4670 struct drm_device *dev = data;
4671 struct drm_i915_private *dev_priv = dev->dev_private;
4672
4673 *val = dev_priv->gpu_error.test_irq_rings;
4674
4675 return 0;
4676}
4677
4678static int
4679i915_ring_test_irq_set(void *data, u64 val)
4680{
4681 struct drm_device *dev = data;
4682 struct drm_i915_private *dev_priv = dev->dev_private;
4683 int ret;
4684
4685 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4686
4687 /* Lock against concurrent debugfs callers */
4688 ret = mutex_lock_interruptible(&dev->struct_mutex);
4689 if (ret)
4690 return ret;
4691
4692 dev_priv->gpu_error.test_irq_rings = val;
4693 mutex_unlock(&dev->struct_mutex);
4694
4695 return 0;
4696}
4697
4698DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4699 i915_ring_test_irq_get, i915_ring_test_irq_set,
4700 "0x%08llx\n");
4701
Chris Wilsondd624af2013-01-15 12:39:35 +00004702#define DROP_UNBOUND 0x1
4703#define DROP_BOUND 0x2
4704#define DROP_RETIRE 0x4
4705#define DROP_ACTIVE 0x8
4706#define DROP_ALL (DROP_UNBOUND | \
4707 DROP_BOUND | \
4708 DROP_RETIRE | \
4709 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004710static int
4711i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004712{
Kees Cook647416f2013-03-10 14:10:06 -07004713 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004714
Kees Cook647416f2013-03-10 14:10:06 -07004715 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004716}
4717
Kees Cook647416f2013-03-10 14:10:06 -07004718static int
4719i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004720{
Kees Cook647416f2013-03-10 14:10:06 -07004721 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004722 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004723 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004724
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004725 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004726
4727 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4728 * on ioctls on -EAGAIN. */
4729 ret = mutex_lock_interruptible(&dev->struct_mutex);
4730 if (ret)
4731 return ret;
4732
4733 if (val & DROP_ACTIVE) {
4734 ret = i915_gpu_idle(dev);
4735 if (ret)
4736 goto unlock;
4737 }
4738
4739 if (val & (DROP_RETIRE | DROP_ACTIVE))
4740 i915_gem_retire_requests(dev);
4741
Chris Wilson21ab4e72014-09-09 11:16:08 +01004742 if (val & DROP_BOUND)
4743 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004744
Chris Wilson21ab4e72014-09-09 11:16:08 +01004745 if (val & DROP_UNBOUND)
4746 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004747
4748unlock:
4749 mutex_unlock(&dev->struct_mutex);
4750
Kees Cook647416f2013-03-10 14:10:06 -07004751 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004752}
4753
Kees Cook647416f2013-03-10 14:10:06 -07004754DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4755 i915_drop_caches_get, i915_drop_caches_set,
4756 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004757
Kees Cook647416f2013-03-10 14:10:06 -07004758static int
4759i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004760{
Kees Cook647416f2013-03-10 14:10:06 -07004761 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004762 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004763 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004764
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004765 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004766 return -ENODEV;
4767
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004768 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4769
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004770 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004771 if (ret)
4772 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004773
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004774 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004775 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004776
Kees Cook647416f2013-03-10 14:10:06 -07004777 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004778}
4779
Kees Cook647416f2013-03-10 14:10:06 -07004780static int
4781i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004782{
Kees Cook647416f2013-03-10 14:10:06 -07004783 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004784 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304785 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004786 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004787
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004788 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004789 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004790
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004791 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4792
Kees Cook647416f2013-03-10 14:10:06 -07004793 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004794
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004795 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004796 if (ret)
4797 return ret;
4798
Jesse Barnes358733e2011-07-27 11:53:01 -07004799 /*
4800 * Turbo will still be enabled, but won't go above the set value.
4801 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304802 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004803
Akash Goelbc4d91f2015-02-26 16:09:47 +05304804 hw_max = dev_priv->rps.max_freq;
4805 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004806
Ben Widawskyb39fb292014-03-19 18:31:11 -07004807 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004808 mutex_unlock(&dev_priv->rps.hw_lock);
4809 return -EINVAL;
4810 }
4811
Ben Widawskyb39fb292014-03-19 18:31:11 -07004812 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004813
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004814 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004815
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004816 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004817
Kees Cook647416f2013-03-10 14:10:06 -07004818 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004819}
4820
Kees Cook647416f2013-03-10 14:10:06 -07004821DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4822 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004823 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004824
Kees Cook647416f2013-03-10 14:10:06 -07004825static int
4826i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004827{
Kees Cook647416f2013-03-10 14:10:06 -07004828 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004829 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004830 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004831
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004832 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004833 return -ENODEV;
4834
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004835 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4836
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004837 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004838 if (ret)
4839 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004840
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004841 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004842 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004843
Kees Cook647416f2013-03-10 14:10:06 -07004844 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004845}
4846
Kees Cook647416f2013-03-10 14:10:06 -07004847static int
4848i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004849{
Kees Cook647416f2013-03-10 14:10:06 -07004850 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004851 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304852 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004853 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004854
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004855 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004856 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004857
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004858 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4859
Kees Cook647416f2013-03-10 14:10:06 -07004860 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004861
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004862 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004863 if (ret)
4864 return ret;
4865
Jesse Barnes1523c312012-05-25 12:34:54 -07004866 /*
4867 * Turbo will still be enabled, but won't go below the set value.
4868 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304869 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004870
Akash Goelbc4d91f2015-02-26 16:09:47 +05304871 hw_max = dev_priv->rps.max_freq;
4872 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004873
Ben Widawskyb39fb292014-03-19 18:31:11 -07004874 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004875 mutex_unlock(&dev_priv->rps.hw_lock);
4876 return -EINVAL;
4877 }
4878
Ben Widawskyb39fb292014-03-19 18:31:11 -07004879 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004880
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004881 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004882
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004883 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004884
Kees Cook647416f2013-03-10 14:10:06 -07004885 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004886}
4887
Kees Cook647416f2013-03-10 14:10:06 -07004888DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4889 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004890 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004891
Kees Cook647416f2013-03-10 14:10:06 -07004892static int
4893i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004894{
Kees Cook647416f2013-03-10 14:10:06 -07004895 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004896 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004897 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004898 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004899
Daniel Vetter004777c2012-08-09 15:07:01 +02004900 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4901 return -ENODEV;
4902
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004903 ret = mutex_lock_interruptible(&dev->struct_mutex);
4904 if (ret)
4905 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004906 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004907
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004908 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004909
4910 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004911 mutex_unlock(&dev_priv->dev->struct_mutex);
4912
Kees Cook647416f2013-03-10 14:10:06 -07004913 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004914
Kees Cook647416f2013-03-10 14:10:06 -07004915 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004916}
4917
Kees Cook647416f2013-03-10 14:10:06 -07004918static int
4919i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004920{
Kees Cook647416f2013-03-10 14:10:06 -07004921 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004922 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004923 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004924
Daniel Vetter004777c2012-08-09 15:07:01 +02004925 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4926 return -ENODEV;
4927
Kees Cook647416f2013-03-10 14:10:06 -07004928 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004929 return -EINVAL;
4930
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004931 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004932 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004933
4934 /* Update the cache sharing policy here as well */
4935 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4936 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4937 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4938 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4939
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004940 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004941 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004942}
4943
Kees Cook647416f2013-03-10 14:10:06 -07004944DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4945 i915_cache_sharing_get, i915_cache_sharing_set,
4946 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004947
Jeff McGee5d395252015-04-03 18:13:17 -07004948struct sseu_dev_status {
4949 unsigned int slice_total;
4950 unsigned int subslice_total;
4951 unsigned int subslice_per_slice;
4952 unsigned int eu_total;
4953 unsigned int eu_per_subslice;
4954};
4955
4956static void cherryview_sseu_device_status(struct drm_device *dev,
4957 struct sseu_dev_status *stat)
4958{
4959 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä0a0b4572015-08-21 20:45:27 +03004960 int ss_max = 2;
Jeff McGee5d395252015-04-03 18:13:17 -07004961 int ss;
4962 u32 sig1[ss_max], sig2[ss_max];
4963
4964 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4965 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4966 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4967 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4968
4969 for (ss = 0; ss < ss_max; ss++) {
4970 unsigned int eu_cnt;
4971
4972 if (sig1[ss] & CHV_SS_PG_ENABLE)
4973 /* skip disabled subslice */
4974 continue;
4975
4976 stat->slice_total = 1;
4977 stat->subslice_per_slice++;
4978 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4979 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4980 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4981 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
4982 stat->eu_total += eu_cnt;
4983 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
4984 }
4985 stat->subslice_total = stat->subslice_per_slice;
4986}
4987
4988static void gen9_sseu_device_status(struct drm_device *dev,
4989 struct sseu_dev_status *stat)
4990{
4991 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004992 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004993 int s, ss;
4994 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4995
Jeff McGee1c046bc2015-04-03 18:13:18 -07004996 /* BXT has a single slice and at most 3 subslices. */
4997 if (IS_BROXTON(dev)) {
4998 s_max = 1;
4999 ss_max = 3;
5000 }
5001
5002 for (s = 0; s < s_max; s++) {
5003 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
5004 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
5005 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
5006 }
5007
Jeff McGee5d395252015-04-03 18:13:17 -07005008 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
5009 GEN9_PGCTL_SSA_EU19_ACK |
5010 GEN9_PGCTL_SSA_EU210_ACK |
5011 GEN9_PGCTL_SSA_EU311_ACK;
5012 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
5013 GEN9_PGCTL_SSB_EU19_ACK |
5014 GEN9_PGCTL_SSB_EU210_ACK |
5015 GEN9_PGCTL_SSB_EU311_ACK;
5016
5017 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07005018 unsigned int ss_cnt = 0;
5019
Jeff McGee5d395252015-04-03 18:13:17 -07005020 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
5021 /* skip disabled slice */
5022 continue;
5023
5024 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07005025
5026 if (IS_SKYLAKE(dev))
5027 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
5028
Jeff McGee5d395252015-04-03 18:13:17 -07005029 for (ss = 0; ss < ss_max; ss++) {
5030 unsigned int eu_cnt;
5031
Jeff McGee1c046bc2015-04-03 18:13:18 -07005032 if (IS_BROXTON(dev) &&
5033 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
5034 /* skip disabled subslice */
5035 continue;
5036
5037 if (IS_BROXTON(dev))
5038 ss_cnt++;
5039
Jeff McGee5d395252015-04-03 18:13:17 -07005040 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
5041 eu_mask[ss%2]);
5042 stat->eu_total += eu_cnt;
5043 stat->eu_per_subslice = max(stat->eu_per_subslice,
5044 eu_cnt);
5045 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07005046
5047 stat->subslice_total += ss_cnt;
5048 stat->subslice_per_slice = max(stat->subslice_per_slice,
5049 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07005050 }
5051}
5052
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005053static void broadwell_sseu_device_status(struct drm_device *dev,
5054 struct sseu_dev_status *stat)
5055{
5056 struct drm_i915_private *dev_priv = dev->dev_private;
5057 int s;
5058 u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
5059
5060 stat->slice_total = hweight32(slice_info & GEN8_LSLICESTAT_MASK);
5061
5062 if (stat->slice_total) {
5063 stat->subslice_per_slice = INTEL_INFO(dev)->subslice_per_slice;
5064 stat->subslice_total = stat->slice_total *
5065 stat->subslice_per_slice;
5066 stat->eu_per_subslice = INTEL_INFO(dev)->eu_per_subslice;
5067 stat->eu_total = stat->eu_per_subslice * stat->subslice_total;
5068
5069 /* subtract fused off EU(s) from enabled slice(s) */
5070 for (s = 0; s < stat->slice_total; s++) {
5071 u8 subslice_7eu = INTEL_INFO(dev)->subslice_7eu[s];
5072
5073 stat->eu_total -= hweight8(subslice_7eu);
5074 }
5075 }
5076}
5077
Jeff McGee38732182015-02-13 10:27:54 -06005078static int i915_sseu_status(struct seq_file *m, void *unused)
5079{
5080 struct drm_info_node *node = (struct drm_info_node *) m->private;
5081 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07005082 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06005083
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005084 if (INTEL_INFO(dev)->gen < 8)
Jeff McGee38732182015-02-13 10:27:54 -06005085 return -ENODEV;
5086
5087 seq_puts(m, "SSEU Device Info\n");
5088 seq_printf(m, " Available Slice Total: %u\n",
5089 INTEL_INFO(dev)->slice_total);
5090 seq_printf(m, " Available Subslice Total: %u\n",
5091 INTEL_INFO(dev)->subslice_total);
5092 seq_printf(m, " Available Subslice Per Slice: %u\n",
5093 INTEL_INFO(dev)->subslice_per_slice);
5094 seq_printf(m, " Available EU Total: %u\n",
5095 INTEL_INFO(dev)->eu_total);
5096 seq_printf(m, " Available EU Per Subslice: %u\n",
5097 INTEL_INFO(dev)->eu_per_subslice);
5098 seq_printf(m, " Has Slice Power Gating: %s\n",
5099 yesno(INTEL_INFO(dev)->has_slice_pg));
5100 seq_printf(m, " Has Subslice Power Gating: %s\n",
5101 yesno(INTEL_INFO(dev)->has_subslice_pg));
5102 seq_printf(m, " Has EU Power Gating: %s\n",
5103 yesno(INTEL_INFO(dev)->has_eu_pg));
5104
Jeff McGee7f992ab2015-02-13 10:27:55 -06005105 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07005106 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08005107 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07005108 cherryview_sseu_device_status(dev, &stat);
Łukasz Daniluk91bedd32015-09-25 11:54:58 +02005109 } else if (IS_BROADWELL(dev)) {
5110 broadwell_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005111 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005112 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005113 }
Jeff McGee5d395252015-04-03 18:13:17 -07005114 seq_printf(m, " Enabled Slice Total: %u\n",
5115 stat.slice_total);
5116 seq_printf(m, " Enabled Subslice Total: %u\n",
5117 stat.subslice_total);
5118 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5119 stat.subslice_per_slice);
5120 seq_printf(m, " Enabled EU Total: %u\n",
5121 stat.eu_total);
5122 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5123 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005124
Jeff McGee38732182015-02-13 10:27:54 -06005125 return 0;
5126}
5127
Ben Widawsky6d794d42011-04-25 11:25:56 -07005128static int i915_forcewake_open(struct inode *inode, struct file *file)
5129{
5130 struct drm_device *dev = inode->i_private;
5131 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005132
Daniel Vetter075edca2012-01-24 09:44:28 +01005133 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005134 return 0;
5135
Chris Wilson6daccb02015-01-16 11:34:35 +02005136 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005137 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005138
5139 return 0;
5140}
5141
Ben Widawskyc43b5632012-04-16 14:07:40 -07005142static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005143{
5144 struct drm_device *dev = inode->i_private;
5145 struct drm_i915_private *dev_priv = dev->dev_private;
5146
Daniel Vetter075edca2012-01-24 09:44:28 +01005147 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005148 return 0;
5149
Mika Kuoppala59bad942015-01-16 11:34:40 +02005150 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005151 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005152
5153 return 0;
5154}
5155
5156static const struct file_operations i915_forcewake_fops = {
5157 .owner = THIS_MODULE,
5158 .open = i915_forcewake_open,
5159 .release = i915_forcewake_release,
5160};
5161
5162static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5163{
5164 struct drm_device *dev = minor->dev;
5165 struct dentry *ent;
5166
5167 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005168 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005169 root, dev,
5170 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005171 if (!ent)
5172 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005173
Ben Widawsky8eb57292011-05-11 15:10:58 -07005174 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005175}
5176
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005177static int i915_debugfs_create(struct dentry *root,
5178 struct drm_minor *minor,
5179 const char *name,
5180 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005181{
5182 struct drm_device *dev = minor->dev;
5183 struct dentry *ent;
5184
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005185 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005186 S_IRUGO | S_IWUSR,
5187 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005188 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005189 if (!ent)
5190 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005191
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005192 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005193}
5194
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005195static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005196 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005197 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005198 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005199 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005200 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005201 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005202 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005203 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005204 {"i915_gem_request", i915_gem_request_info, 0},
5205 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005206 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005207 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005208 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5209 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5210 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005211 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005212 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Dave Gordon8b417c22015-08-12 15:43:44 +01005213 {"i915_guc_info", i915_guc_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005214 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005215 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305216 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005217 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005218 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005219 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005220 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005221 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005222 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005223 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005224 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005225 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005226 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005227 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005228 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005229 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005230 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005231 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005232 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005233 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005234 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005235 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005236 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005237 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005238 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005239 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005240 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005241 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005242 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005243 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005244 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005245 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305246 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005247 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005248};
Ben Gamari27c202a2009-07-01 22:26:52 -04005249#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005250
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005251static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005252 const char *name;
5253 const struct file_operations *fops;
5254} i915_debugfs_files[] = {
5255 {"i915_wedged", &i915_wedged_fops},
5256 {"i915_max_freq", &i915_max_freq_fops},
5257 {"i915_min_freq", &i915_min_freq_fops},
5258 {"i915_cache_sharing", &i915_cache_sharing_fops},
5259 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005260 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5261 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005262 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5263 {"i915_error_state", &i915_error_state_fops},
5264 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005265 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005266 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5267 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5268 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005269 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005270 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5271 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5272 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005273};
5274
Damien Lespiau07144422013-10-15 18:55:40 +01005275void intel_display_crc_init(struct drm_device *dev)
5276{
5277 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005278 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005279
Damien Lespiau055e3932014-08-18 13:49:10 +01005280 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005281 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005282
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005283 pipe_crc->opened = false;
5284 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005285 init_waitqueue_head(&pipe_crc->wq);
5286 }
5287}
5288
Ben Gamari27c202a2009-07-01 22:26:52 -04005289int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005290{
Daniel Vetter34b96742013-07-04 20:49:44 +02005291 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005292
Ben Widawsky6d794d42011-04-25 11:25:56 -07005293 ret = i915_forcewake_create(minor->debugfs_root, minor);
5294 if (ret)
5295 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005296
Damien Lespiau07144422013-10-15 18:55:40 +01005297 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5298 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5299 if (ret)
5300 return ret;
5301 }
5302
Daniel Vetter34b96742013-07-04 20:49:44 +02005303 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5304 ret = i915_debugfs_create(minor->debugfs_root, minor,
5305 i915_debugfs_files[i].name,
5306 i915_debugfs_files[i].fops);
5307 if (ret)
5308 return ret;
5309 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005310
Ben Gamari27c202a2009-07-01 22:26:52 -04005311 return drm_debugfs_create_files(i915_debugfs_list,
5312 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005313 minor->debugfs_root, minor);
5314}
5315
Ben Gamari27c202a2009-07-01 22:26:52 -04005316void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005317{
Daniel Vetter34b96742013-07-04 20:49:44 +02005318 int i;
5319
Ben Gamari27c202a2009-07-01 22:26:52 -04005320 drm_debugfs_remove_files(i915_debugfs_list,
5321 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005322
Ben Widawsky6d794d42011-04-25 11:25:56 -07005323 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5324 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005325
Daniel Vettere309a992013-10-16 22:55:51 +02005326 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005327 struct drm_info_list *info_list =
5328 (struct drm_info_list *)&i915_pipe_crc_data[i];
5329
5330 drm_debugfs_remove_files(info_list, 1, minor);
5331 }
5332
Daniel Vetter34b96742013-07-04 20:49:44 +02005333 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5334 struct drm_info_list *info_list =
5335 (struct drm_info_list *) i915_debugfs_files[i].fops;
5336
5337 drm_debugfs_remove_files(info_list, 1, minor);
5338 }
Ben Gamari20172632009-02-17 20:08:50 -05005339}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005340
5341struct dpcd_block {
5342 /* DPCD dump start address. */
5343 unsigned int offset;
5344 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5345 unsigned int end;
5346 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5347 size_t size;
5348 /* Only valid for eDP. */
5349 bool edp;
5350};
5351
5352static const struct dpcd_block i915_dpcd_debug[] = {
5353 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5354 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5355 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5356 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5357 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5358 { .offset = DP_SET_POWER },
5359 { .offset = DP_EDP_DPCD_REV },
5360 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5361 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5362 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5363};
5364
5365static int i915_dpcd_show(struct seq_file *m, void *data)
5366{
5367 struct drm_connector *connector = m->private;
5368 struct intel_dp *intel_dp =
5369 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5370 uint8_t buf[16];
5371 ssize_t err;
5372 int i;
5373
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005374 if (connector->status != connector_status_connected)
5375 return -ENODEV;
5376
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005377 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5378 const struct dpcd_block *b = &i915_dpcd_debug[i];
5379 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5380
5381 if (b->edp &&
5382 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5383 continue;
5384
5385 /* low tech for now */
5386 if (WARN_ON(size > sizeof(buf)))
5387 continue;
5388
5389 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5390 if (err <= 0) {
5391 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5392 size, b->offset, err);
5393 continue;
5394 }
5395
5396 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005397 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005398
5399 return 0;
5400}
5401
5402static int i915_dpcd_open(struct inode *inode, struct file *file)
5403{
5404 return single_open(file, i915_dpcd_show, inode->i_private);
5405}
5406
5407static const struct file_operations i915_dpcd_fops = {
5408 .owner = THIS_MODULE,
5409 .open = i915_dpcd_open,
5410 .read = seq_read,
5411 .llseek = seq_lseek,
5412 .release = single_release,
5413};
5414
5415/**
5416 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5417 * @connector: pointer to a registered drm_connector
5418 *
5419 * Cleanup will be done by drm_connector_unregister() through a call to
5420 * drm_debugfs_connector_remove().
5421 *
5422 * Returns 0 on success, negative error codes on error.
5423 */
5424int i915_debugfs_connector_add(struct drm_connector *connector)
5425{
5426 struct dentry *root = connector->debugfs_entry;
5427
5428 /* The connector must have been registered beforehands. */
5429 if (!root)
5430 return -ENODEV;
5431
5432 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5433 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5434 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5435 &i915_dpcd_fops);
5436
5437 return 0;
5438}