blob: d0e445eca9ce5fbee6a4b18fd903ca302b541730 [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
Ville Syrjäläfb1ae912013-08-22 19:21:30 +0300126 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %u %u %u%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);
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800142 list_for_each_entry(vma, &obj->vma_list, vma_link)
143 if (vma->pin_count > 0)
144 pin_count++;
145 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100146 if (obj->pin_display)
147 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100148 if (obj->fence_reg != I915_FENCE_REG_NONE)
149 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700150 list_for_each_entry(vma, &obj->vma_list, vma_link) {
151 if (!i915_is_ggtt(vma->vm))
152 seq_puts(m, " (pp");
153 else
154 seq_puts(m, " (g");
155 seq_printf(m, "gtt offset: %08lx, size: %08lx)",
156 vma->node.start, vma->node.size);
157 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000158 if (obj->stolen)
159 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000160 if (obj->pin_mappable || obj->fault_mappable) {
161 char s[3], *t = s;
162 if (obj->pin_mappable)
163 *t++ = 'p';
164 if (obj->fault_mappable)
165 *t++ = 'f';
166 *t = '\0';
167 seq_printf(m, " (%s mappable)", s);
168 }
John Harrison41c52412014-11-24 18:49:43 +0000169 if (obj->last_read_req != NULL)
170 seq_printf(m, " (%s)",
171 i915_gem_request_get_ring(obj->last_read_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200172 if (obj->frontbuffer_bits)
173 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100174}
175
Oscar Mateo273497e2014-05-22 14:13:37 +0100176static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700177{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100178 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700179 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
180 seq_putc(m, ' ');
181}
182
Ben Gamari433e12f2009-02-17 20:08:51 -0500183static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500184{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100185 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500186 uintptr_t list = (uintptr_t) node->info_ent->data;
187 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500188 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700189 struct drm_i915_private *dev_priv = dev->dev_private;
190 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700191 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100192 size_t total_obj_size, total_gtt_size;
193 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100194
195 ret = mutex_lock_interruptible(&dev->struct_mutex);
196 if (ret)
197 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500198
Ben Widawskyca191b12013-07-31 17:00:14 -0700199 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500200 switch (list) {
201 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100202 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700203 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500204 break;
205 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100206 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700207 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500208 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500209 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100210 mutex_unlock(&dev->struct_mutex);
211 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500212 }
213
Chris Wilson8f2480f2010-09-26 11:44:19 +0100214 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700215 list_for_each_entry(vma, head, mm_list) {
216 seq_printf(m, " ");
217 describe_obj(m, vma->obj);
218 seq_printf(m, "\n");
219 total_obj_size += vma->obj->base.size;
220 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100221 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500222 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100223 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700224
Chris Wilson8f2480f2010-09-26 11:44:19 +0100225 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
226 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500227 return 0;
228}
229
Chris Wilson6d2b88852013-08-07 18:30:54 +0100230static int obj_rank_by_stolen(void *priv,
231 struct list_head *A, struct list_head *B)
232{
233 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200234 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100235 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200236 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100237
238 return a->stolen->start - b->stolen->start;
239}
240
241static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
242{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100243 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100244 struct drm_device *dev = node->minor->dev;
245 struct drm_i915_private *dev_priv = dev->dev_private;
246 struct drm_i915_gem_object *obj;
247 size_t total_obj_size, total_gtt_size;
248 LIST_HEAD(stolen);
249 int count, ret;
250
251 ret = mutex_lock_interruptible(&dev->struct_mutex);
252 if (ret)
253 return ret;
254
255 total_obj_size = total_gtt_size = count = 0;
256 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
257 if (obj->stolen == NULL)
258 continue;
259
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200260 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100261
262 total_obj_size += obj->base.size;
263 total_gtt_size += i915_gem_obj_ggtt_size(obj);
264 count++;
265 }
266 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
267 if (obj->stolen == NULL)
268 continue;
269
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200270 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100271
272 total_obj_size += obj->base.size;
273 count++;
274 }
275 list_sort(NULL, &stolen, obj_rank_by_stolen);
276 seq_puts(m, "Stolen:\n");
277 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200278 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100279 seq_puts(m, " ");
280 describe_obj(m, obj);
281 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200282 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100283 }
284 mutex_unlock(&dev->struct_mutex);
285
286 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
287 count, total_obj_size, total_gtt_size);
288 return 0;
289}
290
Chris Wilson6299f992010-11-24 12:23:44 +0000291#define count_objects(list, member) do { \
292 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700293 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000294 ++count; \
295 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700296 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000297 ++mappable_count; \
298 } \
299 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400300} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000301
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100302struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000303 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100304 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000305 size_t total, unbound;
306 size_t global, shared;
307 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100308};
309
310static int per_file_stats(int id, void *ptr, void *data)
311{
312 struct drm_i915_gem_object *obj = ptr;
313 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000314 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100315
316 stats->count++;
317 stats->total += obj->base.size;
318
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000319 if (obj->base.name || obj->base.dma_buf)
320 stats->shared += obj->base.size;
321
Chris Wilson6313c202014-03-19 13:45:45 +0000322 if (USES_FULL_PPGTT(obj->base.dev)) {
323 list_for_each_entry(vma, &obj->vma_list, vma_link) {
324 struct i915_hw_ppgtt *ppgtt;
325
326 if (!drm_mm_node_allocated(&vma->node))
327 continue;
328
329 if (i915_is_ggtt(vma->vm)) {
330 stats->global += obj->base.size;
331 continue;
332 }
333
334 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200335 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000336 continue;
337
John Harrison41c52412014-11-24 18:49:43 +0000338 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000339 stats->active += obj->base.size;
340 else
341 stats->inactive += obj->base.size;
342
343 return 0;
344 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100345 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000346 if (i915_gem_obj_ggtt_bound(obj)) {
347 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000348 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000349 stats->active += obj->base.size;
350 else
351 stats->inactive += obj->base.size;
352 return 0;
353 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100354 }
355
Chris Wilson6313c202014-03-19 13:45:45 +0000356 if (!list_empty(&obj->global_list))
357 stats->unbound += obj->base.size;
358
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100359 return 0;
360}
361
Ben Widawskyca191b12013-07-31 17:00:14 -0700362#define count_vmas(list, member) do { \
363 list_for_each_entry(vma, list, member) { \
364 size += i915_gem_obj_ggtt_size(vma->obj); \
365 ++count; \
366 if (vma->obj->map_and_fenceable) { \
367 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
368 ++mappable_count; \
369 } \
370 } \
371} while (0)
372
373static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100374{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100375 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100376 struct drm_device *dev = node->minor->dev;
377 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200378 u32 count, mappable_count, purgeable_count;
379 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000380 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700381 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100382 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700383 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100384 int ret;
385
386 ret = mutex_lock_interruptible(&dev->struct_mutex);
387 if (ret)
388 return ret;
389
Chris Wilson6299f992010-11-24 12:23:44 +0000390 seq_printf(m, "%u objects, %zu bytes\n",
391 dev_priv->mm.object_count,
392 dev_priv->mm.object_memory);
393
394 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700395 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000396 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
397 count, mappable_count, size, mappable_size);
398
399 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700400 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000401 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
402 count, mappable_count, size, mappable_size);
403
404 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700405 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000406 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
407 count, mappable_count, size, mappable_size);
408
Chris Wilsonb7abb712012-08-20 11:33:30 +0200409 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700410 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200411 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200412 if (obj->madv == I915_MADV_DONTNEED)
413 purgeable_size += obj->base.size, ++purgeable_count;
414 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200415 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
416
Chris Wilson6299f992010-11-24 12:23:44 +0000417 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700418 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000419 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700420 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000421 ++count;
422 }
423 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700424 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000425 ++mappable_count;
426 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200427 if (obj->madv == I915_MADV_DONTNEED) {
428 purgeable_size += obj->base.size;
429 ++purgeable_count;
430 }
Chris Wilson6299f992010-11-24 12:23:44 +0000431 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200432 seq_printf(m, "%u purgeable objects, %zu bytes\n",
433 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000434 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
435 mappable_count, mappable_size);
436 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
437 count, size);
438
Ben Widawsky93d18792013-01-17 12:45:17 -0800439 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700440 dev_priv->gtt.base.total,
441 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100442
Damien Lespiau267f0c92013-06-24 22:59:48 +0100443 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100444 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
445 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900446 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100447
448 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000449 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100450 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100451 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100452 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900453 /*
454 * Although we have a valid reference on file->pid, that does
455 * not guarantee that the task_struct who called get_pid() is
456 * still alive (e.g. get_pid(current) => fork() => exit()).
457 * Therefore, we need to protect this ->comm access using RCU.
458 */
459 rcu_read_lock();
460 task = pid_task(file->pid, PIDTYPE_PID);
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000461 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n",
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900462 task ? task->comm : "<unknown>",
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100463 stats.count,
464 stats.total,
465 stats.active,
466 stats.inactive,
Chris Wilson6313c202014-03-19 13:45:45 +0000467 stats.global,
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000468 stats.shared,
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100469 stats.unbound);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900470 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100471 }
472
Chris Wilson73aa8082010-09-30 11:46:12 +0100473 mutex_unlock(&dev->struct_mutex);
474
475 return 0;
476}
477
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100478static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000479{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100480 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000481 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100482 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000483 struct drm_i915_private *dev_priv = dev->dev_private;
484 struct drm_i915_gem_object *obj;
485 size_t total_obj_size, total_gtt_size;
486 int count, ret;
487
488 ret = mutex_lock_interruptible(&dev->struct_mutex);
489 if (ret)
490 return ret;
491
492 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700493 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800494 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100495 continue;
496
Damien Lespiau267f0c92013-06-24 22:59:48 +0100497 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000498 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100499 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000500 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700501 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000502 count++;
503 }
504
505 mutex_unlock(&dev->struct_mutex);
506
507 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
508 count, total_obj_size, total_gtt_size);
509
510 return 0;
511}
512
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100513static int i915_gem_pageflip_info(struct seq_file *m, void *data)
514{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100515 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100516 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100517 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100518 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200519 int ret;
520
521 ret = mutex_lock_interruptible(&dev->struct_mutex);
522 if (ret)
523 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100524
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100525 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800526 const char pipe = pipe_name(crtc->pipe);
527 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100528 struct intel_unpin_work *work;
529
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200530 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100531 work = crtc->unpin_work;
532 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800533 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100534 pipe, plane);
535 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100536 u32 addr;
537
Chris Wilsone7d841c2012-12-03 11:36:30 +0000538 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800539 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100540 pipe, plane);
541 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800542 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100543 pipe, plane);
544 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100545 if (work->flip_queued_req) {
546 struct intel_engine_cs *ring =
547 i915_gem_request_get_ring(work->flip_queued_req);
548
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100549 seq_printf(m, "Flip queued on %s at seqno %u, next seqno %u [current breadcrumb %u], completed? %d\n",
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100550 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000551 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100552 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100553 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000554 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100555 } else
556 seq_printf(m, "Flip not associated with any ring\n");
557 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
558 work->flip_queued_vblank,
559 work->flip_ready_vblank,
560 drm_vblank_count(dev, crtc->pipe));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100561 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100562 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100563 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100564 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000565 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100566
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100567 if (INTEL_INFO(dev)->gen >= 4)
568 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
569 else
570 addr = I915_READ(DSPADDR(crtc->plane));
571 seq_printf(m, "Current scanout address 0x%08x\n", addr);
572
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100573 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100574 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
575 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100576 }
577 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200578 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100579 }
580
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200581 mutex_unlock(&dev->struct_mutex);
582
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100583 return 0;
584}
585
Ben Gamari20172632009-02-17 20:08:50 -0500586static int i915_gem_request_info(struct seq_file *m, void *data)
587{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100588 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500589 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300590 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100591 struct intel_engine_cs *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500592 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100593 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100594
595 ret = mutex_lock_interruptible(&dev->struct_mutex);
596 if (ret)
597 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500598
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100599 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100600 for_each_ring(ring, dev_priv, i) {
601 if (list_empty(&ring->request_list))
602 continue;
603
604 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100605 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100606 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100607 list) {
608 seq_printf(m, " %d @ %d\n",
609 gem_request->seqno,
610 (int) (jiffies - gem_request->emitted_jiffies));
611 }
612 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500613 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100614 mutex_unlock(&dev->struct_mutex);
615
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100616 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100617 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100618
Ben Gamari20172632009-02-17 20:08:50 -0500619 return 0;
620}
621
Chris Wilsonb2223492010-10-27 15:27:33 +0100622static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100623 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100624{
625 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200626 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100627 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100628 }
629}
630
Ben Gamari20172632009-02-17 20:08:50 -0500631static int i915_gem_seqno_info(struct seq_file *m, void *data)
632{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100633 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500634 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300635 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100636 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000637 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100638
639 ret = mutex_lock_interruptible(&dev->struct_mutex);
640 if (ret)
641 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200642 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500643
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100644 for_each_ring(ring, dev_priv, i)
645 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100646
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200647 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100648 mutex_unlock(&dev->struct_mutex);
649
Ben Gamari20172632009-02-17 20:08:50 -0500650 return 0;
651}
652
653
654static int i915_interrupt_info(struct seq_file *m, void *data)
655{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100656 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500657 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300658 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100659 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800660 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100661
662 ret = mutex_lock_interruptible(&dev->struct_mutex);
663 if (ret)
664 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200665 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500666
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300667 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300668 seq_printf(m, "Master Interrupt Control:\t%08x\n",
669 I915_READ(GEN8_MASTER_IRQ));
670
671 seq_printf(m, "Display IER:\t%08x\n",
672 I915_READ(VLV_IER));
673 seq_printf(m, "Display IIR:\t%08x\n",
674 I915_READ(VLV_IIR));
675 seq_printf(m, "Display IIR_RW:\t%08x\n",
676 I915_READ(VLV_IIR_RW));
677 seq_printf(m, "Display IMR:\t%08x\n",
678 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100679 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300680 seq_printf(m, "Pipe %c stat:\t%08x\n",
681 pipe_name(pipe),
682 I915_READ(PIPESTAT(pipe)));
683
684 seq_printf(m, "Port hotplug:\t%08x\n",
685 I915_READ(PORT_HOTPLUG_EN));
686 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
687 I915_READ(VLV_DPFLIPSTAT));
688 seq_printf(m, "DPINVGTT:\t%08x\n",
689 I915_READ(DPINVGTT));
690
691 for (i = 0; i < 4; i++) {
692 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
693 i, I915_READ(GEN8_GT_IMR(i)));
694 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
695 i, I915_READ(GEN8_GT_IIR(i)));
696 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
697 i, I915_READ(GEN8_GT_IER(i)));
698 }
699
700 seq_printf(m, "PCU interrupt mask:\t%08x\n",
701 I915_READ(GEN8_PCU_IMR));
702 seq_printf(m, "PCU interrupt identity:\t%08x\n",
703 I915_READ(GEN8_PCU_IIR));
704 seq_printf(m, "PCU interrupt enable:\t%08x\n",
705 I915_READ(GEN8_PCU_IER));
706 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700707 seq_printf(m, "Master Interrupt Control:\t%08x\n",
708 I915_READ(GEN8_MASTER_IRQ));
709
710 for (i = 0; i < 4; i++) {
711 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
712 i, I915_READ(GEN8_GT_IMR(i)));
713 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
714 i, I915_READ(GEN8_GT_IIR(i)));
715 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
716 i, I915_READ(GEN8_GT_IER(i)));
717 }
718
Damien Lespiau055e3932014-08-18 13:49:10 +0100719 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200720 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300721 POWER_DOMAIN_PIPE(pipe))) {
722 seq_printf(m, "Pipe %c power disabled\n",
723 pipe_name(pipe));
724 continue;
725 }
Ben Widawskya123f152013-11-02 21:07:10 -0700726 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000727 pipe_name(pipe),
728 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700729 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000730 pipe_name(pipe),
731 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700732 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000733 pipe_name(pipe),
734 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700735 }
736
737 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
738 I915_READ(GEN8_DE_PORT_IMR));
739 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
740 I915_READ(GEN8_DE_PORT_IIR));
741 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
742 I915_READ(GEN8_DE_PORT_IER));
743
744 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
745 I915_READ(GEN8_DE_MISC_IMR));
746 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
747 I915_READ(GEN8_DE_MISC_IIR));
748 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
749 I915_READ(GEN8_DE_MISC_IER));
750
751 seq_printf(m, "PCU interrupt mask:\t%08x\n",
752 I915_READ(GEN8_PCU_IMR));
753 seq_printf(m, "PCU interrupt identity:\t%08x\n",
754 I915_READ(GEN8_PCU_IIR));
755 seq_printf(m, "PCU interrupt enable:\t%08x\n",
756 I915_READ(GEN8_PCU_IER));
757 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700758 seq_printf(m, "Display IER:\t%08x\n",
759 I915_READ(VLV_IER));
760 seq_printf(m, "Display IIR:\t%08x\n",
761 I915_READ(VLV_IIR));
762 seq_printf(m, "Display IIR_RW:\t%08x\n",
763 I915_READ(VLV_IIR_RW));
764 seq_printf(m, "Display IMR:\t%08x\n",
765 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100766 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700767 seq_printf(m, "Pipe %c stat:\t%08x\n",
768 pipe_name(pipe),
769 I915_READ(PIPESTAT(pipe)));
770
771 seq_printf(m, "Master IER:\t%08x\n",
772 I915_READ(VLV_MASTER_IER));
773
774 seq_printf(m, "Render IER:\t%08x\n",
775 I915_READ(GTIER));
776 seq_printf(m, "Render IIR:\t%08x\n",
777 I915_READ(GTIIR));
778 seq_printf(m, "Render IMR:\t%08x\n",
779 I915_READ(GTIMR));
780
781 seq_printf(m, "PM IER:\t\t%08x\n",
782 I915_READ(GEN6_PMIER));
783 seq_printf(m, "PM IIR:\t\t%08x\n",
784 I915_READ(GEN6_PMIIR));
785 seq_printf(m, "PM IMR:\t\t%08x\n",
786 I915_READ(GEN6_PMIMR));
787
788 seq_printf(m, "Port hotplug:\t%08x\n",
789 I915_READ(PORT_HOTPLUG_EN));
790 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
791 I915_READ(VLV_DPFLIPSTAT));
792 seq_printf(m, "DPINVGTT:\t%08x\n",
793 I915_READ(DPINVGTT));
794
795 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800796 seq_printf(m, "Interrupt enable: %08x\n",
797 I915_READ(IER));
798 seq_printf(m, "Interrupt identity: %08x\n",
799 I915_READ(IIR));
800 seq_printf(m, "Interrupt mask: %08x\n",
801 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100802 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800803 seq_printf(m, "Pipe %c stat: %08x\n",
804 pipe_name(pipe),
805 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800806 } else {
807 seq_printf(m, "North Display Interrupt enable: %08x\n",
808 I915_READ(DEIER));
809 seq_printf(m, "North Display Interrupt identity: %08x\n",
810 I915_READ(DEIIR));
811 seq_printf(m, "North Display Interrupt mask: %08x\n",
812 I915_READ(DEIMR));
813 seq_printf(m, "South Display Interrupt enable: %08x\n",
814 I915_READ(SDEIER));
815 seq_printf(m, "South Display Interrupt identity: %08x\n",
816 I915_READ(SDEIIR));
817 seq_printf(m, "South Display Interrupt mask: %08x\n",
818 I915_READ(SDEIMR));
819 seq_printf(m, "Graphics Interrupt enable: %08x\n",
820 I915_READ(GTIER));
821 seq_printf(m, "Graphics Interrupt identity: %08x\n",
822 I915_READ(GTIIR));
823 seq_printf(m, "Graphics Interrupt mask: %08x\n",
824 I915_READ(GTIMR));
825 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100826 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700827 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100828 seq_printf(m,
829 "Graphics Interrupt mask (%s): %08x\n",
830 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000831 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100832 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000833 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200834 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100835 mutex_unlock(&dev->struct_mutex);
836
Ben Gamari20172632009-02-17 20:08:50 -0500837 return 0;
838}
839
Chris Wilsona6172a82009-02-11 14:26:38 +0000840static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
841{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100842 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000843 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300844 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100845 int i, ret;
846
847 ret = mutex_lock_interruptible(&dev->struct_mutex);
848 if (ret)
849 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000850
851 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
852 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
853 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000854 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000855
Chris Wilson6c085a72012-08-20 11:40:46 +0200856 seq_printf(m, "Fence %d, pin count = %d, object = ",
857 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100858 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100859 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100860 else
Chris Wilson05394f32010-11-08 19:18:58 +0000861 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100862 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000863 }
864
Chris Wilson05394f32010-11-08 19:18:58 +0000865 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000866 return 0;
867}
868
Ben Gamari20172632009-02-17 20:08:50 -0500869static int i915_hws_info(struct seq_file *m, void *data)
870{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100871 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500872 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300873 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100874 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100875 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100876 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500877
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000878 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100879 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500880 if (hws == NULL)
881 return 0;
882
883 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
884 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
885 i * 4,
886 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
887 }
888 return 0;
889}
890
Daniel Vetterd5442302012-04-27 15:17:40 +0200891static ssize_t
892i915_error_state_write(struct file *filp,
893 const char __user *ubuf,
894 size_t cnt,
895 loff_t *ppos)
896{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300897 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200898 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200899 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200900
901 DRM_DEBUG_DRIVER("Resetting error state\n");
902
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200903 ret = mutex_lock_interruptible(&dev->struct_mutex);
904 if (ret)
905 return ret;
906
Daniel Vetterd5442302012-04-27 15:17:40 +0200907 i915_destroy_error_state(dev);
908 mutex_unlock(&dev->struct_mutex);
909
910 return cnt;
911}
912
913static int i915_error_state_open(struct inode *inode, struct file *file)
914{
915 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200916 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200917
918 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
919 if (!error_priv)
920 return -ENOMEM;
921
922 error_priv->dev = dev;
923
Mika Kuoppala95d5bfb32013-06-06 15:18:40 +0300924 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200925
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300926 file->private_data = error_priv;
927
928 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200929}
930
931static int i915_error_state_release(struct inode *inode, struct file *file)
932{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300933 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200934
Mika Kuoppala95d5bfb32013-06-06 15:18:40 +0300935 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200936 kfree(error_priv);
937
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300938 return 0;
939}
940
941static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
942 size_t count, loff_t *pos)
943{
944 struct i915_error_state_file_priv *error_priv = file->private_data;
945 struct drm_i915_error_state_buf error_str;
946 loff_t tmp_pos = 0;
947 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300948 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300949
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100950 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300951 if (ret)
952 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300953
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300954 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300955 if (ret)
956 goto out;
957
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300958 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
959 error_str.buf,
960 error_str.bytes);
961
962 if (ret_count < 0)
963 ret = ret_count;
964 else
965 *pos = error_str.start + ret_count;
966out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300967 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300968 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +0200969}
970
971static const struct file_operations i915_error_state_fops = {
972 .owner = THIS_MODULE,
973 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300974 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200975 .write = i915_error_state_write,
976 .llseek = default_llseek,
977 .release = i915_error_state_release,
978};
979
Kees Cook647416f2013-03-10 14:10:06 -0700980static int
981i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200982{
Kees Cook647416f2013-03-10 14:10:06 -0700983 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300984 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +0200985 int ret;
986
987 ret = mutex_lock_interruptible(&dev->struct_mutex);
988 if (ret)
989 return ret;
990
Kees Cook647416f2013-03-10 14:10:06 -0700991 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +0200992 mutex_unlock(&dev->struct_mutex);
993
Kees Cook647416f2013-03-10 14:10:06 -0700994 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +0200995}
996
Kees Cook647416f2013-03-10 14:10:06 -0700997static int
998i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200999{
Kees Cook647416f2013-03-10 14:10:06 -07001000 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001001 int ret;
1002
Mika Kuoppala40633212012-12-04 15:12:00 +02001003 ret = mutex_lock_interruptible(&dev->struct_mutex);
1004 if (ret)
1005 return ret;
1006
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001007 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001008 mutex_unlock(&dev->struct_mutex);
1009
Kees Cook647416f2013-03-10 14:10:06 -07001010 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001011}
1012
Kees Cook647416f2013-03-10 14:10:06 -07001013DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1014 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001015 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001016
Deepak Sadb4bd12014-03-31 11:30:02 +05301017static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001018{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001019 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001020 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001021 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001022 int ret = 0;
1023
1024 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001025
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001026 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1027
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001028 if (IS_GEN5(dev)) {
1029 u16 rgvswctl = I915_READ16(MEMSWCTL);
1030 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1031
1032 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1033 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1034 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1035 MEMSTAT_VID_SHIFT);
1036 seq_printf(m, "Current P-state: %d\n",
1037 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001038 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
1039 IS_BROADWELL(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001040 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1041 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1042 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001043 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001044 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001045 u32 rpupei, rpcurup, rpprevup;
1046 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001047 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001048 int max_freq;
1049
1050 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001051 ret = mutex_lock_interruptible(&dev->struct_mutex);
1052 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001053 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001054
Deepak Sc8d9a592013-11-23 14:55:42 +05301055 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001056
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001057 reqf = I915_READ(GEN6_RPNSWREQ);
1058 reqf &= ~GEN6_TURBO_DISABLE;
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001059 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001060 reqf >>= 24;
1061 else
1062 reqf >>= 25;
1063 reqf *= GT_FREQUENCY_MULTIPLIER;
1064
Chris Wilson0d8f9492014-03-27 09:06:14 +00001065 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1066 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1067 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1068
Jesse Barnesccab5c82011-01-18 15:49:25 -08001069 rpstat = I915_READ(GEN6_RPSTAT1);
1070 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1071 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1072 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1073 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1074 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1075 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001076 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001077 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1078 else
1079 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
1080 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001081
Deepak Sc8d9a592013-11-23 14:55:42 +05301082 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001083 mutex_unlock(&dev->struct_mutex);
1084
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001085 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1086 pm_ier = I915_READ(GEN6_PMIER);
1087 pm_imr = I915_READ(GEN6_PMIMR);
1088 pm_isr = I915_READ(GEN6_PMISR);
1089 pm_iir = I915_READ(GEN6_PMIIR);
1090 pm_mask = I915_READ(GEN6_PMINTRMSK);
1091 } else {
1092 pm_ier = I915_READ(GEN8_GT_IER(2));
1093 pm_imr = I915_READ(GEN8_GT_IMR(2));
1094 pm_isr = I915_READ(GEN8_GT_ISR(2));
1095 pm_iir = I915_READ(GEN8_GT_IIR(2));
1096 pm_mask = I915_READ(GEN6_PMINTRMSK);
1097 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001098 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 -03001099 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001100 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001101 seq_printf(m, "Render p-state ratio: %d\n",
1102 (gt_perf_status & 0xff00) >> 8);
1103 seq_printf(m, "Render p-state VID: %d\n",
1104 gt_perf_status & 0xff);
1105 seq_printf(m, "Render p-state limit: %d\n",
1106 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001107 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1108 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1109 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1110 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001111 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001112 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001113 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1114 GEN6_CURICONT_MASK);
1115 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1116 GEN6_CURBSYTAVG_MASK);
1117 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1118 GEN6_CURBSYTAVG_MASK);
1119 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1120 GEN6_CURIAVG_MASK);
1121 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1122 GEN6_CURBSYTAVG_MASK);
1123 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1124 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001125
1126 max_freq = (rp_state_cap & 0xff0000) >> 16;
1127 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001128 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001129
1130 max_freq = (rp_state_cap & 0xff00) >> 8;
1131 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001132 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001133
1134 max_freq = rp_state_cap & 0xff;
1135 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001136 max_freq * GT_FREQUENCY_MULTIPLIER);
Ben Widawsky31c77382013-04-05 14:29:22 -07001137
1138 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ben Widawskyb39fb292014-03-19 18:31:11 -07001139 dev_priv->rps.max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001140 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001141 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001142
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001143 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001144 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001145 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1146 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1147
Jesse Barnes0a073b82013-04-17 15:54:58 -07001148 seq_printf(m, "max GPU freq: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301149 vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001150
Jesse Barnes0a073b82013-04-17 15:54:58 -07001151 seq_printf(m, "min GPU freq: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301152 vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001153
1154 seq_printf(m, "efficient (RPe) frequency: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301155 vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001156
1157 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001158 vlv_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001159 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001160 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001161 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001162 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001163
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001164out:
1165 intel_runtime_pm_put(dev_priv);
1166 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001167}
1168
Ben Widawsky4d855292011-12-12 19:34:16 -08001169static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001170{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001171 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001172 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001173 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001174 u32 rgvmodectl, rstdbyctl;
1175 u16 crstandvid;
1176 int ret;
1177
1178 ret = mutex_lock_interruptible(&dev->struct_mutex);
1179 if (ret)
1180 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001181 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001182
1183 rgvmodectl = I915_READ(MEMMODECTL);
1184 rstdbyctl = I915_READ(RSTDBYCTL);
1185 crstandvid = I915_READ16(CRSTANDVID);
1186
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001187 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001188 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001189
1190 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1191 "yes" : "no");
1192 seq_printf(m, "Boost freq: %d\n",
1193 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1194 MEMMODE_BOOST_FREQ_SHIFT);
1195 seq_printf(m, "HW control enabled: %s\n",
1196 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1197 seq_printf(m, "SW control enabled: %s\n",
1198 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1199 seq_printf(m, "Gated voltage change: %s\n",
1200 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1201 seq_printf(m, "Starting frequency: P%d\n",
1202 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001203 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001204 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001205 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1206 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1207 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1208 seq_printf(m, "Render standby enabled: %s\n",
1209 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001210 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001211 switch (rstdbyctl & RSX_STATUS_MASK) {
1212 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001213 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001214 break;
1215 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001216 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001217 break;
1218 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001219 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001220 break;
1221 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001222 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001223 break;
1224 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001225 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001226 break;
1227 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001228 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001229 break;
1230 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001231 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001232 break;
1233 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001234
1235 return 0;
1236}
1237
Deepak S669ab5a2014-01-10 15:18:26 +05301238static int vlv_drpc_info(struct seq_file *m)
1239{
1240
Damien Lespiau9f25d002014-05-13 15:30:28 +01001241 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301242 struct drm_device *dev = node->minor->dev;
1243 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001244 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301245 unsigned fw_rendercount = 0, fw_mediacount = 0;
1246
Imre Deakd46c0512014-04-14 20:24:27 +03001247 intel_runtime_pm_get(dev_priv);
1248
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001249 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301250 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1251 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1252
Imre Deakd46c0512014-04-14 20:24:27 +03001253 intel_runtime_pm_put(dev_priv);
1254
Deepak S669ab5a2014-01-10 15:18:26 +05301255 seq_printf(m, "Video Turbo Mode: %s\n",
1256 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1257 seq_printf(m, "Turbo enabled: %s\n",
1258 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1259 seq_printf(m, "HW control enabled: %s\n",
1260 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1261 seq_printf(m, "SW control enabled: %s\n",
1262 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1263 GEN6_RP_MEDIA_SW_MODE));
1264 seq_printf(m, "RC6 Enabled: %s\n",
1265 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1266 GEN6_RC_CTL_EI_MODE(1))));
1267 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001268 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301269 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001270 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301271
Imre Deak9cc19be2014-04-14 20:24:24 +03001272 seq_printf(m, "Render RC6 residency since boot: %u\n",
1273 I915_READ(VLV_GT_RENDER_RC6));
1274 seq_printf(m, "Media RC6 residency since boot: %u\n",
1275 I915_READ(VLV_GT_MEDIA_RC6));
1276
Deepak S669ab5a2014-01-10 15:18:26 +05301277 spin_lock_irq(&dev_priv->uncore.lock);
1278 fw_rendercount = dev_priv->uncore.fw_rendercount;
1279 fw_mediacount = dev_priv->uncore.fw_mediacount;
1280 spin_unlock_irq(&dev_priv->uncore.lock);
1281
1282 seq_printf(m, "Forcewake Render Count = %u\n", fw_rendercount);
1283 seq_printf(m, "Forcewake Media Count = %u\n", fw_mediacount);
1284
1285
1286 return 0;
1287}
1288
1289
Ben Widawsky4d855292011-12-12 19:34:16 -08001290static int gen6_drpc_info(struct seq_file *m)
1291{
1292
Damien Lespiau9f25d002014-05-13 15:30:28 +01001293 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001294 struct drm_device *dev = node->minor->dev;
1295 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001296 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001297 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001298 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001299
1300 ret = mutex_lock_interruptible(&dev->struct_mutex);
1301 if (ret)
1302 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001303 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001304
Chris Wilson907b28c2013-07-19 20:36:52 +01001305 spin_lock_irq(&dev_priv->uncore.lock);
1306 forcewake_count = dev_priv->uncore.forcewake_count;
1307 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001308
1309 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001310 seq_puts(m, "RC information inaccurate because somebody "
1311 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001312 } else {
1313 /* NB: we cannot use forcewake, else we read the wrong values */
1314 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1315 udelay(10);
1316 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1317 }
1318
1319 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001320 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001321
1322 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1323 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1324 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001325 mutex_lock(&dev_priv->rps.hw_lock);
1326 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1327 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001328
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001329 intel_runtime_pm_put(dev_priv);
1330
Ben Widawsky4d855292011-12-12 19:34:16 -08001331 seq_printf(m, "Video Turbo Mode: %s\n",
1332 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1333 seq_printf(m, "HW control enabled: %s\n",
1334 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1335 seq_printf(m, "SW control enabled: %s\n",
1336 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1337 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001338 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001339 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1340 seq_printf(m, "RC6 Enabled: %s\n",
1341 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1342 seq_printf(m, "Deep RC6 Enabled: %s\n",
1343 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1344 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1345 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001346 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001347 switch (gt_core_status & GEN6_RCn_MASK) {
1348 case GEN6_RC0:
1349 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001350 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001351 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001352 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001353 break;
1354 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001355 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001356 break;
1357 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001358 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001359 break;
1360 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001361 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001362 break;
1363 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001364 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001365 break;
1366 }
1367
1368 seq_printf(m, "Core Power Down: %s\n",
1369 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001370
1371 /* Not exactly sure what this is */
1372 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1373 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1374 seq_printf(m, "RC6 residency since boot: %u\n",
1375 I915_READ(GEN6_GT_GFX_RC6));
1376 seq_printf(m, "RC6+ residency since boot: %u\n",
1377 I915_READ(GEN6_GT_GFX_RC6p));
1378 seq_printf(m, "RC6++ residency since boot: %u\n",
1379 I915_READ(GEN6_GT_GFX_RC6pp));
1380
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001381 seq_printf(m, "RC6 voltage: %dmV\n",
1382 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1383 seq_printf(m, "RC6+ voltage: %dmV\n",
1384 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1385 seq_printf(m, "RC6++ voltage: %dmV\n",
1386 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001387 return 0;
1388}
1389
1390static int i915_drpc_info(struct seq_file *m, void *unused)
1391{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001392 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001393 struct drm_device *dev = node->minor->dev;
1394
Deepak S669ab5a2014-01-10 15:18:26 +05301395 if (IS_VALLEYVIEW(dev))
1396 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001397 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001398 return gen6_drpc_info(m);
1399 else
1400 return ironlake_drpc_info(m);
1401}
1402
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001403static int i915_fbc_status(struct seq_file *m, void *unused)
1404{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001405 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001406 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001407 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001408
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001409 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001410 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001411 return 0;
1412 }
1413
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001414 intel_runtime_pm_get(dev_priv);
1415
Adam Jacksonee5382a2010-04-23 11:17:39 -04001416 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001417 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001418 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001419 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001420 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001421 case FBC_OK:
1422 seq_puts(m, "FBC actived, but currently disabled in hardware");
1423 break;
1424 case FBC_UNSUPPORTED:
1425 seq_puts(m, "unsupported by this chipset");
1426 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001427 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001428 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001429 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001430 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001431 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001432 break;
1433 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001434 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001435 break;
1436 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001437 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001438 break;
1439 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001440 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001441 break;
1442 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001443 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001444 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001445 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001446 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001447 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001448 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001449 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001450 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001451 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001452 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001453 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001454 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001455 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001456 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001457 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001458 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001459
1460 intel_runtime_pm_put(dev_priv);
1461
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001462 return 0;
1463}
1464
Rodrigo Vivida46f932014-08-01 02:04:45 -07001465static int i915_fbc_fc_get(void *data, u64 *val)
1466{
1467 struct drm_device *dev = data;
1468 struct drm_i915_private *dev_priv = dev->dev_private;
1469
1470 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1471 return -ENODEV;
1472
1473 drm_modeset_lock_all(dev);
1474 *val = dev_priv->fbc.false_color;
1475 drm_modeset_unlock_all(dev);
1476
1477 return 0;
1478}
1479
1480static int i915_fbc_fc_set(void *data, u64 val)
1481{
1482 struct drm_device *dev = data;
1483 struct drm_i915_private *dev_priv = dev->dev_private;
1484 u32 reg;
1485
1486 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1487 return -ENODEV;
1488
1489 drm_modeset_lock_all(dev);
1490
1491 reg = I915_READ(ILK_DPFC_CONTROL);
1492 dev_priv->fbc.false_color = val;
1493
1494 I915_WRITE(ILK_DPFC_CONTROL, val ?
1495 (reg | FBC_CTL_FALSE_COLOR) :
1496 (reg & ~FBC_CTL_FALSE_COLOR));
1497
1498 drm_modeset_unlock_all(dev);
1499 return 0;
1500}
1501
1502DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1503 i915_fbc_fc_get, i915_fbc_fc_set,
1504 "%llu\n");
1505
Paulo Zanoni92d44622013-05-31 16:33:24 -03001506static int i915_ips_status(struct seq_file *m, void *unused)
1507{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001508 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001509 struct drm_device *dev = node->minor->dev;
1510 struct drm_i915_private *dev_priv = dev->dev_private;
1511
Damien Lespiauf5adf942013-06-24 18:29:34 +01001512 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001513 seq_puts(m, "not supported\n");
1514 return 0;
1515 }
1516
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001517 intel_runtime_pm_get(dev_priv);
1518
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001519 seq_printf(m, "Enabled by kernel parameter: %s\n",
1520 yesno(i915.enable_ips));
1521
1522 if (INTEL_INFO(dev)->gen >= 8) {
1523 seq_puts(m, "Currently: unknown\n");
1524 } else {
1525 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1526 seq_puts(m, "Currently: enabled\n");
1527 else
1528 seq_puts(m, "Currently: disabled\n");
1529 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001530
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001531 intel_runtime_pm_put(dev_priv);
1532
Paulo Zanoni92d44622013-05-31 16:33:24 -03001533 return 0;
1534}
1535
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001536static int i915_sr_status(struct seq_file *m, void *unused)
1537{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001538 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001539 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001540 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001541 bool sr_enabled = false;
1542
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001543 intel_runtime_pm_get(dev_priv);
1544
Yuanhan Liu13982612010-12-15 15:42:31 +08001545 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001546 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001547 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001548 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1549 else if (IS_I915GM(dev))
1550 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1551 else if (IS_PINEVIEW(dev))
1552 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1553
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001554 intel_runtime_pm_put(dev_priv);
1555
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001556 seq_printf(m, "self-refresh: %s\n",
1557 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001558
1559 return 0;
1560}
1561
Jesse Barnes7648fa92010-05-20 14:28:11 -07001562static int i915_emon_status(struct seq_file *m, void *unused)
1563{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001564 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001565 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001566 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001567 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001568 int ret;
1569
Chris Wilson582be6b2012-04-30 19:35:02 +01001570 if (!IS_GEN5(dev))
1571 return -ENODEV;
1572
Chris Wilsonde227ef2010-07-03 07:58:38 +01001573 ret = mutex_lock_interruptible(&dev->struct_mutex);
1574 if (ret)
1575 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001576
1577 temp = i915_mch_val(dev_priv);
1578 chipset = i915_chipset_val(dev_priv);
1579 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001580 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001581
1582 seq_printf(m, "GMCH temp: %ld\n", temp);
1583 seq_printf(m, "Chipset power: %ld\n", chipset);
1584 seq_printf(m, "GFX power: %ld\n", gfx);
1585 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1586
1587 return 0;
1588}
1589
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001590static int i915_ring_freq_table(struct seq_file *m, void *unused)
1591{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001592 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001593 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001594 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001595 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001596 int gpu_freq, ia_freq;
1597
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001598 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001599 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001600 return 0;
1601 }
1602
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001603 intel_runtime_pm_get(dev_priv);
1604
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001605 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1606
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001607 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001608 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001609 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001610
Damien Lespiau267f0c92013-06-24 22:59:48 +01001611 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001612
Ben Widawskyb39fb292014-03-19 18:31:11 -07001613 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1614 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001615 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001616 ia_freq = gpu_freq;
1617 sandybridge_pcode_read(dev_priv,
1618 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1619 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001620 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1621 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1622 ((ia_freq >> 0) & 0xff) * 100,
1623 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001624 }
1625
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001626 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001627
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001628out:
1629 intel_runtime_pm_put(dev_priv);
1630 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001631}
1632
Chris Wilson44834a62010-08-19 16:09:23 +01001633static int i915_opregion(struct seq_file *m, void *unused)
1634{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001635 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001636 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001637 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001638 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001639 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001640 int ret;
1641
Daniel Vetter0d38f002012-04-21 22:49:10 +02001642 if (data == NULL)
1643 return -ENOMEM;
1644
Chris Wilson44834a62010-08-19 16:09:23 +01001645 ret = mutex_lock_interruptible(&dev->struct_mutex);
1646 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001647 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001648
Daniel Vetter0d38f002012-04-21 22:49:10 +02001649 if (opregion->header) {
1650 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1651 seq_write(m, data, OPREGION_SIZE);
1652 }
Chris Wilson44834a62010-08-19 16:09:23 +01001653
1654 mutex_unlock(&dev->struct_mutex);
1655
Daniel Vetter0d38f002012-04-21 22:49:10 +02001656out:
1657 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001658 return 0;
1659}
1660
Chris Wilson37811fc2010-08-25 22:45:57 +01001661static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1662{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001663 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001664 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001665 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001666 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001667
Daniel Vetter4520f532013-10-09 09:18:51 +02001668#ifdef CONFIG_DRM_I915_FBDEV
1669 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001670
1671 ifbdev = dev_priv->fbdev;
1672 fb = to_intel_framebuffer(ifbdev->helper.fb);
1673
Daniel Vetter623f9782012-12-11 16:21:38 +01001674 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001675 fb->base.width,
1676 fb->base.height,
1677 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001678 fb->base.bits_per_pixel,
1679 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001680 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001681 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001682#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001683
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001684 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001685 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001686 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001687 continue;
1688
Daniel Vetter623f9782012-12-11 16:21:38 +01001689 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001690 fb->base.width,
1691 fb->base.height,
1692 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001693 fb->base.bits_per_pixel,
1694 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001695 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001696 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001697 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001698 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001699
1700 return 0;
1701}
1702
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001703static void describe_ctx_ringbuf(struct seq_file *m,
1704 struct intel_ringbuffer *ringbuf)
1705{
1706 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1707 ringbuf->space, ringbuf->head, ringbuf->tail,
1708 ringbuf->last_retired_head);
1709}
1710
Ben Widawskye76d3632011-03-19 18:14:29 -07001711static int i915_context_status(struct seq_file *m, void *unused)
1712{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001713 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001714 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001715 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001716 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001717 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001718 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001719
Daniel Vetterf3d28872014-05-29 23:23:08 +02001720 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001721 if (ret)
1722 return ret;
1723
Daniel Vetter3e373942012-11-02 19:55:04 +01001724 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001725 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001726 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001727 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001728 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001729
Daniel Vetter3e373942012-11-02 19:55:04 +01001730 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001731 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001732 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001733 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001734 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001735
Ben Widawskya33afea2013-09-17 21:12:45 -07001736 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001737 if (!i915.enable_execlists &&
1738 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001739 continue;
1740
Ben Widawskya33afea2013-09-17 21:12:45 -07001741 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001742 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001743 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001744 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001745 seq_printf(m, "(default context %s) ",
1746 ring->name);
1747 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001748
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001749 if (i915.enable_execlists) {
1750 seq_putc(m, '\n');
1751 for_each_ring(ring, dev_priv, i) {
1752 struct drm_i915_gem_object *ctx_obj =
1753 ctx->engine[i].state;
1754 struct intel_ringbuffer *ringbuf =
1755 ctx->engine[i].ringbuf;
1756
1757 seq_printf(m, "%s: ", ring->name);
1758 if (ctx_obj)
1759 describe_obj(m, ctx_obj);
1760 if (ringbuf)
1761 describe_ctx_ringbuf(m, ringbuf);
1762 seq_putc(m, '\n');
1763 }
1764 } else {
1765 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1766 }
1767
Ben Widawskya33afea2013-09-17 21:12:45 -07001768 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001769 }
1770
Daniel Vetterf3d28872014-05-29 23:23:08 +02001771 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001772
1773 return 0;
1774}
1775
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001776static void i915_dump_lrc_obj(struct seq_file *m,
1777 struct intel_engine_cs *ring,
1778 struct drm_i915_gem_object *ctx_obj)
1779{
1780 struct page *page;
1781 uint32_t *reg_state;
1782 int j;
1783 unsigned long ggtt_offset = 0;
1784
1785 if (ctx_obj == NULL) {
1786 seq_printf(m, "Context on %s with no gem object\n",
1787 ring->name);
1788 return;
1789 }
1790
1791 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1792 intel_execlists_ctx_id(ctx_obj));
1793
1794 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1795 seq_puts(m, "\tNot bound in GGTT\n");
1796 else
1797 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1798
1799 if (i915_gem_object_get_pages(ctx_obj)) {
1800 seq_puts(m, "\tFailed to get pages for context object\n");
1801 return;
1802 }
1803
1804 page = i915_gem_object_get_page(ctx_obj, 1);
1805 if (!WARN_ON(page == NULL)) {
1806 reg_state = kmap_atomic(page);
1807
1808 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
1809 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1810 ggtt_offset + 4096 + (j * 4),
1811 reg_state[j], reg_state[j + 1],
1812 reg_state[j + 2], reg_state[j + 3]);
1813 }
1814 kunmap_atomic(reg_state);
1815 }
1816
1817 seq_putc(m, '\n');
1818}
1819
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01001820static int i915_dump_lrc(struct seq_file *m, void *unused)
1821{
1822 struct drm_info_node *node = (struct drm_info_node *) m->private;
1823 struct drm_device *dev = node->minor->dev;
1824 struct drm_i915_private *dev_priv = dev->dev_private;
1825 struct intel_engine_cs *ring;
1826 struct intel_context *ctx;
1827 int ret, i;
1828
1829 if (!i915.enable_execlists) {
1830 seq_printf(m, "Logical Ring Contexts are disabled\n");
1831 return 0;
1832 }
1833
1834 ret = mutex_lock_interruptible(&dev->struct_mutex);
1835 if (ret)
1836 return ret;
1837
1838 list_for_each_entry(ctx, &dev_priv->context_list, link) {
1839 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001840 if (ring->default_context != ctx)
1841 i915_dump_lrc_obj(m, ring,
1842 ctx->engine[i].state);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01001843 }
1844 }
1845
1846 mutex_unlock(&dev->struct_mutex);
1847
1848 return 0;
1849}
1850
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001851static int i915_execlists(struct seq_file *m, void *data)
1852{
1853 struct drm_info_node *node = (struct drm_info_node *)m->private;
1854 struct drm_device *dev = node->minor->dev;
1855 struct drm_i915_private *dev_priv = dev->dev_private;
1856 struct intel_engine_cs *ring;
1857 u32 status_pointer;
1858 u8 read_pointer;
1859 u8 write_pointer;
1860 u32 status;
1861 u32 ctx_id;
1862 struct list_head *cursor;
1863 int ring_id, i;
1864 int ret;
1865
1866 if (!i915.enable_execlists) {
1867 seq_puts(m, "Logical Ring Contexts are disabled\n");
1868 return 0;
1869 }
1870
1871 ret = mutex_lock_interruptible(&dev->struct_mutex);
1872 if (ret)
1873 return ret;
1874
Michel Thierryfc0412e2014-10-16 16:13:38 +01001875 intel_runtime_pm_get(dev_priv);
1876
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001877 for_each_ring(ring, dev_priv, ring_id) {
1878 struct intel_ctx_submit_request *head_req = NULL;
1879 int count = 0;
1880 unsigned long flags;
1881
1882 seq_printf(m, "%s\n", ring->name);
1883
1884 status = I915_READ(RING_EXECLIST_STATUS(ring));
1885 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
1886 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
1887 status, ctx_id);
1888
1889 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
1890 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
1891
1892 read_pointer = ring->next_context_status_buffer;
1893 write_pointer = status_pointer & 0x07;
1894 if (read_pointer > write_pointer)
1895 write_pointer += 6;
1896 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
1897 read_pointer, write_pointer);
1898
1899 for (i = 0; i < 6; i++) {
1900 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
1901 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
1902
1903 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
1904 i, status, ctx_id);
1905 }
1906
1907 spin_lock_irqsave(&ring->execlist_lock, flags);
1908 list_for_each(cursor, &ring->execlist_queue)
1909 count++;
1910 head_req = list_first_entry_or_null(&ring->execlist_queue,
1911 struct intel_ctx_submit_request, execlist_link);
1912 spin_unlock_irqrestore(&ring->execlist_lock, flags);
1913
1914 seq_printf(m, "\t%d requests in queue\n", count);
1915 if (head_req) {
1916 struct drm_i915_gem_object *ctx_obj;
1917
1918 ctx_obj = head_req->ctx->engine[ring_id].state;
1919 seq_printf(m, "\tHead request id: %u\n",
1920 intel_execlists_ctx_id(ctx_obj));
1921 seq_printf(m, "\tHead request tail: %u\n",
1922 head_req->tail);
1923 }
1924
1925 seq_putc(m, '\n');
1926 }
1927
Michel Thierryfc0412e2014-10-16 16:13:38 +01001928 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001929 mutex_unlock(&dev->struct_mutex);
1930
1931 return 0;
1932}
1933
Ben Widawsky6d794d42011-04-25 11:25:56 -07001934static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1935{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001936 struct drm_info_node *node = m->private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001937 struct drm_device *dev = node->minor->dev;
1938 struct drm_i915_private *dev_priv = dev->dev_private;
Deepak S43709ba2013-11-23 14:55:44 +05301939 unsigned forcewake_count = 0, fw_rendercount = 0, fw_mediacount = 0;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001940
Chris Wilson907b28c2013-07-19 20:36:52 +01001941 spin_lock_irq(&dev_priv->uncore.lock);
Deepak S43709ba2013-11-23 14:55:44 +05301942 if (IS_VALLEYVIEW(dev)) {
1943 fw_rendercount = dev_priv->uncore.fw_rendercount;
1944 fw_mediacount = dev_priv->uncore.fw_mediacount;
1945 } else
1946 forcewake_count = dev_priv->uncore.forcewake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001947 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001948
Deepak S43709ba2013-11-23 14:55:44 +05301949 if (IS_VALLEYVIEW(dev)) {
1950 seq_printf(m, "fw_rendercount = %u\n", fw_rendercount);
1951 seq_printf(m, "fw_mediacount = %u\n", fw_mediacount);
1952 } else
1953 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001954
1955 return 0;
1956}
1957
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001958static const char *swizzle_string(unsigned swizzle)
1959{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001960 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001961 case I915_BIT_6_SWIZZLE_NONE:
1962 return "none";
1963 case I915_BIT_6_SWIZZLE_9:
1964 return "bit9";
1965 case I915_BIT_6_SWIZZLE_9_10:
1966 return "bit9/bit10";
1967 case I915_BIT_6_SWIZZLE_9_11:
1968 return "bit9/bit11";
1969 case I915_BIT_6_SWIZZLE_9_10_11:
1970 return "bit9/bit10/bit11";
1971 case I915_BIT_6_SWIZZLE_9_17:
1972 return "bit9/bit17";
1973 case I915_BIT_6_SWIZZLE_9_10_17:
1974 return "bit9/bit10/bit17";
1975 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001976 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001977 }
1978
1979 return "bug";
1980}
1981
1982static int i915_swizzle_info(struct seq_file *m, void *data)
1983{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001984 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001985 struct drm_device *dev = node->minor->dev;
1986 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001987 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001988
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001989 ret = mutex_lock_interruptible(&dev->struct_mutex);
1990 if (ret)
1991 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001992 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001993
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001994 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1995 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1996 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1997 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1998
1999 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2000 seq_printf(m, "DDC = 0x%08x\n",
2001 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002002 seq_printf(m, "DDC2 = 0x%08x\n",
2003 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002004 seq_printf(m, "C0DRB3 = 0x%04x\n",
2005 I915_READ16(C0DRB3));
2006 seq_printf(m, "C1DRB3 = 0x%04x\n",
2007 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002008 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002009 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2010 I915_READ(MAD_DIMM_C0));
2011 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2012 I915_READ(MAD_DIMM_C1));
2013 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2014 I915_READ(MAD_DIMM_C2));
2015 seq_printf(m, "TILECTL = 0x%08x\n",
2016 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002017 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002018 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2019 I915_READ(GAMTARBMODE));
2020 else
2021 seq_printf(m, "ARB_MODE = 0x%08x\n",
2022 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002023 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2024 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002025 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002026
2027 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2028 seq_puts(m, "L-shaped memory detected\n");
2029
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002030 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002031 mutex_unlock(&dev->struct_mutex);
2032
2033 return 0;
2034}
2035
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002036static int per_file_ctx(int id, void *ptr, void *data)
2037{
Oscar Mateo273497e2014-05-22 14:13:37 +01002038 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002039 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002040 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2041
2042 if (!ppgtt) {
2043 seq_printf(m, " no ppgtt for context %d\n",
2044 ctx->user_handle);
2045 return 0;
2046 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002047
Oscar Mateof83d6512014-05-22 14:13:38 +01002048 if (i915_gem_context_is_default(ctx))
2049 seq_puts(m, " default context:\n");
2050 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002051 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002052 ppgtt->debug_dump(ppgtt, m);
2053
2054 return 0;
2055}
2056
Ben Widawsky77df6772013-11-02 21:07:30 -07002057static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002058{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002059 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002060 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002061 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2062 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002063
Ben Widawsky77df6772013-11-02 21:07:30 -07002064 if (!ppgtt)
2065 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002066
Ben Widawsky77df6772013-11-02 21:07:30 -07002067 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08002068 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07002069 for_each_ring(ring, dev_priv, unused) {
2070 seq_printf(m, "%s\n", ring->name);
2071 for (i = 0; i < 4; i++) {
2072 u32 offset = 0x270 + i * 8;
2073 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2074 pdp <<= 32;
2075 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002076 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002077 }
2078 }
2079}
2080
2081static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2082{
2083 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002084 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002085 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002086 int i;
2087
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002088 if (INTEL_INFO(dev)->gen == 6)
2089 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2090
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002091 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002092 seq_printf(m, "%s\n", ring->name);
2093 if (INTEL_INFO(dev)->gen == 7)
2094 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2095 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2096 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2097 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2098 }
2099 if (dev_priv->mm.aliasing_ppgtt) {
2100 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2101
Damien Lespiau267f0c92013-06-24 22:59:48 +01002102 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002103 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002104
Ben Widawsky87d60b62013-12-06 14:11:29 -08002105 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002106 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002107
2108 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2109 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002110
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002111 seq_printf(m, "proc: %s\n",
2112 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002113 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002114 }
2115 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002116}
2117
2118static int i915_ppgtt_info(struct seq_file *m, void *data)
2119{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002120 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002121 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002122 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002123
2124 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2125 if (ret)
2126 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002127 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002128
2129 if (INTEL_INFO(dev)->gen >= 8)
2130 gen8_ppgtt_info(m, dev);
2131 else if (INTEL_INFO(dev)->gen >= 6)
2132 gen6_ppgtt_info(m, dev);
2133
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002134 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002135 mutex_unlock(&dev->struct_mutex);
2136
2137 return 0;
2138}
2139
Ben Widawsky63573eb2013-07-04 11:02:07 -07002140static int i915_llc(struct seq_file *m, void *data)
2141{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002142 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002143 struct drm_device *dev = node->minor->dev;
2144 struct drm_i915_private *dev_priv = dev->dev_private;
2145
2146 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2147 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2148 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2149
2150 return 0;
2151}
2152
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002153static int i915_edp_psr_status(struct seq_file *m, void *data)
2154{
2155 struct drm_info_node *node = m->private;
2156 struct drm_device *dev = node->minor->dev;
2157 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002158 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002159 u32 stat[3];
2160 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002161 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002162
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002163 intel_runtime_pm_get(dev_priv);
2164
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002165 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002166 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2167 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002168 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002169 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002170 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2171 dev_priv->psr.busy_frontbuffer_bits);
2172 seq_printf(m, "Re-enable work scheduled: %s\n",
2173 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002174
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002175 if (HAS_PSR(dev)) {
2176 if (HAS_DDI(dev))
2177 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2178 else {
2179 for_each_pipe(dev_priv, pipe) {
2180 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2181 VLV_EDP_PSR_CURR_STATE_MASK;
2182 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2183 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2184 enabled = true;
2185 }
2186 }
2187 }
2188 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002189
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002190 if (!HAS_DDI(dev))
2191 for_each_pipe(dev_priv, pipe) {
2192 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2193 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2194 seq_printf(m, " pipe %c", pipe_name(pipe));
2195 }
2196 seq_puts(m, "\n");
2197
2198 /* CHV PSR has no kind of performance counter */
2199 if (HAS_PSR(dev) && HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002200 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2201 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002202
2203 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2204 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002205 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002206
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002207 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002208 return 0;
2209}
2210
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002211static int i915_sink_crc(struct seq_file *m, void *data)
2212{
2213 struct drm_info_node *node = m->private;
2214 struct drm_device *dev = node->minor->dev;
2215 struct intel_encoder *encoder;
2216 struct intel_connector *connector;
2217 struct intel_dp *intel_dp = NULL;
2218 int ret;
2219 u8 crc[6];
2220
2221 drm_modeset_lock_all(dev);
2222 list_for_each_entry(connector, &dev->mode_config.connector_list,
2223 base.head) {
2224
2225 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2226 continue;
2227
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002228 if (!connector->base.encoder)
2229 continue;
2230
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002231 encoder = to_intel_encoder(connector->base.encoder);
2232 if (encoder->type != INTEL_OUTPUT_EDP)
2233 continue;
2234
2235 intel_dp = enc_to_intel_dp(&encoder->base);
2236
2237 ret = intel_dp_sink_crc(intel_dp, crc);
2238 if (ret)
2239 goto out;
2240
2241 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2242 crc[0], crc[1], crc[2],
2243 crc[3], crc[4], crc[5]);
2244 goto out;
2245 }
2246 ret = -ENODEV;
2247out:
2248 drm_modeset_unlock_all(dev);
2249 return ret;
2250}
2251
Jesse Barnesec013e72013-08-20 10:29:23 +01002252static int i915_energy_uJ(struct seq_file *m, void *data)
2253{
2254 struct drm_info_node *node = m->private;
2255 struct drm_device *dev = node->minor->dev;
2256 struct drm_i915_private *dev_priv = dev->dev_private;
2257 u64 power;
2258 u32 units;
2259
2260 if (INTEL_INFO(dev)->gen < 6)
2261 return -ENODEV;
2262
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002263 intel_runtime_pm_get(dev_priv);
2264
Jesse Barnesec013e72013-08-20 10:29:23 +01002265 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2266 power = (power & 0x1f00) >> 8;
2267 units = 1000000 / (1 << power); /* convert to uJ */
2268 power = I915_READ(MCH_SECP_NRG_STTS);
2269 power *= units;
2270
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002271 intel_runtime_pm_put(dev_priv);
2272
Jesse Barnesec013e72013-08-20 10:29:23 +01002273 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002274
2275 return 0;
2276}
2277
2278static int i915_pc8_status(struct seq_file *m, void *unused)
2279{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002280 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002281 struct drm_device *dev = node->minor->dev;
2282 struct drm_i915_private *dev_priv = dev->dev_private;
2283
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002284 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002285 seq_puts(m, "not supported\n");
2286 return 0;
2287 }
2288
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002289 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002290 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002291 yesno(!intel_irqs_enabled(dev_priv)));
Paulo Zanoni371db662013-08-19 13:18:10 -03002292
Jesse Barnesec013e72013-08-20 10:29:23 +01002293 return 0;
2294}
2295
Imre Deak1da51582013-11-25 17:15:35 +02002296static const char *power_domain_str(enum intel_display_power_domain domain)
2297{
2298 switch (domain) {
2299 case POWER_DOMAIN_PIPE_A:
2300 return "PIPE_A";
2301 case POWER_DOMAIN_PIPE_B:
2302 return "PIPE_B";
2303 case POWER_DOMAIN_PIPE_C:
2304 return "PIPE_C";
2305 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2306 return "PIPE_A_PANEL_FITTER";
2307 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2308 return "PIPE_B_PANEL_FITTER";
2309 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2310 return "PIPE_C_PANEL_FITTER";
2311 case POWER_DOMAIN_TRANSCODER_A:
2312 return "TRANSCODER_A";
2313 case POWER_DOMAIN_TRANSCODER_B:
2314 return "TRANSCODER_B";
2315 case POWER_DOMAIN_TRANSCODER_C:
2316 return "TRANSCODER_C";
2317 case POWER_DOMAIN_TRANSCODER_EDP:
2318 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002319 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2320 return "PORT_DDI_A_2_LANES";
2321 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2322 return "PORT_DDI_A_4_LANES";
2323 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2324 return "PORT_DDI_B_2_LANES";
2325 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2326 return "PORT_DDI_B_4_LANES";
2327 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2328 return "PORT_DDI_C_2_LANES";
2329 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2330 return "PORT_DDI_C_4_LANES";
2331 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2332 return "PORT_DDI_D_2_LANES";
2333 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2334 return "PORT_DDI_D_4_LANES";
2335 case POWER_DOMAIN_PORT_DSI:
2336 return "PORT_DSI";
2337 case POWER_DOMAIN_PORT_CRT:
2338 return "PORT_CRT";
2339 case POWER_DOMAIN_PORT_OTHER:
2340 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002341 case POWER_DOMAIN_VGA:
2342 return "VGA";
2343 case POWER_DOMAIN_AUDIO:
2344 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002345 case POWER_DOMAIN_PLLS:
2346 return "PLLS";
Imre Deak1da51582013-11-25 17:15:35 +02002347 case POWER_DOMAIN_INIT:
2348 return "INIT";
2349 default:
2350 WARN_ON(1);
2351 return "?";
2352 }
2353}
2354
2355static int i915_power_domain_info(struct seq_file *m, void *unused)
2356{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002357 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002358 struct drm_device *dev = node->minor->dev;
2359 struct drm_i915_private *dev_priv = dev->dev_private;
2360 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2361 int i;
2362
2363 mutex_lock(&power_domains->lock);
2364
2365 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2366 for (i = 0; i < power_domains->power_well_count; i++) {
2367 struct i915_power_well *power_well;
2368 enum intel_display_power_domain power_domain;
2369
2370 power_well = &power_domains->power_wells[i];
2371 seq_printf(m, "%-25s %d\n", power_well->name,
2372 power_well->count);
2373
2374 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2375 power_domain++) {
2376 if (!(BIT(power_domain) & power_well->domains))
2377 continue;
2378
2379 seq_printf(m, " %-23s %d\n",
2380 power_domain_str(power_domain),
2381 power_domains->domain_use_count[power_domain]);
2382 }
2383 }
2384
2385 mutex_unlock(&power_domains->lock);
2386
2387 return 0;
2388}
2389
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002390static void intel_seq_print_mode(struct seq_file *m, int tabs,
2391 struct drm_display_mode *mode)
2392{
2393 int i;
2394
2395 for (i = 0; i < tabs; i++)
2396 seq_putc(m, '\t');
2397
2398 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",
2399 mode->base.id, mode->name,
2400 mode->vrefresh, mode->clock,
2401 mode->hdisplay, mode->hsync_start,
2402 mode->hsync_end, mode->htotal,
2403 mode->vdisplay, mode->vsync_start,
2404 mode->vsync_end, mode->vtotal,
2405 mode->type, mode->flags);
2406}
2407
2408static void intel_encoder_info(struct seq_file *m,
2409 struct intel_crtc *intel_crtc,
2410 struct intel_encoder *intel_encoder)
2411{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002412 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002413 struct drm_device *dev = node->minor->dev;
2414 struct drm_crtc *crtc = &intel_crtc->base;
2415 struct intel_connector *intel_connector;
2416 struct drm_encoder *encoder;
2417
2418 encoder = &intel_encoder->base;
2419 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a02014-06-03 14:56:21 +03002420 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002421 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2422 struct drm_connector *connector = &intel_connector->base;
2423 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2424 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002425 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002426 drm_get_connector_status_name(connector->status));
2427 if (connector->status == connector_status_connected) {
2428 struct drm_display_mode *mode = &crtc->mode;
2429 seq_printf(m, ", mode:\n");
2430 intel_seq_print_mode(m, 2, mode);
2431 } else {
2432 seq_putc(m, '\n');
2433 }
2434 }
2435}
2436
2437static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2438{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002439 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002440 struct drm_device *dev = node->minor->dev;
2441 struct drm_crtc *crtc = &intel_crtc->base;
2442 struct intel_encoder *intel_encoder;
2443
Matt Roper5aa8a932014-06-16 10:12:55 -07002444 if (crtc->primary->fb)
2445 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2446 crtc->primary->fb->base.id, crtc->x, crtc->y,
2447 crtc->primary->fb->width, crtc->primary->fb->height);
2448 else
2449 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002450 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2451 intel_encoder_info(m, intel_crtc, intel_encoder);
2452}
2453
2454static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2455{
2456 struct drm_display_mode *mode = panel->fixed_mode;
2457
2458 seq_printf(m, "\tfixed mode:\n");
2459 intel_seq_print_mode(m, 2, mode);
2460}
2461
2462static void intel_dp_info(struct seq_file *m,
2463 struct intel_connector *intel_connector)
2464{
2465 struct intel_encoder *intel_encoder = intel_connector->encoder;
2466 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2467
2468 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2469 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2470 "no");
2471 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2472 intel_panel_info(m, &intel_connector->panel);
2473}
2474
2475static void intel_hdmi_info(struct seq_file *m,
2476 struct intel_connector *intel_connector)
2477{
2478 struct intel_encoder *intel_encoder = intel_connector->encoder;
2479 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2480
2481 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2482 "no");
2483}
2484
2485static void intel_lvds_info(struct seq_file *m,
2486 struct intel_connector *intel_connector)
2487{
2488 intel_panel_info(m, &intel_connector->panel);
2489}
2490
2491static void intel_connector_info(struct seq_file *m,
2492 struct drm_connector *connector)
2493{
2494 struct intel_connector *intel_connector = to_intel_connector(connector);
2495 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002496 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002497
2498 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002499 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002500 drm_get_connector_status_name(connector->status));
2501 if (connector->status == connector_status_connected) {
2502 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2503 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2504 connector->display_info.width_mm,
2505 connector->display_info.height_mm);
2506 seq_printf(m, "\tsubpixel order: %s\n",
2507 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2508 seq_printf(m, "\tCEA rev: %d\n",
2509 connector->display_info.cea_rev);
2510 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002511 if (intel_encoder) {
2512 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2513 intel_encoder->type == INTEL_OUTPUT_EDP)
2514 intel_dp_info(m, intel_connector);
2515 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2516 intel_hdmi_info(m, intel_connector);
2517 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2518 intel_lvds_info(m, intel_connector);
2519 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002520
Jesse Barnesf103fc72014-02-20 12:39:57 -08002521 seq_printf(m, "\tmodes:\n");
2522 list_for_each_entry(mode, &connector->modes, head)
2523 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002524}
2525
Chris Wilson065f2ec2014-03-12 09:13:13 +00002526static bool cursor_active(struct drm_device *dev, int pipe)
2527{
2528 struct drm_i915_private *dev_priv = dev->dev_private;
2529 u32 state;
2530
2531 if (IS_845G(dev) || IS_I865G(dev))
2532 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002533 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002534 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002535
2536 return state;
2537}
2538
2539static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2540{
2541 struct drm_i915_private *dev_priv = dev->dev_private;
2542 u32 pos;
2543
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002544 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002545
2546 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2547 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2548 *x = -*x;
2549
2550 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2551 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2552 *y = -*y;
2553
2554 return cursor_active(dev, pipe);
2555}
2556
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002557static int i915_display_info(struct seq_file *m, void *unused)
2558{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002559 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002560 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002561 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002562 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002563 struct drm_connector *connector;
2564
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002565 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002566 drm_modeset_lock_all(dev);
2567 seq_printf(m, "CRTC info\n");
2568 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002569 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002570 bool active;
2571 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002572
Chris Wilson57127ef2014-07-04 08:20:11 +01002573 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002574 crtc->base.base.id, pipe_name(crtc->pipe),
Chris Wilson57127ef2014-07-04 08:20:11 +01002575 yesno(crtc->active), crtc->config.pipe_src_w, crtc->config.pipe_src_h);
Paulo Zanonia23dc652014-04-01 14:55:11 -03002576 if (crtc->active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002577 intel_crtc_info(m, crtc);
2578
Paulo Zanonia23dc652014-04-01 14:55:11 -03002579 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002580 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 +03002581 yesno(crtc->cursor_base),
Chris Wilson57127ef2014-07-04 08:20:11 +01002582 x, y, crtc->cursor_width, crtc->cursor_height,
2583 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002584 }
Daniel Vettercace8412014-05-22 17:56:31 +02002585
2586 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2587 yesno(!crtc->cpu_fifo_underrun_disabled),
2588 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002589 }
2590
2591 seq_printf(m, "\n");
2592 seq_printf(m, "Connector info\n");
2593 seq_printf(m, "--------------\n");
2594 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2595 intel_connector_info(m, connector);
2596 }
2597 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002598 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002599
2600 return 0;
2601}
2602
Ben Widawskye04934c2014-06-30 09:53:42 -07002603static int i915_semaphore_status(struct seq_file *m, void *unused)
2604{
2605 struct drm_info_node *node = (struct drm_info_node *) m->private;
2606 struct drm_device *dev = node->minor->dev;
2607 struct drm_i915_private *dev_priv = dev->dev_private;
2608 struct intel_engine_cs *ring;
2609 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2610 int i, j, ret;
2611
2612 if (!i915_semaphore_is_enabled(dev)) {
2613 seq_puts(m, "Semaphores are disabled\n");
2614 return 0;
2615 }
2616
2617 ret = mutex_lock_interruptible(&dev->struct_mutex);
2618 if (ret)
2619 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002620 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002621
2622 if (IS_BROADWELL(dev)) {
2623 struct page *page;
2624 uint64_t *seqno;
2625
2626 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2627
2628 seqno = (uint64_t *)kmap_atomic(page);
2629 for_each_ring(ring, dev_priv, i) {
2630 uint64_t offset;
2631
2632 seq_printf(m, "%s\n", ring->name);
2633
2634 seq_puts(m, " Last signal:");
2635 for (j = 0; j < num_rings; j++) {
2636 offset = i * I915_NUM_RINGS + j;
2637 seq_printf(m, "0x%08llx (0x%02llx) ",
2638 seqno[offset], offset * 8);
2639 }
2640 seq_putc(m, '\n');
2641
2642 seq_puts(m, " Last wait: ");
2643 for (j = 0; j < num_rings; j++) {
2644 offset = i + (j * I915_NUM_RINGS);
2645 seq_printf(m, "0x%08llx (0x%02llx) ",
2646 seqno[offset], offset * 8);
2647 }
2648 seq_putc(m, '\n');
2649
2650 }
2651 kunmap_atomic(seqno);
2652 } else {
2653 seq_puts(m, " Last signal:");
2654 for_each_ring(ring, dev_priv, i)
2655 for (j = 0; j < num_rings; j++)
2656 seq_printf(m, "0x%08x\n",
2657 I915_READ(ring->semaphore.mbox.signal[j]));
2658 seq_putc(m, '\n');
2659 }
2660
2661 seq_puts(m, "\nSync seqno:\n");
2662 for_each_ring(ring, dev_priv, i) {
2663 for (j = 0; j < num_rings; j++) {
2664 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2665 }
2666 seq_putc(m, '\n');
2667 }
2668 seq_putc(m, '\n');
2669
Paulo Zanoni03872062014-07-09 14:31:57 -03002670 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002671 mutex_unlock(&dev->struct_mutex);
2672 return 0;
2673}
2674
Daniel Vetter728e29d2014-06-25 22:01:53 +03002675static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2676{
2677 struct drm_info_node *node = (struct drm_info_node *) m->private;
2678 struct drm_device *dev = node->minor->dev;
2679 struct drm_i915_private *dev_priv = dev->dev_private;
2680 int i;
2681
2682 drm_modeset_lock_all(dev);
2683 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2684 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2685
2686 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002687 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002688 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03002689 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002690 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2691 seq_printf(m, " dpll_md: 0x%08x\n",
2692 pll->config.hw_state.dpll_md);
2693 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2694 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2695 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002696 }
2697 drm_modeset_unlock_all(dev);
2698
2699 return 0;
2700}
2701
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01002702static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01002703{
2704 int i;
2705 int ret;
2706 struct drm_info_node *node = (struct drm_info_node *) m->private;
2707 struct drm_device *dev = node->minor->dev;
2708 struct drm_i915_private *dev_priv = dev->dev_private;
2709
Arun Siluvery888b5992014-08-26 14:44:51 +01002710 ret = mutex_lock_interruptible(&dev->struct_mutex);
2711 if (ret)
2712 return ret;
2713
2714 intel_runtime_pm_get(dev_priv);
2715
Mika Kuoppala72253422014-10-07 17:21:26 +03002716 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
2717 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002718 u32 addr, mask, value, read;
2719 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01002720
Mika Kuoppala72253422014-10-07 17:21:26 +03002721 addr = dev_priv->workarounds.reg[i].addr;
2722 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002723 value = dev_priv->workarounds.reg[i].value;
2724 read = I915_READ(addr);
2725 ok = (value & mask) == (read & mask);
2726 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
2727 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01002728 }
2729
2730 intel_runtime_pm_put(dev_priv);
2731 mutex_unlock(&dev->struct_mutex);
2732
2733 return 0;
2734}
2735
Damien Lespiauc5511e42014-11-04 17:06:51 +00002736static int i915_ddb_info(struct seq_file *m, void *unused)
2737{
2738 struct drm_info_node *node = m->private;
2739 struct drm_device *dev = node->minor->dev;
2740 struct drm_i915_private *dev_priv = dev->dev_private;
2741 struct skl_ddb_allocation *ddb;
2742 struct skl_ddb_entry *entry;
2743 enum pipe pipe;
2744 int plane;
2745
Damien Lespiau2fcffe12014-12-03 17:33:24 +00002746 if (INTEL_INFO(dev)->gen < 9)
2747 return 0;
2748
Damien Lespiauc5511e42014-11-04 17:06:51 +00002749 drm_modeset_lock_all(dev);
2750
2751 ddb = &dev_priv->wm.skl_hw.ddb;
2752
2753 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
2754
2755 for_each_pipe(dev_priv, pipe) {
2756 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
2757
2758 for_each_plane(pipe, plane) {
2759 entry = &ddb->plane[pipe][plane];
2760 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
2761 entry->start, entry->end,
2762 skl_ddb_entry_size(entry));
2763 }
2764
2765 entry = &ddb->cursor[pipe];
2766 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
2767 entry->end, skl_ddb_entry_size(entry));
2768 }
2769
2770 drm_modeset_unlock_all(dev);
2771
2772 return 0;
2773}
2774
Damien Lespiau07144422013-10-15 18:55:40 +01002775struct pipe_crc_info {
2776 const char *name;
2777 struct drm_device *dev;
2778 enum pipe pipe;
2779};
2780
Dave Airlie11bed952014-05-12 15:22:27 +10002781static int i915_dp_mst_info(struct seq_file *m, void *unused)
2782{
2783 struct drm_info_node *node = (struct drm_info_node *) m->private;
2784 struct drm_device *dev = node->minor->dev;
2785 struct drm_encoder *encoder;
2786 struct intel_encoder *intel_encoder;
2787 struct intel_digital_port *intel_dig_port;
2788 drm_modeset_lock_all(dev);
2789 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2790 intel_encoder = to_intel_encoder(encoder);
2791 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
2792 continue;
2793 intel_dig_port = enc_to_dig_port(encoder);
2794 if (!intel_dig_port->dp.can_mst)
2795 continue;
2796
2797 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
2798 }
2799 drm_modeset_unlock_all(dev);
2800 return 0;
2801}
2802
Damien Lespiau07144422013-10-15 18:55:40 +01002803static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01002804{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002805 struct pipe_crc_info *info = inode->i_private;
2806 struct drm_i915_private *dev_priv = info->dev->dev_private;
2807 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2808
Daniel Vetter7eb1c492013-11-14 11:30:43 +01002809 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
2810 return -ENODEV;
2811
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002812 spin_lock_irq(&pipe_crc->lock);
2813
2814 if (pipe_crc->opened) {
2815 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002816 return -EBUSY; /* already open */
2817 }
2818
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002819 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01002820 filep->private_data = inode->i_private;
2821
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002822 spin_unlock_irq(&pipe_crc->lock);
2823
Damien Lespiau07144422013-10-15 18:55:40 +01002824 return 0;
2825}
2826
2827static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
2828{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002829 struct pipe_crc_info *info = inode->i_private;
2830 struct drm_i915_private *dev_priv = info->dev->dev_private;
2831 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2832
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002833 spin_lock_irq(&pipe_crc->lock);
2834 pipe_crc->opened = false;
2835 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002836
Damien Lespiau07144422013-10-15 18:55:40 +01002837 return 0;
2838}
2839
2840/* (6 fields, 8 chars each, space separated (5) + '\n') */
2841#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
2842/* account for \'0' */
2843#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
2844
2845static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
2846{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002847 assert_spin_locked(&pipe_crc->lock);
2848 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2849 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01002850}
Shuang He8bf1e9f2013-10-15 18:55:27 +01002851
Damien Lespiau07144422013-10-15 18:55:40 +01002852static ssize_t
2853i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
2854 loff_t *pos)
2855{
2856 struct pipe_crc_info *info = filep->private_data;
2857 struct drm_device *dev = info->dev;
2858 struct drm_i915_private *dev_priv = dev->dev_private;
2859 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2860 char buf[PIPE_CRC_BUFFER_LEN];
2861 int head, tail, n_entries, n;
2862 ssize_t bytes_read;
2863
2864 /*
2865 * Don't allow user space to provide buffers not big enough to hold
2866 * a line of data.
2867 */
2868 if (count < PIPE_CRC_LINE_LEN)
2869 return -EINVAL;
2870
2871 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2872 return 0;
2873
2874 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002875 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002876 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002877 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002878
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002879 if (filep->f_flags & O_NONBLOCK) {
2880 spin_unlock_irq(&pipe_crc->lock);
2881 return -EAGAIN;
2882 }
2883
2884 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2885 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2886 if (ret) {
2887 spin_unlock_irq(&pipe_crc->lock);
2888 return ret;
2889 }
Damien Lespiau07144422013-10-15 18:55:40 +01002890 }
2891
2892 /* We now have one or more entries to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002893 head = pipe_crc->head;
2894 tail = pipe_crc->tail;
Damien Lespiau07144422013-10-15 18:55:40 +01002895 n_entries = min((size_t)CIRC_CNT(head, tail, INTEL_PIPE_CRC_ENTRIES_NR),
2896 count / PIPE_CRC_LINE_LEN);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002897 spin_unlock_irq(&pipe_crc->lock);
2898
Damien Lespiau07144422013-10-15 18:55:40 +01002899 bytes_read = 0;
2900 n = 0;
2901 do {
2902 struct intel_pipe_crc_entry *entry = &pipe_crc->entries[tail];
2903 int ret;
2904
2905 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
2906 "%8u %8x %8x %8x %8x %8x\n",
2907 entry->frame, entry->crc[0],
2908 entry->crc[1], entry->crc[2],
2909 entry->crc[3], entry->crc[4]);
2910
2911 ret = copy_to_user(user_buf + n * PIPE_CRC_LINE_LEN,
2912 buf, PIPE_CRC_LINE_LEN);
2913 if (ret == PIPE_CRC_LINE_LEN)
2914 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01002915
2916 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
2917 tail = (tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiau07144422013-10-15 18:55:40 +01002918 n++;
2919 } while (--n_entries);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002920
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002921 spin_lock_irq(&pipe_crc->lock);
2922 pipe_crc->tail = tail;
2923 spin_unlock_irq(&pipe_crc->lock);
2924
Damien Lespiau07144422013-10-15 18:55:40 +01002925 return bytes_read;
2926}
2927
2928static const struct file_operations i915_pipe_crc_fops = {
2929 .owner = THIS_MODULE,
2930 .open = i915_pipe_crc_open,
2931 .read = i915_pipe_crc_read,
2932 .release = i915_pipe_crc_release,
2933};
2934
2935static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
2936 {
2937 .name = "i915_pipe_A_crc",
2938 .pipe = PIPE_A,
2939 },
2940 {
2941 .name = "i915_pipe_B_crc",
2942 .pipe = PIPE_B,
2943 },
2944 {
2945 .name = "i915_pipe_C_crc",
2946 .pipe = PIPE_C,
2947 },
2948};
2949
2950static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
2951 enum pipe pipe)
2952{
2953 struct drm_device *dev = minor->dev;
2954 struct dentry *ent;
2955 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
2956
2957 info->dev = dev;
2958 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
2959 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08002960 if (!ent)
2961 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01002962
2963 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002964}
2965
Daniel Vettere8dfcf72013-10-16 11:51:54 +02002966static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02002967 "none",
2968 "plane1",
2969 "plane2",
2970 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002971 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02002972 "TV",
2973 "DP-B",
2974 "DP-C",
2975 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01002976 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02002977};
2978
2979static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
2980{
2981 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
2982 return pipe_crc_sources[source];
2983}
2984
Damien Lespiaubd9db022013-10-15 18:55:36 +01002985static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02002986{
2987 struct drm_device *dev = m->private;
2988 struct drm_i915_private *dev_priv = dev->dev_private;
2989 int i;
2990
2991 for (i = 0; i < I915_MAX_PIPES; i++)
2992 seq_printf(m, "%c %s\n", pipe_name(i),
2993 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
2994
2995 return 0;
2996}
2997
Damien Lespiaubd9db022013-10-15 18:55:36 +01002998static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02002999{
3000 struct drm_device *dev = inode->i_private;
3001
Damien Lespiaubd9db022013-10-15 18:55:36 +01003002 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003003}
3004
Daniel Vetter46a19182013-11-01 10:50:20 +01003005static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003006 uint32_t *val)
3007{
Daniel Vetter46a19182013-11-01 10:50:20 +01003008 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3009 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3010
3011 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003012 case INTEL_PIPE_CRC_SOURCE_PIPE:
3013 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3014 break;
3015 case INTEL_PIPE_CRC_SOURCE_NONE:
3016 *val = 0;
3017 break;
3018 default:
3019 return -EINVAL;
3020 }
3021
3022 return 0;
3023}
3024
Daniel Vetter46a19182013-11-01 10:50:20 +01003025static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3026 enum intel_pipe_crc_source *source)
3027{
3028 struct intel_encoder *encoder;
3029 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003030 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003031 int ret = 0;
3032
3033 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3034
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003035 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003036 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003037 if (!encoder->base.crtc)
3038 continue;
3039
3040 crtc = to_intel_crtc(encoder->base.crtc);
3041
3042 if (crtc->pipe != pipe)
3043 continue;
3044
3045 switch (encoder->type) {
3046 case INTEL_OUTPUT_TVOUT:
3047 *source = INTEL_PIPE_CRC_SOURCE_TV;
3048 break;
3049 case INTEL_OUTPUT_DISPLAYPORT:
3050 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003051 dig_port = enc_to_dig_port(&encoder->base);
3052 switch (dig_port->port) {
3053 case PORT_B:
3054 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3055 break;
3056 case PORT_C:
3057 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3058 break;
3059 case PORT_D:
3060 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3061 break;
3062 default:
3063 WARN(1, "nonexisting DP port %c\n",
3064 port_name(dig_port->port));
3065 break;
3066 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003067 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003068 default:
3069 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003070 }
3071 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003072 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003073
3074 return ret;
3075}
3076
3077static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3078 enum pipe pipe,
3079 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003080 uint32_t *val)
3081{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003082 struct drm_i915_private *dev_priv = dev->dev_private;
3083 bool need_stable_symbols = false;
3084
Daniel Vetter46a19182013-11-01 10:50:20 +01003085 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3086 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3087 if (ret)
3088 return ret;
3089 }
3090
3091 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003092 case INTEL_PIPE_CRC_SOURCE_PIPE:
3093 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3094 break;
3095 case INTEL_PIPE_CRC_SOURCE_DP_B:
3096 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003097 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003098 break;
3099 case INTEL_PIPE_CRC_SOURCE_DP_C:
3100 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003101 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003102 break;
3103 case INTEL_PIPE_CRC_SOURCE_NONE:
3104 *val = 0;
3105 break;
3106 default:
3107 return -EINVAL;
3108 }
3109
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003110 /*
3111 * When the pipe CRC tap point is after the transcoders we need
3112 * to tweak symbol-level features to produce a deterministic series of
3113 * symbols for a given frame. We need to reset those features only once
3114 * a frame (instead of every nth symbol):
3115 * - DC-balance: used to ensure a better clock recovery from the data
3116 * link (SDVO)
3117 * - DisplayPort scrambling: used for EMI reduction
3118 */
3119 if (need_stable_symbols) {
3120 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3121
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003122 tmp |= DC_BALANCE_RESET_VLV;
3123 if (pipe == PIPE_A)
3124 tmp |= PIPE_A_SCRAMBLE_RESET;
3125 else
3126 tmp |= PIPE_B_SCRAMBLE_RESET;
3127
3128 I915_WRITE(PORT_DFT2_G4X, tmp);
3129 }
3130
Daniel Vetter7ac01292013-10-18 16:37:06 +02003131 return 0;
3132}
3133
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003134static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003135 enum pipe pipe,
3136 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003137 uint32_t *val)
3138{
Daniel Vetter84093602013-11-01 10:50:21 +01003139 struct drm_i915_private *dev_priv = dev->dev_private;
3140 bool need_stable_symbols = false;
3141
Daniel Vetter46a19182013-11-01 10:50:20 +01003142 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3143 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3144 if (ret)
3145 return ret;
3146 }
3147
3148 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003149 case INTEL_PIPE_CRC_SOURCE_PIPE:
3150 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3151 break;
3152 case INTEL_PIPE_CRC_SOURCE_TV:
3153 if (!SUPPORTS_TV(dev))
3154 return -EINVAL;
3155 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3156 break;
3157 case INTEL_PIPE_CRC_SOURCE_DP_B:
3158 if (!IS_G4X(dev))
3159 return -EINVAL;
3160 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003161 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003162 break;
3163 case INTEL_PIPE_CRC_SOURCE_DP_C:
3164 if (!IS_G4X(dev))
3165 return -EINVAL;
3166 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003167 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003168 break;
3169 case INTEL_PIPE_CRC_SOURCE_DP_D:
3170 if (!IS_G4X(dev))
3171 return -EINVAL;
3172 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003173 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003174 break;
3175 case INTEL_PIPE_CRC_SOURCE_NONE:
3176 *val = 0;
3177 break;
3178 default:
3179 return -EINVAL;
3180 }
3181
Daniel Vetter84093602013-11-01 10:50:21 +01003182 /*
3183 * When the pipe CRC tap point is after the transcoders we need
3184 * to tweak symbol-level features to produce a deterministic series of
3185 * symbols for a given frame. We need to reset those features only once
3186 * a frame (instead of every nth symbol):
3187 * - DC-balance: used to ensure a better clock recovery from the data
3188 * link (SDVO)
3189 * - DisplayPort scrambling: used for EMI reduction
3190 */
3191 if (need_stable_symbols) {
3192 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3193
3194 WARN_ON(!IS_G4X(dev));
3195
3196 I915_WRITE(PORT_DFT_I9XX,
3197 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3198
3199 if (pipe == PIPE_A)
3200 tmp |= PIPE_A_SCRAMBLE_RESET;
3201 else
3202 tmp |= PIPE_B_SCRAMBLE_RESET;
3203
3204 I915_WRITE(PORT_DFT2_G4X, tmp);
3205 }
3206
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003207 return 0;
3208}
3209
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003210static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3211 enum pipe pipe)
3212{
3213 struct drm_i915_private *dev_priv = dev->dev_private;
3214 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3215
3216 if (pipe == PIPE_A)
3217 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3218 else
3219 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3220 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3221 tmp &= ~DC_BALANCE_RESET_VLV;
3222 I915_WRITE(PORT_DFT2_G4X, tmp);
3223
3224}
3225
Daniel Vetter84093602013-11-01 10:50:21 +01003226static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3227 enum pipe pipe)
3228{
3229 struct drm_i915_private *dev_priv = dev->dev_private;
3230 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3231
3232 if (pipe == PIPE_A)
3233 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3234 else
3235 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3236 I915_WRITE(PORT_DFT2_G4X, tmp);
3237
3238 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3239 I915_WRITE(PORT_DFT_I9XX,
3240 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3241 }
3242}
3243
Daniel Vetter46a19182013-11-01 10:50:20 +01003244static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003245 uint32_t *val)
3246{
Daniel Vetter46a19182013-11-01 10:50:20 +01003247 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3248 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3249
3250 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003251 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3252 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3253 break;
3254 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3255 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3256 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003257 case INTEL_PIPE_CRC_SOURCE_PIPE:
3258 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3259 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003260 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003261 *val = 0;
3262 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003263 default:
3264 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003265 }
3266
3267 return 0;
3268}
3269
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003270static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3271{
3272 struct drm_i915_private *dev_priv = dev->dev_private;
3273 struct intel_crtc *crtc =
3274 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3275
3276 drm_modeset_lock_all(dev);
3277 /*
3278 * If we use the eDP transcoder we need to make sure that we don't
3279 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3280 * relevant on hsw with pipe A when using the always-on power well
3281 * routing.
3282 */
3283 if (crtc->config.cpu_transcoder == TRANSCODER_EDP &&
3284 !crtc->config.pch_pfit.enabled) {
3285 crtc->config.pch_pfit.force_thru = true;
3286
3287 intel_display_power_get(dev_priv,
3288 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3289
3290 dev_priv->display.crtc_disable(&crtc->base);
3291 dev_priv->display.crtc_enable(&crtc->base);
3292 }
3293 drm_modeset_unlock_all(dev);
3294}
3295
3296static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3297{
3298 struct drm_i915_private *dev_priv = dev->dev_private;
3299 struct intel_crtc *crtc =
3300 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3301
3302 drm_modeset_lock_all(dev);
3303 /*
3304 * If we use the eDP transcoder we need to make sure that we don't
3305 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3306 * relevant on hsw with pipe A when using the always-on power well
3307 * routing.
3308 */
3309 if (crtc->config.pch_pfit.force_thru) {
3310 crtc->config.pch_pfit.force_thru = false;
3311
3312 dev_priv->display.crtc_disable(&crtc->base);
3313 dev_priv->display.crtc_enable(&crtc->base);
3314
3315 intel_display_power_put(dev_priv,
3316 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3317 }
3318 drm_modeset_unlock_all(dev);
3319}
3320
3321static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3322 enum pipe pipe,
3323 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003324 uint32_t *val)
3325{
Daniel Vetter46a19182013-11-01 10:50:20 +01003326 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3327 *source = INTEL_PIPE_CRC_SOURCE_PF;
3328
3329 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003330 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3331 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3332 break;
3333 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3334 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3335 break;
3336 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003337 if (IS_HASWELL(dev) && pipe == PIPE_A)
3338 hsw_trans_edp_pipe_A_crc_wa(dev);
3339
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003340 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3341 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003342 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003343 *val = 0;
3344 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003345 default:
3346 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003347 }
3348
3349 return 0;
3350}
3351
Daniel Vetter926321d2013-10-16 13:30:34 +02003352static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3353 enum intel_pipe_crc_source source)
3354{
3355 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003356 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003357 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3358 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003359 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003360 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003361
Damien Lespiaucc3da172013-10-15 18:55:31 +01003362 if (pipe_crc->source == source)
3363 return 0;
3364
Damien Lespiauae676fc2013-10-15 18:55:32 +01003365 /* forbid changing the source without going back to 'none' */
3366 if (pipe_crc->source && source)
3367 return -EINVAL;
3368
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003369 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3370 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3371 return -EIO;
3372 }
3373
Daniel Vetter52f843f2013-10-21 17:26:38 +02003374 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003375 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003376 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003377 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003378 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003379 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003380 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003381 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003382 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003383 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003384
3385 if (ret != 0)
3386 return ret;
3387
Damien Lespiau4b584362013-10-15 18:55:33 +01003388 /* none -> real source transition */
3389 if (source) {
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003390 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3391 pipe_name(pipe), pipe_crc_source_name(source));
3392
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003393 pipe_crc->entries = kzalloc(sizeof(*pipe_crc->entries) *
3394 INTEL_PIPE_CRC_ENTRIES_NR,
3395 GFP_KERNEL);
3396 if (!pipe_crc->entries)
3397 return -ENOMEM;
3398
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003399 /*
3400 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3401 * enabled and disabled dynamically based on package C states,
3402 * user space can't make reliable use of the CRCs, so let's just
3403 * completely disable it.
3404 */
3405 hsw_disable_ips(crtc);
3406
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003407 spin_lock_irq(&pipe_crc->lock);
3408 pipe_crc->head = 0;
3409 pipe_crc->tail = 0;
3410 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003411 }
3412
Damien Lespiaucc3da172013-10-15 18:55:31 +01003413 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003414
Daniel Vetter926321d2013-10-16 13:30:34 +02003415 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3416 POSTING_READ(PIPE_CRC_CTL(pipe));
3417
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003418 /* real source -> none transition */
3419 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003420 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003421 struct intel_crtc *crtc =
3422 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003423
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003424 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3425 pipe_name(pipe));
3426
Daniel Vettera33d7102014-06-06 08:22:08 +02003427 drm_modeset_lock(&crtc->base.mutex, NULL);
3428 if (crtc->active)
3429 intel_wait_for_vblank(dev, pipe);
3430 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003431
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003432 spin_lock_irq(&pipe_crc->lock);
3433 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003434 pipe_crc->entries = NULL;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003435 spin_unlock_irq(&pipe_crc->lock);
3436
3437 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003438
3439 if (IS_G4X(dev))
3440 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003441 else if (IS_VALLEYVIEW(dev))
3442 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003443 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3444 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003445
3446 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003447 }
3448
Daniel Vetter926321d2013-10-16 13:30:34 +02003449 return 0;
3450}
3451
3452/*
3453 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003454 * command: wsp* object wsp+ name wsp+ source wsp*
3455 * object: 'pipe'
3456 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003457 * source: (none | plane1 | plane2 | pf)
3458 * wsp: (#0x20 | #0x9 | #0xA)+
3459 *
3460 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003461 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3462 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003463 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003464static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003465{
3466 int n_words = 0;
3467
3468 while (*buf) {
3469 char *end;
3470
3471 /* skip leading white space */
3472 buf = skip_spaces(buf);
3473 if (!*buf)
3474 break; /* end of buffer */
3475
3476 /* find end of word */
3477 for (end = buf; *end && !isspace(*end); end++)
3478 ;
3479
3480 if (n_words == max_words) {
3481 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3482 max_words);
3483 return -EINVAL; /* ran out of words[] before bytes */
3484 }
3485
3486 if (*end)
3487 *end++ = '\0';
3488 words[n_words++] = buf;
3489 buf = end;
3490 }
3491
3492 return n_words;
3493}
3494
Damien Lespiaub94dec82013-10-15 18:55:35 +01003495enum intel_pipe_crc_object {
3496 PIPE_CRC_OBJECT_PIPE,
3497};
3498
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003499static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003500 "pipe",
3501};
3502
3503static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003504display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003505{
3506 int i;
3507
3508 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3509 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003510 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003511 return 0;
3512 }
3513
3514 return -EINVAL;
3515}
3516
Damien Lespiaubd9db022013-10-15 18:55:36 +01003517static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003518{
3519 const char name = buf[0];
3520
3521 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3522 return -EINVAL;
3523
3524 *pipe = name - 'A';
3525
3526 return 0;
3527}
3528
3529static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003530display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003531{
3532 int i;
3533
3534 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3535 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003536 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003537 return 0;
3538 }
3539
3540 return -EINVAL;
3541}
3542
Damien Lespiaubd9db022013-10-15 18:55:36 +01003543static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003544{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003545#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003546 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003547 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003548 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003549 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003550 enum intel_pipe_crc_source source;
3551
Damien Lespiaubd9db022013-10-15 18:55:36 +01003552 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003553 if (n_words != N_WORDS) {
3554 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3555 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003556 return -EINVAL;
3557 }
3558
Damien Lespiaubd9db022013-10-15 18:55:36 +01003559 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003560 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003561 return -EINVAL;
3562 }
3563
Damien Lespiaubd9db022013-10-15 18:55:36 +01003564 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003565 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3566 return -EINVAL;
3567 }
3568
Damien Lespiaubd9db022013-10-15 18:55:36 +01003569 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003570 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003571 return -EINVAL;
3572 }
3573
3574 return pipe_crc_set_source(dev, pipe, source);
3575}
3576
Damien Lespiaubd9db022013-10-15 18:55:36 +01003577static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3578 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003579{
3580 struct seq_file *m = file->private_data;
3581 struct drm_device *dev = m->private;
3582 char *tmpbuf;
3583 int ret;
3584
3585 if (len == 0)
3586 return 0;
3587
3588 if (len > PAGE_SIZE - 1) {
3589 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3590 PAGE_SIZE);
3591 return -E2BIG;
3592 }
3593
3594 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3595 if (!tmpbuf)
3596 return -ENOMEM;
3597
3598 if (copy_from_user(tmpbuf, ubuf, len)) {
3599 ret = -EFAULT;
3600 goto out;
3601 }
3602 tmpbuf[len] = '\0';
3603
Damien Lespiaubd9db022013-10-15 18:55:36 +01003604 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003605
3606out:
3607 kfree(tmpbuf);
3608 if (ret < 0)
3609 return ret;
3610
3611 *offp += len;
3612 return len;
3613}
3614
Damien Lespiaubd9db022013-10-15 18:55:36 +01003615static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003616 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003617 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003618 .read = seq_read,
3619 .llseek = seq_lseek,
3620 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003621 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003622};
3623
Damien Lespiau97e94b22014-11-04 17:06:50 +00003624static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003625{
3626 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003627 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003628 int level;
3629
3630 drm_modeset_lock_all(dev);
3631
3632 for (level = 0; level < num_levels; level++) {
3633 unsigned int latency = wm[level];
3634
Damien Lespiau97e94b22014-11-04 17:06:50 +00003635 /*
3636 * - WM1+ latency values in 0.5us units
3637 * - latencies are in us on gen9
3638 */
3639 if (INTEL_INFO(dev)->gen >= 9)
3640 latency *= 10;
3641 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003642 latency *= 5;
3643
3644 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003645 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003646 }
3647
3648 drm_modeset_unlock_all(dev);
3649}
3650
3651static int pri_wm_latency_show(struct seq_file *m, void *data)
3652{
3653 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003654 struct drm_i915_private *dev_priv = dev->dev_private;
3655 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003656
Damien Lespiau97e94b22014-11-04 17:06:50 +00003657 if (INTEL_INFO(dev)->gen >= 9)
3658 latencies = dev_priv->wm.skl_latency;
3659 else
3660 latencies = to_i915(dev)->wm.pri_latency;
3661
3662 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003663
3664 return 0;
3665}
3666
3667static int spr_wm_latency_show(struct seq_file *m, void *data)
3668{
3669 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003670 struct drm_i915_private *dev_priv = dev->dev_private;
3671 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003672
Damien Lespiau97e94b22014-11-04 17:06:50 +00003673 if (INTEL_INFO(dev)->gen >= 9)
3674 latencies = dev_priv->wm.skl_latency;
3675 else
3676 latencies = to_i915(dev)->wm.spr_latency;
3677
3678 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003679
3680 return 0;
3681}
3682
3683static int cur_wm_latency_show(struct seq_file *m, void *data)
3684{
3685 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003686 struct drm_i915_private *dev_priv = dev->dev_private;
3687 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003688
Damien Lespiau97e94b22014-11-04 17:06:50 +00003689 if (INTEL_INFO(dev)->gen >= 9)
3690 latencies = dev_priv->wm.skl_latency;
3691 else
3692 latencies = to_i915(dev)->wm.cur_latency;
3693
3694 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003695
3696 return 0;
3697}
3698
3699static int pri_wm_latency_open(struct inode *inode, struct file *file)
3700{
3701 struct drm_device *dev = inode->i_private;
3702
Sonika Jindal9ad02572014-07-21 15:23:39 +05303703 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003704 return -ENODEV;
3705
3706 return single_open(file, pri_wm_latency_show, dev);
3707}
3708
3709static int spr_wm_latency_open(struct inode *inode, struct file *file)
3710{
3711 struct drm_device *dev = inode->i_private;
3712
Sonika Jindal9ad02572014-07-21 15:23:39 +05303713 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003714 return -ENODEV;
3715
3716 return single_open(file, spr_wm_latency_show, dev);
3717}
3718
3719static int cur_wm_latency_open(struct inode *inode, struct file *file)
3720{
3721 struct drm_device *dev = inode->i_private;
3722
Sonika Jindal9ad02572014-07-21 15:23:39 +05303723 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003724 return -ENODEV;
3725
3726 return single_open(file, cur_wm_latency_show, dev);
3727}
3728
3729static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003730 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003731{
3732 struct seq_file *m = file->private_data;
3733 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003734 uint16_t new[8] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003735 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003736 int level;
3737 int ret;
3738 char tmp[32];
3739
3740 if (len >= sizeof(tmp))
3741 return -EINVAL;
3742
3743 if (copy_from_user(tmp, ubuf, len))
3744 return -EFAULT;
3745
3746 tmp[len] = '\0';
3747
Damien Lespiau97e94b22014-11-04 17:06:50 +00003748 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
3749 &new[0], &new[1], &new[2], &new[3],
3750 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003751 if (ret != num_levels)
3752 return -EINVAL;
3753
3754 drm_modeset_lock_all(dev);
3755
3756 for (level = 0; level < num_levels; level++)
3757 wm[level] = new[level];
3758
3759 drm_modeset_unlock_all(dev);
3760
3761 return len;
3762}
3763
3764
3765static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3766 size_t len, loff_t *offp)
3767{
3768 struct seq_file *m = file->private_data;
3769 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003770 struct drm_i915_private *dev_priv = dev->dev_private;
3771 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003772
Damien Lespiau97e94b22014-11-04 17:06:50 +00003773 if (INTEL_INFO(dev)->gen >= 9)
3774 latencies = dev_priv->wm.skl_latency;
3775 else
3776 latencies = to_i915(dev)->wm.pri_latency;
3777
3778 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003779}
3780
3781static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3782 size_t len, loff_t *offp)
3783{
3784 struct seq_file *m = file->private_data;
3785 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003786 struct drm_i915_private *dev_priv = dev->dev_private;
3787 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003788
Damien Lespiau97e94b22014-11-04 17:06:50 +00003789 if (INTEL_INFO(dev)->gen >= 9)
3790 latencies = dev_priv->wm.skl_latency;
3791 else
3792 latencies = to_i915(dev)->wm.spr_latency;
3793
3794 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003795}
3796
3797static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3798 size_t len, loff_t *offp)
3799{
3800 struct seq_file *m = file->private_data;
3801 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003802 struct drm_i915_private *dev_priv = dev->dev_private;
3803 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003804
Damien Lespiau97e94b22014-11-04 17:06:50 +00003805 if (INTEL_INFO(dev)->gen >= 9)
3806 latencies = dev_priv->wm.skl_latency;
3807 else
3808 latencies = to_i915(dev)->wm.cur_latency;
3809
3810 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003811}
3812
3813static const struct file_operations i915_pri_wm_latency_fops = {
3814 .owner = THIS_MODULE,
3815 .open = pri_wm_latency_open,
3816 .read = seq_read,
3817 .llseek = seq_lseek,
3818 .release = single_release,
3819 .write = pri_wm_latency_write
3820};
3821
3822static const struct file_operations i915_spr_wm_latency_fops = {
3823 .owner = THIS_MODULE,
3824 .open = spr_wm_latency_open,
3825 .read = seq_read,
3826 .llseek = seq_lseek,
3827 .release = single_release,
3828 .write = spr_wm_latency_write
3829};
3830
3831static const struct file_operations i915_cur_wm_latency_fops = {
3832 .owner = THIS_MODULE,
3833 .open = cur_wm_latency_open,
3834 .read = seq_read,
3835 .llseek = seq_lseek,
3836 .release = single_release,
3837 .write = cur_wm_latency_write
3838};
3839
Kees Cook647416f2013-03-10 14:10:06 -07003840static int
3841i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003842{
Kees Cook647416f2013-03-10 14:10:06 -07003843 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003844 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003845
Kees Cook647416f2013-03-10 14:10:06 -07003846 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003847
Kees Cook647416f2013-03-10 14:10:06 -07003848 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003849}
3850
Kees Cook647416f2013-03-10 14:10:06 -07003851static int
3852i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003853{
Kees Cook647416f2013-03-10 14:10:06 -07003854 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03003855 struct drm_i915_private *dev_priv = dev->dev_private;
3856
3857 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003858
Mika Kuoppala58174462014-02-25 17:11:26 +02003859 i915_handle_error(dev, val,
3860 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03003861
3862 intel_runtime_pm_put(dev_priv);
3863
Kees Cook647416f2013-03-10 14:10:06 -07003864 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003865}
3866
Kees Cook647416f2013-03-10 14:10:06 -07003867DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
3868 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003869 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003870
Kees Cook647416f2013-03-10 14:10:06 -07003871static int
3872i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003873{
Kees Cook647416f2013-03-10 14:10:06 -07003874 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003875 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003876
Kees Cook647416f2013-03-10 14:10:06 -07003877 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003878
Kees Cook647416f2013-03-10 14:10:06 -07003879 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003880}
3881
Kees Cook647416f2013-03-10 14:10:06 -07003882static int
3883i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003884{
Kees Cook647416f2013-03-10 14:10:06 -07003885 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003886 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003887 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003888
Kees Cook647416f2013-03-10 14:10:06 -07003889 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003890
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003891 ret = mutex_lock_interruptible(&dev->struct_mutex);
3892 if (ret)
3893 return ret;
3894
Daniel Vetter99584db2012-11-14 17:14:04 +01003895 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003896 mutex_unlock(&dev->struct_mutex);
3897
Kees Cook647416f2013-03-10 14:10:06 -07003898 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003899}
3900
Kees Cook647416f2013-03-10 14:10:06 -07003901DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
3902 i915_ring_stop_get, i915_ring_stop_set,
3903 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02003904
Chris Wilson094f9a52013-09-25 17:34:55 +01003905static int
3906i915_ring_missed_irq_get(void *data, u64 *val)
3907{
3908 struct drm_device *dev = data;
3909 struct drm_i915_private *dev_priv = dev->dev_private;
3910
3911 *val = dev_priv->gpu_error.missed_irq_rings;
3912 return 0;
3913}
3914
3915static int
3916i915_ring_missed_irq_set(void *data, u64 val)
3917{
3918 struct drm_device *dev = data;
3919 struct drm_i915_private *dev_priv = dev->dev_private;
3920 int ret;
3921
3922 /* Lock against concurrent debugfs callers */
3923 ret = mutex_lock_interruptible(&dev->struct_mutex);
3924 if (ret)
3925 return ret;
3926 dev_priv->gpu_error.missed_irq_rings = val;
3927 mutex_unlock(&dev->struct_mutex);
3928
3929 return 0;
3930}
3931
3932DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
3933 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
3934 "0x%08llx\n");
3935
3936static int
3937i915_ring_test_irq_get(void *data, u64 *val)
3938{
3939 struct drm_device *dev = data;
3940 struct drm_i915_private *dev_priv = dev->dev_private;
3941
3942 *val = dev_priv->gpu_error.test_irq_rings;
3943
3944 return 0;
3945}
3946
3947static int
3948i915_ring_test_irq_set(void *data, u64 val)
3949{
3950 struct drm_device *dev = data;
3951 struct drm_i915_private *dev_priv = dev->dev_private;
3952 int ret;
3953
3954 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
3955
3956 /* Lock against concurrent debugfs callers */
3957 ret = mutex_lock_interruptible(&dev->struct_mutex);
3958 if (ret)
3959 return ret;
3960
3961 dev_priv->gpu_error.test_irq_rings = val;
3962 mutex_unlock(&dev->struct_mutex);
3963
3964 return 0;
3965}
3966
3967DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
3968 i915_ring_test_irq_get, i915_ring_test_irq_set,
3969 "0x%08llx\n");
3970
Chris Wilsondd624af2013-01-15 12:39:35 +00003971#define DROP_UNBOUND 0x1
3972#define DROP_BOUND 0x2
3973#define DROP_RETIRE 0x4
3974#define DROP_ACTIVE 0x8
3975#define DROP_ALL (DROP_UNBOUND | \
3976 DROP_BOUND | \
3977 DROP_RETIRE | \
3978 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07003979static int
3980i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003981{
Kees Cook647416f2013-03-10 14:10:06 -07003982 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00003983
Kees Cook647416f2013-03-10 14:10:06 -07003984 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00003985}
3986
Kees Cook647416f2013-03-10 14:10:06 -07003987static int
3988i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003989{
Kees Cook647416f2013-03-10 14:10:06 -07003990 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00003991 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003992 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003993
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08003994 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00003995
3996 /* No need to check and wait for gpu resets, only libdrm auto-restarts
3997 * on ioctls on -EAGAIN. */
3998 ret = mutex_lock_interruptible(&dev->struct_mutex);
3999 if (ret)
4000 return ret;
4001
4002 if (val & DROP_ACTIVE) {
4003 ret = i915_gpu_idle(dev);
4004 if (ret)
4005 goto unlock;
4006 }
4007
4008 if (val & (DROP_RETIRE | DROP_ACTIVE))
4009 i915_gem_retire_requests(dev);
4010
Chris Wilson21ab4e72014-09-09 11:16:08 +01004011 if (val & DROP_BOUND)
4012 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004013
Chris Wilson21ab4e72014-09-09 11:16:08 +01004014 if (val & DROP_UNBOUND)
4015 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004016
4017unlock:
4018 mutex_unlock(&dev->struct_mutex);
4019
Kees Cook647416f2013-03-10 14:10:06 -07004020 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004021}
4022
Kees Cook647416f2013-03-10 14:10:06 -07004023DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4024 i915_drop_caches_get, i915_drop_caches_set,
4025 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004026
Kees Cook647416f2013-03-10 14:10:06 -07004027static int
4028i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004029{
Kees Cook647416f2013-03-10 14:10:06 -07004030 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004031 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004032 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004033
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004034 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004035 return -ENODEV;
4036
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004037 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4038
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004039 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004040 if (ret)
4041 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004042
Jesse Barnes0a073b82013-04-17 15:54:58 -07004043 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07004044 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07004045 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07004046 *val = dev_priv->rps.max_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004047 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004048
Kees Cook647416f2013-03-10 14:10:06 -07004049 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004050}
4051
Kees Cook647416f2013-03-10 14:10:06 -07004052static int
4053i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004054{
Kees Cook647416f2013-03-10 14:10:06 -07004055 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004056 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004057 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004058 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004059
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004060 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004061 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004062
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004063 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4064
Kees Cook647416f2013-03-10 14:10:06 -07004065 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004066
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004067 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004068 if (ret)
4069 return ret;
4070
Jesse Barnes358733e2011-07-27 11:53:01 -07004071 /*
4072 * Turbo will still be enabled, but won't go above the set value.
4073 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07004074 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02004075 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004076
Ville Syrjälä03af2042014-06-28 02:03:53 +03004077 hw_max = dev_priv->rps.max_freq;
4078 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004079 } else {
4080 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004081
4082 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07004083 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004084 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004085 }
4086
Ben Widawskyb39fb292014-03-19 18:31:11 -07004087 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004088 mutex_unlock(&dev_priv->rps.hw_lock);
4089 return -EINVAL;
4090 }
4091
Ben Widawskyb39fb292014-03-19 18:31:11 -07004092 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004093
4094 if (IS_VALLEYVIEW(dev))
4095 valleyview_set_rps(dev, val);
4096 else
4097 gen6_set_rps(dev, val);
4098
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004099 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004100
Kees Cook647416f2013-03-10 14:10:06 -07004101 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004102}
4103
Kees Cook647416f2013-03-10 14:10:06 -07004104DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4105 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004106 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004107
Kees Cook647416f2013-03-10 14:10:06 -07004108static int
4109i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004110{
Kees Cook647416f2013-03-10 14:10:06 -07004111 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004112 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004113 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004114
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004115 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004116 return -ENODEV;
4117
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004118 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4119
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004120 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004121 if (ret)
4122 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004123
Jesse Barnes0a073b82013-04-17 15:54:58 -07004124 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07004125 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07004126 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07004127 *val = dev_priv->rps.min_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004128 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004129
Kees Cook647416f2013-03-10 14:10:06 -07004130 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004131}
4132
Kees Cook647416f2013-03-10 14:10:06 -07004133static int
4134i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004135{
Kees Cook647416f2013-03-10 14:10:06 -07004136 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004137 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004138 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004139 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004140
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004141 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004142 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004143
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004144 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4145
Kees Cook647416f2013-03-10 14:10:06 -07004146 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004147
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004148 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004149 if (ret)
4150 return ret;
4151
Jesse Barnes1523c312012-05-25 12:34:54 -07004152 /*
4153 * Turbo will still be enabled, but won't go below the set value.
4154 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07004155 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02004156 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004157
Ville Syrjälä03af2042014-06-28 02:03:53 +03004158 hw_max = dev_priv->rps.max_freq;
4159 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004160 } else {
4161 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004162
4163 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07004164 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004165 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004166 }
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004167
Ben Widawskyb39fb292014-03-19 18:31:11 -07004168 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004169 mutex_unlock(&dev_priv->rps.hw_lock);
4170 return -EINVAL;
4171 }
4172
Ben Widawskyb39fb292014-03-19 18:31:11 -07004173 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004174
4175 if (IS_VALLEYVIEW(dev))
4176 valleyview_set_rps(dev, val);
4177 else
4178 gen6_set_rps(dev, val);
4179
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004180 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004181
Kees Cook647416f2013-03-10 14:10:06 -07004182 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004183}
4184
Kees Cook647416f2013-03-10 14:10:06 -07004185DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4186 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004187 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004188
Kees Cook647416f2013-03-10 14:10:06 -07004189static int
4190i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004191{
Kees Cook647416f2013-03-10 14:10:06 -07004192 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004193 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004194 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004195 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004196
Daniel Vetter004777c2012-08-09 15:07:01 +02004197 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4198 return -ENODEV;
4199
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004200 ret = mutex_lock_interruptible(&dev->struct_mutex);
4201 if (ret)
4202 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004203 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004204
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004205 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004206
4207 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004208 mutex_unlock(&dev_priv->dev->struct_mutex);
4209
Kees Cook647416f2013-03-10 14:10:06 -07004210 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004211
Kees Cook647416f2013-03-10 14:10:06 -07004212 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004213}
4214
Kees Cook647416f2013-03-10 14:10:06 -07004215static int
4216i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004217{
Kees Cook647416f2013-03-10 14:10:06 -07004218 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004219 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004220 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004221
Daniel Vetter004777c2012-08-09 15:07:01 +02004222 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4223 return -ENODEV;
4224
Kees Cook647416f2013-03-10 14:10:06 -07004225 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004226 return -EINVAL;
4227
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004228 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004229 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004230
4231 /* Update the cache sharing policy here as well */
4232 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4233 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4234 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4235 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4236
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004237 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004238 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004239}
4240
Kees Cook647416f2013-03-10 14:10:06 -07004241DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4242 i915_cache_sharing_get, i915_cache_sharing_set,
4243 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004244
Ben Widawsky6d794d42011-04-25 11:25:56 -07004245static int i915_forcewake_open(struct inode *inode, struct file *file)
4246{
4247 struct drm_device *dev = inode->i_private;
4248 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004249
Daniel Vetter075edca2012-01-24 09:44:28 +01004250 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004251 return 0;
4252
Deepak Sc8d9a592013-11-23 14:55:42 +05304253 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004254
4255 return 0;
4256}
4257
Ben Widawskyc43b5632012-04-16 14:07:40 -07004258static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004259{
4260 struct drm_device *dev = inode->i_private;
4261 struct drm_i915_private *dev_priv = dev->dev_private;
4262
Daniel Vetter075edca2012-01-24 09:44:28 +01004263 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004264 return 0;
4265
Deepak Sc8d9a592013-11-23 14:55:42 +05304266 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004267
4268 return 0;
4269}
4270
4271static const struct file_operations i915_forcewake_fops = {
4272 .owner = THIS_MODULE,
4273 .open = i915_forcewake_open,
4274 .release = i915_forcewake_release,
4275};
4276
4277static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4278{
4279 struct drm_device *dev = minor->dev;
4280 struct dentry *ent;
4281
4282 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004283 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004284 root, dev,
4285 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004286 if (!ent)
4287 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004288
Ben Widawsky8eb57292011-05-11 15:10:58 -07004289 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004290}
4291
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004292static int i915_debugfs_create(struct dentry *root,
4293 struct drm_minor *minor,
4294 const char *name,
4295 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004296{
4297 struct drm_device *dev = minor->dev;
4298 struct dentry *ent;
4299
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004300 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004301 S_IRUGO | S_IWUSR,
4302 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004303 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004304 if (!ent)
4305 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004306
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004307 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004308}
4309
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004310static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004311 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004312 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004313 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01004314 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004315 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004316 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004317 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004318 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004319 {"i915_gem_request", i915_gem_request_info, 0},
4320 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004321 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004322 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00004323 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
4324 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
4325 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07004326 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Deepak Sadb4bd12014-03-31 11:30:02 +05304327 {"i915_frequency_info", i915_frequency_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004328 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004329 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004330 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004331 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004332 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004333 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004334 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004335 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004336 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01004337 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01004338 {"i915_execlists", i915_execlists, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07004339 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004340 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004341 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004342 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004343 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004344 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004345 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03004346 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004347 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004348 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004349 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004350 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004351 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004352 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004353 {"i915_ddb_info", i915_ddb_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004354};
Ben Gamari27c202a2009-07-01 22:26:52 -04004355#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004356
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004357static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004358 const char *name;
4359 const struct file_operations *fops;
4360} i915_debugfs_files[] = {
4361 {"i915_wedged", &i915_wedged_fops},
4362 {"i915_max_freq", &i915_max_freq_fops},
4363 {"i915_min_freq", &i915_min_freq_fops},
4364 {"i915_cache_sharing", &i915_cache_sharing_fops},
4365 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004366 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4367 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004368 {"i915_gem_drop_caches", &i915_drop_caches_fops},
4369 {"i915_error_state", &i915_error_state_fops},
4370 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004371 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004372 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4373 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4374 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004375 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004376};
4377
Damien Lespiau07144422013-10-15 18:55:40 +01004378void intel_display_crc_init(struct drm_device *dev)
4379{
4380 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01004381 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01004382
Damien Lespiau055e3932014-08-18 13:49:10 +01004383 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01004384 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01004385
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004386 pipe_crc->opened = false;
4387 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01004388 init_waitqueue_head(&pipe_crc->wq);
4389 }
4390}
4391
Ben Gamari27c202a2009-07-01 22:26:52 -04004392int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004393{
Daniel Vetter34b96742013-07-04 20:49:44 +02004394 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004395
Ben Widawsky6d794d42011-04-25 11:25:56 -07004396 ret = i915_forcewake_create(minor->debugfs_root, minor);
4397 if (ret)
4398 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004399
Damien Lespiau07144422013-10-15 18:55:40 +01004400 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
4401 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
4402 if (ret)
4403 return ret;
4404 }
4405
Daniel Vetter34b96742013-07-04 20:49:44 +02004406 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4407 ret = i915_debugfs_create(minor->debugfs_root, minor,
4408 i915_debugfs_files[i].name,
4409 i915_debugfs_files[i].fops);
4410 if (ret)
4411 return ret;
4412 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004413
Ben Gamari27c202a2009-07-01 22:26:52 -04004414 return drm_debugfs_create_files(i915_debugfs_list,
4415 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004416 minor->debugfs_root, minor);
4417}
4418
Ben Gamari27c202a2009-07-01 22:26:52 -04004419void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004420{
Daniel Vetter34b96742013-07-04 20:49:44 +02004421 int i;
4422
Ben Gamari27c202a2009-07-01 22:26:52 -04004423 drm_debugfs_remove_files(i915_debugfs_list,
4424 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004425
Ben Widawsky6d794d42011-04-25 11:25:56 -07004426 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
4427 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004428
Daniel Vettere309a992013-10-16 22:55:51 +02004429 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01004430 struct drm_info_list *info_list =
4431 (struct drm_info_list *)&i915_pipe_crc_data[i];
4432
4433 drm_debugfs_remove_files(info_list, 1, minor);
4434 }
4435
Daniel Vetter34b96742013-07-04 20:49:44 +02004436 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4437 struct drm_info_list *info_list =
4438 (struct drm_info_list *) i915_debugfs_files[i].fops;
4439
4440 drm_debugfs_remove_files(info_list, 1, minor);
4441 }
Ben Gamari20172632009-02-17 20:08:50 -05004442}