blob: 3a08684a7af33710536ecd87dcb5916643a67fb8 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Chris Wilsonf13d3f72010-09-20 17:36:15 +010043enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010044 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010046 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047};
Ben Gamari433e12f2009-02-17 20:08:51 -050048
Chris Wilson70d39fe2010-08-25 16:03:34 +010049static const char *yesno(int v)
50{
51 return v ? "yes" : "no";
52}
53
Damien Lespiau497666d2013-10-15 18:55:39 +010054/* As the drm_debugfs_init() routines are called before dev->dev_private is
55 * allocated we need to hook into the minor for release. */
56static int
57drm_add_fake_info_node(struct drm_minor *minor,
58 struct dentry *ent,
59 const void *key)
60{
61 struct drm_info_node *node;
62
63 node = kmalloc(sizeof(*node), GFP_KERNEL);
64 if (node == NULL) {
65 debugfs_remove(ent);
66 return -ENOMEM;
67 }
68
69 node->minor = minor;
70 node->dent = ent;
71 node->info_ent = (void *) key;
72
73 mutex_lock(&minor->debugfs_lock);
74 list_add(&node->list, &minor->debugfs_list);
75 mutex_unlock(&minor->debugfs_lock);
76
77 return 0;
78}
79
Chris Wilson70d39fe2010-08-25 16:03:34 +010080static int i915_capabilities(struct seq_file *m, void *data)
81{
Damien Lespiau9f25d002014-05-13 15:30:28 +010082 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010083 struct drm_device *dev = node->minor->dev;
84 const struct intel_device_info *info = INTEL_INFO(dev);
85
86 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030087 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010088#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
89#define SEP_SEMICOLON ;
90 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
91#undef PRINT_FLAG
92#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010093
94 return 0;
95}
Ben Gamari433e12f2009-02-17 20:08:51 -050096
Chris Wilson05394f32010-11-08 19:18:58 +000097static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000098{
Daniel Vetter4feb7652014-11-24 11:21:52 +010099 if (i915_gem_obj_is_pinned(obj))
Chris Wilsona6172a82009-02-11 14:26:38 +0000100 return "p";
101 else
102 return " ";
103}
104
Chris Wilson05394f32010-11-08 19:18:58 +0000105static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000106{
Akshay Joshi0206e352011-08-16 15:34:10 -0400107 switch (obj->tiling_mode) {
108 default:
109 case I915_TILING_NONE: return " ";
110 case I915_TILING_X: return "X";
111 case I915_TILING_Y: return "Y";
112 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000113}
114
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700115static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
116{
Tvrtko Ursulinaff43762014-10-24 12:42:33 +0100117 return i915_gem_obj_to_ggtt(obj) ? "g" : " ";
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700118}
119
Chris Wilson37811fc2010-08-25 22:45:57 +0100120static void
121describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
122{
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700123 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800124 int pin_count = 0;
125
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200126 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %x %x %x%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100127 &obj->base,
128 get_pin_flag(obj),
129 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700130 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800131 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100132 obj->base.read_domains,
133 obj->base.write_domain,
John Harrison97b2a6a2014-11-24 18:49:26 +0000134 i915_gem_request_get_seqno(obj->last_read_req),
135 i915_gem_request_get_seqno(obj->last_write_req),
136 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100137 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100138 obj->dirty ? " dirty" : "",
139 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
140 if (obj->base.name)
141 seq_printf(m, " (name: %d)", obj->base.name);
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");
Tvrtko Ursulinfe14d5f2014-12-10 17:27:58 +0000155 seq_printf(m, "gtt offset: %08lx, size: %08lx, type: %u)",
156 vma->node.start, vma->node.size,
157 vma->ggtt_view.type);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700158 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000159 if (obj->stolen)
160 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000161 if (obj->pin_mappable || obj->fault_mappable) {
162 char s[3], *t = s;
163 if (obj->pin_mappable)
164 *t++ = 'p';
165 if (obj->fault_mappable)
166 *t++ = 'f';
167 *t = '\0';
168 seq_printf(m, " (%s mappable)", s);
169 }
John Harrison41c52412014-11-24 18:49:43 +0000170 if (obj->last_read_req != NULL)
171 seq_printf(m, " (%s)",
172 i915_gem_request_get_ring(obj->last_read_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200173 if (obj->frontbuffer_bits)
174 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100175}
176
Oscar Mateo273497e2014-05-22 14:13:37 +0100177static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700178{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100179 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700180 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
181 seq_putc(m, ' ');
182}
183
Ben Gamari433e12f2009-02-17 20:08:51 -0500184static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500185{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100186 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500187 uintptr_t list = (uintptr_t) node->info_ent->data;
188 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500189 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700190 struct drm_i915_private *dev_priv = dev->dev_private;
191 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700192 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100193 size_t total_obj_size, total_gtt_size;
194 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100195
196 ret = mutex_lock_interruptible(&dev->struct_mutex);
197 if (ret)
198 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500199
Ben Widawskyca191b12013-07-31 17:00:14 -0700200 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500201 switch (list) {
202 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100203 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700204 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500205 break;
206 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100207 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700208 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500209 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500210 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100211 mutex_unlock(&dev->struct_mutex);
212 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500213 }
214
Chris Wilson8f2480f2010-09-26 11:44:19 +0100215 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700216 list_for_each_entry(vma, head, mm_list) {
217 seq_printf(m, " ");
218 describe_obj(m, vma->obj);
219 seq_printf(m, "\n");
220 total_obj_size += vma->obj->base.size;
221 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100222 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500223 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100224 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700225
Chris Wilson8f2480f2010-09-26 11:44:19 +0100226 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
227 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500228 return 0;
229}
230
Chris Wilson6d2b88852013-08-07 18:30:54 +0100231static int obj_rank_by_stolen(void *priv,
232 struct list_head *A, struct list_head *B)
233{
234 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200235 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100236 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200237 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100238
239 return a->stolen->start - b->stolen->start;
240}
241
242static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
243{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100244 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100245 struct drm_device *dev = node->minor->dev;
246 struct drm_i915_private *dev_priv = dev->dev_private;
247 struct drm_i915_gem_object *obj;
248 size_t total_obj_size, total_gtt_size;
249 LIST_HEAD(stolen);
250 int count, ret;
251
252 ret = mutex_lock_interruptible(&dev->struct_mutex);
253 if (ret)
254 return ret;
255
256 total_obj_size = total_gtt_size = count = 0;
257 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
258 if (obj->stolen == NULL)
259 continue;
260
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200261 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100262
263 total_obj_size += obj->base.size;
264 total_gtt_size += i915_gem_obj_ggtt_size(obj);
265 count++;
266 }
267 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
268 if (obj->stolen == NULL)
269 continue;
270
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200271 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100272
273 total_obj_size += obj->base.size;
274 count++;
275 }
276 list_sort(NULL, &stolen, obj_rank_by_stolen);
277 seq_puts(m, "Stolen:\n");
278 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200279 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100280 seq_puts(m, " ");
281 describe_obj(m, obj);
282 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200283 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100284 }
285 mutex_unlock(&dev->struct_mutex);
286
287 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
288 count, total_obj_size, total_gtt_size);
289 return 0;
290}
291
Chris Wilson6299f992010-11-24 12:23:44 +0000292#define count_objects(list, member) do { \
293 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700294 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000295 ++count; \
296 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700297 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000298 ++mappable_count; \
299 } \
300 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400301} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000302
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100303struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000304 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100305 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000306 size_t total, unbound;
307 size_t global, shared;
308 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100309};
310
311static int per_file_stats(int id, void *ptr, void *data)
312{
313 struct drm_i915_gem_object *obj = ptr;
314 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000315 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100316
317 stats->count++;
318 stats->total += obj->base.size;
319
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000320 if (obj->base.name || obj->base.dma_buf)
321 stats->shared += obj->base.size;
322
Chris Wilson6313c202014-03-19 13:45:45 +0000323 if (USES_FULL_PPGTT(obj->base.dev)) {
324 list_for_each_entry(vma, &obj->vma_list, vma_link) {
325 struct i915_hw_ppgtt *ppgtt;
326
327 if (!drm_mm_node_allocated(&vma->node))
328 continue;
329
330 if (i915_is_ggtt(vma->vm)) {
331 stats->global += obj->base.size;
332 continue;
333 }
334
335 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200336 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000337 continue;
338
John Harrison41c52412014-11-24 18:49:43 +0000339 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000340 stats->active += obj->base.size;
341 else
342 stats->inactive += obj->base.size;
343
344 return 0;
345 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100346 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000347 if (i915_gem_obj_ggtt_bound(obj)) {
348 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000349 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000350 stats->active += obj->base.size;
351 else
352 stats->inactive += obj->base.size;
353 return 0;
354 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100355 }
356
Chris Wilson6313c202014-03-19 13:45:45 +0000357 if (!list_empty(&obj->global_list))
358 stats->unbound += obj->base.size;
359
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100360 return 0;
361}
362
Brad Volkin493018d2014-12-11 12:13:08 -0800363#define print_file_stats(m, name, stats) \
364 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n", \
365 name, \
366 stats.count, \
367 stats.total, \
368 stats.active, \
369 stats.inactive, \
370 stats.global, \
371 stats.shared, \
372 stats.unbound)
373
374static void print_batch_pool_stats(struct seq_file *m,
375 struct drm_i915_private *dev_priv)
376{
377 struct drm_i915_gem_object *obj;
378 struct file_stats stats;
379
380 memset(&stats, 0, sizeof(stats));
381
382 list_for_each_entry(obj,
383 &dev_priv->mm.batch_pool.cache_list,
384 batch_pool_list)
385 per_file_stats(0, obj, &stats);
386
387 print_file_stats(m, "batch pool", stats);
388}
389
Ben Widawskyca191b12013-07-31 17:00:14 -0700390#define count_vmas(list, member) do { \
391 list_for_each_entry(vma, list, member) { \
392 size += i915_gem_obj_ggtt_size(vma->obj); \
393 ++count; \
394 if (vma->obj->map_and_fenceable) { \
395 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
396 ++mappable_count; \
397 } \
398 } \
399} while (0)
400
401static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100402{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100403 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100404 struct drm_device *dev = node->minor->dev;
405 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200406 u32 count, mappable_count, purgeable_count;
407 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000408 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700409 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100410 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700411 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100412 int ret;
413
414 ret = mutex_lock_interruptible(&dev->struct_mutex);
415 if (ret)
416 return ret;
417
Chris Wilson6299f992010-11-24 12:23:44 +0000418 seq_printf(m, "%u objects, %zu bytes\n",
419 dev_priv->mm.object_count,
420 dev_priv->mm.object_memory);
421
422 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700423 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000424 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
425 count, mappable_count, size, mappable_size);
426
427 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700428 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000429 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
430 count, mappable_count, size, mappable_size);
431
432 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700433 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000434 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
435 count, mappable_count, size, mappable_size);
436
Chris Wilsonb7abb712012-08-20 11:33:30 +0200437 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700438 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200439 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200440 if (obj->madv == I915_MADV_DONTNEED)
441 purgeable_size += obj->base.size, ++purgeable_count;
442 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200443 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
444
Chris Wilson6299f992010-11-24 12:23:44 +0000445 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700446 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000447 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700448 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000449 ++count;
450 }
451 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700452 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000453 ++mappable_count;
454 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200455 if (obj->madv == I915_MADV_DONTNEED) {
456 purgeable_size += obj->base.size;
457 ++purgeable_count;
458 }
Chris Wilson6299f992010-11-24 12:23:44 +0000459 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200460 seq_printf(m, "%u purgeable objects, %zu bytes\n",
461 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000462 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
463 mappable_count, mappable_size);
464 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
465 count, size);
466
Ben Widawsky93d18792013-01-17 12:45:17 -0800467 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700468 dev_priv->gtt.base.total,
469 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100470
Damien Lespiau267f0c92013-06-24 22:59:48 +0100471 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800472 print_batch_pool_stats(m, dev_priv);
473
474 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100475 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
476 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900477 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100478
479 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000480 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100481 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100482 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100483 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900484 /*
485 * Although we have a valid reference on file->pid, that does
486 * not guarantee that the task_struct who called get_pid() is
487 * still alive (e.g. get_pid(current) => fork() => exit()).
488 * Therefore, we need to protect this ->comm access using RCU.
489 */
490 rcu_read_lock();
491 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800492 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900493 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100494 }
495
Chris Wilson73aa8082010-09-30 11:46:12 +0100496 mutex_unlock(&dev->struct_mutex);
497
498 return 0;
499}
500
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100501static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000502{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100503 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000504 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100505 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000506 struct drm_i915_private *dev_priv = dev->dev_private;
507 struct drm_i915_gem_object *obj;
508 size_t total_obj_size, total_gtt_size;
509 int count, ret;
510
511 ret = mutex_lock_interruptible(&dev->struct_mutex);
512 if (ret)
513 return ret;
514
515 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700516 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800517 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100518 continue;
519
Damien Lespiau267f0c92013-06-24 22:59:48 +0100520 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000521 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100522 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000523 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700524 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000525 count++;
526 }
527
528 mutex_unlock(&dev->struct_mutex);
529
530 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
531 count, total_obj_size, total_gtt_size);
532
533 return 0;
534}
535
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100536static int i915_gem_pageflip_info(struct seq_file *m, void *data)
537{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100538 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100539 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100540 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100541 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200542 int ret;
543
544 ret = mutex_lock_interruptible(&dev->struct_mutex);
545 if (ret)
546 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100547
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100548 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800549 const char pipe = pipe_name(crtc->pipe);
550 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100551 struct intel_unpin_work *work;
552
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200553 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100554 work = crtc->unpin_work;
555 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800556 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100557 pipe, plane);
558 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100559 u32 addr;
560
Chris Wilsone7d841c2012-12-03 11:36:30 +0000561 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800562 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100563 pipe, plane);
564 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800565 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100566 pipe, plane);
567 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100568 if (work->flip_queued_req) {
569 struct intel_engine_cs *ring =
570 i915_gem_request_get_ring(work->flip_queued_req);
571
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200572 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100573 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000574 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100575 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100576 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000577 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100578 } else
579 seq_printf(m, "Flip not associated with any ring\n");
580 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
581 work->flip_queued_vblank,
582 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100583 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100584 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100585 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100586 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100587 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000588 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100589
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100590 if (INTEL_INFO(dev)->gen >= 4)
591 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
592 else
593 addr = I915_READ(DSPADDR(crtc->plane));
594 seq_printf(m, "Current scanout address 0x%08x\n", addr);
595
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100596 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100597 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
598 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100599 }
600 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200601 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100602 }
603
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200604 mutex_unlock(&dev->struct_mutex);
605
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100606 return 0;
607}
608
Brad Volkin493018d2014-12-11 12:13:08 -0800609static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
610{
611 struct drm_info_node *node = m->private;
612 struct drm_device *dev = node->minor->dev;
613 struct drm_i915_private *dev_priv = dev->dev_private;
614 struct drm_i915_gem_object *obj;
615 int count = 0;
616 int ret;
617
618 ret = mutex_lock_interruptible(&dev->struct_mutex);
619 if (ret)
620 return ret;
621
622 seq_puts(m, "cache:\n");
623 list_for_each_entry(obj,
624 &dev_priv->mm.batch_pool.cache_list,
625 batch_pool_list) {
626 seq_puts(m, " ");
627 describe_obj(m, obj);
628 seq_putc(m, '\n');
629 count++;
630 }
631
632 seq_printf(m, "total: %d\n", count);
633
634 mutex_unlock(&dev->struct_mutex);
635
636 return 0;
637}
638
Ben Gamari20172632009-02-17 20:08:50 -0500639static int i915_gem_request_info(struct seq_file *m, void *data)
640{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100641 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500642 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300643 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100644 struct intel_engine_cs *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500645 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100646 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100647
648 ret = mutex_lock_interruptible(&dev->struct_mutex);
649 if (ret)
650 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500651
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100652 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100653 for_each_ring(ring, dev_priv, i) {
654 if (list_empty(&ring->request_list))
655 continue;
656
657 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100658 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100659 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100660 list) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200661 seq_printf(m, " %x @ %d\n",
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100662 gem_request->seqno,
663 (int) (jiffies - gem_request->emitted_jiffies));
664 }
665 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500666 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100667 mutex_unlock(&dev->struct_mutex);
668
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100669 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100670 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100671
Ben Gamari20172632009-02-17 20:08:50 -0500672 return 0;
673}
674
Chris Wilsonb2223492010-10-27 15:27:33 +0100675static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100676 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100677{
678 if (ring->get_seqno) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200679 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100680 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100681 }
682}
683
Ben Gamari20172632009-02-17 20:08:50 -0500684static int i915_gem_seqno_info(struct seq_file *m, void *data)
685{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100686 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500687 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300688 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100689 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000690 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100691
692 ret = mutex_lock_interruptible(&dev->struct_mutex);
693 if (ret)
694 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200695 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500696
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100697 for_each_ring(ring, dev_priv, i)
698 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100699
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200700 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100701 mutex_unlock(&dev->struct_mutex);
702
Ben Gamari20172632009-02-17 20:08:50 -0500703 return 0;
704}
705
706
707static int i915_interrupt_info(struct seq_file *m, void *data)
708{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100709 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500710 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300711 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100712 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800713 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100714
715 ret = mutex_lock_interruptible(&dev->struct_mutex);
716 if (ret)
717 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200718 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500719
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300720 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300721 seq_printf(m, "Master Interrupt Control:\t%08x\n",
722 I915_READ(GEN8_MASTER_IRQ));
723
724 seq_printf(m, "Display IER:\t%08x\n",
725 I915_READ(VLV_IER));
726 seq_printf(m, "Display IIR:\t%08x\n",
727 I915_READ(VLV_IIR));
728 seq_printf(m, "Display IIR_RW:\t%08x\n",
729 I915_READ(VLV_IIR_RW));
730 seq_printf(m, "Display IMR:\t%08x\n",
731 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100732 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300733 seq_printf(m, "Pipe %c stat:\t%08x\n",
734 pipe_name(pipe),
735 I915_READ(PIPESTAT(pipe)));
736
737 seq_printf(m, "Port hotplug:\t%08x\n",
738 I915_READ(PORT_HOTPLUG_EN));
739 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
740 I915_READ(VLV_DPFLIPSTAT));
741 seq_printf(m, "DPINVGTT:\t%08x\n",
742 I915_READ(DPINVGTT));
743
744 for (i = 0; i < 4; i++) {
745 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
746 i, I915_READ(GEN8_GT_IMR(i)));
747 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
748 i, I915_READ(GEN8_GT_IIR(i)));
749 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
750 i, I915_READ(GEN8_GT_IER(i)));
751 }
752
753 seq_printf(m, "PCU interrupt mask:\t%08x\n",
754 I915_READ(GEN8_PCU_IMR));
755 seq_printf(m, "PCU interrupt identity:\t%08x\n",
756 I915_READ(GEN8_PCU_IIR));
757 seq_printf(m, "PCU interrupt enable:\t%08x\n",
758 I915_READ(GEN8_PCU_IER));
759 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700760 seq_printf(m, "Master Interrupt Control:\t%08x\n",
761 I915_READ(GEN8_MASTER_IRQ));
762
763 for (i = 0; i < 4; i++) {
764 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
765 i, I915_READ(GEN8_GT_IMR(i)));
766 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
767 i, I915_READ(GEN8_GT_IIR(i)));
768 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
769 i, I915_READ(GEN8_GT_IER(i)));
770 }
771
Damien Lespiau055e3932014-08-18 13:49:10 +0100772 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200773 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300774 POWER_DOMAIN_PIPE(pipe))) {
775 seq_printf(m, "Pipe %c power disabled\n",
776 pipe_name(pipe));
777 continue;
778 }
Ben Widawskya123f152013-11-02 21:07:10 -0700779 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000780 pipe_name(pipe),
781 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700782 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000783 pipe_name(pipe),
784 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700785 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000786 pipe_name(pipe),
787 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700788 }
789
790 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
791 I915_READ(GEN8_DE_PORT_IMR));
792 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
793 I915_READ(GEN8_DE_PORT_IIR));
794 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
795 I915_READ(GEN8_DE_PORT_IER));
796
797 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
798 I915_READ(GEN8_DE_MISC_IMR));
799 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
800 I915_READ(GEN8_DE_MISC_IIR));
801 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
802 I915_READ(GEN8_DE_MISC_IER));
803
804 seq_printf(m, "PCU interrupt mask:\t%08x\n",
805 I915_READ(GEN8_PCU_IMR));
806 seq_printf(m, "PCU interrupt identity:\t%08x\n",
807 I915_READ(GEN8_PCU_IIR));
808 seq_printf(m, "PCU interrupt enable:\t%08x\n",
809 I915_READ(GEN8_PCU_IER));
810 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700811 seq_printf(m, "Display IER:\t%08x\n",
812 I915_READ(VLV_IER));
813 seq_printf(m, "Display IIR:\t%08x\n",
814 I915_READ(VLV_IIR));
815 seq_printf(m, "Display IIR_RW:\t%08x\n",
816 I915_READ(VLV_IIR_RW));
817 seq_printf(m, "Display IMR:\t%08x\n",
818 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100819 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700820 seq_printf(m, "Pipe %c stat:\t%08x\n",
821 pipe_name(pipe),
822 I915_READ(PIPESTAT(pipe)));
823
824 seq_printf(m, "Master IER:\t%08x\n",
825 I915_READ(VLV_MASTER_IER));
826
827 seq_printf(m, "Render IER:\t%08x\n",
828 I915_READ(GTIER));
829 seq_printf(m, "Render IIR:\t%08x\n",
830 I915_READ(GTIIR));
831 seq_printf(m, "Render IMR:\t%08x\n",
832 I915_READ(GTIMR));
833
834 seq_printf(m, "PM IER:\t\t%08x\n",
835 I915_READ(GEN6_PMIER));
836 seq_printf(m, "PM IIR:\t\t%08x\n",
837 I915_READ(GEN6_PMIIR));
838 seq_printf(m, "PM IMR:\t\t%08x\n",
839 I915_READ(GEN6_PMIMR));
840
841 seq_printf(m, "Port hotplug:\t%08x\n",
842 I915_READ(PORT_HOTPLUG_EN));
843 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
844 I915_READ(VLV_DPFLIPSTAT));
845 seq_printf(m, "DPINVGTT:\t%08x\n",
846 I915_READ(DPINVGTT));
847
848 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800849 seq_printf(m, "Interrupt enable: %08x\n",
850 I915_READ(IER));
851 seq_printf(m, "Interrupt identity: %08x\n",
852 I915_READ(IIR));
853 seq_printf(m, "Interrupt mask: %08x\n",
854 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100855 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800856 seq_printf(m, "Pipe %c stat: %08x\n",
857 pipe_name(pipe),
858 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800859 } else {
860 seq_printf(m, "North Display Interrupt enable: %08x\n",
861 I915_READ(DEIER));
862 seq_printf(m, "North Display Interrupt identity: %08x\n",
863 I915_READ(DEIIR));
864 seq_printf(m, "North Display Interrupt mask: %08x\n",
865 I915_READ(DEIMR));
866 seq_printf(m, "South Display Interrupt enable: %08x\n",
867 I915_READ(SDEIER));
868 seq_printf(m, "South Display Interrupt identity: %08x\n",
869 I915_READ(SDEIIR));
870 seq_printf(m, "South Display Interrupt mask: %08x\n",
871 I915_READ(SDEIMR));
872 seq_printf(m, "Graphics Interrupt enable: %08x\n",
873 I915_READ(GTIER));
874 seq_printf(m, "Graphics Interrupt identity: %08x\n",
875 I915_READ(GTIIR));
876 seq_printf(m, "Graphics Interrupt mask: %08x\n",
877 I915_READ(GTIMR));
878 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100879 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700880 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100881 seq_printf(m,
882 "Graphics Interrupt mask (%s): %08x\n",
883 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000884 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100885 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000886 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200887 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100888 mutex_unlock(&dev->struct_mutex);
889
Ben Gamari20172632009-02-17 20:08:50 -0500890 return 0;
891}
892
Chris Wilsona6172a82009-02-11 14:26:38 +0000893static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
894{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100895 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000896 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300897 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100898 int i, ret;
899
900 ret = mutex_lock_interruptible(&dev->struct_mutex);
901 if (ret)
902 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000903
904 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
905 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
906 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000907 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000908
Chris Wilson6c085a72012-08-20 11:40:46 +0200909 seq_printf(m, "Fence %d, pin count = %d, object = ",
910 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100911 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100912 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100913 else
Chris Wilson05394f32010-11-08 19:18:58 +0000914 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100915 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000916 }
917
Chris Wilson05394f32010-11-08 19:18:58 +0000918 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000919 return 0;
920}
921
Ben Gamari20172632009-02-17 20:08:50 -0500922static int i915_hws_info(struct seq_file *m, void *data)
923{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100924 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500925 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300926 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100927 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100928 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100929 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500930
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000931 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100932 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500933 if (hws == NULL)
934 return 0;
935
936 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
937 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
938 i * 4,
939 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
940 }
941 return 0;
942}
943
Daniel Vetterd5442302012-04-27 15:17:40 +0200944static ssize_t
945i915_error_state_write(struct file *filp,
946 const char __user *ubuf,
947 size_t cnt,
948 loff_t *ppos)
949{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300950 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200951 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200952 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200953
954 DRM_DEBUG_DRIVER("Resetting error state\n");
955
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200956 ret = mutex_lock_interruptible(&dev->struct_mutex);
957 if (ret)
958 return ret;
959
Daniel Vetterd5442302012-04-27 15:17:40 +0200960 i915_destroy_error_state(dev);
961 mutex_unlock(&dev->struct_mutex);
962
963 return cnt;
964}
965
966static int i915_error_state_open(struct inode *inode, struct file *file)
967{
968 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200969 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200970
971 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
972 if (!error_priv)
973 return -ENOMEM;
974
975 error_priv->dev = dev;
976
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300977 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200978
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300979 file->private_data = error_priv;
980
981 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200982}
983
984static int i915_error_state_release(struct inode *inode, struct file *file)
985{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300986 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200987
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300988 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200989 kfree(error_priv);
990
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300991 return 0;
992}
993
994static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
995 size_t count, loff_t *pos)
996{
997 struct i915_error_state_file_priv *error_priv = file->private_data;
998 struct drm_i915_error_state_buf error_str;
999 loff_t tmp_pos = 0;
1000 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001001 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001002
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001003 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001004 if (ret)
1005 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001006
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001007 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001008 if (ret)
1009 goto out;
1010
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001011 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1012 error_str.buf,
1013 error_str.bytes);
1014
1015 if (ret_count < 0)
1016 ret = ret_count;
1017 else
1018 *pos = error_str.start + ret_count;
1019out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001020 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001021 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001022}
1023
1024static const struct file_operations i915_error_state_fops = {
1025 .owner = THIS_MODULE,
1026 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001027 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001028 .write = i915_error_state_write,
1029 .llseek = default_llseek,
1030 .release = i915_error_state_release,
1031};
1032
Kees Cook647416f2013-03-10 14:10:06 -07001033static int
1034i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001035{
Kees Cook647416f2013-03-10 14:10:06 -07001036 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001037 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001038 int ret;
1039
1040 ret = mutex_lock_interruptible(&dev->struct_mutex);
1041 if (ret)
1042 return ret;
1043
Kees Cook647416f2013-03-10 14:10:06 -07001044 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001045 mutex_unlock(&dev->struct_mutex);
1046
Kees Cook647416f2013-03-10 14:10:06 -07001047 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001048}
1049
Kees Cook647416f2013-03-10 14:10:06 -07001050static int
1051i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001052{
Kees Cook647416f2013-03-10 14:10:06 -07001053 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001054 int ret;
1055
Mika Kuoppala40633212012-12-04 15:12:00 +02001056 ret = mutex_lock_interruptible(&dev->struct_mutex);
1057 if (ret)
1058 return ret;
1059
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001060 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001061 mutex_unlock(&dev->struct_mutex);
1062
Kees Cook647416f2013-03-10 14:10:06 -07001063 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001064}
1065
Kees Cook647416f2013-03-10 14:10:06 -07001066DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1067 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001068 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001069
Deepak Sadb4bd12014-03-31 11:30:02 +05301070static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001071{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001072 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001073 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001074 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001075 int ret = 0;
1076
1077 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001078
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001079 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1080
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001081 if (IS_GEN5(dev)) {
1082 u16 rgvswctl = I915_READ16(MEMSWCTL);
1083 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1084
1085 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1086 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1087 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1088 MEMSTAT_VID_SHIFT);
1089 seq_printf(m, "Current P-state: %d\n",
1090 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001091 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
1092 IS_BROADWELL(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001093 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1094 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1095 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001096 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001097 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001098 u32 rpupei, rpcurup, rpprevup;
1099 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001100 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001101 int max_freq;
1102
1103 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001104 ret = mutex_lock_interruptible(&dev->struct_mutex);
1105 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001106 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001107
Mika Kuoppala59bad942015-01-16 11:34:40 +02001108 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001109
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001110 reqf = I915_READ(GEN6_RPNSWREQ);
1111 reqf &= ~GEN6_TURBO_DISABLE;
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001112 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001113 reqf >>= 24;
1114 else
1115 reqf >>= 25;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001116 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001117
Chris Wilson0d8f9492014-03-27 09:06:14 +00001118 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1119 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1120 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1121
Jesse Barnesccab5c82011-01-18 15:49:25 -08001122 rpstat = I915_READ(GEN6_RPSTAT1);
1123 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1124 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1125 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1126 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1127 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1128 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001129 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001130 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1131 else
1132 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001133 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001134
Mika Kuoppala59bad942015-01-16 11:34:40 +02001135 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001136 mutex_unlock(&dev->struct_mutex);
1137
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001138 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1139 pm_ier = I915_READ(GEN6_PMIER);
1140 pm_imr = I915_READ(GEN6_PMIMR);
1141 pm_isr = I915_READ(GEN6_PMISR);
1142 pm_iir = I915_READ(GEN6_PMIIR);
1143 pm_mask = I915_READ(GEN6_PMINTRMSK);
1144 } else {
1145 pm_ier = I915_READ(GEN8_GT_IER(2));
1146 pm_imr = I915_READ(GEN8_GT_IMR(2));
1147 pm_isr = I915_READ(GEN8_GT_ISR(2));
1148 pm_iir = I915_READ(GEN8_GT_IIR(2));
1149 pm_mask = I915_READ(GEN6_PMINTRMSK);
1150 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001151 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 -03001152 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001153 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001154 seq_printf(m, "Render p-state ratio: %d\n",
1155 (gt_perf_status & 0xff00) >> 8);
1156 seq_printf(m, "Render p-state VID: %d\n",
1157 gt_perf_status & 0xff);
1158 seq_printf(m, "Render p-state limit: %d\n",
1159 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001160 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1161 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1162 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1163 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001164 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001165 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001166 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1167 GEN6_CURICONT_MASK);
1168 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1169 GEN6_CURBSYTAVG_MASK);
1170 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1171 GEN6_CURBSYTAVG_MASK);
1172 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1173 GEN6_CURIAVG_MASK);
1174 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1175 GEN6_CURBSYTAVG_MASK);
1176 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1177 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001178
1179 max_freq = (rp_state_cap & 0xff0000) >> 16;
1180 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001181 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001182
1183 max_freq = (rp_state_cap & 0xff00) >> 8;
1184 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001185 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001186
1187 max_freq = rp_state_cap & 0xff;
1188 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001189 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001190
1191 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001192 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001193 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001194 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001195
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001196 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001197 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001198 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1199 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1200
Jesse Barnes0a073b82013-04-17 15:54:58 -07001201 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001202 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001203
Jesse Barnes0a073b82013-04-17 15:54:58 -07001204 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001205 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001206
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001207 seq_printf(m,
1208 "efficient (RPe) frequency: %d MHz\n",
1209 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001210
1211 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001212 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001213 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001214 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001215 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001216 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001217
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001218out:
1219 intel_runtime_pm_put(dev_priv);
1220 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001221}
1222
Chris Wilsonf6544492015-01-26 18:03:04 +02001223static int i915_hangcheck_info(struct seq_file *m, void *unused)
1224{
1225 struct drm_info_node *node = m->private;
1226 struct drm_i915_private *dev_priv = to_i915(node->minor->dev);
1227 struct intel_engine_cs *ring;
1228 int i;
1229
1230 if (!i915.enable_hangcheck) {
1231 seq_printf(m, "Hangcheck disabled\n");
1232 return 0;
1233 }
1234
1235 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1236 seq_printf(m, "Hangcheck active, fires in %dms\n",
1237 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1238 jiffies));
1239 } else
1240 seq_printf(m, "Hangcheck inactive\n");
1241
1242 for_each_ring(ring, dev_priv, i) {
1243 seq_printf(m, "%s:\n", ring->name);
1244 seq_printf(m, "\tseqno = %x [current %x]\n",
1245 ring->hangcheck.seqno, ring->get_seqno(ring, false));
1246 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
1247 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1248 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1249 (long long)ring->hangcheck.acthd,
1250 (long long)intel_ring_get_active_head(ring));
1251 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1252 (long long)ring->hangcheck.max_acthd);
1253 }
1254
1255 return 0;
1256}
1257
Ben Widawsky4d855292011-12-12 19:34:16 -08001258static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001259{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001260 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001261 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001262 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001263 u32 rgvmodectl, rstdbyctl;
1264 u16 crstandvid;
1265 int ret;
1266
1267 ret = mutex_lock_interruptible(&dev->struct_mutex);
1268 if (ret)
1269 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001270 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001271
1272 rgvmodectl = I915_READ(MEMMODECTL);
1273 rstdbyctl = I915_READ(RSTDBYCTL);
1274 crstandvid = I915_READ16(CRSTANDVID);
1275
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001276 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001277 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001278
1279 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1280 "yes" : "no");
1281 seq_printf(m, "Boost freq: %d\n",
1282 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1283 MEMMODE_BOOST_FREQ_SHIFT);
1284 seq_printf(m, "HW control enabled: %s\n",
1285 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1286 seq_printf(m, "SW control enabled: %s\n",
1287 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1288 seq_printf(m, "Gated voltage change: %s\n",
1289 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1290 seq_printf(m, "Starting frequency: P%d\n",
1291 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001292 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001293 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001294 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1295 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1296 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1297 seq_printf(m, "Render standby enabled: %s\n",
1298 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001299 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001300 switch (rstdbyctl & RSX_STATUS_MASK) {
1301 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001302 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001303 break;
1304 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001305 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001306 break;
1307 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001308 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001309 break;
1310 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001311 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001312 break;
1313 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001314 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001315 break;
1316 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001317 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001318 break;
1319 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001320 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001321 break;
1322 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001323
1324 return 0;
1325}
1326
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001327static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001328{
1329 struct drm_info_node *node = m->private;
1330 struct drm_device *dev = node->minor->dev;
1331 struct drm_i915_private *dev_priv = dev->dev_private;
1332 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001333 int i;
1334
1335 spin_lock_irq(&dev_priv->uncore.lock);
1336 for_each_fw_domain(fw_domain, dev_priv, i) {
1337 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001338 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001339 fw_domain->wake_count);
1340 }
1341 spin_unlock_irq(&dev_priv->uncore.lock);
1342
1343 return 0;
1344}
1345
Deepak S669ab5a2014-01-10 15:18:26 +05301346static int vlv_drpc_info(struct seq_file *m)
1347{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001348 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301349 struct drm_device *dev = node->minor->dev;
1350 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001351 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301352
Imre Deakd46c0512014-04-14 20:24:27 +03001353 intel_runtime_pm_get(dev_priv);
1354
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001355 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301356 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1357 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1358
Imre Deakd46c0512014-04-14 20:24:27 +03001359 intel_runtime_pm_put(dev_priv);
1360
Deepak S669ab5a2014-01-10 15:18:26 +05301361 seq_printf(m, "Video Turbo Mode: %s\n",
1362 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1363 seq_printf(m, "Turbo enabled: %s\n",
1364 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1365 seq_printf(m, "HW control enabled: %s\n",
1366 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1367 seq_printf(m, "SW control enabled: %s\n",
1368 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1369 GEN6_RP_MEDIA_SW_MODE));
1370 seq_printf(m, "RC6 Enabled: %s\n",
1371 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1372 GEN6_RC_CTL_EI_MODE(1))));
1373 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001374 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301375 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001376 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301377
Imre Deak9cc19be2014-04-14 20:24:24 +03001378 seq_printf(m, "Render RC6 residency since boot: %u\n",
1379 I915_READ(VLV_GT_RENDER_RC6));
1380 seq_printf(m, "Media RC6 residency since boot: %u\n",
1381 I915_READ(VLV_GT_MEDIA_RC6));
1382
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001383 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301384}
1385
Ben Widawsky4d855292011-12-12 19:34:16 -08001386static int gen6_drpc_info(struct seq_file *m)
1387{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001388 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001389 struct drm_device *dev = node->minor->dev;
1390 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001391 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001392 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001393 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001394
1395 ret = mutex_lock_interruptible(&dev->struct_mutex);
1396 if (ret)
1397 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001398 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001399
Chris Wilson907b28c2013-07-19 20:36:52 +01001400 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001401 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001402 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001403
1404 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001405 seq_puts(m, "RC information inaccurate because somebody "
1406 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001407 } else {
1408 /* NB: we cannot use forcewake, else we read the wrong values */
1409 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1410 udelay(10);
1411 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1412 }
1413
1414 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001415 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001416
1417 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1418 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1419 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001420 mutex_lock(&dev_priv->rps.hw_lock);
1421 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1422 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001423
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001424 intel_runtime_pm_put(dev_priv);
1425
Ben Widawsky4d855292011-12-12 19:34:16 -08001426 seq_printf(m, "Video Turbo Mode: %s\n",
1427 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1428 seq_printf(m, "HW control enabled: %s\n",
1429 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1430 seq_printf(m, "SW control enabled: %s\n",
1431 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1432 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001433 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001434 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1435 seq_printf(m, "RC6 Enabled: %s\n",
1436 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1437 seq_printf(m, "Deep RC6 Enabled: %s\n",
1438 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1439 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1440 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001441 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001442 switch (gt_core_status & GEN6_RCn_MASK) {
1443 case GEN6_RC0:
1444 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001445 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001446 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001448 break;
1449 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001451 break;
1452 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001453 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001454 break;
1455 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001456 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001457 break;
1458 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001459 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001460 break;
1461 }
1462
1463 seq_printf(m, "Core Power Down: %s\n",
1464 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001465
1466 /* Not exactly sure what this is */
1467 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1468 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1469 seq_printf(m, "RC6 residency since boot: %u\n",
1470 I915_READ(GEN6_GT_GFX_RC6));
1471 seq_printf(m, "RC6+ residency since boot: %u\n",
1472 I915_READ(GEN6_GT_GFX_RC6p));
1473 seq_printf(m, "RC6++ residency since boot: %u\n",
1474 I915_READ(GEN6_GT_GFX_RC6pp));
1475
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001476 seq_printf(m, "RC6 voltage: %dmV\n",
1477 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1478 seq_printf(m, "RC6+ voltage: %dmV\n",
1479 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1480 seq_printf(m, "RC6++ voltage: %dmV\n",
1481 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001482 return 0;
1483}
1484
1485static int i915_drpc_info(struct seq_file *m, void *unused)
1486{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001487 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001488 struct drm_device *dev = node->minor->dev;
1489
Deepak S669ab5a2014-01-10 15:18:26 +05301490 if (IS_VALLEYVIEW(dev))
1491 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001492 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001493 return gen6_drpc_info(m);
1494 else
1495 return ironlake_drpc_info(m);
1496}
1497
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001498static int i915_fbc_status(struct seq_file *m, void *unused)
1499{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001500 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001501 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001502 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001503
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001504 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001505 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001506 return 0;
1507 }
1508
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001509 intel_runtime_pm_get(dev_priv);
1510
Adam Jacksonee5382a2010-04-23 11:17:39 -04001511 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001512 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001513 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001514 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001515 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001516 case FBC_OK:
1517 seq_puts(m, "FBC actived, but currently disabled in hardware");
1518 break;
1519 case FBC_UNSUPPORTED:
1520 seq_puts(m, "unsupported by this chipset");
1521 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001522 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001523 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001524 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001525 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001526 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001527 break;
1528 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001529 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001530 break;
1531 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001532 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001533 break;
1534 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001535 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001536 break;
1537 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001538 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001539 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001540 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001541 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001542 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001543 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001544 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001545 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001546 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001547 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001548 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001549 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001550 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001551 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001552 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001553 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001554
1555 intel_runtime_pm_put(dev_priv);
1556
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001557 return 0;
1558}
1559
Rodrigo Vivida46f932014-08-01 02:04:45 -07001560static int i915_fbc_fc_get(void *data, u64 *val)
1561{
1562 struct drm_device *dev = data;
1563 struct drm_i915_private *dev_priv = dev->dev_private;
1564
1565 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1566 return -ENODEV;
1567
1568 drm_modeset_lock_all(dev);
1569 *val = dev_priv->fbc.false_color;
1570 drm_modeset_unlock_all(dev);
1571
1572 return 0;
1573}
1574
1575static int i915_fbc_fc_set(void *data, u64 val)
1576{
1577 struct drm_device *dev = data;
1578 struct drm_i915_private *dev_priv = dev->dev_private;
1579 u32 reg;
1580
1581 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1582 return -ENODEV;
1583
1584 drm_modeset_lock_all(dev);
1585
1586 reg = I915_READ(ILK_DPFC_CONTROL);
1587 dev_priv->fbc.false_color = val;
1588
1589 I915_WRITE(ILK_DPFC_CONTROL, val ?
1590 (reg | FBC_CTL_FALSE_COLOR) :
1591 (reg & ~FBC_CTL_FALSE_COLOR));
1592
1593 drm_modeset_unlock_all(dev);
1594 return 0;
1595}
1596
1597DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1598 i915_fbc_fc_get, i915_fbc_fc_set,
1599 "%llu\n");
1600
Paulo Zanoni92d44622013-05-31 16:33:24 -03001601static int i915_ips_status(struct seq_file *m, void *unused)
1602{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001603 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001604 struct drm_device *dev = node->minor->dev;
1605 struct drm_i915_private *dev_priv = dev->dev_private;
1606
Damien Lespiauf5adf942013-06-24 18:29:34 +01001607 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001608 seq_puts(m, "not supported\n");
1609 return 0;
1610 }
1611
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001612 intel_runtime_pm_get(dev_priv);
1613
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001614 seq_printf(m, "Enabled by kernel parameter: %s\n",
1615 yesno(i915.enable_ips));
1616
1617 if (INTEL_INFO(dev)->gen >= 8) {
1618 seq_puts(m, "Currently: unknown\n");
1619 } else {
1620 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1621 seq_puts(m, "Currently: enabled\n");
1622 else
1623 seq_puts(m, "Currently: disabled\n");
1624 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001625
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001626 intel_runtime_pm_put(dev_priv);
1627
Paulo Zanoni92d44622013-05-31 16:33:24 -03001628 return 0;
1629}
1630
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001631static int i915_sr_status(struct seq_file *m, void *unused)
1632{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001633 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001634 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001635 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001636 bool sr_enabled = false;
1637
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001638 intel_runtime_pm_get(dev_priv);
1639
Yuanhan Liu13982612010-12-15 15:42:31 +08001640 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001641 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001642 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001643 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1644 else if (IS_I915GM(dev))
1645 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1646 else if (IS_PINEVIEW(dev))
1647 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1648
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001649 intel_runtime_pm_put(dev_priv);
1650
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001651 seq_printf(m, "self-refresh: %s\n",
1652 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001653
1654 return 0;
1655}
1656
Jesse Barnes7648fa92010-05-20 14:28:11 -07001657static int i915_emon_status(struct seq_file *m, void *unused)
1658{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001659 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001660 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001661 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001662 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001663 int ret;
1664
Chris Wilson582be6b2012-04-30 19:35:02 +01001665 if (!IS_GEN5(dev))
1666 return -ENODEV;
1667
Chris Wilsonde227ef2010-07-03 07:58:38 +01001668 ret = mutex_lock_interruptible(&dev->struct_mutex);
1669 if (ret)
1670 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001671
1672 temp = i915_mch_val(dev_priv);
1673 chipset = i915_chipset_val(dev_priv);
1674 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001675 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001676
1677 seq_printf(m, "GMCH temp: %ld\n", temp);
1678 seq_printf(m, "Chipset power: %ld\n", chipset);
1679 seq_printf(m, "GFX power: %ld\n", gfx);
1680 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1681
1682 return 0;
1683}
1684
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001685static int i915_ring_freq_table(struct seq_file *m, void *unused)
1686{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001687 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001688 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001689 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001690 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001691 int gpu_freq, ia_freq;
1692
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001693 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001694 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001695 return 0;
1696 }
1697
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001698 intel_runtime_pm_get(dev_priv);
1699
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001700 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1701
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001702 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001703 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001704 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001705
Damien Lespiau267f0c92013-06-24 22:59:48 +01001706 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001707
Ben Widawskyb39fb292014-03-19 18:31:11 -07001708 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1709 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001710 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001711 ia_freq = gpu_freq;
1712 sandybridge_pcode_read(dev_priv,
1713 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1714 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001715 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001716 intel_gpu_freq(dev_priv, gpu_freq),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001717 ((ia_freq >> 0) & 0xff) * 100,
1718 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001719 }
1720
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001721 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001722
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001723out:
1724 intel_runtime_pm_put(dev_priv);
1725 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001726}
1727
Chris Wilson44834a62010-08-19 16:09:23 +01001728static int i915_opregion(struct seq_file *m, void *unused)
1729{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001730 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001731 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001732 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001733 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001734 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001735 int ret;
1736
Daniel Vetter0d38f002012-04-21 22:49:10 +02001737 if (data == NULL)
1738 return -ENOMEM;
1739
Chris Wilson44834a62010-08-19 16:09:23 +01001740 ret = mutex_lock_interruptible(&dev->struct_mutex);
1741 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001742 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001743
Daniel Vetter0d38f002012-04-21 22:49:10 +02001744 if (opregion->header) {
1745 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1746 seq_write(m, data, OPREGION_SIZE);
1747 }
Chris Wilson44834a62010-08-19 16:09:23 +01001748
1749 mutex_unlock(&dev->struct_mutex);
1750
Daniel Vetter0d38f002012-04-21 22:49:10 +02001751out:
1752 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001753 return 0;
1754}
1755
Chris Wilson37811fc2010-08-25 22:45:57 +01001756static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1757{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001758 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001759 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001760 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001761 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001762
Daniel Vetter4520f532013-10-09 09:18:51 +02001763#ifdef CONFIG_DRM_I915_FBDEV
1764 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001765
1766 ifbdev = dev_priv->fbdev;
1767 fb = to_intel_framebuffer(ifbdev->helper.fb);
1768
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001769 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001770 fb->base.width,
1771 fb->base.height,
1772 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001773 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001774 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001775 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001776 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001777 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001778#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001779
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001780 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001781 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001782 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001783 continue;
1784
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001785 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001786 fb->base.width,
1787 fb->base.height,
1788 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001789 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001790 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001791 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001792 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001793 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001794 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001795 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001796
1797 return 0;
1798}
1799
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001800static void describe_ctx_ringbuf(struct seq_file *m,
1801 struct intel_ringbuffer *ringbuf)
1802{
1803 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1804 ringbuf->space, ringbuf->head, ringbuf->tail,
1805 ringbuf->last_retired_head);
1806}
1807
Ben Widawskye76d3632011-03-19 18:14:29 -07001808static int i915_context_status(struct seq_file *m, void *unused)
1809{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001810 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001811 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001812 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001813 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001814 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001815 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001816
Daniel Vetterf3d28872014-05-29 23:23:08 +02001817 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001818 if (ret)
1819 return ret;
1820
Daniel Vetter3e373942012-11-02 19:55:04 +01001821 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001822 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001823 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001824 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001825 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001826
Daniel Vetter3e373942012-11-02 19:55:04 +01001827 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001828 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001829 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001830 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001831 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001832
Ben Widawskya33afea2013-09-17 21:12:45 -07001833 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001834 if (!i915.enable_execlists &&
1835 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001836 continue;
1837
Ben Widawskya33afea2013-09-17 21:12:45 -07001838 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001839 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001840 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001841 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001842 seq_printf(m, "(default context %s) ",
1843 ring->name);
1844 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001845
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001846 if (i915.enable_execlists) {
1847 seq_putc(m, '\n');
1848 for_each_ring(ring, dev_priv, i) {
1849 struct drm_i915_gem_object *ctx_obj =
1850 ctx->engine[i].state;
1851 struct intel_ringbuffer *ringbuf =
1852 ctx->engine[i].ringbuf;
1853
1854 seq_printf(m, "%s: ", ring->name);
1855 if (ctx_obj)
1856 describe_obj(m, ctx_obj);
1857 if (ringbuf)
1858 describe_ctx_ringbuf(m, ringbuf);
1859 seq_putc(m, '\n');
1860 }
1861 } else {
1862 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1863 }
1864
Ben Widawskya33afea2013-09-17 21:12:45 -07001865 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001866 }
1867
Daniel Vetterf3d28872014-05-29 23:23:08 +02001868 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001869
1870 return 0;
1871}
1872
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001873static void i915_dump_lrc_obj(struct seq_file *m,
1874 struct intel_engine_cs *ring,
1875 struct drm_i915_gem_object *ctx_obj)
1876{
1877 struct page *page;
1878 uint32_t *reg_state;
1879 int j;
1880 unsigned long ggtt_offset = 0;
1881
1882 if (ctx_obj == NULL) {
1883 seq_printf(m, "Context on %s with no gem object\n",
1884 ring->name);
1885 return;
1886 }
1887
1888 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1889 intel_execlists_ctx_id(ctx_obj));
1890
1891 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1892 seq_puts(m, "\tNot bound in GGTT\n");
1893 else
1894 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1895
1896 if (i915_gem_object_get_pages(ctx_obj)) {
1897 seq_puts(m, "\tFailed to get pages for context object\n");
1898 return;
1899 }
1900
1901 page = i915_gem_object_get_page(ctx_obj, 1);
1902 if (!WARN_ON(page == NULL)) {
1903 reg_state = kmap_atomic(page);
1904
1905 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
1906 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1907 ggtt_offset + 4096 + (j * 4),
1908 reg_state[j], reg_state[j + 1],
1909 reg_state[j + 2], reg_state[j + 3]);
1910 }
1911 kunmap_atomic(reg_state);
1912 }
1913
1914 seq_putc(m, '\n');
1915}
1916
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01001917static int i915_dump_lrc(struct seq_file *m, void *unused)
1918{
1919 struct drm_info_node *node = (struct drm_info_node *) m->private;
1920 struct drm_device *dev = node->minor->dev;
1921 struct drm_i915_private *dev_priv = dev->dev_private;
1922 struct intel_engine_cs *ring;
1923 struct intel_context *ctx;
1924 int ret, i;
1925
1926 if (!i915.enable_execlists) {
1927 seq_printf(m, "Logical Ring Contexts are disabled\n");
1928 return 0;
1929 }
1930
1931 ret = mutex_lock_interruptible(&dev->struct_mutex);
1932 if (ret)
1933 return ret;
1934
1935 list_for_each_entry(ctx, &dev_priv->context_list, link) {
1936 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001937 if (ring->default_context != ctx)
1938 i915_dump_lrc_obj(m, ring,
1939 ctx->engine[i].state);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01001940 }
1941 }
1942
1943 mutex_unlock(&dev->struct_mutex);
1944
1945 return 0;
1946}
1947
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001948static int i915_execlists(struct seq_file *m, void *data)
1949{
1950 struct drm_info_node *node = (struct drm_info_node *)m->private;
1951 struct drm_device *dev = node->minor->dev;
1952 struct drm_i915_private *dev_priv = dev->dev_private;
1953 struct intel_engine_cs *ring;
1954 u32 status_pointer;
1955 u8 read_pointer;
1956 u8 write_pointer;
1957 u32 status;
1958 u32 ctx_id;
1959 struct list_head *cursor;
1960 int ring_id, i;
1961 int ret;
1962
1963 if (!i915.enable_execlists) {
1964 seq_puts(m, "Logical Ring Contexts are disabled\n");
1965 return 0;
1966 }
1967
1968 ret = mutex_lock_interruptible(&dev->struct_mutex);
1969 if (ret)
1970 return ret;
1971
Michel Thierryfc0412e2014-10-16 16:13:38 +01001972 intel_runtime_pm_get(dev_priv);
1973
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001974 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00001975 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001976 int count = 0;
1977 unsigned long flags;
1978
1979 seq_printf(m, "%s\n", ring->name);
1980
1981 status = I915_READ(RING_EXECLIST_STATUS(ring));
1982 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
1983 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
1984 status, ctx_id);
1985
1986 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
1987 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
1988
1989 read_pointer = ring->next_context_status_buffer;
1990 write_pointer = status_pointer & 0x07;
1991 if (read_pointer > write_pointer)
1992 write_pointer += 6;
1993 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
1994 read_pointer, write_pointer);
1995
1996 for (i = 0; i < 6; i++) {
1997 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
1998 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
1999
2000 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2001 i, status, ctx_id);
2002 }
2003
2004 spin_lock_irqsave(&ring->execlist_lock, flags);
2005 list_for_each(cursor, &ring->execlist_queue)
2006 count++;
2007 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002008 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002009 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2010
2011 seq_printf(m, "\t%d requests in queue\n", count);
2012 if (head_req) {
2013 struct drm_i915_gem_object *ctx_obj;
2014
Nick Hoath6d3d8272015-01-15 13:10:39 +00002015 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002016 seq_printf(m, "\tHead request id: %u\n",
2017 intel_execlists_ctx_id(ctx_obj));
2018 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002019 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002020 }
2021
2022 seq_putc(m, '\n');
2023 }
2024
Michel Thierryfc0412e2014-10-16 16:13:38 +01002025 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002026 mutex_unlock(&dev->struct_mutex);
2027
2028 return 0;
2029}
2030
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002031static const char *swizzle_string(unsigned swizzle)
2032{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002033 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002034 case I915_BIT_6_SWIZZLE_NONE:
2035 return "none";
2036 case I915_BIT_6_SWIZZLE_9:
2037 return "bit9";
2038 case I915_BIT_6_SWIZZLE_9_10:
2039 return "bit9/bit10";
2040 case I915_BIT_6_SWIZZLE_9_11:
2041 return "bit9/bit11";
2042 case I915_BIT_6_SWIZZLE_9_10_11:
2043 return "bit9/bit10/bit11";
2044 case I915_BIT_6_SWIZZLE_9_17:
2045 return "bit9/bit17";
2046 case I915_BIT_6_SWIZZLE_9_10_17:
2047 return "bit9/bit10/bit17";
2048 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002049 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002050 }
2051
2052 return "bug";
2053}
2054
2055static int i915_swizzle_info(struct seq_file *m, void *data)
2056{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002057 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002058 struct drm_device *dev = node->minor->dev;
2059 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002060 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002061
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002062 ret = mutex_lock_interruptible(&dev->struct_mutex);
2063 if (ret)
2064 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002065 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002066
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002067 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2068 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2069 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2070 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2071
2072 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2073 seq_printf(m, "DDC = 0x%08x\n",
2074 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002075 seq_printf(m, "DDC2 = 0x%08x\n",
2076 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002077 seq_printf(m, "C0DRB3 = 0x%04x\n",
2078 I915_READ16(C0DRB3));
2079 seq_printf(m, "C1DRB3 = 0x%04x\n",
2080 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002081 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002082 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2083 I915_READ(MAD_DIMM_C0));
2084 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2085 I915_READ(MAD_DIMM_C1));
2086 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2087 I915_READ(MAD_DIMM_C2));
2088 seq_printf(m, "TILECTL = 0x%08x\n",
2089 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002090 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002091 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2092 I915_READ(GAMTARBMODE));
2093 else
2094 seq_printf(m, "ARB_MODE = 0x%08x\n",
2095 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002096 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2097 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002098 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002099
2100 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2101 seq_puts(m, "L-shaped memory detected\n");
2102
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002103 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002104 mutex_unlock(&dev->struct_mutex);
2105
2106 return 0;
2107}
2108
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002109static int per_file_ctx(int id, void *ptr, void *data)
2110{
Oscar Mateo273497e2014-05-22 14:13:37 +01002111 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002112 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002113 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2114
2115 if (!ppgtt) {
2116 seq_printf(m, " no ppgtt for context %d\n",
2117 ctx->user_handle);
2118 return 0;
2119 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002120
Oscar Mateof83d6512014-05-22 14:13:38 +01002121 if (i915_gem_context_is_default(ctx))
2122 seq_puts(m, " default context:\n");
2123 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002124 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002125 ppgtt->debug_dump(ppgtt, m);
2126
2127 return 0;
2128}
2129
Ben Widawsky77df6772013-11-02 21:07:30 -07002130static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002131{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002132 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002133 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002134 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2135 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002136
Ben Widawsky77df6772013-11-02 21:07:30 -07002137 if (!ppgtt)
2138 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002139
Ben Widawsky77df6772013-11-02 21:07:30 -07002140 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08002141 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07002142 for_each_ring(ring, dev_priv, unused) {
2143 seq_printf(m, "%s\n", ring->name);
2144 for (i = 0; i < 4; i++) {
2145 u32 offset = 0x270 + i * 8;
2146 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2147 pdp <<= 32;
2148 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002149 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002150 }
2151 }
2152}
2153
2154static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2155{
2156 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002157 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002158 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002159 int i;
2160
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002161 if (INTEL_INFO(dev)->gen == 6)
2162 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2163
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002164 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002165 seq_printf(m, "%s\n", ring->name);
2166 if (INTEL_INFO(dev)->gen == 7)
2167 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2168 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2169 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2170 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2171 }
2172 if (dev_priv->mm.aliasing_ppgtt) {
2173 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2174
Damien Lespiau267f0c92013-06-24 22:59:48 +01002175 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002176 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002177
Ben Widawsky87d60b62013-12-06 14:11:29 -08002178 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002179 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002180
2181 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2182 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002183
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002184 seq_printf(m, "proc: %s\n",
2185 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002186 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002187 }
2188 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002189}
2190
2191static int i915_ppgtt_info(struct seq_file *m, void *data)
2192{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002193 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002194 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002195 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002196
2197 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2198 if (ret)
2199 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002200 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002201
2202 if (INTEL_INFO(dev)->gen >= 8)
2203 gen8_ppgtt_info(m, dev);
2204 else if (INTEL_INFO(dev)->gen >= 6)
2205 gen6_ppgtt_info(m, dev);
2206
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002207 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002208 mutex_unlock(&dev->struct_mutex);
2209
2210 return 0;
2211}
2212
Ben Widawsky63573eb2013-07-04 11:02:07 -07002213static int i915_llc(struct seq_file *m, void *data)
2214{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002215 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002216 struct drm_device *dev = node->minor->dev;
2217 struct drm_i915_private *dev_priv = dev->dev_private;
2218
2219 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2220 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2221 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2222
2223 return 0;
2224}
2225
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002226static int i915_edp_psr_status(struct seq_file *m, void *data)
2227{
2228 struct drm_info_node *node = m->private;
2229 struct drm_device *dev = node->minor->dev;
2230 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002231 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002232 u32 stat[3];
2233 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002234 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002235
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002236 intel_runtime_pm_get(dev_priv);
2237
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002238 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002239 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2240 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002241 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002242 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002243 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2244 dev_priv->psr.busy_frontbuffer_bits);
2245 seq_printf(m, "Re-enable work scheduled: %s\n",
2246 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002247
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002248 if (HAS_PSR(dev)) {
2249 if (HAS_DDI(dev))
2250 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2251 else {
2252 for_each_pipe(dev_priv, pipe) {
2253 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2254 VLV_EDP_PSR_CURR_STATE_MASK;
2255 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2256 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2257 enabled = true;
2258 }
2259 }
2260 }
2261 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002262
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002263 if (!HAS_DDI(dev))
2264 for_each_pipe(dev_priv, pipe) {
2265 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2266 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2267 seq_printf(m, " pipe %c", pipe_name(pipe));
2268 }
2269 seq_puts(m, "\n");
2270
Rodrigo Vivifb495812015-01-12 10:14:33 -08002271 seq_printf(m, "Link standby: %s\n",
2272 yesno((bool)dev_priv->psr.link_standby));
2273
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002274 /* CHV PSR has no kind of performance counter */
2275 if (HAS_PSR(dev) && HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002276 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2277 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002278
2279 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2280 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002281 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002282
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002283 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002284 return 0;
2285}
2286
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002287static int i915_sink_crc(struct seq_file *m, void *data)
2288{
2289 struct drm_info_node *node = m->private;
2290 struct drm_device *dev = node->minor->dev;
2291 struct intel_encoder *encoder;
2292 struct intel_connector *connector;
2293 struct intel_dp *intel_dp = NULL;
2294 int ret;
2295 u8 crc[6];
2296
2297 drm_modeset_lock_all(dev);
2298 list_for_each_entry(connector, &dev->mode_config.connector_list,
2299 base.head) {
2300
2301 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2302 continue;
2303
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002304 if (!connector->base.encoder)
2305 continue;
2306
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002307 encoder = to_intel_encoder(connector->base.encoder);
2308 if (encoder->type != INTEL_OUTPUT_EDP)
2309 continue;
2310
2311 intel_dp = enc_to_intel_dp(&encoder->base);
2312
2313 ret = intel_dp_sink_crc(intel_dp, crc);
2314 if (ret)
2315 goto out;
2316
2317 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2318 crc[0], crc[1], crc[2],
2319 crc[3], crc[4], crc[5]);
2320 goto out;
2321 }
2322 ret = -ENODEV;
2323out:
2324 drm_modeset_unlock_all(dev);
2325 return ret;
2326}
2327
Jesse Barnesec013e72013-08-20 10:29:23 +01002328static int i915_energy_uJ(struct seq_file *m, void *data)
2329{
2330 struct drm_info_node *node = m->private;
2331 struct drm_device *dev = node->minor->dev;
2332 struct drm_i915_private *dev_priv = dev->dev_private;
2333 u64 power;
2334 u32 units;
2335
2336 if (INTEL_INFO(dev)->gen < 6)
2337 return -ENODEV;
2338
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002339 intel_runtime_pm_get(dev_priv);
2340
Jesse Barnesec013e72013-08-20 10:29:23 +01002341 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2342 power = (power & 0x1f00) >> 8;
2343 units = 1000000 / (1 << power); /* convert to uJ */
2344 power = I915_READ(MCH_SECP_NRG_STTS);
2345 power *= units;
2346
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002347 intel_runtime_pm_put(dev_priv);
2348
Jesse Barnesec013e72013-08-20 10:29:23 +01002349 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002350
2351 return 0;
2352}
2353
2354static int i915_pc8_status(struct seq_file *m, void *unused)
2355{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002356 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002357 struct drm_device *dev = node->minor->dev;
2358 struct drm_i915_private *dev_priv = dev->dev_private;
2359
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002360 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002361 seq_puts(m, "not supported\n");
2362 return 0;
2363 }
2364
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002365 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002366 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002367 yesno(!intel_irqs_enabled(dev_priv)));
Paulo Zanoni371db662013-08-19 13:18:10 -03002368
Jesse Barnesec013e72013-08-20 10:29:23 +01002369 return 0;
2370}
2371
Imre Deak1da51582013-11-25 17:15:35 +02002372static const char *power_domain_str(enum intel_display_power_domain domain)
2373{
2374 switch (domain) {
2375 case POWER_DOMAIN_PIPE_A:
2376 return "PIPE_A";
2377 case POWER_DOMAIN_PIPE_B:
2378 return "PIPE_B";
2379 case POWER_DOMAIN_PIPE_C:
2380 return "PIPE_C";
2381 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2382 return "PIPE_A_PANEL_FITTER";
2383 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2384 return "PIPE_B_PANEL_FITTER";
2385 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2386 return "PIPE_C_PANEL_FITTER";
2387 case POWER_DOMAIN_TRANSCODER_A:
2388 return "TRANSCODER_A";
2389 case POWER_DOMAIN_TRANSCODER_B:
2390 return "TRANSCODER_B";
2391 case POWER_DOMAIN_TRANSCODER_C:
2392 return "TRANSCODER_C";
2393 case POWER_DOMAIN_TRANSCODER_EDP:
2394 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002395 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2396 return "PORT_DDI_A_2_LANES";
2397 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2398 return "PORT_DDI_A_4_LANES";
2399 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2400 return "PORT_DDI_B_2_LANES";
2401 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2402 return "PORT_DDI_B_4_LANES";
2403 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2404 return "PORT_DDI_C_2_LANES";
2405 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2406 return "PORT_DDI_C_4_LANES";
2407 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2408 return "PORT_DDI_D_2_LANES";
2409 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2410 return "PORT_DDI_D_4_LANES";
2411 case POWER_DOMAIN_PORT_DSI:
2412 return "PORT_DSI";
2413 case POWER_DOMAIN_PORT_CRT:
2414 return "PORT_CRT";
2415 case POWER_DOMAIN_PORT_OTHER:
2416 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002417 case POWER_DOMAIN_VGA:
2418 return "VGA";
2419 case POWER_DOMAIN_AUDIO:
2420 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002421 case POWER_DOMAIN_PLLS:
2422 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002423 case POWER_DOMAIN_AUX_A:
2424 return "AUX_A";
2425 case POWER_DOMAIN_AUX_B:
2426 return "AUX_B";
2427 case POWER_DOMAIN_AUX_C:
2428 return "AUX_C";
2429 case POWER_DOMAIN_AUX_D:
2430 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002431 case POWER_DOMAIN_INIT:
2432 return "INIT";
2433 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002434 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002435 return "?";
2436 }
2437}
2438
2439static int i915_power_domain_info(struct seq_file *m, void *unused)
2440{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002441 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002442 struct drm_device *dev = node->minor->dev;
2443 struct drm_i915_private *dev_priv = dev->dev_private;
2444 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2445 int i;
2446
2447 mutex_lock(&power_domains->lock);
2448
2449 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2450 for (i = 0; i < power_domains->power_well_count; i++) {
2451 struct i915_power_well *power_well;
2452 enum intel_display_power_domain power_domain;
2453
2454 power_well = &power_domains->power_wells[i];
2455 seq_printf(m, "%-25s %d\n", power_well->name,
2456 power_well->count);
2457
2458 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2459 power_domain++) {
2460 if (!(BIT(power_domain) & power_well->domains))
2461 continue;
2462
2463 seq_printf(m, " %-23s %d\n",
2464 power_domain_str(power_domain),
2465 power_domains->domain_use_count[power_domain]);
2466 }
2467 }
2468
2469 mutex_unlock(&power_domains->lock);
2470
2471 return 0;
2472}
2473
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002474static void intel_seq_print_mode(struct seq_file *m, int tabs,
2475 struct drm_display_mode *mode)
2476{
2477 int i;
2478
2479 for (i = 0; i < tabs; i++)
2480 seq_putc(m, '\t');
2481
2482 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",
2483 mode->base.id, mode->name,
2484 mode->vrefresh, mode->clock,
2485 mode->hdisplay, mode->hsync_start,
2486 mode->hsync_end, mode->htotal,
2487 mode->vdisplay, mode->vsync_start,
2488 mode->vsync_end, mode->vtotal,
2489 mode->type, mode->flags);
2490}
2491
2492static void intel_encoder_info(struct seq_file *m,
2493 struct intel_crtc *intel_crtc,
2494 struct intel_encoder *intel_encoder)
2495{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002496 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002497 struct drm_device *dev = node->minor->dev;
2498 struct drm_crtc *crtc = &intel_crtc->base;
2499 struct intel_connector *intel_connector;
2500 struct drm_encoder *encoder;
2501
2502 encoder = &intel_encoder->base;
2503 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002504 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002505 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2506 struct drm_connector *connector = &intel_connector->base;
2507 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2508 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002509 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002510 drm_get_connector_status_name(connector->status));
2511 if (connector->status == connector_status_connected) {
2512 struct drm_display_mode *mode = &crtc->mode;
2513 seq_printf(m, ", mode:\n");
2514 intel_seq_print_mode(m, 2, mode);
2515 } else {
2516 seq_putc(m, '\n');
2517 }
2518 }
2519}
2520
2521static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2522{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002523 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002524 struct drm_device *dev = node->minor->dev;
2525 struct drm_crtc *crtc = &intel_crtc->base;
2526 struct intel_encoder *intel_encoder;
2527
Matt Roper5aa8a932014-06-16 10:12:55 -07002528 if (crtc->primary->fb)
2529 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2530 crtc->primary->fb->base.id, crtc->x, crtc->y,
2531 crtc->primary->fb->width, crtc->primary->fb->height);
2532 else
2533 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002534 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2535 intel_encoder_info(m, intel_crtc, intel_encoder);
2536}
2537
2538static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2539{
2540 struct drm_display_mode *mode = panel->fixed_mode;
2541
2542 seq_printf(m, "\tfixed mode:\n");
2543 intel_seq_print_mode(m, 2, mode);
2544}
2545
2546static void intel_dp_info(struct seq_file *m,
2547 struct intel_connector *intel_connector)
2548{
2549 struct intel_encoder *intel_encoder = intel_connector->encoder;
2550 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2551
2552 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2553 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2554 "no");
2555 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2556 intel_panel_info(m, &intel_connector->panel);
2557}
2558
2559static void intel_hdmi_info(struct seq_file *m,
2560 struct intel_connector *intel_connector)
2561{
2562 struct intel_encoder *intel_encoder = intel_connector->encoder;
2563 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2564
2565 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2566 "no");
2567}
2568
2569static void intel_lvds_info(struct seq_file *m,
2570 struct intel_connector *intel_connector)
2571{
2572 intel_panel_info(m, &intel_connector->panel);
2573}
2574
2575static void intel_connector_info(struct seq_file *m,
2576 struct drm_connector *connector)
2577{
2578 struct intel_connector *intel_connector = to_intel_connector(connector);
2579 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002580 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002581
2582 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002583 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002584 drm_get_connector_status_name(connector->status));
2585 if (connector->status == connector_status_connected) {
2586 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2587 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2588 connector->display_info.width_mm,
2589 connector->display_info.height_mm);
2590 seq_printf(m, "\tsubpixel order: %s\n",
2591 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2592 seq_printf(m, "\tCEA rev: %d\n",
2593 connector->display_info.cea_rev);
2594 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002595 if (intel_encoder) {
2596 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2597 intel_encoder->type == INTEL_OUTPUT_EDP)
2598 intel_dp_info(m, intel_connector);
2599 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2600 intel_hdmi_info(m, intel_connector);
2601 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2602 intel_lvds_info(m, intel_connector);
2603 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002604
Jesse Barnesf103fc72014-02-20 12:39:57 -08002605 seq_printf(m, "\tmodes:\n");
2606 list_for_each_entry(mode, &connector->modes, head)
2607 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002608}
2609
Chris Wilson065f2ec22014-03-12 09:13:13 +00002610static bool cursor_active(struct drm_device *dev, int pipe)
2611{
2612 struct drm_i915_private *dev_priv = dev->dev_private;
2613 u32 state;
2614
2615 if (IS_845G(dev) || IS_I865G(dev))
2616 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002617 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002618 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002619
2620 return state;
2621}
2622
2623static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2624{
2625 struct drm_i915_private *dev_priv = dev->dev_private;
2626 u32 pos;
2627
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002628 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00002629
2630 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2631 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2632 *x = -*x;
2633
2634 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2635 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2636 *y = -*y;
2637
2638 return cursor_active(dev, pipe);
2639}
2640
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002641static int i915_display_info(struct seq_file *m, void *unused)
2642{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002643 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002644 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002645 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002646 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002647 struct drm_connector *connector;
2648
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002649 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002650 drm_modeset_lock_all(dev);
2651 seq_printf(m, "CRTC info\n");
2652 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002653 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002654 bool active;
2655 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002656
Chris Wilson57127ef2014-07-04 08:20:11 +01002657 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00002658 crtc->base.base.id, pipe_name(crtc->pipe),
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002659 yesno(crtc->active), crtc->config->pipe_src_w,
2660 crtc->config->pipe_src_h);
Paulo Zanonia23dc652014-04-01 14:55:11 -03002661 if (crtc->active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002662 intel_crtc_info(m, crtc);
2663
Paulo Zanonia23dc652014-04-01 14:55:11 -03002664 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002665 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 +03002666 yesno(crtc->cursor_base),
Chris Wilson57127ef2014-07-04 08:20:11 +01002667 x, y, crtc->cursor_width, crtc->cursor_height,
2668 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002669 }
Daniel Vettercace8412014-05-22 17:56:31 +02002670
2671 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2672 yesno(!crtc->cpu_fifo_underrun_disabled),
2673 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002674 }
2675
2676 seq_printf(m, "\n");
2677 seq_printf(m, "Connector info\n");
2678 seq_printf(m, "--------------\n");
2679 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2680 intel_connector_info(m, connector);
2681 }
2682 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002683 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002684
2685 return 0;
2686}
2687
Ben Widawskye04934c2014-06-30 09:53:42 -07002688static int i915_semaphore_status(struct seq_file *m, void *unused)
2689{
2690 struct drm_info_node *node = (struct drm_info_node *) m->private;
2691 struct drm_device *dev = node->minor->dev;
2692 struct drm_i915_private *dev_priv = dev->dev_private;
2693 struct intel_engine_cs *ring;
2694 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2695 int i, j, ret;
2696
2697 if (!i915_semaphore_is_enabled(dev)) {
2698 seq_puts(m, "Semaphores are disabled\n");
2699 return 0;
2700 }
2701
2702 ret = mutex_lock_interruptible(&dev->struct_mutex);
2703 if (ret)
2704 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002705 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002706
2707 if (IS_BROADWELL(dev)) {
2708 struct page *page;
2709 uint64_t *seqno;
2710
2711 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2712
2713 seqno = (uint64_t *)kmap_atomic(page);
2714 for_each_ring(ring, dev_priv, i) {
2715 uint64_t offset;
2716
2717 seq_printf(m, "%s\n", ring->name);
2718
2719 seq_puts(m, " Last signal:");
2720 for (j = 0; j < num_rings; j++) {
2721 offset = i * I915_NUM_RINGS + j;
2722 seq_printf(m, "0x%08llx (0x%02llx) ",
2723 seqno[offset], offset * 8);
2724 }
2725 seq_putc(m, '\n');
2726
2727 seq_puts(m, " Last wait: ");
2728 for (j = 0; j < num_rings; j++) {
2729 offset = i + (j * I915_NUM_RINGS);
2730 seq_printf(m, "0x%08llx (0x%02llx) ",
2731 seqno[offset], offset * 8);
2732 }
2733 seq_putc(m, '\n');
2734
2735 }
2736 kunmap_atomic(seqno);
2737 } else {
2738 seq_puts(m, " Last signal:");
2739 for_each_ring(ring, dev_priv, i)
2740 for (j = 0; j < num_rings; j++)
2741 seq_printf(m, "0x%08x\n",
2742 I915_READ(ring->semaphore.mbox.signal[j]));
2743 seq_putc(m, '\n');
2744 }
2745
2746 seq_puts(m, "\nSync seqno:\n");
2747 for_each_ring(ring, dev_priv, i) {
2748 for (j = 0; j < num_rings; j++) {
2749 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2750 }
2751 seq_putc(m, '\n');
2752 }
2753 seq_putc(m, '\n');
2754
Paulo Zanoni03872062014-07-09 14:31:57 -03002755 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002756 mutex_unlock(&dev->struct_mutex);
2757 return 0;
2758}
2759
Daniel Vetter728e29d2014-06-25 22:01:53 +03002760static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2761{
2762 struct drm_info_node *node = (struct drm_info_node *) m->private;
2763 struct drm_device *dev = node->minor->dev;
2764 struct drm_i915_private *dev_priv = dev->dev_private;
2765 int i;
2766
2767 drm_modeset_lock_all(dev);
2768 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2769 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2770
2771 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002772 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002773 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03002774 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002775 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2776 seq_printf(m, " dpll_md: 0x%08x\n",
2777 pll->config.hw_state.dpll_md);
2778 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2779 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2780 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002781 }
2782 drm_modeset_unlock_all(dev);
2783
2784 return 0;
2785}
2786
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01002787static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01002788{
2789 int i;
2790 int ret;
2791 struct drm_info_node *node = (struct drm_info_node *) m->private;
2792 struct drm_device *dev = node->minor->dev;
2793 struct drm_i915_private *dev_priv = dev->dev_private;
2794
Arun Siluvery888b5992014-08-26 14:44:51 +01002795 ret = mutex_lock_interruptible(&dev->struct_mutex);
2796 if (ret)
2797 return ret;
2798
2799 intel_runtime_pm_get(dev_priv);
2800
Mika Kuoppala72253422014-10-07 17:21:26 +03002801 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
2802 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002803 u32 addr, mask, value, read;
2804 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01002805
Mika Kuoppala72253422014-10-07 17:21:26 +03002806 addr = dev_priv->workarounds.reg[i].addr;
2807 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002808 value = dev_priv->workarounds.reg[i].value;
2809 read = I915_READ(addr);
2810 ok = (value & mask) == (read & mask);
2811 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
2812 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01002813 }
2814
2815 intel_runtime_pm_put(dev_priv);
2816 mutex_unlock(&dev->struct_mutex);
2817
2818 return 0;
2819}
2820
Damien Lespiauc5511e42014-11-04 17:06:51 +00002821static int i915_ddb_info(struct seq_file *m, void *unused)
2822{
2823 struct drm_info_node *node = m->private;
2824 struct drm_device *dev = node->minor->dev;
2825 struct drm_i915_private *dev_priv = dev->dev_private;
2826 struct skl_ddb_allocation *ddb;
2827 struct skl_ddb_entry *entry;
2828 enum pipe pipe;
2829 int plane;
2830
Damien Lespiau2fcffe12014-12-03 17:33:24 +00002831 if (INTEL_INFO(dev)->gen < 9)
2832 return 0;
2833
Damien Lespiauc5511e42014-11-04 17:06:51 +00002834 drm_modeset_lock_all(dev);
2835
2836 ddb = &dev_priv->wm.skl_hw.ddb;
2837
2838 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
2839
2840 for_each_pipe(dev_priv, pipe) {
2841 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
2842
2843 for_each_plane(pipe, plane) {
2844 entry = &ddb->plane[pipe][plane];
2845 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
2846 entry->start, entry->end,
2847 skl_ddb_entry_size(entry));
2848 }
2849
2850 entry = &ddb->cursor[pipe];
2851 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
2852 entry->end, skl_ddb_entry_size(entry));
2853 }
2854
2855 drm_modeset_unlock_all(dev);
2856
2857 return 0;
2858}
2859
Damien Lespiau07144422013-10-15 18:55:40 +01002860struct pipe_crc_info {
2861 const char *name;
2862 struct drm_device *dev;
2863 enum pipe pipe;
2864};
2865
Dave Airlie11bed952014-05-12 15:22:27 +10002866static int i915_dp_mst_info(struct seq_file *m, void *unused)
2867{
2868 struct drm_info_node *node = (struct drm_info_node *) m->private;
2869 struct drm_device *dev = node->minor->dev;
2870 struct drm_encoder *encoder;
2871 struct intel_encoder *intel_encoder;
2872 struct intel_digital_port *intel_dig_port;
2873 drm_modeset_lock_all(dev);
2874 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2875 intel_encoder = to_intel_encoder(encoder);
2876 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
2877 continue;
2878 intel_dig_port = enc_to_dig_port(encoder);
2879 if (!intel_dig_port->dp.can_mst)
2880 continue;
2881
2882 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
2883 }
2884 drm_modeset_unlock_all(dev);
2885 return 0;
2886}
2887
Damien Lespiau07144422013-10-15 18:55:40 +01002888static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01002889{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002890 struct pipe_crc_info *info = inode->i_private;
2891 struct drm_i915_private *dev_priv = info->dev->dev_private;
2892 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2893
Daniel Vetter7eb1c492013-11-14 11:30:43 +01002894 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
2895 return -ENODEV;
2896
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002897 spin_lock_irq(&pipe_crc->lock);
2898
2899 if (pipe_crc->opened) {
2900 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002901 return -EBUSY; /* already open */
2902 }
2903
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002904 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01002905 filep->private_data = inode->i_private;
2906
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002907 spin_unlock_irq(&pipe_crc->lock);
2908
Damien Lespiau07144422013-10-15 18:55:40 +01002909 return 0;
2910}
2911
2912static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
2913{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002914 struct pipe_crc_info *info = inode->i_private;
2915 struct drm_i915_private *dev_priv = info->dev->dev_private;
2916 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2917
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002918 spin_lock_irq(&pipe_crc->lock);
2919 pipe_crc->opened = false;
2920 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002921
Damien Lespiau07144422013-10-15 18:55:40 +01002922 return 0;
2923}
2924
2925/* (6 fields, 8 chars each, space separated (5) + '\n') */
2926#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
2927/* account for \'0' */
2928#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
2929
2930static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
2931{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002932 assert_spin_locked(&pipe_crc->lock);
2933 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2934 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01002935}
Shuang He8bf1e9f2013-10-15 18:55:27 +01002936
Damien Lespiau07144422013-10-15 18:55:40 +01002937static ssize_t
2938i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
2939 loff_t *pos)
2940{
2941 struct pipe_crc_info *info = filep->private_data;
2942 struct drm_device *dev = info->dev;
2943 struct drm_i915_private *dev_priv = dev->dev_private;
2944 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2945 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002946 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01002947 ssize_t bytes_read;
2948
2949 /*
2950 * Don't allow user space to provide buffers not big enough to hold
2951 * a line of data.
2952 */
2953 if (count < PIPE_CRC_LINE_LEN)
2954 return -EINVAL;
2955
2956 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2957 return 0;
2958
2959 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002960 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002961 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002962 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002963
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002964 if (filep->f_flags & O_NONBLOCK) {
2965 spin_unlock_irq(&pipe_crc->lock);
2966 return -EAGAIN;
2967 }
2968
2969 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2970 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2971 if (ret) {
2972 spin_unlock_irq(&pipe_crc->lock);
2973 return ret;
2974 }
Damien Lespiau07144422013-10-15 18:55:40 +01002975 }
2976
2977 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002978 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002979
Damien Lespiau07144422013-10-15 18:55:40 +01002980 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002981 while (n_entries > 0) {
2982 struct intel_pipe_crc_entry *entry =
2983 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01002984 int ret;
2985
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002986 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2987 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
2988 break;
2989
2990 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
2991 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
2992
Damien Lespiau07144422013-10-15 18:55:40 +01002993 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
2994 "%8u %8x %8x %8x %8x %8x\n",
2995 entry->frame, entry->crc[0],
2996 entry->crc[1], entry->crc[2],
2997 entry->crc[3], entry->crc[4]);
2998
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002999 spin_unlock_irq(&pipe_crc->lock);
3000
3001 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003002 if (ret == PIPE_CRC_LINE_LEN)
3003 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003004
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003005 user_buf += PIPE_CRC_LINE_LEN;
3006 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003007
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003008 spin_lock_irq(&pipe_crc->lock);
3009 }
3010
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003011 spin_unlock_irq(&pipe_crc->lock);
3012
Damien Lespiau07144422013-10-15 18:55:40 +01003013 return bytes_read;
3014}
3015
3016static const struct file_operations i915_pipe_crc_fops = {
3017 .owner = THIS_MODULE,
3018 .open = i915_pipe_crc_open,
3019 .read = i915_pipe_crc_read,
3020 .release = i915_pipe_crc_release,
3021};
3022
3023static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3024 {
3025 .name = "i915_pipe_A_crc",
3026 .pipe = PIPE_A,
3027 },
3028 {
3029 .name = "i915_pipe_B_crc",
3030 .pipe = PIPE_B,
3031 },
3032 {
3033 .name = "i915_pipe_C_crc",
3034 .pipe = PIPE_C,
3035 },
3036};
3037
3038static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3039 enum pipe pipe)
3040{
3041 struct drm_device *dev = minor->dev;
3042 struct dentry *ent;
3043 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3044
3045 info->dev = dev;
3046 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3047 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003048 if (!ent)
3049 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003050
3051 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003052}
3053
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003054static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003055 "none",
3056 "plane1",
3057 "plane2",
3058 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003059 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003060 "TV",
3061 "DP-B",
3062 "DP-C",
3063 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003064 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003065};
3066
3067static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3068{
3069 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3070 return pipe_crc_sources[source];
3071}
3072
Damien Lespiaubd9db022013-10-15 18:55:36 +01003073static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003074{
3075 struct drm_device *dev = m->private;
3076 struct drm_i915_private *dev_priv = dev->dev_private;
3077 int i;
3078
3079 for (i = 0; i < I915_MAX_PIPES; i++)
3080 seq_printf(m, "%c %s\n", pipe_name(i),
3081 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3082
3083 return 0;
3084}
3085
Damien Lespiaubd9db022013-10-15 18:55:36 +01003086static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003087{
3088 struct drm_device *dev = inode->i_private;
3089
Damien Lespiaubd9db022013-10-15 18:55:36 +01003090 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003091}
3092
Daniel Vetter46a19182013-11-01 10:50:20 +01003093static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003094 uint32_t *val)
3095{
Daniel Vetter46a19182013-11-01 10:50:20 +01003096 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3097 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3098
3099 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003100 case INTEL_PIPE_CRC_SOURCE_PIPE:
3101 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3102 break;
3103 case INTEL_PIPE_CRC_SOURCE_NONE:
3104 *val = 0;
3105 break;
3106 default:
3107 return -EINVAL;
3108 }
3109
3110 return 0;
3111}
3112
Daniel Vetter46a19182013-11-01 10:50:20 +01003113static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3114 enum intel_pipe_crc_source *source)
3115{
3116 struct intel_encoder *encoder;
3117 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003118 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003119 int ret = 0;
3120
3121 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3122
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003123 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003124 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003125 if (!encoder->base.crtc)
3126 continue;
3127
3128 crtc = to_intel_crtc(encoder->base.crtc);
3129
3130 if (crtc->pipe != pipe)
3131 continue;
3132
3133 switch (encoder->type) {
3134 case INTEL_OUTPUT_TVOUT:
3135 *source = INTEL_PIPE_CRC_SOURCE_TV;
3136 break;
3137 case INTEL_OUTPUT_DISPLAYPORT:
3138 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003139 dig_port = enc_to_dig_port(&encoder->base);
3140 switch (dig_port->port) {
3141 case PORT_B:
3142 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3143 break;
3144 case PORT_C:
3145 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3146 break;
3147 case PORT_D:
3148 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3149 break;
3150 default:
3151 WARN(1, "nonexisting DP port %c\n",
3152 port_name(dig_port->port));
3153 break;
3154 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003155 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003156 default:
3157 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003158 }
3159 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003160 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003161
3162 return ret;
3163}
3164
3165static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3166 enum pipe pipe,
3167 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003168 uint32_t *val)
3169{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003170 struct drm_i915_private *dev_priv = dev->dev_private;
3171 bool need_stable_symbols = false;
3172
Daniel Vetter46a19182013-11-01 10:50:20 +01003173 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3174 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3175 if (ret)
3176 return ret;
3177 }
3178
3179 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003180 case INTEL_PIPE_CRC_SOURCE_PIPE:
3181 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3182 break;
3183 case INTEL_PIPE_CRC_SOURCE_DP_B:
3184 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003185 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003186 break;
3187 case INTEL_PIPE_CRC_SOURCE_DP_C:
3188 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003189 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003190 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003191 case INTEL_PIPE_CRC_SOURCE_DP_D:
3192 if (!IS_CHERRYVIEW(dev))
3193 return -EINVAL;
3194 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3195 need_stable_symbols = true;
3196 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003197 case INTEL_PIPE_CRC_SOURCE_NONE:
3198 *val = 0;
3199 break;
3200 default:
3201 return -EINVAL;
3202 }
3203
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003204 /*
3205 * When the pipe CRC tap point is after the transcoders we need
3206 * to tweak symbol-level features to produce a deterministic series of
3207 * symbols for a given frame. We need to reset those features only once
3208 * a frame (instead of every nth symbol):
3209 * - DC-balance: used to ensure a better clock recovery from the data
3210 * link (SDVO)
3211 * - DisplayPort scrambling: used for EMI reduction
3212 */
3213 if (need_stable_symbols) {
3214 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3215
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003216 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003217 switch (pipe) {
3218 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003219 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003220 break;
3221 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003222 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003223 break;
3224 case PIPE_C:
3225 tmp |= PIPE_C_SCRAMBLE_RESET;
3226 break;
3227 default:
3228 return -EINVAL;
3229 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003230 I915_WRITE(PORT_DFT2_G4X, tmp);
3231 }
3232
Daniel Vetter7ac01292013-10-18 16:37:06 +02003233 return 0;
3234}
3235
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003236static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003237 enum pipe pipe,
3238 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003239 uint32_t *val)
3240{
Daniel Vetter84093602013-11-01 10:50:21 +01003241 struct drm_i915_private *dev_priv = dev->dev_private;
3242 bool need_stable_symbols = false;
3243
Daniel Vetter46a19182013-11-01 10:50:20 +01003244 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3245 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3246 if (ret)
3247 return ret;
3248 }
3249
3250 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003251 case INTEL_PIPE_CRC_SOURCE_PIPE:
3252 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3253 break;
3254 case INTEL_PIPE_CRC_SOURCE_TV:
3255 if (!SUPPORTS_TV(dev))
3256 return -EINVAL;
3257 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3258 break;
3259 case INTEL_PIPE_CRC_SOURCE_DP_B:
3260 if (!IS_G4X(dev))
3261 return -EINVAL;
3262 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003263 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003264 break;
3265 case INTEL_PIPE_CRC_SOURCE_DP_C:
3266 if (!IS_G4X(dev))
3267 return -EINVAL;
3268 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003269 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003270 break;
3271 case INTEL_PIPE_CRC_SOURCE_DP_D:
3272 if (!IS_G4X(dev))
3273 return -EINVAL;
3274 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003275 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003276 break;
3277 case INTEL_PIPE_CRC_SOURCE_NONE:
3278 *val = 0;
3279 break;
3280 default:
3281 return -EINVAL;
3282 }
3283
Daniel Vetter84093602013-11-01 10:50:21 +01003284 /*
3285 * When the pipe CRC tap point is after the transcoders we need
3286 * to tweak symbol-level features to produce a deterministic series of
3287 * symbols for a given frame. We need to reset those features only once
3288 * a frame (instead of every nth symbol):
3289 * - DC-balance: used to ensure a better clock recovery from the data
3290 * link (SDVO)
3291 * - DisplayPort scrambling: used for EMI reduction
3292 */
3293 if (need_stable_symbols) {
3294 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3295
3296 WARN_ON(!IS_G4X(dev));
3297
3298 I915_WRITE(PORT_DFT_I9XX,
3299 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3300
3301 if (pipe == PIPE_A)
3302 tmp |= PIPE_A_SCRAMBLE_RESET;
3303 else
3304 tmp |= PIPE_B_SCRAMBLE_RESET;
3305
3306 I915_WRITE(PORT_DFT2_G4X, tmp);
3307 }
3308
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003309 return 0;
3310}
3311
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003312static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3313 enum pipe pipe)
3314{
3315 struct drm_i915_private *dev_priv = dev->dev_private;
3316 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3317
Ville Syrjäläeb736672014-12-09 21:28:28 +02003318 switch (pipe) {
3319 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003320 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003321 break;
3322 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003323 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003324 break;
3325 case PIPE_C:
3326 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3327 break;
3328 default:
3329 return;
3330 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003331 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3332 tmp &= ~DC_BALANCE_RESET_VLV;
3333 I915_WRITE(PORT_DFT2_G4X, tmp);
3334
3335}
3336
Daniel Vetter84093602013-11-01 10:50:21 +01003337static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3338 enum pipe pipe)
3339{
3340 struct drm_i915_private *dev_priv = dev->dev_private;
3341 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3342
3343 if (pipe == PIPE_A)
3344 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3345 else
3346 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3347 I915_WRITE(PORT_DFT2_G4X, tmp);
3348
3349 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3350 I915_WRITE(PORT_DFT_I9XX,
3351 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3352 }
3353}
3354
Daniel Vetter46a19182013-11-01 10:50:20 +01003355static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003356 uint32_t *val)
3357{
Daniel Vetter46a19182013-11-01 10:50:20 +01003358 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3359 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3360
3361 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003362 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3363 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3364 break;
3365 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3366 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3367 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003368 case INTEL_PIPE_CRC_SOURCE_PIPE:
3369 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3370 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003371 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003372 *val = 0;
3373 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003374 default:
3375 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003376 }
3377
3378 return 0;
3379}
3380
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003381static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3382{
3383 struct drm_i915_private *dev_priv = dev->dev_private;
3384 struct intel_crtc *crtc =
3385 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3386
3387 drm_modeset_lock_all(dev);
3388 /*
3389 * If we use the eDP transcoder we need to make sure that we don't
3390 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3391 * relevant on hsw with pipe A when using the always-on power well
3392 * routing.
3393 */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02003394 if (crtc->config->cpu_transcoder == TRANSCODER_EDP &&
3395 !crtc->config->pch_pfit.enabled) {
3396 crtc->config->pch_pfit.force_thru = true;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003397
3398 intel_display_power_get(dev_priv,
3399 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3400
3401 dev_priv->display.crtc_disable(&crtc->base);
3402 dev_priv->display.crtc_enable(&crtc->base);
3403 }
3404 drm_modeset_unlock_all(dev);
3405}
3406
3407static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3408{
3409 struct drm_i915_private *dev_priv = dev->dev_private;
3410 struct intel_crtc *crtc =
3411 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3412
3413 drm_modeset_lock_all(dev);
3414 /*
3415 * If we use the eDP transcoder we need to make sure that we don't
3416 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3417 * relevant on hsw with pipe A when using the always-on power well
3418 * routing.
3419 */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02003420 if (crtc->config->pch_pfit.force_thru) {
3421 crtc->config->pch_pfit.force_thru = false;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003422
3423 dev_priv->display.crtc_disable(&crtc->base);
3424 dev_priv->display.crtc_enable(&crtc->base);
3425
3426 intel_display_power_put(dev_priv,
3427 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3428 }
3429 drm_modeset_unlock_all(dev);
3430}
3431
3432static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3433 enum pipe pipe,
3434 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003435 uint32_t *val)
3436{
Daniel Vetter46a19182013-11-01 10:50:20 +01003437 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3438 *source = INTEL_PIPE_CRC_SOURCE_PF;
3439
3440 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003441 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3442 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3443 break;
3444 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3445 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3446 break;
3447 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003448 if (IS_HASWELL(dev) && pipe == PIPE_A)
3449 hsw_trans_edp_pipe_A_crc_wa(dev);
3450
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003451 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3452 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003453 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003454 *val = 0;
3455 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003456 default:
3457 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003458 }
3459
3460 return 0;
3461}
3462
Daniel Vetter926321d2013-10-16 13:30:34 +02003463static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3464 enum intel_pipe_crc_source source)
3465{
3466 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003467 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003468 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3469 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003470 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003471 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003472
Damien Lespiaucc3da172013-10-15 18:55:31 +01003473 if (pipe_crc->source == source)
3474 return 0;
3475
Damien Lespiauae676fc2013-10-15 18:55:32 +01003476 /* forbid changing the source without going back to 'none' */
3477 if (pipe_crc->source && source)
3478 return -EINVAL;
3479
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003480 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3481 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3482 return -EIO;
3483 }
3484
Daniel Vetter52f843f2013-10-21 17:26:38 +02003485 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003486 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003487 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003488 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003489 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003490 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003491 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003492 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003493 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003494 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003495
3496 if (ret != 0)
3497 return ret;
3498
Damien Lespiau4b584362013-10-15 18:55:33 +01003499 /* none -> real source transition */
3500 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003501 struct intel_pipe_crc_entry *entries;
3502
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003503 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3504 pipe_name(pipe), pipe_crc_source_name(source));
3505
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003506 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3507 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003508 GFP_KERNEL);
3509 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003510 return -ENOMEM;
3511
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003512 /*
3513 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3514 * enabled and disabled dynamically based on package C states,
3515 * user space can't make reliable use of the CRCs, so let's just
3516 * completely disable it.
3517 */
3518 hsw_disable_ips(crtc);
3519
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003520 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003521 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003522 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003523 pipe_crc->head = 0;
3524 pipe_crc->tail = 0;
3525 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003526 }
3527
Damien Lespiaucc3da172013-10-15 18:55:31 +01003528 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003529
Daniel Vetter926321d2013-10-16 13:30:34 +02003530 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3531 POSTING_READ(PIPE_CRC_CTL(pipe));
3532
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003533 /* real source -> none transition */
3534 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003535 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003536 struct intel_crtc *crtc =
3537 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003538
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003539 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3540 pipe_name(pipe));
3541
Daniel Vettera33d7102014-06-06 08:22:08 +02003542 drm_modeset_lock(&crtc->base.mutex, NULL);
3543 if (crtc->active)
3544 intel_wait_for_vblank(dev, pipe);
3545 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003546
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003547 spin_lock_irq(&pipe_crc->lock);
3548 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003549 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003550 pipe_crc->head = 0;
3551 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003552 spin_unlock_irq(&pipe_crc->lock);
3553
3554 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003555
3556 if (IS_G4X(dev))
3557 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003558 else if (IS_VALLEYVIEW(dev))
3559 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003560 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3561 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003562
3563 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003564 }
3565
Daniel Vetter926321d2013-10-16 13:30:34 +02003566 return 0;
3567}
3568
3569/*
3570 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003571 * command: wsp* object wsp+ name wsp+ source wsp*
3572 * object: 'pipe'
3573 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003574 * source: (none | plane1 | plane2 | pf)
3575 * wsp: (#0x20 | #0x9 | #0xA)+
3576 *
3577 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003578 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3579 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003580 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003581static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003582{
3583 int n_words = 0;
3584
3585 while (*buf) {
3586 char *end;
3587
3588 /* skip leading white space */
3589 buf = skip_spaces(buf);
3590 if (!*buf)
3591 break; /* end of buffer */
3592
3593 /* find end of word */
3594 for (end = buf; *end && !isspace(*end); end++)
3595 ;
3596
3597 if (n_words == max_words) {
3598 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3599 max_words);
3600 return -EINVAL; /* ran out of words[] before bytes */
3601 }
3602
3603 if (*end)
3604 *end++ = '\0';
3605 words[n_words++] = buf;
3606 buf = end;
3607 }
3608
3609 return n_words;
3610}
3611
Damien Lespiaub94dec82013-10-15 18:55:35 +01003612enum intel_pipe_crc_object {
3613 PIPE_CRC_OBJECT_PIPE,
3614};
3615
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003616static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003617 "pipe",
3618};
3619
3620static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003621display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003622{
3623 int i;
3624
3625 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3626 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003627 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003628 return 0;
3629 }
3630
3631 return -EINVAL;
3632}
3633
Damien Lespiaubd9db022013-10-15 18:55:36 +01003634static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003635{
3636 const char name = buf[0];
3637
3638 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3639 return -EINVAL;
3640
3641 *pipe = name - 'A';
3642
3643 return 0;
3644}
3645
3646static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003647display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003648{
3649 int i;
3650
3651 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3652 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003653 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003654 return 0;
3655 }
3656
3657 return -EINVAL;
3658}
3659
Damien Lespiaubd9db022013-10-15 18:55:36 +01003660static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003661{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003662#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003663 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003664 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003665 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003666 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003667 enum intel_pipe_crc_source source;
3668
Damien Lespiaubd9db022013-10-15 18:55:36 +01003669 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003670 if (n_words != N_WORDS) {
3671 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3672 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003673 return -EINVAL;
3674 }
3675
Damien Lespiaubd9db022013-10-15 18:55:36 +01003676 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003677 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003678 return -EINVAL;
3679 }
3680
Damien Lespiaubd9db022013-10-15 18:55:36 +01003681 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003682 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3683 return -EINVAL;
3684 }
3685
Damien Lespiaubd9db022013-10-15 18:55:36 +01003686 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003687 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003688 return -EINVAL;
3689 }
3690
3691 return pipe_crc_set_source(dev, pipe, source);
3692}
3693
Damien Lespiaubd9db022013-10-15 18:55:36 +01003694static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3695 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003696{
3697 struct seq_file *m = file->private_data;
3698 struct drm_device *dev = m->private;
3699 char *tmpbuf;
3700 int ret;
3701
3702 if (len == 0)
3703 return 0;
3704
3705 if (len > PAGE_SIZE - 1) {
3706 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3707 PAGE_SIZE);
3708 return -E2BIG;
3709 }
3710
3711 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3712 if (!tmpbuf)
3713 return -ENOMEM;
3714
3715 if (copy_from_user(tmpbuf, ubuf, len)) {
3716 ret = -EFAULT;
3717 goto out;
3718 }
3719 tmpbuf[len] = '\0';
3720
Damien Lespiaubd9db022013-10-15 18:55:36 +01003721 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003722
3723out:
3724 kfree(tmpbuf);
3725 if (ret < 0)
3726 return ret;
3727
3728 *offp += len;
3729 return len;
3730}
3731
Damien Lespiaubd9db022013-10-15 18:55:36 +01003732static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003733 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003734 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003735 .read = seq_read,
3736 .llseek = seq_lseek,
3737 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003738 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003739};
3740
Damien Lespiau97e94b22014-11-04 17:06:50 +00003741static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003742{
3743 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003744 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003745 int level;
3746
3747 drm_modeset_lock_all(dev);
3748
3749 for (level = 0; level < num_levels; level++) {
3750 unsigned int latency = wm[level];
3751
Damien Lespiau97e94b22014-11-04 17:06:50 +00003752 /*
3753 * - WM1+ latency values in 0.5us units
3754 * - latencies are in us on gen9
3755 */
3756 if (INTEL_INFO(dev)->gen >= 9)
3757 latency *= 10;
3758 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003759 latency *= 5;
3760
3761 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003762 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003763 }
3764
3765 drm_modeset_unlock_all(dev);
3766}
3767
3768static int pri_wm_latency_show(struct seq_file *m, void *data)
3769{
3770 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003771 struct drm_i915_private *dev_priv = dev->dev_private;
3772 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003773
Damien Lespiau97e94b22014-11-04 17:06:50 +00003774 if (INTEL_INFO(dev)->gen >= 9)
3775 latencies = dev_priv->wm.skl_latency;
3776 else
3777 latencies = to_i915(dev)->wm.pri_latency;
3778
3779 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003780
3781 return 0;
3782}
3783
3784static int spr_wm_latency_show(struct seq_file *m, void *data)
3785{
3786 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003787 struct drm_i915_private *dev_priv = dev->dev_private;
3788 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003789
Damien Lespiau97e94b22014-11-04 17:06:50 +00003790 if (INTEL_INFO(dev)->gen >= 9)
3791 latencies = dev_priv->wm.skl_latency;
3792 else
3793 latencies = to_i915(dev)->wm.spr_latency;
3794
3795 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003796
3797 return 0;
3798}
3799
3800static int cur_wm_latency_show(struct seq_file *m, void *data)
3801{
3802 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003803 struct drm_i915_private *dev_priv = dev->dev_private;
3804 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003805
Damien Lespiau97e94b22014-11-04 17:06:50 +00003806 if (INTEL_INFO(dev)->gen >= 9)
3807 latencies = dev_priv->wm.skl_latency;
3808 else
3809 latencies = to_i915(dev)->wm.cur_latency;
3810
3811 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003812
3813 return 0;
3814}
3815
3816static int pri_wm_latency_open(struct inode *inode, struct file *file)
3817{
3818 struct drm_device *dev = inode->i_private;
3819
Sonika Jindal9ad02572014-07-21 15:23:39 +05303820 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003821 return -ENODEV;
3822
3823 return single_open(file, pri_wm_latency_show, dev);
3824}
3825
3826static int spr_wm_latency_open(struct inode *inode, struct file *file)
3827{
3828 struct drm_device *dev = inode->i_private;
3829
Sonika Jindal9ad02572014-07-21 15:23:39 +05303830 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003831 return -ENODEV;
3832
3833 return single_open(file, spr_wm_latency_show, dev);
3834}
3835
3836static int cur_wm_latency_open(struct inode *inode, struct file *file)
3837{
3838 struct drm_device *dev = inode->i_private;
3839
Sonika Jindal9ad02572014-07-21 15:23:39 +05303840 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003841 return -ENODEV;
3842
3843 return single_open(file, cur_wm_latency_show, dev);
3844}
3845
3846static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003847 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003848{
3849 struct seq_file *m = file->private_data;
3850 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003851 uint16_t new[8] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003852 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003853 int level;
3854 int ret;
3855 char tmp[32];
3856
3857 if (len >= sizeof(tmp))
3858 return -EINVAL;
3859
3860 if (copy_from_user(tmp, ubuf, len))
3861 return -EFAULT;
3862
3863 tmp[len] = '\0';
3864
Damien Lespiau97e94b22014-11-04 17:06:50 +00003865 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
3866 &new[0], &new[1], &new[2], &new[3],
3867 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003868 if (ret != num_levels)
3869 return -EINVAL;
3870
3871 drm_modeset_lock_all(dev);
3872
3873 for (level = 0; level < num_levels; level++)
3874 wm[level] = new[level];
3875
3876 drm_modeset_unlock_all(dev);
3877
3878 return len;
3879}
3880
3881
3882static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3883 size_t len, loff_t *offp)
3884{
3885 struct seq_file *m = file->private_data;
3886 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003887 struct drm_i915_private *dev_priv = dev->dev_private;
3888 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003889
Damien Lespiau97e94b22014-11-04 17:06:50 +00003890 if (INTEL_INFO(dev)->gen >= 9)
3891 latencies = dev_priv->wm.skl_latency;
3892 else
3893 latencies = to_i915(dev)->wm.pri_latency;
3894
3895 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003896}
3897
3898static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3899 size_t len, loff_t *offp)
3900{
3901 struct seq_file *m = file->private_data;
3902 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003903 struct drm_i915_private *dev_priv = dev->dev_private;
3904 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003905
Damien Lespiau97e94b22014-11-04 17:06:50 +00003906 if (INTEL_INFO(dev)->gen >= 9)
3907 latencies = dev_priv->wm.skl_latency;
3908 else
3909 latencies = to_i915(dev)->wm.spr_latency;
3910
3911 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003912}
3913
3914static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3915 size_t len, loff_t *offp)
3916{
3917 struct seq_file *m = file->private_data;
3918 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003919 struct drm_i915_private *dev_priv = dev->dev_private;
3920 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003921
Damien Lespiau97e94b22014-11-04 17:06:50 +00003922 if (INTEL_INFO(dev)->gen >= 9)
3923 latencies = dev_priv->wm.skl_latency;
3924 else
3925 latencies = to_i915(dev)->wm.cur_latency;
3926
3927 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003928}
3929
3930static const struct file_operations i915_pri_wm_latency_fops = {
3931 .owner = THIS_MODULE,
3932 .open = pri_wm_latency_open,
3933 .read = seq_read,
3934 .llseek = seq_lseek,
3935 .release = single_release,
3936 .write = pri_wm_latency_write
3937};
3938
3939static const struct file_operations i915_spr_wm_latency_fops = {
3940 .owner = THIS_MODULE,
3941 .open = spr_wm_latency_open,
3942 .read = seq_read,
3943 .llseek = seq_lseek,
3944 .release = single_release,
3945 .write = spr_wm_latency_write
3946};
3947
3948static const struct file_operations i915_cur_wm_latency_fops = {
3949 .owner = THIS_MODULE,
3950 .open = cur_wm_latency_open,
3951 .read = seq_read,
3952 .llseek = seq_lseek,
3953 .release = single_release,
3954 .write = cur_wm_latency_write
3955};
3956
Kees Cook647416f2013-03-10 14:10:06 -07003957static int
3958i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003959{
Kees Cook647416f2013-03-10 14:10:06 -07003960 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003961 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003962
Kees Cook647416f2013-03-10 14:10:06 -07003963 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003964
Kees Cook647416f2013-03-10 14:10:06 -07003965 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003966}
3967
Kees Cook647416f2013-03-10 14:10:06 -07003968static int
3969i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003970{
Kees Cook647416f2013-03-10 14:10:06 -07003971 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03003972 struct drm_i915_private *dev_priv = dev->dev_private;
3973
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02003974 /*
3975 * There is no safeguard against this debugfs entry colliding
3976 * with the hangcheck calling same i915_handle_error() in
3977 * parallel, causing an explosion. For now we assume that the
3978 * test harness is responsible enough not to inject gpu hangs
3979 * while it is writing to 'i915_wedged'
3980 */
3981
3982 if (i915_reset_in_progress(&dev_priv->gpu_error))
3983 return -EAGAIN;
3984
Imre Deakd46c0512014-04-14 20:24:27 +03003985 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003986
Mika Kuoppala58174462014-02-25 17:11:26 +02003987 i915_handle_error(dev, val,
3988 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03003989
3990 intel_runtime_pm_put(dev_priv);
3991
Kees Cook647416f2013-03-10 14:10:06 -07003992 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003993}
3994
Kees Cook647416f2013-03-10 14:10:06 -07003995DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
3996 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003997 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003998
Kees Cook647416f2013-03-10 14:10:06 -07003999static int
4000i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004001{
Kees Cook647416f2013-03-10 14:10:06 -07004002 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004003 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004004
Kees Cook647416f2013-03-10 14:10:06 -07004005 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004006
Kees Cook647416f2013-03-10 14:10:06 -07004007 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004008}
4009
Kees Cook647416f2013-03-10 14:10:06 -07004010static int
4011i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004012{
Kees Cook647416f2013-03-10 14:10:06 -07004013 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004014 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004015 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004016
Kees Cook647416f2013-03-10 14:10:06 -07004017 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004018
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004019 ret = mutex_lock_interruptible(&dev->struct_mutex);
4020 if (ret)
4021 return ret;
4022
Daniel Vetter99584db2012-11-14 17:14:04 +01004023 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004024 mutex_unlock(&dev->struct_mutex);
4025
Kees Cook647416f2013-03-10 14:10:06 -07004026 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004027}
4028
Kees Cook647416f2013-03-10 14:10:06 -07004029DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4030 i915_ring_stop_get, i915_ring_stop_set,
4031 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004032
Chris Wilson094f9a52013-09-25 17:34:55 +01004033static int
4034i915_ring_missed_irq_get(void *data, u64 *val)
4035{
4036 struct drm_device *dev = data;
4037 struct drm_i915_private *dev_priv = dev->dev_private;
4038
4039 *val = dev_priv->gpu_error.missed_irq_rings;
4040 return 0;
4041}
4042
4043static int
4044i915_ring_missed_irq_set(void *data, u64 val)
4045{
4046 struct drm_device *dev = data;
4047 struct drm_i915_private *dev_priv = dev->dev_private;
4048 int ret;
4049
4050 /* Lock against concurrent debugfs callers */
4051 ret = mutex_lock_interruptible(&dev->struct_mutex);
4052 if (ret)
4053 return ret;
4054 dev_priv->gpu_error.missed_irq_rings = val;
4055 mutex_unlock(&dev->struct_mutex);
4056
4057 return 0;
4058}
4059
4060DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4061 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4062 "0x%08llx\n");
4063
4064static int
4065i915_ring_test_irq_get(void *data, u64 *val)
4066{
4067 struct drm_device *dev = data;
4068 struct drm_i915_private *dev_priv = dev->dev_private;
4069
4070 *val = dev_priv->gpu_error.test_irq_rings;
4071
4072 return 0;
4073}
4074
4075static int
4076i915_ring_test_irq_set(void *data, u64 val)
4077{
4078 struct drm_device *dev = data;
4079 struct drm_i915_private *dev_priv = dev->dev_private;
4080 int ret;
4081
4082 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4083
4084 /* Lock against concurrent debugfs callers */
4085 ret = mutex_lock_interruptible(&dev->struct_mutex);
4086 if (ret)
4087 return ret;
4088
4089 dev_priv->gpu_error.test_irq_rings = val;
4090 mutex_unlock(&dev->struct_mutex);
4091
4092 return 0;
4093}
4094
4095DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4096 i915_ring_test_irq_get, i915_ring_test_irq_set,
4097 "0x%08llx\n");
4098
Chris Wilsondd624af2013-01-15 12:39:35 +00004099#define DROP_UNBOUND 0x1
4100#define DROP_BOUND 0x2
4101#define DROP_RETIRE 0x4
4102#define DROP_ACTIVE 0x8
4103#define DROP_ALL (DROP_UNBOUND | \
4104 DROP_BOUND | \
4105 DROP_RETIRE | \
4106 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004107static int
4108i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004109{
Kees Cook647416f2013-03-10 14:10:06 -07004110 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004111
Kees Cook647416f2013-03-10 14:10:06 -07004112 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004113}
4114
Kees Cook647416f2013-03-10 14:10:06 -07004115static int
4116i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004117{
Kees Cook647416f2013-03-10 14:10:06 -07004118 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004119 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004120 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004121
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004122 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004123
4124 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4125 * on ioctls on -EAGAIN. */
4126 ret = mutex_lock_interruptible(&dev->struct_mutex);
4127 if (ret)
4128 return ret;
4129
4130 if (val & DROP_ACTIVE) {
4131 ret = i915_gpu_idle(dev);
4132 if (ret)
4133 goto unlock;
4134 }
4135
4136 if (val & (DROP_RETIRE | DROP_ACTIVE))
4137 i915_gem_retire_requests(dev);
4138
Chris Wilson21ab4e72014-09-09 11:16:08 +01004139 if (val & DROP_BOUND)
4140 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004141
Chris Wilson21ab4e72014-09-09 11:16:08 +01004142 if (val & DROP_UNBOUND)
4143 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004144
4145unlock:
4146 mutex_unlock(&dev->struct_mutex);
4147
Kees Cook647416f2013-03-10 14:10:06 -07004148 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004149}
4150
Kees Cook647416f2013-03-10 14:10:06 -07004151DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4152 i915_drop_caches_get, i915_drop_caches_set,
4153 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004154
Kees Cook647416f2013-03-10 14:10:06 -07004155static int
4156i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004157{
Kees Cook647416f2013-03-10 14:10:06 -07004158 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004159 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004160 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004161
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004162 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004163 return -ENODEV;
4164
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004165 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4166
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004167 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004168 if (ret)
4169 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004170
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004171 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004172 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004173
Kees Cook647416f2013-03-10 14:10:06 -07004174 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004175}
4176
Kees Cook647416f2013-03-10 14:10:06 -07004177static int
4178i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004179{
Kees Cook647416f2013-03-10 14:10:06 -07004180 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004181 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004182 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004183 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004184
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004185 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004186 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004187
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004188 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4189
Kees Cook647416f2013-03-10 14:10:06 -07004190 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004191
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004192 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004193 if (ret)
4194 return ret;
4195
Jesse Barnes358733e2011-07-27 11:53:01 -07004196 /*
4197 * Turbo will still be enabled, but won't go above the set value.
4198 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07004199 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004200 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004201
Ville Syrjälä03af2042014-06-28 02:03:53 +03004202 hw_max = dev_priv->rps.max_freq;
4203 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004204 } else {
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004205 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004206
4207 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07004208 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004209 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004210 }
4211
Ben Widawskyb39fb292014-03-19 18:31:11 -07004212 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004213 mutex_unlock(&dev_priv->rps.hw_lock);
4214 return -EINVAL;
4215 }
4216
Ben Widawskyb39fb292014-03-19 18:31:11 -07004217 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004218
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004219 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004220
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004221 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004222
Kees Cook647416f2013-03-10 14:10:06 -07004223 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004224}
4225
Kees Cook647416f2013-03-10 14:10:06 -07004226DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4227 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004228 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004229
Kees Cook647416f2013-03-10 14:10:06 -07004230static int
4231i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004232{
Kees Cook647416f2013-03-10 14:10:06 -07004233 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004234 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004235 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004236
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004237 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004238 return -ENODEV;
4239
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004240 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4241
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004242 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004243 if (ret)
4244 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004245
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004246 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004247 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004248
Kees Cook647416f2013-03-10 14:10:06 -07004249 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004250}
4251
Kees Cook647416f2013-03-10 14:10:06 -07004252static int
4253i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004254{
Kees Cook647416f2013-03-10 14:10:06 -07004255 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004256 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004257 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004258 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004259
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004260 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004261 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004262
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004263 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4264
Kees Cook647416f2013-03-10 14:10:06 -07004265 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004266
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004267 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004268 if (ret)
4269 return ret;
4270
Jesse Barnes1523c312012-05-25 12:34:54 -07004271 /*
4272 * Turbo will still be enabled, but won't go below the set value.
4273 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07004274 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004275 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004276
Ville Syrjälä03af2042014-06-28 02:03:53 +03004277 hw_max = dev_priv->rps.max_freq;
4278 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004279 } else {
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004280 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004281
4282 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07004283 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004284 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004285 }
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004286
Ben Widawskyb39fb292014-03-19 18:31:11 -07004287 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004288 mutex_unlock(&dev_priv->rps.hw_lock);
4289 return -EINVAL;
4290 }
4291
Ben Widawskyb39fb292014-03-19 18:31:11 -07004292 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004293
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004294 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004295
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004296 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004297
Kees Cook647416f2013-03-10 14:10:06 -07004298 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004299}
4300
Kees Cook647416f2013-03-10 14:10:06 -07004301DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4302 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004303 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004304
Kees Cook647416f2013-03-10 14:10:06 -07004305static int
4306i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004307{
Kees Cook647416f2013-03-10 14:10:06 -07004308 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004309 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004310 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004311 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004312
Daniel Vetter004777c2012-08-09 15:07:01 +02004313 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4314 return -ENODEV;
4315
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004316 ret = mutex_lock_interruptible(&dev->struct_mutex);
4317 if (ret)
4318 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004319 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004320
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004321 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004322
4323 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004324 mutex_unlock(&dev_priv->dev->struct_mutex);
4325
Kees Cook647416f2013-03-10 14:10:06 -07004326 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004327
Kees Cook647416f2013-03-10 14:10:06 -07004328 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004329}
4330
Kees Cook647416f2013-03-10 14:10:06 -07004331static int
4332i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004333{
Kees Cook647416f2013-03-10 14:10:06 -07004334 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004335 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004336 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004337
Daniel Vetter004777c2012-08-09 15:07:01 +02004338 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4339 return -ENODEV;
4340
Kees Cook647416f2013-03-10 14:10:06 -07004341 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004342 return -EINVAL;
4343
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004344 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004345 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004346
4347 /* Update the cache sharing policy here as well */
4348 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4349 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4350 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4351 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4352
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004353 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004354 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004355}
4356
Kees Cook647416f2013-03-10 14:10:06 -07004357DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4358 i915_cache_sharing_get, i915_cache_sharing_set,
4359 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004360
Ben Widawsky6d794d42011-04-25 11:25:56 -07004361static int i915_forcewake_open(struct inode *inode, struct file *file)
4362{
4363 struct drm_device *dev = inode->i_private;
4364 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004365
Daniel Vetter075edca2012-01-24 09:44:28 +01004366 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004367 return 0;
4368
Chris Wilson6daccb02015-01-16 11:34:35 +02004369 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004370 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004371
4372 return 0;
4373}
4374
Ben Widawskyc43b5632012-04-16 14:07:40 -07004375static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004376{
4377 struct drm_device *dev = inode->i_private;
4378 struct drm_i915_private *dev_priv = dev->dev_private;
4379
Daniel Vetter075edca2012-01-24 09:44:28 +01004380 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004381 return 0;
4382
Mika Kuoppala59bad942015-01-16 11:34:40 +02004383 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004384 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004385
4386 return 0;
4387}
4388
4389static const struct file_operations i915_forcewake_fops = {
4390 .owner = THIS_MODULE,
4391 .open = i915_forcewake_open,
4392 .release = i915_forcewake_release,
4393};
4394
4395static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4396{
4397 struct drm_device *dev = minor->dev;
4398 struct dentry *ent;
4399
4400 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004401 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004402 root, dev,
4403 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004404 if (!ent)
4405 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004406
Ben Widawsky8eb57292011-05-11 15:10:58 -07004407 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004408}
4409
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004410static int i915_debugfs_create(struct dentry *root,
4411 struct drm_minor *minor,
4412 const char *name,
4413 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004414{
4415 struct drm_device *dev = minor->dev;
4416 struct dentry *ent;
4417
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004418 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004419 S_IRUGO | S_IWUSR,
4420 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004421 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004422 if (!ent)
4423 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004424
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004425 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004426}
4427
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004428static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004429 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004430 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004431 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01004432 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004433 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004434 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004435 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004436 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004437 {"i915_gem_request", i915_gem_request_info, 0},
4438 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004439 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004440 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00004441 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
4442 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
4443 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07004444 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08004445 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304446 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004447 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004448 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004449 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004450 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004451 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004452 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004453 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004454 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004455 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004456 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01004457 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01004458 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004459 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004460 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004461 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004462 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004463 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004464 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004465 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03004466 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004467 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004468 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004469 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004470 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004471 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004472 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004473 {"i915_ddb_info", i915_ddb_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004474};
Ben Gamari27c202a2009-07-01 22:26:52 -04004475#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004476
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004477static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004478 const char *name;
4479 const struct file_operations *fops;
4480} i915_debugfs_files[] = {
4481 {"i915_wedged", &i915_wedged_fops},
4482 {"i915_max_freq", &i915_max_freq_fops},
4483 {"i915_min_freq", &i915_min_freq_fops},
4484 {"i915_cache_sharing", &i915_cache_sharing_fops},
4485 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004486 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4487 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004488 {"i915_gem_drop_caches", &i915_drop_caches_fops},
4489 {"i915_error_state", &i915_error_state_fops},
4490 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004491 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004492 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4493 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4494 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004495 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004496};
4497
Damien Lespiau07144422013-10-15 18:55:40 +01004498void intel_display_crc_init(struct drm_device *dev)
4499{
4500 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01004501 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01004502
Damien Lespiau055e3932014-08-18 13:49:10 +01004503 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01004504 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01004505
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004506 pipe_crc->opened = false;
4507 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01004508 init_waitqueue_head(&pipe_crc->wq);
4509 }
4510}
4511
Ben Gamari27c202a2009-07-01 22:26:52 -04004512int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004513{
Daniel Vetter34b96742013-07-04 20:49:44 +02004514 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004515
Ben Widawsky6d794d42011-04-25 11:25:56 -07004516 ret = i915_forcewake_create(minor->debugfs_root, minor);
4517 if (ret)
4518 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004519
Damien Lespiau07144422013-10-15 18:55:40 +01004520 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
4521 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
4522 if (ret)
4523 return ret;
4524 }
4525
Daniel Vetter34b96742013-07-04 20:49:44 +02004526 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4527 ret = i915_debugfs_create(minor->debugfs_root, minor,
4528 i915_debugfs_files[i].name,
4529 i915_debugfs_files[i].fops);
4530 if (ret)
4531 return ret;
4532 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004533
Ben Gamari27c202a2009-07-01 22:26:52 -04004534 return drm_debugfs_create_files(i915_debugfs_list,
4535 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004536 minor->debugfs_root, minor);
4537}
4538
Ben Gamari27c202a2009-07-01 22:26:52 -04004539void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004540{
Daniel Vetter34b96742013-07-04 20:49:44 +02004541 int i;
4542
Ben Gamari27c202a2009-07-01 22:26:52 -04004543 drm_debugfs_remove_files(i915_debugfs_list,
4544 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004545
Ben Widawsky6d794d42011-04-25 11:25:56 -07004546 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
4547 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004548
Daniel Vettere309a992013-10-16 22:55:51 +02004549 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01004550 struct drm_info_list *info_list =
4551 (struct drm_info_list *)&i915_pipe_crc_data[i];
4552
4553 drm_debugfs_remove_files(info_list, 1, minor);
4554 }
4555
Daniel Vetter34b96742013-07-04 20:49:44 +02004556 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4557 struct drm_info_list *info_list =
4558 (struct drm_info_list *) i915_debugfs_files[i].fops;
4559
4560 drm_debugfs_remove_files(info_list, 1, minor);
4561 }
Ben Gamari20172632009-02-17 20:08:50 -05004562}