blob: 5081e6f8a385129c4db91908db9ca582ba1dc231 [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
Chris Wilson481a3d42015-04-07 16:20:39 +0100126 seq_printf(m, "%pK: %s%s%s%s %8zdKiB %02x %02x %x %x %x%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100127 &obj->base,
Chris Wilson481a3d42015-04-07 16:20:39 +0100128 obj->active ? "*" : " ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100129 get_pin_flag(obj),
130 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700131 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800132 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100133 obj->base.read_domains,
134 obj->base.write_domain,
John Harrison97b2a6a2014-11-24 18:49:26 +0000135 i915_gem_request_get_seqno(obj->last_read_req),
136 i915_gem_request_get_seqno(obj->last_write_req),
137 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100138 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100139 obj->dirty ? " dirty" : "",
140 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
141 if (obj->base.name)
142 seq_printf(m, " (name: %d)", obj->base.name);
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300143 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800144 if (vma->pin_count > 0)
145 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300146 }
147 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100148 if (obj->pin_display)
149 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100150 if (obj->fence_reg != I915_FENCE_REG_NONE)
151 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700152 list_for_each_entry(vma, &obj->vma_list, vma_link) {
153 if (!i915_is_ggtt(vma->vm))
154 seq_puts(m, " (pp");
155 else
156 seq_puts(m, " (g");
Thierry Reding440fd522015-01-23 09:05:06 +0100157 seq_printf(m, "gtt offset: %08llx, size: %08llx, type: %u)",
Tvrtko Ursulinfe14d5f2014-12-10 17:27:58 +0000158 vma->node.start, vma->node.size,
159 vma->ggtt_view.type);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700160 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000161 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100162 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100163 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000164 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100165 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000166 *t++ = 'p';
167 if (obj->fault_mappable)
168 *t++ = 'f';
169 *t = '\0';
170 seq_printf(m, " (%s mappable)", s);
171 }
John Harrison41c52412014-11-24 18:49:43 +0000172 if (obj->last_read_req != NULL)
173 seq_printf(m, " (%s)",
174 i915_gem_request_get_ring(obj->last_read_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200175 if (obj->frontbuffer_bits)
176 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100177}
178
Oscar Mateo273497e2014-05-22 14:13:37 +0100179static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700180{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100181 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700182 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
183 seq_putc(m, ' ');
184}
185
Ben Gamari433e12f2009-02-17 20:08:51 -0500186static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500187{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100188 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500189 uintptr_t list = (uintptr_t) node->info_ent->data;
190 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500191 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700192 struct drm_i915_private *dev_priv = dev->dev_private;
193 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700194 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100195 size_t total_obj_size, total_gtt_size;
196 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100197
198 ret = mutex_lock_interruptible(&dev->struct_mutex);
199 if (ret)
200 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500201
Ben Widawskyca191b12013-07-31 17:00:14 -0700202 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500203 switch (list) {
204 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100205 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700206 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500207 break;
208 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100209 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700210 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500211 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500212 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100213 mutex_unlock(&dev->struct_mutex);
214 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500215 }
216
Chris Wilson8f2480f2010-09-26 11:44:19 +0100217 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700218 list_for_each_entry(vma, head, mm_list) {
219 seq_printf(m, " ");
220 describe_obj(m, vma->obj);
221 seq_printf(m, "\n");
222 total_obj_size += vma->obj->base.size;
223 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100224 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500225 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100226 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700227
Chris Wilson8f2480f2010-09-26 11:44:19 +0100228 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
229 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500230 return 0;
231}
232
Chris Wilson6d2b88852013-08-07 18:30:54 +0100233static int obj_rank_by_stolen(void *priv,
234 struct list_head *A, struct list_head *B)
235{
236 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200237 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100238 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200239 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100240
241 return a->stolen->start - b->stolen->start;
242}
243
244static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
245{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100246 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100247 struct drm_device *dev = node->minor->dev;
248 struct drm_i915_private *dev_priv = dev->dev_private;
249 struct drm_i915_gem_object *obj;
250 size_t total_obj_size, total_gtt_size;
251 LIST_HEAD(stolen);
252 int count, ret;
253
254 ret = mutex_lock_interruptible(&dev->struct_mutex);
255 if (ret)
256 return ret;
257
258 total_obj_size = total_gtt_size = count = 0;
259 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
260 if (obj->stolen == NULL)
261 continue;
262
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200263 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100264
265 total_obj_size += obj->base.size;
266 total_gtt_size += i915_gem_obj_ggtt_size(obj);
267 count++;
268 }
269 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
270 if (obj->stolen == NULL)
271 continue;
272
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200273 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100274
275 total_obj_size += obj->base.size;
276 count++;
277 }
278 list_sort(NULL, &stolen, obj_rank_by_stolen);
279 seq_puts(m, "Stolen:\n");
280 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200281 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100282 seq_puts(m, " ");
283 describe_obj(m, obj);
284 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200285 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100286 }
287 mutex_unlock(&dev->struct_mutex);
288
289 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
290 count, total_obj_size, total_gtt_size);
291 return 0;
292}
293
Chris Wilson6299f992010-11-24 12:23:44 +0000294#define count_objects(list, member) do { \
295 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700296 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000297 ++count; \
298 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700299 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000300 ++mappable_count; \
301 } \
302 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400303} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000304
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100305struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000306 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100307 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000308 size_t total, unbound;
309 size_t global, shared;
310 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100311};
312
313static int per_file_stats(int id, void *ptr, void *data)
314{
315 struct drm_i915_gem_object *obj = ptr;
316 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000317 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100318
319 stats->count++;
320 stats->total += obj->base.size;
321
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000322 if (obj->base.name || obj->base.dma_buf)
323 stats->shared += obj->base.size;
324
Chris Wilson6313c202014-03-19 13:45:45 +0000325 if (USES_FULL_PPGTT(obj->base.dev)) {
326 list_for_each_entry(vma, &obj->vma_list, vma_link) {
327 struct i915_hw_ppgtt *ppgtt;
328
329 if (!drm_mm_node_allocated(&vma->node))
330 continue;
331
332 if (i915_is_ggtt(vma->vm)) {
333 stats->global += obj->base.size;
334 continue;
335 }
336
337 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200338 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000339 continue;
340
John Harrison41c52412014-11-24 18:49:43 +0000341 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000342 stats->active += obj->base.size;
343 else
344 stats->inactive += obj->base.size;
345
346 return 0;
347 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100348 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000349 if (i915_gem_obj_ggtt_bound(obj)) {
350 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000351 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000352 stats->active += obj->base.size;
353 else
354 stats->inactive += obj->base.size;
355 return 0;
356 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100357 }
358
Chris Wilson6313c202014-03-19 13:45:45 +0000359 if (!list_empty(&obj->global_list))
360 stats->unbound += obj->base.size;
361
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100362 return 0;
363}
364
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100365#define print_file_stats(m, name, stats) do { \
366 if (stats.count) \
367 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n", \
368 name, \
369 stats.count, \
370 stats.total, \
371 stats.active, \
372 stats.inactive, \
373 stats.global, \
374 stats.shared, \
375 stats.unbound); \
376} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800377
378static void print_batch_pool_stats(struct seq_file *m,
379 struct drm_i915_private *dev_priv)
380{
381 struct drm_i915_gem_object *obj;
382 struct file_stats stats;
Chris Wilson06fbca72015-04-07 16:20:36 +0100383 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100384 int i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800385
386 memset(&stats, 0, sizeof(stats));
387
Chris Wilson06fbca72015-04-07 16:20:36 +0100388 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100389 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
390 list_for_each_entry(obj,
391 &ring->batch_pool.cache_list[j],
392 batch_pool_link)
393 per_file_stats(0, obj, &stats);
394 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100395 }
Brad Volkin493018d2014-12-11 12:13:08 -0800396
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100397 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800398}
399
Ben Widawskyca191b12013-07-31 17:00:14 -0700400#define count_vmas(list, member) do { \
401 list_for_each_entry(vma, list, member) { \
402 size += i915_gem_obj_ggtt_size(vma->obj); \
403 ++count; \
404 if (vma->obj->map_and_fenceable) { \
405 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
406 ++mappable_count; \
407 } \
408 } \
409} while (0)
410
411static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100412{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100413 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100414 struct drm_device *dev = node->minor->dev;
415 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200416 u32 count, mappable_count, purgeable_count;
417 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000418 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700419 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100420 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700421 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100422 int ret;
423
424 ret = mutex_lock_interruptible(&dev->struct_mutex);
425 if (ret)
426 return ret;
427
Chris Wilson6299f992010-11-24 12:23:44 +0000428 seq_printf(m, "%u objects, %zu bytes\n",
429 dev_priv->mm.object_count,
430 dev_priv->mm.object_memory);
431
432 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700433 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000434 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
435 count, mappable_count, size, mappable_size);
436
437 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700438 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000439 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
440 count, mappable_count, size, mappable_size);
441
442 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700443 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000444 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
445 count, mappable_count, size, mappable_size);
446
Chris Wilsonb7abb712012-08-20 11:33:30 +0200447 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700448 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200449 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200450 if (obj->madv == I915_MADV_DONTNEED)
451 purgeable_size += obj->base.size, ++purgeable_count;
452 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200453 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
454
Chris Wilson6299f992010-11-24 12:23:44 +0000455 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700456 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000457 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700458 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000459 ++count;
460 }
Chris Wilson30154652015-04-07 17:28:24 +0100461 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700462 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000463 ++mappable_count;
464 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200465 if (obj->madv == I915_MADV_DONTNEED) {
466 purgeable_size += obj->base.size;
467 ++purgeable_count;
468 }
Chris Wilson6299f992010-11-24 12:23:44 +0000469 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200470 seq_printf(m, "%u purgeable objects, %zu bytes\n",
471 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000472 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
473 mappable_count, mappable_size);
474 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
475 count, size);
476
Ben Widawsky93d18792013-01-17 12:45:17 -0800477 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700478 dev_priv->gtt.base.total,
479 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100480
Damien Lespiau267f0c92013-06-24 22:59:48 +0100481 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800482 print_batch_pool_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100483 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
484 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900485 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100486
487 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000488 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100489 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100490 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100491 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900492 /*
493 * Although we have a valid reference on file->pid, that does
494 * not guarantee that the task_struct who called get_pid() is
495 * still alive (e.g. get_pid(current) => fork() => exit()).
496 * Therefore, we need to protect this ->comm access using RCU.
497 */
498 rcu_read_lock();
499 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800500 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900501 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100502 }
503
Chris Wilson73aa8082010-09-30 11:46:12 +0100504 mutex_unlock(&dev->struct_mutex);
505
506 return 0;
507}
508
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100509static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000510{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100511 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000512 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100513 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000514 struct drm_i915_private *dev_priv = dev->dev_private;
515 struct drm_i915_gem_object *obj;
516 size_t total_obj_size, total_gtt_size;
517 int count, ret;
518
519 ret = mutex_lock_interruptible(&dev->struct_mutex);
520 if (ret)
521 return ret;
522
523 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700524 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800525 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100526 continue;
527
Damien Lespiau267f0c92013-06-24 22:59:48 +0100528 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000529 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100530 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000531 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700532 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000533 count++;
534 }
535
536 mutex_unlock(&dev->struct_mutex);
537
538 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
539 count, total_obj_size, total_gtt_size);
540
541 return 0;
542}
543
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100544static int i915_gem_pageflip_info(struct seq_file *m, void *data)
545{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100546 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100547 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100548 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100549 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200550 int ret;
551
552 ret = mutex_lock_interruptible(&dev->struct_mutex);
553 if (ret)
554 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100555
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100556 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800557 const char pipe = pipe_name(crtc->pipe);
558 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100559 struct intel_unpin_work *work;
560
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200561 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100562 work = crtc->unpin_work;
563 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800564 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100565 pipe, plane);
566 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100567 u32 addr;
568
Chris Wilsone7d841c2012-12-03 11:36:30 +0000569 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800570 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100571 pipe, plane);
572 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800573 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100574 pipe, plane);
575 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100576 if (work->flip_queued_req) {
577 struct intel_engine_cs *ring =
578 i915_gem_request_get_ring(work->flip_queued_req);
579
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200580 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 +0100581 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000582 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100583 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100584 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000585 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100586 } else
587 seq_printf(m, "Flip not associated with any ring\n");
588 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
589 work->flip_queued_vblank,
590 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100591 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100592 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100593 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100594 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100595 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000596 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100597
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100598 if (INTEL_INFO(dev)->gen >= 4)
599 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
600 else
601 addr = I915_READ(DSPADDR(crtc->plane));
602 seq_printf(m, "Current scanout address 0x%08x\n", addr);
603
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100604 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100605 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
606 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100607 }
608 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200609 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100610 }
611
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200612 mutex_unlock(&dev->struct_mutex);
613
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100614 return 0;
615}
616
Brad Volkin493018d2014-12-11 12:13:08 -0800617static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
618{
619 struct drm_info_node *node = m->private;
620 struct drm_device *dev = node->minor->dev;
621 struct drm_i915_private *dev_priv = dev->dev_private;
622 struct drm_i915_gem_object *obj;
Chris Wilson06fbca72015-04-07 16:20:36 +0100623 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100624 int total = 0;
625 int ret, i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800626
627 ret = mutex_lock_interruptible(&dev->struct_mutex);
628 if (ret)
629 return ret;
630
Chris Wilson06fbca72015-04-07 16:20:36 +0100631 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100632 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
633 int count;
634
635 count = 0;
636 list_for_each_entry(obj,
637 &ring->batch_pool.cache_list[j],
638 batch_pool_link)
639 count++;
640 seq_printf(m, "%s cache[%d]: %d objects\n",
641 ring->name, j, count);
642
643 list_for_each_entry(obj,
644 &ring->batch_pool.cache_list[j],
645 batch_pool_link) {
646 seq_puts(m, " ");
647 describe_obj(m, obj);
648 seq_putc(m, '\n');
649 }
650
651 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100652 }
Brad Volkin493018d2014-12-11 12:13:08 -0800653 }
654
Chris Wilson8d9d5742015-04-07 16:20:38 +0100655 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800656
657 mutex_unlock(&dev->struct_mutex);
658
659 return 0;
660}
661
Ben Gamari20172632009-02-17 20:08:50 -0500662static int i915_gem_request_info(struct seq_file *m, void *data)
663{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100664 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500665 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300666 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100667 struct intel_engine_cs *ring;
Chris Wilson2d1070b2015-04-01 10:36:56 +0100668 struct drm_i915_gem_request *rq;
669 int ret, any, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100670
671 ret = mutex_lock_interruptible(&dev->struct_mutex);
672 if (ret)
673 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500674
Chris Wilson2d1070b2015-04-01 10:36:56 +0100675 any = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100676 for_each_ring(ring, dev_priv, i) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100677 int count;
678
679 count = 0;
680 list_for_each_entry(rq, &ring->request_list, list)
681 count++;
682 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100683 continue;
684
Chris Wilson2d1070b2015-04-01 10:36:56 +0100685 seq_printf(m, "%s requests: %d\n", ring->name, count);
686 list_for_each_entry(rq, &ring->request_list, list) {
687 struct task_struct *task;
688
689 rcu_read_lock();
690 task = NULL;
691 if (rq->pid)
692 task = pid_task(rq->pid, PIDTYPE_PID);
693 seq_printf(m, " %x @ %d: %s [%d]\n",
694 rq->seqno,
695 (int) (jiffies - rq->emitted_jiffies),
696 task ? task->comm : "<unknown>",
697 task ? task->pid : -1);
698 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100699 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100700
701 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500702 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100703 mutex_unlock(&dev->struct_mutex);
704
Chris Wilson2d1070b2015-04-01 10:36:56 +0100705 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100706 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100707
Ben Gamari20172632009-02-17 20:08:50 -0500708 return 0;
709}
710
Chris Wilsonb2223492010-10-27 15:27:33 +0100711static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100712 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100713{
714 if (ring->get_seqno) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200715 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100716 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100717 }
718}
719
Ben Gamari20172632009-02-17 20:08:50 -0500720static int i915_gem_seqno_info(struct seq_file *m, void *data)
721{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100722 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500723 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300724 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100725 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000726 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100727
728 ret = mutex_lock_interruptible(&dev->struct_mutex);
729 if (ret)
730 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200731 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500732
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100733 for_each_ring(ring, dev_priv, i)
734 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100735
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200736 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100737 mutex_unlock(&dev->struct_mutex);
738
Ben Gamari20172632009-02-17 20:08:50 -0500739 return 0;
740}
741
742
743static int i915_interrupt_info(struct seq_file *m, void *data)
744{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100745 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500746 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300747 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100748 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800749 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100750
751 ret = mutex_lock_interruptible(&dev->struct_mutex);
752 if (ret)
753 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200754 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500755
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300756 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300757 seq_printf(m, "Master Interrupt Control:\t%08x\n",
758 I915_READ(GEN8_MASTER_IRQ));
759
760 seq_printf(m, "Display IER:\t%08x\n",
761 I915_READ(VLV_IER));
762 seq_printf(m, "Display IIR:\t%08x\n",
763 I915_READ(VLV_IIR));
764 seq_printf(m, "Display IIR_RW:\t%08x\n",
765 I915_READ(VLV_IIR_RW));
766 seq_printf(m, "Display IMR:\t%08x\n",
767 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100768 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300769 seq_printf(m, "Pipe %c stat:\t%08x\n",
770 pipe_name(pipe),
771 I915_READ(PIPESTAT(pipe)));
772
773 seq_printf(m, "Port hotplug:\t%08x\n",
774 I915_READ(PORT_HOTPLUG_EN));
775 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
776 I915_READ(VLV_DPFLIPSTAT));
777 seq_printf(m, "DPINVGTT:\t%08x\n",
778 I915_READ(DPINVGTT));
779
780 for (i = 0; i < 4; i++) {
781 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
782 i, I915_READ(GEN8_GT_IMR(i)));
783 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
784 i, I915_READ(GEN8_GT_IIR(i)));
785 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
786 i, I915_READ(GEN8_GT_IER(i)));
787 }
788
789 seq_printf(m, "PCU interrupt mask:\t%08x\n",
790 I915_READ(GEN8_PCU_IMR));
791 seq_printf(m, "PCU interrupt identity:\t%08x\n",
792 I915_READ(GEN8_PCU_IIR));
793 seq_printf(m, "PCU interrupt enable:\t%08x\n",
794 I915_READ(GEN8_PCU_IER));
795 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700796 seq_printf(m, "Master Interrupt Control:\t%08x\n",
797 I915_READ(GEN8_MASTER_IRQ));
798
799 for (i = 0; i < 4; i++) {
800 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
801 i, I915_READ(GEN8_GT_IMR(i)));
802 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
803 i, I915_READ(GEN8_GT_IIR(i)));
804 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
805 i, I915_READ(GEN8_GT_IER(i)));
806 }
807
Damien Lespiau055e3932014-08-18 13:49:10 +0100808 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200809 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300810 POWER_DOMAIN_PIPE(pipe))) {
811 seq_printf(m, "Pipe %c power disabled\n",
812 pipe_name(pipe));
813 continue;
814 }
Ben Widawskya123f152013-11-02 21:07:10 -0700815 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000816 pipe_name(pipe),
817 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700818 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000819 pipe_name(pipe),
820 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700821 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000822 pipe_name(pipe),
823 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700824 }
825
826 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
827 I915_READ(GEN8_DE_PORT_IMR));
828 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
829 I915_READ(GEN8_DE_PORT_IIR));
830 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
831 I915_READ(GEN8_DE_PORT_IER));
832
833 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
834 I915_READ(GEN8_DE_MISC_IMR));
835 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
836 I915_READ(GEN8_DE_MISC_IIR));
837 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
838 I915_READ(GEN8_DE_MISC_IER));
839
840 seq_printf(m, "PCU interrupt mask:\t%08x\n",
841 I915_READ(GEN8_PCU_IMR));
842 seq_printf(m, "PCU interrupt identity:\t%08x\n",
843 I915_READ(GEN8_PCU_IIR));
844 seq_printf(m, "PCU interrupt enable:\t%08x\n",
845 I915_READ(GEN8_PCU_IER));
846 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700847 seq_printf(m, "Display IER:\t%08x\n",
848 I915_READ(VLV_IER));
849 seq_printf(m, "Display IIR:\t%08x\n",
850 I915_READ(VLV_IIR));
851 seq_printf(m, "Display IIR_RW:\t%08x\n",
852 I915_READ(VLV_IIR_RW));
853 seq_printf(m, "Display IMR:\t%08x\n",
854 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100855 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700856 seq_printf(m, "Pipe %c stat:\t%08x\n",
857 pipe_name(pipe),
858 I915_READ(PIPESTAT(pipe)));
859
860 seq_printf(m, "Master IER:\t%08x\n",
861 I915_READ(VLV_MASTER_IER));
862
863 seq_printf(m, "Render IER:\t%08x\n",
864 I915_READ(GTIER));
865 seq_printf(m, "Render IIR:\t%08x\n",
866 I915_READ(GTIIR));
867 seq_printf(m, "Render IMR:\t%08x\n",
868 I915_READ(GTIMR));
869
870 seq_printf(m, "PM IER:\t\t%08x\n",
871 I915_READ(GEN6_PMIER));
872 seq_printf(m, "PM IIR:\t\t%08x\n",
873 I915_READ(GEN6_PMIIR));
874 seq_printf(m, "PM IMR:\t\t%08x\n",
875 I915_READ(GEN6_PMIMR));
876
877 seq_printf(m, "Port hotplug:\t%08x\n",
878 I915_READ(PORT_HOTPLUG_EN));
879 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
880 I915_READ(VLV_DPFLIPSTAT));
881 seq_printf(m, "DPINVGTT:\t%08x\n",
882 I915_READ(DPINVGTT));
883
884 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800885 seq_printf(m, "Interrupt enable: %08x\n",
886 I915_READ(IER));
887 seq_printf(m, "Interrupt identity: %08x\n",
888 I915_READ(IIR));
889 seq_printf(m, "Interrupt mask: %08x\n",
890 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100891 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800892 seq_printf(m, "Pipe %c stat: %08x\n",
893 pipe_name(pipe),
894 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800895 } else {
896 seq_printf(m, "North Display Interrupt enable: %08x\n",
897 I915_READ(DEIER));
898 seq_printf(m, "North Display Interrupt identity: %08x\n",
899 I915_READ(DEIIR));
900 seq_printf(m, "North Display Interrupt mask: %08x\n",
901 I915_READ(DEIMR));
902 seq_printf(m, "South Display Interrupt enable: %08x\n",
903 I915_READ(SDEIER));
904 seq_printf(m, "South Display Interrupt identity: %08x\n",
905 I915_READ(SDEIIR));
906 seq_printf(m, "South Display Interrupt mask: %08x\n",
907 I915_READ(SDEIMR));
908 seq_printf(m, "Graphics Interrupt enable: %08x\n",
909 I915_READ(GTIER));
910 seq_printf(m, "Graphics Interrupt identity: %08x\n",
911 I915_READ(GTIIR));
912 seq_printf(m, "Graphics Interrupt mask: %08x\n",
913 I915_READ(GTIMR));
914 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100915 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700916 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100917 seq_printf(m,
918 "Graphics Interrupt mask (%s): %08x\n",
919 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000920 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100921 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000922 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200923 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100924 mutex_unlock(&dev->struct_mutex);
925
Ben Gamari20172632009-02-17 20:08:50 -0500926 return 0;
927}
928
Chris Wilsona6172a82009-02-11 14:26:38 +0000929static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
930{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100931 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000932 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300933 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100934 int i, ret;
935
936 ret = mutex_lock_interruptible(&dev->struct_mutex);
937 if (ret)
938 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000939
940 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
941 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
942 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000943 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000944
Chris Wilson6c085a72012-08-20 11:40:46 +0200945 seq_printf(m, "Fence %d, pin count = %d, object = ",
946 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100947 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100948 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100949 else
Chris Wilson05394f32010-11-08 19:18:58 +0000950 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100951 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000952 }
953
Chris Wilson05394f32010-11-08 19:18:58 +0000954 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000955 return 0;
956}
957
Ben Gamari20172632009-02-17 20:08:50 -0500958static int i915_hws_info(struct seq_file *m, void *data)
959{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100960 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500961 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300962 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100963 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100964 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100965 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500966
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000967 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100968 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500969 if (hws == NULL)
970 return 0;
971
972 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
973 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
974 i * 4,
975 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
976 }
977 return 0;
978}
979
Daniel Vetterd5442302012-04-27 15:17:40 +0200980static ssize_t
981i915_error_state_write(struct file *filp,
982 const char __user *ubuf,
983 size_t cnt,
984 loff_t *ppos)
985{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300986 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200987 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200988 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200989
990 DRM_DEBUG_DRIVER("Resetting error state\n");
991
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200992 ret = mutex_lock_interruptible(&dev->struct_mutex);
993 if (ret)
994 return ret;
995
Daniel Vetterd5442302012-04-27 15:17:40 +0200996 i915_destroy_error_state(dev);
997 mutex_unlock(&dev->struct_mutex);
998
999 return cnt;
1000}
1001
1002static int i915_error_state_open(struct inode *inode, struct file *file)
1003{
1004 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001005 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001006
1007 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1008 if (!error_priv)
1009 return -ENOMEM;
1010
1011 error_priv->dev = dev;
1012
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001013 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001014
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001015 file->private_data = error_priv;
1016
1017 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001018}
1019
1020static int i915_error_state_release(struct inode *inode, struct file *file)
1021{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001022 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001023
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001024 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001025 kfree(error_priv);
1026
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001027 return 0;
1028}
1029
1030static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1031 size_t count, loff_t *pos)
1032{
1033 struct i915_error_state_file_priv *error_priv = file->private_data;
1034 struct drm_i915_error_state_buf error_str;
1035 loff_t tmp_pos = 0;
1036 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001037 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001038
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001039 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001040 if (ret)
1041 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001042
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001043 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001044 if (ret)
1045 goto out;
1046
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001047 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1048 error_str.buf,
1049 error_str.bytes);
1050
1051 if (ret_count < 0)
1052 ret = ret_count;
1053 else
1054 *pos = error_str.start + ret_count;
1055out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001056 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001057 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001058}
1059
1060static const struct file_operations i915_error_state_fops = {
1061 .owner = THIS_MODULE,
1062 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001063 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001064 .write = i915_error_state_write,
1065 .llseek = default_llseek,
1066 .release = i915_error_state_release,
1067};
1068
Kees Cook647416f2013-03-10 14:10:06 -07001069static int
1070i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001071{
Kees Cook647416f2013-03-10 14:10:06 -07001072 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001073 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001074 int ret;
1075
1076 ret = mutex_lock_interruptible(&dev->struct_mutex);
1077 if (ret)
1078 return ret;
1079
Kees Cook647416f2013-03-10 14:10:06 -07001080 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001081 mutex_unlock(&dev->struct_mutex);
1082
Kees Cook647416f2013-03-10 14:10:06 -07001083 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001084}
1085
Kees Cook647416f2013-03-10 14:10:06 -07001086static int
1087i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001088{
Kees Cook647416f2013-03-10 14:10:06 -07001089 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001090 int ret;
1091
Mika Kuoppala40633212012-12-04 15:12:00 +02001092 ret = mutex_lock_interruptible(&dev->struct_mutex);
1093 if (ret)
1094 return ret;
1095
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001096 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001097 mutex_unlock(&dev->struct_mutex);
1098
Kees Cook647416f2013-03-10 14:10:06 -07001099 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001100}
1101
Kees Cook647416f2013-03-10 14:10:06 -07001102DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1103 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001104 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001105
Deepak Sadb4bd12014-03-31 11:30:02 +05301106static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001107{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001108 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001109 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001110 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001111 int ret = 0;
1112
1113 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001114
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001115 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1116
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001117 if (IS_GEN5(dev)) {
1118 u16 rgvswctl = I915_READ16(MEMSWCTL);
1119 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1120
1121 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1122 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1123 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1124 MEMSTAT_VID_SHIFT);
1125 seq_printf(m, "Current P-state: %d\n",
1126 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001127 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
Akash Goel60260a52015-03-06 11:07:21 +05301128 IS_BROADWELL(dev) || IS_GEN9(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001129 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1130 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1131 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001132 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001133 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001134 u32 rpupei, rpcurup, rpprevup;
1135 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001136 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001137 int max_freq;
1138
1139 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001140 ret = mutex_lock_interruptible(&dev->struct_mutex);
1141 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001142 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001143
Mika Kuoppala59bad942015-01-16 11:34:40 +02001144 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001145
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001146 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301147 if (IS_GEN9(dev))
1148 reqf >>= 23;
1149 else {
1150 reqf &= ~GEN6_TURBO_DISABLE;
1151 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1152 reqf >>= 24;
1153 else
1154 reqf >>= 25;
1155 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001156 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001157
Chris Wilson0d8f9492014-03-27 09:06:14 +00001158 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1159 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1160 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1161
Jesse Barnesccab5c82011-01-18 15:49:25 -08001162 rpstat = I915_READ(GEN6_RPSTAT1);
1163 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1164 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1165 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1166 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1167 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1168 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Akash Goel60260a52015-03-06 11:07:21 +05301169 if (IS_GEN9(dev))
1170 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1171 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001172 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1173 else
1174 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001175 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001176
Mika Kuoppala59bad942015-01-16 11:34:40 +02001177 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001178 mutex_unlock(&dev->struct_mutex);
1179
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001180 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1181 pm_ier = I915_READ(GEN6_PMIER);
1182 pm_imr = I915_READ(GEN6_PMIMR);
1183 pm_isr = I915_READ(GEN6_PMISR);
1184 pm_iir = I915_READ(GEN6_PMIIR);
1185 pm_mask = I915_READ(GEN6_PMINTRMSK);
1186 } else {
1187 pm_ier = I915_READ(GEN8_GT_IER(2));
1188 pm_imr = I915_READ(GEN8_GT_IMR(2));
1189 pm_isr = I915_READ(GEN8_GT_ISR(2));
1190 pm_iir = I915_READ(GEN8_GT_IIR(2));
1191 pm_mask = I915_READ(GEN6_PMINTRMSK);
1192 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001193 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 -03001194 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001195 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001196 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301197 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001198 seq_printf(m, "Render p-state VID: %d\n",
1199 gt_perf_status & 0xff);
1200 seq_printf(m, "Render p-state limit: %d\n",
1201 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001202 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1203 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1204 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1205 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001206 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001207 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001208 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1209 GEN6_CURICONT_MASK);
1210 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1211 GEN6_CURBSYTAVG_MASK);
1212 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1213 GEN6_CURBSYTAVG_MASK);
1214 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1215 GEN6_CURIAVG_MASK);
1216 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1217 GEN6_CURBSYTAVG_MASK);
1218 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1219 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001220
1221 max_freq = (rp_state_cap & 0xff0000) >> 16;
Akash Goel60260a52015-03-06 11:07:21 +05301222 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001223 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001224 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001225
1226 max_freq = (rp_state_cap & 0xff00) >> 8;
Akash Goel60260a52015-03-06 11:07:21 +05301227 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001228 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001229 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001230
1231 max_freq = rp_state_cap & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301232 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001233 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001234 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001235
1236 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001237 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001238
1239 seq_printf(m, "Idle freq: %d MHz\n",
1240 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001241 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001242 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001243
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001244 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001245 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001246 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1247 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1248
Jesse Barnes0a073b82013-04-17 15:54:58 -07001249 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001250 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001251
Jesse Barnes0a073b82013-04-17 15:54:58 -07001252 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001253 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001254
Chris Wilsonaed242f2015-03-18 09:48:21 +00001255 seq_printf(m, "idle GPU freq: %d MHz\n",
1256 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1257
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001258 seq_printf(m,
1259 "efficient (RPe) frequency: %d MHz\n",
1260 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001261
1262 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001263 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001264 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001265 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001266 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001267 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001268
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001269out:
1270 intel_runtime_pm_put(dev_priv);
1271 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001272}
1273
Chris Wilsonf6544492015-01-26 18:03:04 +02001274static int i915_hangcheck_info(struct seq_file *m, void *unused)
1275{
1276 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001277 struct drm_device *dev = node->minor->dev;
1278 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf6544492015-01-26 18:03:04 +02001279 struct intel_engine_cs *ring;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001280 u64 acthd[I915_NUM_RINGS];
1281 u32 seqno[I915_NUM_RINGS];
Chris Wilsonf6544492015-01-26 18:03:04 +02001282 int i;
1283
1284 if (!i915.enable_hangcheck) {
1285 seq_printf(m, "Hangcheck disabled\n");
1286 return 0;
1287 }
1288
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001289 intel_runtime_pm_get(dev_priv);
1290
1291 for_each_ring(ring, dev_priv, i) {
1292 seqno[i] = ring->get_seqno(ring, false);
1293 acthd[i] = intel_ring_get_active_head(ring);
1294 }
1295
1296 intel_runtime_pm_put(dev_priv);
1297
Chris Wilsonf6544492015-01-26 18:03:04 +02001298 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1299 seq_printf(m, "Hangcheck active, fires in %dms\n",
1300 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1301 jiffies));
1302 } else
1303 seq_printf(m, "Hangcheck inactive\n");
1304
1305 for_each_ring(ring, dev_priv, i) {
1306 seq_printf(m, "%s:\n", ring->name);
1307 seq_printf(m, "\tseqno = %x [current %x]\n",
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001308 ring->hangcheck.seqno, seqno[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001309 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1310 (long long)ring->hangcheck.acthd,
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001311 (long long)acthd[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001312 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1313 (long long)ring->hangcheck.max_acthd);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001314 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1315 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
Chris Wilsonf6544492015-01-26 18:03:04 +02001316 }
1317
1318 return 0;
1319}
1320
Ben Widawsky4d855292011-12-12 19:34:16 -08001321static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001322{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001323 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001324 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001325 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001326 u32 rgvmodectl, rstdbyctl;
1327 u16 crstandvid;
1328 int ret;
1329
1330 ret = mutex_lock_interruptible(&dev->struct_mutex);
1331 if (ret)
1332 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001333 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001334
1335 rgvmodectl = I915_READ(MEMMODECTL);
1336 rstdbyctl = I915_READ(RSTDBYCTL);
1337 crstandvid = I915_READ16(CRSTANDVID);
1338
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001339 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001340 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001341
1342 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1343 "yes" : "no");
1344 seq_printf(m, "Boost freq: %d\n",
1345 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1346 MEMMODE_BOOST_FREQ_SHIFT);
1347 seq_printf(m, "HW control enabled: %s\n",
1348 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1349 seq_printf(m, "SW control enabled: %s\n",
1350 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1351 seq_printf(m, "Gated voltage change: %s\n",
1352 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1353 seq_printf(m, "Starting frequency: P%d\n",
1354 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001355 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001356 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001357 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1358 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1359 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1360 seq_printf(m, "Render standby enabled: %s\n",
1361 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001362 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001363 switch (rstdbyctl & RSX_STATUS_MASK) {
1364 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001365 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001366 break;
1367 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001368 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001369 break;
1370 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001371 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001372 break;
1373 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001374 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001375 break;
1376 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001377 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001378 break;
1379 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001380 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001381 break;
1382 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001383 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001384 break;
1385 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001386
1387 return 0;
1388}
1389
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001390static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001391{
1392 struct drm_info_node *node = m->private;
1393 struct drm_device *dev = node->minor->dev;
1394 struct drm_i915_private *dev_priv = dev->dev_private;
1395 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001396 int i;
1397
1398 spin_lock_irq(&dev_priv->uncore.lock);
1399 for_each_fw_domain(fw_domain, dev_priv, i) {
1400 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001401 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001402 fw_domain->wake_count);
1403 }
1404 spin_unlock_irq(&dev_priv->uncore.lock);
1405
1406 return 0;
1407}
1408
Deepak S669ab5a2014-01-10 15:18:26 +05301409static int vlv_drpc_info(struct seq_file *m)
1410{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001411 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301412 struct drm_device *dev = node->minor->dev;
1413 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001414 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301415
Imre Deakd46c0512014-04-14 20:24:27 +03001416 intel_runtime_pm_get(dev_priv);
1417
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001418 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301419 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1420 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1421
Imre Deakd46c0512014-04-14 20:24:27 +03001422 intel_runtime_pm_put(dev_priv);
1423
Deepak S669ab5a2014-01-10 15:18:26 +05301424 seq_printf(m, "Video Turbo Mode: %s\n",
1425 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1426 seq_printf(m, "Turbo enabled: %s\n",
1427 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1428 seq_printf(m, "HW control enabled: %s\n",
1429 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1430 seq_printf(m, "SW control enabled: %s\n",
1431 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1432 GEN6_RP_MEDIA_SW_MODE));
1433 seq_printf(m, "RC6 Enabled: %s\n",
1434 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1435 GEN6_RC_CTL_EI_MODE(1))));
1436 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001437 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301438 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001439 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301440
Imre Deak9cc19be2014-04-14 20:24:24 +03001441 seq_printf(m, "Render RC6 residency since boot: %u\n",
1442 I915_READ(VLV_GT_RENDER_RC6));
1443 seq_printf(m, "Media RC6 residency since boot: %u\n",
1444 I915_READ(VLV_GT_MEDIA_RC6));
1445
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001446 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301447}
1448
Ben Widawsky4d855292011-12-12 19:34:16 -08001449static int gen6_drpc_info(struct seq_file *m)
1450{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001451 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001452 struct drm_device *dev = node->minor->dev;
1453 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001454 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001455 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001456 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001457
1458 ret = mutex_lock_interruptible(&dev->struct_mutex);
1459 if (ret)
1460 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001461 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001462
Chris Wilson907b28c2013-07-19 20:36:52 +01001463 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001464 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001465 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001466
1467 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001468 seq_puts(m, "RC information inaccurate because somebody "
1469 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001470 } else {
1471 /* NB: we cannot use forcewake, else we read the wrong values */
1472 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1473 udelay(10);
1474 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1475 }
1476
1477 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001478 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001479
1480 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1481 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1482 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001483 mutex_lock(&dev_priv->rps.hw_lock);
1484 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1485 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001486
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001487 intel_runtime_pm_put(dev_priv);
1488
Ben Widawsky4d855292011-12-12 19:34:16 -08001489 seq_printf(m, "Video Turbo Mode: %s\n",
1490 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1491 seq_printf(m, "HW control enabled: %s\n",
1492 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1493 seq_printf(m, "SW control enabled: %s\n",
1494 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1495 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001496 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001497 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1498 seq_printf(m, "RC6 Enabled: %s\n",
1499 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1500 seq_printf(m, "Deep RC6 Enabled: %s\n",
1501 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1502 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1503 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001504 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001505 switch (gt_core_status & GEN6_RCn_MASK) {
1506 case GEN6_RC0:
1507 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001508 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001509 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001510 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001511 break;
1512 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001513 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001514 break;
1515 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001516 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001517 break;
1518 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001519 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001520 break;
1521 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001522 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001523 break;
1524 }
1525
1526 seq_printf(m, "Core Power Down: %s\n",
1527 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001528
1529 /* Not exactly sure what this is */
1530 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1531 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1532 seq_printf(m, "RC6 residency since boot: %u\n",
1533 I915_READ(GEN6_GT_GFX_RC6));
1534 seq_printf(m, "RC6+ residency since boot: %u\n",
1535 I915_READ(GEN6_GT_GFX_RC6p));
1536 seq_printf(m, "RC6++ residency since boot: %u\n",
1537 I915_READ(GEN6_GT_GFX_RC6pp));
1538
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001539 seq_printf(m, "RC6 voltage: %dmV\n",
1540 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1541 seq_printf(m, "RC6+ voltage: %dmV\n",
1542 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1543 seq_printf(m, "RC6++ voltage: %dmV\n",
1544 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001545 return 0;
1546}
1547
1548static int i915_drpc_info(struct seq_file *m, void *unused)
1549{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001550 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001551 struct drm_device *dev = node->minor->dev;
1552
Deepak S669ab5a2014-01-10 15:18:26 +05301553 if (IS_VALLEYVIEW(dev))
1554 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001555 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001556 return gen6_drpc_info(m);
1557 else
1558 return ironlake_drpc_info(m);
1559}
1560
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001561static int i915_fbc_status(struct seq_file *m, void *unused)
1562{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001563 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001564 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001565 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001566
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001567 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001568 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001569 return 0;
1570 }
1571
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001572 intel_runtime_pm_get(dev_priv);
1573
Adam Jacksonee5382a2010-04-23 11:17:39 -04001574 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001575 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001576 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001577 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001578 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001579 case FBC_OK:
1580 seq_puts(m, "FBC actived, but currently disabled in hardware");
1581 break;
1582 case FBC_UNSUPPORTED:
1583 seq_puts(m, "unsupported by this chipset");
1584 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001585 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001586 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001587 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001588 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001589 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001590 break;
1591 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001592 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001593 break;
1594 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001595 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001596 break;
1597 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001598 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001599 break;
1600 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001601 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001602 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001603 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001604 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001605 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001606 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001607 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001608 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001609 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001610 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001611 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001612 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001613 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001614 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001615 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001616 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001617
1618 intel_runtime_pm_put(dev_priv);
1619
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001620 return 0;
1621}
1622
Rodrigo Vivida46f932014-08-01 02:04:45 -07001623static int i915_fbc_fc_get(void *data, u64 *val)
1624{
1625 struct drm_device *dev = data;
1626 struct drm_i915_private *dev_priv = dev->dev_private;
1627
1628 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1629 return -ENODEV;
1630
1631 drm_modeset_lock_all(dev);
1632 *val = dev_priv->fbc.false_color;
1633 drm_modeset_unlock_all(dev);
1634
1635 return 0;
1636}
1637
1638static int i915_fbc_fc_set(void *data, u64 val)
1639{
1640 struct drm_device *dev = data;
1641 struct drm_i915_private *dev_priv = dev->dev_private;
1642 u32 reg;
1643
1644 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1645 return -ENODEV;
1646
1647 drm_modeset_lock_all(dev);
1648
1649 reg = I915_READ(ILK_DPFC_CONTROL);
1650 dev_priv->fbc.false_color = val;
1651
1652 I915_WRITE(ILK_DPFC_CONTROL, val ?
1653 (reg | FBC_CTL_FALSE_COLOR) :
1654 (reg & ~FBC_CTL_FALSE_COLOR));
1655
1656 drm_modeset_unlock_all(dev);
1657 return 0;
1658}
1659
1660DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1661 i915_fbc_fc_get, i915_fbc_fc_set,
1662 "%llu\n");
1663
Paulo Zanoni92d44622013-05-31 16:33:24 -03001664static int i915_ips_status(struct seq_file *m, void *unused)
1665{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001666 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001667 struct drm_device *dev = node->minor->dev;
1668 struct drm_i915_private *dev_priv = dev->dev_private;
1669
Damien Lespiauf5adf942013-06-24 18:29:34 +01001670 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001671 seq_puts(m, "not supported\n");
1672 return 0;
1673 }
1674
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001675 intel_runtime_pm_get(dev_priv);
1676
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001677 seq_printf(m, "Enabled by kernel parameter: %s\n",
1678 yesno(i915.enable_ips));
1679
1680 if (INTEL_INFO(dev)->gen >= 8) {
1681 seq_puts(m, "Currently: unknown\n");
1682 } else {
1683 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1684 seq_puts(m, "Currently: enabled\n");
1685 else
1686 seq_puts(m, "Currently: disabled\n");
1687 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001688
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001689 intel_runtime_pm_put(dev_priv);
1690
Paulo Zanoni92d44622013-05-31 16:33:24 -03001691 return 0;
1692}
1693
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001694static int i915_sr_status(struct seq_file *m, void *unused)
1695{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001696 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001697 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001698 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001699 bool sr_enabled = false;
1700
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001701 intel_runtime_pm_get(dev_priv);
1702
Yuanhan Liu13982612010-12-15 15:42:31 +08001703 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001704 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001705 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001706 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1707 else if (IS_I915GM(dev))
1708 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1709 else if (IS_PINEVIEW(dev))
1710 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1711
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001712 intel_runtime_pm_put(dev_priv);
1713
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001714 seq_printf(m, "self-refresh: %s\n",
1715 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001716
1717 return 0;
1718}
1719
Jesse Barnes7648fa92010-05-20 14:28:11 -07001720static int i915_emon_status(struct seq_file *m, void *unused)
1721{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001722 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001723 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001724 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001725 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001726 int ret;
1727
Chris Wilson582be6b2012-04-30 19:35:02 +01001728 if (!IS_GEN5(dev))
1729 return -ENODEV;
1730
Chris Wilsonde227ef2010-07-03 07:58:38 +01001731 ret = mutex_lock_interruptible(&dev->struct_mutex);
1732 if (ret)
1733 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001734
1735 temp = i915_mch_val(dev_priv);
1736 chipset = i915_chipset_val(dev_priv);
1737 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001738 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001739
1740 seq_printf(m, "GMCH temp: %ld\n", temp);
1741 seq_printf(m, "Chipset power: %ld\n", chipset);
1742 seq_printf(m, "GFX power: %ld\n", gfx);
1743 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1744
1745 return 0;
1746}
1747
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001748static int i915_ring_freq_table(struct seq_file *m, void *unused)
1749{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001750 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001751 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001752 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001753 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001754 int gpu_freq, ia_freq;
1755
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001756 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001757 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001758 return 0;
1759 }
1760
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001761 intel_runtime_pm_get(dev_priv);
1762
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001763 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1764
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001765 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001766 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001767 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001768
Damien Lespiau267f0c92013-06-24 22:59:48 +01001769 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001770
Ben Widawskyb39fb292014-03-19 18:31:11 -07001771 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1772 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001773 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001774 ia_freq = gpu_freq;
1775 sandybridge_pcode_read(dev_priv,
1776 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1777 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001778 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001779 intel_gpu_freq(dev_priv, gpu_freq),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001780 ((ia_freq >> 0) & 0xff) * 100,
1781 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001782 }
1783
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001784 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001785
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001786out:
1787 intel_runtime_pm_put(dev_priv);
1788 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001789}
1790
Chris Wilson44834a62010-08-19 16:09:23 +01001791static int i915_opregion(struct seq_file *m, void *unused)
1792{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001793 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001794 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001795 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001796 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001797 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001798 int ret;
1799
Daniel Vetter0d38f002012-04-21 22:49:10 +02001800 if (data == NULL)
1801 return -ENOMEM;
1802
Chris Wilson44834a62010-08-19 16:09:23 +01001803 ret = mutex_lock_interruptible(&dev->struct_mutex);
1804 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001805 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001806
Daniel Vetter0d38f002012-04-21 22:49:10 +02001807 if (opregion->header) {
1808 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1809 seq_write(m, data, OPREGION_SIZE);
1810 }
Chris Wilson44834a62010-08-19 16:09:23 +01001811
1812 mutex_unlock(&dev->struct_mutex);
1813
Daniel Vetter0d38f002012-04-21 22:49:10 +02001814out:
1815 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001816 return 0;
1817}
1818
Chris Wilson37811fc2010-08-25 22:45:57 +01001819static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1820{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001821 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001822 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001823 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001824 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001825
Daniel Vetter4520f532013-10-09 09:18:51 +02001826#ifdef CONFIG_DRM_I915_FBDEV
1827 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001828
1829 ifbdev = dev_priv->fbdev;
1830 fb = to_intel_framebuffer(ifbdev->helper.fb);
1831
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001832 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 +01001833 fb->base.width,
1834 fb->base.height,
1835 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001836 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001837 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001838 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001839 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001840 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001841#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001842
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001843 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001844 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001845 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001846 continue;
1847
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001848 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 +01001849 fb->base.width,
1850 fb->base.height,
1851 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001852 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001853 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001854 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001855 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001856 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001857 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001858 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001859
1860 return 0;
1861}
1862
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001863static void describe_ctx_ringbuf(struct seq_file *m,
1864 struct intel_ringbuffer *ringbuf)
1865{
1866 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1867 ringbuf->space, ringbuf->head, ringbuf->tail,
1868 ringbuf->last_retired_head);
1869}
1870
Ben Widawskye76d3632011-03-19 18:14:29 -07001871static int i915_context_status(struct seq_file *m, void *unused)
1872{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001873 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001874 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001875 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001876 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001877 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001878 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001879
Daniel Vetterf3d28872014-05-29 23:23:08 +02001880 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001881 if (ret)
1882 return ret;
1883
Ben Widawskya33afea2013-09-17 21:12:45 -07001884 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001885 if (!i915.enable_execlists &&
1886 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001887 continue;
1888
Ben Widawskya33afea2013-09-17 21:12:45 -07001889 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001890 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001891 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001892 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001893 seq_printf(m, "(default context %s) ",
1894 ring->name);
1895 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001896
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001897 if (i915.enable_execlists) {
1898 seq_putc(m, '\n');
1899 for_each_ring(ring, dev_priv, i) {
1900 struct drm_i915_gem_object *ctx_obj =
1901 ctx->engine[i].state;
1902 struct intel_ringbuffer *ringbuf =
1903 ctx->engine[i].ringbuf;
1904
1905 seq_printf(m, "%s: ", ring->name);
1906 if (ctx_obj)
1907 describe_obj(m, ctx_obj);
1908 if (ringbuf)
1909 describe_ctx_ringbuf(m, ringbuf);
1910 seq_putc(m, '\n');
1911 }
1912 } else {
1913 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1914 }
1915
Ben Widawskya33afea2013-09-17 21:12:45 -07001916 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001917 }
1918
Daniel Vetterf3d28872014-05-29 23:23:08 +02001919 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001920
1921 return 0;
1922}
1923
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001924static void i915_dump_lrc_obj(struct seq_file *m,
1925 struct intel_engine_cs *ring,
1926 struct drm_i915_gem_object *ctx_obj)
1927{
1928 struct page *page;
1929 uint32_t *reg_state;
1930 int j;
1931 unsigned long ggtt_offset = 0;
1932
1933 if (ctx_obj == NULL) {
1934 seq_printf(m, "Context on %s with no gem object\n",
1935 ring->name);
1936 return;
1937 }
1938
1939 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1940 intel_execlists_ctx_id(ctx_obj));
1941
1942 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1943 seq_puts(m, "\tNot bound in GGTT\n");
1944 else
1945 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1946
1947 if (i915_gem_object_get_pages(ctx_obj)) {
1948 seq_puts(m, "\tFailed to get pages for context object\n");
1949 return;
1950 }
1951
1952 page = i915_gem_object_get_page(ctx_obj, 1);
1953 if (!WARN_ON(page == NULL)) {
1954 reg_state = kmap_atomic(page);
1955
1956 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
1957 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1958 ggtt_offset + 4096 + (j * 4),
1959 reg_state[j], reg_state[j + 1],
1960 reg_state[j + 2], reg_state[j + 3]);
1961 }
1962 kunmap_atomic(reg_state);
1963 }
1964
1965 seq_putc(m, '\n');
1966}
1967
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01001968static int i915_dump_lrc(struct seq_file *m, void *unused)
1969{
1970 struct drm_info_node *node = (struct drm_info_node *) m->private;
1971 struct drm_device *dev = node->minor->dev;
1972 struct drm_i915_private *dev_priv = dev->dev_private;
1973 struct intel_engine_cs *ring;
1974 struct intel_context *ctx;
1975 int ret, i;
1976
1977 if (!i915.enable_execlists) {
1978 seq_printf(m, "Logical Ring Contexts are disabled\n");
1979 return 0;
1980 }
1981
1982 ret = mutex_lock_interruptible(&dev->struct_mutex);
1983 if (ret)
1984 return ret;
1985
1986 list_for_each_entry(ctx, &dev_priv->context_list, link) {
1987 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001988 if (ring->default_context != ctx)
1989 i915_dump_lrc_obj(m, ring,
1990 ctx->engine[i].state);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01001991 }
1992 }
1993
1994 mutex_unlock(&dev->struct_mutex);
1995
1996 return 0;
1997}
1998
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001999static int i915_execlists(struct seq_file *m, void *data)
2000{
2001 struct drm_info_node *node = (struct drm_info_node *)m->private;
2002 struct drm_device *dev = node->minor->dev;
2003 struct drm_i915_private *dev_priv = dev->dev_private;
2004 struct intel_engine_cs *ring;
2005 u32 status_pointer;
2006 u8 read_pointer;
2007 u8 write_pointer;
2008 u32 status;
2009 u32 ctx_id;
2010 struct list_head *cursor;
2011 int ring_id, i;
2012 int ret;
2013
2014 if (!i915.enable_execlists) {
2015 seq_puts(m, "Logical Ring Contexts are disabled\n");
2016 return 0;
2017 }
2018
2019 ret = mutex_lock_interruptible(&dev->struct_mutex);
2020 if (ret)
2021 return ret;
2022
Michel Thierryfc0412e2014-10-16 16:13:38 +01002023 intel_runtime_pm_get(dev_priv);
2024
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002025 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002026 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002027 int count = 0;
2028 unsigned long flags;
2029
2030 seq_printf(m, "%s\n", ring->name);
2031
2032 status = I915_READ(RING_EXECLIST_STATUS(ring));
2033 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
2034 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2035 status, ctx_id);
2036
2037 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2038 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2039
2040 read_pointer = ring->next_context_status_buffer;
2041 write_pointer = status_pointer & 0x07;
2042 if (read_pointer > write_pointer)
2043 write_pointer += 6;
2044 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2045 read_pointer, write_pointer);
2046
2047 for (i = 0; i < 6; i++) {
2048 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
2049 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
2050
2051 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2052 i, status, ctx_id);
2053 }
2054
2055 spin_lock_irqsave(&ring->execlist_lock, flags);
2056 list_for_each(cursor, &ring->execlist_queue)
2057 count++;
2058 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002059 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002060 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2061
2062 seq_printf(m, "\t%d requests in queue\n", count);
2063 if (head_req) {
2064 struct drm_i915_gem_object *ctx_obj;
2065
Nick Hoath6d3d8272015-01-15 13:10:39 +00002066 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002067 seq_printf(m, "\tHead request id: %u\n",
2068 intel_execlists_ctx_id(ctx_obj));
2069 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002070 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002071 }
2072
2073 seq_putc(m, '\n');
2074 }
2075
Michel Thierryfc0412e2014-10-16 16:13:38 +01002076 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002077 mutex_unlock(&dev->struct_mutex);
2078
2079 return 0;
2080}
2081
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002082static const char *swizzle_string(unsigned swizzle)
2083{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002084 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002085 case I915_BIT_6_SWIZZLE_NONE:
2086 return "none";
2087 case I915_BIT_6_SWIZZLE_9:
2088 return "bit9";
2089 case I915_BIT_6_SWIZZLE_9_10:
2090 return "bit9/bit10";
2091 case I915_BIT_6_SWIZZLE_9_11:
2092 return "bit9/bit11";
2093 case I915_BIT_6_SWIZZLE_9_10_11:
2094 return "bit9/bit10/bit11";
2095 case I915_BIT_6_SWIZZLE_9_17:
2096 return "bit9/bit17";
2097 case I915_BIT_6_SWIZZLE_9_10_17:
2098 return "bit9/bit10/bit17";
2099 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002100 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002101 }
2102
2103 return "bug";
2104}
2105
2106static int i915_swizzle_info(struct seq_file *m, void *data)
2107{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002108 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002109 struct drm_device *dev = node->minor->dev;
2110 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002111 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002112
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002113 ret = mutex_lock_interruptible(&dev->struct_mutex);
2114 if (ret)
2115 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002116 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002117
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002118 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2119 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2120 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2121 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2122
2123 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2124 seq_printf(m, "DDC = 0x%08x\n",
2125 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002126 seq_printf(m, "DDC2 = 0x%08x\n",
2127 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002128 seq_printf(m, "C0DRB3 = 0x%04x\n",
2129 I915_READ16(C0DRB3));
2130 seq_printf(m, "C1DRB3 = 0x%04x\n",
2131 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002132 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002133 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2134 I915_READ(MAD_DIMM_C0));
2135 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2136 I915_READ(MAD_DIMM_C1));
2137 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2138 I915_READ(MAD_DIMM_C2));
2139 seq_printf(m, "TILECTL = 0x%08x\n",
2140 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002141 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002142 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2143 I915_READ(GAMTARBMODE));
2144 else
2145 seq_printf(m, "ARB_MODE = 0x%08x\n",
2146 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002147 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2148 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002149 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002150
2151 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2152 seq_puts(m, "L-shaped memory detected\n");
2153
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002154 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002155 mutex_unlock(&dev->struct_mutex);
2156
2157 return 0;
2158}
2159
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002160static int per_file_ctx(int id, void *ptr, void *data)
2161{
Oscar Mateo273497e2014-05-22 14:13:37 +01002162 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002163 struct seq_file *m = data;
Daniel Vetterae6c48062014-08-06 15:04:53 +02002164 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2165
2166 if (!ppgtt) {
2167 seq_printf(m, " no ppgtt for context %d\n",
2168 ctx->user_handle);
2169 return 0;
2170 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002171
Oscar Mateof83d6512014-05-22 14:13:38 +01002172 if (i915_gem_context_is_default(ctx))
2173 seq_puts(m, " default context:\n");
2174 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002175 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002176 ppgtt->debug_dump(ppgtt, m);
2177
2178 return 0;
2179}
2180
Ben Widawsky77df6772013-11-02 21:07:30 -07002181static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002182{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002183 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002184 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002185 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2186 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002187
Ben Widawsky77df6772013-11-02 21:07:30 -07002188 if (!ppgtt)
2189 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002190
Ben Widawsky77df6772013-11-02 21:07:30 -07002191 for_each_ring(ring, dev_priv, unused) {
2192 seq_printf(m, "%s\n", ring->name);
2193 for (i = 0; i < 4; i++) {
2194 u32 offset = 0x270 + i * 8;
2195 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2196 pdp <<= 32;
2197 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002198 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002199 }
2200 }
2201}
2202
2203static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2204{
2205 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002206 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002207 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002208 int i;
2209
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002210 if (INTEL_INFO(dev)->gen == 6)
2211 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2212
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002213 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002214 seq_printf(m, "%s\n", ring->name);
2215 if (INTEL_INFO(dev)->gen == 7)
2216 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2217 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2218 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2219 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2220 }
2221 if (dev_priv->mm.aliasing_ppgtt) {
2222 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2223
Damien Lespiau267f0c92013-06-24 22:59:48 +01002224 seq_puts(m, "aliasing PPGTT:\n");
Ben Widawsky7324cc02015-02-24 16:22:35 +00002225 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002226
Ben Widawsky87d60b62013-12-06 14:11:29 -08002227 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c48062014-08-06 15:04:53 +02002228 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002229
2230 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2231 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002232
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002233 seq_printf(m, "proc: %s\n",
2234 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002235 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002236 }
2237 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002238}
2239
2240static int i915_ppgtt_info(struct seq_file *m, void *data)
2241{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002242 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002243 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002244 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002245
2246 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2247 if (ret)
2248 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002249 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002250
2251 if (INTEL_INFO(dev)->gen >= 8)
2252 gen8_ppgtt_info(m, dev);
2253 else if (INTEL_INFO(dev)->gen >= 6)
2254 gen6_ppgtt_info(m, dev);
2255
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002256 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002257 mutex_unlock(&dev->struct_mutex);
2258
2259 return 0;
2260}
2261
Chris Wilson1854d5c2015-04-07 16:20:32 +01002262static int i915_rps_boost_info(struct seq_file *m, void *data)
2263{
2264 struct drm_info_node *node = m->private;
2265 struct drm_device *dev = node->minor->dev;
2266 struct drm_i915_private *dev_priv = dev->dev_private;
2267 struct drm_file *file;
2268 int ret;
2269
2270 ret = mutex_lock_interruptible(&dev->struct_mutex);
2271 if (ret)
2272 return ret;
2273
2274 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
2275 if (ret)
2276 goto unlock;
2277
2278 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2279 struct drm_i915_file_private *file_priv = file->driver_priv;
2280 struct task_struct *task;
2281
2282 rcu_read_lock();
2283 task = pid_task(file->pid, PIDTYPE_PID);
2284 seq_printf(m, "%s [%d]: %d boosts%s\n",
2285 task ? task->comm : "<unknown>",
2286 task ? task->pid : -1,
2287 file_priv->rps_boosts,
2288 list_empty(&file_priv->rps_boost) ? "" : ", active");
2289 rcu_read_unlock();
2290 }
2291 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
2292
2293 mutex_unlock(&dev_priv->rps.hw_lock);
2294unlock:
2295 mutex_unlock(&dev->struct_mutex);
2296
2297 return ret;
2298}
2299
Ben Widawsky63573eb2013-07-04 11:02:07 -07002300static int i915_llc(struct seq_file *m, void *data)
2301{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002302 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002303 struct drm_device *dev = node->minor->dev;
2304 struct drm_i915_private *dev_priv = dev->dev_private;
2305
2306 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2307 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2308 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2309
2310 return 0;
2311}
2312
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002313static int i915_edp_psr_status(struct seq_file *m, void *data)
2314{
2315 struct drm_info_node *node = m->private;
2316 struct drm_device *dev = node->minor->dev;
2317 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002318 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002319 u32 stat[3];
2320 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002321 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002322
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002323 if (!HAS_PSR(dev)) {
2324 seq_puts(m, "PSR not supported\n");
2325 return 0;
2326 }
2327
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002328 intel_runtime_pm_get(dev_priv);
2329
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002330 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002331 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2332 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002333 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002334 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002335 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2336 dev_priv->psr.busy_frontbuffer_bits);
2337 seq_printf(m, "Re-enable work scheduled: %s\n",
2338 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002339
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002340 if (HAS_DDI(dev))
2341 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2342 else {
2343 for_each_pipe(dev_priv, pipe) {
2344 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2345 VLV_EDP_PSR_CURR_STATE_MASK;
2346 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2347 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2348 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002349 }
2350 }
2351 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002352
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002353 if (!HAS_DDI(dev))
2354 for_each_pipe(dev_priv, pipe) {
2355 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2356 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2357 seq_printf(m, " pipe %c", pipe_name(pipe));
2358 }
2359 seq_puts(m, "\n");
2360
Rodrigo Vivifb495812015-01-12 10:14:33 -08002361 seq_printf(m, "Link standby: %s\n",
2362 yesno((bool)dev_priv->psr.link_standby));
2363
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002364 /* CHV PSR has no kind of performance counter */
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002365 if (HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002366 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2367 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002368
2369 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2370 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002371 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002372
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002373 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002374 return 0;
2375}
2376
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002377static int i915_sink_crc(struct seq_file *m, void *data)
2378{
2379 struct drm_info_node *node = m->private;
2380 struct drm_device *dev = node->minor->dev;
2381 struct intel_encoder *encoder;
2382 struct intel_connector *connector;
2383 struct intel_dp *intel_dp = NULL;
2384 int ret;
2385 u8 crc[6];
2386
2387 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002388 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002389
2390 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2391 continue;
2392
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002393 if (!connector->base.encoder)
2394 continue;
2395
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002396 encoder = to_intel_encoder(connector->base.encoder);
2397 if (encoder->type != INTEL_OUTPUT_EDP)
2398 continue;
2399
2400 intel_dp = enc_to_intel_dp(&encoder->base);
2401
2402 ret = intel_dp_sink_crc(intel_dp, crc);
2403 if (ret)
2404 goto out;
2405
2406 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2407 crc[0], crc[1], crc[2],
2408 crc[3], crc[4], crc[5]);
2409 goto out;
2410 }
2411 ret = -ENODEV;
2412out:
2413 drm_modeset_unlock_all(dev);
2414 return ret;
2415}
2416
Jesse Barnesec013e72013-08-20 10:29:23 +01002417static int i915_energy_uJ(struct seq_file *m, void *data)
2418{
2419 struct drm_info_node *node = m->private;
2420 struct drm_device *dev = node->minor->dev;
2421 struct drm_i915_private *dev_priv = dev->dev_private;
2422 u64 power;
2423 u32 units;
2424
2425 if (INTEL_INFO(dev)->gen < 6)
2426 return -ENODEV;
2427
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002428 intel_runtime_pm_get(dev_priv);
2429
Jesse Barnesec013e72013-08-20 10:29:23 +01002430 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2431 power = (power & 0x1f00) >> 8;
2432 units = 1000000 / (1 << power); /* convert to uJ */
2433 power = I915_READ(MCH_SECP_NRG_STTS);
2434 power *= units;
2435
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002436 intel_runtime_pm_put(dev_priv);
2437
Jesse Barnesec013e72013-08-20 10:29:23 +01002438 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002439
2440 return 0;
2441}
2442
2443static int i915_pc8_status(struct seq_file *m, void *unused)
2444{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002445 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002446 struct drm_device *dev = node->minor->dev;
2447 struct drm_i915_private *dev_priv = dev->dev_private;
2448
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002449 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002450 seq_puts(m, "not supported\n");
2451 return 0;
2452 }
2453
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002454 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002455 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002456 yesno(!intel_irqs_enabled(dev_priv)));
Paulo Zanoni371db662013-08-19 13:18:10 -03002457
Jesse Barnesec013e72013-08-20 10:29:23 +01002458 return 0;
2459}
2460
Imre Deak1da51582013-11-25 17:15:35 +02002461static const char *power_domain_str(enum intel_display_power_domain domain)
2462{
2463 switch (domain) {
2464 case POWER_DOMAIN_PIPE_A:
2465 return "PIPE_A";
2466 case POWER_DOMAIN_PIPE_B:
2467 return "PIPE_B";
2468 case POWER_DOMAIN_PIPE_C:
2469 return "PIPE_C";
2470 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2471 return "PIPE_A_PANEL_FITTER";
2472 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2473 return "PIPE_B_PANEL_FITTER";
2474 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2475 return "PIPE_C_PANEL_FITTER";
2476 case POWER_DOMAIN_TRANSCODER_A:
2477 return "TRANSCODER_A";
2478 case POWER_DOMAIN_TRANSCODER_B:
2479 return "TRANSCODER_B";
2480 case POWER_DOMAIN_TRANSCODER_C:
2481 return "TRANSCODER_C";
2482 case POWER_DOMAIN_TRANSCODER_EDP:
2483 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002484 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2485 return "PORT_DDI_A_2_LANES";
2486 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2487 return "PORT_DDI_A_4_LANES";
2488 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2489 return "PORT_DDI_B_2_LANES";
2490 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2491 return "PORT_DDI_B_4_LANES";
2492 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2493 return "PORT_DDI_C_2_LANES";
2494 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2495 return "PORT_DDI_C_4_LANES";
2496 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2497 return "PORT_DDI_D_2_LANES";
2498 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2499 return "PORT_DDI_D_4_LANES";
2500 case POWER_DOMAIN_PORT_DSI:
2501 return "PORT_DSI";
2502 case POWER_DOMAIN_PORT_CRT:
2503 return "PORT_CRT";
2504 case POWER_DOMAIN_PORT_OTHER:
2505 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002506 case POWER_DOMAIN_VGA:
2507 return "VGA";
2508 case POWER_DOMAIN_AUDIO:
2509 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002510 case POWER_DOMAIN_PLLS:
2511 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002512 case POWER_DOMAIN_AUX_A:
2513 return "AUX_A";
2514 case POWER_DOMAIN_AUX_B:
2515 return "AUX_B";
2516 case POWER_DOMAIN_AUX_C:
2517 return "AUX_C";
2518 case POWER_DOMAIN_AUX_D:
2519 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002520 case POWER_DOMAIN_INIT:
2521 return "INIT";
2522 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002523 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002524 return "?";
2525 }
2526}
2527
2528static int i915_power_domain_info(struct seq_file *m, void *unused)
2529{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002530 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002531 struct drm_device *dev = node->minor->dev;
2532 struct drm_i915_private *dev_priv = dev->dev_private;
2533 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2534 int i;
2535
2536 mutex_lock(&power_domains->lock);
2537
2538 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2539 for (i = 0; i < power_domains->power_well_count; i++) {
2540 struct i915_power_well *power_well;
2541 enum intel_display_power_domain power_domain;
2542
2543 power_well = &power_domains->power_wells[i];
2544 seq_printf(m, "%-25s %d\n", power_well->name,
2545 power_well->count);
2546
2547 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2548 power_domain++) {
2549 if (!(BIT(power_domain) & power_well->domains))
2550 continue;
2551
2552 seq_printf(m, " %-23s %d\n",
2553 power_domain_str(power_domain),
2554 power_domains->domain_use_count[power_domain]);
2555 }
2556 }
2557
2558 mutex_unlock(&power_domains->lock);
2559
2560 return 0;
2561}
2562
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002563static void intel_seq_print_mode(struct seq_file *m, int tabs,
2564 struct drm_display_mode *mode)
2565{
2566 int i;
2567
2568 for (i = 0; i < tabs; i++)
2569 seq_putc(m, '\t');
2570
2571 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",
2572 mode->base.id, mode->name,
2573 mode->vrefresh, mode->clock,
2574 mode->hdisplay, mode->hsync_start,
2575 mode->hsync_end, mode->htotal,
2576 mode->vdisplay, mode->vsync_start,
2577 mode->vsync_end, mode->vtotal,
2578 mode->type, mode->flags);
2579}
2580
2581static void intel_encoder_info(struct seq_file *m,
2582 struct intel_crtc *intel_crtc,
2583 struct intel_encoder *intel_encoder)
2584{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002585 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002586 struct drm_device *dev = node->minor->dev;
2587 struct drm_crtc *crtc = &intel_crtc->base;
2588 struct intel_connector *intel_connector;
2589 struct drm_encoder *encoder;
2590
2591 encoder = &intel_encoder->base;
2592 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002593 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002594 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2595 struct drm_connector *connector = &intel_connector->base;
2596 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2597 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002598 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002599 drm_get_connector_status_name(connector->status));
2600 if (connector->status == connector_status_connected) {
2601 struct drm_display_mode *mode = &crtc->mode;
2602 seq_printf(m, ", mode:\n");
2603 intel_seq_print_mode(m, 2, mode);
2604 } else {
2605 seq_putc(m, '\n');
2606 }
2607 }
2608}
2609
2610static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2611{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002612 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002613 struct drm_device *dev = node->minor->dev;
2614 struct drm_crtc *crtc = &intel_crtc->base;
2615 struct intel_encoder *intel_encoder;
2616
Matt Roper5aa8a932014-06-16 10:12:55 -07002617 if (crtc->primary->fb)
2618 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2619 crtc->primary->fb->base.id, crtc->x, crtc->y,
2620 crtc->primary->fb->width, crtc->primary->fb->height);
2621 else
2622 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002623 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2624 intel_encoder_info(m, intel_crtc, intel_encoder);
2625}
2626
2627static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2628{
2629 struct drm_display_mode *mode = panel->fixed_mode;
2630
2631 seq_printf(m, "\tfixed mode:\n");
2632 intel_seq_print_mode(m, 2, mode);
2633}
2634
2635static void intel_dp_info(struct seq_file *m,
2636 struct intel_connector *intel_connector)
2637{
2638 struct intel_encoder *intel_encoder = intel_connector->encoder;
2639 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2640
2641 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2642 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2643 "no");
2644 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2645 intel_panel_info(m, &intel_connector->panel);
2646}
2647
2648static void intel_hdmi_info(struct seq_file *m,
2649 struct intel_connector *intel_connector)
2650{
2651 struct intel_encoder *intel_encoder = intel_connector->encoder;
2652 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2653
2654 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2655 "no");
2656}
2657
2658static void intel_lvds_info(struct seq_file *m,
2659 struct intel_connector *intel_connector)
2660{
2661 intel_panel_info(m, &intel_connector->panel);
2662}
2663
2664static void intel_connector_info(struct seq_file *m,
2665 struct drm_connector *connector)
2666{
2667 struct intel_connector *intel_connector = to_intel_connector(connector);
2668 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002669 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002670
2671 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002672 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002673 drm_get_connector_status_name(connector->status));
2674 if (connector->status == connector_status_connected) {
2675 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2676 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2677 connector->display_info.width_mm,
2678 connector->display_info.height_mm);
2679 seq_printf(m, "\tsubpixel order: %s\n",
2680 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2681 seq_printf(m, "\tCEA rev: %d\n",
2682 connector->display_info.cea_rev);
2683 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002684 if (intel_encoder) {
2685 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2686 intel_encoder->type == INTEL_OUTPUT_EDP)
2687 intel_dp_info(m, intel_connector);
2688 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2689 intel_hdmi_info(m, intel_connector);
2690 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2691 intel_lvds_info(m, intel_connector);
2692 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002693
Jesse Barnesf103fc72014-02-20 12:39:57 -08002694 seq_printf(m, "\tmodes:\n");
2695 list_for_each_entry(mode, &connector->modes, head)
2696 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002697}
2698
Chris Wilson065f2ec22014-03-12 09:13:13 +00002699static bool cursor_active(struct drm_device *dev, int pipe)
2700{
2701 struct drm_i915_private *dev_priv = dev->dev_private;
2702 u32 state;
2703
2704 if (IS_845G(dev) || IS_I865G(dev))
2705 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002706 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002707 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002708
2709 return state;
2710}
2711
2712static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2713{
2714 struct drm_i915_private *dev_priv = dev->dev_private;
2715 u32 pos;
2716
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002717 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec22014-03-12 09:13:13 +00002718
2719 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2720 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2721 *x = -*x;
2722
2723 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2724 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2725 *y = -*y;
2726
2727 return cursor_active(dev, pipe);
2728}
2729
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002730static int i915_display_info(struct seq_file *m, void *unused)
2731{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002732 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002733 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002734 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec22014-03-12 09:13:13 +00002735 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002736 struct drm_connector *connector;
2737
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002738 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002739 drm_modeset_lock_all(dev);
2740 seq_printf(m, "CRTC info\n");
2741 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002742 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002743 bool active;
2744 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002745
Chris Wilson57127ef2014-07-04 08:20:11 +01002746 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec22014-03-12 09:13:13 +00002747 crtc->base.base.id, pipe_name(crtc->pipe),
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02002748 yesno(crtc->active), crtc->config->pipe_src_w,
2749 crtc->config->pipe_src_h);
Paulo Zanonia23dc652014-04-01 14:55:11 -03002750 if (crtc->active) {
Chris Wilson065f2ec22014-03-12 09:13:13 +00002751 intel_crtc_info(m, crtc);
2752
Paulo Zanonia23dc652014-04-01 14:55:11 -03002753 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002754 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 +03002755 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08002756 x, y, crtc->base.cursor->state->crtc_w,
2757 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01002758 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002759 }
Daniel Vettercace8412014-05-22 17:56:31 +02002760
2761 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2762 yesno(!crtc->cpu_fifo_underrun_disabled),
2763 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002764 }
2765
2766 seq_printf(m, "\n");
2767 seq_printf(m, "Connector info\n");
2768 seq_printf(m, "--------------\n");
2769 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2770 intel_connector_info(m, connector);
2771 }
2772 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002773 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002774
2775 return 0;
2776}
2777
Ben Widawskye04934c2014-06-30 09:53:42 -07002778static int i915_semaphore_status(struct seq_file *m, void *unused)
2779{
2780 struct drm_info_node *node = (struct drm_info_node *) m->private;
2781 struct drm_device *dev = node->minor->dev;
2782 struct drm_i915_private *dev_priv = dev->dev_private;
2783 struct intel_engine_cs *ring;
2784 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2785 int i, j, ret;
2786
2787 if (!i915_semaphore_is_enabled(dev)) {
2788 seq_puts(m, "Semaphores are disabled\n");
2789 return 0;
2790 }
2791
2792 ret = mutex_lock_interruptible(&dev->struct_mutex);
2793 if (ret)
2794 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002795 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002796
2797 if (IS_BROADWELL(dev)) {
2798 struct page *page;
2799 uint64_t *seqno;
2800
2801 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2802
2803 seqno = (uint64_t *)kmap_atomic(page);
2804 for_each_ring(ring, dev_priv, i) {
2805 uint64_t offset;
2806
2807 seq_printf(m, "%s\n", ring->name);
2808
2809 seq_puts(m, " Last signal:");
2810 for (j = 0; j < num_rings; j++) {
2811 offset = i * I915_NUM_RINGS + j;
2812 seq_printf(m, "0x%08llx (0x%02llx) ",
2813 seqno[offset], offset * 8);
2814 }
2815 seq_putc(m, '\n');
2816
2817 seq_puts(m, " Last wait: ");
2818 for (j = 0; j < num_rings; j++) {
2819 offset = i + (j * I915_NUM_RINGS);
2820 seq_printf(m, "0x%08llx (0x%02llx) ",
2821 seqno[offset], offset * 8);
2822 }
2823 seq_putc(m, '\n');
2824
2825 }
2826 kunmap_atomic(seqno);
2827 } else {
2828 seq_puts(m, " Last signal:");
2829 for_each_ring(ring, dev_priv, i)
2830 for (j = 0; j < num_rings; j++)
2831 seq_printf(m, "0x%08x\n",
2832 I915_READ(ring->semaphore.mbox.signal[j]));
2833 seq_putc(m, '\n');
2834 }
2835
2836 seq_puts(m, "\nSync seqno:\n");
2837 for_each_ring(ring, dev_priv, i) {
2838 for (j = 0; j < num_rings; j++) {
2839 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2840 }
2841 seq_putc(m, '\n');
2842 }
2843 seq_putc(m, '\n');
2844
Paulo Zanoni03872062014-07-09 14:31:57 -03002845 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002846 mutex_unlock(&dev->struct_mutex);
2847 return 0;
2848}
2849
Daniel Vetter728e29d2014-06-25 22:01:53 +03002850static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2851{
2852 struct drm_info_node *node = (struct drm_info_node *) m->private;
2853 struct drm_device *dev = node->minor->dev;
2854 struct drm_i915_private *dev_priv = dev->dev_private;
2855 int i;
2856
2857 drm_modeset_lock_all(dev);
2858 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2859 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2860
2861 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002862 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002863 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03002864 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002865 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2866 seq_printf(m, " dpll_md: 0x%08x\n",
2867 pll->config.hw_state.dpll_md);
2868 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2869 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2870 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002871 }
2872 drm_modeset_unlock_all(dev);
2873
2874 return 0;
2875}
2876
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01002877static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01002878{
2879 int i;
2880 int ret;
2881 struct drm_info_node *node = (struct drm_info_node *) m->private;
2882 struct drm_device *dev = node->minor->dev;
2883 struct drm_i915_private *dev_priv = dev->dev_private;
2884
Arun Siluvery888b5992014-08-26 14:44:51 +01002885 ret = mutex_lock_interruptible(&dev->struct_mutex);
2886 if (ret)
2887 return ret;
2888
2889 intel_runtime_pm_get(dev_priv);
2890
Mika Kuoppala72253422014-10-07 17:21:26 +03002891 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
2892 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002893 u32 addr, mask, value, read;
2894 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01002895
Mika Kuoppala72253422014-10-07 17:21:26 +03002896 addr = dev_priv->workarounds.reg[i].addr;
2897 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002898 value = dev_priv->workarounds.reg[i].value;
2899 read = I915_READ(addr);
2900 ok = (value & mask) == (read & mask);
2901 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
2902 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01002903 }
2904
2905 intel_runtime_pm_put(dev_priv);
2906 mutex_unlock(&dev->struct_mutex);
2907
2908 return 0;
2909}
2910
Damien Lespiauc5511e42014-11-04 17:06:51 +00002911static int i915_ddb_info(struct seq_file *m, void *unused)
2912{
2913 struct drm_info_node *node = m->private;
2914 struct drm_device *dev = node->minor->dev;
2915 struct drm_i915_private *dev_priv = dev->dev_private;
2916 struct skl_ddb_allocation *ddb;
2917 struct skl_ddb_entry *entry;
2918 enum pipe pipe;
2919 int plane;
2920
Damien Lespiau2fcffe12014-12-03 17:33:24 +00002921 if (INTEL_INFO(dev)->gen < 9)
2922 return 0;
2923
Damien Lespiauc5511e42014-11-04 17:06:51 +00002924 drm_modeset_lock_all(dev);
2925
2926 ddb = &dev_priv->wm.skl_hw.ddb;
2927
2928 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
2929
2930 for_each_pipe(dev_priv, pipe) {
2931 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
2932
Damien Lespiaudd740782015-02-28 14:54:08 +00002933 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00002934 entry = &ddb->plane[pipe][plane];
2935 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
2936 entry->start, entry->end,
2937 skl_ddb_entry_size(entry));
2938 }
2939
2940 entry = &ddb->cursor[pipe];
2941 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
2942 entry->end, skl_ddb_entry_size(entry));
2943 }
2944
2945 drm_modeset_unlock_all(dev);
2946
2947 return 0;
2948}
2949
Vandana Kannana54746e2015-03-03 20:53:10 +05302950static void drrs_status_per_crtc(struct seq_file *m,
2951 struct drm_device *dev, struct intel_crtc *intel_crtc)
2952{
2953 struct intel_encoder *intel_encoder;
2954 struct drm_i915_private *dev_priv = dev->dev_private;
2955 struct i915_drrs *drrs = &dev_priv->drrs;
2956 int vrefresh = 0;
2957
2958 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
2959 /* Encoder connected on this CRTC */
2960 switch (intel_encoder->type) {
2961 case INTEL_OUTPUT_EDP:
2962 seq_puts(m, "eDP:\n");
2963 break;
2964 case INTEL_OUTPUT_DSI:
2965 seq_puts(m, "DSI:\n");
2966 break;
2967 case INTEL_OUTPUT_HDMI:
2968 seq_puts(m, "HDMI:\n");
2969 break;
2970 case INTEL_OUTPUT_DISPLAYPORT:
2971 seq_puts(m, "DP:\n");
2972 break;
2973 default:
2974 seq_printf(m, "Other encoder (id=%d).\n",
2975 intel_encoder->type);
2976 return;
2977 }
2978 }
2979
2980 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
2981 seq_puts(m, "\tVBT: DRRS_type: Static");
2982 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
2983 seq_puts(m, "\tVBT: DRRS_type: Seamless");
2984 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
2985 seq_puts(m, "\tVBT: DRRS_type: None");
2986 else
2987 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
2988
2989 seq_puts(m, "\n\n");
2990
2991 if (intel_crtc->config->has_drrs) {
2992 struct intel_panel *panel;
2993
2994 mutex_lock(&drrs->mutex);
2995 /* DRRS Supported */
2996 seq_puts(m, "\tDRRS Supported: Yes\n");
2997
2998 /* disable_drrs() will make drrs->dp NULL */
2999 if (!drrs->dp) {
3000 seq_puts(m, "Idleness DRRS: Disabled");
3001 mutex_unlock(&drrs->mutex);
3002 return;
3003 }
3004
3005 panel = &drrs->dp->attached_connector->panel;
3006 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3007 drrs->busy_frontbuffer_bits);
3008
3009 seq_puts(m, "\n\t\t");
3010 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3011 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3012 vrefresh = panel->fixed_mode->vrefresh;
3013 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3014 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3015 vrefresh = panel->downclock_mode->vrefresh;
3016 } else {
3017 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3018 drrs->refresh_rate_type);
3019 mutex_unlock(&drrs->mutex);
3020 return;
3021 }
3022 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3023
3024 seq_puts(m, "\n\t\t");
3025 mutex_unlock(&drrs->mutex);
3026 } else {
3027 /* DRRS not supported. Print the VBT parameter*/
3028 seq_puts(m, "\tDRRS Supported : No");
3029 }
3030 seq_puts(m, "\n");
3031}
3032
3033static int i915_drrs_status(struct seq_file *m, void *unused)
3034{
3035 struct drm_info_node *node = m->private;
3036 struct drm_device *dev = node->minor->dev;
3037 struct intel_crtc *intel_crtc;
3038 int active_crtc_cnt = 0;
3039
3040 for_each_intel_crtc(dev, intel_crtc) {
3041 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3042
3043 if (intel_crtc->active) {
3044 active_crtc_cnt++;
3045 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3046
3047 drrs_status_per_crtc(m, dev, intel_crtc);
3048 }
3049
3050 drm_modeset_unlock(&intel_crtc->base.mutex);
3051 }
3052
3053 if (!active_crtc_cnt)
3054 seq_puts(m, "No active crtc found\n");
3055
3056 return 0;
3057}
3058
Damien Lespiau07144422013-10-15 18:55:40 +01003059struct pipe_crc_info {
3060 const char *name;
3061 struct drm_device *dev;
3062 enum pipe pipe;
3063};
3064
Dave Airlie11bed952014-05-12 15:22:27 +10003065static int i915_dp_mst_info(struct seq_file *m, void *unused)
3066{
3067 struct drm_info_node *node = (struct drm_info_node *) m->private;
3068 struct drm_device *dev = node->minor->dev;
3069 struct drm_encoder *encoder;
3070 struct intel_encoder *intel_encoder;
3071 struct intel_digital_port *intel_dig_port;
3072 drm_modeset_lock_all(dev);
3073 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3074 intel_encoder = to_intel_encoder(encoder);
3075 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3076 continue;
3077 intel_dig_port = enc_to_dig_port(encoder);
3078 if (!intel_dig_port->dp.can_mst)
3079 continue;
3080
3081 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3082 }
3083 drm_modeset_unlock_all(dev);
3084 return 0;
3085}
3086
Damien Lespiau07144422013-10-15 18:55:40 +01003087static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003088{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003089 struct pipe_crc_info *info = inode->i_private;
3090 struct drm_i915_private *dev_priv = info->dev->dev_private;
3091 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3092
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003093 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3094 return -ENODEV;
3095
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003096 spin_lock_irq(&pipe_crc->lock);
3097
3098 if (pipe_crc->opened) {
3099 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003100 return -EBUSY; /* already open */
3101 }
3102
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003103 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003104 filep->private_data = inode->i_private;
3105
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003106 spin_unlock_irq(&pipe_crc->lock);
3107
Damien Lespiau07144422013-10-15 18:55:40 +01003108 return 0;
3109}
3110
3111static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3112{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003113 struct pipe_crc_info *info = inode->i_private;
3114 struct drm_i915_private *dev_priv = info->dev->dev_private;
3115 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3116
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003117 spin_lock_irq(&pipe_crc->lock);
3118 pipe_crc->opened = false;
3119 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003120
Damien Lespiau07144422013-10-15 18:55:40 +01003121 return 0;
3122}
3123
3124/* (6 fields, 8 chars each, space separated (5) + '\n') */
3125#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3126/* account for \'0' */
3127#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3128
3129static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3130{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003131 assert_spin_locked(&pipe_crc->lock);
3132 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3133 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003134}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003135
Damien Lespiau07144422013-10-15 18:55:40 +01003136static ssize_t
3137i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3138 loff_t *pos)
3139{
3140 struct pipe_crc_info *info = filep->private_data;
3141 struct drm_device *dev = info->dev;
3142 struct drm_i915_private *dev_priv = dev->dev_private;
3143 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3144 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003145 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003146 ssize_t bytes_read;
3147
3148 /*
3149 * Don't allow user space to provide buffers not big enough to hold
3150 * a line of data.
3151 */
3152 if (count < PIPE_CRC_LINE_LEN)
3153 return -EINVAL;
3154
3155 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3156 return 0;
3157
3158 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003159 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003160 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003161 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003162
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003163 if (filep->f_flags & O_NONBLOCK) {
3164 spin_unlock_irq(&pipe_crc->lock);
3165 return -EAGAIN;
3166 }
3167
3168 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3169 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3170 if (ret) {
3171 spin_unlock_irq(&pipe_crc->lock);
3172 return ret;
3173 }
Damien Lespiau07144422013-10-15 18:55:40 +01003174 }
3175
3176 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003177 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003178
Damien Lespiau07144422013-10-15 18:55:40 +01003179 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003180 while (n_entries > 0) {
3181 struct intel_pipe_crc_entry *entry =
3182 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003183 int ret;
3184
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003185 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3186 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3187 break;
3188
3189 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3190 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3191
Damien Lespiau07144422013-10-15 18:55:40 +01003192 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3193 "%8u %8x %8x %8x %8x %8x\n",
3194 entry->frame, entry->crc[0],
3195 entry->crc[1], entry->crc[2],
3196 entry->crc[3], entry->crc[4]);
3197
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003198 spin_unlock_irq(&pipe_crc->lock);
3199
3200 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003201 if (ret == PIPE_CRC_LINE_LEN)
3202 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003203
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003204 user_buf += PIPE_CRC_LINE_LEN;
3205 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003206
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003207 spin_lock_irq(&pipe_crc->lock);
3208 }
3209
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003210 spin_unlock_irq(&pipe_crc->lock);
3211
Damien Lespiau07144422013-10-15 18:55:40 +01003212 return bytes_read;
3213}
3214
3215static const struct file_operations i915_pipe_crc_fops = {
3216 .owner = THIS_MODULE,
3217 .open = i915_pipe_crc_open,
3218 .read = i915_pipe_crc_read,
3219 .release = i915_pipe_crc_release,
3220};
3221
3222static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3223 {
3224 .name = "i915_pipe_A_crc",
3225 .pipe = PIPE_A,
3226 },
3227 {
3228 .name = "i915_pipe_B_crc",
3229 .pipe = PIPE_B,
3230 },
3231 {
3232 .name = "i915_pipe_C_crc",
3233 .pipe = PIPE_C,
3234 },
3235};
3236
3237static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3238 enum pipe pipe)
3239{
3240 struct drm_device *dev = minor->dev;
3241 struct dentry *ent;
3242 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3243
3244 info->dev = dev;
3245 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3246 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003247 if (!ent)
3248 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003249
3250 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003251}
3252
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003253static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003254 "none",
3255 "plane1",
3256 "plane2",
3257 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003258 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003259 "TV",
3260 "DP-B",
3261 "DP-C",
3262 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003263 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003264};
3265
3266static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3267{
3268 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3269 return pipe_crc_sources[source];
3270}
3271
Damien Lespiaubd9db022013-10-15 18:55:36 +01003272static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003273{
3274 struct drm_device *dev = m->private;
3275 struct drm_i915_private *dev_priv = dev->dev_private;
3276 int i;
3277
3278 for (i = 0; i < I915_MAX_PIPES; i++)
3279 seq_printf(m, "%c %s\n", pipe_name(i),
3280 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3281
3282 return 0;
3283}
3284
Damien Lespiaubd9db022013-10-15 18:55:36 +01003285static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003286{
3287 struct drm_device *dev = inode->i_private;
3288
Damien Lespiaubd9db022013-10-15 18:55:36 +01003289 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003290}
3291
Daniel Vetter46a19182013-11-01 10:50:20 +01003292static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003293 uint32_t *val)
3294{
Daniel Vetter46a19182013-11-01 10:50:20 +01003295 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3296 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3297
3298 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003299 case INTEL_PIPE_CRC_SOURCE_PIPE:
3300 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3301 break;
3302 case INTEL_PIPE_CRC_SOURCE_NONE:
3303 *val = 0;
3304 break;
3305 default:
3306 return -EINVAL;
3307 }
3308
3309 return 0;
3310}
3311
Daniel Vetter46a19182013-11-01 10:50:20 +01003312static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3313 enum intel_pipe_crc_source *source)
3314{
3315 struct intel_encoder *encoder;
3316 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003317 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003318 int ret = 0;
3319
3320 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3321
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003322 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003323 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003324 if (!encoder->base.crtc)
3325 continue;
3326
3327 crtc = to_intel_crtc(encoder->base.crtc);
3328
3329 if (crtc->pipe != pipe)
3330 continue;
3331
3332 switch (encoder->type) {
3333 case INTEL_OUTPUT_TVOUT:
3334 *source = INTEL_PIPE_CRC_SOURCE_TV;
3335 break;
3336 case INTEL_OUTPUT_DISPLAYPORT:
3337 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003338 dig_port = enc_to_dig_port(&encoder->base);
3339 switch (dig_port->port) {
3340 case PORT_B:
3341 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3342 break;
3343 case PORT_C:
3344 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3345 break;
3346 case PORT_D:
3347 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3348 break;
3349 default:
3350 WARN(1, "nonexisting DP port %c\n",
3351 port_name(dig_port->port));
3352 break;
3353 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003354 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003355 default:
3356 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003357 }
3358 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003359 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003360
3361 return ret;
3362}
3363
3364static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3365 enum pipe pipe,
3366 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003367 uint32_t *val)
3368{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003369 struct drm_i915_private *dev_priv = dev->dev_private;
3370 bool need_stable_symbols = false;
3371
Daniel Vetter46a19182013-11-01 10:50:20 +01003372 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3373 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3374 if (ret)
3375 return ret;
3376 }
3377
3378 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003379 case INTEL_PIPE_CRC_SOURCE_PIPE:
3380 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3381 break;
3382 case INTEL_PIPE_CRC_SOURCE_DP_B:
3383 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003384 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003385 break;
3386 case INTEL_PIPE_CRC_SOURCE_DP_C:
3387 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003388 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003389 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003390 case INTEL_PIPE_CRC_SOURCE_DP_D:
3391 if (!IS_CHERRYVIEW(dev))
3392 return -EINVAL;
3393 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3394 need_stable_symbols = true;
3395 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003396 case INTEL_PIPE_CRC_SOURCE_NONE:
3397 *val = 0;
3398 break;
3399 default:
3400 return -EINVAL;
3401 }
3402
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003403 /*
3404 * When the pipe CRC tap point is after the transcoders we need
3405 * to tweak symbol-level features to produce a deterministic series of
3406 * symbols for a given frame. We need to reset those features only once
3407 * a frame (instead of every nth symbol):
3408 * - DC-balance: used to ensure a better clock recovery from the data
3409 * link (SDVO)
3410 * - DisplayPort scrambling: used for EMI reduction
3411 */
3412 if (need_stable_symbols) {
3413 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3414
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003415 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003416 switch (pipe) {
3417 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003418 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003419 break;
3420 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003421 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003422 break;
3423 case PIPE_C:
3424 tmp |= PIPE_C_SCRAMBLE_RESET;
3425 break;
3426 default:
3427 return -EINVAL;
3428 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003429 I915_WRITE(PORT_DFT2_G4X, tmp);
3430 }
3431
Daniel Vetter7ac01292013-10-18 16:37:06 +02003432 return 0;
3433}
3434
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003435static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003436 enum pipe pipe,
3437 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003438 uint32_t *val)
3439{
Daniel Vetter84093602013-11-01 10:50:21 +01003440 struct drm_i915_private *dev_priv = dev->dev_private;
3441 bool need_stable_symbols = false;
3442
Daniel Vetter46a19182013-11-01 10:50:20 +01003443 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3444 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3445 if (ret)
3446 return ret;
3447 }
3448
3449 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003450 case INTEL_PIPE_CRC_SOURCE_PIPE:
3451 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3452 break;
3453 case INTEL_PIPE_CRC_SOURCE_TV:
3454 if (!SUPPORTS_TV(dev))
3455 return -EINVAL;
3456 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3457 break;
3458 case INTEL_PIPE_CRC_SOURCE_DP_B:
3459 if (!IS_G4X(dev))
3460 return -EINVAL;
3461 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003462 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003463 break;
3464 case INTEL_PIPE_CRC_SOURCE_DP_C:
3465 if (!IS_G4X(dev))
3466 return -EINVAL;
3467 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003468 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003469 break;
3470 case INTEL_PIPE_CRC_SOURCE_DP_D:
3471 if (!IS_G4X(dev))
3472 return -EINVAL;
3473 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003474 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003475 break;
3476 case INTEL_PIPE_CRC_SOURCE_NONE:
3477 *val = 0;
3478 break;
3479 default:
3480 return -EINVAL;
3481 }
3482
Daniel Vetter84093602013-11-01 10:50:21 +01003483 /*
3484 * When the pipe CRC tap point is after the transcoders we need
3485 * to tweak symbol-level features to produce a deterministic series of
3486 * symbols for a given frame. We need to reset those features only once
3487 * a frame (instead of every nth symbol):
3488 * - DC-balance: used to ensure a better clock recovery from the data
3489 * link (SDVO)
3490 * - DisplayPort scrambling: used for EMI reduction
3491 */
3492 if (need_stable_symbols) {
3493 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3494
3495 WARN_ON(!IS_G4X(dev));
3496
3497 I915_WRITE(PORT_DFT_I9XX,
3498 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3499
3500 if (pipe == PIPE_A)
3501 tmp |= PIPE_A_SCRAMBLE_RESET;
3502 else
3503 tmp |= PIPE_B_SCRAMBLE_RESET;
3504
3505 I915_WRITE(PORT_DFT2_G4X, tmp);
3506 }
3507
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003508 return 0;
3509}
3510
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003511static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3512 enum pipe pipe)
3513{
3514 struct drm_i915_private *dev_priv = dev->dev_private;
3515 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3516
Ville Syrjäläeb736672014-12-09 21:28:28 +02003517 switch (pipe) {
3518 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003519 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003520 break;
3521 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003522 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003523 break;
3524 case PIPE_C:
3525 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3526 break;
3527 default:
3528 return;
3529 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003530 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3531 tmp &= ~DC_BALANCE_RESET_VLV;
3532 I915_WRITE(PORT_DFT2_G4X, tmp);
3533
3534}
3535
Daniel Vetter84093602013-11-01 10:50:21 +01003536static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3537 enum pipe pipe)
3538{
3539 struct drm_i915_private *dev_priv = dev->dev_private;
3540 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3541
3542 if (pipe == PIPE_A)
3543 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3544 else
3545 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3546 I915_WRITE(PORT_DFT2_G4X, tmp);
3547
3548 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3549 I915_WRITE(PORT_DFT_I9XX,
3550 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3551 }
3552}
3553
Daniel Vetter46a19182013-11-01 10:50:20 +01003554static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003555 uint32_t *val)
3556{
Daniel Vetter46a19182013-11-01 10:50:20 +01003557 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3558 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3559
3560 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003561 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3562 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3563 break;
3564 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3565 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3566 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003567 case INTEL_PIPE_CRC_SOURCE_PIPE:
3568 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3569 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003570 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003571 *val = 0;
3572 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003573 default:
3574 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003575 }
3576
3577 return 0;
3578}
3579
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003580static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3581{
3582 struct drm_i915_private *dev_priv = dev->dev_private;
3583 struct intel_crtc *crtc =
3584 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3585
3586 drm_modeset_lock_all(dev);
3587 /*
3588 * If we use the eDP transcoder we need to make sure that we don't
3589 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3590 * relevant on hsw with pipe A when using the always-on power well
3591 * routing.
3592 */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02003593 if (crtc->config->cpu_transcoder == TRANSCODER_EDP &&
3594 !crtc->config->pch_pfit.enabled) {
3595 crtc->config->pch_pfit.force_thru = true;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003596
3597 intel_display_power_get(dev_priv,
3598 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3599
3600 dev_priv->display.crtc_disable(&crtc->base);
3601 dev_priv->display.crtc_enable(&crtc->base);
3602 }
3603 drm_modeset_unlock_all(dev);
3604}
3605
3606static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3607{
3608 struct drm_i915_private *dev_priv = dev->dev_private;
3609 struct intel_crtc *crtc =
3610 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3611
3612 drm_modeset_lock_all(dev);
3613 /*
3614 * If we use the eDP transcoder we need to make sure that we don't
3615 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3616 * relevant on hsw with pipe A when using the always-on power well
3617 * routing.
3618 */
Ander Conselvan de Oliveira6e3c9712015-01-15 14:55:25 +02003619 if (crtc->config->pch_pfit.force_thru) {
3620 crtc->config->pch_pfit.force_thru = false;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003621
3622 dev_priv->display.crtc_disable(&crtc->base);
3623 dev_priv->display.crtc_enable(&crtc->base);
3624
3625 intel_display_power_put(dev_priv,
3626 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3627 }
3628 drm_modeset_unlock_all(dev);
3629}
3630
3631static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3632 enum pipe pipe,
3633 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003634 uint32_t *val)
3635{
Daniel Vetter46a19182013-11-01 10:50:20 +01003636 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3637 *source = INTEL_PIPE_CRC_SOURCE_PF;
3638
3639 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003640 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3641 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3642 break;
3643 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3644 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3645 break;
3646 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003647 if (IS_HASWELL(dev) && pipe == PIPE_A)
3648 hsw_trans_edp_pipe_A_crc_wa(dev);
3649
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003650 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3651 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003652 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003653 *val = 0;
3654 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003655 default:
3656 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003657 }
3658
3659 return 0;
3660}
3661
Daniel Vetter926321d2013-10-16 13:30:34 +02003662static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3663 enum intel_pipe_crc_source source)
3664{
3665 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003666 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003667 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3668 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003669 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003670 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003671
Damien Lespiaucc3da172013-10-15 18:55:31 +01003672 if (pipe_crc->source == source)
3673 return 0;
3674
Damien Lespiauae676fc2013-10-15 18:55:32 +01003675 /* forbid changing the source without going back to 'none' */
3676 if (pipe_crc->source && source)
3677 return -EINVAL;
3678
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003679 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3680 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3681 return -EIO;
3682 }
3683
Daniel Vetter52f843f2013-10-21 17:26:38 +02003684 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003685 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003686 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003687 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003688 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003689 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003690 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003691 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003692 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003693 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003694
3695 if (ret != 0)
3696 return ret;
3697
Damien Lespiau4b584362013-10-15 18:55:33 +01003698 /* none -> real source transition */
3699 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003700 struct intel_pipe_crc_entry *entries;
3701
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003702 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3703 pipe_name(pipe), pipe_crc_source_name(source));
3704
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003705 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3706 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003707 GFP_KERNEL);
3708 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003709 return -ENOMEM;
3710
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003711 /*
3712 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3713 * enabled and disabled dynamically based on package C states,
3714 * user space can't make reliable use of the CRCs, so let's just
3715 * completely disable it.
3716 */
3717 hsw_disable_ips(crtc);
3718
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003719 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003720 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003721 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003722 pipe_crc->head = 0;
3723 pipe_crc->tail = 0;
3724 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003725 }
3726
Damien Lespiaucc3da172013-10-15 18:55:31 +01003727 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003728
Daniel Vetter926321d2013-10-16 13:30:34 +02003729 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3730 POSTING_READ(PIPE_CRC_CTL(pipe));
3731
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003732 /* real source -> none transition */
3733 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003734 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003735 struct intel_crtc *crtc =
3736 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003737
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003738 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3739 pipe_name(pipe));
3740
Daniel Vettera33d7102014-06-06 08:22:08 +02003741 drm_modeset_lock(&crtc->base.mutex, NULL);
3742 if (crtc->active)
3743 intel_wait_for_vblank(dev, pipe);
3744 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003745
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003746 spin_lock_irq(&pipe_crc->lock);
3747 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003748 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003749 pipe_crc->head = 0;
3750 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003751 spin_unlock_irq(&pipe_crc->lock);
3752
3753 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003754
3755 if (IS_G4X(dev))
3756 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003757 else if (IS_VALLEYVIEW(dev))
3758 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003759 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3760 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003761
3762 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003763 }
3764
Daniel Vetter926321d2013-10-16 13:30:34 +02003765 return 0;
3766}
3767
3768/*
3769 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003770 * command: wsp* object wsp+ name wsp+ source wsp*
3771 * object: 'pipe'
3772 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003773 * source: (none | plane1 | plane2 | pf)
3774 * wsp: (#0x20 | #0x9 | #0xA)+
3775 *
3776 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003777 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3778 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003779 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003780static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003781{
3782 int n_words = 0;
3783
3784 while (*buf) {
3785 char *end;
3786
3787 /* skip leading white space */
3788 buf = skip_spaces(buf);
3789 if (!*buf)
3790 break; /* end of buffer */
3791
3792 /* find end of word */
3793 for (end = buf; *end && !isspace(*end); end++)
3794 ;
3795
3796 if (n_words == max_words) {
3797 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3798 max_words);
3799 return -EINVAL; /* ran out of words[] before bytes */
3800 }
3801
3802 if (*end)
3803 *end++ = '\0';
3804 words[n_words++] = buf;
3805 buf = end;
3806 }
3807
3808 return n_words;
3809}
3810
Damien Lespiaub94dec82013-10-15 18:55:35 +01003811enum intel_pipe_crc_object {
3812 PIPE_CRC_OBJECT_PIPE,
3813};
3814
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003815static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003816 "pipe",
3817};
3818
3819static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003820display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003821{
3822 int i;
3823
3824 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3825 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003826 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003827 return 0;
3828 }
3829
3830 return -EINVAL;
3831}
3832
Damien Lespiaubd9db022013-10-15 18:55:36 +01003833static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003834{
3835 const char name = buf[0];
3836
3837 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3838 return -EINVAL;
3839
3840 *pipe = name - 'A';
3841
3842 return 0;
3843}
3844
3845static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003846display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003847{
3848 int i;
3849
3850 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3851 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003852 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003853 return 0;
3854 }
3855
3856 return -EINVAL;
3857}
3858
Damien Lespiaubd9db022013-10-15 18:55:36 +01003859static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003860{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003861#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003862 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003863 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003864 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003865 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003866 enum intel_pipe_crc_source source;
3867
Damien Lespiaubd9db022013-10-15 18:55:36 +01003868 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003869 if (n_words != N_WORDS) {
3870 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3871 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003872 return -EINVAL;
3873 }
3874
Damien Lespiaubd9db022013-10-15 18:55:36 +01003875 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003876 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003877 return -EINVAL;
3878 }
3879
Damien Lespiaubd9db022013-10-15 18:55:36 +01003880 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003881 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3882 return -EINVAL;
3883 }
3884
Damien Lespiaubd9db022013-10-15 18:55:36 +01003885 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003886 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003887 return -EINVAL;
3888 }
3889
3890 return pipe_crc_set_source(dev, pipe, source);
3891}
3892
Damien Lespiaubd9db022013-10-15 18:55:36 +01003893static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3894 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003895{
3896 struct seq_file *m = file->private_data;
3897 struct drm_device *dev = m->private;
3898 char *tmpbuf;
3899 int ret;
3900
3901 if (len == 0)
3902 return 0;
3903
3904 if (len > PAGE_SIZE - 1) {
3905 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3906 PAGE_SIZE);
3907 return -E2BIG;
3908 }
3909
3910 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3911 if (!tmpbuf)
3912 return -ENOMEM;
3913
3914 if (copy_from_user(tmpbuf, ubuf, len)) {
3915 ret = -EFAULT;
3916 goto out;
3917 }
3918 tmpbuf[len] = '\0';
3919
Damien Lespiaubd9db022013-10-15 18:55:36 +01003920 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003921
3922out:
3923 kfree(tmpbuf);
3924 if (ret < 0)
3925 return ret;
3926
3927 *offp += len;
3928 return len;
3929}
3930
Damien Lespiaubd9db022013-10-15 18:55:36 +01003931static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003932 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003933 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003934 .read = seq_read,
3935 .llseek = seq_lseek,
3936 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003937 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003938};
3939
Damien Lespiau97e94b22014-11-04 17:06:50 +00003940static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003941{
3942 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003943 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003944 int level;
3945
3946 drm_modeset_lock_all(dev);
3947
3948 for (level = 0; level < num_levels; level++) {
3949 unsigned int latency = wm[level];
3950
Damien Lespiau97e94b22014-11-04 17:06:50 +00003951 /*
3952 * - WM1+ latency values in 0.5us units
3953 * - latencies are in us on gen9
3954 */
3955 if (INTEL_INFO(dev)->gen >= 9)
3956 latency *= 10;
3957 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003958 latency *= 5;
3959
3960 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003961 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003962 }
3963
3964 drm_modeset_unlock_all(dev);
3965}
3966
3967static int pri_wm_latency_show(struct seq_file *m, void *data)
3968{
3969 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003970 struct drm_i915_private *dev_priv = dev->dev_private;
3971 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003972
Damien Lespiau97e94b22014-11-04 17:06:50 +00003973 if (INTEL_INFO(dev)->gen >= 9)
3974 latencies = dev_priv->wm.skl_latency;
3975 else
3976 latencies = to_i915(dev)->wm.pri_latency;
3977
3978 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003979
3980 return 0;
3981}
3982
3983static int spr_wm_latency_show(struct seq_file *m, void *data)
3984{
3985 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003986 struct drm_i915_private *dev_priv = dev->dev_private;
3987 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003988
Damien Lespiau97e94b22014-11-04 17:06:50 +00003989 if (INTEL_INFO(dev)->gen >= 9)
3990 latencies = dev_priv->wm.skl_latency;
3991 else
3992 latencies = to_i915(dev)->wm.spr_latency;
3993
3994 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003995
3996 return 0;
3997}
3998
3999static int cur_wm_latency_show(struct seq_file *m, void *data)
4000{
4001 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004002 struct drm_i915_private *dev_priv = dev->dev_private;
4003 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004004
Damien Lespiau97e94b22014-11-04 17:06:50 +00004005 if (INTEL_INFO(dev)->gen >= 9)
4006 latencies = dev_priv->wm.skl_latency;
4007 else
4008 latencies = to_i915(dev)->wm.cur_latency;
4009
4010 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004011
4012 return 0;
4013}
4014
4015static int pri_wm_latency_open(struct inode *inode, struct file *file)
4016{
4017 struct drm_device *dev = inode->i_private;
4018
Sonika Jindal9ad02572014-07-21 15:23:39 +05304019 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004020 return -ENODEV;
4021
4022 return single_open(file, pri_wm_latency_show, dev);
4023}
4024
4025static int spr_wm_latency_open(struct inode *inode, struct file *file)
4026{
4027 struct drm_device *dev = inode->i_private;
4028
Sonika Jindal9ad02572014-07-21 15:23:39 +05304029 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004030 return -ENODEV;
4031
4032 return single_open(file, spr_wm_latency_show, dev);
4033}
4034
4035static int cur_wm_latency_open(struct inode *inode, struct file *file)
4036{
4037 struct drm_device *dev = inode->i_private;
4038
Sonika Jindal9ad02572014-07-21 15:23:39 +05304039 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004040 return -ENODEV;
4041
4042 return single_open(file, cur_wm_latency_show, dev);
4043}
4044
4045static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004046 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004047{
4048 struct seq_file *m = file->private_data;
4049 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004050 uint16_t new[8] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01004051 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004052 int level;
4053 int ret;
4054 char tmp[32];
4055
4056 if (len >= sizeof(tmp))
4057 return -EINVAL;
4058
4059 if (copy_from_user(tmp, ubuf, len))
4060 return -EFAULT;
4061
4062 tmp[len] = '\0';
4063
Damien Lespiau97e94b22014-11-04 17:06:50 +00004064 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4065 &new[0], &new[1], &new[2], &new[3],
4066 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004067 if (ret != num_levels)
4068 return -EINVAL;
4069
4070 drm_modeset_lock_all(dev);
4071
4072 for (level = 0; level < num_levels; level++)
4073 wm[level] = new[level];
4074
4075 drm_modeset_unlock_all(dev);
4076
4077 return len;
4078}
4079
4080
4081static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4082 size_t len, loff_t *offp)
4083{
4084 struct seq_file *m = file->private_data;
4085 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004086 struct drm_i915_private *dev_priv = dev->dev_private;
4087 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004088
Damien Lespiau97e94b22014-11-04 17:06:50 +00004089 if (INTEL_INFO(dev)->gen >= 9)
4090 latencies = dev_priv->wm.skl_latency;
4091 else
4092 latencies = to_i915(dev)->wm.pri_latency;
4093
4094 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004095}
4096
4097static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4098 size_t len, loff_t *offp)
4099{
4100 struct seq_file *m = file->private_data;
4101 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004102 struct drm_i915_private *dev_priv = dev->dev_private;
4103 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004104
Damien Lespiau97e94b22014-11-04 17:06:50 +00004105 if (INTEL_INFO(dev)->gen >= 9)
4106 latencies = dev_priv->wm.skl_latency;
4107 else
4108 latencies = to_i915(dev)->wm.spr_latency;
4109
4110 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004111}
4112
4113static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4114 size_t len, loff_t *offp)
4115{
4116 struct seq_file *m = file->private_data;
4117 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004118 struct drm_i915_private *dev_priv = dev->dev_private;
4119 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004120
Damien Lespiau97e94b22014-11-04 17:06:50 +00004121 if (INTEL_INFO(dev)->gen >= 9)
4122 latencies = dev_priv->wm.skl_latency;
4123 else
4124 latencies = to_i915(dev)->wm.cur_latency;
4125
4126 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004127}
4128
4129static const struct file_operations i915_pri_wm_latency_fops = {
4130 .owner = THIS_MODULE,
4131 .open = pri_wm_latency_open,
4132 .read = seq_read,
4133 .llseek = seq_lseek,
4134 .release = single_release,
4135 .write = pri_wm_latency_write
4136};
4137
4138static const struct file_operations i915_spr_wm_latency_fops = {
4139 .owner = THIS_MODULE,
4140 .open = spr_wm_latency_open,
4141 .read = seq_read,
4142 .llseek = seq_lseek,
4143 .release = single_release,
4144 .write = spr_wm_latency_write
4145};
4146
4147static const struct file_operations i915_cur_wm_latency_fops = {
4148 .owner = THIS_MODULE,
4149 .open = cur_wm_latency_open,
4150 .read = seq_read,
4151 .llseek = seq_lseek,
4152 .release = single_release,
4153 .write = cur_wm_latency_write
4154};
4155
Kees Cook647416f2013-03-10 14:10:06 -07004156static int
4157i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004158{
Kees Cook647416f2013-03-10 14:10:06 -07004159 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004160 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004161
Kees Cook647416f2013-03-10 14:10:06 -07004162 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004163
Kees Cook647416f2013-03-10 14:10:06 -07004164 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004165}
4166
Kees Cook647416f2013-03-10 14:10:06 -07004167static int
4168i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004169{
Kees Cook647416f2013-03-10 14:10:06 -07004170 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004171 struct drm_i915_private *dev_priv = dev->dev_private;
4172
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004173 /*
4174 * There is no safeguard against this debugfs entry colliding
4175 * with the hangcheck calling same i915_handle_error() in
4176 * parallel, causing an explosion. For now we assume that the
4177 * test harness is responsible enough not to inject gpu hangs
4178 * while it is writing to 'i915_wedged'
4179 */
4180
4181 if (i915_reset_in_progress(&dev_priv->gpu_error))
4182 return -EAGAIN;
4183
Imre Deakd46c0512014-04-14 20:24:27 +03004184 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004185
Mika Kuoppala58174462014-02-25 17:11:26 +02004186 i915_handle_error(dev, val,
4187 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004188
4189 intel_runtime_pm_put(dev_priv);
4190
Kees Cook647416f2013-03-10 14:10:06 -07004191 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004192}
4193
Kees Cook647416f2013-03-10 14:10:06 -07004194DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4195 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004196 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004197
Kees Cook647416f2013-03-10 14:10:06 -07004198static int
4199i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004200{
Kees Cook647416f2013-03-10 14:10:06 -07004201 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004202 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004203
Kees Cook647416f2013-03-10 14:10:06 -07004204 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004205
Kees Cook647416f2013-03-10 14:10:06 -07004206 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004207}
4208
Kees Cook647416f2013-03-10 14:10:06 -07004209static int
4210i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004211{
Kees Cook647416f2013-03-10 14:10:06 -07004212 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004213 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004214 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004215
Kees Cook647416f2013-03-10 14:10:06 -07004216 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004217
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004218 ret = mutex_lock_interruptible(&dev->struct_mutex);
4219 if (ret)
4220 return ret;
4221
Daniel Vetter99584db2012-11-14 17:14:04 +01004222 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004223 mutex_unlock(&dev->struct_mutex);
4224
Kees Cook647416f2013-03-10 14:10:06 -07004225 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004226}
4227
Kees Cook647416f2013-03-10 14:10:06 -07004228DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4229 i915_ring_stop_get, i915_ring_stop_set,
4230 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004231
Chris Wilson094f9a52013-09-25 17:34:55 +01004232static int
4233i915_ring_missed_irq_get(void *data, u64 *val)
4234{
4235 struct drm_device *dev = data;
4236 struct drm_i915_private *dev_priv = dev->dev_private;
4237
4238 *val = dev_priv->gpu_error.missed_irq_rings;
4239 return 0;
4240}
4241
4242static int
4243i915_ring_missed_irq_set(void *data, u64 val)
4244{
4245 struct drm_device *dev = data;
4246 struct drm_i915_private *dev_priv = dev->dev_private;
4247 int ret;
4248
4249 /* Lock against concurrent debugfs callers */
4250 ret = mutex_lock_interruptible(&dev->struct_mutex);
4251 if (ret)
4252 return ret;
4253 dev_priv->gpu_error.missed_irq_rings = val;
4254 mutex_unlock(&dev->struct_mutex);
4255
4256 return 0;
4257}
4258
4259DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4260 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4261 "0x%08llx\n");
4262
4263static int
4264i915_ring_test_irq_get(void *data, u64 *val)
4265{
4266 struct drm_device *dev = data;
4267 struct drm_i915_private *dev_priv = dev->dev_private;
4268
4269 *val = dev_priv->gpu_error.test_irq_rings;
4270
4271 return 0;
4272}
4273
4274static int
4275i915_ring_test_irq_set(void *data, u64 val)
4276{
4277 struct drm_device *dev = data;
4278 struct drm_i915_private *dev_priv = dev->dev_private;
4279 int ret;
4280
4281 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4282
4283 /* Lock against concurrent debugfs callers */
4284 ret = mutex_lock_interruptible(&dev->struct_mutex);
4285 if (ret)
4286 return ret;
4287
4288 dev_priv->gpu_error.test_irq_rings = val;
4289 mutex_unlock(&dev->struct_mutex);
4290
4291 return 0;
4292}
4293
4294DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4295 i915_ring_test_irq_get, i915_ring_test_irq_set,
4296 "0x%08llx\n");
4297
Chris Wilsondd624af2013-01-15 12:39:35 +00004298#define DROP_UNBOUND 0x1
4299#define DROP_BOUND 0x2
4300#define DROP_RETIRE 0x4
4301#define DROP_ACTIVE 0x8
4302#define DROP_ALL (DROP_UNBOUND | \
4303 DROP_BOUND | \
4304 DROP_RETIRE | \
4305 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004306static int
4307i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004308{
Kees Cook647416f2013-03-10 14:10:06 -07004309 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004310
Kees Cook647416f2013-03-10 14:10:06 -07004311 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004312}
4313
Kees Cook647416f2013-03-10 14:10:06 -07004314static int
4315i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004316{
Kees Cook647416f2013-03-10 14:10:06 -07004317 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004318 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004319 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004320
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004321 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004322
4323 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4324 * on ioctls on -EAGAIN. */
4325 ret = mutex_lock_interruptible(&dev->struct_mutex);
4326 if (ret)
4327 return ret;
4328
4329 if (val & DROP_ACTIVE) {
4330 ret = i915_gpu_idle(dev);
4331 if (ret)
4332 goto unlock;
4333 }
4334
4335 if (val & (DROP_RETIRE | DROP_ACTIVE))
4336 i915_gem_retire_requests(dev);
4337
Chris Wilson21ab4e72014-09-09 11:16:08 +01004338 if (val & DROP_BOUND)
4339 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004340
Chris Wilson21ab4e72014-09-09 11:16:08 +01004341 if (val & DROP_UNBOUND)
4342 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004343
4344unlock:
4345 mutex_unlock(&dev->struct_mutex);
4346
Kees Cook647416f2013-03-10 14:10:06 -07004347 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004348}
4349
Kees Cook647416f2013-03-10 14:10:06 -07004350DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4351 i915_drop_caches_get, i915_drop_caches_set,
4352 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004353
Kees Cook647416f2013-03-10 14:10:06 -07004354static int
4355i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004356{
Kees Cook647416f2013-03-10 14:10:06 -07004357 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004358 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004359 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004360
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004361 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004362 return -ENODEV;
4363
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004364 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4365
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004366 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004367 if (ret)
4368 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004369
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004370 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004371 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004372
Kees Cook647416f2013-03-10 14:10:06 -07004373 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004374}
4375
Kees Cook647416f2013-03-10 14:10:06 -07004376static int
4377i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004378{
Kees Cook647416f2013-03-10 14:10:06 -07004379 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004380 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304381 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004382 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004383
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004384 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004385 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004386
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004387 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4388
Kees Cook647416f2013-03-10 14:10:06 -07004389 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004390
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004391 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004392 if (ret)
4393 return ret;
4394
Jesse Barnes358733e2011-07-27 11:53:01 -07004395 /*
4396 * Turbo will still be enabled, but won't go above the set value.
4397 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304398 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004399
Akash Goelbc4d91f2015-02-26 16:09:47 +05304400 hw_max = dev_priv->rps.max_freq;
4401 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004402
Ben Widawskyb39fb292014-03-19 18:31:11 -07004403 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004404 mutex_unlock(&dev_priv->rps.hw_lock);
4405 return -EINVAL;
4406 }
4407
Ben Widawskyb39fb292014-03-19 18:31:11 -07004408 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004409
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004410 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004411
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004412 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004413
Kees Cook647416f2013-03-10 14:10:06 -07004414 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004415}
4416
Kees Cook647416f2013-03-10 14:10:06 -07004417DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4418 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004419 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004420
Kees Cook647416f2013-03-10 14:10:06 -07004421static int
4422i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004423{
Kees Cook647416f2013-03-10 14:10:06 -07004424 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004425 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004426 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004427
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004428 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004429 return -ENODEV;
4430
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004431 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4432
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004433 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004434 if (ret)
4435 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004436
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004437 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004438 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004439
Kees Cook647416f2013-03-10 14:10:06 -07004440 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004441}
4442
Kees Cook647416f2013-03-10 14:10:06 -07004443static int
4444i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004445{
Kees Cook647416f2013-03-10 14:10:06 -07004446 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004447 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304448 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004449 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004450
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004451 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004452 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004453
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004454 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4455
Kees Cook647416f2013-03-10 14:10:06 -07004456 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004457
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004458 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004459 if (ret)
4460 return ret;
4461
Jesse Barnes1523c312012-05-25 12:34:54 -07004462 /*
4463 * Turbo will still be enabled, but won't go below the set value.
4464 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304465 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004466
Akash Goelbc4d91f2015-02-26 16:09:47 +05304467 hw_max = dev_priv->rps.max_freq;
4468 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004469
Ben Widawskyb39fb292014-03-19 18:31:11 -07004470 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004471 mutex_unlock(&dev_priv->rps.hw_lock);
4472 return -EINVAL;
4473 }
4474
Ben Widawskyb39fb292014-03-19 18:31:11 -07004475 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004476
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004477 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004478
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004479 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004480
Kees Cook647416f2013-03-10 14:10:06 -07004481 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004482}
4483
Kees Cook647416f2013-03-10 14:10:06 -07004484DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4485 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004486 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004487
Kees Cook647416f2013-03-10 14:10:06 -07004488static int
4489i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004490{
Kees Cook647416f2013-03-10 14:10:06 -07004491 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004492 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004493 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004494 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004495
Daniel Vetter004777c2012-08-09 15:07:01 +02004496 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4497 return -ENODEV;
4498
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004499 ret = mutex_lock_interruptible(&dev->struct_mutex);
4500 if (ret)
4501 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004502 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004503
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004504 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004505
4506 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004507 mutex_unlock(&dev_priv->dev->struct_mutex);
4508
Kees Cook647416f2013-03-10 14:10:06 -07004509 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004510
Kees Cook647416f2013-03-10 14:10:06 -07004511 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004512}
4513
Kees Cook647416f2013-03-10 14:10:06 -07004514static int
4515i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004516{
Kees Cook647416f2013-03-10 14:10:06 -07004517 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004518 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004519 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004520
Daniel Vetter004777c2012-08-09 15:07:01 +02004521 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4522 return -ENODEV;
4523
Kees Cook647416f2013-03-10 14:10:06 -07004524 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004525 return -EINVAL;
4526
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004527 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004528 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004529
4530 /* Update the cache sharing policy here as well */
4531 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4532 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4533 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4534 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4535
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004536 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004537 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004538}
4539
Kees Cook647416f2013-03-10 14:10:06 -07004540DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4541 i915_cache_sharing_get, i915_cache_sharing_set,
4542 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004543
Jeff McGee38732182015-02-13 10:27:54 -06004544static int i915_sseu_status(struct seq_file *m, void *unused)
4545{
4546 struct drm_info_node *node = (struct drm_info_node *) m->private;
4547 struct drm_device *dev = node->minor->dev;
Jeff McGee7f992ab2015-02-13 10:27:55 -06004548 struct drm_i915_private *dev_priv = dev->dev_private;
4549 unsigned int s_tot = 0, ss_tot = 0, ss_per = 0, eu_tot = 0, eu_per = 0;
Jeff McGee38732182015-02-13 10:27:54 -06004550
Jeff McGee5575f032015-02-27 10:22:32 -08004551 if ((INTEL_INFO(dev)->gen < 8) || IS_BROADWELL(dev))
Jeff McGee38732182015-02-13 10:27:54 -06004552 return -ENODEV;
4553
4554 seq_puts(m, "SSEU Device Info\n");
4555 seq_printf(m, " Available Slice Total: %u\n",
4556 INTEL_INFO(dev)->slice_total);
4557 seq_printf(m, " Available Subslice Total: %u\n",
4558 INTEL_INFO(dev)->subslice_total);
4559 seq_printf(m, " Available Subslice Per Slice: %u\n",
4560 INTEL_INFO(dev)->subslice_per_slice);
4561 seq_printf(m, " Available EU Total: %u\n",
4562 INTEL_INFO(dev)->eu_total);
4563 seq_printf(m, " Available EU Per Subslice: %u\n",
4564 INTEL_INFO(dev)->eu_per_subslice);
4565 seq_printf(m, " Has Slice Power Gating: %s\n",
4566 yesno(INTEL_INFO(dev)->has_slice_pg));
4567 seq_printf(m, " Has Subslice Power Gating: %s\n",
4568 yesno(INTEL_INFO(dev)->has_subslice_pg));
4569 seq_printf(m, " Has EU Power Gating: %s\n",
4570 yesno(INTEL_INFO(dev)->has_eu_pg));
4571
Jeff McGee7f992ab2015-02-13 10:27:55 -06004572 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5575f032015-02-27 10:22:32 -08004573 if (IS_CHERRYVIEW(dev)) {
4574 const int ss_max = 2;
4575 int ss;
4576 u32 sig1[ss_max], sig2[ss_max];
4577
4578 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4579 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4580 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4581 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4582
4583 for (ss = 0; ss < ss_max; ss++) {
4584 unsigned int eu_cnt;
4585
4586 if (sig1[ss] & CHV_SS_PG_ENABLE)
4587 /* skip disabled subslice */
4588 continue;
4589
4590 s_tot = 1;
4591 ss_per++;
4592 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4593 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4594 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4595 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
4596 eu_tot += eu_cnt;
4597 eu_per = max(eu_per, eu_cnt);
4598 }
4599 ss_tot = ss_per;
4600 } else if (IS_SKYLAKE(dev)) {
Jeff McGee7f992ab2015-02-13 10:27:55 -06004601 const int s_max = 3, ss_max = 4;
4602 int s, ss;
4603 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4604
4605 s_reg[0] = I915_READ(GEN9_SLICE0_PGCTL_ACK);
4606 s_reg[1] = I915_READ(GEN9_SLICE1_PGCTL_ACK);
4607 s_reg[2] = I915_READ(GEN9_SLICE2_PGCTL_ACK);
4608 eu_reg[0] = I915_READ(GEN9_SLICE0_SS01_EU_PGCTL_ACK);
4609 eu_reg[1] = I915_READ(GEN9_SLICE0_SS23_EU_PGCTL_ACK);
4610 eu_reg[2] = I915_READ(GEN9_SLICE1_SS01_EU_PGCTL_ACK);
4611 eu_reg[3] = I915_READ(GEN9_SLICE1_SS23_EU_PGCTL_ACK);
4612 eu_reg[4] = I915_READ(GEN9_SLICE2_SS01_EU_PGCTL_ACK);
4613 eu_reg[5] = I915_READ(GEN9_SLICE2_SS23_EU_PGCTL_ACK);
4614 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4615 GEN9_PGCTL_SSA_EU19_ACK |
4616 GEN9_PGCTL_SSA_EU210_ACK |
4617 GEN9_PGCTL_SSA_EU311_ACK;
4618 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4619 GEN9_PGCTL_SSB_EU19_ACK |
4620 GEN9_PGCTL_SSB_EU210_ACK |
4621 GEN9_PGCTL_SSB_EU311_ACK;
4622
4623 for (s = 0; s < s_max; s++) {
4624 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4625 /* skip disabled slice */
4626 continue;
4627
4628 s_tot++;
4629 ss_per = INTEL_INFO(dev)->subslice_per_slice;
4630 ss_tot += ss_per;
4631 for (ss = 0; ss < ss_max; ss++) {
4632 unsigned int eu_cnt;
4633
4634 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4635 eu_mask[ss%2]);
4636 eu_tot += eu_cnt;
4637 eu_per = max(eu_per, eu_cnt);
4638 }
4639 }
4640 }
4641 seq_printf(m, " Enabled Slice Total: %u\n", s_tot);
4642 seq_printf(m, " Enabled Subslice Total: %u\n", ss_tot);
4643 seq_printf(m, " Enabled Subslice Per Slice: %u\n", ss_per);
4644 seq_printf(m, " Enabled EU Total: %u\n", eu_tot);
4645 seq_printf(m, " Enabled EU Per Subslice: %u\n", eu_per);
4646
Jeff McGee38732182015-02-13 10:27:54 -06004647 return 0;
4648}
4649
Ben Widawsky6d794d42011-04-25 11:25:56 -07004650static int i915_forcewake_open(struct inode *inode, struct file *file)
4651{
4652 struct drm_device *dev = inode->i_private;
4653 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004654
Daniel Vetter075edca2012-01-24 09:44:28 +01004655 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004656 return 0;
4657
Chris Wilson6daccb02015-01-16 11:34:35 +02004658 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004659 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004660
4661 return 0;
4662}
4663
Ben Widawskyc43b5632012-04-16 14:07:40 -07004664static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004665{
4666 struct drm_device *dev = inode->i_private;
4667 struct drm_i915_private *dev_priv = dev->dev_private;
4668
Daniel Vetter075edca2012-01-24 09:44:28 +01004669 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004670 return 0;
4671
Mika Kuoppala59bad942015-01-16 11:34:40 +02004672 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004673 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004674
4675 return 0;
4676}
4677
4678static const struct file_operations i915_forcewake_fops = {
4679 .owner = THIS_MODULE,
4680 .open = i915_forcewake_open,
4681 .release = i915_forcewake_release,
4682};
4683
4684static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4685{
4686 struct drm_device *dev = minor->dev;
4687 struct dentry *ent;
4688
4689 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004690 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004691 root, dev,
4692 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004693 if (!ent)
4694 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004695
Ben Widawsky8eb57292011-05-11 15:10:58 -07004696 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004697}
4698
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004699static int i915_debugfs_create(struct dentry *root,
4700 struct drm_minor *minor,
4701 const char *name,
4702 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004703{
4704 struct drm_device *dev = minor->dev;
4705 struct dentry *ent;
4706
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004707 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004708 S_IRUGO | S_IWUSR,
4709 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004710 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004711 if (!ent)
4712 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004713
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004714 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004715}
4716
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004717static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004718 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004719 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004720 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01004721 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004722 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004723 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004724 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004725 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004726 {"i915_gem_request", i915_gem_request_info, 0},
4727 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004728 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004729 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00004730 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
4731 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
4732 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07004733 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08004734 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05304735 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02004736 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004737 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004738 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004739 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004740 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004741 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004742 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004743 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004744 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004745 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01004746 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01004747 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02004748 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004749 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004750 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004751 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004752 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004753 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004754 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03004755 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004756 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004757 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004758 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004759 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004760 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004761 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004762 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06004763 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05304764 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01004765 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004766};
Ben Gamari27c202a2009-07-01 22:26:52 -04004767#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004768
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004769static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004770 const char *name;
4771 const struct file_operations *fops;
4772} i915_debugfs_files[] = {
4773 {"i915_wedged", &i915_wedged_fops},
4774 {"i915_max_freq", &i915_max_freq_fops},
4775 {"i915_min_freq", &i915_min_freq_fops},
4776 {"i915_cache_sharing", &i915_cache_sharing_fops},
4777 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004778 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4779 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004780 {"i915_gem_drop_caches", &i915_drop_caches_fops},
4781 {"i915_error_state", &i915_error_state_fops},
4782 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004783 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004784 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4785 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4786 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004787 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004788};
4789
Damien Lespiau07144422013-10-15 18:55:40 +01004790void intel_display_crc_init(struct drm_device *dev)
4791{
4792 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01004793 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01004794
Damien Lespiau055e3932014-08-18 13:49:10 +01004795 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01004796 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01004797
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004798 pipe_crc->opened = false;
4799 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01004800 init_waitqueue_head(&pipe_crc->wq);
4801 }
4802}
4803
Ben Gamari27c202a2009-07-01 22:26:52 -04004804int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004805{
Daniel Vetter34b96742013-07-04 20:49:44 +02004806 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004807
Ben Widawsky6d794d42011-04-25 11:25:56 -07004808 ret = i915_forcewake_create(minor->debugfs_root, minor);
4809 if (ret)
4810 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004811
Damien Lespiau07144422013-10-15 18:55:40 +01004812 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
4813 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
4814 if (ret)
4815 return ret;
4816 }
4817
Daniel Vetter34b96742013-07-04 20:49:44 +02004818 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4819 ret = i915_debugfs_create(minor->debugfs_root, minor,
4820 i915_debugfs_files[i].name,
4821 i915_debugfs_files[i].fops);
4822 if (ret)
4823 return ret;
4824 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004825
Ben Gamari27c202a2009-07-01 22:26:52 -04004826 return drm_debugfs_create_files(i915_debugfs_list,
4827 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004828 minor->debugfs_root, minor);
4829}
4830
Ben Gamari27c202a2009-07-01 22:26:52 -04004831void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004832{
Daniel Vetter34b96742013-07-04 20:49:44 +02004833 int i;
4834
Ben Gamari27c202a2009-07-01 22:26:52 -04004835 drm_debugfs_remove_files(i915_debugfs_list,
4836 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004837
Ben Widawsky6d794d42011-04-25 11:25:56 -07004838 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
4839 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004840
Daniel Vettere309a992013-10-16 22:55:51 +02004841 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01004842 struct drm_info_list *info_list =
4843 (struct drm_info_list *)&i915_pipe_crc_data[i];
4844
4845 drm_debugfs_remove_files(info_list, 1, minor);
4846 }
4847
Daniel Vetter34b96742013-07-04 20:49:44 +02004848 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4849 struct drm_info_list *info_list =
4850 (struct drm_info_list *) i915_debugfs_files[i].fops;
4851
4852 drm_debugfs_remove_files(info_list, 1, minor);
4853 }
Ben Gamari20172632009-02-17 20:08:50 -05004854}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03004855
4856struct dpcd_block {
4857 /* DPCD dump start address. */
4858 unsigned int offset;
4859 /* DPCD dump end address, inclusive. If unset, .size will be used. */
4860 unsigned int end;
4861 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
4862 size_t size;
4863 /* Only valid for eDP. */
4864 bool edp;
4865};
4866
4867static const struct dpcd_block i915_dpcd_debug[] = {
4868 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
4869 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
4870 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
4871 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
4872 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
4873 { .offset = DP_SET_POWER },
4874 { .offset = DP_EDP_DPCD_REV },
4875 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
4876 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
4877 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
4878};
4879
4880static int i915_dpcd_show(struct seq_file *m, void *data)
4881{
4882 struct drm_connector *connector = m->private;
4883 struct intel_dp *intel_dp =
4884 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
4885 uint8_t buf[16];
4886 ssize_t err;
4887 int i;
4888
4889 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
4890 const struct dpcd_block *b = &i915_dpcd_debug[i];
4891 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
4892
4893 if (b->edp &&
4894 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
4895 continue;
4896
4897 /* low tech for now */
4898 if (WARN_ON(size > sizeof(buf)))
4899 continue;
4900
4901 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
4902 if (err <= 0) {
4903 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
4904 size, b->offset, err);
4905 continue;
4906 }
4907
4908 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
4909 };
4910
4911 return 0;
4912}
4913
4914static int i915_dpcd_open(struct inode *inode, struct file *file)
4915{
4916 return single_open(file, i915_dpcd_show, inode->i_private);
4917}
4918
4919static const struct file_operations i915_dpcd_fops = {
4920 .owner = THIS_MODULE,
4921 .open = i915_dpcd_open,
4922 .read = seq_read,
4923 .llseek = seq_lseek,
4924 .release = single_release,
4925};
4926
4927/**
4928 * i915_debugfs_connector_add - add i915 specific connector debugfs files
4929 * @connector: pointer to a registered drm_connector
4930 *
4931 * Cleanup will be done by drm_connector_unregister() through a call to
4932 * drm_debugfs_connector_remove().
4933 *
4934 * Returns 0 on success, negative error codes on error.
4935 */
4936int i915_debugfs_connector_add(struct drm_connector *connector)
4937{
4938 struct dentry *root = connector->debugfs_entry;
4939
4940 /* The connector must have been registered beforehands. */
4941 if (!root)
4942 return -ENODEV;
4943
4944 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
4945 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
4946 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
4947 &i915_dpcd_fops);
4948
4949 return 0;
4950}