blob: e14b44708728ee735227b87319b2d72349046ba5 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Chris Wilsonf13d3f72010-09-20 17:36:15 +010043enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010044 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010046 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047};
Ben Gamari433e12f2009-02-17 20:08:51 -050048
Chris Wilson70d39fe2010-08-25 16:03:34 +010049static const char *yesno(int v)
50{
51 return v ? "yes" : "no";
52}
53
Damien Lespiau497666d2013-10-15 18:55:39 +010054/* As the drm_debugfs_init() routines are called before dev->dev_private is
55 * allocated we need to hook into the minor for release. */
56static int
57drm_add_fake_info_node(struct drm_minor *minor,
58 struct dentry *ent,
59 const void *key)
60{
61 struct drm_info_node *node;
62
63 node = kmalloc(sizeof(*node), GFP_KERNEL);
64 if (node == NULL) {
65 debugfs_remove(ent);
66 return -ENOMEM;
67 }
68
69 node->minor = minor;
70 node->dent = ent;
71 node->info_ent = (void *) key;
72
73 mutex_lock(&minor->debugfs_lock);
74 list_add(&node->list, &minor->debugfs_list);
75 mutex_unlock(&minor->debugfs_lock);
76
77 return 0;
78}
79
Chris Wilson70d39fe2010-08-25 16:03:34 +010080static int i915_capabilities(struct seq_file *m, void *data)
81{
Damien Lespiau9f25d002014-05-13 15:30:28 +010082 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010083 struct drm_device *dev = node->minor->dev;
84 const struct intel_device_info *info = INTEL_INFO(dev);
85
86 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030087 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010088#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
89#define SEP_SEMICOLON ;
90 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
91#undef PRINT_FLAG
92#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010093
94 return 0;
95}
Ben Gamari433e12f2009-02-17 20:08:51 -050096
Chris Wilson05394f32010-11-08 19:18:58 +000097static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000098{
Daniel Vetter4feb7652014-11-24 11:21:52 +010099 if (i915_gem_obj_is_pinned(obj))
Chris Wilsona6172a82009-02-11 14:26:38 +0000100 return "p";
101 else
102 return " ";
103}
104
Chris Wilson05394f32010-11-08 19:18:58 +0000105static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000106{
Akshay Joshi0206e352011-08-16 15:34:10 -0400107 switch (obj->tiling_mode) {
108 default:
109 case I915_TILING_NONE: return " ";
110 case I915_TILING_X: return "X";
111 case I915_TILING_Y: return "Y";
112 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000113}
114
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700115static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
116{
Tvrtko Ursulinaff43762014-10-24 12:42:33 +0100117 return i915_gem_obj_to_ggtt(obj) ? "g" : " ";
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700118}
119
Chris Wilson37811fc2010-08-25 22:45:57 +0100120static void
121describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
122{
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700123 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800124 int pin_count = 0;
125
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200126 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %x %x %x%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100127 &obj->base,
128 get_pin_flag(obj),
129 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700130 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800131 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100132 obj->base.read_domains,
133 obj->base.write_domain,
John Harrison97b2a6a2014-11-24 18:49:26 +0000134 i915_gem_request_get_seqno(obj->last_read_req),
135 i915_gem_request_get_seqno(obj->last_write_req),
136 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100137 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100138 obj->dirty ? " dirty" : "",
139 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
140 if (obj->base.name)
141 seq_printf(m, " (name: %d)", obj->base.name);
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300142 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800143 if (vma->pin_count > 0)
144 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300145 }
146 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100147 if (obj->pin_display)
148 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100149 if (obj->fence_reg != I915_FENCE_REG_NONE)
150 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700151 list_for_each_entry(vma, &obj->vma_list, vma_link) {
152 if (!i915_is_ggtt(vma->vm))
153 seq_puts(m, " (pp");
154 else
155 seq_puts(m, " (g");
Thierry Reding440fd522015-01-23 09:05:06 +0100156 seq_printf(m, "gtt offset: %08llx, size: %08llx, type: %u)",
Tvrtko Ursulinfe14d5f2014-12-10 17:27:58 +0000157 vma->node.start, vma->node.size,
158 vma->ggtt_view.type);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700159 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000160 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100161 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000162 if (obj->pin_mappable || obj->fault_mappable) {
163 char s[3], *t = s;
164 if (obj->pin_mappable)
165 *t++ = 'p';
166 if (obj->fault_mappable)
167 *t++ = 'f';
168 *t = '\0';
169 seq_printf(m, " (%s mappable)", s);
170 }
John Harrison41c52412014-11-24 18:49:43 +0000171 if (obj->last_read_req != NULL)
172 seq_printf(m, " (%s)",
173 i915_gem_request_get_ring(obj->last_read_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200174 if (obj->frontbuffer_bits)
175 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100176}
177
Oscar Mateo273497e2014-05-22 14:13:37 +0100178static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700179{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100180 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700181 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
182 seq_putc(m, ' ');
183}
184
Ben Gamari433e12f2009-02-17 20:08:51 -0500185static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500186{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100187 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500188 uintptr_t list = (uintptr_t) node->info_ent->data;
189 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500190 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700191 struct drm_i915_private *dev_priv = dev->dev_private;
192 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700193 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100194 size_t total_obj_size, total_gtt_size;
195 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100196
197 ret = mutex_lock_interruptible(&dev->struct_mutex);
198 if (ret)
199 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500200
Ben Widawskyca191b12013-07-31 17:00:14 -0700201 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500202 switch (list) {
203 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100204 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700205 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500206 break;
207 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100208 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700209 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500210 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500211 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100212 mutex_unlock(&dev->struct_mutex);
213 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500214 }
215
Chris Wilson8f2480f2010-09-26 11:44:19 +0100216 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700217 list_for_each_entry(vma, head, mm_list) {
218 seq_printf(m, " ");
219 describe_obj(m, vma->obj);
220 seq_printf(m, "\n");
221 total_obj_size += vma->obj->base.size;
222 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100223 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500224 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100225 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700226
Chris Wilson8f2480f2010-09-26 11:44:19 +0100227 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
228 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500229 return 0;
230}
231
Chris Wilson6d2b88852013-08-07 18:30:54 +0100232static int obj_rank_by_stolen(void *priv,
233 struct list_head *A, struct list_head *B)
234{
235 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200236 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100237 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200238 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100239
240 return a->stolen->start - b->stolen->start;
241}
242
243static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
244{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100245 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100246 struct drm_device *dev = node->minor->dev;
247 struct drm_i915_private *dev_priv = dev->dev_private;
248 struct drm_i915_gem_object *obj;
249 size_t total_obj_size, total_gtt_size;
250 LIST_HEAD(stolen);
251 int count, ret;
252
253 ret = mutex_lock_interruptible(&dev->struct_mutex);
254 if (ret)
255 return ret;
256
257 total_obj_size = total_gtt_size = count = 0;
258 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
259 if (obj->stolen == NULL)
260 continue;
261
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200262 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100263
264 total_obj_size += obj->base.size;
265 total_gtt_size += i915_gem_obj_ggtt_size(obj);
266 count++;
267 }
268 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
269 if (obj->stolen == NULL)
270 continue;
271
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200272 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100273
274 total_obj_size += obj->base.size;
275 count++;
276 }
277 list_sort(NULL, &stolen, obj_rank_by_stolen);
278 seq_puts(m, "Stolen:\n");
279 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200280 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100281 seq_puts(m, " ");
282 describe_obj(m, obj);
283 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200284 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100285 }
286 mutex_unlock(&dev->struct_mutex);
287
288 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
289 count, total_obj_size, total_gtt_size);
290 return 0;
291}
292
Chris Wilson6299f992010-11-24 12:23:44 +0000293#define count_objects(list, member) do { \
294 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700295 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000296 ++count; \
297 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700298 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000299 ++mappable_count; \
300 } \
301 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400302} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000303
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100304struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000305 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100306 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000307 size_t total, unbound;
308 size_t global, shared;
309 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100310};
311
312static int per_file_stats(int id, void *ptr, void *data)
313{
314 struct drm_i915_gem_object *obj = ptr;
315 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000316 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100317
318 stats->count++;
319 stats->total += obj->base.size;
320
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000321 if (obj->base.name || obj->base.dma_buf)
322 stats->shared += obj->base.size;
323
Chris Wilson6313c202014-03-19 13:45:45 +0000324 if (USES_FULL_PPGTT(obj->base.dev)) {
325 list_for_each_entry(vma, &obj->vma_list, vma_link) {
326 struct i915_hw_ppgtt *ppgtt;
327
328 if (!drm_mm_node_allocated(&vma->node))
329 continue;
330
331 if (i915_is_ggtt(vma->vm)) {
332 stats->global += obj->base.size;
333 continue;
334 }
335
336 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200337 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000338 continue;
339
John Harrison41c52412014-11-24 18:49:43 +0000340 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000341 stats->active += obj->base.size;
342 else
343 stats->inactive += obj->base.size;
344
345 return 0;
346 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100347 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000348 if (i915_gem_obj_ggtt_bound(obj)) {
349 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000350 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000351 stats->active += obj->base.size;
352 else
353 stats->inactive += obj->base.size;
354 return 0;
355 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100356 }
357
Chris Wilson6313c202014-03-19 13:45:45 +0000358 if (!list_empty(&obj->global_list))
359 stats->unbound += obj->base.size;
360
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100361 return 0;
362}
363
Brad Volkin493018d2014-12-11 12:13:08 -0800364#define print_file_stats(m, name, stats) \
365 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n", \
366 name, \
367 stats.count, \
368 stats.total, \
369 stats.active, \
370 stats.inactive, \
371 stats.global, \
372 stats.shared, \
373 stats.unbound)
374
375static void print_batch_pool_stats(struct seq_file *m,
376 struct drm_i915_private *dev_priv)
377{
378 struct drm_i915_gem_object *obj;
379 struct file_stats stats;
380
381 memset(&stats, 0, sizeof(stats));
382
383 list_for_each_entry(obj,
384 &dev_priv->mm.batch_pool.cache_list,
385 batch_pool_list)
386 per_file_stats(0, obj, &stats);
387
388 print_file_stats(m, "batch pool", stats);
389}
390
Ben Widawskyca191b12013-07-31 17:00:14 -0700391#define count_vmas(list, member) do { \
392 list_for_each_entry(vma, list, member) { \
393 size += i915_gem_obj_ggtt_size(vma->obj); \
394 ++count; \
395 if (vma->obj->map_and_fenceable) { \
396 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
397 ++mappable_count; \
398 } \
399 } \
400} while (0)
401
402static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100403{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100404 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100405 struct drm_device *dev = node->minor->dev;
406 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200407 u32 count, mappable_count, purgeable_count;
408 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000409 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700410 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100411 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700412 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100413 int ret;
414
415 ret = mutex_lock_interruptible(&dev->struct_mutex);
416 if (ret)
417 return ret;
418
Chris Wilson6299f992010-11-24 12:23:44 +0000419 seq_printf(m, "%u objects, %zu bytes\n",
420 dev_priv->mm.object_count,
421 dev_priv->mm.object_memory);
422
423 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700424 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000425 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
426 count, mappable_count, size, mappable_size);
427
428 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700429 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000430 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
431 count, mappable_count, size, mappable_size);
432
433 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700434 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000435 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
436 count, mappable_count, size, mappable_size);
437
Chris Wilsonb7abb712012-08-20 11:33:30 +0200438 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700439 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200440 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200441 if (obj->madv == I915_MADV_DONTNEED)
442 purgeable_size += obj->base.size, ++purgeable_count;
443 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200444 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
445
Chris Wilson6299f992010-11-24 12:23:44 +0000446 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700447 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000448 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700449 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000450 ++count;
451 }
452 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700453 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000454 ++mappable_count;
455 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200456 if (obj->madv == I915_MADV_DONTNEED) {
457 purgeable_size += obj->base.size;
458 ++purgeable_count;
459 }
Chris Wilson6299f992010-11-24 12:23:44 +0000460 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200461 seq_printf(m, "%u purgeable objects, %zu bytes\n",
462 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000463 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
464 mappable_count, mappable_size);
465 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
466 count, size);
467
Ben Widawsky93d18792013-01-17 12:45:17 -0800468 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700469 dev_priv->gtt.base.total,
470 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100471
Damien Lespiau267f0c92013-06-24 22:59:48 +0100472 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800473 print_batch_pool_stats(m, dev_priv);
474
475 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100476 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
477 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900478 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100479
480 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000481 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100482 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100483 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100484 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900485 /*
486 * Although we have a valid reference on file->pid, that does
487 * not guarantee that the task_struct who called get_pid() is
488 * still alive (e.g. get_pid(current) => fork() => exit()).
489 * Therefore, we need to protect this ->comm access using RCU.
490 */
491 rcu_read_lock();
492 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800493 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900494 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100495 }
496
Chris Wilson73aa8082010-09-30 11:46:12 +0100497 mutex_unlock(&dev->struct_mutex);
498
499 return 0;
500}
501
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100502static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000503{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100504 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000505 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100506 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000507 struct drm_i915_private *dev_priv = dev->dev_private;
508 struct drm_i915_gem_object *obj;
509 size_t total_obj_size, total_gtt_size;
510 int count, ret;
511
512 ret = mutex_lock_interruptible(&dev->struct_mutex);
513 if (ret)
514 return ret;
515
516 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700517 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800518 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100519 continue;
520
Damien Lespiau267f0c92013-06-24 22:59:48 +0100521 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000522 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100523 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000524 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700525 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000526 count++;
527 }
528
529 mutex_unlock(&dev->struct_mutex);
530
531 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
532 count, total_obj_size, total_gtt_size);
533
534 return 0;
535}
536
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100537static int i915_gem_pageflip_info(struct seq_file *m, void *data)
538{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100539 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100540 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100541 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100542 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200543 int ret;
544
545 ret = mutex_lock_interruptible(&dev->struct_mutex);
546 if (ret)
547 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100548
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100549 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800550 const char pipe = pipe_name(crtc->pipe);
551 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100552 struct intel_unpin_work *work;
553
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200554 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100555 work = crtc->unpin_work;
556 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800557 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100558 pipe, plane);
559 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100560 u32 addr;
561
Chris Wilsone7d841c2012-12-03 11:36:30 +0000562 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800563 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100564 pipe, plane);
565 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800566 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100567 pipe, plane);
568 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100569 if (work->flip_queued_req) {
570 struct intel_engine_cs *ring =
571 i915_gem_request_get_ring(work->flip_queued_req);
572
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200573 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100574 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000575 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100576 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100577 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000578 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100579 } else
580 seq_printf(m, "Flip not associated with any ring\n");
581 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
582 work->flip_queued_vblank,
583 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100584 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100585 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100586 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100587 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100588 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000589 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100590
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100591 if (INTEL_INFO(dev)->gen >= 4)
592 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
593 else
594 addr = I915_READ(DSPADDR(crtc->plane));
595 seq_printf(m, "Current scanout address 0x%08x\n", addr);
596
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100597 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100598 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
599 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100600 }
601 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200602 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100603 }
604
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200605 mutex_unlock(&dev->struct_mutex);
606
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100607 return 0;
608}
609
Brad Volkin493018d2014-12-11 12:13:08 -0800610static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
611{
612 struct drm_info_node *node = m->private;
613 struct drm_device *dev = node->minor->dev;
614 struct drm_i915_private *dev_priv = dev->dev_private;
615 struct drm_i915_gem_object *obj;
616 int count = 0;
617 int ret;
618
619 ret = mutex_lock_interruptible(&dev->struct_mutex);
620 if (ret)
621 return ret;
622
623 seq_puts(m, "cache:\n");
624 list_for_each_entry(obj,
625 &dev_priv->mm.batch_pool.cache_list,
626 batch_pool_list) {
627 seq_puts(m, " ");
628 describe_obj(m, obj);
629 seq_putc(m, '\n');
630 count++;
631 }
632
633 seq_printf(m, "total: %d\n", count);
634
635 mutex_unlock(&dev->struct_mutex);
636
637 return 0;
638}
639
Ben Gamari20172632009-02-17 20:08:50 -0500640static int i915_gem_request_info(struct seq_file *m, void *data)
641{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100642 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500643 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300644 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100645 struct intel_engine_cs *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500646 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100647 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100648
649 ret = mutex_lock_interruptible(&dev->struct_mutex);
650 if (ret)
651 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500652
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100653 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100654 for_each_ring(ring, dev_priv, i) {
655 if (list_empty(&ring->request_list))
656 continue;
657
658 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100659 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100660 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100661 list) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200662 seq_printf(m, " %x @ %d\n",
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100663 gem_request->seqno,
664 (int) (jiffies - gem_request->emitted_jiffies));
665 }
666 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500667 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100668 mutex_unlock(&dev->struct_mutex);
669
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100670 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100671 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100672
Ben Gamari20172632009-02-17 20:08:50 -0500673 return 0;
674}
675
Chris Wilsonb2223492010-10-27 15:27:33 +0100676static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100677 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100678{
679 if (ring->get_seqno) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200680 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100681 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100682 }
683}
684
Ben Gamari20172632009-02-17 20:08:50 -0500685static int i915_gem_seqno_info(struct seq_file *m, void *data)
686{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100687 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500688 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300689 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100690 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000691 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100692
693 ret = mutex_lock_interruptible(&dev->struct_mutex);
694 if (ret)
695 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200696 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500697
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100698 for_each_ring(ring, dev_priv, i)
699 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100700
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200701 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100702 mutex_unlock(&dev->struct_mutex);
703
Ben Gamari20172632009-02-17 20:08:50 -0500704 return 0;
705}
706
707
708static int i915_interrupt_info(struct seq_file *m, void *data)
709{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100710 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500711 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300712 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100713 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800714 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100715
716 ret = mutex_lock_interruptible(&dev->struct_mutex);
717 if (ret)
718 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200719 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500720
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300721 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300722 seq_printf(m, "Master Interrupt Control:\t%08x\n",
723 I915_READ(GEN8_MASTER_IRQ));
724
725 seq_printf(m, "Display IER:\t%08x\n",
726 I915_READ(VLV_IER));
727 seq_printf(m, "Display IIR:\t%08x\n",
728 I915_READ(VLV_IIR));
729 seq_printf(m, "Display IIR_RW:\t%08x\n",
730 I915_READ(VLV_IIR_RW));
731 seq_printf(m, "Display IMR:\t%08x\n",
732 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100733 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300734 seq_printf(m, "Pipe %c stat:\t%08x\n",
735 pipe_name(pipe),
736 I915_READ(PIPESTAT(pipe)));
737
738 seq_printf(m, "Port hotplug:\t%08x\n",
739 I915_READ(PORT_HOTPLUG_EN));
740 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
741 I915_READ(VLV_DPFLIPSTAT));
742 seq_printf(m, "DPINVGTT:\t%08x\n",
743 I915_READ(DPINVGTT));
744
745 for (i = 0; i < 4; i++) {
746 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
747 i, I915_READ(GEN8_GT_IMR(i)));
748 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
749 i, I915_READ(GEN8_GT_IIR(i)));
750 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
751 i, I915_READ(GEN8_GT_IER(i)));
752 }
753
754 seq_printf(m, "PCU interrupt mask:\t%08x\n",
755 I915_READ(GEN8_PCU_IMR));
756 seq_printf(m, "PCU interrupt identity:\t%08x\n",
757 I915_READ(GEN8_PCU_IIR));
758 seq_printf(m, "PCU interrupt enable:\t%08x\n",
759 I915_READ(GEN8_PCU_IER));
760 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700761 seq_printf(m, "Master Interrupt Control:\t%08x\n",
762 I915_READ(GEN8_MASTER_IRQ));
763
764 for (i = 0; i < 4; i++) {
765 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
766 i, I915_READ(GEN8_GT_IMR(i)));
767 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
768 i, I915_READ(GEN8_GT_IIR(i)));
769 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
770 i, I915_READ(GEN8_GT_IER(i)));
771 }
772
Damien Lespiau055e3932014-08-18 13:49:10 +0100773 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200774 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300775 POWER_DOMAIN_PIPE(pipe))) {
776 seq_printf(m, "Pipe %c power disabled\n",
777 pipe_name(pipe));
778 continue;
779 }
Ben Widawskya123f152013-11-02 21:07:10 -0700780 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000781 pipe_name(pipe),
782 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700783 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000784 pipe_name(pipe),
785 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700786 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000787 pipe_name(pipe),
788 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700789 }
790
791 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
792 I915_READ(GEN8_DE_PORT_IMR));
793 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
794 I915_READ(GEN8_DE_PORT_IIR));
795 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
796 I915_READ(GEN8_DE_PORT_IER));
797
798 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
799 I915_READ(GEN8_DE_MISC_IMR));
800 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
801 I915_READ(GEN8_DE_MISC_IIR));
802 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
803 I915_READ(GEN8_DE_MISC_IER));
804
805 seq_printf(m, "PCU interrupt mask:\t%08x\n",
806 I915_READ(GEN8_PCU_IMR));
807 seq_printf(m, "PCU interrupt identity:\t%08x\n",
808 I915_READ(GEN8_PCU_IIR));
809 seq_printf(m, "PCU interrupt enable:\t%08x\n",
810 I915_READ(GEN8_PCU_IER));
811 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700812 seq_printf(m, "Display IER:\t%08x\n",
813 I915_READ(VLV_IER));
814 seq_printf(m, "Display IIR:\t%08x\n",
815 I915_READ(VLV_IIR));
816 seq_printf(m, "Display IIR_RW:\t%08x\n",
817 I915_READ(VLV_IIR_RW));
818 seq_printf(m, "Display IMR:\t%08x\n",
819 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100820 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700821 seq_printf(m, "Pipe %c stat:\t%08x\n",
822 pipe_name(pipe),
823 I915_READ(PIPESTAT(pipe)));
824
825 seq_printf(m, "Master IER:\t%08x\n",
826 I915_READ(VLV_MASTER_IER));
827
828 seq_printf(m, "Render IER:\t%08x\n",
829 I915_READ(GTIER));
830 seq_printf(m, "Render IIR:\t%08x\n",
831 I915_READ(GTIIR));
832 seq_printf(m, "Render IMR:\t%08x\n",
833 I915_READ(GTIMR));
834
835 seq_printf(m, "PM IER:\t\t%08x\n",
836 I915_READ(GEN6_PMIER));
837 seq_printf(m, "PM IIR:\t\t%08x\n",
838 I915_READ(GEN6_PMIIR));
839 seq_printf(m, "PM IMR:\t\t%08x\n",
840 I915_READ(GEN6_PMIMR));
841
842 seq_printf(m, "Port hotplug:\t%08x\n",
843 I915_READ(PORT_HOTPLUG_EN));
844 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
845 I915_READ(VLV_DPFLIPSTAT));
846 seq_printf(m, "DPINVGTT:\t%08x\n",
847 I915_READ(DPINVGTT));
848
849 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800850 seq_printf(m, "Interrupt enable: %08x\n",
851 I915_READ(IER));
852 seq_printf(m, "Interrupt identity: %08x\n",
853 I915_READ(IIR));
854 seq_printf(m, "Interrupt mask: %08x\n",
855 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100856 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800857 seq_printf(m, "Pipe %c stat: %08x\n",
858 pipe_name(pipe),
859 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800860 } else {
861 seq_printf(m, "North Display Interrupt enable: %08x\n",
862 I915_READ(DEIER));
863 seq_printf(m, "North Display Interrupt identity: %08x\n",
864 I915_READ(DEIIR));
865 seq_printf(m, "North Display Interrupt mask: %08x\n",
866 I915_READ(DEIMR));
867 seq_printf(m, "South Display Interrupt enable: %08x\n",
868 I915_READ(SDEIER));
869 seq_printf(m, "South Display Interrupt identity: %08x\n",
870 I915_READ(SDEIIR));
871 seq_printf(m, "South Display Interrupt mask: %08x\n",
872 I915_READ(SDEIMR));
873 seq_printf(m, "Graphics Interrupt enable: %08x\n",
874 I915_READ(GTIER));
875 seq_printf(m, "Graphics Interrupt identity: %08x\n",
876 I915_READ(GTIIR));
877 seq_printf(m, "Graphics Interrupt mask: %08x\n",
878 I915_READ(GTIMR));
879 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100880 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700881 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100882 seq_printf(m,
883 "Graphics Interrupt mask (%s): %08x\n",
884 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000885 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100886 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000887 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200888 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100889 mutex_unlock(&dev->struct_mutex);
890
Ben Gamari20172632009-02-17 20:08:50 -0500891 return 0;
892}
893
Chris Wilsona6172a82009-02-11 14:26:38 +0000894static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
895{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100896 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000897 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300898 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100899 int i, ret;
900
901 ret = mutex_lock_interruptible(&dev->struct_mutex);
902 if (ret)
903 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000904
905 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
906 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
907 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000908 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000909
Chris Wilson6c085a72012-08-20 11:40:46 +0200910 seq_printf(m, "Fence %d, pin count = %d, object = ",
911 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100912 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100913 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100914 else
Chris Wilson05394f32010-11-08 19:18:58 +0000915 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100916 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000917 }
918
Chris Wilson05394f32010-11-08 19:18:58 +0000919 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000920 return 0;
921}
922
Ben Gamari20172632009-02-17 20:08:50 -0500923static int i915_hws_info(struct seq_file *m, void *data)
924{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100925 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500926 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300927 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100928 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100929 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100930 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500931
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000932 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100933 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500934 if (hws == NULL)
935 return 0;
936
937 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
938 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
939 i * 4,
940 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
941 }
942 return 0;
943}
944
Daniel Vetterd5442302012-04-27 15:17:40 +0200945static ssize_t
946i915_error_state_write(struct file *filp,
947 const char __user *ubuf,
948 size_t cnt,
949 loff_t *ppos)
950{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300951 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200952 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200953 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200954
955 DRM_DEBUG_DRIVER("Resetting error state\n");
956
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200957 ret = mutex_lock_interruptible(&dev->struct_mutex);
958 if (ret)
959 return ret;
960
Daniel Vetterd5442302012-04-27 15:17:40 +0200961 i915_destroy_error_state(dev);
962 mutex_unlock(&dev->struct_mutex);
963
964 return cnt;
965}
966
967static int i915_error_state_open(struct inode *inode, struct file *file)
968{
969 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200970 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200971
972 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
973 if (!error_priv)
974 return -ENOMEM;
975
976 error_priv->dev = dev;
977
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300978 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200979
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300980 file->private_data = error_priv;
981
982 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200983}
984
985static int i915_error_state_release(struct inode *inode, struct file *file)
986{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300987 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200988
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300989 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200990 kfree(error_priv);
991
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300992 return 0;
993}
994
995static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
996 size_t count, loff_t *pos)
997{
998 struct i915_error_state_file_priv *error_priv = file->private_data;
999 struct drm_i915_error_state_buf error_str;
1000 loff_t tmp_pos = 0;
1001 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001002 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001003
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001004 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001005 if (ret)
1006 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001007
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001008 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001009 if (ret)
1010 goto out;
1011
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001012 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1013 error_str.buf,
1014 error_str.bytes);
1015
1016 if (ret_count < 0)
1017 ret = ret_count;
1018 else
1019 *pos = error_str.start + ret_count;
1020out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001021 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001022 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001023}
1024
1025static const struct file_operations i915_error_state_fops = {
1026 .owner = THIS_MODULE,
1027 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001028 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001029 .write = i915_error_state_write,
1030 .llseek = default_llseek,
1031 .release = i915_error_state_release,
1032};
1033
Kees Cook647416f2013-03-10 14:10:06 -07001034static int
1035i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001036{
Kees Cook647416f2013-03-10 14:10:06 -07001037 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001038 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001039 int ret;
1040
1041 ret = mutex_lock_interruptible(&dev->struct_mutex);
1042 if (ret)
1043 return ret;
1044
Kees Cook647416f2013-03-10 14:10:06 -07001045 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001046 mutex_unlock(&dev->struct_mutex);
1047
Kees Cook647416f2013-03-10 14:10:06 -07001048 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001049}
1050
Kees Cook647416f2013-03-10 14:10:06 -07001051static int
1052i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001053{
Kees Cook647416f2013-03-10 14:10:06 -07001054 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001055 int ret;
1056
Mika Kuoppala40633212012-12-04 15:12:00 +02001057 ret = mutex_lock_interruptible(&dev->struct_mutex);
1058 if (ret)
1059 return ret;
1060
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001061 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001062 mutex_unlock(&dev->struct_mutex);
1063
Kees Cook647416f2013-03-10 14:10:06 -07001064 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001065}
1066
Kees Cook647416f2013-03-10 14:10:06 -07001067DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1068 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001069 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001070
Deepak Sadb4bd12014-03-31 11:30:02 +05301071static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001072{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001073 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001074 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001075 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001076 int ret = 0;
1077
1078 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001079
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001080 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1081
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001082 if (IS_GEN5(dev)) {
1083 u16 rgvswctl = I915_READ16(MEMSWCTL);
1084 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1085
1086 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1087 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1088 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1089 MEMSTAT_VID_SHIFT);
1090 seq_printf(m, "Current P-state: %d\n",
1091 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001092 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
1093 IS_BROADWELL(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001094 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1095 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1096 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001097 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001098 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001099 u32 rpupei, rpcurup, rpprevup;
1100 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001101 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001102 int max_freq;
1103
1104 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001105 ret = mutex_lock_interruptible(&dev->struct_mutex);
1106 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001107 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001108
Mika Kuoppala59bad942015-01-16 11:34:40 +02001109 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001110
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001111 reqf = I915_READ(GEN6_RPNSWREQ);
1112 reqf &= ~GEN6_TURBO_DISABLE;
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001113 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001114 reqf >>= 24;
1115 else
1116 reqf >>= 25;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001117 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001118
Chris Wilson0d8f9492014-03-27 09:06:14 +00001119 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1120 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1121 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1122
Jesse Barnesccab5c82011-01-18 15:49:25 -08001123 rpstat = I915_READ(GEN6_RPSTAT1);
1124 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1125 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1126 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1127 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1128 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1129 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001130 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001131 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1132 else
1133 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001134 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001135
Mika Kuoppala59bad942015-01-16 11:34:40 +02001136 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001137 mutex_unlock(&dev->struct_mutex);
1138
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001139 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1140 pm_ier = I915_READ(GEN6_PMIER);
1141 pm_imr = I915_READ(GEN6_PMIMR);
1142 pm_isr = I915_READ(GEN6_PMISR);
1143 pm_iir = I915_READ(GEN6_PMIIR);
1144 pm_mask = I915_READ(GEN6_PMINTRMSK);
1145 } else {
1146 pm_ier = I915_READ(GEN8_GT_IER(2));
1147 pm_imr = I915_READ(GEN8_GT_IMR(2));
1148 pm_isr = I915_READ(GEN8_GT_ISR(2));
1149 pm_iir = I915_READ(GEN8_GT_IIR(2));
1150 pm_mask = I915_READ(GEN6_PMINTRMSK);
1151 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001152 seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001153 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001154 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001155 seq_printf(m, "Render p-state ratio: %d\n",
1156 (gt_perf_status & 0xff00) >> 8);
1157 seq_printf(m, "Render p-state VID: %d\n",
1158 gt_perf_status & 0xff);
1159 seq_printf(m, "Render p-state limit: %d\n",
1160 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001161 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1162 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1163 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1164 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001165 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001166 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001167 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1168 GEN6_CURICONT_MASK);
1169 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1170 GEN6_CURBSYTAVG_MASK);
1171 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1172 GEN6_CURBSYTAVG_MASK);
1173 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1174 GEN6_CURIAVG_MASK);
1175 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1176 GEN6_CURBSYTAVG_MASK);
1177 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1178 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001179
1180 max_freq = (rp_state_cap & 0xff0000) >> 16;
1181 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001182 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001183
1184 max_freq = (rp_state_cap & 0xff00) >> 8;
1185 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001186 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001187
1188 max_freq = rp_state_cap & 0xff;
1189 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001190 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001191
1192 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001193 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001194 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001195 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001196
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001197 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001198 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001199 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1200 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1201
Jesse Barnes0a073b82013-04-17 15:54:58 -07001202 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001203 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001204
Jesse Barnes0a073b82013-04-17 15:54:58 -07001205 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001206 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001207
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001208 seq_printf(m,
1209 "efficient (RPe) frequency: %d MHz\n",
1210 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001211
1212 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001213 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001214 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001215 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001216 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001217 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001218
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001219out:
1220 intel_runtime_pm_put(dev_priv);
1221 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001222}
1223
Chris Wilsonf6544492015-01-26 18:03:04 +02001224static int i915_hangcheck_info(struct seq_file *m, void *unused)
1225{
1226 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001227 struct drm_device *dev = node->minor->dev;
1228 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf6544492015-01-26 18:03:04 +02001229 struct intel_engine_cs *ring;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001230 u64 acthd[I915_NUM_RINGS];
1231 u32 seqno[I915_NUM_RINGS];
Chris Wilsonf6544492015-01-26 18:03:04 +02001232 int i;
1233
1234 if (!i915.enable_hangcheck) {
1235 seq_printf(m, "Hangcheck disabled\n");
1236 return 0;
1237 }
1238
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001239 intel_runtime_pm_get(dev_priv);
1240
1241 for_each_ring(ring, dev_priv, i) {
1242 seqno[i] = ring->get_seqno(ring, false);
1243 acthd[i] = intel_ring_get_active_head(ring);
1244 }
1245
1246 intel_runtime_pm_put(dev_priv);
1247
Chris Wilsonf6544492015-01-26 18:03:04 +02001248 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1249 seq_printf(m, "Hangcheck active, fires in %dms\n",
1250 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1251 jiffies));
1252 } else
1253 seq_printf(m, "Hangcheck inactive\n");
1254
1255 for_each_ring(ring, dev_priv, i) {
1256 seq_printf(m, "%s:\n", ring->name);
1257 seq_printf(m, "\tseqno = %x [current %x]\n",
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001258 ring->hangcheck.seqno, seqno[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001259 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1260 (long long)ring->hangcheck.acthd,
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001261 (long long)acthd[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001262 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1263 (long long)ring->hangcheck.max_acthd);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001264 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1265 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
Chris Wilsonf6544492015-01-26 18:03:04 +02001266 }
1267
1268 return 0;
1269}
1270
Ben Widawsky4d855292011-12-12 19:34:16 -08001271static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001272{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001273 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001274 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001275 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001276 u32 rgvmodectl, rstdbyctl;
1277 u16 crstandvid;
1278 int ret;
1279
1280 ret = mutex_lock_interruptible(&dev->struct_mutex);
1281 if (ret)
1282 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001283 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001284
1285 rgvmodectl = I915_READ(MEMMODECTL);
1286 rstdbyctl = I915_READ(RSTDBYCTL);
1287 crstandvid = I915_READ16(CRSTANDVID);
1288
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001289 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001290 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001291
1292 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1293 "yes" : "no");
1294 seq_printf(m, "Boost freq: %d\n",
1295 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1296 MEMMODE_BOOST_FREQ_SHIFT);
1297 seq_printf(m, "HW control enabled: %s\n",
1298 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1299 seq_printf(m, "SW control enabled: %s\n",
1300 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1301 seq_printf(m, "Gated voltage change: %s\n",
1302 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1303 seq_printf(m, "Starting frequency: P%d\n",
1304 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001305 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001306 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001307 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1308 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1309 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1310 seq_printf(m, "Render standby enabled: %s\n",
1311 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001312 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001313 switch (rstdbyctl & RSX_STATUS_MASK) {
1314 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001315 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001316 break;
1317 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001318 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001319 break;
1320 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001321 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001322 break;
1323 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001324 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001325 break;
1326 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001327 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001328 break;
1329 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001330 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001331 break;
1332 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001333 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001334 break;
1335 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001336
1337 return 0;
1338}
1339
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001340static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001341{
1342 struct drm_info_node *node = m->private;
1343 struct drm_device *dev = node->minor->dev;
1344 struct drm_i915_private *dev_priv = dev->dev_private;
1345 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001346 int i;
1347
1348 spin_lock_irq(&dev_priv->uncore.lock);
1349 for_each_fw_domain(fw_domain, dev_priv, i) {
1350 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001351 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001352 fw_domain->wake_count);
1353 }
1354 spin_unlock_irq(&dev_priv->uncore.lock);
1355
1356 return 0;
1357}
1358
Deepak S669ab5a2014-01-10 15:18:26 +05301359static int vlv_drpc_info(struct seq_file *m)
1360{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001361 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301362 struct drm_device *dev = node->minor->dev;
1363 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001364 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301365
Imre Deakd46c0512014-04-14 20:24:27 +03001366 intel_runtime_pm_get(dev_priv);
1367
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001368 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301369 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1370 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1371
Imre Deakd46c0512014-04-14 20:24:27 +03001372 intel_runtime_pm_put(dev_priv);
1373
Deepak S669ab5a2014-01-10 15:18:26 +05301374 seq_printf(m, "Video Turbo Mode: %s\n",
1375 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1376 seq_printf(m, "Turbo enabled: %s\n",
1377 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1378 seq_printf(m, "HW control enabled: %s\n",
1379 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1380 seq_printf(m, "SW control enabled: %s\n",
1381 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1382 GEN6_RP_MEDIA_SW_MODE));
1383 seq_printf(m, "RC6 Enabled: %s\n",
1384 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1385 GEN6_RC_CTL_EI_MODE(1))));
1386 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001387 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301388 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001389 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301390
Imre Deak9cc19be2014-04-14 20:24:24 +03001391 seq_printf(m, "Render RC6 residency since boot: %u\n",
1392 I915_READ(VLV_GT_RENDER_RC6));
1393 seq_printf(m, "Media RC6 residency since boot: %u\n",
1394 I915_READ(VLV_GT_MEDIA_RC6));
1395
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001396 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301397}
1398
Ben Widawsky4d855292011-12-12 19:34:16 -08001399static int gen6_drpc_info(struct seq_file *m)
1400{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001401 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001402 struct drm_device *dev = node->minor->dev;
1403 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001404 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001405 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001406 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001407
1408 ret = mutex_lock_interruptible(&dev->struct_mutex);
1409 if (ret)
1410 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001411 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001412
Chris Wilson907b28c2013-07-19 20:36:52 +01001413 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001414 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001415 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001416
1417 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001418 seq_puts(m, "RC information inaccurate because somebody "
1419 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001420 } else {
1421 /* NB: we cannot use forcewake, else we read the wrong values */
1422 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1423 udelay(10);
1424 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1425 }
1426
1427 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001428 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001429
1430 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1431 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1432 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001433 mutex_lock(&dev_priv->rps.hw_lock);
1434 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1435 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001436
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001437 intel_runtime_pm_put(dev_priv);
1438
Ben Widawsky4d855292011-12-12 19:34:16 -08001439 seq_printf(m, "Video Turbo Mode: %s\n",
1440 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1441 seq_printf(m, "HW control enabled: %s\n",
1442 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1443 seq_printf(m, "SW control enabled: %s\n",
1444 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1445 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001446 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001447 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1448 seq_printf(m, "RC6 Enabled: %s\n",
1449 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1450 seq_printf(m, "Deep RC6 Enabled: %s\n",
1451 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1452 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1453 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001454 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001455 switch (gt_core_status & GEN6_RCn_MASK) {
1456 case GEN6_RC0:
1457 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001458 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001459 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001460 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001461 break;
1462 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001463 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001464 break;
1465 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001466 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001467 break;
1468 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001469 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001470 break;
1471 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001472 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001473 break;
1474 }
1475
1476 seq_printf(m, "Core Power Down: %s\n",
1477 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001478
1479 /* Not exactly sure what this is */
1480 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1481 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1482 seq_printf(m, "RC6 residency since boot: %u\n",
1483 I915_READ(GEN6_GT_GFX_RC6));
1484 seq_printf(m, "RC6+ residency since boot: %u\n",
1485 I915_READ(GEN6_GT_GFX_RC6p));
1486 seq_printf(m, "RC6++ residency since boot: %u\n",
1487 I915_READ(GEN6_GT_GFX_RC6pp));
1488
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001489 seq_printf(m, "RC6 voltage: %dmV\n",
1490 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1491 seq_printf(m, "RC6+ voltage: %dmV\n",
1492 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1493 seq_printf(m, "RC6++ voltage: %dmV\n",
1494 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001495 return 0;
1496}
1497
1498static int i915_drpc_info(struct seq_file *m, void *unused)
1499{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001500 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001501 struct drm_device *dev = node->minor->dev;
1502
Deepak S669ab5a2014-01-10 15:18:26 +05301503 if (IS_VALLEYVIEW(dev))
1504 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001505 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001506 return gen6_drpc_info(m);
1507 else
1508 return ironlake_drpc_info(m);
1509}
1510
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001511static int i915_fbc_status(struct seq_file *m, void *unused)
1512{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001513 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001514 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001515 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001516
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001517 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001518 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001519 return 0;
1520 }
1521
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001522 intel_runtime_pm_get(dev_priv);
1523
Adam Jacksonee5382a2010-04-23 11:17:39 -04001524 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001525 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001526 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001527 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001528 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001529 case FBC_OK:
1530 seq_puts(m, "FBC actived, but currently disabled in hardware");
1531 break;
1532 case FBC_UNSUPPORTED:
1533 seq_puts(m, "unsupported by this chipset");
1534 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001535 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001536 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001537 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001538 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001539 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001540 break;
1541 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001542 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001543 break;
1544 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001545 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001546 break;
1547 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001548 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001549 break;
1550 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001551 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001552 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001553 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001554 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001555 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001556 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001557 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001558 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001559 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001560 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001561 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001562 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001563 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001564 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001565 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001566 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001567
1568 intel_runtime_pm_put(dev_priv);
1569
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001570 return 0;
1571}
1572
Rodrigo Vivida46f932014-08-01 02:04:45 -07001573static int i915_fbc_fc_get(void *data, u64 *val)
1574{
1575 struct drm_device *dev = data;
1576 struct drm_i915_private *dev_priv = dev->dev_private;
1577
1578 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1579 return -ENODEV;
1580
1581 drm_modeset_lock_all(dev);
1582 *val = dev_priv->fbc.false_color;
1583 drm_modeset_unlock_all(dev);
1584
1585 return 0;
1586}
1587
1588static int i915_fbc_fc_set(void *data, u64 val)
1589{
1590 struct drm_device *dev = data;
1591 struct drm_i915_private *dev_priv = dev->dev_private;
1592 u32 reg;
1593
1594 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1595 return -ENODEV;
1596
1597 drm_modeset_lock_all(dev);
1598
1599 reg = I915_READ(ILK_DPFC_CONTROL);
1600 dev_priv->fbc.false_color = val;
1601
1602 I915_WRITE(ILK_DPFC_CONTROL, val ?
1603 (reg | FBC_CTL_FALSE_COLOR) :
1604 (reg & ~FBC_CTL_FALSE_COLOR));
1605
1606 drm_modeset_unlock_all(dev);
1607 return 0;
1608}
1609
1610DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1611 i915_fbc_fc_get, i915_fbc_fc_set,
1612 "%llu\n");
1613
Paulo Zanoni92d44622013-05-31 16:33:24 -03001614static int i915_ips_status(struct seq_file *m, void *unused)
1615{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001616 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001617 struct drm_device *dev = node->minor->dev;
1618 struct drm_i915_private *dev_priv = dev->dev_private;
1619
Damien Lespiauf5adf942013-06-24 18:29:34 +01001620 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001621 seq_puts(m, "not supported\n");
1622 return 0;
1623 }
1624
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001625 intel_runtime_pm_get(dev_priv);
1626
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001627 seq_printf(m, "Enabled by kernel parameter: %s\n",
1628 yesno(i915.enable_ips));
1629
1630 if (INTEL_INFO(dev)->gen >= 8) {
1631 seq_puts(m, "Currently: unknown\n");
1632 } else {
1633 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1634 seq_puts(m, "Currently: enabled\n");
1635 else
1636 seq_puts(m, "Currently: disabled\n");
1637 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001638
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001639 intel_runtime_pm_put(dev_priv);
1640
Paulo Zanoni92d44622013-05-31 16:33:24 -03001641 return 0;
1642}
1643
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001644static int i915_sr_status(struct seq_file *m, void *unused)
1645{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001646 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001647 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001648 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001649 bool sr_enabled = false;
1650
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001651 intel_runtime_pm_get(dev_priv);
1652
Yuanhan Liu13982612010-12-15 15:42:31 +08001653 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001654 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001655 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001656 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1657 else if (IS_I915GM(dev))
1658 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1659 else if (IS_PINEVIEW(dev))
1660 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1661
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001662 intel_runtime_pm_put(dev_priv);
1663
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001664 seq_printf(m, "self-refresh: %s\n",
1665 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001666
1667 return 0;
1668}
1669
Jesse Barnes7648fa92010-05-20 14:28:11 -07001670static int i915_emon_status(struct seq_file *m, void *unused)
1671{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001672 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001673 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001674 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001675 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001676 int ret;
1677
Chris Wilson582be6b2012-04-30 19:35:02 +01001678 if (!IS_GEN5(dev))
1679 return -ENODEV;
1680
Chris Wilsonde227ef2010-07-03 07:58:38 +01001681 ret = mutex_lock_interruptible(&dev->struct_mutex);
1682 if (ret)
1683 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001684
1685 temp = i915_mch_val(dev_priv);
1686 chipset = i915_chipset_val(dev_priv);
1687 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001688 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001689
1690 seq_printf(m, "GMCH temp: %ld\n", temp);
1691 seq_printf(m, "Chipset power: %ld\n", chipset);
1692 seq_printf(m, "GFX power: %ld\n", gfx);
1693 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1694
1695 return 0;
1696}
1697
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001698static int i915_ring_freq_table(struct seq_file *m, void *unused)
1699{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001700 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001701 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001702 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001703 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001704 int gpu_freq, ia_freq;
1705
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001706 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001707 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001708 return 0;
1709 }
1710
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001711 intel_runtime_pm_get(dev_priv);
1712
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001713 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1714
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001715 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001716 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001717 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001718
Damien Lespiau267f0c92013-06-24 22:59:48 +01001719 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001720
Ben Widawskyb39fb292014-03-19 18:31:11 -07001721 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1722 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001723 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001724 ia_freq = gpu_freq;
1725 sandybridge_pcode_read(dev_priv,
1726 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1727 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001728 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001729 intel_gpu_freq(dev_priv, gpu_freq),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001730 ((ia_freq >> 0) & 0xff) * 100,
1731 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001732 }
1733
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001734 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001735
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001736out:
1737 intel_runtime_pm_put(dev_priv);
1738 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001739}
1740
Chris Wilson44834a62010-08-19 16:09:23 +01001741static int i915_opregion(struct seq_file *m, void *unused)
1742{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001743 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001744 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001745 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001746 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001747 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001748 int ret;
1749
Daniel Vetter0d38f002012-04-21 22:49:10 +02001750 if (data == NULL)
1751 return -ENOMEM;
1752
Chris Wilson44834a62010-08-19 16:09:23 +01001753 ret = mutex_lock_interruptible(&dev->struct_mutex);
1754 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001755 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001756
Daniel Vetter0d38f002012-04-21 22:49:10 +02001757 if (opregion->header) {
1758 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1759 seq_write(m, data, OPREGION_SIZE);
1760 }
Chris Wilson44834a62010-08-19 16:09:23 +01001761
1762 mutex_unlock(&dev->struct_mutex);
1763
Daniel Vetter0d38f002012-04-21 22:49:10 +02001764out:
1765 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001766 return 0;
1767}
1768
Chris Wilson37811fc2010-08-25 22:45:57 +01001769static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1770{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001771 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001772 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001773 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001774 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001775
Daniel Vetter4520f532013-10-09 09:18:51 +02001776#ifdef CONFIG_DRM_I915_FBDEV
1777 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001778
1779 ifbdev = dev_priv->fbdev;
1780 fb = to_intel_framebuffer(ifbdev->helper.fb);
1781
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001782 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001783 fb->base.width,
1784 fb->base.height,
1785 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001786 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001787 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001788 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001789 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001790 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001791#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001792
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001793 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001794 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001795 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001796 continue;
1797
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001798 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001799 fb->base.width,
1800 fb->base.height,
1801 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001802 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001803 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001804 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001805 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001806 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001807 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001808 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001809
1810 return 0;
1811}
1812
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001813static void describe_ctx_ringbuf(struct seq_file *m,
1814 struct intel_ringbuffer *ringbuf)
1815{
1816 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1817 ringbuf->space, ringbuf->head, ringbuf->tail,
1818 ringbuf->last_retired_head);
1819}
1820
Ben Widawskye76d3632011-03-19 18:14:29 -07001821static int i915_context_status(struct seq_file *m, void *unused)
1822{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001823 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001824 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001825 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001826 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001827 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001828 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001829
Daniel Vetterf3d28872014-05-29 23:23:08 +02001830 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001831 if (ret)
1832 return ret;
1833
Daniel Vetter3e373942012-11-02 19:55:04 +01001834 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001835 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001836 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001837 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001838 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001839
Daniel Vetter3e373942012-11-02 19:55:04 +01001840 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001841 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001842 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001843 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001844 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001845
Ben Widawskya33afea2013-09-17 21:12:45 -07001846 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001847 if (!i915.enable_execlists &&
1848 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001849 continue;
1850
Ben Widawskya33afea2013-09-17 21:12:45 -07001851 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001852 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001853 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001854 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001855 seq_printf(m, "(default context %s) ",
1856 ring->name);
1857 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001858
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001859 if (i915.enable_execlists) {
1860 seq_putc(m, '\n');
1861 for_each_ring(ring, dev_priv, i) {
1862 struct drm_i915_gem_object *ctx_obj =
1863 ctx->engine[i].state;
1864 struct intel_ringbuffer *ringbuf =
1865 ctx->engine[i].ringbuf;
1866
1867 seq_printf(m, "%s: ", ring->name);
1868 if (ctx_obj)
1869 describe_obj(m, ctx_obj);
1870 if (ringbuf)
1871 describe_ctx_ringbuf(m, ringbuf);
1872 seq_putc(m, '\n');
1873 }
1874 } else {
1875 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1876 }
1877
Ben Widawskya33afea2013-09-17 21:12:45 -07001878 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001879 }
1880
Daniel Vetterf3d28872014-05-29 23:23:08 +02001881 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001882
1883 return 0;
1884}
1885
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001886static void i915_dump_lrc_obj(struct seq_file *m,
1887 struct intel_engine_cs *ring,
1888 struct drm_i915_gem_object *ctx_obj)
1889{
1890 struct page *page;
1891 uint32_t *reg_state;
1892 int j;
1893 unsigned long ggtt_offset = 0;
1894
1895 if (ctx_obj == NULL) {
1896 seq_printf(m, "Context on %s with no gem object\n",
1897 ring->name);
1898 return;
1899 }
1900
1901 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1902 intel_execlists_ctx_id(ctx_obj));
1903
1904 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1905 seq_puts(m, "\tNot bound in GGTT\n");
1906 else
1907 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1908
1909 if (i915_gem_object_get_pages(ctx_obj)) {
1910 seq_puts(m, "\tFailed to get pages for context object\n");
1911 return;
1912 }
1913
1914 page = i915_gem_object_get_page(ctx_obj, 1);
1915 if (!WARN_ON(page == NULL)) {
1916 reg_state = kmap_atomic(page);
1917
1918 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
1919 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1920 ggtt_offset + 4096 + (j * 4),
1921 reg_state[j], reg_state[j + 1],
1922 reg_state[j + 2], reg_state[j + 3]);
1923 }
1924 kunmap_atomic(reg_state);
1925 }
1926
1927 seq_putc(m, '\n');
1928}
1929
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01001930static int i915_dump_lrc(struct seq_file *m, void *unused)
1931{
1932 struct drm_info_node *node = (struct drm_info_node *) m->private;
1933 struct drm_device *dev = node->minor->dev;
1934 struct drm_i915_private *dev_priv = dev->dev_private;
1935 struct intel_engine_cs *ring;
1936 struct intel_context *ctx;
1937 int ret, i;
1938
1939 if (!i915.enable_execlists) {
1940 seq_printf(m, "Logical Ring Contexts are disabled\n");
1941 return 0;
1942 }
1943
1944 ret = mutex_lock_interruptible(&dev->struct_mutex);
1945 if (ret)
1946 return ret;
1947
1948 list_for_each_entry(ctx, &dev_priv->context_list, link) {
1949 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001950 if (ring->default_context != ctx)
1951 i915_dump_lrc_obj(m, ring,
1952 ctx->engine[i].state);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01001953 }
1954 }
1955
1956 mutex_unlock(&dev->struct_mutex);
1957
1958 return 0;
1959}
1960
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001961static int i915_execlists(struct seq_file *m, void *data)
1962{
1963 struct drm_info_node *node = (struct drm_info_node *)m->private;
1964 struct drm_device *dev = node->minor->dev;
1965 struct drm_i915_private *dev_priv = dev->dev_private;
1966 struct intel_engine_cs *ring;
1967 u32 status_pointer;
1968 u8 read_pointer;
1969 u8 write_pointer;
1970 u32 status;
1971 u32 ctx_id;
1972 struct list_head *cursor;
1973 int ring_id, i;
1974 int ret;
1975
1976 if (!i915.enable_execlists) {
1977 seq_puts(m, "Logical Ring Contexts are disabled\n");
1978 return 0;
1979 }
1980
1981 ret = mutex_lock_interruptible(&dev->struct_mutex);
1982 if (ret)
1983 return ret;
1984
Michel Thierryfc0412e2014-10-16 16:13:38 +01001985 intel_runtime_pm_get(dev_priv);
1986
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001987 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00001988 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001989 int count = 0;
1990 unsigned long flags;
1991
1992 seq_printf(m, "%s\n", ring->name);
1993
1994 status = I915_READ(RING_EXECLIST_STATUS(ring));
1995 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
1996 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
1997 status, ctx_id);
1998
1999 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2000 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2001
2002 read_pointer = ring->next_context_status_buffer;
2003 write_pointer = status_pointer & 0x07;
2004 if (read_pointer > write_pointer)
2005 write_pointer += 6;
2006 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2007 read_pointer, write_pointer);
2008
2009 for (i = 0; i < 6; i++) {
2010 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
2011 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
2012
2013 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2014 i, status, ctx_id);
2015 }
2016
2017 spin_lock_irqsave(&ring->execlist_lock, flags);
2018 list_for_each(cursor, &ring->execlist_queue)
2019 count++;
2020 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002021 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002022 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2023
2024 seq_printf(m, "\t%d requests in queue\n", count);
2025 if (head_req) {
2026 struct drm_i915_gem_object *ctx_obj;
2027
Nick Hoath6d3d8272015-01-15 13:10:39 +00002028 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002029 seq_printf(m, "\tHead request id: %u\n",
2030 intel_execlists_ctx_id(ctx_obj));
2031 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002032 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002033 }
2034
2035 seq_putc(m, '\n');
2036 }
2037
Michel Thierryfc0412e2014-10-16 16:13:38 +01002038 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002039 mutex_unlock(&dev->struct_mutex);
2040
2041 return 0;
2042}
2043
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002044static const char *swizzle_string(unsigned swizzle)
2045{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002046 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002047 case I915_BIT_6_SWIZZLE_NONE:
2048 return "none";
2049 case I915_BIT_6_SWIZZLE_9:
2050 return "bit9";
2051 case I915_BIT_6_SWIZZLE_9_10:
2052 return "bit9/bit10";
2053 case I915_BIT_6_SWIZZLE_9_11:
2054 return "bit9/bit11";
2055 case I915_BIT_6_SWIZZLE_9_10_11:
2056 return "bit9/bit10/bit11";
2057 case I915_BIT_6_SWIZZLE_9_17:
2058 return "bit9/bit17";
2059 case I915_BIT_6_SWIZZLE_9_10_17:
2060 return "bit9/bit10/bit17";
2061 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002062 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002063 }
2064
2065 return "bug";
2066}
2067
2068static int i915_swizzle_info(struct seq_file *m, void *data)
2069{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002070 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002071 struct drm_device *dev = node->minor->dev;
2072 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002073 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002074
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002075 ret = mutex_lock_interruptible(&dev->struct_mutex);
2076 if (ret)
2077 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002078 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002079
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002080 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2081 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2082 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2083 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2084
2085 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2086 seq_printf(m, "DDC = 0x%08x\n",
2087 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002088 seq_printf(m, "DDC2 = 0x%08x\n",
2089 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002090 seq_printf(m, "C0DRB3 = 0x%04x\n",
2091 I915_READ16(C0DRB3));
2092 seq_printf(m, "C1DRB3 = 0x%04x\n",
2093 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002094 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002095 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2096 I915_READ(MAD_DIMM_C0));
2097 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2098 I915_READ(MAD_DIMM_C1));
2099 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2100 I915_READ(MAD_DIMM_C2));
2101 seq_printf(m, "TILECTL = 0x%08x\n",
2102 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002103 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002104 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2105 I915_READ(GAMTARBMODE));
2106 else
2107 seq_printf(m, "ARB_MODE = 0x%08x\n",
2108 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002109 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2110 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002111 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002112
2113 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2114 seq_puts(m, "L-shaped memory detected\n");
2115
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002116 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002117 mutex_unlock(&dev->struct_mutex);
2118
2119 return 0;
2120}
2121
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002122static int per_file_ctx(int id, void *ptr, void *data)
2123{
Oscar Mateo273497e2014-05-22 14:13:37 +01002124 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002125 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002126 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2127
2128 if (!ppgtt) {
2129 seq_printf(m, " no ppgtt for context %d\n",
2130 ctx->user_handle);
2131 return 0;
2132 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002133
Oscar Mateof83d6512014-05-22 14:13:38 +01002134 if (i915_gem_context_is_default(ctx))
2135 seq_puts(m, " default context:\n");
2136 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002137 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002138 ppgtt->debug_dump(ppgtt, m);
2139
2140 return 0;
2141}
2142
Ben Widawsky77df6772013-11-02 21:07:30 -07002143static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002144{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002145 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002146 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002147 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2148 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002149
Ben Widawsky77df6772013-11-02 21:07:30 -07002150 if (!ppgtt)
2151 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002152
Ben Widawsky77df6772013-11-02 21:07:30 -07002153 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08002154 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07002155 for_each_ring(ring, dev_priv, unused) {
2156 seq_printf(m, "%s\n", ring->name);
2157 for (i = 0; i < 4; i++) {
2158 u32 offset = 0x270 + i * 8;
2159 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2160 pdp <<= 32;
2161 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002162 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002163 }
2164 }
2165}
2166
2167static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2168{
2169 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002170 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002171 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002172 int i;
2173
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002174 if (INTEL_INFO(dev)->gen == 6)
2175 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2176
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002177 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002178 seq_printf(m, "%s\n", ring->name);
2179 if (INTEL_INFO(dev)->gen == 7)
2180 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2181 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2182 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2183 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2184 }
2185 if (dev_priv->mm.aliasing_ppgtt) {
2186 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2187
Damien Lespiau267f0c92013-06-24 22:59:48 +01002188 seq_puts(m, "aliasing PPGTT:\n");
Ben Widawsky7324cc02015-02-24 16:22:35 +00002189 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002190
Ben Widawsky87d60b62013-12-06 14:11:29 -08002191 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002192 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002193
2194 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2195 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002196
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002197 seq_printf(m, "proc: %s\n",
2198 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002199 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002200 }
2201 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002202}
2203
2204static int i915_ppgtt_info(struct seq_file *m, void *data)
2205{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002206 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002207 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002208 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002209
2210 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2211 if (ret)
2212 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002213 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002214
2215 if (INTEL_INFO(dev)->gen >= 8)
2216 gen8_ppgtt_info(m, dev);
2217 else if (INTEL_INFO(dev)->gen >= 6)
2218 gen6_ppgtt_info(m, dev);
2219
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002220 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002221 mutex_unlock(&dev->struct_mutex);
2222
2223 return 0;
2224}
2225
Ben Widawsky63573eb2013-07-04 11:02:07 -07002226static int i915_llc(struct seq_file *m, void *data)
2227{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002228 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002229 struct drm_device *dev = node->minor->dev;
2230 struct drm_i915_private *dev_priv = dev->dev_private;
2231
2232 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2233 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2234 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2235
2236 return 0;
2237}
2238
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002239static int i915_edp_psr_status(struct seq_file *m, void *data)
2240{
2241 struct drm_info_node *node = m->private;
2242 struct drm_device *dev = node->minor->dev;
2243 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002244 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002245 u32 stat[3];
2246 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002247 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002248
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002249 intel_runtime_pm_get(dev_priv);
2250
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002251 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002252 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2253 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002254 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002255 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002256 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2257 dev_priv->psr.busy_frontbuffer_bits);
2258 seq_printf(m, "Re-enable work scheduled: %s\n",
2259 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002260
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002261 if (HAS_PSR(dev)) {
2262 if (HAS_DDI(dev))
2263 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2264 else {
2265 for_each_pipe(dev_priv, pipe) {
2266 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2267 VLV_EDP_PSR_CURR_STATE_MASK;
2268 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2269 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2270 enabled = true;
2271 }
2272 }
2273 }
2274 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002275
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002276 if (!HAS_DDI(dev))
2277 for_each_pipe(dev_priv, pipe) {
2278 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2279 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2280 seq_printf(m, " pipe %c", pipe_name(pipe));
2281 }
2282 seq_puts(m, "\n");
2283
Rodrigo Vivifb495812015-01-12 10:14:33 -08002284 seq_printf(m, "Link standby: %s\n",
2285 yesno((bool)dev_priv->psr.link_standby));
2286
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002287 /* CHV PSR has no kind of performance counter */
2288 if (HAS_PSR(dev) && HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002289 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2290 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002291
2292 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2293 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002294 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002295
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002296 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002297 return 0;
2298}
2299
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002300static int i915_sink_crc(struct seq_file *m, void *data)
2301{
2302 struct drm_info_node *node = m->private;
2303 struct drm_device *dev = node->minor->dev;
2304 struct intel_encoder *encoder;
2305 struct intel_connector *connector;
2306 struct intel_dp *intel_dp = NULL;
2307 int ret;
2308 u8 crc[6];
2309
2310 drm_modeset_lock_all(dev);
Ander Conselvan de Oliveira3a3371f2015-03-03 15:21:56 +02002311 for_each_intel_encoder(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002312
2313 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2314 continue;
2315
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002316 if (!connector->base.encoder)
2317 continue;
2318
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002319 encoder = to_intel_encoder(connector->base.encoder);
2320 if (encoder->type != INTEL_OUTPUT_EDP)
2321 continue;
2322
2323 intel_dp = enc_to_intel_dp(&encoder->base);
2324
2325 ret = intel_dp_sink_crc(intel_dp, crc);
2326 if (ret)
2327 goto out;
2328
2329 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2330 crc[0], crc[1], crc[2],
2331 crc[3], crc[4], crc[5]);
2332 goto out;
2333 }
2334 ret = -ENODEV;
2335out:
2336 drm_modeset_unlock_all(dev);
2337 return ret;
2338}
2339
Jesse Barnesec013e72013-08-20 10:29:23 +01002340static int i915_energy_uJ(struct seq_file *m, void *data)
2341{
2342 struct drm_info_node *node = m->private;
2343 struct drm_device *dev = node->minor->dev;
2344 struct drm_i915_private *dev_priv = dev->dev_private;
2345 u64 power;
2346 u32 units;
2347
2348 if (INTEL_INFO(dev)->gen < 6)
2349 return -ENODEV;
2350
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002351 intel_runtime_pm_get(dev_priv);
2352
Jesse Barnesec013e72013-08-20 10:29:23 +01002353 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2354 power = (power & 0x1f00) >> 8;
2355 units = 1000000 / (1 << power); /* convert to uJ */
2356 power = I915_READ(MCH_SECP_NRG_STTS);
2357 power *= units;
2358
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002359 intel_runtime_pm_put(dev_priv);
2360
Jesse Barnesec013e72013-08-20 10:29:23 +01002361 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002362
2363 return 0;
2364}
2365
2366static int i915_pc8_status(struct seq_file *m, void *unused)
2367{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002368 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002369 struct drm_device *dev = node->minor->dev;
2370 struct drm_i915_private *dev_priv = dev->dev_private;
2371
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002372 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002373 seq_puts(m, "not supported\n");
2374 return 0;
2375 }
2376
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002377 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002378 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002379 yesno(!intel_irqs_enabled(dev_priv)));
Paulo Zanoni371db662013-08-19 13:18:10 -03002380
Jesse Barnesec013e72013-08-20 10:29:23 +01002381 return 0;
2382}
2383
Imre Deak1da51582013-11-25 17:15:35 +02002384static const char *power_domain_str(enum intel_display_power_domain domain)
2385{
2386 switch (domain) {
2387 case POWER_DOMAIN_PIPE_A:
2388 return "PIPE_A";
2389 case POWER_DOMAIN_PIPE_B:
2390 return "PIPE_B";
2391 case POWER_DOMAIN_PIPE_C:
2392 return "PIPE_C";
2393 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2394 return "PIPE_A_PANEL_FITTER";
2395 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2396 return "PIPE_B_PANEL_FITTER";
2397 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2398 return "PIPE_C_PANEL_FITTER";
2399 case POWER_DOMAIN_TRANSCODER_A:
2400 return "TRANSCODER_A";
2401 case POWER_DOMAIN_TRANSCODER_B:
2402 return "TRANSCODER_B";
2403 case POWER_DOMAIN_TRANSCODER_C:
2404 return "TRANSCODER_C";
2405 case POWER_DOMAIN_TRANSCODER_EDP:
2406 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002407 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2408 return "PORT_DDI_A_2_LANES";
2409 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2410 return "PORT_DDI_A_4_LANES";
2411 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2412 return "PORT_DDI_B_2_LANES";
2413 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2414 return "PORT_DDI_B_4_LANES";
2415 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2416 return "PORT_DDI_C_2_LANES";
2417 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2418 return "PORT_DDI_C_4_LANES";
2419 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2420 return "PORT_DDI_D_2_LANES";
2421 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2422 return "PORT_DDI_D_4_LANES";
2423 case POWER_DOMAIN_PORT_DSI:
2424 return "PORT_DSI";
2425 case POWER_DOMAIN_PORT_CRT:
2426 return "PORT_CRT";
2427 case POWER_DOMAIN_PORT_OTHER:
2428 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002429 case POWER_DOMAIN_VGA:
2430 return "VGA";
2431 case POWER_DOMAIN_AUDIO:
2432 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002433 case POWER_DOMAIN_PLLS:
2434 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002435 case POWER_DOMAIN_AUX_A:
2436 return "AUX_A";
2437 case POWER_DOMAIN_AUX_B:
2438 return "AUX_B";
2439 case POWER_DOMAIN_AUX_C:
2440 return "AUX_C";
2441 case POWER_DOMAIN_AUX_D:
2442 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002443 case POWER_DOMAIN_INIT:
2444 return "INIT";
2445 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002446 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002447 return "?";
2448 }
2449}
2450
2451static int i915_power_domain_info(struct seq_file *m, void *unused)
2452{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002453 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002454 struct drm_device *dev = node->minor->dev;
2455 struct drm_i915_private *dev_priv = dev->dev_private;
2456 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2457 int i;
2458
2459 mutex_lock(&power_domains->lock);
2460
2461 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2462 for (i = 0; i < power_domains->power_well_count; i++) {
2463 struct i915_power_well *power_well;
2464 enum intel_display_power_domain power_domain;
2465
2466 power_well = &power_domains->power_wells[i];
2467 seq_printf(m, "%-25s %d\n", power_well->name,
2468 power_well->count);
2469
2470 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2471 power_domain++) {
2472 if (!(BIT(power_domain) & power_well->domains))
2473 continue;
2474
2475 seq_printf(m, " %-23s %d\n",
2476 power_domain_str(power_domain),
2477 power_domains->domain_use_count[power_domain]);
2478 }
2479 }
2480
2481 mutex_unlock(&power_domains->lock);
2482
2483 return 0;
2484}
2485
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002486static void intel_seq_print_mode(struct seq_file *m, int tabs,
2487 struct drm_display_mode *mode)
2488{
2489 int i;
2490
2491 for (i = 0; i < tabs; i++)
2492 seq_putc(m, '\t');
2493
2494 seq_printf(m, "id %d:\"%s\" freq %d clock %d hdisp %d hss %d hse %d htot %d vdisp %d vss %d vse %d vtot %d type 0x%x flags 0x%x\n",
2495 mode->base.id, mode->name,
2496 mode->vrefresh, mode->clock,
2497 mode->hdisplay, mode->hsync_start,
2498 mode->hsync_end, mode->htotal,
2499 mode->vdisplay, mode->vsync_start,
2500 mode->vsync_end, mode->vtotal,
2501 mode->type, mode->flags);
2502}
2503
2504static void intel_encoder_info(struct seq_file *m,
2505 struct intel_crtc *intel_crtc,
2506 struct intel_encoder *intel_encoder)
2507{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002508 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002509 struct drm_device *dev = node->minor->dev;
2510 struct drm_crtc *crtc = &intel_crtc->base;
2511 struct intel_connector *intel_connector;
2512 struct drm_encoder *encoder;
2513
2514 encoder = &intel_encoder->base;
2515 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002516 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002517 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2518 struct drm_connector *connector = &intel_connector->base;
2519 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2520 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002521 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002522 drm_get_connector_status_name(connector->status));
2523 if (connector->status == connector_status_connected) {
2524 struct drm_display_mode *mode = &crtc->mode;
2525 seq_printf(m, ", mode:\n");
2526 intel_seq_print_mode(m, 2, mode);
2527 } else {
2528 seq_putc(m, '\n');
2529 }
2530 }
2531}
2532
2533static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2534{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002535 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002536 struct drm_device *dev = node->minor->dev;
2537 struct drm_crtc *crtc = &intel_crtc->base;
2538 struct intel_encoder *intel_encoder;
2539
Matt Roper5aa8a932014-06-16 10:12:55 -07002540 if (crtc->primary->fb)
2541 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2542 crtc->primary->fb->base.id, crtc->x, crtc->y,
2543 crtc->primary->fb->width, crtc->primary->fb->height);
2544 else
2545 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002546 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2547 intel_encoder_info(m, intel_crtc, intel_encoder);
2548}
2549
2550static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2551{
2552 struct drm_display_mode *mode = panel->fixed_mode;
2553
2554 seq_printf(m, "\tfixed mode:\n");
2555 intel_seq_print_mode(m, 2, mode);
2556}
2557
2558static void intel_dp_info(struct seq_file *m,
2559 struct intel_connector *intel_connector)
2560{
2561 struct intel_encoder *intel_encoder = intel_connector->encoder;
2562 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2563
2564 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2565 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2566 "no");
2567 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2568 intel_panel_info(m, &intel_connector->panel);
2569}
2570
2571static void intel_hdmi_info(struct seq_file *m,
2572 struct intel_connector *intel_connector)
2573{
2574 struct intel_encoder *intel_encoder = intel_connector->encoder;
2575 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2576
2577 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2578 "no");
2579}
2580
2581static void intel_lvds_info(struct seq_file *m,
2582 struct intel_connector *intel_connector)
2583{
2584 intel_panel_info(m, &intel_connector->panel);
2585}
2586
2587static void intel_connector_info(struct seq_file *m,
2588 struct drm_connector *connector)
2589{
2590 struct intel_connector *intel_connector = to_intel_connector(connector);
2591 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002592 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002593
2594 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002595 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002596 drm_get_connector_status_name(connector->status));
2597 if (connector->status == connector_status_connected) {
2598 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2599 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2600 connector->display_info.width_mm,
2601 connector->display_info.height_mm);
2602 seq_printf(m, "\tsubpixel order: %s\n",
2603 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2604 seq_printf(m, "\tCEA rev: %d\n",
2605 connector->display_info.cea_rev);
2606 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002607 if (intel_encoder) {
2608 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2609 intel_encoder->type == INTEL_OUTPUT_EDP)
2610 intel_dp_info(m, intel_connector);
2611 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2612 intel_hdmi_info(m, intel_connector);
2613 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2614 intel_lvds_info(m, intel_connector);
2615 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002616
Jesse Barnesf103fc72014-02-20 12:39:57 -08002617 seq_printf(m, "\tmodes:\n");
2618 list_for_each_entry(mode, &connector->modes, head)
2619 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002620}
2621
Chris Wilson065f2ec2014-03-12 09:13:13 +00002622static bool cursor_active(struct drm_device *dev, int pipe)
2623{
2624 struct drm_i915_private *dev_priv = dev->dev_private;
2625 u32 state;
2626
2627 if (IS_845G(dev) || IS_I865G(dev))
2628 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002629 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002630 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002631
2632 return state;
2633}
2634
2635static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2636{
2637 struct drm_i915_private *dev_priv = dev->dev_private;
2638 u32 pos;
2639
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002640 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002641
2642 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2643 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2644 *x = -*x;
2645
2646 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2647 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2648 *y = -*y;
2649
2650 return cursor_active(dev, pipe);
2651}
2652
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002653static int i915_display_info(struct seq_file *m, void *unused)
2654{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002655 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002656 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002657 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002658 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002659 struct drm_connector *connector;
2660
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002661 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002662 drm_modeset_lock_all(dev);
2663 seq_printf(m, "CRTC info\n");
2664 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002665 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002666 bool active;
2667 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002668
Chris Wilson57127ef2014-07-04 08:20:11 +01002669 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002670 crtc->base.base.id, pipe_name(crtc->pipe),
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002671 yesno(crtc->active), crtc->config->pipe_src_w,
2672 crtc->config->pipe_src_h);
Paulo Zanonia23dc652014-04-01 14:55:11 -03002673 if (crtc->active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002674 intel_crtc_info(m, crtc);
2675
Paulo Zanonia23dc652014-04-01 14:55:11 -03002676 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002677 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x, active? %s\n",
Chris Wilson4b0e3332014-05-30 16:35:26 +03002678 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08002679 x, y, crtc->base.cursor->state->crtc_w,
2680 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01002681 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002682 }
Daniel Vettercace8412014-05-22 17:56:31 +02002683
2684 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2685 yesno(!crtc->cpu_fifo_underrun_disabled),
2686 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002687 }
2688
2689 seq_printf(m, "\n");
2690 seq_printf(m, "Connector info\n");
2691 seq_printf(m, "--------------\n");
2692 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2693 intel_connector_info(m, connector);
2694 }
2695 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002696 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002697
2698 return 0;
2699}
2700
Ben Widawskye04934c2014-06-30 09:53:42 -07002701static int i915_semaphore_status(struct seq_file *m, void *unused)
2702{
2703 struct drm_info_node *node = (struct drm_info_node *) m->private;
2704 struct drm_device *dev = node->minor->dev;
2705 struct drm_i915_private *dev_priv = dev->dev_private;
2706 struct intel_engine_cs *ring;
2707 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2708 int i, j, ret;
2709
2710 if (!i915_semaphore_is_enabled(dev)) {
2711 seq_puts(m, "Semaphores are disabled\n");
2712 return 0;
2713 }
2714
2715 ret = mutex_lock_interruptible(&dev->struct_mutex);
2716 if (ret)
2717 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002718 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002719
2720 if (IS_BROADWELL(dev)) {
2721 struct page *page;
2722 uint64_t *seqno;
2723
2724 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2725
2726 seqno = (uint64_t *)kmap_atomic(page);
2727 for_each_ring(ring, dev_priv, i) {
2728 uint64_t offset;
2729
2730 seq_printf(m, "%s\n", ring->name);
2731
2732 seq_puts(m, " Last signal:");
2733 for (j = 0; j < num_rings; j++) {
2734 offset = i * I915_NUM_RINGS + j;
2735 seq_printf(m, "0x%08llx (0x%02llx) ",
2736 seqno[offset], offset * 8);
2737 }
2738 seq_putc(m, '\n');
2739
2740 seq_puts(m, " Last wait: ");
2741 for (j = 0; j < num_rings; j++) {
2742 offset = i + (j * I915_NUM_RINGS);
2743 seq_printf(m, "0x%08llx (0x%02llx) ",
2744 seqno[offset], offset * 8);
2745 }
2746 seq_putc(m, '\n');
2747
2748 }
2749 kunmap_atomic(seqno);
2750 } else {
2751 seq_puts(m, " Last signal:");
2752 for_each_ring(ring, dev_priv, i)
2753 for (j = 0; j < num_rings; j++)
2754 seq_printf(m, "0x%08x\n",
2755 I915_READ(ring->semaphore.mbox.signal[j]));
2756 seq_putc(m, '\n');
2757 }
2758
2759 seq_puts(m, "\nSync seqno:\n");
2760 for_each_ring(ring, dev_priv, i) {
2761 for (j = 0; j < num_rings; j++) {
2762 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2763 }
2764 seq_putc(m, '\n');
2765 }
2766 seq_putc(m, '\n');
2767
Paulo Zanoni03872062014-07-09 14:31:57 -03002768 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002769 mutex_unlock(&dev->struct_mutex);
2770 return 0;
2771}
2772
Daniel Vetter728e29d2014-06-25 22:01:53 +03002773static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2774{
2775 struct drm_info_node *node = (struct drm_info_node *) m->private;
2776 struct drm_device *dev = node->minor->dev;
2777 struct drm_i915_private *dev_priv = dev->dev_private;
2778 int i;
2779
2780 drm_modeset_lock_all(dev);
2781 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2782 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2783
2784 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002785 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002786 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03002787 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002788 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2789 seq_printf(m, " dpll_md: 0x%08x\n",
2790 pll->config.hw_state.dpll_md);
2791 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2792 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2793 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002794 }
2795 drm_modeset_unlock_all(dev);
2796
2797 return 0;
2798}
2799
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01002800static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01002801{
2802 int i;
2803 int ret;
2804 struct drm_info_node *node = (struct drm_info_node *) m->private;
2805 struct drm_device *dev = node->minor->dev;
2806 struct drm_i915_private *dev_priv = dev->dev_private;
2807
Arun Siluvery888b5992014-08-26 14:44:51 +01002808 ret = mutex_lock_interruptible(&dev->struct_mutex);
2809 if (ret)
2810 return ret;
2811
2812 intel_runtime_pm_get(dev_priv);
2813
Mika Kuoppala72253422014-10-07 17:21:26 +03002814 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
2815 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002816 u32 addr, mask, value, read;
2817 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01002818
Mika Kuoppala72253422014-10-07 17:21:26 +03002819 addr = dev_priv->workarounds.reg[i].addr;
2820 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002821 value = dev_priv->workarounds.reg[i].value;
2822 read = I915_READ(addr);
2823 ok = (value & mask) == (read & mask);
2824 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
2825 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01002826 }
2827
2828 intel_runtime_pm_put(dev_priv);
2829 mutex_unlock(&dev->struct_mutex);
2830
2831 return 0;
2832}
2833
Damien Lespiauc5511e42014-11-04 17:06:51 +00002834static int i915_ddb_info(struct seq_file *m, void *unused)
2835{
2836 struct drm_info_node *node = m->private;
2837 struct drm_device *dev = node->minor->dev;
2838 struct drm_i915_private *dev_priv = dev->dev_private;
2839 struct skl_ddb_allocation *ddb;
2840 struct skl_ddb_entry *entry;
2841 enum pipe pipe;
2842 int plane;
2843
Damien Lespiau2fcffe12014-12-03 17:33:24 +00002844 if (INTEL_INFO(dev)->gen < 9)
2845 return 0;
2846
Damien Lespiauc5511e42014-11-04 17:06:51 +00002847 drm_modeset_lock_all(dev);
2848
2849 ddb = &dev_priv->wm.skl_hw.ddb;
2850
2851 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
2852
2853 for_each_pipe(dev_priv, pipe) {
2854 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
2855
Damien Lespiaudd740782015-02-28 14:54:08 +00002856 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00002857 entry = &ddb->plane[pipe][plane];
2858 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
2859 entry->start, entry->end,
2860 skl_ddb_entry_size(entry));
2861 }
2862
2863 entry = &ddb->cursor[pipe];
2864 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
2865 entry->end, skl_ddb_entry_size(entry));
2866 }
2867
2868 drm_modeset_unlock_all(dev);
2869
2870 return 0;
2871}
2872
Vandana Kannana54746e2015-03-03 20:53:10 +05302873static void drrs_status_per_crtc(struct seq_file *m,
2874 struct drm_device *dev, struct intel_crtc *intel_crtc)
2875{
2876 struct intel_encoder *intel_encoder;
2877 struct drm_i915_private *dev_priv = dev->dev_private;
2878 struct i915_drrs *drrs = &dev_priv->drrs;
2879 int vrefresh = 0;
2880
2881 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
2882 /* Encoder connected on this CRTC */
2883 switch (intel_encoder->type) {
2884 case INTEL_OUTPUT_EDP:
2885 seq_puts(m, "eDP:\n");
2886 break;
2887 case INTEL_OUTPUT_DSI:
2888 seq_puts(m, "DSI:\n");
2889 break;
2890 case INTEL_OUTPUT_HDMI:
2891 seq_puts(m, "HDMI:\n");
2892 break;
2893 case INTEL_OUTPUT_DISPLAYPORT:
2894 seq_puts(m, "DP:\n");
2895 break;
2896 default:
2897 seq_printf(m, "Other encoder (id=%d).\n",
2898 intel_encoder->type);
2899 return;
2900 }
2901 }
2902
2903 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
2904 seq_puts(m, "\tVBT: DRRS_type: Static");
2905 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
2906 seq_puts(m, "\tVBT: DRRS_type: Seamless");
2907 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
2908 seq_puts(m, "\tVBT: DRRS_type: None");
2909 else
2910 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
2911
2912 seq_puts(m, "\n\n");
2913
2914 if (intel_crtc->config->has_drrs) {
2915 struct intel_panel *panel;
2916
2917 mutex_lock(&drrs->mutex);
2918 /* DRRS Supported */
2919 seq_puts(m, "\tDRRS Supported: Yes\n");
2920
2921 /* disable_drrs() will make drrs->dp NULL */
2922 if (!drrs->dp) {
2923 seq_puts(m, "Idleness DRRS: Disabled");
2924 mutex_unlock(&drrs->mutex);
2925 return;
2926 }
2927
2928 panel = &drrs->dp->attached_connector->panel;
2929 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
2930 drrs->busy_frontbuffer_bits);
2931
2932 seq_puts(m, "\n\t\t");
2933 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
2934 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
2935 vrefresh = panel->fixed_mode->vrefresh;
2936 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
2937 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
2938 vrefresh = panel->downclock_mode->vrefresh;
2939 } else {
2940 seq_printf(m, "DRRS_State: Unknown(%d)\n",
2941 drrs->refresh_rate_type);
2942 mutex_unlock(&drrs->mutex);
2943 return;
2944 }
2945 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
2946
2947 seq_puts(m, "\n\t\t");
2948 mutex_unlock(&drrs->mutex);
2949 } else {
2950 /* DRRS not supported. Print the VBT parameter*/
2951 seq_puts(m, "\tDRRS Supported : No");
2952 }
2953 seq_puts(m, "\n");
2954}
2955
2956static int i915_drrs_status(struct seq_file *m, void *unused)
2957{
2958 struct drm_info_node *node = m->private;
2959 struct drm_device *dev = node->minor->dev;
2960 struct intel_crtc *intel_crtc;
2961 int active_crtc_cnt = 0;
2962
2963 for_each_intel_crtc(dev, intel_crtc) {
2964 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
2965
2966 if (intel_crtc->active) {
2967 active_crtc_cnt++;
2968 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
2969
2970 drrs_status_per_crtc(m, dev, intel_crtc);
2971 }
2972
2973 drm_modeset_unlock(&intel_crtc->base.mutex);
2974 }
2975
2976 if (!active_crtc_cnt)
2977 seq_puts(m, "No active crtc found\n");
2978
2979 return 0;
2980}
2981
Damien Lespiau07144422013-10-15 18:55:40 +01002982struct pipe_crc_info {
2983 const char *name;
2984 struct drm_device *dev;
2985 enum pipe pipe;
2986};
2987
Dave Airlie11bed952014-05-12 15:22:27 +10002988static int i915_dp_mst_info(struct seq_file *m, void *unused)
2989{
2990 struct drm_info_node *node = (struct drm_info_node *) m->private;
2991 struct drm_device *dev = node->minor->dev;
2992 struct drm_encoder *encoder;
2993 struct intel_encoder *intel_encoder;
2994 struct intel_digital_port *intel_dig_port;
2995 drm_modeset_lock_all(dev);
2996 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2997 intel_encoder = to_intel_encoder(encoder);
2998 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
2999 continue;
3000 intel_dig_port = enc_to_dig_port(encoder);
3001 if (!intel_dig_port->dp.can_mst)
3002 continue;
3003
3004 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3005 }
3006 drm_modeset_unlock_all(dev);
3007 return 0;
3008}
3009
Damien Lespiau07144422013-10-15 18:55:40 +01003010static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003011{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003012 struct pipe_crc_info *info = inode->i_private;
3013 struct drm_i915_private *dev_priv = info->dev->dev_private;
3014 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3015
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003016 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3017 return -ENODEV;
3018
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003019 spin_lock_irq(&pipe_crc->lock);
3020
3021 if (pipe_crc->opened) {
3022 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003023 return -EBUSY; /* already open */
3024 }
3025
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003026 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003027 filep->private_data = inode->i_private;
3028
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003029 spin_unlock_irq(&pipe_crc->lock);
3030
Damien Lespiau07144422013-10-15 18:55:40 +01003031 return 0;
3032}
3033
3034static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3035{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003036 struct pipe_crc_info *info = inode->i_private;
3037 struct drm_i915_private *dev_priv = info->dev->dev_private;
3038 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3039
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003040 spin_lock_irq(&pipe_crc->lock);
3041 pipe_crc->opened = false;
3042 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003043
Damien Lespiau07144422013-10-15 18:55:40 +01003044 return 0;
3045}
3046
3047/* (6 fields, 8 chars each, space separated (5) + '\n') */
3048#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3049/* account for \'0' */
3050#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3051
3052static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3053{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003054 assert_spin_locked(&pipe_crc->lock);
3055 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3056 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003057}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003058
Damien Lespiau07144422013-10-15 18:55:40 +01003059static ssize_t
3060i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3061 loff_t *pos)
3062{
3063 struct pipe_crc_info *info = filep->private_data;
3064 struct drm_device *dev = info->dev;
3065 struct drm_i915_private *dev_priv = dev->dev_private;
3066 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3067 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003068 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003069 ssize_t bytes_read;
3070
3071 /*
3072 * Don't allow user space to provide buffers not big enough to hold
3073 * a line of data.
3074 */
3075 if (count < PIPE_CRC_LINE_LEN)
3076 return -EINVAL;
3077
3078 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3079 return 0;
3080
3081 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003082 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003083 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003084 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003085
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003086 if (filep->f_flags & O_NONBLOCK) {
3087 spin_unlock_irq(&pipe_crc->lock);
3088 return -EAGAIN;
3089 }
3090
3091 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3092 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3093 if (ret) {
3094 spin_unlock_irq(&pipe_crc->lock);
3095 return ret;
3096 }
Damien Lespiau07144422013-10-15 18:55:40 +01003097 }
3098
3099 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003100 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003101
Damien Lespiau07144422013-10-15 18:55:40 +01003102 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003103 while (n_entries > 0) {
3104 struct intel_pipe_crc_entry *entry =
3105 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003106 int ret;
3107
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003108 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3109 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3110 break;
3111
3112 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3113 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3114
Damien Lespiau07144422013-10-15 18:55:40 +01003115 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3116 "%8u %8x %8x %8x %8x %8x\n",
3117 entry->frame, entry->crc[0],
3118 entry->crc[1], entry->crc[2],
3119 entry->crc[3], entry->crc[4]);
3120
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003121 spin_unlock_irq(&pipe_crc->lock);
3122
3123 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003124 if (ret == PIPE_CRC_LINE_LEN)
3125 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003126
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003127 user_buf += PIPE_CRC_LINE_LEN;
3128 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003129
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003130 spin_lock_irq(&pipe_crc->lock);
3131 }
3132
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003133 spin_unlock_irq(&pipe_crc->lock);
3134
Damien Lespiau07144422013-10-15 18:55:40 +01003135 return bytes_read;
3136}
3137
3138static const struct file_operations i915_pipe_crc_fops = {
3139 .owner = THIS_MODULE,
3140 .open = i915_pipe_crc_open,
3141 .read = i915_pipe_crc_read,
3142 .release = i915_pipe_crc_release,
3143};
3144
3145static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3146 {
3147 .name = "i915_pipe_A_crc",
3148 .pipe = PIPE_A,
3149 },
3150 {
3151 .name = "i915_pipe_B_crc",
3152 .pipe = PIPE_B,
3153 },
3154 {
3155 .name = "i915_pipe_C_crc",
3156 .pipe = PIPE_C,
3157 },
3158};
3159
3160static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3161 enum pipe pipe)
3162{
3163 struct drm_device *dev = minor->dev;
3164 struct dentry *ent;
3165 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3166
3167 info->dev = dev;
3168 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3169 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003170 if (!ent)
3171 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003172
3173 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003174}
3175
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003176static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003177 "none",
3178 "plane1",
3179 "plane2",
3180 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003181 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003182 "TV",
3183 "DP-B",
3184 "DP-C",
3185 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003186 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003187};
3188
3189static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3190{
3191 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3192 return pipe_crc_sources[source];
3193}
3194
Damien Lespiaubd9db022013-10-15 18:55:36 +01003195static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003196{
3197 struct drm_device *dev = m->private;
3198 struct drm_i915_private *dev_priv = dev->dev_private;
3199 int i;
3200
3201 for (i = 0; i < I915_MAX_PIPES; i++)
3202 seq_printf(m, "%c %s\n", pipe_name(i),
3203 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3204
3205 return 0;
3206}
3207
Damien Lespiaubd9db022013-10-15 18:55:36 +01003208static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003209{
3210 struct drm_device *dev = inode->i_private;
3211
Damien Lespiaubd9db022013-10-15 18:55:36 +01003212 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003213}
3214
Daniel Vetter46a19182013-11-01 10:50:20 +01003215static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003216 uint32_t *val)
3217{
Daniel Vetter46a19182013-11-01 10:50:20 +01003218 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3219 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3220
3221 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003222 case INTEL_PIPE_CRC_SOURCE_PIPE:
3223 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3224 break;
3225 case INTEL_PIPE_CRC_SOURCE_NONE:
3226 *val = 0;
3227 break;
3228 default:
3229 return -EINVAL;
3230 }
3231
3232 return 0;
3233}
3234
Daniel Vetter46a19182013-11-01 10:50:20 +01003235static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3236 enum intel_pipe_crc_source *source)
3237{
3238 struct intel_encoder *encoder;
3239 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003240 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003241 int ret = 0;
3242
3243 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3244
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003245 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003246 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003247 if (!encoder->base.crtc)
3248 continue;
3249
3250 crtc = to_intel_crtc(encoder->base.crtc);
3251
3252 if (crtc->pipe != pipe)
3253 continue;
3254
3255 switch (encoder->type) {
3256 case INTEL_OUTPUT_TVOUT:
3257 *source = INTEL_PIPE_CRC_SOURCE_TV;
3258 break;
3259 case INTEL_OUTPUT_DISPLAYPORT:
3260 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003261 dig_port = enc_to_dig_port(&encoder->base);
3262 switch (dig_port->port) {
3263 case PORT_B:
3264 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3265 break;
3266 case PORT_C:
3267 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3268 break;
3269 case PORT_D:
3270 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3271 break;
3272 default:
3273 WARN(1, "nonexisting DP port %c\n",
3274 port_name(dig_port->port));
3275 break;
3276 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003277 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003278 default:
3279 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003280 }
3281 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003282 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003283
3284 return ret;
3285}
3286
3287static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3288 enum pipe pipe,
3289 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003290 uint32_t *val)
3291{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003292 struct drm_i915_private *dev_priv = dev->dev_private;
3293 bool need_stable_symbols = false;
3294
Daniel Vetter46a19182013-11-01 10:50:20 +01003295 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3296 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3297 if (ret)
3298 return ret;
3299 }
3300
3301 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003302 case INTEL_PIPE_CRC_SOURCE_PIPE:
3303 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3304 break;
3305 case INTEL_PIPE_CRC_SOURCE_DP_B:
3306 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003307 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003308 break;
3309 case INTEL_PIPE_CRC_SOURCE_DP_C:
3310 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003311 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003312 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003313 case INTEL_PIPE_CRC_SOURCE_DP_D:
3314 if (!IS_CHERRYVIEW(dev))
3315 return -EINVAL;
3316 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3317 need_stable_symbols = true;
3318 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003319 case INTEL_PIPE_CRC_SOURCE_NONE:
3320 *val = 0;
3321 break;
3322 default:
3323 return -EINVAL;
3324 }
3325
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003326 /*
3327 * When the pipe CRC tap point is after the transcoders we need
3328 * to tweak symbol-level features to produce a deterministic series of
3329 * symbols for a given frame. We need to reset those features only once
3330 * a frame (instead of every nth symbol):
3331 * - DC-balance: used to ensure a better clock recovery from the data
3332 * link (SDVO)
3333 * - DisplayPort scrambling: used for EMI reduction
3334 */
3335 if (need_stable_symbols) {
3336 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3337
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003338 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003339 switch (pipe) {
3340 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003341 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003342 break;
3343 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003344 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003345 break;
3346 case PIPE_C:
3347 tmp |= PIPE_C_SCRAMBLE_RESET;
3348 break;
3349 default:
3350 return -EINVAL;
3351 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003352 I915_WRITE(PORT_DFT2_G4X, tmp);
3353 }
3354
Daniel Vetter7ac01292013-10-18 16:37:06 +02003355 return 0;
3356}
3357
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003358static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003359 enum pipe pipe,
3360 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003361 uint32_t *val)
3362{
Daniel Vetter84093602013-11-01 10:50:21 +01003363 struct drm_i915_private *dev_priv = dev->dev_private;
3364 bool need_stable_symbols = false;
3365
Daniel Vetter46a19182013-11-01 10:50:20 +01003366 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3367 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3368 if (ret)
3369 return ret;
3370 }
3371
3372 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003373 case INTEL_PIPE_CRC_SOURCE_PIPE:
3374 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3375 break;
3376 case INTEL_PIPE_CRC_SOURCE_TV:
3377 if (!SUPPORTS_TV(dev))
3378 return -EINVAL;
3379 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3380 break;
3381 case INTEL_PIPE_CRC_SOURCE_DP_B:
3382 if (!IS_G4X(dev))
3383 return -EINVAL;
3384 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003385 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003386 break;
3387 case INTEL_PIPE_CRC_SOURCE_DP_C:
3388 if (!IS_G4X(dev))
3389 return -EINVAL;
3390 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003391 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003392 break;
3393 case INTEL_PIPE_CRC_SOURCE_DP_D:
3394 if (!IS_G4X(dev))
3395 return -EINVAL;
3396 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003397 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003398 break;
3399 case INTEL_PIPE_CRC_SOURCE_NONE:
3400 *val = 0;
3401 break;
3402 default:
3403 return -EINVAL;
3404 }
3405
Daniel Vetter84093602013-11-01 10:50:21 +01003406 /*
3407 * When the pipe CRC tap point is after the transcoders we need
3408 * to tweak symbol-level features to produce a deterministic series of
3409 * symbols for a given frame. We need to reset those features only once
3410 * a frame (instead of every nth symbol):
3411 * - DC-balance: used to ensure a better clock recovery from the data
3412 * link (SDVO)
3413 * - DisplayPort scrambling: used for EMI reduction
3414 */
3415 if (need_stable_symbols) {
3416 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3417
3418 WARN_ON(!IS_G4X(dev));
3419
3420 I915_WRITE(PORT_DFT_I9XX,
3421 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3422
3423 if (pipe == PIPE_A)
3424 tmp |= PIPE_A_SCRAMBLE_RESET;
3425 else
3426 tmp |= PIPE_B_SCRAMBLE_RESET;
3427
3428 I915_WRITE(PORT_DFT2_G4X, tmp);
3429 }
3430
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003431 return 0;
3432}
3433
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003434static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3435 enum pipe pipe)
3436{
3437 struct drm_i915_private *dev_priv = dev->dev_private;
3438 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3439
Ville Syrjäläeb736672014-12-09 21:28:28 +02003440 switch (pipe) {
3441 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003442 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003443 break;
3444 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003445 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003446 break;
3447 case PIPE_C:
3448 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3449 break;
3450 default:
3451 return;
3452 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003453 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3454 tmp &= ~DC_BALANCE_RESET_VLV;
3455 I915_WRITE(PORT_DFT2_G4X, tmp);
3456
3457}
3458
Daniel Vetter84093602013-11-01 10:50:21 +01003459static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3460 enum pipe pipe)
3461{
3462 struct drm_i915_private *dev_priv = dev->dev_private;
3463 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3464
3465 if (pipe == PIPE_A)
3466 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3467 else
3468 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3469 I915_WRITE(PORT_DFT2_G4X, tmp);
3470
3471 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3472 I915_WRITE(PORT_DFT_I9XX,
3473 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3474 }
3475}
3476
Daniel Vetter46a19182013-11-01 10:50:20 +01003477static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003478 uint32_t *val)
3479{
Daniel Vetter46a19182013-11-01 10:50:20 +01003480 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3481 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3482
3483 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003484 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3485 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3486 break;
3487 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3488 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3489 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003490 case INTEL_PIPE_CRC_SOURCE_PIPE:
3491 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3492 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003493 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003494 *val = 0;
3495 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003496 default:
3497 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003498 }
3499
3500 return 0;
3501}
3502
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003503static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3504{
3505 struct drm_i915_private *dev_priv = dev->dev_private;
3506 struct intel_crtc *crtc =
3507 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3508
3509 drm_modeset_lock_all(dev);
3510 /*
3511 * If we use the eDP transcoder we need to make sure that we don't
3512 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3513 * relevant on hsw with pipe A when using the always-on power well
3514 * routing.
3515 */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02003516 if (crtc->config->cpu_transcoder == TRANSCODER_EDP &&
3517 !crtc->config->pch_pfit.enabled) {
3518 crtc->config->pch_pfit.force_thru = true;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003519
3520 intel_display_power_get(dev_priv,
3521 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3522
3523 dev_priv->display.crtc_disable(&crtc->base);
3524 dev_priv->display.crtc_enable(&crtc->base);
3525 }
3526 drm_modeset_unlock_all(dev);
3527}
3528
3529static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3530{
3531 struct drm_i915_private *dev_priv = dev->dev_private;
3532 struct intel_crtc *crtc =
3533 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3534
3535 drm_modeset_lock_all(dev);
3536 /*
3537 * If we use the eDP transcoder we need to make sure that we don't
3538 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3539 * relevant on hsw with pipe A when using the always-on power well
3540 * routing.
3541 */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02003542 if (crtc->config->pch_pfit.force_thru) {
3543 crtc->config->pch_pfit.force_thru = false;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003544
3545 dev_priv->display.crtc_disable(&crtc->base);
3546 dev_priv->display.crtc_enable(&crtc->base);
3547
3548 intel_display_power_put(dev_priv,
3549 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3550 }
3551 drm_modeset_unlock_all(dev);
3552}
3553
3554static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3555 enum pipe pipe,
3556 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003557 uint32_t *val)
3558{
Daniel Vetter46a19182013-11-01 10:50:20 +01003559 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3560 *source = INTEL_PIPE_CRC_SOURCE_PF;
3561
3562 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003563 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3564 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3565 break;
3566 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3567 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3568 break;
3569 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003570 if (IS_HASWELL(dev) && pipe == PIPE_A)
3571 hsw_trans_edp_pipe_A_crc_wa(dev);
3572
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003573 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3574 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003575 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003576 *val = 0;
3577 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003578 default:
3579 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003580 }
3581
3582 return 0;
3583}
3584
Daniel Vetter926321d2013-10-16 13:30:34 +02003585static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3586 enum intel_pipe_crc_source source)
3587{
3588 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003589 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003590 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3591 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003592 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003593 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003594
Damien Lespiaucc3da172013-10-15 18:55:31 +01003595 if (pipe_crc->source == source)
3596 return 0;
3597
Damien Lespiauae676fc2013-10-15 18:55:32 +01003598 /* forbid changing the source without going back to 'none' */
3599 if (pipe_crc->source && source)
3600 return -EINVAL;
3601
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003602 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3603 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3604 return -EIO;
3605 }
3606
Daniel Vetter52f843f2013-10-21 17:26:38 +02003607 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003608 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003609 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003610 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003611 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003612 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003613 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003614 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003615 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003616 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003617
3618 if (ret != 0)
3619 return ret;
3620
Damien Lespiau4b584362013-10-15 18:55:33 +01003621 /* none -> real source transition */
3622 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003623 struct intel_pipe_crc_entry *entries;
3624
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003625 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3626 pipe_name(pipe), pipe_crc_source_name(source));
3627
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003628 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3629 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003630 GFP_KERNEL);
3631 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003632 return -ENOMEM;
3633
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003634 /*
3635 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3636 * enabled and disabled dynamically based on package C states,
3637 * user space can't make reliable use of the CRCs, so let's just
3638 * completely disable it.
3639 */
3640 hsw_disable_ips(crtc);
3641
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003642 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003643 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003644 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003645 pipe_crc->head = 0;
3646 pipe_crc->tail = 0;
3647 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003648 }
3649
Damien Lespiaucc3da172013-10-15 18:55:31 +01003650 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003651
Daniel Vetter926321d2013-10-16 13:30:34 +02003652 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3653 POSTING_READ(PIPE_CRC_CTL(pipe));
3654
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003655 /* real source -> none transition */
3656 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003657 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003658 struct intel_crtc *crtc =
3659 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003660
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003661 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3662 pipe_name(pipe));
3663
Daniel Vettera33d7102014-06-06 08:22:08 +02003664 drm_modeset_lock(&crtc->base.mutex, NULL);
3665 if (crtc->active)
3666 intel_wait_for_vblank(dev, pipe);
3667 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003668
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003669 spin_lock_irq(&pipe_crc->lock);
3670 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003671 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003672 pipe_crc->head = 0;
3673 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003674 spin_unlock_irq(&pipe_crc->lock);
3675
3676 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003677
3678 if (IS_G4X(dev))
3679 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003680 else if (IS_VALLEYVIEW(dev))
3681 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003682 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3683 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003684
3685 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003686 }
3687
Daniel Vetter926321d2013-10-16 13:30:34 +02003688 return 0;
3689}
3690
3691/*
3692 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003693 * command: wsp* object wsp+ name wsp+ source wsp*
3694 * object: 'pipe'
3695 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003696 * source: (none | plane1 | plane2 | pf)
3697 * wsp: (#0x20 | #0x9 | #0xA)+
3698 *
3699 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003700 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3701 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003702 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003703static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003704{
3705 int n_words = 0;
3706
3707 while (*buf) {
3708 char *end;
3709
3710 /* skip leading white space */
3711 buf = skip_spaces(buf);
3712 if (!*buf)
3713 break; /* end of buffer */
3714
3715 /* find end of word */
3716 for (end = buf; *end && !isspace(*end); end++)
3717 ;
3718
3719 if (n_words == max_words) {
3720 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3721 max_words);
3722 return -EINVAL; /* ran out of words[] before bytes */
3723 }
3724
3725 if (*end)
3726 *end++ = '\0';
3727 words[n_words++] = buf;
3728 buf = end;
3729 }
3730
3731 return n_words;
3732}
3733
Damien Lespiaub94dec82013-10-15 18:55:35 +01003734enum intel_pipe_crc_object {
3735 PIPE_CRC_OBJECT_PIPE,
3736};
3737
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003738static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003739 "pipe",
3740};
3741
3742static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003743display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003744{
3745 int i;
3746
3747 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3748 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003749 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003750 return 0;
3751 }
3752
3753 return -EINVAL;
3754}
3755
Damien Lespiaubd9db022013-10-15 18:55:36 +01003756static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003757{
3758 const char name = buf[0];
3759
3760 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3761 return -EINVAL;
3762
3763 *pipe = name - 'A';
3764
3765 return 0;
3766}
3767
3768static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003769display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003770{
3771 int i;
3772
3773 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3774 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003775 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003776 return 0;
3777 }
3778
3779 return -EINVAL;
3780}
3781
Damien Lespiaubd9db022013-10-15 18:55:36 +01003782static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003783{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003784#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003785 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003786 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003787 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003788 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003789 enum intel_pipe_crc_source source;
3790
Damien Lespiaubd9db022013-10-15 18:55:36 +01003791 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003792 if (n_words != N_WORDS) {
3793 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3794 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003795 return -EINVAL;
3796 }
3797
Damien Lespiaubd9db022013-10-15 18:55:36 +01003798 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003799 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003800 return -EINVAL;
3801 }
3802
Damien Lespiaubd9db022013-10-15 18:55:36 +01003803 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003804 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3805 return -EINVAL;
3806 }
3807
Damien Lespiaubd9db022013-10-15 18:55:36 +01003808 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003809 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003810 return -EINVAL;
3811 }
3812
3813 return pipe_crc_set_source(dev, pipe, source);
3814}
3815
Damien Lespiaubd9db022013-10-15 18:55:36 +01003816static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3817 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003818{
3819 struct seq_file *m = file->private_data;
3820 struct drm_device *dev = m->private;
3821 char *tmpbuf;
3822 int ret;
3823
3824 if (len == 0)
3825 return 0;
3826
3827 if (len > PAGE_SIZE - 1) {
3828 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3829 PAGE_SIZE);
3830 return -E2BIG;
3831 }
3832
3833 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3834 if (!tmpbuf)
3835 return -ENOMEM;
3836
3837 if (copy_from_user(tmpbuf, ubuf, len)) {
3838 ret = -EFAULT;
3839 goto out;
3840 }
3841 tmpbuf[len] = '\0';
3842
Damien Lespiaubd9db022013-10-15 18:55:36 +01003843 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003844
3845out:
3846 kfree(tmpbuf);
3847 if (ret < 0)
3848 return ret;
3849
3850 *offp += len;
3851 return len;
3852}
3853
Damien Lespiaubd9db022013-10-15 18:55:36 +01003854static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003855 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003856 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003857 .read = seq_read,
3858 .llseek = seq_lseek,
3859 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003860 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003861};
3862
Damien Lespiau97e94b22014-11-04 17:06:50 +00003863static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003864{
3865 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003866 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003867 int level;
3868
3869 drm_modeset_lock_all(dev);
3870
3871 for (level = 0; level < num_levels; level++) {
3872 unsigned int latency = wm[level];
3873
Damien Lespiau97e94b22014-11-04 17:06:50 +00003874 /*
3875 * - WM1+ latency values in 0.5us units
3876 * - latencies are in us on gen9
3877 */
3878 if (INTEL_INFO(dev)->gen >= 9)
3879 latency *= 10;
3880 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003881 latency *= 5;
3882
3883 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003884 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003885 }
3886
3887 drm_modeset_unlock_all(dev);
3888}
3889
3890static int pri_wm_latency_show(struct seq_file *m, void *data)
3891{
3892 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003893 struct drm_i915_private *dev_priv = dev->dev_private;
3894 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003895
Damien Lespiau97e94b22014-11-04 17:06:50 +00003896 if (INTEL_INFO(dev)->gen >= 9)
3897 latencies = dev_priv->wm.skl_latency;
3898 else
3899 latencies = to_i915(dev)->wm.pri_latency;
3900
3901 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003902
3903 return 0;
3904}
3905
3906static int spr_wm_latency_show(struct seq_file *m, void *data)
3907{
3908 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003909 struct drm_i915_private *dev_priv = dev->dev_private;
3910 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003911
Damien Lespiau97e94b22014-11-04 17:06:50 +00003912 if (INTEL_INFO(dev)->gen >= 9)
3913 latencies = dev_priv->wm.skl_latency;
3914 else
3915 latencies = to_i915(dev)->wm.spr_latency;
3916
3917 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003918
3919 return 0;
3920}
3921
3922static int cur_wm_latency_show(struct seq_file *m, void *data)
3923{
3924 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003925 struct drm_i915_private *dev_priv = dev->dev_private;
3926 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003927
Damien Lespiau97e94b22014-11-04 17:06:50 +00003928 if (INTEL_INFO(dev)->gen >= 9)
3929 latencies = dev_priv->wm.skl_latency;
3930 else
3931 latencies = to_i915(dev)->wm.cur_latency;
3932
3933 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003934
3935 return 0;
3936}
3937
3938static int pri_wm_latency_open(struct inode *inode, struct file *file)
3939{
3940 struct drm_device *dev = inode->i_private;
3941
Sonika Jindal9ad02572014-07-21 15:23:39 +05303942 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003943 return -ENODEV;
3944
3945 return single_open(file, pri_wm_latency_show, dev);
3946}
3947
3948static int spr_wm_latency_open(struct inode *inode, struct file *file)
3949{
3950 struct drm_device *dev = inode->i_private;
3951
Sonika Jindal9ad02572014-07-21 15:23:39 +05303952 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003953 return -ENODEV;
3954
3955 return single_open(file, spr_wm_latency_show, dev);
3956}
3957
3958static int cur_wm_latency_open(struct inode *inode, struct file *file)
3959{
3960 struct drm_device *dev = inode->i_private;
3961
Sonika Jindal9ad02572014-07-21 15:23:39 +05303962 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003963 return -ENODEV;
3964
3965 return single_open(file, cur_wm_latency_show, dev);
3966}
3967
3968static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003969 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003970{
3971 struct seq_file *m = file->private_data;
3972 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003973 uint16_t new[8] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003974 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003975 int level;
3976 int ret;
3977 char tmp[32];
3978
3979 if (len >= sizeof(tmp))
3980 return -EINVAL;
3981
3982 if (copy_from_user(tmp, ubuf, len))
3983 return -EFAULT;
3984
3985 tmp[len] = '\0';
3986
Damien Lespiau97e94b22014-11-04 17:06:50 +00003987 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
3988 &new[0], &new[1], &new[2], &new[3],
3989 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003990 if (ret != num_levels)
3991 return -EINVAL;
3992
3993 drm_modeset_lock_all(dev);
3994
3995 for (level = 0; level < num_levels; level++)
3996 wm[level] = new[level];
3997
3998 drm_modeset_unlock_all(dev);
3999
4000 return len;
4001}
4002
4003
4004static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4005 size_t len, loff_t *offp)
4006{
4007 struct seq_file *m = file->private_data;
4008 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004009 struct drm_i915_private *dev_priv = dev->dev_private;
4010 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004011
Damien Lespiau97e94b22014-11-04 17:06:50 +00004012 if (INTEL_INFO(dev)->gen >= 9)
4013 latencies = dev_priv->wm.skl_latency;
4014 else
4015 latencies = to_i915(dev)->wm.pri_latency;
4016
4017 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004018}
4019
4020static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4021 size_t len, loff_t *offp)
4022{
4023 struct seq_file *m = file->private_data;
4024 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004025 struct drm_i915_private *dev_priv = dev->dev_private;
4026 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004027
Damien Lespiau97e94b22014-11-04 17:06:50 +00004028 if (INTEL_INFO(dev)->gen >= 9)
4029 latencies = dev_priv->wm.skl_latency;
4030 else
4031 latencies = to_i915(dev)->wm.spr_latency;
4032
4033 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004034}
4035
4036static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4037 size_t len, loff_t *offp)
4038{
4039 struct seq_file *m = file->private_data;
4040 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004041 struct drm_i915_private *dev_priv = dev->dev_private;
4042 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004043
Damien Lespiau97e94b22014-11-04 17:06:50 +00004044 if (INTEL_INFO(dev)->gen >= 9)
4045 latencies = dev_priv->wm.skl_latency;
4046 else
4047 latencies = to_i915(dev)->wm.cur_latency;
4048
4049 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004050}
4051
4052static const struct file_operations i915_pri_wm_latency_fops = {
4053 .owner = THIS_MODULE,
4054 .open = pri_wm_latency_open,
4055 .read = seq_read,
4056 .llseek = seq_lseek,
4057 .release = single_release,
4058 .write = pri_wm_latency_write
4059};
4060
4061static const struct file_operations i915_spr_wm_latency_fops = {
4062 .owner = THIS_MODULE,
4063 .open = spr_wm_latency_open,
4064 .read = seq_read,
4065 .llseek = seq_lseek,
4066 .release = single_release,
4067 .write = spr_wm_latency_write
4068};
4069
4070static const struct file_operations i915_cur_wm_latency_fops = {
4071 .owner = THIS_MODULE,
4072 .open = cur_wm_latency_open,
4073 .read = seq_read,
4074 .llseek = seq_lseek,
4075 .release = single_release,
4076 .write = cur_wm_latency_write
4077};
4078
Kees Cook647416f2013-03-10 14:10:06 -07004079static int
4080i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004081{
Kees Cook647416f2013-03-10 14:10:06 -07004082 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004083 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004084
Kees Cook647416f2013-03-10 14:10:06 -07004085 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004086
Kees Cook647416f2013-03-10 14:10:06 -07004087 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004088}
4089
Kees Cook647416f2013-03-10 14:10:06 -07004090static int
4091i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004092{
Kees Cook647416f2013-03-10 14:10:06 -07004093 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004094 struct drm_i915_private *dev_priv = dev->dev_private;
4095
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004096 /*
4097 * There is no safeguard against this debugfs entry colliding
4098 * with the hangcheck calling same i915_handle_error() in
4099 * parallel, causing an explosion. For now we assume that the
4100 * test harness is responsible enough not to inject gpu hangs
4101 * while it is writing to 'i915_wedged'
4102 */
4103
4104 if (i915_reset_in_progress(&dev_priv->gpu_error))
4105 return -EAGAIN;
4106
Imre Deakd46c0512014-04-14 20:24:27 +03004107 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004108
Mika Kuoppala58174462014-02-25 17:11:26 +02004109 i915_handle_error(dev, val,
4110 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004111
4112 intel_runtime_pm_put(dev_priv);
4113
Kees Cook647416f2013-03-10 14:10:06 -07004114 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004115}
4116
Kees Cook647416f2013-03-10 14:10:06 -07004117DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4118 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004119 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004120
Kees Cook647416f2013-03-10 14:10:06 -07004121static int
4122i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004123{
Kees Cook647416f2013-03-10 14:10:06 -07004124 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004125 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004126
Kees Cook647416f2013-03-10 14:10:06 -07004127 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004128
Kees Cook647416f2013-03-10 14:10:06 -07004129 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004130}
4131
Kees Cook647416f2013-03-10 14:10:06 -07004132static int
4133i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004134{
Kees Cook647416f2013-03-10 14:10:06 -07004135 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004136 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004137 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004138
Kees Cook647416f2013-03-10 14:10:06 -07004139 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004140
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004141 ret = mutex_lock_interruptible(&dev->struct_mutex);
4142 if (ret)
4143 return ret;
4144
Daniel Vetter99584db2012-11-14 17:14:04 +01004145 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004146 mutex_unlock(&dev->struct_mutex);
4147
Kees Cook647416f2013-03-10 14:10:06 -07004148 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004149}
4150
Kees Cook647416f2013-03-10 14:10:06 -07004151DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4152 i915_ring_stop_get, i915_ring_stop_set,
4153 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004154
Chris Wilson094f9a52013-09-25 17:34:55 +01004155static int
4156i915_ring_missed_irq_get(void *data, u64 *val)
4157{
4158 struct drm_device *dev = data;
4159 struct drm_i915_private *dev_priv = dev->dev_private;
4160
4161 *val = dev_priv->gpu_error.missed_irq_rings;
4162 return 0;
4163}
4164
4165static int
4166i915_ring_missed_irq_set(void *data, u64 val)
4167{
4168 struct drm_device *dev = data;
4169 struct drm_i915_private *dev_priv = dev->dev_private;
4170 int ret;
4171
4172 /* Lock against concurrent debugfs callers */
4173 ret = mutex_lock_interruptible(&dev->struct_mutex);
4174 if (ret)
4175 return ret;
4176 dev_priv->gpu_error.missed_irq_rings = val;
4177 mutex_unlock(&dev->struct_mutex);
4178
4179 return 0;
4180}
4181
4182DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4183 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4184 "0x%08llx\n");
4185
4186static int
4187i915_ring_test_irq_get(void *data, u64 *val)
4188{
4189 struct drm_device *dev = data;
4190 struct drm_i915_private *dev_priv = dev->dev_private;
4191
4192 *val = dev_priv->gpu_error.test_irq_rings;
4193
4194 return 0;
4195}
4196
4197static int
4198i915_ring_test_irq_set(void *data, u64 val)
4199{
4200 struct drm_device *dev = data;
4201 struct drm_i915_private *dev_priv = dev->dev_private;
4202 int ret;
4203
4204 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4205
4206 /* Lock against concurrent debugfs callers */
4207 ret = mutex_lock_interruptible(&dev->struct_mutex);
4208 if (ret)
4209 return ret;
4210
4211 dev_priv->gpu_error.test_irq_rings = val;
4212 mutex_unlock(&dev->struct_mutex);
4213
4214 return 0;
4215}
4216
4217DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4218 i915_ring_test_irq_get, i915_ring_test_irq_set,
4219 "0x%08llx\n");
4220
Chris Wilsondd624af2013-01-15 12:39:35 +00004221#define DROP_UNBOUND 0x1
4222#define DROP_BOUND 0x2
4223#define DROP_RETIRE 0x4
4224#define DROP_ACTIVE 0x8
4225#define DROP_ALL (DROP_UNBOUND | \
4226 DROP_BOUND | \
4227 DROP_RETIRE | \
4228 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004229static int
4230i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004231{
Kees Cook647416f2013-03-10 14:10:06 -07004232 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004233
Kees Cook647416f2013-03-10 14:10:06 -07004234 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004235}
4236
Kees Cook647416f2013-03-10 14:10:06 -07004237static int
4238i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004239{
Kees Cook647416f2013-03-10 14:10:06 -07004240 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004241 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004242 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004243
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004244 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004245
4246 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4247 * on ioctls on -EAGAIN. */
4248 ret = mutex_lock_interruptible(&dev->struct_mutex);
4249 if (ret)
4250 return ret;
4251
4252 if (val & DROP_ACTIVE) {
4253 ret = i915_gpu_idle(dev);
4254 if (ret)
4255 goto unlock;
4256 }
4257
4258 if (val & (DROP_RETIRE | DROP_ACTIVE))
4259 i915_gem_retire_requests(dev);
4260
Chris Wilson21ab4e72014-09-09 11:16:08 +01004261 if (val & DROP_BOUND)
4262 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004263
Chris Wilson21ab4e72014-09-09 11:16:08 +01004264 if (val & DROP_UNBOUND)
4265 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004266
4267unlock:
4268 mutex_unlock(&dev->struct_mutex);
4269
Kees Cook647416f2013-03-10 14:10:06 -07004270 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004271}
4272
Kees Cook647416f2013-03-10 14:10:06 -07004273DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4274 i915_drop_caches_get, i915_drop_caches_set,
4275 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004276
Kees Cook647416f2013-03-10 14:10:06 -07004277static int
4278i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004279{
Kees Cook647416f2013-03-10 14:10:06 -07004280 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004281 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004282 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004283
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004284 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004285 return -ENODEV;
4286
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004287 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4288
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004289 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004290 if (ret)
4291 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004292
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004293 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004294 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004295
Kees Cook647416f2013-03-10 14:10:06 -07004296 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004297}
4298
Kees Cook647416f2013-03-10 14:10:06 -07004299static int
4300i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004301{
Kees Cook647416f2013-03-10 14:10:06 -07004302 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004303 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304304 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004305 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004306
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004307 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004308 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004309
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004310 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4311
Kees Cook647416f2013-03-10 14:10:06 -07004312 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004313
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004314 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004315 if (ret)
4316 return ret;
4317
Jesse Barnes358733e2011-07-27 11:53:01 -07004318 /*
4319 * Turbo will still be enabled, but won't go above the set value.
4320 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304321 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004322
Akash Goelbc4d91f2015-02-26 16:09:47 +05304323 hw_max = dev_priv->rps.max_freq;
4324 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004325
Ben Widawskyb39fb292014-03-19 18:31:11 -07004326 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004327 mutex_unlock(&dev_priv->rps.hw_lock);
4328 return -EINVAL;
4329 }
4330
Ben Widawskyb39fb292014-03-19 18:31:11 -07004331 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004332
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004333 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004334
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004335 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004336
Kees Cook647416f2013-03-10 14:10:06 -07004337 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004338}
4339
Kees Cook647416f2013-03-10 14:10:06 -07004340DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4341 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004342 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004343
Kees Cook647416f2013-03-10 14:10:06 -07004344static int
4345i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004346{
Kees Cook647416f2013-03-10 14:10:06 -07004347 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004348 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004349 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004350
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004351 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004352 return -ENODEV;
4353
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004354 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4355
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004356 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004357 if (ret)
4358 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004359
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004360 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004361 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004362
Kees Cook647416f2013-03-10 14:10:06 -07004363 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004364}
4365
Kees Cook647416f2013-03-10 14:10:06 -07004366static int
4367i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004368{
Kees Cook647416f2013-03-10 14:10:06 -07004369 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004370 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304371 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004372 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004373
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004374 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004375 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004376
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004377 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4378
Kees Cook647416f2013-03-10 14:10:06 -07004379 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004380
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004381 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004382 if (ret)
4383 return ret;
4384
Jesse Barnes1523c312012-05-25 12:34:54 -07004385 /*
4386 * Turbo will still be enabled, but won't go below the set value.
4387 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304388 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004389
Akash Goelbc4d91f2015-02-26 16:09:47 +05304390 hw_max = dev_priv->rps.max_freq;
4391 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004392
Ben Widawskyb39fb292014-03-19 18:31:11 -07004393 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004394 mutex_unlock(&dev_priv->rps.hw_lock);
4395 return -EINVAL;
4396 }
4397
Ben Widawskyb39fb292014-03-19 18:31:11 -07004398 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004399
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004400 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004401
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004402 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004403
Kees Cook647416f2013-03-10 14:10:06 -07004404 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004405}
4406
Kees Cook647416f2013-03-10 14:10:06 -07004407DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4408 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004409 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004410
Kees Cook647416f2013-03-10 14:10:06 -07004411static int
4412i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004413{
Kees Cook647416f2013-03-10 14:10:06 -07004414 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004415 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004416 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004417 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004418
Daniel Vetter004777c2012-08-09 15:07:01 +02004419 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4420 return -ENODEV;
4421
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004422 ret = mutex_lock_interruptible(&dev->struct_mutex);
4423 if (ret)
4424 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004425 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004426
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004427 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004428
4429 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004430 mutex_unlock(&dev_priv->dev->struct_mutex);
4431
Kees Cook647416f2013-03-10 14:10:06 -07004432 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004433
Kees Cook647416f2013-03-10 14:10:06 -07004434 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004435}
4436
Kees Cook647416f2013-03-10 14:10:06 -07004437static int
4438i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004439{
Kees Cook647416f2013-03-10 14:10:06 -07004440 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004441 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004442 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004443
Daniel Vetter004777c2012-08-09 15:07:01 +02004444 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4445 return -ENODEV;
4446
Kees Cook647416f2013-03-10 14:10:06 -07004447 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004448 return -EINVAL;
4449
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004450 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004451 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004452
4453 /* Update the cache sharing policy here as well */
4454 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4455 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4456 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4457 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4458
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004459 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004460 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004461}
4462
Kees Cook647416f2013-03-10 14:10:06 -07004463DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4464 i915_cache_sharing_get, i915_cache_sharing_set,
4465 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004466
Jeff McGee38732182015-02-13 10:27:54 -06004467static int i915_sseu_status(struct seq_file *m, void *unused)
4468{
4469 struct drm_info_node *node = (struct drm_info_node *) m->private;
4470 struct drm_device *dev = node->minor->dev;
Jeff McGee7f992ab2015-02-13 10:27:55 -06004471 struct drm_i915_private *dev_priv = dev->dev_private;
4472 unsigned int s_tot = 0, ss_tot = 0, ss_per = 0, eu_tot = 0, eu_per = 0;
Jeff McGee38732182015-02-13 10:27:54 -06004473
4474 if (INTEL_INFO(dev)->gen < 9)
4475 return -ENODEV;
4476
4477 seq_puts(m, "SSEU Device Info\n");
4478 seq_printf(m, " Available Slice Total: %u\n",
4479 INTEL_INFO(dev)->slice_total);
4480 seq_printf(m, " Available Subslice Total: %u\n",
4481 INTEL_INFO(dev)->subslice_total);
4482 seq_printf(m, " Available Subslice Per Slice: %u\n",
4483 INTEL_INFO(dev)->subslice_per_slice);
4484 seq_printf(m, " Available EU Total: %u\n",
4485 INTEL_INFO(dev)->eu_total);
4486 seq_printf(m, " Available EU Per Subslice: %u\n",
4487 INTEL_INFO(dev)->eu_per_subslice);
4488 seq_printf(m, " Has Slice Power Gating: %s\n",
4489 yesno(INTEL_INFO(dev)->has_slice_pg));
4490 seq_printf(m, " Has Subslice Power Gating: %s\n",
4491 yesno(INTEL_INFO(dev)->has_subslice_pg));
4492 seq_printf(m, " Has EU Power Gating: %s\n",
4493 yesno(INTEL_INFO(dev)->has_eu_pg));
4494
Jeff McGee7f992ab2015-02-13 10:27:55 -06004495 seq_puts(m, "SSEU Device Status\n");
4496 if (IS_SKYLAKE(dev)) {
4497 const int s_max = 3, ss_max = 4;
4498 int s, ss;
4499 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4500
4501 s_reg[0] = I915_READ(GEN9_SLICE0_PGCTL_ACK);
4502 s_reg[1] = I915_READ(GEN9_SLICE1_PGCTL_ACK);
4503 s_reg[2] = I915_READ(GEN9_SLICE2_PGCTL_ACK);
4504 eu_reg[0] = I915_READ(GEN9_SLICE0_SS01_EU_PGCTL_ACK);
4505 eu_reg[1] = I915_READ(GEN9_SLICE0_SS23_EU_PGCTL_ACK);
4506 eu_reg[2] = I915_READ(GEN9_SLICE1_SS01_EU_PGCTL_ACK);
4507 eu_reg[3] = I915_READ(GEN9_SLICE1_SS23_EU_PGCTL_ACK);
4508 eu_reg[4] = I915_READ(GEN9_SLICE2_SS01_EU_PGCTL_ACK);
4509 eu_reg[5] = I915_READ(GEN9_SLICE2_SS23_EU_PGCTL_ACK);
4510 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4511 GEN9_PGCTL_SSA_EU19_ACK |
4512 GEN9_PGCTL_SSA_EU210_ACK |
4513 GEN9_PGCTL_SSA_EU311_ACK;
4514 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4515 GEN9_PGCTL_SSB_EU19_ACK |
4516 GEN9_PGCTL_SSB_EU210_ACK |
4517 GEN9_PGCTL_SSB_EU311_ACK;
4518
4519 for (s = 0; s < s_max; s++) {
4520 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4521 /* skip disabled slice */
4522 continue;
4523
4524 s_tot++;
4525 ss_per = INTEL_INFO(dev)->subslice_per_slice;
4526 ss_tot += ss_per;
4527 for (ss = 0; ss < ss_max; ss++) {
4528 unsigned int eu_cnt;
4529
4530 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4531 eu_mask[ss%2]);
4532 eu_tot += eu_cnt;
4533 eu_per = max(eu_per, eu_cnt);
4534 }
4535 }
4536 }
4537 seq_printf(m, " Enabled Slice Total: %u\n", s_tot);
4538 seq_printf(m, " Enabled Subslice Total: %u\n", ss_tot);
4539 seq_printf(m, " Enabled Subslice Per Slice: %u\n", ss_per);
4540 seq_printf(m, " Enabled EU Total: %u\n", eu_tot);
4541 seq_printf(m, " Enabled EU Per Subslice: %u\n", eu_per);
4542
Jeff McGee38732182015-02-13 10:27:54 -06004543 return 0;
4544}
4545
Ben Widawsky6d794d42011-04-25 11:25:56 -07004546static int i915_forcewake_open(struct inode *inode, struct file *file)
4547{
4548 struct drm_device *dev = inode->i_private;
4549 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004550
Daniel Vetter075edca2012-01-24 09:44:28 +01004551 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004552 return 0;
4553
Chris Wilson6daccb02015-01-16 11:34:35 +02004554 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004555 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004556
4557 return 0;
4558}
4559
Ben Widawskyc43b5632012-04-16 14:07:40 -07004560static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004561{
4562 struct drm_device *dev = inode->i_private;
4563 struct drm_i915_private *dev_priv = dev->dev_private;
4564
Daniel Vetter075edca2012-01-24 09:44:28 +01004565 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004566 return 0;
4567
Mika Kuoppala59bad942015-01-16 11:34:40 +02004568 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004569 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004570
4571 return 0;
4572}
4573
4574static const struct file_operations i915_forcewake_fops = {
4575 .owner = THIS_MODULE,
4576 .open = i915_forcewake_open,
4577 .release = i915_forcewake_release,
4578};
4579
4580static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4581{
4582 struct drm_device *dev = minor->dev;
4583 struct dentry *ent;
4584
4585 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004586 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004587 root, dev,
4588 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004589 if (!ent)
4590 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004591
Ben Widawsky8eb57292011-05-11 15:10:58 -07004592 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004593}
4594
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004595static int i915_debugfs_create(struct dentry *root,
4596 struct drm_minor *minor,
4597 const char *name,
4598 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004599{
4600 struct drm_device *dev = minor->dev;
4601 struct dentry *ent;
4602
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004603 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004604 S_IRUGO | S_IWUSR,
4605 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004606 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004607 if (!ent)
4608 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004609
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004610 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004611}
4612
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004613static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004614 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004615 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004616 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01004617 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004618 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004619 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004620 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004621 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004622 {"i915_gem_request", i915_gem_request_info, 0},
4623 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004624 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004625 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00004626 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
4627 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
4628 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07004629 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08004630 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304631 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004632 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004633 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004634 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004635 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004636 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004637 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004638 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004639 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004640 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004641 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01004642 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01004643 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004644 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004645 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004646 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004647 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004648 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004649 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004650 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03004651 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004652 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004653 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004654 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004655 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004656 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004657 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004658 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004659 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304660 {"i915_drrs_status", i915_drrs_status, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004661};
Ben Gamari27c202a2009-07-01 22:26:52 -04004662#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004663
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004664static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004665 const char *name;
4666 const struct file_operations *fops;
4667} i915_debugfs_files[] = {
4668 {"i915_wedged", &i915_wedged_fops},
4669 {"i915_max_freq", &i915_max_freq_fops},
4670 {"i915_min_freq", &i915_min_freq_fops},
4671 {"i915_cache_sharing", &i915_cache_sharing_fops},
4672 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004673 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4674 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004675 {"i915_gem_drop_caches", &i915_drop_caches_fops},
4676 {"i915_error_state", &i915_error_state_fops},
4677 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004678 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004679 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4680 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4681 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004682 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004683};
4684
Damien Lespiau07144422013-10-15 18:55:40 +01004685void intel_display_crc_init(struct drm_device *dev)
4686{
4687 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01004688 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01004689
Damien Lespiau055e3932014-08-18 13:49:10 +01004690 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01004691 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01004692
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004693 pipe_crc->opened = false;
4694 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01004695 init_waitqueue_head(&pipe_crc->wq);
4696 }
4697}
4698
Ben Gamari27c202a2009-07-01 22:26:52 -04004699int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004700{
Daniel Vetter34b96742013-07-04 20:49:44 +02004701 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004702
Ben Widawsky6d794d42011-04-25 11:25:56 -07004703 ret = i915_forcewake_create(minor->debugfs_root, minor);
4704 if (ret)
4705 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004706
Damien Lespiau07144422013-10-15 18:55:40 +01004707 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
4708 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
4709 if (ret)
4710 return ret;
4711 }
4712
Daniel Vetter34b96742013-07-04 20:49:44 +02004713 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4714 ret = i915_debugfs_create(minor->debugfs_root, minor,
4715 i915_debugfs_files[i].name,
4716 i915_debugfs_files[i].fops);
4717 if (ret)
4718 return ret;
4719 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004720
Ben Gamari27c202a2009-07-01 22:26:52 -04004721 return drm_debugfs_create_files(i915_debugfs_list,
4722 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004723 minor->debugfs_root, minor);
4724}
4725
Ben Gamari27c202a2009-07-01 22:26:52 -04004726void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004727{
Daniel Vetter34b96742013-07-04 20:49:44 +02004728 int i;
4729
Ben Gamari27c202a2009-07-01 22:26:52 -04004730 drm_debugfs_remove_files(i915_debugfs_list,
4731 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004732
Ben Widawsky6d794d42011-04-25 11:25:56 -07004733 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
4734 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004735
Daniel Vettere309a992013-10-16 22:55:51 +02004736 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01004737 struct drm_info_list *info_list =
4738 (struct drm_info_list *)&i915_pipe_crc_data[i];
4739
4740 drm_debugfs_remove_files(info_list, 1, minor);
4741 }
4742
Daniel Vetter34b96742013-07-04 20:49:44 +02004743 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4744 struct drm_info_list *info_list =
4745 (struct drm_info_list *) i915_debugfs_files[i].fops;
4746
4747 drm_debugfs_remove_files(info_list, 1, minor);
4748 }
Ben Gamari20172632009-02-17 20:08:50 -05004749}