blob: 8d2988ae3c46005039cb7cc9998d8015250c05a3 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Chris Wilsonf13d3f72010-09-20 17:36:15 +010043enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010044 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010046 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047};
Ben Gamari433e12f2009-02-17 20:08:51 -050048
Chris Wilson70d39fe2010-08-25 16:03:34 +010049static const char *yesno(int v)
50{
51 return v ? "yes" : "no";
52}
53
Damien Lespiau497666d2013-10-15 18:55:39 +010054/* As the drm_debugfs_init() routines are called before dev->dev_private is
55 * allocated we need to hook into the minor for release. */
56static int
57drm_add_fake_info_node(struct drm_minor *minor,
58 struct dentry *ent,
59 const void *key)
60{
61 struct drm_info_node *node;
62
63 node = kmalloc(sizeof(*node), GFP_KERNEL);
64 if (node == NULL) {
65 debugfs_remove(ent);
66 return -ENOMEM;
67 }
68
69 node->minor = minor;
70 node->dent = ent;
71 node->info_ent = (void *) key;
72
73 mutex_lock(&minor->debugfs_lock);
74 list_add(&node->list, &minor->debugfs_list);
75 mutex_unlock(&minor->debugfs_lock);
76
77 return 0;
78}
79
Chris Wilson70d39fe2010-08-25 16:03:34 +010080static int i915_capabilities(struct seq_file *m, void *data)
81{
Damien Lespiau9f25d002014-05-13 15:30:28 +010082 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010083 struct drm_device *dev = node->minor->dev;
84 const struct intel_device_info *info = INTEL_INFO(dev);
85
86 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030087 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010088#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
89#define SEP_SEMICOLON ;
90 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
91#undef PRINT_FLAG
92#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010093
94 return 0;
95}
Ben Gamari433e12f2009-02-17 20:08:51 -050096
Chris Wilson05394f32010-11-08 19:18:58 +000097static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000098{
Daniel Vetter4feb7652014-11-24 11:21:52 +010099 if (i915_gem_obj_is_pinned(obj))
Chris Wilsona6172a82009-02-11 14:26:38 +0000100 return "p";
101 else
102 return " ";
103}
104
Chris Wilson05394f32010-11-08 19:18:58 +0000105static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000106{
Akshay Joshi0206e352011-08-16 15:34:10 -0400107 switch (obj->tiling_mode) {
108 default:
109 case I915_TILING_NONE: return " ";
110 case I915_TILING_X: return "X";
111 case I915_TILING_Y: return "Y";
112 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000113}
114
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700115static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
116{
Tvrtko Ursulinaff43762014-10-24 12:42:33 +0100117 return i915_gem_obj_to_ggtt(obj) ? "g" : " ";
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700118}
119
Chris Wilson37811fc2010-08-25 22:45:57 +0100120static void
121describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
122{
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700123 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800124 int pin_count = 0;
125
Ville Syrjäläfb1ae912013-08-22 19:21:30 +0300126 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %u %u %u%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100127 &obj->base,
128 get_pin_flag(obj),
129 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700130 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800131 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100132 obj->base.read_domains,
133 obj->base.write_domain,
John Harrison97b2a6a2014-11-24 18:49:26 +0000134 i915_gem_request_get_seqno(obj->last_read_req),
135 i915_gem_request_get_seqno(obj->last_write_req),
136 i915_gem_request_get_seqno(obj->last_fenced_req),
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100137 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100138 obj->dirty ? " dirty" : "",
139 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
140 if (obj->base.name)
141 seq_printf(m, " (name: %d)", obj->base.name);
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800142 list_for_each_entry(vma, &obj->vma_list, vma_link)
143 if (vma->pin_count > 0)
144 pin_count++;
145 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100146 if (obj->pin_display)
147 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100148 if (obj->fence_reg != I915_FENCE_REG_NONE)
149 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700150 list_for_each_entry(vma, &obj->vma_list, vma_link) {
151 if (!i915_is_ggtt(vma->vm))
152 seq_puts(m, " (pp");
153 else
154 seq_puts(m, " (g");
Tvrtko Ursulinfe14d5f2014-12-10 17:27:58 +0000155 seq_printf(m, "gtt offset: %08lx, size: %08lx, type: %u)",
156 vma->node.start, vma->node.size,
157 vma->ggtt_view.type);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700158 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000159 if (obj->stolen)
160 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000161 if (obj->pin_mappable || obj->fault_mappable) {
162 char s[3], *t = s;
163 if (obj->pin_mappable)
164 *t++ = 'p';
165 if (obj->fault_mappable)
166 *t++ = 'f';
167 *t = '\0';
168 seq_printf(m, " (%s mappable)", s);
169 }
John Harrison41c52412014-11-24 18:49:43 +0000170 if (obj->last_read_req != NULL)
171 seq_printf(m, " (%s)",
172 i915_gem_request_get_ring(obj->last_read_req)->name);
Daniel Vetterd5a81ef2014-06-18 14:46:49 +0200173 if (obj->frontbuffer_bits)
174 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
Chris Wilson37811fc2010-08-25 22:45:57 +0100175}
176
Oscar Mateo273497e2014-05-22 14:13:37 +0100177static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700178{
Oscar Mateoea0c76f2014-07-03 16:27:59 +0100179 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700180 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
181 seq_putc(m, ' ');
182}
183
Ben Gamari433e12f2009-02-17 20:08:51 -0500184static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500185{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100186 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500187 uintptr_t list = (uintptr_t) node->info_ent->data;
188 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500189 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700190 struct drm_i915_private *dev_priv = dev->dev_private;
191 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700192 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100193 size_t total_obj_size, total_gtt_size;
194 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100195
196 ret = mutex_lock_interruptible(&dev->struct_mutex);
197 if (ret)
198 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500199
Ben Widawskyca191b12013-07-31 17:00:14 -0700200 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500201 switch (list) {
202 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100203 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700204 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500205 break;
206 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100207 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700208 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500209 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500210 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100211 mutex_unlock(&dev->struct_mutex);
212 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500213 }
214
Chris Wilson8f2480f2010-09-26 11:44:19 +0100215 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700216 list_for_each_entry(vma, head, mm_list) {
217 seq_printf(m, " ");
218 describe_obj(m, vma->obj);
219 seq_printf(m, "\n");
220 total_obj_size += vma->obj->base.size;
221 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100222 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500223 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100224 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700225
Chris Wilson8f2480f2010-09-26 11:44:19 +0100226 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
227 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500228 return 0;
229}
230
Chris Wilson6d2b88852013-08-07 18:30:54 +0100231static int obj_rank_by_stolen(void *priv,
232 struct list_head *A, struct list_head *B)
233{
234 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200235 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100236 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200237 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100238
239 return a->stolen->start - b->stolen->start;
240}
241
242static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
243{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100244 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100245 struct drm_device *dev = node->minor->dev;
246 struct drm_i915_private *dev_priv = dev->dev_private;
247 struct drm_i915_gem_object *obj;
248 size_t total_obj_size, total_gtt_size;
249 LIST_HEAD(stolen);
250 int count, ret;
251
252 ret = mutex_lock_interruptible(&dev->struct_mutex);
253 if (ret)
254 return ret;
255
256 total_obj_size = total_gtt_size = count = 0;
257 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
258 if (obj->stolen == NULL)
259 continue;
260
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200261 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100262
263 total_obj_size += obj->base.size;
264 total_gtt_size += i915_gem_obj_ggtt_size(obj);
265 count++;
266 }
267 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
268 if (obj->stolen == NULL)
269 continue;
270
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200271 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100272
273 total_obj_size += obj->base.size;
274 count++;
275 }
276 list_sort(NULL, &stolen, obj_rank_by_stolen);
277 seq_puts(m, "Stolen:\n");
278 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200279 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100280 seq_puts(m, " ");
281 describe_obj(m, obj);
282 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200283 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100284 }
285 mutex_unlock(&dev->struct_mutex);
286
287 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
288 count, total_obj_size, total_gtt_size);
289 return 0;
290}
291
Chris Wilson6299f992010-11-24 12:23:44 +0000292#define count_objects(list, member) do { \
293 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700294 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000295 ++count; \
296 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700297 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000298 ++mappable_count; \
299 } \
300 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400301} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000302
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100303struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000304 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100305 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000306 size_t total, unbound;
307 size_t global, shared;
308 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100309};
310
311static int per_file_stats(int id, void *ptr, void *data)
312{
313 struct drm_i915_gem_object *obj = ptr;
314 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000315 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100316
317 stats->count++;
318 stats->total += obj->base.size;
319
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000320 if (obj->base.name || obj->base.dma_buf)
321 stats->shared += obj->base.size;
322
Chris Wilson6313c202014-03-19 13:45:45 +0000323 if (USES_FULL_PPGTT(obj->base.dev)) {
324 list_for_each_entry(vma, &obj->vma_list, vma_link) {
325 struct i915_hw_ppgtt *ppgtt;
326
327 if (!drm_mm_node_allocated(&vma->node))
328 continue;
329
330 if (i915_is_ggtt(vma->vm)) {
331 stats->global += obj->base.size;
332 continue;
333 }
334
335 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
Daniel Vetter4d884702014-08-06 15:04:47 +0200336 if (ppgtt->file_priv != stats->file_priv)
Chris Wilson6313c202014-03-19 13:45:45 +0000337 continue;
338
John Harrison41c52412014-11-24 18:49:43 +0000339 if (obj->active) /* XXX per-vma statistic */
Chris Wilson6313c202014-03-19 13:45:45 +0000340 stats->active += obj->base.size;
341 else
342 stats->inactive += obj->base.size;
343
344 return 0;
345 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100346 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000347 if (i915_gem_obj_ggtt_bound(obj)) {
348 stats->global += obj->base.size;
John Harrison41c52412014-11-24 18:49:43 +0000349 if (obj->active)
Chris Wilson6313c202014-03-19 13:45:45 +0000350 stats->active += obj->base.size;
351 else
352 stats->inactive += obj->base.size;
353 return 0;
354 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100355 }
356
Chris Wilson6313c202014-03-19 13:45:45 +0000357 if (!list_empty(&obj->global_list))
358 stats->unbound += obj->base.size;
359
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100360 return 0;
361}
362
Ben Widawskyca191b12013-07-31 17:00:14 -0700363#define count_vmas(list, member) do { \
364 list_for_each_entry(vma, list, member) { \
365 size += i915_gem_obj_ggtt_size(vma->obj); \
366 ++count; \
367 if (vma->obj->map_and_fenceable) { \
368 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
369 ++mappable_count; \
370 } \
371 } \
372} while (0)
373
374static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100375{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100376 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100377 struct drm_device *dev = node->minor->dev;
378 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200379 u32 count, mappable_count, purgeable_count;
380 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000381 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700382 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100383 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700384 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100385 int ret;
386
387 ret = mutex_lock_interruptible(&dev->struct_mutex);
388 if (ret)
389 return ret;
390
Chris Wilson6299f992010-11-24 12:23:44 +0000391 seq_printf(m, "%u objects, %zu bytes\n",
392 dev_priv->mm.object_count,
393 dev_priv->mm.object_memory);
394
395 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700396 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000397 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
398 count, mappable_count, size, mappable_size);
399
400 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700401 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000402 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
403 count, mappable_count, size, mappable_size);
404
405 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700406 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000407 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
408 count, mappable_count, size, mappable_size);
409
Chris Wilsonb7abb712012-08-20 11:33:30 +0200410 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700411 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200412 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200413 if (obj->madv == I915_MADV_DONTNEED)
414 purgeable_size += obj->base.size, ++purgeable_count;
415 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200416 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
417
Chris Wilson6299f992010-11-24 12:23:44 +0000418 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700419 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000420 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700421 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000422 ++count;
423 }
424 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700425 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000426 ++mappable_count;
427 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200428 if (obj->madv == I915_MADV_DONTNEED) {
429 purgeable_size += obj->base.size;
430 ++purgeable_count;
431 }
Chris Wilson6299f992010-11-24 12:23:44 +0000432 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200433 seq_printf(m, "%u purgeable objects, %zu bytes\n",
434 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000435 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
436 mappable_count, mappable_size);
437 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
438 count, size);
439
Ben Widawsky93d18792013-01-17 12:45:17 -0800440 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700441 dev_priv->gtt.base.total,
442 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100443
Damien Lespiau267f0c92013-06-24 22:59:48 +0100444 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100445 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
446 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900447 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100448
449 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000450 stats.file_priv = file->driver_priv;
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100451 spin_lock(&file->table_lock);
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100452 idr_for_each(&file->object_idr, per_file_stats, &stats);
Chris Wilson5b5ffff2014-06-17 09:56:24 +0100453 spin_unlock(&file->table_lock);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900454 /*
455 * Although we have a valid reference on file->pid, that does
456 * not guarantee that the task_struct who called get_pid() is
457 * still alive (e.g. get_pid(current) => fork() => exit()).
458 * Therefore, we need to protect this ->comm access using RCU.
459 */
460 rcu_read_lock();
461 task = pid_task(file->pid, PIDTYPE_PID);
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000462 seq_printf(m, "%s: %u objects, %zu bytes (%zu active, %zu inactive, %zu global, %zu shared, %zu unbound)\n",
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900463 task ? task->comm : "<unknown>",
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100464 stats.count,
465 stats.total,
466 stats.active,
467 stats.inactive,
Chris Wilson6313c202014-03-19 13:45:45 +0000468 stats.global,
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000469 stats.shared,
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100470 stats.unbound);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900471 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100472 }
473
Chris Wilson73aa8082010-09-30 11:46:12 +0100474 mutex_unlock(&dev->struct_mutex);
475
476 return 0;
477}
478
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100479static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000480{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100481 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000482 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100483 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000484 struct drm_i915_private *dev_priv = dev->dev_private;
485 struct drm_i915_gem_object *obj;
486 size_t total_obj_size, total_gtt_size;
487 int count, ret;
488
489 ret = mutex_lock_interruptible(&dev->struct_mutex);
490 if (ret)
491 return ret;
492
493 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700494 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800495 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100496 continue;
497
Damien Lespiau267f0c92013-06-24 22:59:48 +0100498 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000499 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100500 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000501 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700502 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000503 count++;
504 }
505
506 mutex_unlock(&dev->struct_mutex);
507
508 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
509 count, total_obj_size, total_gtt_size);
510
511 return 0;
512}
513
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100514static int i915_gem_pageflip_info(struct seq_file *m, void *data)
515{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100516 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100517 struct drm_device *dev = node->minor->dev;
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100518 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100519 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200520 int ret;
521
522 ret = mutex_lock_interruptible(&dev->struct_mutex);
523 if (ret)
524 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100525
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100526 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800527 const char pipe = pipe_name(crtc->pipe);
528 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100529 struct intel_unpin_work *work;
530
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200531 spin_lock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100532 work = crtc->unpin_work;
533 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800534 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100535 pipe, plane);
536 } else {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100537 u32 addr;
538
Chris Wilsone7d841c2012-12-03 11:36:30 +0000539 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800540 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100541 pipe, plane);
542 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800543 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100544 pipe, plane);
545 }
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100546 if (work->flip_queued_req) {
547 struct intel_engine_cs *ring =
548 i915_gem_request_get_ring(work->flip_queued_req);
549
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100550 seq_printf(m, "Flip queued on %s at seqno %u, next seqno %u [current breadcrumb %u], completed? %d\n",
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100551 ring->name,
John Harrisonf06cc1b2014-11-24 18:49:37 +0000552 i915_gem_request_get_seqno(work->flip_queued_req),
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100553 dev_priv->next_seqno,
Daniel Vetter3a8a9462014-11-26 14:39:48 +0100554 ring->get_seqno(ring, true),
John Harrison1b5a4332014-11-24 18:49:42 +0000555 i915_gem_request_completed(work->flip_queued_req, true));
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100556 } else
557 seq_printf(m, "Flip not associated with any ring\n");
558 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
559 work->flip_queued_vblank,
560 work->flip_ready_vblank,
561 drm_vblank_count(dev, crtc->pipe));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100562 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100563 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100564 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100565 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000566 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100567
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100568 if (INTEL_INFO(dev)->gen >= 4)
569 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
570 else
571 addr = I915_READ(DSPADDR(crtc->plane));
572 seq_printf(m, "Current scanout address 0x%08x\n", addr);
573
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100574 if (work->pending_flip_obj) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +0100575 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
576 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100577 }
578 }
Daniel Vetter5e2d7af2014-09-15 14:55:22 +0200579 spin_unlock_irq(&dev->event_lock);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100580 }
581
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200582 mutex_unlock(&dev->struct_mutex);
583
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100584 return 0;
585}
586
Ben Gamari20172632009-02-17 20:08:50 -0500587static int i915_gem_request_info(struct seq_file *m, void *data)
588{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100589 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500590 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300591 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100592 struct intel_engine_cs *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500593 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100594 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100595
596 ret = mutex_lock_interruptible(&dev->struct_mutex);
597 if (ret)
598 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500599
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100600 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100601 for_each_ring(ring, dev_priv, i) {
602 if (list_empty(&ring->request_list))
603 continue;
604
605 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100606 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100607 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100608 list) {
609 seq_printf(m, " %d @ %d\n",
610 gem_request->seqno,
611 (int) (jiffies - gem_request->emitted_jiffies));
612 }
613 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500614 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100615 mutex_unlock(&dev->struct_mutex);
616
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100617 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100618 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100619
Ben Gamari20172632009-02-17 20:08:50 -0500620 return 0;
621}
622
Chris Wilsonb2223492010-10-27 15:27:33 +0100623static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100624 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100625{
626 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200627 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100628 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100629 }
630}
631
Ben Gamari20172632009-02-17 20:08:50 -0500632static int i915_gem_seqno_info(struct seq_file *m, void *data)
633{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100634 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500635 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300636 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100637 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000638 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100639
640 ret = mutex_lock_interruptible(&dev->struct_mutex);
641 if (ret)
642 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200643 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500644
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100645 for_each_ring(ring, dev_priv, i)
646 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100647
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200648 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100649 mutex_unlock(&dev->struct_mutex);
650
Ben Gamari20172632009-02-17 20:08:50 -0500651 return 0;
652}
653
654
655static int i915_interrupt_info(struct seq_file *m, void *data)
656{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100657 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500658 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300659 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100660 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800661 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100662
663 ret = mutex_lock_interruptible(&dev->struct_mutex);
664 if (ret)
665 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200666 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500667
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300668 if (IS_CHERRYVIEW(dev)) {
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300669 seq_printf(m, "Master Interrupt Control:\t%08x\n",
670 I915_READ(GEN8_MASTER_IRQ));
671
672 seq_printf(m, "Display IER:\t%08x\n",
673 I915_READ(VLV_IER));
674 seq_printf(m, "Display IIR:\t%08x\n",
675 I915_READ(VLV_IIR));
676 seq_printf(m, "Display IIR_RW:\t%08x\n",
677 I915_READ(VLV_IIR_RW));
678 seq_printf(m, "Display IMR:\t%08x\n",
679 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100680 for_each_pipe(dev_priv, pipe)
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300681 seq_printf(m, "Pipe %c stat:\t%08x\n",
682 pipe_name(pipe),
683 I915_READ(PIPESTAT(pipe)));
684
685 seq_printf(m, "Port hotplug:\t%08x\n",
686 I915_READ(PORT_HOTPLUG_EN));
687 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
688 I915_READ(VLV_DPFLIPSTAT));
689 seq_printf(m, "DPINVGTT:\t%08x\n",
690 I915_READ(DPINVGTT));
691
692 for (i = 0; i < 4; i++) {
693 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
694 i, I915_READ(GEN8_GT_IMR(i)));
695 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
696 i, I915_READ(GEN8_GT_IIR(i)));
697 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
698 i, I915_READ(GEN8_GT_IER(i)));
699 }
700
701 seq_printf(m, "PCU interrupt mask:\t%08x\n",
702 I915_READ(GEN8_PCU_IMR));
703 seq_printf(m, "PCU interrupt identity:\t%08x\n",
704 I915_READ(GEN8_PCU_IIR));
705 seq_printf(m, "PCU interrupt enable:\t%08x\n",
706 I915_READ(GEN8_PCU_IER));
707 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700708 seq_printf(m, "Master Interrupt Control:\t%08x\n",
709 I915_READ(GEN8_MASTER_IRQ));
710
711 for (i = 0; i < 4; i++) {
712 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
713 i, I915_READ(GEN8_GT_IMR(i)));
714 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
715 i, I915_READ(GEN8_GT_IIR(i)));
716 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
717 i, I915_READ(GEN8_GT_IER(i)));
718 }
719
Damien Lespiau055e3932014-08-18 13:49:10 +0100720 for_each_pipe(dev_priv, pipe) {
Daniel Vetterf458ebb2014-09-30 10:56:39 +0200721 if (!intel_display_power_is_enabled(dev_priv,
Paulo Zanoni22c59962014-08-08 17:45:32 -0300722 POWER_DOMAIN_PIPE(pipe))) {
723 seq_printf(m, "Pipe %c power disabled\n",
724 pipe_name(pipe));
725 continue;
726 }
Ben Widawskya123f152013-11-02 21:07:10 -0700727 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000728 pipe_name(pipe),
729 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700730 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000731 pipe_name(pipe),
732 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700733 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000734 pipe_name(pipe),
735 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700736 }
737
738 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
739 I915_READ(GEN8_DE_PORT_IMR));
740 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
741 I915_READ(GEN8_DE_PORT_IIR));
742 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
743 I915_READ(GEN8_DE_PORT_IER));
744
745 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
746 I915_READ(GEN8_DE_MISC_IMR));
747 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
748 I915_READ(GEN8_DE_MISC_IIR));
749 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
750 I915_READ(GEN8_DE_MISC_IER));
751
752 seq_printf(m, "PCU interrupt mask:\t%08x\n",
753 I915_READ(GEN8_PCU_IMR));
754 seq_printf(m, "PCU interrupt identity:\t%08x\n",
755 I915_READ(GEN8_PCU_IIR));
756 seq_printf(m, "PCU interrupt enable:\t%08x\n",
757 I915_READ(GEN8_PCU_IER));
758 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700759 seq_printf(m, "Display IER:\t%08x\n",
760 I915_READ(VLV_IER));
761 seq_printf(m, "Display IIR:\t%08x\n",
762 I915_READ(VLV_IIR));
763 seq_printf(m, "Display IIR_RW:\t%08x\n",
764 I915_READ(VLV_IIR_RW));
765 seq_printf(m, "Display IMR:\t%08x\n",
766 I915_READ(VLV_IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100767 for_each_pipe(dev_priv, pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700768 seq_printf(m, "Pipe %c stat:\t%08x\n",
769 pipe_name(pipe),
770 I915_READ(PIPESTAT(pipe)));
771
772 seq_printf(m, "Master IER:\t%08x\n",
773 I915_READ(VLV_MASTER_IER));
774
775 seq_printf(m, "Render IER:\t%08x\n",
776 I915_READ(GTIER));
777 seq_printf(m, "Render IIR:\t%08x\n",
778 I915_READ(GTIIR));
779 seq_printf(m, "Render IMR:\t%08x\n",
780 I915_READ(GTIMR));
781
782 seq_printf(m, "PM IER:\t\t%08x\n",
783 I915_READ(GEN6_PMIER));
784 seq_printf(m, "PM IIR:\t\t%08x\n",
785 I915_READ(GEN6_PMIIR));
786 seq_printf(m, "PM IMR:\t\t%08x\n",
787 I915_READ(GEN6_PMIMR));
788
789 seq_printf(m, "Port hotplug:\t%08x\n",
790 I915_READ(PORT_HOTPLUG_EN));
791 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
792 I915_READ(VLV_DPFLIPSTAT));
793 seq_printf(m, "DPINVGTT:\t%08x\n",
794 I915_READ(DPINVGTT));
795
796 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800797 seq_printf(m, "Interrupt enable: %08x\n",
798 I915_READ(IER));
799 seq_printf(m, "Interrupt identity: %08x\n",
800 I915_READ(IIR));
801 seq_printf(m, "Interrupt mask: %08x\n",
802 I915_READ(IMR));
Damien Lespiau055e3932014-08-18 13:49:10 +0100803 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800804 seq_printf(m, "Pipe %c stat: %08x\n",
805 pipe_name(pipe),
806 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800807 } else {
808 seq_printf(m, "North Display Interrupt enable: %08x\n",
809 I915_READ(DEIER));
810 seq_printf(m, "North Display Interrupt identity: %08x\n",
811 I915_READ(DEIIR));
812 seq_printf(m, "North Display Interrupt mask: %08x\n",
813 I915_READ(DEIMR));
814 seq_printf(m, "South Display Interrupt enable: %08x\n",
815 I915_READ(SDEIER));
816 seq_printf(m, "South Display Interrupt identity: %08x\n",
817 I915_READ(SDEIIR));
818 seq_printf(m, "South Display Interrupt mask: %08x\n",
819 I915_READ(SDEIMR));
820 seq_printf(m, "Graphics Interrupt enable: %08x\n",
821 I915_READ(GTIER));
822 seq_printf(m, "Graphics Interrupt identity: %08x\n",
823 I915_READ(GTIIR));
824 seq_printf(m, "Graphics Interrupt mask: %08x\n",
825 I915_READ(GTIMR));
826 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100827 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700828 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100829 seq_printf(m,
830 "Graphics Interrupt mask (%s): %08x\n",
831 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000832 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100833 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000834 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200835 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100836 mutex_unlock(&dev->struct_mutex);
837
Ben Gamari20172632009-02-17 20:08:50 -0500838 return 0;
839}
840
Chris Wilsona6172a82009-02-11 14:26:38 +0000841static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
842{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100843 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000844 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300845 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100846 int i, ret;
847
848 ret = mutex_lock_interruptible(&dev->struct_mutex);
849 if (ret)
850 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000851
852 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
853 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
854 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000855 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000856
Chris Wilson6c085a72012-08-20 11:40:46 +0200857 seq_printf(m, "Fence %d, pin count = %d, object = ",
858 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100859 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100860 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100861 else
Chris Wilson05394f32010-11-08 19:18:58 +0000862 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100863 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000864 }
865
Chris Wilson05394f32010-11-08 19:18:58 +0000866 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000867 return 0;
868}
869
Ben Gamari20172632009-02-17 20:08:50 -0500870static int i915_hws_info(struct seq_file *m, void *data)
871{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100872 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500873 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300874 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100875 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100876 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100877 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500878
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000879 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100880 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500881 if (hws == NULL)
882 return 0;
883
884 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
885 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
886 i * 4,
887 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
888 }
889 return 0;
890}
891
Daniel Vetterd5442302012-04-27 15:17:40 +0200892static ssize_t
893i915_error_state_write(struct file *filp,
894 const char __user *ubuf,
895 size_t cnt,
896 loff_t *ppos)
897{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300898 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200899 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200900 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200901
902 DRM_DEBUG_DRIVER("Resetting error state\n");
903
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200904 ret = mutex_lock_interruptible(&dev->struct_mutex);
905 if (ret)
906 return ret;
907
Daniel Vetterd5442302012-04-27 15:17:40 +0200908 i915_destroy_error_state(dev);
909 mutex_unlock(&dev->struct_mutex);
910
911 return cnt;
912}
913
914static int i915_error_state_open(struct inode *inode, struct file *file)
915{
916 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200917 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200918
919 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
920 if (!error_priv)
921 return -ENOMEM;
922
923 error_priv->dev = dev;
924
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300925 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200926
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300927 file->private_data = error_priv;
928
929 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200930}
931
932static int i915_error_state_release(struct inode *inode, struct file *file)
933{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300934 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200935
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300936 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200937 kfree(error_priv);
938
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300939 return 0;
940}
941
942static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
943 size_t count, loff_t *pos)
944{
945 struct i915_error_state_file_priv *error_priv = file->private_data;
946 struct drm_i915_error_state_buf error_str;
947 loff_t tmp_pos = 0;
948 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300949 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300950
Chris Wilson0a4cd7c2014-08-22 14:41:39 +0100951 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300952 if (ret)
953 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300954
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300955 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300956 if (ret)
957 goto out;
958
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300959 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
960 error_str.buf,
961 error_str.bytes);
962
963 if (ret_count < 0)
964 ret = ret_count;
965 else
966 *pos = error_str.start + ret_count;
967out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300968 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300969 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +0200970}
971
972static const struct file_operations i915_error_state_fops = {
973 .owner = THIS_MODULE,
974 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300975 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200976 .write = i915_error_state_write,
977 .llseek = default_llseek,
978 .release = i915_error_state_release,
979};
980
Kees Cook647416f2013-03-10 14:10:06 -0700981static int
982i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200983{
Kees Cook647416f2013-03-10 14:10:06 -0700984 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300985 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +0200986 int ret;
987
988 ret = mutex_lock_interruptible(&dev->struct_mutex);
989 if (ret)
990 return ret;
991
Kees Cook647416f2013-03-10 14:10:06 -0700992 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +0200993 mutex_unlock(&dev->struct_mutex);
994
Kees Cook647416f2013-03-10 14:10:06 -0700995 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +0200996}
997
Kees Cook647416f2013-03-10 14:10:06 -0700998static int
999i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +02001000{
Kees Cook647416f2013-03-10 14:10:06 -07001001 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +02001002 int ret;
1003
Mika Kuoppala40633212012-12-04 15:12:00 +02001004 ret = mutex_lock_interruptible(&dev->struct_mutex);
1005 if (ret)
1006 return ret;
1007
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +02001008 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +02001009 mutex_unlock(&dev->struct_mutex);
1010
Kees Cook647416f2013-03-10 14:10:06 -07001011 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +02001012}
1013
Kees Cook647416f2013-03-10 14:10:06 -07001014DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1015 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03001016 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +02001017
Deepak Sadb4bd12014-03-31 11:30:02 +05301018static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001019{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001020 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001021 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001022 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001023 int ret = 0;
1024
1025 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001026
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001027 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1028
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001029 if (IS_GEN5(dev)) {
1030 u16 rgvswctl = I915_READ16(MEMSWCTL);
1031 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1032
1033 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1034 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1035 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1036 MEMSTAT_VID_SHIFT);
1037 seq_printf(m, "Current P-state: %d\n",
1038 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001039 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
1040 IS_BROADWELL(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001041 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1042 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1043 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001044 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001045 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001046 u32 rpupei, rpcurup, rpprevup;
1047 u32 rpdownei, rpcurdown, rpprevdown;
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001048 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001049 int max_freq;
1050
1051 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001052 ret = mutex_lock_interruptible(&dev->struct_mutex);
1053 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001054 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001055
Deepak Sc8d9a592013-11-23 14:55:42 +05301056 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001057
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001058 reqf = I915_READ(GEN6_RPNSWREQ);
1059 reqf &= ~GEN6_TURBO_DISABLE;
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001060 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001061 reqf >>= 24;
1062 else
1063 reqf >>= 25;
1064 reqf *= GT_FREQUENCY_MULTIPLIER;
1065
Chris Wilson0d8f9492014-03-27 09:06:14 +00001066 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1067 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1068 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1069
Jesse Barnesccab5c82011-01-18 15:49:25 -08001070 rpstat = I915_READ(GEN6_RPSTAT1);
1071 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1072 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1073 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1074 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1075 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1076 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001077 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001078 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1079 else
1080 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
1081 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001082
Deepak Sc8d9a592013-11-23 14:55:42 +05301083 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001084 mutex_unlock(&dev->struct_mutex);
1085
Paulo Zanoni9dd3c602014-08-01 18:14:48 -03001086 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1087 pm_ier = I915_READ(GEN6_PMIER);
1088 pm_imr = I915_READ(GEN6_PMIMR);
1089 pm_isr = I915_READ(GEN6_PMISR);
1090 pm_iir = I915_READ(GEN6_PMIIR);
1091 pm_mask = I915_READ(GEN6_PMINTRMSK);
1092 } else {
1093 pm_ier = I915_READ(GEN8_GT_IER(2));
1094 pm_imr = I915_READ(GEN8_GT_IMR(2));
1095 pm_isr = I915_READ(GEN8_GT_ISR(2));
1096 pm_iir = I915_READ(GEN8_GT_IIR(2));
1097 pm_mask = I915_READ(GEN6_PMINTRMSK);
1098 }
Chris Wilson0d8f9492014-03-27 09:06:14 +00001099 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 -03001100 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001101 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001102 seq_printf(m, "Render p-state ratio: %d\n",
1103 (gt_perf_status & 0xff00) >> 8);
1104 seq_printf(m, "Render p-state VID: %d\n",
1105 gt_perf_status & 0xff);
1106 seq_printf(m, "Render p-state limit: %d\n",
1107 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001108 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1109 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1110 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1111 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001112 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001113 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001114 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1115 GEN6_CURICONT_MASK);
1116 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1117 GEN6_CURBSYTAVG_MASK);
1118 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1119 GEN6_CURBSYTAVG_MASK);
1120 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1121 GEN6_CURIAVG_MASK);
1122 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1123 GEN6_CURBSYTAVG_MASK);
1124 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1125 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001126
1127 max_freq = (rp_state_cap & 0xff0000) >> 16;
1128 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001129 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001130
1131 max_freq = (rp_state_cap & 0xff00) >> 8;
1132 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001133 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001134
1135 max_freq = rp_state_cap & 0xff;
1136 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001137 max_freq * GT_FREQUENCY_MULTIPLIER);
Ben Widawsky31c77382013-04-05 14:29:22 -07001138
1139 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ben Widawskyb39fb292014-03-19 18:31:11 -07001140 dev_priv->rps.max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001141 } else if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001142 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001143
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001144 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001145 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001146 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1147 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1148
Jesse Barnes0a073b82013-04-17 15:54:58 -07001149 seq_printf(m, "max GPU freq: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301150 vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001151
Jesse Barnes0a073b82013-04-17 15:54:58 -07001152 seq_printf(m, "min GPU freq: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301153 vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001154
1155 seq_printf(m, "efficient (RPe) frequency: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301156 vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001157
1158 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001159 vlv_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001160 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001161 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001162 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001163 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001164
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001165out:
1166 intel_runtime_pm_put(dev_priv);
1167 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001168}
1169
Ben Widawsky4d855292011-12-12 19:34:16 -08001170static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001171{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001172 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001173 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001174 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001175 u32 rgvmodectl, rstdbyctl;
1176 u16 crstandvid;
1177 int ret;
1178
1179 ret = mutex_lock_interruptible(&dev->struct_mutex);
1180 if (ret)
1181 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001182 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001183
1184 rgvmodectl = I915_READ(MEMMODECTL);
1185 rstdbyctl = I915_READ(RSTDBYCTL);
1186 crstandvid = I915_READ16(CRSTANDVID);
1187
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001188 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001189 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001190
1191 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1192 "yes" : "no");
1193 seq_printf(m, "Boost freq: %d\n",
1194 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1195 MEMMODE_BOOST_FREQ_SHIFT);
1196 seq_printf(m, "HW control enabled: %s\n",
1197 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1198 seq_printf(m, "SW control enabled: %s\n",
1199 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1200 seq_printf(m, "Gated voltage change: %s\n",
1201 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1202 seq_printf(m, "Starting frequency: P%d\n",
1203 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001204 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001205 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001206 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1207 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1208 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1209 seq_printf(m, "Render standby enabled: %s\n",
1210 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001211 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001212 switch (rstdbyctl & RSX_STATUS_MASK) {
1213 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001214 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001215 break;
1216 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001217 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001218 break;
1219 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001220 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001221 break;
1222 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001223 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001224 break;
1225 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001226 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001227 break;
1228 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001229 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001230 break;
1231 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001232 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001233 break;
1234 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001235
1236 return 0;
1237}
1238
Deepak S669ab5a2014-01-10 15:18:26 +05301239static int vlv_drpc_info(struct seq_file *m)
1240{
1241
Damien Lespiau9f25d002014-05-13 15:30:28 +01001242 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301243 struct drm_device *dev = node->minor->dev;
1244 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001245 u32 rpmodectl1, rcctl1, pw_status;
Deepak S669ab5a2014-01-10 15:18:26 +05301246 unsigned fw_rendercount = 0, fw_mediacount = 0;
1247
Imre Deakd46c0512014-04-14 20:24:27 +03001248 intel_runtime_pm_get(dev_priv);
1249
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001250 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
Deepak S669ab5a2014-01-10 15:18:26 +05301251 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1252 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1253
Imre Deakd46c0512014-04-14 20:24:27 +03001254 intel_runtime_pm_put(dev_priv);
1255
Deepak S669ab5a2014-01-10 15:18:26 +05301256 seq_printf(m, "Video Turbo Mode: %s\n",
1257 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1258 seq_printf(m, "Turbo enabled: %s\n",
1259 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1260 seq_printf(m, "HW control enabled: %s\n",
1261 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1262 seq_printf(m, "SW control enabled: %s\n",
1263 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1264 GEN6_RP_MEDIA_SW_MODE));
1265 seq_printf(m, "RC6 Enabled: %s\n",
1266 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1267 GEN6_RC_CTL_EI_MODE(1))));
1268 seq_printf(m, "Render Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001269 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301270 seq_printf(m, "Media Power Well: %s\n",
Ville Syrjälä6b312cd2014-11-19 20:07:42 +02001271 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
Deepak S669ab5a2014-01-10 15:18:26 +05301272
Imre Deak9cc19be2014-04-14 20:24:24 +03001273 seq_printf(m, "Render RC6 residency since boot: %u\n",
1274 I915_READ(VLV_GT_RENDER_RC6));
1275 seq_printf(m, "Media RC6 residency since boot: %u\n",
1276 I915_READ(VLV_GT_MEDIA_RC6));
1277
Deepak S669ab5a2014-01-10 15:18:26 +05301278 spin_lock_irq(&dev_priv->uncore.lock);
1279 fw_rendercount = dev_priv->uncore.fw_rendercount;
1280 fw_mediacount = dev_priv->uncore.fw_mediacount;
1281 spin_unlock_irq(&dev_priv->uncore.lock);
1282
1283 seq_printf(m, "Forcewake Render Count = %u\n", fw_rendercount);
1284 seq_printf(m, "Forcewake Media Count = %u\n", fw_mediacount);
1285
1286
1287 return 0;
1288}
1289
1290
Ben Widawsky4d855292011-12-12 19:34:16 -08001291static int gen6_drpc_info(struct seq_file *m)
1292{
1293
Damien Lespiau9f25d002014-05-13 15:30:28 +01001294 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001295 struct drm_device *dev = node->minor->dev;
1296 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001297 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001298 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001299 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001300
1301 ret = mutex_lock_interruptible(&dev->struct_mutex);
1302 if (ret)
1303 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001304 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001305
Chris Wilson907b28c2013-07-19 20:36:52 +01001306 spin_lock_irq(&dev_priv->uncore.lock);
1307 forcewake_count = dev_priv->uncore.forcewake_count;
1308 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001309
1310 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001311 seq_puts(m, "RC information inaccurate because somebody "
1312 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001313 } else {
1314 /* NB: we cannot use forcewake, else we read the wrong values */
1315 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1316 udelay(10);
1317 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1318 }
1319
1320 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001321 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001322
1323 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1324 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1325 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001326 mutex_lock(&dev_priv->rps.hw_lock);
1327 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1328 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001329
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001330 intel_runtime_pm_put(dev_priv);
1331
Ben Widawsky4d855292011-12-12 19:34:16 -08001332 seq_printf(m, "Video Turbo Mode: %s\n",
1333 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1334 seq_printf(m, "HW control enabled: %s\n",
1335 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1336 seq_printf(m, "SW control enabled: %s\n",
1337 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1338 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001339 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001340 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1341 seq_printf(m, "RC6 Enabled: %s\n",
1342 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1343 seq_printf(m, "Deep RC6 Enabled: %s\n",
1344 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1345 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1346 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001347 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001348 switch (gt_core_status & GEN6_RCn_MASK) {
1349 case GEN6_RC0:
1350 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001351 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001352 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001353 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001354 break;
1355 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001356 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001357 break;
1358 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001359 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001360 break;
1361 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001362 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001363 break;
1364 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001365 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001366 break;
1367 }
1368
1369 seq_printf(m, "Core Power Down: %s\n",
1370 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001371
1372 /* Not exactly sure what this is */
1373 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1374 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1375 seq_printf(m, "RC6 residency since boot: %u\n",
1376 I915_READ(GEN6_GT_GFX_RC6));
1377 seq_printf(m, "RC6+ residency since boot: %u\n",
1378 I915_READ(GEN6_GT_GFX_RC6p));
1379 seq_printf(m, "RC6++ residency since boot: %u\n",
1380 I915_READ(GEN6_GT_GFX_RC6pp));
1381
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001382 seq_printf(m, "RC6 voltage: %dmV\n",
1383 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1384 seq_printf(m, "RC6+ voltage: %dmV\n",
1385 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1386 seq_printf(m, "RC6++ voltage: %dmV\n",
1387 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001388 return 0;
1389}
1390
1391static int i915_drpc_info(struct seq_file *m, void *unused)
1392{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001393 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001394 struct drm_device *dev = node->minor->dev;
1395
Deepak S669ab5a2014-01-10 15:18:26 +05301396 if (IS_VALLEYVIEW(dev))
1397 return vlv_drpc_info(m);
Vedang Patelac66cf42014-08-26 10:42:51 -07001398 else if (INTEL_INFO(dev)->gen >= 6)
Ben Widawsky4d855292011-12-12 19:34:16 -08001399 return gen6_drpc_info(m);
1400 else
1401 return ironlake_drpc_info(m);
1402}
1403
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001404static int i915_fbc_status(struct seq_file *m, void *unused)
1405{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001406 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001407 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001408 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001409
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001410 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001411 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001412 return 0;
1413 }
1414
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001415 intel_runtime_pm_get(dev_priv);
1416
Adam Jacksonee5382a2010-04-23 11:17:39 -04001417 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001418 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001419 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001420 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001421 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001422 case FBC_OK:
1423 seq_puts(m, "FBC actived, but currently disabled in hardware");
1424 break;
1425 case FBC_UNSUPPORTED:
1426 seq_puts(m, "unsupported by this chipset");
1427 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001428 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001429 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001430 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001431 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001432 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001433 break;
1434 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001435 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001436 break;
1437 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001438 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001439 break;
1440 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001441 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001442 break;
1443 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001444 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001445 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001446 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001447 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001448 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001449 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001450 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001451 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001452 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001453 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001454 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001455 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001456 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001457 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001458 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001459 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001460
1461 intel_runtime_pm_put(dev_priv);
1462
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001463 return 0;
1464}
1465
Rodrigo Vivida46f932014-08-01 02:04:45 -07001466static int i915_fbc_fc_get(void *data, u64 *val)
1467{
1468 struct drm_device *dev = data;
1469 struct drm_i915_private *dev_priv = dev->dev_private;
1470
1471 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1472 return -ENODEV;
1473
1474 drm_modeset_lock_all(dev);
1475 *val = dev_priv->fbc.false_color;
1476 drm_modeset_unlock_all(dev);
1477
1478 return 0;
1479}
1480
1481static int i915_fbc_fc_set(void *data, u64 val)
1482{
1483 struct drm_device *dev = data;
1484 struct drm_i915_private *dev_priv = dev->dev_private;
1485 u32 reg;
1486
1487 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1488 return -ENODEV;
1489
1490 drm_modeset_lock_all(dev);
1491
1492 reg = I915_READ(ILK_DPFC_CONTROL);
1493 dev_priv->fbc.false_color = val;
1494
1495 I915_WRITE(ILK_DPFC_CONTROL, val ?
1496 (reg | FBC_CTL_FALSE_COLOR) :
1497 (reg & ~FBC_CTL_FALSE_COLOR));
1498
1499 drm_modeset_unlock_all(dev);
1500 return 0;
1501}
1502
1503DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1504 i915_fbc_fc_get, i915_fbc_fc_set,
1505 "%llu\n");
1506
Paulo Zanoni92d44622013-05-31 16:33:24 -03001507static int i915_ips_status(struct seq_file *m, void *unused)
1508{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001509 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001510 struct drm_device *dev = node->minor->dev;
1511 struct drm_i915_private *dev_priv = dev->dev_private;
1512
Damien Lespiauf5adf942013-06-24 18:29:34 +01001513 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001514 seq_puts(m, "not supported\n");
1515 return 0;
1516 }
1517
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001518 intel_runtime_pm_get(dev_priv);
1519
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001520 seq_printf(m, "Enabled by kernel parameter: %s\n",
1521 yesno(i915.enable_ips));
1522
1523 if (INTEL_INFO(dev)->gen >= 8) {
1524 seq_puts(m, "Currently: unknown\n");
1525 } else {
1526 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1527 seq_puts(m, "Currently: enabled\n");
1528 else
1529 seq_puts(m, "Currently: disabled\n");
1530 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001531
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001532 intel_runtime_pm_put(dev_priv);
1533
Paulo Zanoni92d44622013-05-31 16:33:24 -03001534 return 0;
1535}
1536
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001537static int i915_sr_status(struct seq_file *m, void *unused)
1538{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001539 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001540 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001541 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001542 bool sr_enabled = false;
1543
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001544 intel_runtime_pm_get(dev_priv);
1545
Yuanhan Liu13982612010-12-15 15:42:31 +08001546 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001547 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001548 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001549 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1550 else if (IS_I915GM(dev))
1551 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1552 else if (IS_PINEVIEW(dev))
1553 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1554
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001555 intel_runtime_pm_put(dev_priv);
1556
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001557 seq_printf(m, "self-refresh: %s\n",
1558 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001559
1560 return 0;
1561}
1562
Jesse Barnes7648fa92010-05-20 14:28:11 -07001563static int i915_emon_status(struct seq_file *m, void *unused)
1564{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001565 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001566 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001567 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001568 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001569 int ret;
1570
Chris Wilson582be6b2012-04-30 19:35:02 +01001571 if (!IS_GEN5(dev))
1572 return -ENODEV;
1573
Chris Wilsonde227ef2010-07-03 07:58:38 +01001574 ret = mutex_lock_interruptible(&dev->struct_mutex);
1575 if (ret)
1576 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001577
1578 temp = i915_mch_val(dev_priv);
1579 chipset = i915_chipset_val(dev_priv);
1580 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001581 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001582
1583 seq_printf(m, "GMCH temp: %ld\n", temp);
1584 seq_printf(m, "Chipset power: %ld\n", chipset);
1585 seq_printf(m, "GFX power: %ld\n", gfx);
1586 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1587
1588 return 0;
1589}
1590
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001591static int i915_ring_freq_table(struct seq_file *m, void *unused)
1592{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001593 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001594 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001595 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001596 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001597 int gpu_freq, ia_freq;
1598
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001599 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001600 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001601 return 0;
1602 }
1603
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001604 intel_runtime_pm_get(dev_priv);
1605
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001606 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1607
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001608 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001609 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001610 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001611
Damien Lespiau267f0c92013-06-24 22:59:48 +01001612 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001613
Ben Widawskyb39fb292014-03-19 18:31:11 -07001614 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1615 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001616 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001617 ia_freq = gpu_freq;
1618 sandybridge_pcode_read(dev_priv,
1619 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1620 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001621 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1622 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1623 ((ia_freq >> 0) & 0xff) * 100,
1624 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001625 }
1626
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001627 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001628
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001629out:
1630 intel_runtime_pm_put(dev_priv);
1631 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001632}
1633
Chris Wilson44834a62010-08-19 16:09:23 +01001634static int i915_opregion(struct seq_file *m, void *unused)
1635{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001636 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001637 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001638 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001639 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001640 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001641 int ret;
1642
Daniel Vetter0d38f002012-04-21 22:49:10 +02001643 if (data == NULL)
1644 return -ENOMEM;
1645
Chris Wilson44834a62010-08-19 16:09:23 +01001646 ret = mutex_lock_interruptible(&dev->struct_mutex);
1647 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001648 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001649
Daniel Vetter0d38f002012-04-21 22:49:10 +02001650 if (opregion->header) {
1651 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1652 seq_write(m, data, OPREGION_SIZE);
1653 }
Chris Wilson44834a62010-08-19 16:09:23 +01001654
1655 mutex_unlock(&dev->struct_mutex);
1656
Daniel Vetter0d38f002012-04-21 22:49:10 +02001657out:
1658 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001659 return 0;
1660}
1661
Chris Wilson37811fc2010-08-25 22:45:57 +01001662static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1663{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001664 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001665 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001666 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001667 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001668
Daniel Vetter4520f532013-10-09 09:18:51 +02001669#ifdef CONFIG_DRM_I915_FBDEV
1670 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001671
1672 ifbdev = dev_priv->fbdev;
1673 fb = to_intel_framebuffer(ifbdev->helper.fb);
1674
Daniel Vetter623f9782012-12-11 16:21:38 +01001675 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001676 fb->base.width,
1677 fb->base.height,
1678 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001679 fb->base.bits_per_pixel,
1680 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001681 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001682 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001683#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001684
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001685 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001686 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001687 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001688 continue;
1689
Daniel Vetter623f9782012-12-11 16:21:38 +01001690 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001691 fb->base.width,
1692 fb->base.height,
1693 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001694 fb->base.bits_per_pixel,
1695 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001696 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001697 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001698 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001699 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001700
1701 return 0;
1702}
1703
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001704static void describe_ctx_ringbuf(struct seq_file *m,
1705 struct intel_ringbuffer *ringbuf)
1706{
1707 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1708 ringbuf->space, ringbuf->head, ringbuf->tail,
1709 ringbuf->last_retired_head);
1710}
1711
Ben Widawskye76d3632011-03-19 18:14:29 -07001712static int i915_context_status(struct seq_file *m, void *unused)
1713{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001714 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001715 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001716 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001717 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001718 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001719 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001720
Daniel Vetterf3d28872014-05-29 23:23:08 +02001721 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001722 if (ret)
1723 return ret;
1724
Daniel Vetter3e373942012-11-02 19:55:04 +01001725 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001726 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001727 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001728 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001729 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001730
Daniel Vetter3e373942012-11-02 19:55:04 +01001731 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001732 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001733 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001734 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001735 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001736
Ben Widawskya33afea2013-09-17 21:12:45 -07001737 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001738 if (!i915.enable_execlists &&
1739 ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001740 continue;
1741
Ben Widawskya33afea2013-09-17 21:12:45 -07001742 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001743 describe_ctx(m, ctx);
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001744 for_each_ring(ring, dev_priv, i) {
Ben Widawskya33afea2013-09-17 21:12:45 -07001745 if (ring->default_context == ctx)
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001746 seq_printf(m, "(default context %s) ",
1747 ring->name);
1748 }
Ben Widawskya33afea2013-09-17 21:12:45 -07001749
Oscar Mateoc9fe99b2014-07-24 17:04:46 +01001750 if (i915.enable_execlists) {
1751 seq_putc(m, '\n');
1752 for_each_ring(ring, dev_priv, i) {
1753 struct drm_i915_gem_object *ctx_obj =
1754 ctx->engine[i].state;
1755 struct intel_ringbuffer *ringbuf =
1756 ctx->engine[i].ringbuf;
1757
1758 seq_printf(m, "%s: ", ring->name);
1759 if (ctx_obj)
1760 describe_obj(m, ctx_obj);
1761 if (ringbuf)
1762 describe_ctx_ringbuf(m, ringbuf);
1763 seq_putc(m, '\n');
1764 }
1765 } else {
1766 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1767 }
1768
Ben Widawskya33afea2013-09-17 21:12:45 -07001769 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001770 }
1771
Daniel Vetterf3d28872014-05-29 23:23:08 +02001772 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001773
1774 return 0;
1775}
1776
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001777static void i915_dump_lrc_obj(struct seq_file *m,
1778 struct intel_engine_cs *ring,
1779 struct drm_i915_gem_object *ctx_obj)
1780{
1781 struct page *page;
1782 uint32_t *reg_state;
1783 int j;
1784 unsigned long ggtt_offset = 0;
1785
1786 if (ctx_obj == NULL) {
1787 seq_printf(m, "Context on %s with no gem object\n",
1788 ring->name);
1789 return;
1790 }
1791
1792 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1793 intel_execlists_ctx_id(ctx_obj));
1794
1795 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1796 seq_puts(m, "\tNot bound in GGTT\n");
1797 else
1798 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1799
1800 if (i915_gem_object_get_pages(ctx_obj)) {
1801 seq_puts(m, "\tFailed to get pages for context object\n");
1802 return;
1803 }
1804
1805 page = i915_gem_object_get_page(ctx_obj, 1);
1806 if (!WARN_ON(page == NULL)) {
1807 reg_state = kmap_atomic(page);
1808
1809 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
1810 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
1811 ggtt_offset + 4096 + (j * 4),
1812 reg_state[j], reg_state[j + 1],
1813 reg_state[j + 2], reg_state[j + 3]);
1814 }
1815 kunmap_atomic(reg_state);
1816 }
1817
1818 seq_putc(m, '\n');
1819}
1820
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01001821static int i915_dump_lrc(struct seq_file *m, void *unused)
1822{
1823 struct drm_info_node *node = (struct drm_info_node *) m->private;
1824 struct drm_device *dev = node->minor->dev;
1825 struct drm_i915_private *dev_priv = dev->dev_private;
1826 struct intel_engine_cs *ring;
1827 struct intel_context *ctx;
1828 int ret, i;
1829
1830 if (!i915.enable_execlists) {
1831 seq_printf(m, "Logical Ring Contexts are disabled\n");
1832 return 0;
1833 }
1834
1835 ret = mutex_lock_interruptible(&dev->struct_mutex);
1836 if (ret)
1837 return ret;
1838
1839 list_for_each_entry(ctx, &dev_priv->context_list, link) {
1840 for_each_ring(ring, dev_priv, i) {
Thomas Daniel064ca1d2014-12-02 13:21:18 +00001841 if (ring->default_context != ctx)
1842 i915_dump_lrc_obj(m, ring,
1843 ctx->engine[i].state);
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01001844 }
1845 }
1846
1847 mutex_unlock(&dev->struct_mutex);
1848
1849 return 0;
1850}
1851
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001852static int i915_execlists(struct seq_file *m, void *data)
1853{
1854 struct drm_info_node *node = (struct drm_info_node *)m->private;
1855 struct drm_device *dev = node->minor->dev;
1856 struct drm_i915_private *dev_priv = dev->dev_private;
1857 struct intel_engine_cs *ring;
1858 u32 status_pointer;
1859 u8 read_pointer;
1860 u8 write_pointer;
1861 u32 status;
1862 u32 ctx_id;
1863 struct list_head *cursor;
1864 int ring_id, i;
1865 int ret;
1866
1867 if (!i915.enable_execlists) {
1868 seq_puts(m, "Logical Ring Contexts are disabled\n");
1869 return 0;
1870 }
1871
1872 ret = mutex_lock_interruptible(&dev->struct_mutex);
1873 if (ret)
1874 return ret;
1875
Michel Thierryfc0412e2014-10-16 16:13:38 +01001876 intel_runtime_pm_get(dev_priv);
1877
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001878 for_each_ring(ring, dev_priv, ring_id) {
1879 struct intel_ctx_submit_request *head_req = NULL;
1880 int count = 0;
1881 unsigned long flags;
1882
1883 seq_printf(m, "%s\n", ring->name);
1884
1885 status = I915_READ(RING_EXECLIST_STATUS(ring));
1886 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
1887 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
1888 status, ctx_id);
1889
1890 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
1891 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
1892
1893 read_pointer = ring->next_context_status_buffer;
1894 write_pointer = status_pointer & 0x07;
1895 if (read_pointer > write_pointer)
1896 write_pointer += 6;
1897 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
1898 read_pointer, write_pointer);
1899
1900 for (i = 0; i < 6; i++) {
1901 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
1902 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
1903
1904 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
1905 i, status, ctx_id);
1906 }
1907
1908 spin_lock_irqsave(&ring->execlist_lock, flags);
1909 list_for_each(cursor, &ring->execlist_queue)
1910 count++;
1911 head_req = list_first_entry_or_null(&ring->execlist_queue,
1912 struct intel_ctx_submit_request, execlist_link);
1913 spin_unlock_irqrestore(&ring->execlist_lock, flags);
1914
1915 seq_printf(m, "\t%d requests in queue\n", count);
1916 if (head_req) {
1917 struct drm_i915_gem_object *ctx_obj;
1918
1919 ctx_obj = head_req->ctx->engine[ring_id].state;
1920 seq_printf(m, "\tHead request id: %u\n",
1921 intel_execlists_ctx_id(ctx_obj));
1922 seq_printf(m, "\tHead request tail: %u\n",
1923 head_req->tail);
1924 }
1925
1926 seq_putc(m, '\n');
1927 }
1928
Michel Thierryfc0412e2014-10-16 16:13:38 +01001929 intel_runtime_pm_put(dev_priv);
Oscar Mateo4ba70e42014-08-07 13:23:20 +01001930 mutex_unlock(&dev->struct_mutex);
1931
1932 return 0;
1933}
1934
Ben Widawsky6d794d42011-04-25 11:25:56 -07001935static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1936{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001937 struct drm_info_node *node = m->private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001938 struct drm_device *dev = node->minor->dev;
1939 struct drm_i915_private *dev_priv = dev->dev_private;
Deepak S43709ba2013-11-23 14:55:44 +05301940 unsigned forcewake_count = 0, fw_rendercount = 0, fw_mediacount = 0;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001941
Chris Wilson907b28c2013-07-19 20:36:52 +01001942 spin_lock_irq(&dev_priv->uncore.lock);
Deepak S43709ba2013-11-23 14:55:44 +05301943 if (IS_VALLEYVIEW(dev)) {
1944 fw_rendercount = dev_priv->uncore.fw_rendercount;
1945 fw_mediacount = dev_priv->uncore.fw_mediacount;
1946 } else
1947 forcewake_count = dev_priv->uncore.forcewake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001948 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001949
Deepak S43709ba2013-11-23 14:55:44 +05301950 if (IS_VALLEYVIEW(dev)) {
1951 seq_printf(m, "fw_rendercount = %u\n", fw_rendercount);
1952 seq_printf(m, "fw_mediacount = %u\n", fw_mediacount);
1953 } else
1954 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001955
1956 return 0;
1957}
1958
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001959static const char *swizzle_string(unsigned swizzle)
1960{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001961 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001962 case I915_BIT_6_SWIZZLE_NONE:
1963 return "none";
1964 case I915_BIT_6_SWIZZLE_9:
1965 return "bit9";
1966 case I915_BIT_6_SWIZZLE_9_10:
1967 return "bit9/bit10";
1968 case I915_BIT_6_SWIZZLE_9_11:
1969 return "bit9/bit11";
1970 case I915_BIT_6_SWIZZLE_9_10_11:
1971 return "bit9/bit10/bit11";
1972 case I915_BIT_6_SWIZZLE_9_17:
1973 return "bit9/bit17";
1974 case I915_BIT_6_SWIZZLE_9_10_17:
1975 return "bit9/bit10/bit17";
1976 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001977 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001978 }
1979
1980 return "bug";
1981}
1982
1983static int i915_swizzle_info(struct seq_file *m, void *data)
1984{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001985 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001986 struct drm_device *dev = node->minor->dev;
1987 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001988 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001989
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001990 ret = mutex_lock_interruptible(&dev->struct_mutex);
1991 if (ret)
1992 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001993 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001994
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001995 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1996 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1997 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1998 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1999
2000 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2001 seq_printf(m, "DDC = 0x%08x\n",
2002 I915_READ(DCC));
Daniel Vetter656bfa32014-11-20 09:26:30 +01002003 seq_printf(m, "DDC2 = 0x%08x\n",
2004 I915_READ(DCC2));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002005 seq_printf(m, "C0DRB3 = 0x%04x\n",
2006 I915_READ16(C0DRB3));
2007 seq_printf(m, "C1DRB3 = 0x%04x\n",
2008 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002009 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002010 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2011 I915_READ(MAD_DIMM_C0));
2012 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2013 I915_READ(MAD_DIMM_C1));
2014 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2015 I915_READ(MAD_DIMM_C2));
2016 seq_printf(m, "TILECTL = 0x%08x\n",
2017 I915_READ(TILECTL));
Robert Beckett5907f5f2014-01-23 14:23:14 +00002018 if (INTEL_INFO(dev)->gen >= 8)
Ben Widawsky9d3203e2013-11-02 21:07:14 -07002019 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2020 I915_READ(GAMTARBMODE));
2021 else
2022 seq_printf(m, "ARB_MODE = 0x%08x\n",
2023 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01002024 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2025 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002026 }
Daniel Vetter656bfa32014-11-20 09:26:30 +01002027
2028 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2029 seq_puts(m, "L-shaped memory detected\n");
2030
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002031 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01002032 mutex_unlock(&dev->struct_mutex);
2033
2034 return 0;
2035}
2036
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002037static int per_file_ctx(int id, void *ptr, void *data)
2038{
Oscar Mateo273497e2014-05-22 14:13:37 +01002039 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002040 struct seq_file *m = data;
Daniel Vetterae6c4802014-08-06 15:04:53 +02002041 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2042
2043 if (!ppgtt) {
2044 seq_printf(m, " no ppgtt for context %d\n",
2045 ctx->user_handle);
2046 return 0;
2047 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002048
Oscar Mateof83d6512014-05-22 14:13:38 +01002049 if (i915_gem_context_is_default(ctx))
2050 seq_puts(m, " default context:\n");
2051 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01002052 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002053 ppgtt->debug_dump(ppgtt, m);
2054
2055 return 0;
2056}
2057
Ben Widawsky77df6772013-11-02 21:07:30 -07002058static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002059{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002060 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002061 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07002062 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2063 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002064
Ben Widawsky77df6772013-11-02 21:07:30 -07002065 if (!ppgtt)
2066 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002067
Ben Widawsky77df6772013-11-02 21:07:30 -07002068 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08002069 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07002070 for_each_ring(ring, dev_priv, unused) {
2071 seq_printf(m, "%s\n", ring->name);
2072 for (i = 0; i < 4; i++) {
2073 u32 offset = 0x270 + i * 8;
2074 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2075 pdp <<= 32;
2076 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03002077 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07002078 }
2079 }
2080}
2081
2082static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2083{
2084 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002085 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002086 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07002087 int i;
2088
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002089 if (INTEL_INFO(dev)->gen == 6)
2090 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2091
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01002092 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002093 seq_printf(m, "%s\n", ring->name);
2094 if (INTEL_INFO(dev)->gen == 7)
2095 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2096 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2097 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2098 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2099 }
2100 if (dev_priv->mm.aliasing_ppgtt) {
2101 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2102
Damien Lespiau267f0c92013-06-24 22:59:48 +01002103 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002104 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002105
Ben Widawsky87d60b62013-12-06 14:11:29 -08002106 ppgtt->debug_dump(ppgtt, m);
Daniel Vetterae6c4802014-08-06 15:04:53 +02002107 }
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002108
2109 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2110 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002111
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002112 seq_printf(m, "proc: %s\n",
2113 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08002114 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002115 }
2116 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07002117}
2118
2119static int i915_ppgtt_info(struct seq_file *m, void *data)
2120{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002121 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002122 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002123 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07002124
2125 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2126 if (ret)
2127 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002128 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07002129
2130 if (INTEL_INFO(dev)->gen >= 8)
2131 gen8_ppgtt_info(m, dev);
2132 else if (INTEL_INFO(dev)->gen >= 6)
2133 gen6_ppgtt_info(m, dev);
2134
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002135 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01002136 mutex_unlock(&dev->struct_mutex);
2137
2138 return 0;
2139}
2140
Ben Widawsky63573eb2013-07-04 11:02:07 -07002141static int i915_llc(struct seq_file *m, void *data)
2142{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002143 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07002144 struct drm_device *dev = node->minor->dev;
2145 struct drm_i915_private *dev_priv = dev->dev_private;
2146
2147 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2148 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2149 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2150
2151 return 0;
2152}
2153
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002154static int i915_edp_psr_status(struct seq_file *m, void *data)
2155{
2156 struct drm_info_node *node = m->private;
2157 struct drm_device *dev = node->minor->dev;
2158 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002159 u32 psrperf = 0;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002160 u32 stat[3];
2161 enum pipe pipe;
Rodrigo Vivia031d702013-10-03 16:15:06 -03002162 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002163
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002164 intel_runtime_pm_get(dev_priv);
2165
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002166 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03002167 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2168 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07002169 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07002170 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002171 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2172 dev_priv->psr.busy_frontbuffer_bits);
2173 seq_printf(m, "Re-enable work scheduled: %s\n",
2174 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002175
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002176 if (HAS_PSR(dev)) {
2177 if (HAS_DDI(dev))
2178 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2179 else {
2180 for_each_pipe(dev_priv, pipe) {
2181 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2182 VLV_EDP_PSR_CURR_STATE_MASK;
2183 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2184 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2185 enabled = true;
2186 }
2187 }
2188 }
2189 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002190
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002191 if (!HAS_DDI(dev))
2192 for_each_pipe(dev_priv, pipe) {
2193 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2194 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2195 seq_printf(m, " pipe %c", pipe_name(pipe));
2196 }
2197 seq_puts(m, "\n");
2198
2199 /* CHV PSR has no kind of performance counter */
2200 if (HAS_PSR(dev) && HAS_DDI(dev)) {
Rodrigo Vivia031d702013-10-03 16:15:06 -03002201 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2202 EDP_PSR_PERF_CNT_MASK;
Rodrigo Vivia6cbdb82014-11-14 08:52:40 -08002203
2204 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2205 }
Daniel Vetterfa128fa2014-07-11 10:30:17 -07002206 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002207
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02002208 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03002209 return 0;
2210}
2211
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002212static int i915_sink_crc(struct seq_file *m, void *data)
2213{
2214 struct drm_info_node *node = m->private;
2215 struct drm_device *dev = node->minor->dev;
2216 struct intel_encoder *encoder;
2217 struct intel_connector *connector;
2218 struct intel_dp *intel_dp = NULL;
2219 int ret;
2220 u8 crc[6];
2221
2222 drm_modeset_lock_all(dev);
2223 list_for_each_entry(connector, &dev->mode_config.connector_list,
2224 base.head) {
2225
2226 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2227 continue;
2228
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002229 if (!connector->base.encoder)
2230 continue;
2231
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002232 encoder = to_intel_encoder(connector->base.encoder);
2233 if (encoder->type != INTEL_OUTPUT_EDP)
2234 continue;
2235
2236 intel_dp = enc_to_intel_dp(&encoder->base);
2237
2238 ret = intel_dp_sink_crc(intel_dp, crc);
2239 if (ret)
2240 goto out;
2241
2242 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2243 crc[0], crc[1], crc[2],
2244 crc[3], crc[4], crc[5]);
2245 goto out;
2246 }
2247 ret = -ENODEV;
2248out:
2249 drm_modeset_unlock_all(dev);
2250 return ret;
2251}
2252
Jesse Barnesec013e72013-08-20 10:29:23 +01002253static int i915_energy_uJ(struct seq_file *m, void *data)
2254{
2255 struct drm_info_node *node = m->private;
2256 struct drm_device *dev = node->minor->dev;
2257 struct drm_i915_private *dev_priv = dev->dev_private;
2258 u64 power;
2259 u32 units;
2260
2261 if (INTEL_INFO(dev)->gen < 6)
2262 return -ENODEV;
2263
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002264 intel_runtime_pm_get(dev_priv);
2265
Jesse Barnesec013e72013-08-20 10:29:23 +01002266 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2267 power = (power & 0x1f00) >> 8;
2268 units = 1000000 / (1 << power); /* convert to uJ */
2269 power = I915_READ(MCH_SECP_NRG_STTS);
2270 power *= units;
2271
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002272 intel_runtime_pm_put(dev_priv);
2273
Jesse Barnesec013e72013-08-20 10:29:23 +01002274 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002275
2276 return 0;
2277}
2278
2279static int i915_pc8_status(struct seq_file *m, void *unused)
2280{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002281 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002282 struct drm_device *dev = node->minor->dev;
2283 struct drm_i915_private *dev_priv = dev->dev_private;
2284
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002285 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002286 seq_puts(m, "not supported\n");
2287 return 0;
2288 }
2289
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002290 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002291 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002292 yesno(!intel_irqs_enabled(dev_priv)));
Paulo Zanoni371db662013-08-19 13:18:10 -03002293
Jesse Barnesec013e72013-08-20 10:29:23 +01002294 return 0;
2295}
2296
Imre Deak1da51582013-11-25 17:15:35 +02002297static const char *power_domain_str(enum intel_display_power_domain domain)
2298{
2299 switch (domain) {
2300 case POWER_DOMAIN_PIPE_A:
2301 return "PIPE_A";
2302 case POWER_DOMAIN_PIPE_B:
2303 return "PIPE_B";
2304 case POWER_DOMAIN_PIPE_C:
2305 return "PIPE_C";
2306 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2307 return "PIPE_A_PANEL_FITTER";
2308 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2309 return "PIPE_B_PANEL_FITTER";
2310 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2311 return "PIPE_C_PANEL_FITTER";
2312 case POWER_DOMAIN_TRANSCODER_A:
2313 return "TRANSCODER_A";
2314 case POWER_DOMAIN_TRANSCODER_B:
2315 return "TRANSCODER_B";
2316 case POWER_DOMAIN_TRANSCODER_C:
2317 return "TRANSCODER_C";
2318 case POWER_DOMAIN_TRANSCODER_EDP:
2319 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002320 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2321 return "PORT_DDI_A_2_LANES";
2322 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2323 return "PORT_DDI_A_4_LANES";
2324 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2325 return "PORT_DDI_B_2_LANES";
2326 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2327 return "PORT_DDI_B_4_LANES";
2328 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2329 return "PORT_DDI_C_2_LANES";
2330 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2331 return "PORT_DDI_C_4_LANES";
2332 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2333 return "PORT_DDI_D_2_LANES";
2334 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2335 return "PORT_DDI_D_4_LANES";
2336 case POWER_DOMAIN_PORT_DSI:
2337 return "PORT_DSI";
2338 case POWER_DOMAIN_PORT_CRT:
2339 return "PORT_CRT";
2340 case POWER_DOMAIN_PORT_OTHER:
2341 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002342 case POWER_DOMAIN_VGA:
2343 return "VGA";
2344 case POWER_DOMAIN_AUDIO:
2345 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002346 case POWER_DOMAIN_PLLS:
2347 return "PLLS";
Imre Deak1da51582013-11-25 17:15:35 +02002348 case POWER_DOMAIN_INIT:
2349 return "INIT";
2350 default:
Daniel Vetter5f77eeb2014-12-08 16:40:10 +01002351 MISSING_CASE(domain);
Imre Deak1da51582013-11-25 17:15:35 +02002352 return "?";
2353 }
2354}
2355
2356static int i915_power_domain_info(struct seq_file *m, void *unused)
2357{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002358 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002359 struct drm_device *dev = node->minor->dev;
2360 struct drm_i915_private *dev_priv = dev->dev_private;
2361 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2362 int i;
2363
2364 mutex_lock(&power_domains->lock);
2365
2366 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2367 for (i = 0; i < power_domains->power_well_count; i++) {
2368 struct i915_power_well *power_well;
2369 enum intel_display_power_domain power_domain;
2370
2371 power_well = &power_domains->power_wells[i];
2372 seq_printf(m, "%-25s %d\n", power_well->name,
2373 power_well->count);
2374
2375 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2376 power_domain++) {
2377 if (!(BIT(power_domain) & power_well->domains))
2378 continue;
2379
2380 seq_printf(m, " %-23s %d\n",
2381 power_domain_str(power_domain),
2382 power_domains->domain_use_count[power_domain]);
2383 }
2384 }
2385
2386 mutex_unlock(&power_domains->lock);
2387
2388 return 0;
2389}
2390
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002391static void intel_seq_print_mode(struct seq_file *m, int tabs,
2392 struct drm_display_mode *mode)
2393{
2394 int i;
2395
2396 for (i = 0; i < tabs; i++)
2397 seq_putc(m, '\t');
2398
2399 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",
2400 mode->base.id, mode->name,
2401 mode->vrefresh, mode->clock,
2402 mode->hdisplay, mode->hsync_start,
2403 mode->hsync_end, mode->htotal,
2404 mode->vdisplay, mode->vsync_start,
2405 mode->vsync_end, mode->vtotal,
2406 mode->type, mode->flags);
2407}
2408
2409static void intel_encoder_info(struct seq_file *m,
2410 struct intel_crtc *intel_crtc,
2411 struct intel_encoder *intel_encoder)
2412{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002413 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002414 struct drm_device *dev = node->minor->dev;
2415 struct drm_crtc *crtc = &intel_crtc->base;
2416 struct intel_connector *intel_connector;
2417 struct drm_encoder *encoder;
2418
2419 encoder = &intel_encoder->base;
2420 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002421 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002422 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2423 struct drm_connector *connector = &intel_connector->base;
2424 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2425 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002426 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002427 drm_get_connector_status_name(connector->status));
2428 if (connector->status == connector_status_connected) {
2429 struct drm_display_mode *mode = &crtc->mode;
2430 seq_printf(m, ", mode:\n");
2431 intel_seq_print_mode(m, 2, mode);
2432 } else {
2433 seq_putc(m, '\n');
2434 }
2435 }
2436}
2437
2438static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2439{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002440 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002441 struct drm_device *dev = node->minor->dev;
2442 struct drm_crtc *crtc = &intel_crtc->base;
2443 struct intel_encoder *intel_encoder;
2444
Matt Roper5aa8a932014-06-16 10:12:55 -07002445 if (crtc->primary->fb)
2446 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2447 crtc->primary->fb->base.id, crtc->x, crtc->y,
2448 crtc->primary->fb->width, crtc->primary->fb->height);
2449 else
2450 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002451 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2452 intel_encoder_info(m, intel_crtc, intel_encoder);
2453}
2454
2455static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2456{
2457 struct drm_display_mode *mode = panel->fixed_mode;
2458
2459 seq_printf(m, "\tfixed mode:\n");
2460 intel_seq_print_mode(m, 2, mode);
2461}
2462
2463static void intel_dp_info(struct seq_file *m,
2464 struct intel_connector *intel_connector)
2465{
2466 struct intel_encoder *intel_encoder = intel_connector->encoder;
2467 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2468
2469 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2470 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2471 "no");
2472 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2473 intel_panel_info(m, &intel_connector->panel);
2474}
2475
2476static void intel_hdmi_info(struct seq_file *m,
2477 struct intel_connector *intel_connector)
2478{
2479 struct intel_encoder *intel_encoder = intel_connector->encoder;
2480 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2481
2482 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2483 "no");
2484}
2485
2486static void intel_lvds_info(struct seq_file *m,
2487 struct intel_connector *intel_connector)
2488{
2489 intel_panel_info(m, &intel_connector->panel);
2490}
2491
2492static void intel_connector_info(struct seq_file *m,
2493 struct drm_connector *connector)
2494{
2495 struct intel_connector *intel_connector = to_intel_connector(connector);
2496 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002497 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002498
2499 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002500 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002501 drm_get_connector_status_name(connector->status));
2502 if (connector->status == connector_status_connected) {
2503 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2504 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2505 connector->display_info.width_mm,
2506 connector->display_info.height_mm);
2507 seq_printf(m, "\tsubpixel order: %s\n",
2508 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2509 seq_printf(m, "\tCEA rev: %d\n",
2510 connector->display_info.cea_rev);
2511 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002512 if (intel_encoder) {
2513 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2514 intel_encoder->type == INTEL_OUTPUT_EDP)
2515 intel_dp_info(m, intel_connector);
2516 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2517 intel_hdmi_info(m, intel_connector);
2518 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2519 intel_lvds_info(m, intel_connector);
2520 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002521
Jesse Barnesf103fc72014-02-20 12:39:57 -08002522 seq_printf(m, "\tmodes:\n");
2523 list_for_each_entry(mode, &connector->modes, head)
2524 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002525}
2526
Chris Wilson065f2ec2014-03-12 09:13:13 +00002527static bool cursor_active(struct drm_device *dev, int pipe)
2528{
2529 struct drm_i915_private *dev_priv = dev->dev_private;
2530 u32 state;
2531
2532 if (IS_845G(dev) || IS_I865G(dev))
2533 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002534 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002535 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002536
2537 return state;
2538}
2539
2540static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2541{
2542 struct drm_i915_private *dev_priv = dev->dev_private;
2543 u32 pos;
2544
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002545 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002546
2547 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2548 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2549 *x = -*x;
2550
2551 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2552 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2553 *y = -*y;
2554
2555 return cursor_active(dev, pipe);
2556}
2557
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002558static int i915_display_info(struct seq_file *m, void *unused)
2559{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002560 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002561 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002562 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002563 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002564 struct drm_connector *connector;
2565
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002566 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002567 drm_modeset_lock_all(dev);
2568 seq_printf(m, "CRTC info\n");
2569 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002570 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002571 bool active;
2572 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002573
Chris Wilson57127ef2014-07-04 08:20:11 +01002574 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002575 crtc->base.base.id, pipe_name(crtc->pipe),
Chris Wilson57127ef2014-07-04 08:20:11 +01002576 yesno(crtc->active), crtc->config.pipe_src_w, crtc->config.pipe_src_h);
Paulo Zanonia23dc652014-04-01 14:55:11 -03002577 if (crtc->active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002578 intel_crtc_info(m, crtc);
2579
Paulo Zanonia23dc652014-04-01 14:55:11 -03002580 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002581 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 +03002582 yesno(crtc->cursor_base),
Chris Wilson57127ef2014-07-04 08:20:11 +01002583 x, y, crtc->cursor_width, crtc->cursor_height,
2584 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002585 }
Daniel Vettercace8412014-05-22 17:56:31 +02002586
2587 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2588 yesno(!crtc->cpu_fifo_underrun_disabled),
2589 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002590 }
2591
2592 seq_printf(m, "\n");
2593 seq_printf(m, "Connector info\n");
2594 seq_printf(m, "--------------\n");
2595 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2596 intel_connector_info(m, connector);
2597 }
2598 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002599 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002600
2601 return 0;
2602}
2603
Ben Widawskye04934c2014-06-30 09:53:42 -07002604static int i915_semaphore_status(struct seq_file *m, void *unused)
2605{
2606 struct drm_info_node *node = (struct drm_info_node *) m->private;
2607 struct drm_device *dev = node->minor->dev;
2608 struct drm_i915_private *dev_priv = dev->dev_private;
2609 struct intel_engine_cs *ring;
2610 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2611 int i, j, ret;
2612
2613 if (!i915_semaphore_is_enabled(dev)) {
2614 seq_puts(m, "Semaphores are disabled\n");
2615 return 0;
2616 }
2617
2618 ret = mutex_lock_interruptible(&dev->struct_mutex);
2619 if (ret)
2620 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002621 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002622
2623 if (IS_BROADWELL(dev)) {
2624 struct page *page;
2625 uint64_t *seqno;
2626
2627 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2628
2629 seqno = (uint64_t *)kmap_atomic(page);
2630 for_each_ring(ring, dev_priv, i) {
2631 uint64_t offset;
2632
2633 seq_printf(m, "%s\n", ring->name);
2634
2635 seq_puts(m, " Last signal:");
2636 for (j = 0; j < num_rings; j++) {
2637 offset = i * I915_NUM_RINGS + j;
2638 seq_printf(m, "0x%08llx (0x%02llx) ",
2639 seqno[offset], offset * 8);
2640 }
2641 seq_putc(m, '\n');
2642
2643 seq_puts(m, " Last wait: ");
2644 for (j = 0; j < num_rings; j++) {
2645 offset = i + (j * I915_NUM_RINGS);
2646 seq_printf(m, "0x%08llx (0x%02llx) ",
2647 seqno[offset], offset * 8);
2648 }
2649 seq_putc(m, '\n');
2650
2651 }
2652 kunmap_atomic(seqno);
2653 } else {
2654 seq_puts(m, " Last signal:");
2655 for_each_ring(ring, dev_priv, i)
2656 for (j = 0; j < num_rings; j++)
2657 seq_printf(m, "0x%08x\n",
2658 I915_READ(ring->semaphore.mbox.signal[j]));
2659 seq_putc(m, '\n');
2660 }
2661
2662 seq_puts(m, "\nSync seqno:\n");
2663 for_each_ring(ring, dev_priv, i) {
2664 for (j = 0; j < num_rings; j++) {
2665 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2666 }
2667 seq_putc(m, '\n');
2668 }
2669 seq_putc(m, '\n');
2670
Paulo Zanoni03872062014-07-09 14:31:57 -03002671 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002672 mutex_unlock(&dev->struct_mutex);
2673 return 0;
2674}
2675
Daniel Vetter728e29d2014-06-25 22:01:53 +03002676static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2677{
2678 struct drm_info_node *node = (struct drm_info_node *) m->private;
2679 struct drm_device *dev = node->minor->dev;
2680 struct drm_i915_private *dev_priv = dev->dev_private;
2681 int i;
2682
2683 drm_modeset_lock_all(dev);
2684 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2685 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2686
2687 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
Ander Conselvan de Oliveira1e6f2dd2014-10-29 11:32:31 +02002688 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002689 pll->config.crtc_mask, pll->active, yesno(pll->on));
Daniel Vetter728e29d2014-06-25 22:01:53 +03002690 seq_printf(m, " tracked hardware state:\n");
Ander Conselvan de Oliveira3e369b72014-10-29 11:32:32 +02002691 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2692 seq_printf(m, " dpll_md: 0x%08x\n",
2693 pll->config.hw_state.dpll_md);
2694 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2695 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2696 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002697 }
2698 drm_modeset_unlock_all(dev);
2699
2700 return 0;
2701}
2702
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01002703static int i915_wa_registers(struct seq_file *m, void *unused)
Arun Siluvery888b5992014-08-26 14:44:51 +01002704{
2705 int i;
2706 int ret;
2707 struct drm_info_node *node = (struct drm_info_node *) m->private;
2708 struct drm_device *dev = node->minor->dev;
2709 struct drm_i915_private *dev_priv = dev->dev_private;
2710
Arun Siluvery888b5992014-08-26 14:44:51 +01002711 ret = mutex_lock_interruptible(&dev->struct_mutex);
2712 if (ret)
2713 return ret;
2714
2715 intel_runtime_pm_get(dev_priv);
2716
Mika Kuoppala72253422014-10-07 17:21:26 +03002717 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
2718 for (i = 0; i < dev_priv->workarounds.count; ++i) {
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002719 u32 addr, mask, value, read;
2720 bool ok;
Arun Siluvery888b5992014-08-26 14:44:51 +01002721
Mika Kuoppala72253422014-10-07 17:21:26 +03002722 addr = dev_priv->workarounds.reg[i].addr;
2723 mask = dev_priv->workarounds.reg[i].mask;
Mika Kuoppala2fa60f62014-10-07 17:21:27 +03002724 value = dev_priv->workarounds.reg[i].value;
2725 read = I915_READ(addr);
2726 ok = (value & mask) == (read & mask);
2727 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
2728 addr, value, mask, read, ok ? "OK" : "FAIL");
Arun Siluvery888b5992014-08-26 14:44:51 +01002729 }
2730
2731 intel_runtime_pm_put(dev_priv);
2732 mutex_unlock(&dev->struct_mutex);
2733
2734 return 0;
2735}
2736
Damien Lespiauc5511e42014-11-04 17:06:51 +00002737static int i915_ddb_info(struct seq_file *m, void *unused)
2738{
2739 struct drm_info_node *node = m->private;
2740 struct drm_device *dev = node->minor->dev;
2741 struct drm_i915_private *dev_priv = dev->dev_private;
2742 struct skl_ddb_allocation *ddb;
2743 struct skl_ddb_entry *entry;
2744 enum pipe pipe;
2745 int plane;
2746
Damien Lespiau2fcffe12014-12-03 17:33:24 +00002747 if (INTEL_INFO(dev)->gen < 9)
2748 return 0;
2749
Damien Lespiauc5511e42014-11-04 17:06:51 +00002750 drm_modeset_lock_all(dev);
2751
2752 ddb = &dev_priv->wm.skl_hw.ddb;
2753
2754 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
2755
2756 for_each_pipe(dev_priv, pipe) {
2757 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
2758
2759 for_each_plane(pipe, plane) {
2760 entry = &ddb->plane[pipe][plane];
2761 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
2762 entry->start, entry->end,
2763 skl_ddb_entry_size(entry));
2764 }
2765
2766 entry = &ddb->cursor[pipe];
2767 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
2768 entry->end, skl_ddb_entry_size(entry));
2769 }
2770
2771 drm_modeset_unlock_all(dev);
2772
2773 return 0;
2774}
2775
Damien Lespiau07144422013-10-15 18:55:40 +01002776struct pipe_crc_info {
2777 const char *name;
2778 struct drm_device *dev;
2779 enum pipe pipe;
2780};
2781
Dave Airlie11bed952014-05-12 15:22:27 +10002782static int i915_dp_mst_info(struct seq_file *m, void *unused)
2783{
2784 struct drm_info_node *node = (struct drm_info_node *) m->private;
2785 struct drm_device *dev = node->minor->dev;
2786 struct drm_encoder *encoder;
2787 struct intel_encoder *intel_encoder;
2788 struct intel_digital_port *intel_dig_port;
2789 drm_modeset_lock_all(dev);
2790 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2791 intel_encoder = to_intel_encoder(encoder);
2792 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
2793 continue;
2794 intel_dig_port = enc_to_dig_port(encoder);
2795 if (!intel_dig_port->dp.can_mst)
2796 continue;
2797
2798 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
2799 }
2800 drm_modeset_unlock_all(dev);
2801 return 0;
2802}
2803
Damien Lespiau07144422013-10-15 18:55:40 +01002804static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01002805{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002806 struct pipe_crc_info *info = inode->i_private;
2807 struct drm_i915_private *dev_priv = info->dev->dev_private;
2808 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2809
Daniel Vetter7eb1c492013-11-14 11:30:43 +01002810 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
2811 return -ENODEV;
2812
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002813 spin_lock_irq(&pipe_crc->lock);
2814
2815 if (pipe_crc->opened) {
2816 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002817 return -EBUSY; /* already open */
2818 }
2819
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002820 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01002821 filep->private_data = inode->i_private;
2822
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002823 spin_unlock_irq(&pipe_crc->lock);
2824
Damien Lespiau07144422013-10-15 18:55:40 +01002825 return 0;
2826}
2827
2828static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
2829{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002830 struct pipe_crc_info *info = inode->i_private;
2831 struct drm_i915_private *dev_priv = info->dev->dev_private;
2832 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2833
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002834 spin_lock_irq(&pipe_crc->lock);
2835 pipe_crc->opened = false;
2836 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002837
Damien Lespiau07144422013-10-15 18:55:40 +01002838 return 0;
2839}
2840
2841/* (6 fields, 8 chars each, space separated (5) + '\n') */
2842#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
2843/* account for \'0' */
2844#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
2845
2846static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
2847{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002848 assert_spin_locked(&pipe_crc->lock);
2849 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2850 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01002851}
Shuang He8bf1e9f2013-10-15 18:55:27 +01002852
Damien Lespiau07144422013-10-15 18:55:40 +01002853static ssize_t
2854i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
2855 loff_t *pos)
2856{
2857 struct pipe_crc_info *info = filep->private_data;
2858 struct drm_device *dev = info->dev;
2859 struct drm_i915_private *dev_priv = dev->dev_private;
2860 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2861 char buf[PIPE_CRC_BUFFER_LEN];
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002862 int n_entries;
Damien Lespiau07144422013-10-15 18:55:40 +01002863 ssize_t bytes_read;
2864
2865 /*
2866 * Don't allow user space to provide buffers not big enough to hold
2867 * a line of data.
2868 */
2869 if (count < PIPE_CRC_LINE_LEN)
2870 return -EINVAL;
2871
2872 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2873 return 0;
2874
2875 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002876 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002877 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002878 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002879
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002880 if (filep->f_flags & O_NONBLOCK) {
2881 spin_unlock_irq(&pipe_crc->lock);
2882 return -EAGAIN;
2883 }
2884
2885 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2886 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2887 if (ret) {
2888 spin_unlock_irq(&pipe_crc->lock);
2889 return ret;
2890 }
Damien Lespiau07144422013-10-15 18:55:40 +01002891 }
2892
2893 /* We now have one or more entries to read */
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002894 n_entries = count / PIPE_CRC_LINE_LEN;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002895
Damien Lespiau07144422013-10-15 18:55:40 +01002896 bytes_read = 0;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002897 while (n_entries > 0) {
2898 struct intel_pipe_crc_entry *entry =
2899 &pipe_crc->entries[pipe_crc->tail];
Damien Lespiau07144422013-10-15 18:55:40 +01002900 int ret;
2901
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002902 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2903 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
2904 break;
2905
2906 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
2907 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
2908
Damien Lespiau07144422013-10-15 18:55:40 +01002909 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
2910 "%8u %8x %8x %8x %8x %8x\n",
2911 entry->frame, entry->crc[0],
2912 entry->crc[1], entry->crc[2],
2913 entry->crc[3], entry->crc[4]);
2914
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002915 spin_unlock_irq(&pipe_crc->lock);
2916
2917 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
Damien Lespiau07144422013-10-15 18:55:40 +01002918 if (ret == PIPE_CRC_LINE_LEN)
2919 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01002920
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002921 user_buf += PIPE_CRC_LINE_LEN;
2922 n_entries--;
Shuang He8bf1e9f2013-10-15 18:55:27 +01002923
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02002924 spin_lock_irq(&pipe_crc->lock);
2925 }
2926
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002927 spin_unlock_irq(&pipe_crc->lock);
2928
Damien Lespiau07144422013-10-15 18:55:40 +01002929 return bytes_read;
2930}
2931
2932static const struct file_operations i915_pipe_crc_fops = {
2933 .owner = THIS_MODULE,
2934 .open = i915_pipe_crc_open,
2935 .read = i915_pipe_crc_read,
2936 .release = i915_pipe_crc_release,
2937};
2938
2939static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
2940 {
2941 .name = "i915_pipe_A_crc",
2942 .pipe = PIPE_A,
2943 },
2944 {
2945 .name = "i915_pipe_B_crc",
2946 .pipe = PIPE_B,
2947 },
2948 {
2949 .name = "i915_pipe_C_crc",
2950 .pipe = PIPE_C,
2951 },
2952};
2953
2954static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
2955 enum pipe pipe)
2956{
2957 struct drm_device *dev = minor->dev;
2958 struct dentry *ent;
2959 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
2960
2961 info->dev = dev;
2962 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
2963 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08002964 if (!ent)
2965 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01002966
2967 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002968}
2969
Daniel Vettere8dfcf72013-10-16 11:51:54 +02002970static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02002971 "none",
2972 "plane1",
2973 "plane2",
2974 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002975 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02002976 "TV",
2977 "DP-B",
2978 "DP-C",
2979 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01002980 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02002981};
2982
2983static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
2984{
2985 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
2986 return pipe_crc_sources[source];
2987}
2988
Damien Lespiaubd9db022013-10-15 18:55:36 +01002989static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02002990{
2991 struct drm_device *dev = m->private;
2992 struct drm_i915_private *dev_priv = dev->dev_private;
2993 int i;
2994
2995 for (i = 0; i < I915_MAX_PIPES; i++)
2996 seq_printf(m, "%c %s\n", pipe_name(i),
2997 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
2998
2999 return 0;
3000}
3001
Damien Lespiaubd9db022013-10-15 18:55:36 +01003002static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02003003{
3004 struct drm_device *dev = inode->i_private;
3005
Damien Lespiaubd9db022013-10-15 18:55:36 +01003006 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02003007}
3008
Daniel Vetter46a19182013-11-01 10:50:20 +01003009static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02003010 uint32_t *val)
3011{
Daniel Vetter46a19182013-11-01 10:50:20 +01003012 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3013 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3014
3015 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02003016 case INTEL_PIPE_CRC_SOURCE_PIPE:
3017 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3018 break;
3019 case INTEL_PIPE_CRC_SOURCE_NONE:
3020 *val = 0;
3021 break;
3022 default:
3023 return -EINVAL;
3024 }
3025
3026 return 0;
3027}
3028
Daniel Vetter46a19182013-11-01 10:50:20 +01003029static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3030 enum intel_pipe_crc_source *source)
3031{
3032 struct intel_encoder *encoder;
3033 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01003034 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01003035 int ret = 0;
3036
3037 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3038
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003039 drm_modeset_lock_all(dev);
Damien Lespiaub2784e12014-08-05 11:29:37 +01003040 for_each_intel_encoder(dev, encoder) {
Daniel Vetter46a19182013-11-01 10:50:20 +01003041 if (!encoder->base.crtc)
3042 continue;
3043
3044 crtc = to_intel_crtc(encoder->base.crtc);
3045
3046 if (crtc->pipe != pipe)
3047 continue;
3048
3049 switch (encoder->type) {
3050 case INTEL_OUTPUT_TVOUT:
3051 *source = INTEL_PIPE_CRC_SOURCE_TV;
3052 break;
3053 case INTEL_OUTPUT_DISPLAYPORT:
3054 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01003055 dig_port = enc_to_dig_port(&encoder->base);
3056 switch (dig_port->port) {
3057 case PORT_B:
3058 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3059 break;
3060 case PORT_C:
3061 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3062 break;
3063 case PORT_D:
3064 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3065 break;
3066 default:
3067 WARN(1, "nonexisting DP port %c\n",
3068 port_name(dig_port->port));
3069 break;
3070 }
Daniel Vetter46a19182013-11-01 10:50:20 +01003071 break;
Paulo Zanoni6847d71b2014-10-27 17:47:52 -02003072 default:
3073 break;
Daniel Vetter46a19182013-11-01 10:50:20 +01003074 }
3075 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02003076 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01003077
3078 return ret;
3079}
3080
3081static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3082 enum pipe pipe,
3083 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02003084 uint32_t *val)
3085{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003086 struct drm_i915_private *dev_priv = dev->dev_private;
3087 bool need_stable_symbols = false;
3088
Daniel Vetter46a19182013-11-01 10:50:20 +01003089 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3090 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3091 if (ret)
3092 return ret;
3093 }
3094
3095 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02003096 case INTEL_PIPE_CRC_SOURCE_PIPE:
3097 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3098 break;
3099 case INTEL_PIPE_CRC_SOURCE_DP_B:
3100 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003101 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003102 break;
3103 case INTEL_PIPE_CRC_SOURCE_DP_C:
3104 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003105 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003106 break;
Ville Syrjälä2be57922014-12-09 21:28:29 +02003107 case INTEL_PIPE_CRC_SOURCE_DP_D:
3108 if (!IS_CHERRYVIEW(dev))
3109 return -EINVAL;
3110 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3111 need_stable_symbols = true;
3112 break;
Daniel Vetter7ac01292013-10-18 16:37:06 +02003113 case INTEL_PIPE_CRC_SOURCE_NONE:
3114 *val = 0;
3115 break;
3116 default:
3117 return -EINVAL;
3118 }
3119
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003120 /*
3121 * When the pipe CRC tap point is after the transcoders we need
3122 * to tweak symbol-level features to produce a deterministic series of
3123 * symbols for a given frame. We need to reset those features only once
3124 * a frame (instead of every nth symbol):
3125 * - DC-balance: used to ensure a better clock recovery from the data
3126 * link (SDVO)
3127 * - DisplayPort scrambling: used for EMI reduction
3128 */
3129 if (need_stable_symbols) {
3130 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3131
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003132 tmp |= DC_BALANCE_RESET_VLV;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003133 switch (pipe) {
3134 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003135 tmp |= PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003136 break;
3137 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003138 tmp |= PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003139 break;
3140 case PIPE_C:
3141 tmp |= PIPE_C_SCRAMBLE_RESET;
3142 break;
3143 default:
3144 return -EINVAL;
3145 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003146 I915_WRITE(PORT_DFT2_G4X, tmp);
3147 }
3148
Daniel Vetter7ac01292013-10-18 16:37:06 +02003149 return 0;
3150}
3151
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003152static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01003153 enum pipe pipe,
3154 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003155 uint32_t *val)
3156{
Daniel Vetter84093602013-11-01 10:50:21 +01003157 struct drm_i915_private *dev_priv = dev->dev_private;
3158 bool need_stable_symbols = false;
3159
Daniel Vetter46a19182013-11-01 10:50:20 +01003160 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3161 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3162 if (ret)
3163 return ret;
3164 }
3165
3166 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003167 case INTEL_PIPE_CRC_SOURCE_PIPE:
3168 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3169 break;
3170 case INTEL_PIPE_CRC_SOURCE_TV:
3171 if (!SUPPORTS_TV(dev))
3172 return -EINVAL;
3173 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3174 break;
3175 case INTEL_PIPE_CRC_SOURCE_DP_B:
3176 if (!IS_G4X(dev))
3177 return -EINVAL;
3178 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003179 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003180 break;
3181 case INTEL_PIPE_CRC_SOURCE_DP_C:
3182 if (!IS_G4X(dev))
3183 return -EINVAL;
3184 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003185 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003186 break;
3187 case INTEL_PIPE_CRC_SOURCE_DP_D:
3188 if (!IS_G4X(dev))
3189 return -EINVAL;
3190 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01003191 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003192 break;
3193 case INTEL_PIPE_CRC_SOURCE_NONE:
3194 *val = 0;
3195 break;
3196 default:
3197 return -EINVAL;
3198 }
3199
Daniel Vetter84093602013-11-01 10:50:21 +01003200 /*
3201 * When the pipe CRC tap point is after the transcoders we need
3202 * to tweak symbol-level features to produce a deterministic series of
3203 * symbols for a given frame. We need to reset those features only once
3204 * a frame (instead of every nth symbol):
3205 * - DC-balance: used to ensure a better clock recovery from the data
3206 * link (SDVO)
3207 * - DisplayPort scrambling: used for EMI reduction
3208 */
3209 if (need_stable_symbols) {
3210 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3211
3212 WARN_ON(!IS_G4X(dev));
3213
3214 I915_WRITE(PORT_DFT_I9XX,
3215 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3216
3217 if (pipe == PIPE_A)
3218 tmp |= PIPE_A_SCRAMBLE_RESET;
3219 else
3220 tmp |= PIPE_B_SCRAMBLE_RESET;
3221
3222 I915_WRITE(PORT_DFT2_G4X, tmp);
3223 }
3224
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003225 return 0;
3226}
3227
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003228static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3229 enum pipe pipe)
3230{
3231 struct drm_i915_private *dev_priv = dev->dev_private;
3232 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3233
Ville Syrjäläeb736672014-12-09 21:28:28 +02003234 switch (pipe) {
3235 case PIPE_A:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003236 tmp &= ~PIPE_A_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003237 break;
3238 case PIPE_B:
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003239 tmp &= ~PIPE_B_SCRAMBLE_RESET;
Ville Syrjäläeb736672014-12-09 21:28:28 +02003240 break;
3241 case PIPE_C:
3242 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3243 break;
3244 default:
3245 return;
3246 }
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003247 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3248 tmp &= ~DC_BALANCE_RESET_VLV;
3249 I915_WRITE(PORT_DFT2_G4X, tmp);
3250
3251}
3252
Daniel Vetter84093602013-11-01 10:50:21 +01003253static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3254 enum pipe pipe)
3255{
3256 struct drm_i915_private *dev_priv = dev->dev_private;
3257 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3258
3259 if (pipe == PIPE_A)
3260 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3261 else
3262 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3263 I915_WRITE(PORT_DFT2_G4X, tmp);
3264
3265 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3266 I915_WRITE(PORT_DFT_I9XX,
3267 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3268 }
3269}
3270
Daniel Vetter46a19182013-11-01 10:50:20 +01003271static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003272 uint32_t *val)
3273{
Daniel Vetter46a19182013-11-01 10:50:20 +01003274 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3275 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3276
3277 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003278 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3279 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3280 break;
3281 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3282 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3283 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003284 case INTEL_PIPE_CRC_SOURCE_PIPE:
3285 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3286 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003287 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003288 *val = 0;
3289 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003290 default:
3291 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003292 }
3293
3294 return 0;
3295}
3296
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003297static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3298{
3299 struct drm_i915_private *dev_priv = dev->dev_private;
3300 struct intel_crtc *crtc =
3301 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3302
3303 drm_modeset_lock_all(dev);
3304 /*
3305 * If we use the eDP transcoder we need to make sure that we don't
3306 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3307 * relevant on hsw with pipe A when using the always-on power well
3308 * routing.
3309 */
3310 if (crtc->config.cpu_transcoder == TRANSCODER_EDP &&
3311 !crtc->config.pch_pfit.enabled) {
3312 crtc->config.pch_pfit.force_thru = true;
3313
3314 intel_display_power_get(dev_priv,
3315 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3316
3317 dev_priv->display.crtc_disable(&crtc->base);
3318 dev_priv->display.crtc_enable(&crtc->base);
3319 }
3320 drm_modeset_unlock_all(dev);
3321}
3322
3323static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3324{
3325 struct drm_i915_private *dev_priv = dev->dev_private;
3326 struct intel_crtc *crtc =
3327 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
3328
3329 drm_modeset_lock_all(dev);
3330 /*
3331 * If we use the eDP transcoder we need to make sure that we don't
3332 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3333 * relevant on hsw with pipe A when using the always-on power well
3334 * routing.
3335 */
3336 if (crtc->config.pch_pfit.force_thru) {
3337 crtc->config.pch_pfit.force_thru = false;
3338
3339 dev_priv->display.crtc_disable(&crtc->base);
3340 dev_priv->display.crtc_enable(&crtc->base);
3341
3342 intel_display_power_put(dev_priv,
3343 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3344 }
3345 drm_modeset_unlock_all(dev);
3346}
3347
3348static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3349 enum pipe pipe,
3350 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003351 uint32_t *val)
3352{
Daniel Vetter46a19182013-11-01 10:50:20 +01003353 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3354 *source = INTEL_PIPE_CRC_SOURCE_PF;
3355
3356 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003357 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3358 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3359 break;
3360 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3361 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3362 break;
3363 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003364 if (IS_HASWELL(dev) && pipe == PIPE_A)
3365 hsw_trans_edp_pipe_A_crc_wa(dev);
3366
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003367 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3368 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003369 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003370 *val = 0;
3371 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003372 default:
3373 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003374 }
3375
3376 return 0;
3377}
3378
Daniel Vetter926321d2013-10-16 13:30:34 +02003379static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3380 enum intel_pipe_crc_source source)
3381{
3382 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003383 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003384 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3385 pipe));
Borislav Petkov432f3342013-11-21 16:49:46 +01003386 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003387 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003388
Damien Lespiaucc3da172013-10-15 18:55:31 +01003389 if (pipe_crc->source == source)
3390 return 0;
3391
Damien Lespiauae676fc2013-10-15 18:55:32 +01003392 /* forbid changing the source without going back to 'none' */
3393 if (pipe_crc->source && source)
3394 return -EINVAL;
3395
Daniel Vetter9d8b0582014-11-25 14:00:40 +01003396 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3397 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3398 return -EIO;
3399 }
3400
Daniel Vetter52f843f2013-10-21 17:26:38 +02003401 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003402 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003403 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003404 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003405 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003406 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003407 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003408 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003409 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003410 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003411
3412 if (ret != 0)
3413 return ret;
3414
Damien Lespiau4b584362013-10-15 18:55:33 +01003415 /* none -> real source transition */
3416 if (source) {
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003417 struct intel_pipe_crc_entry *entries;
3418
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003419 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3420 pipe_name(pipe), pipe_crc_source_name(source));
3421
Ville Syrjälä3cf54b32014-12-09 21:28:31 +02003422 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3423 sizeof(pipe_crc->entries[0]),
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003424 GFP_KERNEL);
3425 if (!entries)
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003426 return -ENOMEM;
3427
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003428 /*
3429 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3430 * enabled and disabled dynamically based on package C states,
3431 * user space can't make reliable use of the CRCs, so let's just
3432 * completely disable it.
3433 */
3434 hsw_disable_ips(crtc);
3435
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003436 spin_lock_irq(&pipe_crc->lock);
Daniel Vetter64387b62014-12-10 11:00:29 +01003437 kfree(pipe_crc->entries);
Ville Syrjälä4252fbc2014-12-09 21:28:30 +02003438 pipe_crc->entries = entries;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003439 pipe_crc->head = 0;
3440 pipe_crc->tail = 0;
3441 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003442 }
3443
Damien Lespiaucc3da172013-10-15 18:55:31 +01003444 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003445
Daniel Vetter926321d2013-10-16 13:30:34 +02003446 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3447 POSTING_READ(PIPE_CRC_CTL(pipe));
3448
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003449 /* real source -> none transition */
3450 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003451 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003452 struct intel_crtc *crtc =
3453 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003454
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003455 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3456 pipe_name(pipe));
3457
Daniel Vettera33d7102014-06-06 08:22:08 +02003458 drm_modeset_lock(&crtc->base.mutex, NULL);
3459 if (crtc->active)
3460 intel_wait_for_vblank(dev, pipe);
3461 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003462
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003463 spin_lock_irq(&pipe_crc->lock);
3464 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003465 pipe_crc->entries = NULL;
Ville Syrjälä9ad6d992014-12-09 21:28:32 +02003466 pipe_crc->head = 0;
3467 pipe_crc->tail = 0;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003468 spin_unlock_irq(&pipe_crc->lock);
3469
3470 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003471
3472 if (IS_G4X(dev))
3473 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003474 else if (IS_VALLEYVIEW(dev))
3475 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003476 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3477 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Paulo Zanoni8c740dc2014-10-17 18:42:03 -03003478
3479 hsw_enable_ips(crtc);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003480 }
3481
Daniel Vetter926321d2013-10-16 13:30:34 +02003482 return 0;
3483}
3484
3485/*
3486 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003487 * command: wsp* object wsp+ name wsp+ source wsp*
3488 * object: 'pipe'
3489 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003490 * source: (none | plane1 | plane2 | pf)
3491 * wsp: (#0x20 | #0x9 | #0xA)+
3492 *
3493 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003494 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3495 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003496 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003497static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003498{
3499 int n_words = 0;
3500
3501 while (*buf) {
3502 char *end;
3503
3504 /* skip leading white space */
3505 buf = skip_spaces(buf);
3506 if (!*buf)
3507 break; /* end of buffer */
3508
3509 /* find end of word */
3510 for (end = buf; *end && !isspace(*end); end++)
3511 ;
3512
3513 if (n_words == max_words) {
3514 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3515 max_words);
3516 return -EINVAL; /* ran out of words[] before bytes */
3517 }
3518
3519 if (*end)
3520 *end++ = '\0';
3521 words[n_words++] = buf;
3522 buf = end;
3523 }
3524
3525 return n_words;
3526}
3527
Damien Lespiaub94dec82013-10-15 18:55:35 +01003528enum intel_pipe_crc_object {
3529 PIPE_CRC_OBJECT_PIPE,
3530};
3531
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003532static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003533 "pipe",
3534};
3535
3536static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003537display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003538{
3539 int i;
3540
3541 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3542 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003543 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003544 return 0;
3545 }
3546
3547 return -EINVAL;
3548}
3549
Damien Lespiaubd9db022013-10-15 18:55:36 +01003550static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003551{
3552 const char name = buf[0];
3553
3554 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3555 return -EINVAL;
3556
3557 *pipe = name - 'A';
3558
3559 return 0;
3560}
3561
3562static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003563display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003564{
3565 int i;
3566
3567 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3568 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003569 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003570 return 0;
3571 }
3572
3573 return -EINVAL;
3574}
3575
Damien Lespiaubd9db022013-10-15 18:55:36 +01003576static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003577{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003578#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003579 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003580 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003581 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003582 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003583 enum intel_pipe_crc_source source;
3584
Damien Lespiaubd9db022013-10-15 18:55:36 +01003585 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003586 if (n_words != N_WORDS) {
3587 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3588 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003589 return -EINVAL;
3590 }
3591
Damien Lespiaubd9db022013-10-15 18:55:36 +01003592 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003593 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003594 return -EINVAL;
3595 }
3596
Damien Lespiaubd9db022013-10-15 18:55:36 +01003597 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003598 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3599 return -EINVAL;
3600 }
3601
Damien Lespiaubd9db022013-10-15 18:55:36 +01003602 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003603 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003604 return -EINVAL;
3605 }
3606
3607 return pipe_crc_set_source(dev, pipe, source);
3608}
3609
Damien Lespiaubd9db022013-10-15 18:55:36 +01003610static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3611 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003612{
3613 struct seq_file *m = file->private_data;
3614 struct drm_device *dev = m->private;
3615 char *tmpbuf;
3616 int ret;
3617
3618 if (len == 0)
3619 return 0;
3620
3621 if (len > PAGE_SIZE - 1) {
3622 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3623 PAGE_SIZE);
3624 return -E2BIG;
3625 }
3626
3627 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3628 if (!tmpbuf)
3629 return -ENOMEM;
3630
3631 if (copy_from_user(tmpbuf, ubuf, len)) {
3632 ret = -EFAULT;
3633 goto out;
3634 }
3635 tmpbuf[len] = '\0';
3636
Damien Lespiaubd9db022013-10-15 18:55:36 +01003637 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003638
3639out:
3640 kfree(tmpbuf);
3641 if (ret < 0)
3642 return ret;
3643
3644 *offp += len;
3645 return len;
3646}
3647
Damien Lespiaubd9db022013-10-15 18:55:36 +01003648static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003649 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003650 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003651 .read = seq_read,
3652 .llseek = seq_lseek,
3653 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003654 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003655};
3656
Damien Lespiau97e94b22014-11-04 17:06:50 +00003657static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003658{
3659 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003660 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003661 int level;
3662
3663 drm_modeset_lock_all(dev);
3664
3665 for (level = 0; level < num_levels; level++) {
3666 unsigned int latency = wm[level];
3667
Damien Lespiau97e94b22014-11-04 17:06:50 +00003668 /*
3669 * - WM1+ latency values in 0.5us units
3670 * - latencies are in us on gen9
3671 */
3672 if (INTEL_INFO(dev)->gen >= 9)
3673 latency *= 10;
3674 else if (level > 0)
Ville Syrjälä369a1342014-01-22 14:36:08 +02003675 latency *= 5;
3676
3677 seq_printf(m, "WM%d %u (%u.%u usec)\n",
Damien Lespiau97e94b22014-11-04 17:06:50 +00003678 level, wm[level], latency / 10, latency % 10);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003679 }
3680
3681 drm_modeset_unlock_all(dev);
3682}
3683
3684static int pri_wm_latency_show(struct seq_file *m, void *data)
3685{
3686 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003687 struct drm_i915_private *dev_priv = dev->dev_private;
3688 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003689
Damien Lespiau97e94b22014-11-04 17:06:50 +00003690 if (INTEL_INFO(dev)->gen >= 9)
3691 latencies = dev_priv->wm.skl_latency;
3692 else
3693 latencies = to_i915(dev)->wm.pri_latency;
3694
3695 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003696
3697 return 0;
3698}
3699
3700static int spr_wm_latency_show(struct seq_file *m, void *data)
3701{
3702 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003703 struct drm_i915_private *dev_priv = dev->dev_private;
3704 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003705
Damien Lespiau97e94b22014-11-04 17:06:50 +00003706 if (INTEL_INFO(dev)->gen >= 9)
3707 latencies = dev_priv->wm.skl_latency;
3708 else
3709 latencies = to_i915(dev)->wm.spr_latency;
3710
3711 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003712
3713 return 0;
3714}
3715
3716static int cur_wm_latency_show(struct seq_file *m, void *data)
3717{
3718 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003719 struct drm_i915_private *dev_priv = dev->dev_private;
3720 const uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003721
Damien Lespiau97e94b22014-11-04 17:06:50 +00003722 if (INTEL_INFO(dev)->gen >= 9)
3723 latencies = dev_priv->wm.skl_latency;
3724 else
3725 latencies = to_i915(dev)->wm.cur_latency;
3726
3727 wm_latency_show(m, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003728
3729 return 0;
3730}
3731
3732static int pri_wm_latency_open(struct inode *inode, struct file *file)
3733{
3734 struct drm_device *dev = inode->i_private;
3735
Sonika Jindal9ad02572014-07-21 15:23:39 +05303736 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003737 return -ENODEV;
3738
3739 return single_open(file, pri_wm_latency_show, dev);
3740}
3741
3742static int spr_wm_latency_open(struct inode *inode, struct file *file)
3743{
3744 struct drm_device *dev = inode->i_private;
3745
Sonika Jindal9ad02572014-07-21 15:23:39 +05303746 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003747 return -ENODEV;
3748
3749 return single_open(file, spr_wm_latency_show, dev);
3750}
3751
3752static int cur_wm_latency_open(struct inode *inode, struct file *file)
3753{
3754 struct drm_device *dev = inode->i_private;
3755
Sonika Jindal9ad02572014-07-21 15:23:39 +05303756 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003757 return -ENODEV;
3758
3759 return single_open(file, cur_wm_latency_show, dev);
3760}
3761
3762static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
Damien Lespiau97e94b22014-11-04 17:06:50 +00003763 size_t len, loff_t *offp, uint16_t wm[8])
Ville Syrjälä369a1342014-01-22 14:36:08 +02003764{
3765 struct seq_file *m = file->private_data;
3766 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003767 uint16_t new[8] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003768 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003769 int level;
3770 int ret;
3771 char tmp[32];
3772
3773 if (len >= sizeof(tmp))
3774 return -EINVAL;
3775
3776 if (copy_from_user(tmp, ubuf, len))
3777 return -EFAULT;
3778
3779 tmp[len] = '\0';
3780
Damien Lespiau97e94b22014-11-04 17:06:50 +00003781 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
3782 &new[0], &new[1], &new[2], &new[3],
3783 &new[4], &new[5], &new[6], &new[7]);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003784 if (ret != num_levels)
3785 return -EINVAL;
3786
3787 drm_modeset_lock_all(dev);
3788
3789 for (level = 0; level < num_levels; level++)
3790 wm[level] = new[level];
3791
3792 drm_modeset_unlock_all(dev);
3793
3794 return len;
3795}
3796
3797
3798static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3799 size_t len, loff_t *offp)
3800{
3801 struct seq_file *m = file->private_data;
3802 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003803 struct drm_i915_private *dev_priv = dev->dev_private;
3804 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003805
Damien Lespiau97e94b22014-11-04 17:06:50 +00003806 if (INTEL_INFO(dev)->gen >= 9)
3807 latencies = dev_priv->wm.skl_latency;
3808 else
3809 latencies = to_i915(dev)->wm.pri_latency;
3810
3811 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003812}
3813
3814static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3815 size_t len, loff_t *offp)
3816{
3817 struct seq_file *m = file->private_data;
3818 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003819 struct drm_i915_private *dev_priv = dev->dev_private;
3820 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003821
Damien Lespiau97e94b22014-11-04 17:06:50 +00003822 if (INTEL_INFO(dev)->gen >= 9)
3823 latencies = dev_priv->wm.skl_latency;
3824 else
3825 latencies = to_i915(dev)->wm.spr_latency;
3826
3827 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003828}
3829
3830static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3831 size_t len, loff_t *offp)
3832{
3833 struct seq_file *m = file->private_data;
3834 struct drm_device *dev = m->private;
Damien Lespiau97e94b22014-11-04 17:06:50 +00003835 struct drm_i915_private *dev_priv = dev->dev_private;
3836 uint16_t *latencies;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003837
Damien Lespiau97e94b22014-11-04 17:06:50 +00003838 if (INTEL_INFO(dev)->gen >= 9)
3839 latencies = dev_priv->wm.skl_latency;
3840 else
3841 latencies = to_i915(dev)->wm.cur_latency;
3842
3843 return wm_latency_write(file, ubuf, len, offp, latencies);
Ville Syrjälä369a1342014-01-22 14:36:08 +02003844}
3845
3846static const struct file_operations i915_pri_wm_latency_fops = {
3847 .owner = THIS_MODULE,
3848 .open = pri_wm_latency_open,
3849 .read = seq_read,
3850 .llseek = seq_lseek,
3851 .release = single_release,
3852 .write = pri_wm_latency_write
3853};
3854
3855static const struct file_operations i915_spr_wm_latency_fops = {
3856 .owner = THIS_MODULE,
3857 .open = spr_wm_latency_open,
3858 .read = seq_read,
3859 .llseek = seq_lseek,
3860 .release = single_release,
3861 .write = spr_wm_latency_write
3862};
3863
3864static const struct file_operations i915_cur_wm_latency_fops = {
3865 .owner = THIS_MODULE,
3866 .open = cur_wm_latency_open,
3867 .read = seq_read,
3868 .llseek = seq_lseek,
3869 .release = single_release,
3870 .write = cur_wm_latency_write
3871};
3872
Kees Cook647416f2013-03-10 14:10:06 -07003873static int
3874i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003875{
Kees Cook647416f2013-03-10 14:10:06 -07003876 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003877 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003878
Kees Cook647416f2013-03-10 14:10:06 -07003879 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003880
Kees Cook647416f2013-03-10 14:10:06 -07003881 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003882}
3883
Kees Cook647416f2013-03-10 14:10:06 -07003884static int
3885i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003886{
Kees Cook647416f2013-03-10 14:10:06 -07003887 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03003888 struct drm_i915_private *dev_priv = dev->dev_private;
3889
3890 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003891
Mika Kuoppala58174462014-02-25 17:11:26 +02003892 i915_handle_error(dev, val,
3893 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03003894
3895 intel_runtime_pm_put(dev_priv);
3896
Kees Cook647416f2013-03-10 14:10:06 -07003897 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003898}
3899
Kees Cook647416f2013-03-10 14:10:06 -07003900DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
3901 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003902 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003903
Kees Cook647416f2013-03-10 14:10:06 -07003904static int
3905i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003906{
Kees Cook647416f2013-03-10 14:10:06 -07003907 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003908 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003909
Kees Cook647416f2013-03-10 14:10:06 -07003910 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003911
Kees Cook647416f2013-03-10 14:10:06 -07003912 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003913}
3914
Kees Cook647416f2013-03-10 14:10:06 -07003915static int
3916i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003917{
Kees Cook647416f2013-03-10 14:10:06 -07003918 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003919 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003920 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003921
Kees Cook647416f2013-03-10 14:10:06 -07003922 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003923
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003924 ret = mutex_lock_interruptible(&dev->struct_mutex);
3925 if (ret)
3926 return ret;
3927
Daniel Vetter99584db2012-11-14 17:14:04 +01003928 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003929 mutex_unlock(&dev->struct_mutex);
3930
Kees Cook647416f2013-03-10 14:10:06 -07003931 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003932}
3933
Kees Cook647416f2013-03-10 14:10:06 -07003934DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
3935 i915_ring_stop_get, i915_ring_stop_set,
3936 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02003937
Chris Wilson094f9a52013-09-25 17:34:55 +01003938static int
3939i915_ring_missed_irq_get(void *data, u64 *val)
3940{
3941 struct drm_device *dev = data;
3942 struct drm_i915_private *dev_priv = dev->dev_private;
3943
3944 *val = dev_priv->gpu_error.missed_irq_rings;
3945 return 0;
3946}
3947
3948static int
3949i915_ring_missed_irq_set(void *data, u64 val)
3950{
3951 struct drm_device *dev = data;
3952 struct drm_i915_private *dev_priv = dev->dev_private;
3953 int ret;
3954
3955 /* Lock against concurrent debugfs callers */
3956 ret = mutex_lock_interruptible(&dev->struct_mutex);
3957 if (ret)
3958 return ret;
3959 dev_priv->gpu_error.missed_irq_rings = val;
3960 mutex_unlock(&dev->struct_mutex);
3961
3962 return 0;
3963}
3964
3965DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
3966 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
3967 "0x%08llx\n");
3968
3969static int
3970i915_ring_test_irq_get(void *data, u64 *val)
3971{
3972 struct drm_device *dev = data;
3973 struct drm_i915_private *dev_priv = dev->dev_private;
3974
3975 *val = dev_priv->gpu_error.test_irq_rings;
3976
3977 return 0;
3978}
3979
3980static int
3981i915_ring_test_irq_set(void *data, u64 val)
3982{
3983 struct drm_device *dev = data;
3984 struct drm_i915_private *dev_priv = dev->dev_private;
3985 int ret;
3986
3987 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
3988
3989 /* Lock against concurrent debugfs callers */
3990 ret = mutex_lock_interruptible(&dev->struct_mutex);
3991 if (ret)
3992 return ret;
3993
3994 dev_priv->gpu_error.test_irq_rings = val;
3995 mutex_unlock(&dev->struct_mutex);
3996
3997 return 0;
3998}
3999
4000DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4001 i915_ring_test_irq_get, i915_ring_test_irq_set,
4002 "0x%08llx\n");
4003
Chris Wilsondd624af2013-01-15 12:39:35 +00004004#define DROP_UNBOUND 0x1
4005#define DROP_BOUND 0x2
4006#define DROP_RETIRE 0x4
4007#define DROP_ACTIVE 0x8
4008#define DROP_ALL (DROP_UNBOUND | \
4009 DROP_BOUND | \
4010 DROP_RETIRE | \
4011 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07004012static int
4013i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004014{
Kees Cook647416f2013-03-10 14:10:06 -07004015 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00004016
Kees Cook647416f2013-03-10 14:10:06 -07004017 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00004018}
4019
Kees Cook647416f2013-03-10 14:10:06 -07004020static int
4021i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00004022{
Kees Cook647416f2013-03-10 14:10:06 -07004023 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00004024 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004025 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004026
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08004027 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00004028
4029 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4030 * on ioctls on -EAGAIN. */
4031 ret = mutex_lock_interruptible(&dev->struct_mutex);
4032 if (ret)
4033 return ret;
4034
4035 if (val & DROP_ACTIVE) {
4036 ret = i915_gpu_idle(dev);
4037 if (ret)
4038 goto unlock;
4039 }
4040
4041 if (val & (DROP_RETIRE | DROP_ACTIVE))
4042 i915_gem_retire_requests(dev);
4043
Chris Wilson21ab4e72014-09-09 11:16:08 +01004044 if (val & DROP_BOUND)
4045 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
Chris Wilson4ad72b72014-09-03 19:23:37 +01004046
Chris Wilson21ab4e72014-09-09 11:16:08 +01004047 if (val & DROP_UNBOUND)
4048 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
Chris Wilsondd624af2013-01-15 12:39:35 +00004049
4050unlock:
4051 mutex_unlock(&dev->struct_mutex);
4052
Kees Cook647416f2013-03-10 14:10:06 -07004053 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00004054}
4055
Kees Cook647416f2013-03-10 14:10:06 -07004056DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4057 i915_drop_caches_get, i915_drop_caches_set,
4058 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00004059
Kees Cook647416f2013-03-10 14:10:06 -07004060static int
4061i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004062{
Kees Cook647416f2013-03-10 14:10:06 -07004063 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004064 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004065 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004066
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004067 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004068 return -ENODEV;
4069
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004070 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4071
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004072 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004073 if (ret)
4074 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07004075
Jesse Barnes0a073b82013-04-17 15:54:58 -07004076 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07004077 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07004078 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07004079 *val = dev_priv->rps.max_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004080 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004081
Kees Cook647416f2013-03-10 14:10:06 -07004082 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004083}
4084
Kees Cook647416f2013-03-10 14:10:06 -07004085static int
4086i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07004087{
Kees Cook647416f2013-03-10 14:10:06 -07004088 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07004089 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004090 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004091 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004092
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004093 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004094 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07004095
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004096 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4097
Kees Cook647416f2013-03-10 14:10:06 -07004098 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07004099
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004100 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004101 if (ret)
4102 return ret;
4103
Jesse Barnes358733e2011-07-27 11:53:01 -07004104 /*
4105 * Turbo will still be enabled, but won't go above the set value.
4106 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07004107 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02004108 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004109
Ville Syrjälä03af2042014-06-28 02:03:53 +03004110 hw_max = dev_priv->rps.max_freq;
4111 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004112 } else {
4113 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004114
4115 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07004116 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004117 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004118 }
4119
Ben Widawskyb39fb292014-03-19 18:31:11 -07004120 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004121 mutex_unlock(&dev_priv->rps.hw_lock);
4122 return -EINVAL;
4123 }
4124
Ben Widawskyb39fb292014-03-19 18:31:11 -07004125 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004126
4127 if (IS_VALLEYVIEW(dev))
4128 valleyview_set_rps(dev, val);
4129 else
4130 gen6_set_rps(dev, val);
4131
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004132 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07004133
Kees Cook647416f2013-03-10 14:10:06 -07004134 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07004135}
4136
Kees Cook647416f2013-03-10 14:10:06 -07004137DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4138 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004139 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07004140
Kees Cook647416f2013-03-10 14:10:06 -07004141static int
4142i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004143{
Kees Cook647416f2013-03-10 14:10:06 -07004144 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004145 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07004146 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004147
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004148 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004149 return -ENODEV;
4150
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004151 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4152
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004153 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004154 if (ret)
4155 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07004156
Jesse Barnes0a073b82013-04-17 15:54:58 -07004157 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07004158 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07004159 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07004160 *val = dev_priv->rps.min_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004161 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004162
Kees Cook647416f2013-03-10 14:10:06 -07004163 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004164}
4165
Kees Cook647416f2013-03-10 14:10:06 -07004166static int
4167i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07004168{
Kees Cook647416f2013-03-10 14:10:06 -07004169 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07004170 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004171 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07004172 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02004173
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07004174 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02004175 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07004176
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07004177 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4178
Kees Cook647416f2013-03-10 14:10:06 -07004179 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07004180
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004181 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02004182 if (ret)
4183 return ret;
4184
Jesse Barnes1523c312012-05-25 12:34:54 -07004185 /*
4186 * Turbo will still be enabled, but won't go below the set value.
4187 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07004188 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02004189 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004190
Ville Syrjälä03af2042014-06-28 02:03:53 +03004191 hw_max = dev_priv->rps.max_freq;
4192 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004193 } else {
4194 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004195
4196 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07004197 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004198 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07004199 }
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004200
Ben Widawskyb39fb292014-03-19 18:31:11 -07004201 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004202 mutex_unlock(&dev_priv->rps.hw_lock);
4203 return -EINVAL;
4204 }
4205
Ben Widawskyb39fb292014-03-19 18:31:11 -07004206 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06004207
4208 if (IS_VALLEYVIEW(dev))
4209 valleyview_set_rps(dev, val);
4210 else
4211 gen6_set_rps(dev, val);
4212
Jesse Barnes4fc688c2012-11-02 11:14:01 -07004213 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07004214
Kees Cook647416f2013-03-10 14:10:06 -07004215 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07004216}
4217
Kees Cook647416f2013-03-10 14:10:06 -07004218DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4219 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03004220 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07004221
Kees Cook647416f2013-03-10 14:10:06 -07004222static int
4223i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004224{
Kees Cook647416f2013-03-10 14:10:06 -07004225 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03004226 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004227 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07004228 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004229
Daniel Vetter004777c2012-08-09 15:07:01 +02004230 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4231 return -ENODEV;
4232
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004233 ret = mutex_lock_interruptible(&dev->struct_mutex);
4234 if (ret)
4235 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004236 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02004237
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004238 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004239
4240 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004241 mutex_unlock(&dev_priv->dev->struct_mutex);
4242
Kees Cook647416f2013-03-10 14:10:06 -07004243 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004244
Kees Cook647416f2013-03-10 14:10:06 -07004245 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004246}
4247
Kees Cook647416f2013-03-10 14:10:06 -07004248static int
4249i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004250{
Kees Cook647416f2013-03-10 14:10:06 -07004251 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004252 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004253 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004254
Daniel Vetter004777c2012-08-09 15:07:01 +02004255 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4256 return -ENODEV;
4257
Kees Cook647416f2013-03-10 14:10:06 -07004258 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004259 return -EINVAL;
4260
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004261 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004262 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004263
4264 /* Update the cache sharing policy here as well */
4265 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4266 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4267 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4268 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4269
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02004270 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07004271 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004272}
4273
Kees Cook647416f2013-03-10 14:10:06 -07004274DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4275 i915_cache_sharing_get, i915_cache_sharing_set,
4276 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004277
Ben Widawsky6d794d42011-04-25 11:25:56 -07004278static int i915_forcewake_open(struct inode *inode, struct file *file)
4279{
4280 struct drm_device *dev = inode->i_private;
4281 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004282
Daniel Vetter075edca2012-01-24 09:44:28 +01004283 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004284 return 0;
4285
Deepak Sc8d9a592013-11-23 14:55:42 +05304286 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004287
4288 return 0;
4289}
4290
Ben Widawskyc43b5632012-04-16 14:07:40 -07004291static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004292{
4293 struct drm_device *dev = inode->i_private;
4294 struct drm_i915_private *dev_priv = dev->dev_private;
4295
Daniel Vetter075edca2012-01-24 09:44:28 +01004296 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07004297 return 0;
4298
Deepak Sc8d9a592013-11-23 14:55:42 +05304299 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004300
4301 return 0;
4302}
4303
4304static const struct file_operations i915_forcewake_fops = {
4305 .owner = THIS_MODULE,
4306 .open = i915_forcewake_open,
4307 .release = i915_forcewake_release,
4308};
4309
4310static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
4311{
4312 struct drm_device *dev = minor->dev;
4313 struct dentry *ent;
4314
4315 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07004316 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07004317 root, dev,
4318 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004319 if (!ent)
4320 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07004321
Ben Widawsky8eb57292011-05-11 15:10:58 -07004322 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07004323}
4324
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004325static int i915_debugfs_create(struct dentry *root,
4326 struct drm_minor *minor,
4327 const char *name,
4328 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07004329{
4330 struct drm_device *dev = minor->dev;
4331 struct dentry *ent;
4332
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004333 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07004334 S_IRUGO | S_IWUSR,
4335 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004336 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08004337 if (!ent)
4338 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07004339
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004340 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07004341}
4342
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004343static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00004344 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01004345 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00004346 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01004347 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004348 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05004349 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01004350 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01004351 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004352 {"i915_gem_request", i915_gem_request_info, 0},
4353 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00004354 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004355 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00004356 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
4357 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
4358 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07004359 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Deepak Sadb4bd12014-03-31 11:30:02 +05304360 {"i915_frequency_info", i915_frequency_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08004361 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07004362 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07004363 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08004364 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03004365 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08004366 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01004367 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01004368 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07004369 {"i915_context_status", i915_context_status, 0},
Ben Widawskyc0ab1ae2014-08-07 13:24:26 +01004370 {"i915_dump_lrc", i915_dump_lrc, 0},
Oscar Mateo4ba70e42014-08-07 13:23:20 +01004371 {"i915_execlists", i915_execlists, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07004372 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01004373 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01004374 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07004375 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03004376 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02004377 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01004378 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03004379 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02004380 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08004381 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07004382 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03004383 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10004384 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Damien Lespiau1ed1ef92014-08-30 16:50:59 +01004385 {"i915_wa_registers", i915_wa_registers, 0},
Damien Lespiauc5511e42014-11-04 17:06:51 +00004386 {"i915_ddb_info", i915_ddb_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05004387};
Ben Gamari27c202a2009-07-01 22:26:52 -04004388#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05004389
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01004390static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02004391 const char *name;
4392 const struct file_operations *fops;
4393} i915_debugfs_files[] = {
4394 {"i915_wedged", &i915_wedged_fops},
4395 {"i915_max_freq", &i915_max_freq_fops},
4396 {"i915_min_freq", &i915_min_freq_fops},
4397 {"i915_cache_sharing", &i915_cache_sharing_fops},
4398 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01004399 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
4400 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004401 {"i915_gem_drop_caches", &i915_drop_caches_fops},
4402 {"i915_error_state", &i915_error_state_fops},
4403 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01004404 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02004405 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
4406 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4407 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004408 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004409};
4410
Damien Lespiau07144422013-10-15 18:55:40 +01004411void intel_display_crc_init(struct drm_device *dev)
4412{
4413 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01004414 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01004415
Damien Lespiau055e3932014-08-18 13:49:10 +01004416 for_each_pipe(dev_priv, pipe) {
Daniel Vetterb3783602013-11-14 11:30:42 +01004417 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01004418
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004419 pipe_crc->opened = false;
4420 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01004421 init_waitqueue_head(&pipe_crc->wq);
4422 }
4423}
4424
Ben Gamari27c202a2009-07-01 22:26:52 -04004425int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004426{
Daniel Vetter34b96742013-07-04 20:49:44 +02004427 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004428
Ben Widawsky6d794d42011-04-25 11:25:56 -07004429 ret = i915_forcewake_create(minor->debugfs_root, minor);
4430 if (ret)
4431 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004432
Damien Lespiau07144422013-10-15 18:55:40 +01004433 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
4434 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
4435 if (ret)
4436 return ret;
4437 }
4438
Daniel Vetter34b96742013-07-04 20:49:44 +02004439 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4440 ret = i915_debugfs_create(minor->debugfs_root, minor,
4441 i915_debugfs_files[i].name,
4442 i915_debugfs_files[i].fops);
4443 if (ret)
4444 return ret;
4445 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004446
Ben Gamari27c202a2009-07-01 22:26:52 -04004447 return drm_debugfs_create_files(i915_debugfs_list,
4448 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004449 minor->debugfs_root, minor);
4450}
4451
Ben Gamari27c202a2009-07-01 22:26:52 -04004452void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004453{
Daniel Vetter34b96742013-07-04 20:49:44 +02004454 int i;
4455
Ben Gamari27c202a2009-07-01 22:26:52 -04004456 drm_debugfs_remove_files(i915_debugfs_list,
4457 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004458
Ben Widawsky6d794d42011-04-25 11:25:56 -07004459 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
4460 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004461
Daniel Vettere309a992013-10-16 22:55:51 +02004462 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01004463 struct drm_info_list *info_list =
4464 (struct drm_info_list *)&i915_pipe_crc_data[i];
4465
4466 drm_debugfs_remove_files(info_list, 1, minor);
4467 }
4468
Daniel Vetter34b96742013-07-04 20:49:44 +02004469 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4470 struct drm_info_list *info_list =
4471 (struct drm_info_list *) i915_debugfs_files[i].fops;
4472
4473 drm_debugfs_remove_files(info_list, 1, minor);
4474 }
Ben Gamari20172632009-02-17 20:08:50 -05004475}