blob: 843b471090f33f19f64e4c85489270b6f6f370ec [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{
Daniel Vetter4feb7652014-11-24 11:21:52 +010099 if (i915_gem_obj_is_pinned(obj))
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
Chris Wilson37811fc2010-08-25 22:45:57 +0100120static void
121describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
122{
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700123 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800124 int pin_count = 0;
125
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200126 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %x %x %x%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100127 &obj->base,
128 get_pin_flag(obj),
129 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700130 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800131 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100132 obj->base.read_domains,
133 obj->base.write_domain,
John Harrison97b2a6a2014-11-24 18:49:26 +0000134 i915_gem_request_get_seqno(obj->last_read_req),
135 i915_gem_request_get_seqno(obj->last_write_req),
136 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100137 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100138 obj->dirty ? " dirty" : "",
139 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
140 if (obj->base.name)
141 seq_printf(m, " (name: %d)", obj->base.name);
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300142 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800143 if (vma->pin_count > 0)
144 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300145 }
146 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100147 if (obj->pin_display)
148 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100149 if (obj->fence_reg != I915_FENCE_REG_NONE)
150 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700151 list_for_each_entry(vma, &obj->vma_list, vma_link) {
152 if (!i915_is_ggtt(vma->vm))
153 seq_puts(m, " (pp");
154 else
155 seq_puts(m, " (g");
Tvrtko Ursulinfe14d5f2014-12-10 17:27:58 +0000156 seq_printf(m, "gtt offset: %08lx, size: %08lx, type: %u)",
157 vma->node.start, vma->node.size,
158 vma->ggtt_view.type);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700159 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000160 if (obj->stolen)
161 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000162 if (obj->pin_mappable || obj->fault_mappable) {
163 char s[3], *t = s;
164 if (obj->pin_mappable)
165 *t++ = 'p';
166 if (obj->fault_mappable)
167 *t++ = 'f';
168 *t = '\0';
169 seq_printf(m, " (%s mappable)", s);
170 }
John Harrison41c52412014-11-24 18:49:43 +0000171 if (obj->last_read_req != NULL)
172 seq_printf(m, " (%s)",
173 i915_gem_request_get_ring(obj->last_read_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200174 if (obj->frontbuffer_bits)
175 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100176}
177
Oscar Mateo273497e2014-05-22 14:13:37 +0100178static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700179{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100180 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700181 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
182 seq_putc(m, ' ');
183}
184
Ben Gamari433e12f2009-02-17 20:08:51 -0500185static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500186{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100187 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500188 uintptr_t list = (uintptr_t) node->info_ent->data;
189 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500190 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700191 struct drm_i915_private *dev_priv = dev->dev_private;
192 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700193 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100194 size_t total_obj_size, total_gtt_size;
195 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100196
197 ret = mutex_lock_interruptible(&dev->struct_mutex);
198 if (ret)
199 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500200
Ben Widawskyca191b12013-07-31 17:00:14 -0700201 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500202 switch (list) {
203 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100204 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700205 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500206 break;
207 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100208 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700209 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500210 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500211 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100212 mutex_unlock(&dev->struct_mutex);
213 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500214 }
215
Chris Wilson8f2480f2010-09-26 11:44:19 +0100216 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700217 list_for_each_entry(vma, head, mm_list) {
218 seq_printf(m, " ");
219 describe_obj(m, vma->obj);
220 seq_printf(m, "\n");
221 total_obj_size += vma->obj->base.size;
222 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100223 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500224 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100225 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700226
Chris Wilson8f2480f2010-09-26 11:44:19 +0100227 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
228 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500229 return 0;
230}
231
Chris Wilson6d2b88852013-08-07 18:30:54 +0100232static int obj_rank_by_stolen(void *priv,
233 struct list_head *A, struct list_head *B)
234{
235 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200236 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100237 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200238 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100239
240 return a->stolen->start - b->stolen->start;
241}
242
243static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
244{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100245 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100246 struct drm_device *dev = node->minor->dev;
247 struct drm_i915_private *dev_priv = dev->dev_private;
248 struct drm_i915_gem_object *obj;
249 size_t total_obj_size, total_gtt_size;
250 LIST_HEAD(stolen);
251 int count, ret;
252
253 ret = mutex_lock_interruptible(&dev->struct_mutex);
254 if (ret)
255 return ret;
256
257 total_obj_size = total_gtt_size = count = 0;
258 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
259 if (obj->stolen == NULL)
260 continue;
261
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200262 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100263
264 total_obj_size += obj->base.size;
265 total_gtt_size += i915_gem_obj_ggtt_size(obj);
266 count++;
267 }
268 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
269 if (obj->stolen == NULL)
270 continue;
271
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200272 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100273
274 total_obj_size += obj->base.size;
275 count++;
276 }
277 list_sort(NULL, &stolen, obj_rank_by_stolen);
278 seq_puts(m, "Stolen:\n");
279 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200280 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100281 seq_puts(m, " ");
282 describe_obj(m, obj);
283 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200284 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100285 }
286 mutex_unlock(&dev->struct_mutex);
287
288 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
289 count, total_obj_size, total_gtt_size);
290 return 0;
291}
292
Chris Wilson6299f992010-11-24 12:23:44 +0000293#define count_objects(list, member) do { \
294 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700295 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000296 ++count; \
297 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700298 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000299 ++mappable_count; \
300 } \
301 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400302} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000303
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100304struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000305 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100306 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000307 size_t total, unbound;
308 size_t global, shared;
309 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100310};
311
312static int per_file_stats(int id, void *ptr, void *data)
313{
314 struct drm_i915_gem_object *obj = ptr;
315 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000316 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100317
318 stats->count++;
319 stats->total += obj->base.size;
320
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000321 if (obj->base.name || obj->base.dma_buf)
322 stats->shared += obj->base.size;
323
Chris Wilson6313c202014-03-19 13:45:45 +0000324 if (USES_FULL_PPGTT(obj->base.dev)) {
325 list_for_each_entry(vma, &obj->vma_list, vma_link) {
326 struct i915_hw_ppgtt *ppgtt;
327
328 if (!drm_mm_node_allocated(&vma->node))
329 continue;
330
331 if (i915_is_ggtt(vma->vm)) {
332 stats->global += obj->base.size;
333 continue;
334 }
335
336 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200337 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000338 continue;
339
John Harrison41c52412014-11-24 18:49:43 +0000340 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000341 stats->active += obj->base.size;
342 else
343 stats->inactive += obj->base.size;
344
345 return 0;
346 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100347 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000348 if (i915_gem_obj_ggtt_bound(obj)) {
349 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000350 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000351 stats->active += obj->base.size;
352 else
353 stats->inactive += obj->base.size;
354 return 0;
355 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100356 }
357
Chris Wilson6313c202014-03-19 13:45:45 +0000358 if (!list_empty(&obj->global_list))
359 stats->unbound += obj->base.size;
360
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100361 return 0;
362}
363
Brad Volkin493018d2014-12-11 12:13:08 -0800364#define print_file_stats(m, name, stats) \
365 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n", \
366 name, \
367 stats.count, \
368 stats.total, \
369 stats.active, \
370 stats.inactive, \
371 stats.global, \
372 stats.shared, \
373 stats.unbound)
374
375static void print_batch_pool_stats(struct seq_file *m,
376 struct drm_i915_private *dev_priv)
377{
378 struct drm_i915_gem_object *obj;
379 struct file_stats stats;
380
381 memset(&stats, 0, sizeof(stats));
382
383 list_for_each_entry(obj,
384 &dev_priv->mm.batch_pool.cache_list,
385 batch_pool_list)
386 per_file_stats(0, obj, &stats);
387
388 print_file_stats(m, "batch pool", stats);
389}
390
Ben Widawskyca191b12013-07-31 17:00:14 -0700391#define count_vmas(list, member) do { \
392 list_for_each_entry(vma, list, member) { \
393 size += i915_gem_obj_ggtt_size(vma->obj); \
394 ++count; \
395 if (vma->obj->map_and_fenceable) { \
396 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
397 ++mappable_count; \
398 } \
399 } \
400} while (0)
401
402static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100403{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100404 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100405 struct drm_device *dev = node->minor->dev;
406 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200407 u32 count, mappable_count, purgeable_count;
408 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000409 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700410 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100411 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700412 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100413 int ret;
414
415 ret = mutex_lock_interruptible(&dev->struct_mutex);
416 if (ret)
417 return ret;
418
Chris Wilson6299f992010-11-24 12:23:44 +0000419 seq_printf(m, "%u objects, %zu bytes\n",
420 dev_priv->mm.object_count,
421 dev_priv->mm.object_memory);
422
423 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700424 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000425 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
426 count, mappable_count, size, mappable_size);
427
428 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700429 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000430 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
431 count, mappable_count, size, mappable_size);
432
433 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700434 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000435 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
436 count, mappable_count, size, mappable_size);
437
Chris Wilsonb7abb712012-08-20 11:33:30 +0200438 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700439 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200440 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200441 if (obj->madv == I915_MADV_DONTNEED)
442 purgeable_size += obj->base.size, ++purgeable_count;
443 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200444 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
445
Chris Wilson6299f992010-11-24 12:23:44 +0000446 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700447 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000448 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700449 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000450 ++count;
451 }
452 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700453 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000454 ++mappable_count;
455 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200456 if (obj->madv == I915_MADV_DONTNEED) {
457 purgeable_size += obj->base.size;
458 ++purgeable_count;
459 }
Chris Wilson6299f992010-11-24 12:23:44 +0000460 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200461 seq_printf(m, "%u purgeable objects, %zu bytes\n",
462 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000463 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
464 mappable_count, mappable_size);
465 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
466 count, size);
467
Ben Widawsky93d18792013-01-17 12:45:17 -0800468 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700469 dev_priv->gtt.base.total,
470 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100471
Damien Lespiau267f0c92013-06-24 22:59:48 +0100472 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800473 print_batch_pool_stats(m, dev_priv);
474
475 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100476 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
477 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900478 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100479
480 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000481 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100482 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100483 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100484 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900485 /*
486 * Although we have a valid reference on file->pid, that does
487 * not guarantee that the task_struct who called get_pid() is
488 * still alive (e.g. get_pid(current) => fork() => exit()).
489 * Therefore, we need to protect this ->comm access using RCU.
490 */
491 rcu_read_lock();
492 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800493 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900494 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100495 }
496
Chris Wilson73aa8082010-09-30 11:46:12 +0100497 mutex_unlock(&dev->struct_mutex);
498
499 return 0;
500}
501
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100502static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000503{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100504 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000505 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100506 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000507 struct drm_i915_private *dev_priv = dev->dev_private;
508 struct drm_i915_gem_object *obj;
509 size_t total_obj_size, total_gtt_size;
510 int count, ret;
511
512 ret = mutex_lock_interruptible(&dev->struct_mutex);
513 if (ret)
514 return ret;
515
516 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700517 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800518 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100519 continue;
520
Damien Lespiau267f0c92013-06-24 22:59:48 +0100521 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000522 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100523 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000524 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700525 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000526 count++;
527 }
528
529 mutex_unlock(&dev->struct_mutex);
530
531 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
532 count, total_obj_size, total_gtt_size);
533
534 return 0;
535}
536
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100537static int i915_gem_pageflip_info(struct seq_file *m, void *data)
538{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100539 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100540 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100541 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100542 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200543 int ret;
544
545 ret = mutex_lock_interruptible(&dev->struct_mutex);
546 if (ret)
547 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100548
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100549 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800550 const char pipe = pipe_name(crtc->pipe);
551 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100552 struct intel_unpin_work *work;
553
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200554 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100555 work = crtc->unpin_work;
556 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800557 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100558 pipe, plane);
559 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100560 u32 addr;
561
Chris Wilsone7d841c2012-12-03 11:36:30 +0000562 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800563 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100564 pipe, plane);
565 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800566 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100567 pipe, plane);
568 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100569 if (work->flip_queued_req) {
570 struct intel_engine_cs *ring =
571 i915_gem_request_get_ring(work->flip_queued_req);
572
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200573 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 +0100574 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000575 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100576 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100577 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000578 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100579 } else
580 seq_printf(m, "Flip not associated with any ring\n");
581 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
582 work->flip_queued_vblank,
583 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100584 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100585 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100586 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100587 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100588 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000589 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100590
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100591 if (INTEL_INFO(dev)->gen >= 4)
592 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
593 else
594 addr = I915_READ(DSPADDR(crtc->plane));
595 seq_printf(m, "Current scanout address 0x%08x\n", addr);
596
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100597 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100598 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
599 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100600 }
601 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200602 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100603 }
604
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200605 mutex_unlock(&dev->struct_mutex);
606
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100607 return 0;
608}
609
Brad Volkin493018d2014-12-11 12:13:08 -0800610static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
611{
612 struct drm_info_node *node = m->private;
613 struct drm_device *dev = node->minor->dev;
614 struct drm_i915_private *dev_priv = dev->dev_private;
615 struct drm_i915_gem_object *obj;
616 int count = 0;
617 int ret;
618
619 ret = mutex_lock_interruptible(&dev->struct_mutex);
620 if (ret)
621 return ret;
622
623 seq_puts(m, "cache:\n");
624 list_for_each_entry(obj,
625 &dev_priv->mm.batch_pool.cache_list,
626 batch_pool_list) {
627 seq_puts(m, " ");
628 describe_obj(m, obj);
629 seq_putc(m, '\n');
630 count++;
631 }
632
633 seq_printf(m, "total: %d\n", count);
634
635 mutex_unlock(&dev->struct_mutex);
636
637 return 0;
638}
639
Ben Gamari20172632009-02-17 20:08:50 -0500640static int i915_gem_request_info(struct seq_file *m, void *data)
641{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100642 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500643 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300644 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100645 struct intel_engine_cs *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500646 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100647 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100648
649 ret = mutex_lock_interruptible(&dev->struct_mutex);
650 if (ret)
651 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500652
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100653 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100654 for_each_ring(ring, dev_priv, i) {
655 if (list_empty(&ring->request_list))
656 continue;
657
658 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100659 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100660 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100661 list) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200662 seq_printf(m, " %x @ %d\n",
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100663 gem_request->seqno,
664 (int) (jiffies - gem_request->emitted_jiffies));
665 }
666 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500667 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100668 mutex_unlock(&dev->struct_mutex);
669
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100670 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100671 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100672
Ben Gamari20172632009-02-17 20:08:50 -0500673 return 0;
674}
675
Chris Wilsonb2223492010-10-27 15:27:33 +0100676static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100677 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100678{
679 if (ring->get_seqno) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200680 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100681 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100682 }
683}
684
Ben Gamari20172632009-02-17 20:08:50 -0500685static int i915_gem_seqno_info(struct seq_file *m, void *data)
686{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100687 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500688 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300689 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100690 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000691 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100692
693 ret = mutex_lock_interruptible(&dev->struct_mutex);
694 if (ret)
695 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200696 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500697
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100698 for_each_ring(ring, dev_priv, i)
699 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100700
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200701 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100702 mutex_unlock(&dev->struct_mutex);
703
Ben Gamari20172632009-02-17 20:08:50 -0500704 return 0;
705}
706
707
708static int i915_interrupt_info(struct seq_file *m, void *data)
709{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100710 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500711 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300712 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100713 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800714 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100715
716 ret = mutex_lock_interruptible(&dev->struct_mutex);
717 if (ret)
718 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200719 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500720
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300721 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300722 seq_printf(m, "Master Interrupt Control:\t%08x\n",
723 I915_READ(GEN8_MASTER_IRQ));
724
725 seq_printf(m, "Display IER:\t%08x\n",
726 I915_READ(VLV_IER));
727 seq_printf(m, "Display IIR:\t%08x\n",
728 I915_READ(VLV_IIR));
729 seq_printf(m, "Display IIR_RW:\t%08x\n",
730 I915_READ(VLV_IIR_RW));
731 seq_printf(m, "Display IMR:\t%08x\n",
732 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100733 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300734 seq_printf(m, "Pipe %c stat:\t%08x\n",
735 pipe_name(pipe),
736 I915_READ(PIPESTAT(pipe)));
737
738 seq_printf(m, "Port hotplug:\t%08x\n",
739 I915_READ(PORT_HOTPLUG_EN));
740 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
741 I915_READ(VLV_DPFLIPSTAT));
742 seq_printf(m, "DPINVGTT:\t%08x\n",
743 I915_READ(DPINVGTT));
744
745 for (i = 0; i < 4; i++) {
746 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
747 i, I915_READ(GEN8_GT_IMR(i)));
748 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
749 i, I915_READ(GEN8_GT_IIR(i)));
750 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
751 i, I915_READ(GEN8_GT_IER(i)));
752 }
753
754 seq_printf(m, "PCU interrupt mask:\t%08x\n",
755 I915_READ(GEN8_PCU_IMR));
756 seq_printf(m, "PCU interrupt identity:\t%08x\n",
757 I915_READ(GEN8_PCU_IIR));
758 seq_printf(m, "PCU interrupt enable:\t%08x\n",
759 I915_READ(GEN8_PCU_IER));
760 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700761 seq_printf(m, "Master Interrupt Control:\t%08x\n",
762 I915_READ(GEN8_MASTER_IRQ));
763
764 for (i = 0; i < 4; i++) {
765 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
766 i, I915_READ(GEN8_GT_IMR(i)));
767 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
768 i, I915_READ(GEN8_GT_IIR(i)));
769 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
770 i, I915_READ(GEN8_GT_IER(i)));
771 }
772
Damien Lespiau055e3932014-08-18 13:49:10 +0100773 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200774 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300775 POWER_DOMAIN_PIPE(pipe))) {
776 seq_printf(m, "Pipe %c power disabled\n",
777 pipe_name(pipe));
778 continue;
779 }
Ben Widawskya123f152013-11-02 21:07:10 -0700780 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000781 pipe_name(pipe),
782 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700783 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000784 pipe_name(pipe),
785 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700786 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000787 pipe_name(pipe),
788 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700789 }
790
791 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
792 I915_READ(GEN8_DE_PORT_IMR));
793 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
794 I915_READ(GEN8_DE_PORT_IIR));
795 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
796 I915_READ(GEN8_DE_PORT_IER));
797
798 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
799 I915_READ(GEN8_DE_MISC_IMR));
800 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
801 I915_READ(GEN8_DE_MISC_IIR));
802 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
803 I915_READ(GEN8_DE_MISC_IER));
804
805 seq_printf(m, "PCU interrupt mask:\t%08x\n",
806 I915_READ(GEN8_PCU_IMR));
807 seq_printf(m, "PCU interrupt identity:\t%08x\n",
808 I915_READ(GEN8_PCU_IIR));
809 seq_printf(m, "PCU interrupt enable:\t%08x\n",
810 I915_READ(GEN8_PCU_IER));
811 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700812 seq_printf(m, "Display IER:\t%08x\n",
813 I915_READ(VLV_IER));
814 seq_printf(m, "Display IIR:\t%08x\n",
815 I915_READ(VLV_IIR));
816 seq_printf(m, "Display IIR_RW:\t%08x\n",
817 I915_READ(VLV_IIR_RW));
818 seq_printf(m, "Display IMR:\t%08x\n",
819 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100820 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700821 seq_printf(m, "Pipe %c stat:\t%08x\n",
822 pipe_name(pipe),
823 I915_READ(PIPESTAT(pipe)));
824
825 seq_printf(m, "Master IER:\t%08x\n",
826 I915_READ(VLV_MASTER_IER));
827
828 seq_printf(m, "Render IER:\t%08x\n",
829 I915_READ(GTIER));
830 seq_printf(m, "Render IIR:\t%08x\n",
831 I915_READ(GTIIR));
832 seq_printf(m, "Render IMR:\t%08x\n",
833 I915_READ(GTIMR));
834
835 seq_printf(m, "PM IER:\t\t%08x\n",
836 I915_READ(GEN6_PMIER));
837 seq_printf(m, "PM IIR:\t\t%08x\n",
838 I915_READ(GEN6_PMIIR));
839 seq_printf(m, "PM IMR:\t\t%08x\n",
840 I915_READ(GEN6_PMIMR));
841
842 seq_printf(m, "Port hotplug:\t%08x\n",
843 I915_READ(PORT_HOTPLUG_EN));
844 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
845 I915_READ(VLV_DPFLIPSTAT));
846 seq_printf(m, "DPINVGTT:\t%08x\n",
847 I915_READ(DPINVGTT));
848
849 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800850 seq_printf(m, "Interrupt enable: %08x\n",
851 I915_READ(IER));
852 seq_printf(m, "Interrupt identity: %08x\n",
853 I915_READ(IIR));
854 seq_printf(m, "Interrupt mask: %08x\n",
855 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100856 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800857 seq_printf(m, "Pipe %c stat: %08x\n",
858 pipe_name(pipe),
859 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800860 } else {
861 seq_printf(m, "North Display Interrupt enable: %08x\n",
862 I915_READ(DEIER));
863 seq_printf(m, "North Display Interrupt identity: %08x\n",
864 I915_READ(DEIIR));
865 seq_printf(m, "North Display Interrupt mask: %08x\n",
866 I915_READ(DEIMR));
867 seq_printf(m, "South Display Interrupt enable: %08x\n",
868 I915_READ(SDEIER));
869 seq_printf(m, "South Display Interrupt identity: %08x\n",
870 I915_READ(SDEIIR));
871 seq_printf(m, "South Display Interrupt mask: %08x\n",
872 I915_READ(SDEIMR));
873 seq_printf(m, "Graphics Interrupt enable: %08x\n",
874 I915_READ(GTIER));
875 seq_printf(m, "Graphics Interrupt identity: %08x\n",
876 I915_READ(GTIIR));
877 seq_printf(m, "Graphics Interrupt mask: %08x\n",
878 I915_READ(GTIMR));
879 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100880 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700881 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100882 seq_printf(m,
883 "Graphics Interrupt mask (%s): %08x\n",
884 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000885 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100886 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000887 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200888 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100889 mutex_unlock(&dev->struct_mutex);
890
Ben Gamari20172632009-02-17 20:08:50 -0500891 return 0;
892}
893
Chris Wilsona6172a82009-02-11 14:26:38 +0000894static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
895{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100896 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000897 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300898 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100899 int i, ret;
900
901 ret = mutex_lock_interruptible(&dev->struct_mutex);
902 if (ret)
903 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000904
905 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
906 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
907 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000908 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000909
Chris Wilson6c085a72012-08-20 11:40:46 +0200910 seq_printf(m, "Fence %d, pin count = %d, object = ",
911 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100912 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100913 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100914 else
Chris Wilson05394f32010-11-08 19:18:58 +0000915 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100916 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000917 }
918
Chris Wilson05394f32010-11-08 19:18:58 +0000919 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000920 return 0;
921}
922
Ben Gamari20172632009-02-17 20:08:50 -0500923static int i915_hws_info(struct seq_file *m, void *data)
924{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100925 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500926 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300927 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100928 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100929 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100930 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500931
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000932 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100933 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500934 if (hws == NULL)
935 return 0;
936
937 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
938 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
939 i * 4,
940 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
941 }
942 return 0;
943}
944
Daniel Vetterd5442302012-04-27 15:17:40 +0200945static ssize_t
946i915_error_state_write(struct file *filp,
947 const char __user *ubuf,
948 size_t cnt,
949 loff_t *ppos)
950{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300951 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200952 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200953 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200954
955 DRM_DEBUG_DRIVER("Resetting error state\n");
956
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200957 ret = mutex_lock_interruptible(&dev->struct_mutex);
958 if (ret)
959 return ret;
960
Daniel Vetterd5442302012-04-27 15:17:40 +0200961 i915_destroy_error_state(dev);
962 mutex_unlock(&dev->struct_mutex);
963
964 return cnt;
965}
966
967static int i915_error_state_open(struct inode *inode, struct file *file)
968{
969 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200970 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200971
972 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
973 if (!error_priv)
974 return -ENOMEM;
975
976 error_priv->dev = dev;
977
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300978 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200979
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300980 file->private_data = error_priv;
981
982 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200983}
984
985static int i915_error_state_release(struct inode *inode, struct file *file)
986{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300987 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200988
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300989 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200990 kfree(error_priv);
991
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300992 return 0;
993}
994
995static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
996 size_t count, loff_t *pos)
997{
998 struct i915_error_state_file_priv *error_priv = file->private_data;
999 struct drm_i915_error_state_buf error_str;
1000 loff_t tmp_pos = 0;
1001 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001002 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001003
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001004 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001005 if (ret)
1006 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001007
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001008 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001009 if (ret)
1010 goto out;
1011
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001012 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1013 error_str.buf,
1014 error_str.bytes);
1015
1016 if (ret_count < 0)
1017 ret = ret_count;
1018 else
1019 *pos = error_str.start + ret_count;
1020out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001021 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001022 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001023}
1024
1025static const struct file_operations i915_error_state_fops = {
1026 .owner = THIS_MODULE,
1027 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001028 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001029 .write = i915_error_state_write,
1030 .llseek = default_llseek,
1031 .release = i915_error_state_release,
1032};
1033
Kees Cook647416f2013-03-10 14:10:06 -07001034static int
1035i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001036{
Kees Cook647416f2013-03-10 14:10:06 -07001037 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001038 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001039 int ret;
1040
1041 ret = mutex_lock_interruptible(&dev->struct_mutex);
1042 if (ret)
1043 return ret;
1044
Kees Cook647416f2013-03-10 14:10:06 -07001045 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001046 mutex_unlock(&dev->struct_mutex);
1047
Kees Cook647416f2013-03-10 14:10:06 -07001048 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001049}
1050
Kees Cook647416f2013-03-10 14:10:06 -07001051static int
1052i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001053{
Kees Cook647416f2013-03-10 14:10:06 -07001054 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001055 int ret;
1056
Mika Kuoppala40633212012-12-04 15:12:00 +02001057 ret = mutex_lock_interruptible(&dev->struct_mutex);
1058 if (ret)
1059 return ret;
1060
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001061 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001062 mutex_unlock(&dev->struct_mutex);
1063
Kees Cook647416f2013-03-10 14:10:06 -07001064 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001065}
1066
Kees Cook647416f2013-03-10 14:10:06 -07001067DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1068 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001069 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001070
Deepak Sadb4bd12014-03-31 11:30:02 +05301071static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001072{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001073 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001074 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001075 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001076 int ret = 0;
1077
1078 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001079
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001080 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1081
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001082 if (IS_GEN5(dev)) {
1083 u16 rgvswctl = I915_READ16(MEMSWCTL);
1084 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1085
1086 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1087 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1088 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1089 MEMSTAT_VID_SHIFT);
1090 seq_printf(m, "Current P-state: %d\n",
1091 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001092 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
1093 IS_BROADWELL(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001094 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1095 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1096 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001097 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001098 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001099 u32 rpupei, rpcurup, rpprevup;
1100 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001101 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001102 int max_freq;
1103
1104 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001105 ret = mutex_lock_interruptible(&dev->struct_mutex);
1106 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001107 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001108
Mika Kuoppala59bad942015-01-16 11:34:40 +02001109 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001110
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001111 reqf = I915_READ(GEN6_RPNSWREQ);
1112 reqf &= ~GEN6_TURBO_DISABLE;
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001113 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001114 reqf >>= 24;
1115 else
1116 reqf >>= 25;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001117 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001118
Chris Wilson0d8f9492014-03-27 09:06:14 +00001119 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1120 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1121 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1122
Jesse Barnesccab5c82011-01-18 15:49:25 -08001123 rpstat = I915_READ(GEN6_RPSTAT1);
1124 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1125 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1126 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1127 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1128 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1129 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001130 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001131 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1132 else
1133 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001134 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001135
Mika Kuoppala59bad942015-01-16 11:34:40 +02001136 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001137 mutex_unlock(&dev->struct_mutex);
1138
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001139 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1140 pm_ier = I915_READ(GEN6_PMIER);
1141 pm_imr = I915_READ(GEN6_PMIMR);
1142 pm_isr = I915_READ(GEN6_PMISR);
1143 pm_iir = I915_READ(GEN6_PMIIR);
1144 pm_mask = I915_READ(GEN6_PMINTRMSK);
1145 } else {
1146 pm_ier = I915_READ(GEN8_GT_IER(2));
1147 pm_imr = I915_READ(GEN8_GT_IMR(2));
1148 pm_isr = I915_READ(GEN8_GT_ISR(2));
1149 pm_iir = I915_READ(GEN8_GT_IIR(2));
1150 pm_mask = I915_READ(GEN6_PMINTRMSK);
1151 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001152 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 -03001153 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001154 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001155 seq_printf(m, "Render p-state ratio: %d\n",
1156 (gt_perf_status & 0xff00) >> 8);
1157 seq_printf(m, "Render p-state VID: %d\n",
1158 gt_perf_status & 0xff);
1159 seq_printf(m, "Render p-state limit: %d\n",
1160 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001161 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1162 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1163 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1164 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001165 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001166 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001167 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1168 GEN6_CURICONT_MASK);
1169 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1170 GEN6_CURBSYTAVG_MASK);
1171 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1172 GEN6_CURBSYTAVG_MASK);
1173 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1174 GEN6_CURIAVG_MASK);
1175 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1176 GEN6_CURBSYTAVG_MASK);
1177 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1178 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001179
1180 max_freq = (rp_state_cap & 0xff0000) >> 16;
1181 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001182 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001183
1184 max_freq = (rp_state_cap & 0xff00) >> 8;
1185 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001186 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001187
1188 max_freq = rp_state_cap & 0xff;
1189 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001190 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001191
1192 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001193 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001194 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001195 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001196
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001197 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001198 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001199 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1200 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1201
Jesse Barnes0a073b82013-04-17 15:54:58 -07001202 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001203 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001204
Jesse Barnes0a073b82013-04-17 15:54:58 -07001205 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001206 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001207
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001208 seq_printf(m,
1209 "efficient (RPe) frequency: %d MHz\n",
1210 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001211
1212 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001213 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001214 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001215 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001216 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001217 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001218
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001219out:
1220 intel_runtime_pm_put(dev_priv);
1221 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001222}
1223
Chris Wilsonf6544492015-01-26 18:03:04 +02001224static int i915_hangcheck_info(struct seq_file *m, void *unused)
1225{
1226 struct drm_info_node *node = m->private;
1227 struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
1228 struct intel_engine_cs *ring;
1229 int i;
1230
1231 if (!i915.enable_hangcheck) {
1232 seq_printf(m, "Hangcheck disabled\n");
1233 return 0;
1234 }
1235
1236 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1237 seq_printf(m, "Hangcheck active, fires in %dms\n",
1238 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1239 jiffies));
1240 } else
1241 seq_printf(m, "Hangcheck inactive\n");
1242
1243 for_each_ring(ring, dev_priv, i) {
1244 seq_printf(m, "%s:\n", ring->name);
1245 seq_printf(m, "\tseqno = %x [current %x]\n",
1246 ring->hangcheck.seqno, ring->get_seqno(ring, false));
1247 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
1248 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1249 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1250 (long long)ring->hangcheck.acthd,
1251 (long long)intel_ring_get_active_head(ring));
1252 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1253 (long long)ring->hangcheck.max_acthd);
1254 }
1255
1256 return 0;
1257}
1258
Ben Widawsky4d855292011-12-12 19:34:16 -08001259static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001260{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001261 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001262 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001263 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001264 u32 rgvmodectl, rstdbyctl;
1265 u16 crstandvid;
1266 int ret;
1267
1268 ret = mutex_lock_interruptible(&dev->struct_mutex);
1269 if (ret)
1270 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001271 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001272
1273 rgvmodectl = I915_READ(MEMMODECTL);
1274 rstdbyctl = I915_READ(RSTDBYCTL);
1275 crstandvid = I915_READ16(CRSTANDVID);
1276
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001277 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001278 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001279
1280 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1281 "yes" : "no");
1282 seq_printf(m, "Boost freq: %d\n",
1283 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1284 MEMMODE_BOOST_FREQ_SHIFT);
1285 seq_printf(m, "HW control enabled: %s\n",
1286 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1287 seq_printf(m, "SW control enabled: %s\n",
1288 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1289 seq_printf(m, "Gated voltage change: %s\n",
1290 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1291 seq_printf(m, "Starting frequency: P%d\n",
1292 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001293 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001294 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001295 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1296 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1297 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1298 seq_printf(m, "Render standby enabled: %s\n",
1299 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001300 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001301 switch (rstdbyctl & RSX_STATUS_MASK) {
1302 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001303 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001304 break;
1305 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001306 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001307 break;
1308 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001309 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001310 break;
1311 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001312 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001313 break;
1314 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001315 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001316 break;
1317 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001318 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001319 break;
1320 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001321 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001322 break;
1323 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001324
1325 return 0;
1326}
1327
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001328static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001329{
1330 struct drm_info_node *node = m->private;
1331 struct drm_device *dev = node->minor->dev;
1332 struct drm_i915_private *dev_priv = dev->dev_private;
1333 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001334 int i;
1335
1336 spin_lock_irq(&dev_priv->uncore.lock);
1337 for_each_fw_domain(fw_domain, dev_priv, i) {
1338 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001339 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001340 fw_domain->wake_count);
1341 }
1342 spin_unlock_irq(&dev_priv->uncore.lock);
1343
1344 return 0;
1345}
1346
Deepak S669ab5a2014-01-10 15:18:26 +05301347static int vlv_drpc_info(struct seq_file *m)
1348{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001349 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301350 struct drm_device *dev = node->minor->dev;
1351 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001352 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301353
Imre Deakd46c0512014-04-14 20:24:27 +03001354 intel_runtime_pm_get(dev_priv);
1355
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001356 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301357 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1358 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1359
Imre Deakd46c0512014-04-14 20:24:27 +03001360 intel_runtime_pm_put(dev_priv);
1361
Deepak S669ab5a2014-01-10 15:18:26 +05301362 seq_printf(m, "Video Turbo Mode: %s\n",
1363 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1364 seq_printf(m, "Turbo enabled: %s\n",
1365 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1366 seq_printf(m, "HW control enabled: %s\n",
1367 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1368 seq_printf(m, "SW control enabled: %s\n",
1369 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1370 GEN6_RP_MEDIA_SW_MODE));
1371 seq_printf(m, "RC6 Enabled: %s\n",
1372 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1373 GEN6_RC_CTL_EI_MODE(1))));
1374 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001375 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301376 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001377 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301378
Imre Deak9cc19be2014-04-14 20:24:24 +03001379 seq_printf(m, "Render RC6 residency since boot: %u\n",
1380 I915_READ(VLV_GT_RENDER_RC6));
1381 seq_printf(m, "Media RC6 residency since boot: %u\n",
1382 I915_READ(VLV_GT_MEDIA_RC6));
1383
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001384 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301385}
1386
Ben Widawsky4d855292011-12-12 19:34:16 -08001387static int gen6_drpc_info(struct seq_file *m)
1388{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001389 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001390 struct drm_device *dev = node->minor->dev;
1391 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001392 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001393 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001394 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001395
1396 ret = mutex_lock_interruptible(&dev->struct_mutex);
1397 if (ret)
1398 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001399 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001400
Chris Wilson907b28c2013-07-19 20:36:52 +01001401 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001402 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001403 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001404
1405 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001406 seq_puts(m, "RC information inaccurate because somebody "
1407 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001408 } else {
1409 /* NB: we cannot use forcewake, else we read the wrong values */
1410 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1411 udelay(10);
1412 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1413 }
1414
1415 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001416 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001417
1418 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1419 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1420 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001421 mutex_lock(&dev_priv->rps.hw_lock);
1422 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1423 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001424
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001425 intel_runtime_pm_put(dev_priv);
1426
Ben Widawsky4d855292011-12-12 19:34:16 -08001427 seq_printf(m, "Video Turbo Mode: %s\n",
1428 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1429 seq_printf(m, "HW control enabled: %s\n",
1430 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1431 seq_printf(m, "SW control enabled: %s\n",
1432 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1433 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001434 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001435 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1436 seq_printf(m, "RC6 Enabled: %s\n",
1437 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1438 seq_printf(m, "Deep RC6 Enabled: %s\n",
1439 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1440 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1441 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001442 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001443 switch (gt_core_status & GEN6_RCn_MASK) {
1444 case GEN6_RC0:
1445 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001446 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001447 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001448 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001449 break;
1450 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001451 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001452 break;
1453 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001454 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001455 break;
1456 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001457 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001458 break;
1459 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001460 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001461 break;
1462 }
1463
1464 seq_printf(m, "Core Power Down: %s\n",
1465 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001466
1467 /* Not exactly sure what this is */
1468 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1469 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1470 seq_printf(m, "RC6 residency since boot: %u\n",
1471 I915_READ(GEN6_GT_GFX_RC6));
1472 seq_printf(m, "RC6+ residency since boot: %u\n",
1473 I915_READ(GEN6_GT_GFX_RC6p));
1474 seq_printf(m, "RC6++ residency since boot: %u\n",
1475 I915_READ(GEN6_GT_GFX_RC6pp));
1476
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001477 seq_printf(m, "RC6 voltage: %dmV\n",
1478 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1479 seq_printf(m, "RC6+ voltage: %dmV\n",
1480 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1481 seq_printf(m, "RC6++ voltage: %dmV\n",
1482 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001483 return 0;
1484}
1485
1486static int i915_drpc_info(struct seq_file *m, void *unused)
1487{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001488 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001489 struct drm_device *dev = node->minor->dev;
1490
Deepak S669ab5a2014-01-10 15:18:26 +05301491 if (IS_VALLEYVIEW(dev))
1492 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001493 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001494 return gen6_drpc_info(m);
1495 else
1496 return ironlake_drpc_info(m);
1497}
1498
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001499static int i915_fbc_status(struct seq_file *m, void *unused)
1500{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001501 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001502 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001503 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001504
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001505 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001506 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001507 return 0;
1508 }
1509
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001510 intel_runtime_pm_get(dev_priv);
1511
Adam Jacksonee5382a2010-04-23 11:17:39 -04001512 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001513 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001514 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001515 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001516 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001517 case FBC_OK:
1518 seq_puts(m, "FBC actived, but currently disabled in hardware");
1519 break;
1520 case FBC_UNSUPPORTED:
1521 seq_puts(m, "unsupported by this chipset");
1522 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001523 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001524 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001525 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001526 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001527 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001528 break;
1529 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001530 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001531 break;
1532 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001533 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001534 break;
1535 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001536 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001537 break;
1538 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001539 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001540 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001541 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001542 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001543 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001544 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001545 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001546 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001547 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001548 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001549 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001550 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001551 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001552 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001553 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001554 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001555
1556 intel_runtime_pm_put(dev_priv);
1557
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001558 return 0;
1559}
1560
Rodrigo Vivida46f932014-08-01 02:04:45 -07001561static int i915_fbc_fc_get(void *data, u64 *val)
1562{
1563 struct drm_device *dev = data;
1564 struct drm_i915_private *dev_priv = dev->dev_private;
1565
1566 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1567 return -ENODEV;
1568
1569 drm_modeset_lock_all(dev);
1570 *val = dev_priv->fbc.false_color;
1571 drm_modeset_unlock_all(dev);
1572
1573 return 0;
1574}
1575
1576static int i915_fbc_fc_set(void *data, u64 val)
1577{
1578 struct drm_device *dev = data;
1579 struct drm_i915_private *dev_priv = dev->dev_private;
1580 u32 reg;
1581
1582 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1583 return -ENODEV;
1584
1585 drm_modeset_lock_all(dev);
1586
1587 reg = I915_READ(ILK_DPFC_CONTROL);
1588 dev_priv->fbc.false_color = val;
1589
1590 I915_WRITE(ILK_DPFC_CONTROL, val ?
1591 (reg | FBC_CTL_FALSE_COLOR) :
1592 (reg & ~FBC_CTL_FALSE_COLOR));
1593
1594 drm_modeset_unlock_all(dev);
1595 return 0;
1596}
1597
1598DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1599 i915_fbc_fc_get, i915_fbc_fc_set,
1600 "%llu\n");
1601
Paulo Zanoni92d44622013-05-31 16:33:24 -03001602static int i915_ips_status(struct seq_file *m, void *unused)
1603{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001604 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001605 struct drm_device *dev = node->minor->dev;
1606 struct drm_i915_private *dev_priv = dev->dev_private;
1607
Damien Lespiauf5adf942013-06-24 18:29:34 +01001608 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001609 seq_puts(m, "not supported\n");
1610 return 0;
1611 }
1612
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001613 intel_runtime_pm_get(dev_priv);
1614
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001615 seq_printf(m, "Enabled by kernel parameter: %s\n",
1616 yesno(i915.enable_ips));
1617
1618 if (INTEL_INFO(dev)->gen >= 8) {
1619 seq_puts(m, "Currently: unknown\n");
1620 } else {
1621 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1622 seq_puts(m, "Currently: enabled\n");
1623 else
1624 seq_puts(m, "Currently: disabled\n");
1625 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001626
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001627 intel_runtime_pm_put(dev_priv);
1628
Paulo Zanoni92d44622013-05-31 16:33:24 -03001629 return 0;
1630}
1631
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001632static int i915_sr_status(struct seq_file *m, void *unused)
1633{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001634 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001635 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001636 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001637 bool sr_enabled = false;
1638
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001639 intel_runtime_pm_get(dev_priv);
1640
Yuanhan Liu13982612010-12-15 15:42:31 +08001641 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001642 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001643 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001644 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1645 else if (IS_I915GM(dev))
1646 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1647 else if (IS_PINEVIEW(dev))
1648 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1649
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001650 intel_runtime_pm_put(dev_priv);
1651
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001652 seq_printf(m, "self-refresh: %s\n",
1653 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001654
1655 return 0;
1656}
1657
Jesse Barnes7648fa92010-05-20 14:28:11 -07001658static int i915_emon_status(struct seq_file *m, void *unused)
1659{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001660 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001661 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001662 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001663 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001664 int ret;
1665
Chris Wilson582be6b2012-04-30 19:35:02 +01001666 if (!IS_GEN5(dev))
1667 return -ENODEV;
1668
Chris Wilsonde227ef2010-07-03 07:58:38 +01001669 ret = mutex_lock_interruptible(&dev->struct_mutex);
1670 if (ret)
1671 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001672
1673 temp = i915_mch_val(dev_priv);
1674 chipset = i915_chipset_val(dev_priv);
1675 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001676 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001677
1678 seq_printf(m, "GMCH temp: %ld\n", temp);
1679 seq_printf(m, "Chipset power: %ld\n", chipset);
1680 seq_printf(m, "GFX power: %ld\n", gfx);
1681 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1682
1683 return 0;
1684}
1685
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001686static int i915_ring_freq_table(struct seq_file *m, void *unused)
1687{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001688 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001689 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001690 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001691 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001692 int gpu_freq, ia_freq;
1693
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001694 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001695 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001696 return 0;
1697 }
1698
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001699 intel_runtime_pm_get(dev_priv);
1700
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001701 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1702
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001703 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001704 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001705 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001706
Damien Lespiau267f0c92013-06-24 22:59:48 +01001707 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001708
Ben Widawskyb39fb292014-03-19 18:31:11 -07001709 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1710 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001711 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001712 ia_freq = gpu_freq;
1713 sandybridge_pcode_read(dev_priv,
1714 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1715 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001716 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001717 intel_gpu_freq(dev_priv, gpu_freq),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001718 ((ia_freq >> 0) & 0xff) * 100,
1719 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001720 }
1721
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001722 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001723
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001724out:
1725 intel_runtime_pm_put(dev_priv);
1726 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001727}
1728
Chris Wilson44834a62010-08-19 16:09:23 +01001729static int i915_opregion(struct seq_file *m, void *unused)
1730{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001731 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001732 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001733 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001734 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001735 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001736 int ret;
1737
Daniel Vetter0d38f002012-04-21 22:49:10 +02001738 if (data == NULL)
1739 return -ENOMEM;
1740
Chris Wilson44834a62010-08-19 16:09:23 +01001741 ret = mutex_lock_interruptible(&dev->struct_mutex);
1742 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001743 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001744
Daniel Vetter0d38f002012-04-21 22:49:10 +02001745 if (opregion->header) {
1746 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1747 seq_write(m, data, OPREGION_SIZE);
1748 }
Chris Wilson44834a62010-08-19 16:09:23 +01001749
1750 mutex_unlock(&dev->struct_mutex);
1751
Daniel Vetter0d38f002012-04-21 22:49:10 +02001752out:
1753 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001754 return 0;
1755}
1756
Chris Wilson37811fc2010-08-25 22:45:57 +01001757static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1758{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001759 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001760 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001761 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001762 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001763
Daniel Vetter4520f532013-10-09 09:18:51 +02001764#ifdef CONFIG_DRM_I915_FBDEV
1765 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001766
1767 ifbdev = dev_priv->fbdev;
1768 fb = to_intel_framebuffer(ifbdev->helper.fb);
1769
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001770 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 +01001771 fb->base.width,
1772 fb->base.height,
1773 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001774 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001775 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001776 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001777 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001778 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001779#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001780
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001781 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001782 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001783 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001784 continue;
1785
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001786 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 +01001787 fb->base.width,
1788 fb->base.height,
1789 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001790 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001791 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001792 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001793 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001794 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001795 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001796 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001797
1798 return 0;
1799}
1800
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001801static void describe_ctx_ringbuf(struct seq_file *m,
1802 struct intel_ringbuffer *ringbuf)
1803{
1804 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1805 ringbuf->space, ringbuf->head, ringbuf->tail,
1806 ringbuf->last_retired_head);
1807}
1808
Ben Widawskye76d3632011-03-19 18:14:29 -07001809static int i915_context_status(struct seq_file *m, void *unused)
1810{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001811 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001812 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001813 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001814 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001815 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001816 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001817
Daniel Vetterf3d28872014-05-29 23:23:08 +02001818 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001819 if (ret)
1820 return ret;
1821
Daniel Vetter3e373942012-11-02 19:55:04 +01001822 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001823 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001824 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001825 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001826 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001827
Daniel Vetter3e373942012-11-02 19:55:04 +01001828 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001829 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001830 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001831 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001832 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001833
Ben Widawskya33afea2013-09-17 21:12:45 -07001834 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001835 if (!i915.enable_execlists &&
1836 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001837 continue;
1838
Ben Widawskya33afea2013-09-17 21:12:45 -07001839 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001840 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001841 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001842 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001843 seq_printf(m, "(default context %s) ",
1844 ring->name);
1845 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001846
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001847 if (i915.enable_execlists) {
1848 seq_putc(m, '\n');
1849 for_each_ring(ring, dev_priv, i) {
1850 struct drm_i915_gem_object *ctx_obj =
1851 ctx->engine[i].state;
1852 struct intel_ringbuffer *ringbuf =
1853 ctx->engine[i].ringbuf;
1854
1855 seq_printf(m, "%s: ", ring->name);
1856 if (ctx_obj)
1857 describe_obj(m, ctx_obj);
1858 if (ringbuf)
1859 describe_ctx_ringbuf(m, ringbuf);
1860 seq_putc(m, '\n');
1861 }
1862 } else {
1863 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1864 }
1865
Ben Widawskya33afea2013-09-17 21:12:45 -07001866 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001867 }
1868
Daniel Vetterf3d28872014-05-29 23:23:08 +02001869 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001870
1871 return 0;
1872}
1873
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001874static void i915_dump_lrc_obj(struct seq_file *m,
1875 struct intel_engine_cs *ring,
1876 struct drm_i915_gem_object *ctx_obj)
1877{
1878 struct page *page;
1879 uint32_t *reg_state;
1880 int j;
1881 unsigned long ggtt_offset = 0;
1882
1883 if (ctx_obj == NULL) {
1884 seq_printf(m, "Context on %s with no gem object\n",
1885 ring->name);
1886 return;
1887 }
1888
1889 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1890 intel_execlists_ctx_id(ctx_obj));
1891
1892 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1893 seq_puts(m, "\tNot bound in GGTT\n");
1894 else
1895 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1896
1897 if (i915_gem_object_get_pages(ctx_obj)) {
1898 seq_puts(m, "\tFailed to get pages for context object\n");
1899 return;
1900 }
1901
1902 page = i915_gem_object_get_page(ctx_obj, 1);
1903 if (!WARN_ON(page == NULL)) {
1904 reg_state = kmap_atomic(page);
1905
1906 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
1907 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1908 ggtt_offset + 4096 + (j * 4),
1909 reg_state[j], reg_state[j + 1],
1910 reg_state[j + 2], reg_state[j + 3]);
1911 }
1912 kunmap_atomic(reg_state);
1913 }
1914
1915 seq_putc(m, '\n');
1916}
1917
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01001918static int i915_dump_lrc(struct seq_file *m, void *unused)
1919{
1920 struct drm_info_node *node = (struct drm_info_node *) m->private;
1921 struct drm_device *dev = node->minor->dev;
1922 struct drm_i915_private *dev_priv = dev->dev_private;
1923 struct intel_engine_cs *ring;
1924 struct intel_context *ctx;
1925 int ret, i;
1926
1927 if (!i915.enable_execlists) {
1928 seq_printf(m, "Logical Ring Contexts are disabled\n");
1929 return 0;
1930 }
1931
1932 ret = mutex_lock_interruptible(&dev->struct_mutex);
1933 if (ret)
1934 return ret;
1935
1936 list_for_each_entry(ctx, &dev_priv->context_list, link) {
1937 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001938 if (ring->default_context != ctx)
1939 i915_dump_lrc_obj(m, ring,
1940 ctx->engine[i].state);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01001941 }
1942 }
1943
1944 mutex_unlock(&dev->struct_mutex);
1945
1946 return 0;
1947}
1948
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001949static int i915_execlists(struct seq_file *m, void *data)
1950{
1951 struct drm_info_node *node = (struct drm_info_node *)m->private;
1952 struct drm_device *dev = node->minor->dev;
1953 struct drm_i915_private *dev_priv = dev->dev_private;
1954 struct intel_engine_cs *ring;
1955 u32 status_pointer;
1956 u8 read_pointer;
1957 u8 write_pointer;
1958 u32 status;
1959 u32 ctx_id;
1960 struct list_head *cursor;
1961 int ring_id, i;
1962 int ret;
1963
1964 if (!i915.enable_execlists) {
1965 seq_puts(m, "Logical Ring Contexts are disabled\n");
1966 return 0;
1967 }
1968
1969 ret = mutex_lock_interruptible(&dev->struct_mutex);
1970 if (ret)
1971 return ret;
1972
Michel Thierryfc0412e2014-10-16 16:13:38 +01001973 intel_runtime_pm_get(dev_priv);
1974
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001975 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00001976 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001977 int count = 0;
1978 unsigned long flags;
1979
1980 seq_printf(m, "%s\n", ring->name);
1981
1982 status = I915_READ(RING_EXECLIST_STATUS(ring));
1983 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
1984 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
1985 status, ctx_id);
1986
1987 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
1988 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
1989
1990 read_pointer = ring->next_context_status_buffer;
1991 write_pointer = status_pointer & 0x07;
1992 if (read_pointer > write_pointer)
1993 write_pointer += 6;
1994 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
1995 read_pointer, write_pointer);
1996
1997 for (i = 0; i < 6; i++) {
1998 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
1999 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
2000
2001 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2002 i, status, ctx_id);
2003 }
2004
2005 spin_lock_irqsave(&ring->execlist_lock, flags);
2006 list_for_each(cursor, &ring->execlist_queue)
2007 count++;
2008 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002009 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002010 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2011
2012 seq_printf(m, "\t%d requests in queue\n", count);
2013 if (head_req) {
2014 struct drm_i915_gem_object *ctx_obj;
2015
Nick Hoath6d3d8272015-01-15 13:10:39 +00002016 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002017 seq_printf(m, "\tHead request id: %u\n",
2018 intel_execlists_ctx_id(ctx_obj));
2019 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002020 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002021 }
2022
2023 seq_putc(m, '\n');
2024 }
2025
Michel Thierryfc0412e2014-10-16 16:13:38 +01002026 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002027 mutex_unlock(&dev->struct_mutex);
2028
2029 return 0;
2030}
2031
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002032static const char *swizzle_string(unsigned swizzle)
2033{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002034 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002035 case I915_BIT_6_SWIZZLE_NONE:
2036 return "none";
2037 case I915_BIT_6_SWIZZLE_9:
2038 return "bit9";
2039 case I915_BIT_6_SWIZZLE_9_10:
2040 return "bit9/bit10";
2041 case I915_BIT_6_SWIZZLE_9_11:
2042 return "bit9/bit11";
2043 case I915_BIT_6_SWIZZLE_9_10_11:
2044 return "bit9/bit10/bit11";
2045 case I915_BIT_6_SWIZZLE_9_17:
2046 return "bit9/bit17";
2047 case I915_BIT_6_SWIZZLE_9_10_17:
2048 return "bit9/bit10/bit17";
2049 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002050 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002051 }
2052
2053 return "bug";
2054}
2055
2056static int i915_swizzle_info(struct seq_file *m, void *data)
2057{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002058 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002059 struct drm_device *dev = node->minor->dev;
2060 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002061 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002062
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002063 ret = mutex_lock_interruptible(&dev->struct_mutex);
2064 if (ret)
2065 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002066 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002067
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002068 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2069 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2070 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2071 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2072
2073 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2074 seq_printf(m, "DDC = 0x%08x\n",
2075 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002076 seq_printf(m, "DDC2 = 0x%08x\n",
2077 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002078 seq_printf(m, "C0DRB3 = 0x%04x\n",
2079 I915_READ16(C0DRB3));
2080 seq_printf(m, "C1DRB3 = 0x%04x\n",
2081 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002082 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002083 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2084 I915_READ(MAD_DIMM_C0));
2085 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2086 I915_READ(MAD_DIMM_C1));
2087 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2088 I915_READ(MAD_DIMM_C2));
2089 seq_printf(m, "TILECTL = 0x%08x\n",
2090 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002091 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002092 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2093 I915_READ(GAMTARBMODE));
2094 else
2095 seq_printf(m, "ARB_MODE = 0x%08x\n",
2096 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002097 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2098 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002099 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002100
2101 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2102 seq_puts(m, "L-shaped memory detected\n");
2103
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002104 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002105 mutex_unlock(&dev->struct_mutex);
2106
2107 return 0;
2108}
2109
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002110static int per_file_ctx(int id, void *ptr, void *data)
2111{
Oscar Mateo273497e2014-05-22 14:13:37 +01002112 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002113 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002114 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2115
2116 if (!ppgtt) {
2117 seq_printf(m, " no ppgtt for context %d\n",
2118 ctx->user_handle);
2119 return 0;
2120 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002121
Oscar Mateof83d6512014-05-22 14:13:38 +01002122 if (i915_gem_context_is_default(ctx))
2123 seq_puts(m, " default context:\n");
2124 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002125 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002126 ppgtt->debug_dump(ppgtt, m);
2127
2128 return 0;
2129}
2130
Ben Widawsky77df6772013-11-02 21:07:30 -07002131static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002132{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002133 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002134 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002135 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2136 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002137
Ben Widawsky77df6772013-11-02 21:07:30 -07002138 if (!ppgtt)
2139 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002140
Ben Widawsky77df6772013-11-02 21:07:30 -07002141 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08002142 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07002143 for_each_ring(ring, dev_priv, unused) {
2144 seq_printf(m, "%s\n", ring->name);
2145 for (i = 0; i < 4; i++) {
2146 u32 offset = 0x270 + i * 8;
2147 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2148 pdp <<= 32;
2149 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002150 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002151 }
2152 }
2153}
2154
2155static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2156{
2157 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002158 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002159 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002160 int i;
2161
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002162 if (INTEL_INFO(dev)->gen == 6)
2163 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2164
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002165 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002166 seq_printf(m, "%s\n", ring->name);
2167 if (INTEL_INFO(dev)->gen == 7)
2168 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2169 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2170 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2171 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2172 }
2173 if (dev_priv->mm.aliasing_ppgtt) {
2174 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2175
Damien Lespiau267f0c92013-06-24 22:59:48 +01002176 seq_puts(m, "aliasing PPGTT:\n");
Ben Widawsky7324cc02015-02-24 16:22:35 +00002177 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002178
Ben Widawsky87d60b62013-12-06 14:11:29 -08002179 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002180 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002181
2182 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2183 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002184
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002185 seq_printf(m, "proc: %s\n",
2186 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002187 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002188 }
2189 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002190}
2191
2192static int i915_ppgtt_info(struct seq_file *m, void *data)
2193{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002194 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002195 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002196 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002197
2198 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2199 if (ret)
2200 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002201 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002202
2203 if (INTEL_INFO(dev)->gen >= 8)
2204 gen8_ppgtt_info(m, dev);
2205 else if (INTEL_INFO(dev)->gen >= 6)
2206 gen6_ppgtt_info(m, dev);
2207
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002208 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002209 mutex_unlock(&dev->struct_mutex);
2210
2211 return 0;
2212}
2213
Ben Widawsky63573eb2013-07-04 11:02:07 -07002214static int i915_llc(struct seq_file *m, void *data)
2215{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002216 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002217 struct drm_device *dev = node->minor->dev;
2218 struct drm_i915_private *dev_priv = dev->dev_private;
2219
2220 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2221 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2222 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2223
2224 return 0;
2225}
2226
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002227static int i915_edp_psr_status(struct seq_file *m, void *data)
2228{
2229 struct drm_info_node *node = m->private;
2230 struct drm_device *dev = node->minor->dev;
2231 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002232 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002233 u32 stat[3];
2234 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002235 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002236
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002237 intel_runtime_pm_get(dev_priv);
2238
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002239 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002240 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2241 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002242 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002243 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002244 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2245 dev_priv->psr.busy_frontbuffer_bits);
2246 seq_printf(m, "Re-enable work scheduled: %s\n",
2247 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002248
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002249 if (HAS_PSR(dev)) {
2250 if (HAS_DDI(dev))
2251 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2252 else {
2253 for_each_pipe(dev_priv, pipe) {
2254 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2255 VLV_EDP_PSR_CURR_STATE_MASK;
2256 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2257 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2258 enabled = true;
2259 }
2260 }
2261 }
2262 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002263
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002264 if (!HAS_DDI(dev))
2265 for_each_pipe(dev_priv, pipe) {
2266 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2267 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2268 seq_printf(m, " pipe %c", pipe_name(pipe));
2269 }
2270 seq_puts(m, "\n");
2271
Rodrigo Vivifb495812015-01-12 10:14:33 -08002272 seq_printf(m, "Link standby: %s\n",
2273 yesno((bool)dev_priv->psr.link_standby));
2274
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002275 /* CHV PSR has no kind of performance counter */
2276 if (HAS_PSR(dev) && HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002277 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2278 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002279
2280 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2281 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002282 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002283
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002284 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002285 return 0;
2286}
2287
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002288static int i915_sink_crc(struct seq_file *m, void *data)
2289{
2290 struct drm_info_node *node = m->private;
2291 struct drm_device *dev = node->minor->dev;
2292 struct intel_encoder *encoder;
2293 struct intel_connector *connector;
2294 struct intel_dp *intel_dp = NULL;
2295 int ret;
2296 u8 crc[6];
2297
2298 drm_modeset_lock_all(dev);
2299 list_for_each_entry(connector, &dev->mode_config.connector_list,
2300 base.head) {
2301
2302 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2303 continue;
2304
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002305 if (!connector->base.encoder)
2306 continue;
2307
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002308 encoder = to_intel_encoder(connector->base.encoder);
2309 if (encoder->type != INTEL_OUTPUT_EDP)
2310 continue;
2311
2312 intel_dp = enc_to_intel_dp(&encoder->base);
2313
2314 ret = intel_dp_sink_crc(intel_dp, crc);
2315 if (ret)
2316 goto out;
2317
2318 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2319 crc[0], crc[1], crc[2],
2320 crc[3], crc[4], crc[5]);
2321 goto out;
2322 }
2323 ret = -ENODEV;
2324out:
2325 drm_modeset_unlock_all(dev);
2326 return ret;
2327}
2328
Jesse Barnesec013e72013-08-20 10:29:23 +01002329static int i915_energy_uJ(struct seq_file *m, void *data)
2330{
2331 struct drm_info_node *node = m->private;
2332 struct drm_device *dev = node->minor->dev;
2333 struct drm_i915_private *dev_priv = dev->dev_private;
2334 u64 power;
2335 u32 units;
2336
2337 if (INTEL_INFO(dev)->gen < 6)
2338 return -ENODEV;
2339
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002340 intel_runtime_pm_get(dev_priv);
2341
Jesse Barnesec013e72013-08-20 10:29:23 +01002342 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2343 power = (power & 0x1f00) >> 8;
2344 units = 1000000 / (1 << power); /* convert to uJ */
2345 power = I915_READ(MCH_SECP_NRG_STTS);
2346 power *= units;
2347
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002348 intel_runtime_pm_put(dev_priv);
2349
Jesse Barnesec013e72013-08-20 10:29:23 +01002350 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002351
2352 return 0;
2353}
2354
2355static int i915_pc8_status(struct seq_file *m, void *unused)
2356{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002357 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002358 struct drm_device *dev = node->minor->dev;
2359 struct drm_i915_private *dev_priv = dev->dev_private;
2360
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002361 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002362 seq_puts(m, "not supported\n");
2363 return 0;
2364 }
2365
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002366 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002367 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002368 yesno(!intel_irqs_enabled(dev_priv)));
Paulo Zanoni371db662013-08-19 13:18:10 -03002369
Jesse Barnesec013e72013-08-20 10:29:23 +01002370 return 0;
2371}
2372
Imre Deak1da51582013-11-25 17:15:35 +02002373static const char *power_domain_str(enum intel_display_power_domain domain)
2374{
2375 switch (domain) {
2376 case POWER_DOMAIN_PIPE_A:
2377 return "PIPE_A";
2378 case POWER_DOMAIN_PIPE_B:
2379 return "PIPE_B";
2380 case POWER_DOMAIN_PIPE_C:
2381 return "PIPE_C";
2382 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2383 return "PIPE_A_PANEL_FITTER";
2384 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2385 return "PIPE_B_PANEL_FITTER";
2386 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2387 return "PIPE_C_PANEL_FITTER";
2388 case POWER_DOMAIN_TRANSCODER_A:
2389 return "TRANSCODER_A";
2390 case POWER_DOMAIN_TRANSCODER_B:
2391 return "TRANSCODER_B";
2392 case POWER_DOMAIN_TRANSCODER_C:
2393 return "TRANSCODER_C";
2394 case POWER_DOMAIN_TRANSCODER_EDP:
2395 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002396 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2397 return "PORT_DDI_A_2_LANES";
2398 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2399 return "PORT_DDI_A_4_LANES";
2400 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2401 return "PORT_DDI_B_2_LANES";
2402 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2403 return "PORT_DDI_B_4_LANES";
2404 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2405 return "PORT_DDI_C_2_LANES";
2406 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2407 return "PORT_DDI_C_4_LANES";
2408 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2409 return "PORT_DDI_D_2_LANES";
2410 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2411 return "PORT_DDI_D_4_LANES";
2412 case POWER_DOMAIN_PORT_DSI:
2413 return "PORT_DSI";
2414 case POWER_DOMAIN_PORT_CRT:
2415 return "PORT_CRT";
2416 case POWER_DOMAIN_PORT_OTHER:
2417 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002418 case POWER_DOMAIN_VGA:
2419 return "VGA";
2420 case POWER_DOMAIN_AUDIO:
2421 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002422 case POWER_DOMAIN_PLLS:
2423 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002424 case POWER_DOMAIN_AUX_A:
2425 return "AUX_A";
2426 case POWER_DOMAIN_AUX_B:
2427 return "AUX_B";
2428 case POWER_DOMAIN_AUX_C:
2429 return "AUX_C";
2430 case POWER_DOMAIN_AUX_D:
2431 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002432 case POWER_DOMAIN_INIT:
2433 return "INIT";
2434 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002435 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002436 return "?";
2437 }
2438}
2439
2440static int i915_power_domain_info(struct seq_file *m, void *unused)
2441{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002442 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002443 struct drm_device *dev = node->minor->dev;
2444 struct drm_i915_private *dev_priv = dev->dev_private;
2445 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2446 int i;
2447
2448 mutex_lock(&power_domains->lock);
2449
2450 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2451 for (i = 0; i < power_domains->power_well_count; i++) {
2452 struct i915_power_well *power_well;
2453 enum intel_display_power_domain power_domain;
2454
2455 power_well = &power_domains->power_wells[i];
2456 seq_printf(m, "%-25s %d\n", power_well->name,
2457 power_well->count);
2458
2459 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2460 power_domain++) {
2461 if (!(BIT(power_domain) & power_well->domains))
2462 continue;
2463
2464 seq_printf(m, " %-23s %d\n",
2465 power_domain_str(power_domain),
2466 power_domains->domain_use_count[power_domain]);
2467 }
2468 }
2469
2470 mutex_unlock(&power_domains->lock);
2471
2472 return 0;
2473}
2474
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002475static void intel_seq_print_mode(struct seq_file *m, int tabs,
2476 struct drm_display_mode *mode)
2477{
2478 int i;
2479
2480 for (i = 0; i < tabs; i++)
2481 seq_putc(m, '\t');
2482
2483 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",
2484 mode->base.id, mode->name,
2485 mode->vrefresh, mode->clock,
2486 mode->hdisplay, mode->hsync_start,
2487 mode->hsync_end, mode->htotal,
2488 mode->vdisplay, mode->vsync_start,
2489 mode->vsync_end, mode->vtotal,
2490 mode->type, mode->flags);
2491}
2492
2493static void intel_encoder_info(struct seq_file *m,
2494 struct intel_crtc *intel_crtc,
2495 struct intel_encoder *intel_encoder)
2496{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002497 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002498 struct drm_device *dev = node->minor->dev;
2499 struct drm_crtc *crtc = &intel_crtc->base;
2500 struct intel_connector *intel_connector;
2501 struct drm_encoder *encoder;
2502
2503 encoder = &intel_encoder->base;
2504 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002505 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002506 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2507 struct drm_connector *connector = &intel_connector->base;
2508 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2509 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002510 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002511 drm_get_connector_status_name(connector->status));
2512 if (connector->status == connector_status_connected) {
2513 struct drm_display_mode *mode = &crtc->mode;
2514 seq_printf(m, ", mode:\n");
2515 intel_seq_print_mode(m, 2, mode);
2516 } else {
2517 seq_putc(m, '\n');
2518 }
2519 }
2520}
2521
2522static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2523{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002524 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002525 struct drm_device *dev = node->minor->dev;
2526 struct drm_crtc *crtc = &intel_crtc->base;
2527 struct intel_encoder *intel_encoder;
2528
Matt Roper5aa8a932014-06-16 10:12:55 -07002529 if (crtc->primary->fb)
2530 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2531 crtc->primary->fb->base.id, crtc->x, crtc->y,
2532 crtc->primary->fb->width, crtc->primary->fb->height);
2533 else
2534 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002535 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2536 intel_encoder_info(m, intel_crtc, intel_encoder);
2537}
2538
2539static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2540{
2541 struct drm_display_mode *mode = panel->fixed_mode;
2542
2543 seq_printf(m, "\tfixed mode:\n");
2544 intel_seq_print_mode(m, 2, mode);
2545}
2546
2547static void intel_dp_info(struct seq_file *m,
2548 struct intel_connector *intel_connector)
2549{
2550 struct intel_encoder *intel_encoder = intel_connector->encoder;
2551 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2552
2553 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2554 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2555 "no");
2556 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2557 intel_panel_info(m, &intel_connector->panel);
2558}
2559
2560static void intel_hdmi_info(struct seq_file *m,
2561 struct intel_connector *intel_connector)
2562{
2563 struct intel_encoder *intel_encoder = intel_connector->encoder;
2564 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2565
2566 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2567 "no");
2568}
2569
2570static void intel_lvds_info(struct seq_file *m,
2571 struct intel_connector *intel_connector)
2572{
2573 intel_panel_info(m, &intel_connector->panel);
2574}
2575
2576static void intel_connector_info(struct seq_file *m,
2577 struct drm_connector *connector)
2578{
2579 struct intel_connector *intel_connector = to_intel_connector(connector);
2580 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002581 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002582
2583 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002584 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002585 drm_get_connector_status_name(connector->status));
2586 if (connector->status == connector_status_connected) {
2587 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2588 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2589 connector->display_info.width_mm,
2590 connector->display_info.height_mm);
2591 seq_printf(m, "\tsubpixel order: %s\n",
2592 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2593 seq_printf(m, "\tCEA rev: %d\n",
2594 connector->display_info.cea_rev);
2595 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002596 if (intel_encoder) {
2597 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2598 intel_encoder->type == INTEL_OUTPUT_EDP)
2599 intel_dp_info(m, intel_connector);
2600 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2601 intel_hdmi_info(m, intel_connector);
2602 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2603 intel_lvds_info(m, intel_connector);
2604 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002605
Jesse Barnesf103fc72014-02-20 12:39:57 -08002606 seq_printf(m, "\tmodes:\n");
2607 list_for_each_entry(mode, &connector->modes, head)
2608 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002609}
2610
Chris Wilson065f2ec22014-03-12 09:13:13 +00002611static bool cursor_active(struct drm_device *dev, int pipe)
2612{
2613 struct drm_i915_private *dev_priv = dev->dev_private;
2614 u32 state;
2615
2616 if (IS_845G(dev) || IS_I865G(dev))
2617 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002618 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002619 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002620
2621 return state;
2622}
2623
2624static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2625{
2626 struct drm_i915_private *dev_priv = dev->dev_private;
2627 u32 pos;
2628
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002629 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00002630
2631 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2632 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2633 *x = -*x;
2634
2635 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2636 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2637 *y = -*y;
2638
2639 return cursor_active(dev, pipe);
2640}
2641
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002642static int i915_display_info(struct seq_file *m, void *unused)
2643{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002644 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002645 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002646 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002647 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002648 struct drm_connector *connector;
2649
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002650 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002651 drm_modeset_lock_all(dev);
2652 seq_printf(m, "CRTC info\n");
2653 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002654 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002655 bool active;
2656 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002657
Chris Wilson57127ef2014-07-04 08:20:11 +01002658 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00002659 crtc->base.base.id, pipe_name(crtc->pipe),
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002660 yesno(crtc->active), crtc->config->pipe_src_w,
2661 crtc->config->pipe_src_h);
Paulo Zanonia23dc652014-04-01 14:55:11 -03002662 if (crtc->active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002663 intel_crtc_info(m, crtc);
2664
Paulo Zanonia23dc652014-04-01 14:55:11 -03002665 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002666 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 +03002667 yesno(crtc->cursor_base),
Chris Wilson57127ef2014-07-04 08:20:11 +01002668 x, y, crtc->cursor_width, crtc->cursor_height,
2669 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002670 }
Daniel Vettercace8412014-05-22 17:56:31 +02002671
2672 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2673 yesno(!crtc->cpu_fifo_underrun_disabled),
2674 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002675 }
2676
2677 seq_printf(m, "\n");
2678 seq_printf(m, "Connector info\n");
2679 seq_printf(m, "--------------\n");
2680 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2681 intel_connector_info(m, connector);
2682 }
2683 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002684 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002685
2686 return 0;
2687}
2688
Ben Widawskye04934c2014-06-30 09:53:42 -07002689static int i915_semaphore_status(struct seq_file *m, void *unused)
2690{
2691 struct drm_info_node *node = (struct drm_info_node *) m->private;
2692 struct drm_device *dev = node->minor->dev;
2693 struct drm_i915_private *dev_priv = dev->dev_private;
2694 struct intel_engine_cs *ring;
2695 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2696 int i, j, ret;
2697
2698 if (!i915_semaphore_is_enabled(dev)) {
2699 seq_puts(m, "Semaphores are disabled\n");
2700 return 0;
2701 }
2702
2703 ret = mutex_lock_interruptible(&dev->struct_mutex);
2704 if (ret)
2705 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002706 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002707
2708 if (IS_BROADWELL(dev)) {
2709 struct page *page;
2710 uint64_t *seqno;
2711
2712 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2713
2714 seqno = (uint64_t *)kmap_atomic(page);
2715 for_each_ring(ring, dev_priv, i) {
2716 uint64_t offset;
2717
2718 seq_printf(m, "%s\n", ring->name);
2719
2720 seq_puts(m, " Last signal:");
2721 for (j = 0; j < num_rings; j++) {
2722 offset = i * I915_NUM_RINGS + j;
2723 seq_printf(m, "0x%08llx (0x%02llx) ",
2724 seqno[offset], offset * 8);
2725 }
2726 seq_putc(m, '\n');
2727
2728 seq_puts(m, " Last wait: ");
2729 for (j = 0; j < num_rings; j++) {
2730 offset = i + (j * I915_NUM_RINGS);
2731 seq_printf(m, "0x%08llx (0x%02llx) ",
2732 seqno[offset], offset * 8);
2733 }
2734 seq_putc(m, '\n');
2735
2736 }
2737 kunmap_atomic(seqno);
2738 } else {
2739 seq_puts(m, " Last signal:");
2740 for_each_ring(ring, dev_priv, i)
2741 for (j = 0; j < num_rings; j++)
2742 seq_printf(m, "0x%08x\n",
2743 I915_READ(ring->semaphore.mbox.signal[j]));
2744 seq_putc(m, '\n');
2745 }
2746
2747 seq_puts(m, "\nSync seqno:\n");
2748 for_each_ring(ring, dev_priv, i) {
2749 for (j = 0; j < num_rings; j++) {
2750 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2751 }
2752 seq_putc(m, '\n');
2753 }
2754 seq_putc(m, '\n');
2755
Paulo Zanoni03872062014-07-09 14:31:57 -03002756 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002757 mutex_unlock(&dev->struct_mutex);
2758 return 0;
2759}
2760
Daniel Vetter728e29d2014-06-25 22:01:53 +03002761static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2762{
2763 struct drm_info_node *node = (struct drm_info_node *) m->private;
2764 struct drm_device *dev = node->minor->dev;
2765 struct drm_i915_private *dev_priv = dev->dev_private;
2766 int i;
2767
2768 drm_modeset_lock_all(dev);
2769 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2770 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2771
2772 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002773 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002774 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03002775 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002776 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2777 seq_printf(m, " dpll_md: 0x%08x\n",
2778 pll->config.hw_state.dpll_md);
2779 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2780 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2781 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002782 }
2783 drm_modeset_unlock_all(dev);
2784
2785 return 0;
2786}
2787
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01002788static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01002789{
2790 int i;
2791 int ret;
2792 struct drm_info_node *node = (struct drm_info_node *) m->private;
2793 struct drm_device *dev = node->minor->dev;
2794 struct drm_i915_private *dev_priv = dev->dev_private;
2795
Arun Siluvery888b5992014-08-26 14:44:51 +01002796 ret = mutex_lock_interruptible(&dev->struct_mutex);
2797 if (ret)
2798 return ret;
2799
2800 intel_runtime_pm_get(dev_priv);
2801
Mika Kuoppala72253422014-10-07 17:21:26 +03002802 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
2803 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002804 u32 addr, mask, value, read;
2805 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01002806
Mika Kuoppala72253422014-10-07 17:21:26 +03002807 addr = dev_priv->workarounds.reg[i].addr;
2808 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002809 value = dev_priv->workarounds.reg[i].value;
2810 read = I915_READ(addr);
2811 ok = (value & mask) == (read & mask);
2812 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
2813 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01002814 }
2815
2816 intel_runtime_pm_put(dev_priv);
2817 mutex_unlock(&dev->struct_mutex);
2818
2819 return 0;
2820}
2821
Damien Lespiauc5511e42014-11-04 17:06:51 +00002822static int i915_ddb_info(struct seq_file *m, void *unused)
2823{
2824 struct drm_info_node *node = m->private;
2825 struct drm_device *dev = node->minor->dev;
2826 struct drm_i915_private *dev_priv = dev->dev_private;
2827 struct skl_ddb_allocation *ddb;
2828 struct skl_ddb_entry *entry;
2829 enum pipe pipe;
2830 int plane;
2831
Damien Lespiau2fcffe12014-12-03 17:33:24 +00002832 if (INTEL_INFO(dev)->gen < 9)
2833 return 0;
2834
Damien Lespiauc5511e42014-11-04 17:06:51 +00002835 drm_modeset_lock_all(dev);
2836
2837 ddb = &dev_priv->wm.skl_hw.ddb;
2838
2839 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
2840
2841 for_each_pipe(dev_priv, pipe) {
2842 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
2843
2844 for_each_plane(pipe, plane) {
2845 entry = &ddb->plane[pipe][plane];
2846 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
2847 entry->start, entry->end,
2848 skl_ddb_entry_size(entry));
2849 }
2850
2851 entry = &ddb->cursor[pipe];
2852 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
2853 entry->end, skl_ddb_entry_size(entry));
2854 }
2855
2856 drm_modeset_unlock_all(dev);
2857
2858 return 0;
2859}
2860
Damien Lespiau07144422013-10-15 18:55:40 +01002861struct pipe_crc_info {
2862 const char *name;
2863 struct drm_device *dev;
2864 enum pipe pipe;
2865};
2866
Dave Airlie11bed952014-05-12 15:22:27 +10002867static int i915_dp_mst_info(struct seq_file *m, void *unused)
2868{
2869 struct drm_info_node *node = (struct drm_info_node *) m->private;
2870 struct drm_device *dev = node->minor->dev;
2871 struct drm_encoder *encoder;
2872 struct intel_encoder *intel_encoder;
2873 struct intel_digital_port *intel_dig_port;
2874 drm_modeset_lock_all(dev);
2875 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2876 intel_encoder = to_intel_encoder(encoder);
2877 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
2878 continue;
2879 intel_dig_port = enc_to_dig_port(encoder);
2880 if (!intel_dig_port->dp.can_mst)
2881 continue;
2882
2883 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
2884 }
2885 drm_modeset_unlock_all(dev);
2886 return 0;
2887}
2888
Damien Lespiau07144422013-10-15 18:55:40 +01002889static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01002890{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002891 struct pipe_crc_info *info = inode->i_private;
2892 struct drm_i915_private *dev_priv = info->dev->dev_private;
2893 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2894
Daniel Vetter7eb1c492013-11-14 11:30:43 +01002895 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
2896 return -ENODEV;
2897
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002898 spin_lock_irq(&pipe_crc->lock);
2899
2900 if (pipe_crc->opened) {
2901 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002902 return -EBUSY; /* already open */
2903 }
2904
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002905 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01002906 filep->private_data = inode->i_private;
2907
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002908 spin_unlock_irq(&pipe_crc->lock);
2909
Damien Lespiau07144422013-10-15 18:55:40 +01002910 return 0;
2911}
2912
2913static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
2914{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002915 struct pipe_crc_info *info = inode->i_private;
2916 struct drm_i915_private *dev_priv = info->dev->dev_private;
2917 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2918
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002919 spin_lock_irq(&pipe_crc->lock);
2920 pipe_crc->opened = false;
2921 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002922
Damien Lespiau07144422013-10-15 18:55:40 +01002923 return 0;
2924}
2925
2926/* (6 fields, 8 chars each, space separated (5) + '\n') */
2927#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
2928/* account for \'0' */
2929#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
2930
2931static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
2932{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002933 assert_spin_locked(&pipe_crc->lock);
2934 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2935 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01002936}
Shuang He8bf1e9f2013-10-15 18:55:27 +01002937
Damien Lespiau07144422013-10-15 18:55:40 +01002938static ssize_t
2939i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
2940 loff_t *pos)
2941{
2942 struct pipe_crc_info *info = filep->private_data;
2943 struct drm_device *dev = info->dev;
2944 struct drm_i915_private *dev_priv = dev->dev_private;
2945 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2946 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002947 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01002948 ssize_t bytes_read;
2949
2950 /*
2951 * Don't allow user space to provide buffers not big enough to hold
2952 * a line of data.
2953 */
2954 if (count < PIPE_CRC_LINE_LEN)
2955 return -EINVAL;
2956
2957 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2958 return 0;
2959
2960 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002961 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002962 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002963 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002964
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002965 if (filep->f_flags & O_NONBLOCK) {
2966 spin_unlock_irq(&pipe_crc->lock);
2967 return -EAGAIN;
2968 }
2969
2970 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2971 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2972 if (ret) {
2973 spin_unlock_irq(&pipe_crc->lock);
2974 return ret;
2975 }
Damien Lespiau07144422013-10-15 18:55:40 +01002976 }
2977
2978 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002979 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002980
Damien Lespiau07144422013-10-15 18:55:40 +01002981 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002982 while (n_entries > 0) {
2983 struct intel_pipe_crc_entry *entry =
2984 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01002985 int ret;
2986
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002987 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2988 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
2989 break;
2990
2991 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
2992 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
2993
Damien Lespiau07144422013-10-15 18:55:40 +01002994 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
2995 "%8u %8x %8x %8x %8x %8x\n",
2996 entry->frame, entry->crc[0],
2997 entry->crc[1], entry->crc[2],
2998 entry->crc[3], entry->crc[4]);
2999
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003000 spin_unlock_irq(&pipe_crc->lock);
3001
3002 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003003 if (ret == PIPE_CRC_LINE_LEN)
3004 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003005
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003006 user_buf += PIPE_CRC_LINE_LEN;
3007 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003008
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003009 spin_lock_irq(&pipe_crc->lock);
3010 }
3011
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003012 spin_unlock_irq(&pipe_crc->lock);
3013
Damien Lespiau07144422013-10-15 18:55:40 +01003014 return bytes_read;
3015}
3016
3017static const struct file_operations i915_pipe_crc_fops = {
3018 .owner = THIS_MODULE,
3019 .open = i915_pipe_crc_open,
3020 .read = i915_pipe_crc_read,
3021 .release = i915_pipe_crc_release,
3022};
3023
3024static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3025 {
3026 .name = "i915_pipe_A_crc",
3027 .pipe = PIPE_A,
3028 },
3029 {
3030 .name = "i915_pipe_B_crc",
3031 .pipe = PIPE_B,
3032 },
3033 {
3034 .name = "i915_pipe_C_crc",
3035 .pipe = PIPE_C,
3036 },
3037};
3038
3039static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3040 enum pipe pipe)
3041{
3042 struct drm_device *dev = minor->dev;
3043 struct dentry *ent;
3044 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3045
3046 info->dev = dev;
3047 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3048 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003049 if (!ent)
3050 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003051
3052 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003053}
3054
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003055static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003056 "none",
3057 "plane1",
3058 "plane2",
3059 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003060 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003061 "TV",
3062 "DP-B",
3063 "DP-C",
3064 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003065 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003066};
3067
3068static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3069{
3070 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3071 return pipe_crc_sources[source];
3072}
3073
Damien Lespiaubd9db022013-10-15 18:55:36 +01003074static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003075{
3076 struct drm_device *dev = m->private;
3077 struct drm_i915_private *dev_priv = dev->dev_private;
3078 int i;
3079
3080 for (i = 0; i < I915_MAX_PIPES; i++)
3081 seq_printf(m, "%c %s\n", pipe_name(i),
3082 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3083
3084 return 0;
3085}
3086
Damien Lespiaubd9db022013-10-15 18:55:36 +01003087static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003088{
3089 struct drm_device *dev = inode->i_private;
3090
Damien Lespiaubd9db022013-10-15 18:55:36 +01003091 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003092}
3093
Daniel Vetter46a19182013-11-01 10:50:20 +01003094static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003095 uint32_t *val)
3096{
Daniel Vetter46a19182013-11-01 10:50:20 +01003097 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3098 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3099
3100 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003101 case INTEL_PIPE_CRC_SOURCE_PIPE:
3102 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3103 break;
3104 case INTEL_PIPE_CRC_SOURCE_NONE:
3105 *val = 0;
3106 break;
3107 default:
3108 return -EINVAL;
3109 }
3110
3111 return 0;
3112}
3113
Daniel Vetter46a19182013-11-01 10:50:20 +01003114static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3115 enum intel_pipe_crc_source *source)
3116{
3117 struct intel_encoder *encoder;
3118 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003119 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003120 int ret = 0;
3121
3122 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3123
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003124 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003125 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003126 if (!encoder->base.crtc)
3127 continue;
3128
3129 crtc = to_intel_crtc(encoder->base.crtc);
3130
3131 if (crtc->pipe != pipe)
3132 continue;
3133
3134 switch (encoder->type) {
3135 case INTEL_OUTPUT_TVOUT:
3136 *source = INTEL_PIPE_CRC_SOURCE_TV;
3137 break;
3138 case INTEL_OUTPUT_DISPLAYPORT:
3139 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003140 dig_port = enc_to_dig_port(&encoder->base);
3141 switch (dig_port->port) {
3142 case PORT_B:
3143 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3144 break;
3145 case PORT_C:
3146 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3147 break;
3148 case PORT_D:
3149 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3150 break;
3151 default:
3152 WARN(1, "nonexisting DP port %c\n",
3153 port_name(dig_port->port));
3154 break;
3155 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003156 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003157 default:
3158 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003159 }
3160 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003161 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003162
3163 return ret;
3164}
3165
3166static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3167 enum pipe pipe,
3168 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003169 uint32_t *val)
3170{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003171 struct drm_i915_private *dev_priv = dev->dev_private;
3172 bool need_stable_symbols = false;
3173
Daniel Vetter46a19182013-11-01 10:50:20 +01003174 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3175 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3176 if (ret)
3177 return ret;
3178 }
3179
3180 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003181 case INTEL_PIPE_CRC_SOURCE_PIPE:
3182 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3183 break;
3184 case INTEL_PIPE_CRC_SOURCE_DP_B:
3185 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003186 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003187 break;
3188 case INTEL_PIPE_CRC_SOURCE_DP_C:
3189 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003190 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003191 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003192 case INTEL_PIPE_CRC_SOURCE_DP_D:
3193 if (!IS_CHERRYVIEW(dev))
3194 return -EINVAL;
3195 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3196 need_stable_symbols = true;
3197 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003198 case INTEL_PIPE_CRC_SOURCE_NONE:
3199 *val = 0;
3200 break;
3201 default:
3202 return -EINVAL;
3203 }
3204
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003205 /*
3206 * When the pipe CRC tap point is after the transcoders we need
3207 * to tweak symbol-level features to produce a deterministic series of
3208 * symbols for a given frame. We need to reset those features only once
3209 * a frame (instead of every nth symbol):
3210 * - DC-balance: used to ensure a better clock recovery from the data
3211 * link (SDVO)
3212 * - DisplayPort scrambling: used for EMI reduction
3213 */
3214 if (need_stable_symbols) {
3215 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3216
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003217 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003218 switch (pipe) {
3219 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003220 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003221 break;
3222 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003223 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003224 break;
3225 case PIPE_C:
3226 tmp |= PIPE_C_SCRAMBLE_RESET;
3227 break;
3228 default:
3229 return -EINVAL;
3230 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003231 I915_WRITE(PORT_DFT2_G4X, tmp);
3232 }
3233
Daniel Vetter7ac01292013-10-18 16:37:06 +02003234 return 0;
3235}
3236
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003237static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003238 enum pipe pipe,
3239 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003240 uint32_t *val)
3241{
Daniel Vetter84093602013-11-01 10:50:21 +01003242 struct drm_i915_private *dev_priv = dev->dev_private;
3243 bool need_stable_symbols = false;
3244
Daniel Vetter46a19182013-11-01 10:50:20 +01003245 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3246 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3247 if (ret)
3248 return ret;
3249 }
3250
3251 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003252 case INTEL_PIPE_CRC_SOURCE_PIPE:
3253 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3254 break;
3255 case INTEL_PIPE_CRC_SOURCE_TV:
3256 if (!SUPPORTS_TV(dev))
3257 return -EINVAL;
3258 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3259 break;
3260 case INTEL_PIPE_CRC_SOURCE_DP_B:
3261 if (!IS_G4X(dev))
3262 return -EINVAL;
3263 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003264 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003265 break;
3266 case INTEL_PIPE_CRC_SOURCE_DP_C:
3267 if (!IS_G4X(dev))
3268 return -EINVAL;
3269 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003270 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003271 break;
3272 case INTEL_PIPE_CRC_SOURCE_DP_D:
3273 if (!IS_G4X(dev))
3274 return -EINVAL;
3275 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003276 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003277 break;
3278 case INTEL_PIPE_CRC_SOURCE_NONE:
3279 *val = 0;
3280 break;
3281 default:
3282 return -EINVAL;
3283 }
3284
Daniel Vetter84093602013-11-01 10:50:21 +01003285 /*
3286 * When the pipe CRC tap point is after the transcoders we need
3287 * to tweak symbol-level features to produce a deterministic series of
3288 * symbols for a given frame. We need to reset those features only once
3289 * a frame (instead of every nth symbol):
3290 * - DC-balance: used to ensure a better clock recovery from the data
3291 * link (SDVO)
3292 * - DisplayPort scrambling: used for EMI reduction
3293 */
3294 if (need_stable_symbols) {
3295 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3296
3297 WARN_ON(!IS_G4X(dev));
3298
3299 I915_WRITE(PORT_DFT_I9XX,
3300 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3301
3302 if (pipe == PIPE_A)
3303 tmp |= PIPE_A_SCRAMBLE_RESET;
3304 else
3305 tmp |= PIPE_B_SCRAMBLE_RESET;
3306
3307 I915_WRITE(PORT_DFT2_G4X, tmp);
3308 }
3309
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003310 return 0;
3311}
3312
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003313static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3314 enum pipe pipe)
3315{
3316 struct drm_i915_private *dev_priv = dev->dev_private;
3317 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3318
Ville Syrjäläeb736672014-12-09 21:28:28 +02003319 switch (pipe) {
3320 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003321 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003322 break;
3323 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003324 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003325 break;
3326 case PIPE_C:
3327 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3328 break;
3329 default:
3330 return;
3331 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003332 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3333 tmp &= ~DC_BALANCE_RESET_VLV;
3334 I915_WRITE(PORT_DFT2_G4X, tmp);
3335
3336}
3337
Daniel Vetter84093602013-11-01 10:50:21 +01003338static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3339 enum pipe pipe)
3340{
3341 struct drm_i915_private *dev_priv = dev->dev_private;
3342 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3343
3344 if (pipe == PIPE_A)
3345 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3346 else
3347 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3348 I915_WRITE(PORT_DFT2_G4X, tmp);
3349
3350 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3351 I915_WRITE(PORT_DFT_I9XX,
3352 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3353 }
3354}
3355
Daniel Vetter46a19182013-11-01 10:50:20 +01003356static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003357 uint32_t *val)
3358{
Daniel Vetter46a19182013-11-01 10:50:20 +01003359 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3360 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3361
3362 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003363 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3364 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3365 break;
3366 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3367 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3368 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003369 case INTEL_PIPE_CRC_SOURCE_PIPE:
3370 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3371 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003372 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003373 *val = 0;
3374 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003375 default:
3376 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003377 }
3378
3379 return 0;
3380}
3381
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003382static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3383{
3384 struct drm_i915_private *dev_priv = dev->dev_private;
3385 struct intel_crtc *crtc =
3386 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3387
3388 drm_modeset_lock_all(dev);
3389 /*
3390 * If we use the eDP transcoder we need to make sure that we don't
3391 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3392 * relevant on hsw with pipe A when using the always-on power well
3393 * routing.
3394 */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02003395 if (crtc->config->cpu_transcoder == TRANSCODER_EDP &&
3396 !crtc->config->pch_pfit.enabled) {
3397 crtc->config->pch_pfit.force_thru = true;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003398
3399 intel_display_power_get(dev_priv,
3400 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3401
3402 dev_priv->display.crtc_disable(&crtc->base);
3403 dev_priv->display.crtc_enable(&crtc->base);
3404 }
3405 drm_modeset_unlock_all(dev);
3406}
3407
3408static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3409{
3410 struct drm_i915_private *dev_priv = dev->dev_private;
3411 struct intel_crtc *crtc =
3412 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3413
3414 drm_modeset_lock_all(dev);
3415 /*
3416 * If we use the eDP transcoder we need to make sure that we don't
3417 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3418 * relevant on hsw with pipe A when using the always-on power well
3419 * routing.
3420 */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02003421 if (crtc->config->pch_pfit.force_thru) {
3422 crtc->config->pch_pfit.force_thru = false;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003423
3424 dev_priv->display.crtc_disable(&crtc->base);
3425 dev_priv->display.crtc_enable(&crtc->base);
3426
3427 intel_display_power_put(dev_priv,
3428 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3429 }
3430 drm_modeset_unlock_all(dev);
3431}
3432
3433static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3434 enum pipe pipe,
3435 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003436 uint32_t *val)
3437{
Daniel Vetter46a19182013-11-01 10:50:20 +01003438 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3439 *source = INTEL_PIPE_CRC_SOURCE_PF;
3440
3441 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003442 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3443 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3444 break;
3445 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3446 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3447 break;
3448 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003449 if (IS_HASWELL(dev) && pipe == PIPE_A)
3450 hsw_trans_edp_pipe_A_crc_wa(dev);
3451
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003452 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3453 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003454 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003455 *val = 0;
3456 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003457 default:
3458 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003459 }
3460
3461 return 0;
3462}
3463
Daniel Vetter926321d2013-10-16 13:30:34 +02003464static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3465 enum intel_pipe_crc_source source)
3466{
3467 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003468 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003469 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3470 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003471 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003472 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003473
Damien Lespiaucc3da172013-10-15 18:55:31 +01003474 if (pipe_crc->source == source)
3475 return 0;
3476
Damien Lespiauae676fc2013-10-15 18:55:32 +01003477 /* forbid changing the source without going back to 'none' */
3478 if (pipe_crc->source && source)
3479 return -EINVAL;
3480
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003481 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3482 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3483 return -EIO;
3484 }
3485
Daniel Vetter52f843f2013-10-21 17:26:38 +02003486 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003487 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003488 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003489 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003490 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003491 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003492 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003493 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003494 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003495 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003496
3497 if (ret != 0)
3498 return ret;
3499
Damien Lespiau4b584362013-10-15 18:55:33 +01003500 /* none -> real source transition */
3501 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003502 struct intel_pipe_crc_entry *entries;
3503
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003504 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3505 pipe_name(pipe), pipe_crc_source_name(source));
3506
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003507 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3508 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003509 GFP_KERNEL);
3510 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003511 return -ENOMEM;
3512
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003513 /*
3514 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3515 * enabled and disabled dynamically based on package C states,
3516 * user space can't make reliable use of the CRCs, so let's just
3517 * completely disable it.
3518 */
3519 hsw_disable_ips(crtc);
3520
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003521 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003522 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003523 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003524 pipe_crc->head = 0;
3525 pipe_crc->tail = 0;
3526 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003527 }
3528
Damien Lespiaucc3da172013-10-15 18:55:31 +01003529 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003530
Daniel Vetter926321d2013-10-16 13:30:34 +02003531 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3532 POSTING_READ(PIPE_CRC_CTL(pipe));
3533
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003534 /* real source -> none transition */
3535 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003536 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003537 struct intel_crtc *crtc =
3538 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003539
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003540 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3541 pipe_name(pipe));
3542
Daniel Vettera33d7102014-06-06 08:22:08 +02003543 drm_modeset_lock(&crtc->base.mutex, NULL);
3544 if (crtc->active)
3545 intel_wait_for_vblank(dev, pipe);
3546 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003547
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003548 spin_lock_irq(&pipe_crc->lock);
3549 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003550 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003551 pipe_crc->head = 0;
3552 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003553 spin_unlock_irq(&pipe_crc->lock);
3554
3555 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003556
3557 if (IS_G4X(dev))
3558 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003559 else if (IS_VALLEYVIEW(dev))
3560 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003561 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3562 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003563
3564 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003565 }
3566
Daniel Vetter926321d2013-10-16 13:30:34 +02003567 return 0;
3568}
3569
3570/*
3571 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003572 * command: wsp* object wsp+ name wsp+ source wsp*
3573 * object: 'pipe'
3574 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003575 * source: (none | plane1 | plane2 | pf)
3576 * wsp: (#0x20 | #0x9 | #0xA)+
3577 *
3578 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003579 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3580 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003581 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003582static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003583{
3584 int n_words = 0;
3585
3586 while (*buf) {
3587 char *end;
3588
3589 /* skip leading white space */
3590 buf = skip_spaces(buf);
3591 if (!*buf)
3592 break; /* end of buffer */
3593
3594 /* find end of word */
3595 for (end = buf; *end && !isspace(*end); end++)
3596 ;
3597
3598 if (n_words == max_words) {
3599 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3600 max_words);
3601 return -EINVAL; /* ran out of words[] before bytes */
3602 }
3603
3604 if (*end)
3605 *end++ = '\0';
3606 words[n_words++] = buf;
3607 buf = end;
3608 }
3609
3610 return n_words;
3611}
3612
Damien Lespiaub94dec82013-10-15 18:55:35 +01003613enum intel_pipe_crc_object {
3614 PIPE_CRC_OBJECT_PIPE,
3615};
3616
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003617static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003618 "pipe",
3619};
3620
3621static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003622display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003623{
3624 int i;
3625
3626 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3627 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003628 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003629 return 0;
3630 }
3631
3632 return -EINVAL;
3633}
3634
Damien Lespiaubd9db022013-10-15 18:55:36 +01003635static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003636{
3637 const char name = buf[0];
3638
3639 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3640 return -EINVAL;
3641
3642 *pipe = name - 'A';
3643
3644 return 0;
3645}
3646
3647static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003648display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003649{
3650 int i;
3651
3652 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3653 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003654 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003655 return 0;
3656 }
3657
3658 return -EINVAL;
3659}
3660
Damien Lespiaubd9db022013-10-15 18:55:36 +01003661static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003662{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003663#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003664 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003665 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003666 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003667 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003668 enum intel_pipe_crc_source source;
3669
Damien Lespiaubd9db022013-10-15 18:55:36 +01003670 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003671 if (n_words != N_WORDS) {
3672 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3673 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003674 return -EINVAL;
3675 }
3676
Damien Lespiaubd9db022013-10-15 18:55:36 +01003677 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003678 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003679 return -EINVAL;
3680 }
3681
Damien Lespiaubd9db022013-10-15 18:55:36 +01003682 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003683 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3684 return -EINVAL;
3685 }
3686
Damien Lespiaubd9db022013-10-15 18:55:36 +01003687 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003688 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003689 return -EINVAL;
3690 }
3691
3692 return pipe_crc_set_source(dev, pipe, source);
3693}
3694
Damien Lespiaubd9db022013-10-15 18:55:36 +01003695static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3696 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003697{
3698 struct seq_file *m = file->private_data;
3699 struct drm_device *dev = m->private;
3700 char *tmpbuf;
3701 int ret;
3702
3703 if (len == 0)
3704 return 0;
3705
3706 if (len > PAGE_SIZE - 1) {
3707 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3708 PAGE_SIZE);
3709 return -E2BIG;
3710 }
3711
3712 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3713 if (!tmpbuf)
3714 return -ENOMEM;
3715
3716 if (copy_from_user(tmpbuf, ubuf, len)) {
3717 ret = -EFAULT;
3718 goto out;
3719 }
3720 tmpbuf[len] = '\0';
3721
Damien Lespiaubd9db022013-10-15 18:55:36 +01003722 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003723
3724out:
3725 kfree(tmpbuf);
3726 if (ret < 0)
3727 return ret;
3728
3729 *offp += len;
3730 return len;
3731}
3732
Damien Lespiaubd9db022013-10-15 18:55:36 +01003733static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003734 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003735 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003736 .read = seq_read,
3737 .llseek = seq_lseek,
3738 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003739 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003740};
3741
Damien Lespiau97e94b22014-11-04 17:06:50 +00003742static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003743{
3744 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003745 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003746 int level;
3747
3748 drm_modeset_lock_all(dev);
3749
3750 for (level = 0; level < num_levels; level++) {
3751 unsigned int latency = wm[level];
3752
Damien Lespiau97e94b22014-11-04 17:06:50 +00003753 /*
3754 * - WM1+ latency values in 0.5us units
3755 * - latencies are in us on gen9
3756 */
3757 if (INTEL_INFO(dev)->gen >= 9)
3758 latency *= 10;
3759 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003760 latency *= 5;
3761
3762 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003763 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003764 }
3765
3766 drm_modeset_unlock_all(dev);
3767}
3768
3769static int pri_wm_latency_show(struct seq_file *m, void *data)
3770{
3771 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003772 struct drm_i915_private *dev_priv = dev->dev_private;
3773 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003774
Damien Lespiau97e94b22014-11-04 17:06:50 +00003775 if (INTEL_INFO(dev)->gen >= 9)
3776 latencies = dev_priv->wm.skl_latency;
3777 else
3778 latencies = to_i915(dev)->wm.pri_latency;
3779
3780 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003781
3782 return 0;
3783}
3784
3785static int spr_wm_latency_show(struct seq_file *m, void *data)
3786{
3787 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003788 struct drm_i915_private *dev_priv = dev->dev_private;
3789 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003790
Damien Lespiau97e94b22014-11-04 17:06:50 +00003791 if (INTEL_INFO(dev)->gen >= 9)
3792 latencies = dev_priv->wm.skl_latency;
3793 else
3794 latencies = to_i915(dev)->wm.spr_latency;
3795
3796 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003797
3798 return 0;
3799}
3800
3801static int cur_wm_latency_show(struct seq_file *m, void *data)
3802{
3803 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003804 struct drm_i915_private *dev_priv = dev->dev_private;
3805 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003806
Damien Lespiau97e94b22014-11-04 17:06:50 +00003807 if (INTEL_INFO(dev)->gen >= 9)
3808 latencies = dev_priv->wm.skl_latency;
3809 else
3810 latencies = to_i915(dev)->wm.cur_latency;
3811
3812 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003813
3814 return 0;
3815}
3816
3817static int pri_wm_latency_open(struct inode *inode, struct file *file)
3818{
3819 struct drm_device *dev = inode->i_private;
3820
Sonika Jindal9ad02572014-07-21 15:23:39 +05303821 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003822 return -ENODEV;
3823
3824 return single_open(file, pri_wm_latency_show, dev);
3825}
3826
3827static int spr_wm_latency_open(struct inode *inode, struct file *file)
3828{
3829 struct drm_device *dev = inode->i_private;
3830
Sonika Jindal9ad02572014-07-21 15:23:39 +05303831 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003832 return -ENODEV;
3833
3834 return single_open(file, spr_wm_latency_show, dev);
3835}
3836
3837static int cur_wm_latency_open(struct inode *inode, struct file *file)
3838{
3839 struct drm_device *dev = inode->i_private;
3840
Sonika Jindal9ad02572014-07-21 15:23:39 +05303841 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003842 return -ENODEV;
3843
3844 return single_open(file, cur_wm_latency_show, dev);
3845}
3846
3847static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003848 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003849{
3850 struct seq_file *m = file->private_data;
3851 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003852 uint16_t new[8] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003853 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003854 int level;
3855 int ret;
3856 char tmp[32];
3857
3858 if (len >= sizeof(tmp))
3859 return -EINVAL;
3860
3861 if (copy_from_user(tmp, ubuf, len))
3862 return -EFAULT;
3863
3864 tmp[len] = '\0';
3865
Damien Lespiau97e94b22014-11-04 17:06:50 +00003866 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
3867 &new[0], &new[1], &new[2], &new[3],
3868 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003869 if (ret != num_levels)
3870 return -EINVAL;
3871
3872 drm_modeset_lock_all(dev);
3873
3874 for (level = 0; level < num_levels; level++)
3875 wm[level] = new[level];
3876
3877 drm_modeset_unlock_all(dev);
3878
3879 return len;
3880}
3881
3882
3883static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3884 size_t len, loff_t *offp)
3885{
3886 struct seq_file *m = file->private_data;
3887 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003888 struct drm_i915_private *dev_priv = dev->dev_private;
3889 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003890
Damien Lespiau97e94b22014-11-04 17:06:50 +00003891 if (INTEL_INFO(dev)->gen >= 9)
3892 latencies = dev_priv->wm.skl_latency;
3893 else
3894 latencies = to_i915(dev)->wm.pri_latency;
3895
3896 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003897}
3898
3899static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3900 size_t len, loff_t *offp)
3901{
3902 struct seq_file *m = file->private_data;
3903 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003904 struct drm_i915_private *dev_priv = dev->dev_private;
3905 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003906
Damien Lespiau97e94b22014-11-04 17:06:50 +00003907 if (INTEL_INFO(dev)->gen >= 9)
3908 latencies = dev_priv->wm.skl_latency;
3909 else
3910 latencies = to_i915(dev)->wm.spr_latency;
3911
3912 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003913}
3914
3915static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3916 size_t len, loff_t *offp)
3917{
3918 struct seq_file *m = file->private_data;
3919 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003920 struct drm_i915_private *dev_priv = dev->dev_private;
3921 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003922
Damien Lespiau97e94b22014-11-04 17:06:50 +00003923 if (INTEL_INFO(dev)->gen >= 9)
3924 latencies = dev_priv->wm.skl_latency;
3925 else
3926 latencies = to_i915(dev)->wm.cur_latency;
3927
3928 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003929}
3930
3931static const struct file_operations i915_pri_wm_latency_fops = {
3932 .owner = THIS_MODULE,
3933 .open = pri_wm_latency_open,
3934 .read = seq_read,
3935 .llseek = seq_lseek,
3936 .release = single_release,
3937 .write = pri_wm_latency_write
3938};
3939
3940static const struct file_operations i915_spr_wm_latency_fops = {
3941 .owner = THIS_MODULE,
3942 .open = spr_wm_latency_open,
3943 .read = seq_read,
3944 .llseek = seq_lseek,
3945 .release = single_release,
3946 .write = spr_wm_latency_write
3947};
3948
3949static const struct file_operations i915_cur_wm_latency_fops = {
3950 .owner = THIS_MODULE,
3951 .open = cur_wm_latency_open,
3952 .read = seq_read,
3953 .llseek = seq_lseek,
3954 .release = single_release,
3955 .write = cur_wm_latency_write
3956};
3957
Kees Cook647416f2013-03-10 14:10:06 -07003958static int
3959i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003960{
Kees Cook647416f2013-03-10 14:10:06 -07003961 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003962 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003963
Kees Cook647416f2013-03-10 14:10:06 -07003964 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003965
Kees Cook647416f2013-03-10 14:10:06 -07003966 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003967}
3968
Kees Cook647416f2013-03-10 14:10:06 -07003969static int
3970i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003971{
Kees Cook647416f2013-03-10 14:10:06 -07003972 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03003973 struct drm_i915_private *dev_priv = dev->dev_private;
3974
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02003975 /*
3976 * There is no safeguard against this debugfs entry colliding
3977 * with the hangcheck calling same i915_handle_error() in
3978 * parallel, causing an explosion. For now we assume that the
3979 * test harness is responsible enough not to inject gpu hangs
3980 * while it is writing to 'i915_wedged'
3981 */
3982
3983 if (i915_reset_in_progress(&dev_priv->gpu_error))
3984 return -EAGAIN;
3985
Imre Deakd46c0512014-04-14 20:24:27 +03003986 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003987
Mika Kuoppala58174462014-02-25 17:11:26 +02003988 i915_handle_error(dev, val,
3989 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03003990
3991 intel_runtime_pm_put(dev_priv);
3992
Kees Cook647416f2013-03-10 14:10:06 -07003993 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003994}
3995
Kees Cook647416f2013-03-10 14:10:06 -07003996DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
3997 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003998 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003999
Kees Cook647416f2013-03-10 14:10:06 -07004000static int
4001i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004002{
Kees Cook647416f2013-03-10 14:10:06 -07004003 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004004 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004005
Kees Cook647416f2013-03-10 14:10:06 -07004006 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004007
Kees Cook647416f2013-03-10 14:10:06 -07004008 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004009}
4010
Kees Cook647416f2013-03-10 14:10:06 -07004011static int
4012i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004013{
Kees Cook647416f2013-03-10 14:10:06 -07004014 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004015 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004016 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004017
Kees Cook647416f2013-03-10 14:10:06 -07004018 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004019
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004020 ret = mutex_lock_interruptible(&dev->struct_mutex);
4021 if (ret)
4022 return ret;
4023
Daniel Vetter99584db2012-11-14 17:14:04 +01004024 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004025 mutex_unlock(&dev->struct_mutex);
4026
Kees Cook647416f2013-03-10 14:10:06 -07004027 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004028}
4029
Kees Cook647416f2013-03-10 14:10:06 -07004030DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4031 i915_ring_stop_get, i915_ring_stop_set,
4032 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004033
Chris Wilson094f9a52013-09-25 17:34:55 +01004034static int
4035i915_ring_missed_irq_get(void *data, u64 *val)
4036{
4037 struct drm_device *dev = data;
4038 struct drm_i915_private *dev_priv = dev->dev_private;
4039
4040 *val = dev_priv->gpu_error.missed_irq_rings;
4041 return 0;
4042}
4043
4044static int
4045i915_ring_missed_irq_set(void *data, u64 val)
4046{
4047 struct drm_device *dev = data;
4048 struct drm_i915_private *dev_priv = dev->dev_private;
4049 int ret;
4050
4051 /* Lock against concurrent debugfs callers */
4052 ret = mutex_lock_interruptible(&dev->struct_mutex);
4053 if (ret)
4054 return ret;
4055 dev_priv->gpu_error.missed_irq_rings = val;
4056 mutex_unlock(&dev->struct_mutex);
4057
4058 return 0;
4059}
4060
4061DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4062 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4063 "0x%08llx\n");
4064
4065static int
4066i915_ring_test_irq_get(void *data, u64 *val)
4067{
4068 struct drm_device *dev = data;
4069 struct drm_i915_private *dev_priv = dev->dev_private;
4070
4071 *val = dev_priv->gpu_error.test_irq_rings;
4072
4073 return 0;
4074}
4075
4076static int
4077i915_ring_test_irq_set(void *data, u64 val)
4078{
4079 struct drm_device *dev = data;
4080 struct drm_i915_private *dev_priv = dev->dev_private;
4081 int ret;
4082
4083 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4084
4085 /* Lock against concurrent debugfs callers */
4086 ret = mutex_lock_interruptible(&dev->struct_mutex);
4087 if (ret)
4088 return ret;
4089
4090 dev_priv->gpu_error.test_irq_rings = val;
4091 mutex_unlock(&dev->struct_mutex);
4092
4093 return 0;
4094}
4095
4096DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4097 i915_ring_test_irq_get, i915_ring_test_irq_set,
4098 "0x%08llx\n");
4099
Chris Wilsondd624af2013-01-15 12:39:35 +00004100#define DROP_UNBOUND 0x1
4101#define DROP_BOUND 0x2
4102#define DROP_RETIRE 0x4
4103#define DROP_ACTIVE 0x8
4104#define DROP_ALL (DROP_UNBOUND | \
4105 DROP_BOUND | \
4106 DROP_RETIRE | \
4107 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004108static int
4109i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004110{
Kees Cook647416f2013-03-10 14:10:06 -07004111 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004112
Kees Cook647416f2013-03-10 14:10:06 -07004113 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004114}
4115
Kees Cook647416f2013-03-10 14:10:06 -07004116static int
4117i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004118{
Kees Cook647416f2013-03-10 14:10:06 -07004119 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004120 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004121 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004122
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004123 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004124
4125 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4126 * on ioctls on -EAGAIN. */
4127 ret = mutex_lock_interruptible(&dev->struct_mutex);
4128 if (ret)
4129 return ret;
4130
4131 if (val & DROP_ACTIVE) {
4132 ret = i915_gpu_idle(dev);
4133 if (ret)
4134 goto unlock;
4135 }
4136
4137 if (val & (DROP_RETIRE | DROP_ACTIVE))
4138 i915_gem_retire_requests(dev);
4139
Chris Wilson21ab4e72014-09-09 11:16:08 +01004140 if (val & DROP_BOUND)
4141 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004142
Chris Wilson21ab4e72014-09-09 11:16:08 +01004143 if (val & DROP_UNBOUND)
4144 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004145
4146unlock:
4147 mutex_unlock(&dev->struct_mutex);
4148
Kees Cook647416f2013-03-10 14:10:06 -07004149 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004150}
4151
Kees Cook647416f2013-03-10 14:10:06 -07004152DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4153 i915_drop_caches_get, i915_drop_caches_set,
4154 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004155
Kees Cook647416f2013-03-10 14:10:06 -07004156static int
4157i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004158{
Kees Cook647416f2013-03-10 14:10:06 -07004159 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004160 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004161 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004162
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004163 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004164 return -ENODEV;
4165
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004166 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4167
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004168 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004169 if (ret)
4170 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004171
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004172 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004173 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004174
Kees Cook647416f2013-03-10 14:10:06 -07004175 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004176}
4177
Kees Cook647416f2013-03-10 14:10:06 -07004178static int
4179i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004180{
Kees Cook647416f2013-03-10 14:10:06 -07004181 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004182 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004183 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004184 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004185
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004186 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004187 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004188
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004189 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4190
Kees Cook647416f2013-03-10 14:10:06 -07004191 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004192
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004193 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004194 if (ret)
4195 return ret;
4196
Jesse Barnes358733e2011-07-27 11:53:01 -07004197 /*
4198 * Turbo will still be enabled, but won't go above the set value.
4199 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07004200 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004201 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004202
Ville Syrjälä03af2042014-06-28 02:03:53 +03004203 hw_max = dev_priv->rps.max_freq;
4204 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004205 } else {
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004206 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004207
4208 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07004209 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004210 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004211 }
4212
Ben Widawskyb39fb292014-03-19 18:31:11 -07004213 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004214 mutex_unlock(&dev_priv->rps.hw_lock);
4215 return -EINVAL;
4216 }
4217
Ben Widawskyb39fb292014-03-19 18:31:11 -07004218 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004219
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004220 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004221
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004222 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004223
Kees Cook647416f2013-03-10 14:10:06 -07004224 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004225}
4226
Kees Cook647416f2013-03-10 14:10:06 -07004227DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4228 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004229 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004230
Kees Cook647416f2013-03-10 14:10:06 -07004231static int
4232i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004233{
Kees Cook647416f2013-03-10 14:10:06 -07004234 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004235 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004236 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004237
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004238 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004239 return -ENODEV;
4240
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004241 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4242
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004243 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004244 if (ret)
4245 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004246
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004247 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004248 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004249
Kees Cook647416f2013-03-10 14:10:06 -07004250 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004251}
4252
Kees Cook647416f2013-03-10 14:10:06 -07004253static int
4254i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004255{
Kees Cook647416f2013-03-10 14:10:06 -07004256 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004257 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004258 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004259 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004260
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004261 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004262 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004263
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004264 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4265
Kees Cook647416f2013-03-10 14:10:06 -07004266 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004267
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004268 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004269 if (ret)
4270 return ret;
4271
Jesse Barnes1523c312012-05-25 12:34:54 -07004272 /*
4273 * Turbo will still be enabled, but won't go below the set value.
4274 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07004275 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004276 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004277
Ville Syrjälä03af2042014-06-28 02:03:53 +03004278 hw_max = dev_priv->rps.max_freq;
4279 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004280 } else {
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004281 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004282
4283 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07004284 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004285 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004286 }
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004287
Ben Widawskyb39fb292014-03-19 18:31:11 -07004288 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004289 mutex_unlock(&dev_priv->rps.hw_lock);
4290 return -EINVAL;
4291 }
4292
Ben Widawskyb39fb292014-03-19 18:31:11 -07004293 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004294
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004295 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004296
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004297 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004298
Kees Cook647416f2013-03-10 14:10:06 -07004299 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004300}
4301
Kees Cook647416f2013-03-10 14:10:06 -07004302DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4303 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004304 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004305
Kees Cook647416f2013-03-10 14:10:06 -07004306static int
4307i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004308{
Kees Cook647416f2013-03-10 14:10:06 -07004309 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004310 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004311 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004312 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004313
Daniel Vetter004777c2012-08-09 15:07:01 +02004314 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4315 return -ENODEV;
4316
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004317 ret = mutex_lock_interruptible(&dev->struct_mutex);
4318 if (ret)
4319 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004320 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004321
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004322 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004323
4324 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004325 mutex_unlock(&dev_priv->dev->struct_mutex);
4326
Kees Cook647416f2013-03-10 14:10:06 -07004327 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004328
Kees Cook647416f2013-03-10 14:10:06 -07004329 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004330}
4331
Kees Cook647416f2013-03-10 14:10:06 -07004332static int
4333i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004334{
Kees Cook647416f2013-03-10 14:10:06 -07004335 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004336 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004337 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004338
Daniel Vetter004777c2012-08-09 15:07:01 +02004339 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4340 return -ENODEV;
4341
Kees Cook647416f2013-03-10 14:10:06 -07004342 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004343 return -EINVAL;
4344
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004345 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004346 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004347
4348 /* Update the cache sharing policy here as well */
4349 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4350 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4351 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4352 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4353
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004354 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004355 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004356}
4357
Kees Cook647416f2013-03-10 14:10:06 -07004358DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4359 i915_cache_sharing_get, i915_cache_sharing_set,
4360 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004361
Jeff McGee38732182015-02-13 10:27:54 -06004362static int i915_sseu_status(struct seq_file *m, void *unused)
4363{
4364 struct drm_info_node *node = (struct drm_info_node *) m->private;
4365 struct drm_device *dev = node->minor->dev;
Jeff McGee7f992ab2015-02-13 10:27:55 -06004366 struct drm_i915_private *dev_priv = dev->dev_private;
4367 unsigned int s_tot = 0, ss_tot = 0, ss_per = 0, eu_tot = 0, eu_per = 0;
Jeff McGee38732182015-02-13 10:27:54 -06004368
4369 if (INTEL_INFO(dev)->gen < 9)
4370 return -ENODEV;
4371
4372 seq_puts(m, "SSEU Device Info\n");
4373 seq_printf(m, " Available Slice Total: %u\n",
4374 INTEL_INFO(dev)->slice_total);
4375 seq_printf(m, " Available Subslice Total: %u\n",
4376 INTEL_INFO(dev)->subslice_total);
4377 seq_printf(m, " Available Subslice Per Slice: %u\n",
4378 INTEL_INFO(dev)->subslice_per_slice);
4379 seq_printf(m, " Available EU Total: %u\n",
4380 INTEL_INFO(dev)->eu_total);
4381 seq_printf(m, " Available EU Per Subslice: %u\n",
4382 INTEL_INFO(dev)->eu_per_subslice);
4383 seq_printf(m, " Has Slice Power Gating: %s\n",
4384 yesno(INTEL_INFO(dev)->has_slice_pg));
4385 seq_printf(m, " Has Subslice Power Gating: %s\n",
4386 yesno(INTEL_INFO(dev)->has_subslice_pg));
4387 seq_printf(m, " Has EU Power Gating: %s\n",
4388 yesno(INTEL_INFO(dev)->has_eu_pg));
4389
Jeff McGee7f992ab2015-02-13 10:27:55 -06004390 seq_puts(m, "SSEU Device Status\n");
4391 if (IS_SKYLAKE(dev)) {
4392 const int s_max = 3, ss_max = 4;
4393 int s, ss;
4394 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4395
4396 s_reg[0] = I915_READ(GEN9_SLICE0_PGCTL_ACK);
4397 s_reg[1] = I915_READ(GEN9_SLICE1_PGCTL_ACK);
4398 s_reg[2] = I915_READ(GEN9_SLICE2_PGCTL_ACK);
4399 eu_reg[0] = I915_READ(GEN9_SLICE0_SS01_EU_PGCTL_ACK);
4400 eu_reg[1] = I915_READ(GEN9_SLICE0_SS23_EU_PGCTL_ACK);
4401 eu_reg[2] = I915_READ(GEN9_SLICE1_SS01_EU_PGCTL_ACK);
4402 eu_reg[3] = I915_READ(GEN9_SLICE1_SS23_EU_PGCTL_ACK);
4403 eu_reg[4] = I915_READ(GEN9_SLICE2_SS01_EU_PGCTL_ACK);
4404 eu_reg[5] = I915_READ(GEN9_SLICE2_SS23_EU_PGCTL_ACK);
4405 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4406 GEN9_PGCTL_SSA_EU19_ACK |
4407 GEN9_PGCTL_SSA_EU210_ACK |
4408 GEN9_PGCTL_SSA_EU311_ACK;
4409 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4410 GEN9_PGCTL_SSB_EU19_ACK |
4411 GEN9_PGCTL_SSB_EU210_ACK |
4412 GEN9_PGCTL_SSB_EU311_ACK;
4413
4414 for (s = 0; s < s_max; s++) {
4415 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4416 /* skip disabled slice */
4417 continue;
4418
4419 s_tot++;
4420 ss_per = INTEL_INFO(dev)->subslice_per_slice;
4421 ss_tot += ss_per;
4422 for (ss = 0; ss < ss_max; ss++) {
4423 unsigned int eu_cnt;
4424
4425 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4426 eu_mask[ss%2]);
4427 eu_tot += eu_cnt;
4428 eu_per = max(eu_per, eu_cnt);
4429 }
4430 }
4431 }
4432 seq_printf(m, " Enabled Slice Total: %u\n", s_tot);
4433 seq_printf(m, " Enabled Subslice Total: %u\n", ss_tot);
4434 seq_printf(m, " Enabled Subslice Per Slice: %u\n", ss_per);
4435 seq_printf(m, " Enabled EU Total: %u\n", eu_tot);
4436 seq_printf(m, " Enabled EU Per Subslice: %u\n", eu_per);
4437
Jeff McGee38732182015-02-13 10:27:54 -06004438 return 0;
4439}
4440
Ben Widawsky6d794d42011-04-25 11:25:56 -07004441static int i915_forcewake_open(struct inode *inode, struct file *file)
4442{
4443 struct drm_device *dev = inode->i_private;
4444 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004445
Daniel Vetter075edca2012-01-24 09:44:28 +01004446 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004447 return 0;
4448
Chris Wilson6daccb02015-01-16 11:34:35 +02004449 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004450 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004451
4452 return 0;
4453}
4454
Ben Widawskyc43b5632012-04-16 14:07:40 -07004455static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004456{
4457 struct drm_device *dev = inode->i_private;
4458 struct drm_i915_private *dev_priv = dev->dev_private;
4459
Daniel Vetter075edca2012-01-24 09:44:28 +01004460 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004461 return 0;
4462
Mika Kuoppala59bad942015-01-16 11:34:40 +02004463 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004464 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004465
4466 return 0;
4467}
4468
4469static const struct file_operations i915_forcewake_fops = {
4470 .owner = THIS_MODULE,
4471 .open = i915_forcewake_open,
4472 .release = i915_forcewake_release,
4473};
4474
4475static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4476{
4477 struct drm_device *dev = minor->dev;
4478 struct dentry *ent;
4479
4480 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004481 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004482 root, dev,
4483 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004484 if (!ent)
4485 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004486
Ben Widawsky8eb57292011-05-11 15:10:58 -07004487 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004488}
4489
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004490static int i915_debugfs_create(struct dentry *root,
4491 struct drm_minor *minor,
4492 const char *name,
4493 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004494{
4495 struct drm_device *dev = minor->dev;
4496 struct dentry *ent;
4497
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004498 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004499 S_IRUGO | S_IWUSR,
4500 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004501 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004502 if (!ent)
4503 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004504
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004505 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004506}
4507
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004508static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004509 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004510 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004511 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01004512 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004513 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004514 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004515 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004516 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004517 {"i915_gem_request", i915_gem_request_info, 0},
4518 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004519 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004520 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00004521 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
4522 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
4523 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07004524 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08004525 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304526 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004527 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004528 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004529 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004530 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004531 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004532 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004533 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004534 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004535 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004536 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01004537 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01004538 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004539 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004540 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004541 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004542 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004543 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004544 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004545 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03004546 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004547 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004548 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004549 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004550 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004551 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004552 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004553 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004554 {"i915_sseu_status", i915_sseu_status, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004555};
Ben Gamari27c202a2009-07-01 22:26:52 -04004556#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004557
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004558static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004559 const char *name;
4560 const struct file_operations *fops;
4561} i915_debugfs_files[] = {
4562 {"i915_wedged", &i915_wedged_fops},
4563 {"i915_max_freq", &i915_max_freq_fops},
4564 {"i915_min_freq", &i915_min_freq_fops},
4565 {"i915_cache_sharing", &i915_cache_sharing_fops},
4566 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004567 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4568 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004569 {"i915_gem_drop_caches", &i915_drop_caches_fops},
4570 {"i915_error_state", &i915_error_state_fops},
4571 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004572 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004573 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4574 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4575 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004576 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004577};
4578
Damien Lespiau07144422013-10-15 18:55:40 +01004579void intel_display_crc_init(struct drm_device *dev)
4580{
4581 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01004582 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01004583
Damien Lespiau055e3932014-08-18 13:49:10 +01004584 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01004585 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01004586
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004587 pipe_crc->opened = false;
4588 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01004589 init_waitqueue_head(&pipe_crc->wq);
4590 }
4591}
4592
Ben Gamari27c202a2009-07-01 22:26:52 -04004593int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004594{
Daniel Vetter34b96742013-07-04 20:49:44 +02004595 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004596
Ben Widawsky6d794d42011-04-25 11:25:56 -07004597 ret = i915_forcewake_create(minor->debugfs_root, minor);
4598 if (ret)
4599 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004600
Damien Lespiau07144422013-10-15 18:55:40 +01004601 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
4602 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
4603 if (ret)
4604 return ret;
4605 }
4606
Daniel Vetter34b96742013-07-04 20:49:44 +02004607 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4608 ret = i915_debugfs_create(minor->debugfs_root, minor,
4609 i915_debugfs_files[i].name,
4610 i915_debugfs_files[i].fops);
4611 if (ret)
4612 return ret;
4613 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004614
Ben Gamari27c202a2009-07-01 22:26:52 -04004615 return drm_debugfs_create_files(i915_debugfs_list,
4616 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004617 minor->debugfs_root, minor);
4618}
4619
Ben Gamari27c202a2009-07-01 22:26:52 -04004620void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004621{
Daniel Vetter34b96742013-07-04 20:49:44 +02004622 int i;
4623
Ben Gamari27c202a2009-07-01 22:26:52 -04004624 drm_debugfs_remove_files(i915_debugfs_list,
4625 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004626
Ben Widawsky6d794d42011-04-25 11:25:56 -07004627 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
4628 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004629
Daniel Vettere309a992013-10-16 22:55:51 +02004630 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01004631 struct drm_info_list *info_list =
4632 (struct drm_info_list *)&i915_pipe_crc_data[i];
4633
4634 drm_debugfs_remove_files(info_list, 1, minor);
4635 }
4636
Daniel Vetter34b96742013-07-04 20:49:44 +02004637 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4638 struct drm_info_list *info_list =
4639 (struct drm_info_list *) i915_debugfs_files[i].fops;
4640
4641 drm_debugfs_remove_files(info_list, 1, minor);
4642 }
Ben Gamari20172632009-02-17 20:08:50 -05004643}