blob: a815fcc407c6d478a0660b50a8b0bd333072f38e [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{
Chris Wilsonbaaa5cf2015-04-15 16:42:46 +010099 if (obj->pin_display)
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
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100120static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
121{
122 u64 size = 0;
123 struct i915_vma *vma;
124
125 list_for_each_entry(vma, &obj->vma_list, vma_link) {
126 if (i915_is_ggtt(vma->vm) &&
127 drm_mm_node_allocated(&vma->node))
128 size += vma->node.size;
129 }
130
131 return size;
132}
133
Chris Wilson37811fc2010-08-25 22:45:57 +0100134static void
135describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
136{
Chris Wilsonb4716182015-04-27 13:41:17 +0100137 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
138 struct intel_engine_cs *ring;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700139 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800140 int pin_count = 0;
Chris Wilsonb4716182015-04-27 13:41:17 +0100141 int i;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800142
Chris Wilsonb4716182015-04-27 13:41:17 +0100143 seq_printf(m, "%pK: %s%s%s%s %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100144 &obj->base,
Chris Wilson481a3d42015-04-07 16:20:39 +0100145 obj->active ? "*" : " ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100146 get_pin_flag(obj),
147 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700148 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800149 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100150 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100151 obj->base.write_domain);
152 for_each_ring(ring, dev_priv, i)
153 seq_printf(m, "%x ",
154 i915_gem_request_get_seqno(obj->last_read_req[i]));
155 seq_printf(m, "] %x %x%s%s%s",
John Harrison97b2a6a2014-11-24 18:49:26 +0000156 i915_gem_request_get_seqno(obj->last_write_req),
157 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100158 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100159 obj->dirty ? " dirty" : "",
160 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
161 if (obj->base.name)
162 seq_printf(m, " (name: %d)", obj->base.name);
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300163 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800164 if (vma->pin_count > 0)
165 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300166 }
167 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100168 if (obj->pin_display)
169 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100170 if (obj->fence_reg != I915_FENCE_REG_NONE)
171 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700172 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100173 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
174 i915_is_ggtt(vma->vm) ? "g" : "pp",
175 vma->node.start, vma->node.size);
176 if (i915_is_ggtt(vma->vm))
177 seq_printf(m, ", type: %u)", vma->ggtt_view.type);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700178 else
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100179 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700180 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000181 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100182 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100183 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000184 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100185 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000186 *t++ = 'p';
187 if (obj->fault_mappable)
188 *t++ = 'f';
189 *t = '\0';
190 seq_printf(m, " (%s mappable)", s);
191 }
Chris Wilsonb4716182015-04-27 13:41:17 +0100192 if (obj->last_write_req != NULL)
John Harrison41c52412014-11-24 18:49:43 +0000193 seq_printf(m, " (%s)",
Chris Wilsonb4716182015-04-27 13:41:17 +0100194 i915_gem_request_get_ring(obj->last_write_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200195 if (obj->frontbuffer_bits)
196 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100197}
198
Oscar Mateo273497e2014-05-22 14:13:37 +0100199static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700200{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100201 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700202 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
203 seq_putc(m, ' ');
204}
205
Ben Gamari433e12f2009-02-17 20:08:51 -0500206static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500207{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100208 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500209 uintptr_t list = (uintptr_t) node->info_ent->data;
210 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500211 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700212 struct drm_i915_private *dev_priv = dev->dev_private;
213 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700214 struct i915_vma *vma;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300215 u64 total_obj_size, total_gtt_size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100216 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100217
218 ret = mutex_lock_interruptible(&dev->struct_mutex);
219 if (ret)
220 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500221
Ben Widawskyca191b12013-07-31 17:00:14 -0700222 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500223 switch (list) {
224 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100225 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700226 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500227 break;
228 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100229 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700230 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500231 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500232 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100233 mutex_unlock(&dev->struct_mutex);
234 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500235 }
236
Chris Wilson8f2480f2010-09-26 11:44:19 +0100237 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700238 list_for_each_entry(vma, head, mm_list) {
239 seq_printf(m, " ");
240 describe_obj(m, vma->obj);
241 seq_printf(m, "\n");
242 total_obj_size += vma->obj->base.size;
243 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100244 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500245 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100246 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700247
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300248 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson8f2480f2010-09-26 11:44:19 +0100249 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500250 return 0;
251}
252
Chris Wilson6d2b88852013-08-07 18:30:54 +0100253static int obj_rank_by_stolen(void *priv,
254 struct list_head *A, struct list_head *B)
255{
256 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200257 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100258 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200259 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100260
261 return a->stolen->start - b->stolen->start;
262}
263
264static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
265{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100266 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100267 struct drm_device *dev = node->minor->dev;
268 struct drm_i915_private *dev_priv = dev->dev_private;
269 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300270 u64 total_obj_size, total_gtt_size;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100271 LIST_HEAD(stolen);
272 int count, ret;
273
274 ret = mutex_lock_interruptible(&dev->struct_mutex);
275 if (ret)
276 return ret;
277
278 total_obj_size = total_gtt_size = count = 0;
279 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
280 if (obj->stolen == NULL)
281 continue;
282
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200283 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100284
285 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100286 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100287 count++;
288 }
289 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
290 if (obj->stolen == NULL)
291 continue;
292
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200293 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100294
295 total_obj_size += obj->base.size;
296 count++;
297 }
298 list_sort(NULL, &stolen, obj_rank_by_stolen);
299 seq_puts(m, "Stolen:\n");
300 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200301 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100302 seq_puts(m, " ");
303 describe_obj(m, obj);
304 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200305 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100306 }
307 mutex_unlock(&dev->struct_mutex);
308
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300309 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson6d2b88852013-08-07 18:30:54 +0100310 count, total_obj_size, total_gtt_size);
311 return 0;
312}
313
Chris Wilson6299f992010-11-24 12:23:44 +0000314#define count_objects(list, member) do { \
315 list_for_each_entry(obj, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100316 size += i915_gem_obj_total_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000317 ++count; \
318 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700319 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000320 ++mappable_count; \
321 } \
322 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400323} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000324
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100325struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000326 struct drm_i915_file_private *file_priv;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300327 unsigned long count;
328 u64 total, unbound;
329 u64 global, shared;
330 u64 active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100331};
332
333static int per_file_stats(int id, void *ptr, void *data)
334{
335 struct drm_i915_gem_object *obj = ptr;
336 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000337 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100338
339 stats->count++;
340 stats->total += obj->base.size;
341
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000342 if (obj->base.name || obj->base.dma_buf)
343 stats->shared += obj->base.size;
344
Chris Wilson6313c202014-03-19 13:45:45 +0000345 if (USES_FULL_PPGTT(obj->base.dev)) {
346 list_for_each_entry(vma, &obj->vma_list, vma_link) {
347 struct i915_hw_ppgtt *ppgtt;
348
349 if (!drm_mm_node_allocated(&vma->node))
350 continue;
351
352 if (i915_is_ggtt(vma->vm)) {
353 stats->global += obj->base.size;
354 continue;
355 }
356
357 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200358 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000359 continue;
360
John Harrison41c52412014-11-24 18:49:43 +0000361 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000362 stats->active += obj->base.size;
363 else
364 stats->inactive += obj->base.size;
365
366 return 0;
367 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100368 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000369 if (i915_gem_obj_ggtt_bound(obj)) {
370 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000371 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000372 stats->active += obj->base.size;
373 else
374 stats->inactive += obj->base.size;
375 return 0;
376 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100377 }
378
Chris Wilson6313c202014-03-19 13:45:45 +0000379 if (!list_empty(&obj->global_list))
380 stats->unbound += obj->base.size;
381
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100382 return 0;
383}
384
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100385#define print_file_stats(m, name, stats) do { \
386 if (stats.count) \
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300387 seq_printf(m, "%s: %lu objects, %llu bytes (%llu active, %llu inactive, %llu global, %llu shared, %llu unbound)\n", \
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100388 name, \
389 stats.count, \
390 stats.total, \
391 stats.active, \
392 stats.inactive, \
393 stats.global, \
394 stats.shared, \
395 stats.unbound); \
396} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800397
398static void print_batch_pool_stats(struct seq_file *m,
399 struct drm_i915_private *dev_priv)
400{
401 struct drm_i915_gem_object *obj;
402 struct file_stats stats;
Chris Wilson06fbca72015-04-07 16:20:36 +0100403 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100404 int i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800405
406 memset(&stats, 0, sizeof(stats));
407
Chris Wilson06fbca72015-04-07 16:20:36 +0100408 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100409 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
410 list_for_each_entry(obj,
411 &ring->batch_pool.cache_list[j],
412 batch_pool_link)
413 per_file_stats(0, obj, &stats);
414 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100415 }
Brad Volkin493018d2014-12-11 12:13:08 -0800416
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100417 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800418}
419
Ben Widawskyca191b12013-07-31 17:00:14 -0700420#define count_vmas(list, member) do { \
421 list_for_each_entry(vma, list, member) { \
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100422 size += i915_gem_obj_total_ggtt_size(vma->obj); \
Ben Widawskyca191b12013-07-31 17:00:14 -0700423 ++count; \
424 if (vma->obj->map_and_fenceable) { \
425 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
426 ++mappable_count; \
427 } \
428 } \
429} while (0)
430
431static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100432{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100433 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100434 struct drm_device *dev = node->minor->dev;
435 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200436 u32 count, mappable_count, purgeable_count;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300437 u64 size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000438 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700439 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100440 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700441 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100442 int ret;
443
444 ret = mutex_lock_interruptible(&dev->struct_mutex);
445 if (ret)
446 return ret;
447
Chris Wilson6299f992010-11-24 12:23:44 +0000448 seq_printf(m, "%u objects, %zu bytes\n",
449 dev_priv->mm.object_count,
450 dev_priv->mm.object_memory);
451
452 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700453 count_objects(&dev_priv->mm.bound_list, global_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300454 seq_printf(m, "%u [%u] objects, %llu [%llu] bytes in gtt\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000455 count, mappable_count, size, mappable_size);
456
457 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700458 count_vmas(&vm->active_list, mm_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300459 seq_printf(m, " %u [%u] active objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000460 count, mappable_count, size, mappable_size);
461
462 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700463 count_vmas(&vm->inactive_list, mm_list);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300464 seq_printf(m, " %u [%u] inactive objects, %llu [%llu] bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000465 count, mappable_count, size, mappable_size);
466
Chris Wilsonb7abb712012-08-20 11:33:30 +0200467 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700468 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200469 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200470 if (obj->madv == I915_MADV_DONTNEED)
471 purgeable_size += obj->base.size, ++purgeable_count;
472 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300473 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
Chris Wilson6c085a72012-08-20 11:40:46 +0200474
Chris Wilson6299f992010-11-24 12:23:44 +0000475 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700476 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000477 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700478 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000479 ++count;
480 }
Chris Wilson30154652015-04-07 17:28:24 +0100481 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700482 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000483 ++mappable_count;
484 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200485 if (obj->madv == I915_MADV_DONTNEED) {
486 purgeable_size += obj->base.size;
487 ++purgeable_count;
488 }
Chris Wilson6299f992010-11-24 12:23:44 +0000489 }
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300490 seq_printf(m, "%u purgeable objects, %llu bytes\n",
Chris Wilsonb7abb712012-08-20 11:33:30 +0200491 purgeable_count, purgeable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300492 seq_printf(m, "%u pinned mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000493 mappable_count, mappable_size);
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300494 seq_printf(m, "%u fault mappable objects, %llu bytes\n",
Chris Wilson6299f992010-11-24 12:23:44 +0000495 count, size);
496
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300497 seq_printf(m, "%llu [%llu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700498 dev_priv->gtt.base.total,
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300499 (u64)dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100500
Damien Lespiau267f0c92013-06-24 22:59:48 +0100501 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800502 print_batch_pool_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100503 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
504 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900505 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100506
507 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000508 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100509 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100510 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100511 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900512 /*
513 * Although we have a valid reference on file->pid, that does
514 * not guarantee that the task_struct who called get_pid() is
515 * still alive (e.g. get_pid(current) => fork() => exit()).
516 * Therefore, we need to protect this ->comm access using RCU.
517 */
518 rcu_read_lock();
519 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800520 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900521 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100522 }
523
Chris Wilson73aa8082010-09-30 11:46:12 +0100524 mutex_unlock(&dev->struct_mutex);
525
526 return 0;
527}
528
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100529static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000530{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100531 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000532 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100533 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000534 struct drm_i915_private *dev_priv = dev->dev_private;
535 struct drm_i915_gem_object *obj;
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300536 u64 total_obj_size, total_gtt_size;
Chris Wilson08c18322011-01-10 00:00:24 +0000537 int count, ret;
538
539 ret = mutex_lock_interruptible(&dev->struct_mutex);
540 if (ret)
541 return ret;
542
543 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700544 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800545 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100546 continue;
547
Damien Lespiau267f0c92013-06-24 22:59:48 +0100548 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000549 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100550 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000551 total_obj_size += obj->base.size;
Tvrtko Ursulinca1543b2015-07-01 11:51:10 +0100552 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000553 count++;
554 }
555
556 mutex_unlock(&dev->struct_mutex);
557
Mika Kuoppalac44ef602015-06-25 18:35:05 +0300558 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
Chris Wilson08c18322011-01-10 00:00:24 +0000559 count, total_obj_size, total_gtt_size);
560
561 return 0;
562}
563
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100564static int i915_gem_pageflip_info(struct seq_file *m, void *data)
565{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100566 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100567 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100568 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100569 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200570 int ret;
571
572 ret = mutex_lock_interruptible(&dev->struct_mutex);
573 if (ret)
574 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100575
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100576 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800577 const char pipe = pipe_name(crtc->pipe);
578 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100579 struct intel_unpin_work *work;
580
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200581 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100582 work = crtc->unpin_work;
583 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800584 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100585 pipe, plane);
586 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100587 u32 addr;
588
Chris Wilsone7d841c2012-12-03 11:36:30 +0000589 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800590 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100591 pipe, plane);
592 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800593 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100594 pipe, plane);
595 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100596 if (work->flip_queued_req) {
597 struct intel_engine_cs *ring =
598 i915_gem_request_get_ring(work->flip_queued_req);
599
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200600 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 +0100601 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000602 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100603 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100604 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000605 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100606 } else
607 seq_printf(m, "Flip not associated with any ring\n");
608 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
609 work->flip_queued_vblank,
610 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100611 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100612 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100613 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100614 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100615 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000616 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100617
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100618 if (INTEL_INFO(dev)->gen >= 4)
619 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
620 else
621 addr = I915_READ(DSPADDR(crtc->plane));
622 seq_printf(m, "Current scanout address 0x%08x\n", addr);
623
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100624 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100625 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
626 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100627 }
628 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200629 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100630 }
631
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200632 mutex_unlock(&dev->struct_mutex);
633
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100634 return 0;
635}
636
Brad Volkin493018d2014-12-11 12:13:08 -0800637static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
638{
639 struct drm_info_node *node = m->private;
640 struct drm_device *dev = node->minor->dev;
641 struct drm_i915_private *dev_priv = dev->dev_private;
642 struct drm_i915_gem_object *obj;
Chris Wilson06fbca72015-04-07 16:20:36 +0100643 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100644 int total = 0;
645 int ret, i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800646
647 ret = mutex_lock_interruptible(&dev->struct_mutex);
648 if (ret)
649 return ret;
650
Chris Wilson06fbca72015-04-07 16:20:36 +0100651 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100652 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
653 int count;
654
655 count = 0;
656 list_for_each_entry(obj,
657 &ring->batch_pool.cache_list[j],
658 batch_pool_link)
659 count++;
660 seq_printf(m, "%s cache[%d]: %d objects\n",
661 ring->name, j, count);
662
663 list_for_each_entry(obj,
664 &ring->batch_pool.cache_list[j],
665 batch_pool_link) {
666 seq_puts(m, " ");
667 describe_obj(m, obj);
668 seq_putc(m, '\n');
669 }
670
671 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100672 }
Brad Volkin493018d2014-12-11 12:13:08 -0800673 }
674
Chris Wilson8d9d5742015-04-07 16:20:38 +0100675 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800676
677 mutex_unlock(&dev->struct_mutex);
678
679 return 0;
680}
681
Ben Gamari20172632009-02-17 20:08:50 -0500682static int i915_gem_request_info(struct seq_file *m, void *data)
683{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100684 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500685 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300686 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100687 struct intel_engine_cs *ring;
Daniel Vettereed29a52015-05-21 14:21:25 +0200688 struct drm_i915_gem_request *req;
Chris Wilson2d1070b2015-04-01 10:36:56 +0100689 int ret, any, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100690
691 ret = mutex_lock_interruptible(&dev->struct_mutex);
692 if (ret)
693 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500694
Chris Wilson2d1070b2015-04-01 10:36:56 +0100695 any = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100696 for_each_ring(ring, dev_priv, i) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100697 int count;
698
699 count = 0;
Daniel Vettereed29a52015-05-21 14:21:25 +0200700 list_for_each_entry(req, &ring->request_list, list)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100701 count++;
702 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100703 continue;
704
Chris Wilson2d1070b2015-04-01 10:36:56 +0100705 seq_printf(m, "%s requests: %d\n", ring->name, count);
Daniel Vettereed29a52015-05-21 14:21:25 +0200706 list_for_each_entry(req, &ring->request_list, list) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100707 struct task_struct *task;
708
709 rcu_read_lock();
710 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200711 if (req->pid)
712 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100713 seq_printf(m, " %x @ %d: %s [%d]\n",
Daniel Vettereed29a52015-05-21 14:21:25 +0200714 req->seqno,
715 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100716 task ? task->comm : "<unknown>",
717 task ? task->pid : -1);
718 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100719 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100720
721 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500722 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100723 mutex_unlock(&dev->struct_mutex);
724
Chris Wilson2d1070b2015-04-01 10:36:56 +0100725 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100726 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100727
Ben Gamari20172632009-02-17 20:08:50 -0500728 return 0;
729}
730
Chris Wilsonb2223492010-10-27 15:27:33 +0100731static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100732 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100733{
734 if (ring->get_seqno) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200735 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100736 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100737 }
738}
739
Ben Gamari20172632009-02-17 20:08:50 -0500740static int i915_gem_seqno_info(struct seq_file *m, void *data)
741{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100742 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500743 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300744 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100745 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000746 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100747
748 ret = mutex_lock_interruptible(&dev->struct_mutex);
749 if (ret)
750 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200751 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500752
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100753 for_each_ring(ring, dev_priv, i)
754 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100755
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200756 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100757 mutex_unlock(&dev->struct_mutex);
758
Ben Gamari20172632009-02-17 20:08:50 -0500759 return 0;
760}
761
762
763static int i915_interrupt_info(struct seq_file *m, void *data)
764{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100765 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500766 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300767 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100768 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800769 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100770
771 ret = mutex_lock_interruptible(&dev->struct_mutex);
772 if (ret)
773 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200774 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500775
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300776 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300777 seq_printf(m, "Master Interrupt Control:\t%08x\n",
778 I915_READ(GEN8_MASTER_IRQ));
779
780 seq_printf(m, "Display IER:\t%08x\n",
781 I915_READ(VLV_IER));
782 seq_printf(m, "Display IIR:\t%08x\n",
783 I915_READ(VLV_IIR));
784 seq_printf(m, "Display IIR_RW:\t%08x\n",
785 I915_READ(VLV_IIR_RW));
786 seq_printf(m, "Display IMR:\t%08x\n",
787 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100788 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300789 seq_printf(m, "Pipe %c stat:\t%08x\n",
790 pipe_name(pipe),
791 I915_READ(PIPESTAT(pipe)));
792
793 seq_printf(m, "Port hotplug:\t%08x\n",
794 I915_READ(PORT_HOTPLUG_EN));
795 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
796 I915_READ(VLV_DPFLIPSTAT));
797 seq_printf(m, "DPINVGTT:\t%08x\n",
798 I915_READ(DPINVGTT));
799
800 for (i = 0; i < 4; i++) {
801 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
802 i, I915_READ(GEN8_GT_IMR(i)));
803 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
804 i, I915_READ(GEN8_GT_IIR(i)));
805 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
806 i, I915_READ(GEN8_GT_IER(i)));
807 }
808
809 seq_printf(m, "PCU interrupt mask:\t%08x\n",
810 I915_READ(GEN8_PCU_IMR));
811 seq_printf(m, "PCU interrupt identity:\t%08x\n",
812 I915_READ(GEN8_PCU_IIR));
813 seq_printf(m, "PCU interrupt enable:\t%08x\n",
814 I915_READ(GEN8_PCU_IER));
815 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700816 seq_printf(m, "Master Interrupt Control:\t%08x\n",
817 I915_READ(GEN8_MASTER_IRQ));
818
819 for (i = 0; i < 4; i++) {
820 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
821 i, I915_READ(GEN8_GT_IMR(i)));
822 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
823 i, I915_READ(GEN8_GT_IIR(i)));
824 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
825 i, I915_READ(GEN8_GT_IER(i)));
826 }
827
Damien Lespiau055e3932014-08-18 13:49:10 +0100828 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200829 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300830 POWER_DOMAIN_PIPE(pipe))) {
831 seq_printf(m, "Pipe %c power disabled\n",
832 pipe_name(pipe));
833 continue;
834 }
Ben Widawskya123f152013-11-02 21:07:10 -0700835 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000836 pipe_name(pipe),
837 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700838 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000839 pipe_name(pipe),
840 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700841 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000842 pipe_name(pipe),
843 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700844 }
845
846 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
847 I915_READ(GEN8_DE_PORT_IMR));
848 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
849 I915_READ(GEN8_DE_PORT_IIR));
850 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
851 I915_READ(GEN8_DE_PORT_IER));
852
853 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
854 I915_READ(GEN8_DE_MISC_IMR));
855 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
856 I915_READ(GEN8_DE_MISC_IIR));
857 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
858 I915_READ(GEN8_DE_MISC_IER));
859
860 seq_printf(m, "PCU interrupt mask:\t%08x\n",
861 I915_READ(GEN8_PCU_IMR));
862 seq_printf(m, "PCU interrupt identity:\t%08x\n",
863 I915_READ(GEN8_PCU_IIR));
864 seq_printf(m, "PCU interrupt enable:\t%08x\n",
865 I915_READ(GEN8_PCU_IER));
866 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700867 seq_printf(m, "Display IER:\t%08x\n",
868 I915_READ(VLV_IER));
869 seq_printf(m, "Display IIR:\t%08x\n",
870 I915_READ(VLV_IIR));
871 seq_printf(m, "Display IIR_RW:\t%08x\n",
872 I915_READ(VLV_IIR_RW));
873 seq_printf(m, "Display IMR:\t%08x\n",
874 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100875 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700876 seq_printf(m, "Pipe %c stat:\t%08x\n",
877 pipe_name(pipe),
878 I915_READ(PIPESTAT(pipe)));
879
880 seq_printf(m, "Master IER:\t%08x\n",
881 I915_READ(VLV_MASTER_IER));
882
883 seq_printf(m, "Render IER:\t%08x\n",
884 I915_READ(GTIER));
885 seq_printf(m, "Render IIR:\t%08x\n",
886 I915_READ(GTIIR));
887 seq_printf(m, "Render IMR:\t%08x\n",
888 I915_READ(GTIMR));
889
890 seq_printf(m, "PM IER:\t\t%08x\n",
891 I915_READ(GEN6_PMIER));
892 seq_printf(m, "PM IIR:\t\t%08x\n",
893 I915_READ(GEN6_PMIIR));
894 seq_printf(m, "PM IMR:\t\t%08x\n",
895 I915_READ(GEN6_PMIMR));
896
897 seq_printf(m, "Port hotplug:\t%08x\n",
898 I915_READ(PORT_HOTPLUG_EN));
899 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
900 I915_READ(VLV_DPFLIPSTAT));
901 seq_printf(m, "DPINVGTT:\t%08x\n",
902 I915_READ(DPINVGTT));
903
904 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800905 seq_printf(m, "Interrupt enable: %08x\n",
906 I915_READ(IER));
907 seq_printf(m, "Interrupt identity: %08x\n",
908 I915_READ(IIR));
909 seq_printf(m, "Interrupt mask: %08x\n",
910 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100911 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800912 seq_printf(m, "Pipe %c stat: %08x\n",
913 pipe_name(pipe),
914 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800915 } else {
916 seq_printf(m, "North Display Interrupt enable: %08x\n",
917 I915_READ(DEIER));
918 seq_printf(m, "North Display Interrupt identity: %08x\n",
919 I915_READ(DEIIR));
920 seq_printf(m, "North Display Interrupt mask: %08x\n",
921 I915_READ(DEIMR));
922 seq_printf(m, "South Display Interrupt enable: %08x\n",
923 I915_READ(SDEIER));
924 seq_printf(m, "South Display Interrupt identity: %08x\n",
925 I915_READ(SDEIIR));
926 seq_printf(m, "South Display Interrupt mask: %08x\n",
927 I915_READ(SDEIMR));
928 seq_printf(m, "Graphics Interrupt enable: %08x\n",
929 I915_READ(GTIER));
930 seq_printf(m, "Graphics Interrupt identity: %08x\n",
931 I915_READ(GTIIR));
932 seq_printf(m, "Graphics Interrupt mask: %08x\n",
933 I915_READ(GTIMR));
934 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100935 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700936 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100937 seq_printf(m,
938 "Graphics Interrupt mask (%s): %08x\n",
939 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000940 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100941 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000942 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200943 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100944 mutex_unlock(&dev->struct_mutex);
945
Ben Gamari20172632009-02-17 20:08:50 -0500946 return 0;
947}
948
Chris Wilsona6172a82009-02-11 14:26:38 +0000949static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
950{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100951 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000952 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300953 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100954 int i, ret;
955
956 ret = mutex_lock_interruptible(&dev->struct_mutex);
957 if (ret)
958 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000959
960 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
961 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
962 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000963 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000964
Chris Wilson6c085a72012-08-20 11:40:46 +0200965 seq_printf(m, "Fence %d, pin count = %d, object = ",
966 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100967 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100968 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100969 else
Chris Wilson05394f32010-11-08 19:18:58 +0000970 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100971 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000972 }
973
Chris Wilson05394f32010-11-08 19:18:58 +0000974 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000975 return 0;
976}
977
Ben Gamari20172632009-02-17 20:08:50 -0500978static int i915_hws_info(struct seq_file *m, void *data)
979{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100980 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500981 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300982 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100983 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100984 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100985 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500986
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000987 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100988 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500989 if (hws == NULL)
990 return 0;
991
992 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
993 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
994 i * 4,
995 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
996 }
997 return 0;
998}
999
Daniel Vetterd5442302012-04-27 15:17:40 +02001000static ssize_t
1001i915_error_state_write(struct file *filp,
1002 const char __user *ubuf,
1003 size_t cnt,
1004 loff_t *ppos)
1005{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001006 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001007 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001008 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +02001009
1010 DRM_DEBUG_DRIVER("Resetting error state\n");
1011
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001012 ret = mutex_lock_interruptible(&dev->struct_mutex);
1013 if (ret)
1014 return ret;
1015
Daniel Vetterd5442302012-04-27 15:17:40 +02001016 i915_destroy_error_state(dev);
1017 mutex_unlock(&dev->struct_mutex);
1018
1019 return cnt;
1020}
1021
1022static int i915_error_state_open(struct inode *inode, struct file *file)
1023{
1024 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001025 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001026
1027 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1028 if (!error_priv)
1029 return -ENOMEM;
1030
1031 error_priv->dev = dev;
1032
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001033 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001034
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001035 file->private_data = error_priv;
1036
1037 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001038}
1039
1040static int i915_error_state_release(struct inode *inode, struct file *file)
1041{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001042 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001043
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001044 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001045 kfree(error_priv);
1046
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001047 return 0;
1048}
1049
1050static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1051 size_t count, loff_t *pos)
1052{
1053 struct i915_error_state_file_priv *error_priv = file->private_data;
1054 struct drm_i915_error_state_buf error_str;
1055 loff_t tmp_pos = 0;
1056 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001057 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001058
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001059 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001060 if (ret)
1061 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001062
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001063 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001064 if (ret)
1065 goto out;
1066
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001067 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1068 error_str.buf,
1069 error_str.bytes);
1070
1071 if (ret_count < 0)
1072 ret = ret_count;
1073 else
1074 *pos = error_str.start + ret_count;
1075out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001076 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001077 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001078}
1079
1080static const struct file_operations i915_error_state_fops = {
1081 .owner = THIS_MODULE,
1082 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001083 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001084 .write = i915_error_state_write,
1085 .llseek = default_llseek,
1086 .release = i915_error_state_release,
1087};
1088
Kees Cook647416f2013-03-10 14:10:06 -07001089static int
1090i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001091{
Kees Cook647416f2013-03-10 14:10:06 -07001092 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001093 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001094 int ret;
1095
1096 ret = mutex_lock_interruptible(&dev->struct_mutex);
1097 if (ret)
1098 return ret;
1099
Kees Cook647416f2013-03-10 14:10:06 -07001100 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001101 mutex_unlock(&dev->struct_mutex);
1102
Kees Cook647416f2013-03-10 14:10:06 -07001103 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001104}
1105
Kees Cook647416f2013-03-10 14:10:06 -07001106static int
1107i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001108{
Kees Cook647416f2013-03-10 14:10:06 -07001109 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001110 int ret;
1111
Mika Kuoppala40633212012-12-04 15:12:00 +02001112 ret = mutex_lock_interruptible(&dev->struct_mutex);
1113 if (ret)
1114 return ret;
1115
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001116 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001117 mutex_unlock(&dev->struct_mutex);
1118
Kees Cook647416f2013-03-10 14:10:06 -07001119 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001120}
1121
Kees Cook647416f2013-03-10 14:10:06 -07001122DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1123 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001124 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001125
Deepak Sadb4bd12014-03-31 11:30:02 +05301126static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001127{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001128 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001129 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001130 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001131 int ret = 0;
1132
1133 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001134
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001135 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1136
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001137 if (IS_GEN5(dev)) {
1138 u16 rgvswctl = I915_READ16(MEMSWCTL);
1139 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1140
1141 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1142 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1143 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1144 MEMSTAT_VID_SHIFT);
1145 seq_printf(m, "Current P-state: %d\n",
1146 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001147 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
Akash Goel60260a52015-03-06 11:07:21 +05301148 IS_BROADWELL(dev) || IS_GEN9(dev)) {
Bob Paauwe35040562015-06-25 14:54:07 -07001149 u32 rp_state_limits;
1150 u32 gt_perf_status;
1151 u32 rp_state_cap;
Chris Wilson0d8f9492014-03-27 09:06:14 +00001152 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001153 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001154 u32 rpupei, rpcurup, rpprevup;
1155 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001156 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001157 int max_freq;
1158
Bob Paauwe35040562015-06-25 14:54:07 -07001159 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1160 if (IS_BROXTON(dev)) {
1161 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1162 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1163 } else {
1164 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1165 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1166 }
1167
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001168 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001169 ret = mutex_lock_interruptible(&dev->struct_mutex);
1170 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001171 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001172
Mika Kuoppala59bad942015-01-16 11:34:40 +02001173 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001174
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001175 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301176 if (IS_GEN9(dev))
1177 reqf >>= 23;
1178 else {
1179 reqf &= ~GEN6_TURBO_DISABLE;
1180 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1181 reqf >>= 24;
1182 else
1183 reqf >>= 25;
1184 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001185 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001186
Chris Wilson0d8f9492014-03-27 09:06:14 +00001187 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1188 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1189 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1190
Jesse Barnesccab5c82011-01-18 15:49:25 -08001191 rpstat = I915_READ(GEN6_RPSTAT1);
1192 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1193 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1194 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1195 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1196 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1197 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Akash Goel60260a52015-03-06 11:07:21 +05301198 if (IS_GEN9(dev))
1199 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1200 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001201 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1202 else
1203 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001204 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001205
Mika Kuoppala59bad942015-01-16 11:34:40 +02001206 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001207 mutex_unlock(&dev->struct_mutex);
1208
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001209 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1210 pm_ier = I915_READ(GEN6_PMIER);
1211 pm_imr = I915_READ(GEN6_PMIMR);
1212 pm_isr = I915_READ(GEN6_PMISR);
1213 pm_iir = I915_READ(GEN6_PMIIR);
1214 pm_mask = I915_READ(GEN6_PMINTRMSK);
1215 } else {
1216 pm_ier = I915_READ(GEN8_GT_IER(2));
1217 pm_imr = I915_READ(GEN8_GT_IMR(2));
1218 pm_isr = I915_READ(GEN8_GT_ISR(2));
1219 pm_iir = I915_READ(GEN8_GT_IIR(2));
1220 pm_mask = I915_READ(GEN6_PMINTRMSK);
1221 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001222 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 -03001223 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001224 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001225 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301226 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001227 seq_printf(m, "Render p-state VID: %d\n",
1228 gt_perf_status & 0xff);
1229 seq_printf(m, "Render p-state limit: %d\n",
1230 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001231 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1232 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1233 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1234 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001235 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001236 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001237 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1238 GEN6_CURICONT_MASK);
1239 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1240 GEN6_CURBSYTAVG_MASK);
1241 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1242 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001243 seq_printf(m, "Up threshold: %d%%\n",
1244 dev_priv->rps.up_threshold);
1245
Jesse Barnesccab5c82011-01-18 15:49:25 -08001246 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1247 GEN6_CURIAVG_MASK);
1248 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1249 GEN6_CURBSYTAVG_MASK);
1250 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1251 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001252 seq_printf(m, "Down threshold: %d%%\n",
1253 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001254
Bob Paauwe35040562015-06-25 14:54:07 -07001255 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1256 rp_state_cap >> 16) & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301257 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001258 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001259 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001260
1261 max_freq = (rp_state_cap & 0xff00) >> 8;
Akash Goel60260a52015-03-06 11:07:21 +05301262 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001263 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001264 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001265
Bob Paauwe35040562015-06-25 14:54:07 -07001266 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1267 rp_state_cap >> 0) & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301268 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001269 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001270 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001271 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001272 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001273
Chris Wilsond86ed342015-04-27 13:41:19 +01001274 seq_printf(m, "Current freq: %d MHz\n",
1275 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1276 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001277 seq_printf(m, "Idle freq: %d MHz\n",
1278 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001279 seq_printf(m, "Min freq: %d MHz\n",
1280 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1281 seq_printf(m, "Max freq: %d MHz\n",
1282 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1283 seq_printf(m,
1284 "efficient (RPe) frequency: %d MHz\n",
1285 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001286 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001287 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001288
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001289 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001290 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001291 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1292 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1293
Chris Wilsond86ed342015-04-27 13:41:19 +01001294 seq_printf(m, "actual GPU freq: %d MHz\n",
1295 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1296
1297 seq_printf(m, "current GPU freq: %d MHz\n",
1298 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1299
Jesse Barnes0a073b82013-04-17 15:54:58 -07001300 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001301 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001302
Jesse Barnes0a073b82013-04-17 15:54:58 -07001303 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001304 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001305
Chris Wilsonaed242f2015-03-18 09:48:21 +00001306 seq_printf(m, "idle GPU freq: %d MHz\n",
1307 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1308
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001309 seq_printf(m,
1310 "efficient (RPe) frequency: %d MHz\n",
1311 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001312 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001313 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001314 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001315 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001316
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001317out:
1318 intel_runtime_pm_put(dev_priv);
1319 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001320}
1321
Chris Wilsonf6544492015-01-26 18:03:04 +02001322static int i915_hangcheck_info(struct seq_file *m, void *unused)
1323{
1324 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001325 struct drm_device *dev = node->minor->dev;
1326 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf6544492015-01-26 18:03:04 +02001327 struct intel_engine_cs *ring;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001328 u64 acthd[I915_NUM_RINGS];
1329 u32 seqno[I915_NUM_RINGS];
Chris Wilsonf6544492015-01-26 18:03:04 +02001330 int i;
1331
1332 if (!i915.enable_hangcheck) {
1333 seq_printf(m, "Hangcheck disabled\n");
1334 return 0;
1335 }
1336
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001337 intel_runtime_pm_get(dev_priv);
1338
1339 for_each_ring(ring, dev_priv, i) {
1340 seqno[i] = ring->get_seqno(ring, false);
1341 acthd[i] = intel_ring_get_active_head(ring);
1342 }
1343
1344 intel_runtime_pm_put(dev_priv);
1345
Chris Wilsonf6544492015-01-26 18:03:04 +02001346 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1347 seq_printf(m, "Hangcheck active, fires in %dms\n",
1348 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1349 jiffies));
1350 } else
1351 seq_printf(m, "Hangcheck inactive\n");
1352
1353 for_each_ring(ring, dev_priv, i) {
1354 seq_printf(m, "%s:\n", ring->name);
1355 seq_printf(m, "\tseqno = %x [current %x]\n",
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001356 ring->hangcheck.seqno, seqno[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001357 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1358 (long long)ring->hangcheck.acthd,
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001359 (long long)acthd[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001360 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1361 (long long)ring->hangcheck.max_acthd);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001362 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1363 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
Chris Wilsonf6544492015-01-26 18:03:04 +02001364 }
1365
1366 return 0;
1367}
1368
Ben Widawsky4d855292011-12-12 19:34:16 -08001369static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001370{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001371 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001372 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001373 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001374 u32 rgvmodectl, rstdbyctl;
1375 u16 crstandvid;
1376 int ret;
1377
1378 ret = mutex_lock_interruptible(&dev->struct_mutex);
1379 if (ret)
1380 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001381 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001382
1383 rgvmodectl = I915_READ(MEMMODECTL);
1384 rstdbyctl = I915_READ(RSTDBYCTL);
1385 crstandvid = I915_READ16(CRSTANDVID);
1386
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001387 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001388 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001389
1390 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1391 "yes" : "no");
1392 seq_printf(m, "Boost freq: %d\n",
1393 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1394 MEMMODE_BOOST_FREQ_SHIFT);
1395 seq_printf(m, "HW control enabled: %s\n",
1396 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1397 seq_printf(m, "SW control enabled: %s\n",
1398 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1399 seq_printf(m, "Gated voltage change: %s\n",
1400 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1401 seq_printf(m, "Starting frequency: P%d\n",
1402 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001403 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001404 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001405 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1406 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1407 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1408 seq_printf(m, "Render standby enabled: %s\n",
1409 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001410 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001411 switch (rstdbyctl & RSX_STATUS_MASK) {
1412 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001413 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001414 break;
1415 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001416 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001417 break;
1418 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001419 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001420 break;
1421 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001422 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001423 break;
1424 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001425 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001426 break;
1427 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001428 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001429 break;
1430 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001431 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001432 break;
1433 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001434
1435 return 0;
1436}
1437
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001438static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001439{
1440 struct drm_info_node *node = m->private;
1441 struct drm_device *dev = node->minor->dev;
1442 struct drm_i915_private *dev_priv = dev->dev_private;
1443 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001444 int i;
1445
1446 spin_lock_irq(&dev_priv->uncore.lock);
1447 for_each_fw_domain(fw_domain, dev_priv, i) {
1448 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001449 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001450 fw_domain->wake_count);
1451 }
1452 spin_unlock_irq(&dev_priv->uncore.lock);
1453
1454 return 0;
1455}
1456
Deepak S669ab5a2014-01-10 15:18:26 +05301457static int vlv_drpc_info(struct seq_file *m)
1458{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001459 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301460 struct drm_device *dev = node->minor->dev;
1461 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001462 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301463
Imre Deakd46c0512014-04-14 20:24:27 +03001464 intel_runtime_pm_get(dev_priv);
1465
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001466 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301467 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1468 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1469
Imre Deakd46c0512014-04-14 20:24:27 +03001470 intel_runtime_pm_put(dev_priv);
1471
Deepak S669ab5a2014-01-10 15:18:26 +05301472 seq_printf(m, "Video Turbo Mode: %s\n",
1473 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1474 seq_printf(m, "Turbo enabled: %s\n",
1475 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1476 seq_printf(m, "HW control enabled: %s\n",
1477 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1478 seq_printf(m, "SW control enabled: %s\n",
1479 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1480 GEN6_RP_MEDIA_SW_MODE));
1481 seq_printf(m, "RC6 Enabled: %s\n",
1482 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1483 GEN6_RC_CTL_EI_MODE(1))));
1484 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001485 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301486 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001487 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301488
Imre Deak9cc19be2014-04-14 20:24:24 +03001489 seq_printf(m, "Render RC6 residency since boot: %u\n",
1490 I915_READ(VLV_GT_RENDER_RC6));
1491 seq_printf(m, "Media RC6 residency since boot: %u\n",
1492 I915_READ(VLV_GT_MEDIA_RC6));
1493
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001494 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301495}
1496
Ben Widawsky4d855292011-12-12 19:34:16 -08001497static int gen6_drpc_info(struct seq_file *m)
1498{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001499 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001500 struct drm_device *dev = node->minor->dev;
1501 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001502 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001503 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001504 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001505
1506 ret = mutex_lock_interruptible(&dev->struct_mutex);
1507 if (ret)
1508 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001509 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001510
Chris Wilson907b28c2013-07-19 20:36:52 +01001511 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001512 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001513 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001514
1515 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001516 seq_puts(m, "RC information inaccurate because somebody "
1517 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001518 } else {
1519 /* NB: we cannot use forcewake, else we read the wrong values */
1520 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1521 udelay(10);
1522 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1523 }
1524
1525 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001526 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001527
1528 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1529 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1530 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001531 mutex_lock(&dev_priv->rps.hw_lock);
1532 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1533 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001534
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001535 intel_runtime_pm_put(dev_priv);
1536
Ben Widawsky4d855292011-12-12 19:34:16 -08001537 seq_printf(m, "Video Turbo Mode: %s\n",
1538 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1539 seq_printf(m, "HW control enabled: %s\n",
1540 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1541 seq_printf(m, "SW control enabled: %s\n",
1542 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1543 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001544 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001545 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1546 seq_printf(m, "RC6 Enabled: %s\n",
1547 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1548 seq_printf(m, "Deep RC6 Enabled: %s\n",
1549 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1550 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1551 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001552 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001553 switch (gt_core_status & GEN6_RCn_MASK) {
1554 case GEN6_RC0:
1555 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001556 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001557 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001558 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001559 break;
1560 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001561 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001562 break;
1563 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001564 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001565 break;
1566 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001567 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001568 break;
1569 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001570 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001571 break;
1572 }
1573
1574 seq_printf(m, "Core Power Down: %s\n",
1575 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001576
1577 /* Not exactly sure what this is */
1578 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1579 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1580 seq_printf(m, "RC6 residency since boot: %u\n",
1581 I915_READ(GEN6_GT_GFX_RC6));
1582 seq_printf(m, "RC6+ residency since boot: %u\n",
1583 I915_READ(GEN6_GT_GFX_RC6p));
1584 seq_printf(m, "RC6++ residency since boot: %u\n",
1585 I915_READ(GEN6_GT_GFX_RC6pp));
1586
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001587 seq_printf(m, "RC6 voltage: %dmV\n",
1588 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1589 seq_printf(m, "RC6+ voltage: %dmV\n",
1590 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1591 seq_printf(m, "RC6++ voltage: %dmV\n",
1592 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001593 return 0;
1594}
1595
1596static int i915_drpc_info(struct seq_file *m, void *unused)
1597{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001598 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001599 struct drm_device *dev = node->minor->dev;
1600
Deepak S669ab5a2014-01-10 15:18:26 +05301601 if (IS_VALLEYVIEW(dev))
1602 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001603 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001604 return gen6_drpc_info(m);
1605 else
1606 return ironlake_drpc_info(m);
1607}
1608
Daniel Vetter9a851782015-06-18 10:30:22 +02001609static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1610{
1611 struct drm_info_node *node = m->private;
1612 struct drm_device *dev = node->minor->dev;
1613 struct drm_i915_private *dev_priv = dev->dev_private;
1614
1615 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1616 dev_priv->fb_tracking.busy_bits);
1617
1618 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1619 dev_priv->fb_tracking.flip_bits);
1620
1621 return 0;
1622}
1623
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001624static int i915_fbc_status(struct seq_file *m, void *unused)
1625{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001626 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001627 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001628 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001629
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001630 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001631 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001632 return 0;
1633 }
1634
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001635 intel_runtime_pm_get(dev_priv);
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001636 mutex_lock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001637
Paulo Zanoni7733b492015-07-07 15:26:04 -03001638 if (intel_fbc_enabled(dev_priv))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001639 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001640 else
1641 seq_printf(m, "FBC disabled: %s\n",
1642 intel_no_fbc_reason_str(dev_priv->fbc.no_fbc_reason));
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001643
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001644 if (INTEL_INFO(dev_priv)->gen >= 7)
1645 seq_printf(m, "Compressing: %s\n",
1646 yesno(I915_READ(FBC_STATUS2) &
1647 FBC_COMPRESSION_MASK));
1648
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001649 mutex_unlock(&dev_priv->fbc.lock);
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001650 intel_runtime_pm_put(dev_priv);
1651
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001652 return 0;
1653}
1654
Rodrigo Vivida46f932014-08-01 02:04:45 -07001655static int i915_fbc_fc_get(void *data, u64 *val)
1656{
1657 struct drm_device *dev = data;
1658 struct drm_i915_private *dev_priv = dev->dev_private;
1659
1660 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1661 return -ENODEV;
1662
Rodrigo Vivida46f932014-08-01 02:04:45 -07001663 *val = dev_priv->fbc.false_color;
Rodrigo Vivida46f932014-08-01 02:04:45 -07001664
1665 return 0;
1666}
1667
1668static int i915_fbc_fc_set(void *data, u64 val)
1669{
1670 struct drm_device *dev = data;
1671 struct drm_i915_private *dev_priv = dev->dev_private;
1672 u32 reg;
1673
1674 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1675 return -ENODEV;
1676
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001677 mutex_lock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001678
1679 reg = I915_READ(ILK_DPFC_CONTROL);
1680 dev_priv->fbc.false_color = val;
1681
1682 I915_WRITE(ILK_DPFC_CONTROL, val ?
1683 (reg | FBC_CTL_FALSE_COLOR) :
1684 (reg & ~FBC_CTL_FALSE_COLOR));
1685
Paulo Zanoni25ad93f2015-07-02 19:25:10 -03001686 mutex_unlock(&dev_priv->fbc.lock);
Rodrigo Vivida46f932014-08-01 02:04:45 -07001687 return 0;
1688}
1689
1690DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1691 i915_fbc_fc_get, i915_fbc_fc_set,
1692 "%llu\n");
1693
Paulo Zanoni92d44622013-05-31 16:33:24 -03001694static int i915_ips_status(struct seq_file *m, void *unused)
1695{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001696 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001697 struct drm_device *dev = node->minor->dev;
1698 struct drm_i915_private *dev_priv = dev->dev_private;
1699
Damien Lespiauf5adf942013-06-24 18:29:34 +01001700 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001701 seq_puts(m, "not supported\n");
1702 return 0;
1703 }
1704
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001705 intel_runtime_pm_get(dev_priv);
1706
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001707 seq_printf(m, "Enabled by kernel parameter: %s\n",
1708 yesno(i915.enable_ips));
1709
1710 if (INTEL_INFO(dev)->gen >= 8) {
1711 seq_puts(m, "Currently: unknown\n");
1712 } else {
1713 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1714 seq_puts(m, "Currently: enabled\n");
1715 else
1716 seq_puts(m, "Currently: disabled\n");
1717 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001718
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001719 intel_runtime_pm_put(dev_priv);
1720
Paulo Zanoni92d44622013-05-31 16:33:24 -03001721 return 0;
1722}
1723
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001724static int i915_sr_status(struct seq_file *m, void *unused)
1725{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001726 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001727 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001728 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001729 bool sr_enabled = false;
1730
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001731 intel_runtime_pm_get(dev_priv);
1732
Yuanhan Liu13982612010-12-15 15:42:31 +08001733 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001734 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001735 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1736 IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001737 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1738 else if (IS_I915GM(dev))
1739 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1740 else if (IS_PINEVIEW(dev))
1741 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
Ander Conselvan de Oliveira77b64552015-06-02 14:17:47 +03001742 else if (IS_VALLEYVIEW(dev))
1743 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001744
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001745 intel_runtime_pm_put(dev_priv);
1746
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001747 seq_printf(m, "self-refresh: %s\n",
1748 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001749
1750 return 0;
1751}
1752
Jesse Barnes7648fa92010-05-20 14:28:11 -07001753static int i915_emon_status(struct seq_file *m, void *unused)
1754{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001755 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001756 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001757 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001758 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001759 int ret;
1760
Chris Wilson582be6b2012-04-30 19:35:02 +01001761 if (!IS_GEN5(dev))
1762 return -ENODEV;
1763
Chris Wilsonde227ef2010-07-03 07:58:38 +01001764 ret = mutex_lock_interruptible(&dev->struct_mutex);
1765 if (ret)
1766 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001767
1768 temp = i915_mch_val(dev_priv);
1769 chipset = i915_chipset_val(dev_priv);
1770 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001771 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001772
1773 seq_printf(m, "GMCH temp: %ld\n", temp);
1774 seq_printf(m, "Chipset power: %ld\n", chipset);
1775 seq_printf(m, "GFX power: %ld\n", gfx);
1776 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1777
1778 return 0;
1779}
1780
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001781static int i915_ring_freq_table(struct seq_file *m, void *unused)
1782{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001783 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001784 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001785 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001786 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001787 int gpu_freq, ia_freq;
Akash Goelf936ec32015-06-29 14:50:22 +05301788 unsigned int max_gpu_freq, min_gpu_freq;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001789
Akash Goel97d33082015-06-29 14:50:23 +05301790 if (!HAS_CORE_RING_FREQ(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001791 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001792 return 0;
1793 }
1794
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001795 intel_runtime_pm_get(dev_priv);
1796
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001797 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1798
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001799 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001800 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001801 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001802
Akash Goelf936ec32015-06-29 14:50:22 +05301803 if (IS_SKYLAKE(dev)) {
1804 /* Convert GT frequency to 50 HZ units */
1805 min_gpu_freq =
1806 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1807 max_gpu_freq =
1808 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1809 } else {
1810 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1811 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1812 }
1813
Damien Lespiau267f0c92013-06-24 22:59:48 +01001814 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001815
Akash Goelf936ec32015-06-29 14:50:22 +05301816 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001817 ia_freq = gpu_freq;
1818 sandybridge_pcode_read(dev_priv,
1819 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1820 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001821 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Akash Goelf936ec32015-06-29 14:50:22 +05301822 intel_gpu_freq(dev_priv, (gpu_freq *
1823 (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1))),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001824 ((ia_freq >> 0) & 0xff) * 100,
1825 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001826 }
1827
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001828 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001829
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001830out:
1831 intel_runtime_pm_put(dev_priv);
1832 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001833}
1834
Chris Wilson44834a62010-08-19 16:09:23 +01001835static int i915_opregion(struct seq_file *m, void *unused)
1836{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001837 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001838 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001839 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001840 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001841 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001842 int ret;
1843
Daniel Vetter0d38f002012-04-21 22:49:10 +02001844 if (data == NULL)
1845 return -ENOMEM;
1846
Chris Wilson44834a62010-08-19 16:09:23 +01001847 ret = mutex_lock_interruptible(&dev->struct_mutex);
1848 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001849 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001850
Daniel Vetter0d38f002012-04-21 22:49:10 +02001851 if (opregion->header) {
1852 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1853 seq_write(m, data, OPREGION_SIZE);
1854 }
Chris Wilson44834a62010-08-19 16:09:23 +01001855
1856 mutex_unlock(&dev->struct_mutex);
1857
Daniel Vetter0d38f002012-04-21 22:49:10 +02001858out:
1859 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001860 return 0;
1861}
1862
Chris Wilson37811fc2010-08-25 22:45:57 +01001863static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1864{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001865 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001866 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001867 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001868 struct intel_framebuffer *fb;
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001869 struct drm_framebuffer *drm_fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001870
Daniel Vetter4520f532013-10-09 09:18:51 +02001871#ifdef CONFIG_DRM_I915_FBDEV
1872 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001873
1874 ifbdev = dev_priv->fbdev;
1875 fb = to_intel_framebuffer(ifbdev->helper.fb);
1876
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001877 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 +01001878 fb->base.width,
1879 fb->base.height,
1880 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001881 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001882 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001883 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001884 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001885 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001886#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001887
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001888 mutex_lock(&dev->mode_config.fb_lock);
Daniel Vetter3a58ee12015-07-10 19:02:51 +02001889 drm_for_each_fb(drm_fb, dev) {
1890 fb = to_intel_framebuffer(drm_fb);
Daniel Vetter131a56d2013-10-17 14:35:31 +02001891 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001892 continue;
1893
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001894 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 +01001895 fb->base.width,
1896 fb->base.height,
1897 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001898 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001899 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001900 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001901 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001902 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001903 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001904 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001905
1906 return 0;
1907}
1908
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001909static void describe_ctx_ringbuf(struct seq_file *m,
1910 struct intel_ringbuffer *ringbuf)
1911{
1912 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1913 ringbuf->space, ringbuf->head, ringbuf->tail,
1914 ringbuf->last_retired_head);
1915}
1916
Ben Widawskye76d3632011-03-19 18:14:29 -07001917static int i915_context_status(struct seq_file *m, void *unused)
1918{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001919 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001920 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001921 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001922 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001923 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001924 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001925
Daniel Vetterf3d28872014-05-29 23:23:08 +02001926 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001927 if (ret)
1928 return ret;
1929
Ben Widawskya33afea2013-09-17 21:12:45 -07001930 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001931 if (!i915.enable_execlists &&
1932 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001933 continue;
1934
Ben Widawskya33afea2013-09-17 21:12:45 -07001935 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001936 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001937 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001938 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001939 seq_printf(m, "(default context %s) ",
1940 ring->name);
1941 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001942
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001943 if (i915.enable_execlists) {
1944 seq_putc(m, '\n');
1945 for_each_ring(ring, dev_priv, i) {
1946 struct drm_i915_gem_object *ctx_obj =
1947 ctx->engine[i].state;
1948 struct intel_ringbuffer *ringbuf =
1949 ctx->engine[i].ringbuf;
1950
1951 seq_printf(m, "%s: ", ring->name);
1952 if (ctx_obj)
1953 describe_obj(m, ctx_obj);
1954 if (ringbuf)
1955 describe_ctx_ringbuf(m, ringbuf);
1956 seq_putc(m, '\n');
1957 }
1958 } else {
1959 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1960 }
1961
Ben Widawskya33afea2013-09-17 21:12:45 -07001962 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001963 }
1964
Daniel Vetterf3d28872014-05-29 23:23:08 +02001965 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001966
1967 return 0;
1968}
1969
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001970static void i915_dump_lrc_obj(struct seq_file *m,
1971 struct intel_engine_cs *ring,
1972 struct drm_i915_gem_object *ctx_obj)
1973{
1974 struct page *page;
1975 uint32_t *reg_state;
1976 int j;
1977 unsigned long ggtt_offset = 0;
1978
1979 if (ctx_obj == NULL) {
1980 seq_printf(m, "Context on %s with no gem object\n",
1981 ring->name);
1982 return;
1983 }
1984
1985 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1986 intel_execlists_ctx_id(ctx_obj));
1987
1988 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1989 seq_puts(m, "\tNot bound in GGTT\n");
1990 else
1991 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1992
1993 if (i915_gem_object_get_pages(ctx_obj)) {
1994 seq_puts(m, "\tFailed to get pages for context object\n");
1995 return;
1996 }
1997
Alex Daid1675192015-08-12 15:43:43 +01001998 page = i915_gem_object_get_page(ctx_obj, LRC_STATE_PN);
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001999 if (!WARN_ON(page == NULL)) {
2000 reg_state = kmap_atomic(page);
2001
2002 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2003 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2004 ggtt_offset + 4096 + (j * 4),
2005 reg_state[j], reg_state[j + 1],
2006 reg_state[j + 2], reg_state[j + 3]);
2007 }
2008 kunmap_atomic(reg_state);
2009 }
2010
2011 seq_putc(m, '\n');
2012}
2013
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002014static int i915_dump_lrc(struct seq_file *m, void *unused)
2015{
2016 struct drm_info_node *node = (struct drm_info_node *) m->private;
2017 struct drm_device *dev = node->minor->dev;
2018 struct drm_i915_private *dev_priv = dev->dev_private;
2019 struct intel_engine_cs *ring;
2020 struct intel_context *ctx;
2021 int ret, i;
2022
2023 if (!i915.enable_execlists) {
2024 seq_printf(m, "Logical Ring Contexts are disabled\n");
2025 return 0;
2026 }
2027
2028 ret = mutex_lock_interruptible(&dev->struct_mutex);
2029 if (ret)
2030 return ret;
2031
2032 list_for_each_entry(ctx, &dev_priv->context_list, link) {
2033 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00002034 if (ring->default_context != ctx)
2035 i915_dump_lrc_obj(m, ring,
2036 ctx->engine[i].state);
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01002037 }
2038 }
2039
2040 mutex_unlock(&dev->struct_mutex);
2041
2042 return 0;
2043}
2044
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002045static int i915_execlists(struct seq_file *m, void *data)
2046{
2047 struct drm_info_node *node = (struct drm_info_node *)m->private;
2048 struct drm_device *dev = node->minor->dev;
2049 struct drm_i915_private *dev_priv = dev->dev_private;
2050 struct intel_engine_cs *ring;
2051 u32 status_pointer;
2052 u8 read_pointer;
2053 u8 write_pointer;
2054 u32 status;
2055 u32 ctx_id;
2056 struct list_head *cursor;
2057 int ring_id, i;
2058 int ret;
2059
2060 if (!i915.enable_execlists) {
2061 seq_puts(m, "Logical Ring Contexts are disabled\n");
2062 return 0;
2063 }
2064
2065 ret = mutex_lock_interruptible(&dev->struct_mutex);
2066 if (ret)
2067 return ret;
2068
Michel Thierryfc0412e2014-10-16 16:13:38 +01002069 intel_runtime_pm_get(dev_priv);
2070
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002071 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002072 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002073 int count = 0;
2074 unsigned long flags;
2075
2076 seq_printf(m, "%s\n", ring->name);
2077
2078 status = I915_READ(RING_EXECLIST_STATUS(ring));
2079 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
2080 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2081 status, ctx_id);
2082
2083 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2084 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2085
2086 read_pointer = ring->next_context_status_buffer;
2087 write_pointer = status_pointer & 0x07;
2088 if (read_pointer > write_pointer)
2089 write_pointer += 6;
2090 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2091 read_pointer, write_pointer);
2092
2093 for (i = 0; i < 6; i++) {
2094 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
2095 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
2096
2097 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2098 i, status, ctx_id);
2099 }
2100
2101 spin_lock_irqsave(&ring->execlist_lock, flags);
2102 list_for_each(cursor, &ring->execlist_queue)
2103 count++;
2104 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002105 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002106 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2107
2108 seq_printf(m, "\t%d requests in queue\n", count);
2109 if (head_req) {
2110 struct drm_i915_gem_object *ctx_obj;
2111
Nick Hoath6d3d8272015-01-15 13:10:39 +00002112 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002113 seq_printf(m, "\tHead request id: %u\n",
2114 intel_execlists_ctx_id(ctx_obj));
2115 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002116 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002117 }
2118
2119 seq_putc(m, '\n');
2120 }
2121
Michel Thierryfc0412e2014-10-16 16:13:38 +01002122 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002123 mutex_unlock(&dev->struct_mutex);
2124
2125 return 0;
2126}
2127
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002128static const char *swizzle_string(unsigned swizzle)
2129{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002130 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002131 case I915_BIT_6_SWIZZLE_NONE:
2132 return "none";
2133 case I915_BIT_6_SWIZZLE_9:
2134 return "bit9";
2135 case I915_BIT_6_SWIZZLE_9_10:
2136 return "bit9/bit10";
2137 case I915_BIT_6_SWIZZLE_9_11:
2138 return "bit9/bit11";
2139 case I915_BIT_6_SWIZZLE_9_10_11:
2140 return "bit9/bit10/bit11";
2141 case I915_BIT_6_SWIZZLE_9_17:
2142 return "bit9/bit17";
2143 case I915_BIT_6_SWIZZLE_9_10_17:
2144 return "bit9/bit10/bit17";
2145 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002146 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002147 }
2148
2149 return "bug";
2150}
2151
2152static int i915_swizzle_info(struct seq_file *m, void *data)
2153{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002154 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002155 struct drm_device *dev = node->minor->dev;
2156 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002157 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002158
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002159 ret = mutex_lock_interruptible(&dev->struct_mutex);
2160 if (ret)
2161 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002162 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002163
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002164 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2165 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2166 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2167 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2168
2169 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2170 seq_printf(m, "DDC = 0x%08x\n",
2171 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002172 seq_printf(m, "DDC2 = 0x%08x\n",
2173 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002174 seq_printf(m, "C0DRB3 = 0x%04x\n",
2175 I915_READ16(C0DRB3));
2176 seq_printf(m, "C1DRB3 = 0x%04x\n",
2177 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002178 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002179 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2180 I915_READ(MAD_DIMM_C0));
2181 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2182 I915_READ(MAD_DIMM_C1));
2183 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2184 I915_READ(MAD_DIMM_C2));
2185 seq_printf(m, "TILECTL = 0x%08x\n",
2186 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002187 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002188 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2189 I915_READ(GAMTARBMODE));
2190 else
2191 seq_printf(m, "ARB_MODE = 0x%08x\n",
2192 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002193 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2194 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002195 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002196
2197 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2198 seq_puts(m, "L-shaped memory detected\n");
2199
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002200 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002201 mutex_unlock(&dev->struct_mutex);
2202
2203 return 0;
2204}
2205
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002206static int per_file_ctx(int id, void *ptr, void *data)
2207{
Oscar Mateo273497e2014-05-22 14:13:37 +01002208 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002209 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002210 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2211
2212 if (!ppgtt) {
2213 seq_printf(m, " no ppgtt for context %d\n",
2214 ctx->user_handle);
2215 return 0;
2216 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002217
Oscar Mateof83d6512014-05-22 14:13:38 +01002218 if (i915_gem_context_is_default(ctx))
2219 seq_puts(m, " default context:\n");
2220 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002221 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002222 ppgtt->debug_dump(ppgtt, m);
2223
2224 return 0;
2225}
2226
Ben Widawsky77df6772013-11-02 21:07:30 -07002227static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002228{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002229 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002230 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002231 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2232 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002233
Ben Widawsky77df6772013-11-02 21:07:30 -07002234 if (!ppgtt)
2235 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002236
Ben Widawsky77df6772013-11-02 21:07:30 -07002237 for_each_ring(ring, dev_priv, unused) {
2238 seq_printf(m, "%s\n", ring->name);
2239 for (i = 0; i < 4; i++) {
2240 u32 offset = 0x270 + i * 8;
2241 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2242 pdp <<= 32;
2243 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002244 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002245 }
2246 }
2247}
2248
2249static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2250{
2251 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002252 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002253 int i;
2254
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002255 if (INTEL_INFO(dev)->gen == 6)
2256 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2257
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002258 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002259 seq_printf(m, "%s\n", ring->name);
2260 if (INTEL_INFO(dev)->gen == 7)
2261 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2262 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2263 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2264 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2265 }
2266 if (dev_priv->mm.aliasing_ppgtt) {
2267 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2268
Damien Lespiau267f0c92013-06-24 22:59:48 +01002269 seq_puts(m, "aliasing PPGTT:\n");
Mika Kuoppala44159dd2015-06-25 18:35:07 +03002270 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002271
Ben Widawsky87d60b62013-12-06 14:11:29 -08002272 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002273 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002274
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002275 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002276}
2277
2278static int i915_ppgtt_info(struct seq_file *m, void *data)
2279{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002280 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002281 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002282 struct drm_i915_private *dev_priv = dev->dev_private;
Michel Thierryea91e402015-07-29 17:23:57 +01002283 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002284
2285 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2286 if (ret)
2287 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002288 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002289
2290 if (INTEL_INFO(dev)->gen >= 8)
2291 gen8_ppgtt_info(m, dev);
2292 else if (INTEL_INFO(dev)->gen >= 6)
2293 gen6_ppgtt_info(m, dev);
2294
Michel Thierryea91e402015-07-29 17:23:57 +01002295 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2296 struct drm_i915_file_private *file_priv = file->driver_priv;
2297
2298 seq_printf(m, "\nproc: %s\n",
2299 get_pid_task(file->pid, PIDTYPE_PID)->comm);
2300 idr_for_each(&file_priv->context_idr, per_file_ctx,
2301 (void *)(unsigned long)m);
2302 }
2303
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002304 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002305 mutex_unlock(&dev->struct_mutex);
2306
2307 return 0;
2308}
2309
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002310static int count_irq_waiters(struct drm_i915_private *i915)
2311{
2312 struct intel_engine_cs *ring;
2313 int count = 0;
2314 int i;
2315
2316 for_each_ring(ring, i915, i)
2317 count += ring->irq_refcount;
2318
2319 return count;
2320}
2321
Chris Wilson1854d5c2015-04-07 16:20:32 +01002322static int i915_rps_boost_info(struct seq_file *m, void *data)
2323{
2324 struct drm_info_node *node = m->private;
2325 struct drm_device *dev = node->minor->dev;
2326 struct drm_i915_private *dev_priv = dev->dev_private;
2327 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002328
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002329 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2330 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2331 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2332 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2333 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2334 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2335 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2336 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2337 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson8d3afd72015-05-21 21:01:47 +01002338 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002339 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2340 struct drm_i915_file_private *file_priv = file->driver_priv;
2341 struct task_struct *task;
2342
2343 rcu_read_lock();
2344 task = pid_task(file->pid, PIDTYPE_PID);
2345 seq_printf(m, "%s [%d]: %d boosts%s\n",
2346 task ? task->comm : "<unknown>",
2347 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002348 file_priv->rps.boosts,
2349 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002350 rcu_read_unlock();
2351 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002352 seq_printf(m, "Semaphore boosts: %d%s\n",
2353 dev_priv->rps.semaphores.boosts,
2354 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2355 seq_printf(m, "MMIO flip boosts: %d%s\n",
2356 dev_priv->rps.mmioflips.boosts,
2357 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002358 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002359 spin_unlock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002360
Chris Wilson8d3afd72015-05-21 21:01:47 +01002361 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002362}
2363
Ben Widawsky63573eb2013-07-04 11:02:07 -07002364static int i915_llc(struct seq_file *m, void *data)
2365{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002366 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002367 struct drm_device *dev = node->minor->dev;
2368 struct drm_i915_private *dev_priv = dev->dev_private;
2369
2370 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2371 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2372 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2373
2374 return 0;
2375}
2376
Alex Daifdf5d352015-08-12 15:43:37 +01002377static int i915_guc_load_status_info(struct seq_file *m, void *data)
2378{
2379 struct drm_info_node *node = m->private;
2380 struct drm_i915_private *dev_priv = node->minor->dev->dev_private;
2381 struct intel_guc_fw *guc_fw = &dev_priv->guc.guc_fw;
2382 u32 tmp, i;
2383
2384 if (!HAS_GUC_UCODE(dev_priv->dev))
2385 return 0;
2386
2387 seq_printf(m, "GuC firmware status:\n");
2388 seq_printf(m, "\tpath: %s\n",
2389 guc_fw->guc_fw_path);
2390 seq_printf(m, "\tfetch: %s\n",
2391 intel_guc_fw_status_repr(guc_fw->guc_fw_fetch_status));
2392 seq_printf(m, "\tload: %s\n",
2393 intel_guc_fw_status_repr(guc_fw->guc_fw_load_status));
2394 seq_printf(m, "\tversion wanted: %d.%d\n",
2395 guc_fw->guc_fw_major_wanted, guc_fw->guc_fw_minor_wanted);
2396 seq_printf(m, "\tversion found: %d.%d\n",
2397 guc_fw->guc_fw_major_found, guc_fw->guc_fw_minor_found);
2398
2399 tmp = I915_READ(GUC_STATUS);
2400
2401 seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
2402 seq_printf(m, "\tBootrom status = 0x%x\n",
2403 (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
2404 seq_printf(m, "\tuKernel status = 0x%x\n",
2405 (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
2406 seq_printf(m, "\tMIA Core status = 0x%x\n",
2407 (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
2408 seq_puts(m, "\nScratch registers:\n");
2409 for (i = 0; i < 16; i++)
2410 seq_printf(m, "\t%2d: \t0x%x\n", i, I915_READ(SOFT_SCRATCH(i)));
2411
2412 return 0;
2413}
2414
Alex Dai4c7e77f2015-08-12 15:43:40 +01002415static int i915_guc_log_dump(struct seq_file *m, void *data)
2416{
2417 struct drm_info_node *node = m->private;
2418 struct drm_device *dev = node->minor->dev;
2419 struct drm_i915_private *dev_priv = dev->dev_private;
2420 struct drm_i915_gem_object *log_obj = dev_priv->guc.log_obj;
2421 u32 *log;
2422 int i = 0, pg;
2423
2424 if (!log_obj)
2425 return 0;
2426
2427 for (pg = 0; pg < log_obj->base.size / PAGE_SIZE; pg++) {
2428 log = kmap_atomic(i915_gem_object_get_page(log_obj, pg));
2429
2430 for (i = 0; i < PAGE_SIZE / sizeof(u32); i += 4)
2431 seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
2432 *(log + i), *(log + i + 1),
2433 *(log + i + 2), *(log + i + 3));
2434
2435 kunmap_atomic(log);
2436 }
2437
2438 seq_putc(m, '\n');
2439
2440 return 0;
2441}
2442
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002443static int i915_edp_psr_status(struct seq_file *m, void *data)
2444{
2445 struct drm_info_node *node = m->private;
2446 struct drm_device *dev = node->minor->dev;
2447 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002448 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002449 u32 stat[3];
2450 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002451 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002452
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002453 if (!HAS_PSR(dev)) {
2454 seq_puts(m, "PSR not supported\n");
2455 return 0;
2456 }
2457
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002458 intel_runtime_pm_get(dev_priv);
2459
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002460 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002461 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2462 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002463 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002464 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002465 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2466 dev_priv->psr.busy_frontbuffer_bits);
2467 seq_printf(m, "Re-enable work scheduled: %s\n",
2468 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002469
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002470 if (HAS_DDI(dev))
2471 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2472 else {
2473 for_each_pipe(dev_priv, pipe) {
2474 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2475 VLV_EDP_PSR_CURR_STATE_MASK;
2476 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2477 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2478 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002479 }
2480 }
2481 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002482
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002483 if (!HAS_DDI(dev))
2484 for_each_pipe(dev_priv, pipe) {
2485 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2486 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2487 seq_printf(m, " pipe %c", pipe_name(pipe));
2488 }
2489 seq_puts(m, "\n");
2490
2491 /* CHV PSR has no kind of performance counter */
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002492 if (HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002493 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2494 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002495
2496 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2497 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002498 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002499
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002500 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002501 return 0;
2502}
2503
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002504static int i915_sink_crc(struct seq_file *m, void *data)
2505{
2506 struct drm_info_node *node = m->private;
2507 struct drm_device *dev = node->minor->dev;
2508 struct intel_encoder *encoder;
2509 struct intel_connector *connector;
2510 struct intel_dp *intel_dp = NULL;
2511 int ret;
2512 u8 crc[6];
2513
2514 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002515 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002516
2517 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2518 continue;
2519
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002520 if (!connector->base.encoder)
2521 continue;
2522
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002523 encoder = to_intel_encoder(connector->base.encoder);
2524 if (encoder->type != INTEL_OUTPUT_EDP)
2525 continue;
2526
2527 intel_dp = enc_to_intel_dp(&encoder->base);
2528
2529 ret = intel_dp_sink_crc(intel_dp, crc);
2530 if (ret)
2531 goto out;
2532
2533 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2534 crc[0], crc[1], crc[2],
2535 crc[3], crc[4], crc[5]);
2536 goto out;
2537 }
2538 ret = -ENODEV;
2539out:
2540 drm_modeset_unlock_all(dev);
2541 return ret;
2542}
2543
Jesse Barnesec013e72013-08-20 10:29:23 +01002544static int i915_energy_uJ(struct seq_file *m, void *data)
2545{
2546 struct drm_info_node *node = m->private;
2547 struct drm_device *dev = node->minor->dev;
2548 struct drm_i915_private *dev_priv = dev->dev_private;
2549 u64 power;
2550 u32 units;
2551
2552 if (INTEL_INFO(dev)->gen < 6)
2553 return -ENODEV;
2554
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002555 intel_runtime_pm_get(dev_priv);
2556
Jesse Barnesec013e72013-08-20 10:29:23 +01002557 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2558 power = (power & 0x1f00) >> 8;
2559 units = 1000000 / (1 << power); /* convert to uJ */
2560 power = I915_READ(MCH_SECP_NRG_STTS);
2561 power *= units;
2562
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002563 intel_runtime_pm_put(dev_priv);
2564
Jesse Barnesec013e72013-08-20 10:29:23 +01002565 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002566
2567 return 0;
2568}
2569
Damien Lespiau6455c872015-06-04 18:23:57 +01002570static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002571{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002572 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002573 struct drm_device *dev = node->minor->dev;
2574 struct drm_i915_private *dev_priv = dev->dev_private;
2575
Damien Lespiau6455c872015-06-04 18:23:57 +01002576 if (!HAS_RUNTIME_PM(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002577 seq_puts(m, "not supported\n");
2578 return 0;
2579 }
2580
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002581 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002582 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002583 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002584#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002585 seq_printf(m, "Usage count: %d\n",
2586 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002587#else
2588 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2589#endif
Paulo Zanoni371db662013-08-19 13:18:10 -03002590
Jesse Barnesec013e72013-08-20 10:29:23 +01002591 return 0;
2592}
2593
Imre Deak1da51582013-11-25 17:15:35 +02002594static const char *power_domain_str(enum intel_display_power_domain domain)
2595{
2596 switch (domain) {
2597 case POWER_DOMAIN_PIPE_A:
2598 return "PIPE_A";
2599 case POWER_DOMAIN_PIPE_B:
2600 return "PIPE_B";
2601 case POWER_DOMAIN_PIPE_C:
2602 return "PIPE_C";
2603 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2604 return "PIPE_A_PANEL_FITTER";
2605 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2606 return "PIPE_B_PANEL_FITTER";
2607 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2608 return "PIPE_C_PANEL_FITTER";
2609 case POWER_DOMAIN_TRANSCODER_A:
2610 return "TRANSCODER_A";
2611 case POWER_DOMAIN_TRANSCODER_B:
2612 return "TRANSCODER_B";
2613 case POWER_DOMAIN_TRANSCODER_C:
2614 return "TRANSCODER_C";
2615 case POWER_DOMAIN_TRANSCODER_EDP:
2616 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002617 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2618 return "PORT_DDI_A_2_LANES";
2619 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2620 return "PORT_DDI_A_4_LANES";
2621 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2622 return "PORT_DDI_B_2_LANES";
2623 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2624 return "PORT_DDI_B_4_LANES";
2625 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2626 return "PORT_DDI_C_2_LANES";
2627 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2628 return "PORT_DDI_C_4_LANES";
2629 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2630 return "PORT_DDI_D_2_LANES";
2631 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2632 return "PORT_DDI_D_4_LANES";
2633 case POWER_DOMAIN_PORT_DSI:
2634 return "PORT_DSI";
2635 case POWER_DOMAIN_PORT_CRT:
2636 return "PORT_CRT";
2637 case POWER_DOMAIN_PORT_OTHER:
2638 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002639 case POWER_DOMAIN_VGA:
2640 return "VGA";
2641 case POWER_DOMAIN_AUDIO:
2642 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002643 case POWER_DOMAIN_PLLS:
2644 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002645 case POWER_DOMAIN_AUX_A:
2646 return "AUX_A";
2647 case POWER_DOMAIN_AUX_B:
2648 return "AUX_B";
2649 case POWER_DOMAIN_AUX_C:
2650 return "AUX_C";
2651 case POWER_DOMAIN_AUX_D:
2652 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002653 case POWER_DOMAIN_INIT:
2654 return "INIT";
2655 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002656 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002657 return "?";
2658 }
2659}
2660
2661static int i915_power_domain_info(struct seq_file *m, void *unused)
2662{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002663 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002664 struct drm_device *dev = node->minor->dev;
2665 struct drm_i915_private *dev_priv = dev->dev_private;
2666 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2667 int i;
2668
2669 mutex_lock(&power_domains->lock);
2670
2671 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2672 for (i = 0; i < power_domains->power_well_count; i++) {
2673 struct i915_power_well *power_well;
2674 enum intel_display_power_domain power_domain;
2675
2676 power_well = &power_domains->power_wells[i];
2677 seq_printf(m, "%-25s %d\n", power_well->name,
2678 power_well->count);
2679
2680 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2681 power_domain++) {
2682 if (!(BIT(power_domain) & power_well->domains))
2683 continue;
2684
2685 seq_printf(m, " %-23s %d\n",
2686 power_domain_str(power_domain),
2687 power_domains->domain_use_count[power_domain]);
2688 }
2689 }
2690
2691 mutex_unlock(&power_domains->lock);
2692
2693 return 0;
2694}
2695
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002696static void intel_seq_print_mode(struct seq_file *m, int tabs,
2697 struct drm_display_mode *mode)
2698{
2699 int i;
2700
2701 for (i = 0; i < tabs; i++)
2702 seq_putc(m, '\t');
2703
2704 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",
2705 mode->base.id, mode->name,
2706 mode->vrefresh, mode->clock,
2707 mode->hdisplay, mode->hsync_start,
2708 mode->hsync_end, mode->htotal,
2709 mode->vdisplay, mode->vsync_start,
2710 mode->vsync_end, mode->vtotal,
2711 mode->type, mode->flags);
2712}
2713
2714static void intel_encoder_info(struct seq_file *m,
2715 struct intel_crtc *intel_crtc,
2716 struct intel_encoder *intel_encoder)
2717{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002718 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002719 struct drm_device *dev = node->minor->dev;
2720 struct drm_crtc *crtc = &intel_crtc->base;
2721 struct intel_connector *intel_connector;
2722 struct drm_encoder *encoder;
2723
2724 encoder = &intel_encoder->base;
2725 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002726 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002727 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2728 struct drm_connector *connector = &intel_connector->base;
2729 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2730 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002731 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002732 drm_get_connector_status_name(connector->status));
2733 if (connector->status == connector_status_connected) {
2734 struct drm_display_mode *mode = &crtc->mode;
2735 seq_printf(m, ", mode:\n");
2736 intel_seq_print_mode(m, 2, mode);
2737 } else {
2738 seq_putc(m, '\n');
2739 }
2740 }
2741}
2742
2743static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2744{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002745 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002746 struct drm_device *dev = node->minor->dev;
2747 struct drm_crtc *crtc = &intel_crtc->base;
2748 struct intel_encoder *intel_encoder;
2749
Matt Roper5aa8a932014-06-16 10:12:55 -07002750 if (crtc->primary->fb)
2751 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2752 crtc->primary->fb->base.id, crtc->x, crtc->y,
2753 crtc->primary->fb->width, crtc->primary->fb->height);
2754 else
2755 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002756 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2757 intel_encoder_info(m, intel_crtc, intel_encoder);
2758}
2759
2760static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2761{
2762 struct drm_display_mode *mode = panel->fixed_mode;
2763
2764 seq_printf(m, "\tfixed mode:\n");
2765 intel_seq_print_mode(m, 2, mode);
2766}
2767
2768static void intel_dp_info(struct seq_file *m,
2769 struct intel_connector *intel_connector)
2770{
2771 struct intel_encoder *intel_encoder = intel_connector->encoder;
2772 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2773
2774 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2775 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2776 "no");
2777 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2778 intel_panel_info(m, &intel_connector->panel);
2779}
2780
2781static void intel_hdmi_info(struct seq_file *m,
2782 struct intel_connector *intel_connector)
2783{
2784 struct intel_encoder *intel_encoder = intel_connector->encoder;
2785 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2786
2787 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2788 "no");
2789}
2790
2791static void intel_lvds_info(struct seq_file *m,
2792 struct intel_connector *intel_connector)
2793{
2794 intel_panel_info(m, &intel_connector->panel);
2795}
2796
2797static void intel_connector_info(struct seq_file *m,
2798 struct drm_connector *connector)
2799{
2800 struct intel_connector *intel_connector = to_intel_connector(connector);
2801 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002802 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002803
2804 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002805 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002806 drm_get_connector_status_name(connector->status));
2807 if (connector->status == connector_status_connected) {
2808 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2809 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2810 connector->display_info.width_mm,
2811 connector->display_info.height_mm);
2812 seq_printf(m, "\tsubpixel order: %s\n",
2813 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2814 seq_printf(m, "\tCEA rev: %d\n",
2815 connector->display_info.cea_rev);
2816 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002817 if (intel_encoder) {
2818 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2819 intel_encoder->type == INTEL_OUTPUT_EDP)
2820 intel_dp_info(m, intel_connector);
2821 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2822 intel_hdmi_info(m, intel_connector);
2823 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2824 intel_lvds_info(m, intel_connector);
2825 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002826
Jesse Barnesf103fc72014-02-20 12:39:57 -08002827 seq_printf(m, "\tmodes:\n");
2828 list_for_each_entry(mode, &connector->modes, head)
2829 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002830}
2831
Chris Wilson065f2ec2014-03-12 09:13:13 +00002832static bool cursor_active(struct drm_device *dev, int pipe)
2833{
2834 struct drm_i915_private *dev_priv = dev->dev_private;
2835 u32 state;
2836
2837 if (IS_845G(dev) || IS_I865G(dev))
2838 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002839 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002840 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002841
2842 return state;
2843}
2844
2845static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2846{
2847 struct drm_i915_private *dev_priv = dev->dev_private;
2848 u32 pos;
2849
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002850 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002851
2852 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2853 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2854 *x = -*x;
2855
2856 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2857 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2858 *y = -*y;
2859
2860 return cursor_active(dev, pipe);
2861}
2862
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002863static int i915_display_info(struct seq_file *m, void *unused)
2864{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002865 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002866 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002867 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002868 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002869 struct drm_connector *connector;
2870
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002871 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002872 drm_modeset_lock_all(dev);
2873 seq_printf(m, "CRTC info\n");
2874 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002875 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002876 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002877 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002878 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002879
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002880 pipe_config = to_intel_crtc_state(crtc->base.state);
2881
Chris Wilson57127ef2014-07-04 08:20:11 +01002882 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002883 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002884 yesno(pipe_config->base.active),
2885 pipe_config->pipe_src_w, pipe_config->pipe_src_h);
2886 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002887 intel_crtc_info(m, crtc);
2888
Paulo Zanonia23dc652014-04-01 14:55:11 -03002889 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002890 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 +03002891 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08002892 x, y, crtc->base.cursor->state->crtc_w,
2893 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01002894 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002895 }
Daniel Vettercace8412014-05-22 17:56:31 +02002896
2897 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2898 yesno(!crtc->cpu_fifo_underrun_disabled),
2899 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002900 }
2901
2902 seq_printf(m, "\n");
2903 seq_printf(m, "Connector info\n");
2904 seq_printf(m, "--------------\n");
2905 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2906 intel_connector_info(m, connector);
2907 }
2908 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002909 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002910
2911 return 0;
2912}
2913
Ben Widawskye04934c2014-06-30 09:53:42 -07002914static int i915_semaphore_status(struct seq_file *m, void *unused)
2915{
2916 struct drm_info_node *node = (struct drm_info_node *) m->private;
2917 struct drm_device *dev = node->minor->dev;
2918 struct drm_i915_private *dev_priv = dev->dev_private;
2919 struct intel_engine_cs *ring;
2920 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2921 int i, j, ret;
2922
2923 if (!i915_semaphore_is_enabled(dev)) {
2924 seq_puts(m, "Semaphores are disabled\n");
2925 return 0;
2926 }
2927
2928 ret = mutex_lock_interruptible(&dev->struct_mutex);
2929 if (ret)
2930 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002931 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002932
2933 if (IS_BROADWELL(dev)) {
2934 struct page *page;
2935 uint64_t *seqno;
2936
2937 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2938
2939 seqno = (uint64_t *)kmap_atomic(page);
2940 for_each_ring(ring, dev_priv, i) {
2941 uint64_t offset;
2942
2943 seq_printf(m, "%s\n", ring->name);
2944
2945 seq_puts(m, " Last signal:");
2946 for (j = 0; j < num_rings; j++) {
2947 offset = i * I915_NUM_RINGS + j;
2948 seq_printf(m, "0x%08llx (0x%02llx) ",
2949 seqno[offset], offset * 8);
2950 }
2951 seq_putc(m, '\n');
2952
2953 seq_puts(m, " Last wait: ");
2954 for (j = 0; j < num_rings; j++) {
2955 offset = i + (j * I915_NUM_RINGS);
2956 seq_printf(m, "0x%08llx (0x%02llx) ",
2957 seqno[offset], offset * 8);
2958 }
2959 seq_putc(m, '\n');
2960
2961 }
2962 kunmap_atomic(seqno);
2963 } else {
2964 seq_puts(m, " Last signal:");
2965 for_each_ring(ring, dev_priv, i)
2966 for (j = 0; j < num_rings; j++)
2967 seq_printf(m, "0x%08x\n",
2968 I915_READ(ring->semaphore.mbox.signal[j]));
2969 seq_putc(m, '\n');
2970 }
2971
2972 seq_puts(m, "\nSync seqno:\n");
2973 for_each_ring(ring, dev_priv, i) {
2974 for (j = 0; j < num_rings; j++) {
2975 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2976 }
2977 seq_putc(m, '\n');
2978 }
2979 seq_putc(m, '\n');
2980
Paulo Zanoni03872062014-07-09 14:31:57 -03002981 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002982 mutex_unlock(&dev->struct_mutex);
2983 return 0;
2984}
2985
Daniel Vetter728e29d2014-06-25 22:01:53 +03002986static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2987{
2988 struct drm_info_node *node = (struct drm_info_node *) m->private;
2989 struct drm_device *dev = node->minor->dev;
2990 struct drm_i915_private *dev_priv = dev->dev_private;
2991 int i;
2992
2993 drm_modeset_lock_all(dev);
2994 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2995 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2996
2997 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002998 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002999 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03003000 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02003001 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
3002 seq_printf(m, " dpll_md: 0x%08x\n",
3003 pll->config.hw_state.dpll_md);
3004 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
3005 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
3006 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03003007 }
3008 drm_modeset_unlock_all(dev);
3009
3010 return 0;
3011}
3012
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01003013static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01003014{
3015 int i;
3016 int ret;
3017 struct drm_info_node *node = (struct drm_info_node *) m->private;
3018 struct drm_device *dev = node->minor->dev;
3019 struct drm_i915_private *dev_priv = dev->dev_private;
3020
Arun Siluvery888b5992014-08-26 14:44:51 +01003021 ret = mutex_lock_interruptible(&dev->struct_mutex);
3022 if (ret)
3023 return ret;
3024
3025 intel_runtime_pm_get(dev_priv);
3026
Mika Kuoppala72253422014-10-07 17:21:26 +03003027 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
3028 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003029 u32 addr, mask, value, read;
3030 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01003031
Mika Kuoppala72253422014-10-07 17:21:26 +03003032 addr = dev_priv->workarounds.reg[i].addr;
3033 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03003034 value = dev_priv->workarounds.reg[i].value;
3035 read = I915_READ(addr);
3036 ok = (value & mask) == (read & mask);
3037 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
3038 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01003039 }
3040
3041 intel_runtime_pm_put(dev_priv);
3042 mutex_unlock(&dev->struct_mutex);
3043
3044 return 0;
3045}
3046
Damien Lespiauc5511e42014-11-04 17:06:51 +00003047static int i915_ddb_info(struct seq_file *m, void *unused)
3048{
3049 struct drm_info_node *node = m->private;
3050 struct drm_device *dev = node->minor->dev;
3051 struct drm_i915_private *dev_priv = dev->dev_private;
3052 struct skl_ddb_allocation *ddb;
3053 struct skl_ddb_entry *entry;
3054 enum pipe pipe;
3055 int plane;
3056
Damien Lespiau2fcffe12014-12-03 17:33:24 +00003057 if (INTEL_INFO(dev)->gen < 9)
3058 return 0;
3059
Damien Lespiauc5511e42014-11-04 17:06:51 +00003060 drm_modeset_lock_all(dev);
3061
3062 ddb = &dev_priv->wm.skl_hw.ddb;
3063
3064 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
3065
3066 for_each_pipe(dev_priv, pipe) {
3067 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3068
Damien Lespiaudd740782015-02-28 14:54:08 +00003069 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00003070 entry = &ddb->plane[pipe][plane];
3071 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3072 entry->start, entry->end,
3073 skl_ddb_entry_size(entry));
3074 }
3075
3076 entry = &ddb->cursor[pipe];
3077 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3078 entry->end, skl_ddb_entry_size(entry));
3079 }
3080
3081 drm_modeset_unlock_all(dev);
3082
3083 return 0;
3084}
3085
Vandana Kannana54746e2015-03-03 20:53:10 +05303086static void drrs_status_per_crtc(struct seq_file *m,
3087 struct drm_device *dev, struct intel_crtc *intel_crtc)
3088{
3089 struct intel_encoder *intel_encoder;
3090 struct drm_i915_private *dev_priv = dev->dev_private;
3091 struct i915_drrs *drrs = &dev_priv->drrs;
3092 int vrefresh = 0;
3093
3094 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3095 /* Encoder connected on this CRTC */
3096 switch (intel_encoder->type) {
3097 case INTEL_OUTPUT_EDP:
3098 seq_puts(m, "eDP:\n");
3099 break;
3100 case INTEL_OUTPUT_DSI:
3101 seq_puts(m, "DSI:\n");
3102 break;
3103 case INTEL_OUTPUT_HDMI:
3104 seq_puts(m, "HDMI:\n");
3105 break;
3106 case INTEL_OUTPUT_DISPLAYPORT:
3107 seq_puts(m, "DP:\n");
3108 break;
3109 default:
3110 seq_printf(m, "Other encoder (id=%d).\n",
3111 intel_encoder->type);
3112 return;
3113 }
3114 }
3115
3116 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3117 seq_puts(m, "\tVBT: DRRS_type: Static");
3118 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3119 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3120 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3121 seq_puts(m, "\tVBT: DRRS_type: None");
3122 else
3123 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3124
3125 seq_puts(m, "\n\n");
3126
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003127 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303128 struct intel_panel *panel;
3129
3130 mutex_lock(&drrs->mutex);
3131 /* DRRS Supported */
3132 seq_puts(m, "\tDRRS Supported: Yes\n");
3133
3134 /* disable_drrs() will make drrs->dp NULL */
3135 if (!drrs->dp) {
3136 seq_puts(m, "Idleness DRRS: Disabled");
3137 mutex_unlock(&drrs->mutex);
3138 return;
3139 }
3140
3141 panel = &drrs->dp->attached_connector->panel;
3142 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3143 drrs->busy_frontbuffer_bits);
3144
3145 seq_puts(m, "\n\t\t");
3146 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3147 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3148 vrefresh = panel->fixed_mode->vrefresh;
3149 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3150 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3151 vrefresh = panel->downclock_mode->vrefresh;
3152 } else {
3153 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3154 drrs->refresh_rate_type);
3155 mutex_unlock(&drrs->mutex);
3156 return;
3157 }
3158 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3159
3160 seq_puts(m, "\n\t\t");
3161 mutex_unlock(&drrs->mutex);
3162 } else {
3163 /* DRRS not supported. Print the VBT parameter*/
3164 seq_puts(m, "\tDRRS Supported : No");
3165 }
3166 seq_puts(m, "\n");
3167}
3168
3169static int i915_drrs_status(struct seq_file *m, void *unused)
3170{
3171 struct drm_info_node *node = m->private;
3172 struct drm_device *dev = node->minor->dev;
3173 struct intel_crtc *intel_crtc;
3174 int active_crtc_cnt = 0;
3175
3176 for_each_intel_crtc(dev, intel_crtc) {
3177 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3178
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003179 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303180 active_crtc_cnt++;
3181 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3182
3183 drrs_status_per_crtc(m, dev, intel_crtc);
3184 }
3185
3186 drm_modeset_unlock(&intel_crtc->base.mutex);
3187 }
3188
3189 if (!active_crtc_cnt)
3190 seq_puts(m, "No active crtc found\n");
3191
3192 return 0;
3193}
3194
Damien Lespiau07144422013-10-15 18:55:40 +01003195struct pipe_crc_info {
3196 const char *name;
3197 struct drm_device *dev;
3198 enum pipe pipe;
3199};
3200
Dave Airlie11bed952014-05-12 15:22:27 +10003201static int i915_dp_mst_info(struct seq_file *m, void *unused)
3202{
3203 struct drm_info_node *node = (struct drm_info_node *) m->private;
3204 struct drm_device *dev = node->minor->dev;
3205 struct drm_encoder *encoder;
3206 struct intel_encoder *intel_encoder;
3207 struct intel_digital_port *intel_dig_port;
3208 drm_modeset_lock_all(dev);
3209 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3210 intel_encoder = to_intel_encoder(encoder);
3211 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3212 continue;
3213 intel_dig_port = enc_to_dig_port(encoder);
3214 if (!intel_dig_port->dp.can_mst)
3215 continue;
3216
3217 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3218 }
3219 drm_modeset_unlock_all(dev);
3220 return 0;
3221}
3222
Damien Lespiau07144422013-10-15 18:55:40 +01003223static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003224{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003225 struct pipe_crc_info *info = inode->i_private;
3226 struct drm_i915_private *dev_priv = info->dev->dev_private;
3227 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3228
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003229 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3230 return -ENODEV;
3231
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003232 spin_lock_irq(&pipe_crc->lock);
3233
3234 if (pipe_crc->opened) {
3235 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003236 return -EBUSY; /* already open */
3237 }
3238
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003239 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003240 filep->private_data = inode->i_private;
3241
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003242 spin_unlock_irq(&pipe_crc->lock);
3243
Damien Lespiau07144422013-10-15 18:55:40 +01003244 return 0;
3245}
3246
3247static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3248{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003249 struct pipe_crc_info *info = inode->i_private;
3250 struct drm_i915_private *dev_priv = info->dev->dev_private;
3251 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3252
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003253 spin_lock_irq(&pipe_crc->lock);
3254 pipe_crc->opened = false;
3255 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003256
Damien Lespiau07144422013-10-15 18:55:40 +01003257 return 0;
3258}
3259
3260/* (6 fields, 8 chars each, space separated (5) + '\n') */
3261#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3262/* account for \'0' */
3263#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3264
3265static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3266{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003267 assert_spin_locked(&pipe_crc->lock);
3268 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3269 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003270}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003271
Damien Lespiau07144422013-10-15 18:55:40 +01003272static ssize_t
3273i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3274 loff_t *pos)
3275{
3276 struct pipe_crc_info *info = filep->private_data;
3277 struct drm_device *dev = info->dev;
3278 struct drm_i915_private *dev_priv = dev->dev_private;
3279 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3280 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003281 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003282 ssize_t bytes_read;
3283
3284 /*
3285 * Don't allow user space to provide buffers not big enough to hold
3286 * a line of data.
3287 */
3288 if (count < PIPE_CRC_LINE_LEN)
3289 return -EINVAL;
3290
3291 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3292 return 0;
3293
3294 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003295 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003296 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003297 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003298
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003299 if (filep->f_flags & O_NONBLOCK) {
3300 spin_unlock_irq(&pipe_crc->lock);
3301 return -EAGAIN;
3302 }
3303
3304 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3305 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3306 if (ret) {
3307 spin_unlock_irq(&pipe_crc->lock);
3308 return ret;
3309 }
Damien Lespiau07144422013-10-15 18:55:40 +01003310 }
3311
3312 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003313 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003314
Damien Lespiau07144422013-10-15 18:55:40 +01003315 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003316 while (n_entries > 0) {
3317 struct intel_pipe_crc_entry *entry =
3318 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003319 int ret;
3320
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003321 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3322 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3323 break;
3324
3325 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3326 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3327
Damien Lespiau07144422013-10-15 18:55:40 +01003328 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3329 "%8u %8x %8x %8x %8x %8x\n",
3330 entry->frame, entry->crc[0],
3331 entry->crc[1], entry->crc[2],
3332 entry->crc[3], entry->crc[4]);
3333
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003334 spin_unlock_irq(&pipe_crc->lock);
3335
3336 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003337 if (ret == PIPE_CRC_LINE_LEN)
3338 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003339
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003340 user_buf += PIPE_CRC_LINE_LEN;
3341 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003342
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003343 spin_lock_irq(&pipe_crc->lock);
3344 }
3345
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003346 spin_unlock_irq(&pipe_crc->lock);
3347
Damien Lespiau07144422013-10-15 18:55:40 +01003348 return bytes_read;
3349}
3350
3351static const struct file_operations i915_pipe_crc_fops = {
3352 .owner = THIS_MODULE,
3353 .open = i915_pipe_crc_open,
3354 .read = i915_pipe_crc_read,
3355 .release = i915_pipe_crc_release,
3356};
3357
3358static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3359 {
3360 .name = "i915_pipe_A_crc",
3361 .pipe = PIPE_A,
3362 },
3363 {
3364 .name = "i915_pipe_B_crc",
3365 .pipe = PIPE_B,
3366 },
3367 {
3368 .name = "i915_pipe_C_crc",
3369 .pipe = PIPE_C,
3370 },
3371};
3372
3373static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3374 enum pipe pipe)
3375{
3376 struct drm_device *dev = minor->dev;
3377 struct dentry *ent;
3378 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3379
3380 info->dev = dev;
3381 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3382 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003383 if (!ent)
3384 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003385
3386 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003387}
3388
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003389static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003390 "none",
3391 "plane1",
3392 "plane2",
3393 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003394 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003395 "TV",
3396 "DP-B",
3397 "DP-C",
3398 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003399 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003400};
3401
3402static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3403{
3404 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3405 return pipe_crc_sources[source];
3406}
3407
Damien Lespiaubd9db022013-10-15 18:55:36 +01003408static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003409{
3410 struct drm_device *dev = m->private;
3411 struct drm_i915_private *dev_priv = dev->dev_private;
3412 int i;
3413
3414 for (i = 0; i < I915_MAX_PIPES; i++)
3415 seq_printf(m, "%c %s\n", pipe_name(i),
3416 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3417
3418 return 0;
3419}
3420
Damien Lespiaubd9db022013-10-15 18:55:36 +01003421static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003422{
3423 struct drm_device *dev = inode->i_private;
3424
Damien Lespiaubd9db022013-10-15 18:55:36 +01003425 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003426}
3427
Daniel Vetter46a19182013-11-01 10:50:20 +01003428static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003429 uint32_t *val)
3430{
Daniel Vetter46a19182013-11-01 10:50:20 +01003431 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3432 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3433
3434 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003435 case INTEL_PIPE_CRC_SOURCE_PIPE:
3436 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3437 break;
3438 case INTEL_PIPE_CRC_SOURCE_NONE:
3439 *val = 0;
3440 break;
3441 default:
3442 return -EINVAL;
3443 }
3444
3445 return 0;
3446}
3447
Daniel Vetter46a19182013-11-01 10:50:20 +01003448static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3449 enum intel_pipe_crc_source *source)
3450{
3451 struct intel_encoder *encoder;
3452 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003453 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003454 int ret = 0;
3455
3456 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3457
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003458 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003459 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003460 if (!encoder->base.crtc)
3461 continue;
3462
3463 crtc = to_intel_crtc(encoder->base.crtc);
3464
3465 if (crtc->pipe != pipe)
3466 continue;
3467
3468 switch (encoder->type) {
3469 case INTEL_OUTPUT_TVOUT:
3470 *source = INTEL_PIPE_CRC_SOURCE_TV;
3471 break;
3472 case INTEL_OUTPUT_DISPLAYPORT:
3473 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003474 dig_port = enc_to_dig_port(&encoder->base);
3475 switch (dig_port->port) {
3476 case PORT_B:
3477 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3478 break;
3479 case PORT_C:
3480 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3481 break;
3482 case PORT_D:
3483 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3484 break;
3485 default:
3486 WARN(1, "nonexisting DP port %c\n",
3487 port_name(dig_port->port));
3488 break;
3489 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003490 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003491 default:
3492 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003493 }
3494 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003495 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003496
3497 return ret;
3498}
3499
3500static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3501 enum pipe pipe,
3502 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003503 uint32_t *val)
3504{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003505 struct drm_i915_private *dev_priv = dev->dev_private;
3506 bool need_stable_symbols = false;
3507
Daniel Vetter46a19182013-11-01 10:50:20 +01003508 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3509 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3510 if (ret)
3511 return ret;
3512 }
3513
3514 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003515 case INTEL_PIPE_CRC_SOURCE_PIPE:
3516 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3517 break;
3518 case INTEL_PIPE_CRC_SOURCE_DP_B:
3519 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003520 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003521 break;
3522 case INTEL_PIPE_CRC_SOURCE_DP_C:
3523 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003524 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003525 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003526 case INTEL_PIPE_CRC_SOURCE_DP_D:
3527 if (!IS_CHERRYVIEW(dev))
3528 return -EINVAL;
3529 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3530 need_stable_symbols = true;
3531 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003532 case INTEL_PIPE_CRC_SOURCE_NONE:
3533 *val = 0;
3534 break;
3535 default:
3536 return -EINVAL;
3537 }
3538
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003539 /*
3540 * When the pipe CRC tap point is after the transcoders we need
3541 * to tweak symbol-level features to produce a deterministic series of
3542 * symbols for a given frame. We need to reset those features only once
3543 * a frame (instead of every nth symbol):
3544 * - DC-balance: used to ensure a better clock recovery from the data
3545 * link (SDVO)
3546 * - DisplayPort scrambling: used for EMI reduction
3547 */
3548 if (need_stable_symbols) {
3549 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3550
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003551 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003552 switch (pipe) {
3553 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003554 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003555 break;
3556 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003557 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003558 break;
3559 case PIPE_C:
3560 tmp |= PIPE_C_SCRAMBLE_RESET;
3561 break;
3562 default:
3563 return -EINVAL;
3564 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003565 I915_WRITE(PORT_DFT2_G4X, tmp);
3566 }
3567
Daniel Vetter7ac01292013-10-18 16:37:06 +02003568 return 0;
3569}
3570
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003571static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003572 enum pipe pipe,
3573 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003574 uint32_t *val)
3575{
Daniel Vetter84093602013-11-01 10:50:21 +01003576 struct drm_i915_private *dev_priv = dev->dev_private;
3577 bool need_stable_symbols = false;
3578
Daniel Vetter46a19182013-11-01 10:50:20 +01003579 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3580 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3581 if (ret)
3582 return ret;
3583 }
3584
3585 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003586 case INTEL_PIPE_CRC_SOURCE_PIPE:
3587 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3588 break;
3589 case INTEL_PIPE_CRC_SOURCE_TV:
3590 if (!SUPPORTS_TV(dev))
3591 return -EINVAL;
3592 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3593 break;
3594 case INTEL_PIPE_CRC_SOURCE_DP_B:
3595 if (!IS_G4X(dev))
3596 return -EINVAL;
3597 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003598 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003599 break;
3600 case INTEL_PIPE_CRC_SOURCE_DP_C:
3601 if (!IS_G4X(dev))
3602 return -EINVAL;
3603 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003604 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003605 break;
3606 case INTEL_PIPE_CRC_SOURCE_DP_D:
3607 if (!IS_G4X(dev))
3608 return -EINVAL;
3609 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003610 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003611 break;
3612 case INTEL_PIPE_CRC_SOURCE_NONE:
3613 *val = 0;
3614 break;
3615 default:
3616 return -EINVAL;
3617 }
3618
Daniel Vetter84093602013-11-01 10:50:21 +01003619 /*
3620 * When the pipe CRC tap point is after the transcoders we need
3621 * to tweak symbol-level features to produce a deterministic series of
3622 * symbols for a given frame. We need to reset those features only once
3623 * a frame (instead of every nth symbol):
3624 * - DC-balance: used to ensure a better clock recovery from the data
3625 * link (SDVO)
3626 * - DisplayPort scrambling: used for EMI reduction
3627 */
3628 if (need_stable_symbols) {
3629 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3630
3631 WARN_ON(!IS_G4X(dev));
3632
3633 I915_WRITE(PORT_DFT_I9XX,
3634 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3635
3636 if (pipe == PIPE_A)
3637 tmp |= PIPE_A_SCRAMBLE_RESET;
3638 else
3639 tmp |= PIPE_B_SCRAMBLE_RESET;
3640
3641 I915_WRITE(PORT_DFT2_G4X, tmp);
3642 }
3643
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003644 return 0;
3645}
3646
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003647static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3648 enum pipe pipe)
3649{
3650 struct drm_i915_private *dev_priv = dev->dev_private;
3651 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3652
Ville Syrjäläeb736672014-12-09 21:28:28 +02003653 switch (pipe) {
3654 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003655 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003656 break;
3657 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003658 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003659 break;
3660 case PIPE_C:
3661 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3662 break;
3663 default:
3664 return;
3665 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003666 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3667 tmp &= ~DC_BALANCE_RESET_VLV;
3668 I915_WRITE(PORT_DFT2_G4X, tmp);
3669
3670}
3671
Daniel Vetter84093602013-11-01 10:50:21 +01003672static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3673 enum pipe pipe)
3674{
3675 struct drm_i915_private *dev_priv = dev->dev_private;
3676 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3677
3678 if (pipe == PIPE_A)
3679 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3680 else
3681 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3682 I915_WRITE(PORT_DFT2_G4X, tmp);
3683
3684 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3685 I915_WRITE(PORT_DFT_I9XX,
3686 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3687 }
3688}
3689
Daniel Vetter46a19182013-11-01 10:50:20 +01003690static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003691 uint32_t *val)
3692{
Daniel Vetter46a19182013-11-01 10:50:20 +01003693 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3694 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3695
3696 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003697 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3698 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3699 break;
3700 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3701 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3702 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003703 case INTEL_PIPE_CRC_SOURCE_PIPE:
3704 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3705 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003706 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003707 *val = 0;
3708 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003709 default:
3710 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003711 }
3712
3713 return 0;
3714}
3715
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003716static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev, bool enable)
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003717{
3718 struct drm_i915_private *dev_priv = dev->dev_private;
3719 struct intel_crtc *crtc =
3720 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003721 struct intel_crtc_state *pipe_config;
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003722 struct drm_atomic_state *state;
3723 int ret = 0;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003724
3725 drm_modeset_lock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003726 state = drm_atomic_state_alloc(dev);
3727 if (!state) {
3728 ret = -ENOMEM;
3729 goto out;
3730 }
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003731
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003732 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(&crtc->base);
3733 pipe_config = intel_atomic_get_crtc_state(state, crtc);
3734 if (IS_ERR(pipe_config)) {
3735 ret = PTR_ERR(pipe_config);
3736 goto out;
3737 }
3738
3739 pipe_config->pch_pfit.force_thru = enable;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003740 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003741 pipe_config->pch_pfit.enabled != enable)
3742 pipe_config->base.connectors_changed = true;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003743
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003744 ret = drm_atomic_commit(state);
3745out:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003746 drm_modeset_unlock_all(dev);
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003747 WARN(ret, "Toggling workaround to %i returns %i\n", enable, ret);
3748 if (ret)
3749 drm_atomic_state_free(state);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003750}
3751
3752static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3753 enum pipe pipe,
3754 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003755 uint32_t *val)
3756{
Daniel Vetter46a19182013-11-01 10:50:20 +01003757 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3758 *source = INTEL_PIPE_CRC_SOURCE_PF;
3759
3760 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003761 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3762 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3763 break;
3764 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3765 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3766 break;
3767 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003768 if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003769 hsw_trans_edp_pipe_A_crc_wa(dev, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003770
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003771 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3772 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003773 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003774 *val = 0;
3775 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003776 default:
3777 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003778 }
3779
3780 return 0;
3781}
3782
Daniel Vetter926321d2013-10-16 13:30:34 +02003783static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3784 enum intel_pipe_crc_source source)
3785{
3786 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003787 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003788 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3789 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003790 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003791 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003792
Damien Lespiaucc3da172013-10-15 18:55:31 +01003793 if (pipe_crc->source == source)
3794 return 0;
3795
Damien Lespiauae676fc2013-10-15 18:55:32 +01003796 /* forbid changing the source without going back to 'none' */
3797 if (pipe_crc->source && source)
3798 return -EINVAL;
3799
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003800 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3801 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3802 return -EIO;
3803 }
3804
Daniel Vetter52f843f2013-10-21 17:26:38 +02003805 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003806 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003807 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003808 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003809 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003810 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003811 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003812 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003813 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003814 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003815
3816 if (ret != 0)
3817 return ret;
3818
Damien Lespiau4b584362013-10-15 18:55:33 +01003819 /* none -> real source transition */
3820 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003821 struct intel_pipe_crc_entry *entries;
3822
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003823 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3824 pipe_name(pipe), pipe_crc_source_name(source));
3825
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003826 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3827 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003828 GFP_KERNEL);
3829 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003830 return -ENOMEM;
3831
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003832 /*
3833 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3834 * enabled and disabled dynamically based on package C states,
3835 * user space can't make reliable use of the CRCs, so let's just
3836 * completely disable it.
3837 */
3838 hsw_disable_ips(crtc);
3839
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003840 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003841 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003842 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003843 pipe_crc->head = 0;
3844 pipe_crc->tail = 0;
3845 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003846 }
3847
Damien Lespiaucc3da172013-10-15 18:55:31 +01003848 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003849
Daniel Vetter926321d2013-10-16 13:30:34 +02003850 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3851 POSTING_READ(PIPE_CRC_CTL(pipe));
3852
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003853 /* real source -> none transition */
3854 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003855 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003856 struct intel_crtc *crtc =
3857 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003858
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003859 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3860 pipe_name(pipe));
3861
Daniel Vettera33d7102014-06-06 08:22:08 +02003862 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003863 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02003864 intel_wait_for_vblank(dev, pipe);
3865 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003866
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003867 spin_lock_irq(&pipe_crc->lock);
3868 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003869 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003870 pipe_crc->head = 0;
3871 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003872 spin_unlock_irq(&pipe_crc->lock);
3873
3874 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003875
3876 if (IS_G4X(dev))
3877 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003878 else if (IS_VALLEYVIEW(dev))
3879 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003880 else if (IS_HASWELL(dev) && pipe == PIPE_A)
Maarten Lankhorstc4e2d042015-08-05 12:36:59 +02003881 hsw_trans_edp_pipe_A_crc_wa(dev, false);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003882
3883 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003884 }
3885
Daniel Vetter926321d2013-10-16 13:30:34 +02003886 return 0;
3887}
3888
3889/*
3890 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003891 * command: wsp* object wsp+ name wsp+ source wsp*
3892 * object: 'pipe'
3893 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003894 * source: (none | plane1 | plane2 | pf)
3895 * wsp: (#0x20 | #0x9 | #0xA)+
3896 *
3897 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003898 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3899 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003900 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003901static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003902{
3903 int n_words = 0;
3904
3905 while (*buf) {
3906 char *end;
3907
3908 /* skip leading white space */
3909 buf = skip_spaces(buf);
3910 if (!*buf)
3911 break; /* end of buffer */
3912
3913 /* find end of word */
3914 for (end = buf; *end && !isspace(*end); end++)
3915 ;
3916
3917 if (n_words == max_words) {
3918 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3919 max_words);
3920 return -EINVAL; /* ran out of words[] before bytes */
3921 }
3922
3923 if (*end)
3924 *end++ = '\0';
3925 words[n_words++] = buf;
3926 buf = end;
3927 }
3928
3929 return n_words;
3930}
3931
Damien Lespiaub94dec82013-10-15 18:55:35 +01003932enum intel_pipe_crc_object {
3933 PIPE_CRC_OBJECT_PIPE,
3934};
3935
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003936static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003937 "pipe",
3938};
3939
3940static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003941display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003942{
3943 int i;
3944
3945 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3946 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003947 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003948 return 0;
3949 }
3950
3951 return -EINVAL;
3952}
3953
Damien Lespiaubd9db022013-10-15 18:55:36 +01003954static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003955{
3956 const char name = buf[0];
3957
3958 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3959 return -EINVAL;
3960
3961 *pipe = name - 'A';
3962
3963 return 0;
3964}
3965
3966static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003967display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003968{
3969 int i;
3970
3971 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3972 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003973 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003974 return 0;
3975 }
3976
3977 return -EINVAL;
3978}
3979
Damien Lespiaubd9db022013-10-15 18:55:36 +01003980static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003981{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003982#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003983 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003984 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003985 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003986 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003987 enum intel_pipe_crc_source source;
3988
Damien Lespiaubd9db022013-10-15 18:55:36 +01003989 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003990 if (n_words != N_WORDS) {
3991 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3992 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003993 return -EINVAL;
3994 }
3995
Damien Lespiaubd9db022013-10-15 18:55:36 +01003996 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003997 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003998 return -EINVAL;
3999 }
4000
Damien Lespiaubd9db022013-10-15 18:55:36 +01004001 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004002 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
4003 return -EINVAL;
4004 }
4005
Damien Lespiaubd9db022013-10-15 18:55:36 +01004006 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01004007 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02004008 return -EINVAL;
4009 }
4010
4011 return pipe_crc_set_source(dev, pipe, source);
4012}
4013
Damien Lespiaubd9db022013-10-15 18:55:36 +01004014static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
4015 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02004016{
4017 struct seq_file *m = file->private_data;
4018 struct drm_device *dev = m->private;
4019 char *tmpbuf;
4020 int ret;
4021
4022 if (len == 0)
4023 return 0;
4024
4025 if (len > PAGE_SIZE - 1) {
4026 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
4027 PAGE_SIZE);
4028 return -E2BIG;
4029 }
4030
4031 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
4032 if (!tmpbuf)
4033 return -ENOMEM;
4034
4035 if (copy_from_user(tmpbuf, ubuf, len)) {
4036 ret = -EFAULT;
4037 goto out;
4038 }
4039 tmpbuf[len] = '\0';
4040
Damien Lespiaubd9db022013-10-15 18:55:36 +01004041 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02004042
4043out:
4044 kfree(tmpbuf);
4045 if (ret < 0)
4046 return ret;
4047
4048 *offp += len;
4049 return len;
4050}
4051
Damien Lespiaubd9db022013-10-15 18:55:36 +01004052static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02004053 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004054 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02004055 .read = seq_read,
4056 .llseek = seq_lseek,
4057 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01004058 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02004059};
4060
Todd Previteeb3394fa2015-04-18 00:04:19 -07004061static ssize_t i915_displayport_test_active_write(struct file *file,
4062 const char __user *ubuf,
4063 size_t len, loff_t *offp)
4064{
4065 char *input_buffer;
4066 int status = 0;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004067 struct drm_device *dev;
4068 struct drm_connector *connector;
4069 struct list_head *connector_list;
4070 struct intel_dp *intel_dp;
4071 int val = 0;
4072
Sudip Mukherjee9aaffa32015-07-21 17:36:45 +05304073 dev = ((struct seq_file *)file->private_data)->private;
Todd Previteeb3394fa2015-04-18 00:04:19 -07004074
Todd Previteeb3394fa2015-04-18 00:04:19 -07004075 connector_list = &dev->mode_config.connector_list;
4076
4077 if (len == 0)
4078 return 0;
4079
4080 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4081 if (!input_buffer)
4082 return -ENOMEM;
4083
4084 if (copy_from_user(input_buffer, ubuf, len)) {
4085 status = -EFAULT;
4086 goto out;
4087 }
4088
4089 input_buffer[len] = '\0';
4090 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4091
4092 list_for_each_entry(connector, connector_list, head) {
4093
4094 if (connector->connector_type !=
4095 DRM_MODE_CONNECTOR_DisplayPort)
4096 continue;
4097
Sudip Mukherjeeb8bb08e2015-07-21 17:36:46 +05304098 if (connector->status == connector_status_connected &&
Todd Previteeb3394fa2015-04-18 00:04:19 -07004099 connector->encoder != NULL) {
4100 intel_dp = enc_to_intel_dp(connector->encoder);
4101 status = kstrtoint(input_buffer, 10, &val);
4102 if (status < 0)
4103 goto out;
4104 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4105 /* To prevent erroneous activation of the compliance
4106 * testing code, only accept an actual value of 1 here
4107 */
4108 if (val == 1)
4109 intel_dp->compliance_test_active = 1;
4110 else
4111 intel_dp->compliance_test_active = 0;
4112 }
4113 }
4114out:
4115 kfree(input_buffer);
4116 if (status < 0)
4117 return status;
4118
4119 *offp += len;
4120 return len;
4121}
4122
4123static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4124{
4125 struct drm_device *dev = m->private;
4126 struct drm_connector *connector;
4127 struct list_head *connector_list = &dev->mode_config.connector_list;
4128 struct intel_dp *intel_dp;
4129
Todd Previteeb3394fa2015-04-18 00:04:19 -07004130 list_for_each_entry(connector, connector_list, head) {
4131
4132 if (connector->connector_type !=
4133 DRM_MODE_CONNECTOR_DisplayPort)
4134 continue;
4135
4136 if (connector->status == connector_status_connected &&
4137 connector->encoder != NULL) {
4138 intel_dp = enc_to_intel_dp(connector->encoder);
4139 if (intel_dp->compliance_test_active)
4140 seq_puts(m, "1");
4141 else
4142 seq_puts(m, "0");
4143 } else
4144 seq_puts(m, "0");
4145 }
4146
4147 return 0;
4148}
4149
4150static int i915_displayport_test_active_open(struct inode *inode,
4151 struct file *file)
4152{
4153 struct drm_device *dev = inode->i_private;
4154
4155 return single_open(file, i915_displayport_test_active_show, dev);
4156}
4157
4158static const struct file_operations i915_displayport_test_active_fops = {
4159 .owner = THIS_MODULE,
4160 .open = i915_displayport_test_active_open,
4161 .read = seq_read,
4162 .llseek = seq_lseek,
4163 .release = single_release,
4164 .write = i915_displayport_test_active_write
4165};
4166
4167static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4168{
4169 struct drm_device *dev = m->private;
4170 struct drm_connector *connector;
4171 struct list_head *connector_list = &dev->mode_config.connector_list;
4172 struct intel_dp *intel_dp;
4173
Todd Previteeb3394fa2015-04-18 00:04:19 -07004174 list_for_each_entry(connector, connector_list, head) {
4175
4176 if (connector->connector_type !=
4177 DRM_MODE_CONNECTOR_DisplayPort)
4178 continue;
4179
4180 if (connector->status == connector_status_connected &&
4181 connector->encoder != NULL) {
4182 intel_dp = enc_to_intel_dp(connector->encoder);
4183 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4184 } else
4185 seq_puts(m, "0");
4186 }
4187
4188 return 0;
4189}
4190static int i915_displayport_test_data_open(struct inode *inode,
4191 struct file *file)
4192{
4193 struct drm_device *dev = inode->i_private;
4194
4195 return single_open(file, i915_displayport_test_data_show, dev);
4196}
4197
4198static const struct file_operations i915_displayport_test_data_fops = {
4199 .owner = THIS_MODULE,
4200 .open = i915_displayport_test_data_open,
4201 .read = seq_read,
4202 .llseek = seq_lseek,
4203 .release = single_release
4204};
4205
4206static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4207{
4208 struct drm_device *dev = m->private;
4209 struct drm_connector *connector;
4210 struct list_head *connector_list = &dev->mode_config.connector_list;
4211 struct intel_dp *intel_dp;
4212
Todd Previteeb3394fa2015-04-18 00:04:19 -07004213 list_for_each_entry(connector, connector_list, head) {
4214
4215 if (connector->connector_type !=
4216 DRM_MODE_CONNECTOR_DisplayPort)
4217 continue;
4218
4219 if (connector->status == connector_status_connected &&
4220 connector->encoder != NULL) {
4221 intel_dp = enc_to_intel_dp(connector->encoder);
4222 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4223 } else
4224 seq_puts(m, "0");
4225 }
4226
4227 return 0;
4228}
4229
4230static int i915_displayport_test_type_open(struct inode *inode,
4231 struct file *file)
4232{
4233 struct drm_device *dev = inode->i_private;
4234
4235 return single_open(file, i915_displayport_test_type_show, dev);
4236}
4237
4238static const struct file_operations i915_displayport_test_type_fops = {
4239 .owner = THIS_MODULE,
4240 .open = i915_displayport_test_type_open,
4241 .read = seq_read,
4242 .llseek = seq_lseek,
4243 .release = single_release
4244};
4245
Damien Lespiau97e94b22014-11-04 17:06:50 +00004246static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004247{
4248 struct drm_device *dev = m->private;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004249 int level;
Ville Syrjäläde38b952015-06-24 22:00:09 +03004250 int num_levels;
4251
4252 if (IS_CHERRYVIEW(dev))
4253 num_levels = 3;
4254 else if (IS_VALLEYVIEW(dev))
4255 num_levels = 1;
4256 else
4257 num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004258
4259 drm_modeset_lock_all(dev);
4260
4261 for (level = 0; level < num_levels; level++) {
4262 unsigned int latency = wm[level];
4263
Damien Lespiau97e94b22014-11-04 17:06:50 +00004264 /*
4265 * - WM1+ latency values in 0.5us units
Ville Syrjäläde38b952015-06-24 22:00:09 +03004266 * - latencies are in us on gen9/vlv/chv
Damien Lespiau97e94b22014-11-04 17:06:50 +00004267 */
Ville Syrjäläde38b952015-06-24 22:00:09 +03004268 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev))
Damien Lespiau97e94b22014-11-04 17:06:50 +00004269 latency *= 10;
4270 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004271 latency *= 5;
4272
4273 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004274 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004275 }
4276
4277 drm_modeset_unlock_all(dev);
4278}
4279
4280static int pri_wm_latency_show(struct seq_file *m, void *data)
4281{
4282 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004283 struct drm_i915_private *dev_priv = dev->dev_private;
4284 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004285
Damien Lespiau97e94b22014-11-04 17:06:50 +00004286 if (INTEL_INFO(dev)->gen >= 9)
4287 latencies = dev_priv->wm.skl_latency;
4288 else
4289 latencies = to_i915(dev)->wm.pri_latency;
4290
4291 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004292
4293 return 0;
4294}
4295
4296static int spr_wm_latency_show(struct seq_file *m, void *data)
4297{
4298 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004299 struct drm_i915_private *dev_priv = dev->dev_private;
4300 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004301
Damien Lespiau97e94b22014-11-04 17:06:50 +00004302 if (INTEL_INFO(dev)->gen >= 9)
4303 latencies = dev_priv->wm.skl_latency;
4304 else
4305 latencies = to_i915(dev)->wm.spr_latency;
4306
4307 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004308
4309 return 0;
4310}
4311
4312static int cur_wm_latency_show(struct seq_file *m, void *data)
4313{
4314 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004315 struct drm_i915_private *dev_priv = dev->dev_private;
4316 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004317
Damien Lespiau97e94b22014-11-04 17:06:50 +00004318 if (INTEL_INFO(dev)->gen >= 9)
4319 latencies = dev_priv->wm.skl_latency;
4320 else
4321 latencies = to_i915(dev)->wm.cur_latency;
4322
4323 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004324
4325 return 0;
4326}
4327
4328static int pri_wm_latency_open(struct inode *inode, struct file *file)
4329{
4330 struct drm_device *dev = inode->i_private;
4331
Ville Syrjäläde38b952015-06-24 22:00:09 +03004332 if (INTEL_INFO(dev)->gen < 5)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004333 return -ENODEV;
4334
4335 return single_open(file, pri_wm_latency_show, dev);
4336}
4337
4338static int spr_wm_latency_open(struct inode *inode, struct file *file)
4339{
4340 struct drm_device *dev = inode->i_private;
4341
Sonika Jindal9ad02572014-07-21 15:23:39 +05304342 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004343 return -ENODEV;
4344
4345 return single_open(file, spr_wm_latency_show, dev);
4346}
4347
4348static int cur_wm_latency_open(struct inode *inode, struct file *file)
4349{
4350 struct drm_device *dev = inode->i_private;
4351
Sonika Jindal9ad02572014-07-21 15:23:39 +05304352 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004353 return -ENODEV;
4354
4355 return single_open(file, cur_wm_latency_show, dev);
4356}
4357
4358static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004359 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004360{
4361 struct seq_file *m = file->private_data;
4362 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004363 uint16_t new[8] = { 0 };
Ville Syrjäläde38b952015-06-24 22:00:09 +03004364 int num_levels;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004365 int level;
4366 int ret;
4367 char tmp[32];
4368
Ville Syrjäläde38b952015-06-24 22:00:09 +03004369 if (IS_CHERRYVIEW(dev))
4370 num_levels = 3;
4371 else if (IS_VALLEYVIEW(dev))
4372 num_levels = 1;
4373 else
4374 num_levels = ilk_wm_max_level(dev) + 1;
4375
Ville Syrjälä369a1342014-01-22 14:36:08 +02004376 if (len >= sizeof(tmp))
4377 return -EINVAL;
4378
4379 if (copy_from_user(tmp, ubuf, len))
4380 return -EFAULT;
4381
4382 tmp[len] = '\0';
4383
Damien Lespiau97e94b22014-11-04 17:06:50 +00004384 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4385 &new[0], &new[1], &new[2], &new[3],
4386 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004387 if (ret != num_levels)
4388 return -EINVAL;
4389
4390 drm_modeset_lock_all(dev);
4391
4392 for (level = 0; level < num_levels; level++)
4393 wm[level] = new[level];
4394
4395 drm_modeset_unlock_all(dev);
4396
4397 return len;
4398}
4399
4400
4401static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4402 size_t len, loff_t *offp)
4403{
4404 struct seq_file *m = file->private_data;
4405 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004406 struct drm_i915_private *dev_priv = dev->dev_private;
4407 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004408
Damien Lespiau97e94b22014-11-04 17:06:50 +00004409 if (INTEL_INFO(dev)->gen >= 9)
4410 latencies = dev_priv->wm.skl_latency;
4411 else
4412 latencies = to_i915(dev)->wm.pri_latency;
4413
4414 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004415}
4416
4417static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4418 size_t len, loff_t *offp)
4419{
4420 struct seq_file *m = file->private_data;
4421 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004422 struct drm_i915_private *dev_priv = dev->dev_private;
4423 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004424
Damien Lespiau97e94b22014-11-04 17:06:50 +00004425 if (INTEL_INFO(dev)->gen >= 9)
4426 latencies = dev_priv->wm.skl_latency;
4427 else
4428 latencies = to_i915(dev)->wm.spr_latency;
4429
4430 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004431}
4432
4433static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4434 size_t len, loff_t *offp)
4435{
4436 struct seq_file *m = file->private_data;
4437 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004438 struct drm_i915_private *dev_priv = dev->dev_private;
4439 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004440
Damien Lespiau97e94b22014-11-04 17:06:50 +00004441 if (INTEL_INFO(dev)->gen >= 9)
4442 latencies = dev_priv->wm.skl_latency;
4443 else
4444 latencies = to_i915(dev)->wm.cur_latency;
4445
4446 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004447}
4448
4449static const struct file_operations i915_pri_wm_latency_fops = {
4450 .owner = THIS_MODULE,
4451 .open = pri_wm_latency_open,
4452 .read = seq_read,
4453 .llseek = seq_lseek,
4454 .release = single_release,
4455 .write = pri_wm_latency_write
4456};
4457
4458static const struct file_operations i915_spr_wm_latency_fops = {
4459 .owner = THIS_MODULE,
4460 .open = spr_wm_latency_open,
4461 .read = seq_read,
4462 .llseek = seq_lseek,
4463 .release = single_release,
4464 .write = spr_wm_latency_write
4465};
4466
4467static const struct file_operations i915_cur_wm_latency_fops = {
4468 .owner = THIS_MODULE,
4469 .open = cur_wm_latency_open,
4470 .read = seq_read,
4471 .llseek = seq_lseek,
4472 .release = single_release,
4473 .write = cur_wm_latency_write
4474};
4475
Kees Cook647416f2013-03-10 14:10:06 -07004476static int
4477i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004478{
Kees Cook647416f2013-03-10 14:10:06 -07004479 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004480 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004481
Kees Cook647416f2013-03-10 14:10:06 -07004482 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004483
Kees Cook647416f2013-03-10 14:10:06 -07004484 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004485}
4486
Kees Cook647416f2013-03-10 14:10:06 -07004487static int
4488i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004489{
Kees Cook647416f2013-03-10 14:10:06 -07004490 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004491 struct drm_i915_private *dev_priv = dev->dev_private;
4492
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004493 /*
4494 * There is no safeguard against this debugfs entry colliding
4495 * with the hangcheck calling same i915_handle_error() in
4496 * parallel, causing an explosion. For now we assume that the
4497 * test harness is responsible enough not to inject gpu hangs
4498 * while it is writing to 'i915_wedged'
4499 */
4500
4501 if (i915_reset_in_progress(&dev_priv->gpu_error))
4502 return -EAGAIN;
4503
Imre Deakd46c0512014-04-14 20:24:27 +03004504 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004505
Mika Kuoppala58174462014-02-25 17:11:26 +02004506 i915_handle_error(dev, val,
4507 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004508
4509 intel_runtime_pm_put(dev_priv);
4510
Kees Cook647416f2013-03-10 14:10:06 -07004511 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004512}
4513
Kees Cook647416f2013-03-10 14:10:06 -07004514DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4515 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004516 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004517
Kees Cook647416f2013-03-10 14:10:06 -07004518static int
4519i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004520{
Kees Cook647416f2013-03-10 14:10:06 -07004521 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004522 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004523
Kees Cook647416f2013-03-10 14:10:06 -07004524 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004525
Kees Cook647416f2013-03-10 14:10:06 -07004526 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004527}
4528
Kees Cook647416f2013-03-10 14:10:06 -07004529static int
4530i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004531{
Kees Cook647416f2013-03-10 14:10:06 -07004532 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004533 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004534 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004535
Kees Cook647416f2013-03-10 14:10:06 -07004536 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004537
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004538 ret = mutex_lock_interruptible(&dev->struct_mutex);
4539 if (ret)
4540 return ret;
4541
Daniel Vetter99584db2012-11-14 17:14:04 +01004542 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004543 mutex_unlock(&dev->struct_mutex);
4544
Kees Cook647416f2013-03-10 14:10:06 -07004545 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004546}
4547
Kees Cook647416f2013-03-10 14:10:06 -07004548DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4549 i915_ring_stop_get, i915_ring_stop_set,
4550 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004551
Chris Wilson094f9a52013-09-25 17:34:55 +01004552static int
4553i915_ring_missed_irq_get(void *data, u64 *val)
4554{
4555 struct drm_device *dev = data;
4556 struct drm_i915_private *dev_priv = dev->dev_private;
4557
4558 *val = dev_priv->gpu_error.missed_irq_rings;
4559 return 0;
4560}
4561
4562static int
4563i915_ring_missed_irq_set(void *data, u64 val)
4564{
4565 struct drm_device *dev = data;
4566 struct drm_i915_private *dev_priv = dev->dev_private;
4567 int ret;
4568
4569 /* Lock against concurrent debugfs callers */
4570 ret = mutex_lock_interruptible(&dev->struct_mutex);
4571 if (ret)
4572 return ret;
4573 dev_priv->gpu_error.missed_irq_rings = val;
4574 mutex_unlock(&dev->struct_mutex);
4575
4576 return 0;
4577}
4578
4579DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4580 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4581 "0x%08llx\n");
4582
4583static int
4584i915_ring_test_irq_get(void *data, u64 *val)
4585{
4586 struct drm_device *dev = data;
4587 struct drm_i915_private *dev_priv = dev->dev_private;
4588
4589 *val = dev_priv->gpu_error.test_irq_rings;
4590
4591 return 0;
4592}
4593
4594static int
4595i915_ring_test_irq_set(void *data, u64 val)
4596{
4597 struct drm_device *dev = data;
4598 struct drm_i915_private *dev_priv = dev->dev_private;
4599 int ret;
4600
4601 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4602
4603 /* Lock against concurrent debugfs callers */
4604 ret = mutex_lock_interruptible(&dev->struct_mutex);
4605 if (ret)
4606 return ret;
4607
4608 dev_priv->gpu_error.test_irq_rings = val;
4609 mutex_unlock(&dev->struct_mutex);
4610
4611 return 0;
4612}
4613
4614DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4615 i915_ring_test_irq_get, i915_ring_test_irq_set,
4616 "0x%08llx\n");
4617
Chris Wilsondd624af2013-01-15 12:39:35 +00004618#define DROP_UNBOUND 0x1
4619#define DROP_BOUND 0x2
4620#define DROP_RETIRE 0x4
4621#define DROP_ACTIVE 0x8
4622#define DROP_ALL (DROP_UNBOUND | \
4623 DROP_BOUND | \
4624 DROP_RETIRE | \
4625 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004626static int
4627i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004628{
Kees Cook647416f2013-03-10 14:10:06 -07004629 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004630
Kees Cook647416f2013-03-10 14:10:06 -07004631 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004632}
4633
Kees Cook647416f2013-03-10 14:10:06 -07004634static int
4635i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004636{
Kees Cook647416f2013-03-10 14:10:06 -07004637 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004638 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004639 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004640
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004641 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004642
4643 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4644 * on ioctls on -EAGAIN. */
4645 ret = mutex_lock_interruptible(&dev->struct_mutex);
4646 if (ret)
4647 return ret;
4648
4649 if (val & DROP_ACTIVE) {
4650 ret = i915_gpu_idle(dev);
4651 if (ret)
4652 goto unlock;
4653 }
4654
4655 if (val & (DROP_RETIRE | DROP_ACTIVE))
4656 i915_gem_retire_requests(dev);
4657
Chris Wilson21ab4e72014-09-09 11:16:08 +01004658 if (val & DROP_BOUND)
4659 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004660
Chris Wilson21ab4e72014-09-09 11:16:08 +01004661 if (val & DROP_UNBOUND)
4662 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004663
4664unlock:
4665 mutex_unlock(&dev->struct_mutex);
4666
Kees Cook647416f2013-03-10 14:10:06 -07004667 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004668}
4669
Kees Cook647416f2013-03-10 14:10:06 -07004670DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4671 i915_drop_caches_get, i915_drop_caches_set,
4672 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004673
Kees Cook647416f2013-03-10 14:10:06 -07004674static int
4675i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004676{
Kees Cook647416f2013-03-10 14:10:06 -07004677 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004678 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004679 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004680
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004681 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004682 return -ENODEV;
4683
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004684 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4685
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004686 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004687 if (ret)
4688 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004689
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004690 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004691 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004692
Kees Cook647416f2013-03-10 14:10:06 -07004693 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004694}
4695
Kees Cook647416f2013-03-10 14:10:06 -07004696static int
4697i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004698{
Kees Cook647416f2013-03-10 14:10:06 -07004699 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004700 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304701 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004702 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004703
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004704 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004705 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004706
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004707 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4708
Kees Cook647416f2013-03-10 14:10:06 -07004709 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004710
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004711 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004712 if (ret)
4713 return ret;
4714
Jesse Barnes358733e2011-07-27 11:53:01 -07004715 /*
4716 * Turbo will still be enabled, but won't go above the set value.
4717 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304718 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004719
Akash Goelbc4d91f2015-02-26 16:09:47 +05304720 hw_max = dev_priv->rps.max_freq;
4721 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004722
Ben Widawskyb39fb292014-03-19 18:31:11 -07004723 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004724 mutex_unlock(&dev_priv->rps.hw_lock);
4725 return -EINVAL;
4726 }
4727
Ben Widawskyb39fb292014-03-19 18:31:11 -07004728 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004729
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004730 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004731
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004732 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004733
Kees Cook647416f2013-03-10 14:10:06 -07004734 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004735}
4736
Kees Cook647416f2013-03-10 14:10:06 -07004737DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4738 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004739 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004740
Kees Cook647416f2013-03-10 14:10:06 -07004741static int
4742i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004743{
Kees Cook647416f2013-03-10 14:10:06 -07004744 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004745 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004746 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004747
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004748 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004749 return -ENODEV;
4750
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004751 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4752
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004753 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004754 if (ret)
4755 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004756
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004757 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004758 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004759
Kees Cook647416f2013-03-10 14:10:06 -07004760 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004761}
4762
Kees Cook647416f2013-03-10 14:10:06 -07004763static int
4764i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004765{
Kees Cook647416f2013-03-10 14:10:06 -07004766 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004767 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304768 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004769 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004770
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004771 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004772 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004773
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004774 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4775
Kees Cook647416f2013-03-10 14:10:06 -07004776 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004777
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004778 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004779 if (ret)
4780 return ret;
4781
Jesse Barnes1523c312012-05-25 12:34:54 -07004782 /*
4783 * Turbo will still be enabled, but won't go below the set value.
4784 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304785 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004786
Akash Goelbc4d91f2015-02-26 16:09:47 +05304787 hw_max = dev_priv->rps.max_freq;
4788 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004789
Ben Widawskyb39fb292014-03-19 18:31:11 -07004790 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004791 mutex_unlock(&dev_priv->rps.hw_lock);
4792 return -EINVAL;
4793 }
4794
Ben Widawskyb39fb292014-03-19 18:31:11 -07004795 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004796
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004797 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004798
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004799 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004800
Kees Cook647416f2013-03-10 14:10:06 -07004801 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004802}
4803
Kees Cook647416f2013-03-10 14:10:06 -07004804DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4805 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004806 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004807
Kees Cook647416f2013-03-10 14:10:06 -07004808static int
4809i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004810{
Kees Cook647416f2013-03-10 14:10:06 -07004811 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004812 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004813 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004814 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004815
Daniel Vetter004777c2012-08-09 15:07:01 +02004816 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4817 return -ENODEV;
4818
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004819 ret = mutex_lock_interruptible(&dev->struct_mutex);
4820 if (ret)
4821 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004822 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004823
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004824 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004825
4826 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004827 mutex_unlock(&dev_priv->dev->struct_mutex);
4828
Kees Cook647416f2013-03-10 14:10:06 -07004829 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004830
Kees Cook647416f2013-03-10 14:10:06 -07004831 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004832}
4833
Kees Cook647416f2013-03-10 14:10:06 -07004834static int
4835i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004836{
Kees Cook647416f2013-03-10 14:10:06 -07004837 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004838 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004839 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004840
Daniel Vetter004777c2012-08-09 15:07:01 +02004841 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4842 return -ENODEV;
4843
Kees Cook647416f2013-03-10 14:10:06 -07004844 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004845 return -EINVAL;
4846
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004847 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004848 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004849
4850 /* Update the cache sharing policy here as well */
4851 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4852 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4853 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4854 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4855
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004856 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004857 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004858}
4859
Kees Cook647416f2013-03-10 14:10:06 -07004860DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4861 i915_cache_sharing_get, i915_cache_sharing_set,
4862 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004863
Jeff McGee5d395252015-04-03 18:13:17 -07004864struct sseu_dev_status {
4865 unsigned int slice_total;
4866 unsigned int subslice_total;
4867 unsigned int subslice_per_slice;
4868 unsigned int eu_total;
4869 unsigned int eu_per_subslice;
4870};
4871
4872static void cherryview_sseu_device_status(struct drm_device *dev,
4873 struct sseu_dev_status *stat)
4874{
4875 struct drm_i915_private *dev_priv = dev->dev_private;
4876 const int ss_max = 2;
4877 int ss;
4878 u32 sig1[ss_max], sig2[ss_max];
4879
4880 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4881 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4882 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4883 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4884
4885 for (ss = 0; ss < ss_max; ss++) {
4886 unsigned int eu_cnt;
4887
4888 if (sig1[ss] & CHV_SS_PG_ENABLE)
4889 /* skip disabled subslice */
4890 continue;
4891
4892 stat->slice_total = 1;
4893 stat->subslice_per_slice++;
4894 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4895 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4896 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4897 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
4898 stat->eu_total += eu_cnt;
4899 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
4900 }
4901 stat->subslice_total = stat->subslice_per_slice;
4902}
4903
4904static void gen9_sseu_device_status(struct drm_device *dev,
4905 struct sseu_dev_status *stat)
4906{
4907 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004908 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004909 int s, ss;
4910 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4911
Jeff McGee1c046bc2015-04-03 18:13:18 -07004912 /* BXT has a single slice and at most 3 subslices. */
4913 if (IS_BROXTON(dev)) {
4914 s_max = 1;
4915 ss_max = 3;
4916 }
4917
4918 for (s = 0; s < s_max; s++) {
4919 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4920 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4921 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4922 }
4923
Jeff McGee5d395252015-04-03 18:13:17 -07004924 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4925 GEN9_PGCTL_SSA_EU19_ACK |
4926 GEN9_PGCTL_SSA_EU210_ACK |
4927 GEN9_PGCTL_SSA_EU311_ACK;
4928 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4929 GEN9_PGCTL_SSB_EU19_ACK |
4930 GEN9_PGCTL_SSB_EU210_ACK |
4931 GEN9_PGCTL_SSB_EU311_ACK;
4932
4933 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004934 unsigned int ss_cnt = 0;
4935
Jeff McGee5d395252015-04-03 18:13:17 -07004936 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4937 /* skip disabled slice */
4938 continue;
4939
4940 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004941
4942 if (IS_SKYLAKE(dev))
4943 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
4944
Jeff McGee5d395252015-04-03 18:13:17 -07004945 for (ss = 0; ss < ss_max; ss++) {
4946 unsigned int eu_cnt;
4947
Jeff McGee1c046bc2015-04-03 18:13:18 -07004948 if (IS_BROXTON(dev) &&
4949 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4950 /* skip disabled subslice */
4951 continue;
4952
4953 if (IS_BROXTON(dev))
4954 ss_cnt++;
4955
Jeff McGee5d395252015-04-03 18:13:17 -07004956 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4957 eu_mask[ss%2]);
4958 stat->eu_total += eu_cnt;
4959 stat->eu_per_subslice = max(stat->eu_per_subslice,
4960 eu_cnt);
4961 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004962
4963 stat->subslice_total += ss_cnt;
4964 stat->subslice_per_slice = max(stat->subslice_per_slice,
4965 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004966 }
4967}
4968
Jeff McGee38732182015-02-13 10:27:54 -06004969static int i915_sseu_status(struct seq_file *m, void *unused)
4970{
4971 struct drm_info_node *node = (struct drm_info_node *) m->private;
4972 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07004973 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06004974
Jeff McGee5575f032015-02-27 10:22:32 -08004975 if ((INTEL_INFO(dev)->gen < 8) || IS_BROADWELL(dev))
Jeff McGee38732182015-02-13 10:27:54 -06004976 return -ENODEV;
4977
4978 seq_puts(m, "SSEU Device Info\n");
4979 seq_printf(m, " Available Slice Total: %u\n",
4980 INTEL_INFO(dev)->slice_total);
4981 seq_printf(m, " Available Subslice Total: %u\n",
4982 INTEL_INFO(dev)->subslice_total);
4983 seq_printf(m, " Available Subslice Per Slice: %u\n",
4984 INTEL_INFO(dev)->subslice_per_slice);
4985 seq_printf(m, " Available EU Total: %u\n",
4986 INTEL_INFO(dev)->eu_total);
4987 seq_printf(m, " Available EU Per Subslice: %u\n",
4988 INTEL_INFO(dev)->eu_per_subslice);
4989 seq_printf(m, " Has Slice Power Gating: %s\n",
4990 yesno(INTEL_INFO(dev)->has_slice_pg));
4991 seq_printf(m, " Has Subslice Power Gating: %s\n",
4992 yesno(INTEL_INFO(dev)->has_subslice_pg));
4993 seq_printf(m, " Has EU Power Gating: %s\n",
4994 yesno(INTEL_INFO(dev)->has_eu_pg));
4995
Jeff McGee7f992ab2015-02-13 10:27:55 -06004996 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07004997 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08004998 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07004999 cherryview_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07005000 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07005001 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005002 }
Jeff McGee5d395252015-04-03 18:13:17 -07005003 seq_printf(m, " Enabled Slice Total: %u\n",
5004 stat.slice_total);
5005 seq_printf(m, " Enabled Subslice Total: %u\n",
5006 stat.subslice_total);
5007 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
5008 stat.subslice_per_slice);
5009 seq_printf(m, " Enabled EU Total: %u\n",
5010 stat.eu_total);
5011 seq_printf(m, " Enabled EU Per Subslice: %u\n",
5012 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06005013
Jeff McGee38732182015-02-13 10:27:54 -06005014 return 0;
5015}
5016
Ben Widawsky6d794d42011-04-25 11:25:56 -07005017static int i915_forcewake_open(struct inode *inode, struct file *file)
5018{
5019 struct drm_device *dev = inode->i_private;
5020 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005021
Daniel Vetter075edca2012-01-24 09:44:28 +01005022 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005023 return 0;
5024
Chris Wilson6daccb02015-01-16 11:34:35 +02005025 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02005026 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005027
5028 return 0;
5029}
5030
Ben Widawskyc43b5632012-04-16 14:07:40 -07005031static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005032{
5033 struct drm_device *dev = inode->i_private;
5034 struct drm_i915_private *dev_priv = dev->dev_private;
5035
Daniel Vetter075edca2012-01-24 09:44:28 +01005036 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07005037 return 0;
5038
Mika Kuoppala59bad942015-01-16 11:34:40 +02005039 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02005040 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005041
5042 return 0;
5043}
5044
5045static const struct file_operations i915_forcewake_fops = {
5046 .owner = THIS_MODULE,
5047 .open = i915_forcewake_open,
5048 .release = i915_forcewake_release,
5049};
5050
5051static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5052{
5053 struct drm_device *dev = minor->dev;
5054 struct dentry *ent;
5055
5056 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07005057 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07005058 root, dev,
5059 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005060 if (!ent)
5061 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07005062
Ben Widawsky8eb57292011-05-11 15:10:58 -07005063 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07005064}
5065
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005066static int i915_debugfs_create(struct dentry *root,
5067 struct drm_minor *minor,
5068 const char *name,
5069 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07005070{
5071 struct drm_device *dev = minor->dev;
5072 struct dentry *ent;
5073
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005074 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07005075 S_IRUGO | S_IWUSR,
5076 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005077 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08005078 if (!ent)
5079 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07005080
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005081 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07005082}
5083
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005084static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005085 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005086 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005087 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005088 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005089 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005090 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005091 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005092 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005093 {"i915_gem_request", i915_gem_request_info, 0},
5094 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005095 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005096 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005097 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5098 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5099 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005100 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005101 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Alex Daifdf5d352015-08-12 15:43:37 +01005102 {"i915_guc_load_status", i915_guc_load_status_info, 0},
Alex Dai4c7e77f2015-08-12 15:43:40 +01005103 {"i915_guc_log_dump", i915_guc_log_dump, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305104 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005105 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005106 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005107 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005108 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Daniel Vetter9a851782015-06-18 10:30:22 +02005109 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005110 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005111 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005112 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005113 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005114 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005115 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae92014-08-07 13:24:26 +01005116 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005117 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005118 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005119 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005120 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005121 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005122 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005123 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005124 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005125 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005126 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005127 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005128 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005129 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005130 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005131 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005132 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005133 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305134 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005135 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005136};
Ben Gamari27c202a2009-07-01 22:26:52 -04005137#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005138
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005139static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005140 const char *name;
5141 const struct file_operations *fops;
5142} i915_debugfs_files[] = {
5143 {"i915_wedged", &i915_wedged_fops},
5144 {"i915_max_freq", &i915_max_freq_fops},
5145 {"i915_min_freq", &i915_min_freq_fops},
5146 {"i915_cache_sharing", &i915_cache_sharing_fops},
5147 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005148 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5149 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005150 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5151 {"i915_error_state", &i915_error_state_fops},
5152 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005153 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005154 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5155 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5156 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005157 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005158 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5159 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5160 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005161};
5162
Damien Lespiau07144422013-10-15 18:55:40 +01005163void intel_display_crc_init(struct drm_device *dev)
5164{
5165 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005166 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005167
Damien Lespiau055e3932014-08-18 13:49:10 +01005168 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005169 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005170
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005171 pipe_crc->opened = false;
5172 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005173 init_waitqueue_head(&pipe_crc->wq);
5174 }
5175}
5176
Ben Gamari27c202a2009-07-01 22:26:52 -04005177int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005178{
Daniel Vetter34b96742013-07-04 20:49:44 +02005179 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005180
Ben Widawsky6d794d42011-04-25 11:25:56 -07005181 ret = i915_forcewake_create(minor->debugfs_root, minor);
5182 if (ret)
5183 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005184
Damien Lespiau07144422013-10-15 18:55:40 +01005185 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5186 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5187 if (ret)
5188 return ret;
5189 }
5190
Daniel Vetter34b96742013-07-04 20:49:44 +02005191 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5192 ret = i915_debugfs_create(minor->debugfs_root, minor,
5193 i915_debugfs_files[i].name,
5194 i915_debugfs_files[i].fops);
5195 if (ret)
5196 return ret;
5197 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005198
Ben Gamari27c202a2009-07-01 22:26:52 -04005199 return drm_debugfs_create_files(i915_debugfs_list,
5200 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005201 minor->debugfs_root, minor);
5202}
5203
Ben Gamari27c202a2009-07-01 22:26:52 -04005204void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005205{
Daniel Vetter34b96742013-07-04 20:49:44 +02005206 int i;
5207
Ben Gamari27c202a2009-07-01 22:26:52 -04005208 drm_debugfs_remove_files(i915_debugfs_list,
5209 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005210
Ben Widawsky6d794d42011-04-25 11:25:56 -07005211 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5212 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005213
Daniel Vettere309a992013-10-16 22:55:51 +02005214 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005215 struct drm_info_list *info_list =
5216 (struct drm_info_list *)&i915_pipe_crc_data[i];
5217
5218 drm_debugfs_remove_files(info_list, 1, minor);
5219 }
5220
Daniel Vetter34b96742013-07-04 20:49:44 +02005221 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5222 struct drm_info_list *info_list =
5223 (struct drm_info_list *) i915_debugfs_files[i].fops;
5224
5225 drm_debugfs_remove_files(info_list, 1, minor);
5226 }
Ben Gamari20172632009-02-17 20:08:50 -05005227}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005228
5229struct dpcd_block {
5230 /* DPCD dump start address. */
5231 unsigned int offset;
5232 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5233 unsigned int end;
5234 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5235 size_t size;
5236 /* Only valid for eDP. */
5237 bool edp;
5238};
5239
5240static const struct dpcd_block i915_dpcd_debug[] = {
5241 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5242 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5243 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5244 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5245 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5246 { .offset = DP_SET_POWER },
5247 { .offset = DP_EDP_DPCD_REV },
5248 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5249 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5250 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5251};
5252
5253static int i915_dpcd_show(struct seq_file *m, void *data)
5254{
5255 struct drm_connector *connector = m->private;
5256 struct intel_dp *intel_dp =
5257 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5258 uint8_t buf[16];
5259 ssize_t err;
5260 int i;
5261
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005262 if (connector->status != connector_status_connected)
5263 return -ENODEV;
5264
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005265 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5266 const struct dpcd_block *b = &i915_dpcd_debug[i];
5267 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5268
5269 if (b->edp &&
5270 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5271 continue;
5272
5273 /* low tech for now */
5274 if (WARN_ON(size > sizeof(buf)))
5275 continue;
5276
5277 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5278 if (err <= 0) {
5279 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5280 size, b->offset, err);
5281 continue;
5282 }
5283
5284 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005285 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005286
5287 return 0;
5288}
5289
5290static int i915_dpcd_open(struct inode *inode, struct file *file)
5291{
5292 return single_open(file, i915_dpcd_show, inode->i_private);
5293}
5294
5295static const struct file_operations i915_dpcd_fops = {
5296 .owner = THIS_MODULE,
5297 .open = i915_dpcd_open,
5298 .read = seq_read,
5299 .llseek = seq_lseek,
5300 .release = single_release,
5301};
5302
5303/**
5304 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5305 * @connector: pointer to a registered drm_connector
5306 *
5307 * Cleanup will be done by drm_connector_unregister() through a call to
5308 * drm_debugfs_connector_remove().
5309 *
5310 * Returns 0 on success, negative error codes on error.
5311 */
5312int i915_debugfs_connector_add(struct drm_connector *connector)
5313{
5314 struct dentry *root = connector->debugfs_entry;
5315
5316 /* The connector must have been registered beforehands. */
5317 if (!root)
5318 return -ENODEV;
5319
5320 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5321 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5322 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5323 &i915_dpcd_fops);
5324
5325 return 0;
5326}