blob: aea1a819c77571f84ff2652b63ded8ce1d57e28d [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b88852013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Chris Wilsonf13d3f72010-09-20 17:36:15 +010043enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010044 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010046 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047};
Ben Gamari433e12f2009-02-17 20:08:51 -050048
Chris Wilson70d39fe2010-08-25 16:03:34 +010049static const char *yesno(int v)
50{
51 return v ? "yes" : "no";
52}
53
Damien Lespiau497666d2013-10-15 18:55:39 +010054/* As the drm_debugfs_init() routines are called before dev->dev_private is
55 * allocated we need to hook into the minor for release. */
56static int
57drm_add_fake_info_node(struct drm_minor *minor,
58 struct dentry *ent,
59 const void *key)
60{
61 struct drm_info_node *node;
62
63 node = kmalloc(sizeof(*node), GFP_KERNEL);
64 if (node == NULL) {
65 debugfs_remove(ent);
66 return -ENOMEM;
67 }
68
69 node->minor = minor;
70 node->dent = ent;
71 node->info_ent = (void *) key;
72
73 mutex_lock(&minor->debugfs_lock);
74 list_add(&node->list, &minor->debugfs_list);
75 mutex_unlock(&minor->debugfs_lock);
76
77 return 0;
78}
79
Chris Wilson70d39fe2010-08-25 16:03:34 +010080static int i915_capabilities(struct seq_file *m, void *data)
81{
Damien Lespiau9f25d002014-05-13 15:30:28 +010082 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010083 struct drm_device *dev = node->minor->dev;
84 const struct intel_device_info *info = INTEL_INFO(dev);
85
86 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030087 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010088#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
89#define SEP_SEMICOLON ;
90 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
91#undef PRINT_FLAG
92#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010093
94 return 0;
95}
Ben Gamari433e12f2009-02-17 20:08:51 -050096
Chris Wilson05394f32010-11-08 19:18:58 +000097static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000098{
Chris 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 Wilson6d2b88852013-08-07 18:30:54 +0100231static int obj_rank_by_stolen(void *priv,
232 struct list_head *A, struct list_head *B)
233{
234 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200235 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100236 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200237 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100238
239 return a->stolen->start - b->stolen->start;
240}
241
242static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
243{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100244 struct drm_info_node *node = m->private;
Chris Wilson6d2b88852013-08-07 18:30:54 +0100245 struct drm_device *dev = node->minor->dev;
246 struct drm_i915_private *dev_priv = dev->dev_private;
247 struct drm_i915_gem_object *obj;
248 size_t total_obj_size, total_gtt_size;
249 LIST_HEAD(stolen);
250 int count, ret;
251
252 ret = mutex_lock_interruptible(&dev->struct_mutex);
253 if (ret)
254 return ret;
255
256 total_obj_size = total_gtt_size = count = 0;
257 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
258 if (obj->stolen == NULL)
259 continue;
260
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200261 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100262
263 total_obj_size += obj->base.size;
264 total_gtt_size += i915_gem_obj_ggtt_size(obj);
265 count++;
266 }
267 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
268 if (obj->stolen == NULL)
269 continue;
270
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200271 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100272
273 total_obj_size += obj->base.size;
274 count++;
275 }
276 list_sort(NULL, &stolen, obj_rank_by_stolen);
277 seq_puts(m, "Stolen:\n");
278 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200279 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100280 seq_puts(m, " ");
281 describe_obj(m, obj);
282 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200283 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b88852013-08-07 18:30:54 +0100284 }
285 mutex_unlock(&dev->struct_mutex);
286
287 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
288 count, total_obj_size, total_gtt_size);
289 return 0;
290}
291
Chris Wilson6299f992010-11-24 12:23:44 +0000292#define count_objects(list, member) do { \
293 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700294 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000295 ++count; \
296 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700297 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000298 ++mappable_count; \
299 } \
300 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400301} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000302
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100303struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000304 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100305 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000306 size_t total, unbound;
307 size_t global, shared;
308 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100309};
310
311static int per_file_stats(int id, void *ptr, void *data)
312{
313 struct drm_i915_gem_object *obj = ptr;
314 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000315 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100316
317 stats->count++;
318 stats->total += obj->base.size;
319
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000320 if (obj->base.name || obj->base.dma_buf)
321 stats->shared += obj->base.size;
322
Chris Wilson6313c202014-03-19 13:45:45 +0000323 if (USES_FULL_PPGTT(obj->base.dev)) {
324 list_for_each_entry(vma, &obj->vma_list, vma_link) {
325 struct i915_hw_ppgtt *ppgtt;
326
327 if (!drm_mm_node_allocated(&vma->node))
328 continue;
329
330 if (i915_is_ggtt(vma->vm)) {
331 stats->global += obj->base.size;
332 continue;
333 }
334
335 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
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)) {
Ville Syrjälä03af2042014-06-28 02:03:53 +03001111 u32 freq_sts;
Jesse Barnes0a073b82013-04-17 15:54:58 -07001112
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
Jesse Barnes0a073b82013-04-17 15:54:58 -07001118 seq_printf(m, "max GPU freq: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301119 vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001120
Jesse Barnes0a073b82013-04-17 15:54:58 -07001121 seq_printf(m, "min GPU freq: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301122 vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq));
Ville Syrjälä03af2042014-06-28 02:03:53 +03001123
1124 seq_printf(m, "efficient (RPe) frequency: %d MHz\n",
Deepak Sb2435c92014-07-17 14:21:14 +05301125 vlv_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001126
1127 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001128 vlv_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001129 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001130 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001131 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001132 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001133
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001134out:
1135 intel_runtime_pm_put(dev_priv);
1136 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001137}
1138
Ben Widawsky4d855292011-12-12 19:34:16 -08001139static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001140{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001141 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001142 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001143 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001144 u32 rgvmodectl, rstdbyctl;
1145 u16 crstandvid;
1146 int ret;
1147
1148 ret = mutex_lock_interruptible(&dev->struct_mutex);
1149 if (ret)
1150 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001151 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001152
1153 rgvmodectl = I915_READ(MEMMODECTL);
1154 rstdbyctl = I915_READ(RSTDBYCTL);
1155 crstandvid = I915_READ16(CRSTANDVID);
1156
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001157 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001158 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001159
1160 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1161 "yes" : "no");
1162 seq_printf(m, "Boost freq: %d\n",
1163 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1164 MEMMODE_BOOST_FREQ_SHIFT);
1165 seq_printf(m, "HW control enabled: %s\n",
1166 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1167 seq_printf(m, "SW control enabled: %s\n",
1168 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1169 seq_printf(m, "Gated voltage change: %s\n",
1170 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1171 seq_printf(m, "Starting frequency: P%d\n",
1172 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001173 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001174 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001175 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1176 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1177 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1178 seq_printf(m, "Render standby enabled: %s\n",
1179 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001180 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001181 switch (rstdbyctl & RSX_STATUS_MASK) {
1182 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001183 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001184 break;
1185 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001186 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001187 break;
1188 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001189 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001190 break;
1191 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001192 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001193 break;
1194 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001195 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001196 break;
1197 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001198 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001199 break;
1200 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001201 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001202 break;
1203 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001204
1205 return 0;
1206}
1207
Deepak S669ab5a2014-01-10 15:18:26 +05301208static int vlv_drpc_info(struct seq_file *m)
1209{
1210
Damien Lespiau9f25d002014-05-13 15:30:28 +01001211 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301212 struct drm_device *dev = node->minor->dev;
1213 struct drm_i915_private *dev_priv = dev->dev_private;
1214 u32 rpmodectl1, rcctl1;
1215 unsigned fw_rendercount = 0, fw_mediacount = 0;
1216
Imre Deakd46c0512014-04-14 20:24:27 +03001217 intel_runtime_pm_get(dev_priv);
1218
Deepak S669ab5a2014-01-10 15:18:26 +05301219 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1220 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1221
Imre Deakd46c0512014-04-14 20:24:27 +03001222 intel_runtime_pm_put(dev_priv);
1223
Deepak S669ab5a2014-01-10 15:18:26 +05301224 seq_printf(m, "Video Turbo Mode: %s\n",
1225 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1226 seq_printf(m, "Turbo enabled: %s\n",
1227 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1228 seq_printf(m, "HW control enabled: %s\n",
1229 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1230 seq_printf(m, "SW control enabled: %s\n",
1231 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1232 GEN6_RP_MEDIA_SW_MODE));
1233 seq_printf(m, "RC6 Enabled: %s\n",
1234 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1235 GEN6_RC_CTL_EI_MODE(1))));
1236 seq_printf(m, "Render Power Well: %s\n",
1237 (I915_READ(VLV_GTLC_PW_STATUS) &
1238 VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
1239 seq_printf(m, "Media Power Well: %s\n",
1240 (I915_READ(VLV_GTLC_PW_STATUS) &
1241 VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
1242
Imre Deak9cc19be2014-04-14 20:24:24 +03001243 seq_printf(m, "Render RC6 residency since boot: %u\n",
1244 I915_READ(VLV_GT_RENDER_RC6));
1245 seq_printf(m, "Media RC6 residency since boot: %u\n",
1246 I915_READ(VLV_GT_MEDIA_RC6));
1247
Deepak S669ab5a2014-01-10 15:18:26 +05301248 spin_lock_irq(&dev_priv->uncore.lock);
1249 fw_rendercount = dev_priv->uncore.fw_rendercount;
1250 fw_mediacount = dev_priv->uncore.fw_mediacount;
1251 spin_unlock_irq(&dev_priv->uncore.lock);
1252
1253 seq_printf(m, "Forcewake Render Count = %u\n", fw_rendercount);
1254 seq_printf(m, "Forcewake Media Count = %u\n", fw_mediacount);
1255
1256
1257 return 0;
1258}
1259
1260
Ben Widawsky4d855292011-12-12 19:34:16 -08001261static int gen6_drpc_info(struct seq_file *m)
1262{
1263
Damien Lespiau9f25d002014-05-13 15:30:28 +01001264 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001265 struct drm_device *dev = node->minor->dev;
1266 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001267 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001268 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001269 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001270
1271 ret = mutex_lock_interruptible(&dev->struct_mutex);
1272 if (ret)
1273 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001274 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001275
Chris Wilson907b28c2013-07-19 20:36:52 +01001276 spin_lock_irq(&dev_priv->uncore.lock);
1277 forcewake_count = dev_priv->uncore.forcewake_count;
1278 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001279
1280 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001281 seq_puts(m, "RC information inaccurate because somebody "
1282 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001283 } else {
1284 /* NB: we cannot use forcewake, else we read the wrong values */
1285 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1286 udelay(10);
1287 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1288 }
1289
1290 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001291 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001292
1293 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1294 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1295 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001296 mutex_lock(&dev_priv->rps.hw_lock);
1297 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1298 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001299
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001300 intel_runtime_pm_put(dev_priv);
1301
Ben Widawsky4d855292011-12-12 19:34:16 -08001302 seq_printf(m, "Video Turbo Mode: %s\n",
1303 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1304 seq_printf(m, "HW control enabled: %s\n",
1305 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1306 seq_printf(m, "SW control enabled: %s\n",
1307 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1308 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001309 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001310 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1311 seq_printf(m, "RC6 Enabled: %s\n",
1312 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1313 seq_printf(m, "Deep RC6 Enabled: %s\n",
1314 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1315 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1316 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001317 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001318 switch (gt_core_status & GEN6_RCn_MASK) {
1319 case GEN6_RC0:
1320 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001321 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001322 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001323 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001324 break;
1325 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001326 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001327 break;
1328 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001329 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001330 break;
1331 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001332 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001333 break;
1334 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001335 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001336 break;
1337 }
1338
1339 seq_printf(m, "Core Power Down: %s\n",
1340 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001341
1342 /* Not exactly sure what this is */
1343 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1344 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1345 seq_printf(m, "RC6 residency since boot: %u\n",
1346 I915_READ(GEN6_GT_GFX_RC6));
1347 seq_printf(m, "RC6+ residency since boot: %u\n",
1348 I915_READ(GEN6_GT_GFX_RC6p));
1349 seq_printf(m, "RC6++ residency since boot: %u\n",
1350 I915_READ(GEN6_GT_GFX_RC6pp));
1351
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001352 seq_printf(m, "RC6 voltage: %dmV\n",
1353 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1354 seq_printf(m, "RC6+ voltage: %dmV\n",
1355 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1356 seq_printf(m, "RC6++ voltage: %dmV\n",
1357 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001358 return 0;
1359}
1360
1361static int i915_drpc_info(struct seq_file *m, void *unused)
1362{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001363 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001364 struct drm_device *dev = node->minor->dev;
1365
Deepak S669ab5a2014-01-10 15:18:26 +05301366 if (IS_VALLEYVIEW(dev))
1367 return vlv_drpc_info(m);
1368 else if (IS_GEN6(dev) || IS_GEN7(dev))
Ben Widawsky4d855292011-12-12 19:34:16 -08001369 return gen6_drpc_info(m);
1370 else
1371 return ironlake_drpc_info(m);
1372}
1373
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001374static int i915_fbc_status(struct seq_file *m, void *unused)
1375{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001376 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001377 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001378 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001379
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001380 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001381 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001382 return 0;
1383 }
1384
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001385 intel_runtime_pm_get(dev_priv);
1386
Adam Jacksonee5382a2010-04-23 11:17:39 -04001387 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001388 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001389 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001390 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001391 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001392 case FBC_OK:
1393 seq_puts(m, "FBC actived, but currently disabled in hardware");
1394 break;
1395 case FBC_UNSUPPORTED:
1396 seq_puts(m, "unsupported by this chipset");
1397 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001398 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001399 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001400 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001401 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001402 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001403 break;
1404 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001405 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001406 break;
1407 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001408 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001409 break;
1410 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001411 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001412 break;
1413 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001414 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001415 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001416 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001417 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001418 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001419 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001420 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001421 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001422 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001423 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001424 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001425 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001426 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001427 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001428 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001429 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001430
1431 intel_runtime_pm_put(dev_priv);
1432
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001433 return 0;
1434}
1435
Rodrigo Vivida46f932014-08-01 02:04:45 -07001436static int i915_fbc_fc_get(void *data, u64 *val)
1437{
1438 struct drm_device *dev = data;
1439 struct drm_i915_private *dev_priv = dev->dev_private;
1440
1441 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1442 return -ENODEV;
1443
1444 drm_modeset_lock_all(dev);
1445 *val = dev_priv->fbc.false_color;
1446 drm_modeset_unlock_all(dev);
1447
1448 return 0;
1449}
1450
1451static int i915_fbc_fc_set(void *data, u64 val)
1452{
1453 struct drm_device *dev = data;
1454 struct drm_i915_private *dev_priv = dev->dev_private;
1455 u32 reg;
1456
1457 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1458 return -ENODEV;
1459
1460 drm_modeset_lock_all(dev);
1461
1462 reg = I915_READ(ILK_DPFC_CONTROL);
1463 dev_priv->fbc.false_color = val;
1464
1465 I915_WRITE(ILK_DPFC_CONTROL, val ?
1466 (reg | FBC_CTL_FALSE_COLOR) :
1467 (reg & ~FBC_CTL_FALSE_COLOR));
1468
1469 drm_modeset_unlock_all(dev);
1470 return 0;
1471}
1472
1473DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1474 i915_fbc_fc_get, i915_fbc_fc_set,
1475 "%llu\n");
1476
Paulo Zanoni92d44622013-05-31 16:33:24 -03001477static int i915_ips_status(struct seq_file *m, void *unused)
1478{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001479 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001480 struct drm_device *dev = node->minor->dev;
1481 struct drm_i915_private *dev_priv = dev->dev_private;
1482
Damien Lespiauf5adf942013-06-24 18:29:34 +01001483 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001484 seq_puts(m, "not supported\n");
1485 return 0;
1486 }
1487
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001488 intel_runtime_pm_get(dev_priv);
1489
Rodrigo Vivi0eaa53f2014-06-30 04:45:01 -07001490 seq_printf(m, "Enabled by kernel parameter: %s\n",
1491 yesno(i915.enable_ips));
1492
1493 if (INTEL_INFO(dev)->gen >= 8) {
1494 seq_puts(m, "Currently: unknown\n");
1495 } else {
1496 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1497 seq_puts(m, "Currently: enabled\n");
1498 else
1499 seq_puts(m, "Currently: disabled\n");
1500 }
Paulo Zanoni92d44622013-05-31 16:33:24 -03001501
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001502 intel_runtime_pm_put(dev_priv);
1503
Paulo Zanoni92d44622013-05-31 16:33:24 -03001504 return 0;
1505}
1506
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001507static int i915_sr_status(struct seq_file *m, void *unused)
1508{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001509 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001510 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001511 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001512 bool sr_enabled = false;
1513
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001514 intel_runtime_pm_get(dev_priv);
1515
Yuanhan Liu13982612010-12-15 15:42:31 +08001516 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001517 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001518 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001519 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1520 else if (IS_I915GM(dev))
1521 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1522 else if (IS_PINEVIEW(dev))
1523 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1524
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001525 intel_runtime_pm_put(dev_priv);
1526
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001527 seq_printf(m, "self-refresh: %s\n",
1528 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001529
1530 return 0;
1531}
1532
Jesse Barnes7648fa92010-05-20 14:28:11 -07001533static int i915_emon_status(struct seq_file *m, void *unused)
1534{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001535 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001536 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001537 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001538 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001539 int ret;
1540
Chris Wilson582be6b2012-04-30 19:35:02 +01001541 if (!IS_GEN5(dev))
1542 return -ENODEV;
1543
Chris Wilsonde227ef2010-07-03 07:58:38 +01001544 ret = mutex_lock_interruptible(&dev->struct_mutex);
1545 if (ret)
1546 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001547
1548 temp = i915_mch_val(dev_priv);
1549 chipset = i915_chipset_val(dev_priv);
1550 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001551 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001552
1553 seq_printf(m, "GMCH temp: %ld\n", temp);
1554 seq_printf(m, "Chipset power: %ld\n", chipset);
1555 seq_printf(m, "GFX power: %ld\n", gfx);
1556 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1557
1558 return 0;
1559}
1560
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001561static int i915_ring_freq_table(struct seq_file *m, void *unused)
1562{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001563 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001564 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001565 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001566 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001567 int gpu_freq, ia_freq;
1568
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001569 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001570 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001571 return 0;
1572 }
1573
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001574 intel_runtime_pm_get(dev_priv);
1575
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001576 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1577
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001578 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001579 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001580 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001581
Damien Lespiau267f0c92013-06-24 22:59:48 +01001582 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001583
Ben Widawskyb39fb292014-03-19 18:31:11 -07001584 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1585 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001586 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001587 ia_freq = gpu_freq;
1588 sandybridge_pcode_read(dev_priv,
1589 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1590 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001591 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1592 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1593 ((ia_freq >> 0) & 0xff) * 100,
1594 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001595 }
1596
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001597 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001598
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001599out:
1600 intel_runtime_pm_put(dev_priv);
1601 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001602}
1603
Chris Wilson44834a62010-08-19 16:09:23 +01001604static int i915_opregion(struct seq_file *m, void *unused)
1605{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001606 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001607 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001608 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001609 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001610 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001611 int ret;
1612
Daniel Vetter0d38f002012-04-21 22:49:10 +02001613 if (data == NULL)
1614 return -ENOMEM;
1615
Chris Wilson44834a62010-08-19 16:09:23 +01001616 ret = mutex_lock_interruptible(&dev->struct_mutex);
1617 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001618 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001619
Daniel Vetter0d38f002012-04-21 22:49:10 +02001620 if (opregion->header) {
1621 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1622 seq_write(m, data, OPREGION_SIZE);
1623 }
Chris Wilson44834a62010-08-19 16:09:23 +01001624
1625 mutex_unlock(&dev->struct_mutex);
1626
Daniel Vetter0d38f002012-04-21 22:49:10 +02001627out:
1628 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001629 return 0;
1630}
1631
Chris Wilson37811fc2010-08-25 22:45:57 +01001632static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1633{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001634 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001635 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001636 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001637 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001638
Daniel Vetter4520f532013-10-09 09:18:51 +02001639#ifdef CONFIG_DRM_I915_FBDEV
1640 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001641
1642 ifbdev = dev_priv->fbdev;
1643 fb = to_intel_framebuffer(ifbdev->helper.fb);
1644
Daniel Vetter623f9782012-12-11 16:21:38 +01001645 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001646 fb->base.width,
1647 fb->base.height,
1648 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001649 fb->base.bits_per_pixel,
1650 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001651 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001652 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001653#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001654
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001655 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001656 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001657 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001658 continue;
1659
Daniel Vetter623f9782012-12-11 16:21:38 +01001660 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001661 fb->base.width,
1662 fb->base.height,
1663 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001664 fb->base.bits_per_pixel,
1665 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001666 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001667 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001668 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001669 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001670
1671 return 0;
1672}
1673
Ben Widawskye76d3632011-03-19 18:14:29 -07001674static int i915_context_status(struct seq_file *m, void *unused)
1675{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001676 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001677 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001678 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001679 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001680 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001681 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001682
Daniel Vetterf3d28872014-05-29 23:23:08 +02001683 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001684 if (ret)
1685 return ret;
1686
Daniel Vetter3e373942012-11-02 19:55:04 +01001687 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001688 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001689 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001690 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001691 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001692
Daniel Vetter3e373942012-11-02 19:55:04 +01001693 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001694 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001695 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001696 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001697 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001698
Ben Widawskya33afea2013-09-17 21:12:45 -07001699 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Oscar Mateoea0c76f2014-07-03 16:27:59 +01001700 if (ctx->legacy_hw_ctx.rcs_state == NULL)
Chris Wilsonb77f6992014-04-30 08:30:00 +01001701 continue;
1702
Ben Widawskya33afea2013-09-17 21:12:45 -07001703 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001704 describe_ctx(m, ctx);
Ben Widawskya33afea2013-09-17 21:12:45 -07001705 for_each_ring(ring, dev_priv, i)
1706 if (ring->default_context == ctx)
1707 seq_printf(m, "(default context %s) ", ring->name);
1708
Oscar Mateoea0c76f2014-07-03 16:27:59 +01001709 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
Ben Widawskya33afea2013-09-17 21:12:45 -07001710 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001711 }
1712
Daniel Vetterf3d28872014-05-29 23:23:08 +02001713 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001714
1715 return 0;
1716}
1717
Ben Widawsky6d794d42011-04-25 11:25:56 -07001718static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1719{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001720 struct drm_info_node *node = m->private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001721 struct drm_device *dev = node->minor->dev;
1722 struct drm_i915_private *dev_priv = dev->dev_private;
Deepak S43709ba2013-11-23 14:55:44 +05301723 unsigned forcewake_count = 0, fw_rendercount = 0, fw_mediacount = 0;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001724
Chris Wilson907b28c2013-07-19 20:36:52 +01001725 spin_lock_irq(&dev_priv->uncore.lock);
Deepak S43709ba2013-11-23 14:55:44 +05301726 if (IS_VALLEYVIEW(dev)) {
1727 fw_rendercount = dev_priv->uncore.fw_rendercount;
1728 fw_mediacount = dev_priv->uncore.fw_mediacount;
1729 } else
1730 forcewake_count = dev_priv->uncore.forcewake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001731 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001732
Deepak S43709ba2013-11-23 14:55:44 +05301733 if (IS_VALLEYVIEW(dev)) {
1734 seq_printf(m, "fw_rendercount = %u\n", fw_rendercount);
1735 seq_printf(m, "fw_mediacount = %u\n", fw_mediacount);
1736 } else
1737 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001738
1739 return 0;
1740}
1741
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001742static const char *swizzle_string(unsigned swizzle)
1743{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001744 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001745 case I915_BIT_6_SWIZZLE_NONE:
1746 return "none";
1747 case I915_BIT_6_SWIZZLE_9:
1748 return "bit9";
1749 case I915_BIT_6_SWIZZLE_9_10:
1750 return "bit9/bit10";
1751 case I915_BIT_6_SWIZZLE_9_11:
1752 return "bit9/bit11";
1753 case I915_BIT_6_SWIZZLE_9_10_11:
1754 return "bit9/bit10/bit11";
1755 case I915_BIT_6_SWIZZLE_9_17:
1756 return "bit9/bit17";
1757 case I915_BIT_6_SWIZZLE_9_10_17:
1758 return "bit9/bit10/bit17";
1759 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001760 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001761 }
1762
1763 return "bug";
1764}
1765
1766static int i915_swizzle_info(struct seq_file *m, void *data)
1767{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001768 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001769 struct drm_device *dev = node->minor->dev;
1770 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001771 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001772
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001773 ret = mutex_lock_interruptible(&dev->struct_mutex);
1774 if (ret)
1775 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001776 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001777
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001778 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1779 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1780 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1781 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1782
1783 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1784 seq_printf(m, "DDC = 0x%08x\n",
1785 I915_READ(DCC));
1786 seq_printf(m, "C0DRB3 = 0x%04x\n",
1787 I915_READ16(C0DRB3));
1788 seq_printf(m, "C1DRB3 = 0x%04x\n",
1789 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001790 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001791 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1792 I915_READ(MAD_DIMM_C0));
1793 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1794 I915_READ(MAD_DIMM_C1));
1795 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1796 I915_READ(MAD_DIMM_C2));
1797 seq_printf(m, "TILECTL = 0x%08x\n",
1798 I915_READ(TILECTL));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001799 if (IS_GEN8(dev))
1800 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
1801 I915_READ(GAMTARBMODE));
1802 else
1803 seq_printf(m, "ARB_MODE = 0x%08x\n",
1804 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001805 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1806 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001807 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001808 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001809 mutex_unlock(&dev->struct_mutex);
1810
1811 return 0;
1812}
1813
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001814static int per_file_ctx(int id, void *ptr, void *data)
1815{
Oscar Mateo273497e2014-05-22 14:13:37 +01001816 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001817 struct seq_file *m = data;
1818 struct i915_hw_ppgtt *ppgtt = ctx_to_ppgtt(ctx);
1819
Oscar Mateof83d6512014-05-22 14:13:38 +01001820 if (i915_gem_context_is_default(ctx))
1821 seq_puts(m, " default context:\n");
1822 else
Oscar Mateo821d66d2014-07-03 16:28:00 +01001823 seq_printf(m, " context %d:\n", ctx->user_handle);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001824 ppgtt->debug_dump(ppgtt, m);
1825
1826 return 0;
1827}
1828
Ben Widawsky77df6772013-11-02 21:07:30 -07001829static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001830{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001831 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001832 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07001833 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1834 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001835
Ben Widawsky77df6772013-11-02 21:07:30 -07001836 if (!ppgtt)
1837 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001838
Ben Widawsky77df6772013-11-02 21:07:30 -07001839 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08001840 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07001841 for_each_ring(ring, dev_priv, unused) {
1842 seq_printf(m, "%s\n", ring->name);
1843 for (i = 0; i < 4; i++) {
1844 u32 offset = 0x270 + i * 8;
1845 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
1846 pdp <<= 32;
1847 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03001848 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07001849 }
1850 }
1851}
1852
1853static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
1854{
1855 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001856 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001857 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07001858 int i;
1859
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001860 if (INTEL_INFO(dev)->gen == 6)
1861 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1862
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001863 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001864 seq_printf(m, "%s\n", ring->name);
1865 if (INTEL_INFO(dev)->gen == 7)
1866 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1867 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1868 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1869 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1870 }
1871 if (dev_priv->mm.aliasing_ppgtt) {
1872 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1873
Damien Lespiau267f0c92013-06-24 22:59:48 +01001874 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001875 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001876
Ben Widawsky87d60b62013-12-06 14:11:29 -08001877 ppgtt->debug_dump(ppgtt, m);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001878 } else
1879 return;
1880
1881 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
1882 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001883
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001884 seq_printf(m, "proc: %s\n",
1885 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001886 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001887 }
1888 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07001889}
1890
1891static int i915_ppgtt_info(struct seq_file *m, void *data)
1892{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001893 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07001894 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001895 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07001896
1897 int ret = mutex_lock_interruptible(&dev->struct_mutex);
1898 if (ret)
1899 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001900 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07001901
1902 if (INTEL_INFO(dev)->gen >= 8)
1903 gen8_ppgtt_info(m, dev);
1904 else if (INTEL_INFO(dev)->gen >= 6)
1905 gen6_ppgtt_info(m, dev);
1906
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001907 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001908 mutex_unlock(&dev->struct_mutex);
1909
1910 return 0;
1911}
1912
Ben Widawsky63573eb2013-07-04 11:02:07 -07001913static int i915_llc(struct seq_file *m, void *data)
1914{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001915 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07001916 struct drm_device *dev = node->minor->dev;
1917 struct drm_i915_private *dev_priv = dev->dev_private;
1918
1919 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
1920 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
1921 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
1922
1923 return 0;
1924}
1925
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001926static int i915_edp_psr_status(struct seq_file *m, void *data)
1927{
1928 struct drm_info_node *node = m->private;
1929 struct drm_device *dev = node->minor->dev;
1930 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03001931 u32 psrperf = 0;
1932 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001933
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001934 intel_runtime_pm_get(dev_priv);
1935
Daniel Vetterfa128fa2014-07-11 10:30:17 -07001936 mutex_lock(&dev_priv->psr.lock);
Rodrigo Vivia031d702013-10-03 16:15:06 -03001937 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
1938 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Daniel Vetter2807cf62014-07-11 10:30:11 -07001939 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07001940 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Daniel Vetterfa128fa2014-07-11 10:30:17 -07001941 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
1942 dev_priv->psr.busy_frontbuffer_bits);
1943 seq_printf(m, "Re-enable work scheduled: %s\n",
1944 yesno(work_busy(&dev_priv->psr.work.work)));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001945
Rodrigo Vivia031d702013-10-03 16:15:06 -03001946 enabled = HAS_PSR(dev) &&
1947 I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
Rodrigo Vivi5755c782014-06-12 10:16:45 -07001948 seq_printf(m, "HW Enabled & Active bit: %s\n", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001949
Rodrigo Vivia031d702013-10-03 16:15:06 -03001950 if (HAS_PSR(dev))
1951 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
1952 EDP_PSR_PERF_CNT_MASK;
1953 seq_printf(m, "Performance_Counter: %u\n", psrperf);
Daniel Vetterfa128fa2014-07-11 10:30:17 -07001954 mutex_unlock(&dev_priv->psr.lock);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001955
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001956 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001957 return 0;
1958}
1959
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02001960static int i915_sink_crc(struct seq_file *m, void *data)
1961{
1962 struct drm_info_node *node = m->private;
1963 struct drm_device *dev = node->minor->dev;
1964 struct intel_encoder *encoder;
1965 struct intel_connector *connector;
1966 struct intel_dp *intel_dp = NULL;
1967 int ret;
1968 u8 crc[6];
1969
1970 drm_modeset_lock_all(dev);
1971 list_for_each_entry(connector, &dev->mode_config.connector_list,
1972 base.head) {
1973
1974 if (connector->base.dpms != DRM_MODE_DPMS_ON)
1975 continue;
1976
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02001977 if (!connector->base.encoder)
1978 continue;
1979
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02001980 encoder = to_intel_encoder(connector->base.encoder);
1981 if (encoder->type != INTEL_OUTPUT_EDP)
1982 continue;
1983
1984 intel_dp = enc_to_intel_dp(&encoder->base);
1985
1986 ret = intel_dp_sink_crc(intel_dp, crc);
1987 if (ret)
1988 goto out;
1989
1990 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
1991 crc[0], crc[1], crc[2],
1992 crc[3], crc[4], crc[5]);
1993 goto out;
1994 }
1995 ret = -ENODEV;
1996out:
1997 drm_modeset_unlock_all(dev);
1998 return ret;
1999}
2000
Jesse Barnesec013e72013-08-20 10:29:23 +01002001static int i915_energy_uJ(struct seq_file *m, void *data)
2002{
2003 struct drm_info_node *node = m->private;
2004 struct drm_device *dev = node->minor->dev;
2005 struct drm_i915_private *dev_priv = dev->dev_private;
2006 u64 power;
2007 u32 units;
2008
2009 if (INTEL_INFO(dev)->gen < 6)
2010 return -ENODEV;
2011
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002012 intel_runtime_pm_get(dev_priv);
2013
Jesse Barnesec013e72013-08-20 10:29:23 +01002014 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2015 power = (power & 0x1f00) >> 8;
2016 units = 1000000 / (1 << power); /* convert to uJ */
2017 power = I915_READ(MCH_SECP_NRG_STTS);
2018 power *= units;
2019
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002020 intel_runtime_pm_put(dev_priv);
2021
Jesse Barnesec013e72013-08-20 10:29:23 +01002022 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002023
2024 return 0;
2025}
2026
2027static int i915_pc8_status(struct seq_file *m, void *unused)
2028{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002029 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002030 struct drm_device *dev = node->minor->dev;
2031 struct drm_i915_private *dev_priv = dev->dev_private;
2032
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002033 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002034 seq_puts(m, "not supported\n");
2035 return 0;
2036 }
2037
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002038 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002039 seq_printf(m, "IRQs disabled: %s\n",
Jesse Barnes9df7575f2014-06-20 09:29:20 -07002040 yesno(!intel_irqs_enabled(dev_priv)));
Paulo Zanoni371db662013-08-19 13:18:10 -03002041
Jesse Barnesec013e72013-08-20 10:29:23 +01002042 return 0;
2043}
2044
Imre Deak1da51582013-11-25 17:15:35 +02002045static const char *power_domain_str(enum intel_display_power_domain domain)
2046{
2047 switch (domain) {
2048 case POWER_DOMAIN_PIPE_A:
2049 return "PIPE_A";
2050 case POWER_DOMAIN_PIPE_B:
2051 return "PIPE_B";
2052 case POWER_DOMAIN_PIPE_C:
2053 return "PIPE_C";
2054 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2055 return "PIPE_A_PANEL_FITTER";
2056 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2057 return "PIPE_B_PANEL_FITTER";
2058 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2059 return "PIPE_C_PANEL_FITTER";
2060 case POWER_DOMAIN_TRANSCODER_A:
2061 return "TRANSCODER_A";
2062 case POWER_DOMAIN_TRANSCODER_B:
2063 return "TRANSCODER_B";
2064 case POWER_DOMAIN_TRANSCODER_C:
2065 return "TRANSCODER_C";
2066 case POWER_DOMAIN_TRANSCODER_EDP:
2067 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002068 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2069 return "PORT_DDI_A_2_LANES";
2070 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2071 return "PORT_DDI_A_4_LANES";
2072 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2073 return "PORT_DDI_B_2_LANES";
2074 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2075 return "PORT_DDI_B_4_LANES";
2076 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2077 return "PORT_DDI_C_2_LANES";
2078 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2079 return "PORT_DDI_C_4_LANES";
2080 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2081 return "PORT_DDI_D_2_LANES";
2082 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2083 return "PORT_DDI_D_4_LANES";
2084 case POWER_DOMAIN_PORT_DSI:
2085 return "PORT_DSI";
2086 case POWER_DOMAIN_PORT_CRT:
2087 return "PORT_CRT";
2088 case POWER_DOMAIN_PORT_OTHER:
2089 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002090 case POWER_DOMAIN_VGA:
2091 return "VGA";
2092 case POWER_DOMAIN_AUDIO:
2093 return "AUDIO";
Paulo Zanonibd2bb1b2014-07-04 11:27:38 -03002094 case POWER_DOMAIN_PLLS:
2095 return "PLLS";
Imre Deak1da51582013-11-25 17:15:35 +02002096 case POWER_DOMAIN_INIT:
2097 return "INIT";
2098 default:
2099 WARN_ON(1);
2100 return "?";
2101 }
2102}
2103
2104static int i915_power_domain_info(struct seq_file *m, void *unused)
2105{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002106 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002107 struct drm_device *dev = node->minor->dev;
2108 struct drm_i915_private *dev_priv = dev->dev_private;
2109 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2110 int i;
2111
2112 mutex_lock(&power_domains->lock);
2113
2114 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2115 for (i = 0; i < power_domains->power_well_count; i++) {
2116 struct i915_power_well *power_well;
2117 enum intel_display_power_domain power_domain;
2118
2119 power_well = &power_domains->power_wells[i];
2120 seq_printf(m, "%-25s %d\n", power_well->name,
2121 power_well->count);
2122
2123 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2124 power_domain++) {
2125 if (!(BIT(power_domain) & power_well->domains))
2126 continue;
2127
2128 seq_printf(m, " %-23s %d\n",
2129 power_domain_str(power_domain),
2130 power_domains->domain_use_count[power_domain]);
2131 }
2132 }
2133
2134 mutex_unlock(&power_domains->lock);
2135
2136 return 0;
2137}
2138
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002139static void intel_seq_print_mode(struct seq_file *m, int tabs,
2140 struct drm_display_mode *mode)
2141{
2142 int i;
2143
2144 for (i = 0; i < tabs; i++)
2145 seq_putc(m, '\t');
2146
2147 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",
2148 mode->base.id, mode->name,
2149 mode->vrefresh, mode->clock,
2150 mode->hdisplay, mode->hsync_start,
2151 mode->hsync_end, mode->htotal,
2152 mode->vdisplay, mode->vsync_start,
2153 mode->vsync_end, mode->vtotal,
2154 mode->type, mode->flags);
2155}
2156
2157static void intel_encoder_info(struct seq_file *m,
2158 struct intel_crtc *intel_crtc,
2159 struct intel_encoder *intel_encoder)
2160{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002161 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002162 struct drm_device *dev = node->minor->dev;
2163 struct drm_crtc *crtc = &intel_crtc->base;
2164 struct intel_connector *intel_connector;
2165 struct drm_encoder *encoder;
2166
2167 encoder = &intel_encoder->base;
2168 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a032014-06-03 14:56:21 +03002169 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002170 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2171 struct drm_connector *connector = &intel_connector->base;
2172 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2173 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002174 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002175 drm_get_connector_status_name(connector->status));
2176 if (connector->status == connector_status_connected) {
2177 struct drm_display_mode *mode = &crtc->mode;
2178 seq_printf(m, ", mode:\n");
2179 intel_seq_print_mode(m, 2, mode);
2180 } else {
2181 seq_putc(m, '\n');
2182 }
2183 }
2184}
2185
2186static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2187{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002188 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002189 struct drm_device *dev = node->minor->dev;
2190 struct drm_crtc *crtc = &intel_crtc->base;
2191 struct intel_encoder *intel_encoder;
2192
Matt Roper5aa8a932014-06-16 10:12:55 -07002193 if (crtc->primary->fb)
2194 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2195 crtc->primary->fb->base.id, crtc->x, crtc->y,
2196 crtc->primary->fb->width, crtc->primary->fb->height);
2197 else
2198 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002199 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2200 intel_encoder_info(m, intel_crtc, intel_encoder);
2201}
2202
2203static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2204{
2205 struct drm_display_mode *mode = panel->fixed_mode;
2206
2207 seq_printf(m, "\tfixed mode:\n");
2208 intel_seq_print_mode(m, 2, mode);
2209}
2210
2211static void intel_dp_info(struct seq_file *m,
2212 struct intel_connector *intel_connector)
2213{
2214 struct intel_encoder *intel_encoder = intel_connector->encoder;
2215 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2216
2217 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2218 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2219 "no");
2220 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2221 intel_panel_info(m, &intel_connector->panel);
2222}
2223
2224static void intel_hdmi_info(struct seq_file *m,
2225 struct intel_connector *intel_connector)
2226{
2227 struct intel_encoder *intel_encoder = intel_connector->encoder;
2228 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2229
2230 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2231 "no");
2232}
2233
2234static void intel_lvds_info(struct seq_file *m,
2235 struct intel_connector *intel_connector)
2236{
2237 intel_panel_info(m, &intel_connector->panel);
2238}
2239
2240static void intel_connector_info(struct seq_file *m,
2241 struct drm_connector *connector)
2242{
2243 struct intel_connector *intel_connector = to_intel_connector(connector);
2244 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002245 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002246
2247 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002248 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002249 drm_get_connector_status_name(connector->status));
2250 if (connector->status == connector_status_connected) {
2251 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2252 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2253 connector->display_info.width_mm,
2254 connector->display_info.height_mm);
2255 seq_printf(m, "\tsubpixel order: %s\n",
2256 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2257 seq_printf(m, "\tCEA rev: %d\n",
2258 connector->display_info.cea_rev);
2259 }
Dave Airlie36cd7442014-05-02 13:44:18 +10002260 if (intel_encoder) {
2261 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2262 intel_encoder->type == INTEL_OUTPUT_EDP)
2263 intel_dp_info(m, intel_connector);
2264 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2265 intel_hdmi_info(m, intel_connector);
2266 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2267 intel_lvds_info(m, intel_connector);
2268 }
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002269
Jesse Barnesf103fc72014-02-20 12:39:57 -08002270 seq_printf(m, "\tmodes:\n");
2271 list_for_each_entry(mode, &connector->modes, head)
2272 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002273}
2274
Chris Wilson065f2ec2014-03-12 09:13:13 +00002275static bool cursor_active(struct drm_device *dev, int pipe)
2276{
2277 struct drm_i915_private *dev_priv = dev->dev_private;
2278 u32 state;
2279
2280 if (IS_845G(dev) || IS_I865G(dev))
2281 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002282 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002283 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002284
2285 return state;
2286}
2287
2288static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2289{
2290 struct drm_i915_private *dev_priv = dev->dev_private;
2291 u32 pos;
2292
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002293 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002294
2295 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2296 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2297 *x = -*x;
2298
2299 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2300 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2301 *y = -*y;
2302
2303 return cursor_active(dev, pipe);
2304}
2305
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002306static int i915_display_info(struct seq_file *m, void *unused)
2307{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002308 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002309 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002310 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002311 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002312 struct drm_connector *connector;
2313
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002314 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002315 drm_modeset_lock_all(dev);
2316 seq_printf(m, "CRTC info\n");
2317 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002318 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002319 bool active;
2320 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002321
Chris Wilson57127ef2014-07-04 08:20:11 +01002322 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002323 crtc->base.base.id, pipe_name(crtc->pipe),
Chris Wilson57127ef2014-07-04 08:20:11 +01002324 yesno(crtc->active), crtc->config.pipe_src_w, crtc->config.pipe_src_h);
Paulo Zanonia23dc652014-04-01 14:55:11 -03002325 if (crtc->active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002326 intel_crtc_info(m, crtc);
2327
Paulo Zanonia23dc652014-04-01 14:55:11 -03002328 active = cursor_position(dev, crtc->pipe, &x, &y);
Chris Wilson57127ef2014-07-04 08:20:11 +01002329 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 +03002330 yesno(crtc->cursor_base),
Chris Wilson57127ef2014-07-04 08:20:11 +01002331 x, y, crtc->cursor_width, crtc->cursor_height,
2332 crtc->cursor_addr, yesno(active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002333 }
Daniel Vettercace8412014-05-22 17:56:31 +02002334
2335 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2336 yesno(!crtc->cpu_fifo_underrun_disabled),
2337 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002338 }
2339
2340 seq_printf(m, "\n");
2341 seq_printf(m, "Connector info\n");
2342 seq_printf(m, "--------------\n");
2343 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2344 intel_connector_info(m, connector);
2345 }
2346 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002347 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002348
2349 return 0;
2350}
2351
Ben Widawskye04934c2014-06-30 09:53:42 -07002352static int i915_semaphore_status(struct seq_file *m, void *unused)
2353{
2354 struct drm_info_node *node = (struct drm_info_node *) m->private;
2355 struct drm_device *dev = node->minor->dev;
2356 struct drm_i915_private *dev_priv = dev->dev_private;
2357 struct intel_engine_cs *ring;
2358 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2359 int i, j, ret;
2360
2361 if (!i915_semaphore_is_enabled(dev)) {
2362 seq_puts(m, "Semaphores are disabled\n");
2363 return 0;
2364 }
2365
2366 ret = mutex_lock_interruptible(&dev->struct_mutex);
2367 if (ret)
2368 return ret;
Paulo Zanoni03872062014-07-09 14:31:57 -03002369 intel_runtime_pm_get(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002370
2371 if (IS_BROADWELL(dev)) {
2372 struct page *page;
2373 uint64_t *seqno;
2374
2375 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2376
2377 seqno = (uint64_t *)kmap_atomic(page);
2378 for_each_ring(ring, dev_priv, i) {
2379 uint64_t offset;
2380
2381 seq_printf(m, "%s\n", ring->name);
2382
2383 seq_puts(m, " Last signal:");
2384 for (j = 0; j < num_rings; j++) {
2385 offset = i * I915_NUM_RINGS + j;
2386 seq_printf(m, "0x%08llx (0x%02llx) ",
2387 seqno[offset], offset * 8);
2388 }
2389 seq_putc(m, '\n');
2390
2391 seq_puts(m, " Last wait: ");
2392 for (j = 0; j < num_rings; j++) {
2393 offset = i + (j * I915_NUM_RINGS);
2394 seq_printf(m, "0x%08llx (0x%02llx) ",
2395 seqno[offset], offset * 8);
2396 }
2397 seq_putc(m, '\n');
2398
2399 }
2400 kunmap_atomic(seqno);
2401 } else {
2402 seq_puts(m, " Last signal:");
2403 for_each_ring(ring, dev_priv, i)
2404 for (j = 0; j < num_rings; j++)
2405 seq_printf(m, "0x%08x\n",
2406 I915_READ(ring->semaphore.mbox.signal[j]));
2407 seq_putc(m, '\n');
2408 }
2409
2410 seq_puts(m, "\nSync seqno:\n");
2411 for_each_ring(ring, dev_priv, i) {
2412 for (j = 0; j < num_rings; j++) {
2413 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2414 }
2415 seq_putc(m, '\n');
2416 }
2417 seq_putc(m, '\n');
2418
Paulo Zanoni03872062014-07-09 14:31:57 -03002419 intel_runtime_pm_put(dev_priv);
Ben Widawskye04934c2014-06-30 09:53:42 -07002420 mutex_unlock(&dev->struct_mutex);
2421 return 0;
2422}
2423
Daniel Vetter728e29d2014-06-25 22:01:53 +03002424static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2425{
2426 struct drm_info_node *node = (struct drm_info_node *) m->private;
2427 struct drm_device *dev = node->minor->dev;
2428 struct drm_i915_private *dev_priv = dev->dev_private;
2429 int i;
2430
2431 drm_modeset_lock_all(dev);
2432 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2433 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2434
2435 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
2436 seq_printf(m, " refcount: %i, active: %i, on: %s\n", pll->refcount,
2437 pll->active, yesno(pll->on));
2438 seq_printf(m, " tracked hardware state:\n");
2439 seq_printf(m, " dpll: 0x%08x\n", pll->hw_state.dpll);
2440 seq_printf(m, " dpll_md: 0x%08x\n", pll->hw_state.dpll_md);
2441 seq_printf(m, " fp0: 0x%08x\n", pll->hw_state.fp0);
2442 seq_printf(m, " fp1: 0x%08x\n", pll->hw_state.fp1);
Daniel Vetterd452c5b2014-07-04 11:27:39 -03002443 seq_printf(m, " wrpll: 0x%08x\n", pll->hw_state.wrpll);
Daniel Vetter728e29d2014-06-25 22:01:53 +03002444 }
2445 drm_modeset_unlock_all(dev);
2446
2447 return 0;
2448}
2449
Damien Lespiau07144422013-10-15 18:55:40 +01002450struct pipe_crc_info {
2451 const char *name;
2452 struct drm_device *dev;
2453 enum pipe pipe;
2454};
2455
Dave Airlie11bed952014-05-12 15:22:27 +10002456static int i915_dp_mst_info(struct seq_file *m, void *unused)
2457{
2458 struct drm_info_node *node = (struct drm_info_node *) m->private;
2459 struct drm_device *dev = node->minor->dev;
2460 struct drm_encoder *encoder;
2461 struct intel_encoder *intel_encoder;
2462 struct intel_digital_port *intel_dig_port;
2463 drm_modeset_lock_all(dev);
2464 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
2465 intel_encoder = to_intel_encoder(encoder);
2466 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
2467 continue;
2468 intel_dig_port = enc_to_dig_port(encoder);
2469 if (!intel_dig_port->dp.can_mst)
2470 continue;
2471
2472 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
2473 }
2474 drm_modeset_unlock_all(dev);
2475 return 0;
2476}
2477
Damien Lespiau07144422013-10-15 18:55:40 +01002478static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01002479{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002480 struct pipe_crc_info *info = inode->i_private;
2481 struct drm_i915_private *dev_priv = info->dev->dev_private;
2482 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2483
Daniel Vetter7eb1c492013-11-14 11:30:43 +01002484 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
2485 return -ENODEV;
2486
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002487 spin_lock_irq(&pipe_crc->lock);
2488
2489 if (pipe_crc->opened) {
2490 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002491 return -EBUSY; /* already open */
2492 }
2493
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002494 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01002495 filep->private_data = inode->i_private;
2496
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002497 spin_unlock_irq(&pipe_crc->lock);
2498
Damien Lespiau07144422013-10-15 18:55:40 +01002499 return 0;
2500}
2501
2502static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
2503{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002504 struct pipe_crc_info *info = inode->i_private;
2505 struct drm_i915_private *dev_priv = info->dev->dev_private;
2506 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2507
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002508 spin_lock_irq(&pipe_crc->lock);
2509 pipe_crc->opened = false;
2510 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002511
Damien Lespiau07144422013-10-15 18:55:40 +01002512 return 0;
2513}
2514
2515/* (6 fields, 8 chars each, space separated (5) + '\n') */
2516#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
2517/* account for \'0' */
2518#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
2519
2520static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
2521{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002522 assert_spin_locked(&pipe_crc->lock);
2523 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2524 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01002525}
Shuang He8bf1e9f2013-10-15 18:55:27 +01002526
Damien Lespiau07144422013-10-15 18:55:40 +01002527static ssize_t
2528i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
2529 loff_t *pos)
2530{
2531 struct pipe_crc_info *info = filep->private_data;
2532 struct drm_device *dev = info->dev;
2533 struct drm_i915_private *dev_priv = dev->dev_private;
2534 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2535 char buf[PIPE_CRC_BUFFER_LEN];
2536 int head, tail, n_entries, n;
2537 ssize_t bytes_read;
2538
2539 /*
2540 * Don't allow user space to provide buffers not big enough to hold
2541 * a line of data.
2542 */
2543 if (count < PIPE_CRC_LINE_LEN)
2544 return -EINVAL;
2545
2546 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2547 return 0;
2548
2549 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002550 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002551 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002552 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002553
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002554 if (filep->f_flags & O_NONBLOCK) {
2555 spin_unlock_irq(&pipe_crc->lock);
2556 return -EAGAIN;
2557 }
2558
2559 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2560 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2561 if (ret) {
2562 spin_unlock_irq(&pipe_crc->lock);
2563 return ret;
2564 }
Damien Lespiau07144422013-10-15 18:55:40 +01002565 }
2566
2567 /* We now have one or more entries to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002568 head = pipe_crc->head;
2569 tail = pipe_crc->tail;
Damien Lespiau07144422013-10-15 18:55:40 +01002570 n_entries = min((size_t)CIRC_CNT(head, tail, INTEL_PIPE_CRC_ENTRIES_NR),
2571 count / PIPE_CRC_LINE_LEN);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002572 spin_unlock_irq(&pipe_crc->lock);
2573
Damien Lespiau07144422013-10-15 18:55:40 +01002574 bytes_read = 0;
2575 n = 0;
2576 do {
2577 struct intel_pipe_crc_entry *entry = &pipe_crc->entries[tail];
2578 int ret;
2579
2580 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
2581 "%8u %8x %8x %8x %8x %8x\n",
2582 entry->frame, entry->crc[0],
2583 entry->crc[1], entry->crc[2],
2584 entry->crc[3], entry->crc[4]);
2585
2586 ret = copy_to_user(user_buf + n * PIPE_CRC_LINE_LEN,
2587 buf, PIPE_CRC_LINE_LEN);
2588 if (ret == PIPE_CRC_LINE_LEN)
2589 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01002590
2591 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
2592 tail = (tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiau07144422013-10-15 18:55:40 +01002593 n++;
2594 } while (--n_entries);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002595
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002596 spin_lock_irq(&pipe_crc->lock);
2597 pipe_crc->tail = tail;
2598 spin_unlock_irq(&pipe_crc->lock);
2599
Damien Lespiau07144422013-10-15 18:55:40 +01002600 return bytes_read;
2601}
2602
2603static const struct file_operations i915_pipe_crc_fops = {
2604 .owner = THIS_MODULE,
2605 .open = i915_pipe_crc_open,
2606 .read = i915_pipe_crc_read,
2607 .release = i915_pipe_crc_release,
2608};
2609
2610static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
2611 {
2612 .name = "i915_pipe_A_crc",
2613 .pipe = PIPE_A,
2614 },
2615 {
2616 .name = "i915_pipe_B_crc",
2617 .pipe = PIPE_B,
2618 },
2619 {
2620 .name = "i915_pipe_C_crc",
2621 .pipe = PIPE_C,
2622 },
2623};
2624
2625static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
2626 enum pipe pipe)
2627{
2628 struct drm_device *dev = minor->dev;
2629 struct dentry *ent;
2630 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
2631
2632 info->dev = dev;
2633 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
2634 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08002635 if (!ent)
2636 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01002637
2638 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002639}
2640
Daniel Vettere8dfcf72013-10-16 11:51:54 +02002641static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02002642 "none",
2643 "plane1",
2644 "plane2",
2645 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002646 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02002647 "TV",
2648 "DP-B",
2649 "DP-C",
2650 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01002651 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02002652};
2653
2654static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
2655{
2656 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
2657 return pipe_crc_sources[source];
2658}
2659
Damien Lespiaubd9db022013-10-15 18:55:36 +01002660static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02002661{
2662 struct drm_device *dev = m->private;
2663 struct drm_i915_private *dev_priv = dev->dev_private;
2664 int i;
2665
2666 for (i = 0; i < I915_MAX_PIPES; i++)
2667 seq_printf(m, "%c %s\n", pipe_name(i),
2668 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
2669
2670 return 0;
2671}
2672
Damien Lespiaubd9db022013-10-15 18:55:36 +01002673static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02002674{
2675 struct drm_device *dev = inode->i_private;
2676
Damien Lespiaubd9db022013-10-15 18:55:36 +01002677 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02002678}
2679
Daniel Vetter46a19182013-11-01 10:50:20 +01002680static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02002681 uint32_t *val)
2682{
Daniel Vetter46a19182013-11-01 10:50:20 +01002683 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2684 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2685
2686 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02002687 case INTEL_PIPE_CRC_SOURCE_PIPE:
2688 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
2689 break;
2690 case INTEL_PIPE_CRC_SOURCE_NONE:
2691 *val = 0;
2692 break;
2693 default:
2694 return -EINVAL;
2695 }
2696
2697 return 0;
2698}
2699
Daniel Vetter46a19182013-11-01 10:50:20 +01002700static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
2701 enum intel_pipe_crc_source *source)
2702{
2703 struct intel_encoder *encoder;
2704 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01002705 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01002706 int ret = 0;
2707
2708 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2709
Daniel Vetter6e9f7982014-05-29 23:54:47 +02002710 drm_modeset_lock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01002711 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
2712 base.head) {
2713 if (!encoder->base.crtc)
2714 continue;
2715
2716 crtc = to_intel_crtc(encoder->base.crtc);
2717
2718 if (crtc->pipe != pipe)
2719 continue;
2720
2721 switch (encoder->type) {
2722 case INTEL_OUTPUT_TVOUT:
2723 *source = INTEL_PIPE_CRC_SOURCE_TV;
2724 break;
2725 case INTEL_OUTPUT_DISPLAYPORT:
2726 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01002727 dig_port = enc_to_dig_port(&encoder->base);
2728 switch (dig_port->port) {
2729 case PORT_B:
2730 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
2731 break;
2732 case PORT_C:
2733 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
2734 break;
2735 case PORT_D:
2736 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
2737 break;
2738 default:
2739 WARN(1, "nonexisting DP port %c\n",
2740 port_name(dig_port->port));
2741 break;
2742 }
Daniel Vetter46a19182013-11-01 10:50:20 +01002743 break;
2744 }
2745 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02002746 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01002747
2748 return ret;
2749}
2750
2751static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
2752 enum pipe pipe,
2753 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02002754 uint32_t *val)
2755{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002756 struct drm_i915_private *dev_priv = dev->dev_private;
2757 bool need_stable_symbols = false;
2758
Daniel Vetter46a19182013-11-01 10:50:20 +01002759 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2760 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2761 if (ret)
2762 return ret;
2763 }
2764
2765 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02002766 case INTEL_PIPE_CRC_SOURCE_PIPE:
2767 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
2768 break;
2769 case INTEL_PIPE_CRC_SOURCE_DP_B:
2770 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002771 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002772 break;
2773 case INTEL_PIPE_CRC_SOURCE_DP_C:
2774 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002775 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002776 break;
2777 case INTEL_PIPE_CRC_SOURCE_NONE:
2778 *val = 0;
2779 break;
2780 default:
2781 return -EINVAL;
2782 }
2783
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002784 /*
2785 * When the pipe CRC tap point is after the transcoders we need
2786 * to tweak symbol-level features to produce a deterministic series of
2787 * symbols for a given frame. We need to reset those features only once
2788 * a frame (instead of every nth symbol):
2789 * - DC-balance: used to ensure a better clock recovery from the data
2790 * link (SDVO)
2791 * - DisplayPort scrambling: used for EMI reduction
2792 */
2793 if (need_stable_symbols) {
2794 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2795
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002796 tmp |= DC_BALANCE_RESET_VLV;
2797 if (pipe == PIPE_A)
2798 tmp |= PIPE_A_SCRAMBLE_RESET;
2799 else
2800 tmp |= PIPE_B_SCRAMBLE_RESET;
2801
2802 I915_WRITE(PORT_DFT2_G4X, tmp);
2803 }
2804
Daniel Vetter7ac01292013-10-18 16:37:06 +02002805 return 0;
2806}
2807
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002808static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01002809 enum pipe pipe,
2810 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002811 uint32_t *val)
2812{
Daniel Vetter84093602013-11-01 10:50:21 +01002813 struct drm_i915_private *dev_priv = dev->dev_private;
2814 bool need_stable_symbols = false;
2815
Daniel Vetter46a19182013-11-01 10:50:20 +01002816 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2817 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2818 if (ret)
2819 return ret;
2820 }
2821
2822 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002823 case INTEL_PIPE_CRC_SOURCE_PIPE:
2824 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
2825 break;
2826 case INTEL_PIPE_CRC_SOURCE_TV:
2827 if (!SUPPORTS_TV(dev))
2828 return -EINVAL;
2829 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
2830 break;
2831 case INTEL_PIPE_CRC_SOURCE_DP_B:
2832 if (!IS_G4X(dev))
2833 return -EINVAL;
2834 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002835 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002836 break;
2837 case INTEL_PIPE_CRC_SOURCE_DP_C:
2838 if (!IS_G4X(dev))
2839 return -EINVAL;
2840 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002841 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002842 break;
2843 case INTEL_PIPE_CRC_SOURCE_DP_D:
2844 if (!IS_G4X(dev))
2845 return -EINVAL;
2846 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002847 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002848 break;
2849 case INTEL_PIPE_CRC_SOURCE_NONE:
2850 *val = 0;
2851 break;
2852 default:
2853 return -EINVAL;
2854 }
2855
Daniel Vetter84093602013-11-01 10:50:21 +01002856 /*
2857 * When the pipe CRC tap point is after the transcoders we need
2858 * to tweak symbol-level features to produce a deterministic series of
2859 * symbols for a given frame. We need to reset those features only once
2860 * a frame (instead of every nth symbol):
2861 * - DC-balance: used to ensure a better clock recovery from the data
2862 * link (SDVO)
2863 * - DisplayPort scrambling: used for EMI reduction
2864 */
2865 if (need_stable_symbols) {
2866 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2867
2868 WARN_ON(!IS_G4X(dev));
2869
2870 I915_WRITE(PORT_DFT_I9XX,
2871 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
2872
2873 if (pipe == PIPE_A)
2874 tmp |= PIPE_A_SCRAMBLE_RESET;
2875 else
2876 tmp |= PIPE_B_SCRAMBLE_RESET;
2877
2878 I915_WRITE(PORT_DFT2_G4X, tmp);
2879 }
2880
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002881 return 0;
2882}
2883
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002884static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
2885 enum pipe pipe)
2886{
2887 struct drm_i915_private *dev_priv = dev->dev_private;
2888 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2889
2890 if (pipe == PIPE_A)
2891 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2892 else
2893 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2894 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
2895 tmp &= ~DC_BALANCE_RESET_VLV;
2896 I915_WRITE(PORT_DFT2_G4X, tmp);
2897
2898}
2899
Daniel Vetter84093602013-11-01 10:50:21 +01002900static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
2901 enum pipe pipe)
2902{
2903 struct drm_i915_private *dev_priv = dev->dev_private;
2904 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2905
2906 if (pipe == PIPE_A)
2907 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2908 else
2909 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2910 I915_WRITE(PORT_DFT2_G4X, tmp);
2911
2912 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
2913 I915_WRITE(PORT_DFT_I9XX,
2914 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
2915 }
2916}
2917
Daniel Vetter46a19182013-11-01 10:50:20 +01002918static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002919 uint32_t *val)
2920{
Daniel Vetter46a19182013-11-01 10:50:20 +01002921 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2922 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2923
2924 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002925 case INTEL_PIPE_CRC_SOURCE_PLANE1:
2926 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
2927 break;
2928 case INTEL_PIPE_CRC_SOURCE_PLANE2:
2929 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
2930 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002931 case INTEL_PIPE_CRC_SOURCE_PIPE:
2932 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
2933 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002934 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002935 *val = 0;
2936 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002937 default:
2938 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002939 }
2940
2941 return 0;
2942}
2943
Daniel Vetterfabf6e52014-05-29 14:10:22 +02002944static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
2945{
2946 struct drm_i915_private *dev_priv = dev->dev_private;
2947 struct intel_crtc *crtc =
2948 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
2949
2950 drm_modeset_lock_all(dev);
2951 /*
2952 * If we use the eDP transcoder we need to make sure that we don't
2953 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
2954 * relevant on hsw with pipe A when using the always-on power well
2955 * routing.
2956 */
2957 if (crtc->config.cpu_transcoder == TRANSCODER_EDP &&
2958 !crtc->config.pch_pfit.enabled) {
2959 crtc->config.pch_pfit.force_thru = true;
2960
2961 intel_display_power_get(dev_priv,
2962 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
2963
2964 dev_priv->display.crtc_disable(&crtc->base);
2965 dev_priv->display.crtc_enable(&crtc->base);
2966 }
2967 drm_modeset_unlock_all(dev);
2968}
2969
2970static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
2971{
2972 struct drm_i915_private *dev_priv = dev->dev_private;
2973 struct intel_crtc *crtc =
2974 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
2975
2976 drm_modeset_lock_all(dev);
2977 /*
2978 * If we use the eDP transcoder we need to make sure that we don't
2979 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
2980 * relevant on hsw with pipe A when using the always-on power well
2981 * routing.
2982 */
2983 if (crtc->config.pch_pfit.force_thru) {
2984 crtc->config.pch_pfit.force_thru = false;
2985
2986 dev_priv->display.crtc_disable(&crtc->base);
2987 dev_priv->display.crtc_enable(&crtc->base);
2988
2989 intel_display_power_put(dev_priv,
2990 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
2991 }
2992 drm_modeset_unlock_all(dev);
2993}
2994
2995static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
2996 enum pipe pipe,
2997 enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002998 uint32_t *val)
2999{
Daniel Vetter46a19182013-11-01 10:50:20 +01003000 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3001 *source = INTEL_PIPE_CRC_SOURCE_PF;
3002
3003 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003004 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3005 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3006 break;
3007 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3008 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3009 break;
3010 case INTEL_PIPE_CRC_SOURCE_PF:
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003011 if (IS_HASWELL(dev) && pipe == PIPE_A)
3012 hsw_trans_edp_pipe_A_crc_wa(dev);
3013
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003014 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3015 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003016 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003017 *val = 0;
3018 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02003019 default:
3020 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003021 }
3022
3023 return 0;
3024}
3025
Daniel Vetter926321d2013-10-16 13:30:34 +02003026static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3027 enum intel_pipe_crc_source source)
3028{
3029 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01003030 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Borislav Petkov432f3342013-11-21 16:49:46 +01003031 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003032 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02003033
Damien Lespiaucc3da172013-10-15 18:55:31 +01003034 if (pipe_crc->source == source)
3035 return 0;
3036
Damien Lespiauae676fc2013-10-15 18:55:32 +01003037 /* forbid changing the source without going back to 'none' */
3038 if (pipe_crc->source && source)
3039 return -EINVAL;
3040
Daniel Vetter52f843f2013-10-21 17:26:38 +02003041 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003042 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02003043 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01003044 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02003045 else if (IS_VALLEYVIEW(dev))
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003046 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02003047 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01003048 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003049 else
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003050 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003051
3052 if (ret != 0)
3053 return ret;
3054
Damien Lespiau4b584362013-10-15 18:55:33 +01003055 /* none -> real source transition */
3056 if (source) {
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003057 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3058 pipe_name(pipe), pipe_crc_source_name(source));
3059
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003060 pipe_crc->entries = kzalloc(sizeof(*pipe_crc->entries) *
3061 INTEL_PIPE_CRC_ENTRIES_NR,
3062 GFP_KERNEL);
3063 if (!pipe_crc->entries)
3064 return -ENOMEM;
3065
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003066 spin_lock_irq(&pipe_crc->lock);
3067 pipe_crc->head = 0;
3068 pipe_crc->tail = 0;
3069 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01003070 }
3071
Damien Lespiaucc3da172013-10-15 18:55:31 +01003072 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02003073
Daniel Vetter926321d2013-10-16 13:30:34 +02003074 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3075 POSTING_READ(PIPE_CRC_CTL(pipe));
3076
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003077 /* real source -> none transition */
3078 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003079 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02003080 struct intel_crtc *crtc =
3081 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003082
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01003083 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3084 pipe_name(pipe));
3085
Daniel Vettera33d7102014-06-06 08:22:08 +02003086 drm_modeset_lock(&crtc->base.mutex, NULL);
3087 if (crtc->active)
3088 intel_wait_for_vblank(dev, pipe);
3089 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02003090
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003091 spin_lock_irq(&pipe_crc->lock);
3092 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003093 pipe_crc->entries = NULL;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003094 spin_unlock_irq(&pipe_crc->lock);
3095
3096 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01003097
3098 if (IS_G4X(dev))
3099 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01003100 else if (IS_VALLEYVIEW(dev))
3101 vlv_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetterfabf6e52014-05-29 14:10:22 +02003102 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3103 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01003104 }
3105
Daniel Vetter926321d2013-10-16 13:30:34 +02003106 return 0;
3107}
3108
3109/*
3110 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003111 * command: wsp* object wsp+ name wsp+ source wsp*
3112 * object: 'pipe'
3113 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02003114 * source: (none | plane1 | plane2 | pf)
3115 * wsp: (#0x20 | #0x9 | #0xA)+
3116 *
3117 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01003118 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3119 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02003120 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01003121static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02003122{
3123 int n_words = 0;
3124
3125 while (*buf) {
3126 char *end;
3127
3128 /* skip leading white space */
3129 buf = skip_spaces(buf);
3130 if (!*buf)
3131 break; /* end of buffer */
3132
3133 /* find end of word */
3134 for (end = buf; *end && !isspace(*end); end++)
3135 ;
3136
3137 if (n_words == max_words) {
3138 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3139 max_words);
3140 return -EINVAL; /* ran out of words[] before bytes */
3141 }
3142
3143 if (*end)
3144 *end++ = '\0';
3145 words[n_words++] = buf;
3146 buf = end;
3147 }
3148
3149 return n_words;
3150}
3151
Damien Lespiaub94dec82013-10-15 18:55:35 +01003152enum intel_pipe_crc_object {
3153 PIPE_CRC_OBJECT_PIPE,
3154};
3155
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003156static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003157 "pipe",
3158};
3159
3160static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003161display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003162{
3163 int i;
3164
3165 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3166 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003167 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003168 return 0;
3169 }
3170
3171 return -EINVAL;
3172}
3173
Damien Lespiaubd9db022013-10-15 18:55:36 +01003174static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003175{
3176 const char name = buf[0];
3177
3178 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3179 return -EINVAL;
3180
3181 *pipe = name - 'A';
3182
3183 return 0;
3184}
3185
3186static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003187display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003188{
3189 int i;
3190
3191 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3192 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003193 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003194 return 0;
3195 }
3196
3197 return -EINVAL;
3198}
3199
Damien Lespiaubd9db022013-10-15 18:55:36 +01003200static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003201{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003202#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003203 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003204 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003205 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003206 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003207 enum intel_pipe_crc_source source;
3208
Damien Lespiaubd9db022013-10-15 18:55:36 +01003209 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003210 if (n_words != N_WORDS) {
3211 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3212 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003213 return -EINVAL;
3214 }
3215
Damien Lespiaubd9db022013-10-15 18:55:36 +01003216 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003217 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003218 return -EINVAL;
3219 }
3220
Damien Lespiaubd9db022013-10-15 18:55:36 +01003221 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003222 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3223 return -EINVAL;
3224 }
3225
Damien Lespiaubd9db022013-10-15 18:55:36 +01003226 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003227 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003228 return -EINVAL;
3229 }
3230
3231 return pipe_crc_set_source(dev, pipe, source);
3232}
3233
Damien Lespiaubd9db022013-10-15 18:55:36 +01003234static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3235 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003236{
3237 struct seq_file *m = file->private_data;
3238 struct drm_device *dev = m->private;
3239 char *tmpbuf;
3240 int ret;
3241
3242 if (len == 0)
3243 return 0;
3244
3245 if (len > PAGE_SIZE - 1) {
3246 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3247 PAGE_SIZE);
3248 return -E2BIG;
3249 }
3250
3251 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3252 if (!tmpbuf)
3253 return -ENOMEM;
3254
3255 if (copy_from_user(tmpbuf, ubuf, len)) {
3256 ret = -EFAULT;
3257 goto out;
3258 }
3259 tmpbuf[len] = '\0';
3260
Damien Lespiaubd9db022013-10-15 18:55:36 +01003261 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003262
3263out:
3264 kfree(tmpbuf);
3265 if (ret < 0)
3266 return ret;
3267
3268 *offp += len;
3269 return len;
3270}
3271
Damien Lespiaubd9db022013-10-15 18:55:36 +01003272static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003273 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003274 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003275 .read = seq_read,
3276 .llseek = seq_lseek,
3277 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003278 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003279};
3280
Ville Syrjälä369a1342014-01-22 14:36:08 +02003281static void wm_latency_show(struct seq_file *m, const uint16_t wm[5])
3282{
3283 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003284 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003285 int level;
3286
3287 drm_modeset_lock_all(dev);
3288
3289 for (level = 0; level < num_levels; level++) {
3290 unsigned int latency = wm[level];
3291
3292 /* WM1+ latency values in 0.5us units */
3293 if (level > 0)
3294 latency *= 5;
3295
3296 seq_printf(m, "WM%d %u (%u.%u usec)\n",
3297 level, wm[level],
3298 latency / 10, latency % 10);
3299 }
3300
3301 drm_modeset_unlock_all(dev);
3302}
3303
3304static int pri_wm_latency_show(struct seq_file *m, void *data)
3305{
3306 struct drm_device *dev = m->private;
3307
3308 wm_latency_show(m, to_i915(dev)->wm.pri_latency);
3309
3310 return 0;
3311}
3312
3313static int spr_wm_latency_show(struct seq_file *m, void *data)
3314{
3315 struct drm_device *dev = m->private;
3316
3317 wm_latency_show(m, to_i915(dev)->wm.spr_latency);
3318
3319 return 0;
3320}
3321
3322static int cur_wm_latency_show(struct seq_file *m, void *data)
3323{
3324 struct drm_device *dev = m->private;
3325
3326 wm_latency_show(m, to_i915(dev)->wm.cur_latency);
3327
3328 return 0;
3329}
3330
3331static int pri_wm_latency_open(struct inode *inode, struct file *file)
3332{
3333 struct drm_device *dev = inode->i_private;
3334
Sonika Jindal9ad02572014-07-21 15:23:39 +05303335 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003336 return -ENODEV;
3337
3338 return single_open(file, pri_wm_latency_show, dev);
3339}
3340
3341static int spr_wm_latency_open(struct inode *inode, struct file *file)
3342{
3343 struct drm_device *dev = inode->i_private;
3344
Sonika Jindal9ad02572014-07-21 15:23:39 +05303345 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003346 return -ENODEV;
3347
3348 return single_open(file, spr_wm_latency_show, dev);
3349}
3350
3351static int cur_wm_latency_open(struct inode *inode, struct file *file)
3352{
3353 struct drm_device *dev = inode->i_private;
3354
Sonika Jindal9ad02572014-07-21 15:23:39 +05303355 if (HAS_GMCH_DISPLAY(dev))
Ville Syrjälä369a1342014-01-22 14:36:08 +02003356 return -ENODEV;
3357
3358 return single_open(file, cur_wm_latency_show, dev);
3359}
3360
3361static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
3362 size_t len, loff_t *offp, uint16_t wm[5])
3363{
3364 struct seq_file *m = file->private_data;
3365 struct drm_device *dev = m->private;
3366 uint16_t new[5] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003367 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003368 int level;
3369 int ret;
3370 char tmp[32];
3371
3372 if (len >= sizeof(tmp))
3373 return -EINVAL;
3374
3375 if (copy_from_user(tmp, ubuf, len))
3376 return -EFAULT;
3377
3378 tmp[len] = '\0';
3379
3380 ret = sscanf(tmp, "%hu %hu %hu %hu %hu", &new[0], &new[1], &new[2], &new[3], &new[4]);
3381 if (ret != num_levels)
3382 return -EINVAL;
3383
3384 drm_modeset_lock_all(dev);
3385
3386 for (level = 0; level < num_levels; level++)
3387 wm[level] = new[level];
3388
3389 drm_modeset_unlock_all(dev);
3390
3391 return len;
3392}
3393
3394
3395static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3396 size_t len, loff_t *offp)
3397{
3398 struct seq_file *m = file->private_data;
3399 struct drm_device *dev = m->private;
3400
3401 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.pri_latency);
3402}
3403
3404static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3405 size_t len, loff_t *offp)
3406{
3407 struct seq_file *m = file->private_data;
3408 struct drm_device *dev = m->private;
3409
3410 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.spr_latency);
3411}
3412
3413static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3414 size_t len, loff_t *offp)
3415{
3416 struct seq_file *m = file->private_data;
3417 struct drm_device *dev = m->private;
3418
3419 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.cur_latency);
3420}
3421
3422static const struct file_operations i915_pri_wm_latency_fops = {
3423 .owner = THIS_MODULE,
3424 .open = pri_wm_latency_open,
3425 .read = seq_read,
3426 .llseek = seq_lseek,
3427 .release = single_release,
3428 .write = pri_wm_latency_write
3429};
3430
3431static const struct file_operations i915_spr_wm_latency_fops = {
3432 .owner = THIS_MODULE,
3433 .open = spr_wm_latency_open,
3434 .read = seq_read,
3435 .llseek = seq_lseek,
3436 .release = single_release,
3437 .write = spr_wm_latency_write
3438};
3439
3440static const struct file_operations i915_cur_wm_latency_fops = {
3441 .owner = THIS_MODULE,
3442 .open = cur_wm_latency_open,
3443 .read = seq_read,
3444 .llseek = seq_lseek,
3445 .release = single_release,
3446 .write = cur_wm_latency_write
3447};
3448
Kees Cook647416f2013-03-10 14:10:06 -07003449static int
3450i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003451{
Kees Cook647416f2013-03-10 14:10:06 -07003452 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003453 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003454
Kees Cook647416f2013-03-10 14:10:06 -07003455 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003456
Kees Cook647416f2013-03-10 14:10:06 -07003457 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003458}
3459
Kees Cook647416f2013-03-10 14:10:06 -07003460static int
3461i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003462{
Kees Cook647416f2013-03-10 14:10:06 -07003463 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03003464 struct drm_i915_private *dev_priv = dev->dev_private;
3465
3466 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003467
Mika Kuoppala58174462014-02-25 17:11:26 +02003468 i915_handle_error(dev, val,
3469 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03003470
3471 intel_runtime_pm_put(dev_priv);
3472
Kees Cook647416f2013-03-10 14:10:06 -07003473 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003474}
3475
Kees Cook647416f2013-03-10 14:10:06 -07003476DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
3477 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003478 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003479
Kees Cook647416f2013-03-10 14:10:06 -07003480static int
3481i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003482{
Kees Cook647416f2013-03-10 14:10:06 -07003483 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003484 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003485
Kees Cook647416f2013-03-10 14:10:06 -07003486 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003487
Kees Cook647416f2013-03-10 14:10:06 -07003488 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003489}
3490
Kees Cook647416f2013-03-10 14:10:06 -07003491static int
3492i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003493{
Kees Cook647416f2013-03-10 14:10:06 -07003494 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003495 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003496 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003497
Kees Cook647416f2013-03-10 14:10:06 -07003498 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003499
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003500 ret = mutex_lock_interruptible(&dev->struct_mutex);
3501 if (ret)
3502 return ret;
3503
Daniel Vetter99584db2012-11-14 17:14:04 +01003504 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003505 mutex_unlock(&dev->struct_mutex);
3506
Kees Cook647416f2013-03-10 14:10:06 -07003507 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003508}
3509
Kees Cook647416f2013-03-10 14:10:06 -07003510DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
3511 i915_ring_stop_get, i915_ring_stop_set,
3512 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02003513
Chris Wilson094f9a52013-09-25 17:34:55 +01003514static int
3515i915_ring_missed_irq_get(void *data, u64 *val)
3516{
3517 struct drm_device *dev = data;
3518 struct drm_i915_private *dev_priv = dev->dev_private;
3519
3520 *val = dev_priv->gpu_error.missed_irq_rings;
3521 return 0;
3522}
3523
3524static int
3525i915_ring_missed_irq_set(void *data, u64 val)
3526{
3527 struct drm_device *dev = data;
3528 struct drm_i915_private *dev_priv = dev->dev_private;
3529 int ret;
3530
3531 /* Lock against concurrent debugfs callers */
3532 ret = mutex_lock_interruptible(&dev->struct_mutex);
3533 if (ret)
3534 return ret;
3535 dev_priv->gpu_error.missed_irq_rings = val;
3536 mutex_unlock(&dev->struct_mutex);
3537
3538 return 0;
3539}
3540
3541DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
3542 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
3543 "0x%08llx\n");
3544
3545static int
3546i915_ring_test_irq_get(void *data, u64 *val)
3547{
3548 struct drm_device *dev = data;
3549 struct drm_i915_private *dev_priv = dev->dev_private;
3550
3551 *val = dev_priv->gpu_error.test_irq_rings;
3552
3553 return 0;
3554}
3555
3556static int
3557i915_ring_test_irq_set(void *data, u64 val)
3558{
3559 struct drm_device *dev = data;
3560 struct drm_i915_private *dev_priv = dev->dev_private;
3561 int ret;
3562
3563 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
3564
3565 /* Lock against concurrent debugfs callers */
3566 ret = mutex_lock_interruptible(&dev->struct_mutex);
3567 if (ret)
3568 return ret;
3569
3570 dev_priv->gpu_error.test_irq_rings = val;
3571 mutex_unlock(&dev->struct_mutex);
3572
3573 return 0;
3574}
3575
3576DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
3577 i915_ring_test_irq_get, i915_ring_test_irq_set,
3578 "0x%08llx\n");
3579
Chris Wilsondd624af2013-01-15 12:39:35 +00003580#define DROP_UNBOUND 0x1
3581#define DROP_BOUND 0x2
3582#define DROP_RETIRE 0x4
3583#define DROP_ACTIVE 0x8
3584#define DROP_ALL (DROP_UNBOUND | \
3585 DROP_BOUND | \
3586 DROP_RETIRE | \
3587 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07003588static int
3589i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003590{
Kees Cook647416f2013-03-10 14:10:06 -07003591 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00003592
Kees Cook647416f2013-03-10 14:10:06 -07003593 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00003594}
3595
Kees Cook647416f2013-03-10 14:10:06 -07003596static int
3597i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003598{
Kees Cook647416f2013-03-10 14:10:06 -07003599 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00003600 struct drm_i915_private *dev_priv = dev->dev_private;
3601 struct drm_i915_gem_object *obj, *next;
Ben Widawskyca191b12013-07-31 17:00:14 -07003602 struct i915_address_space *vm;
3603 struct i915_vma *vma, *x;
Kees Cook647416f2013-03-10 14:10:06 -07003604 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003605
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08003606 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00003607
3608 /* No need to check and wait for gpu resets, only libdrm auto-restarts
3609 * on ioctls on -EAGAIN. */
3610 ret = mutex_lock_interruptible(&dev->struct_mutex);
3611 if (ret)
3612 return ret;
3613
3614 if (val & DROP_ACTIVE) {
3615 ret = i915_gpu_idle(dev);
3616 if (ret)
3617 goto unlock;
3618 }
3619
3620 if (val & (DROP_RETIRE | DROP_ACTIVE))
3621 i915_gem_retire_requests(dev);
3622
3623 if (val & DROP_BOUND) {
Ben Widawskyca191b12013-07-31 17:00:14 -07003624 list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
3625 list_for_each_entry_safe(vma, x, &vm->inactive_list,
3626 mm_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -08003627 if (vma->pin_count)
Ben Widawskyca191b12013-07-31 17:00:14 -07003628 continue;
Ben Widawsky31a46c92013-07-31 16:59:55 -07003629
Ben Widawskyca191b12013-07-31 17:00:14 -07003630 ret = i915_vma_unbind(vma);
3631 if (ret)
3632 goto unlock;
3633 }
Ben Widawsky31a46c92013-07-31 16:59:55 -07003634 }
Chris Wilsondd624af2013-01-15 12:39:35 +00003635 }
3636
3637 if (val & DROP_UNBOUND) {
Ben Widawsky35c20a62013-05-31 11:28:48 -07003638 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list,
3639 global_list)
Chris Wilsondd624af2013-01-15 12:39:35 +00003640 if (obj->pages_pin_count == 0) {
3641 ret = i915_gem_object_put_pages(obj);
3642 if (ret)
3643 goto unlock;
3644 }
3645 }
3646
3647unlock:
3648 mutex_unlock(&dev->struct_mutex);
3649
Kees Cook647416f2013-03-10 14:10:06 -07003650 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003651}
3652
Kees Cook647416f2013-03-10 14:10:06 -07003653DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
3654 i915_drop_caches_get, i915_drop_caches_set,
3655 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00003656
Kees Cook647416f2013-03-10 14:10:06 -07003657static int
3658i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07003659{
Kees Cook647416f2013-03-10 14:10:06 -07003660 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003661 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003662 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003663
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003664 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003665 return -ENODEV;
3666
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003667 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3668
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003669 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003670 if (ret)
3671 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07003672
Jesse Barnes0a073b82013-04-17 15:54:58 -07003673 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07003674 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003675 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07003676 *val = dev_priv->rps.max_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003677 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07003678
Kees Cook647416f2013-03-10 14:10:06 -07003679 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07003680}
3681
Kees Cook647416f2013-03-10 14:10:06 -07003682static int
3683i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07003684{
Kees Cook647416f2013-03-10 14:10:06 -07003685 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07003686 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003687 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07003688 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003689
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003690 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003691 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07003692
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003693 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3694
Kees Cook647416f2013-03-10 14:10:06 -07003695 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07003696
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003697 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003698 if (ret)
3699 return ret;
3700
Jesse Barnes358733e2011-07-27 11:53:01 -07003701 /*
3702 * Turbo will still be enabled, but won't go above the set value.
3703 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07003704 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02003705 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003706
Ville Syrjälä03af2042014-06-28 02:03:53 +03003707 hw_max = dev_priv->rps.max_freq;
3708 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003709 } else {
3710 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003711
3712 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07003713 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003714 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003715 }
3716
Ben Widawskyb39fb292014-03-19 18:31:11 -07003717 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003718 mutex_unlock(&dev_priv->rps.hw_lock);
3719 return -EINVAL;
3720 }
3721
Ben Widawskyb39fb292014-03-19 18:31:11 -07003722 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003723
3724 if (IS_VALLEYVIEW(dev))
3725 valleyview_set_rps(dev, val);
3726 else
3727 gen6_set_rps(dev, val);
3728
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003729 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07003730
Kees Cook647416f2013-03-10 14:10:06 -07003731 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07003732}
3733
Kees Cook647416f2013-03-10 14:10:06 -07003734DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
3735 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003736 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07003737
Kees Cook647416f2013-03-10 14:10:06 -07003738static int
3739i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07003740{
Kees Cook647416f2013-03-10 14:10:06 -07003741 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003742 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003743 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003744
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003745 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003746 return -ENODEV;
3747
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003748 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3749
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003750 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003751 if (ret)
3752 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07003753
Jesse Barnes0a073b82013-04-17 15:54:58 -07003754 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07003755 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003756 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07003757 *val = dev_priv->rps.min_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003758 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003759
Kees Cook647416f2013-03-10 14:10:06 -07003760 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003761}
3762
Kees Cook647416f2013-03-10 14:10:06 -07003763static int
3764i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07003765{
Kees Cook647416f2013-03-10 14:10:06 -07003766 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07003767 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003768 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07003769 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003770
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003771 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003772 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07003773
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003774 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3775
Kees Cook647416f2013-03-10 14:10:06 -07003776 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07003777
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003778 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003779 if (ret)
3780 return ret;
3781
Jesse Barnes1523c312012-05-25 12:34:54 -07003782 /*
3783 * Turbo will still be enabled, but won't go below the set value.
3784 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07003785 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02003786 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003787
Ville Syrjälä03af2042014-06-28 02:03:53 +03003788 hw_max = dev_priv->rps.max_freq;
3789 hw_min = dev_priv->rps.min_freq;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003790 } else {
3791 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003792
3793 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07003794 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003795 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003796 }
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003797
Ben Widawskyb39fb292014-03-19 18:31:11 -07003798 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003799 mutex_unlock(&dev_priv->rps.hw_lock);
3800 return -EINVAL;
3801 }
3802
Ben Widawskyb39fb292014-03-19 18:31:11 -07003803 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003804
3805 if (IS_VALLEYVIEW(dev))
3806 valleyview_set_rps(dev, val);
3807 else
3808 gen6_set_rps(dev, val);
3809
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003810 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003811
Kees Cook647416f2013-03-10 14:10:06 -07003812 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003813}
3814
Kees Cook647416f2013-03-10 14:10:06 -07003815DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
3816 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003817 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07003818
Kees Cook647416f2013-03-10 14:10:06 -07003819static int
3820i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003821{
Kees Cook647416f2013-03-10 14:10:06 -07003822 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003823 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003824 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07003825 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003826
Daniel Vetter004777c2012-08-09 15:07:01 +02003827 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3828 return -ENODEV;
3829
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003830 ret = mutex_lock_interruptible(&dev->struct_mutex);
3831 if (ret)
3832 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003833 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003834
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003835 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003836
3837 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003838 mutex_unlock(&dev_priv->dev->struct_mutex);
3839
Kees Cook647416f2013-03-10 14:10:06 -07003840 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003841
Kees Cook647416f2013-03-10 14:10:06 -07003842 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003843}
3844
Kees Cook647416f2013-03-10 14:10:06 -07003845static int
3846i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003847{
Kees Cook647416f2013-03-10 14:10:06 -07003848 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003849 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003850 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003851
Daniel Vetter004777c2012-08-09 15:07:01 +02003852 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3853 return -ENODEV;
3854
Kees Cook647416f2013-03-10 14:10:06 -07003855 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003856 return -EINVAL;
3857
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003858 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07003859 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003860
3861 /* Update the cache sharing policy here as well */
3862 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
3863 snpcr &= ~GEN6_MBC_SNPCR_MASK;
3864 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
3865 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
3866
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003867 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07003868 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003869}
3870
Kees Cook647416f2013-03-10 14:10:06 -07003871DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
3872 i915_cache_sharing_get, i915_cache_sharing_set,
3873 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003874
Ben Widawsky6d794d42011-04-25 11:25:56 -07003875static int i915_forcewake_open(struct inode *inode, struct file *file)
3876{
3877 struct drm_device *dev = inode->i_private;
3878 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003879
Daniel Vetter075edca2012-01-24 09:44:28 +01003880 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003881 return 0;
3882
Deepak Sc8d9a592013-11-23 14:55:42 +05303883 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003884
3885 return 0;
3886}
3887
Ben Widawskyc43b5632012-04-16 14:07:40 -07003888static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003889{
3890 struct drm_device *dev = inode->i_private;
3891 struct drm_i915_private *dev_priv = dev->dev_private;
3892
Daniel Vetter075edca2012-01-24 09:44:28 +01003893 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003894 return 0;
3895
Deepak Sc8d9a592013-11-23 14:55:42 +05303896 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003897
3898 return 0;
3899}
3900
3901static const struct file_operations i915_forcewake_fops = {
3902 .owner = THIS_MODULE,
3903 .open = i915_forcewake_open,
3904 .release = i915_forcewake_release,
3905};
3906
3907static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
3908{
3909 struct drm_device *dev = minor->dev;
3910 struct dentry *ent;
3911
3912 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07003913 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07003914 root, dev,
3915 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003916 if (!ent)
3917 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003918
Ben Widawsky8eb57292011-05-11 15:10:58 -07003919 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003920}
3921
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003922static int i915_debugfs_create(struct dentry *root,
3923 struct drm_minor *minor,
3924 const char *name,
3925 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07003926{
3927 struct drm_device *dev = minor->dev;
3928 struct dentry *ent;
3929
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003930 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07003931 S_IRUGO | S_IWUSR,
3932 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003933 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003934 if (!ent)
3935 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07003936
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003937 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003938}
3939
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003940static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00003941 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01003942 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00003943 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01003944 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003945 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003946 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b88852013-08-07 18:30:54 +01003947 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01003948 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003949 {"i915_gem_request", i915_gem_request_info, 0},
3950 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00003951 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003952 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003953 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
3954 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
3955 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07003956 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Deepak Sadb4bd12014-03-31 11:30:02 +05303957 {"i915_frequency_info", i915_frequency_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08003958 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07003959 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07003960 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08003961 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03003962 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08003963 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01003964 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01003965 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07003966 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07003967 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01003968 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01003969 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07003970 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03003971 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003972 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01003973 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03003974 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02003975 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003976 {"i915_display_info", i915_display_info, 0},
Ben Widawskye04934c2014-06-30 09:53:42 -07003977 {"i915_semaphore_status", i915_semaphore_status, 0},
Daniel Vetter728e29d2014-06-25 22:01:53 +03003978 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
Dave Airlie11bed952014-05-12 15:22:27 +10003979 {"i915_dp_mst_info", i915_dp_mst_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003980};
Ben Gamari27c202a2009-07-01 22:26:52 -04003981#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05003982
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003983static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02003984 const char *name;
3985 const struct file_operations *fops;
3986} i915_debugfs_files[] = {
3987 {"i915_wedged", &i915_wedged_fops},
3988 {"i915_max_freq", &i915_max_freq_fops},
3989 {"i915_min_freq", &i915_min_freq_fops},
3990 {"i915_cache_sharing", &i915_cache_sharing_fops},
3991 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01003992 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
3993 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02003994 {"i915_gem_drop_caches", &i915_drop_caches_fops},
3995 {"i915_error_state", &i915_error_state_fops},
3996 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01003997 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02003998 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
3999 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
4000 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Rodrigo Vivida46f932014-08-01 02:04:45 -07004001 {"i915_fbc_false_color", &i915_fbc_fc_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02004002};
4003
Damien Lespiau07144422013-10-15 18:55:40 +01004004void intel_display_crc_init(struct drm_device *dev)
4005{
4006 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01004007 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01004008
Daniel Vetterb3783602013-11-14 11:30:42 +01004009 for_each_pipe(pipe) {
4010 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01004011
Damien Lespiaud538bbd2013-10-21 14:29:30 +01004012 pipe_crc->opened = false;
4013 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01004014 init_waitqueue_head(&pipe_crc->wq);
4015 }
4016}
4017
Ben Gamari27c202a2009-07-01 22:26:52 -04004018int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004019{
Daniel Vetter34b96742013-07-04 20:49:44 +02004020 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01004021
Ben Widawsky6d794d42011-04-25 11:25:56 -07004022 ret = i915_forcewake_create(minor->debugfs_root, minor);
4023 if (ret)
4024 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01004025
Damien Lespiau07144422013-10-15 18:55:40 +01004026 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
4027 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
4028 if (ret)
4029 return ret;
4030 }
4031
Daniel Vetter34b96742013-07-04 20:49:44 +02004032 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4033 ret = i915_debugfs_create(minor->debugfs_root, minor,
4034 i915_debugfs_files[i].name,
4035 i915_debugfs_files[i].fops);
4036 if (ret)
4037 return ret;
4038 }
Mika Kuoppala40633212012-12-04 15:12:00 +02004039
Ben Gamari27c202a2009-07-01 22:26:52 -04004040 return drm_debugfs_create_files(i915_debugfs_list,
4041 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05004042 minor->debugfs_root, minor);
4043}
4044
Ben Gamari27c202a2009-07-01 22:26:52 -04004045void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05004046{
Daniel Vetter34b96742013-07-04 20:49:44 +02004047 int i;
4048
Ben Gamari27c202a2009-07-01 22:26:52 -04004049 drm_debugfs_remove_files(i915_debugfs_list,
4050 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004051
Ben Widawsky6d794d42011-04-25 11:25:56 -07004052 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
4053 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01004054
Daniel Vettere309a992013-10-16 22:55:51 +02004055 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01004056 struct drm_info_list *info_list =
4057 (struct drm_info_list *)&i915_pipe_crc_data[i];
4058
4059 drm_debugfs_remove_files(info_list, 1, minor);
4060 }
4061
Daniel Vetter34b96742013-07-04 20:49:44 +02004062 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
4063 struct drm_info_list *info_list =
4064 (struct drm_info_list *) i915_debugfs_files[i].fops;
4065
4066 drm_debugfs_remove_files(info_list, 1, minor);
4067 }
Ben Gamari20172632009-02-17 20:08:50 -05004068}