blob: 1946411e90e3eb553f0a7b1a04e2909f9418e02c [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
Chris Wilson70d39fe2010-08-25 16:03:34 +010049static const char *yesno(int v)
50{
51 return v ? "yes" : "no";
52}
53
Damien Lespiau497666d2013-10-15 18:55:39 +010054/* As the drm_debugfs_init() routines are called before dev->dev_private is
55 * allocated we need to hook into the minor for release. */
56static int
57drm_add_fake_info_node(struct drm_minor *minor,
58 struct dentry *ent,
59 const void *key)
60{
61 struct drm_info_node *node;
62
63 node = kmalloc(sizeof(*node), GFP_KERNEL);
64 if (node == NULL) {
65 debugfs_remove(ent);
66 return -ENOMEM;
67 }
68
69 node->minor = minor;
70 node->dent = ent;
71 node->info_ent = (void *) key;
72
73 mutex_lock(&minor->debugfs_lock);
74 list_add(&node->list, &minor->debugfs_list);
75 mutex_unlock(&minor->debugfs_lock);
76
77 return 0;
78}
79
Chris Wilson70d39fe2010-08-25 16:03:34 +010080static int i915_capabilities(struct seq_file *m, void *data)
81{
Damien Lespiau9f25d002014-05-13 15:30:28 +010082 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010083 struct drm_device *dev = node->minor->dev;
84 const struct intel_device_info *info = INTEL_INFO(dev);
85
86 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030087 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010088#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
89#define SEP_SEMICOLON ;
90 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
91#undef PRINT_FLAG
92#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010093
94 return 0;
95}
Ben Gamari433e12f2009-02-17 20:08:51 -050096
Chris Wilson05394f32010-11-08 19:18:58 +000097static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000098{
Chris Wilsonbaaa5cf2015-04-15 16:42:46 +010099 if (obj->pin_display)
Chris Wilsona6172a82009-02-11 14:26:38 +0000100 return "p";
101 else
102 return " ";
103}
104
Chris Wilson05394f32010-11-08 19:18:58 +0000105static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000106{
Akshay Joshi0206e352011-08-16 15:34:10 -0400107 switch (obj->tiling_mode) {
108 default:
109 case I915_TILING_NONE: return " ";
110 case I915_TILING_X: return "X";
111 case I915_TILING_Y: return "Y";
112 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000113}
114
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700115static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
116{
Tvrtko Ursulinaff43762014-10-24 12:42:33 +0100117 return i915_gem_obj_to_ggtt(obj) ? "g" : " ";
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700118}
119
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100120static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
121{
122 u64 size = 0;
123 struct i915_vma *vma;
124
125 list_for_each_entry(vma, &obj->vma_list, vma_link) {
126 if (i915_is_ggtt(vma->vm) &&
127 drm_mm_node_allocated(&vma->node))
128 size += vma->node.size;
129 }
130
131 return size;
132}
133
Chris Wilson37811fc2010-08-25 22:45:57 +0100134static void
135describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
136{
Chris Wilsonb4716182015-04-27 13:41:17 +0100137 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
138 struct intel_engine_cs *ring;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700139 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800140 int pin_count = 0;
Chris Wilsonb4716182015-04-27 13:41:17 +0100141 int i;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800142
Chris Wilsonb4716182015-04-27 13:41:17 +0100143 seq_printf(m, "%pK: %s%s%s%s %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100144 &obj->base,
Chris Wilson481a3d42015-04-07 16:20:39 +0100145 obj->active ? "*" : " ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100146 get_pin_flag(obj),
147 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700148 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800149 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100150 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100151 obj->base.write_domain);
152 for_each_ring(ring, dev_priv, i)
153 seq_printf(m, "%x ",
154 i915_gem_request_get_seqno(obj->last_read_req[i]));
155 seq_printf(m, "] %x %x%s%s%s",
John Harrison97b2a6a2014-11-24 18:49:26 +0000156 i915_gem_request_get_seqno(obj->last_write_req),
157 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100158 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100159 obj->dirty ? " dirty" : "",
160 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
161 if (obj->base.name)
162 seq_printf(m, " (name: %d)", obj->base.name);
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300163 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800164 if (vma->pin_count > 0)
165 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300166 }
167 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100168 if (obj->pin_display)
169 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100170 if (obj->fence_reg != I915_FENCE_REG_NONE)
171 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700172 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100173 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
174 i915_is_ggtt(vma->vm) ? "g" : "pp",
175 vma->node.start, vma->node.size);
176 if (i915_is_ggtt(vma->vm))
177 seq_printf(m, ", type: %u)", vma->ggtt_view.type);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700178 else
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100179 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700180 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000181 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100182 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100183 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000184 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100185 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000186 *t++ = 'p';
187 if (obj->fault_mappable)
188 *t++ = 'f';
189 *t = '\0';
190 seq_printf(m, " (%s mappable)", s);
191 }
Chris Wilsonb4716182015-04-27 13:41:17 +0100192 if (obj->last_write_req != NULL)
John Harrison41c52412014-11-24 18:49:43 +0000193 seq_printf(m, " (%s)",
Chris Wilsonb4716182015-04-27 13:41:17 +0100194 i915_gem_request_get_ring(obj->last_write_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200195 if (obj->frontbuffer_bits)
196 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100197}
198
Oscar Mateo273497e2014-05-22 14:13:37 +0100199static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700200{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100201 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700202 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
203 seq_putc(m, ' ');
204}
205
Ben Gamari433e12f2009-02-17 20:08:51 -0500206static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500207{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100208 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500209 uintptr_t list = (uintptr_t) node->info_ent->data;
210 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500211 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700212 struct drm_i915_private *dev_priv = dev->dev_private;
213 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700214 struct i915_vma *vma;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300215 u64 total_obj_size, total_gtt_size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100216 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100217
218 ret = mutex_lock_interruptible(&dev->struct_mutex);
219 if (ret)
220 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500221
Ben Widawskyca191b12013-07-31 17:00:14 -0700222 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500223 switch (list) {
224 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100225 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700226 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500227 break;
228 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100229 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700230 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500231 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500232 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100233 mutex_unlock(&dev->struct_mutex);
234 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500235 }
236
Chris Wilson8f2480f2010-09-26 11:44:19 +0100237 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700238 list_for_each_entry(vma, head, mm_list) {
239 seq_printf(m, " ");
240 describe_obj(m, vma->obj);
241 seq_printf(m, "\n");
242 total_obj_size += vma->obj->base.size;
243 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100244 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500245 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100246 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700247
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300248 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson8f2480f2010-09-26 11:44:19 +0100249 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500250 return 0;
251}
252
Chris Wilson6d2b88852013-08-07 18:30:54 +0100253static int obj_rank_by_stolen(void *priv,
254 struct list_head *A, struct list_head *B)
255{
256 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200257 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100258 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200259 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100260
261 return a->stolen->start - b->stolen->start;
262}
263
264static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
265{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100266 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100267 struct drm_device *dev = node->minor->dev;
268 struct drm_i915_private *dev_priv = dev->dev_private;
269 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300270 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100271 LIST_HEAD(stolen);
272 int count, ret;
273
274 ret = mutex_lock_interruptible(&dev->struct_mutex);
275 if (ret)
276 return ret;
277
278 total_obj_size = total_gtt_size = count = 0;
279 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
280 if (obj->stolen == NULL)
281 continue;
282
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200283 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100284
285 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100286 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100287 count++;
288 }
289 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
290 if (obj->stolen == NULL)
291 continue;
292
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200293 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100294
295 total_obj_size += obj->base.size;
296 count++;
297 }
298 list_sort(NULL, &stolen, obj_rank_by_stolen);
299 seq_puts(m, "Stolen:\n");
300 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200301 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100302 seq_puts(m, " ");
303 describe_obj(m, obj);
304 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200305 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100306 }
307 mutex_unlock(&dev->struct_mutex);
308
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300309 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100310 count, total_obj_size, total_gtt_size);
311 return 0;
312}
313
Chris Wilson6299f992010-11-24 12:23:44 +0000314#define count_objects(list, member) do { \
315 list_for_each_entry(obj, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100316 size += i915_gem_obj_total_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000317 ++count; \
318 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700319 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000320 ++mappable_count; \
321 } \
322 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400323} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000324
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100325struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000326 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300327 unsigned long count;
328 u64 total, unbound;
329 u64 global, shared;
330 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100331};
332
333static int per_file_stats(int id, void *ptr, void *data)
334{
335 struct drm_i915_gem_object *obj = ptr;
336 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000337 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100338
339 stats->count++;
340 stats->total += obj->base.size;
341
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000342 if (obj->base.name || obj->base.dma_buf)
343 stats->shared += obj->base.size;
344
Chris Wilson6313c202014-03-19 13:45:45 +0000345 if (USES_FULL_PPGTT(obj->base.dev)) {
346 list_for_each_entry(vma, &obj->vma_list, vma_link) {
347 struct i915_hw_ppgtt *ppgtt;
348
349 if (!drm_mm_node_allocated(&vma->node))
350 continue;
351
352 if (i915_is_ggtt(vma->vm)) {
353 stats->global += obj->base.size;
354 continue;
355 }
356
357 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200358 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000359 continue;
360
John Harrison41c52412014-11-24 18:49:43 +0000361 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000362 stats->active += obj->base.size;
363 else
364 stats->inactive += obj->base.size;
365
366 return 0;
367 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100368 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000369 if (i915_gem_obj_ggtt_bound(obj)) {
370 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000371 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000372 stats->active += obj->base.size;
373 else
374 stats->inactive += obj->base.size;
375 return 0;
376 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100377 }
378
Chris Wilson6313c202014-03-19 13:45:45 +0000379 if (!list_empty(&obj->global_list))
380 stats->unbound += obj->base.size;
381
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100382 return 0;
383}
384
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100385#define print_file_stats(m, name, stats) do { \
386 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300387 seq_printf(m, "%s: %lu objects, %llu bytes (%llu active, %llu inactive, %llu global, %llu shared, %llu unbound)\n", \
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100388 name, \
389 stats.count, \
390 stats.total, \
391 stats.active, \
392 stats.inactive, \
393 stats.global, \
394 stats.shared, \
395 stats.unbound); \
396} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800397
398static void print_batch_pool_stats(struct seq_file *m,
399 struct drm_i915_private *dev_priv)
400{
401 struct drm_i915_gem_object *obj;
402 struct file_stats stats;
Chris Wilson06fbca72015-04-07 16:20:36 +0100403 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100404 int i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800405
406 memset(&stats, 0, sizeof(stats));
407
Chris Wilson06fbca72015-04-07 16:20:36 +0100408 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100409 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
410 list_for_each_entry(obj,
411 &ring->batch_pool.cache_list[j],
412 batch_pool_link)
413 per_file_stats(0, obj, &stats);
414 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100415 }
Brad Volkin493018d2014-12-11 12:13:08 -0800416
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100417 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800418}
419
Ben Widawskyca191b12013-07-31 17:00:14 -0700420#define count_vmas(list, member) do { \
421 list_for_each_entry(vma, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100422 size += i915_gem_obj_total_ggtt_size(vma->obj); \
Ben Widawskyca191b12013-07-31 17:00:14 -0700423 ++count; \
424 if (vma->obj->map_and_fenceable) { \
425 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
426 ++mappable_count; \
427 } \
428 } \
429} while (0)
430
431static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100432{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100433 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100434 struct drm_device *dev = node->minor->dev;
435 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200436 u32 count, mappable_count, purgeable_count;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300437 u64 size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000438 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700439 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100440 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700441 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100442 int ret;
443
444 ret = mutex_lock_interruptible(&dev->struct_mutex);
445 if (ret)
446 return ret;
447
Chris Wilson6299f992010-11-24 12:23:44 +0000448 seq_printf(m, "%u objects, %zu bytes\n",
449 dev_priv->mm.object_count,
450 dev_priv->mm.object_memory);
451
452 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700453 count_objects(&dev_priv->mm.bound_list, global_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300454 seq_printf(m, "%u [%u] objects, %llu [%llu] bytes in gtt\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000455 count, mappable_count, size, mappable_size);
456
457 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700458 count_vmas(&vm->active_list, mm_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300459 seq_printf(m, " %u [%u] active objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000460 count, mappable_count, size, mappable_size);
461
462 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700463 count_vmas(&vm->inactive_list, mm_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300464 seq_printf(m, " %u [%u] inactive objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000465 count, mappable_count, size, mappable_size);
466
Chris Wilsonb7abb712012-08-20 11:33:30 +0200467 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700468 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200469 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200470 if (obj->madv == I915_MADV_DONTNEED)
471 purgeable_size += obj->base.size, ++purgeable_count;
472 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300473 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
Chris Wilson6c085a72012-08-20 11:40:46 +0200474
Chris Wilson6299f992010-11-24 12:23:44 +0000475 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700476 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000477 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700478 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000479 ++count;
480 }
Chris Wilson30154652015-04-07 17:28:24 +0100481 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700482 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000483 ++mappable_count;
484 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200485 if (obj->madv == I915_MADV_DONTNEED) {
486 purgeable_size += obj->base.size;
487 ++purgeable_count;
488 }
Chris Wilson6299f992010-11-24 12:23:44 +0000489 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300490 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200491 purgeable_count, purgeable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300492 seq_printf(m, "%u pinned mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000493 mappable_count, mappable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300494 seq_printf(m, "%u fault mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000495 count, size);
496
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300497 seq_printf(m, "%llu [%llu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700498 dev_priv->gtt.base.total,
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300499 (u64)dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100500
Damien Lespiau267f0c92013-06-24 22:59:48 +0100501 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800502 print_batch_pool_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100503 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
504 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900505 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100506
507 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000508 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100509 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100510 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100511 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900512 /*
513 * Although we have a valid reference on file->pid, that does
514 * not guarantee that the task_struct who called get_pid() is
515 * still alive (e.g. get_pid(current) => fork() => exit()).
516 * Therefore, we need to protect this ->comm access using RCU.
517 */
518 rcu_read_lock();
519 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800520 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900521 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100522 }
523
Chris Wilson73aa8082010-09-30 11:46:12 +0100524 mutex_unlock(&dev->struct_mutex);
525
526 return 0;
527}
528
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100529static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000530{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100531 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000532 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100533 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000534 struct drm_i915_private *dev_priv = dev->dev_private;
535 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300536 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000537 int count, ret;
538
539 ret = mutex_lock_interruptible(&dev->struct_mutex);
540 if (ret)
541 return ret;
542
543 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700544 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800545 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100546 continue;
547
Damien Lespiau267f0c92013-06-24 22:59:48 +0100548 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000549 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100550 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000551 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100552 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000553 count++;
554 }
555
556 mutex_unlock(&dev->struct_mutex);
557
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300558 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000559 count, total_obj_size, total_gtt_size);
560
561 return 0;
562}
563
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100564static int i915_gem_pageflip_info(struct seq_file *m, void *data)
565{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100566 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100567 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100568 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100569 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200570 int ret;
571
572 ret = mutex_lock_interruptible(&dev->struct_mutex);
573 if (ret)
574 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100575
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100576 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800577 const char pipe = pipe_name(crtc->pipe);
578 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100579 struct intel_unpin_work *work;
580
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200581 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100582 work = crtc->unpin_work;
583 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800584 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100585 pipe, plane);
586 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100587 u32 addr;
588
Chris Wilsone7d841c2012-12-03 11:36:30 +0000589 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800590 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100591 pipe, plane);
592 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800593 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100594 pipe, plane);
595 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100596 if (work->flip_queued_req) {
597 struct intel_engine_cs *ring =
598 i915_gem_request_get_ring(work->flip_queued_req);
599
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200600 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 +0100601 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000602 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100603 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100604 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000605 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100606 } else
607 seq_printf(m, "Flip not associated with any ring\n");
608 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
609 work->flip_queued_vblank,
610 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100611 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100612 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100613 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100614 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100615 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000616 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100617
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100618 if (INTEL_INFO(dev)->gen >= 4)
619 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
620 else
621 addr = I915_READ(DSPADDR(crtc->plane));
622 seq_printf(m, "Current scanout address 0x%08x\n", addr);
623
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100624 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100625 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
626 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100627 }
628 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200629 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100630 }
631
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200632 mutex_unlock(&dev->struct_mutex);
633
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100634 return 0;
635}
636
Brad Volkin493018d2014-12-11 12:13:08 -0800637static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
638{
639 struct drm_info_node *node = m->private;
640 struct drm_device *dev = node->minor->dev;
641 struct drm_i915_private *dev_priv = dev->dev_private;
642 struct drm_i915_gem_object *obj;
Chris Wilson06fbca72015-04-07 16:20:36 +0100643 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100644 int total = 0;
645 int ret, i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800646
647 ret = mutex_lock_interruptible(&dev->struct_mutex);
648 if (ret)
649 return ret;
650
Chris Wilson06fbca72015-04-07 16:20:36 +0100651 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100652 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
653 int count;
654
655 count = 0;
656 list_for_each_entry(obj,
657 &ring->batch_pool.cache_list[j],
658 batch_pool_link)
659 count++;
660 seq_printf(m, "%s cache[%d]: %d objects\n",
661 ring->name, j, count);
662
663 list_for_each_entry(obj,
664 &ring->batch_pool.cache_list[j],
665 batch_pool_link) {
666 seq_puts(m, " ");
667 describe_obj(m, obj);
668 seq_putc(m, '\n');
669 }
670
671 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100672 }
Brad Volkin493018d2014-12-11 12:13:08 -0800673 }
674
Chris Wilson8d9d5742015-04-07 16:20:38 +0100675 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800676
677 mutex_unlock(&dev->struct_mutex);
678
679 return 0;
680}
681
Ben Gamari20172632009-02-17 20:08:50 -0500682static int i915_gem_request_info(struct seq_file *m, void *data)
683{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100684 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500685 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300686 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100687 struct intel_engine_cs *ring;
Daniel Vettereed29a52015-05-21 14:21:25 +0200688 struct drm_i915_gem_request *req;
Chris Wilson2d1070b2015-04-01 10:36:56 +0100689 int ret, any, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100690
691 ret = mutex_lock_interruptible(&dev->struct_mutex);
692 if (ret)
693 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500694
Chris Wilson2d1070b2015-04-01 10:36:56 +0100695 any = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100696 for_each_ring(ring, dev_priv, i) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100697 int count;
698
699 count = 0;
Daniel Vettereed29a52015-05-21 14:21:25 +0200700 list_for_each_entry(req, &ring->request_list, list)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100701 count++;
702 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100703 continue;
704
Chris Wilson2d1070b2015-04-01 10:36:56 +0100705 seq_printf(m, "%s requests: %d\n", ring->name, count);
Daniel Vettereed29a52015-05-21 14:21:25 +0200706 list_for_each_entry(req, &ring->request_list, list) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100707 struct task_struct *task;
708
709 rcu_read_lock();
710 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200711 if (req->pid)
712 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100713 seq_printf(m, " %x @ %d: %s [%d]\n",
Daniel Vettereed29a52015-05-21 14:21:25 +0200714 req->seqno,
715 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100716 task ? task->comm : "<unknown>",
717 task ? task->pid : -1);
718 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100719 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100720
721 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500722 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100723 mutex_unlock(&dev->struct_mutex);
724
Chris Wilson2d1070b2015-04-01 10:36:56 +0100725 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100726 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100727
Ben Gamari20172632009-02-17 20:08:50 -0500728 return 0;
729}
730
Chris Wilsonb2223492010-10-27 15:27:33 +0100731static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100732 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100733{
734 if (ring->get_seqno) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200735 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100736 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100737 }
738}
739
Ben Gamari20172632009-02-17 20:08:50 -0500740static int i915_gem_seqno_info(struct seq_file *m, void *data)
741{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100742 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500743 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300744 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100745 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000746 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100747
748 ret = mutex_lock_interruptible(&dev->struct_mutex);
749 if (ret)
750 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200751 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500752
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100753 for_each_ring(ring, dev_priv, i)
754 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100755
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200756 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100757 mutex_unlock(&dev->struct_mutex);
758
Ben Gamari20172632009-02-17 20:08:50 -0500759 return 0;
760}
761
762
763static int i915_interrupt_info(struct seq_file *m, void *data)
764{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100765 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500766 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300767 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100768 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800769 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100770
771 ret = mutex_lock_interruptible(&dev->struct_mutex);
772 if (ret)
773 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200774 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500775
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300776 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300777 seq_printf(m, "Master Interrupt Control:\t%08x\n",
778 I915_READ(GEN8_MASTER_IRQ));
779
780 seq_printf(m, "Display IER:\t%08x\n",
781 I915_READ(VLV_IER));
782 seq_printf(m, "Display IIR:\t%08x\n",
783 I915_READ(VLV_IIR));
784 seq_printf(m, "Display IIR_RW:\t%08x\n",
785 I915_READ(VLV_IIR_RW));
786 seq_printf(m, "Display IMR:\t%08x\n",
787 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100788 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300789 seq_printf(m, "Pipe %c stat:\t%08x\n",
790 pipe_name(pipe),
791 I915_READ(PIPESTAT(pipe)));
792
793 seq_printf(m, "Port hotplug:\t%08x\n",
794 I915_READ(PORT_HOTPLUG_EN));
795 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
796 I915_READ(VLV_DPFLIPSTAT));
797 seq_printf(m, "DPINVGTT:\t%08x\n",
798 I915_READ(DPINVGTT));
799
800 for (i = 0; i < 4; i++) {
801 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
802 i, I915_READ(GEN8_GT_IMR(i)));
803 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
804 i, I915_READ(GEN8_GT_IIR(i)));
805 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
806 i, I915_READ(GEN8_GT_IER(i)));
807 }
808
809 seq_printf(m, "PCU interrupt mask:\t%08x\n",
810 I915_READ(GEN8_PCU_IMR));
811 seq_printf(m, "PCU interrupt identity:\t%08x\n",
812 I915_READ(GEN8_PCU_IIR));
813 seq_printf(m, "PCU interrupt enable:\t%08x\n",
814 I915_READ(GEN8_PCU_IER));
815 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700816 seq_printf(m, "Master Interrupt Control:\t%08x\n",
817 I915_READ(GEN8_MASTER_IRQ));
818
819 for (i = 0; i < 4; i++) {
820 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
821 i, I915_READ(GEN8_GT_IMR(i)));
822 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
823 i, I915_READ(GEN8_GT_IIR(i)));
824 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
825 i, I915_READ(GEN8_GT_IER(i)));
826 }
827
Damien Lespiau055e3932014-08-18 13:49:10 +0100828 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200829 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300830 POWER_DOMAIN_PIPE(pipe))) {
831 seq_printf(m, "Pipe %c power disabled\n",
832 pipe_name(pipe));
833 continue;
834 }
Ben Widawskya123f152013-11-02 21:07:10 -0700835 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000836 pipe_name(pipe),
837 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700838 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000839 pipe_name(pipe),
840 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700841 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000842 pipe_name(pipe),
843 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700844 }
845
846 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
847 I915_READ(GEN8_DE_PORT_IMR));
848 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
849 I915_READ(GEN8_DE_PORT_IIR));
850 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
851 I915_READ(GEN8_DE_PORT_IER));
852
853 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
854 I915_READ(GEN8_DE_MISC_IMR));
855 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
856 I915_READ(GEN8_DE_MISC_IIR));
857 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
858 I915_READ(GEN8_DE_MISC_IER));
859
860 seq_printf(m, "PCU interrupt mask:\t%08x\n",
861 I915_READ(GEN8_PCU_IMR));
862 seq_printf(m, "PCU interrupt identity:\t%08x\n",
863 I915_READ(GEN8_PCU_IIR));
864 seq_printf(m, "PCU interrupt enable:\t%08x\n",
865 I915_READ(GEN8_PCU_IER));
866 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700867 seq_printf(m, "Display IER:\t%08x\n",
868 I915_READ(VLV_IER));
869 seq_printf(m, "Display IIR:\t%08x\n",
870 I915_READ(VLV_IIR));
871 seq_printf(m, "Display IIR_RW:\t%08x\n",
872 I915_READ(VLV_IIR_RW));
873 seq_printf(m, "Display IMR:\t%08x\n",
874 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100875 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700876 seq_printf(m, "Pipe %c stat:\t%08x\n",
877 pipe_name(pipe),
878 I915_READ(PIPESTAT(pipe)));
879
880 seq_printf(m, "Master IER:\t%08x\n",
881 I915_READ(VLV_MASTER_IER));
882
883 seq_printf(m, "Render IER:\t%08x\n",
884 I915_READ(GTIER));
885 seq_printf(m, "Render IIR:\t%08x\n",
886 I915_READ(GTIIR));
887 seq_printf(m, "Render IMR:\t%08x\n",
888 I915_READ(GTIMR));
889
890 seq_printf(m, "PM IER:\t\t%08x\n",
891 I915_READ(GEN6_PMIER));
892 seq_printf(m, "PM IIR:\t\t%08x\n",
893 I915_READ(GEN6_PMIIR));
894 seq_printf(m, "PM IMR:\t\t%08x\n",
895 I915_READ(GEN6_PMIMR));
896
897 seq_printf(m, "Port hotplug:\t%08x\n",
898 I915_READ(PORT_HOTPLUG_EN));
899 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
900 I915_READ(VLV_DPFLIPSTAT));
901 seq_printf(m, "DPINVGTT:\t%08x\n",
902 I915_READ(DPINVGTT));
903
904 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800905 seq_printf(m, "Interrupt enable: %08x\n",
906 I915_READ(IER));
907 seq_printf(m, "Interrupt identity: %08x\n",
908 I915_READ(IIR));
909 seq_printf(m, "Interrupt mask: %08x\n",
910 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100911 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800912 seq_printf(m, "Pipe %c stat: %08x\n",
913 pipe_name(pipe),
914 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800915 } else {
916 seq_printf(m, "North Display Interrupt enable: %08x\n",
917 I915_READ(DEIER));
918 seq_printf(m, "North Display Interrupt identity: %08x\n",
919 I915_READ(DEIIR));
920 seq_printf(m, "North Display Interrupt mask: %08x\n",
921 I915_READ(DEIMR));
922 seq_printf(m, "South Display Interrupt enable: %08x\n",
923 I915_READ(SDEIER));
924 seq_printf(m, "South Display Interrupt identity: %08x\n",
925 I915_READ(SDEIIR));
926 seq_printf(m, "South Display Interrupt mask: %08x\n",
927 I915_READ(SDEIMR));
928 seq_printf(m, "Graphics Interrupt enable: %08x\n",
929 I915_READ(GTIER));
930 seq_printf(m, "Graphics Interrupt identity: %08x\n",
931 I915_READ(GTIIR));
932 seq_printf(m, "Graphics Interrupt mask: %08x\n",
933 I915_READ(GTIMR));
934 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100935 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700936 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100937 seq_printf(m,
938 "Graphics Interrupt mask (%s): %08x\n",
939 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000940 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100941 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000942 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200943 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100944 mutex_unlock(&dev->struct_mutex);
945
Ben Gamari20172632009-02-17 20:08:50 -0500946 return 0;
947}
948
Chris Wilsona6172a82009-02-11 14:26:38 +0000949static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
950{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100951 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000952 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300953 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100954 int i, ret;
955
956 ret = mutex_lock_interruptible(&dev->struct_mutex);
957 if (ret)
958 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000959
960 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
961 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
962 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000963 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000964
Chris Wilson6c085a72012-08-20 11:40:46 +0200965 seq_printf(m, "Fence %d, pin count = %d, object = ",
966 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100967 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100968 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100969 else
Chris Wilson05394f32010-11-08 19:18:58 +0000970 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100971 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000972 }
973
Chris Wilson05394f32010-11-08 19:18:58 +0000974 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000975 return 0;
976}
977
Ben Gamari20172632009-02-17 20:08:50 -0500978static int i915_hws_info(struct seq_file *m, void *data)
979{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100980 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500981 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300982 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100983 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100984 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100985 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500986
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000987 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100988 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500989 if (hws == NULL)
990 return 0;
991
992 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
993 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
994 i * 4,
995 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
996 }
997 return 0;
998}
999
Daniel Vetterd5442302012-04-27 15:17:40 +02001000static ssize_t
1001i915_error_state_write(struct file *filp,
1002 const char __user *ubuf,
1003 size_t cnt,
1004 loff_t *ppos)
1005{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001006 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001007 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001008 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001009
1010 DRM_DEBUG_DRIVER("Resetting error state\n");
1011
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001012 ret = mutex_lock_interruptible(&dev->struct_mutex);
1013 if (ret)
1014 return ret;
1015
Daniel Vetterd5442302012-04-27 15:17:40 +02001016 i915_destroy_error_state(dev);
1017 mutex_unlock(&dev->struct_mutex);
1018
1019 return cnt;
1020}
1021
1022static int i915_error_state_open(struct inode *inode, struct file *file)
1023{
1024 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001025 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001026
1027 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1028 if (!error_priv)
1029 return -ENOMEM;
1030
1031 error_priv->dev = dev;
1032
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001033 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001034
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001035 file->private_data = error_priv;
1036
1037 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001038}
1039
1040static int i915_error_state_release(struct inode *inode, struct file *file)
1041{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001042 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001043
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001044 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001045 kfree(error_priv);
1046
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001047 return 0;
1048}
1049
1050static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1051 size_t count, loff_t *pos)
1052{
1053 struct i915_error_state_file_priv *error_priv = file->private_data;
1054 struct drm_i915_error_state_buf error_str;
1055 loff_t tmp_pos = 0;
1056 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001057 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001058
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001059 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001060 if (ret)
1061 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001062
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001063 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001064 if (ret)
1065 goto out;
1066
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001067 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1068 error_str.buf,
1069 error_str.bytes);
1070
1071 if (ret_count < 0)
1072 ret = ret_count;
1073 else
1074 *pos = error_str.start + ret_count;
1075out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001076 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001077 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001078}
1079
1080static const struct file_operations i915_error_state_fops = {
1081 .owner = THIS_MODULE,
1082 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001083 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001084 .write = i915_error_state_write,
1085 .llseek = default_llseek,
1086 .release = i915_error_state_release,
1087};
1088
Kees Cook647416f2013-03-10 14:10:06 -07001089static int
1090i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001091{
Kees Cook647416f2013-03-10 14:10:06 -07001092 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001093 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001094 int ret;
1095
1096 ret = mutex_lock_interruptible(&dev->struct_mutex);
1097 if (ret)
1098 return ret;
1099
Kees Cook647416f2013-03-10 14:10:06 -07001100 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001101 mutex_unlock(&dev->struct_mutex);
1102
Kees Cook647416f2013-03-10 14:10:06 -07001103 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001104}
1105
Kees Cook647416f2013-03-10 14:10:06 -07001106static int
1107i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001108{
Kees Cook647416f2013-03-10 14:10:06 -07001109 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001110 int ret;
1111
Mika Kuoppala40633212012-12-04 15:12:00 +02001112 ret = mutex_lock_interruptible(&dev->struct_mutex);
1113 if (ret)
1114 return ret;
1115
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001116 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001117 mutex_unlock(&dev->struct_mutex);
1118
Kees Cook647416f2013-03-10 14:10:06 -07001119 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001120}
1121
Kees Cook647416f2013-03-10 14:10:06 -07001122DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1123 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001124 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001125
Deepak Sadb4bd12014-03-31 11:30:02 +05301126static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001127{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001128 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001129 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001130 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001131 int ret = 0;
1132
1133 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001134
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001135 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1136
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001137 if (IS_GEN5(dev)) {
1138 u16 rgvswctl = I915_READ16(MEMSWCTL);
1139 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1140
1141 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1142 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1143 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1144 MEMSTAT_VID_SHIFT);
1145 seq_printf(m, "Current P-state: %d\n",
1146 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001147 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
Akash Goel60260a52015-03-06 11:07:21 +05301148 IS_BROADWELL(dev) || IS_GEN9(dev)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001149 u32 rp_state_limits;
1150 u32 gt_perf_status;
1151 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001152 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001153 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001154 u32 rpupei, rpcurup, rpprevup;
1155 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001156 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001157 int max_freq;
1158
Bob Paauwe35040562015-06-25 14:54:07 -07001159 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1160 if (IS_BROXTON(dev)) {
1161 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1162 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1163 } else {
1164 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1165 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1166 }
1167
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001168 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001169 ret = mutex_lock_interruptible(&dev->struct_mutex);
1170 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001171 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001172
Mika Kuoppala59bad942015-01-16 11:34:40 +02001173 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001174
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001175 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301176 if (IS_GEN9(dev))
1177 reqf >>= 23;
1178 else {
1179 reqf &= ~GEN6_TURBO_DISABLE;
1180 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1181 reqf >>= 24;
1182 else
1183 reqf >>= 25;
1184 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001185 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001186
Chris Wilson0d8f9492014-03-27 09:06:14 +00001187 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1188 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1189 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1190
Jesse Barnesccab5c82011-01-18 15:49:25 -08001191 rpstat = I915_READ(GEN6_RPSTAT1);
1192 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1193 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1194 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1195 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1196 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1197 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Akash Goel60260a52015-03-06 11:07:21 +05301198 if (IS_GEN9(dev))
1199 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1200 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001201 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1202 else
1203 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001204 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001205
Mika Kuoppala59bad942015-01-16 11:34:40 +02001206 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001207 mutex_unlock(&dev->struct_mutex);
1208
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001209 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1210 pm_ier = I915_READ(GEN6_PMIER);
1211 pm_imr = I915_READ(GEN6_PMIMR);
1212 pm_isr = I915_READ(GEN6_PMISR);
1213 pm_iir = I915_READ(GEN6_PMIIR);
1214 pm_mask = I915_READ(GEN6_PMINTRMSK);
1215 } else {
1216 pm_ier = I915_READ(GEN8_GT_IER(2));
1217 pm_imr = I915_READ(GEN8_GT_IMR(2));
1218 pm_isr = I915_READ(GEN8_GT_ISR(2));
1219 pm_iir = I915_READ(GEN8_GT_IIR(2));
1220 pm_mask = I915_READ(GEN6_PMINTRMSK);
1221 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001222 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 -03001223 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001224 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001225 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301226 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001227 seq_printf(m, "Render p-state VID: %d\n",
1228 gt_perf_status & 0xff);
1229 seq_printf(m, "Render p-state limit: %d\n",
1230 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001231 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1232 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1233 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1234 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001235 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001236 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001237 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1238 GEN6_CURICONT_MASK);
1239 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1240 GEN6_CURBSYTAVG_MASK);
1241 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1242 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001243 seq_printf(m, "Up threshold: %d%%\n",
1244 dev_priv->rps.up_threshold);
1245
Jesse Barnesccab5c82011-01-18 15:49:25 -08001246 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1247 GEN6_CURIAVG_MASK);
1248 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1249 GEN6_CURBSYTAVG_MASK);
1250 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1251 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001252 seq_printf(m, "Down threshold: %d%%\n",
1253 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001254
Bob Paauwe35040562015-06-25 14:54:07 -07001255 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1256 rp_state_cap >> 16) & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301257 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001258 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001259 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001260
1261 max_freq = (rp_state_cap & 0xff00) >> 8;
Akash Goel60260a52015-03-06 11:07:21 +05301262 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001263 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001264 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001265
Bob Paauwe35040562015-06-25 14:54:07 -07001266 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1267 rp_state_cap >> 0) & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301268 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001269 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001270 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001271 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001272 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001273
Chris Wilsond86ed342015-04-27 13:41:19 +01001274 seq_printf(m, "Current freq: %d MHz\n",
1275 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1276 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001277 seq_printf(m, "Idle freq: %d MHz\n",
1278 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001279 seq_printf(m, "Min freq: %d MHz\n",
1280 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1281 seq_printf(m, "Max freq: %d MHz\n",
1282 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1283 seq_printf(m,
1284 "efficient (RPe) frequency: %d MHz\n",
1285 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001286 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001287 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001288
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001289 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001290 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001291 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1292 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1293
Chris Wilsond86ed342015-04-27 13:41:19 +01001294 seq_printf(m, "actual GPU freq: %d MHz\n",
1295 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1296
1297 seq_printf(m, "current GPU freq: %d MHz\n",
1298 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1299
Jesse Barnes0a073b82013-04-17 15:54:58 -07001300 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001301 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001302
Jesse Barnes0a073b82013-04-17 15:54:58 -07001303 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001304 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001305
Chris Wilsonaed242f2015-03-18 09:48:21 +00001306 seq_printf(m, "idle GPU freq: %d MHz\n",
1307 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1308
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001309 seq_printf(m,
1310 "efficient (RPe) frequency: %d MHz\n",
1311 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001312 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001313 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001314 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001315 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001316
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001317out:
1318 intel_runtime_pm_put(dev_priv);
1319 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001320}
1321
Chris Wilsonf6544492015-01-26 18:03:04 +02001322static int i915_hangcheck_info(struct seq_file *m, void *unused)
1323{
1324 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001325 struct drm_device *dev = node->minor->dev;
1326 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf6544492015-01-26 18:03:04 +02001327 struct intel_engine_cs *ring;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001328 u64 acthd[I915_NUM_RINGS];
1329 u32 seqno[I915_NUM_RINGS];
Chris Wilsonf6544492015-01-26 18:03:04 +02001330 int i;
1331
1332 if (!i915.enable_hangcheck) {
1333 seq_printf(m, "Hangcheck disabled\n");
1334 return 0;
1335 }
1336
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001337 intel_runtime_pm_get(dev_priv);
1338
1339 for_each_ring(ring, dev_priv, i) {
1340 seqno[i] = ring->get_seqno(ring, false);
1341 acthd[i] = intel_ring_get_active_head(ring);
1342 }
1343
1344 intel_runtime_pm_put(dev_priv);
1345
Chris Wilsonf6544492015-01-26 18:03:04 +02001346 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1347 seq_printf(m, "Hangcheck active, fires in %dms\n",
1348 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1349 jiffies));
1350 } else
1351 seq_printf(m, "Hangcheck inactive\n");
1352
1353 for_each_ring(ring, dev_priv, i) {
1354 seq_printf(m, "%s:\n", ring->name);
1355 seq_printf(m, "\tseqno = %x [current %x]\n",
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001356 ring->hangcheck.seqno, seqno[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001357 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1358 (long long)ring->hangcheck.acthd,
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001359 (long long)acthd[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001360 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1361 (long long)ring->hangcheck.max_acthd);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001362 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1363 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
Chris Wilsonf6544492015-01-26 18:03:04 +02001364 }
1365
1366 return 0;
1367}
1368
Ben Widawsky4d855292011-12-12 19:34:16 -08001369static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001370{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001371 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001372 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001373 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001374 u32 rgvmodectl, rstdbyctl;
1375 u16 crstandvid;
1376 int ret;
1377
1378 ret = mutex_lock_interruptible(&dev->struct_mutex);
1379 if (ret)
1380 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001381 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001382
1383 rgvmodectl = I915_READ(MEMMODECTL);
1384 rstdbyctl = I915_READ(RSTDBYCTL);
1385 crstandvid = I915_READ16(CRSTANDVID);
1386
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001387 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001388 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001389
1390 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1391 "yes" : "no");
1392 seq_printf(m, "Boost freq: %d\n",
1393 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1394 MEMMODE_BOOST_FREQ_SHIFT);
1395 seq_printf(m, "HW control enabled: %s\n",
1396 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1397 seq_printf(m, "SW control enabled: %s\n",
1398 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1399 seq_printf(m, "Gated voltage change: %s\n",
1400 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1401 seq_printf(m, "Starting frequency: P%d\n",
1402 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001403 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001404 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001405 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1406 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1407 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1408 seq_printf(m, "Render standby enabled: %s\n",
1409 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001410 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001411 switch (rstdbyctl & RSX_STATUS_MASK) {
1412 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001413 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001414 break;
1415 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001416 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001417 break;
1418 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001419 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001420 break;
1421 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001422 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001423 break;
1424 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001425 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001426 break;
1427 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001428 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001429 break;
1430 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001431 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001432 break;
1433 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001434
1435 return 0;
1436}
1437
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001438static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001439{
1440 struct drm_info_node *node = m->private;
1441 struct drm_device *dev = node->minor->dev;
1442 struct drm_i915_private *dev_priv = dev->dev_private;
1443 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001444 int i;
1445
1446 spin_lock_irq(&dev_priv->uncore.lock);
1447 for_each_fw_domain(fw_domain, dev_priv, i) {
1448 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001449 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001450 fw_domain->wake_count);
1451 }
1452 spin_unlock_irq(&dev_priv->uncore.lock);
1453
1454 return 0;
1455}
1456
Deepak S669ab5a2014-01-10 15:18:26 +05301457static int vlv_drpc_info(struct seq_file *m)
1458{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001459 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301460 struct drm_device *dev = node->minor->dev;
1461 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001462 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301463
Imre Deakd46c0512014-04-14 20:24:27 +03001464 intel_runtime_pm_get(dev_priv);
1465
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001466 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301467 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1468 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1469
Imre Deakd46c0512014-04-14 20:24:27 +03001470 intel_runtime_pm_put(dev_priv);
1471
Deepak S669ab5a2014-01-10 15:18:26 +05301472 seq_printf(m, "Video Turbo Mode: %s\n",
1473 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1474 seq_printf(m, "Turbo enabled: %s\n",
1475 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1476 seq_printf(m, "HW control enabled: %s\n",
1477 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1478 seq_printf(m, "SW control enabled: %s\n",
1479 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1480 GEN6_RP_MEDIA_SW_MODE));
1481 seq_printf(m, "RC6 Enabled: %s\n",
1482 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1483 GEN6_RC_CTL_EI_MODE(1))));
1484 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001485 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301486 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001487 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301488
Imre Deak9cc19be2014-04-14 20:24:24 +03001489 seq_printf(m, "Render RC6 residency since boot: %u\n",
1490 I915_READ(VLV_GT_RENDER_RC6));
1491 seq_printf(m, "Media RC6 residency since boot: %u\n",
1492 I915_READ(VLV_GT_MEDIA_RC6));
1493
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001494 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301495}
1496
Ben Widawsky4d855292011-12-12 19:34:16 -08001497static int gen6_drpc_info(struct seq_file *m)
1498{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001499 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001500 struct drm_device *dev = node->minor->dev;
1501 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001502 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001503 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001504 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001505
1506 ret = mutex_lock_interruptible(&dev->struct_mutex);
1507 if (ret)
1508 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001509 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001510
Chris Wilson907b28c2013-07-19 20:36:52 +01001511 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001512 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001513 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001514
1515 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001516 seq_puts(m, "RC information inaccurate because somebody "
1517 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001518 } else {
1519 /* NB: we cannot use forcewake, else we read the wrong values */
1520 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1521 udelay(10);
1522 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1523 }
1524
1525 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001526 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001527
1528 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1529 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1530 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001531 mutex_lock(&dev_priv->rps.hw_lock);
1532 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1533 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001534
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001535 intel_runtime_pm_put(dev_priv);
1536
Ben Widawsky4d855292011-12-12 19:34:16 -08001537 seq_printf(m, "Video Turbo Mode: %s\n",
1538 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1539 seq_printf(m, "HW control enabled: %s\n",
1540 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1541 seq_printf(m, "SW control enabled: %s\n",
1542 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1543 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001544 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001545 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1546 seq_printf(m, "RC6 Enabled: %s\n",
1547 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1548 seq_printf(m, "Deep RC6 Enabled: %s\n",
1549 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1550 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1551 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001552 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001553 switch (gt_core_status & GEN6_RCn_MASK) {
1554 case GEN6_RC0:
1555 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001556 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001557 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001558 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001559 break;
1560 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001561 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001562 break;
1563 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001564 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001565 break;
1566 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001567 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001568 break;
1569 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001570 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001571 break;
1572 }
1573
1574 seq_printf(m, "Core Power Down: %s\n",
1575 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001576
1577 /* Not exactly sure what this is */
1578 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1579 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1580 seq_printf(m, "RC6 residency since boot: %u\n",
1581 I915_READ(GEN6_GT_GFX_RC6));
1582 seq_printf(m, "RC6+ residency since boot: %u\n",
1583 I915_READ(GEN6_GT_GFX_RC6p));
1584 seq_printf(m, "RC6++ residency since boot: %u\n",
1585 I915_READ(GEN6_GT_GFX_RC6pp));
1586
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001587 seq_printf(m, "RC6 voltage: %dmV\n",
1588 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1589 seq_printf(m, "RC6+ voltage: %dmV\n",
1590 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1591 seq_printf(m, "RC6++ voltage: %dmV\n",
1592 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001593 return 0;
1594}
1595
1596static int i915_drpc_info(struct seq_file *m, void *unused)
1597{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001598 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001599 struct drm_device *dev = node->minor->dev;
1600
Deepak S669ab5a2014-01-10 15:18:26 +05301601 if (IS_VALLEYVIEW(dev))
1602 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001603 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001604 return gen6_drpc_info(m);
1605 else
1606 return ironlake_drpc_info(m);
1607}
1608
Daniel Vetter9a851782015-06-18 10:30:22 +02001609static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1610{
1611 struct drm_info_node *node = m->private;
1612 struct drm_device *dev = node->minor->dev;
1613 struct drm_i915_private *dev_priv = dev->dev_private;
1614
1615 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1616 dev_priv->fb_tracking.busy_bits);
1617
1618 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1619 dev_priv->fb_tracking.flip_bits);
1620
1621 return 0;
1622}
1623
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001624static int i915_fbc_status(struct seq_file *m, void *unused)
1625{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001626 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001627 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001628 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001629
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001630 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001631 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001632 return 0;
1633 }
1634
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001635 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001636 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001637
Paulo Zanoni7733b492015-07-07 15:26:04 -03001638 if (intel_fbc_enabled(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001639 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001640 else
1641 seq_printf(m, "FBC disabled: %s\n",
1642 intel_no_fbc_reason_str(dev_priv->fbc.no_fbc_reason));
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001643
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001644 if (INTEL_INFO(dev_priv)->gen >= 7)
1645 seq_printf(m, "Compressing: %s\n",
1646 yesno(I915_READ(FBC_STATUS2) &
1647 FBC_COMPRESSION_MASK));
1648
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001649 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001650 intel_runtime_pm_put(dev_priv);
1651
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001652 return 0;
1653}
1654
Rodrigo Vivida46f932014-08-01 02:04:45 -07001655static int i915_fbc_fc_get(void *data, u64 *val)
1656{
1657 struct drm_device *dev = data;
1658 struct drm_i915_private *dev_priv = dev->dev_private;
1659
1660 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1661 return -ENODEV;
1662
Rodrigo Vivida46f932014-08-01 02:04:45 -07001663 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001664
1665 return 0;
1666}
1667
1668static int i915_fbc_fc_set(void *data, u64 val)
1669{
1670 struct drm_device *dev = data;
1671 struct drm_i915_private *dev_priv = dev->dev_private;
1672 u32 reg;
1673
1674 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1675 return -ENODEV;
1676
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001677 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001678
1679 reg = I915_READ(ILK_DPFC_CONTROL);
1680 dev_priv->fbc.false_color = val;
1681
1682 I915_WRITE(ILK_DPFC_CONTROL, val ?
1683 (reg | FBC_CTL_FALSE_COLOR) :
1684 (reg & ~FBC_CTL_FALSE_COLOR));
1685
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001686 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001687 return 0;
1688}
1689
1690DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1691 i915_fbc_fc_get, i915_fbc_fc_set,
1692 "%llu\n");
1693
Paulo Zanoni92d44622013-05-31 16:33:24 -03001694static int i915_ips_status(struct seq_file *m, void *unused)
1695{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001696 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001697 struct drm_device *dev = node->minor->dev;
1698 struct drm_i915_private *dev_priv = dev->dev_private;
1699
Damien Lespiauf5adf942013-06-24 18:29:34 +01001700 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001701 seq_puts(m, "not supported\n");
1702 return 0;
1703 }
1704
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001705 intel_runtime_pm_get(dev_priv);
1706
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001707 seq_printf(m, "Enabled by kernel parameter: %s\n",
1708 yesno(i915.enable_ips));
1709
1710 if (INTEL_INFO(dev)->gen >= 8) {
1711 seq_puts(m, "Currently: unknown\n");
1712 } else {
1713 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1714 seq_puts(m, "Currently: enabled\n");
1715 else
1716 seq_puts(m, "Currently: disabled\n");
1717 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001718
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001719 intel_runtime_pm_put(dev_priv);
1720
Paulo Zanoni92d44622013-05-31 16:33:24 -03001721 return 0;
1722}
1723
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001724static int i915_sr_status(struct seq_file *m, void *unused)
1725{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001726 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001727 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001728 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001729 bool sr_enabled = false;
1730
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001731 intel_runtime_pm_get(dev_priv);
1732
Yuanhan Liu13982612010-12-15 15:42:31 +08001733 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001734 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001735 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1736 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001737 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1738 else if (IS_I915GM(dev))
1739 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1740 else if (IS_PINEVIEW(dev))
1741 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001742 else if (IS_VALLEYVIEW(dev))
1743 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001744
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001745 intel_runtime_pm_put(dev_priv);
1746
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001747 seq_printf(m, "self-refresh: %s\n",
1748 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001749
1750 return 0;
1751}
1752
Jesse Barnes7648fa92010-05-20 14:28:11 -07001753static int i915_emon_status(struct seq_file *m, void *unused)
1754{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001755 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001756 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001757 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001758 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001759 int ret;
1760
Chris Wilson582be6b2012-04-30 19:35:02 +01001761 if (!IS_GEN5(dev))
1762 return -ENODEV;
1763
Chris Wilsonde227ef2010-07-03 07:58:38 +01001764 ret = mutex_lock_interruptible(&dev->struct_mutex);
1765 if (ret)
1766 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001767
1768 temp = i915_mch_val(dev_priv);
1769 chipset = i915_chipset_val(dev_priv);
1770 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001771 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001772
1773 seq_printf(m, "GMCH temp: %ld\n", temp);
1774 seq_printf(m, "Chipset power: %ld\n", chipset);
1775 seq_printf(m, "GFX power: %ld\n", gfx);
1776 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1777
1778 return 0;
1779}
1780
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001781static int i915_ring_freq_table(struct seq_file *m, void *unused)
1782{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001783 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001784 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001785 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001786 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001787 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301788 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001789
Akash Goel97d33082015-06-29 14:50:23 +05301790 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001791 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001792 return 0;
1793 }
1794
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001795 intel_runtime_pm_get(dev_priv);
1796
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001797 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1798
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001799 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001800 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001801 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001802
Akash Goelf936ec32015-06-29 14:50:22 +05301803 if (IS_SKYLAKE(dev)) {
1804 /* Convert GT frequency to 50 HZ units */
1805 min_gpu_freq =
1806 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1807 max_gpu_freq =
1808 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1809 } else {
1810 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1811 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1812 }
1813
Damien Lespiau267f0c92013-06-24 22:59:48 +01001814 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001815
Akash Goelf936ec32015-06-29 14:50:22 +05301816 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001817 ia_freq = gpu_freq;
1818 sandybridge_pcode_read(dev_priv,
1819 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1820 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001821 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301822 intel_gpu_freq(dev_priv, (gpu_freq *
1823 (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001824 ((ia_freq >> 0) & 0xff) * 100,
1825 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001826 }
1827
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001828 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001829
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001830out:
1831 intel_runtime_pm_put(dev_priv);
1832 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001833}
1834
Chris Wilson44834a62010-08-19 16:09:23 +01001835static int i915_opregion(struct seq_file *m, void *unused)
1836{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001837 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001838 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001839 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001840 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001841 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001842 int ret;
1843
Daniel Vetter0d38f002012-04-21 22:49:10 +02001844 if (data == NULL)
1845 return -ENOMEM;
1846
Chris Wilson44834a62010-08-19 16:09:23 +01001847 ret = mutex_lock_interruptible(&dev->struct_mutex);
1848 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001849 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001850
Daniel Vetter0d38f002012-04-21 22:49:10 +02001851 if (opregion->header) {
1852 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1853 seq_write(m, data, OPREGION_SIZE);
1854 }
Chris Wilson44834a62010-08-19 16:09:23 +01001855
1856 mutex_unlock(&dev->struct_mutex);
1857
Daniel Vetter0d38f002012-04-21 22:49:10 +02001858out:
1859 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001860 return 0;
1861}
1862
Chris Wilson37811fc2010-08-25 22:45:57 +01001863static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1864{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001865 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001866 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001867 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001868 struct intel_framebuffer *fb;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001869 struct drm_framebuffer *drm_fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001870
Daniel Vetter4520f532013-10-09 09:18:51 +02001871#ifdef CONFIG_DRM_I915_FBDEV
1872 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001873
1874 ifbdev = dev_priv->fbdev;
1875 fb = to_intel_framebuffer(ifbdev->helper.fb);
1876
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001877 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 +01001878 fb->base.width,
1879 fb->base.height,
1880 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001881 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001882 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001883 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001884 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001885 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001886#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001887
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001888 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001889 drm_for_each_fb(drm_fb, dev) {
1890 fb = to_intel_framebuffer(drm_fb);
Daniel Vetter131a56d2013-10-17 14:35:31 +02001891 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001892 continue;
1893
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001894 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 +01001895 fb->base.width,
1896 fb->base.height,
1897 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001898 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001899 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001900 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001901 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001902 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001903 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001904 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001905
1906 return 0;
1907}
1908
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001909static void describe_ctx_ringbuf(struct seq_file *m,
1910 struct intel_ringbuffer *ringbuf)
1911{
1912 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1913 ringbuf->space, ringbuf->head, ringbuf->tail,
1914 ringbuf->last_retired_head);
1915}
1916
Ben Widawskye76d3632011-03-19 18:14:29 -07001917static int i915_context_status(struct seq_file *m, void *unused)
1918{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001919 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001920 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001921 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001922 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001923 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001924 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001925
Daniel Vetterf3d28872014-05-29 23:23:08 +02001926 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001927 if (ret)
1928 return ret;
1929
Ben Widawskya33afea2013-09-17 21:12:45 -07001930 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001931 if (!i915.enable_execlists &&
1932 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001933 continue;
1934
Ben Widawskya33afea2013-09-17 21:12:45 -07001935 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001936 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001937 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001938 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001939 seq_printf(m, "(default context %s) ",
1940 ring->name);
1941 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001942
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001943 if (i915.enable_execlists) {
1944 seq_putc(m, '\n');
1945 for_each_ring(ring, dev_priv, i) {
1946 struct drm_i915_gem_object *ctx_obj =
1947 ctx->engine[i].state;
1948 struct intel_ringbuffer *ringbuf =
1949 ctx->engine[i].ringbuf;
1950
1951 seq_printf(m, "%s: ", ring->name);
1952 if (ctx_obj)
1953 describe_obj(m, ctx_obj);
1954 if (ringbuf)
1955 describe_ctx_ringbuf(m, ringbuf);
1956 seq_putc(m, '\n');
1957 }
1958 } else {
1959 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1960 }
1961
Ben Widawskya33afea2013-09-17 21:12:45 -07001962 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001963 }
1964
Daniel Vetterf3d28872014-05-29 23:23:08 +02001965 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001966
1967 return 0;
1968}
1969
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001970static void i915_dump_lrc_obj(struct seq_file *m,
1971 struct intel_engine_cs *ring,
1972 struct drm_i915_gem_object *ctx_obj)
1973{
1974 struct page *page;
1975 uint32_t *reg_state;
1976 int j;
1977 unsigned long ggtt_offset = 0;
1978
1979 if (ctx_obj == NULL) {
1980 seq_printf(m, "Context on %s with no gem object\n",
1981 ring->name);
1982 return;
1983 }
1984
1985 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1986 intel_execlists_ctx_id(ctx_obj));
1987
1988 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1989 seq_puts(m, "\tNot bound in GGTT\n");
1990 else
1991 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1992
1993 if (i915_gem_object_get_pages(ctx_obj)) {
1994 seq_puts(m, "\tFailed to get pages for context object\n");
1995 return;
1996 }
1997
1998 page = i915_gem_object_get_page(ctx_obj, 1);
1999 if (!WARN_ON(page == NULL)) {
2000 reg_state = kmap_atomic(page);
2001
2002 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2003 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2004 ggtt_offset + 4096 + (j * 4),
2005 reg_state[j], reg_state[j + 1],
2006 reg_state[j + 2], reg_state[j + 3]);
2007 }
2008 kunmap_atomic(reg_state);
2009 }
2010
2011 seq_putc(m, '\n');
2012}
2013
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002014static int i915_dump_lrc(struct seq_file *m, void *unused)
2015{
2016 struct drm_info_node *node = (struct drm_info_node *) m->private;
2017 struct drm_device *dev = node->minor->dev;
2018 struct drm_i915_private *dev_priv = dev->dev_private;
2019 struct intel_engine_cs *ring;
2020 struct intel_context *ctx;
2021 int ret, i;
2022
2023 if (!i915.enable_execlists) {
2024 seq_printf(m, "Logical Ring Contexts are disabled\n");
2025 return 0;
2026 }
2027
2028 ret = mutex_lock_interruptible(&dev->struct_mutex);
2029 if (ret)
2030 return ret;
2031
2032 list_for_each_entry(ctx, &dev_priv->context_list, link) {
2033 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002034 if (ring->default_context != ctx)
2035 i915_dump_lrc_obj(m, ring,
2036 ctx->engine[i].state);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01002037 }
2038 }
2039
2040 mutex_unlock(&dev->struct_mutex);
2041
2042 return 0;
2043}
2044
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002045static int i915_execlists(struct seq_file *m, void *data)
2046{
2047 struct drm_info_node *node = (struct drm_info_node *)m->private;
2048 struct drm_device *dev = node->minor->dev;
2049 struct drm_i915_private *dev_priv = dev->dev_private;
2050 struct intel_engine_cs *ring;
2051 u32 status_pointer;
2052 u8 read_pointer;
2053 u8 write_pointer;
2054 u32 status;
2055 u32 ctx_id;
2056 struct list_head *cursor;
2057 int ring_id, i;
2058 int ret;
2059
2060 if (!i915.enable_execlists) {
2061 seq_puts(m, "Logical Ring Contexts are disabled\n");
2062 return 0;
2063 }
2064
2065 ret = mutex_lock_interruptible(&dev->struct_mutex);
2066 if (ret)
2067 return ret;
2068
Michel Thierryfc0412e2014-10-16 16:13:38 +01002069 intel_runtime_pm_get(dev_priv);
2070
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002071 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002072 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002073 int count = 0;
2074 unsigned long flags;
2075
2076 seq_printf(m, "%s\n", ring->name);
2077
2078 status = I915_READ(RING_EXECLIST_STATUS(ring));
2079 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
2080 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2081 status, ctx_id);
2082
2083 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2084 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2085
2086 read_pointer = ring->next_context_status_buffer;
2087 write_pointer = status_pointer & 0x07;
2088 if (read_pointer > write_pointer)
2089 write_pointer += 6;
2090 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2091 read_pointer, write_pointer);
2092
2093 for (i = 0; i < 6; i++) {
2094 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
2095 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
2096
2097 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2098 i, status, ctx_id);
2099 }
2100
2101 spin_lock_irqsave(&ring->execlist_lock, flags);
2102 list_for_each(cursor, &ring->execlist_queue)
2103 count++;
2104 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002105 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002106 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2107
2108 seq_printf(m, "\t%d requests in queue\n", count);
2109 if (head_req) {
2110 struct drm_i915_gem_object *ctx_obj;
2111
Nick Hoath6d3d8272015-01-15 13:10:39 +00002112 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002113 seq_printf(m, "\tHead request id: %u\n",
2114 intel_execlists_ctx_id(ctx_obj));
2115 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002116 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002117 }
2118
2119 seq_putc(m, '\n');
2120 }
2121
Michel Thierryfc0412e2014-10-16 16:13:38 +01002122 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002123 mutex_unlock(&dev->struct_mutex);
2124
2125 return 0;
2126}
2127
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002128static const char *swizzle_string(unsigned swizzle)
2129{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002130 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002131 case I915_BIT_6_SWIZZLE_NONE:
2132 return "none";
2133 case I915_BIT_6_SWIZZLE_9:
2134 return "bit9";
2135 case I915_BIT_6_SWIZZLE_9_10:
2136 return "bit9/bit10";
2137 case I915_BIT_6_SWIZZLE_9_11:
2138 return "bit9/bit11";
2139 case I915_BIT_6_SWIZZLE_9_10_11:
2140 return "bit9/bit10/bit11";
2141 case I915_BIT_6_SWIZZLE_9_17:
2142 return "bit9/bit17";
2143 case I915_BIT_6_SWIZZLE_9_10_17:
2144 return "bit9/bit10/bit17";
2145 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002146 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002147 }
2148
2149 return "bug";
2150}
2151
2152static int i915_swizzle_info(struct seq_file *m, void *data)
2153{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002154 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002155 struct drm_device *dev = node->minor->dev;
2156 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002157 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002158
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002159 ret = mutex_lock_interruptible(&dev->struct_mutex);
2160 if (ret)
2161 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002162 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002163
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002164 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2165 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2166 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2167 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2168
2169 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2170 seq_printf(m, "DDC = 0x%08x\n",
2171 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002172 seq_printf(m, "DDC2 = 0x%08x\n",
2173 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002174 seq_printf(m, "C0DRB3 = 0x%04x\n",
2175 I915_READ16(C0DRB3));
2176 seq_printf(m, "C1DRB3 = 0x%04x\n",
2177 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002178 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002179 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2180 I915_READ(MAD_DIMM_C0));
2181 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2182 I915_READ(MAD_DIMM_C1));
2183 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2184 I915_READ(MAD_DIMM_C2));
2185 seq_printf(m, "TILECTL = 0x%08x\n",
2186 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002187 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002188 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2189 I915_READ(GAMTARBMODE));
2190 else
2191 seq_printf(m, "ARB_MODE = 0x%08x\n",
2192 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002193 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2194 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002195 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002196
2197 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2198 seq_puts(m, "L-shaped memory detected\n");
2199
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002200 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002201 mutex_unlock(&dev->struct_mutex);
2202
2203 return 0;
2204}
2205
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002206static int per_file_ctx(int id, void *ptr, void *data)
2207{
Oscar Mateo273497e2014-05-22 14:13:37 +01002208 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002209 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002210 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2211
2212 if (!ppgtt) {
2213 seq_printf(m, " no ppgtt for context %d\n",
2214 ctx->user_handle);
2215 return 0;
2216 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002217
Oscar Mateof83d6512014-05-22 14:13:38 +01002218 if (i915_gem_context_is_default(ctx))
2219 seq_puts(m, " default context:\n");
2220 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002221 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002222 ppgtt->debug_dump(ppgtt, m);
2223
2224 return 0;
2225}
2226
Ben Widawsky77df6772013-11-02 21:07:30 -07002227static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002228{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002229 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002230 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002231 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2232 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002233
Ben Widawsky77df6772013-11-02 21:07:30 -07002234 if (!ppgtt)
2235 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002236
Ben Widawsky77df6772013-11-02 21:07:30 -07002237 for_each_ring(ring, dev_priv, unused) {
2238 seq_printf(m, "%s\n", ring->name);
2239 for (i = 0; i < 4; i++) {
2240 u32 offset = 0x270 + i * 8;
2241 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2242 pdp <<= 32;
2243 pdp |= I915_READ(ring->mmio_base + offset);
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;
2297
2298 seq_printf(m, "\nproc: %s\n",
2299 get_pid_task(file->pid, PIDTYPE_PID)->comm);
2300 idr_for_each(&file_priv->context_idr, per_file_ctx,
2301 (void *)(unsigned long)m);
2302 }
2303
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002304 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002305 mutex_unlock(&dev->struct_mutex);
2306
2307 return 0;
2308}
2309
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002310static int count_irq_waiters(struct drm_i915_private *i915)
2311{
2312 struct intel_engine_cs *ring;
2313 int count = 0;
2314 int i;
2315
2316 for_each_ring(ring, i915, i)
2317 count += ring->irq_refcount;
2318
2319 return count;
2320}
2321
Chris Wilson1854d5c2015-04-07 16:20:32 +01002322static int i915_rps_boost_info(struct seq_file *m, void *data)
2323{
2324 struct drm_info_node *node = m->private;
2325 struct drm_device *dev = node->minor->dev;
2326 struct drm_i915_private *dev_priv = dev->dev_private;
2327 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002328
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002329 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2330 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2331 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2332 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2333 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2334 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2335 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2336 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2337 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson8d3afd72015-05-21 21:01:47 +01002338 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002339 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2340 struct drm_i915_file_private *file_priv = file->driver_priv;
2341 struct task_struct *task;
2342
2343 rcu_read_lock();
2344 task = pid_task(file->pid, PIDTYPE_PID);
2345 seq_printf(m, "%s [%d]: %d boosts%s\n",
2346 task ? task->comm : "<unknown>",
2347 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002348 file_priv->rps.boosts,
2349 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002350 rcu_read_unlock();
2351 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002352 seq_printf(m, "Semaphore boosts: %d%s\n",
2353 dev_priv->rps.semaphores.boosts,
2354 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2355 seq_printf(m, "MMIO flip boosts: %d%s\n",
2356 dev_priv->rps.mmioflips.boosts,
2357 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002358 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002359 spin_unlock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002360
Chris Wilson8d3afd72015-05-21 21:01:47 +01002361 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002362}
2363
Ben Widawsky63573eb2013-07-04 11:02:07 -07002364static int i915_llc(struct seq_file *m, void *data)
2365{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002366 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002367 struct drm_device *dev = node->minor->dev;
2368 struct drm_i915_private *dev_priv = dev->dev_private;
2369
2370 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2371 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2372 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2373
2374 return 0;
2375}
2376
Alex Daifdf5d352015-08-12 15:43:37 +01002377static int i915_guc_load_status_info(struct seq_file *m, void *data)
2378{
2379 struct drm_info_node *node = m->private;
2380 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2381 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2382 u32 tmp, i;
2383
2384 if (!HAS_GUC_UCODE(dev_priv->dev))
2385 return 0;
2386
2387 seq_printf(m, "GuC firmware status:\n");
2388 seq_printf(m, "\tpath: %s\n",
2389 guc_fw->guc_fw_path);
2390 seq_printf(m, "\tfetch: %s\n",
2391 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2392 seq_printf(m, "\tload: %s\n",
2393 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2394 seq_printf(m, "\tversion wanted: %d.%d\n",
2395 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2396 seq_printf(m, "\tversion found: %d.%d\n",
2397 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
2398
2399 tmp = I915_READ(GUC_STATUS);
2400
2401 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2402 seq_printf(m, "\tBootrom status = 0x%x\n",
2403 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2404 seq_printf(m, "\tuKernel status = 0x%x\n",
2405 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2406 seq_printf(m, "\tMIA Core status = 0x%x\n",
2407 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2408 seq_puts(m, "\nScratch registers:\n");
2409 for (i = 0; i < 16; i++)
2410 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2411
2412 return 0;
2413}
2414
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002415static int i915_edp_psr_status(struct seq_file *m, void *data)
2416{
2417 struct drm_info_node *node = m->private;
2418 struct drm_device *dev = node->minor->dev;
2419 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002420 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002421 u32 stat[3];
2422 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002423 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002424
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002425 if (!HAS_PSR(dev)) {
2426 seq_puts(m, "PSR not supported\n");
2427 return 0;
2428 }
2429
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002430 intel_runtime_pm_get(dev_priv);
2431
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002432 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002433 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2434 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002435 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002436 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002437 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2438 dev_priv->psr.busy_frontbuffer_bits);
2439 seq_printf(m, "Re-enable work scheduled: %s\n",
2440 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002441
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002442 if (HAS_DDI(dev))
2443 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2444 else {
2445 for_each_pipe(dev_priv, pipe) {
2446 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2447 VLV_EDP_PSR_CURR_STATE_MASK;
2448 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2449 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2450 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002451 }
2452 }
2453 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002454
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002455 if (!HAS_DDI(dev))
2456 for_each_pipe(dev_priv, pipe) {
2457 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2458 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2459 seq_printf(m, " pipe %c", pipe_name(pipe));
2460 }
2461 seq_puts(m, "\n");
2462
2463 /* CHV PSR has no kind of performance counter */
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002464 if (HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002465 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2466 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002467
2468 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2469 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002470 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002471
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002472 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002473 return 0;
2474}
2475
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002476static int i915_sink_crc(struct seq_file *m, void *data)
2477{
2478 struct drm_info_node *node = m->private;
2479 struct drm_device *dev = node->minor->dev;
2480 struct intel_encoder *encoder;
2481 struct intel_connector *connector;
2482 struct intel_dp *intel_dp = NULL;
2483 int ret;
2484 u8 crc[6];
2485
2486 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002487 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002488
2489 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2490 continue;
2491
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002492 if (!connector->base.encoder)
2493 continue;
2494
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002495 encoder = to_intel_encoder(connector->base.encoder);
2496 if (encoder->type != INTEL_OUTPUT_EDP)
2497 continue;
2498
2499 intel_dp = enc_to_intel_dp(&encoder->base);
2500
2501 ret = intel_dp_sink_crc(intel_dp, crc);
2502 if (ret)
2503 goto out;
2504
2505 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2506 crc[0], crc[1], crc[2],
2507 crc[3], crc[4], crc[5]);
2508 goto out;
2509 }
2510 ret = -ENODEV;
2511out:
2512 drm_modeset_unlock_all(dev);
2513 return ret;
2514}
2515
Jesse Barnesec013e72013-08-20 10:29:23 +01002516static int i915_energy_uJ(struct seq_file *m, void *data)
2517{
2518 struct drm_info_node *node = m->private;
2519 struct drm_device *dev = node->minor->dev;
2520 struct drm_i915_private *dev_priv = dev->dev_private;
2521 u64 power;
2522 u32 units;
2523
2524 if (INTEL_INFO(dev)->gen < 6)
2525 return -ENODEV;
2526
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002527 intel_runtime_pm_get(dev_priv);
2528
Jesse Barnesec013e72013-08-20 10:29:23 +01002529 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2530 power = (power & 0x1f00) >> 8;
2531 units = 1000000 / (1 << power); /* convert to uJ */
2532 power = I915_READ(MCH_SECP_NRG_STTS);
2533 power *= units;
2534
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002535 intel_runtime_pm_put(dev_priv);
2536
Jesse Barnesec013e72013-08-20 10:29:23 +01002537 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002538
2539 return 0;
2540}
2541
Damien Lespiau6455c872015-06-04 18:23:57 +01002542static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002543{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002544 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002545 struct drm_device *dev = node->minor->dev;
2546 struct drm_i915_private *dev_priv = dev->dev_private;
2547
Damien Lespiau6455c872015-06-04 18:23:57 +01002548 if (!HAS_RUNTIME_PM(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002549 seq_puts(m, "not supported\n");
2550 return 0;
2551 }
2552
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002553 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002554 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002555 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002556#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002557 seq_printf(m, "Usage count: %d\n",
2558 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002559#else
2560 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2561#endif
Paulo Zanoni371db662013-08-19 13:18:10 -03002562
Jesse Barnesec013e72013-08-20 10:29:23 +01002563 return 0;
2564}
2565
Imre Deak1da51582013-11-25 17:15:35 +02002566static const char *power_domain_str(enum intel_display_power_domain domain)
2567{
2568 switch (domain) {
2569 case POWER_DOMAIN_PIPE_A:
2570 return "PIPE_A";
2571 case POWER_DOMAIN_PIPE_B:
2572 return "PIPE_B";
2573 case POWER_DOMAIN_PIPE_C:
2574 return "PIPE_C";
2575 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2576 return "PIPE_A_PANEL_FITTER";
2577 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2578 return "PIPE_B_PANEL_FITTER";
2579 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2580 return "PIPE_C_PANEL_FITTER";
2581 case POWER_DOMAIN_TRANSCODER_A:
2582 return "TRANSCODER_A";
2583 case POWER_DOMAIN_TRANSCODER_B:
2584 return "TRANSCODER_B";
2585 case POWER_DOMAIN_TRANSCODER_C:
2586 return "TRANSCODER_C";
2587 case POWER_DOMAIN_TRANSCODER_EDP:
2588 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002589 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2590 return "PORT_DDI_A_2_LANES";
2591 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2592 return "PORT_DDI_A_4_LANES";
2593 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2594 return "PORT_DDI_B_2_LANES";
2595 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2596 return "PORT_DDI_B_4_LANES";
2597 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2598 return "PORT_DDI_C_2_LANES";
2599 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2600 return "PORT_DDI_C_4_LANES";
2601 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2602 return "PORT_DDI_D_2_LANES";
2603 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2604 return "PORT_DDI_D_4_LANES";
2605 case POWER_DOMAIN_PORT_DSI:
2606 return "PORT_DSI";
2607 case POWER_DOMAIN_PORT_CRT:
2608 return "PORT_CRT";
2609 case POWER_DOMAIN_PORT_OTHER:
2610 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002611 case POWER_DOMAIN_VGA:
2612 return "VGA";
2613 case POWER_DOMAIN_AUDIO:
2614 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002615 case POWER_DOMAIN_PLLS:
2616 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002617 case POWER_DOMAIN_AUX_A:
2618 return "AUX_A";
2619 case POWER_DOMAIN_AUX_B:
2620 return "AUX_B";
2621 case POWER_DOMAIN_AUX_C:
2622 return "AUX_C";
2623 case POWER_DOMAIN_AUX_D:
2624 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002625 case POWER_DOMAIN_INIT:
2626 return "INIT";
2627 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002628 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002629 return "?";
2630 }
2631}
2632
2633static int i915_power_domain_info(struct seq_file *m, void *unused)
2634{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002635 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002636 struct drm_device *dev = node->minor->dev;
2637 struct drm_i915_private *dev_priv = dev->dev_private;
2638 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2639 int i;
2640
2641 mutex_lock(&power_domains->lock);
2642
2643 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2644 for (i = 0; i < power_domains->power_well_count; i++) {
2645 struct i915_power_well *power_well;
2646 enum intel_display_power_domain power_domain;
2647
2648 power_well = &power_domains->power_wells[i];
2649 seq_printf(m, "%-25s %d\n", power_well->name,
2650 power_well->count);
2651
2652 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2653 power_domain++) {
2654 if (!(BIT(power_domain) & power_well->domains))
2655 continue;
2656
2657 seq_printf(m, " %-23s %d\n",
2658 power_domain_str(power_domain),
2659 power_domains->domain_use_count[power_domain]);
2660 }
2661 }
2662
2663 mutex_unlock(&power_domains->lock);
2664
2665 return 0;
2666}
2667
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002668static void intel_seq_print_mode(struct seq_file *m, int tabs,
2669 struct drm_display_mode *mode)
2670{
2671 int i;
2672
2673 for (i = 0; i < tabs; i++)
2674 seq_putc(m, '\t');
2675
2676 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",
2677 mode->base.id, mode->name,
2678 mode->vrefresh, mode->clock,
2679 mode->hdisplay, mode->hsync_start,
2680 mode->hsync_end, mode->htotal,
2681 mode->vdisplay, mode->vsync_start,
2682 mode->vsync_end, mode->vtotal,
2683 mode->type, mode->flags);
2684}
2685
2686static void intel_encoder_info(struct seq_file *m,
2687 struct intel_crtc *intel_crtc,
2688 struct intel_encoder *intel_encoder)
2689{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002690 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002691 struct drm_device *dev = node->minor->dev;
2692 struct drm_crtc *crtc = &intel_crtc->base;
2693 struct intel_connector *intel_connector;
2694 struct drm_encoder *encoder;
2695
2696 encoder = &intel_encoder->base;
2697 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002698 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002699 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2700 struct drm_connector *connector = &intel_connector->base;
2701 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2702 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002703 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002704 drm_get_connector_status_name(connector->status));
2705 if (connector->status == connector_status_connected) {
2706 struct drm_display_mode *mode = &crtc->mode;
2707 seq_printf(m, ", mode:\n");
2708 intel_seq_print_mode(m, 2, mode);
2709 } else {
2710 seq_putc(m, '\n');
2711 }
2712 }
2713}
2714
2715static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2716{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002717 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002718 struct drm_device *dev = node->minor->dev;
2719 struct drm_crtc *crtc = &intel_crtc->base;
2720 struct intel_encoder *intel_encoder;
2721
Matt Roper5aa8a932014-06-16 10:12:55 -07002722 if (crtc->primary->fb)
2723 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2724 crtc->primary->fb->base.id, crtc->x, crtc->y,
2725 crtc->primary->fb->width, crtc->primary->fb->height);
2726 else
2727 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002728 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2729 intel_encoder_info(m, intel_crtc, intel_encoder);
2730}
2731
2732static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2733{
2734 struct drm_display_mode *mode = panel->fixed_mode;
2735
2736 seq_printf(m, "\tfixed mode:\n");
2737 intel_seq_print_mode(m, 2, mode);
2738}
2739
2740static void intel_dp_info(struct seq_file *m,
2741 struct intel_connector *intel_connector)
2742{
2743 struct intel_encoder *intel_encoder = intel_connector->encoder;
2744 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2745
2746 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2747 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2748 "no");
2749 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2750 intel_panel_info(m, &intel_connector->panel);
2751}
2752
2753static void intel_hdmi_info(struct seq_file *m,
2754 struct intel_connector *intel_connector)
2755{
2756 struct intel_encoder *intel_encoder = intel_connector->encoder;
2757 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2758
2759 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2760 "no");
2761}
2762
2763static void intel_lvds_info(struct seq_file *m,
2764 struct intel_connector *intel_connector)
2765{
2766 intel_panel_info(m, &intel_connector->panel);
2767}
2768
2769static void intel_connector_info(struct seq_file *m,
2770 struct drm_connector *connector)
2771{
2772 struct intel_connector *intel_connector = to_intel_connector(connector);
2773 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002774 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002775
2776 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002777 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002778 drm_get_connector_status_name(connector->status));
2779 if (connector->status == connector_status_connected) {
2780 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2781 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2782 connector->display_info.width_mm,
2783 connector->display_info.height_mm);
2784 seq_printf(m, "\tsubpixel order: %s\n",
2785 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2786 seq_printf(m, "\tCEA rev: %d\n",
2787 connector->display_info.cea_rev);
2788 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002789 if (intel_encoder) {
2790 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2791 intel_encoder->type == INTEL_OUTPUT_EDP)
2792 intel_dp_info(m, intel_connector);
2793 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2794 intel_hdmi_info(m, intel_connector);
2795 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2796 intel_lvds_info(m, intel_connector);
2797 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002798
Jesse Barnesf103fc72014-02-20 12:39:57 -08002799 seq_printf(m, "\tmodes:\n");
2800 list_for_each_entry(mode, &connector->modes, head)
2801 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002802}
2803
Chris Wilson065f2ec2014-03-12 09:13:13 +00002804static bool cursor_active(struct drm_device *dev, int pipe)
2805{
2806 struct drm_i915_private *dev_priv = dev->dev_private;
2807 u32 state;
2808
2809 if (IS_845G(dev) || IS_I865G(dev))
2810 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002811 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002812 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002813
2814 return state;
2815}
2816
2817static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2818{
2819 struct drm_i915_private *dev_priv = dev->dev_private;
2820 u32 pos;
2821
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002822 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002823
2824 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2825 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2826 *x = -*x;
2827
2828 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2829 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2830 *y = -*y;
2831
2832 return cursor_active(dev, pipe);
2833}
2834
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002835static int i915_display_info(struct seq_file *m, void *unused)
2836{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002837 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002838 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002839 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002840 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002841 struct drm_connector *connector;
2842
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002843 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002844 drm_modeset_lock_all(dev);
2845 seq_printf(m, "CRTC info\n");
2846 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002847 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002848 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002849 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002850 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002851
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002852 pipe_config = to_intel_crtc_state(crtc->base.state);
2853
Chris Wilson57127ef2014-07-04 08:20:11 +01002854 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002855 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002856 yesno(pipe_config->base.active),
2857 pipe_config->pipe_src_w, pipe_config->pipe_src_h);
2858 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002859 intel_crtc_info(m, crtc);
2860
Paulo Zanonia23dc652014-04-01 14:55:11 -03002861 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002862 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 +03002863 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08002864 x, y, crtc->base.cursor->state->crtc_w,
2865 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01002866 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002867 }
Daniel Vettercace8412014-05-22 17:56:31 +02002868
2869 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2870 yesno(!crtc->cpu_fifo_underrun_disabled),
2871 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002872 }
2873
2874 seq_printf(m, "\n");
2875 seq_printf(m, "Connector info\n");
2876 seq_printf(m, "--------------\n");
2877 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2878 intel_connector_info(m, connector);
2879 }
2880 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002881 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002882
2883 return 0;
2884}
2885
Ben Widawskye04934c2014-06-30 09:53:42 -07002886static int i915_semaphore_status(struct seq_file *m, void *unused)
2887{
2888 struct drm_info_node *node = (struct drm_info_node *) m->private;
2889 struct drm_device *dev = node->minor->dev;
2890 struct drm_i915_private *dev_priv = dev->dev_private;
2891 struct intel_engine_cs *ring;
2892 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2893 int i, j, ret;
2894
2895 if (!i915_semaphore_is_enabled(dev)) {
2896 seq_puts(m, "Semaphores are disabled\n");
2897 return 0;
2898 }
2899
2900 ret = mutex_lock_interruptible(&dev->struct_mutex);
2901 if (ret)
2902 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002903 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002904
2905 if (IS_BROADWELL(dev)) {
2906 struct page *page;
2907 uint64_t *seqno;
2908
2909 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2910
2911 seqno = (uint64_t *)kmap_atomic(page);
2912 for_each_ring(ring, dev_priv, i) {
2913 uint64_t offset;
2914
2915 seq_printf(m, "%s\n", ring->name);
2916
2917 seq_puts(m, " Last signal:");
2918 for (j = 0; j < num_rings; j++) {
2919 offset = i * I915_NUM_RINGS + j;
2920 seq_printf(m, "0x%08llx (0x%02llx) ",
2921 seqno[offset], offset * 8);
2922 }
2923 seq_putc(m, '\n');
2924
2925 seq_puts(m, " Last wait: ");
2926 for (j = 0; j < num_rings; j++) {
2927 offset = i + (j * I915_NUM_RINGS);
2928 seq_printf(m, "0x%08llx (0x%02llx) ",
2929 seqno[offset], offset * 8);
2930 }
2931 seq_putc(m, '\n');
2932
2933 }
2934 kunmap_atomic(seqno);
2935 } else {
2936 seq_puts(m, " Last signal:");
2937 for_each_ring(ring, dev_priv, i)
2938 for (j = 0; j < num_rings; j++)
2939 seq_printf(m, "0x%08x\n",
2940 I915_READ(ring->semaphore.mbox.signal[j]));
2941 seq_putc(m, '\n');
2942 }
2943
2944 seq_puts(m, "\nSync seqno:\n");
2945 for_each_ring(ring, dev_priv, i) {
2946 for (j = 0; j < num_rings; j++) {
2947 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2948 }
2949 seq_putc(m, '\n');
2950 }
2951 seq_putc(m, '\n');
2952
Paulo Zanoni03872062014-07-09 14:31:57 -03002953 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002954 mutex_unlock(&dev->struct_mutex);
2955 return 0;
2956}
2957
Daniel Vetter728e29d2014-06-25 22:01:53 +03002958static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2959{
2960 struct drm_info_node *node = (struct drm_info_node *) m->private;
2961 struct drm_device *dev = node->minor->dev;
2962 struct drm_i915_private *dev_priv = dev->dev_private;
2963 int i;
2964
2965 drm_modeset_lock_all(dev);
2966 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2967 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2968
2969 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002970 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002971 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03002972 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002973 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2974 seq_printf(m, " dpll_md: 0x%08x\n",
2975 pll->config.hw_state.dpll_md);
2976 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2977 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2978 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002979 }
2980 drm_modeset_unlock_all(dev);
2981
2982 return 0;
2983}
2984
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01002985static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01002986{
2987 int i;
2988 int ret;
2989 struct drm_info_node *node = (struct drm_info_node *) m->private;
2990 struct drm_device *dev = node->minor->dev;
2991 struct drm_i915_private *dev_priv = dev->dev_private;
2992
Arun Siluvery888b5992014-08-26 14:44:51 +01002993 ret = mutex_lock_interruptible(&dev->struct_mutex);
2994 if (ret)
2995 return ret;
2996
2997 intel_runtime_pm_get(dev_priv);
2998
Mika Kuoppala72253422014-10-07 17:21:26 +03002999 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
3000 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003001 u32 addr, mask, value, read;
3002 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003003
Mika Kuoppala72253422014-10-07 17:21:26 +03003004 addr = dev_priv->workarounds.reg[i].addr;
3005 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003006 value = dev_priv->workarounds.reg[i].value;
3007 read = I915_READ(addr);
3008 ok = (value & mask) == (read & mask);
3009 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
3010 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003011 }
3012
3013 intel_runtime_pm_put(dev_priv);
3014 mutex_unlock(&dev->struct_mutex);
3015
3016 return 0;
3017}
3018
Damien Lespiauc5511e42014-11-04 17:06:51 +00003019static int i915_ddb_info(struct seq_file *m, void *unused)
3020{
3021 struct drm_info_node *node = m->private;
3022 struct drm_device *dev = node->minor->dev;
3023 struct drm_i915_private *dev_priv = dev->dev_private;
3024 struct skl_ddb_allocation *ddb;
3025 struct skl_ddb_entry *entry;
3026 enum pipe pipe;
3027 int plane;
3028
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003029 if (INTEL_INFO(dev)->gen < 9)
3030 return 0;
3031
Damien Lespiauc5511e42014-11-04 17:06:51 +00003032 drm_modeset_lock_all(dev);
3033
3034 ddb = &dev_priv->wm.skl_hw.ddb;
3035
3036 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3037
3038 for_each_pipe(dev_priv, pipe) {
3039 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3040
Damien Lespiaudd740782015-02-28 14:54:08 +00003041 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003042 entry = &ddb->plane[pipe][plane];
3043 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3044 entry->start, entry->end,
3045 skl_ddb_entry_size(entry));
3046 }
3047
3048 entry = &ddb->cursor[pipe];
3049 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3050 entry->end, skl_ddb_entry_size(entry));
3051 }
3052
3053 drm_modeset_unlock_all(dev);
3054
3055 return 0;
3056}
3057
Vandana Kannana54746e2015-03-03 20:53:10 +05303058static void drrs_status_per_crtc(struct seq_file *m,
3059 struct drm_device *dev, struct intel_crtc *intel_crtc)
3060{
3061 struct intel_encoder *intel_encoder;
3062 struct drm_i915_private *dev_priv = dev->dev_private;
3063 struct i915_drrs *drrs = &dev_priv->drrs;
3064 int vrefresh = 0;
3065
3066 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3067 /* Encoder connected on this CRTC */
3068 switch (intel_encoder->type) {
3069 case INTEL_OUTPUT_EDP:
3070 seq_puts(m, "eDP:\n");
3071 break;
3072 case INTEL_OUTPUT_DSI:
3073 seq_puts(m, "DSI:\n");
3074 break;
3075 case INTEL_OUTPUT_HDMI:
3076 seq_puts(m, "HDMI:\n");
3077 break;
3078 case INTEL_OUTPUT_DISPLAYPORT:
3079 seq_puts(m, "DP:\n");
3080 break;
3081 default:
3082 seq_printf(m, "Other encoder (id=%d).\n",
3083 intel_encoder->type);
3084 return;
3085 }
3086 }
3087
3088 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3089 seq_puts(m, "\tVBT: DRRS_type: Static");
3090 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3091 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3092 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3093 seq_puts(m, "\tVBT: DRRS_type: None");
3094 else
3095 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3096
3097 seq_puts(m, "\n\n");
3098
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003099 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303100 struct intel_panel *panel;
3101
3102 mutex_lock(&drrs->mutex);
3103 /* DRRS Supported */
3104 seq_puts(m, "\tDRRS Supported: Yes\n");
3105
3106 /* disable_drrs() will make drrs->dp NULL */
3107 if (!drrs->dp) {
3108 seq_puts(m, "Idleness DRRS: Disabled");
3109 mutex_unlock(&drrs->mutex);
3110 return;
3111 }
3112
3113 panel = &drrs->dp->attached_connector->panel;
3114 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3115 drrs->busy_frontbuffer_bits);
3116
3117 seq_puts(m, "\n\t\t");
3118 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3119 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3120 vrefresh = panel->fixed_mode->vrefresh;
3121 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3122 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3123 vrefresh = panel->downclock_mode->vrefresh;
3124 } else {
3125 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3126 drrs->refresh_rate_type);
3127 mutex_unlock(&drrs->mutex);
3128 return;
3129 }
3130 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3131
3132 seq_puts(m, "\n\t\t");
3133 mutex_unlock(&drrs->mutex);
3134 } else {
3135 /* DRRS not supported. Print the VBT parameter*/
3136 seq_puts(m, "\tDRRS Supported : No");
3137 }
3138 seq_puts(m, "\n");
3139}
3140
3141static int i915_drrs_status(struct seq_file *m, void *unused)
3142{
3143 struct drm_info_node *node = m->private;
3144 struct drm_device *dev = node->minor->dev;
3145 struct intel_crtc *intel_crtc;
3146 int active_crtc_cnt = 0;
3147
3148 for_each_intel_crtc(dev, intel_crtc) {
3149 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3150
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003151 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303152 active_crtc_cnt++;
3153 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3154
3155 drrs_status_per_crtc(m, dev, intel_crtc);
3156 }
3157
3158 drm_modeset_unlock(&intel_crtc->base.mutex);
3159 }
3160
3161 if (!active_crtc_cnt)
3162 seq_puts(m, "No active crtc found\n");
3163
3164 return 0;
3165}
3166
Damien Lespiau07144422013-10-15 18:55:40 +01003167struct pipe_crc_info {
3168 const char *name;
3169 struct drm_device *dev;
3170 enum pipe pipe;
3171};
3172
Dave Airlie11bed952014-05-12 15:22:27 +10003173static int i915_dp_mst_info(struct seq_file *m, void *unused)
3174{
3175 struct drm_info_node *node = (struct drm_info_node *) m->private;
3176 struct drm_device *dev = node->minor->dev;
3177 struct drm_encoder *encoder;
3178 struct intel_encoder *intel_encoder;
3179 struct intel_digital_port *intel_dig_port;
3180 drm_modeset_lock_all(dev);
3181 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3182 intel_encoder = to_intel_encoder(encoder);
3183 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3184 continue;
3185 intel_dig_port = enc_to_dig_port(encoder);
3186 if (!intel_dig_port->dp.can_mst)
3187 continue;
3188
3189 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3190 }
3191 drm_modeset_unlock_all(dev);
3192 return 0;
3193}
3194
Damien Lespiau07144422013-10-15 18:55:40 +01003195static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003196{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003197 struct pipe_crc_info *info = inode->i_private;
3198 struct drm_i915_private *dev_priv = info->dev->dev_private;
3199 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3200
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003201 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3202 return -ENODEV;
3203
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003204 spin_lock_irq(&pipe_crc->lock);
3205
3206 if (pipe_crc->opened) {
3207 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003208 return -EBUSY; /* already open */
3209 }
3210
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003211 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003212 filep->private_data = inode->i_private;
3213
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003214 spin_unlock_irq(&pipe_crc->lock);
3215
Damien Lespiau07144422013-10-15 18:55:40 +01003216 return 0;
3217}
3218
3219static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3220{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003221 struct pipe_crc_info *info = inode->i_private;
3222 struct drm_i915_private *dev_priv = info->dev->dev_private;
3223 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3224
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003225 spin_lock_irq(&pipe_crc->lock);
3226 pipe_crc->opened = false;
3227 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003228
Damien Lespiau07144422013-10-15 18:55:40 +01003229 return 0;
3230}
3231
3232/* (6 fields, 8 chars each, space separated (5) + '\n') */
3233#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3234/* account for \'0' */
3235#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3236
3237static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3238{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003239 assert_spin_locked(&pipe_crc->lock);
3240 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3241 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003242}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003243
Damien Lespiau07144422013-10-15 18:55:40 +01003244static ssize_t
3245i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3246 loff_t *pos)
3247{
3248 struct pipe_crc_info *info = filep->private_data;
3249 struct drm_device *dev = info->dev;
3250 struct drm_i915_private *dev_priv = dev->dev_private;
3251 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3252 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003253 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003254 ssize_t bytes_read;
3255
3256 /*
3257 * Don't allow user space to provide buffers not big enough to hold
3258 * a line of data.
3259 */
3260 if (count < PIPE_CRC_LINE_LEN)
3261 return -EINVAL;
3262
3263 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3264 return 0;
3265
3266 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003267 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003268 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003269 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003270
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003271 if (filep->f_flags & O_NONBLOCK) {
3272 spin_unlock_irq(&pipe_crc->lock);
3273 return -EAGAIN;
3274 }
3275
3276 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3277 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3278 if (ret) {
3279 spin_unlock_irq(&pipe_crc->lock);
3280 return ret;
3281 }
Damien Lespiau07144422013-10-15 18:55:40 +01003282 }
3283
3284 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003285 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003286
Damien Lespiau07144422013-10-15 18:55:40 +01003287 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003288 while (n_entries > 0) {
3289 struct intel_pipe_crc_entry *entry =
3290 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003291 int ret;
3292
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003293 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3294 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3295 break;
3296
3297 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3298 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3299
Damien Lespiau07144422013-10-15 18:55:40 +01003300 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3301 "%8u %8x %8x %8x %8x %8x\n",
3302 entry->frame, entry->crc[0],
3303 entry->crc[1], entry->crc[2],
3304 entry->crc[3], entry->crc[4]);
3305
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003306 spin_unlock_irq(&pipe_crc->lock);
3307
3308 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003309 if (ret == PIPE_CRC_LINE_LEN)
3310 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003311
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003312 user_buf += PIPE_CRC_LINE_LEN;
3313 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003314
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003315 spin_lock_irq(&pipe_crc->lock);
3316 }
3317
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003318 spin_unlock_irq(&pipe_crc->lock);
3319
Damien Lespiau07144422013-10-15 18:55:40 +01003320 return bytes_read;
3321}
3322
3323static const struct file_operations i915_pipe_crc_fops = {
3324 .owner = THIS_MODULE,
3325 .open = i915_pipe_crc_open,
3326 .read = i915_pipe_crc_read,
3327 .release = i915_pipe_crc_release,
3328};
3329
3330static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3331 {
3332 .name = "i915_pipe_A_crc",
3333 .pipe = PIPE_A,
3334 },
3335 {
3336 .name = "i915_pipe_B_crc",
3337 .pipe = PIPE_B,
3338 },
3339 {
3340 .name = "i915_pipe_C_crc",
3341 .pipe = PIPE_C,
3342 },
3343};
3344
3345static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3346 enum pipe pipe)
3347{
3348 struct drm_device *dev = minor->dev;
3349 struct dentry *ent;
3350 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3351
3352 info->dev = dev;
3353 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3354 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003355 if (!ent)
3356 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003357
3358 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003359}
3360
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003361static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003362 "none",
3363 "plane1",
3364 "plane2",
3365 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003366 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003367 "TV",
3368 "DP-B",
3369 "DP-C",
3370 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003371 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003372};
3373
3374static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3375{
3376 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3377 return pipe_crc_sources[source];
3378}
3379
Damien Lespiaubd9db022013-10-15 18:55:36 +01003380static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003381{
3382 struct drm_device *dev = m->private;
3383 struct drm_i915_private *dev_priv = dev->dev_private;
3384 int i;
3385
3386 for (i = 0; i < I915_MAX_PIPES; i++)
3387 seq_printf(m, "%c %s\n", pipe_name(i),
3388 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3389
3390 return 0;
3391}
3392
Damien Lespiaubd9db022013-10-15 18:55:36 +01003393static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003394{
3395 struct drm_device *dev = inode->i_private;
3396
Damien Lespiaubd9db022013-10-15 18:55:36 +01003397 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003398}
3399
Daniel Vetter46a19182013-11-01 10:50:20 +01003400static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003401 uint32_t *val)
3402{
Daniel Vetter46a19182013-11-01 10:50:20 +01003403 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3404 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3405
3406 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003407 case INTEL_PIPE_CRC_SOURCE_PIPE:
3408 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3409 break;
3410 case INTEL_PIPE_CRC_SOURCE_NONE:
3411 *val = 0;
3412 break;
3413 default:
3414 return -EINVAL;
3415 }
3416
3417 return 0;
3418}
3419
Daniel Vetter46a19182013-11-01 10:50:20 +01003420static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3421 enum intel_pipe_crc_source *source)
3422{
3423 struct intel_encoder *encoder;
3424 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003425 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003426 int ret = 0;
3427
3428 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3429
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003430 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003431 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003432 if (!encoder->base.crtc)
3433 continue;
3434
3435 crtc = to_intel_crtc(encoder->base.crtc);
3436
3437 if (crtc->pipe != pipe)
3438 continue;
3439
3440 switch (encoder->type) {
3441 case INTEL_OUTPUT_TVOUT:
3442 *source = INTEL_PIPE_CRC_SOURCE_TV;
3443 break;
3444 case INTEL_OUTPUT_DISPLAYPORT:
3445 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003446 dig_port = enc_to_dig_port(&encoder->base);
3447 switch (dig_port->port) {
3448 case PORT_B:
3449 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3450 break;
3451 case PORT_C:
3452 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3453 break;
3454 case PORT_D:
3455 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3456 break;
3457 default:
3458 WARN(1, "nonexisting DP port %c\n",
3459 port_name(dig_port->port));
3460 break;
3461 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003462 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003463 default:
3464 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003465 }
3466 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003467 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003468
3469 return ret;
3470}
3471
3472static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3473 enum pipe pipe,
3474 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003475 uint32_t *val)
3476{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003477 struct drm_i915_private *dev_priv = dev->dev_private;
3478 bool need_stable_symbols = false;
3479
Daniel Vetter46a19182013-11-01 10:50:20 +01003480 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3481 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3482 if (ret)
3483 return ret;
3484 }
3485
3486 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003487 case INTEL_PIPE_CRC_SOURCE_PIPE:
3488 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3489 break;
3490 case INTEL_PIPE_CRC_SOURCE_DP_B:
3491 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003492 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003493 break;
3494 case INTEL_PIPE_CRC_SOURCE_DP_C:
3495 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003496 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003497 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003498 case INTEL_PIPE_CRC_SOURCE_DP_D:
3499 if (!IS_CHERRYVIEW(dev))
3500 return -EINVAL;
3501 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3502 need_stable_symbols = true;
3503 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003504 case INTEL_PIPE_CRC_SOURCE_NONE:
3505 *val = 0;
3506 break;
3507 default:
3508 return -EINVAL;
3509 }
3510
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003511 /*
3512 * When the pipe CRC tap point is after the transcoders we need
3513 * to tweak symbol-level features to produce a deterministic series of
3514 * symbols for a given frame. We need to reset those features only once
3515 * a frame (instead of every nth symbol):
3516 * - DC-balance: used to ensure a better clock recovery from the data
3517 * link (SDVO)
3518 * - DisplayPort scrambling: used for EMI reduction
3519 */
3520 if (need_stable_symbols) {
3521 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3522
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003523 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003524 switch (pipe) {
3525 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003526 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003527 break;
3528 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003529 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003530 break;
3531 case PIPE_C:
3532 tmp |= PIPE_C_SCRAMBLE_RESET;
3533 break;
3534 default:
3535 return -EINVAL;
3536 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003537 I915_WRITE(PORT_DFT2_G4X, tmp);
3538 }
3539
Daniel Vetter7ac01292013-10-18 16:37:06 +02003540 return 0;
3541}
3542
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003543static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003544 enum pipe pipe,
3545 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003546 uint32_t *val)
3547{
Daniel Vetter84093602013-11-01 10:50:21 +01003548 struct drm_i915_private *dev_priv = dev->dev_private;
3549 bool need_stable_symbols = false;
3550
Daniel Vetter46a19182013-11-01 10:50:20 +01003551 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3552 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3553 if (ret)
3554 return ret;
3555 }
3556
3557 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003558 case INTEL_PIPE_CRC_SOURCE_PIPE:
3559 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3560 break;
3561 case INTEL_PIPE_CRC_SOURCE_TV:
3562 if (!SUPPORTS_TV(dev))
3563 return -EINVAL;
3564 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3565 break;
3566 case INTEL_PIPE_CRC_SOURCE_DP_B:
3567 if (!IS_G4X(dev))
3568 return -EINVAL;
3569 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003570 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003571 break;
3572 case INTEL_PIPE_CRC_SOURCE_DP_C:
3573 if (!IS_G4X(dev))
3574 return -EINVAL;
3575 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003576 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003577 break;
3578 case INTEL_PIPE_CRC_SOURCE_DP_D:
3579 if (!IS_G4X(dev))
3580 return -EINVAL;
3581 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003582 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003583 break;
3584 case INTEL_PIPE_CRC_SOURCE_NONE:
3585 *val = 0;
3586 break;
3587 default:
3588 return -EINVAL;
3589 }
3590
Daniel Vetter84093602013-11-01 10:50:21 +01003591 /*
3592 * When the pipe CRC tap point is after the transcoders we need
3593 * to tweak symbol-level features to produce a deterministic series of
3594 * symbols for a given frame. We need to reset those features only once
3595 * a frame (instead of every nth symbol):
3596 * - DC-balance: used to ensure a better clock recovery from the data
3597 * link (SDVO)
3598 * - DisplayPort scrambling: used for EMI reduction
3599 */
3600 if (need_stable_symbols) {
3601 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3602
3603 WARN_ON(!IS_G4X(dev));
3604
3605 I915_WRITE(PORT_DFT_I9XX,
3606 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3607
3608 if (pipe == PIPE_A)
3609 tmp |= PIPE_A_SCRAMBLE_RESET;
3610 else
3611 tmp |= PIPE_B_SCRAMBLE_RESET;
3612
3613 I915_WRITE(PORT_DFT2_G4X, tmp);
3614 }
3615
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003616 return 0;
3617}
3618
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003619static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3620 enum pipe pipe)
3621{
3622 struct drm_i915_private *dev_priv = dev->dev_private;
3623 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3624
Ville Syrjäläeb736672014-12-09 21:28:28 +02003625 switch (pipe) {
3626 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003627 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003628 break;
3629 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003630 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003631 break;
3632 case PIPE_C:
3633 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3634 break;
3635 default:
3636 return;
3637 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003638 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3639 tmp &= ~DC_BALANCE_RESET_VLV;
3640 I915_WRITE(PORT_DFT2_G4X, tmp);
3641
3642}
3643
Daniel Vetter84093602013-11-01 10:50:21 +01003644static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3645 enum pipe pipe)
3646{
3647 struct drm_i915_private *dev_priv = dev->dev_private;
3648 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3649
3650 if (pipe == PIPE_A)
3651 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3652 else
3653 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3654 I915_WRITE(PORT_DFT2_G4X, tmp);
3655
3656 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3657 I915_WRITE(PORT_DFT_I9XX,
3658 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3659 }
3660}
3661
Daniel Vetter46a19182013-11-01 10:50:20 +01003662static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003663 uint32_t *val)
3664{
Daniel Vetter46a19182013-11-01 10:50:20 +01003665 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3666 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3667
3668 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003669 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3670 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3671 break;
3672 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3673 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3674 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003675 case INTEL_PIPE_CRC_SOURCE_PIPE:
3676 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3677 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003678 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003679 *val = 0;
3680 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003681 default:
3682 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003683 }
3684
3685 return 0;
3686}
3687
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003688static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003689{
3690 struct drm_i915_private *dev_priv = dev->dev_private;
3691 struct intel_crtc *crtc =
3692 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003693 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003694 struct drm_atomic_state *state;
3695 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003696
3697 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003698 state = drm_atomic_state_alloc(dev);
3699 if (!state) {
3700 ret = -ENOMEM;
3701 goto out;
3702 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003703
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003704 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
3705 pipe_config = intel_atomic_get_crtc_state(state, crtc);
3706 if (IS_ERR(pipe_config)) {
3707 ret = PTR_ERR(pipe_config);
3708 goto out;
3709 }
3710
3711 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003712 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003713 pipe_config->pch_pfit.enabled != enable)
3714 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003715
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003716 ret = drm_atomic_commit(state);
3717out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003718 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003719 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
3720 if (ret)
3721 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003722}
3723
3724static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3725 enum pipe pipe,
3726 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003727 uint32_t *val)
3728{
Daniel Vetter46a19182013-11-01 10:50:20 +01003729 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3730 *source = INTEL_PIPE_CRC_SOURCE_PF;
3731
3732 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003733 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3734 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3735 break;
3736 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3737 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3738 break;
3739 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003740 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003741 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003742
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003743 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3744 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003745 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003746 *val = 0;
3747 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003748 default:
3749 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003750 }
3751
3752 return 0;
3753}
3754
Daniel Vetter926321d2013-10-16 13:30:34 +02003755static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3756 enum intel_pipe_crc_source source)
3757{
3758 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003759 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003760 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3761 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003762 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003763 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003764
Damien Lespiaucc3da172013-10-15 18:55:31 +01003765 if (pipe_crc->source == source)
3766 return 0;
3767
Damien Lespiauae676fc2013-10-15 18:55:32 +01003768 /* forbid changing the source without going back to 'none' */
3769 if (pipe_crc->source && source)
3770 return -EINVAL;
3771
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003772 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3773 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3774 return -EIO;
3775 }
3776
Daniel Vetter52f843f2013-10-21 17:26:38 +02003777 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003778 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003779 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003780 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003781 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003782 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003783 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003784 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003785 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003786 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003787
3788 if (ret != 0)
3789 return ret;
3790
Damien Lespiau4b584362013-10-15 18:55:33 +01003791 /* none -> real source transition */
3792 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003793 struct intel_pipe_crc_entry *entries;
3794
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003795 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3796 pipe_name(pipe), pipe_crc_source_name(source));
3797
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003798 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3799 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003800 GFP_KERNEL);
3801 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003802 return -ENOMEM;
3803
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003804 /*
3805 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3806 * enabled and disabled dynamically based on package C states,
3807 * user space can't make reliable use of the CRCs, so let's just
3808 * completely disable it.
3809 */
3810 hsw_disable_ips(crtc);
3811
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003812 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003813 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003814 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003815 pipe_crc->head = 0;
3816 pipe_crc->tail = 0;
3817 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003818 }
3819
Damien Lespiaucc3da172013-10-15 18:55:31 +01003820 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003821
Daniel Vetter926321d2013-10-16 13:30:34 +02003822 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3823 POSTING_READ(PIPE_CRC_CTL(pipe));
3824
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003825 /* real source -> none transition */
3826 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003827 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003828 struct intel_crtc *crtc =
3829 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003830
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003831 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3832 pipe_name(pipe));
3833
Daniel Vettera33d7102014-06-06 08:22:08 +02003834 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003835 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02003836 intel_wait_for_vblank(dev, pipe);
3837 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003838
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003839 spin_lock_irq(&pipe_crc->lock);
3840 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003841 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003842 pipe_crc->head = 0;
3843 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003844 spin_unlock_irq(&pipe_crc->lock);
3845
3846 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003847
3848 if (IS_G4X(dev))
3849 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003850 else if (IS_VALLEYVIEW(dev))
3851 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003852 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003853 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003854
3855 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003856 }
3857
Daniel Vetter926321d2013-10-16 13:30:34 +02003858 return 0;
3859}
3860
3861/*
3862 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003863 * command: wsp* object wsp+ name wsp+ source wsp*
3864 * object: 'pipe'
3865 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003866 * source: (none | plane1 | plane2 | pf)
3867 * wsp: (#0x20 | #0x9 | #0xA)+
3868 *
3869 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003870 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3871 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003872 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003873static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003874{
3875 int n_words = 0;
3876
3877 while (*buf) {
3878 char *end;
3879
3880 /* skip leading white space */
3881 buf = skip_spaces(buf);
3882 if (!*buf)
3883 break; /* end of buffer */
3884
3885 /* find end of word */
3886 for (end = buf; *end && !isspace(*end); end++)
3887 ;
3888
3889 if (n_words == max_words) {
3890 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3891 max_words);
3892 return -EINVAL; /* ran out of words[] before bytes */
3893 }
3894
3895 if (*end)
3896 *end++ = '\0';
3897 words[n_words++] = buf;
3898 buf = end;
3899 }
3900
3901 return n_words;
3902}
3903
Damien Lespiaub94dec82013-10-15 18:55:35 +01003904enum intel_pipe_crc_object {
3905 PIPE_CRC_OBJECT_PIPE,
3906};
3907
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003908static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003909 "pipe",
3910};
3911
3912static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003913display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003914{
3915 int i;
3916
3917 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3918 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003919 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003920 return 0;
3921 }
3922
3923 return -EINVAL;
3924}
3925
Damien Lespiaubd9db022013-10-15 18:55:36 +01003926static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003927{
3928 const char name = buf[0];
3929
3930 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3931 return -EINVAL;
3932
3933 *pipe = name - 'A';
3934
3935 return 0;
3936}
3937
3938static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003939display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003940{
3941 int i;
3942
3943 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3944 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003945 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003946 return 0;
3947 }
3948
3949 return -EINVAL;
3950}
3951
Damien Lespiaubd9db022013-10-15 18:55:36 +01003952static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003953{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003954#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003955 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003956 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003957 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003958 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003959 enum intel_pipe_crc_source source;
3960
Damien Lespiaubd9db022013-10-15 18:55:36 +01003961 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003962 if (n_words != N_WORDS) {
3963 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3964 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003965 return -EINVAL;
3966 }
3967
Damien Lespiaubd9db022013-10-15 18:55:36 +01003968 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003969 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003970 return -EINVAL;
3971 }
3972
Damien Lespiaubd9db022013-10-15 18:55:36 +01003973 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003974 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3975 return -EINVAL;
3976 }
3977
Damien Lespiaubd9db022013-10-15 18:55:36 +01003978 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003979 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003980 return -EINVAL;
3981 }
3982
3983 return pipe_crc_set_source(dev, pipe, source);
3984}
3985
Damien Lespiaubd9db022013-10-15 18:55:36 +01003986static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3987 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003988{
3989 struct seq_file *m = file->private_data;
3990 struct drm_device *dev = m->private;
3991 char *tmpbuf;
3992 int ret;
3993
3994 if (len == 0)
3995 return 0;
3996
3997 if (len > PAGE_SIZE - 1) {
3998 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3999 PAGE_SIZE);
4000 return -E2BIG;
4001 }
4002
4003 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4004 if (!tmpbuf)
4005 return -ENOMEM;
4006
4007 if (copy_from_user(tmpbuf, ubuf, len)) {
4008 ret = -EFAULT;
4009 goto out;
4010 }
4011 tmpbuf[len] = '\0';
4012
Damien Lespiaubd9db022013-10-15 18:55:36 +01004013 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004014
4015out:
4016 kfree(tmpbuf);
4017 if (ret < 0)
4018 return ret;
4019
4020 *offp += len;
4021 return len;
4022}
4023
Damien Lespiaubd9db022013-10-15 18:55:36 +01004024static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004025 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004026 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004027 .read = seq_read,
4028 .llseek = seq_lseek,
4029 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004030 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004031};
4032
Todd Previteeb3394fa2015-04-18 00:04:19 -07004033static ssize_t i915_displayport_test_active_write(struct file *file,
4034 const char __user *ubuf,
4035 size_t len, loff_t *offp)
4036{
4037 char *input_buffer;
4038 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004039 struct drm_device *dev;
4040 struct drm_connector *connector;
4041 struct list_head *connector_list;
4042 struct intel_dp *intel_dp;
4043 int val = 0;
4044
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304045 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004046
Todd Previteeb3394fa2015-04-18 00:04:19 -07004047 connector_list = &dev->mode_config.connector_list;
4048
4049 if (len == 0)
4050 return 0;
4051
4052 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4053 if (!input_buffer)
4054 return -ENOMEM;
4055
4056 if (copy_from_user(input_buffer, ubuf, len)) {
4057 status = -EFAULT;
4058 goto out;
4059 }
4060
4061 input_buffer[len] = '\0';
4062 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4063
4064 list_for_each_entry(connector, connector_list, head) {
4065
4066 if (connector->connector_type !=
4067 DRM_MODE_CONNECTOR_DisplayPort)
4068 continue;
4069
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304070 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004071 connector->encoder != NULL) {
4072 intel_dp = enc_to_intel_dp(connector->encoder);
4073 status = kstrtoint(input_buffer, 10, &val);
4074 if (status < 0)
4075 goto out;
4076 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4077 /* To prevent erroneous activation of the compliance
4078 * testing code, only accept an actual value of 1 here
4079 */
4080 if (val == 1)
4081 intel_dp->compliance_test_active = 1;
4082 else
4083 intel_dp->compliance_test_active = 0;
4084 }
4085 }
4086out:
4087 kfree(input_buffer);
4088 if (status < 0)
4089 return status;
4090
4091 *offp += len;
4092 return len;
4093}
4094
4095static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4096{
4097 struct drm_device *dev = m->private;
4098 struct drm_connector *connector;
4099 struct list_head *connector_list = &dev->mode_config.connector_list;
4100 struct intel_dp *intel_dp;
4101
Todd Previteeb3394fa2015-04-18 00:04:19 -07004102 list_for_each_entry(connector, connector_list, head) {
4103
4104 if (connector->connector_type !=
4105 DRM_MODE_CONNECTOR_DisplayPort)
4106 continue;
4107
4108 if (connector->status == connector_status_connected &&
4109 connector->encoder != NULL) {
4110 intel_dp = enc_to_intel_dp(connector->encoder);
4111 if (intel_dp->compliance_test_active)
4112 seq_puts(m, "1");
4113 else
4114 seq_puts(m, "0");
4115 } else
4116 seq_puts(m, "0");
4117 }
4118
4119 return 0;
4120}
4121
4122static int i915_displayport_test_active_open(struct inode *inode,
4123 struct file *file)
4124{
4125 struct drm_device *dev = inode->i_private;
4126
4127 return single_open(file, i915_displayport_test_active_show, dev);
4128}
4129
4130static const struct file_operations i915_displayport_test_active_fops = {
4131 .owner = THIS_MODULE,
4132 .open = i915_displayport_test_active_open,
4133 .read = seq_read,
4134 .llseek = seq_lseek,
4135 .release = single_release,
4136 .write = i915_displayport_test_active_write
4137};
4138
4139static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4140{
4141 struct drm_device *dev = m->private;
4142 struct drm_connector *connector;
4143 struct list_head *connector_list = &dev->mode_config.connector_list;
4144 struct intel_dp *intel_dp;
4145
Todd Previteeb3394fa2015-04-18 00:04:19 -07004146 list_for_each_entry(connector, connector_list, head) {
4147
4148 if (connector->connector_type !=
4149 DRM_MODE_CONNECTOR_DisplayPort)
4150 continue;
4151
4152 if (connector->status == connector_status_connected &&
4153 connector->encoder != NULL) {
4154 intel_dp = enc_to_intel_dp(connector->encoder);
4155 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4156 } else
4157 seq_puts(m, "0");
4158 }
4159
4160 return 0;
4161}
4162static int i915_displayport_test_data_open(struct inode *inode,
4163 struct file *file)
4164{
4165 struct drm_device *dev = inode->i_private;
4166
4167 return single_open(file, i915_displayport_test_data_show, dev);
4168}
4169
4170static const struct file_operations i915_displayport_test_data_fops = {
4171 .owner = THIS_MODULE,
4172 .open = i915_displayport_test_data_open,
4173 .read = seq_read,
4174 .llseek = seq_lseek,
4175 .release = single_release
4176};
4177
4178static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4179{
4180 struct drm_device *dev = m->private;
4181 struct drm_connector *connector;
4182 struct list_head *connector_list = &dev->mode_config.connector_list;
4183 struct intel_dp *intel_dp;
4184
Todd Previteeb3394fa2015-04-18 00:04:19 -07004185 list_for_each_entry(connector, connector_list, head) {
4186
4187 if (connector->connector_type !=
4188 DRM_MODE_CONNECTOR_DisplayPort)
4189 continue;
4190
4191 if (connector->status == connector_status_connected &&
4192 connector->encoder != NULL) {
4193 intel_dp = enc_to_intel_dp(connector->encoder);
4194 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4195 } else
4196 seq_puts(m, "0");
4197 }
4198
4199 return 0;
4200}
4201
4202static int i915_displayport_test_type_open(struct inode *inode,
4203 struct file *file)
4204{
4205 struct drm_device *dev = inode->i_private;
4206
4207 return single_open(file, i915_displayport_test_type_show, dev);
4208}
4209
4210static const struct file_operations i915_displayport_test_type_fops = {
4211 .owner = THIS_MODULE,
4212 .open = i915_displayport_test_type_open,
4213 .read = seq_read,
4214 .llseek = seq_lseek,
4215 .release = single_release
4216};
4217
Damien Lespiau97e94b22014-11-04 17:06:50 +00004218static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004219{
4220 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004221 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004222 int num_levels;
4223
4224 if (IS_CHERRYVIEW(dev))
4225 num_levels = 3;
4226 else if (IS_VALLEYVIEW(dev))
4227 num_levels = 1;
4228 else
4229 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004230
4231 drm_modeset_lock_all(dev);
4232
4233 for (level = 0; level < num_levels; level++) {
4234 unsigned int latency = wm[level];
4235
Damien Lespiau97e94b22014-11-04 17:06:50 +00004236 /*
4237 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004238 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004239 */
Ville Syrjäläde38b952015-06-24 22:00:09 +03004240 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004241 latency *= 10;
4242 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004243 latency *= 5;
4244
4245 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004246 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004247 }
4248
4249 drm_modeset_unlock_all(dev);
4250}
4251
4252static int pri_wm_latency_show(struct seq_file *m, void *data)
4253{
4254 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004255 struct drm_i915_private *dev_priv = dev->dev_private;
4256 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004257
Damien Lespiau97e94b22014-11-04 17:06:50 +00004258 if (INTEL_INFO(dev)->gen >= 9)
4259 latencies = dev_priv->wm.skl_latency;
4260 else
4261 latencies = to_i915(dev)->wm.pri_latency;
4262
4263 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004264
4265 return 0;
4266}
4267
4268static int spr_wm_latency_show(struct seq_file *m, void *data)
4269{
4270 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004271 struct drm_i915_private *dev_priv = dev->dev_private;
4272 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004273
Damien Lespiau97e94b22014-11-04 17:06:50 +00004274 if (INTEL_INFO(dev)->gen >= 9)
4275 latencies = dev_priv->wm.skl_latency;
4276 else
4277 latencies = to_i915(dev)->wm.spr_latency;
4278
4279 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004280
4281 return 0;
4282}
4283
4284static int cur_wm_latency_show(struct seq_file *m, void *data)
4285{
4286 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004287 struct drm_i915_private *dev_priv = dev->dev_private;
4288 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004289
Damien Lespiau97e94b22014-11-04 17:06:50 +00004290 if (INTEL_INFO(dev)->gen >= 9)
4291 latencies = dev_priv->wm.skl_latency;
4292 else
4293 latencies = to_i915(dev)->wm.cur_latency;
4294
4295 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004296
4297 return 0;
4298}
4299
4300static int pri_wm_latency_open(struct inode *inode, struct file *file)
4301{
4302 struct drm_device *dev = inode->i_private;
4303
Ville Syrjäläde38b952015-06-24 22:00:09 +03004304 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004305 return -ENODEV;
4306
4307 return single_open(file, pri_wm_latency_show, dev);
4308}
4309
4310static int spr_wm_latency_open(struct inode *inode, struct file *file)
4311{
4312 struct drm_device *dev = inode->i_private;
4313
Sonika Jindal9ad02572014-07-21 15:23:39 +05304314 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004315 return -ENODEV;
4316
4317 return single_open(file, spr_wm_latency_show, dev);
4318}
4319
4320static int cur_wm_latency_open(struct inode *inode, struct file *file)
4321{
4322 struct drm_device *dev = inode->i_private;
4323
Sonika Jindal9ad02572014-07-21 15:23:39 +05304324 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004325 return -ENODEV;
4326
4327 return single_open(file, cur_wm_latency_show, dev);
4328}
4329
4330static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004331 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004332{
4333 struct seq_file *m = file->private_data;
4334 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004335 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004336 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004337 int level;
4338 int ret;
4339 char tmp[32];
4340
Ville Syrjäläde38b952015-06-24 22:00:09 +03004341 if (IS_CHERRYVIEW(dev))
4342 num_levels = 3;
4343 else if (IS_VALLEYVIEW(dev))
4344 num_levels = 1;
4345 else
4346 num_levels = ilk_wm_max_level(dev) + 1;
4347
Ville Syrjälä369a1342014-01-22 14:36:08 +02004348 if (len >= sizeof(tmp))
4349 return -EINVAL;
4350
4351 if (copy_from_user(tmp, ubuf, len))
4352 return -EFAULT;
4353
4354 tmp[len] = '\0';
4355
Damien Lespiau97e94b22014-11-04 17:06:50 +00004356 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4357 &new[0], &new[1], &new[2], &new[3],
4358 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004359 if (ret != num_levels)
4360 return -EINVAL;
4361
4362 drm_modeset_lock_all(dev);
4363
4364 for (level = 0; level < num_levels; level++)
4365 wm[level] = new[level];
4366
4367 drm_modeset_unlock_all(dev);
4368
4369 return len;
4370}
4371
4372
4373static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4374 size_t len, loff_t *offp)
4375{
4376 struct seq_file *m = file->private_data;
4377 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004378 struct drm_i915_private *dev_priv = dev->dev_private;
4379 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004380
Damien Lespiau97e94b22014-11-04 17:06:50 +00004381 if (INTEL_INFO(dev)->gen >= 9)
4382 latencies = dev_priv->wm.skl_latency;
4383 else
4384 latencies = to_i915(dev)->wm.pri_latency;
4385
4386 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004387}
4388
4389static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4390 size_t len, loff_t *offp)
4391{
4392 struct seq_file *m = file->private_data;
4393 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004394 struct drm_i915_private *dev_priv = dev->dev_private;
4395 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004396
Damien Lespiau97e94b22014-11-04 17:06:50 +00004397 if (INTEL_INFO(dev)->gen >= 9)
4398 latencies = dev_priv->wm.skl_latency;
4399 else
4400 latencies = to_i915(dev)->wm.spr_latency;
4401
4402 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004403}
4404
4405static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4406 size_t len, loff_t *offp)
4407{
4408 struct seq_file *m = file->private_data;
4409 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004410 struct drm_i915_private *dev_priv = dev->dev_private;
4411 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004412
Damien Lespiau97e94b22014-11-04 17:06:50 +00004413 if (INTEL_INFO(dev)->gen >= 9)
4414 latencies = dev_priv->wm.skl_latency;
4415 else
4416 latencies = to_i915(dev)->wm.cur_latency;
4417
4418 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004419}
4420
4421static const struct file_operations i915_pri_wm_latency_fops = {
4422 .owner = THIS_MODULE,
4423 .open = pri_wm_latency_open,
4424 .read = seq_read,
4425 .llseek = seq_lseek,
4426 .release = single_release,
4427 .write = pri_wm_latency_write
4428};
4429
4430static const struct file_operations i915_spr_wm_latency_fops = {
4431 .owner = THIS_MODULE,
4432 .open = spr_wm_latency_open,
4433 .read = seq_read,
4434 .llseek = seq_lseek,
4435 .release = single_release,
4436 .write = spr_wm_latency_write
4437};
4438
4439static const struct file_operations i915_cur_wm_latency_fops = {
4440 .owner = THIS_MODULE,
4441 .open = cur_wm_latency_open,
4442 .read = seq_read,
4443 .llseek = seq_lseek,
4444 .release = single_release,
4445 .write = cur_wm_latency_write
4446};
4447
Kees Cook647416f2013-03-10 14:10:06 -07004448static int
4449i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004450{
Kees Cook647416f2013-03-10 14:10:06 -07004451 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004452 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004453
Kees Cook647416f2013-03-10 14:10:06 -07004454 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004455
Kees Cook647416f2013-03-10 14:10:06 -07004456 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004457}
4458
Kees Cook647416f2013-03-10 14:10:06 -07004459static int
4460i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004461{
Kees Cook647416f2013-03-10 14:10:06 -07004462 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004463 struct drm_i915_private *dev_priv = dev->dev_private;
4464
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004465 /*
4466 * There is no safeguard against this debugfs entry colliding
4467 * with the hangcheck calling same i915_handle_error() in
4468 * parallel, causing an explosion. For now we assume that the
4469 * test harness is responsible enough not to inject gpu hangs
4470 * while it is writing to 'i915_wedged'
4471 */
4472
4473 if (i915_reset_in_progress(&dev_priv->gpu_error))
4474 return -EAGAIN;
4475
Imre Deakd46c0512014-04-14 20:24:27 +03004476 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004477
Mika Kuoppala58174462014-02-25 17:11:26 +02004478 i915_handle_error(dev, val,
4479 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004480
4481 intel_runtime_pm_put(dev_priv);
4482
Kees Cook647416f2013-03-10 14:10:06 -07004483 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004484}
4485
Kees Cook647416f2013-03-10 14:10:06 -07004486DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4487 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004488 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004489
Kees Cook647416f2013-03-10 14:10:06 -07004490static int
4491i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004492{
Kees Cook647416f2013-03-10 14:10:06 -07004493 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004494 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004495
Kees Cook647416f2013-03-10 14:10:06 -07004496 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004497
Kees Cook647416f2013-03-10 14:10:06 -07004498 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004499}
4500
Kees Cook647416f2013-03-10 14:10:06 -07004501static int
4502i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004503{
Kees Cook647416f2013-03-10 14:10:06 -07004504 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004505 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004506 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004507
Kees Cook647416f2013-03-10 14:10:06 -07004508 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004509
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004510 ret = mutex_lock_interruptible(&dev->struct_mutex);
4511 if (ret)
4512 return ret;
4513
Daniel Vetter99584db2012-11-14 17:14:04 +01004514 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004515 mutex_unlock(&dev->struct_mutex);
4516
Kees Cook647416f2013-03-10 14:10:06 -07004517 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004518}
4519
Kees Cook647416f2013-03-10 14:10:06 -07004520DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4521 i915_ring_stop_get, i915_ring_stop_set,
4522 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004523
Chris Wilson094f9a52013-09-25 17:34:55 +01004524static int
4525i915_ring_missed_irq_get(void *data, u64 *val)
4526{
4527 struct drm_device *dev = data;
4528 struct drm_i915_private *dev_priv = dev->dev_private;
4529
4530 *val = dev_priv->gpu_error.missed_irq_rings;
4531 return 0;
4532}
4533
4534static int
4535i915_ring_missed_irq_set(void *data, u64 val)
4536{
4537 struct drm_device *dev = data;
4538 struct drm_i915_private *dev_priv = dev->dev_private;
4539 int ret;
4540
4541 /* Lock against concurrent debugfs callers */
4542 ret = mutex_lock_interruptible(&dev->struct_mutex);
4543 if (ret)
4544 return ret;
4545 dev_priv->gpu_error.missed_irq_rings = val;
4546 mutex_unlock(&dev->struct_mutex);
4547
4548 return 0;
4549}
4550
4551DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4552 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4553 "0x%08llx\n");
4554
4555static int
4556i915_ring_test_irq_get(void *data, u64 *val)
4557{
4558 struct drm_device *dev = data;
4559 struct drm_i915_private *dev_priv = dev->dev_private;
4560
4561 *val = dev_priv->gpu_error.test_irq_rings;
4562
4563 return 0;
4564}
4565
4566static int
4567i915_ring_test_irq_set(void *data, u64 val)
4568{
4569 struct drm_device *dev = data;
4570 struct drm_i915_private *dev_priv = dev->dev_private;
4571 int ret;
4572
4573 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4574
4575 /* Lock against concurrent debugfs callers */
4576 ret = mutex_lock_interruptible(&dev->struct_mutex);
4577 if (ret)
4578 return ret;
4579
4580 dev_priv->gpu_error.test_irq_rings = val;
4581 mutex_unlock(&dev->struct_mutex);
4582
4583 return 0;
4584}
4585
4586DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4587 i915_ring_test_irq_get, i915_ring_test_irq_set,
4588 "0x%08llx\n");
4589
Chris Wilsondd624af2013-01-15 12:39:35 +00004590#define DROP_UNBOUND 0x1
4591#define DROP_BOUND 0x2
4592#define DROP_RETIRE 0x4
4593#define DROP_ACTIVE 0x8
4594#define DROP_ALL (DROP_UNBOUND | \
4595 DROP_BOUND | \
4596 DROP_RETIRE | \
4597 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004598static int
4599i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004600{
Kees Cook647416f2013-03-10 14:10:06 -07004601 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004602
Kees Cook647416f2013-03-10 14:10:06 -07004603 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004604}
4605
Kees Cook647416f2013-03-10 14:10:06 -07004606static int
4607i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004608{
Kees Cook647416f2013-03-10 14:10:06 -07004609 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004610 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004611 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004612
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004613 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004614
4615 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4616 * on ioctls on -EAGAIN. */
4617 ret = mutex_lock_interruptible(&dev->struct_mutex);
4618 if (ret)
4619 return ret;
4620
4621 if (val & DROP_ACTIVE) {
4622 ret = i915_gpu_idle(dev);
4623 if (ret)
4624 goto unlock;
4625 }
4626
4627 if (val & (DROP_RETIRE | DROP_ACTIVE))
4628 i915_gem_retire_requests(dev);
4629
Chris Wilson21ab4e72014-09-09 11:16:08 +01004630 if (val & DROP_BOUND)
4631 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004632
Chris Wilson21ab4e72014-09-09 11:16:08 +01004633 if (val & DROP_UNBOUND)
4634 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004635
4636unlock:
4637 mutex_unlock(&dev->struct_mutex);
4638
Kees Cook647416f2013-03-10 14:10:06 -07004639 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004640}
4641
Kees Cook647416f2013-03-10 14:10:06 -07004642DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4643 i915_drop_caches_get, i915_drop_caches_set,
4644 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004645
Kees Cook647416f2013-03-10 14:10:06 -07004646static int
4647i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004648{
Kees Cook647416f2013-03-10 14:10:06 -07004649 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004650 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004651 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004652
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004653 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004654 return -ENODEV;
4655
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004656 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4657
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004658 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004659 if (ret)
4660 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004661
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004662 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004663 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004664
Kees Cook647416f2013-03-10 14:10:06 -07004665 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004666}
4667
Kees Cook647416f2013-03-10 14:10:06 -07004668static int
4669i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004670{
Kees Cook647416f2013-03-10 14:10:06 -07004671 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004672 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304673 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004674 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004675
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004676 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004677 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004678
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004679 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4680
Kees Cook647416f2013-03-10 14:10:06 -07004681 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004682
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004683 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004684 if (ret)
4685 return ret;
4686
Jesse Barnes358733e2011-07-27 11:53:01 -07004687 /*
4688 * Turbo will still be enabled, but won't go above the set value.
4689 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304690 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004691
Akash Goelbc4d91f2015-02-26 16:09:47 +05304692 hw_max = dev_priv->rps.max_freq;
4693 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004694
Ben Widawskyb39fb292014-03-19 18:31:11 -07004695 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004696 mutex_unlock(&dev_priv->rps.hw_lock);
4697 return -EINVAL;
4698 }
4699
Ben Widawskyb39fb292014-03-19 18:31:11 -07004700 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004701
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004702 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004703
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004704 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004705
Kees Cook647416f2013-03-10 14:10:06 -07004706 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004707}
4708
Kees Cook647416f2013-03-10 14:10:06 -07004709DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4710 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004711 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004712
Kees Cook647416f2013-03-10 14:10:06 -07004713static int
4714i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004715{
Kees Cook647416f2013-03-10 14:10:06 -07004716 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004717 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004718 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004719
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004720 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004721 return -ENODEV;
4722
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004723 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4724
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004725 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004726 if (ret)
4727 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004728
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004729 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004730 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004731
Kees Cook647416f2013-03-10 14:10:06 -07004732 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004733}
4734
Kees Cook647416f2013-03-10 14:10:06 -07004735static int
4736i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004737{
Kees Cook647416f2013-03-10 14:10:06 -07004738 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004739 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304740 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004741 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004742
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004743 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004744 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004745
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004746 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4747
Kees Cook647416f2013-03-10 14:10:06 -07004748 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004749
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004750 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004751 if (ret)
4752 return ret;
4753
Jesse Barnes1523c312012-05-25 12:34:54 -07004754 /*
4755 * Turbo will still be enabled, but won't go below the set value.
4756 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304757 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004758
Akash Goelbc4d91f2015-02-26 16:09:47 +05304759 hw_max = dev_priv->rps.max_freq;
4760 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004761
Ben Widawskyb39fb292014-03-19 18:31:11 -07004762 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004763 mutex_unlock(&dev_priv->rps.hw_lock);
4764 return -EINVAL;
4765 }
4766
Ben Widawskyb39fb292014-03-19 18:31:11 -07004767 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004768
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004769 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004770
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004771 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004772
Kees Cook647416f2013-03-10 14:10:06 -07004773 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004774}
4775
Kees Cook647416f2013-03-10 14:10:06 -07004776DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4777 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004778 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004779
Kees Cook647416f2013-03-10 14:10:06 -07004780static int
4781i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004782{
Kees Cook647416f2013-03-10 14:10:06 -07004783 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004784 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004785 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004786 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004787
Daniel Vetter004777c2012-08-09 15:07:01 +02004788 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4789 return -ENODEV;
4790
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004791 ret = mutex_lock_interruptible(&dev->struct_mutex);
4792 if (ret)
4793 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004794 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004795
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004796 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004797
4798 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004799 mutex_unlock(&dev_priv->dev->struct_mutex);
4800
Kees Cook647416f2013-03-10 14:10:06 -07004801 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004802
Kees Cook647416f2013-03-10 14:10:06 -07004803 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004804}
4805
Kees Cook647416f2013-03-10 14:10:06 -07004806static int
4807i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004808{
Kees Cook647416f2013-03-10 14:10:06 -07004809 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004810 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004811 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004812
Daniel Vetter004777c2012-08-09 15:07:01 +02004813 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4814 return -ENODEV;
4815
Kees Cook647416f2013-03-10 14:10:06 -07004816 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004817 return -EINVAL;
4818
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004819 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004820 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004821
4822 /* Update the cache sharing policy here as well */
4823 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4824 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4825 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4826 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4827
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004828 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004829 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004830}
4831
Kees Cook647416f2013-03-10 14:10:06 -07004832DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4833 i915_cache_sharing_get, i915_cache_sharing_set,
4834 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004835
Jeff McGee5d395252015-04-03 18:13:17 -07004836struct sseu_dev_status {
4837 unsigned int slice_total;
4838 unsigned int subslice_total;
4839 unsigned int subslice_per_slice;
4840 unsigned int eu_total;
4841 unsigned int eu_per_subslice;
4842};
4843
4844static void cherryview_sseu_device_status(struct drm_device *dev,
4845 struct sseu_dev_status *stat)
4846{
4847 struct drm_i915_private *dev_priv = dev->dev_private;
4848 const int ss_max = 2;
4849 int ss;
4850 u32 sig1[ss_max], sig2[ss_max];
4851
4852 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4853 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4854 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4855 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4856
4857 for (ss = 0; ss < ss_max; ss++) {
4858 unsigned int eu_cnt;
4859
4860 if (sig1[ss] & CHV_SS_PG_ENABLE)
4861 /* skip disabled subslice */
4862 continue;
4863
4864 stat->slice_total = 1;
4865 stat->subslice_per_slice++;
4866 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4867 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4868 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4869 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
4870 stat->eu_total += eu_cnt;
4871 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
4872 }
4873 stat->subslice_total = stat->subslice_per_slice;
4874}
4875
4876static void gen9_sseu_device_status(struct drm_device *dev,
4877 struct sseu_dev_status *stat)
4878{
4879 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004880 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004881 int s, ss;
4882 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4883
Jeff McGee1c046bc2015-04-03 18:13:18 -07004884 /* BXT has a single slice and at most 3 subslices. */
4885 if (IS_BROXTON(dev)) {
4886 s_max = 1;
4887 ss_max = 3;
4888 }
4889
4890 for (s = 0; s < s_max; s++) {
4891 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4892 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4893 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4894 }
4895
Jeff McGee5d395252015-04-03 18:13:17 -07004896 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4897 GEN9_PGCTL_SSA_EU19_ACK |
4898 GEN9_PGCTL_SSA_EU210_ACK |
4899 GEN9_PGCTL_SSA_EU311_ACK;
4900 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4901 GEN9_PGCTL_SSB_EU19_ACK |
4902 GEN9_PGCTL_SSB_EU210_ACK |
4903 GEN9_PGCTL_SSB_EU311_ACK;
4904
4905 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004906 unsigned int ss_cnt = 0;
4907
Jeff McGee5d395252015-04-03 18:13:17 -07004908 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4909 /* skip disabled slice */
4910 continue;
4911
4912 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004913
4914 if (IS_SKYLAKE(dev))
4915 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
4916
Jeff McGee5d395252015-04-03 18:13:17 -07004917 for (ss = 0; ss < ss_max; ss++) {
4918 unsigned int eu_cnt;
4919
Jeff McGee1c046bc2015-04-03 18:13:18 -07004920 if (IS_BROXTON(dev) &&
4921 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4922 /* skip disabled subslice */
4923 continue;
4924
4925 if (IS_BROXTON(dev))
4926 ss_cnt++;
4927
Jeff McGee5d395252015-04-03 18:13:17 -07004928 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4929 eu_mask[ss%2]);
4930 stat->eu_total += eu_cnt;
4931 stat->eu_per_subslice = max(stat->eu_per_subslice,
4932 eu_cnt);
4933 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004934
4935 stat->subslice_total += ss_cnt;
4936 stat->subslice_per_slice = max(stat->subslice_per_slice,
4937 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004938 }
4939}
4940
Jeff McGee38732182015-02-13 10:27:54 -06004941static int i915_sseu_status(struct seq_file *m, void *unused)
4942{
4943 struct drm_info_node *node = (struct drm_info_node *) m->private;
4944 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07004945 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06004946
Jeff McGee5575f032015-02-27 10:22:32 -08004947 if ((INTEL_INFO(dev)->gen < 8) || IS_BROADWELL(dev))
Jeff McGee38732182015-02-13 10:27:54 -06004948 return -ENODEV;
4949
4950 seq_puts(m, "SSEU Device Info\n");
4951 seq_printf(m, " Available Slice Total: %u\n",
4952 INTEL_INFO(dev)->slice_total);
4953 seq_printf(m, " Available Subslice Total: %u\n",
4954 INTEL_INFO(dev)->subslice_total);
4955 seq_printf(m, " Available Subslice Per Slice: %u\n",
4956 INTEL_INFO(dev)->subslice_per_slice);
4957 seq_printf(m, " Available EU Total: %u\n",
4958 INTEL_INFO(dev)->eu_total);
4959 seq_printf(m, " Available EU Per Subslice: %u\n",
4960 INTEL_INFO(dev)->eu_per_subslice);
4961 seq_printf(m, " Has Slice Power Gating: %s\n",
4962 yesno(INTEL_INFO(dev)->has_slice_pg));
4963 seq_printf(m, " Has Subslice Power Gating: %s\n",
4964 yesno(INTEL_INFO(dev)->has_subslice_pg));
4965 seq_printf(m, " Has EU Power Gating: %s\n",
4966 yesno(INTEL_INFO(dev)->has_eu_pg));
4967
Jeff McGee7f992ab2015-02-13 10:27:55 -06004968 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07004969 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08004970 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07004971 cherryview_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004972 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07004973 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004974 }
Jeff McGee5d395252015-04-03 18:13:17 -07004975 seq_printf(m, " Enabled Slice Total: %u\n",
4976 stat.slice_total);
4977 seq_printf(m, " Enabled Subslice Total: %u\n",
4978 stat.subslice_total);
4979 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
4980 stat.subslice_per_slice);
4981 seq_printf(m, " Enabled EU Total: %u\n",
4982 stat.eu_total);
4983 seq_printf(m, " Enabled EU Per Subslice: %u\n",
4984 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004985
Jeff McGee38732182015-02-13 10:27:54 -06004986 return 0;
4987}
4988
Ben Widawsky6d794d42011-04-25 11:25:56 -07004989static int i915_forcewake_open(struct inode *inode, struct file *file)
4990{
4991 struct drm_device *dev = inode->i_private;
4992 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004993
Daniel Vetter075edca2012-01-24 09:44:28 +01004994 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004995 return 0;
4996
Chris Wilson6daccb02015-01-16 11:34:35 +02004997 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004998 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004999
5000 return 0;
5001}
5002
Ben Widawskyc43b5632012-04-16 14:07:40 -07005003static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005004{
5005 struct drm_device *dev = inode->i_private;
5006 struct drm_i915_private *dev_priv = dev->dev_private;
5007
Daniel Vetter075edca2012-01-24 09:44:28 +01005008 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005009 return 0;
5010
Mika Kuoppala59bad942015-01-16 11:34:40 +02005011 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005012 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005013
5014 return 0;
5015}
5016
5017static const struct file_operations i915_forcewake_fops = {
5018 .owner = THIS_MODULE,
5019 .open = i915_forcewake_open,
5020 .release = i915_forcewake_release,
5021};
5022
5023static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5024{
5025 struct drm_device *dev = minor->dev;
5026 struct dentry *ent;
5027
5028 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005029 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005030 root, dev,
5031 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005032 if (!ent)
5033 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005034
Ben Widawsky8eb57292011-05-11 15:10:58 -07005035 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005036}
5037
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005038static int i915_debugfs_create(struct dentry *root,
5039 struct drm_minor *minor,
5040 const char *name,
5041 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005042{
5043 struct drm_device *dev = minor->dev;
5044 struct dentry *ent;
5045
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005046 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005047 S_IRUGO | S_IWUSR,
5048 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005049 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005050 if (!ent)
5051 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005052
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005053 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005054}
5055
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005056static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005057 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005058 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005059 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005060 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005061 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005062 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005063 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005064 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005065 {"i915_gem_request", i915_gem_request_info, 0},
5066 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005067 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005068 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005069 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5070 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5071 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005072 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005073 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005074 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305075 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005076 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005077 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005078 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005079 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005080 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005081 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005082 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005083 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005084 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005085 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005086 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005087 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005088 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005089 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005090 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005091 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005092 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005093 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005094 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005095 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005096 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005097 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005098 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005099 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005100 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005101 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005102 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005103 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005104 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305105 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005106 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005107};
Ben Gamari27c202a2009-07-01 22:26:52 -04005108#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005109
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005110static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005111 const char *name;
5112 const struct file_operations *fops;
5113} i915_debugfs_files[] = {
5114 {"i915_wedged", &i915_wedged_fops},
5115 {"i915_max_freq", &i915_max_freq_fops},
5116 {"i915_min_freq", &i915_min_freq_fops},
5117 {"i915_cache_sharing", &i915_cache_sharing_fops},
5118 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005119 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5120 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005121 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5122 {"i915_error_state", &i915_error_state_fops},
5123 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005124 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005125 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5126 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5127 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005128 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005129 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5130 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5131 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005132};
5133
Damien Lespiau07144422013-10-15 18:55:40 +01005134void intel_display_crc_init(struct drm_device *dev)
5135{
5136 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005137 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005138
Damien Lespiau055e3932014-08-18 13:49:10 +01005139 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005140 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005141
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005142 pipe_crc->opened = false;
5143 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005144 init_waitqueue_head(&pipe_crc->wq);
5145 }
5146}
5147
Ben Gamari27c202a2009-07-01 22:26:52 -04005148int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005149{
Daniel Vetter34b96742013-07-04 20:49:44 +02005150 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005151
Ben Widawsky6d794d42011-04-25 11:25:56 -07005152 ret = i915_forcewake_create(minor->debugfs_root, minor);
5153 if (ret)
5154 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005155
Damien Lespiau07144422013-10-15 18:55:40 +01005156 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5157 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5158 if (ret)
5159 return ret;
5160 }
5161
Daniel Vetter34b96742013-07-04 20:49:44 +02005162 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5163 ret = i915_debugfs_create(minor->debugfs_root, minor,
5164 i915_debugfs_files[i].name,
5165 i915_debugfs_files[i].fops);
5166 if (ret)
5167 return ret;
5168 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005169
Ben Gamari27c202a2009-07-01 22:26:52 -04005170 return drm_debugfs_create_files(i915_debugfs_list,
5171 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005172 minor->debugfs_root, minor);
5173}
5174
Ben Gamari27c202a2009-07-01 22:26:52 -04005175void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005176{
Daniel Vetter34b96742013-07-04 20:49:44 +02005177 int i;
5178
Ben Gamari27c202a2009-07-01 22:26:52 -04005179 drm_debugfs_remove_files(i915_debugfs_list,
5180 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005181
Ben Widawsky6d794d42011-04-25 11:25:56 -07005182 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5183 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005184
Daniel Vettere309a992013-10-16 22:55:51 +02005185 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005186 struct drm_info_list *info_list =
5187 (struct drm_info_list *)&i915_pipe_crc_data[i];
5188
5189 drm_debugfs_remove_files(info_list, 1, minor);
5190 }
5191
Daniel Vetter34b96742013-07-04 20:49:44 +02005192 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5193 struct drm_info_list *info_list =
5194 (struct drm_info_list *) i915_debugfs_files[i].fops;
5195
5196 drm_debugfs_remove_files(info_list, 1, minor);
5197 }
Ben Gamari20172632009-02-17 20:08:50 -05005198}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005199
5200struct dpcd_block {
5201 /* DPCD dump start address. */
5202 unsigned int offset;
5203 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5204 unsigned int end;
5205 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5206 size_t size;
5207 /* Only valid for eDP. */
5208 bool edp;
5209};
5210
5211static const struct dpcd_block i915_dpcd_debug[] = {
5212 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5213 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5214 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5215 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5216 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5217 { .offset = DP_SET_POWER },
5218 { .offset = DP_EDP_DPCD_REV },
5219 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5220 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5221 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5222};
5223
5224static int i915_dpcd_show(struct seq_file *m, void *data)
5225{
5226 struct drm_connector *connector = m->private;
5227 struct intel_dp *intel_dp =
5228 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5229 uint8_t buf[16];
5230 ssize_t err;
5231 int i;
5232
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005233 if (connector->status != connector_status_connected)
5234 return -ENODEV;
5235
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005236 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5237 const struct dpcd_block *b = &i915_dpcd_debug[i];
5238 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5239
5240 if (b->edp &&
5241 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5242 continue;
5243
5244 /* low tech for now */
5245 if (WARN_ON(size > sizeof(buf)))
5246 continue;
5247
5248 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5249 if (err <= 0) {
5250 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5251 size, b->offset, err);
5252 continue;
5253 }
5254
5255 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005256 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005257
5258 return 0;
5259}
5260
5261static int i915_dpcd_open(struct inode *inode, struct file *file)
5262{
5263 return single_open(file, i915_dpcd_show, inode->i_private);
5264}
5265
5266static const struct file_operations i915_dpcd_fops = {
5267 .owner = THIS_MODULE,
5268 .open = i915_dpcd_open,
5269 .read = seq_read,
5270 .llseek = seq_lseek,
5271 .release = single_release,
5272};
5273
5274/**
5275 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5276 * @connector: pointer to a registered drm_connector
5277 *
5278 * Cleanup will be done by drm_connector_unregister() through a call to
5279 * drm_debugfs_connector_remove().
5280 *
5281 * Returns 0 on success, negative error codes on error.
5282 */
5283int i915_debugfs_connector_add(struct drm_connector *connector)
5284{
5285 struct dentry *root = connector->debugfs_entry;
5286
5287 /* The connector must have been registered beforehands. */
5288 if (!root)
5289 return -ENODEV;
5290
5291 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5292 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5293 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5294 &i915_dpcd_fops);
5295
5296 return 0;
5297}