blob: 27f0a0d98e3ac705eb64bdaac43ec40928de1adc [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;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001735 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001736 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1737 else if (IS_I915GM(dev))
1738 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1739 else if (IS_PINEVIEW(dev))
1740 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1741
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001742 intel_runtime_pm_put(dev_priv);
1743
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001744 seq_printf(m, "self-refresh: %s\n",
1745 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001746
1747 return 0;
1748}
1749
Jesse Barnes7648fa92010-05-20 14:28:11 -07001750static int i915_emon_status(struct seq_file *m, void *unused)
1751{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001752 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001753 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001754 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001755 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001756 int ret;
1757
Chris Wilson582be6b2012-04-30 19:35:02 +01001758 if (!IS_GEN5(dev))
1759 return -ENODEV;
1760
Chris Wilsonde227ef2010-07-03 07:58:38 +01001761 ret = mutex_lock_interruptible(&dev->struct_mutex);
1762 if (ret)
1763 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001764
1765 temp = i915_mch_val(dev_priv);
1766 chipset = i915_chipset_val(dev_priv);
1767 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001768 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001769
1770 seq_printf(m, "GMCH temp: %ld\n", temp);
1771 seq_printf(m, "Chipset power: %ld\n", chipset);
1772 seq_printf(m, "GFX power: %ld\n", gfx);
1773 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1774
1775 return 0;
1776}
1777
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001778static int i915_ring_freq_table(struct seq_file *m, void *unused)
1779{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001780 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001781 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001782 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001783 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001784 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301785 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001786
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001787 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001788 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001789 return 0;
1790 }
1791
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001792 intel_runtime_pm_get(dev_priv);
1793
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001794 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1795
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001796 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001797 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001798 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001799
Akash Goelf936ec32015-06-29 14:50:22 +05301800 if (IS_SKYLAKE(dev)) {
1801 /* Convert GT frequency to 50 HZ units */
1802 min_gpu_freq =
1803 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1804 max_gpu_freq =
1805 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1806 } else {
1807 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1808 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1809 }
1810
Damien Lespiau267f0c92013-06-24 22:59:48 +01001811 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001812
Akash Goelf936ec32015-06-29 14:50:22 +05301813 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001814 ia_freq = gpu_freq;
1815 sandybridge_pcode_read(dev_priv,
1816 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1817 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001818 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301819 intel_gpu_freq(dev_priv, (gpu_freq *
1820 (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001821 ((ia_freq >> 0) & 0xff) * 100,
1822 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001823 }
1824
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001825 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001826
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001827out:
1828 intel_runtime_pm_put(dev_priv);
1829 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001830}
1831
Chris Wilson44834a62010-08-19 16:09:23 +01001832static int i915_opregion(struct seq_file *m, void *unused)
1833{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001834 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001835 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001836 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001837 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001838 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001839 int ret;
1840
Daniel Vetter0d38f002012-04-21 22:49:10 +02001841 if (data == NULL)
1842 return -ENOMEM;
1843
Chris Wilson44834a62010-08-19 16:09:23 +01001844 ret = mutex_lock_interruptible(&dev->struct_mutex);
1845 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001846 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001847
Daniel Vetter0d38f002012-04-21 22:49:10 +02001848 if (opregion->header) {
1849 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1850 seq_write(m, data, OPREGION_SIZE);
1851 }
Chris Wilson44834a62010-08-19 16:09:23 +01001852
1853 mutex_unlock(&dev->struct_mutex);
1854
Daniel Vetter0d38f002012-04-21 22:49:10 +02001855out:
1856 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001857 return 0;
1858}
1859
Chris Wilson37811fc2010-08-25 22:45:57 +01001860static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1861{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001862 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001863 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001864 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001865 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001866
Daniel Vetter4520f532013-10-09 09:18:51 +02001867#ifdef CONFIG_DRM_I915_FBDEV
1868 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001869
1870 ifbdev = dev_priv->fbdev;
1871 fb = to_intel_framebuffer(ifbdev->helper.fb);
1872
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001873 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 +01001874 fb->base.width,
1875 fb->base.height,
1876 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001877 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001878 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001879 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001880 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001881 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001882#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001883
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001884 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001885 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001886 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001887 continue;
1888
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001889 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 +01001890 fb->base.width,
1891 fb->base.height,
1892 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001893 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001894 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001895 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001896 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001897 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001898 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001899 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001900
1901 return 0;
1902}
1903
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001904static void describe_ctx_ringbuf(struct seq_file *m,
1905 struct intel_ringbuffer *ringbuf)
1906{
1907 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1908 ringbuf->space, ringbuf->head, ringbuf->tail,
1909 ringbuf->last_retired_head);
1910}
1911
Ben Widawskye76d3632011-03-19 18:14:29 -07001912static int i915_context_status(struct seq_file *m, void *unused)
1913{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001914 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001915 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001916 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001917 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001918 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001919 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001920
Daniel Vetterf3d28872014-05-29 23:23:08 +02001921 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001922 if (ret)
1923 return ret;
1924
Ben Widawskya33afea2013-09-17 21:12:45 -07001925 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001926 if (!i915.enable_execlists &&
1927 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001928 continue;
1929
Ben Widawskya33afea2013-09-17 21:12:45 -07001930 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001931 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001932 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001933 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001934 seq_printf(m, "(default context %s) ",
1935 ring->name);
1936 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001937
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001938 if (i915.enable_execlists) {
1939 seq_putc(m, '\n');
1940 for_each_ring(ring, dev_priv, i) {
1941 struct drm_i915_gem_object *ctx_obj =
1942 ctx->engine[i].state;
1943 struct intel_ringbuffer *ringbuf =
1944 ctx->engine[i].ringbuf;
1945
1946 seq_printf(m, "%s: ", ring->name);
1947 if (ctx_obj)
1948 describe_obj(m, ctx_obj);
1949 if (ringbuf)
1950 describe_ctx_ringbuf(m, ringbuf);
1951 seq_putc(m, '\n');
1952 }
1953 } else {
1954 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1955 }
1956
Ben Widawskya33afea2013-09-17 21:12:45 -07001957 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001958 }
1959
Daniel Vetterf3d28872014-05-29 23:23:08 +02001960 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001961
1962 return 0;
1963}
1964
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001965static void i915_dump_lrc_obj(struct seq_file *m,
1966 struct intel_engine_cs *ring,
1967 struct drm_i915_gem_object *ctx_obj)
1968{
1969 struct page *page;
1970 uint32_t *reg_state;
1971 int j;
1972 unsigned long ggtt_offset = 0;
1973
1974 if (ctx_obj == NULL) {
1975 seq_printf(m, "Context on %s with no gem object\n",
1976 ring->name);
1977 return;
1978 }
1979
1980 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1981 intel_execlists_ctx_id(ctx_obj));
1982
1983 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1984 seq_puts(m, "\tNot bound in GGTT\n");
1985 else
1986 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1987
1988 if (i915_gem_object_get_pages(ctx_obj)) {
1989 seq_puts(m, "\tFailed to get pages for context object\n");
1990 return;
1991 }
1992
1993 page = i915_gem_object_get_page(ctx_obj, 1);
1994 if (!WARN_ON(page == NULL)) {
1995 reg_state = kmap_atomic(page);
1996
1997 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
1998 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1999 ggtt_offset + 4096 + (j * 4),
2000 reg_state[j], reg_state[j + 1],
2001 reg_state[j + 2], reg_state[j + 3]);
2002 }
2003 kunmap_atomic(reg_state);
2004 }
2005
2006 seq_putc(m, '\n');
2007}
2008
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002009static int i915_dump_lrc(struct seq_file *m, void *unused)
2010{
2011 struct drm_info_node *node = (struct drm_info_node *) m->private;
2012 struct drm_device *dev = node->minor->dev;
2013 struct drm_i915_private *dev_priv = dev->dev_private;
2014 struct intel_engine_cs *ring;
2015 struct intel_context *ctx;
2016 int ret, i;
2017
2018 if (!i915.enable_execlists) {
2019 seq_printf(m, "Logical Ring Contexts are disabled\n");
2020 return 0;
2021 }
2022
2023 ret = mutex_lock_interruptible(&dev->struct_mutex);
2024 if (ret)
2025 return ret;
2026
2027 list_for_each_entry(ctx, &dev_priv->context_list, link) {
2028 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002029 if (ring->default_context != ctx)
2030 i915_dump_lrc_obj(m, ring,
2031 ctx->engine[i].state);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002032 }
2033 }
2034
2035 mutex_unlock(&dev->struct_mutex);
2036
2037 return 0;
2038}
2039
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002040static int i915_execlists(struct seq_file *m, void *data)
2041{
2042 struct drm_info_node *node = (struct drm_info_node *)m->private;
2043 struct drm_device *dev = node->minor->dev;
2044 struct drm_i915_private *dev_priv = dev->dev_private;
2045 struct intel_engine_cs *ring;
2046 u32 status_pointer;
2047 u8 read_pointer;
2048 u8 write_pointer;
2049 u32 status;
2050 u32 ctx_id;
2051 struct list_head *cursor;
2052 int ring_id, i;
2053 int ret;
2054
2055 if (!i915.enable_execlists) {
2056 seq_puts(m, "Logical Ring Contexts are disabled\n");
2057 return 0;
2058 }
2059
2060 ret = mutex_lock_interruptible(&dev->struct_mutex);
2061 if (ret)
2062 return ret;
2063
Michel Thierryfc0412e2014-10-16 16:13:38 +01002064 intel_runtime_pm_get(dev_priv);
2065
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002066 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002067 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002068 int count = 0;
2069 unsigned long flags;
2070
2071 seq_printf(m, "%s\n", ring->name);
2072
2073 status = I915_READ(RING_EXECLIST_STATUS(ring));
2074 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
2075 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2076 status, ctx_id);
2077
2078 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2079 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2080
2081 read_pointer = ring->next_context_status_buffer;
2082 write_pointer = status_pointer & 0x07;
2083 if (read_pointer > write_pointer)
2084 write_pointer += 6;
2085 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2086 read_pointer, write_pointer);
2087
2088 for (i = 0; i < 6; i++) {
2089 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
2090 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
2091
2092 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2093 i, status, ctx_id);
2094 }
2095
2096 spin_lock_irqsave(&ring->execlist_lock, flags);
2097 list_for_each(cursor, &ring->execlist_queue)
2098 count++;
2099 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002100 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002101 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2102
2103 seq_printf(m, "\t%d requests in queue\n", count);
2104 if (head_req) {
2105 struct drm_i915_gem_object *ctx_obj;
2106
Nick Hoath6d3d8272015-01-15 13:10:39 +00002107 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002108 seq_printf(m, "\tHead request id: %u\n",
2109 intel_execlists_ctx_id(ctx_obj));
2110 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002111 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002112 }
2113
2114 seq_putc(m, '\n');
2115 }
2116
Michel Thierryfc0412e2014-10-16 16:13:38 +01002117 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002118 mutex_unlock(&dev->struct_mutex);
2119
2120 return 0;
2121}
2122
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002123static const char *swizzle_string(unsigned swizzle)
2124{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002125 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002126 case I915_BIT_6_SWIZZLE_NONE:
2127 return "none";
2128 case I915_BIT_6_SWIZZLE_9:
2129 return "bit9";
2130 case I915_BIT_6_SWIZZLE_9_10:
2131 return "bit9/bit10";
2132 case I915_BIT_6_SWIZZLE_9_11:
2133 return "bit9/bit11";
2134 case I915_BIT_6_SWIZZLE_9_10_11:
2135 return "bit9/bit10/bit11";
2136 case I915_BIT_6_SWIZZLE_9_17:
2137 return "bit9/bit17";
2138 case I915_BIT_6_SWIZZLE_9_10_17:
2139 return "bit9/bit10/bit17";
2140 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002141 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002142 }
2143
2144 return "bug";
2145}
2146
2147static int i915_swizzle_info(struct seq_file *m, void *data)
2148{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002149 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002150 struct drm_device *dev = node->minor->dev;
2151 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002152 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002153
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002154 ret = mutex_lock_interruptible(&dev->struct_mutex);
2155 if (ret)
2156 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002157 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002158
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002159 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2160 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2161 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2162 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2163
2164 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2165 seq_printf(m, "DDC = 0x%08x\n",
2166 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002167 seq_printf(m, "DDC2 = 0x%08x\n",
2168 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002169 seq_printf(m, "C0DRB3 = 0x%04x\n",
2170 I915_READ16(C0DRB3));
2171 seq_printf(m, "C1DRB3 = 0x%04x\n",
2172 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002173 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002174 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2175 I915_READ(MAD_DIMM_C0));
2176 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2177 I915_READ(MAD_DIMM_C1));
2178 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2179 I915_READ(MAD_DIMM_C2));
2180 seq_printf(m, "TILECTL = 0x%08x\n",
2181 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002182 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002183 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2184 I915_READ(GAMTARBMODE));
2185 else
2186 seq_printf(m, "ARB_MODE = 0x%08x\n",
2187 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002188 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2189 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002190 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002191
2192 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2193 seq_puts(m, "L-shaped memory detected\n");
2194
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002195 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002196 mutex_unlock(&dev->struct_mutex);
2197
2198 return 0;
2199}
2200
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002201static int per_file_ctx(int id, void *ptr, void *data)
2202{
Oscar Mateo273497e2014-05-22 14:13:37 +01002203 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002204 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002205 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2206
2207 if (!ppgtt) {
2208 seq_printf(m, " no ppgtt for context %d\n",
2209 ctx->user_handle);
2210 return 0;
2211 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002212
Oscar Mateof83d6512014-05-22 14:13:38 +01002213 if (i915_gem_context_is_default(ctx))
2214 seq_puts(m, " default context:\n");
2215 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002216 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002217 ppgtt->debug_dump(ppgtt, m);
2218
2219 return 0;
2220}
2221
Ben Widawsky77df6772013-11-02 21:07:30 -07002222static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002223{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002224 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002225 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002226 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2227 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002228
Ben Widawsky77df6772013-11-02 21:07:30 -07002229 if (!ppgtt)
2230 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002231
Ben Widawsky77df6772013-11-02 21:07:30 -07002232 for_each_ring(ring, dev_priv, unused) {
2233 seq_printf(m, "%s\n", ring->name);
2234 for (i = 0; i < 4; i++) {
2235 u32 offset = 0x270 + i * 8;
2236 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2237 pdp <<= 32;
2238 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002239 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002240 }
2241 }
2242}
2243
2244static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2245{
2246 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002247 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002248 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002249 int i;
2250
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002251 if (INTEL_INFO(dev)->gen == 6)
2252 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2253
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002254 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002255 seq_printf(m, "%s\n", ring->name);
2256 if (INTEL_INFO(dev)->gen == 7)
2257 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2258 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2259 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2260 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2261 }
2262 if (dev_priv->mm.aliasing_ppgtt) {
2263 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2264
Damien Lespiau267f0c92013-06-24 22:59:48 +01002265 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002266 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002267
Ben Widawsky87d60b62013-12-06 14:11:29 -08002268 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002269 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002270
2271 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2272 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002273
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002274 seq_printf(m, "proc: %s\n",
2275 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002276 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002277 }
2278 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002279}
2280
2281static int i915_ppgtt_info(struct seq_file *m, void *data)
2282{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002283 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002284 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002285 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002286
2287 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2288 if (ret)
2289 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002290 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002291
2292 if (INTEL_INFO(dev)->gen >= 8)
2293 gen8_ppgtt_info(m, dev);
2294 else if (INTEL_INFO(dev)->gen >= 6)
2295 gen6_ppgtt_info(m, dev);
2296
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002297 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002298 mutex_unlock(&dev->struct_mutex);
2299
2300 return 0;
2301}
2302
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002303static int count_irq_waiters(struct drm_i915_private *i915)
2304{
2305 struct intel_engine_cs *ring;
2306 int count = 0;
2307 int i;
2308
2309 for_each_ring(ring, i915, i)
2310 count += ring->irq_refcount;
2311
2312 return count;
2313}
2314
Chris Wilson1854d5c2015-04-07 16:20:32 +01002315static int i915_rps_boost_info(struct seq_file *m, void *data)
2316{
2317 struct drm_info_node *node = m->private;
2318 struct drm_device *dev = node->minor->dev;
2319 struct drm_i915_private *dev_priv = dev->dev_private;
2320 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002321
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002322 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2323 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2324 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2325 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2326 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2327 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2328 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2329 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2330 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson8d3afd72015-05-21 21:01:47 +01002331 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002332 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2333 struct drm_i915_file_private *file_priv = file->driver_priv;
2334 struct task_struct *task;
2335
2336 rcu_read_lock();
2337 task = pid_task(file->pid, PIDTYPE_PID);
2338 seq_printf(m, "%s [%d]: %d boosts%s\n",
2339 task ? task->comm : "<unknown>",
2340 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002341 file_priv->rps.boosts,
2342 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002343 rcu_read_unlock();
2344 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002345 seq_printf(m, "Semaphore boosts: %d%s\n",
2346 dev_priv->rps.semaphores.boosts,
2347 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2348 seq_printf(m, "MMIO flip boosts: %d%s\n",
2349 dev_priv->rps.mmioflips.boosts,
2350 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002351 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002352 spin_unlock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002353
Chris Wilson8d3afd72015-05-21 21:01:47 +01002354 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002355}
2356
Ben Widawsky63573eb2013-07-04 11:02:07 -07002357static int i915_llc(struct seq_file *m, void *data)
2358{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002359 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002360 struct drm_device *dev = node->minor->dev;
2361 struct drm_i915_private *dev_priv = dev->dev_private;
2362
2363 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2364 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2365 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2366
2367 return 0;
2368}
2369
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002370static int i915_edp_psr_status(struct seq_file *m, void *data)
2371{
2372 struct drm_info_node *node = m->private;
2373 struct drm_device *dev = node->minor->dev;
2374 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002375 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002376 u32 stat[3];
2377 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002378 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002379
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002380 if (!HAS_PSR(dev)) {
2381 seq_puts(m, "PSR not supported\n");
2382 return 0;
2383 }
2384
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002385 intel_runtime_pm_get(dev_priv);
2386
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002387 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002388 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2389 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002390 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002391 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002392 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2393 dev_priv->psr.busy_frontbuffer_bits);
2394 seq_printf(m, "Re-enable work scheduled: %s\n",
2395 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002396
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002397 if (HAS_DDI(dev))
2398 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2399 else {
2400 for_each_pipe(dev_priv, pipe) {
2401 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2402 VLV_EDP_PSR_CURR_STATE_MASK;
2403 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2404 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2405 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002406 }
2407 }
2408 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002409
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002410 if (!HAS_DDI(dev))
2411 for_each_pipe(dev_priv, pipe) {
2412 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2413 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2414 seq_printf(m, " pipe %c", pipe_name(pipe));
2415 }
2416 seq_puts(m, "\n");
2417
2418 /* CHV PSR has no kind of performance counter */
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002419 if (HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002420 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2421 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002422
2423 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2424 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002425 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002426
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002427 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002428 return 0;
2429}
2430
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002431static int i915_sink_crc(struct seq_file *m, void *data)
2432{
2433 struct drm_info_node *node = m->private;
2434 struct drm_device *dev = node->minor->dev;
2435 struct intel_encoder *encoder;
2436 struct intel_connector *connector;
2437 struct intel_dp *intel_dp = NULL;
2438 int ret;
2439 u8 crc[6];
2440
2441 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002442 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002443
2444 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2445 continue;
2446
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002447 if (!connector->base.encoder)
2448 continue;
2449
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002450 encoder = to_intel_encoder(connector->base.encoder);
2451 if (encoder->type != INTEL_OUTPUT_EDP)
2452 continue;
2453
2454 intel_dp = enc_to_intel_dp(&encoder->base);
2455
2456 ret = intel_dp_sink_crc(intel_dp, crc);
2457 if (ret)
2458 goto out;
2459
2460 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2461 crc[0], crc[1], crc[2],
2462 crc[3], crc[4], crc[5]);
2463 goto out;
2464 }
2465 ret = -ENODEV;
2466out:
2467 drm_modeset_unlock_all(dev);
2468 return ret;
2469}
2470
Jesse Barnesec013e72013-08-20 10:29:23 +01002471static int i915_energy_uJ(struct seq_file *m, void *data)
2472{
2473 struct drm_info_node *node = m->private;
2474 struct drm_device *dev = node->minor->dev;
2475 struct drm_i915_private *dev_priv = dev->dev_private;
2476 u64 power;
2477 u32 units;
2478
2479 if (INTEL_INFO(dev)->gen < 6)
2480 return -ENODEV;
2481
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002482 intel_runtime_pm_get(dev_priv);
2483
Jesse Barnesec013e72013-08-20 10:29:23 +01002484 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2485 power = (power & 0x1f00) >> 8;
2486 units = 1000000 / (1 << power); /* convert to uJ */
2487 power = I915_READ(MCH_SECP_NRG_STTS);
2488 power *= units;
2489
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002490 intel_runtime_pm_put(dev_priv);
2491
Jesse Barnesec013e72013-08-20 10:29:23 +01002492 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002493
2494 return 0;
2495}
2496
Damien Lespiau6455c872015-06-04 18:23:57 +01002497static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002498{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002499 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002500 struct drm_device *dev = node->minor->dev;
2501 struct drm_i915_private *dev_priv = dev->dev_private;
2502
Damien Lespiau6455c872015-06-04 18:23:57 +01002503 if (!HAS_RUNTIME_PM(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002504 seq_puts(m, "not supported\n");
2505 return 0;
2506 }
2507
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002508 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002509 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002510 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002511#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002512 seq_printf(m, "Usage count: %d\n",
2513 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002514#else
2515 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2516#endif
Paulo Zanoni371db662013-08-19 13:18:10 -03002517
Jesse Barnesec013e72013-08-20 10:29:23 +01002518 return 0;
2519}
2520
Imre Deak1da51582013-11-25 17:15:35 +02002521static const char *power_domain_str(enum intel_display_power_domain domain)
2522{
2523 switch (domain) {
2524 case POWER_DOMAIN_PIPE_A:
2525 return "PIPE_A";
2526 case POWER_DOMAIN_PIPE_B:
2527 return "PIPE_B";
2528 case POWER_DOMAIN_PIPE_C:
2529 return "PIPE_C";
2530 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2531 return "PIPE_A_PANEL_FITTER";
2532 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2533 return "PIPE_B_PANEL_FITTER";
2534 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2535 return "PIPE_C_PANEL_FITTER";
2536 case POWER_DOMAIN_TRANSCODER_A:
2537 return "TRANSCODER_A";
2538 case POWER_DOMAIN_TRANSCODER_B:
2539 return "TRANSCODER_B";
2540 case POWER_DOMAIN_TRANSCODER_C:
2541 return "TRANSCODER_C";
2542 case POWER_DOMAIN_TRANSCODER_EDP:
2543 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002544 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2545 return "PORT_DDI_A_2_LANES";
2546 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2547 return "PORT_DDI_A_4_LANES";
2548 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2549 return "PORT_DDI_B_2_LANES";
2550 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2551 return "PORT_DDI_B_4_LANES";
2552 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2553 return "PORT_DDI_C_2_LANES";
2554 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2555 return "PORT_DDI_C_4_LANES";
2556 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2557 return "PORT_DDI_D_2_LANES";
2558 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2559 return "PORT_DDI_D_4_LANES";
2560 case POWER_DOMAIN_PORT_DSI:
2561 return "PORT_DSI";
2562 case POWER_DOMAIN_PORT_CRT:
2563 return "PORT_CRT";
2564 case POWER_DOMAIN_PORT_OTHER:
2565 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002566 case POWER_DOMAIN_VGA:
2567 return "VGA";
2568 case POWER_DOMAIN_AUDIO:
2569 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002570 case POWER_DOMAIN_PLLS:
2571 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002572 case POWER_DOMAIN_AUX_A:
2573 return "AUX_A";
2574 case POWER_DOMAIN_AUX_B:
2575 return "AUX_B";
2576 case POWER_DOMAIN_AUX_C:
2577 return "AUX_C";
2578 case POWER_DOMAIN_AUX_D:
2579 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002580 case POWER_DOMAIN_INIT:
2581 return "INIT";
2582 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002583 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002584 return "?";
2585 }
2586}
2587
2588static int i915_power_domain_info(struct seq_file *m, void *unused)
2589{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002590 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002591 struct drm_device *dev = node->minor->dev;
2592 struct drm_i915_private *dev_priv = dev->dev_private;
2593 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2594 int i;
2595
2596 mutex_lock(&power_domains->lock);
2597
2598 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2599 for (i = 0; i < power_domains->power_well_count; i++) {
2600 struct i915_power_well *power_well;
2601 enum intel_display_power_domain power_domain;
2602
2603 power_well = &power_domains->power_wells[i];
2604 seq_printf(m, "%-25s %d\n", power_well->name,
2605 power_well->count);
2606
2607 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2608 power_domain++) {
2609 if (!(BIT(power_domain) & power_well->domains))
2610 continue;
2611
2612 seq_printf(m, " %-23s %d\n",
2613 power_domain_str(power_domain),
2614 power_domains->domain_use_count[power_domain]);
2615 }
2616 }
2617
2618 mutex_unlock(&power_domains->lock);
2619
2620 return 0;
2621}
2622
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002623static void intel_seq_print_mode(struct seq_file *m, int tabs,
2624 struct drm_display_mode *mode)
2625{
2626 int i;
2627
2628 for (i = 0; i < tabs; i++)
2629 seq_putc(m, '\t');
2630
2631 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",
2632 mode->base.id, mode->name,
2633 mode->vrefresh, mode->clock,
2634 mode->hdisplay, mode->hsync_start,
2635 mode->hsync_end, mode->htotal,
2636 mode->vdisplay, mode->vsync_start,
2637 mode->vsync_end, mode->vtotal,
2638 mode->type, mode->flags);
2639}
2640
2641static void intel_encoder_info(struct seq_file *m,
2642 struct intel_crtc *intel_crtc,
2643 struct intel_encoder *intel_encoder)
2644{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002645 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002646 struct drm_device *dev = node->minor->dev;
2647 struct drm_crtc *crtc = &intel_crtc->base;
2648 struct intel_connector *intel_connector;
2649 struct drm_encoder *encoder;
2650
2651 encoder = &intel_encoder->base;
2652 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002653 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002654 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2655 struct drm_connector *connector = &intel_connector->base;
2656 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2657 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002658 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002659 drm_get_connector_status_name(connector->status));
2660 if (connector->status == connector_status_connected) {
2661 struct drm_display_mode *mode = &crtc->mode;
2662 seq_printf(m, ", mode:\n");
2663 intel_seq_print_mode(m, 2, mode);
2664 } else {
2665 seq_putc(m, '\n');
2666 }
2667 }
2668}
2669
2670static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2671{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002672 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002673 struct drm_device *dev = node->minor->dev;
2674 struct drm_crtc *crtc = &intel_crtc->base;
2675 struct intel_encoder *intel_encoder;
2676
Matt Roper5aa8a932014-06-16 10:12:55 -07002677 if (crtc->primary->fb)
2678 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2679 crtc->primary->fb->base.id, crtc->x, crtc->y,
2680 crtc->primary->fb->width, crtc->primary->fb->height);
2681 else
2682 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002683 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2684 intel_encoder_info(m, intel_crtc, intel_encoder);
2685}
2686
2687static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2688{
2689 struct drm_display_mode *mode = panel->fixed_mode;
2690
2691 seq_printf(m, "\tfixed mode:\n");
2692 intel_seq_print_mode(m, 2, mode);
2693}
2694
2695static void intel_dp_info(struct seq_file *m,
2696 struct intel_connector *intel_connector)
2697{
2698 struct intel_encoder *intel_encoder = intel_connector->encoder;
2699 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2700
2701 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2702 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2703 "no");
2704 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2705 intel_panel_info(m, &intel_connector->panel);
2706}
2707
2708static void intel_hdmi_info(struct seq_file *m,
2709 struct intel_connector *intel_connector)
2710{
2711 struct intel_encoder *intel_encoder = intel_connector->encoder;
2712 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2713
2714 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2715 "no");
2716}
2717
2718static void intel_lvds_info(struct seq_file *m,
2719 struct intel_connector *intel_connector)
2720{
2721 intel_panel_info(m, &intel_connector->panel);
2722}
2723
2724static void intel_connector_info(struct seq_file *m,
2725 struct drm_connector *connector)
2726{
2727 struct intel_connector *intel_connector = to_intel_connector(connector);
2728 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002729 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002730
2731 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002732 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002733 drm_get_connector_status_name(connector->status));
2734 if (connector->status == connector_status_connected) {
2735 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2736 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2737 connector->display_info.width_mm,
2738 connector->display_info.height_mm);
2739 seq_printf(m, "\tsubpixel order: %s\n",
2740 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2741 seq_printf(m, "\tCEA rev: %d\n",
2742 connector->display_info.cea_rev);
2743 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002744 if (intel_encoder) {
2745 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2746 intel_encoder->type == INTEL_OUTPUT_EDP)
2747 intel_dp_info(m, intel_connector);
2748 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2749 intel_hdmi_info(m, intel_connector);
2750 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2751 intel_lvds_info(m, intel_connector);
2752 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002753
Jesse Barnesf103fc72014-02-20 12:39:57 -08002754 seq_printf(m, "\tmodes:\n");
2755 list_for_each_entry(mode, &connector->modes, head)
2756 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002757}
2758
Chris Wilson065f2ec22014-03-12 09:13:13 +00002759static bool cursor_active(struct drm_device *dev, int pipe)
2760{
2761 struct drm_i915_private *dev_priv = dev->dev_private;
2762 u32 state;
2763
2764 if (IS_845G(dev) || IS_I865G(dev))
2765 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002766 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002767 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002768
2769 return state;
2770}
2771
2772static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2773{
2774 struct drm_i915_private *dev_priv = dev->dev_private;
2775 u32 pos;
2776
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002777 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00002778
2779 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2780 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2781 *x = -*x;
2782
2783 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2784 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2785 *y = -*y;
2786
2787 return cursor_active(dev, pipe);
2788}
2789
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002790static int i915_display_info(struct seq_file *m, void *unused)
2791{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002792 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002793 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002794 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002795 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002796 struct drm_connector *connector;
2797
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002798 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002799 drm_modeset_lock_all(dev);
2800 seq_printf(m, "CRTC info\n");
2801 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002802 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002803 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002804 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002805 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002806
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002807 pipe_config = to_intel_crtc_state(crtc->base.state);
2808
Chris Wilson57127ef2014-07-04 08:20:11 +01002809 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00002810 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002811 yesno(pipe_config->base.active),
2812 pipe_config->pipe_src_w, pipe_config->pipe_src_h);
2813 if (pipe_config->base.active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002814 intel_crtc_info(m, crtc);
2815
Paulo Zanonia23dc652014-04-01 14:55:11 -03002816 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002817 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 +03002818 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08002819 x, y, crtc->base.cursor->state->crtc_w,
2820 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01002821 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002822 }
Daniel Vettercace8412014-05-22 17:56:31 +02002823
2824 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2825 yesno(!crtc->cpu_fifo_underrun_disabled),
2826 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002827 }
2828
2829 seq_printf(m, "\n");
2830 seq_printf(m, "Connector info\n");
2831 seq_printf(m, "--------------\n");
2832 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2833 intel_connector_info(m, connector);
2834 }
2835 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002836 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002837
2838 return 0;
2839}
2840
Ben Widawskye04934c2014-06-30 09:53:42 -07002841static int i915_semaphore_status(struct seq_file *m, void *unused)
2842{
2843 struct drm_info_node *node = (struct drm_info_node *) m->private;
2844 struct drm_device *dev = node->minor->dev;
2845 struct drm_i915_private *dev_priv = dev->dev_private;
2846 struct intel_engine_cs *ring;
2847 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2848 int i, j, ret;
2849
2850 if (!i915_semaphore_is_enabled(dev)) {
2851 seq_puts(m, "Semaphores are disabled\n");
2852 return 0;
2853 }
2854
2855 ret = mutex_lock_interruptible(&dev->struct_mutex);
2856 if (ret)
2857 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002858 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002859
2860 if (IS_BROADWELL(dev)) {
2861 struct page *page;
2862 uint64_t *seqno;
2863
2864 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2865
2866 seqno = (uint64_t *)kmap_atomic(page);
2867 for_each_ring(ring, dev_priv, i) {
2868 uint64_t offset;
2869
2870 seq_printf(m, "%s\n", ring->name);
2871
2872 seq_puts(m, " Last signal:");
2873 for (j = 0; j < num_rings; j++) {
2874 offset = i * I915_NUM_RINGS + j;
2875 seq_printf(m, "0x%08llx (0x%02llx) ",
2876 seqno[offset], offset * 8);
2877 }
2878 seq_putc(m, '\n');
2879
2880 seq_puts(m, " Last wait: ");
2881 for (j = 0; j < num_rings; j++) {
2882 offset = i + (j * I915_NUM_RINGS);
2883 seq_printf(m, "0x%08llx (0x%02llx) ",
2884 seqno[offset], offset * 8);
2885 }
2886 seq_putc(m, '\n');
2887
2888 }
2889 kunmap_atomic(seqno);
2890 } else {
2891 seq_puts(m, " Last signal:");
2892 for_each_ring(ring, dev_priv, i)
2893 for (j = 0; j < num_rings; j++)
2894 seq_printf(m, "0x%08x\n",
2895 I915_READ(ring->semaphore.mbox.signal[j]));
2896 seq_putc(m, '\n');
2897 }
2898
2899 seq_puts(m, "\nSync seqno:\n");
2900 for_each_ring(ring, dev_priv, i) {
2901 for (j = 0; j < num_rings; j++) {
2902 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2903 }
2904 seq_putc(m, '\n');
2905 }
2906 seq_putc(m, '\n');
2907
Paulo Zanoni03872062014-07-09 14:31:57 -03002908 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002909 mutex_unlock(&dev->struct_mutex);
2910 return 0;
2911}
2912
Daniel Vetter728e29d2014-06-25 22:01:53 +03002913static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2914{
2915 struct drm_info_node *node = (struct drm_info_node *) m->private;
2916 struct drm_device *dev = node->minor->dev;
2917 struct drm_i915_private *dev_priv = dev->dev_private;
2918 int i;
2919
2920 drm_modeset_lock_all(dev);
2921 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2922 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2923
2924 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002925 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002926 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03002927 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002928 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2929 seq_printf(m, " dpll_md: 0x%08x\n",
2930 pll->config.hw_state.dpll_md);
2931 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2932 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2933 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002934 }
2935 drm_modeset_unlock_all(dev);
2936
2937 return 0;
2938}
2939
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01002940static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01002941{
2942 int i;
2943 int ret;
2944 struct drm_info_node *node = (struct drm_info_node *) m->private;
2945 struct drm_device *dev = node->minor->dev;
2946 struct drm_i915_private *dev_priv = dev->dev_private;
2947
Arun Siluvery888b5992014-08-26 14:44:51 +01002948 ret = mutex_lock_interruptible(&dev->struct_mutex);
2949 if (ret)
2950 return ret;
2951
2952 intel_runtime_pm_get(dev_priv);
2953
Mika Kuoppala72253422014-10-07 17:21:26 +03002954 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
2955 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002956 u32 addr, mask, value, read;
2957 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01002958
Mika Kuoppala72253422014-10-07 17:21:26 +03002959 addr = dev_priv->workarounds.reg[i].addr;
2960 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002961 value = dev_priv->workarounds.reg[i].value;
2962 read = I915_READ(addr);
2963 ok = (value & mask) == (read & mask);
2964 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
2965 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01002966 }
2967
2968 intel_runtime_pm_put(dev_priv);
2969 mutex_unlock(&dev->struct_mutex);
2970
2971 return 0;
2972}
2973
Damien Lespiauc5511e42014-11-04 17:06:51 +00002974static int i915_ddb_info(struct seq_file *m, void *unused)
2975{
2976 struct drm_info_node *node = m->private;
2977 struct drm_device *dev = node->minor->dev;
2978 struct drm_i915_private *dev_priv = dev->dev_private;
2979 struct skl_ddb_allocation *ddb;
2980 struct skl_ddb_entry *entry;
2981 enum pipe pipe;
2982 int plane;
2983
Damien Lespiau2fcffe12014-12-03 17:33:24 +00002984 if (INTEL_INFO(dev)->gen < 9)
2985 return 0;
2986
Damien Lespiauc5511e42014-11-04 17:06:51 +00002987 drm_modeset_lock_all(dev);
2988
2989 ddb = &dev_priv->wm.skl_hw.ddb;
2990
2991 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
2992
2993 for_each_pipe(dev_priv, pipe) {
2994 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
2995
Damien Lespiaudd740782015-02-28 14:54:08 +00002996 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00002997 entry = &ddb->plane[pipe][plane];
2998 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
2999 entry->start, entry->end,
3000 skl_ddb_entry_size(entry));
3001 }
3002
3003 entry = &ddb->cursor[pipe];
3004 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3005 entry->end, skl_ddb_entry_size(entry));
3006 }
3007
3008 drm_modeset_unlock_all(dev);
3009
3010 return 0;
3011}
3012
Vandana Kannana54746e2015-03-03 20:53:10 +05303013static void drrs_status_per_crtc(struct seq_file *m,
3014 struct drm_device *dev, struct intel_crtc *intel_crtc)
3015{
3016 struct intel_encoder *intel_encoder;
3017 struct drm_i915_private *dev_priv = dev->dev_private;
3018 struct i915_drrs *drrs = &dev_priv->drrs;
3019 int vrefresh = 0;
3020
3021 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3022 /* Encoder connected on this CRTC */
3023 switch (intel_encoder->type) {
3024 case INTEL_OUTPUT_EDP:
3025 seq_puts(m, "eDP:\n");
3026 break;
3027 case INTEL_OUTPUT_DSI:
3028 seq_puts(m, "DSI:\n");
3029 break;
3030 case INTEL_OUTPUT_HDMI:
3031 seq_puts(m, "HDMI:\n");
3032 break;
3033 case INTEL_OUTPUT_DISPLAYPORT:
3034 seq_puts(m, "DP:\n");
3035 break;
3036 default:
3037 seq_printf(m, "Other encoder (id=%d).\n",
3038 intel_encoder->type);
3039 return;
3040 }
3041 }
3042
3043 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3044 seq_puts(m, "\tVBT: DRRS_type: Static");
3045 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3046 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3047 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3048 seq_puts(m, "\tVBT: DRRS_type: None");
3049 else
3050 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3051
3052 seq_puts(m, "\n\n");
3053
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003054 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303055 struct intel_panel *panel;
3056
3057 mutex_lock(&drrs->mutex);
3058 /* DRRS Supported */
3059 seq_puts(m, "\tDRRS Supported: Yes\n");
3060
3061 /* disable_drrs() will make drrs->dp NULL */
3062 if (!drrs->dp) {
3063 seq_puts(m, "Idleness DRRS: Disabled");
3064 mutex_unlock(&drrs->mutex);
3065 return;
3066 }
3067
3068 panel = &drrs->dp->attached_connector->panel;
3069 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3070 drrs->busy_frontbuffer_bits);
3071
3072 seq_puts(m, "\n\t\t");
3073 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3074 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3075 vrefresh = panel->fixed_mode->vrefresh;
3076 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3077 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3078 vrefresh = panel->downclock_mode->vrefresh;
3079 } else {
3080 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3081 drrs->refresh_rate_type);
3082 mutex_unlock(&drrs->mutex);
3083 return;
3084 }
3085 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3086
3087 seq_puts(m, "\n\t\t");
3088 mutex_unlock(&drrs->mutex);
3089 } else {
3090 /* DRRS not supported. Print the VBT parameter*/
3091 seq_puts(m, "\tDRRS Supported : No");
3092 }
3093 seq_puts(m, "\n");
3094}
3095
3096static int i915_drrs_status(struct seq_file *m, void *unused)
3097{
3098 struct drm_info_node *node = m->private;
3099 struct drm_device *dev = node->minor->dev;
3100 struct intel_crtc *intel_crtc;
3101 int active_crtc_cnt = 0;
3102
3103 for_each_intel_crtc(dev, intel_crtc) {
3104 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3105
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003106 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303107 active_crtc_cnt++;
3108 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3109
3110 drrs_status_per_crtc(m, dev, intel_crtc);
3111 }
3112
3113 drm_modeset_unlock(&intel_crtc->base.mutex);
3114 }
3115
3116 if (!active_crtc_cnt)
3117 seq_puts(m, "No active crtc found\n");
3118
3119 return 0;
3120}
3121
Damien Lespiau07144422013-10-15 18:55:40 +01003122struct pipe_crc_info {
3123 const char *name;
3124 struct drm_device *dev;
3125 enum pipe pipe;
3126};
3127
Dave Airlie11bed952014-05-12 15:22:27 +10003128static int i915_dp_mst_info(struct seq_file *m, void *unused)
3129{
3130 struct drm_info_node *node = (struct drm_info_node *) m->private;
3131 struct drm_device *dev = node->minor->dev;
3132 struct drm_encoder *encoder;
3133 struct intel_encoder *intel_encoder;
3134 struct intel_digital_port *intel_dig_port;
3135 drm_modeset_lock_all(dev);
3136 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3137 intel_encoder = to_intel_encoder(encoder);
3138 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3139 continue;
3140 intel_dig_port = enc_to_dig_port(encoder);
3141 if (!intel_dig_port->dp.can_mst)
3142 continue;
3143
3144 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3145 }
3146 drm_modeset_unlock_all(dev);
3147 return 0;
3148}
3149
Damien Lespiau07144422013-10-15 18:55:40 +01003150static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003151{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003152 struct pipe_crc_info *info = inode->i_private;
3153 struct drm_i915_private *dev_priv = info->dev->dev_private;
3154 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3155
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003156 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3157 return -ENODEV;
3158
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003159 spin_lock_irq(&pipe_crc->lock);
3160
3161 if (pipe_crc->opened) {
3162 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003163 return -EBUSY; /* already open */
3164 }
3165
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003166 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003167 filep->private_data = inode->i_private;
3168
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003169 spin_unlock_irq(&pipe_crc->lock);
3170
Damien Lespiau07144422013-10-15 18:55:40 +01003171 return 0;
3172}
3173
3174static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3175{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003176 struct pipe_crc_info *info = inode->i_private;
3177 struct drm_i915_private *dev_priv = info->dev->dev_private;
3178 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3179
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003180 spin_lock_irq(&pipe_crc->lock);
3181 pipe_crc->opened = false;
3182 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003183
Damien Lespiau07144422013-10-15 18:55:40 +01003184 return 0;
3185}
3186
3187/* (6 fields, 8 chars each, space separated (5) + '\n') */
3188#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3189/* account for \'0' */
3190#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3191
3192static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3193{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003194 assert_spin_locked(&pipe_crc->lock);
3195 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3196 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003197}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003198
Damien Lespiau07144422013-10-15 18:55:40 +01003199static ssize_t
3200i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3201 loff_t *pos)
3202{
3203 struct pipe_crc_info *info = filep->private_data;
3204 struct drm_device *dev = info->dev;
3205 struct drm_i915_private *dev_priv = dev->dev_private;
3206 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3207 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003208 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003209 ssize_t bytes_read;
3210
3211 /*
3212 * Don't allow user space to provide buffers not big enough to hold
3213 * a line of data.
3214 */
3215 if (count < PIPE_CRC_LINE_LEN)
3216 return -EINVAL;
3217
3218 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3219 return 0;
3220
3221 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003222 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003223 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003224 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003225
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003226 if (filep->f_flags & O_NONBLOCK) {
3227 spin_unlock_irq(&pipe_crc->lock);
3228 return -EAGAIN;
3229 }
3230
3231 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3232 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3233 if (ret) {
3234 spin_unlock_irq(&pipe_crc->lock);
3235 return ret;
3236 }
Damien Lespiau07144422013-10-15 18:55:40 +01003237 }
3238
3239 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003240 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003241
Damien Lespiau07144422013-10-15 18:55:40 +01003242 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003243 while (n_entries > 0) {
3244 struct intel_pipe_crc_entry *entry =
3245 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003246 int ret;
3247
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003248 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3249 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3250 break;
3251
3252 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3253 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3254
Damien Lespiau07144422013-10-15 18:55:40 +01003255 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3256 "%8u %8x %8x %8x %8x %8x\n",
3257 entry->frame, entry->crc[0],
3258 entry->crc[1], entry->crc[2],
3259 entry->crc[3], entry->crc[4]);
3260
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003261 spin_unlock_irq(&pipe_crc->lock);
3262
3263 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003264 if (ret == PIPE_CRC_LINE_LEN)
3265 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003266
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003267 user_buf += PIPE_CRC_LINE_LEN;
3268 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003269
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003270 spin_lock_irq(&pipe_crc->lock);
3271 }
3272
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003273 spin_unlock_irq(&pipe_crc->lock);
3274
Damien Lespiau07144422013-10-15 18:55:40 +01003275 return bytes_read;
3276}
3277
3278static const struct file_operations i915_pipe_crc_fops = {
3279 .owner = THIS_MODULE,
3280 .open = i915_pipe_crc_open,
3281 .read = i915_pipe_crc_read,
3282 .release = i915_pipe_crc_release,
3283};
3284
3285static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3286 {
3287 .name = "i915_pipe_A_crc",
3288 .pipe = PIPE_A,
3289 },
3290 {
3291 .name = "i915_pipe_B_crc",
3292 .pipe = PIPE_B,
3293 },
3294 {
3295 .name = "i915_pipe_C_crc",
3296 .pipe = PIPE_C,
3297 },
3298};
3299
3300static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3301 enum pipe pipe)
3302{
3303 struct drm_device *dev = minor->dev;
3304 struct dentry *ent;
3305 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3306
3307 info->dev = dev;
3308 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3309 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003310 if (!ent)
3311 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003312
3313 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003314}
3315
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003316static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003317 "none",
3318 "plane1",
3319 "plane2",
3320 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003321 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003322 "TV",
3323 "DP-B",
3324 "DP-C",
3325 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003326 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003327};
3328
3329static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3330{
3331 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3332 return pipe_crc_sources[source];
3333}
3334
Damien Lespiaubd9db022013-10-15 18:55:36 +01003335static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003336{
3337 struct drm_device *dev = m->private;
3338 struct drm_i915_private *dev_priv = dev->dev_private;
3339 int i;
3340
3341 for (i = 0; i < I915_MAX_PIPES; i++)
3342 seq_printf(m, "%c %s\n", pipe_name(i),
3343 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3344
3345 return 0;
3346}
3347
Damien Lespiaubd9db022013-10-15 18:55:36 +01003348static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003349{
3350 struct drm_device *dev = inode->i_private;
3351
Damien Lespiaubd9db022013-10-15 18:55:36 +01003352 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003353}
3354
Daniel Vetter46a19182013-11-01 10:50:20 +01003355static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003356 uint32_t *val)
3357{
Daniel Vetter46a19182013-11-01 10:50:20 +01003358 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3359 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3360
3361 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003362 case INTEL_PIPE_CRC_SOURCE_PIPE:
3363 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3364 break;
3365 case INTEL_PIPE_CRC_SOURCE_NONE:
3366 *val = 0;
3367 break;
3368 default:
3369 return -EINVAL;
3370 }
3371
3372 return 0;
3373}
3374
Daniel Vetter46a19182013-11-01 10:50:20 +01003375static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3376 enum intel_pipe_crc_source *source)
3377{
3378 struct intel_encoder *encoder;
3379 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003380 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003381 int ret = 0;
3382
3383 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3384
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003385 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003386 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003387 if (!encoder->base.crtc)
3388 continue;
3389
3390 crtc = to_intel_crtc(encoder->base.crtc);
3391
3392 if (crtc->pipe != pipe)
3393 continue;
3394
3395 switch (encoder->type) {
3396 case INTEL_OUTPUT_TVOUT:
3397 *source = INTEL_PIPE_CRC_SOURCE_TV;
3398 break;
3399 case INTEL_OUTPUT_DISPLAYPORT:
3400 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003401 dig_port = enc_to_dig_port(&encoder->base);
3402 switch (dig_port->port) {
3403 case PORT_B:
3404 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3405 break;
3406 case PORT_C:
3407 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3408 break;
3409 case PORT_D:
3410 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3411 break;
3412 default:
3413 WARN(1, "nonexisting DP port %c\n",
3414 port_name(dig_port->port));
3415 break;
3416 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003417 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003418 default:
3419 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003420 }
3421 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003422 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003423
3424 return ret;
3425}
3426
3427static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3428 enum pipe pipe,
3429 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003430 uint32_t *val)
3431{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003432 struct drm_i915_private *dev_priv = dev->dev_private;
3433 bool need_stable_symbols = false;
3434
Daniel Vetter46a19182013-11-01 10:50:20 +01003435 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3436 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3437 if (ret)
3438 return ret;
3439 }
3440
3441 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003442 case INTEL_PIPE_CRC_SOURCE_PIPE:
3443 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3444 break;
3445 case INTEL_PIPE_CRC_SOURCE_DP_B:
3446 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003447 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003448 break;
3449 case INTEL_PIPE_CRC_SOURCE_DP_C:
3450 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003451 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003452 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003453 case INTEL_PIPE_CRC_SOURCE_DP_D:
3454 if (!IS_CHERRYVIEW(dev))
3455 return -EINVAL;
3456 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3457 need_stable_symbols = true;
3458 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003459 case INTEL_PIPE_CRC_SOURCE_NONE:
3460 *val = 0;
3461 break;
3462 default:
3463 return -EINVAL;
3464 }
3465
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003466 /*
3467 * When the pipe CRC tap point is after the transcoders we need
3468 * to tweak symbol-level features to produce a deterministic series of
3469 * symbols for a given frame. We need to reset those features only once
3470 * a frame (instead of every nth symbol):
3471 * - DC-balance: used to ensure a better clock recovery from the data
3472 * link (SDVO)
3473 * - DisplayPort scrambling: used for EMI reduction
3474 */
3475 if (need_stable_symbols) {
3476 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3477
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003478 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003479 switch (pipe) {
3480 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003481 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003482 break;
3483 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003484 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003485 break;
3486 case PIPE_C:
3487 tmp |= PIPE_C_SCRAMBLE_RESET;
3488 break;
3489 default:
3490 return -EINVAL;
3491 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003492 I915_WRITE(PORT_DFT2_G4X, tmp);
3493 }
3494
Daniel Vetter7ac01292013-10-18 16:37:06 +02003495 return 0;
3496}
3497
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003498static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003499 enum pipe pipe,
3500 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003501 uint32_t *val)
3502{
Daniel Vetter84093602013-11-01 10:50:21 +01003503 struct drm_i915_private *dev_priv = dev->dev_private;
3504 bool need_stable_symbols = false;
3505
Daniel Vetter46a19182013-11-01 10:50:20 +01003506 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3507 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3508 if (ret)
3509 return ret;
3510 }
3511
3512 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003513 case INTEL_PIPE_CRC_SOURCE_PIPE:
3514 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3515 break;
3516 case INTEL_PIPE_CRC_SOURCE_TV:
3517 if (!SUPPORTS_TV(dev))
3518 return -EINVAL;
3519 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3520 break;
3521 case INTEL_PIPE_CRC_SOURCE_DP_B:
3522 if (!IS_G4X(dev))
3523 return -EINVAL;
3524 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003525 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003526 break;
3527 case INTEL_PIPE_CRC_SOURCE_DP_C:
3528 if (!IS_G4X(dev))
3529 return -EINVAL;
3530 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003531 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003532 break;
3533 case INTEL_PIPE_CRC_SOURCE_DP_D:
3534 if (!IS_G4X(dev))
3535 return -EINVAL;
3536 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003537 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003538 break;
3539 case INTEL_PIPE_CRC_SOURCE_NONE:
3540 *val = 0;
3541 break;
3542 default:
3543 return -EINVAL;
3544 }
3545
Daniel Vetter84093602013-11-01 10:50:21 +01003546 /*
3547 * When the pipe CRC tap point is after the transcoders we need
3548 * to tweak symbol-level features to produce a deterministic series of
3549 * symbols for a given frame. We need to reset those features only once
3550 * a frame (instead of every nth symbol):
3551 * - DC-balance: used to ensure a better clock recovery from the data
3552 * link (SDVO)
3553 * - DisplayPort scrambling: used for EMI reduction
3554 */
3555 if (need_stable_symbols) {
3556 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3557
3558 WARN_ON(!IS_G4X(dev));
3559
3560 I915_WRITE(PORT_DFT_I9XX,
3561 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3562
3563 if (pipe == PIPE_A)
3564 tmp |= PIPE_A_SCRAMBLE_RESET;
3565 else
3566 tmp |= PIPE_B_SCRAMBLE_RESET;
3567
3568 I915_WRITE(PORT_DFT2_G4X, tmp);
3569 }
3570
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003571 return 0;
3572}
3573
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003574static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3575 enum pipe pipe)
3576{
3577 struct drm_i915_private *dev_priv = dev->dev_private;
3578 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3579
Ville Syrjäläeb736672014-12-09 21:28:28 +02003580 switch (pipe) {
3581 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003582 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003583 break;
3584 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003585 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003586 break;
3587 case PIPE_C:
3588 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3589 break;
3590 default:
3591 return;
3592 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003593 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3594 tmp &= ~DC_BALANCE_RESET_VLV;
3595 I915_WRITE(PORT_DFT2_G4X, tmp);
3596
3597}
3598
Daniel Vetter84093602013-11-01 10:50:21 +01003599static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3600 enum pipe pipe)
3601{
3602 struct drm_i915_private *dev_priv = dev->dev_private;
3603 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3604
3605 if (pipe == PIPE_A)
3606 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3607 else
3608 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3609 I915_WRITE(PORT_DFT2_G4X, tmp);
3610
3611 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3612 I915_WRITE(PORT_DFT_I9XX,
3613 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3614 }
3615}
3616
Daniel Vetter46a19182013-11-01 10:50:20 +01003617static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003618 uint32_t *val)
3619{
Daniel Vetter46a19182013-11-01 10:50:20 +01003620 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3621 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3622
3623 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003624 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3625 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3626 break;
3627 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3628 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3629 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003630 case INTEL_PIPE_CRC_SOURCE_PIPE:
3631 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3632 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003633 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003634 *val = 0;
3635 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003636 default:
3637 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003638 }
3639
3640 return 0;
3641}
3642
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003643static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3644{
3645 struct drm_i915_private *dev_priv = dev->dev_private;
3646 struct intel_crtc *crtc =
3647 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003648 struct intel_crtc_state *pipe_config;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003649
3650 drm_modeset_lock_all(dev);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003651 pipe_config = to_intel_crtc_state(crtc->base.state);
3652
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003653 /*
3654 * If we use the eDP transcoder we need to make sure that we don't
3655 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3656 * relevant on hsw with pipe A when using the always-on power well
3657 * routing.
3658 */
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003659 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
3660 !pipe_config->pch_pfit.enabled) {
3661 bool active = pipe_config->base.active;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003662
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003663 if (active) {
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003664 intel_crtc_control(&crtc->base, false);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003665 pipe_config = to_intel_crtc_state(crtc->base.state);
3666 }
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003667
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003668 pipe_config->pch_pfit.force_thru = true;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003669
3670 intel_display_power_get(dev_priv,
3671 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3672
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003673 if (active)
3674 intel_crtc_control(&crtc->base, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003675 }
3676 drm_modeset_unlock_all(dev);
3677}
3678
3679static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3680{
3681 struct drm_i915_private *dev_priv = dev->dev_private;
3682 struct intel_crtc *crtc =
3683 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003684 struct intel_crtc_state *pipe_config;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003685
3686 drm_modeset_lock_all(dev);
3687 /*
3688 * If we use the eDP transcoder we need to make sure that we don't
3689 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3690 * relevant on hsw with pipe A when using the always-on power well
3691 * routing.
3692 */
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003693 pipe_config = to_intel_crtc_state(crtc->base.state);
3694 if (pipe_config->pch_pfit.force_thru) {
3695 bool active = pipe_config->base.active;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003696
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003697 if (active) {
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003698 intel_crtc_control(&crtc->base, false);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003699 pipe_config = to_intel_crtc_state(crtc->base.state);
3700 }
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003701
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003702 pipe_config->pch_pfit.force_thru = false;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003703
3704 intel_display_power_put(dev_priv,
3705 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003706
3707 if (active)
3708 intel_crtc_control(&crtc->base, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003709 }
3710 drm_modeset_unlock_all(dev);
3711}
3712
3713static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3714 enum pipe pipe,
3715 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003716 uint32_t *val)
3717{
Daniel Vetter46a19182013-11-01 10:50:20 +01003718 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3719 *source = INTEL_PIPE_CRC_SOURCE_PF;
3720
3721 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003722 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3723 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3724 break;
3725 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3726 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3727 break;
3728 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003729 if (IS_HASWELL(dev) && pipe == PIPE_A)
3730 hsw_trans_edp_pipe_A_crc_wa(dev);
3731
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003732 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3733 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003734 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003735 *val = 0;
3736 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003737 default:
3738 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003739 }
3740
3741 return 0;
3742}
3743
Daniel Vetter926321d2013-10-16 13:30:34 +02003744static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3745 enum intel_pipe_crc_source source)
3746{
3747 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003748 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003749 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3750 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003751 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003752 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003753
Damien Lespiaucc3da172013-10-15 18:55:31 +01003754 if (pipe_crc->source == source)
3755 return 0;
3756
Damien Lespiauae676fc2013-10-15 18:55:32 +01003757 /* forbid changing the source without going back to 'none' */
3758 if (pipe_crc->source && source)
3759 return -EINVAL;
3760
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003761 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3762 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3763 return -EIO;
3764 }
3765
Daniel Vetter52f843f2013-10-21 17:26:38 +02003766 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003767 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003768 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003769 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003770 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003771 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003772 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003773 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003774 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003775 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003776
3777 if (ret != 0)
3778 return ret;
3779
Damien Lespiau4b584362013-10-15 18:55:33 +01003780 /* none -> real source transition */
3781 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003782 struct intel_pipe_crc_entry *entries;
3783
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003784 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3785 pipe_name(pipe), pipe_crc_source_name(source));
3786
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003787 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3788 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003789 GFP_KERNEL);
3790 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003791 return -ENOMEM;
3792
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003793 /*
3794 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3795 * enabled and disabled dynamically based on package C states,
3796 * user space can't make reliable use of the CRCs, so let's just
3797 * completely disable it.
3798 */
3799 hsw_disable_ips(crtc);
3800
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003801 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003802 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003803 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003804 pipe_crc->head = 0;
3805 pipe_crc->tail = 0;
3806 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003807 }
3808
Damien Lespiaucc3da172013-10-15 18:55:31 +01003809 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003810
Daniel Vetter926321d2013-10-16 13:30:34 +02003811 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3812 POSTING_READ(PIPE_CRC_CTL(pipe));
3813
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003814 /* real source -> none transition */
3815 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003816 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003817 struct intel_crtc *crtc =
3818 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003819
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003820 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3821 pipe_name(pipe));
3822
Daniel Vettera33d7102014-06-06 08:22:08 +02003823 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003824 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02003825 intel_wait_for_vblank(dev, pipe);
3826 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003827
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003828 spin_lock_irq(&pipe_crc->lock);
3829 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003830 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003831 pipe_crc->head = 0;
3832 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003833 spin_unlock_irq(&pipe_crc->lock);
3834
3835 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003836
3837 if (IS_G4X(dev))
3838 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003839 else if (IS_VALLEYVIEW(dev))
3840 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003841 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3842 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003843
3844 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003845 }
3846
Daniel Vetter926321d2013-10-16 13:30:34 +02003847 return 0;
3848}
3849
3850/*
3851 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003852 * command: wsp* object wsp+ name wsp+ source wsp*
3853 * object: 'pipe'
3854 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003855 * source: (none | plane1 | plane2 | pf)
3856 * wsp: (#0x20 | #0x9 | #0xA)+
3857 *
3858 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003859 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3860 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003861 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003862static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003863{
3864 int n_words = 0;
3865
3866 while (*buf) {
3867 char *end;
3868
3869 /* skip leading white space */
3870 buf = skip_spaces(buf);
3871 if (!*buf)
3872 break; /* end of buffer */
3873
3874 /* find end of word */
3875 for (end = buf; *end && !isspace(*end); end++)
3876 ;
3877
3878 if (n_words == max_words) {
3879 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3880 max_words);
3881 return -EINVAL; /* ran out of words[] before bytes */
3882 }
3883
3884 if (*end)
3885 *end++ = '\0';
3886 words[n_words++] = buf;
3887 buf = end;
3888 }
3889
3890 return n_words;
3891}
3892
Damien Lespiaub94dec82013-10-15 18:55:35 +01003893enum intel_pipe_crc_object {
3894 PIPE_CRC_OBJECT_PIPE,
3895};
3896
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003897static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003898 "pipe",
3899};
3900
3901static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003902display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003903{
3904 int i;
3905
3906 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3907 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003908 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003909 return 0;
3910 }
3911
3912 return -EINVAL;
3913}
3914
Damien Lespiaubd9db022013-10-15 18:55:36 +01003915static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003916{
3917 const char name = buf[0];
3918
3919 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3920 return -EINVAL;
3921
3922 *pipe = name - 'A';
3923
3924 return 0;
3925}
3926
3927static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003928display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003929{
3930 int i;
3931
3932 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3933 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003934 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003935 return 0;
3936 }
3937
3938 return -EINVAL;
3939}
3940
Damien Lespiaubd9db022013-10-15 18:55:36 +01003941static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003942{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003943#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003944 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003945 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003946 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003947 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003948 enum intel_pipe_crc_source source;
3949
Damien Lespiaubd9db022013-10-15 18:55:36 +01003950 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003951 if (n_words != N_WORDS) {
3952 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3953 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003954 return -EINVAL;
3955 }
3956
Damien Lespiaubd9db022013-10-15 18:55:36 +01003957 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003958 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003959 return -EINVAL;
3960 }
3961
Damien Lespiaubd9db022013-10-15 18:55:36 +01003962 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003963 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3964 return -EINVAL;
3965 }
3966
Damien Lespiaubd9db022013-10-15 18:55:36 +01003967 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003968 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003969 return -EINVAL;
3970 }
3971
3972 return pipe_crc_set_source(dev, pipe, source);
3973}
3974
Damien Lespiaubd9db022013-10-15 18:55:36 +01003975static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3976 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003977{
3978 struct seq_file *m = file->private_data;
3979 struct drm_device *dev = m->private;
3980 char *tmpbuf;
3981 int ret;
3982
3983 if (len == 0)
3984 return 0;
3985
3986 if (len > PAGE_SIZE - 1) {
3987 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3988 PAGE_SIZE);
3989 return -E2BIG;
3990 }
3991
3992 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3993 if (!tmpbuf)
3994 return -ENOMEM;
3995
3996 if (copy_from_user(tmpbuf, ubuf, len)) {
3997 ret = -EFAULT;
3998 goto out;
3999 }
4000 tmpbuf[len] = '\0';
4001
Damien Lespiaubd9db022013-10-15 18:55:36 +01004002 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004003
4004out:
4005 kfree(tmpbuf);
4006 if (ret < 0)
4007 return ret;
4008
4009 *offp += len;
4010 return len;
4011}
4012
Damien Lespiaubd9db022013-10-15 18:55:36 +01004013static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004014 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004015 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004016 .read = seq_read,
4017 .llseek = seq_lseek,
4018 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004019 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004020};
4021
Todd Previteeb3394fa2015-04-18 00:04:19 -07004022static ssize_t i915_displayport_test_active_write(struct file *file,
4023 const char __user *ubuf,
4024 size_t len, loff_t *offp)
4025{
4026 char *input_buffer;
4027 int status = 0;
4028 struct seq_file *m;
4029 struct drm_device *dev;
4030 struct drm_connector *connector;
4031 struct list_head *connector_list;
4032 struct intel_dp *intel_dp;
4033 int val = 0;
4034
4035 m = file->private_data;
4036 if (!m) {
4037 status = -ENODEV;
4038 return status;
4039 }
4040 dev = m->private;
4041
4042 if (!dev) {
4043 status = -ENODEV;
4044 return status;
4045 }
4046 connector_list = &dev->mode_config.connector_list;
4047
4048 if (len == 0)
4049 return 0;
4050
4051 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4052 if (!input_buffer)
4053 return -ENOMEM;
4054
4055 if (copy_from_user(input_buffer, ubuf, len)) {
4056 status = -EFAULT;
4057 goto out;
4058 }
4059
4060 input_buffer[len] = '\0';
4061 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4062
4063 list_for_each_entry(connector, connector_list, head) {
4064
4065 if (connector->connector_type !=
4066 DRM_MODE_CONNECTOR_DisplayPort)
4067 continue;
4068
4069 if (connector->connector_type ==
4070 DRM_MODE_CONNECTOR_DisplayPort &&
4071 connector->status == connector_status_connected &&
4072 connector->encoder != NULL) {
4073 intel_dp = enc_to_intel_dp(connector->encoder);
4074 status = kstrtoint(input_buffer, 10, &val);
4075 if (status < 0)
4076 goto out;
4077 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4078 /* To prevent erroneous activation of the compliance
4079 * testing code, only accept an actual value of 1 here
4080 */
4081 if (val == 1)
4082 intel_dp->compliance_test_active = 1;
4083 else
4084 intel_dp->compliance_test_active = 0;
4085 }
4086 }
4087out:
4088 kfree(input_buffer);
4089 if (status < 0)
4090 return status;
4091
4092 *offp += len;
4093 return len;
4094}
4095
4096static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4097{
4098 struct drm_device *dev = m->private;
4099 struct drm_connector *connector;
4100 struct list_head *connector_list = &dev->mode_config.connector_list;
4101 struct intel_dp *intel_dp;
4102
4103 if (!dev)
4104 return -ENODEV;
4105
4106 list_for_each_entry(connector, connector_list, head) {
4107
4108 if (connector->connector_type !=
4109 DRM_MODE_CONNECTOR_DisplayPort)
4110 continue;
4111
4112 if (connector->status == connector_status_connected &&
4113 connector->encoder != NULL) {
4114 intel_dp = enc_to_intel_dp(connector->encoder);
4115 if (intel_dp->compliance_test_active)
4116 seq_puts(m, "1");
4117 else
4118 seq_puts(m, "0");
4119 } else
4120 seq_puts(m, "0");
4121 }
4122
4123 return 0;
4124}
4125
4126static int i915_displayport_test_active_open(struct inode *inode,
4127 struct file *file)
4128{
4129 struct drm_device *dev = inode->i_private;
4130
4131 return single_open(file, i915_displayport_test_active_show, dev);
4132}
4133
4134static const struct file_operations i915_displayport_test_active_fops = {
4135 .owner = THIS_MODULE,
4136 .open = i915_displayport_test_active_open,
4137 .read = seq_read,
4138 .llseek = seq_lseek,
4139 .release = single_release,
4140 .write = i915_displayport_test_active_write
4141};
4142
4143static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4144{
4145 struct drm_device *dev = m->private;
4146 struct drm_connector *connector;
4147 struct list_head *connector_list = &dev->mode_config.connector_list;
4148 struct intel_dp *intel_dp;
4149
4150 if (!dev)
4151 return -ENODEV;
4152
4153 list_for_each_entry(connector, connector_list, head) {
4154
4155 if (connector->connector_type !=
4156 DRM_MODE_CONNECTOR_DisplayPort)
4157 continue;
4158
4159 if (connector->status == connector_status_connected &&
4160 connector->encoder != NULL) {
4161 intel_dp = enc_to_intel_dp(connector->encoder);
4162 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4163 } else
4164 seq_puts(m, "0");
4165 }
4166
4167 return 0;
4168}
4169static int i915_displayport_test_data_open(struct inode *inode,
4170 struct file *file)
4171{
4172 struct drm_device *dev = inode->i_private;
4173
4174 return single_open(file, i915_displayport_test_data_show, dev);
4175}
4176
4177static const struct file_operations i915_displayport_test_data_fops = {
4178 .owner = THIS_MODULE,
4179 .open = i915_displayport_test_data_open,
4180 .read = seq_read,
4181 .llseek = seq_lseek,
4182 .release = single_release
4183};
4184
4185static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4186{
4187 struct drm_device *dev = m->private;
4188 struct drm_connector *connector;
4189 struct list_head *connector_list = &dev->mode_config.connector_list;
4190 struct intel_dp *intel_dp;
4191
4192 if (!dev)
4193 return -ENODEV;
4194
4195 list_for_each_entry(connector, connector_list, head) {
4196
4197 if (connector->connector_type !=
4198 DRM_MODE_CONNECTOR_DisplayPort)
4199 continue;
4200
4201 if (connector->status == connector_status_connected &&
4202 connector->encoder != NULL) {
4203 intel_dp = enc_to_intel_dp(connector->encoder);
4204 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4205 } else
4206 seq_puts(m, "0");
4207 }
4208
4209 return 0;
4210}
4211
4212static int i915_displayport_test_type_open(struct inode *inode,
4213 struct file *file)
4214{
4215 struct drm_device *dev = inode->i_private;
4216
4217 return single_open(file, i915_displayport_test_type_show, dev);
4218}
4219
4220static const struct file_operations i915_displayport_test_type_fops = {
4221 .owner = THIS_MODULE,
4222 .open = i915_displayport_test_type_open,
4223 .read = seq_read,
4224 .llseek = seq_lseek,
4225 .release = single_release
4226};
4227
Damien Lespiau97e94b22014-11-04 17:06:50 +00004228static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004229{
4230 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004231 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004232 int num_levels;
4233
4234 if (IS_CHERRYVIEW(dev))
4235 num_levels = 3;
4236 else if (IS_VALLEYVIEW(dev))
4237 num_levels = 1;
4238 else
4239 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004240
4241 drm_modeset_lock_all(dev);
4242
4243 for (level = 0; level < num_levels; level++) {
4244 unsigned int latency = wm[level];
4245
Damien Lespiau97e94b22014-11-04 17:06:50 +00004246 /*
4247 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004248 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004249 */
Ville Syrjäläde38b952015-06-24 22:00:09 +03004250 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004251 latency *= 10;
4252 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004253 latency *= 5;
4254
4255 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004256 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004257 }
4258
4259 drm_modeset_unlock_all(dev);
4260}
4261
4262static int pri_wm_latency_show(struct seq_file *m, void *data)
4263{
4264 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004265 struct drm_i915_private *dev_priv = dev->dev_private;
4266 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004267
Damien Lespiau97e94b22014-11-04 17:06:50 +00004268 if (INTEL_INFO(dev)->gen >= 9)
4269 latencies = dev_priv->wm.skl_latency;
4270 else
4271 latencies = to_i915(dev)->wm.pri_latency;
4272
4273 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004274
4275 return 0;
4276}
4277
4278static int spr_wm_latency_show(struct seq_file *m, void *data)
4279{
4280 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004281 struct drm_i915_private *dev_priv = dev->dev_private;
4282 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004283
Damien Lespiau97e94b22014-11-04 17:06:50 +00004284 if (INTEL_INFO(dev)->gen >= 9)
4285 latencies = dev_priv->wm.skl_latency;
4286 else
4287 latencies = to_i915(dev)->wm.spr_latency;
4288
4289 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004290
4291 return 0;
4292}
4293
4294static int cur_wm_latency_show(struct seq_file *m, void *data)
4295{
4296 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004297 struct drm_i915_private *dev_priv = dev->dev_private;
4298 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004299
Damien Lespiau97e94b22014-11-04 17:06:50 +00004300 if (INTEL_INFO(dev)->gen >= 9)
4301 latencies = dev_priv->wm.skl_latency;
4302 else
4303 latencies = to_i915(dev)->wm.cur_latency;
4304
4305 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004306
4307 return 0;
4308}
4309
4310static int pri_wm_latency_open(struct inode *inode, struct file *file)
4311{
4312 struct drm_device *dev = inode->i_private;
4313
Ville Syrjäläde38b952015-06-24 22:00:09 +03004314 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004315 return -ENODEV;
4316
4317 return single_open(file, pri_wm_latency_show, dev);
4318}
4319
4320static int spr_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, spr_wm_latency_show, dev);
4328}
4329
4330static int cur_wm_latency_open(struct inode *inode, struct file *file)
4331{
4332 struct drm_device *dev = inode->i_private;
4333
Sonika Jindal9ad02572014-07-21 15:23:39 +05304334 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004335 return -ENODEV;
4336
4337 return single_open(file, cur_wm_latency_show, dev);
4338}
4339
4340static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004341 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004342{
4343 struct seq_file *m = file->private_data;
4344 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004345 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004346 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004347 int level;
4348 int ret;
4349 char tmp[32];
4350
Ville Syrjäläde38b952015-06-24 22:00:09 +03004351 if (IS_CHERRYVIEW(dev))
4352 num_levels = 3;
4353 else if (IS_VALLEYVIEW(dev))
4354 num_levels = 1;
4355 else
4356 num_levels = ilk_wm_max_level(dev) + 1;
4357
Ville Syrjälä369a1342014-01-22 14:36:08 +02004358 if (len >= sizeof(tmp))
4359 return -EINVAL;
4360
4361 if (copy_from_user(tmp, ubuf, len))
4362 return -EFAULT;
4363
4364 tmp[len] = '\0';
4365
Damien Lespiau97e94b22014-11-04 17:06:50 +00004366 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4367 &new[0], &new[1], &new[2], &new[3],
4368 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004369 if (ret != num_levels)
4370 return -EINVAL;
4371
4372 drm_modeset_lock_all(dev);
4373
4374 for (level = 0; level < num_levels; level++)
4375 wm[level] = new[level];
4376
4377 drm_modeset_unlock_all(dev);
4378
4379 return len;
4380}
4381
4382
4383static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4384 size_t len, loff_t *offp)
4385{
4386 struct seq_file *m = file->private_data;
4387 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004388 struct drm_i915_private *dev_priv = dev->dev_private;
4389 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004390
Damien Lespiau97e94b22014-11-04 17:06:50 +00004391 if (INTEL_INFO(dev)->gen >= 9)
4392 latencies = dev_priv->wm.skl_latency;
4393 else
4394 latencies = to_i915(dev)->wm.pri_latency;
4395
4396 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004397}
4398
4399static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4400 size_t len, loff_t *offp)
4401{
4402 struct seq_file *m = file->private_data;
4403 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004404 struct drm_i915_private *dev_priv = dev->dev_private;
4405 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004406
Damien Lespiau97e94b22014-11-04 17:06:50 +00004407 if (INTEL_INFO(dev)->gen >= 9)
4408 latencies = dev_priv->wm.skl_latency;
4409 else
4410 latencies = to_i915(dev)->wm.spr_latency;
4411
4412 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004413}
4414
4415static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4416 size_t len, loff_t *offp)
4417{
4418 struct seq_file *m = file->private_data;
4419 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004420 struct drm_i915_private *dev_priv = dev->dev_private;
4421 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004422
Damien Lespiau97e94b22014-11-04 17:06:50 +00004423 if (INTEL_INFO(dev)->gen >= 9)
4424 latencies = dev_priv->wm.skl_latency;
4425 else
4426 latencies = to_i915(dev)->wm.cur_latency;
4427
4428 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004429}
4430
4431static const struct file_operations i915_pri_wm_latency_fops = {
4432 .owner = THIS_MODULE,
4433 .open = pri_wm_latency_open,
4434 .read = seq_read,
4435 .llseek = seq_lseek,
4436 .release = single_release,
4437 .write = pri_wm_latency_write
4438};
4439
4440static const struct file_operations i915_spr_wm_latency_fops = {
4441 .owner = THIS_MODULE,
4442 .open = spr_wm_latency_open,
4443 .read = seq_read,
4444 .llseek = seq_lseek,
4445 .release = single_release,
4446 .write = spr_wm_latency_write
4447};
4448
4449static const struct file_operations i915_cur_wm_latency_fops = {
4450 .owner = THIS_MODULE,
4451 .open = cur_wm_latency_open,
4452 .read = seq_read,
4453 .llseek = seq_lseek,
4454 .release = single_release,
4455 .write = cur_wm_latency_write
4456};
4457
Kees Cook647416f2013-03-10 14:10:06 -07004458static int
4459i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004460{
Kees Cook647416f2013-03-10 14:10:06 -07004461 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004462 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004463
Kees Cook647416f2013-03-10 14:10:06 -07004464 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004465
Kees Cook647416f2013-03-10 14:10:06 -07004466 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004467}
4468
Kees Cook647416f2013-03-10 14:10:06 -07004469static int
4470i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004471{
Kees Cook647416f2013-03-10 14:10:06 -07004472 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004473 struct drm_i915_private *dev_priv = dev->dev_private;
4474
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004475 /*
4476 * There is no safeguard against this debugfs entry colliding
4477 * with the hangcheck calling same i915_handle_error() in
4478 * parallel, causing an explosion. For now we assume that the
4479 * test harness is responsible enough not to inject gpu hangs
4480 * while it is writing to 'i915_wedged'
4481 */
4482
4483 if (i915_reset_in_progress(&dev_priv->gpu_error))
4484 return -EAGAIN;
4485
Imre Deakd46c0512014-04-14 20:24:27 +03004486 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004487
Mika Kuoppala58174462014-02-25 17:11:26 +02004488 i915_handle_error(dev, val,
4489 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004490
4491 intel_runtime_pm_put(dev_priv);
4492
Kees Cook647416f2013-03-10 14:10:06 -07004493 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004494}
4495
Kees Cook647416f2013-03-10 14:10:06 -07004496DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4497 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004498 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004499
Kees Cook647416f2013-03-10 14:10:06 -07004500static int
4501i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004502{
Kees Cook647416f2013-03-10 14:10:06 -07004503 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004504 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004505
Kees Cook647416f2013-03-10 14:10:06 -07004506 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004507
Kees Cook647416f2013-03-10 14:10:06 -07004508 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004509}
4510
Kees Cook647416f2013-03-10 14:10:06 -07004511static int
4512i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004513{
Kees Cook647416f2013-03-10 14:10:06 -07004514 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004515 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004516 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004517
Kees Cook647416f2013-03-10 14:10:06 -07004518 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004519
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004520 ret = mutex_lock_interruptible(&dev->struct_mutex);
4521 if (ret)
4522 return ret;
4523
Daniel Vetter99584db2012-11-14 17:14:04 +01004524 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004525 mutex_unlock(&dev->struct_mutex);
4526
Kees Cook647416f2013-03-10 14:10:06 -07004527 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004528}
4529
Kees Cook647416f2013-03-10 14:10:06 -07004530DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4531 i915_ring_stop_get, i915_ring_stop_set,
4532 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004533
Chris Wilson094f9a52013-09-25 17:34:55 +01004534static int
4535i915_ring_missed_irq_get(void *data, u64 *val)
4536{
4537 struct drm_device *dev = data;
4538 struct drm_i915_private *dev_priv = dev->dev_private;
4539
4540 *val = dev_priv->gpu_error.missed_irq_rings;
4541 return 0;
4542}
4543
4544static int
4545i915_ring_missed_irq_set(void *data, u64 val)
4546{
4547 struct drm_device *dev = data;
4548 struct drm_i915_private *dev_priv = dev->dev_private;
4549 int ret;
4550
4551 /* Lock against concurrent debugfs callers */
4552 ret = mutex_lock_interruptible(&dev->struct_mutex);
4553 if (ret)
4554 return ret;
4555 dev_priv->gpu_error.missed_irq_rings = val;
4556 mutex_unlock(&dev->struct_mutex);
4557
4558 return 0;
4559}
4560
4561DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4562 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4563 "0x%08llx\n");
4564
4565static int
4566i915_ring_test_irq_get(void *data, u64 *val)
4567{
4568 struct drm_device *dev = data;
4569 struct drm_i915_private *dev_priv = dev->dev_private;
4570
4571 *val = dev_priv->gpu_error.test_irq_rings;
4572
4573 return 0;
4574}
4575
4576static int
4577i915_ring_test_irq_set(void *data, u64 val)
4578{
4579 struct drm_device *dev = data;
4580 struct drm_i915_private *dev_priv = dev->dev_private;
4581 int ret;
4582
4583 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4584
4585 /* Lock against concurrent debugfs callers */
4586 ret = mutex_lock_interruptible(&dev->struct_mutex);
4587 if (ret)
4588 return ret;
4589
4590 dev_priv->gpu_error.test_irq_rings = val;
4591 mutex_unlock(&dev->struct_mutex);
4592
4593 return 0;
4594}
4595
4596DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4597 i915_ring_test_irq_get, i915_ring_test_irq_set,
4598 "0x%08llx\n");
4599
Chris Wilsondd624af2013-01-15 12:39:35 +00004600#define DROP_UNBOUND 0x1
4601#define DROP_BOUND 0x2
4602#define DROP_RETIRE 0x4
4603#define DROP_ACTIVE 0x8
4604#define DROP_ALL (DROP_UNBOUND | \
4605 DROP_BOUND | \
4606 DROP_RETIRE | \
4607 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004608static int
4609i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004610{
Kees Cook647416f2013-03-10 14:10:06 -07004611 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004612
Kees Cook647416f2013-03-10 14:10:06 -07004613 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004614}
4615
Kees Cook647416f2013-03-10 14:10:06 -07004616static int
4617i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004618{
Kees Cook647416f2013-03-10 14:10:06 -07004619 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004620 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004621 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004622
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004623 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004624
4625 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4626 * on ioctls on -EAGAIN. */
4627 ret = mutex_lock_interruptible(&dev->struct_mutex);
4628 if (ret)
4629 return ret;
4630
4631 if (val & DROP_ACTIVE) {
4632 ret = i915_gpu_idle(dev);
4633 if (ret)
4634 goto unlock;
4635 }
4636
4637 if (val & (DROP_RETIRE | DROP_ACTIVE))
4638 i915_gem_retire_requests(dev);
4639
Chris Wilson21ab4e72014-09-09 11:16:08 +01004640 if (val & DROP_BOUND)
4641 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004642
Chris Wilson21ab4e72014-09-09 11:16:08 +01004643 if (val & DROP_UNBOUND)
4644 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004645
4646unlock:
4647 mutex_unlock(&dev->struct_mutex);
4648
Kees Cook647416f2013-03-10 14:10:06 -07004649 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004650}
4651
Kees Cook647416f2013-03-10 14:10:06 -07004652DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4653 i915_drop_caches_get, i915_drop_caches_set,
4654 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004655
Kees Cook647416f2013-03-10 14:10:06 -07004656static int
4657i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004658{
Kees Cook647416f2013-03-10 14:10:06 -07004659 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004660 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004661 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004662
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004663 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004664 return -ENODEV;
4665
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004666 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4667
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004668 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004669 if (ret)
4670 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004671
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004672 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004673 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004674
Kees Cook647416f2013-03-10 14:10:06 -07004675 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004676}
4677
Kees Cook647416f2013-03-10 14:10:06 -07004678static int
4679i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004680{
Kees Cook647416f2013-03-10 14:10:06 -07004681 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004682 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304683 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004684 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004685
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004686 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004687 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004688
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004689 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4690
Kees Cook647416f2013-03-10 14:10:06 -07004691 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004692
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004693 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004694 if (ret)
4695 return ret;
4696
Jesse Barnes358733e2011-07-27 11:53:01 -07004697 /*
4698 * Turbo will still be enabled, but won't go above the set value.
4699 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304700 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004701
Akash Goelbc4d91f2015-02-26 16:09:47 +05304702 hw_max = dev_priv->rps.max_freq;
4703 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004704
Ben Widawskyb39fb292014-03-19 18:31:11 -07004705 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004706 mutex_unlock(&dev_priv->rps.hw_lock);
4707 return -EINVAL;
4708 }
4709
Ben Widawskyb39fb292014-03-19 18:31:11 -07004710 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004711
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004712 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004713
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004714 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004715
Kees Cook647416f2013-03-10 14:10:06 -07004716 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004717}
4718
Kees Cook647416f2013-03-10 14:10:06 -07004719DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4720 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004721 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004722
Kees Cook647416f2013-03-10 14:10:06 -07004723static int
4724i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004725{
Kees Cook647416f2013-03-10 14:10:06 -07004726 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004727 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004728 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004729
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004730 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004731 return -ENODEV;
4732
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004733 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4734
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004735 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004736 if (ret)
4737 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004738
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004739 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004740 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004741
Kees Cook647416f2013-03-10 14:10:06 -07004742 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004743}
4744
Kees Cook647416f2013-03-10 14:10:06 -07004745static int
4746i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004747{
Kees Cook647416f2013-03-10 14:10:06 -07004748 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004749 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304750 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004751 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004752
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004753 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004754 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004755
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004756 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4757
Kees Cook647416f2013-03-10 14:10:06 -07004758 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004759
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004760 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004761 if (ret)
4762 return ret;
4763
Jesse Barnes1523c312012-05-25 12:34:54 -07004764 /*
4765 * Turbo will still be enabled, but won't go below the set value.
4766 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304767 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004768
Akash Goelbc4d91f2015-02-26 16:09:47 +05304769 hw_max = dev_priv->rps.max_freq;
4770 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004771
Ben Widawskyb39fb292014-03-19 18:31:11 -07004772 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004773 mutex_unlock(&dev_priv->rps.hw_lock);
4774 return -EINVAL;
4775 }
4776
Ben Widawskyb39fb292014-03-19 18:31:11 -07004777 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004778
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004779 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004780
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004781 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004782
Kees Cook647416f2013-03-10 14:10:06 -07004783 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004784}
4785
Kees Cook647416f2013-03-10 14:10:06 -07004786DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4787 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004788 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004789
Kees Cook647416f2013-03-10 14:10:06 -07004790static int
4791i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004792{
Kees Cook647416f2013-03-10 14:10:06 -07004793 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004794 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004795 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004796 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004797
Daniel Vetter004777c2012-08-09 15:07:01 +02004798 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4799 return -ENODEV;
4800
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004801 ret = mutex_lock_interruptible(&dev->struct_mutex);
4802 if (ret)
4803 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004804 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004805
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004806 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004807
4808 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004809 mutex_unlock(&dev_priv->dev->struct_mutex);
4810
Kees Cook647416f2013-03-10 14:10:06 -07004811 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004812
Kees Cook647416f2013-03-10 14:10:06 -07004813 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004814}
4815
Kees Cook647416f2013-03-10 14:10:06 -07004816static int
4817i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004818{
Kees Cook647416f2013-03-10 14:10:06 -07004819 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004820 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004821 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004822
Daniel Vetter004777c2012-08-09 15:07:01 +02004823 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4824 return -ENODEV;
4825
Kees Cook647416f2013-03-10 14:10:06 -07004826 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004827 return -EINVAL;
4828
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004829 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004830 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004831
4832 /* Update the cache sharing policy here as well */
4833 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4834 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4835 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4836 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4837
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004838 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004839 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004840}
4841
Kees Cook647416f2013-03-10 14:10:06 -07004842DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4843 i915_cache_sharing_get, i915_cache_sharing_set,
4844 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004845
Jeff McGee5d395252015-04-03 18:13:17 -07004846struct sseu_dev_status {
4847 unsigned int slice_total;
4848 unsigned int subslice_total;
4849 unsigned int subslice_per_slice;
4850 unsigned int eu_total;
4851 unsigned int eu_per_subslice;
4852};
4853
4854static void cherryview_sseu_device_status(struct drm_device *dev,
4855 struct sseu_dev_status *stat)
4856{
4857 struct drm_i915_private *dev_priv = dev->dev_private;
4858 const int ss_max = 2;
4859 int ss;
4860 u32 sig1[ss_max], sig2[ss_max];
4861
4862 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4863 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4864 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4865 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4866
4867 for (ss = 0; ss < ss_max; ss++) {
4868 unsigned int eu_cnt;
4869
4870 if (sig1[ss] & CHV_SS_PG_ENABLE)
4871 /* skip disabled subslice */
4872 continue;
4873
4874 stat->slice_total = 1;
4875 stat->subslice_per_slice++;
4876 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4877 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4878 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4879 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
4880 stat->eu_total += eu_cnt;
4881 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
4882 }
4883 stat->subslice_total = stat->subslice_per_slice;
4884}
4885
4886static void gen9_sseu_device_status(struct drm_device *dev,
4887 struct sseu_dev_status *stat)
4888{
4889 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004890 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004891 int s, ss;
4892 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4893
Jeff McGee1c046bc2015-04-03 18:13:18 -07004894 /* BXT has a single slice and at most 3 subslices. */
4895 if (IS_BROXTON(dev)) {
4896 s_max = 1;
4897 ss_max = 3;
4898 }
4899
4900 for (s = 0; s < s_max; s++) {
4901 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4902 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4903 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4904 }
4905
Jeff McGee5d395252015-04-03 18:13:17 -07004906 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4907 GEN9_PGCTL_SSA_EU19_ACK |
4908 GEN9_PGCTL_SSA_EU210_ACK |
4909 GEN9_PGCTL_SSA_EU311_ACK;
4910 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4911 GEN9_PGCTL_SSB_EU19_ACK |
4912 GEN9_PGCTL_SSB_EU210_ACK |
4913 GEN9_PGCTL_SSB_EU311_ACK;
4914
4915 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004916 unsigned int ss_cnt = 0;
4917
Jeff McGee5d395252015-04-03 18:13:17 -07004918 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4919 /* skip disabled slice */
4920 continue;
4921
4922 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004923
4924 if (IS_SKYLAKE(dev))
4925 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
4926
Jeff McGee5d395252015-04-03 18:13:17 -07004927 for (ss = 0; ss < ss_max; ss++) {
4928 unsigned int eu_cnt;
4929
Jeff McGee1c046bc2015-04-03 18:13:18 -07004930 if (IS_BROXTON(dev) &&
4931 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4932 /* skip disabled subslice */
4933 continue;
4934
4935 if (IS_BROXTON(dev))
4936 ss_cnt++;
4937
Jeff McGee5d395252015-04-03 18:13:17 -07004938 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4939 eu_mask[ss%2]);
4940 stat->eu_total += eu_cnt;
4941 stat->eu_per_subslice = max(stat->eu_per_subslice,
4942 eu_cnt);
4943 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004944
4945 stat->subslice_total += ss_cnt;
4946 stat->subslice_per_slice = max(stat->subslice_per_slice,
4947 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004948 }
4949}
4950
Jeff McGee38732182015-02-13 10:27:54 -06004951static int i915_sseu_status(struct seq_file *m, void *unused)
4952{
4953 struct drm_info_node *node = (struct drm_info_node *) m->private;
4954 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07004955 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06004956
Jeff McGee5575f032015-02-27 10:22:32 -08004957 if ((INTEL_INFO(dev)->gen < 8) || IS_BROADWELL(dev))
Jeff McGee38732182015-02-13 10:27:54 -06004958 return -ENODEV;
4959
4960 seq_puts(m, "SSEU Device Info\n");
4961 seq_printf(m, " Available Slice Total: %u\n",
4962 INTEL_INFO(dev)->slice_total);
4963 seq_printf(m, " Available Subslice Total: %u\n",
4964 INTEL_INFO(dev)->subslice_total);
4965 seq_printf(m, " Available Subslice Per Slice: %u\n",
4966 INTEL_INFO(dev)->subslice_per_slice);
4967 seq_printf(m, " Available EU Total: %u\n",
4968 INTEL_INFO(dev)->eu_total);
4969 seq_printf(m, " Available EU Per Subslice: %u\n",
4970 INTEL_INFO(dev)->eu_per_subslice);
4971 seq_printf(m, " Has Slice Power Gating: %s\n",
4972 yesno(INTEL_INFO(dev)->has_slice_pg));
4973 seq_printf(m, " Has Subslice Power Gating: %s\n",
4974 yesno(INTEL_INFO(dev)->has_subslice_pg));
4975 seq_printf(m, " Has EU Power Gating: %s\n",
4976 yesno(INTEL_INFO(dev)->has_eu_pg));
4977
Jeff McGee7f992ab2015-02-13 10:27:55 -06004978 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07004979 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08004980 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07004981 cherryview_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004982 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07004983 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004984 }
Jeff McGee5d395252015-04-03 18:13:17 -07004985 seq_printf(m, " Enabled Slice Total: %u\n",
4986 stat.slice_total);
4987 seq_printf(m, " Enabled Subslice Total: %u\n",
4988 stat.subslice_total);
4989 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
4990 stat.subslice_per_slice);
4991 seq_printf(m, " Enabled EU Total: %u\n",
4992 stat.eu_total);
4993 seq_printf(m, " Enabled EU Per Subslice: %u\n",
4994 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004995
Jeff McGee38732182015-02-13 10:27:54 -06004996 return 0;
4997}
4998
Ben Widawsky6d794d42011-04-25 11:25:56 -07004999static int i915_forcewake_open(struct inode *inode, struct file *file)
5000{
5001 struct drm_device *dev = inode->i_private;
5002 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005003
Daniel Vetter075edca2012-01-24 09:44:28 +01005004 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005005 return 0;
5006
Chris Wilson6daccb02015-01-16 11:34:35 +02005007 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005008 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005009
5010 return 0;
5011}
5012
Ben Widawskyc43b5632012-04-16 14:07:40 -07005013static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005014{
5015 struct drm_device *dev = inode->i_private;
5016 struct drm_i915_private *dev_priv = dev->dev_private;
5017
Daniel Vetter075edca2012-01-24 09:44:28 +01005018 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005019 return 0;
5020
Mika Kuoppala59bad942015-01-16 11:34:40 +02005021 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005022 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005023
5024 return 0;
5025}
5026
5027static const struct file_operations i915_forcewake_fops = {
5028 .owner = THIS_MODULE,
5029 .open = i915_forcewake_open,
5030 .release = i915_forcewake_release,
5031};
5032
5033static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5034{
5035 struct drm_device *dev = minor->dev;
5036 struct dentry *ent;
5037
5038 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005039 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005040 root, dev,
5041 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005042 if (!ent)
5043 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005044
Ben Widawsky8eb57292011-05-11 15:10:58 -07005045 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005046}
5047
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005048static int i915_debugfs_create(struct dentry *root,
5049 struct drm_minor *minor,
5050 const char *name,
5051 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005052{
5053 struct drm_device *dev = minor->dev;
5054 struct dentry *ent;
5055
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005056 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005057 S_IRUGO | S_IWUSR,
5058 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005059 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005060 if (!ent)
5061 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005062
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005063 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005064}
5065
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005066static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005067 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005068 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005069 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005070 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005071 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005072 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005073 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005074 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005075 {"i915_gem_request", i915_gem_request_info, 0},
5076 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005077 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005078 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005079 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5080 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5081 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005082 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005083 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305084 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005085 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005086 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005087 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005088 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005089 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005090 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005091 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005092 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005093 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005094 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005095 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005096 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005097 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005098 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005099 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005100 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005101 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005102 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005103 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005104 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005105 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005106 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005107 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005108 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005109 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005110 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005111 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005112 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005113 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305114 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005115 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005116};
Ben Gamari27c202a2009-07-01 22:26:52 -04005117#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005118
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005119static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005120 const char *name;
5121 const struct file_operations *fops;
5122} i915_debugfs_files[] = {
5123 {"i915_wedged", &i915_wedged_fops},
5124 {"i915_max_freq", &i915_max_freq_fops},
5125 {"i915_min_freq", &i915_min_freq_fops},
5126 {"i915_cache_sharing", &i915_cache_sharing_fops},
5127 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005128 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5129 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005130 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5131 {"i915_error_state", &i915_error_state_fops},
5132 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005133 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005134 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5135 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5136 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005137 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005138 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5139 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5140 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005141};
5142
Damien Lespiau07144422013-10-15 18:55:40 +01005143void intel_display_crc_init(struct drm_device *dev)
5144{
5145 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005146 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005147
Damien Lespiau055e3932014-08-18 13:49:10 +01005148 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005149 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005150
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005151 pipe_crc->opened = false;
5152 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005153 init_waitqueue_head(&pipe_crc->wq);
5154 }
5155}
5156
Ben Gamari27c202a2009-07-01 22:26:52 -04005157int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005158{
Daniel Vetter34b96742013-07-04 20:49:44 +02005159 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005160
Ben Widawsky6d794d42011-04-25 11:25:56 -07005161 ret = i915_forcewake_create(minor->debugfs_root, minor);
5162 if (ret)
5163 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005164
Damien Lespiau07144422013-10-15 18:55:40 +01005165 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5166 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5167 if (ret)
5168 return ret;
5169 }
5170
Daniel Vetter34b96742013-07-04 20:49:44 +02005171 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5172 ret = i915_debugfs_create(minor->debugfs_root, minor,
5173 i915_debugfs_files[i].name,
5174 i915_debugfs_files[i].fops);
5175 if (ret)
5176 return ret;
5177 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005178
Ben Gamari27c202a2009-07-01 22:26:52 -04005179 return drm_debugfs_create_files(i915_debugfs_list,
5180 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005181 minor->debugfs_root, minor);
5182}
5183
Ben Gamari27c202a2009-07-01 22:26:52 -04005184void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005185{
Daniel Vetter34b96742013-07-04 20:49:44 +02005186 int i;
5187
Ben Gamari27c202a2009-07-01 22:26:52 -04005188 drm_debugfs_remove_files(i915_debugfs_list,
5189 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005190
Ben Widawsky6d794d42011-04-25 11:25:56 -07005191 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5192 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005193
Daniel Vettere309a992013-10-16 22:55:51 +02005194 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005195 struct drm_info_list *info_list =
5196 (struct drm_info_list *)&i915_pipe_crc_data[i];
5197
5198 drm_debugfs_remove_files(info_list, 1, minor);
5199 }
5200
Daniel Vetter34b96742013-07-04 20:49:44 +02005201 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5202 struct drm_info_list *info_list =
5203 (struct drm_info_list *) i915_debugfs_files[i].fops;
5204
5205 drm_debugfs_remove_files(info_list, 1, minor);
5206 }
Ben Gamari20172632009-02-17 20:08:50 -05005207}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005208
5209struct dpcd_block {
5210 /* DPCD dump start address. */
5211 unsigned int offset;
5212 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5213 unsigned int end;
5214 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5215 size_t size;
5216 /* Only valid for eDP. */
5217 bool edp;
5218};
5219
5220static const struct dpcd_block i915_dpcd_debug[] = {
5221 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5222 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5223 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5224 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5225 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5226 { .offset = DP_SET_POWER },
5227 { .offset = DP_EDP_DPCD_REV },
5228 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5229 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5230 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5231};
5232
5233static int i915_dpcd_show(struct seq_file *m, void *data)
5234{
5235 struct drm_connector *connector = m->private;
5236 struct intel_dp *intel_dp =
5237 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5238 uint8_t buf[16];
5239 ssize_t err;
5240 int i;
5241
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005242 if (connector->status != connector_status_connected)
5243 return -ENODEV;
5244
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005245 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5246 const struct dpcd_block *b = &i915_dpcd_debug[i];
5247 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5248
5249 if (b->edp &&
5250 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5251 continue;
5252
5253 /* low tech for now */
5254 if (WARN_ON(size > sizeof(buf)))
5255 continue;
5256
5257 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5258 if (err <= 0) {
5259 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5260 size, b->offset, err);
5261 continue;
5262 }
5263
5264 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005265 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005266
5267 return 0;
5268}
5269
5270static int i915_dpcd_open(struct inode *inode, struct file *file)
5271{
5272 return single_open(file, i915_dpcd_show, inode->i_private);
5273}
5274
5275static const struct file_operations i915_dpcd_fops = {
5276 .owner = THIS_MODULE,
5277 .open = i915_dpcd_open,
5278 .read = seq_read,
5279 .llseek = seq_lseek,
5280 .release = single_release,
5281};
5282
5283/**
5284 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5285 * @connector: pointer to a registered drm_connector
5286 *
5287 * Cleanup will be done by drm_connector_unregister() through a call to
5288 * drm_debugfs_connector_remove().
5289 *
5290 * Returns 0 on success, negative error codes on error.
5291 */
5292int i915_debugfs_connector_add(struct drm_connector *connector)
5293{
5294 struct dentry *root = connector->debugfs_entry;
5295
5296 /* The connector must have been registered beforehands. */
5297 if (!root)
5298 return -ENODEV;
5299
5300 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5301 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5302 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5303 &i915_dpcd_fops);
5304
5305 return 0;
5306}