blob: 35a5defe7e29f23453ab85a07e0057da7ba52351 [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
Chris Wilson37811fc2010-08-25 22:45:57 +0100120static void
121describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
122{
Chris Wilsonb4716182015-04-27 13:41:17 +0100123 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
124 struct intel_engine_cs *ring;
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700125 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800126 int pin_count = 0;
Chris Wilsonb4716182015-04-27 13:41:17 +0100127 int i;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800128
Chris Wilsonb4716182015-04-27 13:41:17 +0100129 seq_printf(m, "%pK: %s%s%s%s %8zdKiB %02x %02x [ ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100130 &obj->base,
Chris Wilson481a3d42015-04-07 16:20:39 +0100131 obj->active ? "*" : " ",
Chris Wilson37811fc2010-08-25 22:45:57 +0100132 get_pin_flag(obj),
133 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700134 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800135 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100136 obj->base.read_domains,
Chris Wilsonb4716182015-04-27 13:41:17 +0100137 obj->base.write_domain);
138 for_each_ring(ring, dev_priv, i)
139 seq_printf(m, "%x ",
140 i915_gem_request_get_seqno(obj->last_read_req[i]));
141 seq_printf(m, "] %x %x%s%s%s",
John Harrison97b2a6a2014-11-24 18:49:26 +0000142 i915_gem_request_get_seqno(obj->last_write_req),
143 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100144 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100145 obj->dirty ? " dirty" : "",
146 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
147 if (obj->base.name)
148 seq_printf(m, " (name: %d)", obj->base.name);
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300149 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800150 if (vma->pin_count > 0)
151 pin_count++;
Dan Carpenterba0635ff2015-02-25 16:17:48 +0300152 }
153 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100154 if (obj->pin_display)
155 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100156 if (obj->fence_reg != I915_FENCE_REG_NONE)
157 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700158 list_for_each_entry(vma, &obj->vma_list, vma_link) {
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100159 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
160 i915_is_ggtt(vma->vm) ? "g" : "pp",
161 vma->node.start, vma->node.size);
162 if (i915_is_ggtt(vma->vm))
163 seq_printf(m, ", type: %u)", vma->ggtt_view.type);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700164 else
Tvrtko Ursulin8d2fdc32015-05-27 10:52:32 +0100165 seq_puts(m, ")");
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700166 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000167 if (obj->stolen)
Thierry Reding440fd522015-01-23 09:05:06 +0100168 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
Chris Wilson30154652015-04-07 17:28:24 +0100169 if (obj->pin_display || obj->fault_mappable) {
Chris Wilson6299f992010-11-24 12:23:44 +0000170 char s[3], *t = s;
Chris Wilson30154652015-04-07 17:28:24 +0100171 if (obj->pin_display)
Chris Wilson6299f992010-11-24 12:23:44 +0000172 *t++ = 'p';
173 if (obj->fault_mappable)
174 *t++ = 'f';
175 *t = '\0';
176 seq_printf(m, " (%s mappable)", s);
177 }
Chris Wilsonb4716182015-04-27 13:41:17 +0100178 if (obj->last_write_req != NULL)
John Harrison41c52412014-11-24 18:49:43 +0000179 seq_printf(m, " (%s)",
Chris Wilsonb4716182015-04-27 13:41:17 +0100180 i915_gem_request_get_ring(obj->last_write_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200181 if (obj->frontbuffer_bits)
182 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100183}
184
Oscar Mateo273497e2014-05-22 14:13:37 +0100185static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700186{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100187 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700188 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
189 seq_putc(m, ' ');
190}
191
Ben Gamari433e12f2009-02-17 20:08:51 -0500192static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500193{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100194 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500195 uintptr_t list = (uintptr_t) node->info_ent->data;
196 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500197 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700198 struct drm_i915_private *dev_priv = dev->dev_private;
199 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700200 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100201 size_t total_obj_size, total_gtt_size;
202 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100203
204 ret = mutex_lock_interruptible(&dev->struct_mutex);
205 if (ret)
206 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500207
Ben Widawskyca191b12013-07-31 17:00:14 -0700208 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500209 switch (list) {
210 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100211 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700212 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500213 break;
214 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100215 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700216 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500217 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500218 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100219 mutex_unlock(&dev->struct_mutex);
220 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500221 }
222
Chris Wilson8f2480f2010-09-26 11:44:19 +0100223 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700224 list_for_each_entry(vma, head, mm_list) {
225 seq_printf(m, " ");
226 describe_obj(m, vma->obj);
227 seq_printf(m, "\n");
228 total_obj_size += vma->obj->base.size;
229 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100230 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500231 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100232 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700233
Chris Wilson8f2480f2010-09-26 11:44:19 +0100234 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
235 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500236 return 0;
237}
238
Chris Wilson6d2b88852013-08-07 18:30:54 +0100239static int obj_rank_by_stolen(void *priv,
240 struct list_head *A, struct list_head *B)
241{
242 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200243 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100244 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200245 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100246
247 return a->stolen->start - b->stolen->start;
248}
249
250static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
251{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100252 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100253 struct drm_device *dev = node->minor->dev;
254 struct drm_i915_private *dev_priv = dev->dev_private;
255 struct drm_i915_gem_object *obj;
256 size_t total_obj_size, total_gtt_size;
257 LIST_HEAD(stolen);
258 int count, ret;
259
260 ret = mutex_lock_interruptible(&dev->struct_mutex);
261 if (ret)
262 return ret;
263
264 total_obj_size = total_gtt_size = count = 0;
265 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
266 if (obj->stolen == NULL)
267 continue;
268
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200269 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100270
271 total_obj_size += obj->base.size;
272 total_gtt_size += i915_gem_obj_ggtt_size(obj);
273 count++;
274 }
275 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
276 if (obj->stolen == NULL)
277 continue;
278
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200279 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100280
281 total_obj_size += obj->base.size;
282 count++;
283 }
284 list_sort(NULL, &stolen, obj_rank_by_stolen);
285 seq_puts(m, "Stolen:\n");
286 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200287 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100288 seq_puts(m, " ");
289 describe_obj(m, obj);
290 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200291 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100292 }
293 mutex_unlock(&dev->struct_mutex);
294
295 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
296 count, total_obj_size, total_gtt_size);
297 return 0;
298}
299
Chris Wilson6299f992010-11-24 12:23:44 +0000300#define count_objects(list, member) do { \
301 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700302 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000303 ++count; \
304 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700305 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000306 ++mappable_count; \
307 } \
308 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400309} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000310
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100311struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000312 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100313 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000314 size_t total, unbound;
315 size_t global, shared;
316 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100317};
318
319static int per_file_stats(int id, void *ptr, void *data)
320{
321 struct drm_i915_gem_object *obj = ptr;
322 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000323 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100324
325 stats->count++;
326 stats->total += obj->base.size;
327
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000328 if (obj->base.name || obj->base.dma_buf)
329 stats->shared += obj->base.size;
330
Chris Wilson6313c202014-03-19 13:45:45 +0000331 if (USES_FULL_PPGTT(obj->base.dev)) {
332 list_for_each_entry(vma, &obj->vma_list, vma_link) {
333 struct i915_hw_ppgtt *ppgtt;
334
335 if (!drm_mm_node_allocated(&vma->node))
336 continue;
337
338 if (i915_is_ggtt(vma->vm)) {
339 stats->global += obj->base.size;
340 continue;
341 }
342
343 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200344 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000345 continue;
346
John Harrison41c52412014-11-24 18:49:43 +0000347 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000348 stats->active += obj->base.size;
349 else
350 stats->inactive += obj->base.size;
351
352 return 0;
353 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100354 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000355 if (i915_gem_obj_ggtt_bound(obj)) {
356 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000357 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000358 stats->active += obj->base.size;
359 else
360 stats->inactive += obj->base.size;
361 return 0;
362 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100363 }
364
Chris Wilson6313c202014-03-19 13:45:45 +0000365 if (!list_empty(&obj->global_list))
366 stats->unbound += obj->base.size;
367
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100368 return 0;
369}
370
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100371#define print_file_stats(m, name, stats) do { \
372 if (stats.count) \
373 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n", \
374 name, \
375 stats.count, \
376 stats.total, \
377 stats.active, \
378 stats.inactive, \
379 stats.global, \
380 stats.shared, \
381 stats.unbound); \
382} while (0)
Brad Volkin493018d2014-12-11 12:13:08 -0800383
384static void print_batch_pool_stats(struct seq_file *m,
385 struct drm_i915_private *dev_priv)
386{
387 struct drm_i915_gem_object *obj;
388 struct file_stats stats;
Chris Wilson06fbca72015-04-07 16:20:36 +0100389 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100390 int i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800391
392 memset(&stats, 0, sizeof(stats));
393
Chris Wilson06fbca72015-04-07 16:20:36 +0100394 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100395 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
396 list_for_each_entry(obj,
397 &ring->batch_pool.cache_list[j],
398 batch_pool_link)
399 per_file_stats(0, obj, &stats);
400 }
Chris Wilson06fbca72015-04-07 16:20:36 +0100401 }
Brad Volkin493018d2014-12-11 12:13:08 -0800402
Chris Wilsonb0da1b72015-04-07 16:20:40 +0100403 print_file_stats(m, "[k]batch pool", stats);
Brad Volkin493018d2014-12-11 12:13:08 -0800404}
405
Ben Widawskyca191b12013-07-31 17:00:14 -0700406#define count_vmas(list, member) do { \
407 list_for_each_entry(vma, list, member) { \
408 size += i915_gem_obj_ggtt_size(vma->obj); \
409 ++count; \
410 if (vma->obj->map_and_fenceable) { \
411 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
412 ++mappable_count; \
413 } \
414 } \
415} while (0)
416
417static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100418{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100419 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100420 struct drm_device *dev = node->minor->dev;
421 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200422 u32 count, mappable_count, purgeable_count;
423 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000424 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700425 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100426 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700427 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100428 int ret;
429
430 ret = mutex_lock_interruptible(&dev->struct_mutex);
431 if (ret)
432 return ret;
433
Chris Wilson6299f992010-11-24 12:23:44 +0000434 seq_printf(m, "%u objects, %zu bytes\n",
435 dev_priv->mm.object_count,
436 dev_priv->mm.object_memory);
437
438 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700439 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000440 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
441 count, mappable_count, size, mappable_size);
442
443 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700444 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000445 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
446 count, mappable_count, size, mappable_size);
447
448 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700449 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000450 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
451 count, mappable_count, size, mappable_size);
452
Chris Wilsonb7abb712012-08-20 11:33:30 +0200453 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700454 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200455 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200456 if (obj->madv == I915_MADV_DONTNEED)
457 purgeable_size += obj->base.size, ++purgeable_count;
458 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200459 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
460
Chris Wilson6299f992010-11-24 12:23:44 +0000461 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700462 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000463 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700464 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000465 ++count;
466 }
Chris Wilson30154652015-04-07 17:28:24 +0100467 if (obj->pin_display) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700468 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000469 ++mappable_count;
470 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200471 if (obj->madv == I915_MADV_DONTNEED) {
472 purgeable_size += obj->base.size;
473 ++purgeable_count;
474 }
Chris Wilson6299f992010-11-24 12:23:44 +0000475 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200476 seq_printf(m, "%u purgeable objects, %zu bytes\n",
477 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000478 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
479 mappable_count, mappable_size);
480 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
481 count, size);
482
Ben Widawsky93d18792013-01-17 12:45:17 -0800483 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700484 dev_priv->gtt.base.total,
485 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100486
Damien Lespiau267f0c92013-06-24 22:59:48 +0100487 seq_putc(m, '\n');
Brad Volkin493018d2014-12-11 12:13:08 -0800488 print_batch_pool_stats(m, dev_priv);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100489 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
490 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900491 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100492
493 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000494 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100495 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100496 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100497 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900498 /*
499 * Although we have a valid reference on file->pid, that does
500 * not guarantee that the task_struct who called get_pid() is
501 * still alive (e.g. get_pid(current) => fork() => exit()).
502 * Therefore, we need to protect this ->comm access using RCU.
503 */
504 rcu_read_lock();
505 task = pid_task(file->pid, PIDTYPE_PID);
Brad Volkin493018d2014-12-11 12:13:08 -0800506 print_file_stats(m, task ? task->comm : "<unknown>", stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900507 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100508 }
509
Chris Wilson73aa8082010-09-30 11:46:12 +0100510 mutex_unlock(&dev->struct_mutex);
511
512 return 0;
513}
514
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100515static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000516{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100517 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000518 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100519 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000520 struct drm_i915_private *dev_priv = dev->dev_private;
521 struct drm_i915_gem_object *obj;
522 size_t total_obj_size, total_gtt_size;
523 int count, ret;
524
525 ret = mutex_lock_interruptible(&dev->struct_mutex);
526 if (ret)
527 return ret;
528
529 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700530 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800531 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100532 continue;
533
Damien Lespiau267f0c92013-06-24 22:59:48 +0100534 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000535 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100536 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000537 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700538 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000539 count++;
540 }
541
542 mutex_unlock(&dev->struct_mutex);
543
544 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
545 count, total_obj_size, total_gtt_size);
546
547 return 0;
548}
549
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100550static int i915_gem_pageflip_info(struct seq_file *m, void *data)
551{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100552 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100553 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100554 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100555 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200556 int ret;
557
558 ret = mutex_lock_interruptible(&dev->struct_mutex);
559 if (ret)
560 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100561
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100562 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800563 const char pipe = pipe_name(crtc->pipe);
564 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100565 struct intel_unpin_work *work;
566
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200567 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100568 work = crtc->unpin_work;
569 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800570 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100571 pipe, plane);
572 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100573 u32 addr;
574
Chris Wilsone7d841c2012-12-03 11:36:30 +0000575 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800576 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100577 pipe, plane);
578 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800579 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100580 pipe, plane);
581 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100582 if (work->flip_queued_req) {
583 struct intel_engine_cs *ring =
584 i915_gem_request_get_ring(work->flip_queued_req);
585
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200586 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 +0100587 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000588 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100589 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100590 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000591 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100592 } else
593 seq_printf(m, "Flip not associated with any ring\n");
594 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
595 work->flip_queued_vblank,
596 work->flip_ready_vblank,
Daniel Vetter1e3feef2015-02-13 21:03:45 +0100597 drm_crtc_vblank_count(&crtc->base));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100598 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100599 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100600 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100601 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000602 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100603
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100604 if (INTEL_INFO(dev)->gen >= 4)
605 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
606 else
607 addr = I915_READ(DSPADDR(crtc->plane));
608 seq_printf(m, "Current scanout address 0x%08x\n", addr);
609
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100610 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100611 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
612 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100613 }
614 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200615 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100616 }
617
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200618 mutex_unlock(&dev->struct_mutex);
619
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100620 return 0;
621}
622
Brad Volkin493018d2014-12-11 12:13:08 -0800623static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
624{
625 struct drm_info_node *node = m->private;
626 struct drm_device *dev = node->minor->dev;
627 struct drm_i915_private *dev_priv = dev->dev_private;
628 struct drm_i915_gem_object *obj;
Chris Wilson06fbca72015-04-07 16:20:36 +0100629 struct intel_engine_cs *ring;
Chris Wilson8d9d5742015-04-07 16:20:38 +0100630 int total = 0;
631 int ret, i, j;
Brad Volkin493018d2014-12-11 12:13:08 -0800632
633 ret = mutex_lock_interruptible(&dev->struct_mutex);
634 if (ret)
635 return ret;
636
Chris Wilson06fbca72015-04-07 16:20:36 +0100637 for_each_ring(ring, dev_priv, i) {
Chris Wilson8d9d5742015-04-07 16:20:38 +0100638 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
639 int count;
640
641 count = 0;
642 list_for_each_entry(obj,
643 &ring->batch_pool.cache_list[j],
644 batch_pool_link)
645 count++;
646 seq_printf(m, "%s cache[%d]: %d objects\n",
647 ring->name, j, count);
648
649 list_for_each_entry(obj,
650 &ring->batch_pool.cache_list[j],
651 batch_pool_link) {
652 seq_puts(m, " ");
653 describe_obj(m, obj);
654 seq_putc(m, '\n');
655 }
656
657 total += count;
Chris Wilson06fbca72015-04-07 16:20:36 +0100658 }
Brad Volkin493018d2014-12-11 12:13:08 -0800659 }
660
Chris Wilson8d9d5742015-04-07 16:20:38 +0100661 seq_printf(m, "total: %d\n", total);
Brad Volkin493018d2014-12-11 12:13:08 -0800662
663 mutex_unlock(&dev->struct_mutex);
664
665 return 0;
666}
667
Ben Gamari20172632009-02-17 20:08:50 -0500668static int i915_gem_request_info(struct seq_file *m, void *data)
669{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100670 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500671 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300672 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100673 struct intel_engine_cs *ring;
Daniel Vettereed29a52015-05-21 14:21:25 +0200674 struct drm_i915_gem_request *req;
Chris Wilson2d1070b2015-04-01 10:36:56 +0100675 int ret, any, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100676
677 ret = mutex_lock_interruptible(&dev->struct_mutex);
678 if (ret)
679 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500680
Chris Wilson2d1070b2015-04-01 10:36:56 +0100681 any = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100682 for_each_ring(ring, dev_priv, i) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100683 int count;
684
685 count = 0;
Daniel Vettereed29a52015-05-21 14:21:25 +0200686 list_for_each_entry(req, &ring->request_list, list)
Chris Wilson2d1070b2015-04-01 10:36:56 +0100687 count++;
688 if (count == 0)
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100689 continue;
690
Chris Wilson2d1070b2015-04-01 10:36:56 +0100691 seq_printf(m, "%s requests: %d\n", ring->name, count);
Daniel Vettereed29a52015-05-21 14:21:25 +0200692 list_for_each_entry(req, &ring->request_list, list) {
Chris Wilson2d1070b2015-04-01 10:36:56 +0100693 struct task_struct *task;
694
695 rcu_read_lock();
696 task = NULL;
Daniel Vettereed29a52015-05-21 14:21:25 +0200697 if (req->pid)
698 task = pid_task(req->pid, PIDTYPE_PID);
Chris Wilson2d1070b2015-04-01 10:36:56 +0100699 seq_printf(m, " %x @ %d: %s [%d]\n",
Daniel Vettereed29a52015-05-21 14:21:25 +0200700 req->seqno,
701 (int) (jiffies - req->emitted_jiffies),
Chris Wilson2d1070b2015-04-01 10:36:56 +0100702 task ? task->comm : "<unknown>",
703 task ? task->pid : -1);
704 rcu_read_unlock();
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100705 }
Chris Wilson2d1070b2015-04-01 10:36:56 +0100706
707 any++;
Ben Gamari20172632009-02-17 20:08:50 -0500708 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100709 mutex_unlock(&dev->struct_mutex);
710
Chris Wilson2d1070b2015-04-01 10:36:56 +0100711 if (any == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100712 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100713
Ben Gamari20172632009-02-17 20:08:50 -0500714 return 0;
715}
716
Chris Wilsonb2223492010-10-27 15:27:33 +0100717static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100718 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100719{
720 if (ring->get_seqno) {
Mika Kuoppala20e28fb2015-01-26 18:03:06 +0200721 seq_printf(m, "Current sequence (%s): %x\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100722 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100723 }
724}
725
Ben Gamari20172632009-02-17 20:08:50 -0500726static int i915_gem_seqno_info(struct seq_file *m, void *data)
727{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100728 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500729 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300730 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100731 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000732 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100733
734 ret = mutex_lock_interruptible(&dev->struct_mutex);
735 if (ret)
736 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200737 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500738
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100739 for_each_ring(ring, dev_priv, i)
740 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100741
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200742 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100743 mutex_unlock(&dev->struct_mutex);
744
Ben Gamari20172632009-02-17 20:08:50 -0500745 return 0;
746}
747
748
749static int i915_interrupt_info(struct seq_file *m, void *data)
750{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100751 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500752 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300753 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100754 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800755 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100756
757 ret = mutex_lock_interruptible(&dev->struct_mutex);
758 if (ret)
759 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200760 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500761
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300762 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300763 seq_printf(m, "Master Interrupt Control:\t%08x\n",
764 I915_READ(GEN8_MASTER_IRQ));
765
766 seq_printf(m, "Display IER:\t%08x\n",
767 I915_READ(VLV_IER));
768 seq_printf(m, "Display IIR:\t%08x\n",
769 I915_READ(VLV_IIR));
770 seq_printf(m, "Display IIR_RW:\t%08x\n",
771 I915_READ(VLV_IIR_RW));
772 seq_printf(m, "Display IMR:\t%08x\n",
773 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100774 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300775 seq_printf(m, "Pipe %c stat:\t%08x\n",
776 pipe_name(pipe),
777 I915_READ(PIPESTAT(pipe)));
778
779 seq_printf(m, "Port hotplug:\t%08x\n",
780 I915_READ(PORT_HOTPLUG_EN));
781 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
782 I915_READ(VLV_DPFLIPSTAT));
783 seq_printf(m, "DPINVGTT:\t%08x\n",
784 I915_READ(DPINVGTT));
785
786 for (i = 0; i < 4; i++) {
787 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
788 i, I915_READ(GEN8_GT_IMR(i)));
789 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
790 i, I915_READ(GEN8_GT_IIR(i)));
791 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
792 i, I915_READ(GEN8_GT_IER(i)));
793 }
794
795 seq_printf(m, "PCU interrupt mask:\t%08x\n",
796 I915_READ(GEN8_PCU_IMR));
797 seq_printf(m, "PCU interrupt identity:\t%08x\n",
798 I915_READ(GEN8_PCU_IIR));
799 seq_printf(m, "PCU interrupt enable:\t%08x\n",
800 I915_READ(GEN8_PCU_IER));
801 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700802 seq_printf(m, "Master Interrupt Control:\t%08x\n",
803 I915_READ(GEN8_MASTER_IRQ));
804
805 for (i = 0; i < 4; i++) {
806 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
807 i, I915_READ(GEN8_GT_IMR(i)));
808 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
809 i, I915_READ(GEN8_GT_IIR(i)));
810 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
811 i, I915_READ(GEN8_GT_IER(i)));
812 }
813
Damien Lespiau055e3932014-08-18 13:49:10 +0100814 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200815 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300816 POWER_DOMAIN_PIPE(pipe))) {
817 seq_printf(m, "Pipe %c power disabled\n",
818 pipe_name(pipe));
819 continue;
820 }
Ben Widawskya123f152013-11-02 21:07:10 -0700821 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000822 pipe_name(pipe),
823 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700824 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000825 pipe_name(pipe),
826 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700827 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000828 pipe_name(pipe),
829 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700830 }
831
832 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
833 I915_READ(GEN8_DE_PORT_IMR));
834 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
835 I915_READ(GEN8_DE_PORT_IIR));
836 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
837 I915_READ(GEN8_DE_PORT_IER));
838
839 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
840 I915_READ(GEN8_DE_MISC_IMR));
841 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
842 I915_READ(GEN8_DE_MISC_IIR));
843 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
844 I915_READ(GEN8_DE_MISC_IER));
845
846 seq_printf(m, "PCU interrupt mask:\t%08x\n",
847 I915_READ(GEN8_PCU_IMR));
848 seq_printf(m, "PCU interrupt identity:\t%08x\n",
849 I915_READ(GEN8_PCU_IIR));
850 seq_printf(m, "PCU interrupt enable:\t%08x\n",
851 I915_READ(GEN8_PCU_IER));
852 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700853 seq_printf(m, "Display IER:\t%08x\n",
854 I915_READ(VLV_IER));
855 seq_printf(m, "Display IIR:\t%08x\n",
856 I915_READ(VLV_IIR));
857 seq_printf(m, "Display IIR_RW:\t%08x\n",
858 I915_READ(VLV_IIR_RW));
859 seq_printf(m, "Display IMR:\t%08x\n",
860 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100861 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700862 seq_printf(m, "Pipe %c stat:\t%08x\n",
863 pipe_name(pipe),
864 I915_READ(PIPESTAT(pipe)));
865
866 seq_printf(m, "Master IER:\t%08x\n",
867 I915_READ(VLV_MASTER_IER));
868
869 seq_printf(m, "Render IER:\t%08x\n",
870 I915_READ(GTIER));
871 seq_printf(m, "Render IIR:\t%08x\n",
872 I915_READ(GTIIR));
873 seq_printf(m, "Render IMR:\t%08x\n",
874 I915_READ(GTIMR));
875
876 seq_printf(m, "PM IER:\t\t%08x\n",
877 I915_READ(GEN6_PMIER));
878 seq_printf(m, "PM IIR:\t\t%08x\n",
879 I915_READ(GEN6_PMIIR));
880 seq_printf(m, "PM IMR:\t\t%08x\n",
881 I915_READ(GEN6_PMIMR));
882
883 seq_printf(m, "Port hotplug:\t%08x\n",
884 I915_READ(PORT_HOTPLUG_EN));
885 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
886 I915_READ(VLV_DPFLIPSTAT));
887 seq_printf(m, "DPINVGTT:\t%08x\n",
888 I915_READ(DPINVGTT));
889
890 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800891 seq_printf(m, "Interrupt enable: %08x\n",
892 I915_READ(IER));
893 seq_printf(m, "Interrupt identity: %08x\n",
894 I915_READ(IIR));
895 seq_printf(m, "Interrupt mask: %08x\n",
896 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100897 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800898 seq_printf(m, "Pipe %c stat: %08x\n",
899 pipe_name(pipe),
900 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800901 } else {
902 seq_printf(m, "North Display Interrupt enable: %08x\n",
903 I915_READ(DEIER));
904 seq_printf(m, "North Display Interrupt identity: %08x\n",
905 I915_READ(DEIIR));
906 seq_printf(m, "North Display Interrupt mask: %08x\n",
907 I915_READ(DEIMR));
908 seq_printf(m, "South Display Interrupt enable: %08x\n",
909 I915_READ(SDEIER));
910 seq_printf(m, "South Display Interrupt identity: %08x\n",
911 I915_READ(SDEIIR));
912 seq_printf(m, "South Display Interrupt mask: %08x\n",
913 I915_READ(SDEIMR));
914 seq_printf(m, "Graphics Interrupt enable: %08x\n",
915 I915_READ(GTIER));
916 seq_printf(m, "Graphics Interrupt identity: %08x\n",
917 I915_READ(GTIIR));
918 seq_printf(m, "Graphics Interrupt mask: %08x\n",
919 I915_READ(GTIMR));
920 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100921 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700922 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100923 seq_printf(m,
924 "Graphics Interrupt mask (%s): %08x\n",
925 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000926 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100927 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000928 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200929 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100930 mutex_unlock(&dev->struct_mutex);
931
Ben Gamari20172632009-02-17 20:08:50 -0500932 return 0;
933}
934
Chris Wilsona6172a82009-02-11 14:26:38 +0000935static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
936{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100937 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000938 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300939 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100940 int i, ret;
941
942 ret = mutex_lock_interruptible(&dev->struct_mutex);
943 if (ret)
944 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000945
946 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
947 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
948 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000949 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000950
Chris Wilson6c085a72012-08-20 11:40:46 +0200951 seq_printf(m, "Fence %d, pin count = %d, object = ",
952 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100953 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100954 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100955 else
Chris Wilson05394f32010-11-08 19:18:58 +0000956 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100957 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000958 }
959
Chris Wilson05394f32010-11-08 19:18:58 +0000960 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000961 return 0;
962}
963
Ben Gamari20172632009-02-17 20:08:50 -0500964static int i915_hws_info(struct seq_file *m, void *data)
965{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100966 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500967 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300968 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100969 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100970 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100971 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500972
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000973 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100974 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500975 if (hws == NULL)
976 return 0;
977
978 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
979 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
980 i * 4,
981 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
982 }
983 return 0;
984}
985
Daniel Vetterd5442302012-04-27 15:17:40 +0200986static ssize_t
987i915_error_state_write(struct file *filp,
988 const char __user *ubuf,
989 size_t cnt,
990 loff_t *ppos)
991{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300992 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200993 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200994 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200995
996 DRM_DEBUG_DRIVER("Resetting error state\n");
997
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200998 ret = mutex_lock_interruptible(&dev->struct_mutex);
999 if (ret)
1000 return ret;
1001
Daniel Vetterd5442302012-04-27 15:17:40 +02001002 i915_destroy_error_state(dev);
1003 mutex_unlock(&dev->struct_mutex);
1004
1005 return cnt;
1006}
1007
1008static int i915_error_state_open(struct inode *inode, struct file *file)
1009{
1010 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +02001011 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +02001012
1013 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1014 if (!error_priv)
1015 return -ENOMEM;
1016
1017 error_priv->dev = dev;
1018
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001019 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001020
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001021 file->private_data = error_priv;
1022
1023 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +02001024}
1025
1026static int i915_error_state_release(struct inode *inode, struct file *file)
1027{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001028 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +02001029
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +03001030 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +02001031 kfree(error_priv);
1032
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001033 return 0;
1034}
1035
1036static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1037 size_t count, loff_t *pos)
1038{
1039 struct i915_error_state_file_priv *error_priv = file->private_data;
1040 struct drm_i915_error_state_buf error_str;
1041 loff_t tmp_pos = 0;
1042 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001043 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001044
Chris Wilson0a4cd7c2014-08-22 14:41:39 +01001045 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001046 if (ret)
1047 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001048
Mika Kuoppalafc16b482013-06-06 15:18:39 +03001049 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001050 if (ret)
1051 goto out;
1052
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001053 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1054 error_str.buf,
1055 error_str.bytes);
1056
1057 if (ret_count < 0)
1058 ret = ret_count;
1059 else
1060 *pos = error_str.start + ret_count;
1061out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +03001062 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001063 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +02001064}
1065
1066static const struct file_operations i915_error_state_fops = {
1067 .owner = THIS_MODULE,
1068 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +03001069 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +02001070 .write = i915_error_state_write,
1071 .llseek = default_llseek,
1072 .release = i915_error_state_release,
1073};
1074
Kees Cook647416f2013-03-10 14:10:06 -07001075static int
1076i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001077{
Kees Cook647416f2013-03-10 14:10:06 -07001078 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001079 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +02001080 int ret;
1081
1082 ret = mutex_lock_interruptible(&dev->struct_mutex);
1083 if (ret)
1084 return ret;
1085
Kees Cook647416f2013-03-10 14:10:06 -07001086 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +02001087 mutex_unlock(&dev->struct_mutex);
1088
Kees Cook647416f2013-03-10 14:10:06 -07001089 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +02001090}
1091
Kees Cook647416f2013-03-10 14:10:06 -07001092static int
1093i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001094{
Kees Cook647416f2013-03-10 14:10:06 -07001095 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001096 int ret;
1097
Mika Kuoppala40633212012-12-04 15:12:00 +02001098 ret = mutex_lock_interruptible(&dev->struct_mutex);
1099 if (ret)
1100 return ret;
1101
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001102 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001103 mutex_unlock(&dev->struct_mutex);
1104
Kees Cook647416f2013-03-10 14:10:06 -07001105 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001106}
1107
Kees Cook647416f2013-03-10 14:10:06 -07001108DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1109 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001110 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001111
Deepak Sadb4bd12014-03-31 11:30:02 +05301112static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001113{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001114 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001115 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001116 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001117 int ret = 0;
1118
1119 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001120
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001121 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1122
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001123 if (IS_GEN5(dev)) {
1124 u16 rgvswctl = I915_READ16(MEMSWCTL);
1125 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1126
1127 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1128 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1129 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1130 MEMSTAT_VID_SHIFT);
1131 seq_printf(m, "Current P-state: %d\n",
1132 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001133 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
Akash Goel60260a52015-03-06 11:07:21 +05301134 IS_BROADWELL(dev) || IS_GEN9(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001135 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1136 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1137 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001138 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001139 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001140 u32 rpupei, rpcurup, rpprevup;
1141 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001142 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001143 int max_freq;
1144
1145 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001146 ret = mutex_lock_interruptible(&dev->struct_mutex);
1147 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001148 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001149
Mika Kuoppala59bad942015-01-16 11:34:40 +02001150 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001151
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001152 reqf = I915_READ(GEN6_RPNSWREQ);
Akash Goel60260a52015-03-06 11:07:21 +05301153 if (IS_GEN9(dev))
1154 reqf >>= 23;
1155 else {
1156 reqf &= ~GEN6_TURBO_DISABLE;
1157 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1158 reqf >>= 24;
1159 else
1160 reqf >>= 25;
1161 }
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001162 reqf = intel_gpu_freq(dev_priv, reqf);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001163
Chris Wilson0d8f9492014-03-27 09:06:14 +00001164 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1165 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1166 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1167
Jesse Barnesccab5c82011-01-18 15:49:25 -08001168 rpstat = I915_READ(GEN6_RPSTAT1);
1169 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1170 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1171 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1172 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1173 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1174 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Akash Goel60260a52015-03-06 11:07:21 +05301175 if (IS_GEN9(dev))
1176 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1177 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001178 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1179 else
1180 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001181 cagf = intel_gpu_freq(dev_priv, cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001182
Mika Kuoppala59bad942015-01-16 11:34:40 +02001183 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001184 mutex_unlock(&dev->struct_mutex);
1185
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001186 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1187 pm_ier = I915_READ(GEN6_PMIER);
1188 pm_imr = I915_READ(GEN6_PMIMR);
1189 pm_isr = I915_READ(GEN6_PMISR);
1190 pm_iir = I915_READ(GEN6_PMIIR);
1191 pm_mask = I915_READ(GEN6_PMINTRMSK);
1192 } else {
1193 pm_ier = I915_READ(GEN8_GT_IER(2));
1194 pm_imr = I915_READ(GEN8_GT_IMR(2));
1195 pm_isr = I915_READ(GEN8_GT_ISR(2));
1196 pm_iir = I915_READ(GEN8_GT_IIR(2));
1197 pm_mask = I915_READ(GEN6_PMINTRMSK);
1198 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001199 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 -03001200 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001201 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001202 seq_printf(m, "Render p-state ratio: %d\n",
Akash Goel60260a52015-03-06 11:07:21 +05301203 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001204 seq_printf(m, "Render p-state VID: %d\n",
1205 gt_perf_status & 0xff);
1206 seq_printf(m, "Render p-state limit: %d\n",
1207 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001208 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1209 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1210 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1211 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001212 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001213 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001214 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1215 GEN6_CURICONT_MASK);
1216 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1217 GEN6_CURBSYTAVG_MASK);
1218 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1219 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001220 seq_printf(m, "Up threshold: %d%%\n",
1221 dev_priv->rps.up_threshold);
1222
Jesse Barnesccab5c82011-01-18 15:49:25 -08001223 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1224 GEN6_CURIAVG_MASK);
1225 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1226 GEN6_CURBSYTAVG_MASK);
1227 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1228 GEN6_CURBSYTAVG_MASK);
Chris Wilsond86ed342015-04-27 13:41:19 +01001229 seq_printf(m, "Down threshold: %d%%\n",
1230 dev_priv->rps.down_threshold);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001231
1232 max_freq = (rp_state_cap & 0xff0000) >> 16;
Akash Goel60260a52015-03-06 11:07:21 +05301233 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001234 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001235 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001236
1237 max_freq = (rp_state_cap & 0xff00) >> 8;
Akash Goel60260a52015-03-06 11:07:21 +05301238 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001239 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001240 intel_gpu_freq(dev_priv, max_freq));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001241
1242 max_freq = rp_state_cap & 0xff;
Akash Goel60260a52015-03-06 11:07:21 +05301243 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001244 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001245 intel_gpu_freq(dev_priv, max_freq));
Ben Widawsky31c77382013-04-05 14:29:22 -07001246 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001247 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilsonaed242f2015-03-18 09:48:21 +00001248
Chris Wilsond86ed342015-04-27 13:41:19 +01001249 seq_printf(m, "Current freq: %d MHz\n",
1250 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1251 seq_printf(m, "Actual freq: %d MHz\n", cagf);
Chris Wilsonaed242f2015-03-18 09:48:21 +00001252 seq_printf(m, "Idle freq: %d MHz\n",
1253 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
Chris Wilsond86ed342015-04-27 13:41:19 +01001254 seq_printf(m, "Min freq: %d MHz\n",
1255 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1256 seq_printf(m, "Max freq: %d MHz\n",
1257 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1258 seq_printf(m,
1259 "efficient (RPe) frequency: %d MHz\n",
1260 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001261 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001262 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001263
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001264 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001265 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001266 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1267 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1268
Chris Wilsond86ed342015-04-27 13:41:19 +01001269 seq_printf(m, "actual GPU freq: %d MHz\n",
1270 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1271
1272 seq_printf(m, "current GPU freq: %d MHz\n",
1273 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1274
Jesse Barnes0a073b82013-04-17 15:54:58 -07001275 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001276 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001277
Jesse Barnes0a073b82013-04-17 15:54:58 -07001278 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001279 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001280
Chris Wilsonaed242f2015-03-18 09:48:21 +00001281 seq_printf(m, "idle GPU freq: %d MHz\n",
1282 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1283
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001284 seq_printf(m,
1285 "efficient (RPe) frequency: %d MHz\n",
1286 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001287 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001288 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001289 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001290 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001291
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001292out:
1293 intel_runtime_pm_put(dev_priv);
1294 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001295}
1296
Chris Wilsonf6544492015-01-26 18:03:04 +02001297static int i915_hangcheck_info(struct seq_file *m, void *unused)
1298{
1299 struct drm_info_node *node = m->private;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001300 struct drm_device *dev = node->minor->dev;
1301 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf6544492015-01-26 18:03:04 +02001302 struct intel_engine_cs *ring;
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001303 u64 acthd[I915_NUM_RINGS];
1304 u32 seqno[I915_NUM_RINGS];
Chris Wilsonf6544492015-01-26 18:03:04 +02001305 int i;
1306
1307 if (!i915.enable_hangcheck) {
1308 seq_printf(m, "Hangcheck disabled\n");
1309 return 0;
1310 }
1311
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001312 intel_runtime_pm_get(dev_priv);
1313
1314 for_each_ring(ring, dev_priv, i) {
1315 seqno[i] = ring->get_seqno(ring, false);
1316 acthd[i] = intel_ring_get_active_head(ring);
1317 }
1318
1319 intel_runtime_pm_put(dev_priv);
1320
Chris Wilsonf6544492015-01-26 18:03:04 +02001321 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1322 seq_printf(m, "Hangcheck active, fires in %dms\n",
1323 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1324 jiffies));
1325 } else
1326 seq_printf(m, "Hangcheck inactive\n");
1327
1328 for_each_ring(ring, dev_priv, i) {
1329 seq_printf(m, "%s:\n", ring->name);
1330 seq_printf(m, "\tseqno = %x [current %x]\n",
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001331 ring->hangcheck.seqno, seqno[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001332 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1333 (long long)ring->hangcheck.acthd,
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001334 (long long)acthd[i]);
Chris Wilsonf6544492015-01-26 18:03:04 +02001335 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1336 (long long)ring->hangcheck.max_acthd);
Mika Kuoppalaebbc7542015-02-05 18:41:48 +02001337 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1338 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
Chris Wilsonf6544492015-01-26 18:03:04 +02001339 }
1340
1341 return 0;
1342}
1343
Ben Widawsky4d855292011-12-12 19:34:16 -08001344static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001345{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001346 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001347 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001348 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001349 u32 rgvmodectl, rstdbyctl;
1350 u16 crstandvid;
1351 int ret;
1352
1353 ret = mutex_lock_interruptible(&dev->struct_mutex);
1354 if (ret)
1355 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001356 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001357
1358 rgvmodectl = I915_READ(MEMMODECTL);
1359 rstdbyctl = I915_READ(RSTDBYCTL);
1360 crstandvid = I915_READ16(CRSTANDVID);
1361
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001362 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001363 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001364
1365 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1366 "yes" : "no");
1367 seq_printf(m, "Boost freq: %d\n",
1368 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1369 MEMMODE_BOOST_FREQ_SHIFT);
1370 seq_printf(m, "HW control enabled: %s\n",
1371 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1372 seq_printf(m, "SW control enabled: %s\n",
1373 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1374 seq_printf(m, "Gated voltage change: %s\n",
1375 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1376 seq_printf(m, "Starting frequency: P%d\n",
1377 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001378 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001379 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001380 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1381 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1382 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1383 seq_printf(m, "Render standby enabled: %s\n",
1384 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001385 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001386 switch (rstdbyctl & RSX_STATUS_MASK) {
1387 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001388 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001389 break;
1390 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001391 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001392 break;
1393 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001394 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001395 break;
1396 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001397 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001398 break;
1399 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001400 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001401 break;
1402 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001403 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001404 break;
1405 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001406 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001407 break;
1408 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001409
1410 return 0;
1411}
1412
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001413static int i915_forcewake_domains(struct seq_file *m, void *data)
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001414{
1415 struct drm_info_node *node = m->private;
1416 struct drm_device *dev = node->minor->dev;
1417 struct drm_i915_private *dev_priv = dev->dev_private;
1418 struct intel_uncore_forcewake_domain *fw_domain;
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001419 int i;
1420
1421 spin_lock_irq(&dev_priv->uncore.lock);
1422 for_each_fw_domain(fw_domain, dev_priv, i) {
1423 seq_printf(m, "%s.wake_count = %u\n",
Mika Kuoppala05a2fb12015-01-19 16:20:43 +02001424 intel_uncore_forcewake_domain_to_str(i),
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001425 fw_domain->wake_count);
1426 }
1427 spin_unlock_irq(&dev_priv->uncore.lock);
1428
1429 return 0;
1430}
1431
Deepak S669ab5a2014-01-10 15:18:26 +05301432static int vlv_drpc_info(struct seq_file *m)
1433{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001434 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301435 struct drm_device *dev = node->minor->dev;
1436 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001437 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301438
Imre Deakd46c0512014-04-14 20:24:27 +03001439 intel_runtime_pm_get(dev_priv);
1440
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001441 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301442 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1443 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1444
Imre Deakd46c0512014-04-14 20:24:27 +03001445 intel_runtime_pm_put(dev_priv);
1446
Deepak S669ab5a2014-01-10 15:18:26 +05301447 seq_printf(m, "Video Turbo Mode: %s\n",
1448 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1449 seq_printf(m, "Turbo enabled: %s\n",
1450 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1451 seq_printf(m, "HW control enabled: %s\n",
1452 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1453 seq_printf(m, "SW control enabled: %s\n",
1454 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1455 GEN6_RP_MEDIA_SW_MODE));
1456 seq_printf(m, "RC6 Enabled: %s\n",
1457 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1458 GEN6_RC_CTL_EI_MODE(1))));
1459 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001460 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301461 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001462 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301463
Imre Deak9cc19be2014-04-14 20:24:24 +03001464 seq_printf(m, "Render RC6 residency since boot: %u\n",
1465 I915_READ(VLV_GT_RENDER_RC6));
1466 seq_printf(m, "Media RC6 residency since boot: %u\n",
1467 I915_READ(VLV_GT_MEDIA_RC6));
1468
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02001469 return i915_forcewake_domains(m, NULL);
Deepak S669ab5a2014-01-10 15:18:26 +05301470}
1471
Ben Widawsky4d855292011-12-12 19:34:16 -08001472static int gen6_drpc_info(struct seq_file *m)
1473{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001474 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001475 struct drm_device *dev = node->minor->dev;
1476 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001477 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001478 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001479 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001480
1481 ret = mutex_lock_interruptible(&dev->struct_mutex);
1482 if (ret)
1483 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001484 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001485
Chris Wilson907b28c2013-07-19 20:36:52 +01001486 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonb2cff0d2015-01-16 11:34:37 +02001487 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001488 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001489
1490 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001491 seq_puts(m, "RC information inaccurate because somebody "
1492 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001493 } else {
1494 /* NB: we cannot use forcewake, else we read the wrong values */
1495 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1496 udelay(10);
1497 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1498 }
1499
1500 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001501 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001502
1503 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1504 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1505 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001506 mutex_lock(&dev_priv->rps.hw_lock);
1507 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1508 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001509
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001510 intel_runtime_pm_put(dev_priv);
1511
Ben Widawsky4d855292011-12-12 19:34:16 -08001512 seq_printf(m, "Video Turbo Mode: %s\n",
1513 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1514 seq_printf(m, "HW control enabled: %s\n",
1515 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1516 seq_printf(m, "SW control enabled: %s\n",
1517 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1518 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001519 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001520 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1521 seq_printf(m, "RC6 Enabled: %s\n",
1522 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1523 seq_printf(m, "Deep RC6 Enabled: %s\n",
1524 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1525 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1526 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001527 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001528 switch (gt_core_status & GEN6_RCn_MASK) {
1529 case GEN6_RC0:
1530 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001531 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001532 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001533 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001534 break;
1535 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001536 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001537 break;
1538 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001539 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001540 break;
1541 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001542 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001543 break;
1544 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001545 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001546 break;
1547 }
1548
1549 seq_printf(m, "Core Power Down: %s\n",
1550 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001551
1552 /* Not exactly sure what this is */
1553 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1554 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1555 seq_printf(m, "RC6 residency since boot: %u\n",
1556 I915_READ(GEN6_GT_GFX_RC6));
1557 seq_printf(m, "RC6+ residency since boot: %u\n",
1558 I915_READ(GEN6_GT_GFX_RC6p));
1559 seq_printf(m, "RC6++ residency since boot: %u\n",
1560 I915_READ(GEN6_GT_GFX_RC6pp));
1561
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001562 seq_printf(m, "RC6 voltage: %dmV\n",
1563 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1564 seq_printf(m, "RC6+ voltage: %dmV\n",
1565 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1566 seq_printf(m, "RC6++ voltage: %dmV\n",
1567 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001568 return 0;
1569}
1570
1571static int i915_drpc_info(struct seq_file *m, void *unused)
1572{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001573 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001574 struct drm_device *dev = node->minor->dev;
1575
Deepak S669ab5a2014-01-10 15:18:26 +05301576 if (IS_VALLEYVIEW(dev))
1577 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001578 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001579 return gen6_drpc_info(m);
1580 else
1581 return ironlake_drpc_info(m);
1582}
1583
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001584static int i915_fbc_status(struct seq_file *m, void *unused)
1585{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001586 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001587 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001588 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001589
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001590 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001591 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001592 return 0;
1593 }
1594
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001595 intel_runtime_pm_get(dev_priv);
1596
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001597 if (intel_fbc_enabled(dev))
Damien Lespiau267f0c92013-06-24 22:59:48 +01001598 seq_puts(m, "FBC enabled\n");
Paulo Zanoni2e8144a2015-06-12 14:36:20 -03001599 else
1600 seq_printf(m, "FBC disabled: %s\n",
1601 intel_no_fbc_reason_str(dev_priv->fbc.no_fbc_reason));
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001602
Paulo Zanoni31b9df12015-06-12 14:36:18 -03001603 if (INTEL_INFO(dev_priv)->gen >= 7)
1604 seq_printf(m, "Compressing: %s\n",
1605 yesno(I915_READ(FBC_STATUS2) &
1606 FBC_COMPRESSION_MASK));
1607
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001608 intel_runtime_pm_put(dev_priv);
1609
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001610 return 0;
1611}
1612
Rodrigo Vivida46f932014-08-01 02:04:45 -07001613static int i915_fbc_fc_get(void *data, u64 *val)
1614{
1615 struct drm_device *dev = data;
1616 struct drm_i915_private *dev_priv = dev->dev_private;
1617
1618 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1619 return -ENODEV;
1620
1621 drm_modeset_lock_all(dev);
1622 *val = dev_priv->fbc.false_color;
1623 drm_modeset_unlock_all(dev);
1624
1625 return 0;
1626}
1627
1628static int i915_fbc_fc_set(void *data, u64 val)
1629{
1630 struct drm_device *dev = data;
1631 struct drm_i915_private *dev_priv = dev->dev_private;
1632 u32 reg;
1633
1634 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1635 return -ENODEV;
1636
1637 drm_modeset_lock_all(dev);
1638
1639 reg = I915_READ(ILK_DPFC_CONTROL);
1640 dev_priv->fbc.false_color = val;
1641
1642 I915_WRITE(ILK_DPFC_CONTROL, val ?
1643 (reg | FBC_CTL_FALSE_COLOR) :
1644 (reg & ~FBC_CTL_FALSE_COLOR));
1645
1646 drm_modeset_unlock_all(dev);
1647 return 0;
1648}
1649
1650DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1651 i915_fbc_fc_get, i915_fbc_fc_set,
1652 "%llu\n");
1653
Paulo Zanoni92d44622013-05-31 16:33:24 -03001654static int i915_ips_status(struct seq_file *m, void *unused)
1655{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001656 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001657 struct drm_device *dev = node->minor->dev;
1658 struct drm_i915_private *dev_priv = dev->dev_private;
1659
Damien Lespiauf5adf942013-06-24 18:29:34 +01001660 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001661 seq_puts(m, "not supported\n");
1662 return 0;
1663 }
1664
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001665 intel_runtime_pm_get(dev_priv);
1666
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001667 seq_printf(m, "Enabled by kernel parameter: %s\n",
1668 yesno(i915.enable_ips));
1669
1670 if (INTEL_INFO(dev)->gen >= 8) {
1671 seq_puts(m, "Currently: unknown\n");
1672 } else {
1673 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1674 seq_puts(m, "Currently: enabled\n");
1675 else
1676 seq_puts(m, "Currently: disabled\n");
1677 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001678
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001679 intel_runtime_pm_put(dev_priv);
1680
Paulo Zanoni92d44622013-05-31 16:33:24 -03001681 return 0;
1682}
1683
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001684static int i915_sr_status(struct seq_file *m, void *unused)
1685{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001686 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001687 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001688 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001689 bool sr_enabled = false;
1690
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001691 intel_runtime_pm_get(dev_priv);
1692
Yuanhan Liu13982612010-12-15 15:42:31 +08001693 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001694 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001695 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001696 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1697 else if (IS_I915GM(dev))
1698 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1699 else if (IS_PINEVIEW(dev))
1700 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1701
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001702 intel_runtime_pm_put(dev_priv);
1703
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001704 seq_printf(m, "self-refresh: %s\n",
1705 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001706
1707 return 0;
1708}
1709
Jesse Barnes7648fa92010-05-20 14:28:11 -07001710static int i915_emon_status(struct seq_file *m, void *unused)
1711{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001712 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001713 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001714 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001715 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001716 int ret;
1717
Chris Wilson582be6b2012-04-30 19:35:02 +01001718 if (!IS_GEN5(dev))
1719 return -ENODEV;
1720
Chris Wilsonde227ef2010-07-03 07:58:38 +01001721 ret = mutex_lock_interruptible(&dev->struct_mutex);
1722 if (ret)
1723 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001724
1725 temp = i915_mch_val(dev_priv);
1726 chipset = i915_chipset_val(dev_priv);
1727 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001728 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001729
1730 seq_printf(m, "GMCH temp: %ld\n", temp);
1731 seq_printf(m, "Chipset power: %ld\n", chipset);
1732 seq_printf(m, "GFX power: %ld\n", gfx);
1733 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1734
1735 return 0;
1736}
1737
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001738static int i915_ring_freq_table(struct seq_file *m, void *unused)
1739{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001740 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001741 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001742 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001743 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001744 int gpu_freq, ia_freq;
1745
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001746 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001747 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001748 return 0;
1749 }
1750
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001751 intel_runtime_pm_get(dev_priv);
1752
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001753 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1754
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001755 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001756 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001757 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001758
Damien Lespiau267f0c92013-06-24 22:59:48 +01001759 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001760
Ben Widawskyb39fb292014-03-19 18:31:11 -07001761 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1762 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001763 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001764 ia_freq = gpu_freq;
1765 sandybridge_pcode_read(dev_priv,
1766 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1767 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001768 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02001769 intel_gpu_freq(dev_priv, gpu_freq),
Chris Wilson3ebecd02013-04-12 19:10:13 +01001770 ((ia_freq >> 0) & 0xff) * 100,
1771 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001772 }
1773
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001774 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001775
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001776out:
1777 intel_runtime_pm_put(dev_priv);
1778 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001779}
1780
Chris Wilson44834a62010-08-19 16:09:23 +01001781static int i915_opregion(struct seq_file *m, void *unused)
1782{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001783 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001784 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001785 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001786 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001787 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001788 int ret;
1789
Daniel Vetter0d38f002012-04-21 22:49:10 +02001790 if (data == NULL)
1791 return -ENOMEM;
1792
Chris Wilson44834a62010-08-19 16:09:23 +01001793 ret = mutex_lock_interruptible(&dev->struct_mutex);
1794 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001795 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001796
Daniel Vetter0d38f002012-04-21 22:49:10 +02001797 if (opregion->header) {
1798 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1799 seq_write(m, data, OPREGION_SIZE);
1800 }
Chris Wilson44834a62010-08-19 16:09:23 +01001801
1802 mutex_unlock(&dev->struct_mutex);
1803
Daniel Vetter0d38f002012-04-21 22:49:10 +02001804out:
1805 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001806 return 0;
1807}
1808
Chris Wilson37811fc2010-08-25 22:45:57 +01001809static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1810{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001811 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001812 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001813 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001814 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001815
Daniel Vetter4520f532013-10-09 09:18:51 +02001816#ifdef CONFIG_DRM_I915_FBDEV
1817 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001818
1819 ifbdev = dev_priv->fbdev;
1820 fb = to_intel_framebuffer(ifbdev->helper.fb);
1821
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001822 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 +01001823 fb->base.width,
1824 fb->base.height,
1825 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001826 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001827 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001828 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001829 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001830 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001831#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001832
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001833 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001834 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001835 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001836 continue;
1837
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001838 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 +01001839 fb->base.width,
1840 fb->base.height,
1841 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001842 fb->base.bits_per_pixel,
Tvrtko Ursulinc1ca506d2015-02-10 17:16:07 +00001843 fb->base.modifier[0],
Daniel Vetter623f9782012-12-11 16:21:38 +01001844 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001845 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001846 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001847 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001848 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001849
1850 return 0;
1851}
1852
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001853static void describe_ctx_ringbuf(struct seq_file *m,
1854 struct intel_ringbuffer *ringbuf)
1855{
1856 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1857 ringbuf->space, ringbuf->head, ringbuf->tail,
1858 ringbuf->last_retired_head);
1859}
1860
Ben Widawskye76d3632011-03-19 18:14:29 -07001861static int i915_context_status(struct seq_file *m, void *unused)
1862{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001863 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001864 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001865 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001866 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001867 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001868 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001869
Daniel Vetterf3d28872014-05-29 23:23:08 +02001870 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001871 if (ret)
1872 return ret;
1873
Ben Widawskya33afea2013-09-17 21:12:45 -07001874 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001875 if (!i915.enable_execlists &&
1876 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001877 continue;
1878
Ben Widawskya33afea2013-09-17 21:12:45 -07001879 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001880 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001881 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001882 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001883 seq_printf(m, "(default context %s) ",
1884 ring->name);
1885 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001886
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001887 if (i915.enable_execlists) {
1888 seq_putc(m, '\n');
1889 for_each_ring(ring, dev_priv, i) {
1890 struct drm_i915_gem_object *ctx_obj =
1891 ctx->engine[i].state;
1892 struct intel_ringbuffer *ringbuf =
1893 ctx->engine[i].ringbuf;
1894
1895 seq_printf(m, "%s: ", ring->name);
1896 if (ctx_obj)
1897 describe_obj(m, ctx_obj);
1898 if (ringbuf)
1899 describe_ctx_ringbuf(m, ringbuf);
1900 seq_putc(m, '\n');
1901 }
1902 } else {
1903 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1904 }
1905
Ben Widawskya33afea2013-09-17 21:12:45 -07001906 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001907 }
1908
Daniel Vetterf3d28872014-05-29 23:23:08 +02001909 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001910
1911 return 0;
1912}
1913
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001914static void i915_dump_lrc_obj(struct seq_file *m,
1915 struct intel_engine_cs *ring,
1916 struct drm_i915_gem_object *ctx_obj)
1917{
1918 struct page *page;
1919 uint32_t *reg_state;
1920 int j;
1921 unsigned long ggtt_offset = 0;
1922
1923 if (ctx_obj == NULL) {
1924 seq_printf(m, "Context on %s with no gem object\n",
1925 ring->name);
1926 return;
1927 }
1928
1929 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1930 intel_execlists_ctx_id(ctx_obj));
1931
1932 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1933 seq_puts(m, "\tNot bound in GGTT\n");
1934 else
1935 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1936
1937 if (i915_gem_object_get_pages(ctx_obj)) {
1938 seq_puts(m, "\tFailed to get pages for context object\n");
1939 return;
1940 }
1941
1942 page = i915_gem_object_get_page(ctx_obj, 1);
1943 if (!WARN_ON(page == NULL)) {
1944 reg_state = kmap_atomic(page);
1945
1946 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
1947 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1948 ggtt_offset + 4096 + (j * 4),
1949 reg_state[j], reg_state[j + 1],
1950 reg_state[j + 2], reg_state[j + 3]);
1951 }
1952 kunmap_atomic(reg_state);
1953 }
1954
1955 seq_putc(m, '\n');
1956}
1957
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01001958static int i915_dump_lrc(struct seq_file *m, void *unused)
1959{
1960 struct drm_info_node *node = (struct drm_info_node *) m->private;
1961 struct drm_device *dev = node->minor->dev;
1962 struct drm_i915_private *dev_priv = dev->dev_private;
1963 struct intel_engine_cs *ring;
1964 struct intel_context *ctx;
1965 int ret, i;
1966
1967 if (!i915.enable_execlists) {
1968 seq_printf(m, "Logical Ring Contexts are disabled\n");
1969 return 0;
1970 }
1971
1972 ret = mutex_lock_interruptible(&dev->struct_mutex);
1973 if (ret)
1974 return ret;
1975
1976 list_for_each_entry(ctx, &dev_priv->context_list, link) {
1977 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001978 if (ring->default_context != ctx)
1979 i915_dump_lrc_obj(m, ring,
1980 ctx->engine[i].state);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01001981 }
1982 }
1983
1984 mutex_unlock(&dev->struct_mutex);
1985
1986 return 0;
1987}
1988
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001989static int i915_execlists(struct seq_file *m, void *data)
1990{
1991 struct drm_info_node *node = (struct drm_info_node *)m->private;
1992 struct drm_device *dev = node->minor->dev;
1993 struct drm_i915_private *dev_priv = dev->dev_private;
1994 struct intel_engine_cs *ring;
1995 u32 status_pointer;
1996 u8 read_pointer;
1997 u8 write_pointer;
1998 u32 status;
1999 u32 ctx_id;
2000 struct list_head *cursor;
2001 int ring_id, i;
2002 int ret;
2003
2004 if (!i915.enable_execlists) {
2005 seq_puts(m, "Logical Ring Contexts are disabled\n");
2006 return 0;
2007 }
2008
2009 ret = mutex_lock_interruptible(&dev->struct_mutex);
2010 if (ret)
2011 return ret;
2012
Michel Thierryfc0412e2014-10-16 16:13:38 +01002013 intel_runtime_pm_get(dev_priv);
2014
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002015 for_each_ring(ring, dev_priv, ring_id) {
Nick Hoath6d3d8272015-01-15 13:10:39 +00002016 struct drm_i915_gem_request *head_req = NULL;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002017 int count = 0;
2018 unsigned long flags;
2019
2020 seq_printf(m, "%s\n", ring->name);
2021
2022 status = I915_READ(RING_EXECLIST_STATUS(ring));
2023 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
2024 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2025 status, ctx_id);
2026
2027 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2028 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2029
2030 read_pointer = ring->next_context_status_buffer;
2031 write_pointer = status_pointer & 0x07;
2032 if (read_pointer > write_pointer)
2033 write_pointer += 6;
2034 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2035 read_pointer, write_pointer);
2036
2037 for (i = 0; i < 6; i++) {
2038 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
2039 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
2040
2041 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2042 i, status, ctx_id);
2043 }
2044
2045 spin_lock_irqsave(&ring->execlist_lock, flags);
2046 list_for_each(cursor, &ring->execlist_queue)
2047 count++;
2048 head_req = list_first_entry_or_null(&ring->execlist_queue,
Nick Hoath6d3d8272015-01-15 13:10:39 +00002049 struct drm_i915_gem_request, execlist_link);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002050 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2051
2052 seq_printf(m, "\t%d requests in queue\n", count);
2053 if (head_req) {
2054 struct drm_i915_gem_object *ctx_obj;
2055
Nick Hoath6d3d8272015-01-15 13:10:39 +00002056 ctx_obj = head_req->ctx->engine[ring_id].state;
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002057 seq_printf(m, "\tHead request id: %u\n",
2058 intel_execlists_ctx_id(ctx_obj));
2059 seq_printf(m, "\tHead request tail: %u\n",
Nick Hoath6d3d8272015-01-15 13:10:39 +00002060 head_req->tail);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002061 }
2062
2063 seq_putc(m, '\n');
2064 }
2065
Michel Thierryfc0412e2014-10-16 16:13:38 +01002066 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01002067 mutex_unlock(&dev->struct_mutex);
2068
2069 return 0;
2070}
2071
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002072static const char *swizzle_string(unsigned swizzle)
2073{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01002074 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002075 case I915_BIT_6_SWIZZLE_NONE:
2076 return "none";
2077 case I915_BIT_6_SWIZZLE_9:
2078 return "bit9";
2079 case I915_BIT_6_SWIZZLE_9_10:
2080 return "bit9/bit10";
2081 case I915_BIT_6_SWIZZLE_9_11:
2082 return "bit9/bit11";
2083 case I915_BIT_6_SWIZZLE_9_10_11:
2084 return "bit9/bit10/bit11";
2085 case I915_BIT_6_SWIZZLE_9_17:
2086 return "bit9/bit17";
2087 case I915_BIT_6_SWIZZLE_9_10_17:
2088 return "bit9/bit10/bit17";
2089 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09002090 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002091 }
2092
2093 return "bug";
2094}
2095
2096static int i915_swizzle_info(struct seq_file *m, void *data)
2097{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002098 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002099 struct drm_device *dev = node->minor->dev;
2100 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002101 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002102
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002103 ret = mutex_lock_interruptible(&dev->struct_mutex);
2104 if (ret)
2105 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002106 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02002107
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002108 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2109 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2110 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2111 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2112
2113 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2114 seq_printf(m, "DDC = 0x%08x\n",
2115 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002116 seq_printf(m, "DDC2 = 0x%08x\n",
2117 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002118 seq_printf(m, "C0DRB3 = 0x%04x\n",
2119 I915_READ16(C0DRB3));
2120 seq_printf(m, "C1DRB3 = 0x%04x\n",
2121 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002122 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002123 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2124 I915_READ(MAD_DIMM_C0));
2125 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2126 I915_READ(MAD_DIMM_C1));
2127 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2128 I915_READ(MAD_DIMM_C2));
2129 seq_printf(m, "TILECTL = 0x%08x\n",
2130 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002131 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002132 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2133 I915_READ(GAMTARBMODE));
2134 else
2135 seq_printf(m, "ARB_MODE = 0x%08x\n",
2136 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002137 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2138 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002139 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002140
2141 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2142 seq_puts(m, "L-shaped memory detected\n");
2143
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002144 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002145 mutex_unlock(&dev->struct_mutex);
2146
2147 return 0;
2148}
2149
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002150static int per_file_ctx(int id, void *ptr, void *data)
2151{
Oscar Mateo273497e2014-05-22 14:13:37 +01002152 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002153 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002154 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2155
2156 if (!ppgtt) {
2157 seq_printf(m, " no ppgtt for context %d\n",
2158 ctx->user_handle);
2159 return 0;
2160 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002161
Oscar Mateof83d6512014-05-22 14:13:38 +01002162 if (i915_gem_context_is_default(ctx))
2163 seq_puts(m, " default context:\n");
2164 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002165 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002166 ppgtt->debug_dump(ppgtt, m);
2167
2168 return 0;
2169}
2170
Ben Widawsky77df6772013-11-02 21:07:30 -07002171static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002172{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002173 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002174 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002175 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2176 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002177
Ben Widawsky77df6772013-11-02 21:07:30 -07002178 if (!ppgtt)
2179 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002180
Ben Widawsky77df6772013-11-02 21:07:30 -07002181 for_each_ring(ring, dev_priv, unused) {
2182 seq_printf(m, "%s\n", ring->name);
2183 for (i = 0; i < 4; i++) {
2184 u32 offset = 0x270 + i * 8;
2185 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2186 pdp <<= 32;
2187 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002188 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002189 }
2190 }
2191}
2192
2193static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2194{
2195 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002196 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002197 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002198 int i;
2199
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002200 if (INTEL_INFO(dev)->gen == 6)
2201 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2202
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002203 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002204 seq_printf(m, "%s\n", ring->name);
2205 if (INTEL_INFO(dev)->gen == 7)
2206 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2207 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2208 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2209 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2210 }
2211 if (dev_priv->mm.aliasing_ppgtt) {
2212 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2213
Damien Lespiau267f0c92013-06-24 22:59:48 +01002214 seq_puts(m, "aliasing PPGTT:\n");
Ben Widawsky7324cc02015-02-24 16:22:35 +00002215 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002216
Ben Widawsky87d60b62013-12-06 14:11:29 -08002217 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002218 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002219
2220 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2221 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002222
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002223 seq_printf(m, "proc: %s\n",
2224 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002225 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002226 }
2227 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002228}
2229
2230static int i915_ppgtt_info(struct seq_file *m, void *data)
2231{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002232 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002233 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002234 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002235
2236 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2237 if (ret)
2238 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002239 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002240
2241 if (INTEL_INFO(dev)->gen >= 8)
2242 gen8_ppgtt_info(m, dev);
2243 else if (INTEL_INFO(dev)->gen >= 6)
2244 gen6_ppgtt_info(m, dev);
2245
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002246 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002247 mutex_unlock(&dev->struct_mutex);
2248
2249 return 0;
2250}
2251
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002252static int count_irq_waiters(struct drm_i915_private *i915)
2253{
2254 struct intel_engine_cs *ring;
2255 int count = 0;
2256 int i;
2257
2258 for_each_ring(ring, i915, i)
2259 count += ring->irq_refcount;
2260
2261 return count;
2262}
2263
Chris Wilson1854d5c2015-04-07 16:20:32 +01002264static int i915_rps_boost_info(struct seq_file *m, void *data)
2265{
2266 struct drm_info_node *node = m->private;
2267 struct drm_device *dev = node->minor->dev;
2268 struct drm_i915_private *dev_priv = dev->dev_private;
2269 struct drm_file *file;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002270
Chris Wilsonf5a4c672015-04-27 13:41:23 +01002271 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2272 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2273 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2274 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2275 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2276 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2277 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2278 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2279 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Chris Wilson8d3afd72015-05-21 21:01:47 +01002280 spin_lock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002281 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2282 struct drm_i915_file_private *file_priv = file->driver_priv;
2283 struct task_struct *task;
2284
2285 rcu_read_lock();
2286 task = pid_task(file->pid, PIDTYPE_PID);
2287 seq_printf(m, "%s [%d]: %d boosts%s\n",
2288 task ? task->comm : "<unknown>",
2289 task ? task->pid : -1,
Chris Wilson2e1b8732015-04-27 13:41:22 +01002290 file_priv->rps.boosts,
2291 list_empty(&file_priv->rps.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002292 rcu_read_unlock();
2293 }
Chris Wilson2e1b8732015-04-27 13:41:22 +01002294 seq_printf(m, "Semaphore boosts: %d%s\n",
2295 dev_priv->rps.semaphores.boosts,
2296 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2297 seq_printf(m, "MMIO flip boosts: %d%s\n",
2298 dev_priv->rps.mmioflips.boosts,
2299 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
Chris Wilson1854d5c2015-04-07 16:20:32 +01002300 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
Chris Wilson8d3afd72015-05-21 21:01:47 +01002301 spin_unlock(&dev_priv->rps.client_lock);
Chris Wilson1854d5c2015-04-07 16:20:32 +01002302
Chris Wilson8d3afd72015-05-21 21:01:47 +01002303 return 0;
Chris Wilson1854d5c2015-04-07 16:20:32 +01002304}
2305
Ben Widawsky63573eb2013-07-04 11:02:07 -07002306static int i915_llc(struct seq_file *m, void *data)
2307{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002308 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002309 struct drm_device *dev = node->minor->dev;
2310 struct drm_i915_private *dev_priv = dev->dev_private;
2311
2312 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2313 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2314 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2315
2316 return 0;
2317}
2318
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002319static int i915_edp_psr_status(struct seq_file *m, void *data)
2320{
2321 struct drm_info_node *node = m->private;
2322 struct drm_device *dev = node->minor->dev;
2323 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002324 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002325 u32 stat[3];
2326 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002327 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002328
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002329 if (!HAS_PSR(dev)) {
2330 seq_puts(m, "PSR not supported\n");
2331 return 0;
2332 }
2333
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002334 intel_runtime_pm_get(dev_priv);
2335
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002336 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002337 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2338 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002339 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002340 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002341 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2342 dev_priv->psr.busy_frontbuffer_bits);
2343 seq_printf(m, "Re-enable work scheduled: %s\n",
2344 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002345
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002346 if (HAS_DDI(dev))
2347 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2348 else {
2349 for_each_pipe(dev_priv, pipe) {
2350 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2351 VLV_EDP_PSR_CURR_STATE_MASK;
2352 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2353 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2354 enabled = true;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002355 }
2356 }
2357 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002358
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002359 if (!HAS_DDI(dev))
2360 for_each_pipe(dev_priv, pipe) {
2361 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2362 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2363 seq_printf(m, " pipe %c", pipe_name(pipe));
2364 }
2365 seq_puts(m, "\n");
2366
2367 /* CHV PSR has no kind of performance counter */
Damien Lespiau3553a8e2015-03-09 14:17:58 +00002368 if (HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002369 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2370 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002371
2372 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2373 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002374 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002375
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002376 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002377 return 0;
2378}
2379
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002380static int i915_sink_crc(struct seq_file *m, void *data)
2381{
2382 struct drm_info_node *node = m->private;
2383 struct drm_device *dev = node->minor->dev;
2384 struct intel_encoder *encoder;
2385 struct intel_connector *connector;
2386 struct intel_dp *intel_dp = NULL;
2387 int ret;
2388 u8 crc[6];
2389
2390 drm_modeset_lock_all(dev);
Rodrigo Viviaca5e362015-03-13 16:13:59 -07002391 for_each_intel_connector(dev, connector) {
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002392
2393 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2394 continue;
2395
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002396 if (!connector->base.encoder)
2397 continue;
2398
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002399 encoder = to_intel_encoder(connector->base.encoder);
2400 if (encoder->type != INTEL_OUTPUT_EDP)
2401 continue;
2402
2403 intel_dp = enc_to_intel_dp(&encoder->base);
2404
2405 ret = intel_dp_sink_crc(intel_dp, crc);
2406 if (ret)
2407 goto out;
2408
2409 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2410 crc[0], crc[1], crc[2],
2411 crc[3], crc[4], crc[5]);
2412 goto out;
2413 }
2414 ret = -ENODEV;
2415out:
2416 drm_modeset_unlock_all(dev);
2417 return ret;
2418}
2419
Jesse Barnesec013e72013-08-20 10:29:23 +01002420static int i915_energy_uJ(struct seq_file *m, void *data)
2421{
2422 struct drm_info_node *node = m->private;
2423 struct drm_device *dev = node->minor->dev;
2424 struct drm_i915_private *dev_priv = dev->dev_private;
2425 u64 power;
2426 u32 units;
2427
2428 if (INTEL_INFO(dev)->gen < 6)
2429 return -ENODEV;
2430
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002431 intel_runtime_pm_get(dev_priv);
2432
Jesse Barnesec013e72013-08-20 10:29:23 +01002433 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2434 power = (power & 0x1f00) >> 8;
2435 units = 1000000 / (1 << power); /* convert to uJ */
2436 power = I915_READ(MCH_SECP_NRG_STTS);
2437 power *= units;
2438
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002439 intel_runtime_pm_put(dev_priv);
2440
Jesse Barnesec013e72013-08-20 10:29:23 +01002441 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002442
2443 return 0;
2444}
2445
Damien Lespiau6455c872015-06-04 18:23:57 +01002446static int i915_runtime_pm_status(struct seq_file *m, void *unused)
Paulo Zanoni371db662013-08-19 13:18:10 -03002447{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002448 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002449 struct drm_device *dev = node->minor->dev;
2450 struct drm_i915_private *dev_priv = dev->dev_private;
2451
Damien Lespiau6455c872015-06-04 18:23:57 +01002452 if (!HAS_RUNTIME_PM(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002453 seq_puts(m, "not supported\n");
2454 return 0;
2455 }
2456
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002457 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002458 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002459 yesno(!intel_irqs_enabled(dev_priv)));
Chris Wilson0d804182015-06-15 12:52:28 +01002460#ifdef CONFIG_PM
Damien Lespiaua6aaec82015-06-04 18:23:58 +01002461 seq_printf(m, "Usage count: %d\n",
2462 atomic_read(&dev->dev->power.usage_count));
Chris Wilson0d804182015-06-15 12:52:28 +01002463#else
2464 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2465#endif
Paulo Zanoni371db662013-08-19 13:18:10 -03002466
Jesse Barnesec013e72013-08-20 10:29:23 +01002467 return 0;
2468}
2469
Imre Deak1da51582013-11-25 17:15:35 +02002470static const char *power_domain_str(enum intel_display_power_domain domain)
2471{
2472 switch (domain) {
2473 case POWER_DOMAIN_PIPE_A:
2474 return "PIPE_A";
2475 case POWER_DOMAIN_PIPE_B:
2476 return "PIPE_B";
2477 case POWER_DOMAIN_PIPE_C:
2478 return "PIPE_C";
2479 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2480 return "PIPE_A_PANEL_FITTER";
2481 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2482 return "PIPE_B_PANEL_FITTER";
2483 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2484 return "PIPE_C_PANEL_FITTER";
2485 case POWER_DOMAIN_TRANSCODER_A:
2486 return "TRANSCODER_A";
2487 case POWER_DOMAIN_TRANSCODER_B:
2488 return "TRANSCODER_B";
2489 case POWER_DOMAIN_TRANSCODER_C:
2490 return "TRANSCODER_C";
2491 case POWER_DOMAIN_TRANSCODER_EDP:
2492 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002493 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2494 return "PORT_DDI_A_2_LANES";
2495 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2496 return "PORT_DDI_A_4_LANES";
2497 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2498 return "PORT_DDI_B_2_LANES";
2499 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2500 return "PORT_DDI_B_4_LANES";
2501 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2502 return "PORT_DDI_C_2_LANES";
2503 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2504 return "PORT_DDI_C_4_LANES";
2505 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2506 return "PORT_DDI_D_2_LANES";
2507 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2508 return "PORT_DDI_D_4_LANES";
2509 case POWER_DOMAIN_PORT_DSI:
2510 return "PORT_DSI";
2511 case POWER_DOMAIN_PORT_CRT:
2512 return "PORT_CRT";
2513 case POWER_DOMAIN_PORT_OTHER:
2514 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002515 case POWER_DOMAIN_VGA:
2516 return "VGA";
2517 case POWER_DOMAIN_AUDIO:
2518 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002519 case POWER_DOMAIN_PLLS:
2520 return "PLLS";
Satheeshakrishna M14071212015-01-16 15:57:51 +00002521 case POWER_DOMAIN_AUX_A:
2522 return "AUX_A";
2523 case POWER_DOMAIN_AUX_B:
2524 return "AUX_B";
2525 case POWER_DOMAIN_AUX_C:
2526 return "AUX_C";
2527 case POWER_DOMAIN_AUX_D:
2528 return "AUX_D";
Imre Deak1da51582013-11-25 17:15:35 +02002529 case POWER_DOMAIN_INIT:
2530 return "INIT";
2531 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002532 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002533 return "?";
2534 }
2535}
2536
2537static int i915_power_domain_info(struct seq_file *m, void *unused)
2538{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002539 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002540 struct drm_device *dev = node->minor->dev;
2541 struct drm_i915_private *dev_priv = dev->dev_private;
2542 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2543 int i;
2544
2545 mutex_lock(&power_domains->lock);
2546
2547 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2548 for (i = 0; i < power_domains->power_well_count; i++) {
2549 struct i915_power_well *power_well;
2550 enum intel_display_power_domain power_domain;
2551
2552 power_well = &power_domains->power_wells[i];
2553 seq_printf(m, "%-25s %d\n", power_well->name,
2554 power_well->count);
2555
2556 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2557 power_domain++) {
2558 if (!(BIT(power_domain) & power_well->domains))
2559 continue;
2560
2561 seq_printf(m, " %-23s %d\n",
2562 power_domain_str(power_domain),
2563 power_domains->domain_use_count[power_domain]);
2564 }
2565 }
2566
2567 mutex_unlock(&power_domains->lock);
2568
2569 return 0;
2570}
2571
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002572static void intel_seq_print_mode(struct seq_file *m, int tabs,
2573 struct drm_display_mode *mode)
2574{
2575 int i;
2576
2577 for (i = 0; i < tabs; i++)
2578 seq_putc(m, '\t');
2579
2580 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",
2581 mode->base.id, mode->name,
2582 mode->vrefresh, mode->clock,
2583 mode->hdisplay, mode->hsync_start,
2584 mode->hsync_end, mode->htotal,
2585 mode->vdisplay, mode->vsync_start,
2586 mode->vsync_end, mode->vtotal,
2587 mode->type, mode->flags);
2588}
2589
2590static void intel_encoder_info(struct seq_file *m,
2591 struct intel_crtc *intel_crtc,
2592 struct intel_encoder *intel_encoder)
2593{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002594 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002595 struct drm_device *dev = node->minor->dev;
2596 struct drm_crtc *crtc = &intel_crtc->base;
2597 struct intel_connector *intel_connector;
2598 struct drm_encoder *encoder;
2599
2600 encoder = &intel_encoder->base;
2601 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002602 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002603 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2604 struct drm_connector *connector = &intel_connector->base;
2605 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2606 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002607 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002608 drm_get_connector_status_name(connector->status));
2609 if (connector->status == connector_status_connected) {
2610 struct drm_display_mode *mode = &crtc->mode;
2611 seq_printf(m, ", mode:\n");
2612 intel_seq_print_mode(m, 2, mode);
2613 } else {
2614 seq_putc(m, '\n');
2615 }
2616 }
2617}
2618
2619static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2620{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002621 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002622 struct drm_device *dev = node->minor->dev;
2623 struct drm_crtc *crtc = &intel_crtc->base;
2624 struct intel_encoder *intel_encoder;
2625
Matt Roper5aa8a932014-06-16 10:12:55 -07002626 if (crtc->primary->fb)
2627 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2628 crtc->primary->fb->base.id, crtc->x, crtc->y,
2629 crtc->primary->fb->width, crtc->primary->fb->height);
2630 else
2631 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002632 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2633 intel_encoder_info(m, intel_crtc, intel_encoder);
2634}
2635
2636static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2637{
2638 struct drm_display_mode *mode = panel->fixed_mode;
2639
2640 seq_printf(m, "\tfixed mode:\n");
2641 intel_seq_print_mode(m, 2, mode);
2642}
2643
2644static void intel_dp_info(struct seq_file *m,
2645 struct intel_connector *intel_connector)
2646{
2647 struct intel_encoder *intel_encoder = intel_connector->encoder;
2648 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2649
2650 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2651 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2652 "no");
2653 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2654 intel_panel_info(m, &intel_connector->panel);
2655}
2656
2657static void intel_hdmi_info(struct seq_file *m,
2658 struct intel_connector *intel_connector)
2659{
2660 struct intel_encoder *intel_encoder = intel_connector->encoder;
2661 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2662
2663 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2664 "no");
2665}
2666
2667static void intel_lvds_info(struct seq_file *m,
2668 struct intel_connector *intel_connector)
2669{
2670 intel_panel_info(m, &intel_connector->panel);
2671}
2672
2673static void intel_connector_info(struct seq_file *m,
2674 struct drm_connector *connector)
2675{
2676 struct intel_connector *intel_connector = to_intel_connector(connector);
2677 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002678 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002679
2680 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002681 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002682 drm_get_connector_status_name(connector->status));
2683 if (connector->status == connector_status_connected) {
2684 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2685 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2686 connector->display_info.width_mm,
2687 connector->display_info.height_mm);
2688 seq_printf(m, "\tsubpixel order: %s\n",
2689 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2690 seq_printf(m, "\tCEA rev: %d\n",
2691 connector->display_info.cea_rev);
2692 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002693 if (intel_encoder) {
2694 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2695 intel_encoder->type == INTEL_OUTPUT_EDP)
2696 intel_dp_info(m, intel_connector);
2697 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2698 intel_hdmi_info(m, intel_connector);
2699 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2700 intel_lvds_info(m, intel_connector);
2701 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002702
Jesse Barnesf103fc72014-02-20 12:39:57 -08002703 seq_printf(m, "\tmodes:\n");
2704 list_for_each_entry(mode, &connector->modes, head)
2705 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002706}
2707
Chris Wilson065f2ec2014-03-12 09:13:13 +00002708static bool cursor_active(struct drm_device *dev, int pipe)
2709{
2710 struct drm_i915_private *dev_priv = dev->dev_private;
2711 u32 state;
2712
2713 if (IS_845G(dev) || IS_I865G(dev))
2714 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002715 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002716 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002717
2718 return state;
2719}
2720
2721static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2722{
2723 struct drm_i915_private *dev_priv = dev->dev_private;
2724 u32 pos;
2725
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002726 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002727
2728 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2729 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2730 *x = -*x;
2731
2732 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2733 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2734 *y = -*y;
2735
2736 return cursor_active(dev, pipe);
2737}
2738
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002739static int i915_display_info(struct seq_file *m, void *unused)
2740{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002741 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002742 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002743 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002744 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002745 struct drm_connector *connector;
2746
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002747 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002748 drm_modeset_lock_all(dev);
2749 seq_printf(m, "CRTC info\n");
2750 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002751 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002752 bool active;
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002753 struct intel_crtc_state *pipe_config;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002754 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002755
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002756 pipe_config = to_intel_crtc_state(crtc->base.state);
2757
Chris Wilson57127ef2014-07-04 08:20:11 +01002758 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002759 crtc->base.base.id, pipe_name(crtc->pipe),
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02002760 yesno(pipe_config->base.active),
2761 pipe_config->pipe_src_w, pipe_config->pipe_src_h);
2762 if (pipe_config->base.active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002763 intel_crtc_info(m, crtc);
2764
Paulo Zanonia23dc652014-04-01 14:55:11 -03002765 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002766 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 +03002767 yesno(crtc->cursor_base),
Matt Roper3dd512f2015-02-27 10:12:00 -08002768 x, y, crtc->base.cursor->state->crtc_w,
2769 crtc->base.cursor->state->crtc_h,
Chris Wilson57127ef2014-07-04 08:20:11 +01002770 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002771 }
Daniel Vettercace8412014-05-22 17:56:31 +02002772
2773 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2774 yesno(!crtc->cpu_fifo_underrun_disabled),
2775 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002776 }
2777
2778 seq_printf(m, "\n");
2779 seq_printf(m, "Connector info\n");
2780 seq_printf(m, "--------------\n");
2781 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2782 intel_connector_info(m, connector);
2783 }
2784 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002785 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002786
2787 return 0;
2788}
2789
Ben Widawskye04934c2014-06-30 09:53:42 -07002790static int i915_semaphore_status(struct seq_file *m, void *unused)
2791{
2792 struct drm_info_node *node = (struct drm_info_node *) m->private;
2793 struct drm_device *dev = node->minor->dev;
2794 struct drm_i915_private *dev_priv = dev->dev_private;
2795 struct intel_engine_cs *ring;
2796 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2797 int i, j, ret;
2798
2799 if (!i915_semaphore_is_enabled(dev)) {
2800 seq_puts(m, "Semaphores are disabled\n");
2801 return 0;
2802 }
2803
2804 ret = mutex_lock_interruptible(&dev->struct_mutex);
2805 if (ret)
2806 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002807 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002808
2809 if (IS_BROADWELL(dev)) {
2810 struct page *page;
2811 uint64_t *seqno;
2812
2813 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2814
2815 seqno = (uint64_t *)kmap_atomic(page);
2816 for_each_ring(ring, dev_priv, i) {
2817 uint64_t offset;
2818
2819 seq_printf(m, "%s\n", ring->name);
2820
2821 seq_puts(m, " Last signal:");
2822 for (j = 0; j < num_rings; j++) {
2823 offset = i * I915_NUM_RINGS + j;
2824 seq_printf(m, "0x%08llx (0x%02llx) ",
2825 seqno[offset], offset * 8);
2826 }
2827 seq_putc(m, '\n');
2828
2829 seq_puts(m, " Last wait: ");
2830 for (j = 0; j < num_rings; j++) {
2831 offset = i + (j * I915_NUM_RINGS);
2832 seq_printf(m, "0x%08llx (0x%02llx) ",
2833 seqno[offset], offset * 8);
2834 }
2835 seq_putc(m, '\n');
2836
2837 }
2838 kunmap_atomic(seqno);
2839 } else {
2840 seq_puts(m, " Last signal:");
2841 for_each_ring(ring, dev_priv, i)
2842 for (j = 0; j < num_rings; j++)
2843 seq_printf(m, "0x%08x\n",
2844 I915_READ(ring->semaphore.mbox.signal[j]));
2845 seq_putc(m, '\n');
2846 }
2847
2848 seq_puts(m, "\nSync seqno:\n");
2849 for_each_ring(ring, dev_priv, i) {
2850 for (j = 0; j < num_rings; j++) {
2851 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2852 }
2853 seq_putc(m, '\n');
2854 }
2855 seq_putc(m, '\n');
2856
Paulo Zanoni03872062014-07-09 14:31:57 -03002857 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002858 mutex_unlock(&dev->struct_mutex);
2859 return 0;
2860}
2861
Daniel Vetter728e29d2014-06-25 22:01:53 +03002862static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2863{
2864 struct drm_info_node *node = (struct drm_info_node *) m->private;
2865 struct drm_device *dev = node->minor->dev;
2866 struct drm_i915_private *dev_priv = dev->dev_private;
2867 int i;
2868
2869 drm_modeset_lock_all(dev);
2870 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2871 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2872
2873 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002874 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002875 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03002876 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002877 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2878 seq_printf(m, " dpll_md: 0x%08x\n",
2879 pll->config.hw_state.dpll_md);
2880 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2881 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2882 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002883 }
2884 drm_modeset_unlock_all(dev);
2885
2886 return 0;
2887}
2888
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01002889static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01002890{
2891 int i;
2892 int ret;
2893 struct drm_info_node *node = (struct drm_info_node *) m->private;
2894 struct drm_device *dev = node->minor->dev;
2895 struct drm_i915_private *dev_priv = dev->dev_private;
2896
Arun Siluvery888b5992014-08-26 14:44:51 +01002897 ret = mutex_lock_interruptible(&dev->struct_mutex);
2898 if (ret)
2899 return ret;
2900
2901 intel_runtime_pm_get(dev_priv);
2902
Mika Kuoppala72253422014-10-07 17:21:26 +03002903 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
2904 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002905 u32 addr, mask, value, read;
2906 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01002907
Mika Kuoppala72253422014-10-07 17:21:26 +03002908 addr = dev_priv->workarounds.reg[i].addr;
2909 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002910 value = dev_priv->workarounds.reg[i].value;
2911 read = I915_READ(addr);
2912 ok = (value & mask) == (read & mask);
2913 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
2914 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01002915 }
2916
2917 intel_runtime_pm_put(dev_priv);
2918 mutex_unlock(&dev->struct_mutex);
2919
2920 return 0;
2921}
2922
Damien Lespiauc5511e42014-11-04 17:06:51 +00002923static int i915_ddb_info(struct seq_file *m, void *unused)
2924{
2925 struct drm_info_node *node = m->private;
2926 struct drm_device *dev = node->minor->dev;
2927 struct drm_i915_private *dev_priv = dev->dev_private;
2928 struct skl_ddb_allocation *ddb;
2929 struct skl_ddb_entry *entry;
2930 enum pipe pipe;
2931 int plane;
2932
Damien Lespiau2fcffe12014-12-03 17:33:24 +00002933 if (INTEL_INFO(dev)->gen < 9)
2934 return 0;
2935
Damien Lespiauc5511e42014-11-04 17:06:51 +00002936 drm_modeset_lock_all(dev);
2937
2938 ddb = &dev_priv->wm.skl_hw.ddb;
2939
2940 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
2941
2942 for_each_pipe(dev_priv, pipe) {
2943 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
2944
Damien Lespiaudd740782015-02-28 14:54:08 +00002945 for_each_plane(dev_priv, pipe, plane) {
Damien Lespiauc5511e42014-11-04 17:06:51 +00002946 entry = &ddb->plane[pipe][plane];
2947 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
2948 entry->start, entry->end,
2949 skl_ddb_entry_size(entry));
2950 }
2951
2952 entry = &ddb->cursor[pipe];
2953 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
2954 entry->end, skl_ddb_entry_size(entry));
2955 }
2956
2957 drm_modeset_unlock_all(dev);
2958
2959 return 0;
2960}
2961
Vandana Kannana54746e2015-03-03 20:53:10 +05302962static void drrs_status_per_crtc(struct seq_file *m,
2963 struct drm_device *dev, struct intel_crtc *intel_crtc)
2964{
2965 struct intel_encoder *intel_encoder;
2966 struct drm_i915_private *dev_priv = dev->dev_private;
2967 struct i915_drrs *drrs = &dev_priv->drrs;
2968 int vrefresh = 0;
2969
2970 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
2971 /* Encoder connected on this CRTC */
2972 switch (intel_encoder->type) {
2973 case INTEL_OUTPUT_EDP:
2974 seq_puts(m, "eDP:\n");
2975 break;
2976 case INTEL_OUTPUT_DSI:
2977 seq_puts(m, "DSI:\n");
2978 break;
2979 case INTEL_OUTPUT_HDMI:
2980 seq_puts(m, "HDMI:\n");
2981 break;
2982 case INTEL_OUTPUT_DISPLAYPORT:
2983 seq_puts(m, "DP:\n");
2984 break;
2985 default:
2986 seq_printf(m, "Other encoder (id=%d).\n",
2987 intel_encoder->type);
2988 return;
2989 }
2990 }
2991
2992 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
2993 seq_puts(m, "\tVBT: DRRS_type: Static");
2994 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
2995 seq_puts(m, "\tVBT: DRRS_type: Seamless");
2996 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
2997 seq_puts(m, "\tVBT: DRRS_type: None");
2998 else
2999 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3000
3001 seq_puts(m, "\n\n");
3002
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003003 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303004 struct intel_panel *panel;
3005
3006 mutex_lock(&drrs->mutex);
3007 /* DRRS Supported */
3008 seq_puts(m, "\tDRRS Supported: Yes\n");
3009
3010 /* disable_drrs() will make drrs->dp NULL */
3011 if (!drrs->dp) {
3012 seq_puts(m, "Idleness DRRS: Disabled");
3013 mutex_unlock(&drrs->mutex);
3014 return;
3015 }
3016
3017 panel = &drrs->dp->attached_connector->panel;
3018 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3019 drrs->busy_frontbuffer_bits);
3020
3021 seq_puts(m, "\n\t\t");
3022 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3023 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3024 vrefresh = panel->fixed_mode->vrefresh;
3025 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3026 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3027 vrefresh = panel->downclock_mode->vrefresh;
3028 } else {
3029 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3030 drrs->refresh_rate_type);
3031 mutex_unlock(&drrs->mutex);
3032 return;
3033 }
3034 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3035
3036 seq_puts(m, "\n\t\t");
3037 mutex_unlock(&drrs->mutex);
3038 } else {
3039 /* DRRS not supported. Print the VBT parameter*/
3040 seq_puts(m, "\tDRRS Supported : No");
3041 }
3042 seq_puts(m, "\n");
3043}
3044
3045static int i915_drrs_status(struct seq_file *m, void *unused)
3046{
3047 struct drm_info_node *node = m->private;
3048 struct drm_device *dev = node->minor->dev;
3049 struct intel_crtc *intel_crtc;
3050 int active_crtc_cnt = 0;
3051
3052 for_each_intel_crtc(dev, intel_crtc) {
3053 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3054
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003055 if (intel_crtc->base.state->active) {
Vandana Kannana54746e2015-03-03 20:53:10 +05303056 active_crtc_cnt++;
3057 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3058
3059 drrs_status_per_crtc(m, dev, intel_crtc);
3060 }
3061
3062 drm_modeset_unlock(&intel_crtc->base.mutex);
3063 }
3064
3065 if (!active_crtc_cnt)
3066 seq_puts(m, "No active crtc found\n");
3067
3068 return 0;
3069}
3070
Damien Lespiau07144422013-10-15 18:55:40 +01003071struct pipe_crc_info {
3072 const char *name;
3073 struct drm_device *dev;
3074 enum pipe pipe;
3075};
3076
Dave Airlie11bed952014-05-12 15:22:27 +10003077static int i915_dp_mst_info(struct seq_file *m, void *unused)
3078{
3079 struct drm_info_node *node = (struct drm_info_node *) m->private;
3080 struct drm_device *dev = node->minor->dev;
3081 struct drm_encoder *encoder;
3082 struct intel_encoder *intel_encoder;
3083 struct intel_digital_port *intel_dig_port;
3084 drm_modeset_lock_all(dev);
3085 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3086 intel_encoder = to_intel_encoder(encoder);
3087 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3088 continue;
3089 intel_dig_port = enc_to_dig_port(encoder);
3090 if (!intel_dig_port->dp.can_mst)
3091 continue;
3092
3093 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3094 }
3095 drm_modeset_unlock_all(dev);
3096 return 0;
3097}
3098
Damien Lespiau07144422013-10-15 18:55:40 +01003099static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01003100{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003101 struct pipe_crc_info *info = inode->i_private;
3102 struct drm_i915_private *dev_priv = info->dev->dev_private;
3103 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3104
Daniel Vetter7eb1c492013-11-14 11:30:43 +01003105 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3106 return -ENODEV;
3107
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003108 spin_lock_irq(&pipe_crc->lock);
3109
3110 if (pipe_crc->opened) {
3111 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003112 return -EBUSY; /* already open */
3113 }
3114
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003115 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01003116 filep->private_data = inode->i_private;
3117
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003118 spin_unlock_irq(&pipe_crc->lock);
3119
Damien Lespiau07144422013-10-15 18:55:40 +01003120 return 0;
3121}
3122
3123static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3124{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003125 struct pipe_crc_info *info = inode->i_private;
3126 struct drm_i915_private *dev_priv = info->dev->dev_private;
3127 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3128
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003129 spin_lock_irq(&pipe_crc->lock);
3130 pipe_crc->opened = false;
3131 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01003132
Damien Lespiau07144422013-10-15 18:55:40 +01003133 return 0;
3134}
3135
3136/* (6 fields, 8 chars each, space separated (5) + '\n') */
3137#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3138/* account for \'0' */
3139#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3140
3141static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
3142{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003143 assert_spin_locked(&pipe_crc->lock);
3144 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3145 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01003146}
Shuang He8bf1e9f2013-10-15 18:55:27 +01003147
Damien Lespiau07144422013-10-15 18:55:40 +01003148static ssize_t
3149i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3150 loff_t *pos)
3151{
3152 struct pipe_crc_info *info = filep->private_data;
3153 struct drm_device *dev = info->dev;
3154 struct drm_i915_private *dev_priv = dev->dev_private;
3155 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3156 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003157 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01003158 ssize_t bytes_read;
3159
3160 /*
3161 * Don't allow user space to provide buffers not big enough to hold
3162 * a line of data.
3163 */
3164 if (count < PIPE_CRC_LINE_LEN)
3165 return -EINVAL;
3166
3167 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
3168 return 0;
3169
3170 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003171 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003172 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003173 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01003174
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003175 if (filep->f_flags & O_NONBLOCK) {
3176 spin_unlock_irq(&pipe_crc->lock);
3177 return -EAGAIN;
3178 }
3179
3180 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3181 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3182 if (ret) {
3183 spin_unlock_irq(&pipe_crc->lock);
3184 return ret;
3185 }
Damien Lespiau07144422013-10-15 18:55:40 +01003186 }
3187
3188 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003189 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003190
Damien Lespiau07144422013-10-15 18:55:40 +01003191 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003192 while (n_entries > 0) {
3193 struct intel_pipe_crc_entry *entry =
3194 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01003195 int ret;
3196
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003197 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3198 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3199 break;
3200
3201 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3202 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3203
Damien Lespiau07144422013-10-15 18:55:40 +01003204 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3205 "%8u %8x %8x %8x %8x %8x\n",
3206 entry->frame, entry->crc[0],
3207 entry->crc[1], entry->crc[2],
3208 entry->crc[3], entry->crc[4]);
3209
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003210 spin_unlock_irq(&pipe_crc->lock);
3211
3212 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01003213 if (ret == PIPE_CRC_LINE_LEN)
3214 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01003215
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003216 user_buf += PIPE_CRC_LINE_LEN;
3217 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01003218
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003219 spin_lock_irq(&pipe_crc->lock);
3220 }
3221
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003222 spin_unlock_irq(&pipe_crc->lock);
3223
Damien Lespiau07144422013-10-15 18:55:40 +01003224 return bytes_read;
3225}
3226
3227static const struct file_operations i915_pipe_crc_fops = {
3228 .owner = THIS_MODULE,
3229 .open = i915_pipe_crc_open,
3230 .read = i915_pipe_crc_read,
3231 .release = i915_pipe_crc_release,
3232};
3233
3234static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3235 {
3236 .name = "i915_pipe_A_crc",
3237 .pipe = PIPE_A,
3238 },
3239 {
3240 .name = "i915_pipe_B_crc",
3241 .pipe = PIPE_B,
3242 },
3243 {
3244 .name = "i915_pipe_C_crc",
3245 .pipe = PIPE_C,
3246 },
3247};
3248
3249static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3250 enum pipe pipe)
3251{
3252 struct drm_device *dev = minor->dev;
3253 struct dentry *ent;
3254 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3255
3256 info->dev = dev;
3257 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3258 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003259 if (!ent)
3260 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01003261
3262 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01003263}
3264
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003265static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003266 "none",
3267 "plane1",
3268 "plane2",
3269 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003270 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02003271 "TV",
3272 "DP-B",
3273 "DP-C",
3274 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01003275 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02003276};
3277
3278static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3279{
3280 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3281 return pipe_crc_sources[source];
3282}
3283
Damien Lespiaubd9db022013-10-15 18:55:36 +01003284static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02003285{
3286 struct drm_device *dev = m->private;
3287 struct drm_i915_private *dev_priv = dev->dev_private;
3288 int i;
3289
3290 for (i = 0; i < I915_MAX_PIPES; i++)
3291 seq_printf(m, "%c %s\n", pipe_name(i),
3292 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3293
3294 return 0;
3295}
3296
Damien Lespiaubd9db022013-10-15 18:55:36 +01003297static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003298{
3299 struct drm_device *dev = inode->i_private;
3300
Damien Lespiaubd9db022013-10-15 18:55:36 +01003301 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003302}
3303
Daniel Vetter46a19182013-11-01 10:50:20 +01003304static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003305 uint32_t *val)
3306{
Daniel Vetter46a19182013-11-01 10:50:20 +01003307 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3308 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3309
3310 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003311 case INTEL_PIPE_CRC_SOURCE_PIPE:
3312 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3313 break;
3314 case INTEL_PIPE_CRC_SOURCE_NONE:
3315 *val = 0;
3316 break;
3317 default:
3318 return -EINVAL;
3319 }
3320
3321 return 0;
3322}
3323
Daniel Vetter46a19182013-11-01 10:50:20 +01003324static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3325 enum intel_pipe_crc_source *source)
3326{
3327 struct intel_encoder *encoder;
3328 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003329 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003330 int ret = 0;
3331
3332 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3333
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003334 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003335 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003336 if (!encoder->base.crtc)
3337 continue;
3338
3339 crtc = to_intel_crtc(encoder->base.crtc);
3340
3341 if (crtc->pipe != pipe)
3342 continue;
3343
3344 switch (encoder->type) {
3345 case INTEL_OUTPUT_TVOUT:
3346 *source = INTEL_PIPE_CRC_SOURCE_TV;
3347 break;
3348 case INTEL_OUTPUT_DISPLAYPORT:
3349 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003350 dig_port = enc_to_dig_port(&encoder->base);
3351 switch (dig_port->port) {
3352 case PORT_B:
3353 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3354 break;
3355 case PORT_C:
3356 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3357 break;
3358 case PORT_D:
3359 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3360 break;
3361 default:
3362 WARN(1, "nonexisting DP port %c\n",
3363 port_name(dig_port->port));
3364 break;
3365 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003366 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003367 default:
3368 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003369 }
3370 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003371 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003372
3373 return ret;
3374}
3375
3376static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3377 enum pipe pipe,
3378 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003379 uint32_t *val)
3380{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003381 struct drm_i915_private *dev_priv = dev->dev_private;
3382 bool need_stable_symbols = false;
3383
Daniel Vetter46a19182013-11-01 10:50:20 +01003384 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3385 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3386 if (ret)
3387 return ret;
3388 }
3389
3390 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003391 case INTEL_PIPE_CRC_SOURCE_PIPE:
3392 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3393 break;
3394 case INTEL_PIPE_CRC_SOURCE_DP_B:
3395 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003396 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003397 break;
3398 case INTEL_PIPE_CRC_SOURCE_DP_C:
3399 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003400 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003401 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003402 case INTEL_PIPE_CRC_SOURCE_DP_D:
3403 if (!IS_CHERRYVIEW(dev))
3404 return -EINVAL;
3405 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3406 need_stable_symbols = true;
3407 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003408 case INTEL_PIPE_CRC_SOURCE_NONE:
3409 *val = 0;
3410 break;
3411 default:
3412 return -EINVAL;
3413 }
3414
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003415 /*
3416 * When the pipe CRC tap point is after the transcoders we need
3417 * to tweak symbol-level features to produce a deterministic series of
3418 * symbols for a given frame. We need to reset those features only once
3419 * a frame (instead of every nth symbol):
3420 * - DC-balance: used to ensure a better clock recovery from the data
3421 * link (SDVO)
3422 * - DisplayPort scrambling: used for EMI reduction
3423 */
3424 if (need_stable_symbols) {
3425 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3426
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003427 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003428 switch (pipe) {
3429 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003430 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003431 break;
3432 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003433 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003434 break;
3435 case PIPE_C:
3436 tmp |= PIPE_C_SCRAMBLE_RESET;
3437 break;
3438 default:
3439 return -EINVAL;
3440 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003441 I915_WRITE(PORT_DFT2_G4X, tmp);
3442 }
3443
Daniel Vetter7ac01292013-10-18 16:37:06 +02003444 return 0;
3445}
3446
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003447static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003448 enum pipe pipe,
3449 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003450 uint32_t *val)
3451{
Daniel Vetter84093602013-11-01 10:50:21 +01003452 struct drm_i915_private *dev_priv = dev->dev_private;
3453 bool need_stable_symbols = false;
3454
Daniel Vetter46a19182013-11-01 10:50:20 +01003455 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3456 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3457 if (ret)
3458 return ret;
3459 }
3460
3461 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003462 case INTEL_PIPE_CRC_SOURCE_PIPE:
3463 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3464 break;
3465 case INTEL_PIPE_CRC_SOURCE_TV:
3466 if (!SUPPORTS_TV(dev))
3467 return -EINVAL;
3468 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3469 break;
3470 case INTEL_PIPE_CRC_SOURCE_DP_B:
3471 if (!IS_G4X(dev))
3472 return -EINVAL;
3473 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003474 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003475 break;
3476 case INTEL_PIPE_CRC_SOURCE_DP_C:
3477 if (!IS_G4X(dev))
3478 return -EINVAL;
3479 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003480 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003481 break;
3482 case INTEL_PIPE_CRC_SOURCE_DP_D:
3483 if (!IS_G4X(dev))
3484 return -EINVAL;
3485 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003486 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003487 break;
3488 case INTEL_PIPE_CRC_SOURCE_NONE:
3489 *val = 0;
3490 break;
3491 default:
3492 return -EINVAL;
3493 }
3494
Daniel Vetter84093602013-11-01 10:50:21 +01003495 /*
3496 * When the pipe CRC tap point is after the transcoders we need
3497 * to tweak symbol-level features to produce a deterministic series of
3498 * symbols for a given frame. We need to reset those features only once
3499 * a frame (instead of every nth symbol):
3500 * - DC-balance: used to ensure a better clock recovery from the data
3501 * link (SDVO)
3502 * - DisplayPort scrambling: used for EMI reduction
3503 */
3504 if (need_stable_symbols) {
3505 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3506
3507 WARN_ON(!IS_G4X(dev));
3508
3509 I915_WRITE(PORT_DFT_I9XX,
3510 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3511
3512 if (pipe == PIPE_A)
3513 tmp |= PIPE_A_SCRAMBLE_RESET;
3514 else
3515 tmp |= PIPE_B_SCRAMBLE_RESET;
3516
3517 I915_WRITE(PORT_DFT2_G4X, tmp);
3518 }
3519
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003520 return 0;
3521}
3522
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003523static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3524 enum pipe pipe)
3525{
3526 struct drm_i915_private *dev_priv = dev->dev_private;
3527 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3528
Ville Syrjäläeb736672014-12-09 21:28:28 +02003529 switch (pipe) {
3530 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003531 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003532 break;
3533 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003534 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003535 break;
3536 case PIPE_C:
3537 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3538 break;
3539 default:
3540 return;
3541 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003542 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3543 tmp &= ~DC_BALANCE_RESET_VLV;
3544 I915_WRITE(PORT_DFT2_G4X, tmp);
3545
3546}
3547
Daniel Vetter84093602013-11-01 10:50:21 +01003548static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3549 enum pipe pipe)
3550{
3551 struct drm_i915_private *dev_priv = dev->dev_private;
3552 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3553
3554 if (pipe == PIPE_A)
3555 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3556 else
3557 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3558 I915_WRITE(PORT_DFT2_G4X, tmp);
3559
3560 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3561 I915_WRITE(PORT_DFT_I9XX,
3562 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3563 }
3564}
3565
Daniel Vetter46a19182013-11-01 10:50:20 +01003566static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003567 uint32_t *val)
3568{
Daniel Vetter46a19182013-11-01 10:50:20 +01003569 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3570 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3571
3572 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003573 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3574 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3575 break;
3576 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3577 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3578 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003579 case INTEL_PIPE_CRC_SOURCE_PIPE:
3580 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3581 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003582 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003583 *val = 0;
3584 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003585 default:
3586 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003587 }
3588
3589 return 0;
3590}
3591
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003592static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3593{
3594 struct drm_i915_private *dev_priv = dev->dev_private;
3595 struct intel_crtc *crtc =
3596 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003597 struct intel_crtc_state *pipe_config;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003598
3599 drm_modeset_lock_all(dev);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003600 pipe_config = to_intel_crtc_state(crtc->base.state);
3601
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003602 /*
3603 * If we use the eDP transcoder we need to make sure that we don't
3604 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3605 * relevant on hsw with pipe A when using the always-on power well
3606 * routing.
3607 */
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003608 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
3609 !pipe_config->pch_pfit.enabled) {
3610 bool active = pipe_config->base.active;
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003611
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003612 if (active) {
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003613 intel_crtc_control(&crtc->base, false);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003614 pipe_config = to_intel_crtc_state(crtc->base.state);
3615 }
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003616
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003617 pipe_config->pch_pfit.force_thru = true;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003618
3619 intel_display_power_get(dev_priv,
3620 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3621
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003622 if (active)
3623 intel_crtc_control(&crtc->base, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003624 }
3625 drm_modeset_unlock_all(dev);
3626}
3627
3628static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3629{
3630 struct drm_i915_private *dev_priv = dev->dev_private;
3631 struct intel_crtc *crtc =
3632 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003633 struct intel_crtc_state *pipe_config;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003634
3635 drm_modeset_lock_all(dev);
3636 /*
3637 * If we use the eDP transcoder we need to make sure that we don't
3638 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3639 * relevant on hsw with pipe A when using the always-on power well
3640 * routing.
3641 */
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003642 pipe_config = to_intel_crtc_state(crtc->base.state);
3643 if (pipe_config->pch_pfit.force_thru) {
3644 bool active = pipe_config->base.active;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003645
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003646 if (active) {
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003647 intel_crtc_control(&crtc->base, false);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003648 pipe_config = to_intel_crtc_state(crtc->base.state);
3649 }
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003650
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003651 pipe_config->pch_pfit.force_thru = false;
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003652
3653 intel_display_power_put(dev_priv,
3654 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
Maarten Lankhorst1b509252015-06-01 12:49:48 +02003655
3656 if (active)
3657 intel_crtc_control(&crtc->base, true);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003658 }
3659 drm_modeset_unlock_all(dev);
3660}
3661
3662static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3663 enum pipe pipe,
3664 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003665 uint32_t *val)
3666{
Daniel Vetter46a19182013-11-01 10:50:20 +01003667 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3668 *source = INTEL_PIPE_CRC_SOURCE_PF;
3669
3670 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003671 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3672 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3673 break;
3674 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3675 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3676 break;
3677 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003678 if (IS_HASWELL(dev) && pipe == PIPE_A)
3679 hsw_trans_edp_pipe_A_crc_wa(dev);
3680
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003681 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3682 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003683 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003684 *val = 0;
3685 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003686 default:
3687 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003688 }
3689
3690 return 0;
3691}
3692
Daniel Vetter926321d2013-10-16 13:30:34 +02003693static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3694 enum intel_pipe_crc_source source)
3695{
3696 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003697 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003698 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3699 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003700 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003701 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003702
Damien Lespiaucc3da172013-10-15 18:55:31 +01003703 if (pipe_crc->source == source)
3704 return 0;
3705
Damien Lespiauae676fc2013-10-15 18:55:32 +01003706 /* forbid changing the source without going back to 'none' */
3707 if (pipe_crc->source && source)
3708 return -EINVAL;
3709
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003710 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3711 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3712 return -EIO;
3713 }
3714
Daniel Vetter52f843f2013-10-21 17:26:38 +02003715 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003716 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003717 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003718 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003719 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003720 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003721 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003722 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003723 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003724 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003725
3726 if (ret != 0)
3727 return ret;
3728
Damien Lespiau4b584362013-10-15 18:55:33 +01003729 /* none -> real source transition */
3730 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003731 struct intel_pipe_crc_entry *entries;
3732
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003733 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3734 pipe_name(pipe), pipe_crc_source_name(source));
3735
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003736 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3737 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003738 GFP_KERNEL);
3739 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003740 return -ENOMEM;
3741
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003742 /*
3743 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3744 * enabled and disabled dynamically based on package C states,
3745 * user space can't make reliable use of the CRCs, so let's just
3746 * completely disable it.
3747 */
3748 hsw_disable_ips(crtc);
3749
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003750 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003751 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003752 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003753 pipe_crc->head = 0;
3754 pipe_crc->tail = 0;
3755 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003756 }
3757
Damien Lespiaucc3da172013-10-15 18:55:31 +01003758 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003759
Daniel Vetter926321d2013-10-16 13:30:34 +02003760 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3761 POSTING_READ(PIPE_CRC_CTL(pipe));
3762
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003763 /* real source -> none transition */
3764 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003765 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003766 struct intel_crtc *crtc =
3767 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003768
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003769 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3770 pipe_name(pipe));
3771
Daniel Vettera33d7102014-06-06 08:22:08 +02003772 drm_modeset_lock(&crtc->base.mutex, NULL);
Maarten Lankhorstf77076c2015-06-01 12:50:08 +02003773 if (crtc->base.state->active)
Daniel Vettera33d7102014-06-06 08:22:08 +02003774 intel_wait_for_vblank(dev, pipe);
3775 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003776
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003777 spin_lock_irq(&pipe_crc->lock);
3778 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003779 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003780 pipe_crc->head = 0;
3781 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003782 spin_unlock_irq(&pipe_crc->lock);
3783
3784 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003785
3786 if (IS_G4X(dev))
3787 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003788 else if (IS_VALLEYVIEW(dev))
3789 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003790 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3791 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003792
3793 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003794 }
3795
Daniel Vetter926321d2013-10-16 13:30:34 +02003796 return 0;
3797}
3798
3799/*
3800 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003801 * command: wsp* object wsp+ name wsp+ source wsp*
3802 * object: 'pipe'
3803 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003804 * source: (none | plane1 | plane2 | pf)
3805 * wsp: (#0x20 | #0x9 | #0xA)+
3806 *
3807 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003808 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3809 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003810 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003811static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003812{
3813 int n_words = 0;
3814
3815 while (*buf) {
3816 char *end;
3817
3818 /* skip leading white space */
3819 buf = skip_spaces(buf);
3820 if (!*buf)
3821 break; /* end of buffer */
3822
3823 /* find end of word */
3824 for (end = buf; *end && !isspace(*end); end++)
3825 ;
3826
3827 if (n_words == max_words) {
3828 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3829 max_words);
3830 return -EINVAL; /* ran out of words[] before bytes */
3831 }
3832
3833 if (*end)
3834 *end++ = '\0';
3835 words[n_words++] = buf;
3836 buf = end;
3837 }
3838
3839 return n_words;
3840}
3841
Damien Lespiaub94dec82013-10-15 18:55:35 +01003842enum intel_pipe_crc_object {
3843 PIPE_CRC_OBJECT_PIPE,
3844};
3845
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003846static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003847 "pipe",
3848};
3849
3850static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003851display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003852{
3853 int i;
3854
3855 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3856 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003857 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003858 return 0;
3859 }
3860
3861 return -EINVAL;
3862}
3863
Damien Lespiaubd9db022013-10-15 18:55:36 +01003864static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003865{
3866 const char name = buf[0];
3867
3868 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3869 return -EINVAL;
3870
3871 *pipe = name - 'A';
3872
3873 return 0;
3874}
3875
3876static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003877display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003878{
3879 int i;
3880
3881 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3882 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003883 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003884 return 0;
3885 }
3886
3887 return -EINVAL;
3888}
3889
Damien Lespiaubd9db022013-10-15 18:55:36 +01003890static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003891{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003892#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003893 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003894 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003895 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003896 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003897 enum intel_pipe_crc_source source;
3898
Damien Lespiaubd9db022013-10-15 18:55:36 +01003899 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003900 if (n_words != N_WORDS) {
3901 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3902 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003903 return -EINVAL;
3904 }
3905
Damien Lespiaubd9db022013-10-15 18:55:36 +01003906 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003907 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003908 return -EINVAL;
3909 }
3910
Damien Lespiaubd9db022013-10-15 18:55:36 +01003911 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003912 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3913 return -EINVAL;
3914 }
3915
Damien Lespiaubd9db022013-10-15 18:55:36 +01003916 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003917 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003918 return -EINVAL;
3919 }
3920
3921 return pipe_crc_set_source(dev, pipe, source);
3922}
3923
Damien Lespiaubd9db022013-10-15 18:55:36 +01003924static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3925 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003926{
3927 struct seq_file *m = file->private_data;
3928 struct drm_device *dev = m->private;
3929 char *tmpbuf;
3930 int ret;
3931
3932 if (len == 0)
3933 return 0;
3934
3935 if (len > PAGE_SIZE - 1) {
3936 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3937 PAGE_SIZE);
3938 return -E2BIG;
3939 }
3940
3941 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3942 if (!tmpbuf)
3943 return -ENOMEM;
3944
3945 if (copy_from_user(tmpbuf, ubuf, len)) {
3946 ret = -EFAULT;
3947 goto out;
3948 }
3949 tmpbuf[len] = '\0';
3950
Damien Lespiaubd9db022013-10-15 18:55:36 +01003951 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003952
3953out:
3954 kfree(tmpbuf);
3955 if (ret < 0)
3956 return ret;
3957
3958 *offp += len;
3959 return len;
3960}
3961
Damien Lespiaubd9db022013-10-15 18:55:36 +01003962static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003963 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003964 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003965 .read = seq_read,
3966 .llseek = seq_lseek,
3967 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003968 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003969};
3970
Todd Previteeb3394fa2015-04-18 00:04:19 -07003971static ssize_t i915_displayport_test_active_write(struct file *file,
3972 const char __user *ubuf,
3973 size_t len, loff_t *offp)
3974{
3975 char *input_buffer;
3976 int status = 0;
3977 struct seq_file *m;
3978 struct drm_device *dev;
3979 struct drm_connector *connector;
3980 struct list_head *connector_list;
3981 struct intel_dp *intel_dp;
3982 int val = 0;
3983
3984 m = file->private_data;
3985 if (!m) {
3986 status = -ENODEV;
3987 return status;
3988 }
3989 dev = m->private;
3990
3991 if (!dev) {
3992 status = -ENODEV;
3993 return status;
3994 }
3995 connector_list = &dev->mode_config.connector_list;
3996
3997 if (len == 0)
3998 return 0;
3999
4000 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4001 if (!input_buffer)
4002 return -ENOMEM;
4003
4004 if (copy_from_user(input_buffer, ubuf, len)) {
4005 status = -EFAULT;
4006 goto out;
4007 }
4008
4009 input_buffer[len] = '\0';
4010 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4011
4012 list_for_each_entry(connector, connector_list, head) {
4013
4014 if (connector->connector_type !=
4015 DRM_MODE_CONNECTOR_DisplayPort)
4016 continue;
4017
4018 if (connector->connector_type ==
4019 DRM_MODE_CONNECTOR_DisplayPort &&
4020 connector->status == connector_status_connected &&
4021 connector->encoder != NULL) {
4022 intel_dp = enc_to_intel_dp(connector->encoder);
4023 status = kstrtoint(input_buffer, 10, &val);
4024 if (status < 0)
4025 goto out;
4026 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4027 /* To prevent erroneous activation of the compliance
4028 * testing code, only accept an actual value of 1 here
4029 */
4030 if (val == 1)
4031 intel_dp->compliance_test_active = 1;
4032 else
4033 intel_dp->compliance_test_active = 0;
4034 }
4035 }
4036out:
4037 kfree(input_buffer);
4038 if (status < 0)
4039 return status;
4040
4041 *offp += len;
4042 return len;
4043}
4044
4045static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4046{
4047 struct drm_device *dev = m->private;
4048 struct drm_connector *connector;
4049 struct list_head *connector_list = &dev->mode_config.connector_list;
4050 struct intel_dp *intel_dp;
4051
4052 if (!dev)
4053 return -ENODEV;
4054
4055 list_for_each_entry(connector, connector_list, head) {
4056
4057 if (connector->connector_type !=
4058 DRM_MODE_CONNECTOR_DisplayPort)
4059 continue;
4060
4061 if (connector->status == connector_status_connected &&
4062 connector->encoder != NULL) {
4063 intel_dp = enc_to_intel_dp(connector->encoder);
4064 if (intel_dp->compliance_test_active)
4065 seq_puts(m, "1");
4066 else
4067 seq_puts(m, "0");
4068 } else
4069 seq_puts(m, "0");
4070 }
4071
4072 return 0;
4073}
4074
4075static int i915_displayport_test_active_open(struct inode *inode,
4076 struct file *file)
4077{
4078 struct drm_device *dev = inode->i_private;
4079
4080 return single_open(file, i915_displayport_test_active_show, dev);
4081}
4082
4083static const struct file_operations i915_displayport_test_active_fops = {
4084 .owner = THIS_MODULE,
4085 .open = i915_displayport_test_active_open,
4086 .read = seq_read,
4087 .llseek = seq_lseek,
4088 .release = single_release,
4089 .write = i915_displayport_test_active_write
4090};
4091
4092static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4093{
4094 struct drm_device *dev = m->private;
4095 struct drm_connector *connector;
4096 struct list_head *connector_list = &dev->mode_config.connector_list;
4097 struct intel_dp *intel_dp;
4098
4099 if (!dev)
4100 return -ENODEV;
4101
4102 list_for_each_entry(connector, connector_list, head) {
4103
4104 if (connector->connector_type !=
4105 DRM_MODE_CONNECTOR_DisplayPort)
4106 continue;
4107
4108 if (connector->status == connector_status_connected &&
4109 connector->encoder != NULL) {
4110 intel_dp = enc_to_intel_dp(connector->encoder);
4111 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4112 } else
4113 seq_puts(m, "0");
4114 }
4115
4116 return 0;
4117}
4118static int i915_displayport_test_data_open(struct inode *inode,
4119 struct file *file)
4120{
4121 struct drm_device *dev = inode->i_private;
4122
4123 return single_open(file, i915_displayport_test_data_show, dev);
4124}
4125
4126static const struct file_operations i915_displayport_test_data_fops = {
4127 .owner = THIS_MODULE,
4128 .open = i915_displayport_test_data_open,
4129 .read = seq_read,
4130 .llseek = seq_lseek,
4131 .release = single_release
4132};
4133
4134static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4135{
4136 struct drm_device *dev = m->private;
4137 struct drm_connector *connector;
4138 struct list_head *connector_list = &dev->mode_config.connector_list;
4139 struct intel_dp *intel_dp;
4140
4141 if (!dev)
4142 return -ENODEV;
4143
4144 list_for_each_entry(connector, connector_list, head) {
4145
4146 if (connector->connector_type !=
4147 DRM_MODE_CONNECTOR_DisplayPort)
4148 continue;
4149
4150 if (connector->status == connector_status_connected &&
4151 connector->encoder != NULL) {
4152 intel_dp = enc_to_intel_dp(connector->encoder);
4153 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4154 } else
4155 seq_puts(m, "0");
4156 }
4157
4158 return 0;
4159}
4160
4161static int i915_displayport_test_type_open(struct inode *inode,
4162 struct file *file)
4163{
4164 struct drm_device *dev = inode->i_private;
4165
4166 return single_open(file, i915_displayport_test_type_show, dev);
4167}
4168
4169static const struct file_operations i915_displayport_test_type_fops = {
4170 .owner = THIS_MODULE,
4171 .open = i915_displayport_test_type_open,
4172 .read = seq_read,
4173 .llseek = seq_lseek,
4174 .release = single_release
4175};
4176
Damien Lespiau97e94b22014-11-04 17:06:50 +00004177static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004178{
4179 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01004180 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004181 int level;
4182
4183 drm_modeset_lock_all(dev);
4184
4185 for (level = 0; level < num_levels; level++) {
4186 unsigned int latency = wm[level];
4187
Damien Lespiau97e94b22014-11-04 17:06:50 +00004188 /*
4189 * - WM1+ latency values in 0.5us units
4190 * - latencies are in us on gen9
4191 */
4192 if (INTEL_INFO(dev)->gen >= 9)
4193 latency *= 10;
4194 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02004195 latency *= 5;
4196
4197 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00004198 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004199 }
4200
4201 drm_modeset_unlock_all(dev);
4202}
4203
4204static int pri_wm_latency_show(struct seq_file *m, void *data)
4205{
4206 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004207 struct drm_i915_private *dev_priv = dev->dev_private;
4208 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004209
Damien Lespiau97e94b22014-11-04 17:06:50 +00004210 if (INTEL_INFO(dev)->gen >= 9)
4211 latencies = dev_priv->wm.skl_latency;
4212 else
4213 latencies = to_i915(dev)->wm.pri_latency;
4214
4215 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004216
4217 return 0;
4218}
4219
4220static int spr_wm_latency_show(struct seq_file *m, void *data)
4221{
4222 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004223 struct drm_i915_private *dev_priv = dev->dev_private;
4224 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004225
Damien Lespiau97e94b22014-11-04 17:06:50 +00004226 if (INTEL_INFO(dev)->gen >= 9)
4227 latencies = dev_priv->wm.skl_latency;
4228 else
4229 latencies = to_i915(dev)->wm.spr_latency;
4230
4231 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004232
4233 return 0;
4234}
4235
4236static int cur_wm_latency_show(struct seq_file *m, void *data)
4237{
4238 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004239 struct drm_i915_private *dev_priv = dev->dev_private;
4240 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004241
Damien Lespiau97e94b22014-11-04 17:06:50 +00004242 if (INTEL_INFO(dev)->gen >= 9)
4243 latencies = dev_priv->wm.skl_latency;
4244 else
4245 latencies = to_i915(dev)->wm.cur_latency;
4246
4247 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004248
4249 return 0;
4250}
4251
4252static int pri_wm_latency_open(struct inode *inode, struct file *file)
4253{
4254 struct drm_device *dev = inode->i_private;
4255
Sonika Jindal9ad02572014-07-21 15:23:39 +05304256 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004257 return -ENODEV;
4258
4259 return single_open(file, pri_wm_latency_show, dev);
4260}
4261
4262static int spr_wm_latency_open(struct inode *inode, struct file *file)
4263{
4264 struct drm_device *dev = inode->i_private;
4265
Sonika Jindal9ad02572014-07-21 15:23:39 +05304266 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004267 return -ENODEV;
4268
4269 return single_open(file, spr_wm_latency_show, dev);
4270}
4271
4272static int cur_wm_latency_open(struct inode *inode, struct file *file)
4273{
4274 struct drm_device *dev = inode->i_private;
4275
Sonika Jindal9ad02572014-07-21 15:23:39 +05304276 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02004277 return -ENODEV;
4278
4279 return single_open(file, cur_wm_latency_show, dev);
4280}
4281
4282static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00004283 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02004284{
4285 struct seq_file *m = file->private_data;
4286 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004287 uint16_t new[8] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01004288 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004289 int level;
4290 int ret;
4291 char tmp[32];
4292
4293 if (len >= sizeof(tmp))
4294 return -EINVAL;
4295
4296 if (copy_from_user(tmp, ubuf, len))
4297 return -EFAULT;
4298
4299 tmp[len] = '\0';
4300
Damien Lespiau97e94b22014-11-04 17:06:50 +00004301 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4302 &new[0], &new[1], &new[2], &new[3],
4303 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004304 if (ret != num_levels)
4305 return -EINVAL;
4306
4307 drm_modeset_lock_all(dev);
4308
4309 for (level = 0; level < num_levels; level++)
4310 wm[level] = new[level];
4311
4312 drm_modeset_unlock_all(dev);
4313
4314 return len;
4315}
4316
4317
4318static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4319 size_t len, loff_t *offp)
4320{
4321 struct seq_file *m = file->private_data;
4322 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004323 struct drm_i915_private *dev_priv = dev->dev_private;
4324 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004325
Damien Lespiau97e94b22014-11-04 17:06:50 +00004326 if (INTEL_INFO(dev)->gen >= 9)
4327 latencies = dev_priv->wm.skl_latency;
4328 else
4329 latencies = to_i915(dev)->wm.pri_latency;
4330
4331 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004332}
4333
4334static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4335 size_t len, loff_t *offp)
4336{
4337 struct seq_file *m = file->private_data;
4338 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004339 struct drm_i915_private *dev_priv = dev->dev_private;
4340 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004341
Damien Lespiau97e94b22014-11-04 17:06:50 +00004342 if (INTEL_INFO(dev)->gen >= 9)
4343 latencies = dev_priv->wm.skl_latency;
4344 else
4345 latencies = to_i915(dev)->wm.spr_latency;
4346
4347 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004348}
4349
4350static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4351 size_t len, loff_t *offp)
4352{
4353 struct seq_file *m = file->private_data;
4354 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00004355 struct drm_i915_private *dev_priv = dev->dev_private;
4356 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02004357
Damien Lespiau97e94b22014-11-04 17:06:50 +00004358 if (INTEL_INFO(dev)->gen >= 9)
4359 latencies = dev_priv->wm.skl_latency;
4360 else
4361 latencies = to_i915(dev)->wm.cur_latency;
4362
4363 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02004364}
4365
4366static const struct file_operations i915_pri_wm_latency_fops = {
4367 .owner = THIS_MODULE,
4368 .open = pri_wm_latency_open,
4369 .read = seq_read,
4370 .llseek = seq_lseek,
4371 .release = single_release,
4372 .write = pri_wm_latency_write
4373};
4374
4375static const struct file_operations i915_spr_wm_latency_fops = {
4376 .owner = THIS_MODULE,
4377 .open = spr_wm_latency_open,
4378 .read = seq_read,
4379 .llseek = seq_lseek,
4380 .release = single_release,
4381 .write = spr_wm_latency_write
4382};
4383
4384static const struct file_operations i915_cur_wm_latency_fops = {
4385 .owner = THIS_MODULE,
4386 .open = cur_wm_latency_open,
4387 .read = seq_read,
4388 .llseek = seq_lseek,
4389 .release = single_release,
4390 .write = cur_wm_latency_write
4391};
4392
Kees Cook647416f2013-03-10 14:10:06 -07004393static int
4394i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004395{
Kees Cook647416f2013-03-10 14:10:06 -07004396 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004397 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004398
Kees Cook647416f2013-03-10 14:10:06 -07004399 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004400
Kees Cook647416f2013-03-10 14:10:06 -07004401 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004402}
4403
Kees Cook647416f2013-03-10 14:10:06 -07004404static int
4405i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004406{
Kees Cook647416f2013-03-10 14:10:06 -07004407 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03004408 struct drm_i915_private *dev_priv = dev->dev_private;
4409
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02004410 /*
4411 * There is no safeguard against this debugfs entry colliding
4412 * with the hangcheck calling same i915_handle_error() in
4413 * parallel, causing an explosion. For now we assume that the
4414 * test harness is responsible enough not to inject gpu hangs
4415 * while it is writing to 'i915_wedged'
4416 */
4417
4418 if (i915_reset_in_progress(&dev_priv->gpu_error))
4419 return -EAGAIN;
4420
Imre Deakd46c0512014-04-14 20:24:27 +03004421 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004422
Mika Kuoppala58174462014-02-25 17:11:26 +02004423 i915_handle_error(dev, val,
4424 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03004425
4426 intel_runtime_pm_put(dev_priv);
4427
Kees Cook647416f2013-03-10 14:10:06 -07004428 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004429}
4430
Kees Cook647416f2013-03-10 14:10:06 -07004431DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4432 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004433 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004434
Kees Cook647416f2013-03-10 14:10:06 -07004435static int
4436i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004437{
Kees Cook647416f2013-03-10 14:10:06 -07004438 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004439 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004440
Kees Cook647416f2013-03-10 14:10:06 -07004441 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004442
Kees Cook647416f2013-03-10 14:10:06 -07004443 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004444}
4445
Kees Cook647416f2013-03-10 14:10:06 -07004446static int
4447i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004448{
Kees Cook647416f2013-03-10 14:10:06 -07004449 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004450 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004451 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004452
Kees Cook647416f2013-03-10 14:10:06 -07004453 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004454
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004455 ret = mutex_lock_interruptible(&dev->struct_mutex);
4456 if (ret)
4457 return ret;
4458
Daniel Vetter99584db2012-11-14 17:14:04 +01004459 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004460 mutex_unlock(&dev->struct_mutex);
4461
Kees Cook647416f2013-03-10 14:10:06 -07004462 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02004463}
4464
Kees Cook647416f2013-03-10 14:10:06 -07004465DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4466 i915_ring_stop_get, i915_ring_stop_set,
4467 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02004468
Chris Wilson094f9a52013-09-25 17:34:55 +01004469static int
4470i915_ring_missed_irq_get(void *data, u64 *val)
4471{
4472 struct drm_device *dev = data;
4473 struct drm_i915_private *dev_priv = dev->dev_private;
4474
4475 *val = dev_priv->gpu_error.missed_irq_rings;
4476 return 0;
4477}
4478
4479static int
4480i915_ring_missed_irq_set(void *data, u64 val)
4481{
4482 struct drm_device *dev = data;
4483 struct drm_i915_private *dev_priv = dev->dev_private;
4484 int ret;
4485
4486 /* Lock against concurrent debugfs callers */
4487 ret = mutex_lock_interruptible(&dev->struct_mutex);
4488 if (ret)
4489 return ret;
4490 dev_priv->gpu_error.missed_irq_rings = val;
4491 mutex_unlock(&dev->struct_mutex);
4492
4493 return 0;
4494}
4495
4496DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4497 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4498 "0x%08llx\n");
4499
4500static int
4501i915_ring_test_irq_get(void *data, u64 *val)
4502{
4503 struct drm_device *dev = data;
4504 struct drm_i915_private *dev_priv = dev->dev_private;
4505
4506 *val = dev_priv->gpu_error.test_irq_rings;
4507
4508 return 0;
4509}
4510
4511static int
4512i915_ring_test_irq_set(void *data, u64 val)
4513{
4514 struct drm_device *dev = data;
4515 struct drm_i915_private *dev_priv = dev->dev_private;
4516 int ret;
4517
4518 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4519
4520 /* Lock against concurrent debugfs callers */
4521 ret = mutex_lock_interruptible(&dev->struct_mutex);
4522 if (ret)
4523 return ret;
4524
4525 dev_priv->gpu_error.test_irq_rings = val;
4526 mutex_unlock(&dev->struct_mutex);
4527
4528 return 0;
4529}
4530
4531DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4532 i915_ring_test_irq_get, i915_ring_test_irq_set,
4533 "0x%08llx\n");
4534
Chris Wilsondd624af2013-01-15 12:39:35 +00004535#define DROP_UNBOUND 0x1
4536#define DROP_BOUND 0x2
4537#define DROP_RETIRE 0x4
4538#define DROP_ACTIVE 0x8
4539#define DROP_ALL (DROP_UNBOUND | \
4540 DROP_BOUND | \
4541 DROP_RETIRE | \
4542 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004543static int
4544i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004545{
Kees Cook647416f2013-03-10 14:10:06 -07004546 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004547
Kees Cook647416f2013-03-10 14:10:06 -07004548 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004549}
4550
Kees Cook647416f2013-03-10 14:10:06 -07004551static int
4552i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004553{
Kees Cook647416f2013-03-10 14:10:06 -07004554 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004555 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004556 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004557
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004558 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004559
4560 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4561 * on ioctls on -EAGAIN. */
4562 ret = mutex_lock_interruptible(&dev->struct_mutex);
4563 if (ret)
4564 return ret;
4565
4566 if (val & DROP_ACTIVE) {
4567 ret = i915_gpu_idle(dev);
4568 if (ret)
4569 goto unlock;
4570 }
4571
4572 if (val & (DROP_RETIRE | DROP_ACTIVE))
4573 i915_gem_retire_requests(dev);
4574
Chris Wilson21ab4e72014-09-09 11:16:08 +01004575 if (val & DROP_BOUND)
4576 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004577
Chris Wilson21ab4e72014-09-09 11:16:08 +01004578 if (val & DROP_UNBOUND)
4579 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004580
4581unlock:
4582 mutex_unlock(&dev->struct_mutex);
4583
Kees Cook647416f2013-03-10 14:10:06 -07004584 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004585}
4586
Kees Cook647416f2013-03-10 14:10:06 -07004587DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4588 i915_drop_caches_get, i915_drop_caches_set,
4589 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004590
Kees Cook647416f2013-03-10 14:10:06 -07004591static int
4592i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004593{
Kees Cook647416f2013-03-10 14:10:06 -07004594 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004595 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004596 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004597
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004598 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004599 return -ENODEV;
4600
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004601 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4602
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004603 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004604 if (ret)
4605 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004606
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004607 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004608 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004609
Kees Cook647416f2013-03-10 14:10:06 -07004610 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004611}
4612
Kees Cook647416f2013-03-10 14:10:06 -07004613static int
4614i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004615{
Kees Cook647416f2013-03-10 14:10:06 -07004616 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004617 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304618 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004619 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004620
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004621 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004622 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004623
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004624 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4625
Kees Cook647416f2013-03-10 14:10:06 -07004626 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004627
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004628 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004629 if (ret)
4630 return ret;
4631
Jesse Barnes358733e2011-07-27 11:53:01 -07004632 /*
4633 * Turbo will still be enabled, but won't go above the set value.
4634 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304635 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004636
Akash Goelbc4d91f2015-02-26 16:09:47 +05304637 hw_max = dev_priv->rps.max_freq;
4638 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004639
Ben Widawskyb39fb292014-03-19 18:31:11 -07004640 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004641 mutex_unlock(&dev_priv->rps.hw_lock);
4642 return -EINVAL;
4643 }
4644
Ben Widawskyb39fb292014-03-19 18:31:11 -07004645 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004646
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004647 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004648
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004649 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004650
Kees Cook647416f2013-03-10 14:10:06 -07004651 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004652}
4653
Kees Cook647416f2013-03-10 14:10:06 -07004654DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4655 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004656 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004657
Kees Cook647416f2013-03-10 14:10:06 -07004658static int
4659i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004660{
Kees Cook647416f2013-03-10 14:10:06 -07004661 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004662 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004663 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004664
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004665 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004666 return -ENODEV;
4667
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004668 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4669
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004670 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004671 if (ret)
4672 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004673
Ville Syrjälä7c59a9c12015-01-23 21:04:26 +02004674 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004675 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004676
Kees Cook647416f2013-03-10 14:10:06 -07004677 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004678}
4679
Kees Cook647416f2013-03-10 14:10:06 -07004680static int
4681i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004682{
Kees Cook647416f2013-03-10 14:10:06 -07004683 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004684 struct drm_i915_private *dev_priv = dev->dev_private;
Akash Goelbc4d91f2015-02-26 16:09:47 +05304685 u32 hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004686 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004687
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004688 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004689 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004690
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004691 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4692
Kees Cook647416f2013-03-10 14:10:06 -07004693 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004694
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004695 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004696 if (ret)
4697 return ret;
4698
Jesse Barnes1523c312012-05-25 12:34:54 -07004699 /*
4700 * Turbo will still be enabled, but won't go below the set value.
4701 */
Akash Goelbc4d91f2015-02-26 16:09:47 +05304702 val = intel_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004703
Akash Goelbc4d91f2015-02-26 16:09:47 +05304704 hw_max = dev_priv->rps.max_freq;
4705 hw_min = dev_priv->rps.min_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004706
Ben Widawskyb39fb292014-03-19 18:31:11 -07004707 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004708 mutex_unlock(&dev_priv->rps.hw_lock);
4709 return -EINVAL;
4710 }
4711
Ben Widawskyb39fb292014-03-19 18:31:11 -07004712 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004713
Ville Syrjäläffe02b42015-02-02 19:09:50 +02004714 intel_set_rps(dev, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004715
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004716 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004717
Kees Cook647416f2013-03-10 14:10:06 -07004718 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004719}
4720
Kees Cook647416f2013-03-10 14:10:06 -07004721DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4722 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004723 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004724
Kees Cook647416f2013-03-10 14:10:06 -07004725static int
4726i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004727{
Kees Cook647416f2013-03-10 14:10:06 -07004728 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004729 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004730 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004731 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004732
Daniel Vetter004777c2012-08-09 15:07:01 +02004733 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4734 return -ENODEV;
4735
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004736 ret = mutex_lock_interruptible(&dev->struct_mutex);
4737 if (ret)
4738 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004739 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004740
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004741 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004742
4743 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004744 mutex_unlock(&dev_priv->dev->struct_mutex);
4745
Kees Cook647416f2013-03-10 14:10:06 -07004746 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004747
Kees Cook647416f2013-03-10 14:10:06 -07004748 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004749}
4750
Kees Cook647416f2013-03-10 14:10:06 -07004751static int
4752i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004753{
Kees Cook647416f2013-03-10 14:10:06 -07004754 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004755 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004756 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004757
Daniel Vetter004777c2012-08-09 15:07:01 +02004758 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4759 return -ENODEV;
4760
Kees Cook647416f2013-03-10 14:10:06 -07004761 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004762 return -EINVAL;
4763
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004764 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004765 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004766
4767 /* Update the cache sharing policy here as well */
4768 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4769 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4770 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4771 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4772
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004773 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004774 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004775}
4776
Kees Cook647416f2013-03-10 14:10:06 -07004777DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4778 i915_cache_sharing_get, i915_cache_sharing_set,
4779 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004780
Jeff McGee5d395252015-04-03 18:13:17 -07004781struct sseu_dev_status {
4782 unsigned int slice_total;
4783 unsigned int subslice_total;
4784 unsigned int subslice_per_slice;
4785 unsigned int eu_total;
4786 unsigned int eu_per_subslice;
4787};
4788
4789static void cherryview_sseu_device_status(struct drm_device *dev,
4790 struct sseu_dev_status *stat)
4791{
4792 struct drm_i915_private *dev_priv = dev->dev_private;
4793 const int ss_max = 2;
4794 int ss;
4795 u32 sig1[ss_max], sig2[ss_max];
4796
4797 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4798 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4799 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4800 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4801
4802 for (ss = 0; ss < ss_max; ss++) {
4803 unsigned int eu_cnt;
4804
4805 if (sig1[ss] & CHV_SS_PG_ENABLE)
4806 /* skip disabled subslice */
4807 continue;
4808
4809 stat->slice_total = 1;
4810 stat->subslice_per_slice++;
4811 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4812 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4813 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4814 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
4815 stat->eu_total += eu_cnt;
4816 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
4817 }
4818 stat->subslice_total = stat->subslice_per_slice;
4819}
4820
4821static void gen9_sseu_device_status(struct drm_device *dev,
4822 struct sseu_dev_status *stat)
4823{
4824 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004825 int s_max = 3, ss_max = 4;
Jeff McGee5d395252015-04-03 18:13:17 -07004826 int s, ss;
4827 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4828
Jeff McGee1c046bc2015-04-03 18:13:18 -07004829 /* BXT has a single slice and at most 3 subslices. */
4830 if (IS_BROXTON(dev)) {
4831 s_max = 1;
4832 ss_max = 3;
4833 }
4834
4835 for (s = 0; s < s_max; s++) {
4836 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4837 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4838 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4839 }
4840
Jeff McGee5d395252015-04-03 18:13:17 -07004841 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4842 GEN9_PGCTL_SSA_EU19_ACK |
4843 GEN9_PGCTL_SSA_EU210_ACK |
4844 GEN9_PGCTL_SSA_EU311_ACK;
4845 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4846 GEN9_PGCTL_SSB_EU19_ACK |
4847 GEN9_PGCTL_SSB_EU210_ACK |
4848 GEN9_PGCTL_SSB_EU311_ACK;
4849
4850 for (s = 0; s < s_max; s++) {
Jeff McGee1c046bc2015-04-03 18:13:18 -07004851 unsigned int ss_cnt = 0;
4852
Jeff McGee5d395252015-04-03 18:13:17 -07004853 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4854 /* skip disabled slice */
4855 continue;
4856
4857 stat->slice_total++;
Jeff McGee1c046bc2015-04-03 18:13:18 -07004858
4859 if (IS_SKYLAKE(dev))
4860 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
4861
Jeff McGee5d395252015-04-03 18:13:17 -07004862 for (ss = 0; ss < ss_max; ss++) {
4863 unsigned int eu_cnt;
4864
Jeff McGee1c046bc2015-04-03 18:13:18 -07004865 if (IS_BROXTON(dev) &&
4866 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4867 /* skip disabled subslice */
4868 continue;
4869
4870 if (IS_BROXTON(dev))
4871 ss_cnt++;
4872
Jeff McGee5d395252015-04-03 18:13:17 -07004873 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4874 eu_mask[ss%2]);
4875 stat->eu_total += eu_cnt;
4876 stat->eu_per_subslice = max(stat->eu_per_subslice,
4877 eu_cnt);
4878 }
Jeff McGee1c046bc2015-04-03 18:13:18 -07004879
4880 stat->subslice_total += ss_cnt;
4881 stat->subslice_per_slice = max(stat->subslice_per_slice,
4882 ss_cnt);
Jeff McGee5d395252015-04-03 18:13:17 -07004883 }
4884}
4885
Jeff McGee38732182015-02-13 10:27:54 -06004886static int i915_sseu_status(struct seq_file *m, void *unused)
4887{
4888 struct drm_info_node *node = (struct drm_info_node *) m->private;
4889 struct drm_device *dev = node->minor->dev;
Jeff McGee5d395252015-04-03 18:13:17 -07004890 struct sseu_dev_status stat;
Jeff McGee38732182015-02-13 10:27:54 -06004891
Jeff McGee5575f032015-02-27 10:22:32 -08004892 if ((INTEL_INFO(dev)->gen < 8) || IS_BROADWELL(dev))
Jeff McGee38732182015-02-13 10:27:54 -06004893 return -ENODEV;
4894
4895 seq_puts(m, "SSEU Device Info\n");
4896 seq_printf(m, " Available Slice Total: %u\n",
4897 INTEL_INFO(dev)->slice_total);
4898 seq_printf(m, " Available Subslice Total: %u\n",
4899 INTEL_INFO(dev)->subslice_total);
4900 seq_printf(m, " Available Subslice Per Slice: %u\n",
4901 INTEL_INFO(dev)->subslice_per_slice);
4902 seq_printf(m, " Available EU Total: %u\n",
4903 INTEL_INFO(dev)->eu_total);
4904 seq_printf(m, " Available EU Per Subslice: %u\n",
4905 INTEL_INFO(dev)->eu_per_subslice);
4906 seq_printf(m, " Has Slice Power Gating: %s\n",
4907 yesno(INTEL_INFO(dev)->has_slice_pg));
4908 seq_printf(m, " Has Subslice Power Gating: %s\n",
4909 yesno(INTEL_INFO(dev)->has_subslice_pg));
4910 seq_printf(m, " Has EU Power Gating: %s\n",
4911 yesno(INTEL_INFO(dev)->has_eu_pg));
4912
Jeff McGee7f992ab2015-02-13 10:27:55 -06004913 seq_puts(m, "SSEU Device Status\n");
Jeff McGee5d395252015-04-03 18:13:17 -07004914 memset(&stat, 0, sizeof(stat));
Jeff McGee5575f032015-02-27 10:22:32 -08004915 if (IS_CHERRYVIEW(dev)) {
Jeff McGee5d395252015-04-03 18:13:17 -07004916 cherryview_sseu_device_status(dev, &stat);
Jeff McGee1c046bc2015-04-03 18:13:18 -07004917 } else if (INTEL_INFO(dev)->gen >= 9) {
Jeff McGee5d395252015-04-03 18:13:17 -07004918 gen9_sseu_device_status(dev, &stat);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004919 }
Jeff McGee5d395252015-04-03 18:13:17 -07004920 seq_printf(m, " Enabled Slice Total: %u\n",
4921 stat.slice_total);
4922 seq_printf(m, " Enabled Subslice Total: %u\n",
4923 stat.subslice_total);
4924 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
4925 stat.subslice_per_slice);
4926 seq_printf(m, " Enabled EU Total: %u\n",
4927 stat.eu_total);
4928 seq_printf(m, " Enabled EU Per Subslice: %u\n",
4929 stat.eu_per_subslice);
Jeff McGee7f992ab2015-02-13 10:27:55 -06004930
Jeff McGee38732182015-02-13 10:27:54 -06004931 return 0;
4932}
4933
Ben Widawsky6d794d42011-04-25 11:25:56 -07004934static int i915_forcewake_open(struct inode *inode, struct file *file)
4935{
4936 struct drm_device *dev = inode->i_private;
4937 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004938
Daniel Vetter075edca2012-01-24 09:44:28 +01004939 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004940 return 0;
4941
Chris Wilson6daccb02015-01-16 11:34:35 +02004942 intel_runtime_pm_get(dev_priv);
Mika Kuoppala59bad942015-01-16 11:34:40 +02004943 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004944
4945 return 0;
4946}
4947
Ben Widawskyc43b5632012-04-16 14:07:40 -07004948static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004949{
4950 struct drm_device *dev = inode->i_private;
4951 struct drm_i915_private *dev_priv = dev->dev_private;
4952
Daniel Vetter075edca2012-01-24 09:44:28 +01004953 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004954 return 0;
4955
Mika Kuoppala59bad942015-01-16 11:34:40 +02004956 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Chris Wilson6daccb02015-01-16 11:34:35 +02004957 intel_runtime_pm_put(dev_priv);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004958
4959 return 0;
4960}
4961
4962static const struct file_operations i915_forcewake_fops = {
4963 .owner = THIS_MODULE,
4964 .open = i915_forcewake_open,
4965 .release = i915_forcewake_release,
4966};
4967
4968static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4969{
4970 struct drm_device *dev = minor->dev;
4971 struct dentry *ent;
4972
4973 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004974 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004975 root, dev,
4976 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004977 if (!ent)
4978 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004979
Ben Widawsky8eb57292011-05-11 15:10:58 -07004980 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004981}
4982
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004983static int i915_debugfs_create(struct dentry *root,
4984 struct drm_minor *minor,
4985 const char *name,
4986 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004987{
4988 struct drm_device *dev = minor->dev;
4989 struct dentry *ent;
4990
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004991 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004992 S_IRUGO | S_IWUSR,
4993 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004994 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004995 if (!ent)
4996 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004997
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004998 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004999}
5000
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005001static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00005002 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01005003 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00005004 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01005005 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005006 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05005007 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01005008 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01005009 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005010 {"i915_gem_request", i915_gem_request_info, 0},
5011 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00005012 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005013 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00005014 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5015 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5016 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07005017 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Brad Volkin493018d2014-12-11 12:13:08 -08005018 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05305019 {"i915_frequency_info", i915_frequency_info, 0},
Chris Wilsonf6544492015-01-26 18:03:04 +02005020 {"i915_hangcheck_info", i915_hangcheck_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08005021 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07005022 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07005023 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08005024 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03005025 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08005026 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01005027 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01005028 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07005029 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01005030 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01005031 {"i915_execlists", i915_execlists, 0},
Mika Kuoppalaf65367b2015-01-16 11:34:42 +02005032 {"i915_forcewake_domains", i915_forcewake_domains, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01005033 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01005034 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07005035 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03005036 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02005037 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01005038 {"i915_energy_uJ", i915_energy_uJ, 0},
Damien Lespiau6455c872015-06-04 18:23:57 +01005039 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02005040 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08005041 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07005042 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03005043 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10005044 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01005045 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00005046 {"i915_ddb_info", i915_ddb_info, 0},
Jeff McGee38732182015-02-13 10:27:54 -06005047 {"i915_sseu_status", i915_sseu_status, 0},
Vandana Kannana54746e2015-03-03 20:53:10 +05305048 {"i915_drrs_status", i915_drrs_status, 0},
Chris Wilson1854d5c2015-04-07 16:20:32 +01005049 {"i915_rps_boost_info", i915_rps_boost_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05005050};
Ben Gamari27c202a2009-07-01 22:26:52 -04005051#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05005052
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01005053static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02005054 const char *name;
5055 const struct file_operations *fops;
5056} i915_debugfs_files[] = {
5057 {"i915_wedged", &i915_wedged_fops},
5058 {"i915_max_freq", &i915_max_freq_fops},
5059 {"i915_min_freq", &i915_min_freq_fops},
5060 {"i915_cache_sharing", &i915_cache_sharing_fops},
5061 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01005062 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5063 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02005064 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5065 {"i915_error_state", &i915_error_state_fops},
5066 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01005067 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02005068 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5069 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5070 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07005071 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Todd Previteeb3394fa2015-04-18 00:04:19 -07005072 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5073 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5074 {"i915_dp_test_active", &i915_displayport_test_active_fops}
Daniel Vetter34b96742013-07-04 20:49:44 +02005075};
5076
Damien Lespiau07144422013-10-15 18:55:40 +01005077void intel_display_crc_init(struct drm_device *dev)
5078{
5079 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01005080 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01005081
Damien Lespiau055e3932014-08-18 13:49:10 +01005082 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01005083 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01005084
Damien Lespiaud538bbd2013-10-21 14:29:30 +01005085 pipe_crc->opened = false;
5086 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01005087 init_waitqueue_head(&pipe_crc->wq);
5088 }
5089}
5090
Ben Gamari27c202a2009-07-01 22:26:52 -04005091int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005092{
Daniel Vetter34b96742013-07-04 20:49:44 +02005093 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01005094
Ben Widawsky6d794d42011-04-25 11:25:56 -07005095 ret = i915_forcewake_create(minor->debugfs_root, minor);
5096 if (ret)
5097 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01005098
Damien Lespiau07144422013-10-15 18:55:40 +01005099 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5100 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5101 if (ret)
5102 return ret;
5103 }
5104
Daniel Vetter34b96742013-07-04 20:49:44 +02005105 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5106 ret = i915_debugfs_create(minor->debugfs_root, minor,
5107 i915_debugfs_files[i].name,
5108 i915_debugfs_files[i].fops);
5109 if (ret)
5110 return ret;
5111 }
Mika Kuoppala40633212012-12-04 15:12:00 +02005112
Ben Gamari27c202a2009-07-01 22:26:52 -04005113 return drm_debugfs_create_files(i915_debugfs_list,
5114 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05005115 minor->debugfs_root, minor);
5116}
5117
Ben Gamari27c202a2009-07-01 22:26:52 -04005118void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05005119{
Daniel Vetter34b96742013-07-04 20:49:44 +02005120 int i;
5121
Ben Gamari27c202a2009-07-01 22:26:52 -04005122 drm_debugfs_remove_files(i915_debugfs_list,
5123 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005124
Ben Widawsky6d794d42011-04-25 11:25:56 -07005125 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5126 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01005127
Daniel Vettere309a992013-10-16 22:55:51 +02005128 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01005129 struct drm_info_list *info_list =
5130 (struct drm_info_list *)&i915_pipe_crc_data[i];
5131
5132 drm_debugfs_remove_files(info_list, 1, minor);
5133 }
5134
Daniel Vetter34b96742013-07-04 20:49:44 +02005135 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5136 struct drm_info_list *info_list =
5137 (struct drm_info_list *) i915_debugfs_files[i].fops;
5138
5139 drm_debugfs_remove_files(info_list, 1, minor);
5140 }
Ben Gamari20172632009-02-17 20:08:50 -05005141}
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005142
5143struct dpcd_block {
5144 /* DPCD dump start address. */
5145 unsigned int offset;
5146 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5147 unsigned int end;
5148 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5149 size_t size;
5150 /* Only valid for eDP. */
5151 bool edp;
5152};
5153
5154static const struct dpcd_block i915_dpcd_debug[] = {
5155 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5156 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5157 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5158 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5159 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5160 { .offset = DP_SET_POWER },
5161 { .offset = DP_EDP_DPCD_REV },
5162 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5163 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5164 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5165};
5166
5167static int i915_dpcd_show(struct seq_file *m, void *data)
5168{
5169 struct drm_connector *connector = m->private;
5170 struct intel_dp *intel_dp =
5171 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5172 uint8_t buf[16];
5173 ssize_t err;
5174 int i;
5175
Mika Kuoppala5c1a8872015-05-15 13:09:21 +03005176 if (connector->status != connector_status_connected)
5177 return -ENODEV;
5178
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005179 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5180 const struct dpcd_block *b = &i915_dpcd_debug[i];
5181 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5182
5183 if (b->edp &&
5184 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5185 continue;
5186
5187 /* low tech for now */
5188 if (WARN_ON(size > sizeof(buf)))
5189 continue;
5190
5191 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5192 if (err <= 0) {
5193 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5194 size, b->offset, err);
5195 continue;
5196 }
5197
5198 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
kbuild test robotb3f9d7d2015-04-16 18:34:06 +08005199 }
Jani Nikulaaa7471d2015-04-01 11:15:21 +03005200
5201 return 0;
5202}
5203
5204static int i915_dpcd_open(struct inode *inode, struct file *file)
5205{
5206 return single_open(file, i915_dpcd_show, inode->i_private);
5207}
5208
5209static const struct file_operations i915_dpcd_fops = {
5210 .owner = THIS_MODULE,
5211 .open = i915_dpcd_open,
5212 .read = seq_read,
5213 .llseek = seq_lseek,
5214 .release = single_release,
5215};
5216
5217/**
5218 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5219 * @connector: pointer to a registered drm_connector
5220 *
5221 * Cleanup will be done by drm_connector_unregister() through a call to
5222 * drm_debugfs_connector_remove().
5223 *
5224 * Returns 0 on success, negative error codes on error.
5225 */
5226int i915_debugfs_connector_add(struct drm_connector *connector)
5227{
5228 struct dentry *root = connector->debugfs_entry;
5229
5230 /* The connector must have been registered beforehands. */
5231 if (!root)
5232 return -ENODEV;
5233
5234 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5235 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5236 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5237 &i915_dpcd_fops);
5238
5239 return 0;
5240}