blob: f27daf70ba72a2c1c144bd3a2eb3478957d583c6 [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 Wilson6d2b8882013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Chris Wilsonf13d3f72010-09-20 17:36:15 +010043enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010044 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010046 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047};
Ben Gamari433e12f2009-02-17 20:08:51 -050048
Chris Wilson70d39fe2010-08-25 16:03:34 +010049static const char *yesno(int v)
50{
51 return v ? "yes" : "no";
52}
53
Damien Lespiau497666d2013-10-15 18:55:39 +010054/* As the drm_debugfs_init() routines are called before dev->dev_private is
55 * allocated we need to hook into the minor for release. */
56static int
57drm_add_fake_info_node(struct drm_minor *minor,
58 struct dentry *ent,
59 const void *key)
60{
61 struct drm_info_node *node;
62
63 node = kmalloc(sizeof(*node), GFP_KERNEL);
64 if (node == NULL) {
65 debugfs_remove(ent);
66 return -ENOMEM;
67 }
68
69 node->minor = minor;
70 node->dent = ent;
71 node->info_ent = (void *) key;
72
73 mutex_lock(&minor->debugfs_lock);
74 list_add(&node->list, &minor->debugfs_list);
75 mutex_unlock(&minor->debugfs_lock);
76
77 return 0;
78}
79
Chris Wilson70d39fe2010-08-25 16:03:34 +010080static int i915_capabilities(struct seq_file *m, void *data)
81{
Damien Lespiau9f25d002014-05-13 15:30:28 +010082 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010083 struct drm_device *dev = node->minor->dev;
84 const struct intel_device_info *info = INTEL_INFO(dev);
85
86 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030087 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010088#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
89#define SEP_SEMICOLON ;
90 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
91#undef PRINT_FLAG
92#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010093
94 return 0;
95}
Ben Gamari433e12f2009-02-17 20:08:51 -050096
Chris Wilson05394f32010-11-08 19:18:58 +000097static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000098{
Chris Wilson05394f32010-11-08 19:18:58 +000099 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +0000100 return "P";
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800101 else if (i915_gem_obj_is_pinned(obj))
Chris Wilsona6172a82009-02-11 14:26:38 +0000102 return "p";
103 else
104 return " ";
105}
106
Chris Wilson05394f32010-11-08 19:18:58 +0000107static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000108{
Akshay Joshi0206e352011-08-16 15:34:10 -0400109 switch (obj->tiling_mode) {
110 default:
111 case I915_TILING_NONE: return " ";
112 case I915_TILING_X: return "X";
113 case I915_TILING_Y: return "Y";
114 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000115}
116
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700117static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
118{
119 return obj->has_global_gtt_mapping ? "g" : " ";
120}
121
Chris Wilson37811fc2010-08-25 22:45:57 +0100122static void
123describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
124{
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700125 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800126 int pin_count = 0;
127
Ville Syrjäläfb1ae912013-08-22 19:21:30 +0300128 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %u %u %u%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100129 &obj->base,
130 get_pin_flag(obj),
131 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700132 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800133 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100134 obj->base.read_domains,
135 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100136 obj->last_read_seqno,
137 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000138 obj->last_fenced_seqno,
Mika Kuoppala84734a02013-07-12 16:50:57 +0300139 i915_cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100140 obj->dirty ? " dirty" : "",
141 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
142 if (obj->base.name)
143 seq_printf(m, " (name: %d)", obj->base.name);
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800144 list_for_each_entry(vma, &obj->vma_list, vma_link)
145 if (vma->pin_count > 0)
146 pin_count++;
147 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100148 if (obj->pin_display)
149 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100150 if (obj->fence_reg != I915_FENCE_REG_NONE)
151 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700152 list_for_each_entry(vma, &obj->vma_list, vma_link) {
153 if (!i915_is_ggtt(vma->vm))
154 seq_puts(m, " (pp");
155 else
156 seq_puts(m, " (g");
157 seq_printf(m, "gtt offset: %08lx, size: %08lx)",
158 vma->node.start, vma->node.size);
159 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000160 if (obj->stolen)
161 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000162 if (obj->pin_mappable || obj->fault_mappable) {
163 char s[3], *t = s;
164 if (obj->pin_mappable)
165 *t++ = 'p';
166 if (obj->fault_mappable)
167 *t++ = 'f';
168 *t = '\0';
169 seq_printf(m, " (%s mappable)", s);
170 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100171 if (obj->ring != NULL)
172 seq_printf(m, " (%s)", obj->ring->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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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 Wilson6d2b8882013-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);
336 if (ppgtt->ctx && ppgtt->ctx->file_priv != stats->file_priv)
337 continue;
338
339 if (obj->ring) /* XXX per-vma statistic */
340 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;
349 if (obj->ring)
350 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;
518 unsigned long flags;
519 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
531 spin_lock_irqsave(&dev->event_lock, flags);
532 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 Wilsone7d841c2012-12-03 11:36:30 +0000537 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800538 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100539 pipe, plane);
540 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800541 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100542 pipe, plane);
543 }
544 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100545 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100546 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100547 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000548 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100549
550 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000551 struct drm_i915_gem_object *obj = work->old_fb_obj;
552 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700553 seq_printf(m, "Old framebuffer gtt_offset 0x%08lx\n",
554 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100555 }
556 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000557 struct drm_i915_gem_object *obj = work->pending_flip_obj;
558 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700559 seq_printf(m, "New framebuffer gtt_offset 0x%08lx\n",
560 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100561 }
562 }
563 spin_unlock_irqrestore(&dev->event_lock, flags);
564 }
565
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200566 mutex_unlock(&dev->struct_mutex);
567
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100568 return 0;
569}
570
Ben Gamari20172632009-02-17 20:08:50 -0500571static int i915_gem_request_info(struct seq_file *m, void *data)
572{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100573 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500574 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300575 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100576 struct intel_engine_cs *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500577 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100578 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100579
580 ret = mutex_lock_interruptible(&dev->struct_mutex);
581 if (ret)
582 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500583
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100584 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100585 for_each_ring(ring, dev_priv, i) {
586 if (list_empty(&ring->request_list))
587 continue;
588
589 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100590 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100591 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100592 list) {
593 seq_printf(m, " %d @ %d\n",
594 gem_request->seqno,
595 (int) (jiffies - gem_request->emitted_jiffies));
596 }
597 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500598 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100599 mutex_unlock(&dev->struct_mutex);
600
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100601 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100602 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100603
Ben Gamari20172632009-02-17 20:08:50 -0500604 return 0;
605}
606
Chris Wilsonb2223492010-10-27 15:27:33 +0100607static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100608 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100609{
610 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200611 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100612 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100613 }
614}
615
Ben Gamari20172632009-02-17 20:08:50 -0500616static int i915_gem_seqno_info(struct seq_file *m, void *data)
617{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100618 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500619 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300620 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100621 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000622 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100623
624 ret = mutex_lock_interruptible(&dev->struct_mutex);
625 if (ret)
626 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200627 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500628
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100629 for_each_ring(ring, dev_priv, i)
630 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100631
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200632 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100633 mutex_unlock(&dev->struct_mutex);
634
Ben Gamari20172632009-02-17 20:08:50 -0500635 return 0;
636}
637
638
639static int i915_interrupt_info(struct seq_file *m, void *data)
640{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100641 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500642 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300643 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100644 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800645 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100646
647 ret = mutex_lock_interruptible(&dev->struct_mutex);
648 if (ret)
649 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200650 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500651
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300652 if (IS_CHERRYVIEW(dev)) {
653 int i;
654 seq_printf(m, "Master Interrupt Control:\t%08x\n",
655 I915_READ(GEN8_MASTER_IRQ));
656
657 seq_printf(m, "Display IER:\t%08x\n",
658 I915_READ(VLV_IER));
659 seq_printf(m, "Display IIR:\t%08x\n",
660 I915_READ(VLV_IIR));
661 seq_printf(m, "Display IIR_RW:\t%08x\n",
662 I915_READ(VLV_IIR_RW));
663 seq_printf(m, "Display IMR:\t%08x\n",
664 I915_READ(VLV_IMR));
665 for_each_pipe(pipe)
666 seq_printf(m, "Pipe %c stat:\t%08x\n",
667 pipe_name(pipe),
668 I915_READ(PIPESTAT(pipe)));
669
670 seq_printf(m, "Port hotplug:\t%08x\n",
671 I915_READ(PORT_HOTPLUG_EN));
672 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
673 I915_READ(VLV_DPFLIPSTAT));
674 seq_printf(m, "DPINVGTT:\t%08x\n",
675 I915_READ(DPINVGTT));
676
677 for (i = 0; i < 4; i++) {
678 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
679 i, I915_READ(GEN8_GT_IMR(i)));
680 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
681 i, I915_READ(GEN8_GT_IIR(i)));
682 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
683 i, I915_READ(GEN8_GT_IER(i)));
684 }
685
686 seq_printf(m, "PCU interrupt mask:\t%08x\n",
687 I915_READ(GEN8_PCU_IMR));
688 seq_printf(m, "PCU interrupt identity:\t%08x\n",
689 I915_READ(GEN8_PCU_IIR));
690 seq_printf(m, "PCU interrupt enable:\t%08x\n",
691 I915_READ(GEN8_PCU_IER));
692 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700693 seq_printf(m, "Master Interrupt Control:\t%08x\n",
694 I915_READ(GEN8_MASTER_IRQ));
695
696 for (i = 0; i < 4; i++) {
697 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
698 i, I915_READ(GEN8_GT_IMR(i)));
699 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
700 i, I915_READ(GEN8_GT_IIR(i)));
701 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
702 i, I915_READ(GEN8_GT_IER(i)));
703 }
704
Damien Lespiau07d27e22014-03-03 17:31:46 +0000705 for_each_pipe(pipe) {
Ben Widawskya123f152013-11-02 21:07:10 -0700706 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000707 pipe_name(pipe),
708 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700709 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000710 pipe_name(pipe),
711 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700712 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000713 pipe_name(pipe),
714 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700715 }
716
717 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
718 I915_READ(GEN8_DE_PORT_IMR));
719 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
720 I915_READ(GEN8_DE_PORT_IIR));
721 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
722 I915_READ(GEN8_DE_PORT_IER));
723
724 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
725 I915_READ(GEN8_DE_MISC_IMR));
726 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
727 I915_READ(GEN8_DE_MISC_IIR));
728 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
729 I915_READ(GEN8_DE_MISC_IER));
730
731 seq_printf(m, "PCU interrupt mask:\t%08x\n",
732 I915_READ(GEN8_PCU_IMR));
733 seq_printf(m, "PCU interrupt identity:\t%08x\n",
734 I915_READ(GEN8_PCU_IIR));
735 seq_printf(m, "PCU interrupt enable:\t%08x\n",
736 I915_READ(GEN8_PCU_IER));
737 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700738 seq_printf(m, "Display IER:\t%08x\n",
739 I915_READ(VLV_IER));
740 seq_printf(m, "Display IIR:\t%08x\n",
741 I915_READ(VLV_IIR));
742 seq_printf(m, "Display IIR_RW:\t%08x\n",
743 I915_READ(VLV_IIR_RW));
744 seq_printf(m, "Display IMR:\t%08x\n",
745 I915_READ(VLV_IMR));
746 for_each_pipe(pipe)
747 seq_printf(m, "Pipe %c stat:\t%08x\n",
748 pipe_name(pipe),
749 I915_READ(PIPESTAT(pipe)));
750
751 seq_printf(m, "Master IER:\t%08x\n",
752 I915_READ(VLV_MASTER_IER));
753
754 seq_printf(m, "Render IER:\t%08x\n",
755 I915_READ(GTIER));
756 seq_printf(m, "Render IIR:\t%08x\n",
757 I915_READ(GTIIR));
758 seq_printf(m, "Render IMR:\t%08x\n",
759 I915_READ(GTIMR));
760
761 seq_printf(m, "PM IER:\t\t%08x\n",
762 I915_READ(GEN6_PMIER));
763 seq_printf(m, "PM IIR:\t\t%08x\n",
764 I915_READ(GEN6_PMIIR));
765 seq_printf(m, "PM IMR:\t\t%08x\n",
766 I915_READ(GEN6_PMIMR));
767
768 seq_printf(m, "Port hotplug:\t%08x\n",
769 I915_READ(PORT_HOTPLUG_EN));
770 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
771 I915_READ(VLV_DPFLIPSTAT));
772 seq_printf(m, "DPINVGTT:\t%08x\n",
773 I915_READ(DPINVGTT));
774
775 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800776 seq_printf(m, "Interrupt enable: %08x\n",
777 I915_READ(IER));
778 seq_printf(m, "Interrupt identity: %08x\n",
779 I915_READ(IIR));
780 seq_printf(m, "Interrupt mask: %08x\n",
781 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800782 for_each_pipe(pipe)
783 seq_printf(m, "Pipe %c stat: %08x\n",
784 pipe_name(pipe),
785 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800786 } else {
787 seq_printf(m, "North Display Interrupt enable: %08x\n",
788 I915_READ(DEIER));
789 seq_printf(m, "North Display Interrupt identity: %08x\n",
790 I915_READ(DEIIR));
791 seq_printf(m, "North Display Interrupt mask: %08x\n",
792 I915_READ(DEIMR));
793 seq_printf(m, "South Display Interrupt enable: %08x\n",
794 I915_READ(SDEIER));
795 seq_printf(m, "South Display Interrupt identity: %08x\n",
796 I915_READ(SDEIIR));
797 seq_printf(m, "South Display Interrupt mask: %08x\n",
798 I915_READ(SDEIMR));
799 seq_printf(m, "Graphics Interrupt enable: %08x\n",
800 I915_READ(GTIER));
801 seq_printf(m, "Graphics Interrupt identity: %08x\n",
802 I915_READ(GTIIR));
803 seq_printf(m, "Graphics Interrupt mask: %08x\n",
804 I915_READ(GTIMR));
805 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100806 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700807 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100808 seq_printf(m,
809 "Graphics Interrupt mask (%s): %08x\n",
810 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000811 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100812 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000813 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200814 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100815 mutex_unlock(&dev->struct_mutex);
816
Ben Gamari20172632009-02-17 20:08:50 -0500817 return 0;
818}
819
Chris Wilsona6172a82009-02-11 14:26:38 +0000820static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
821{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100822 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000823 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300824 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100825 int i, ret;
826
827 ret = mutex_lock_interruptible(&dev->struct_mutex);
828 if (ret)
829 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000830
831 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
832 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
833 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000834 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000835
Chris Wilson6c085a72012-08-20 11:40:46 +0200836 seq_printf(m, "Fence %d, pin count = %d, object = ",
837 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100838 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100839 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100840 else
Chris Wilson05394f32010-11-08 19:18:58 +0000841 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100842 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000843 }
844
Chris Wilson05394f32010-11-08 19:18:58 +0000845 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000846 return 0;
847}
848
Ben Gamari20172632009-02-17 20:08:50 -0500849static int i915_hws_info(struct seq_file *m, void *data)
850{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100851 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500852 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300853 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100854 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100855 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100856 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500857
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000858 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100859 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500860 if (hws == NULL)
861 return 0;
862
863 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
864 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
865 i * 4,
866 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
867 }
868 return 0;
869}
870
Daniel Vetterd5442302012-04-27 15:17:40 +0200871static ssize_t
872i915_error_state_write(struct file *filp,
873 const char __user *ubuf,
874 size_t cnt,
875 loff_t *ppos)
876{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300877 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200878 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200879 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200880
881 DRM_DEBUG_DRIVER("Resetting error state\n");
882
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200883 ret = mutex_lock_interruptible(&dev->struct_mutex);
884 if (ret)
885 return ret;
886
Daniel Vetterd5442302012-04-27 15:17:40 +0200887 i915_destroy_error_state(dev);
888 mutex_unlock(&dev->struct_mutex);
889
890 return cnt;
891}
892
893static int i915_error_state_open(struct inode *inode, struct file *file)
894{
895 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200896 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200897
898 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
899 if (!error_priv)
900 return -ENOMEM;
901
902 error_priv->dev = dev;
903
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300904 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200905
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300906 file->private_data = error_priv;
907
908 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200909}
910
911static int i915_error_state_release(struct inode *inode, struct file *file)
912{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300913 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200914
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300915 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200916 kfree(error_priv);
917
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300918 return 0;
919}
920
921static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
922 size_t count, loff_t *pos)
923{
924 struct i915_error_state_file_priv *error_priv = file->private_data;
925 struct drm_i915_error_state_buf error_str;
926 loff_t tmp_pos = 0;
927 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300928 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300929
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300930 ret = i915_error_state_buf_init(&error_str, count, *pos);
931 if (ret)
932 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300933
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300934 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300935 if (ret)
936 goto out;
937
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300938 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
939 error_str.buf,
940 error_str.bytes);
941
942 if (ret_count < 0)
943 ret = ret_count;
944 else
945 *pos = error_str.start + ret_count;
946out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300947 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300948 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +0200949}
950
951static const struct file_operations i915_error_state_fops = {
952 .owner = THIS_MODULE,
953 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300954 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200955 .write = i915_error_state_write,
956 .llseek = default_llseek,
957 .release = i915_error_state_release,
958};
959
Kees Cook647416f2013-03-10 14:10:06 -0700960static int
961i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200962{
Kees Cook647416f2013-03-10 14:10:06 -0700963 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300964 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +0200965 int ret;
966
967 ret = mutex_lock_interruptible(&dev->struct_mutex);
968 if (ret)
969 return ret;
970
Kees Cook647416f2013-03-10 14:10:06 -0700971 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +0200972 mutex_unlock(&dev->struct_mutex);
973
Kees Cook647416f2013-03-10 14:10:06 -0700974 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +0200975}
976
Kees Cook647416f2013-03-10 14:10:06 -0700977static int
978i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200979{
Kees Cook647416f2013-03-10 14:10:06 -0700980 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200981 int ret;
982
Mika Kuoppala40633212012-12-04 15:12:00 +0200983 ret = mutex_lock_interruptible(&dev->struct_mutex);
984 if (ret)
985 return ret;
986
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200987 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200988 mutex_unlock(&dev->struct_mutex);
989
Kees Cook647416f2013-03-10 14:10:06 -0700990 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +0200991}
992
Kees Cook647416f2013-03-10 14:10:06 -0700993DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
994 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +0300995 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +0200996
Deepak Sadb4bd12014-03-31 11:30:02 +0530997static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800998{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100999 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001000 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001001 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001002 int ret = 0;
1003
1004 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001005
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001006 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1007
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001008 if (IS_GEN5(dev)) {
1009 u16 rgvswctl = I915_READ16(MEMSWCTL);
1010 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1011
1012 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1013 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1014 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1015 MEMSTAT_VID_SHIFT);
1016 seq_printf(m, "Current P-state: %d\n",
1017 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001018 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
1019 IS_BROADWELL(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001020 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1021 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1022 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001023 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001024 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001025 u32 rpupei, rpcurup, rpprevup;
1026 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001027 int max_freq;
1028
1029 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001030 ret = mutex_lock_interruptible(&dev->struct_mutex);
1031 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001032 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001033
Deepak Sc8d9a592013-11-23 14:55:42 +05301034 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001035
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001036 reqf = I915_READ(GEN6_RPNSWREQ);
1037 reqf &= ~GEN6_TURBO_DISABLE;
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001038 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001039 reqf >>= 24;
1040 else
1041 reqf >>= 25;
1042 reqf *= GT_FREQUENCY_MULTIPLIER;
1043
Chris Wilson0d8f9492014-03-27 09:06:14 +00001044 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1045 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1046 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1047
Jesse Barnesccab5c82011-01-18 15:49:25 -08001048 rpstat = I915_READ(GEN6_RPSTAT1);
1049 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1050 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1051 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1052 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1053 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1054 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001055 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001056 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1057 else
1058 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
1059 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001060
Deepak Sc8d9a592013-11-23 14:55:42 +05301061 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001062 mutex_unlock(&dev->struct_mutex);
1063
Chris Wilson0d8f9492014-03-27 09:06:14 +00001064 seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
1065 I915_READ(GEN6_PMIER),
1066 I915_READ(GEN6_PMIMR),
1067 I915_READ(GEN6_PMISR),
1068 I915_READ(GEN6_PMIIR),
1069 I915_READ(GEN6_PMINTRMSK));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001070 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001071 seq_printf(m, "Render p-state ratio: %d\n",
1072 (gt_perf_status & 0xff00) >> 8);
1073 seq_printf(m, "Render p-state VID: %d\n",
1074 gt_perf_status & 0xff);
1075 seq_printf(m, "Render p-state limit: %d\n",
1076 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001077 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1078 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1079 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1080 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001081 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001082 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001083 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1084 GEN6_CURICONT_MASK);
1085 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1086 GEN6_CURBSYTAVG_MASK);
1087 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1088 GEN6_CURBSYTAVG_MASK);
1089 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1090 GEN6_CURIAVG_MASK);
1091 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1092 GEN6_CURBSYTAVG_MASK);
1093 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1094 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001095
1096 max_freq = (rp_state_cap & 0xff0000) >> 16;
1097 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001098 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001099
1100 max_freq = (rp_state_cap & 0xff00) >> 8;
1101 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001102 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001103
1104 max_freq = rp_state_cap & 0xff;
1105 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001106 max_freq * GT_FREQUENCY_MULTIPLIER);
Ben Widawsky31c77382013-04-05 14:29:22 -07001107
1108 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ben Widawskyb39fb292014-03-19 18:31:11 -07001109 dev_priv->rps.max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001110 } else if (IS_VALLEYVIEW(dev)) {
1111 u32 freq_sts, val;
1112
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001113 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001114 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001115 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1116 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1117
Chon Ming Leec5bd2bf2013-11-07 15:23:27 +08001118 val = valleyview_rps_max_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001119 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001120 vlv_gpu_freq(dev_priv, val));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001121
Chon Ming Leec5bd2bf2013-11-07 15:23:27 +08001122 val = valleyview_rps_min_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001123 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001124 vlv_gpu_freq(dev_priv, val));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001125
1126 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001127 vlv_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001128 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001129 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001130 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001131 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001132
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001133out:
1134 intel_runtime_pm_put(dev_priv);
1135 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001136}
1137
Ben Widawsky4d855292011-12-12 19:34:16 -08001138static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001139{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001140 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001141 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001142 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001143 u32 rgvmodectl, rstdbyctl;
1144 u16 crstandvid;
1145 int ret;
1146
1147 ret = mutex_lock_interruptible(&dev->struct_mutex);
1148 if (ret)
1149 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001150 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001151
1152 rgvmodectl = I915_READ(MEMMODECTL);
1153 rstdbyctl = I915_READ(RSTDBYCTL);
1154 crstandvid = I915_READ16(CRSTANDVID);
1155
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001156 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001157 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001158
1159 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1160 "yes" : "no");
1161 seq_printf(m, "Boost freq: %d\n",
1162 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1163 MEMMODE_BOOST_FREQ_SHIFT);
1164 seq_printf(m, "HW control enabled: %s\n",
1165 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1166 seq_printf(m, "SW control enabled: %s\n",
1167 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1168 seq_printf(m, "Gated voltage change: %s\n",
1169 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1170 seq_printf(m, "Starting frequency: P%d\n",
1171 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001172 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001173 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001174 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1175 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1176 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1177 seq_printf(m, "Render standby enabled: %s\n",
1178 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001179 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001180 switch (rstdbyctl & RSX_STATUS_MASK) {
1181 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001182 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001183 break;
1184 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001185 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001186 break;
1187 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001188 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001189 break;
1190 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001191 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001192 break;
1193 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001194 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001195 break;
1196 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001197 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001198 break;
1199 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001200 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001201 break;
1202 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001203
1204 return 0;
1205}
1206
Deepak S669ab5a2014-01-10 15:18:26 +05301207static int vlv_drpc_info(struct seq_file *m)
1208{
1209
Damien Lespiau9f25d002014-05-13 15:30:28 +01001210 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301211 struct drm_device *dev = node->minor->dev;
1212 struct drm_i915_private *dev_priv = dev->dev_private;
1213 u32 rpmodectl1, rcctl1;
1214 unsigned fw_rendercount = 0, fw_mediacount = 0;
1215
Imre Deakd46c0512014-04-14 20:24:27 +03001216 intel_runtime_pm_get(dev_priv);
1217
Deepak S669ab5a2014-01-10 15:18:26 +05301218 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1219 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1220
Imre Deakd46c0512014-04-14 20:24:27 +03001221 intel_runtime_pm_put(dev_priv);
1222
Deepak S669ab5a2014-01-10 15:18:26 +05301223 seq_printf(m, "Video Turbo Mode: %s\n",
1224 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1225 seq_printf(m, "Turbo enabled: %s\n",
1226 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1227 seq_printf(m, "HW control enabled: %s\n",
1228 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1229 seq_printf(m, "SW control enabled: %s\n",
1230 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1231 GEN6_RP_MEDIA_SW_MODE));
1232 seq_printf(m, "RC6 Enabled: %s\n",
1233 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1234 GEN6_RC_CTL_EI_MODE(1))));
1235 seq_printf(m, "Render Power Well: %s\n",
1236 (I915_READ(VLV_GTLC_PW_STATUS) &
1237 VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
1238 seq_printf(m, "Media Power Well: %s\n",
1239 (I915_READ(VLV_GTLC_PW_STATUS) &
1240 VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
1241
Imre Deak9cc19be2014-04-14 20:24:24 +03001242 seq_printf(m, "Render RC6 residency since boot: %u\n",
1243 I915_READ(VLV_GT_RENDER_RC6));
1244 seq_printf(m, "Media RC6 residency since boot: %u\n",
1245 I915_READ(VLV_GT_MEDIA_RC6));
1246
Deepak S669ab5a2014-01-10 15:18:26 +05301247 spin_lock_irq(&dev_priv->uncore.lock);
1248 fw_rendercount = dev_priv->uncore.fw_rendercount;
1249 fw_mediacount = dev_priv->uncore.fw_mediacount;
1250 spin_unlock_irq(&dev_priv->uncore.lock);
1251
1252 seq_printf(m, "Forcewake Render Count = %u\n", fw_rendercount);
1253 seq_printf(m, "Forcewake Media Count = %u\n", fw_mediacount);
1254
1255
1256 return 0;
1257}
1258
1259
Ben Widawsky4d855292011-12-12 19:34:16 -08001260static int gen6_drpc_info(struct seq_file *m)
1261{
1262
Damien Lespiau9f25d002014-05-13 15:30:28 +01001263 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001264 struct drm_device *dev = node->minor->dev;
1265 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001266 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001267 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001268 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001269
1270 ret = mutex_lock_interruptible(&dev->struct_mutex);
1271 if (ret)
1272 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001273 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001274
Chris Wilson907b28c2013-07-19 20:36:52 +01001275 spin_lock_irq(&dev_priv->uncore.lock);
1276 forcewake_count = dev_priv->uncore.forcewake_count;
1277 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001278
1279 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001280 seq_puts(m, "RC information inaccurate because somebody "
1281 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001282 } else {
1283 /* NB: we cannot use forcewake, else we read the wrong values */
1284 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1285 udelay(10);
1286 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1287 }
1288
1289 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001290 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001291
1292 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1293 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1294 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001295 mutex_lock(&dev_priv->rps.hw_lock);
1296 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1297 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001298
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001299 intel_runtime_pm_put(dev_priv);
1300
Ben Widawsky4d855292011-12-12 19:34:16 -08001301 seq_printf(m, "Video Turbo Mode: %s\n",
1302 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1303 seq_printf(m, "HW control enabled: %s\n",
1304 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1305 seq_printf(m, "SW control enabled: %s\n",
1306 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1307 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001308 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001309 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1310 seq_printf(m, "RC6 Enabled: %s\n",
1311 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1312 seq_printf(m, "Deep RC6 Enabled: %s\n",
1313 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1314 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1315 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001316 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001317 switch (gt_core_status & GEN6_RCn_MASK) {
1318 case GEN6_RC0:
1319 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001320 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001321 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001322 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001323 break;
1324 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001325 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001326 break;
1327 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001328 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001329 break;
1330 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001331 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001332 break;
1333 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001334 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001335 break;
1336 }
1337
1338 seq_printf(m, "Core Power Down: %s\n",
1339 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001340
1341 /* Not exactly sure what this is */
1342 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1343 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1344 seq_printf(m, "RC6 residency since boot: %u\n",
1345 I915_READ(GEN6_GT_GFX_RC6));
1346 seq_printf(m, "RC6+ residency since boot: %u\n",
1347 I915_READ(GEN6_GT_GFX_RC6p));
1348 seq_printf(m, "RC6++ residency since boot: %u\n",
1349 I915_READ(GEN6_GT_GFX_RC6pp));
1350
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001351 seq_printf(m, "RC6 voltage: %dmV\n",
1352 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1353 seq_printf(m, "RC6+ voltage: %dmV\n",
1354 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1355 seq_printf(m, "RC6++ voltage: %dmV\n",
1356 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001357 return 0;
1358}
1359
1360static int i915_drpc_info(struct seq_file *m, void *unused)
1361{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001362 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001363 struct drm_device *dev = node->minor->dev;
1364
Deepak S669ab5a2014-01-10 15:18:26 +05301365 if (IS_VALLEYVIEW(dev))
1366 return vlv_drpc_info(m);
1367 else if (IS_GEN6(dev) || IS_GEN7(dev))
Ben Widawsky4d855292011-12-12 19:34:16 -08001368 return gen6_drpc_info(m);
1369 else
1370 return ironlake_drpc_info(m);
1371}
1372
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001373static int i915_fbc_status(struct seq_file *m, void *unused)
1374{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001375 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001376 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001377 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001378
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001379 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001380 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001381 return 0;
1382 }
1383
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001384 intel_runtime_pm_get(dev_priv);
1385
Adam Jacksonee5382a2010-04-23 11:17:39 -04001386 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001387 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001388 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001389 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001390 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001391 case FBC_OK:
1392 seq_puts(m, "FBC actived, but currently disabled in hardware");
1393 break;
1394 case FBC_UNSUPPORTED:
1395 seq_puts(m, "unsupported by this chipset");
1396 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001397 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001398 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001399 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001400 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001401 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001402 break;
1403 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001404 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001405 break;
1406 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001407 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001408 break;
1409 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001410 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001411 break;
1412 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001413 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001414 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001415 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001416 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001417 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001418 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001419 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001420 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001421 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001422 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001423 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001424 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001425 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001426 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001427 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001428 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001429
1430 intel_runtime_pm_put(dev_priv);
1431
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001432 return 0;
1433}
1434
Paulo Zanoni92d44622013-05-31 16:33:24 -03001435static int i915_ips_status(struct seq_file *m, void *unused)
1436{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001437 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001438 struct drm_device *dev = node->minor->dev;
1439 struct drm_i915_private *dev_priv = dev->dev_private;
1440
Damien Lespiauf5adf942013-06-24 18:29:34 +01001441 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001442 seq_puts(m, "not supported\n");
1443 return 0;
1444 }
1445
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001446 intel_runtime_pm_get(dev_priv);
1447
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001448 seq_printf(m, "Enabled by kernel parameter: %s\n",
1449 yesno(i915.enable_ips));
1450
1451 if (INTEL_INFO(dev)->gen >= 8) {
1452 seq_puts(m, "Currently: unknown\n");
1453 } else {
1454 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1455 seq_puts(m, "Currently: enabled\n");
1456 else
1457 seq_puts(m, "Currently: disabled\n");
1458 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001459
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001460 intel_runtime_pm_put(dev_priv);
1461
Paulo Zanoni92d44622013-05-31 16:33:24 -03001462 return 0;
1463}
1464
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001465static int i915_sr_status(struct seq_file *m, void *unused)
1466{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001467 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001468 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001469 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001470 bool sr_enabled = false;
1471
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001472 intel_runtime_pm_get(dev_priv);
1473
Yuanhan Liu13982612010-12-15 15:42:31 +08001474 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001475 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001476 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001477 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1478 else if (IS_I915GM(dev))
1479 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1480 else if (IS_PINEVIEW(dev))
1481 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1482
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001483 intel_runtime_pm_put(dev_priv);
1484
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001485 seq_printf(m, "self-refresh: %s\n",
1486 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001487
1488 return 0;
1489}
1490
Jesse Barnes7648fa92010-05-20 14:28:11 -07001491static int i915_emon_status(struct seq_file *m, void *unused)
1492{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001493 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001494 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001495 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001496 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001497 int ret;
1498
Chris Wilson582be6b2012-04-30 19:35:02 +01001499 if (!IS_GEN5(dev))
1500 return -ENODEV;
1501
Chris Wilsonde227ef2010-07-03 07:58:38 +01001502 ret = mutex_lock_interruptible(&dev->struct_mutex);
1503 if (ret)
1504 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001505
1506 temp = i915_mch_val(dev_priv);
1507 chipset = i915_chipset_val(dev_priv);
1508 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001509 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001510
1511 seq_printf(m, "GMCH temp: %ld\n", temp);
1512 seq_printf(m, "Chipset power: %ld\n", chipset);
1513 seq_printf(m, "GFX power: %ld\n", gfx);
1514 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1515
1516 return 0;
1517}
1518
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001519static int i915_ring_freq_table(struct seq_file *m, void *unused)
1520{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001521 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001522 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001523 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001524 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001525 int gpu_freq, ia_freq;
1526
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001527 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001528 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001529 return 0;
1530 }
1531
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001532 intel_runtime_pm_get(dev_priv);
1533
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001534 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1535
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001536 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001537 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001538 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001539
Damien Lespiau267f0c92013-06-24 22:59:48 +01001540 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001541
Ben Widawskyb39fb292014-03-19 18:31:11 -07001542 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1543 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001544 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001545 ia_freq = gpu_freq;
1546 sandybridge_pcode_read(dev_priv,
1547 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1548 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001549 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1550 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1551 ((ia_freq >> 0) & 0xff) * 100,
1552 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001553 }
1554
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001555 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001556
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001557out:
1558 intel_runtime_pm_put(dev_priv);
1559 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001560}
1561
Chris Wilson44834a62010-08-19 16:09:23 +01001562static int i915_opregion(struct seq_file *m, void *unused)
1563{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001564 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001565 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001566 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001567 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001568 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001569 int ret;
1570
Daniel Vetter0d38f002012-04-21 22:49:10 +02001571 if (data == NULL)
1572 return -ENOMEM;
1573
Chris Wilson44834a62010-08-19 16:09:23 +01001574 ret = mutex_lock_interruptible(&dev->struct_mutex);
1575 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001576 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001577
Daniel Vetter0d38f002012-04-21 22:49:10 +02001578 if (opregion->header) {
1579 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1580 seq_write(m, data, OPREGION_SIZE);
1581 }
Chris Wilson44834a62010-08-19 16:09:23 +01001582
1583 mutex_unlock(&dev->struct_mutex);
1584
Daniel Vetter0d38f002012-04-21 22:49:10 +02001585out:
1586 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001587 return 0;
1588}
1589
Chris Wilson37811fc2010-08-25 22:45:57 +01001590static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1591{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001592 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001593 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001594 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001595 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001596
Daniel Vetter4520f532013-10-09 09:18:51 +02001597#ifdef CONFIG_DRM_I915_FBDEV
1598 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001599
1600 ifbdev = dev_priv->fbdev;
1601 fb = to_intel_framebuffer(ifbdev->helper.fb);
1602
Daniel Vetter623f9782012-12-11 16:21:38 +01001603 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001604 fb->base.width,
1605 fb->base.height,
1606 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001607 fb->base.bits_per_pixel,
1608 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001609 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001610 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001611#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001612
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001613 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001614 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001615 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001616 continue;
1617
Daniel Vetter623f9782012-12-11 16:21:38 +01001618 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001619 fb->base.width,
1620 fb->base.height,
1621 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001622 fb->base.bits_per_pixel,
1623 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001624 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001625 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001626 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001627 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001628
1629 return 0;
1630}
1631
Ben Widawskye76d3632011-03-19 18:14:29 -07001632static int i915_context_status(struct seq_file *m, void *unused)
1633{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001634 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001635 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001636 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001637 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001638 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001639 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001640
Daniel Vetterf3d28872014-05-29 23:23:08 +02001641 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001642 if (ret)
1643 return ret;
1644
Daniel Vetter3e373942012-11-02 19:55:04 +01001645 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001646 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001647 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001648 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001649 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001650
Daniel Vetter3e373942012-11-02 19:55:04 +01001651 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001652 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001653 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001654 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001655 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001656
Ben Widawskya33afea2013-09-17 21:12:45 -07001657 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoea0c76f2014-07-03 16:27:59 +01001658 if (ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001659 continue;
1660
Ben Widawskya33afea2013-09-17 21:12:45 -07001661 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001662 describe_ctx(m, ctx);
Ben Widawskya33afea2013-09-17 21:12:45 -07001663 for_each_ring(ring, dev_priv, i)
1664 if (ring->default_context == ctx)
1665 seq_printf(m, "(default context %s) ", ring->name);
1666
Oscar Mateoea0c76f2014-07-03 16:27:59 +01001667 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
Ben Widawskya33afea2013-09-17 21:12:45 -07001668 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001669 }
1670
Daniel Vetterf3d28872014-05-29 23:23:08 +02001671 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001672
1673 return 0;
1674}
1675
Ben Widawsky6d794d42011-04-25 11:25:56 -07001676static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1677{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001678 struct drm_info_node *node = m->private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001679 struct drm_device *dev = node->minor->dev;
1680 struct drm_i915_private *dev_priv = dev->dev_private;
Deepak S43709ba2013-11-23 14:55:44 +05301681 unsigned forcewake_count = 0, fw_rendercount = 0, fw_mediacount = 0;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001682
Chris Wilson907b28c2013-07-19 20:36:52 +01001683 spin_lock_irq(&dev_priv->uncore.lock);
Deepak S43709ba2013-11-23 14:55:44 +05301684 if (IS_VALLEYVIEW(dev)) {
1685 fw_rendercount = dev_priv->uncore.fw_rendercount;
1686 fw_mediacount = dev_priv->uncore.fw_mediacount;
1687 } else
1688 forcewake_count = dev_priv->uncore.forcewake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001689 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001690
Deepak S43709ba2013-11-23 14:55:44 +05301691 if (IS_VALLEYVIEW(dev)) {
1692 seq_printf(m, "fw_rendercount = %u\n", fw_rendercount);
1693 seq_printf(m, "fw_mediacount = %u\n", fw_mediacount);
1694 } else
1695 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001696
1697 return 0;
1698}
1699
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001700static const char *swizzle_string(unsigned swizzle)
1701{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001702 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001703 case I915_BIT_6_SWIZZLE_NONE:
1704 return "none";
1705 case I915_BIT_6_SWIZZLE_9:
1706 return "bit9";
1707 case I915_BIT_6_SWIZZLE_9_10:
1708 return "bit9/bit10";
1709 case I915_BIT_6_SWIZZLE_9_11:
1710 return "bit9/bit11";
1711 case I915_BIT_6_SWIZZLE_9_10_11:
1712 return "bit9/bit10/bit11";
1713 case I915_BIT_6_SWIZZLE_9_17:
1714 return "bit9/bit17";
1715 case I915_BIT_6_SWIZZLE_9_10_17:
1716 return "bit9/bit10/bit17";
1717 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001718 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001719 }
1720
1721 return "bug";
1722}
1723
1724static int i915_swizzle_info(struct seq_file *m, void *data)
1725{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001726 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001727 struct drm_device *dev = node->minor->dev;
1728 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001729 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001730
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001731 ret = mutex_lock_interruptible(&dev->struct_mutex);
1732 if (ret)
1733 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001734 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001735
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001736 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1737 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1738 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1739 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1740
1741 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1742 seq_printf(m, "DDC = 0x%08x\n",
1743 I915_READ(DCC));
1744 seq_printf(m, "C0DRB3 = 0x%04x\n",
1745 I915_READ16(C0DRB3));
1746 seq_printf(m, "C1DRB3 = 0x%04x\n",
1747 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001748 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001749 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1750 I915_READ(MAD_DIMM_C0));
1751 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1752 I915_READ(MAD_DIMM_C1));
1753 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1754 I915_READ(MAD_DIMM_C2));
1755 seq_printf(m, "TILECTL = 0x%08x\n",
1756 I915_READ(TILECTL));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001757 if (IS_GEN8(dev))
1758 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
1759 I915_READ(GAMTARBMODE));
1760 else
1761 seq_printf(m, "ARB_MODE = 0x%08x\n",
1762 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001763 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1764 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001765 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001766 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001767 mutex_unlock(&dev->struct_mutex);
1768
1769 return 0;
1770}
1771
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001772static int per_file_ctx(int id, void *ptr, void *data)
1773{
Oscar Mateo273497e2014-05-22 14:13:37 +01001774 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001775 struct seq_file *m = data;
1776 struct i915_hw_ppgtt *ppgtt = ctx_to_ppgtt(ctx);
1777
Oscar Mateof83d6512014-05-22 14:13:38 +01001778 if (i915_gem_context_is_default(ctx))
1779 seq_puts(m, " default context:\n");
1780 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01001781 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001782 ppgtt->debug_dump(ppgtt, m);
1783
1784 return 0;
1785}
1786
Ben Widawsky77df6772013-11-02 21:07:30 -07001787static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001788{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001789 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001790 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07001791 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1792 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001793
Ben Widawsky77df6772013-11-02 21:07:30 -07001794 if (!ppgtt)
1795 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001796
Ben Widawsky77df6772013-11-02 21:07:30 -07001797 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08001798 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07001799 for_each_ring(ring, dev_priv, unused) {
1800 seq_printf(m, "%s\n", ring->name);
1801 for (i = 0; i < 4; i++) {
1802 u32 offset = 0x270 + i * 8;
1803 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
1804 pdp <<= 32;
1805 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03001806 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07001807 }
1808 }
1809}
1810
1811static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
1812{
1813 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001814 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001815 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07001816 int i;
1817
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001818 if (INTEL_INFO(dev)->gen == 6)
1819 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1820
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001821 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001822 seq_printf(m, "%s\n", ring->name);
1823 if (INTEL_INFO(dev)->gen == 7)
1824 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1825 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1826 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1827 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1828 }
1829 if (dev_priv->mm.aliasing_ppgtt) {
1830 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1831
Damien Lespiau267f0c92013-06-24 22:59:48 +01001832 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001833 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001834
Ben Widawsky87d60b62013-12-06 14:11:29 -08001835 ppgtt->debug_dump(ppgtt, m);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001836 } else
1837 return;
1838
1839 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
1840 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001841
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001842 seq_printf(m, "proc: %s\n",
1843 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001844 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001845 }
1846 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07001847}
1848
1849static int i915_ppgtt_info(struct seq_file *m, void *data)
1850{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001851 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07001852 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001853 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07001854
1855 int ret = mutex_lock_interruptible(&dev->struct_mutex);
1856 if (ret)
1857 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001858 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07001859
1860 if (INTEL_INFO(dev)->gen >= 8)
1861 gen8_ppgtt_info(m, dev);
1862 else if (INTEL_INFO(dev)->gen >= 6)
1863 gen6_ppgtt_info(m, dev);
1864
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001865 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001866 mutex_unlock(&dev->struct_mutex);
1867
1868 return 0;
1869}
1870
Ben Widawsky63573eb2013-07-04 11:02:07 -07001871static int i915_llc(struct seq_file *m, void *data)
1872{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001873 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07001874 struct drm_device *dev = node->minor->dev;
1875 struct drm_i915_private *dev_priv = dev->dev_private;
1876
1877 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
1878 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
1879 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
1880
1881 return 0;
1882}
1883
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001884static int i915_edp_psr_status(struct seq_file *m, void *data)
1885{
1886 struct drm_info_node *node = m->private;
1887 struct drm_device *dev = node->minor->dev;
1888 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03001889 u32 psrperf = 0;
1890 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001891
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001892 intel_runtime_pm_get(dev_priv);
1893
Rodrigo Vivia031d702013-10-03 16:15:06 -03001894 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
1895 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07001896 seq_printf(m, "Enabled: %s\n", yesno(dev_priv->psr.enabled));
1897 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001898
Rodrigo Vivia031d702013-10-03 16:15:06 -03001899 enabled = HAS_PSR(dev) &&
1900 I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
Rodrigo Vivi5755c782014-06-12 10:16:45 -07001901 seq_printf(m, "HW Enabled & Active bit: %s\n", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001902
Rodrigo Vivia031d702013-10-03 16:15:06 -03001903 if (HAS_PSR(dev))
1904 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
1905 EDP_PSR_PERF_CNT_MASK;
1906 seq_printf(m, "Performance_Counter: %u\n", psrperf);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001907
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001908 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001909 return 0;
1910}
1911
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02001912static int i915_sink_crc(struct seq_file *m, void *data)
1913{
1914 struct drm_info_node *node = m->private;
1915 struct drm_device *dev = node->minor->dev;
1916 struct intel_encoder *encoder;
1917 struct intel_connector *connector;
1918 struct intel_dp *intel_dp = NULL;
1919 int ret;
1920 u8 crc[6];
1921
1922 drm_modeset_lock_all(dev);
1923 list_for_each_entry(connector, &dev->mode_config.connector_list,
1924 base.head) {
1925
1926 if (connector->base.dpms != DRM_MODE_DPMS_ON)
1927 continue;
1928
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02001929 if (!connector->base.encoder)
1930 continue;
1931
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02001932 encoder = to_intel_encoder(connector->base.encoder);
1933 if (encoder->type != INTEL_OUTPUT_EDP)
1934 continue;
1935
1936 intel_dp = enc_to_intel_dp(&encoder->base);
1937
1938 ret = intel_dp_sink_crc(intel_dp, crc);
1939 if (ret)
1940 goto out;
1941
1942 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
1943 crc[0], crc[1], crc[2],
1944 crc[3], crc[4], crc[5]);
1945 goto out;
1946 }
1947 ret = -ENODEV;
1948out:
1949 drm_modeset_unlock_all(dev);
1950 return ret;
1951}
1952
Jesse Barnesec013e72013-08-20 10:29:23 +01001953static int i915_energy_uJ(struct seq_file *m, void *data)
1954{
1955 struct drm_info_node *node = m->private;
1956 struct drm_device *dev = node->minor->dev;
1957 struct drm_i915_private *dev_priv = dev->dev_private;
1958 u64 power;
1959 u32 units;
1960
1961 if (INTEL_INFO(dev)->gen < 6)
1962 return -ENODEV;
1963
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001964 intel_runtime_pm_get(dev_priv);
1965
Jesse Barnesec013e72013-08-20 10:29:23 +01001966 rdmsrl(MSR_RAPL_POWER_UNIT, power);
1967 power = (power & 0x1f00) >> 8;
1968 units = 1000000 / (1 << power); /* convert to uJ */
1969 power = I915_READ(MCH_SECP_NRG_STTS);
1970 power *= units;
1971
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001972 intel_runtime_pm_put(dev_priv);
1973
Jesse Barnesec013e72013-08-20 10:29:23 +01001974 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03001975
1976 return 0;
1977}
1978
1979static int i915_pc8_status(struct seq_file *m, void *unused)
1980{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001981 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03001982 struct drm_device *dev = node->minor->dev;
1983 struct drm_i915_private *dev_priv = dev->dev_private;
1984
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03001985 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03001986 seq_puts(m, "not supported\n");
1987 return 0;
1988 }
1989
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03001990 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03001991 seq_printf(m, "IRQs disabled: %s\n",
Paulo Zanoni5d584b22014-03-07 20:08:15 -03001992 yesno(dev_priv->pm.irqs_disabled));
Paulo Zanoni371db662013-08-19 13:18:10 -03001993
Jesse Barnesec013e72013-08-20 10:29:23 +01001994 return 0;
1995}
1996
Imre Deak1da51582013-11-25 17:15:35 +02001997static const char *power_domain_str(enum intel_display_power_domain domain)
1998{
1999 switch (domain) {
2000 case POWER_DOMAIN_PIPE_A:
2001 return "PIPE_A";
2002 case POWER_DOMAIN_PIPE_B:
2003 return "PIPE_B";
2004 case POWER_DOMAIN_PIPE_C:
2005 return "PIPE_C";
2006 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2007 return "PIPE_A_PANEL_FITTER";
2008 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2009 return "PIPE_B_PANEL_FITTER";
2010 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2011 return "PIPE_C_PANEL_FITTER";
2012 case POWER_DOMAIN_TRANSCODER_A:
2013 return "TRANSCODER_A";
2014 case POWER_DOMAIN_TRANSCODER_B:
2015 return "TRANSCODER_B";
2016 case POWER_DOMAIN_TRANSCODER_C:
2017 return "TRANSCODER_C";
2018 case POWER_DOMAIN_TRANSCODER_EDP:
2019 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002020 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2021 return "PORT_DDI_A_2_LANES";
2022 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2023 return "PORT_DDI_A_4_LANES";
2024 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2025 return "PORT_DDI_B_2_LANES";
2026 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2027 return "PORT_DDI_B_4_LANES";
2028 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2029 return "PORT_DDI_C_2_LANES";
2030 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2031 return "PORT_DDI_C_4_LANES";
2032 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2033 return "PORT_DDI_D_2_LANES";
2034 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2035 return "PORT_DDI_D_4_LANES";
2036 case POWER_DOMAIN_PORT_DSI:
2037 return "PORT_DSI";
2038 case POWER_DOMAIN_PORT_CRT:
2039 return "PORT_CRT";
2040 case POWER_DOMAIN_PORT_OTHER:
2041 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002042 case POWER_DOMAIN_VGA:
2043 return "VGA";
2044 case POWER_DOMAIN_AUDIO:
2045 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002046 case POWER_DOMAIN_PLLS:
2047 return "PLLS";
Imre Deak1da51582013-11-25 17:15:35 +02002048 case POWER_DOMAIN_INIT:
2049 return "INIT";
2050 default:
2051 WARN_ON(1);
2052 return "?";
2053 }
2054}
2055
2056static int i915_power_domain_info(struct seq_file *m, void *unused)
2057{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002058 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002059 struct drm_device *dev = node->minor->dev;
2060 struct drm_i915_private *dev_priv = dev->dev_private;
2061 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2062 int i;
2063
2064 mutex_lock(&power_domains->lock);
2065
2066 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2067 for (i = 0; i < power_domains->power_well_count; i++) {
2068 struct i915_power_well *power_well;
2069 enum intel_display_power_domain power_domain;
2070
2071 power_well = &power_domains->power_wells[i];
2072 seq_printf(m, "%-25s %d\n", power_well->name,
2073 power_well->count);
2074
2075 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2076 power_domain++) {
2077 if (!(BIT(power_domain) & power_well->domains))
2078 continue;
2079
2080 seq_printf(m, " %-23s %d\n",
2081 power_domain_str(power_domain),
2082 power_domains->domain_use_count[power_domain]);
2083 }
2084 }
2085
2086 mutex_unlock(&power_domains->lock);
2087
2088 return 0;
2089}
2090
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002091static void intel_seq_print_mode(struct seq_file *m, int tabs,
2092 struct drm_display_mode *mode)
2093{
2094 int i;
2095
2096 for (i = 0; i < tabs; i++)
2097 seq_putc(m, '\t');
2098
2099 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",
2100 mode->base.id, mode->name,
2101 mode->vrefresh, mode->clock,
2102 mode->hdisplay, mode->hsync_start,
2103 mode->hsync_end, mode->htotal,
2104 mode->vdisplay, mode->vsync_start,
2105 mode->vsync_end, mode->vtotal,
2106 mode->type, mode->flags);
2107}
2108
2109static void intel_encoder_info(struct seq_file *m,
2110 struct intel_crtc *intel_crtc,
2111 struct intel_encoder *intel_encoder)
2112{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002113 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002114 struct drm_device *dev = node->minor->dev;
2115 struct drm_crtc *crtc = &intel_crtc->base;
2116 struct intel_connector *intel_connector;
2117 struct drm_encoder *encoder;
2118
2119 encoder = &intel_encoder->base;
2120 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a02014-06-03 14:56:21 +03002121 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002122 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2123 struct drm_connector *connector = &intel_connector->base;
2124 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2125 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002126 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002127 drm_get_connector_status_name(connector->status));
2128 if (connector->status == connector_status_connected) {
2129 struct drm_display_mode *mode = &crtc->mode;
2130 seq_printf(m, ", mode:\n");
2131 intel_seq_print_mode(m, 2, mode);
2132 } else {
2133 seq_putc(m, '\n');
2134 }
2135 }
2136}
2137
2138static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2139{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002140 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002141 struct drm_device *dev = node->minor->dev;
2142 struct drm_crtc *crtc = &intel_crtc->base;
2143 struct intel_encoder *intel_encoder;
2144
Matt Roper5aa8a932014-06-16 10:12:55 -07002145 if (crtc->primary->fb)
2146 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2147 crtc->primary->fb->base.id, crtc->x, crtc->y,
2148 crtc->primary->fb->width, crtc->primary->fb->height);
2149 else
2150 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002151 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2152 intel_encoder_info(m, intel_crtc, intel_encoder);
2153}
2154
2155static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2156{
2157 struct drm_display_mode *mode = panel->fixed_mode;
2158
2159 seq_printf(m, "\tfixed mode:\n");
2160 intel_seq_print_mode(m, 2, mode);
2161}
2162
2163static void intel_dp_info(struct seq_file *m,
2164 struct intel_connector *intel_connector)
2165{
2166 struct intel_encoder *intel_encoder = intel_connector->encoder;
2167 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2168
2169 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2170 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2171 "no");
2172 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2173 intel_panel_info(m, &intel_connector->panel);
2174}
2175
2176static void intel_hdmi_info(struct seq_file *m,
2177 struct intel_connector *intel_connector)
2178{
2179 struct intel_encoder *intel_encoder = intel_connector->encoder;
2180 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2181
2182 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2183 "no");
2184}
2185
2186static void intel_lvds_info(struct seq_file *m,
2187 struct intel_connector *intel_connector)
2188{
2189 intel_panel_info(m, &intel_connector->panel);
2190}
2191
2192static void intel_connector_info(struct seq_file *m,
2193 struct drm_connector *connector)
2194{
2195 struct intel_connector *intel_connector = to_intel_connector(connector);
2196 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002197 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002198
2199 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002200 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002201 drm_get_connector_status_name(connector->status));
2202 if (connector->status == connector_status_connected) {
2203 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2204 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2205 connector->display_info.width_mm,
2206 connector->display_info.height_mm);
2207 seq_printf(m, "\tsubpixel order: %s\n",
2208 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2209 seq_printf(m, "\tCEA rev: %d\n",
2210 connector->display_info.cea_rev);
2211 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002212 if (intel_encoder) {
2213 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2214 intel_encoder->type == INTEL_OUTPUT_EDP)
2215 intel_dp_info(m, intel_connector);
2216 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2217 intel_hdmi_info(m, intel_connector);
2218 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2219 intel_lvds_info(m, intel_connector);
2220 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002221
Jesse Barnesf103fc72014-02-20 12:39:57 -08002222 seq_printf(m, "\tmodes:\n");
2223 list_for_each_entry(mode, &connector->modes, head)
2224 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002225}
2226
Chris Wilson065f2ec2014-03-12 09:13:13 +00002227static bool cursor_active(struct drm_device *dev, int pipe)
2228{
2229 struct drm_i915_private *dev_priv = dev->dev_private;
2230 u32 state;
2231
2232 if (IS_845G(dev) || IS_I865G(dev))
2233 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002234 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002235 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002236
2237 return state;
2238}
2239
2240static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2241{
2242 struct drm_i915_private *dev_priv = dev->dev_private;
2243 u32 pos;
2244
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002245 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002246
2247 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2248 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2249 *x = -*x;
2250
2251 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2252 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2253 *y = -*y;
2254
2255 return cursor_active(dev, pipe);
2256}
2257
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002258static int i915_display_info(struct seq_file *m, void *unused)
2259{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002260 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002261 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002262 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002263 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002264 struct drm_connector *connector;
2265
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002266 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002267 drm_modeset_lock_all(dev);
2268 seq_printf(m, "CRTC info\n");
2269 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002270 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002271 bool active;
2272 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002273
Chris Wilson57127ef2014-07-04 08:20:11 +01002274 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002275 crtc->base.base.id, pipe_name(crtc->pipe),
Chris Wilson57127ef2014-07-04 08:20:11 +01002276 yesno(crtc->active), crtc->config.pipe_src_w, crtc->config.pipe_src_h);
Paulo Zanonia23dc652014-04-01 14:55:11 -03002277 if (crtc->active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002278 intel_crtc_info(m, crtc);
2279
Paulo Zanonia23dc652014-04-01 14:55:11 -03002280 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002281 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 +03002282 yesno(crtc->cursor_base),
Chris Wilson57127ef2014-07-04 08:20:11 +01002283 x, y, crtc->cursor_width, crtc->cursor_height,
2284 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002285 }
Daniel Vettercace8412014-05-22 17:56:31 +02002286
2287 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2288 yesno(!crtc->cpu_fifo_underrun_disabled),
2289 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002290 }
2291
2292 seq_printf(m, "\n");
2293 seq_printf(m, "Connector info\n");
2294 seq_printf(m, "--------------\n");
2295 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2296 intel_connector_info(m, connector);
2297 }
2298 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002299 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002300
2301 return 0;
2302}
2303
Ben Widawskye04934c2014-06-30 09:53:42 -07002304static int i915_semaphore_status(struct seq_file *m, void *unused)
2305{
2306 struct drm_info_node *node = (struct drm_info_node *) m->private;
2307 struct drm_device *dev = node->minor->dev;
2308 struct drm_i915_private *dev_priv = dev->dev_private;
2309 struct intel_engine_cs *ring;
2310 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2311 int i, j, ret;
2312
2313 if (!i915_semaphore_is_enabled(dev)) {
2314 seq_puts(m, "Semaphores are disabled\n");
2315 return 0;
2316 }
2317
2318 ret = mutex_lock_interruptible(&dev->struct_mutex);
2319 if (ret)
2320 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002321 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002322
2323 if (IS_BROADWELL(dev)) {
2324 struct page *page;
2325 uint64_t *seqno;
2326
2327 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2328
2329 seqno = (uint64_t *)kmap_atomic(page);
2330 for_each_ring(ring, dev_priv, i) {
2331 uint64_t offset;
2332
2333 seq_printf(m, "%s\n", ring->name);
2334
2335 seq_puts(m, " Last signal:");
2336 for (j = 0; j < num_rings; j++) {
2337 offset = i * I915_NUM_RINGS + j;
2338 seq_printf(m, "0x%08llx (0x%02llx) ",
2339 seqno[offset], offset * 8);
2340 }
2341 seq_putc(m, '\n');
2342
2343 seq_puts(m, " Last wait: ");
2344 for (j = 0; j < num_rings; j++) {
2345 offset = i + (j * I915_NUM_RINGS);
2346 seq_printf(m, "0x%08llx (0x%02llx) ",
2347 seqno[offset], offset * 8);
2348 }
2349 seq_putc(m, '\n');
2350
2351 }
2352 kunmap_atomic(seqno);
2353 } else {
2354 seq_puts(m, " Last signal:");
2355 for_each_ring(ring, dev_priv, i)
2356 for (j = 0; j < num_rings; j++)
2357 seq_printf(m, "0x%08x\n",
2358 I915_READ(ring->semaphore.mbox.signal[j]));
2359 seq_putc(m, '\n');
2360 }
2361
2362 seq_puts(m, "\nSync seqno:\n");
2363 for_each_ring(ring, dev_priv, i) {
2364 for (j = 0; j < num_rings; j++) {
2365 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2366 }
2367 seq_putc(m, '\n');
2368 }
2369 seq_putc(m, '\n');
2370
Paulo Zanoni03872062014-07-09 14:31:57 -03002371 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002372 mutex_unlock(&dev->struct_mutex);
2373 return 0;
2374}
2375
Daniel Vetter728e29d2014-06-25 22:01:53 +03002376static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2377{
2378 struct drm_info_node *node = (struct drm_info_node *) m->private;
2379 struct drm_device *dev = node->minor->dev;
2380 struct drm_i915_private *dev_priv = dev->dev_private;
2381 int i;
2382
2383 drm_modeset_lock_all(dev);
2384 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2385 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2386
2387 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
2388 seq_printf(m, " refcount: %i, active: %i, on: %s\n", pll->refcount,
2389 pll->active, yesno(pll->on));
2390 seq_printf(m, " tracked hardware state:\n");
2391 seq_printf(m, " dpll: 0x%08x\n", pll->hw_state.dpll);
2392 seq_printf(m, " dpll_md: 0x%08x\n", pll->hw_state.dpll_md);
2393 seq_printf(m, " fp0: 0x%08x\n", pll->hw_state.fp0);
2394 seq_printf(m, " fp1: 0x%08x\n", pll->hw_state.fp1);
Daniel Vetterd452c5b2014-07-04 11:27:39 -03002395 seq_printf(m, " wrpll: 0x%08x\n", pll->hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002396 }
2397 drm_modeset_unlock_all(dev);
2398
2399 return 0;
2400}
2401
Damien Lespiau07144422013-10-15 18:55:40 +01002402struct pipe_crc_info {
2403 const char *name;
2404 struct drm_device *dev;
2405 enum pipe pipe;
2406};
2407
2408static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01002409{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002410 struct pipe_crc_info *info = inode->i_private;
2411 struct drm_i915_private *dev_priv = info->dev->dev_private;
2412 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2413
Daniel Vetter7eb1c492013-11-14 11:30:43 +01002414 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
2415 return -ENODEV;
2416
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002417 spin_lock_irq(&pipe_crc->lock);
2418
2419 if (pipe_crc->opened) {
2420 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002421 return -EBUSY; /* already open */
2422 }
2423
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002424 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01002425 filep->private_data = inode->i_private;
2426
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002427 spin_unlock_irq(&pipe_crc->lock);
2428
Damien Lespiau07144422013-10-15 18:55:40 +01002429 return 0;
2430}
2431
2432static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
2433{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002434 struct pipe_crc_info *info = inode->i_private;
2435 struct drm_i915_private *dev_priv = info->dev->dev_private;
2436 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2437
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002438 spin_lock_irq(&pipe_crc->lock);
2439 pipe_crc->opened = false;
2440 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002441
Damien Lespiau07144422013-10-15 18:55:40 +01002442 return 0;
2443}
2444
2445/* (6 fields, 8 chars each, space separated (5) + '\n') */
2446#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
2447/* account for \'0' */
2448#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
2449
2450static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
2451{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002452 assert_spin_locked(&pipe_crc->lock);
2453 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2454 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01002455}
Shuang He8bf1e9f2013-10-15 18:55:27 +01002456
Damien Lespiau07144422013-10-15 18:55:40 +01002457static ssize_t
2458i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
2459 loff_t *pos)
2460{
2461 struct pipe_crc_info *info = filep->private_data;
2462 struct drm_device *dev = info->dev;
2463 struct drm_i915_private *dev_priv = dev->dev_private;
2464 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2465 char buf[PIPE_CRC_BUFFER_LEN];
2466 int head, tail, n_entries, n;
2467 ssize_t bytes_read;
2468
2469 /*
2470 * Don't allow user space to provide buffers not big enough to hold
2471 * a line of data.
2472 */
2473 if (count < PIPE_CRC_LINE_LEN)
2474 return -EINVAL;
2475
2476 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2477 return 0;
2478
2479 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002480 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002481 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002482 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002483
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002484 if (filep->f_flags & O_NONBLOCK) {
2485 spin_unlock_irq(&pipe_crc->lock);
2486 return -EAGAIN;
2487 }
2488
2489 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2490 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2491 if (ret) {
2492 spin_unlock_irq(&pipe_crc->lock);
2493 return ret;
2494 }
Damien Lespiau07144422013-10-15 18:55:40 +01002495 }
2496
2497 /* We now have one or more entries to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002498 head = pipe_crc->head;
2499 tail = pipe_crc->tail;
Damien Lespiau07144422013-10-15 18:55:40 +01002500 n_entries = min((size_t)CIRC_CNT(head, tail, INTEL_PIPE_CRC_ENTRIES_NR),
2501 count / PIPE_CRC_LINE_LEN);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002502 spin_unlock_irq(&pipe_crc->lock);
2503
Damien Lespiau07144422013-10-15 18:55:40 +01002504 bytes_read = 0;
2505 n = 0;
2506 do {
2507 struct intel_pipe_crc_entry *entry = &pipe_crc->entries[tail];
2508 int ret;
2509
2510 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
2511 "%8u %8x %8x %8x %8x %8x\n",
2512 entry->frame, entry->crc[0],
2513 entry->crc[1], entry->crc[2],
2514 entry->crc[3], entry->crc[4]);
2515
2516 ret = copy_to_user(user_buf + n * PIPE_CRC_LINE_LEN,
2517 buf, PIPE_CRC_LINE_LEN);
2518 if (ret == PIPE_CRC_LINE_LEN)
2519 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01002520
2521 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
2522 tail = (tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiau07144422013-10-15 18:55:40 +01002523 n++;
2524 } while (--n_entries);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002525
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002526 spin_lock_irq(&pipe_crc->lock);
2527 pipe_crc->tail = tail;
2528 spin_unlock_irq(&pipe_crc->lock);
2529
Damien Lespiau07144422013-10-15 18:55:40 +01002530 return bytes_read;
2531}
2532
2533static const struct file_operations i915_pipe_crc_fops = {
2534 .owner = THIS_MODULE,
2535 .open = i915_pipe_crc_open,
2536 .read = i915_pipe_crc_read,
2537 .release = i915_pipe_crc_release,
2538};
2539
2540static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
2541 {
2542 .name = "i915_pipe_A_crc",
2543 .pipe = PIPE_A,
2544 },
2545 {
2546 .name = "i915_pipe_B_crc",
2547 .pipe = PIPE_B,
2548 },
2549 {
2550 .name = "i915_pipe_C_crc",
2551 .pipe = PIPE_C,
2552 },
2553};
2554
2555static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
2556 enum pipe pipe)
2557{
2558 struct drm_device *dev = minor->dev;
2559 struct dentry *ent;
2560 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
2561
2562 info->dev = dev;
2563 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
2564 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08002565 if (!ent)
2566 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01002567
2568 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002569}
2570
Daniel Vettere8dfcf72013-10-16 11:51:54 +02002571static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02002572 "none",
2573 "plane1",
2574 "plane2",
2575 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002576 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02002577 "TV",
2578 "DP-B",
2579 "DP-C",
2580 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01002581 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02002582};
2583
2584static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
2585{
2586 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
2587 return pipe_crc_sources[source];
2588}
2589
Damien Lespiaubd9db022013-10-15 18:55:36 +01002590static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02002591{
2592 struct drm_device *dev = m->private;
2593 struct drm_i915_private *dev_priv = dev->dev_private;
2594 int i;
2595
2596 for (i = 0; i < I915_MAX_PIPES; i++)
2597 seq_printf(m, "%c %s\n", pipe_name(i),
2598 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
2599
2600 return 0;
2601}
2602
Damien Lespiaubd9db022013-10-15 18:55:36 +01002603static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02002604{
2605 struct drm_device *dev = inode->i_private;
2606
Damien Lespiaubd9db022013-10-15 18:55:36 +01002607 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02002608}
2609
Daniel Vetter46a19182013-11-01 10:50:20 +01002610static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02002611 uint32_t *val)
2612{
Daniel Vetter46a19182013-11-01 10:50:20 +01002613 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2614 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2615
2616 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02002617 case INTEL_PIPE_CRC_SOURCE_PIPE:
2618 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
2619 break;
2620 case INTEL_PIPE_CRC_SOURCE_NONE:
2621 *val = 0;
2622 break;
2623 default:
2624 return -EINVAL;
2625 }
2626
2627 return 0;
2628}
2629
Daniel Vetter46a19182013-11-01 10:50:20 +01002630static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
2631 enum intel_pipe_crc_source *source)
2632{
2633 struct intel_encoder *encoder;
2634 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01002635 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01002636 int ret = 0;
2637
2638 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2639
Daniel Vetter6e9f7982014-05-29 23:54:47 +02002640 drm_modeset_lock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01002641 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
2642 base.head) {
2643 if (!encoder->base.crtc)
2644 continue;
2645
2646 crtc = to_intel_crtc(encoder->base.crtc);
2647
2648 if (crtc->pipe != pipe)
2649 continue;
2650
2651 switch (encoder->type) {
2652 case INTEL_OUTPUT_TVOUT:
2653 *source = INTEL_PIPE_CRC_SOURCE_TV;
2654 break;
2655 case INTEL_OUTPUT_DISPLAYPORT:
2656 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01002657 dig_port = enc_to_dig_port(&encoder->base);
2658 switch (dig_port->port) {
2659 case PORT_B:
2660 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
2661 break;
2662 case PORT_C:
2663 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
2664 break;
2665 case PORT_D:
2666 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
2667 break;
2668 default:
2669 WARN(1, "nonexisting DP port %c\n",
2670 port_name(dig_port->port));
2671 break;
2672 }
Daniel Vetter46a19182013-11-01 10:50:20 +01002673 break;
2674 }
2675 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02002676 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01002677
2678 return ret;
2679}
2680
2681static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
2682 enum pipe pipe,
2683 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02002684 uint32_t *val)
2685{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002686 struct drm_i915_private *dev_priv = dev->dev_private;
2687 bool need_stable_symbols = false;
2688
Daniel Vetter46a19182013-11-01 10:50:20 +01002689 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2690 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2691 if (ret)
2692 return ret;
2693 }
2694
2695 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02002696 case INTEL_PIPE_CRC_SOURCE_PIPE:
2697 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
2698 break;
2699 case INTEL_PIPE_CRC_SOURCE_DP_B:
2700 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002701 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002702 break;
2703 case INTEL_PIPE_CRC_SOURCE_DP_C:
2704 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002705 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002706 break;
2707 case INTEL_PIPE_CRC_SOURCE_NONE:
2708 *val = 0;
2709 break;
2710 default:
2711 return -EINVAL;
2712 }
2713
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002714 /*
2715 * When the pipe CRC tap point is after the transcoders we need
2716 * to tweak symbol-level features to produce a deterministic series of
2717 * symbols for a given frame. We need to reset those features only once
2718 * a frame (instead of every nth symbol):
2719 * - DC-balance: used to ensure a better clock recovery from the data
2720 * link (SDVO)
2721 * - DisplayPort scrambling: used for EMI reduction
2722 */
2723 if (need_stable_symbols) {
2724 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2725
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002726 tmp |= DC_BALANCE_RESET_VLV;
2727 if (pipe == PIPE_A)
2728 tmp |= PIPE_A_SCRAMBLE_RESET;
2729 else
2730 tmp |= PIPE_B_SCRAMBLE_RESET;
2731
2732 I915_WRITE(PORT_DFT2_G4X, tmp);
2733 }
2734
Daniel Vetter7ac01292013-10-18 16:37:06 +02002735 return 0;
2736}
2737
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002738static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01002739 enum pipe pipe,
2740 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002741 uint32_t *val)
2742{
Daniel Vetter84093602013-11-01 10:50:21 +01002743 struct drm_i915_private *dev_priv = dev->dev_private;
2744 bool need_stable_symbols = false;
2745
Daniel Vetter46a19182013-11-01 10:50:20 +01002746 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2747 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2748 if (ret)
2749 return ret;
2750 }
2751
2752 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002753 case INTEL_PIPE_CRC_SOURCE_PIPE:
2754 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
2755 break;
2756 case INTEL_PIPE_CRC_SOURCE_TV:
2757 if (!SUPPORTS_TV(dev))
2758 return -EINVAL;
2759 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
2760 break;
2761 case INTEL_PIPE_CRC_SOURCE_DP_B:
2762 if (!IS_G4X(dev))
2763 return -EINVAL;
2764 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002765 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002766 break;
2767 case INTEL_PIPE_CRC_SOURCE_DP_C:
2768 if (!IS_G4X(dev))
2769 return -EINVAL;
2770 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002771 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002772 break;
2773 case INTEL_PIPE_CRC_SOURCE_DP_D:
2774 if (!IS_G4X(dev))
2775 return -EINVAL;
2776 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002777 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002778 break;
2779 case INTEL_PIPE_CRC_SOURCE_NONE:
2780 *val = 0;
2781 break;
2782 default:
2783 return -EINVAL;
2784 }
2785
Daniel Vetter84093602013-11-01 10:50:21 +01002786 /*
2787 * When the pipe CRC tap point is after the transcoders we need
2788 * to tweak symbol-level features to produce a deterministic series of
2789 * symbols for a given frame. We need to reset those features only once
2790 * a frame (instead of every nth symbol):
2791 * - DC-balance: used to ensure a better clock recovery from the data
2792 * link (SDVO)
2793 * - DisplayPort scrambling: used for EMI reduction
2794 */
2795 if (need_stable_symbols) {
2796 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2797
2798 WARN_ON(!IS_G4X(dev));
2799
2800 I915_WRITE(PORT_DFT_I9XX,
2801 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
2802
2803 if (pipe == PIPE_A)
2804 tmp |= PIPE_A_SCRAMBLE_RESET;
2805 else
2806 tmp |= PIPE_B_SCRAMBLE_RESET;
2807
2808 I915_WRITE(PORT_DFT2_G4X, tmp);
2809 }
2810
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002811 return 0;
2812}
2813
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002814static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
2815 enum pipe pipe)
2816{
2817 struct drm_i915_private *dev_priv = dev->dev_private;
2818 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2819
2820 if (pipe == PIPE_A)
2821 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2822 else
2823 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2824 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
2825 tmp &= ~DC_BALANCE_RESET_VLV;
2826 I915_WRITE(PORT_DFT2_G4X, tmp);
2827
2828}
2829
Daniel Vetter84093602013-11-01 10:50:21 +01002830static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
2831 enum pipe pipe)
2832{
2833 struct drm_i915_private *dev_priv = dev->dev_private;
2834 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2835
2836 if (pipe == PIPE_A)
2837 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2838 else
2839 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2840 I915_WRITE(PORT_DFT2_G4X, tmp);
2841
2842 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
2843 I915_WRITE(PORT_DFT_I9XX,
2844 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
2845 }
2846}
2847
Daniel Vetter46a19182013-11-01 10:50:20 +01002848static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002849 uint32_t *val)
2850{
Daniel Vetter46a19182013-11-01 10:50:20 +01002851 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2852 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2853
2854 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002855 case INTEL_PIPE_CRC_SOURCE_PLANE1:
2856 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
2857 break;
2858 case INTEL_PIPE_CRC_SOURCE_PLANE2:
2859 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
2860 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002861 case INTEL_PIPE_CRC_SOURCE_PIPE:
2862 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
2863 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002864 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002865 *val = 0;
2866 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002867 default:
2868 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002869 }
2870
2871 return 0;
2872}
2873
Daniel Vetterfabf6e52014-05-29 14:10:22 +02002874static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
2875{
2876 struct drm_i915_private *dev_priv = dev->dev_private;
2877 struct intel_crtc *crtc =
2878 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
2879
2880 drm_modeset_lock_all(dev);
2881 /*
2882 * If we use the eDP transcoder we need to make sure that we don't
2883 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
2884 * relevant on hsw with pipe A when using the always-on power well
2885 * routing.
2886 */
2887 if (crtc->config.cpu_transcoder == TRANSCODER_EDP &&
2888 !crtc->config.pch_pfit.enabled) {
2889 crtc->config.pch_pfit.force_thru = true;
2890
2891 intel_display_power_get(dev_priv,
2892 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
2893
2894 dev_priv->display.crtc_disable(&crtc->base);
2895 dev_priv->display.crtc_enable(&crtc->base);
2896 }
2897 drm_modeset_unlock_all(dev);
2898}
2899
2900static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
2901{
2902 struct drm_i915_private *dev_priv = dev->dev_private;
2903 struct intel_crtc *crtc =
2904 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
2905
2906 drm_modeset_lock_all(dev);
2907 /*
2908 * If we use the eDP transcoder we need to make sure that we don't
2909 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
2910 * relevant on hsw with pipe A when using the always-on power well
2911 * routing.
2912 */
2913 if (crtc->config.pch_pfit.force_thru) {
2914 crtc->config.pch_pfit.force_thru = false;
2915
2916 dev_priv->display.crtc_disable(&crtc->base);
2917 dev_priv->display.crtc_enable(&crtc->base);
2918
2919 intel_display_power_put(dev_priv,
2920 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
2921 }
2922 drm_modeset_unlock_all(dev);
2923}
2924
2925static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
2926 enum pipe pipe,
2927 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002928 uint32_t *val)
2929{
Daniel Vetter46a19182013-11-01 10:50:20 +01002930 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2931 *source = INTEL_PIPE_CRC_SOURCE_PF;
2932
2933 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002934 case INTEL_PIPE_CRC_SOURCE_PLANE1:
2935 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
2936 break;
2937 case INTEL_PIPE_CRC_SOURCE_PLANE2:
2938 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
2939 break;
2940 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02002941 if (IS_HASWELL(dev) && pipe == PIPE_A)
2942 hsw_trans_edp_pipe_A_crc_wa(dev);
2943
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002944 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
2945 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002946 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002947 *val = 0;
2948 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002949 default:
2950 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002951 }
2952
2953 return 0;
2954}
2955
Daniel Vetter926321d2013-10-16 13:30:34 +02002956static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
2957 enum intel_pipe_crc_source source)
2958{
2959 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01002960 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Borislav Petkov432f3342013-11-21 16:49:46 +01002961 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002962 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02002963
Damien Lespiaucc3da172013-10-15 18:55:31 +01002964 if (pipe_crc->source == source)
2965 return 0;
2966
Damien Lespiauae676fc2013-10-15 18:55:32 +01002967 /* forbid changing the source without going back to 'none' */
2968 if (pipe_crc->source && source)
2969 return -EINVAL;
2970
Daniel Vetter52f843f2013-10-21 17:26:38 +02002971 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002972 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02002973 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01002974 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02002975 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02002976 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002977 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002978 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002979 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02002980 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002981
2982 if (ret != 0)
2983 return ret;
2984
Damien Lespiau4b584362013-10-15 18:55:33 +01002985 /* none -> real source transition */
2986 if (source) {
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01002987 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
2988 pipe_name(pipe), pipe_crc_source_name(source));
2989
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002990 pipe_crc->entries = kzalloc(sizeof(*pipe_crc->entries) *
2991 INTEL_PIPE_CRC_ENTRIES_NR,
2992 GFP_KERNEL);
2993 if (!pipe_crc->entries)
2994 return -ENOMEM;
2995
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002996 spin_lock_irq(&pipe_crc->lock);
2997 pipe_crc->head = 0;
2998 pipe_crc->tail = 0;
2999 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003000 }
3001
Damien Lespiaucc3da172013-10-15 18:55:31 +01003002 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003003
Daniel Vetter926321d2013-10-16 13:30:34 +02003004 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3005 POSTING_READ(PIPE_CRC_CTL(pipe));
3006
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003007 /* real source -> none transition */
3008 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003009 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003010 struct intel_crtc *crtc =
3011 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003012
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003013 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3014 pipe_name(pipe));
3015
Daniel Vettera33d7102014-06-06 08:22:08 +02003016 drm_modeset_lock(&crtc->base.mutex, NULL);
3017 if (crtc->active)
3018 intel_wait_for_vblank(dev, pipe);
3019 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003020
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003021 spin_lock_irq(&pipe_crc->lock);
3022 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003023 pipe_crc->entries = NULL;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003024 spin_unlock_irq(&pipe_crc->lock);
3025
3026 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003027
3028 if (IS_G4X(dev))
3029 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003030 else if (IS_VALLEYVIEW(dev))
3031 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003032 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3033 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003034 }
3035
Daniel Vetter926321d2013-10-16 13:30:34 +02003036 return 0;
3037}
3038
3039/*
3040 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003041 * command: wsp* object wsp+ name wsp+ source wsp*
3042 * object: 'pipe'
3043 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003044 * source: (none | plane1 | plane2 | pf)
3045 * wsp: (#0x20 | #0x9 | #0xA)+
3046 *
3047 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003048 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3049 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003050 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003051static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003052{
3053 int n_words = 0;
3054
3055 while (*buf) {
3056 char *end;
3057
3058 /* skip leading white space */
3059 buf = skip_spaces(buf);
3060 if (!*buf)
3061 break; /* end of buffer */
3062
3063 /* find end of word */
3064 for (end = buf; *end && !isspace(*end); end++)
3065 ;
3066
3067 if (n_words == max_words) {
3068 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3069 max_words);
3070 return -EINVAL; /* ran out of words[] before bytes */
3071 }
3072
3073 if (*end)
3074 *end++ = '\0';
3075 words[n_words++] = buf;
3076 buf = end;
3077 }
3078
3079 return n_words;
3080}
3081
Damien Lespiaub94dec82013-10-15 18:55:35 +01003082enum intel_pipe_crc_object {
3083 PIPE_CRC_OBJECT_PIPE,
3084};
3085
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003086static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003087 "pipe",
3088};
3089
3090static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003091display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003092{
3093 int i;
3094
3095 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3096 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003097 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003098 return 0;
3099 }
3100
3101 return -EINVAL;
3102}
3103
Damien Lespiaubd9db022013-10-15 18:55:36 +01003104static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003105{
3106 const char name = buf[0];
3107
3108 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3109 return -EINVAL;
3110
3111 *pipe = name - 'A';
3112
3113 return 0;
3114}
3115
3116static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003117display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003118{
3119 int i;
3120
3121 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3122 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003123 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003124 return 0;
3125 }
3126
3127 return -EINVAL;
3128}
3129
Damien Lespiaubd9db022013-10-15 18:55:36 +01003130static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003131{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003132#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003133 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003134 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003135 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003136 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003137 enum intel_pipe_crc_source source;
3138
Damien Lespiaubd9db022013-10-15 18:55:36 +01003139 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003140 if (n_words != N_WORDS) {
3141 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3142 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003143 return -EINVAL;
3144 }
3145
Damien Lespiaubd9db022013-10-15 18:55:36 +01003146 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003147 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003148 return -EINVAL;
3149 }
3150
Damien Lespiaubd9db022013-10-15 18:55:36 +01003151 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003152 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3153 return -EINVAL;
3154 }
3155
Damien Lespiaubd9db022013-10-15 18:55:36 +01003156 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003157 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003158 return -EINVAL;
3159 }
3160
3161 return pipe_crc_set_source(dev, pipe, source);
3162}
3163
Damien Lespiaubd9db022013-10-15 18:55:36 +01003164static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3165 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003166{
3167 struct seq_file *m = file->private_data;
3168 struct drm_device *dev = m->private;
3169 char *tmpbuf;
3170 int ret;
3171
3172 if (len == 0)
3173 return 0;
3174
3175 if (len > PAGE_SIZE - 1) {
3176 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3177 PAGE_SIZE);
3178 return -E2BIG;
3179 }
3180
3181 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3182 if (!tmpbuf)
3183 return -ENOMEM;
3184
3185 if (copy_from_user(tmpbuf, ubuf, len)) {
3186 ret = -EFAULT;
3187 goto out;
3188 }
3189 tmpbuf[len] = '\0';
3190
Damien Lespiaubd9db022013-10-15 18:55:36 +01003191 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003192
3193out:
3194 kfree(tmpbuf);
3195 if (ret < 0)
3196 return ret;
3197
3198 *offp += len;
3199 return len;
3200}
3201
Damien Lespiaubd9db022013-10-15 18:55:36 +01003202static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003203 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003204 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003205 .read = seq_read,
3206 .llseek = seq_lseek,
3207 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003208 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003209};
3210
Ville Syrjälä369a1342014-01-22 14:36:08 +02003211static void wm_latency_show(struct seq_file *m, const uint16_t wm[5])
3212{
3213 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003214 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003215 int level;
3216
3217 drm_modeset_lock_all(dev);
3218
3219 for (level = 0; level < num_levels; level++) {
3220 unsigned int latency = wm[level];
3221
3222 /* WM1+ latency values in 0.5us units */
3223 if (level > 0)
3224 latency *= 5;
3225
3226 seq_printf(m, "WM%d %u (%u.%u usec)\n",
3227 level, wm[level],
3228 latency / 10, latency % 10);
3229 }
3230
3231 drm_modeset_unlock_all(dev);
3232}
3233
3234static int pri_wm_latency_show(struct seq_file *m, void *data)
3235{
3236 struct drm_device *dev = m->private;
3237
3238 wm_latency_show(m, to_i915(dev)->wm.pri_latency);
3239
3240 return 0;
3241}
3242
3243static int spr_wm_latency_show(struct seq_file *m, void *data)
3244{
3245 struct drm_device *dev = m->private;
3246
3247 wm_latency_show(m, to_i915(dev)->wm.spr_latency);
3248
3249 return 0;
3250}
3251
3252static int cur_wm_latency_show(struct seq_file *m, void *data)
3253{
3254 struct drm_device *dev = m->private;
3255
3256 wm_latency_show(m, to_i915(dev)->wm.cur_latency);
3257
3258 return 0;
3259}
3260
3261static int pri_wm_latency_open(struct inode *inode, struct file *file)
3262{
3263 struct drm_device *dev = inode->i_private;
3264
3265 if (!HAS_PCH_SPLIT(dev))
3266 return -ENODEV;
3267
3268 return single_open(file, pri_wm_latency_show, dev);
3269}
3270
3271static int spr_wm_latency_open(struct inode *inode, struct file *file)
3272{
3273 struct drm_device *dev = inode->i_private;
3274
3275 if (!HAS_PCH_SPLIT(dev))
3276 return -ENODEV;
3277
3278 return single_open(file, spr_wm_latency_show, dev);
3279}
3280
3281static int cur_wm_latency_open(struct inode *inode, struct file *file)
3282{
3283 struct drm_device *dev = inode->i_private;
3284
3285 if (!HAS_PCH_SPLIT(dev))
3286 return -ENODEV;
3287
3288 return single_open(file, cur_wm_latency_show, dev);
3289}
3290
3291static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
3292 size_t len, loff_t *offp, uint16_t wm[5])
3293{
3294 struct seq_file *m = file->private_data;
3295 struct drm_device *dev = m->private;
3296 uint16_t new[5] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003297 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003298 int level;
3299 int ret;
3300 char tmp[32];
3301
3302 if (len >= sizeof(tmp))
3303 return -EINVAL;
3304
3305 if (copy_from_user(tmp, ubuf, len))
3306 return -EFAULT;
3307
3308 tmp[len] = '\0';
3309
3310 ret = sscanf(tmp, "%hu %hu %hu %hu %hu", &new[0], &new[1], &new[2], &new[3], &new[4]);
3311 if (ret != num_levels)
3312 return -EINVAL;
3313
3314 drm_modeset_lock_all(dev);
3315
3316 for (level = 0; level < num_levels; level++)
3317 wm[level] = new[level];
3318
3319 drm_modeset_unlock_all(dev);
3320
3321 return len;
3322}
3323
3324
3325static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3326 size_t len, loff_t *offp)
3327{
3328 struct seq_file *m = file->private_data;
3329 struct drm_device *dev = m->private;
3330
3331 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.pri_latency);
3332}
3333
3334static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3335 size_t len, loff_t *offp)
3336{
3337 struct seq_file *m = file->private_data;
3338 struct drm_device *dev = m->private;
3339
3340 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.spr_latency);
3341}
3342
3343static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3344 size_t len, loff_t *offp)
3345{
3346 struct seq_file *m = file->private_data;
3347 struct drm_device *dev = m->private;
3348
3349 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.cur_latency);
3350}
3351
3352static const struct file_operations i915_pri_wm_latency_fops = {
3353 .owner = THIS_MODULE,
3354 .open = pri_wm_latency_open,
3355 .read = seq_read,
3356 .llseek = seq_lseek,
3357 .release = single_release,
3358 .write = pri_wm_latency_write
3359};
3360
3361static const struct file_operations i915_spr_wm_latency_fops = {
3362 .owner = THIS_MODULE,
3363 .open = spr_wm_latency_open,
3364 .read = seq_read,
3365 .llseek = seq_lseek,
3366 .release = single_release,
3367 .write = spr_wm_latency_write
3368};
3369
3370static const struct file_operations i915_cur_wm_latency_fops = {
3371 .owner = THIS_MODULE,
3372 .open = cur_wm_latency_open,
3373 .read = seq_read,
3374 .llseek = seq_lseek,
3375 .release = single_release,
3376 .write = cur_wm_latency_write
3377};
3378
Kees Cook647416f2013-03-10 14:10:06 -07003379static int
3380i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003381{
Kees Cook647416f2013-03-10 14:10:06 -07003382 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003383 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003384
Kees Cook647416f2013-03-10 14:10:06 -07003385 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003386
Kees Cook647416f2013-03-10 14:10:06 -07003387 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003388}
3389
Kees Cook647416f2013-03-10 14:10:06 -07003390static int
3391i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003392{
Kees Cook647416f2013-03-10 14:10:06 -07003393 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03003394 struct drm_i915_private *dev_priv = dev->dev_private;
3395
3396 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003397
Mika Kuoppala58174462014-02-25 17:11:26 +02003398 i915_handle_error(dev, val,
3399 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03003400
3401 intel_runtime_pm_put(dev_priv);
3402
Kees Cook647416f2013-03-10 14:10:06 -07003403 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003404}
3405
Kees Cook647416f2013-03-10 14:10:06 -07003406DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
3407 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003408 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003409
Kees Cook647416f2013-03-10 14:10:06 -07003410static int
3411i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003412{
Kees Cook647416f2013-03-10 14:10:06 -07003413 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003414 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003415
Kees Cook647416f2013-03-10 14:10:06 -07003416 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003417
Kees Cook647416f2013-03-10 14:10:06 -07003418 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003419}
3420
Kees Cook647416f2013-03-10 14:10:06 -07003421static int
3422i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003423{
Kees Cook647416f2013-03-10 14:10:06 -07003424 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003425 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003426 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003427
Kees Cook647416f2013-03-10 14:10:06 -07003428 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003429
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003430 ret = mutex_lock_interruptible(&dev->struct_mutex);
3431 if (ret)
3432 return ret;
3433
Daniel Vetter99584db2012-11-14 17:14:04 +01003434 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003435 mutex_unlock(&dev->struct_mutex);
3436
Kees Cook647416f2013-03-10 14:10:06 -07003437 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003438}
3439
Kees Cook647416f2013-03-10 14:10:06 -07003440DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
3441 i915_ring_stop_get, i915_ring_stop_set,
3442 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02003443
Chris Wilson094f9a52013-09-25 17:34:55 +01003444static int
3445i915_ring_missed_irq_get(void *data, u64 *val)
3446{
3447 struct drm_device *dev = data;
3448 struct drm_i915_private *dev_priv = dev->dev_private;
3449
3450 *val = dev_priv->gpu_error.missed_irq_rings;
3451 return 0;
3452}
3453
3454static int
3455i915_ring_missed_irq_set(void *data, u64 val)
3456{
3457 struct drm_device *dev = data;
3458 struct drm_i915_private *dev_priv = dev->dev_private;
3459 int ret;
3460
3461 /* Lock against concurrent debugfs callers */
3462 ret = mutex_lock_interruptible(&dev->struct_mutex);
3463 if (ret)
3464 return ret;
3465 dev_priv->gpu_error.missed_irq_rings = val;
3466 mutex_unlock(&dev->struct_mutex);
3467
3468 return 0;
3469}
3470
3471DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
3472 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
3473 "0x%08llx\n");
3474
3475static int
3476i915_ring_test_irq_get(void *data, u64 *val)
3477{
3478 struct drm_device *dev = data;
3479 struct drm_i915_private *dev_priv = dev->dev_private;
3480
3481 *val = dev_priv->gpu_error.test_irq_rings;
3482
3483 return 0;
3484}
3485
3486static int
3487i915_ring_test_irq_set(void *data, u64 val)
3488{
3489 struct drm_device *dev = data;
3490 struct drm_i915_private *dev_priv = dev->dev_private;
3491 int ret;
3492
3493 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
3494
3495 /* Lock against concurrent debugfs callers */
3496 ret = mutex_lock_interruptible(&dev->struct_mutex);
3497 if (ret)
3498 return ret;
3499
3500 dev_priv->gpu_error.test_irq_rings = val;
3501 mutex_unlock(&dev->struct_mutex);
3502
3503 return 0;
3504}
3505
3506DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
3507 i915_ring_test_irq_get, i915_ring_test_irq_set,
3508 "0x%08llx\n");
3509
Chris Wilsondd624af2013-01-15 12:39:35 +00003510#define DROP_UNBOUND 0x1
3511#define DROP_BOUND 0x2
3512#define DROP_RETIRE 0x4
3513#define DROP_ACTIVE 0x8
3514#define DROP_ALL (DROP_UNBOUND | \
3515 DROP_BOUND | \
3516 DROP_RETIRE | \
3517 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07003518static int
3519i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003520{
Kees Cook647416f2013-03-10 14:10:06 -07003521 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00003522
Kees Cook647416f2013-03-10 14:10:06 -07003523 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00003524}
3525
Kees Cook647416f2013-03-10 14:10:06 -07003526static int
3527i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003528{
Kees Cook647416f2013-03-10 14:10:06 -07003529 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00003530 struct drm_i915_private *dev_priv = dev->dev_private;
3531 struct drm_i915_gem_object *obj, *next;
Ben Widawskyca191b12013-07-31 17:00:14 -07003532 struct i915_address_space *vm;
3533 struct i915_vma *vma, *x;
Kees Cook647416f2013-03-10 14:10:06 -07003534 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003535
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08003536 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00003537
3538 /* No need to check and wait for gpu resets, only libdrm auto-restarts
3539 * on ioctls on -EAGAIN. */
3540 ret = mutex_lock_interruptible(&dev->struct_mutex);
3541 if (ret)
3542 return ret;
3543
3544 if (val & DROP_ACTIVE) {
3545 ret = i915_gpu_idle(dev);
3546 if (ret)
3547 goto unlock;
3548 }
3549
3550 if (val & (DROP_RETIRE | DROP_ACTIVE))
3551 i915_gem_retire_requests(dev);
3552
3553 if (val & DROP_BOUND) {
Ben Widawskyca191b12013-07-31 17:00:14 -07003554 list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
3555 list_for_each_entry_safe(vma, x, &vm->inactive_list,
3556 mm_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -08003557 if (vma->pin_count)
Ben Widawskyca191b12013-07-31 17:00:14 -07003558 continue;
Ben Widawsky31a46c92013-07-31 16:59:55 -07003559
Ben Widawskyca191b12013-07-31 17:00:14 -07003560 ret = i915_vma_unbind(vma);
3561 if (ret)
3562 goto unlock;
3563 }
Ben Widawsky31a46c92013-07-31 16:59:55 -07003564 }
Chris Wilsondd624af2013-01-15 12:39:35 +00003565 }
3566
3567 if (val & DROP_UNBOUND) {
Ben Widawsky35c20a62013-05-31 11:28:48 -07003568 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list,
3569 global_list)
Chris Wilsondd624af2013-01-15 12:39:35 +00003570 if (obj->pages_pin_count == 0) {
3571 ret = i915_gem_object_put_pages(obj);
3572 if (ret)
3573 goto unlock;
3574 }
3575 }
3576
3577unlock:
3578 mutex_unlock(&dev->struct_mutex);
3579
Kees Cook647416f2013-03-10 14:10:06 -07003580 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003581}
3582
Kees Cook647416f2013-03-10 14:10:06 -07003583DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
3584 i915_drop_caches_get, i915_drop_caches_set,
3585 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00003586
Kees Cook647416f2013-03-10 14:10:06 -07003587static int
3588i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07003589{
Kees Cook647416f2013-03-10 14:10:06 -07003590 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003591 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003592 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003593
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003594 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003595 return -ENODEV;
3596
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003597 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3598
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003599 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003600 if (ret)
3601 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07003602
Jesse Barnes0a073b82013-04-17 15:54:58 -07003603 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07003604 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003605 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07003606 *val = dev_priv->rps.max_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003607 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07003608
Kees Cook647416f2013-03-10 14:10:06 -07003609 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07003610}
3611
Kees Cook647416f2013-03-10 14:10:06 -07003612static int
3613i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07003614{
Kees Cook647416f2013-03-10 14:10:06 -07003615 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07003616 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003617 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07003618 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003619
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003620 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003621 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07003622
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003623 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3624
Kees Cook647416f2013-03-10 14:10:06 -07003625 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07003626
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003627 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003628 if (ret)
3629 return ret;
3630
Jesse Barnes358733e2011-07-27 11:53:01 -07003631 /*
3632 * Turbo will still be enabled, but won't go above the set value.
3633 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07003634 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02003635 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003636
3637 hw_max = valleyview_rps_max_freq(dev_priv);
3638 hw_min = valleyview_rps_min_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003639 } else {
3640 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003641
3642 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07003643 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003644 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003645 }
3646
Ben Widawskyb39fb292014-03-19 18:31:11 -07003647 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003648 mutex_unlock(&dev_priv->rps.hw_lock);
3649 return -EINVAL;
3650 }
3651
Ben Widawskyb39fb292014-03-19 18:31:11 -07003652 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003653
3654 if (IS_VALLEYVIEW(dev))
3655 valleyview_set_rps(dev, val);
3656 else
3657 gen6_set_rps(dev, val);
3658
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003659 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07003660
Kees Cook647416f2013-03-10 14:10:06 -07003661 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07003662}
3663
Kees Cook647416f2013-03-10 14:10:06 -07003664DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
3665 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003666 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07003667
Kees Cook647416f2013-03-10 14:10:06 -07003668static int
3669i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07003670{
Kees Cook647416f2013-03-10 14:10:06 -07003671 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003672 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003673 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003674
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003675 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003676 return -ENODEV;
3677
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003678 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3679
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003680 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003681 if (ret)
3682 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07003683
Jesse Barnes0a073b82013-04-17 15:54:58 -07003684 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07003685 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003686 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07003687 *val = dev_priv->rps.min_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003688 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003689
Kees Cook647416f2013-03-10 14:10:06 -07003690 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003691}
3692
Kees Cook647416f2013-03-10 14:10:06 -07003693static int
3694i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07003695{
Kees Cook647416f2013-03-10 14:10:06 -07003696 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07003697 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003698 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07003699 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003700
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003701 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003702 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07003703
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003704 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3705
Kees Cook647416f2013-03-10 14:10:06 -07003706 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07003707
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003708 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003709 if (ret)
3710 return ret;
3711
Jesse Barnes1523c312012-05-25 12:34:54 -07003712 /*
3713 * Turbo will still be enabled, but won't go below the set value.
3714 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07003715 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02003716 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003717
3718 hw_max = valleyview_rps_max_freq(dev_priv);
3719 hw_min = valleyview_rps_min_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003720 } else {
3721 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003722
3723 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07003724 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003725 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003726 }
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003727
Ben Widawskyb39fb292014-03-19 18:31:11 -07003728 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003729 mutex_unlock(&dev_priv->rps.hw_lock);
3730 return -EINVAL;
3731 }
3732
Ben Widawskyb39fb292014-03-19 18:31:11 -07003733 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003734
3735 if (IS_VALLEYVIEW(dev))
3736 valleyview_set_rps(dev, val);
3737 else
3738 gen6_set_rps(dev, val);
3739
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003740 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003741
Kees Cook647416f2013-03-10 14:10:06 -07003742 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003743}
3744
Kees Cook647416f2013-03-10 14:10:06 -07003745DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
3746 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003747 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07003748
Kees Cook647416f2013-03-10 14:10:06 -07003749static int
3750i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003751{
Kees Cook647416f2013-03-10 14:10:06 -07003752 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003753 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003754 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07003755 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003756
Daniel Vetter004777c2012-08-09 15:07:01 +02003757 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3758 return -ENODEV;
3759
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003760 ret = mutex_lock_interruptible(&dev->struct_mutex);
3761 if (ret)
3762 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003763 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003764
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003765 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003766
3767 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003768 mutex_unlock(&dev_priv->dev->struct_mutex);
3769
Kees Cook647416f2013-03-10 14:10:06 -07003770 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003771
Kees Cook647416f2013-03-10 14:10:06 -07003772 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003773}
3774
Kees Cook647416f2013-03-10 14:10:06 -07003775static int
3776i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003777{
Kees Cook647416f2013-03-10 14:10:06 -07003778 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003779 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003780 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003781
Daniel Vetter004777c2012-08-09 15:07:01 +02003782 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3783 return -ENODEV;
3784
Kees Cook647416f2013-03-10 14:10:06 -07003785 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003786 return -EINVAL;
3787
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003788 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07003789 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003790
3791 /* Update the cache sharing policy here as well */
3792 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
3793 snpcr &= ~GEN6_MBC_SNPCR_MASK;
3794 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
3795 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
3796
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003797 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07003798 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003799}
3800
Kees Cook647416f2013-03-10 14:10:06 -07003801DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
3802 i915_cache_sharing_get, i915_cache_sharing_set,
3803 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003804
Ben Widawsky6d794d42011-04-25 11:25:56 -07003805static int i915_forcewake_open(struct inode *inode, struct file *file)
3806{
3807 struct drm_device *dev = inode->i_private;
3808 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003809
Daniel Vetter075edca2012-01-24 09:44:28 +01003810 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003811 return 0;
3812
Deepak Sc8d9a592013-11-23 14:55:42 +05303813 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003814
3815 return 0;
3816}
3817
Ben Widawskyc43b5632012-04-16 14:07:40 -07003818static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003819{
3820 struct drm_device *dev = inode->i_private;
3821 struct drm_i915_private *dev_priv = dev->dev_private;
3822
Daniel Vetter075edca2012-01-24 09:44:28 +01003823 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003824 return 0;
3825
Deepak Sc8d9a592013-11-23 14:55:42 +05303826 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003827
3828 return 0;
3829}
3830
3831static const struct file_operations i915_forcewake_fops = {
3832 .owner = THIS_MODULE,
3833 .open = i915_forcewake_open,
3834 .release = i915_forcewake_release,
3835};
3836
3837static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
3838{
3839 struct drm_device *dev = minor->dev;
3840 struct dentry *ent;
3841
3842 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07003843 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07003844 root, dev,
3845 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003846 if (!ent)
3847 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003848
Ben Widawsky8eb57292011-05-11 15:10:58 -07003849 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003850}
3851
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003852static int i915_debugfs_create(struct dentry *root,
3853 struct drm_minor *minor,
3854 const char *name,
3855 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07003856{
3857 struct drm_device *dev = minor->dev;
3858 struct dentry *ent;
3859
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003860 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07003861 S_IRUGO | S_IWUSR,
3862 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003863 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003864 if (!ent)
3865 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07003866
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003867 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003868}
3869
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003870static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00003871 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01003872 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00003873 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01003874 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003875 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003876 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b8882013-08-07 18:30:54 +01003877 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01003878 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003879 {"i915_gem_request", i915_gem_request_info, 0},
3880 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00003881 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003882 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003883 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
3884 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
3885 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07003886 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Deepak Sadb4bd12014-03-31 11:30:02 +05303887 {"i915_frequency_info", i915_frequency_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08003888 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07003889 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07003890 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08003891 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03003892 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08003893 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01003894 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01003895 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07003896 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07003897 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01003898 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01003899 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07003900 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03003901 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003902 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01003903 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03003904 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02003905 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003906 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07003907 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03003908 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003909};
Ben Gamari27c202a2009-07-01 22:26:52 -04003910#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05003911
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003912static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02003913 const char *name;
3914 const struct file_operations *fops;
3915} i915_debugfs_files[] = {
3916 {"i915_wedged", &i915_wedged_fops},
3917 {"i915_max_freq", &i915_max_freq_fops},
3918 {"i915_min_freq", &i915_min_freq_fops},
3919 {"i915_cache_sharing", &i915_cache_sharing_fops},
3920 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01003921 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
3922 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02003923 {"i915_gem_drop_caches", &i915_drop_caches_fops},
3924 {"i915_error_state", &i915_error_state_fops},
3925 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01003926 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02003927 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
3928 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
3929 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02003930};
3931
Damien Lespiau07144422013-10-15 18:55:40 +01003932void intel_display_crc_init(struct drm_device *dev)
3933{
3934 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01003935 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01003936
Daniel Vetterb3783602013-11-14 11:30:42 +01003937 for_each_pipe(pipe) {
3938 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01003939
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003940 pipe_crc->opened = false;
3941 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003942 init_waitqueue_head(&pipe_crc->wq);
3943 }
3944}
3945
Ben Gamari27c202a2009-07-01 22:26:52 -04003946int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05003947{
Daniel Vetter34b96742013-07-04 20:49:44 +02003948 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003949
Ben Widawsky6d794d42011-04-25 11:25:56 -07003950 ret = i915_forcewake_create(minor->debugfs_root, minor);
3951 if (ret)
3952 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003953
Damien Lespiau07144422013-10-15 18:55:40 +01003954 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
3955 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
3956 if (ret)
3957 return ret;
3958 }
3959
Daniel Vetter34b96742013-07-04 20:49:44 +02003960 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
3961 ret = i915_debugfs_create(minor->debugfs_root, minor,
3962 i915_debugfs_files[i].name,
3963 i915_debugfs_files[i].fops);
3964 if (ret)
3965 return ret;
3966 }
Mika Kuoppala40633212012-12-04 15:12:00 +02003967
Ben Gamari27c202a2009-07-01 22:26:52 -04003968 return drm_debugfs_create_files(i915_debugfs_list,
3969 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05003970 minor->debugfs_root, minor);
3971}
3972
Ben Gamari27c202a2009-07-01 22:26:52 -04003973void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05003974{
Daniel Vetter34b96742013-07-04 20:49:44 +02003975 int i;
3976
Ben Gamari27c202a2009-07-01 22:26:52 -04003977 drm_debugfs_remove_files(i915_debugfs_list,
3978 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01003979
Ben Widawsky6d794d42011-04-25 11:25:56 -07003980 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
3981 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01003982
Daniel Vettere309a992013-10-16 22:55:51 +02003983 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01003984 struct drm_info_list *info_list =
3985 (struct drm_info_list *)&i915_pipe_crc_data[i];
3986
3987 drm_debugfs_remove_files(info_list, 1, minor);
3988 }
3989
Daniel Vetter34b96742013-07-04 20:49:44 +02003990 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
3991 struct drm_info_list *info_list =
3992 (struct drm_info_list *) i915_debugfs_files[i].fops;
3993
3994 drm_debugfs_remove_files(info_list, 1, minor);
3995 }
Ben Gamari20172632009-02-17 20:08:50 -05003996}