blob: 63aa72152f72fb9fce33ac93a50367ca6b6608d5 [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");
Thierry Reding440fd522015-01-23 09:05:06 +0100156 seq_printf(m, "gtt offset: %08llx, size: %08llx, type: %u)",
Tvrtko Ursulinfe14d5f2014-12-10 17:27:58 +0000157 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)
Thierry Reding440fd522015-01-23 09:05:06 +0100161 seq_printf(m, " (stolen: %08llx)", 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;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001227 struct drm_device *dev = node->minor->dev;
1228 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf6544492015-01-26 18:03:04 +02001229 struct intel_engine_cs *ring;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001230 u64 acthd[I915_NUM_RINGS];
1231 u32 seqno[I915_NUM_RINGS];
Chris Wilsonf6544492015-01-26 18:03:04 +02001232 int i;
1233
1234 if (!i915.enable_hangcheck) {
1235 seq_printf(m, "Hangcheck disabled\n");
1236 return 0;
1237 }
1238
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001239 intel_runtime_pm_get(dev_priv);
1240
1241 for_each_ring(ring, dev_priv, i) {
1242 seqno[i] = ring->get_seqno(ring, false);
1243 acthd[i] = intel_ring_get_active_head(ring);
1244 }
1245
1246 intel_runtime_pm_put(dev_priv);
1247
Chris Wilsonf6544492015-01-26 18:03:04 +02001248 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1249 seq_printf(m, "Hangcheck active, fires in %dms\n",
1250 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1251 jiffies));
1252 } else
1253 seq_printf(m, "Hangcheck inactive\n");
1254
1255 for_each_ring(ring, dev_priv, i) {
1256 seq_printf(m, "%s:\n", ring->name);
1257 seq_printf(m, "\tseqno = %x [current %x]\n",
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001258 ring->hangcheck.seqno, seqno[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001259 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1260 (long long)ring->hangcheck.acthd,
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001261 (long long)acthd[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001262 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1263 (long long)ring->hangcheck.max_acthd);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001264 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1265 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
Chris Wilsonf6544492015-01-26 18:03:04 +02001266 }
1267
1268 return 0;
1269}
1270
Ben Widawsky4d855292011-12-12 19:34:16 -08001271static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001272{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001273 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001274 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001275 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001276 u32 rgvmodectl, rstdbyctl;
1277 u16 crstandvid;
1278 int ret;
1279
1280 ret = mutex_lock_interruptible(&dev->struct_mutex);
1281 if (ret)
1282 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001283 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001284
1285 rgvmodectl = I915_READ(MEMMODECTL);
1286 rstdbyctl = I915_READ(RSTDBYCTL);
1287 crstandvid = I915_READ16(CRSTANDVID);
1288
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001289 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001290 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001291
1292 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1293 "yes" : "no");
1294 seq_printf(m, "Boost freq: %d\n",
1295 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1296 MEMMODE_BOOST_FREQ_SHIFT);
1297 seq_printf(m, "HW control enabled: %s\n",
1298 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1299 seq_printf(m, "SW control enabled: %s\n",
1300 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1301 seq_printf(m, "Gated voltage change: %s\n",
1302 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1303 seq_printf(m, "Starting frequency: P%d\n",
1304 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001305 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001306 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001307 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1308 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1309 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1310 seq_printf(m, "Render standby enabled: %s\n",
1311 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001312 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001313 switch (rstdbyctl & RSX_STATUS_MASK) {
1314 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001315 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001316 break;
1317 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001318 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001319 break;
1320 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001321 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001322 break;
1323 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001324 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001325 break;
1326 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001327 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001328 break;
1329 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001330 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001331 break;
1332 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001333 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001334 break;
1335 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001336
1337 return 0;
1338}
1339
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001340static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001341{
1342 struct drm_info_node *node = m->private;
1343 struct drm_device *dev = node->minor->dev;
1344 struct drm_i915_private *dev_priv = dev->dev_private;
1345 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001346 int i;
1347
1348 spin_lock_irq(&dev_priv->uncore.lock);
1349 for_each_fw_domain(fw_domain, dev_priv, i) {
1350 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001351 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001352 fw_domain->wake_count);
1353 }
1354 spin_unlock_irq(&dev_priv->uncore.lock);
1355
1356 return 0;
1357}
1358
Deepak S669ab5a2014-01-10 15:18:26 +05301359static int vlv_drpc_info(struct seq_file *m)
1360{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001361 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301362 struct drm_device *dev = node->minor->dev;
1363 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001364 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301365
Imre Deakd46c0512014-04-14 20:24:27 +03001366 intel_runtime_pm_get(dev_priv);
1367
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001368 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301369 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1370 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1371
Imre Deakd46c0512014-04-14 20:24:27 +03001372 intel_runtime_pm_put(dev_priv);
1373
Deepak S669ab5a2014-01-10 15:18:26 +05301374 seq_printf(m, "Video Turbo Mode: %s\n",
1375 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1376 seq_printf(m, "Turbo enabled: %s\n",
1377 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1378 seq_printf(m, "HW control enabled: %s\n",
1379 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1380 seq_printf(m, "SW control enabled: %s\n",
1381 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1382 GEN6_RP_MEDIA_SW_MODE));
1383 seq_printf(m, "RC6 Enabled: %s\n",
1384 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1385 GEN6_RC_CTL_EI_MODE(1))));
1386 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001387 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301388 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001389 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301390
Imre Deak9cc19be2014-04-14 20:24:24 +03001391 seq_printf(m, "Render RC6 residency since boot: %u\n",
1392 I915_READ(VLV_GT_RENDER_RC6));
1393 seq_printf(m, "Media RC6 residency since boot: %u\n",
1394 I915_READ(VLV_GT_MEDIA_RC6));
1395
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001396 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301397}
1398
Ben Widawsky4d855292011-12-12 19:34:16 -08001399static int gen6_drpc_info(struct seq_file *m)
1400{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001401 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001402 struct drm_device *dev = node->minor->dev;
1403 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001404 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001405 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001406 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001407
1408 ret = mutex_lock_interruptible(&dev->struct_mutex);
1409 if (ret)
1410 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001411 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001412
Chris Wilson907b28c2013-07-19 20:36:52 +01001413 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001414 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001415 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001416
1417 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001418 seq_puts(m, "RC information inaccurate because somebody "
1419 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001420 } else {
1421 /* NB: we cannot use forcewake, else we read the wrong values */
1422 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1423 udelay(10);
1424 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1425 }
1426
1427 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001428 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001429
1430 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1431 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1432 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001433 mutex_lock(&dev_priv->rps.hw_lock);
1434 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1435 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001436
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001437 intel_runtime_pm_put(dev_priv);
1438
Ben Widawsky4d855292011-12-12 19:34:16 -08001439 seq_printf(m, "Video Turbo Mode: %s\n",
1440 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1441 seq_printf(m, "HW control enabled: %s\n",
1442 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1443 seq_printf(m, "SW control enabled: %s\n",
1444 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1445 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001446 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001447 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1448 seq_printf(m, "RC6 Enabled: %s\n",
1449 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1450 seq_printf(m, "Deep RC6 Enabled: %s\n",
1451 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1452 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1453 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001454 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001455 switch (gt_core_status & GEN6_RCn_MASK) {
1456 case GEN6_RC0:
1457 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001458 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001459 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001460 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001461 break;
1462 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001463 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001464 break;
1465 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001466 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001467 break;
1468 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001469 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001470 break;
1471 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001472 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001473 break;
1474 }
1475
1476 seq_printf(m, "Core Power Down: %s\n",
1477 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001478
1479 /* Not exactly sure what this is */
1480 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1481 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1482 seq_printf(m, "RC6 residency since boot: %u\n",
1483 I915_READ(GEN6_GT_GFX_RC6));
1484 seq_printf(m, "RC6+ residency since boot: %u\n",
1485 I915_READ(GEN6_GT_GFX_RC6p));
1486 seq_printf(m, "RC6++ residency since boot: %u\n",
1487 I915_READ(GEN6_GT_GFX_RC6pp));
1488
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001489 seq_printf(m, "RC6 voltage: %dmV\n",
1490 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1491 seq_printf(m, "RC6+ voltage: %dmV\n",
1492 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1493 seq_printf(m, "RC6++ voltage: %dmV\n",
1494 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001495 return 0;
1496}
1497
1498static int i915_drpc_info(struct seq_file *m, void *unused)
1499{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001500 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001501 struct drm_device *dev = node->minor->dev;
1502
Deepak S669ab5a2014-01-10 15:18:26 +05301503 if (IS_VALLEYVIEW(dev))
1504 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001505 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001506 return gen6_drpc_info(m);
1507 else
1508 return ironlake_drpc_info(m);
1509}
1510
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001511static int i915_fbc_status(struct seq_file *m, void *unused)
1512{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001513 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001514 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001515 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001516
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001517 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001518 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001519 return 0;
1520 }
1521
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001522 intel_runtime_pm_get(dev_priv);
1523
Adam Jacksonee5382a2010-04-23 11:17:39 -04001524 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001525 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001526 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001527 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001528 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001529 case FBC_OK:
1530 seq_puts(m, "FBC actived, but currently disabled in hardware");
1531 break;
1532 case FBC_UNSUPPORTED:
1533 seq_puts(m, "unsupported by this chipset");
1534 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001535 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001536 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001537 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001538 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001539 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001540 break;
1541 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001542 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001543 break;
1544 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001545 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001546 break;
1547 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001548 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001549 break;
1550 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001551 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001552 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001553 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001554 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001555 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001556 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001557 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001558 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001559 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001560 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001561 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001562 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001563 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001564 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001565 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001566 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001567
1568 intel_runtime_pm_put(dev_priv);
1569
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001570 return 0;
1571}
1572
Rodrigo Vivida46f932014-08-01 02:04:45 -07001573static int i915_fbc_fc_get(void *data, u64 *val)
1574{
1575 struct drm_device *dev = data;
1576 struct drm_i915_private *dev_priv = dev->dev_private;
1577
1578 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1579 return -ENODEV;
1580
1581 drm_modeset_lock_all(dev);
1582 *val = dev_priv->fbc.false_color;
1583 drm_modeset_unlock_all(dev);
1584
1585 return 0;
1586}
1587
1588static int i915_fbc_fc_set(void *data, u64 val)
1589{
1590 struct drm_device *dev = data;
1591 struct drm_i915_private *dev_priv = dev->dev_private;
1592 u32 reg;
1593
1594 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1595 return -ENODEV;
1596
1597 drm_modeset_lock_all(dev);
1598
1599 reg = I915_READ(ILK_DPFC_CONTROL);
1600 dev_priv->fbc.false_color = val;
1601
1602 I915_WRITE(ILK_DPFC_CONTROL, val ?
1603 (reg | FBC_CTL_FALSE_COLOR) :
1604 (reg & ~FBC_CTL_FALSE_COLOR));
1605
1606 drm_modeset_unlock_all(dev);
1607 return 0;
1608}
1609
1610DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1611 i915_fbc_fc_get, i915_fbc_fc_set,
1612 "%llu\n");
1613
Paulo Zanoni92d44622013-05-31 16:33:24 -03001614static int i915_ips_status(struct seq_file *m, void *unused)
1615{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001616 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001617 struct drm_device *dev = node->minor->dev;
1618 struct drm_i915_private *dev_priv = dev->dev_private;
1619
Damien Lespiauf5adf942013-06-24 18:29:34 +01001620 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001621 seq_puts(m, "not supported\n");
1622 return 0;
1623 }
1624
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001625 intel_runtime_pm_get(dev_priv);
1626
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001627 seq_printf(m, "Enabled by kernel parameter: %s\n",
1628 yesno(i915.enable_ips));
1629
1630 if (INTEL_INFO(dev)->gen >= 8) {
1631 seq_puts(m, "Currently: unknown\n");
1632 } else {
1633 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1634 seq_puts(m, "Currently: enabled\n");
1635 else
1636 seq_puts(m, "Currently: disabled\n");
1637 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001638
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001639 intel_runtime_pm_put(dev_priv);
1640
Paulo Zanoni92d44622013-05-31 16:33:24 -03001641 return 0;
1642}
1643
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001644static int i915_sr_status(struct seq_file *m, void *unused)
1645{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001646 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001647 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001648 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001649 bool sr_enabled = false;
1650
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001651 intel_runtime_pm_get(dev_priv);
1652
Yuanhan Liu13982612010-12-15 15:42:31 +08001653 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001654 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001655 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001656 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1657 else if (IS_I915GM(dev))
1658 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1659 else if (IS_PINEVIEW(dev))
1660 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1661
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001662 intel_runtime_pm_put(dev_priv);
1663
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001664 seq_printf(m, "self-refresh: %s\n",
1665 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001666
1667 return 0;
1668}
1669
Jesse Barnes7648fa92010-05-20 14:28:11 -07001670static int i915_emon_status(struct seq_file *m, void *unused)
1671{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001672 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001673 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001674 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001675 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001676 int ret;
1677
Chris Wilson582be6b2012-04-30 19:35:02 +01001678 if (!IS_GEN5(dev))
1679 return -ENODEV;
1680
Chris Wilsonde227ef2010-07-03 07:58:38 +01001681 ret = mutex_lock_interruptible(&dev->struct_mutex);
1682 if (ret)
1683 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001684
1685 temp = i915_mch_val(dev_priv);
1686 chipset = i915_chipset_val(dev_priv);
1687 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001688 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001689
1690 seq_printf(m, "GMCH temp: %ld\n", temp);
1691 seq_printf(m, "Chipset power: %ld\n", chipset);
1692 seq_printf(m, "GFX power: %ld\n", gfx);
1693 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1694
1695 return 0;
1696}
1697
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001698static int i915_ring_freq_table(struct seq_file *m, void *unused)
1699{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001700 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001701 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001702 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001703 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001704 int gpu_freq, ia_freq;
1705
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001706 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001707 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001708 return 0;
1709 }
1710
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001711 intel_runtime_pm_get(dev_priv);
1712
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001713 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1714
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001715 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001716 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001717 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001718
Damien Lespiau267f0c92013-06-24 22:59:48 +01001719 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001720
Ben Widawskyb39fb292014-03-19 18:31:11 -07001721 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1722 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001723 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001724 ia_freq = gpu_freq;
1725 sandybridge_pcode_read(dev_priv,
1726 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1727 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001728 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001729 intel_gpu_freq(dev_priv, gpu_freq),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001730 ((ia_freq >> 0) & 0xff) * 100,
1731 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001732 }
1733
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001734 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001735
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001736out:
1737 intel_runtime_pm_put(dev_priv);
1738 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001739}
1740
Chris Wilson44834a62010-08-19 16:09:23 +01001741static int i915_opregion(struct seq_file *m, void *unused)
1742{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001743 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001744 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001745 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001746 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001747 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001748 int ret;
1749
Daniel Vetter0d38f002012-04-21 22:49:10 +02001750 if (data == NULL)
1751 return -ENOMEM;
1752
Chris Wilson44834a62010-08-19 16:09:23 +01001753 ret = mutex_lock_interruptible(&dev->struct_mutex);
1754 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001755 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001756
Daniel Vetter0d38f002012-04-21 22:49:10 +02001757 if (opregion->header) {
1758 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1759 seq_write(m, data, OPREGION_SIZE);
1760 }
Chris Wilson44834a62010-08-19 16:09:23 +01001761
1762 mutex_unlock(&dev->struct_mutex);
1763
Daniel Vetter0d38f002012-04-21 22:49:10 +02001764out:
1765 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001766 return 0;
1767}
1768
Chris Wilson37811fc2010-08-25 22:45:57 +01001769static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1770{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001771 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001772 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001773 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001774 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001775
Daniel Vetter4520f532013-10-09 09:18:51 +02001776#ifdef CONFIG_DRM_I915_FBDEV
1777 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001778
1779 ifbdev = dev_priv->fbdev;
1780 fb = to_intel_framebuffer(ifbdev->helper.fb);
1781
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001782 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 +01001783 fb->base.width,
1784 fb->base.height,
1785 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001786 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001787 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001788 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001789 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001790 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001791#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001792
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001793 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001794 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001795 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001796 continue;
1797
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001798 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 +01001799 fb->base.width,
1800 fb->base.height,
1801 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001802 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001803 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001804 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001805 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001806 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001807 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001808 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001809
1810 return 0;
1811}
1812
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001813static void describe_ctx_ringbuf(struct seq_file *m,
1814 struct intel_ringbuffer *ringbuf)
1815{
1816 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1817 ringbuf->space, ringbuf->head, ringbuf->tail,
1818 ringbuf->last_retired_head);
1819}
1820
Ben Widawskye76d3632011-03-19 18:14:29 -07001821static int i915_context_status(struct seq_file *m, void *unused)
1822{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001823 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001824 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001825 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001826 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001827 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001828 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001829
Daniel Vetterf3d28872014-05-29 23:23:08 +02001830 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001831 if (ret)
1832 return ret;
1833
Daniel Vetter3e373942012-11-02 19:55:04 +01001834 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001835 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001836 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001837 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001838 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001839
Daniel Vetter3e373942012-11-02 19:55:04 +01001840 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001841 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001842 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001843 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001844 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001845
Ben Widawskya33afea2013-09-17 21:12:45 -07001846 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001847 if (!i915.enable_execlists &&
1848 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001849 continue;
1850
Ben Widawskya33afea2013-09-17 21:12:45 -07001851 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001852 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001853 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001854 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001855 seq_printf(m, "(default context %s) ",
1856 ring->name);
1857 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001858
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001859 if (i915.enable_execlists) {
1860 seq_putc(m, '\n');
1861 for_each_ring(ring, dev_priv, i) {
1862 struct drm_i915_gem_object *ctx_obj =
1863 ctx->engine[i].state;
1864 struct intel_ringbuffer *ringbuf =
1865 ctx->engine[i].ringbuf;
1866
1867 seq_printf(m, "%s: ", ring->name);
1868 if (ctx_obj)
1869 describe_obj(m, ctx_obj);
1870 if (ringbuf)
1871 describe_ctx_ringbuf(m, ringbuf);
1872 seq_putc(m, '\n');
1873 }
1874 } else {
1875 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1876 }
1877
Ben Widawskya33afea2013-09-17 21:12:45 -07001878 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001879 }
1880
Daniel Vetterf3d28872014-05-29 23:23:08 +02001881 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001882
1883 return 0;
1884}
1885
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001886static void i915_dump_lrc_obj(struct seq_file *m,
1887 struct intel_engine_cs *ring,
1888 struct drm_i915_gem_object *ctx_obj)
1889{
1890 struct page *page;
1891 uint32_t *reg_state;
1892 int j;
1893 unsigned long ggtt_offset = 0;
1894
1895 if (ctx_obj == NULL) {
1896 seq_printf(m, "Context on %s with no gem object\n",
1897 ring->name);
1898 return;
1899 }
1900
1901 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1902 intel_execlists_ctx_id(ctx_obj));
1903
1904 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1905 seq_puts(m, "\tNot bound in GGTT\n");
1906 else
1907 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1908
1909 if (i915_gem_object_get_pages(ctx_obj)) {
1910 seq_puts(m, "\tFailed to get pages for context object\n");
1911 return;
1912 }
1913
1914 page = i915_gem_object_get_page(ctx_obj, 1);
1915 if (!WARN_ON(page == NULL)) {
1916 reg_state = kmap_atomic(page);
1917
1918 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
1919 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1920 ggtt_offset + 4096 + (j * 4),
1921 reg_state[j], reg_state[j + 1],
1922 reg_state[j + 2], reg_state[j + 3]);
1923 }
1924 kunmap_atomic(reg_state);
1925 }
1926
1927 seq_putc(m, '\n');
1928}
1929
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01001930static int i915_dump_lrc(struct seq_file *m, void *unused)
1931{
1932 struct drm_info_node *node = (struct drm_info_node *) m->private;
1933 struct drm_device *dev = node->minor->dev;
1934 struct drm_i915_private *dev_priv = dev->dev_private;
1935 struct intel_engine_cs *ring;
1936 struct intel_context *ctx;
1937 int ret, i;
1938
1939 if (!i915.enable_execlists) {
1940 seq_printf(m, "Logical Ring Contexts are disabled\n");
1941 return 0;
1942 }
1943
1944 ret = mutex_lock_interruptible(&dev->struct_mutex);
1945 if (ret)
1946 return ret;
1947
1948 list_for_each_entry(ctx, &dev_priv->context_list, link) {
1949 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001950 if (ring->default_context != ctx)
1951 i915_dump_lrc_obj(m, ring,
1952 ctx->engine[i].state);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01001953 }
1954 }
1955
1956 mutex_unlock(&dev->struct_mutex);
1957
1958 return 0;
1959}
1960
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001961static int i915_execlists(struct seq_file *m, void *data)
1962{
1963 struct drm_info_node *node = (struct drm_info_node *)m->private;
1964 struct drm_device *dev = node->minor->dev;
1965 struct drm_i915_private *dev_priv = dev->dev_private;
1966 struct intel_engine_cs *ring;
1967 u32 status_pointer;
1968 u8 read_pointer;
1969 u8 write_pointer;
1970 u32 status;
1971 u32 ctx_id;
1972 struct list_head *cursor;
1973 int ring_id, i;
1974 int ret;
1975
1976 if (!i915.enable_execlists) {
1977 seq_puts(m, "Logical Ring Contexts are disabled\n");
1978 return 0;
1979 }
1980
1981 ret = mutex_lock_interruptible(&dev->struct_mutex);
1982 if (ret)
1983 return ret;
1984
Michel Thierryfc0412e2014-10-16 16:13:38 +01001985 intel_runtime_pm_get(dev_priv);
1986
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001987 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00001988 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001989 int count = 0;
1990 unsigned long flags;
1991
1992 seq_printf(m, "%s\n", ring->name);
1993
1994 status = I915_READ(RING_EXECLIST_STATUS(ring));
1995 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
1996 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
1997 status, ctx_id);
1998
1999 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2000 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2001
2002 read_pointer = ring->next_context_status_buffer;
2003 write_pointer = status_pointer & 0x07;
2004 if (read_pointer > write_pointer)
2005 write_pointer += 6;
2006 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2007 read_pointer, write_pointer);
2008
2009 for (i = 0; i < 6; i++) {
2010 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
2011 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
2012
2013 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2014 i, status, ctx_id);
2015 }
2016
2017 spin_lock_irqsave(&ring->execlist_lock, flags);
2018 list_for_each(cursor, &ring->execlist_queue)
2019 count++;
2020 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002021 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002022 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2023
2024 seq_printf(m, "\t%d requests in queue\n", count);
2025 if (head_req) {
2026 struct drm_i915_gem_object *ctx_obj;
2027
Nick Hoath6d3d8272015-01-15 13:10:39 +00002028 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002029 seq_printf(m, "\tHead request id: %u\n",
2030 intel_execlists_ctx_id(ctx_obj));
2031 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002032 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002033 }
2034
2035 seq_putc(m, '\n');
2036 }
2037
Michel Thierryfc0412e2014-10-16 16:13:38 +01002038 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002039 mutex_unlock(&dev->struct_mutex);
2040
2041 return 0;
2042}
2043
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002044static const char *swizzle_string(unsigned swizzle)
2045{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002046 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002047 case I915_BIT_6_SWIZZLE_NONE:
2048 return "none";
2049 case I915_BIT_6_SWIZZLE_9:
2050 return "bit9";
2051 case I915_BIT_6_SWIZZLE_9_10:
2052 return "bit9/bit10";
2053 case I915_BIT_6_SWIZZLE_9_11:
2054 return "bit9/bit11";
2055 case I915_BIT_6_SWIZZLE_9_10_11:
2056 return "bit9/bit10/bit11";
2057 case I915_BIT_6_SWIZZLE_9_17:
2058 return "bit9/bit17";
2059 case I915_BIT_6_SWIZZLE_9_10_17:
2060 return "bit9/bit10/bit17";
2061 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002062 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002063 }
2064
2065 return "bug";
2066}
2067
2068static int i915_swizzle_info(struct seq_file *m, void *data)
2069{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002070 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002071 struct drm_device *dev = node->minor->dev;
2072 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002073 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002074
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002075 ret = mutex_lock_interruptible(&dev->struct_mutex);
2076 if (ret)
2077 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002078 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002079
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002080 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2081 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2082 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2083 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2084
2085 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2086 seq_printf(m, "DDC = 0x%08x\n",
2087 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002088 seq_printf(m, "DDC2 = 0x%08x\n",
2089 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002090 seq_printf(m, "C0DRB3 = 0x%04x\n",
2091 I915_READ16(C0DRB3));
2092 seq_printf(m, "C1DRB3 = 0x%04x\n",
2093 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002094 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002095 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2096 I915_READ(MAD_DIMM_C0));
2097 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2098 I915_READ(MAD_DIMM_C1));
2099 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2100 I915_READ(MAD_DIMM_C2));
2101 seq_printf(m, "TILECTL = 0x%08x\n",
2102 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002103 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002104 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2105 I915_READ(GAMTARBMODE));
2106 else
2107 seq_printf(m, "ARB_MODE = 0x%08x\n",
2108 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002109 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2110 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002111 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002112
2113 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2114 seq_puts(m, "L-shaped memory detected\n");
2115
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002116 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002117 mutex_unlock(&dev->struct_mutex);
2118
2119 return 0;
2120}
2121
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002122static int per_file_ctx(int id, void *ptr, void *data)
2123{
Oscar Mateo273497e2014-05-22 14:13:37 +01002124 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002125 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002126 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2127
2128 if (!ppgtt) {
2129 seq_printf(m, " no ppgtt for context %d\n",
2130 ctx->user_handle);
2131 return 0;
2132 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002133
Oscar Mateof83d6512014-05-22 14:13:38 +01002134 if (i915_gem_context_is_default(ctx))
2135 seq_puts(m, " default context:\n");
2136 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002137 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002138 ppgtt->debug_dump(ppgtt, m);
2139
2140 return 0;
2141}
2142
Ben Widawsky77df6772013-11-02 21:07:30 -07002143static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002144{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002145 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002146 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002147 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2148 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002149
Ben Widawsky77df6772013-11-02 21:07:30 -07002150 if (!ppgtt)
2151 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002152
Ben Widawsky77df6772013-11-02 21:07:30 -07002153 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08002154 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07002155 for_each_ring(ring, dev_priv, unused) {
2156 seq_printf(m, "%s\n", ring->name);
2157 for (i = 0; i < 4; i++) {
2158 u32 offset = 0x270 + i * 8;
2159 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2160 pdp <<= 32;
2161 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002162 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002163 }
2164 }
2165}
2166
2167static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2168{
2169 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002170 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002171 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002172 int i;
2173
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002174 if (INTEL_INFO(dev)->gen == 6)
2175 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2176
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002177 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002178 seq_printf(m, "%s\n", ring->name);
2179 if (INTEL_INFO(dev)->gen == 7)
2180 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2181 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2182 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2183 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2184 }
2185 if (dev_priv->mm.aliasing_ppgtt) {
2186 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2187
Damien Lespiau267f0c92013-06-24 22:59:48 +01002188 seq_puts(m, "aliasing PPGTT:\n");
Ben Widawsky7324cc02015-02-24 16:22:35 +00002189 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002190
Ben Widawsky87d60b62013-12-06 14:11:29 -08002191 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002192 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002193
2194 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2195 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002196
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002197 seq_printf(m, "proc: %s\n",
2198 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002199 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002200 }
2201 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002202}
2203
2204static int i915_ppgtt_info(struct seq_file *m, void *data)
2205{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002206 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002207 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002208 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002209
2210 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2211 if (ret)
2212 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002213 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002214
2215 if (INTEL_INFO(dev)->gen >= 8)
2216 gen8_ppgtt_info(m, dev);
2217 else if (INTEL_INFO(dev)->gen >= 6)
2218 gen6_ppgtt_info(m, dev);
2219
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002220 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002221 mutex_unlock(&dev->struct_mutex);
2222
2223 return 0;
2224}
2225
Ben Widawsky63573eb2013-07-04 11:02:07 -07002226static int i915_llc(struct seq_file *m, void *data)
2227{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002228 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002229 struct drm_device *dev = node->minor->dev;
2230 struct drm_i915_private *dev_priv = dev->dev_private;
2231
2232 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2233 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2234 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2235
2236 return 0;
2237}
2238
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002239static int i915_edp_psr_status(struct seq_file *m, void *data)
2240{
2241 struct drm_info_node *node = m->private;
2242 struct drm_device *dev = node->minor->dev;
2243 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002244 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002245 u32 stat[3];
2246 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002247 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002248
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002249 intel_runtime_pm_get(dev_priv);
2250
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002251 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002252 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2253 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002254 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002255 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002256 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2257 dev_priv->psr.busy_frontbuffer_bits);
2258 seq_printf(m, "Re-enable work scheduled: %s\n",
2259 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002260
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002261 if (HAS_PSR(dev)) {
2262 if (HAS_DDI(dev))
2263 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2264 else {
2265 for_each_pipe(dev_priv, pipe) {
2266 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2267 VLV_EDP_PSR_CURR_STATE_MASK;
2268 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2269 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2270 enabled = true;
2271 }
2272 }
2273 }
2274 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002275
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002276 if (!HAS_DDI(dev))
2277 for_each_pipe(dev_priv, pipe) {
2278 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2279 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2280 seq_printf(m, " pipe %c", pipe_name(pipe));
2281 }
2282 seq_puts(m, "\n");
2283
Rodrigo Vivifb495812015-01-12 10:14:33 -08002284 seq_printf(m, "Link standby: %s\n",
2285 yesno((bool)dev_priv->psr.link_standby));
2286
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002287 /* CHV PSR has no kind of performance counter */
2288 if (HAS_PSR(dev) && HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002289 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2290 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002291
2292 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2293 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002294 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002295
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002296 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002297 return 0;
2298}
2299
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002300static int i915_sink_crc(struct seq_file *m, void *data)
2301{
2302 struct drm_info_node *node = m->private;
2303 struct drm_device *dev = node->minor->dev;
2304 struct intel_encoder *encoder;
2305 struct intel_connector *connector;
2306 struct intel_dp *intel_dp = NULL;
2307 int ret;
2308 u8 crc[6];
2309
2310 drm_modeset_lock_all(dev);
Ander Conselvan de Oliveira3a3371f2015-03-03 15:21:56 +02002311 for_each_intel_encoder(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002312
2313 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2314 continue;
2315
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002316 if (!connector->base.encoder)
2317 continue;
2318
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002319 encoder = to_intel_encoder(connector->base.encoder);
2320 if (encoder->type != INTEL_OUTPUT_EDP)
2321 continue;
2322
2323 intel_dp = enc_to_intel_dp(&encoder->base);
2324
2325 ret = intel_dp_sink_crc(intel_dp, crc);
2326 if (ret)
2327 goto out;
2328
2329 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2330 crc[0], crc[1], crc[2],
2331 crc[3], crc[4], crc[5]);
2332 goto out;
2333 }
2334 ret = -ENODEV;
2335out:
2336 drm_modeset_unlock_all(dev);
2337 return ret;
2338}
2339
Jesse Barnesec013e72013-08-20 10:29:23 +01002340static int i915_energy_uJ(struct seq_file *m, void *data)
2341{
2342 struct drm_info_node *node = m->private;
2343 struct drm_device *dev = node->minor->dev;
2344 struct drm_i915_private *dev_priv = dev->dev_private;
2345 u64 power;
2346 u32 units;
2347
2348 if (INTEL_INFO(dev)->gen < 6)
2349 return -ENODEV;
2350
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002351 intel_runtime_pm_get(dev_priv);
2352
Jesse Barnesec013e72013-08-20 10:29:23 +01002353 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2354 power = (power & 0x1f00) >> 8;
2355 units = 1000000 / (1 << power); /* convert to uJ */
2356 power = I915_READ(MCH_SECP_NRG_STTS);
2357 power *= units;
2358
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002359 intel_runtime_pm_put(dev_priv);
2360
Jesse Barnesec013e72013-08-20 10:29:23 +01002361 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002362
2363 return 0;
2364}
2365
2366static int i915_pc8_status(struct seq_file *m, void *unused)
2367{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002368 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002369 struct drm_device *dev = node->minor->dev;
2370 struct drm_i915_private *dev_priv = dev->dev_private;
2371
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002372 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002373 seq_puts(m, "not supported\n");
2374 return 0;
2375 }
2376
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002377 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002378 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002379 yesno(!intel_irqs_enabled(dev_priv)));
Paulo Zanoni371db662013-08-19 13:18:10 -03002380
Jesse Barnesec013e72013-08-20 10:29:23 +01002381 return 0;
2382}
2383
Imre Deak1da51582013-11-25 17:15:35 +02002384static const char *power_domain_str(enum intel_display_power_domain domain)
2385{
2386 switch (domain) {
2387 case POWER_DOMAIN_PIPE_A:
2388 return "PIPE_A";
2389 case POWER_DOMAIN_PIPE_B:
2390 return "PIPE_B";
2391 case POWER_DOMAIN_PIPE_C:
2392 return "PIPE_C";
2393 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2394 return "PIPE_A_PANEL_FITTER";
2395 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2396 return "PIPE_B_PANEL_FITTER";
2397 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2398 return "PIPE_C_PANEL_FITTER";
2399 case POWER_DOMAIN_TRANSCODER_A:
2400 return "TRANSCODER_A";
2401 case POWER_DOMAIN_TRANSCODER_B:
2402 return "TRANSCODER_B";
2403 case POWER_DOMAIN_TRANSCODER_C:
2404 return "TRANSCODER_C";
2405 case POWER_DOMAIN_TRANSCODER_EDP:
2406 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002407 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2408 return "PORT_DDI_A_2_LANES";
2409 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2410 return "PORT_DDI_A_4_LANES";
2411 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2412 return "PORT_DDI_B_2_LANES";
2413 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2414 return "PORT_DDI_B_4_LANES";
2415 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2416 return "PORT_DDI_C_2_LANES";
2417 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2418 return "PORT_DDI_C_4_LANES";
2419 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2420 return "PORT_DDI_D_2_LANES";
2421 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2422 return "PORT_DDI_D_4_LANES";
2423 case POWER_DOMAIN_PORT_DSI:
2424 return "PORT_DSI";
2425 case POWER_DOMAIN_PORT_CRT:
2426 return "PORT_CRT";
2427 case POWER_DOMAIN_PORT_OTHER:
2428 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002429 case POWER_DOMAIN_VGA:
2430 return "VGA";
2431 case POWER_DOMAIN_AUDIO:
2432 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002433 case POWER_DOMAIN_PLLS:
2434 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002435 case POWER_DOMAIN_AUX_A:
2436 return "AUX_A";
2437 case POWER_DOMAIN_AUX_B:
2438 return "AUX_B";
2439 case POWER_DOMAIN_AUX_C:
2440 return "AUX_C";
2441 case POWER_DOMAIN_AUX_D:
2442 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002443 case POWER_DOMAIN_INIT:
2444 return "INIT";
2445 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002446 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002447 return "?";
2448 }
2449}
2450
2451static int i915_power_domain_info(struct seq_file *m, void *unused)
2452{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002453 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002454 struct drm_device *dev = node->minor->dev;
2455 struct drm_i915_private *dev_priv = dev->dev_private;
2456 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2457 int i;
2458
2459 mutex_lock(&power_domains->lock);
2460
2461 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2462 for (i = 0; i < power_domains->power_well_count; i++) {
2463 struct i915_power_well *power_well;
2464 enum intel_display_power_domain power_domain;
2465
2466 power_well = &power_domains->power_wells[i];
2467 seq_printf(m, "%-25s %d\n", power_well->name,
2468 power_well->count);
2469
2470 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2471 power_domain++) {
2472 if (!(BIT(power_domain) & power_well->domains))
2473 continue;
2474
2475 seq_printf(m, " %-23s %d\n",
2476 power_domain_str(power_domain),
2477 power_domains->domain_use_count[power_domain]);
2478 }
2479 }
2480
2481 mutex_unlock(&power_domains->lock);
2482
2483 return 0;
2484}
2485
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002486static void intel_seq_print_mode(struct seq_file *m, int tabs,
2487 struct drm_display_mode *mode)
2488{
2489 int i;
2490
2491 for (i = 0; i < tabs; i++)
2492 seq_putc(m, '\t');
2493
2494 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",
2495 mode->base.id, mode->name,
2496 mode->vrefresh, mode->clock,
2497 mode->hdisplay, mode->hsync_start,
2498 mode->hsync_end, mode->htotal,
2499 mode->vdisplay, mode->vsync_start,
2500 mode->vsync_end, mode->vtotal,
2501 mode->type, mode->flags);
2502}
2503
2504static void intel_encoder_info(struct seq_file *m,
2505 struct intel_crtc *intel_crtc,
2506 struct intel_encoder *intel_encoder)
2507{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002508 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002509 struct drm_device *dev = node->minor->dev;
2510 struct drm_crtc *crtc = &intel_crtc->base;
2511 struct intel_connector *intel_connector;
2512 struct drm_encoder *encoder;
2513
2514 encoder = &intel_encoder->base;
2515 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002516 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002517 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2518 struct drm_connector *connector = &intel_connector->base;
2519 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2520 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002521 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002522 drm_get_connector_status_name(connector->status));
2523 if (connector->status == connector_status_connected) {
2524 struct drm_display_mode *mode = &crtc->mode;
2525 seq_printf(m, ", mode:\n");
2526 intel_seq_print_mode(m, 2, mode);
2527 } else {
2528 seq_putc(m, '\n');
2529 }
2530 }
2531}
2532
2533static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2534{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002535 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002536 struct drm_device *dev = node->minor->dev;
2537 struct drm_crtc *crtc = &intel_crtc->base;
2538 struct intel_encoder *intel_encoder;
2539
Matt Roper5aa8a932014-06-16 10:12:55 -07002540 if (crtc->primary->fb)
2541 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2542 crtc->primary->fb->base.id, crtc->x, crtc->y,
2543 crtc->primary->fb->width, crtc->primary->fb->height);
2544 else
2545 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002546 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2547 intel_encoder_info(m, intel_crtc, intel_encoder);
2548}
2549
2550static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2551{
2552 struct drm_display_mode *mode = panel->fixed_mode;
2553
2554 seq_printf(m, "\tfixed mode:\n");
2555 intel_seq_print_mode(m, 2, mode);
2556}
2557
2558static void intel_dp_info(struct seq_file *m,
2559 struct intel_connector *intel_connector)
2560{
2561 struct intel_encoder *intel_encoder = intel_connector->encoder;
2562 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2563
2564 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2565 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2566 "no");
2567 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2568 intel_panel_info(m, &intel_connector->panel);
2569}
2570
2571static void intel_hdmi_info(struct seq_file *m,
2572 struct intel_connector *intel_connector)
2573{
2574 struct intel_encoder *intel_encoder = intel_connector->encoder;
2575 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2576
2577 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2578 "no");
2579}
2580
2581static void intel_lvds_info(struct seq_file *m,
2582 struct intel_connector *intel_connector)
2583{
2584 intel_panel_info(m, &intel_connector->panel);
2585}
2586
2587static void intel_connector_info(struct seq_file *m,
2588 struct drm_connector *connector)
2589{
2590 struct intel_connector *intel_connector = to_intel_connector(connector);
2591 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002592 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002593
2594 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002595 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002596 drm_get_connector_status_name(connector->status));
2597 if (connector->status == connector_status_connected) {
2598 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2599 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2600 connector->display_info.width_mm,
2601 connector->display_info.height_mm);
2602 seq_printf(m, "\tsubpixel order: %s\n",
2603 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2604 seq_printf(m, "\tCEA rev: %d\n",
2605 connector->display_info.cea_rev);
2606 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002607 if (intel_encoder) {
2608 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2609 intel_encoder->type == INTEL_OUTPUT_EDP)
2610 intel_dp_info(m, intel_connector);
2611 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2612 intel_hdmi_info(m, intel_connector);
2613 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2614 intel_lvds_info(m, intel_connector);
2615 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002616
Jesse Barnesf103fc72014-02-20 12:39:57 -08002617 seq_printf(m, "\tmodes:\n");
2618 list_for_each_entry(mode, &connector->modes, head)
2619 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002620}
2621
Chris Wilson065f2ec2014-03-12 09:13:13 +00002622static bool cursor_active(struct drm_device *dev, int pipe)
2623{
2624 struct drm_i915_private *dev_priv = dev->dev_private;
2625 u32 state;
2626
2627 if (IS_845G(dev) || IS_I865G(dev))
2628 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002629 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002630 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002631
2632 return state;
2633}
2634
2635static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2636{
2637 struct drm_i915_private *dev_priv = dev->dev_private;
2638 u32 pos;
2639
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002640 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002641
2642 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2643 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2644 *x = -*x;
2645
2646 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2647 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2648 *y = -*y;
2649
2650 return cursor_active(dev, pipe);
2651}
2652
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002653static int i915_display_info(struct seq_file *m, void *unused)
2654{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002655 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002656 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002657 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002658 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002659 struct drm_connector *connector;
2660
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002661 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002662 drm_modeset_lock_all(dev);
2663 seq_printf(m, "CRTC info\n");
2664 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002665 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002666 bool active;
2667 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002668
Chris Wilson57127ef2014-07-04 08:20:11 +01002669 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002670 crtc->base.base.id, pipe_name(crtc->pipe),
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002671 yesno(crtc->active), crtc->config->pipe_src_w,
2672 crtc->config->pipe_src_h);
Paulo Zanonia23dc652014-04-01 14:55:11 -03002673 if (crtc->active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002674 intel_crtc_info(m, crtc);
2675
Paulo Zanonia23dc652014-04-01 14:55:11 -03002676 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002677 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 +03002678 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08002679 x, y, crtc->base.cursor->state->crtc_w,
2680 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01002681 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002682 }
Daniel Vettercace8412014-05-22 17:56:31 +02002683
2684 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2685 yesno(!crtc->cpu_fifo_underrun_disabled),
2686 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002687 }
2688
2689 seq_printf(m, "\n");
2690 seq_printf(m, "Connector info\n");
2691 seq_printf(m, "--------------\n");
2692 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2693 intel_connector_info(m, connector);
2694 }
2695 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002696 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002697
2698 return 0;
2699}
2700
Ben Widawskye04934c2014-06-30 09:53:42 -07002701static int i915_semaphore_status(struct seq_file *m, void *unused)
2702{
2703 struct drm_info_node *node = (struct drm_info_node *) m->private;
2704 struct drm_device *dev = node->minor->dev;
2705 struct drm_i915_private *dev_priv = dev->dev_private;
2706 struct intel_engine_cs *ring;
2707 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2708 int i, j, ret;
2709
2710 if (!i915_semaphore_is_enabled(dev)) {
2711 seq_puts(m, "Semaphores are disabled\n");
2712 return 0;
2713 }
2714
2715 ret = mutex_lock_interruptible(&dev->struct_mutex);
2716 if (ret)
2717 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002718 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002719
2720 if (IS_BROADWELL(dev)) {
2721 struct page *page;
2722 uint64_t *seqno;
2723
2724 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2725
2726 seqno = (uint64_t *)kmap_atomic(page);
2727 for_each_ring(ring, dev_priv, i) {
2728 uint64_t offset;
2729
2730 seq_printf(m, "%s\n", ring->name);
2731
2732 seq_puts(m, " Last signal:");
2733 for (j = 0; j < num_rings; j++) {
2734 offset = i * I915_NUM_RINGS + j;
2735 seq_printf(m, "0x%08llx (0x%02llx) ",
2736 seqno[offset], offset * 8);
2737 }
2738 seq_putc(m, '\n');
2739
2740 seq_puts(m, " Last wait: ");
2741 for (j = 0; j < num_rings; j++) {
2742 offset = i + (j * I915_NUM_RINGS);
2743 seq_printf(m, "0x%08llx (0x%02llx) ",
2744 seqno[offset], offset * 8);
2745 }
2746 seq_putc(m, '\n');
2747
2748 }
2749 kunmap_atomic(seqno);
2750 } else {
2751 seq_puts(m, " Last signal:");
2752 for_each_ring(ring, dev_priv, i)
2753 for (j = 0; j < num_rings; j++)
2754 seq_printf(m, "0x%08x\n",
2755 I915_READ(ring->semaphore.mbox.signal[j]));
2756 seq_putc(m, '\n');
2757 }
2758
2759 seq_puts(m, "\nSync seqno:\n");
2760 for_each_ring(ring, dev_priv, i) {
2761 for (j = 0; j < num_rings; j++) {
2762 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2763 }
2764 seq_putc(m, '\n');
2765 }
2766 seq_putc(m, '\n');
2767
Paulo Zanoni03872062014-07-09 14:31:57 -03002768 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002769 mutex_unlock(&dev->struct_mutex);
2770 return 0;
2771}
2772
Daniel Vetter728e29d2014-06-25 22:01:53 +03002773static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2774{
2775 struct drm_info_node *node = (struct drm_info_node *) m->private;
2776 struct drm_device *dev = node->minor->dev;
2777 struct drm_i915_private *dev_priv = dev->dev_private;
2778 int i;
2779
2780 drm_modeset_lock_all(dev);
2781 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2782 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2783
2784 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002785 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002786 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03002787 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002788 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2789 seq_printf(m, " dpll_md: 0x%08x\n",
2790 pll->config.hw_state.dpll_md);
2791 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2792 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2793 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002794 }
2795 drm_modeset_unlock_all(dev);
2796
2797 return 0;
2798}
2799
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01002800static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01002801{
2802 int i;
2803 int ret;
2804 struct drm_info_node *node = (struct drm_info_node *) m->private;
2805 struct drm_device *dev = node->minor->dev;
2806 struct drm_i915_private *dev_priv = dev->dev_private;
2807
Arun Siluvery888b5992014-08-26 14:44:51 +01002808 ret = mutex_lock_interruptible(&dev->struct_mutex);
2809 if (ret)
2810 return ret;
2811
2812 intel_runtime_pm_get(dev_priv);
2813
Mika Kuoppala72253422014-10-07 17:21:26 +03002814 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
2815 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002816 u32 addr, mask, value, read;
2817 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01002818
Mika Kuoppala72253422014-10-07 17:21:26 +03002819 addr = dev_priv->workarounds.reg[i].addr;
2820 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002821 value = dev_priv->workarounds.reg[i].value;
2822 read = I915_READ(addr);
2823 ok = (value & mask) == (read & mask);
2824 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
2825 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01002826 }
2827
2828 intel_runtime_pm_put(dev_priv);
2829 mutex_unlock(&dev->struct_mutex);
2830
2831 return 0;
2832}
2833
Damien Lespiauc5511e42014-11-04 17:06:51 +00002834static int i915_ddb_info(struct seq_file *m, void *unused)
2835{
2836 struct drm_info_node *node = m->private;
2837 struct drm_device *dev = node->minor->dev;
2838 struct drm_i915_private *dev_priv = dev->dev_private;
2839 struct skl_ddb_allocation *ddb;
2840 struct skl_ddb_entry *entry;
2841 enum pipe pipe;
2842 int plane;
2843
Damien Lespiau2fcffe12014-12-03 17:33:24 +00002844 if (INTEL_INFO(dev)->gen < 9)
2845 return 0;
2846
Damien Lespiauc5511e42014-11-04 17:06:51 +00002847 drm_modeset_lock_all(dev);
2848
2849 ddb = &dev_priv->wm.skl_hw.ddb;
2850
2851 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
2852
2853 for_each_pipe(dev_priv, pipe) {
2854 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
2855
Damien Lespiaudd740782015-02-28 14:54:08 +00002856 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00002857 entry = &ddb->plane[pipe][plane];
2858 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
2859 entry->start, entry->end,
2860 skl_ddb_entry_size(entry));
2861 }
2862
2863 entry = &ddb->cursor[pipe];
2864 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
2865 entry->end, skl_ddb_entry_size(entry));
2866 }
2867
2868 drm_modeset_unlock_all(dev);
2869
2870 return 0;
2871}
2872
Damien Lespiau07144422013-10-15 18:55:40 +01002873struct pipe_crc_info {
2874 const char *name;
2875 struct drm_device *dev;
2876 enum pipe pipe;
2877};
2878
Dave Airlie11bed952014-05-12 15:22:27 +10002879static int i915_dp_mst_info(struct seq_file *m, void *unused)
2880{
2881 struct drm_info_node *node = (struct drm_info_node *) m->private;
2882 struct drm_device *dev = node->minor->dev;
2883 struct drm_encoder *encoder;
2884 struct intel_encoder *intel_encoder;
2885 struct intel_digital_port *intel_dig_port;
2886 drm_modeset_lock_all(dev);
2887 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2888 intel_encoder = to_intel_encoder(encoder);
2889 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
2890 continue;
2891 intel_dig_port = enc_to_dig_port(encoder);
2892 if (!intel_dig_port->dp.can_mst)
2893 continue;
2894
2895 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
2896 }
2897 drm_modeset_unlock_all(dev);
2898 return 0;
2899}
2900
Damien Lespiau07144422013-10-15 18:55:40 +01002901static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01002902{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002903 struct pipe_crc_info *info = inode->i_private;
2904 struct drm_i915_private *dev_priv = info->dev->dev_private;
2905 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2906
Daniel Vetter7eb1c492013-11-14 11:30:43 +01002907 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
2908 return -ENODEV;
2909
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002910 spin_lock_irq(&pipe_crc->lock);
2911
2912 if (pipe_crc->opened) {
2913 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002914 return -EBUSY; /* already open */
2915 }
2916
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002917 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01002918 filep->private_data = inode->i_private;
2919
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002920 spin_unlock_irq(&pipe_crc->lock);
2921
Damien Lespiau07144422013-10-15 18:55:40 +01002922 return 0;
2923}
2924
2925static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
2926{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002927 struct pipe_crc_info *info = inode->i_private;
2928 struct drm_i915_private *dev_priv = info->dev->dev_private;
2929 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2930
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002931 spin_lock_irq(&pipe_crc->lock);
2932 pipe_crc->opened = false;
2933 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002934
Damien Lespiau07144422013-10-15 18:55:40 +01002935 return 0;
2936}
2937
2938/* (6 fields, 8 chars each, space separated (5) + '\n') */
2939#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
2940/* account for \'0' */
2941#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
2942
2943static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
2944{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002945 assert_spin_locked(&pipe_crc->lock);
2946 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2947 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01002948}
Shuang He8bf1e9f2013-10-15 18:55:27 +01002949
Damien Lespiau07144422013-10-15 18:55:40 +01002950static ssize_t
2951i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
2952 loff_t *pos)
2953{
2954 struct pipe_crc_info *info = filep->private_data;
2955 struct drm_device *dev = info->dev;
2956 struct drm_i915_private *dev_priv = dev->dev_private;
2957 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2958 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002959 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01002960 ssize_t bytes_read;
2961
2962 /*
2963 * Don't allow user space to provide buffers not big enough to hold
2964 * a line of data.
2965 */
2966 if (count < PIPE_CRC_LINE_LEN)
2967 return -EINVAL;
2968
2969 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2970 return 0;
2971
2972 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002973 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002974 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002975 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002976
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002977 if (filep->f_flags & O_NONBLOCK) {
2978 spin_unlock_irq(&pipe_crc->lock);
2979 return -EAGAIN;
2980 }
2981
2982 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2983 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2984 if (ret) {
2985 spin_unlock_irq(&pipe_crc->lock);
2986 return ret;
2987 }
Damien Lespiau07144422013-10-15 18:55:40 +01002988 }
2989
2990 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002991 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002992
Damien Lespiau07144422013-10-15 18:55:40 +01002993 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002994 while (n_entries > 0) {
2995 struct intel_pipe_crc_entry *entry =
2996 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01002997 int ret;
2998
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002999 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3000 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3001 break;
3002
3003 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3004 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3005
Damien Lespiau07144422013-10-15 18:55:40 +01003006 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3007 "%8u %8x %8x %8x %8x %8x\n",
3008 entry->frame, entry->crc[0],
3009 entry->crc[1], entry->crc[2],
3010 entry->crc[3], entry->crc[4]);
3011
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003012 spin_unlock_irq(&pipe_crc->lock);
3013
3014 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003015 if (ret == PIPE_CRC_LINE_LEN)
3016 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003017
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003018 user_buf += PIPE_CRC_LINE_LEN;
3019 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003020
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003021 spin_lock_irq(&pipe_crc->lock);
3022 }
3023
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003024 spin_unlock_irq(&pipe_crc->lock);
3025
Damien Lespiau07144422013-10-15 18:55:40 +01003026 return bytes_read;
3027}
3028
3029static const struct file_operations i915_pipe_crc_fops = {
3030 .owner = THIS_MODULE,
3031 .open = i915_pipe_crc_open,
3032 .read = i915_pipe_crc_read,
3033 .release = i915_pipe_crc_release,
3034};
3035
3036static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3037 {
3038 .name = "i915_pipe_A_crc",
3039 .pipe = PIPE_A,
3040 },
3041 {
3042 .name = "i915_pipe_B_crc",
3043 .pipe = PIPE_B,
3044 },
3045 {
3046 .name = "i915_pipe_C_crc",
3047 .pipe = PIPE_C,
3048 },
3049};
3050
3051static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3052 enum pipe pipe)
3053{
3054 struct drm_device *dev = minor->dev;
3055 struct dentry *ent;
3056 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3057
3058 info->dev = dev;
3059 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3060 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003061 if (!ent)
3062 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003063
3064 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003065}
3066
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003067static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003068 "none",
3069 "plane1",
3070 "plane2",
3071 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003072 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003073 "TV",
3074 "DP-B",
3075 "DP-C",
3076 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003077 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003078};
3079
3080static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3081{
3082 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3083 return pipe_crc_sources[source];
3084}
3085
Damien Lespiaubd9db022013-10-15 18:55:36 +01003086static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003087{
3088 struct drm_device *dev = m->private;
3089 struct drm_i915_private *dev_priv = dev->dev_private;
3090 int i;
3091
3092 for (i = 0; i < I915_MAX_PIPES; i++)
3093 seq_printf(m, "%c %s\n", pipe_name(i),
3094 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3095
3096 return 0;
3097}
3098
Damien Lespiaubd9db022013-10-15 18:55:36 +01003099static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003100{
3101 struct drm_device *dev = inode->i_private;
3102
Damien Lespiaubd9db022013-10-15 18:55:36 +01003103 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003104}
3105
Daniel Vetter46a19182013-11-01 10:50:20 +01003106static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003107 uint32_t *val)
3108{
Daniel Vetter46a19182013-11-01 10:50:20 +01003109 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3110 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3111
3112 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003113 case INTEL_PIPE_CRC_SOURCE_PIPE:
3114 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3115 break;
3116 case INTEL_PIPE_CRC_SOURCE_NONE:
3117 *val = 0;
3118 break;
3119 default:
3120 return -EINVAL;
3121 }
3122
3123 return 0;
3124}
3125
Daniel Vetter46a19182013-11-01 10:50:20 +01003126static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3127 enum intel_pipe_crc_source *source)
3128{
3129 struct intel_encoder *encoder;
3130 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003131 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003132 int ret = 0;
3133
3134 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3135
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003136 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003137 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003138 if (!encoder->base.crtc)
3139 continue;
3140
3141 crtc = to_intel_crtc(encoder->base.crtc);
3142
3143 if (crtc->pipe != pipe)
3144 continue;
3145
3146 switch (encoder->type) {
3147 case INTEL_OUTPUT_TVOUT:
3148 *source = INTEL_PIPE_CRC_SOURCE_TV;
3149 break;
3150 case INTEL_OUTPUT_DISPLAYPORT:
3151 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003152 dig_port = enc_to_dig_port(&encoder->base);
3153 switch (dig_port->port) {
3154 case PORT_B:
3155 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3156 break;
3157 case PORT_C:
3158 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3159 break;
3160 case PORT_D:
3161 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3162 break;
3163 default:
3164 WARN(1, "nonexisting DP port %c\n",
3165 port_name(dig_port->port));
3166 break;
3167 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003168 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003169 default:
3170 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003171 }
3172 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003173 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003174
3175 return ret;
3176}
3177
3178static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3179 enum pipe pipe,
3180 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003181 uint32_t *val)
3182{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003183 struct drm_i915_private *dev_priv = dev->dev_private;
3184 bool need_stable_symbols = false;
3185
Daniel Vetter46a19182013-11-01 10:50:20 +01003186 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3187 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3188 if (ret)
3189 return ret;
3190 }
3191
3192 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003193 case INTEL_PIPE_CRC_SOURCE_PIPE:
3194 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3195 break;
3196 case INTEL_PIPE_CRC_SOURCE_DP_B:
3197 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003198 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003199 break;
3200 case INTEL_PIPE_CRC_SOURCE_DP_C:
3201 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003202 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003203 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003204 case INTEL_PIPE_CRC_SOURCE_DP_D:
3205 if (!IS_CHERRYVIEW(dev))
3206 return -EINVAL;
3207 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3208 need_stable_symbols = true;
3209 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003210 case INTEL_PIPE_CRC_SOURCE_NONE:
3211 *val = 0;
3212 break;
3213 default:
3214 return -EINVAL;
3215 }
3216
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003217 /*
3218 * When the pipe CRC tap point is after the transcoders we need
3219 * to tweak symbol-level features to produce a deterministic series of
3220 * symbols for a given frame. We need to reset those features only once
3221 * a frame (instead of every nth symbol):
3222 * - DC-balance: used to ensure a better clock recovery from the data
3223 * link (SDVO)
3224 * - DisplayPort scrambling: used for EMI reduction
3225 */
3226 if (need_stable_symbols) {
3227 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3228
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003229 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003230 switch (pipe) {
3231 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003232 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003233 break;
3234 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003235 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003236 break;
3237 case PIPE_C:
3238 tmp |= PIPE_C_SCRAMBLE_RESET;
3239 break;
3240 default:
3241 return -EINVAL;
3242 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003243 I915_WRITE(PORT_DFT2_G4X, tmp);
3244 }
3245
Daniel Vetter7ac01292013-10-18 16:37:06 +02003246 return 0;
3247}
3248
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003249static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003250 enum pipe pipe,
3251 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003252 uint32_t *val)
3253{
Daniel Vetter84093602013-11-01 10:50:21 +01003254 struct drm_i915_private *dev_priv = dev->dev_private;
3255 bool need_stable_symbols = false;
3256
Daniel Vetter46a19182013-11-01 10:50:20 +01003257 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3258 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3259 if (ret)
3260 return ret;
3261 }
3262
3263 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003264 case INTEL_PIPE_CRC_SOURCE_PIPE:
3265 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3266 break;
3267 case INTEL_PIPE_CRC_SOURCE_TV:
3268 if (!SUPPORTS_TV(dev))
3269 return -EINVAL;
3270 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3271 break;
3272 case INTEL_PIPE_CRC_SOURCE_DP_B:
3273 if (!IS_G4X(dev))
3274 return -EINVAL;
3275 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_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_DP_C:
3279 if (!IS_G4X(dev))
3280 return -EINVAL;
3281 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003282 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003283 break;
3284 case INTEL_PIPE_CRC_SOURCE_DP_D:
3285 if (!IS_G4X(dev))
3286 return -EINVAL;
3287 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003288 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003289 break;
3290 case INTEL_PIPE_CRC_SOURCE_NONE:
3291 *val = 0;
3292 break;
3293 default:
3294 return -EINVAL;
3295 }
3296
Daniel Vetter84093602013-11-01 10:50:21 +01003297 /*
3298 * When the pipe CRC tap point is after the transcoders we need
3299 * to tweak symbol-level features to produce a deterministic series of
3300 * symbols for a given frame. We need to reset those features only once
3301 * a frame (instead of every nth symbol):
3302 * - DC-balance: used to ensure a better clock recovery from the data
3303 * link (SDVO)
3304 * - DisplayPort scrambling: used for EMI reduction
3305 */
3306 if (need_stable_symbols) {
3307 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3308
3309 WARN_ON(!IS_G4X(dev));
3310
3311 I915_WRITE(PORT_DFT_I9XX,
3312 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3313
3314 if (pipe == PIPE_A)
3315 tmp |= PIPE_A_SCRAMBLE_RESET;
3316 else
3317 tmp |= PIPE_B_SCRAMBLE_RESET;
3318
3319 I915_WRITE(PORT_DFT2_G4X, tmp);
3320 }
3321
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003322 return 0;
3323}
3324
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003325static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3326 enum pipe pipe)
3327{
3328 struct drm_i915_private *dev_priv = dev->dev_private;
3329 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3330
Ville Syrjäläeb736672014-12-09 21:28:28 +02003331 switch (pipe) {
3332 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003333 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003334 break;
3335 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003336 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003337 break;
3338 case PIPE_C:
3339 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3340 break;
3341 default:
3342 return;
3343 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003344 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3345 tmp &= ~DC_BALANCE_RESET_VLV;
3346 I915_WRITE(PORT_DFT2_G4X, tmp);
3347
3348}
3349
Daniel Vetter84093602013-11-01 10:50:21 +01003350static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3351 enum pipe pipe)
3352{
3353 struct drm_i915_private *dev_priv = dev->dev_private;
3354 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3355
3356 if (pipe == PIPE_A)
3357 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3358 else
3359 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3360 I915_WRITE(PORT_DFT2_G4X, tmp);
3361
3362 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3363 I915_WRITE(PORT_DFT_I9XX,
3364 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3365 }
3366}
3367
Daniel Vetter46a19182013-11-01 10:50:20 +01003368static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003369 uint32_t *val)
3370{
Daniel Vetter46a19182013-11-01 10:50:20 +01003371 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3372 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3373
3374 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003375 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3376 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3377 break;
3378 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3379 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3380 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003381 case INTEL_PIPE_CRC_SOURCE_PIPE:
3382 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3383 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003384 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003385 *val = 0;
3386 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003387 default:
3388 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003389 }
3390
3391 return 0;
3392}
3393
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003394static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3395{
3396 struct drm_i915_private *dev_priv = dev->dev_private;
3397 struct intel_crtc *crtc =
3398 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3399
3400 drm_modeset_lock_all(dev);
3401 /*
3402 * If we use the eDP transcoder we need to make sure that we don't
3403 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3404 * relevant on hsw with pipe A when using the always-on power well
3405 * routing.
3406 */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02003407 if (crtc->config->cpu_transcoder == TRANSCODER_EDP &&
3408 !crtc->config->pch_pfit.enabled) {
3409 crtc->config->pch_pfit.force_thru = true;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003410
3411 intel_display_power_get(dev_priv,
3412 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3413
3414 dev_priv->display.crtc_disable(&crtc->base);
3415 dev_priv->display.crtc_enable(&crtc->base);
3416 }
3417 drm_modeset_unlock_all(dev);
3418}
3419
3420static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3421{
3422 struct drm_i915_private *dev_priv = dev->dev_private;
3423 struct intel_crtc *crtc =
3424 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3425
3426 drm_modeset_lock_all(dev);
3427 /*
3428 * If we use the eDP transcoder we need to make sure that we don't
3429 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3430 * relevant on hsw with pipe A when using the always-on power well
3431 * routing.
3432 */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02003433 if (crtc->config->pch_pfit.force_thru) {
3434 crtc->config->pch_pfit.force_thru = false;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003435
3436 dev_priv->display.crtc_disable(&crtc->base);
3437 dev_priv->display.crtc_enable(&crtc->base);
3438
3439 intel_display_power_put(dev_priv,
3440 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3441 }
3442 drm_modeset_unlock_all(dev);
3443}
3444
3445static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3446 enum pipe pipe,
3447 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003448 uint32_t *val)
3449{
Daniel Vetter46a19182013-11-01 10:50:20 +01003450 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3451 *source = INTEL_PIPE_CRC_SOURCE_PF;
3452
3453 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003454 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3455 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3456 break;
3457 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3458 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3459 break;
3460 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003461 if (IS_HASWELL(dev) && pipe == PIPE_A)
3462 hsw_trans_edp_pipe_A_crc_wa(dev);
3463
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003464 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3465 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003466 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003467 *val = 0;
3468 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003469 default:
3470 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003471 }
3472
3473 return 0;
3474}
3475
Daniel Vetter926321d2013-10-16 13:30:34 +02003476static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3477 enum intel_pipe_crc_source source)
3478{
3479 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003480 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003481 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3482 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003483 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003484 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003485
Damien Lespiaucc3da172013-10-15 18:55:31 +01003486 if (pipe_crc->source == source)
3487 return 0;
3488
Damien Lespiauae676fc2013-10-15 18:55:32 +01003489 /* forbid changing the source without going back to 'none' */
3490 if (pipe_crc->source && source)
3491 return -EINVAL;
3492
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003493 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3494 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3495 return -EIO;
3496 }
3497
Daniel Vetter52f843f2013-10-21 17:26:38 +02003498 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003499 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003500 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003501 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003502 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003503 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003504 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003505 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003506 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003507 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003508
3509 if (ret != 0)
3510 return ret;
3511
Damien Lespiau4b584362013-10-15 18:55:33 +01003512 /* none -> real source transition */
3513 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003514 struct intel_pipe_crc_entry *entries;
3515
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003516 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3517 pipe_name(pipe), pipe_crc_source_name(source));
3518
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003519 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3520 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003521 GFP_KERNEL);
3522 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003523 return -ENOMEM;
3524
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003525 /*
3526 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3527 * enabled and disabled dynamically based on package C states,
3528 * user space can't make reliable use of the CRCs, so let's just
3529 * completely disable it.
3530 */
3531 hsw_disable_ips(crtc);
3532
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003533 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003534 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003535 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003536 pipe_crc->head = 0;
3537 pipe_crc->tail = 0;
3538 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003539 }
3540
Damien Lespiaucc3da172013-10-15 18:55:31 +01003541 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003542
Daniel Vetter926321d2013-10-16 13:30:34 +02003543 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3544 POSTING_READ(PIPE_CRC_CTL(pipe));
3545
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003546 /* real source -> none transition */
3547 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003548 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003549 struct intel_crtc *crtc =
3550 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003551
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003552 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3553 pipe_name(pipe));
3554
Daniel Vettera33d7102014-06-06 08:22:08 +02003555 drm_modeset_lock(&crtc->base.mutex, NULL);
3556 if (crtc->active)
3557 intel_wait_for_vblank(dev, pipe);
3558 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003559
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003560 spin_lock_irq(&pipe_crc->lock);
3561 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003562 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003563 pipe_crc->head = 0;
3564 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003565 spin_unlock_irq(&pipe_crc->lock);
3566
3567 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003568
3569 if (IS_G4X(dev))
3570 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003571 else if (IS_VALLEYVIEW(dev))
3572 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003573 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3574 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003575
3576 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003577 }
3578
Daniel Vetter926321d2013-10-16 13:30:34 +02003579 return 0;
3580}
3581
3582/*
3583 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003584 * command: wsp* object wsp+ name wsp+ source wsp*
3585 * object: 'pipe'
3586 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003587 * source: (none | plane1 | plane2 | pf)
3588 * wsp: (#0x20 | #0x9 | #0xA)+
3589 *
3590 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003591 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3592 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003593 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003594static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003595{
3596 int n_words = 0;
3597
3598 while (*buf) {
3599 char *end;
3600
3601 /* skip leading white space */
3602 buf = skip_spaces(buf);
3603 if (!*buf)
3604 break; /* end of buffer */
3605
3606 /* find end of word */
3607 for (end = buf; *end && !isspace(*end); end++)
3608 ;
3609
3610 if (n_words == max_words) {
3611 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3612 max_words);
3613 return -EINVAL; /* ran out of words[] before bytes */
3614 }
3615
3616 if (*end)
3617 *end++ = '\0';
3618 words[n_words++] = buf;
3619 buf = end;
3620 }
3621
3622 return n_words;
3623}
3624
Damien Lespiaub94dec82013-10-15 18:55:35 +01003625enum intel_pipe_crc_object {
3626 PIPE_CRC_OBJECT_PIPE,
3627};
3628
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003629static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003630 "pipe",
3631};
3632
3633static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003634display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003635{
3636 int i;
3637
3638 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3639 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003640 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003641 return 0;
3642 }
3643
3644 return -EINVAL;
3645}
3646
Damien Lespiaubd9db022013-10-15 18:55:36 +01003647static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003648{
3649 const char name = buf[0];
3650
3651 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3652 return -EINVAL;
3653
3654 *pipe = name - 'A';
3655
3656 return 0;
3657}
3658
3659static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003660display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003661{
3662 int i;
3663
3664 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3665 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003666 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003667 return 0;
3668 }
3669
3670 return -EINVAL;
3671}
3672
Damien Lespiaubd9db022013-10-15 18:55:36 +01003673static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003674{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003675#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003676 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003677 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003678 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003679 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003680 enum intel_pipe_crc_source source;
3681
Damien Lespiaubd9db022013-10-15 18:55:36 +01003682 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003683 if (n_words != N_WORDS) {
3684 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3685 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003686 return -EINVAL;
3687 }
3688
Damien Lespiaubd9db022013-10-15 18:55:36 +01003689 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003690 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003691 return -EINVAL;
3692 }
3693
Damien Lespiaubd9db022013-10-15 18:55:36 +01003694 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003695 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3696 return -EINVAL;
3697 }
3698
Damien Lespiaubd9db022013-10-15 18:55:36 +01003699 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003700 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003701 return -EINVAL;
3702 }
3703
3704 return pipe_crc_set_source(dev, pipe, source);
3705}
3706
Damien Lespiaubd9db022013-10-15 18:55:36 +01003707static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3708 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003709{
3710 struct seq_file *m = file->private_data;
3711 struct drm_device *dev = m->private;
3712 char *tmpbuf;
3713 int ret;
3714
3715 if (len == 0)
3716 return 0;
3717
3718 if (len > PAGE_SIZE - 1) {
3719 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3720 PAGE_SIZE);
3721 return -E2BIG;
3722 }
3723
3724 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3725 if (!tmpbuf)
3726 return -ENOMEM;
3727
3728 if (copy_from_user(tmpbuf, ubuf, len)) {
3729 ret = -EFAULT;
3730 goto out;
3731 }
3732 tmpbuf[len] = '\0';
3733
Damien Lespiaubd9db022013-10-15 18:55:36 +01003734 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003735
3736out:
3737 kfree(tmpbuf);
3738 if (ret < 0)
3739 return ret;
3740
3741 *offp += len;
3742 return len;
3743}
3744
Damien Lespiaubd9db022013-10-15 18:55:36 +01003745static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003746 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003747 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003748 .read = seq_read,
3749 .llseek = seq_lseek,
3750 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003751 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003752};
3753
Damien Lespiau97e94b22014-11-04 17:06:50 +00003754static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003755{
3756 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003757 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003758 int level;
3759
3760 drm_modeset_lock_all(dev);
3761
3762 for (level = 0; level < num_levels; level++) {
3763 unsigned int latency = wm[level];
3764
Damien Lespiau97e94b22014-11-04 17:06:50 +00003765 /*
3766 * - WM1+ latency values in 0.5us units
3767 * - latencies are in us on gen9
3768 */
3769 if (INTEL_INFO(dev)->gen >= 9)
3770 latency *= 10;
3771 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003772 latency *= 5;
3773
3774 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003775 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003776 }
3777
3778 drm_modeset_unlock_all(dev);
3779}
3780
3781static int pri_wm_latency_show(struct seq_file *m, void *data)
3782{
3783 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003784 struct drm_i915_private *dev_priv = dev->dev_private;
3785 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003786
Damien Lespiau97e94b22014-11-04 17:06:50 +00003787 if (INTEL_INFO(dev)->gen >= 9)
3788 latencies = dev_priv->wm.skl_latency;
3789 else
3790 latencies = to_i915(dev)->wm.pri_latency;
3791
3792 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003793
3794 return 0;
3795}
3796
3797static int spr_wm_latency_show(struct seq_file *m, void *data)
3798{
3799 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003800 struct drm_i915_private *dev_priv = dev->dev_private;
3801 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003802
Damien Lespiau97e94b22014-11-04 17:06:50 +00003803 if (INTEL_INFO(dev)->gen >= 9)
3804 latencies = dev_priv->wm.skl_latency;
3805 else
3806 latencies = to_i915(dev)->wm.spr_latency;
3807
3808 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003809
3810 return 0;
3811}
3812
3813static int cur_wm_latency_show(struct seq_file *m, void *data)
3814{
3815 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003816 struct drm_i915_private *dev_priv = dev->dev_private;
3817 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003818
Damien Lespiau97e94b22014-11-04 17:06:50 +00003819 if (INTEL_INFO(dev)->gen >= 9)
3820 latencies = dev_priv->wm.skl_latency;
3821 else
3822 latencies = to_i915(dev)->wm.cur_latency;
3823
3824 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003825
3826 return 0;
3827}
3828
3829static int pri_wm_latency_open(struct inode *inode, struct file *file)
3830{
3831 struct drm_device *dev = inode->i_private;
3832
Sonika Jindal9ad02572014-07-21 15:23:39 +05303833 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003834 return -ENODEV;
3835
3836 return single_open(file, pri_wm_latency_show, dev);
3837}
3838
3839static int spr_wm_latency_open(struct inode *inode, struct file *file)
3840{
3841 struct drm_device *dev = inode->i_private;
3842
Sonika Jindal9ad02572014-07-21 15:23:39 +05303843 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003844 return -ENODEV;
3845
3846 return single_open(file, spr_wm_latency_show, dev);
3847}
3848
3849static int cur_wm_latency_open(struct inode *inode, struct file *file)
3850{
3851 struct drm_device *dev = inode->i_private;
3852
Sonika Jindal9ad02572014-07-21 15:23:39 +05303853 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003854 return -ENODEV;
3855
3856 return single_open(file, cur_wm_latency_show, dev);
3857}
3858
3859static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003860 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003861{
3862 struct seq_file *m = file->private_data;
3863 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003864 uint16_t new[8] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003865 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003866 int level;
3867 int ret;
3868 char tmp[32];
3869
3870 if (len >= sizeof(tmp))
3871 return -EINVAL;
3872
3873 if (copy_from_user(tmp, ubuf, len))
3874 return -EFAULT;
3875
3876 tmp[len] = '\0';
3877
Damien Lespiau97e94b22014-11-04 17:06:50 +00003878 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
3879 &new[0], &new[1], &new[2], &new[3],
3880 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003881 if (ret != num_levels)
3882 return -EINVAL;
3883
3884 drm_modeset_lock_all(dev);
3885
3886 for (level = 0; level < num_levels; level++)
3887 wm[level] = new[level];
3888
3889 drm_modeset_unlock_all(dev);
3890
3891 return len;
3892}
3893
3894
3895static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3896 size_t len, loff_t *offp)
3897{
3898 struct seq_file *m = file->private_data;
3899 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003900 struct drm_i915_private *dev_priv = dev->dev_private;
3901 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003902
Damien Lespiau97e94b22014-11-04 17:06:50 +00003903 if (INTEL_INFO(dev)->gen >= 9)
3904 latencies = dev_priv->wm.skl_latency;
3905 else
3906 latencies = to_i915(dev)->wm.pri_latency;
3907
3908 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003909}
3910
3911static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3912 size_t len, loff_t *offp)
3913{
3914 struct seq_file *m = file->private_data;
3915 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003916 struct drm_i915_private *dev_priv = dev->dev_private;
3917 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003918
Damien Lespiau97e94b22014-11-04 17:06:50 +00003919 if (INTEL_INFO(dev)->gen >= 9)
3920 latencies = dev_priv->wm.skl_latency;
3921 else
3922 latencies = to_i915(dev)->wm.spr_latency;
3923
3924 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003925}
3926
3927static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3928 size_t len, loff_t *offp)
3929{
3930 struct seq_file *m = file->private_data;
3931 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003932 struct drm_i915_private *dev_priv = dev->dev_private;
3933 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003934
Damien Lespiau97e94b22014-11-04 17:06:50 +00003935 if (INTEL_INFO(dev)->gen >= 9)
3936 latencies = dev_priv->wm.skl_latency;
3937 else
3938 latencies = to_i915(dev)->wm.cur_latency;
3939
3940 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003941}
3942
3943static const struct file_operations i915_pri_wm_latency_fops = {
3944 .owner = THIS_MODULE,
3945 .open = pri_wm_latency_open,
3946 .read = seq_read,
3947 .llseek = seq_lseek,
3948 .release = single_release,
3949 .write = pri_wm_latency_write
3950};
3951
3952static const struct file_operations i915_spr_wm_latency_fops = {
3953 .owner = THIS_MODULE,
3954 .open = spr_wm_latency_open,
3955 .read = seq_read,
3956 .llseek = seq_lseek,
3957 .release = single_release,
3958 .write = spr_wm_latency_write
3959};
3960
3961static const struct file_operations i915_cur_wm_latency_fops = {
3962 .owner = THIS_MODULE,
3963 .open = cur_wm_latency_open,
3964 .read = seq_read,
3965 .llseek = seq_lseek,
3966 .release = single_release,
3967 .write = cur_wm_latency_write
3968};
3969
Kees Cook647416f2013-03-10 14:10:06 -07003970static int
3971i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003972{
Kees Cook647416f2013-03-10 14:10:06 -07003973 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003974 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003975
Kees Cook647416f2013-03-10 14:10:06 -07003976 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003977
Kees Cook647416f2013-03-10 14:10:06 -07003978 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003979}
3980
Kees Cook647416f2013-03-10 14:10:06 -07003981static int
3982i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003983{
Kees Cook647416f2013-03-10 14:10:06 -07003984 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03003985 struct drm_i915_private *dev_priv = dev->dev_private;
3986
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02003987 /*
3988 * There is no safeguard against this debugfs entry colliding
3989 * with the hangcheck calling same i915_handle_error() in
3990 * parallel, causing an explosion. For now we assume that the
3991 * test harness is responsible enough not to inject gpu hangs
3992 * while it is writing to 'i915_wedged'
3993 */
3994
3995 if (i915_reset_in_progress(&dev_priv->gpu_error))
3996 return -EAGAIN;
3997
Imre Deakd46c0512014-04-14 20:24:27 +03003998 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003999
Mika Kuoppala58174462014-02-25 17:11:26 +02004000 i915_handle_error(dev, val,
4001 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004002
4003 intel_runtime_pm_put(dev_priv);
4004
Kees Cook647416f2013-03-10 14:10:06 -07004005 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004006}
4007
Kees Cook647416f2013-03-10 14:10:06 -07004008DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4009 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004010 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004011
Kees Cook647416f2013-03-10 14:10:06 -07004012static int
4013i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004014{
Kees Cook647416f2013-03-10 14:10:06 -07004015 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004016 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004017
Kees Cook647416f2013-03-10 14:10:06 -07004018 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004019
Kees Cook647416f2013-03-10 14:10:06 -07004020 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004021}
4022
Kees Cook647416f2013-03-10 14:10:06 -07004023static int
4024i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004025{
Kees Cook647416f2013-03-10 14:10:06 -07004026 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004027 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004028 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004029
Kees Cook647416f2013-03-10 14:10:06 -07004030 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004031
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004032 ret = mutex_lock_interruptible(&dev->struct_mutex);
4033 if (ret)
4034 return ret;
4035
Daniel Vetter99584db2012-11-14 17:14:04 +01004036 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004037 mutex_unlock(&dev->struct_mutex);
4038
Kees Cook647416f2013-03-10 14:10:06 -07004039 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004040}
4041
Kees Cook647416f2013-03-10 14:10:06 -07004042DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4043 i915_ring_stop_get, i915_ring_stop_set,
4044 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004045
Chris Wilson094f9a52013-09-25 17:34:55 +01004046static int
4047i915_ring_missed_irq_get(void *data, u64 *val)
4048{
4049 struct drm_device *dev = data;
4050 struct drm_i915_private *dev_priv = dev->dev_private;
4051
4052 *val = dev_priv->gpu_error.missed_irq_rings;
4053 return 0;
4054}
4055
4056static int
4057i915_ring_missed_irq_set(void *data, u64 val)
4058{
4059 struct drm_device *dev = data;
4060 struct drm_i915_private *dev_priv = dev->dev_private;
4061 int ret;
4062
4063 /* Lock against concurrent debugfs callers */
4064 ret = mutex_lock_interruptible(&dev->struct_mutex);
4065 if (ret)
4066 return ret;
4067 dev_priv->gpu_error.missed_irq_rings = val;
4068 mutex_unlock(&dev->struct_mutex);
4069
4070 return 0;
4071}
4072
4073DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4074 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4075 "0x%08llx\n");
4076
4077static int
4078i915_ring_test_irq_get(void *data, u64 *val)
4079{
4080 struct drm_device *dev = data;
4081 struct drm_i915_private *dev_priv = dev->dev_private;
4082
4083 *val = dev_priv->gpu_error.test_irq_rings;
4084
4085 return 0;
4086}
4087
4088static int
4089i915_ring_test_irq_set(void *data, u64 val)
4090{
4091 struct drm_device *dev = data;
4092 struct drm_i915_private *dev_priv = dev->dev_private;
4093 int ret;
4094
4095 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4096
4097 /* Lock against concurrent debugfs callers */
4098 ret = mutex_lock_interruptible(&dev->struct_mutex);
4099 if (ret)
4100 return ret;
4101
4102 dev_priv->gpu_error.test_irq_rings = val;
4103 mutex_unlock(&dev->struct_mutex);
4104
4105 return 0;
4106}
4107
4108DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4109 i915_ring_test_irq_get, i915_ring_test_irq_set,
4110 "0x%08llx\n");
4111
Chris Wilsondd624af2013-01-15 12:39:35 +00004112#define DROP_UNBOUND 0x1
4113#define DROP_BOUND 0x2
4114#define DROP_RETIRE 0x4
4115#define DROP_ACTIVE 0x8
4116#define DROP_ALL (DROP_UNBOUND | \
4117 DROP_BOUND | \
4118 DROP_RETIRE | \
4119 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004120static int
4121i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004122{
Kees Cook647416f2013-03-10 14:10:06 -07004123 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004124
Kees Cook647416f2013-03-10 14:10:06 -07004125 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004126}
4127
Kees Cook647416f2013-03-10 14:10:06 -07004128static int
4129i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004130{
Kees Cook647416f2013-03-10 14:10:06 -07004131 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004132 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004133 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004134
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004135 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004136
4137 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4138 * on ioctls on -EAGAIN. */
4139 ret = mutex_lock_interruptible(&dev->struct_mutex);
4140 if (ret)
4141 return ret;
4142
4143 if (val & DROP_ACTIVE) {
4144 ret = i915_gpu_idle(dev);
4145 if (ret)
4146 goto unlock;
4147 }
4148
4149 if (val & (DROP_RETIRE | DROP_ACTIVE))
4150 i915_gem_retire_requests(dev);
4151
Chris Wilson21ab4e72014-09-09 11:16:08 +01004152 if (val & DROP_BOUND)
4153 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004154
Chris Wilson21ab4e72014-09-09 11:16:08 +01004155 if (val & DROP_UNBOUND)
4156 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004157
4158unlock:
4159 mutex_unlock(&dev->struct_mutex);
4160
Kees Cook647416f2013-03-10 14:10:06 -07004161 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004162}
4163
Kees Cook647416f2013-03-10 14:10:06 -07004164DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4165 i915_drop_caches_get, i915_drop_caches_set,
4166 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004167
Kees Cook647416f2013-03-10 14:10:06 -07004168static int
4169i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004170{
Kees Cook647416f2013-03-10 14:10:06 -07004171 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004172 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004173 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004174
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004175 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004176 return -ENODEV;
4177
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004178 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4179
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004180 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004181 if (ret)
4182 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004183
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004184 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004185 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004186
Kees Cook647416f2013-03-10 14:10:06 -07004187 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004188}
4189
Kees Cook647416f2013-03-10 14:10:06 -07004190static int
4191i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004192{
Kees Cook647416f2013-03-10 14:10:06 -07004193 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004194 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304195 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004196 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004197
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004198 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004199 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004200
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004201 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4202
Kees Cook647416f2013-03-10 14:10:06 -07004203 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004204
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004205 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004206 if (ret)
4207 return ret;
4208
Jesse Barnes358733e2011-07-27 11:53:01 -07004209 /*
4210 * Turbo will still be enabled, but won't go above the set value.
4211 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304212 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004213
Akash Goelbc4d91f2015-02-26 16:09:47 +05304214 hw_max = dev_priv->rps.max_freq;
4215 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004216
Ben Widawskyb39fb292014-03-19 18:31:11 -07004217 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004218 mutex_unlock(&dev_priv->rps.hw_lock);
4219 return -EINVAL;
4220 }
4221
Ben Widawskyb39fb292014-03-19 18:31:11 -07004222 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004223
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004224 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004225
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004226 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004227
Kees Cook647416f2013-03-10 14:10:06 -07004228 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004229}
4230
Kees Cook647416f2013-03-10 14:10:06 -07004231DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4232 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004233 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004234
Kees Cook647416f2013-03-10 14:10:06 -07004235static int
4236i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004237{
Kees Cook647416f2013-03-10 14:10:06 -07004238 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004239 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004240 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004241
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004242 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004243 return -ENODEV;
4244
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004245 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4246
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004247 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004248 if (ret)
4249 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004250
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004251 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004252 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004253
Kees Cook647416f2013-03-10 14:10:06 -07004254 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004255}
4256
Kees Cook647416f2013-03-10 14:10:06 -07004257static int
4258i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004259{
Kees Cook647416f2013-03-10 14:10:06 -07004260 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004261 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304262 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004263 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004264
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004265 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004266 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004267
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004268 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4269
Kees Cook647416f2013-03-10 14:10:06 -07004270 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004271
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004272 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004273 if (ret)
4274 return ret;
4275
Jesse Barnes1523c312012-05-25 12:34:54 -07004276 /*
4277 * Turbo will still be enabled, but won't go below the set value.
4278 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304279 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004280
Akash Goelbc4d91f2015-02-26 16:09:47 +05304281 hw_max = dev_priv->rps.max_freq;
4282 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004283
Ben Widawskyb39fb292014-03-19 18:31:11 -07004284 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004285 mutex_unlock(&dev_priv->rps.hw_lock);
4286 return -EINVAL;
4287 }
4288
Ben Widawskyb39fb292014-03-19 18:31:11 -07004289 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004290
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004291 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004292
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004293 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004294
Kees Cook647416f2013-03-10 14:10:06 -07004295 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004296}
4297
Kees Cook647416f2013-03-10 14:10:06 -07004298DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4299 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004300 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004301
Kees Cook647416f2013-03-10 14:10:06 -07004302static int
4303i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004304{
Kees Cook647416f2013-03-10 14:10:06 -07004305 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004306 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004307 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004308 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004309
Daniel Vetter004777c2012-08-09 15:07:01 +02004310 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4311 return -ENODEV;
4312
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004313 ret = mutex_lock_interruptible(&dev->struct_mutex);
4314 if (ret)
4315 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004316 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004317
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004318 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004319
4320 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004321 mutex_unlock(&dev_priv->dev->struct_mutex);
4322
Kees Cook647416f2013-03-10 14:10:06 -07004323 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004324
Kees Cook647416f2013-03-10 14:10:06 -07004325 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004326}
4327
Kees Cook647416f2013-03-10 14:10:06 -07004328static int
4329i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004330{
Kees Cook647416f2013-03-10 14:10:06 -07004331 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004332 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004333 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004334
Daniel Vetter004777c2012-08-09 15:07:01 +02004335 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4336 return -ENODEV;
4337
Kees Cook647416f2013-03-10 14:10:06 -07004338 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004339 return -EINVAL;
4340
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004341 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004342 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004343
4344 /* Update the cache sharing policy here as well */
4345 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4346 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4347 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4348 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4349
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004350 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004351 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004352}
4353
Kees Cook647416f2013-03-10 14:10:06 -07004354DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4355 i915_cache_sharing_get, i915_cache_sharing_set,
4356 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004357
Jeff McGee38732182015-02-13 10:27:54 -06004358static int i915_sseu_status(struct seq_file *m, void *unused)
4359{
4360 struct drm_info_node *node = (struct drm_info_node *) m->private;
4361 struct drm_device *dev = node->minor->dev;
Jeff McGee7f992ab2015-02-13 10:27:55 -06004362 struct drm_i915_private *dev_priv = dev->dev_private;
4363 unsigned int s_tot = 0, ss_tot = 0, ss_per = 0, eu_tot = 0, eu_per = 0;
Jeff McGee38732182015-02-13 10:27:54 -06004364
4365 if (INTEL_INFO(dev)->gen < 9)
4366 return -ENODEV;
4367
4368 seq_puts(m, "SSEU Device Info\n");
4369 seq_printf(m, " Available Slice Total: %u\n",
4370 INTEL_INFO(dev)->slice_total);
4371 seq_printf(m, " Available Subslice Total: %u\n",
4372 INTEL_INFO(dev)->subslice_total);
4373 seq_printf(m, " Available Subslice Per Slice: %u\n",
4374 INTEL_INFO(dev)->subslice_per_slice);
4375 seq_printf(m, " Available EU Total: %u\n",
4376 INTEL_INFO(dev)->eu_total);
4377 seq_printf(m, " Available EU Per Subslice: %u\n",
4378 INTEL_INFO(dev)->eu_per_subslice);
4379 seq_printf(m, " Has Slice Power Gating: %s\n",
4380 yesno(INTEL_INFO(dev)->has_slice_pg));
4381 seq_printf(m, " Has Subslice Power Gating: %s\n",
4382 yesno(INTEL_INFO(dev)->has_subslice_pg));
4383 seq_printf(m, " Has EU Power Gating: %s\n",
4384 yesno(INTEL_INFO(dev)->has_eu_pg));
4385
Jeff McGee7f992ab2015-02-13 10:27:55 -06004386 seq_puts(m, "SSEU Device Status\n");
4387 if (IS_SKYLAKE(dev)) {
4388 const int s_max = 3, ss_max = 4;
4389 int s, ss;
4390 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4391
4392 s_reg[0] = I915_READ(GEN9_SLICE0_PGCTL_ACK);
4393 s_reg[1] = I915_READ(GEN9_SLICE1_PGCTL_ACK);
4394 s_reg[2] = I915_READ(GEN9_SLICE2_PGCTL_ACK);
4395 eu_reg[0] = I915_READ(GEN9_SLICE0_SS01_EU_PGCTL_ACK);
4396 eu_reg[1] = I915_READ(GEN9_SLICE0_SS23_EU_PGCTL_ACK);
4397 eu_reg[2] = I915_READ(GEN9_SLICE1_SS01_EU_PGCTL_ACK);
4398 eu_reg[3] = I915_READ(GEN9_SLICE1_SS23_EU_PGCTL_ACK);
4399 eu_reg[4] = I915_READ(GEN9_SLICE2_SS01_EU_PGCTL_ACK);
4400 eu_reg[5] = I915_READ(GEN9_SLICE2_SS23_EU_PGCTL_ACK);
4401 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4402 GEN9_PGCTL_SSA_EU19_ACK |
4403 GEN9_PGCTL_SSA_EU210_ACK |
4404 GEN9_PGCTL_SSA_EU311_ACK;
4405 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4406 GEN9_PGCTL_SSB_EU19_ACK |
4407 GEN9_PGCTL_SSB_EU210_ACK |
4408 GEN9_PGCTL_SSB_EU311_ACK;
4409
4410 for (s = 0; s < s_max; s++) {
4411 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4412 /* skip disabled slice */
4413 continue;
4414
4415 s_tot++;
4416 ss_per = INTEL_INFO(dev)->subslice_per_slice;
4417 ss_tot += ss_per;
4418 for (ss = 0; ss < ss_max; ss++) {
4419 unsigned int eu_cnt;
4420
4421 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4422 eu_mask[ss%2]);
4423 eu_tot += eu_cnt;
4424 eu_per = max(eu_per, eu_cnt);
4425 }
4426 }
4427 }
4428 seq_printf(m, " Enabled Slice Total: %u\n", s_tot);
4429 seq_printf(m, " Enabled Subslice Total: %u\n", ss_tot);
4430 seq_printf(m, " Enabled Subslice Per Slice: %u\n", ss_per);
4431 seq_printf(m, " Enabled EU Total: %u\n", eu_tot);
4432 seq_printf(m, " Enabled EU Per Subslice: %u\n", eu_per);
4433
Jeff McGee38732182015-02-13 10:27:54 -06004434 return 0;
4435}
4436
Ben Widawsky6d794d42011-04-25 11:25:56 -07004437static int i915_forcewake_open(struct inode *inode, struct file *file)
4438{
4439 struct drm_device *dev = inode->i_private;
4440 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004441
Daniel Vetter075edca2012-01-24 09:44:28 +01004442 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004443 return 0;
4444
Chris Wilson6daccb02015-01-16 11:34:35 +02004445 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004446 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004447
4448 return 0;
4449}
4450
Ben Widawskyc43b5632012-04-16 14:07:40 -07004451static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004452{
4453 struct drm_device *dev = inode->i_private;
4454 struct drm_i915_private *dev_priv = dev->dev_private;
4455
Daniel Vetter075edca2012-01-24 09:44:28 +01004456 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004457 return 0;
4458
Mika Kuoppala59bad942015-01-16 11:34:40 +02004459 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004460 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004461
4462 return 0;
4463}
4464
4465static const struct file_operations i915_forcewake_fops = {
4466 .owner = THIS_MODULE,
4467 .open = i915_forcewake_open,
4468 .release = i915_forcewake_release,
4469};
4470
4471static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4472{
4473 struct drm_device *dev = minor->dev;
4474 struct dentry *ent;
4475
4476 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004477 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004478 root, dev,
4479 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004480 if (!ent)
4481 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004482
Ben Widawsky8eb57292011-05-11 15:10:58 -07004483 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004484}
4485
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004486static int i915_debugfs_create(struct dentry *root,
4487 struct drm_minor *minor,
4488 const char *name,
4489 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004490{
4491 struct drm_device *dev = minor->dev;
4492 struct dentry *ent;
4493
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004494 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004495 S_IRUGO | S_IWUSR,
4496 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004497 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004498 if (!ent)
4499 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004500
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004501 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004502}
4503
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004504static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004505 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004506 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004507 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01004508 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004509 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004510 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004511 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004512 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004513 {"i915_gem_request", i915_gem_request_info, 0},
4514 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004515 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004516 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00004517 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
4518 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
4519 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07004520 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08004521 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304522 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004523 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004524 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004525 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004526 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004527 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004528 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004529 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004530 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004531 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004532 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01004533 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01004534 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004535 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004536 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004537 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004538 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004539 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004540 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004541 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03004542 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004543 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004544 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004545 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004546 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004547 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004548 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004549 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004550 {"i915_sseu_status", i915_sseu_status, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004551};
Ben Gamari27c202a2009-07-01 22:26:52 -04004552#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004553
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004554static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004555 const char *name;
4556 const struct file_operations *fops;
4557} i915_debugfs_files[] = {
4558 {"i915_wedged", &i915_wedged_fops},
4559 {"i915_max_freq", &i915_max_freq_fops},
4560 {"i915_min_freq", &i915_min_freq_fops},
4561 {"i915_cache_sharing", &i915_cache_sharing_fops},
4562 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004563 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4564 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004565 {"i915_gem_drop_caches", &i915_drop_caches_fops},
4566 {"i915_error_state", &i915_error_state_fops},
4567 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004568 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004569 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4570 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4571 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004572 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004573};
4574
Damien Lespiau07144422013-10-15 18:55:40 +01004575void intel_display_crc_init(struct drm_device *dev)
4576{
4577 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01004578 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01004579
Damien Lespiau055e3932014-08-18 13:49:10 +01004580 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01004581 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01004582
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004583 pipe_crc->opened = false;
4584 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01004585 init_waitqueue_head(&pipe_crc->wq);
4586 }
4587}
4588
Ben Gamari27c202a2009-07-01 22:26:52 -04004589int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004590{
Daniel Vetter34b96742013-07-04 20:49:44 +02004591 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004592
Ben Widawsky6d794d42011-04-25 11:25:56 -07004593 ret = i915_forcewake_create(minor->debugfs_root, minor);
4594 if (ret)
4595 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004596
Damien Lespiau07144422013-10-15 18:55:40 +01004597 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
4598 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
4599 if (ret)
4600 return ret;
4601 }
4602
Daniel Vetter34b96742013-07-04 20:49:44 +02004603 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4604 ret = i915_debugfs_create(minor->debugfs_root, minor,
4605 i915_debugfs_files[i].name,
4606 i915_debugfs_files[i].fops);
4607 if (ret)
4608 return ret;
4609 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004610
Ben Gamari27c202a2009-07-01 22:26:52 -04004611 return drm_debugfs_create_files(i915_debugfs_list,
4612 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004613 minor->debugfs_root, minor);
4614}
4615
Ben Gamari27c202a2009-07-01 22:26:52 -04004616void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004617{
Daniel Vetter34b96742013-07-04 20:49:44 +02004618 int i;
4619
Ben Gamari27c202a2009-07-01 22:26:52 -04004620 drm_debugfs_remove_files(i915_debugfs_list,
4621 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004622
Ben Widawsky6d794d42011-04-25 11:25:56 -07004623 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
4624 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004625
Daniel Vettere309a992013-10-16 22:55:51 +02004626 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01004627 struct drm_info_list *info_list =
4628 (struct drm_info_list *)&i915_pipe_crc_data[i];
4629
4630 drm_debugfs_remove_files(info_list, 1, minor);
4631 }
4632
Daniel Vetter34b96742013-07-04 20:49:44 +02004633 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4634 struct drm_info_list *info_list =
4635 (struct drm_info_list *) i915_debugfs_files[i].fops;
4636
4637 drm_debugfs_remove_files(info_list, 1, minor);
4638 }
Ben Gamari20172632009-02-17 20:08:50 -05004639}