blob: 76c2572872f65cff0047b0e06319db8cc59a1505 [file] [log] [blame]
Ben Gamari20172632009-02-17 20:08:50 -05001/*
2 * Copyright © 2008 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 * Keith Packard <keithp@keithp.com>
26 *
27 */
28
29#include <linux/seq_file.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010030#include <linux/circ_buf.h>
Daniel Vetter926321d2013-10-16 13:30:34 +020031#include <linux/ctype.h>
Chris Wilsonf3cd4742009-10-13 22:20:20 +010032#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Chris Wilson6d2b8882013-08-07 18:30:54 +010035#include <linux/list_sort.h>
Jesse Barnesec013e72013-08-20 10:29:23 +010036#include <asm/msr-index.h>
David Howells760285e2012-10-02 18:01:07 +010037#include <drm/drmP.h>
Simon Farnsworth4e5359c2010-09-01 17:47:52 +010038#include "intel_drv.h"
Chris Wilsone5c65262010-11-01 11:35:28 +000039#include "intel_ringbuffer.h"
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/i915_drm.h>
Ben Gamari20172632009-02-17 20:08:50 -050041#include "i915_drv.h"
42
Chris Wilsonf13d3f72010-09-20 17:36:15 +010043enum {
Chris Wilson69dc4982010-10-19 10:36:51 +010044 ACTIVE_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010045 INACTIVE_LIST,
Chris Wilsond21d5972010-09-26 11:19:33 +010046 PINNED_LIST,
Chris Wilsonf13d3f72010-09-20 17:36:15 +010047};
Ben Gamari433e12f2009-02-17 20:08:51 -050048
Chris Wilson70d39fe2010-08-25 16:03:34 +010049static const char *yesno(int v)
50{
51 return v ? "yes" : "no";
52}
53
Damien Lespiau497666d2013-10-15 18:55:39 +010054/* As the drm_debugfs_init() routines are called before dev->dev_private is
55 * allocated we need to hook into the minor for release. */
56static int
57drm_add_fake_info_node(struct drm_minor *minor,
58 struct dentry *ent,
59 const void *key)
60{
61 struct drm_info_node *node;
62
63 node = kmalloc(sizeof(*node), GFP_KERNEL);
64 if (node == NULL) {
65 debugfs_remove(ent);
66 return -ENOMEM;
67 }
68
69 node->minor = minor;
70 node->dent = ent;
71 node->info_ent = (void *) key;
72
73 mutex_lock(&minor->debugfs_lock);
74 list_add(&node->list, &minor->debugfs_list);
75 mutex_unlock(&minor->debugfs_lock);
76
77 return 0;
78}
79
Chris Wilson70d39fe2010-08-25 16:03:34 +010080static int i915_capabilities(struct seq_file *m, void *data)
81{
Damien Lespiau9f25d002014-05-13 15:30:28 +010082 struct drm_info_node *node = m->private;
Chris Wilson70d39fe2010-08-25 16:03:34 +010083 struct drm_device *dev = node->minor->dev;
84 const struct intel_device_info *info = INTEL_INFO(dev);
85
86 seq_printf(m, "gen: %d\n", info->gen);
Paulo Zanoni03d00ac2011-10-14 18:17:41 -030087 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
Damien Lespiau79fc46d2013-04-23 16:37:17 +010088#define PRINT_FLAG(x) seq_printf(m, #x ": %s\n", yesno(info->x))
89#define SEP_SEMICOLON ;
90 DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG, SEP_SEMICOLON);
91#undef PRINT_FLAG
92#undef SEP_SEMICOLON
Chris Wilson70d39fe2010-08-25 16:03:34 +010093
94 return 0;
95}
Ben Gamari433e12f2009-02-17 20:08:51 -050096
Chris Wilson05394f32010-11-08 19:18:58 +000097static const char *get_pin_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +000098{
Chris Wilson05394f32010-11-08 19:18:58 +000099 if (obj->user_pin_count > 0)
Chris Wilsona6172a82009-02-11 14:26:38 +0000100 return "P";
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800101 else if (i915_gem_obj_is_pinned(obj))
Chris Wilsona6172a82009-02-11 14:26:38 +0000102 return "p";
103 else
104 return " ";
105}
106
Chris Wilson05394f32010-11-08 19:18:58 +0000107static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
Chris Wilsona6172a82009-02-11 14:26:38 +0000108{
Akshay Joshi0206e352011-08-16 15:34:10 -0400109 switch (obj->tiling_mode) {
110 default:
111 case I915_TILING_NONE: return " ";
112 case I915_TILING_X: return "X";
113 case I915_TILING_Y: return "Y";
114 }
Chris Wilsona6172a82009-02-11 14:26:38 +0000115}
116
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700117static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
118{
119 return obj->has_global_gtt_mapping ? "g" : " ";
120}
121
Chris Wilson37811fc2010-08-25 22:45:57 +0100122static void
123describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
124{
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700125 struct i915_vma *vma;
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800126 int pin_count = 0;
127
Ville Syrjäläfb1ae912013-08-22 19:21:30 +0300128 seq_printf(m, "%pK: %s%s%s %8zdKiB %02x %02x %u %u %u%s%s%s",
Chris Wilson37811fc2010-08-25 22:45:57 +0100129 &obj->base,
130 get_pin_flag(obj),
131 get_tiling_flag(obj),
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700132 get_global_flag(obj),
Eric Anholta05a5862011-12-20 08:54:15 -0800133 obj->base.size / 1024,
Chris Wilson37811fc2010-08-25 22:45:57 +0100134 obj->base.read_domains,
135 obj->base.write_domain,
Chris Wilson0201f1e2012-07-20 12:41:01 +0100136 obj->last_read_seqno,
137 obj->last_write_seqno,
Chris Wilsoncaea7472010-11-12 13:53:37 +0000138 obj->last_fenced_seqno,
Mika Kuoppala84734a02013-07-12 16:50:57 +0300139 i915_cache_level_str(obj->cache_level),
Chris Wilson37811fc2010-08-25 22:45:57 +0100140 obj->dirty ? " dirty" : "",
141 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
142 if (obj->base.name)
143 seq_printf(m, " (name: %d)", obj->base.name);
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800144 list_for_each_entry(vma, &obj->vma_list, vma_link)
145 if (vma->pin_count > 0)
146 pin_count++;
147 seq_printf(m, " (pinned x %d)", pin_count);
Chris Wilsoncc98b412013-08-09 12:25:09 +0100148 if (obj->pin_display)
149 seq_printf(m, " (display)");
Chris Wilson37811fc2010-08-25 22:45:57 +0100150 if (obj->fence_reg != I915_FENCE_REG_NONE)
151 seq_printf(m, " (fence: %d)", obj->fence_reg);
Ben Widawsky1d693bc2013-07-31 17:00:00 -0700152 list_for_each_entry(vma, &obj->vma_list, vma_link) {
153 if (!i915_is_ggtt(vma->vm))
154 seq_puts(m, " (pp");
155 else
156 seq_puts(m, " (g");
157 seq_printf(m, "gtt offset: %08lx, size: %08lx)",
158 vma->node.start, vma->node.size);
159 }
Chris Wilsonc1ad11f2012-11-15 11:32:21 +0000160 if (obj->stolen)
161 seq_printf(m, " (stolen: %08lx)", obj->stolen->start);
Chris Wilson6299f992010-11-24 12:23:44 +0000162 if (obj->pin_mappable || obj->fault_mappable) {
163 char s[3], *t = s;
164 if (obj->pin_mappable)
165 *t++ = 'p';
166 if (obj->fault_mappable)
167 *t++ = 'f';
168 *t = '\0';
169 seq_printf(m, " (%s mappable)", s);
170 }
Chris Wilson69dc4982010-10-19 10:36:51 +0100171 if (obj->ring != NULL)
172 seq_printf(m, " (%s)", obj->ring->name);
Chris Wilson37811fc2010-08-25 22:45:57 +0100173}
174
Oscar Mateo273497e2014-05-22 14:13:37 +0100175static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
Ben Widawsky3ccfd192013-09-18 19:03:18 -0700176{
177 seq_putc(m, ctx->is_initialized ? 'I' : 'i');
178 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
179 seq_putc(m, ' ');
180}
181
Ben Gamari433e12f2009-02-17 20:08:51 -0500182static int i915_gem_object_list_info(struct seq_file *m, void *data)
Ben Gamari20172632009-02-17 20:08:50 -0500183{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100184 struct drm_info_node *node = m->private;
Ben Gamari433e12f2009-02-17 20:08:51 -0500185 uintptr_t list = (uintptr_t) node->info_ent->data;
186 struct list_head *head;
Ben Gamari20172632009-02-17 20:08:50 -0500187 struct drm_device *dev = node->minor->dev;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700188 struct drm_i915_private *dev_priv = dev->dev_private;
189 struct i915_address_space *vm = &dev_priv->gtt.base;
Ben Widawskyca191b12013-07-31 17:00:14 -0700190 struct i915_vma *vma;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100191 size_t total_obj_size, total_gtt_size;
192 int count, ret;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100193
194 ret = mutex_lock_interruptible(&dev->struct_mutex);
195 if (ret)
196 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500197
Ben Widawskyca191b12013-07-31 17:00:14 -0700198 /* FIXME: the user of this interface might want more than just GGTT */
Ben Gamari433e12f2009-02-17 20:08:51 -0500199 switch (list) {
200 case ACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100201 seq_puts(m, "Active:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700202 head = &vm->active_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500203 break;
204 case INACTIVE_LIST:
Damien Lespiau267f0c92013-06-24 22:59:48 +0100205 seq_puts(m, "Inactive:\n");
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700206 head = &vm->inactive_list;
Ben Gamari433e12f2009-02-17 20:08:51 -0500207 break;
Ben Gamari433e12f2009-02-17 20:08:51 -0500208 default:
Chris Wilsonde227ef2010-07-03 07:58:38 +0100209 mutex_unlock(&dev->struct_mutex);
210 return -EINVAL;
Ben Gamari433e12f2009-02-17 20:08:51 -0500211 }
212
Chris Wilson8f2480f2010-09-26 11:44:19 +0100213 total_obj_size = total_gtt_size = count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700214 list_for_each_entry(vma, head, mm_list) {
215 seq_printf(m, " ");
216 describe_obj(m, vma->obj);
217 seq_printf(m, "\n");
218 total_obj_size += vma->obj->base.size;
219 total_gtt_size += vma->node.size;
Chris Wilson8f2480f2010-09-26 11:44:19 +0100220 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500221 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100222 mutex_unlock(&dev->struct_mutex);
Carl Worth5e118f42009-03-20 11:54:25 -0700223
Chris Wilson8f2480f2010-09-26 11:44:19 +0100224 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
225 count, total_obj_size, total_gtt_size);
Ben Gamari20172632009-02-17 20:08:50 -0500226 return 0;
227}
228
Chris Wilson6d2b8882013-08-07 18:30:54 +0100229static int obj_rank_by_stolen(void *priv,
230 struct list_head *A, struct list_head *B)
231{
232 struct drm_i915_gem_object *a =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200233 container_of(A, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100234 struct drm_i915_gem_object *b =
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200235 container_of(B, struct drm_i915_gem_object, obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100236
237 return a->stolen->start - b->stolen->start;
238}
239
240static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
241{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100242 struct drm_info_node *node = m->private;
Chris Wilson6d2b8882013-08-07 18:30:54 +0100243 struct drm_device *dev = node->minor->dev;
244 struct drm_i915_private *dev_priv = dev->dev_private;
245 struct drm_i915_gem_object *obj;
246 size_t total_obj_size, total_gtt_size;
247 LIST_HEAD(stolen);
248 int count, ret;
249
250 ret = mutex_lock_interruptible(&dev->struct_mutex);
251 if (ret)
252 return ret;
253
254 total_obj_size = total_gtt_size = count = 0;
255 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
256 if (obj->stolen == NULL)
257 continue;
258
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200259 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100260
261 total_obj_size += obj->base.size;
262 total_gtt_size += i915_gem_obj_ggtt_size(obj);
263 count++;
264 }
265 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
266 if (obj->stolen == NULL)
267 continue;
268
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200269 list_add(&obj->obj_exec_link, &stolen);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100270
271 total_obj_size += obj->base.size;
272 count++;
273 }
274 list_sort(NULL, &stolen, obj_rank_by_stolen);
275 seq_puts(m, "Stolen:\n");
276 while (!list_empty(&stolen)) {
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200277 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100278 seq_puts(m, " ");
279 describe_obj(m, obj);
280 seq_putc(m, '\n');
Ben Widawskyb25cb2f2013-08-14 11:38:33 +0200281 list_del_init(&obj->obj_exec_link);
Chris Wilson6d2b8882013-08-07 18:30:54 +0100282 }
283 mutex_unlock(&dev->struct_mutex);
284
285 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
286 count, total_obj_size, total_gtt_size);
287 return 0;
288}
289
Chris Wilson6299f992010-11-24 12:23:44 +0000290#define count_objects(list, member) do { \
291 list_for_each_entry(obj, list, member) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700292 size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000293 ++count; \
294 if (obj->map_and_fenceable) { \
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700295 mappable_size += i915_gem_obj_ggtt_size(obj); \
Chris Wilson6299f992010-11-24 12:23:44 +0000296 ++mappable_count; \
297 } \
298 } \
Akshay Joshi0206e352011-08-16 15:34:10 -0400299} while (0)
Chris Wilson6299f992010-11-24 12:23:44 +0000300
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100301struct file_stats {
Chris Wilson6313c202014-03-19 13:45:45 +0000302 struct drm_i915_file_private *file_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100303 int count;
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000304 size_t total, unbound;
305 size_t global, shared;
306 size_t active, inactive;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100307};
308
309static int per_file_stats(int id, void *ptr, void *data)
310{
311 struct drm_i915_gem_object *obj = ptr;
312 struct file_stats *stats = data;
Chris Wilson6313c202014-03-19 13:45:45 +0000313 struct i915_vma *vma;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100314
315 stats->count++;
316 stats->total += obj->base.size;
317
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000318 if (obj->base.name || obj->base.dma_buf)
319 stats->shared += obj->base.size;
320
Chris Wilson6313c202014-03-19 13:45:45 +0000321 if (USES_FULL_PPGTT(obj->base.dev)) {
322 list_for_each_entry(vma, &obj->vma_list, vma_link) {
323 struct i915_hw_ppgtt *ppgtt;
324
325 if (!drm_mm_node_allocated(&vma->node))
326 continue;
327
328 if (i915_is_ggtt(vma->vm)) {
329 stats->global += obj->base.size;
330 continue;
331 }
332
333 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
334 if (ppgtt->ctx && ppgtt->ctx->file_priv != stats->file_priv)
335 continue;
336
337 if (obj->ring) /* XXX per-vma statistic */
338 stats->active += obj->base.size;
339 else
340 stats->inactive += obj->base.size;
341
342 return 0;
343 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100344 } else {
Chris Wilson6313c202014-03-19 13:45:45 +0000345 if (i915_gem_obj_ggtt_bound(obj)) {
346 stats->global += obj->base.size;
347 if (obj->ring)
348 stats->active += obj->base.size;
349 else
350 stats->inactive += obj->base.size;
351 return 0;
352 }
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100353 }
354
Chris Wilson6313c202014-03-19 13:45:45 +0000355 if (!list_empty(&obj->global_list))
356 stats->unbound += obj->base.size;
357
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100358 return 0;
359}
360
Ben Widawskyca191b12013-07-31 17:00:14 -0700361#define count_vmas(list, member) do { \
362 list_for_each_entry(vma, list, member) { \
363 size += i915_gem_obj_ggtt_size(vma->obj); \
364 ++count; \
365 if (vma->obj->map_and_fenceable) { \
366 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
367 ++mappable_count; \
368 } \
369 } \
370} while (0)
371
372static int i915_gem_object_info(struct seq_file *m, void* data)
Chris Wilson73aa8082010-09-30 11:46:12 +0100373{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100374 struct drm_info_node *node = m->private;
Chris Wilson73aa8082010-09-30 11:46:12 +0100375 struct drm_device *dev = node->minor->dev;
376 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200377 u32 count, mappable_count, purgeable_count;
378 size_t size, mappable_size, purgeable_size;
Chris Wilson6299f992010-11-24 12:23:44 +0000379 struct drm_i915_gem_object *obj;
Ben Widawsky5cef07e2013-07-16 16:50:08 -0700380 struct i915_address_space *vm = &dev_priv->gtt.base;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100381 struct drm_file *file;
Ben Widawskyca191b12013-07-31 17:00:14 -0700382 struct i915_vma *vma;
Chris Wilson73aa8082010-09-30 11:46:12 +0100383 int ret;
384
385 ret = mutex_lock_interruptible(&dev->struct_mutex);
386 if (ret)
387 return ret;
388
Chris Wilson6299f992010-11-24 12:23:44 +0000389 seq_printf(m, "%u objects, %zu bytes\n",
390 dev_priv->mm.object_count,
391 dev_priv->mm.object_memory);
392
393 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700394 count_objects(&dev_priv->mm.bound_list, global_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000395 seq_printf(m, "%u [%u] objects, %zu [%zu] bytes in gtt\n",
396 count, mappable_count, size, mappable_size);
397
398 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700399 count_vmas(&vm->active_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000400 seq_printf(m, " %u [%u] active objects, %zu [%zu] bytes\n",
401 count, mappable_count, size, mappable_size);
402
403 size = count = mappable_size = mappable_count = 0;
Ben Widawskyca191b12013-07-31 17:00:14 -0700404 count_vmas(&vm->inactive_list, mm_list);
Chris Wilson6299f992010-11-24 12:23:44 +0000405 seq_printf(m, " %u [%u] inactive objects, %zu [%zu] bytes\n",
406 count, mappable_count, size, mappable_size);
407
Chris Wilsonb7abb712012-08-20 11:33:30 +0200408 size = count = purgeable_size = purgeable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700409 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
Chris Wilson6c085a72012-08-20 11:40:46 +0200410 size += obj->base.size, ++count;
Chris Wilsonb7abb712012-08-20 11:33:30 +0200411 if (obj->madv == I915_MADV_DONTNEED)
412 purgeable_size += obj->base.size, ++purgeable_count;
413 }
Chris Wilson6c085a72012-08-20 11:40:46 +0200414 seq_printf(m, "%u unbound objects, %zu bytes\n", count, size);
415
Chris Wilson6299f992010-11-24 12:23:44 +0000416 size = count = mappable_size = mappable_count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700417 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Chris Wilson6299f992010-11-24 12:23:44 +0000418 if (obj->fault_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700419 size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000420 ++count;
421 }
422 if (obj->pin_mappable) {
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700423 mappable_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson6299f992010-11-24 12:23:44 +0000424 ++mappable_count;
425 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200426 if (obj->madv == I915_MADV_DONTNEED) {
427 purgeable_size += obj->base.size;
428 ++purgeable_count;
429 }
Chris Wilson6299f992010-11-24 12:23:44 +0000430 }
Chris Wilsonb7abb712012-08-20 11:33:30 +0200431 seq_printf(m, "%u purgeable objects, %zu bytes\n",
432 purgeable_count, purgeable_size);
Chris Wilson6299f992010-11-24 12:23:44 +0000433 seq_printf(m, "%u pinned mappable objects, %zu bytes\n",
434 mappable_count, mappable_size);
435 seq_printf(m, "%u fault mappable objects, %zu bytes\n",
436 count, size);
437
Ben Widawsky93d18792013-01-17 12:45:17 -0800438 seq_printf(m, "%zu [%lu] gtt total\n",
Ben Widawsky853ba5d2013-07-16 16:50:05 -0700439 dev_priv->gtt.base.total,
440 dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
Chris Wilson73aa8082010-09-30 11:46:12 +0100441
Damien Lespiau267f0c92013-06-24 22:59:48 +0100442 seq_putc(m, '\n');
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100443 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
444 struct file_stats stats;
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900445 struct task_struct *task;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100446
447 memset(&stats, 0, sizeof(stats));
Chris Wilson6313c202014-03-19 13:45:45 +0000448 stats.file_priv = file->driver_priv;
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100449 idr_for_each(&file->object_idr, per_file_stats, &stats);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900450 /*
451 * Although we have a valid reference on file->pid, that does
452 * not guarantee that the task_struct who called get_pid() is
453 * still alive (e.g. get_pid(current) => fork() => exit()).
454 * Therefore, we need to protect this ->comm access using RCU.
455 */
456 rcu_read_lock();
457 task = pid_task(file->pid, PIDTYPE_PID);
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000458 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 +0900459 task ? task->comm : "<unknown>",
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100460 stats.count,
461 stats.total,
462 stats.active,
463 stats.inactive,
Chris Wilson6313c202014-03-19 13:45:45 +0000464 stats.global,
Chris Wilsonc67a17e2014-03-19 13:45:46 +0000465 stats.shared,
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100466 stats.unbound);
Tetsuo Handa3ec2f422014-01-03 20:42:18 +0900467 rcu_read_unlock();
Chris Wilson2db8e9d2013-06-04 23:49:08 +0100468 }
469
Chris Wilson73aa8082010-09-30 11:46:12 +0100470 mutex_unlock(&dev->struct_mutex);
471
472 return 0;
473}
474
Damien Lespiauaee56cf2013-06-24 22:59:49 +0100475static int i915_gem_gtt_info(struct seq_file *m, void *data)
Chris Wilson08c18322011-01-10 00:00:24 +0000476{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100477 struct drm_info_node *node = m->private;
Chris Wilson08c18322011-01-10 00:00:24 +0000478 struct drm_device *dev = node->minor->dev;
Chris Wilson1b502472012-04-24 15:47:30 +0100479 uintptr_t list = (uintptr_t) node->info_ent->data;
Chris Wilson08c18322011-01-10 00:00:24 +0000480 struct drm_i915_private *dev_priv = dev->dev_private;
481 struct drm_i915_gem_object *obj;
482 size_t total_obj_size, total_gtt_size;
483 int count, ret;
484
485 ret = mutex_lock_interruptible(&dev->struct_mutex);
486 if (ret)
487 return ret;
488
489 total_obj_size = total_gtt_size = count = 0;
Ben Widawsky35c20a62013-05-31 11:28:48 -0700490 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -0800491 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
Chris Wilson1b502472012-04-24 15:47:30 +0100492 continue;
493
Damien Lespiau267f0c92013-06-24 22:59:48 +0100494 seq_puts(m, " ");
Chris Wilson08c18322011-01-10 00:00:24 +0000495 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100496 seq_putc(m, '\n');
Chris Wilson08c18322011-01-10 00:00:24 +0000497 total_obj_size += obj->base.size;
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700498 total_gtt_size += i915_gem_obj_ggtt_size(obj);
Chris Wilson08c18322011-01-10 00:00:24 +0000499 count++;
500 }
501
502 mutex_unlock(&dev->struct_mutex);
503
504 seq_printf(m, "Total %d objects, %zu bytes, %zu GTT size\n",
505 count, total_obj_size, total_gtt_size);
506
507 return 0;
508}
509
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100510static int i915_gem_pageflip_info(struct seq_file *m, void *data)
511{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100512 struct drm_info_node *node = m->private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100513 struct drm_device *dev = node->minor->dev;
514 unsigned long flags;
515 struct intel_crtc *crtc;
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200516 int ret;
517
518 ret = mutex_lock_interruptible(&dev->struct_mutex);
519 if (ret)
520 return ret;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100521
Damien Lespiaud3fcc802014-05-13 23:32:22 +0100522 for_each_intel_crtc(dev, crtc) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800523 const char pipe = pipe_name(crtc->pipe);
524 const char plane = plane_name(crtc->plane);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100525 struct intel_unpin_work *work;
526
527 spin_lock_irqsave(&dev->event_lock, flags);
528 work = crtc->unpin_work;
529 if (work == NULL) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800530 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100531 pipe, plane);
532 } else {
Chris Wilsone7d841c2012-12-03 11:36:30 +0000533 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800534 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100535 pipe, plane);
536 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800537 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100538 pipe, plane);
539 }
540 if (work->enable_stall_check)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100541 seq_puts(m, "Stall check enabled, ");
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100542 else
Damien Lespiau267f0c92013-06-24 22:59:48 +0100543 seq_puts(m, "Stall check waiting for page flip ioctl, ");
Chris Wilsone7d841c2012-12-03 11:36:30 +0000544 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100545
546 if (work->old_fb_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000547 struct drm_i915_gem_object *obj = work->old_fb_obj;
548 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700549 seq_printf(m, "Old framebuffer gtt_offset 0x%08lx\n",
550 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100551 }
552 if (work->pending_flip_obj) {
Chris Wilson05394f32010-11-08 19:18:58 +0000553 struct drm_i915_gem_object *obj = work->pending_flip_obj;
554 if (obj)
Ben Widawskyf343c5f2013-07-05 14:41:04 -0700555 seq_printf(m, "New framebuffer gtt_offset 0x%08lx\n",
556 i915_gem_obj_ggtt_offset(obj));
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100557 }
558 }
559 spin_unlock_irqrestore(&dev->event_lock, flags);
560 }
561
Daniel Vetter8a270eb2014-06-17 22:34:37 +0200562 mutex_unlock(&dev->struct_mutex);
563
Simon Farnsworth4e5359c2010-09-01 17:47:52 +0100564 return 0;
565}
566
Ben Gamari20172632009-02-17 20:08:50 -0500567static int i915_gem_request_info(struct seq_file *m, void *data)
568{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100569 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500570 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300571 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100572 struct intel_engine_cs *ring;
Ben Gamari20172632009-02-17 20:08:50 -0500573 struct drm_i915_gem_request *gem_request;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100574 int ret, count, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100575
576 ret = mutex_lock_interruptible(&dev->struct_mutex);
577 if (ret)
578 return ret;
Ben Gamari20172632009-02-17 20:08:50 -0500579
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100580 count = 0;
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100581 for_each_ring(ring, dev_priv, i) {
582 if (list_empty(&ring->request_list))
583 continue;
584
585 seq_printf(m, "%s requests:\n", ring->name);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100586 list_for_each_entry(gem_request,
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100587 &ring->request_list,
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100588 list) {
589 seq_printf(m, " %d @ %d\n",
590 gem_request->seqno,
591 (int) (jiffies - gem_request->emitted_jiffies));
592 }
593 count++;
Ben Gamari20172632009-02-17 20:08:50 -0500594 }
Chris Wilsonde227ef2010-07-03 07:58:38 +0100595 mutex_unlock(&dev->struct_mutex);
596
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100597 if (count == 0)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100598 seq_puts(m, "No requests\n");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100599
Ben Gamari20172632009-02-17 20:08:50 -0500600 return 0;
601}
602
Chris Wilsonb2223492010-10-27 15:27:33 +0100603static void i915_ring_seqno_info(struct seq_file *m,
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100604 struct intel_engine_cs *ring)
Chris Wilsonb2223492010-10-27 15:27:33 +0100605{
606 if (ring->get_seqno) {
Mika Kuoppala43a7b922012-12-04 15:12:01 +0200607 seq_printf(m, "Current sequence (%s): %u\n",
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100608 ring->name, ring->get_seqno(ring, false));
Chris Wilsonb2223492010-10-27 15:27:33 +0100609 }
610}
611
Ben Gamari20172632009-02-17 20:08:50 -0500612static int i915_gem_seqno_info(struct seq_file *m, void *data)
613{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100614 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500615 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300616 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100617 struct intel_engine_cs *ring;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000618 int ret, i;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100619
620 ret = mutex_lock_interruptible(&dev->struct_mutex);
621 if (ret)
622 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200623 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500624
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100625 for_each_ring(ring, dev_priv, i)
626 i915_ring_seqno_info(m, ring);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100627
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200628 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100629 mutex_unlock(&dev->struct_mutex);
630
Ben Gamari20172632009-02-17 20:08:50 -0500631 return 0;
632}
633
634
635static int i915_interrupt_info(struct seq_file *m, void *data)
636{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100637 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500638 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300639 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100640 struct intel_engine_cs *ring;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800641 int ret, i, pipe;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100642
643 ret = mutex_lock_interruptible(&dev->struct_mutex);
644 if (ret)
645 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200646 intel_runtime_pm_get(dev_priv);
Ben Gamari20172632009-02-17 20:08:50 -0500647
Ville Syrjälä74e1ca82014-04-09 13:28:09 +0300648 if (IS_CHERRYVIEW(dev)) {
649 int i;
650 seq_printf(m, "Master Interrupt Control:\t%08x\n",
651 I915_READ(GEN8_MASTER_IRQ));
652
653 seq_printf(m, "Display IER:\t%08x\n",
654 I915_READ(VLV_IER));
655 seq_printf(m, "Display IIR:\t%08x\n",
656 I915_READ(VLV_IIR));
657 seq_printf(m, "Display IIR_RW:\t%08x\n",
658 I915_READ(VLV_IIR_RW));
659 seq_printf(m, "Display IMR:\t%08x\n",
660 I915_READ(VLV_IMR));
661 for_each_pipe(pipe)
662 seq_printf(m, "Pipe %c stat:\t%08x\n",
663 pipe_name(pipe),
664 I915_READ(PIPESTAT(pipe)));
665
666 seq_printf(m, "Port hotplug:\t%08x\n",
667 I915_READ(PORT_HOTPLUG_EN));
668 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
669 I915_READ(VLV_DPFLIPSTAT));
670 seq_printf(m, "DPINVGTT:\t%08x\n",
671 I915_READ(DPINVGTT));
672
673 for (i = 0; i < 4; i++) {
674 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
675 i, I915_READ(GEN8_GT_IMR(i)));
676 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
677 i, I915_READ(GEN8_GT_IIR(i)));
678 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
679 i, I915_READ(GEN8_GT_IER(i)));
680 }
681
682 seq_printf(m, "PCU interrupt mask:\t%08x\n",
683 I915_READ(GEN8_PCU_IMR));
684 seq_printf(m, "PCU interrupt identity:\t%08x\n",
685 I915_READ(GEN8_PCU_IIR));
686 seq_printf(m, "PCU interrupt enable:\t%08x\n",
687 I915_READ(GEN8_PCU_IER));
688 } else if (INTEL_INFO(dev)->gen >= 8) {
Ben Widawskya123f152013-11-02 21:07:10 -0700689 seq_printf(m, "Master Interrupt Control:\t%08x\n",
690 I915_READ(GEN8_MASTER_IRQ));
691
692 for (i = 0; i < 4; i++) {
693 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
694 i, I915_READ(GEN8_GT_IMR(i)));
695 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
696 i, I915_READ(GEN8_GT_IIR(i)));
697 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
698 i, I915_READ(GEN8_GT_IER(i)));
699 }
700
Damien Lespiau07d27e22014-03-03 17:31:46 +0000701 for_each_pipe(pipe) {
Ben Widawskya123f152013-11-02 21:07:10 -0700702 seq_printf(m, "Pipe %c IMR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000703 pipe_name(pipe),
704 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700705 seq_printf(m, "Pipe %c IIR:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000706 pipe_name(pipe),
707 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700708 seq_printf(m, "Pipe %c IER:\t%08x\n",
Damien Lespiau07d27e22014-03-03 17:31:46 +0000709 pipe_name(pipe),
710 I915_READ(GEN8_DE_PIPE_IER(pipe)));
Ben Widawskya123f152013-11-02 21:07:10 -0700711 }
712
713 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
714 I915_READ(GEN8_DE_PORT_IMR));
715 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
716 I915_READ(GEN8_DE_PORT_IIR));
717 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
718 I915_READ(GEN8_DE_PORT_IER));
719
720 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
721 I915_READ(GEN8_DE_MISC_IMR));
722 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
723 I915_READ(GEN8_DE_MISC_IIR));
724 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
725 I915_READ(GEN8_DE_MISC_IER));
726
727 seq_printf(m, "PCU interrupt mask:\t%08x\n",
728 I915_READ(GEN8_PCU_IMR));
729 seq_printf(m, "PCU interrupt identity:\t%08x\n",
730 I915_READ(GEN8_PCU_IIR));
731 seq_printf(m, "PCU interrupt enable:\t%08x\n",
732 I915_READ(GEN8_PCU_IER));
733 } else if (IS_VALLEYVIEW(dev)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700734 seq_printf(m, "Display IER:\t%08x\n",
735 I915_READ(VLV_IER));
736 seq_printf(m, "Display IIR:\t%08x\n",
737 I915_READ(VLV_IIR));
738 seq_printf(m, "Display IIR_RW:\t%08x\n",
739 I915_READ(VLV_IIR_RW));
740 seq_printf(m, "Display IMR:\t%08x\n",
741 I915_READ(VLV_IMR));
742 for_each_pipe(pipe)
743 seq_printf(m, "Pipe %c stat:\t%08x\n",
744 pipe_name(pipe),
745 I915_READ(PIPESTAT(pipe)));
746
747 seq_printf(m, "Master IER:\t%08x\n",
748 I915_READ(VLV_MASTER_IER));
749
750 seq_printf(m, "Render IER:\t%08x\n",
751 I915_READ(GTIER));
752 seq_printf(m, "Render IIR:\t%08x\n",
753 I915_READ(GTIIR));
754 seq_printf(m, "Render IMR:\t%08x\n",
755 I915_READ(GTIMR));
756
757 seq_printf(m, "PM IER:\t\t%08x\n",
758 I915_READ(GEN6_PMIER));
759 seq_printf(m, "PM IIR:\t\t%08x\n",
760 I915_READ(GEN6_PMIIR));
761 seq_printf(m, "PM IMR:\t\t%08x\n",
762 I915_READ(GEN6_PMIMR));
763
764 seq_printf(m, "Port hotplug:\t%08x\n",
765 I915_READ(PORT_HOTPLUG_EN));
766 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
767 I915_READ(VLV_DPFLIPSTAT));
768 seq_printf(m, "DPINVGTT:\t%08x\n",
769 I915_READ(DPINVGTT));
770
771 } else if (!HAS_PCH_SPLIT(dev)) {
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800772 seq_printf(m, "Interrupt enable: %08x\n",
773 I915_READ(IER));
774 seq_printf(m, "Interrupt identity: %08x\n",
775 I915_READ(IIR));
776 seq_printf(m, "Interrupt mask: %08x\n",
777 I915_READ(IMR));
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800778 for_each_pipe(pipe)
779 seq_printf(m, "Pipe %c stat: %08x\n",
780 pipe_name(pipe),
781 I915_READ(PIPESTAT(pipe)));
Zhenyu Wang5f6a1692009-08-10 21:37:24 +0800782 } else {
783 seq_printf(m, "North Display Interrupt enable: %08x\n",
784 I915_READ(DEIER));
785 seq_printf(m, "North Display Interrupt identity: %08x\n",
786 I915_READ(DEIIR));
787 seq_printf(m, "North Display Interrupt mask: %08x\n",
788 I915_READ(DEIMR));
789 seq_printf(m, "South Display Interrupt enable: %08x\n",
790 I915_READ(SDEIER));
791 seq_printf(m, "South Display Interrupt identity: %08x\n",
792 I915_READ(SDEIIR));
793 seq_printf(m, "South Display Interrupt mask: %08x\n",
794 I915_READ(SDEIMR));
795 seq_printf(m, "Graphics Interrupt enable: %08x\n",
796 I915_READ(GTIER));
797 seq_printf(m, "Graphics Interrupt identity: %08x\n",
798 I915_READ(GTIIR));
799 seq_printf(m, "Graphics Interrupt mask: %08x\n",
800 I915_READ(GTIMR));
801 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100802 for_each_ring(ring, dev_priv, i) {
Ben Widawskya123f152013-11-02 21:07:10 -0700803 if (INTEL_INFO(dev)->gen >= 6) {
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100804 seq_printf(m,
805 "Graphics Interrupt mask (%s): %08x\n",
806 ring->name, I915_READ_IMR(ring));
Chris Wilson9862e602011-01-04 22:22:17 +0000807 }
Chris Wilsona2c7f6f2012-09-01 20:51:22 +0100808 i915_ring_seqno_info(m, ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000809 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -0200810 intel_runtime_pm_put(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +0100811 mutex_unlock(&dev->struct_mutex);
812
Ben Gamari20172632009-02-17 20:08:50 -0500813 return 0;
814}
815
Chris Wilsona6172a82009-02-11 14:26:38 +0000816static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
817{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100818 struct drm_info_node *node = m->private;
Chris Wilsona6172a82009-02-11 14:26:38 +0000819 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300820 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonde227ef2010-07-03 07:58:38 +0100821 int i, ret;
822
823 ret = mutex_lock_interruptible(&dev->struct_mutex);
824 if (ret)
825 return ret;
Chris Wilsona6172a82009-02-11 14:26:38 +0000826
827 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
828 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
829 for (i = 0; i < dev_priv->num_fence_regs; i++) {
Chris Wilson05394f32010-11-08 19:18:58 +0000830 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
Chris Wilsona6172a82009-02-11 14:26:38 +0000831
Chris Wilson6c085a72012-08-20 11:40:46 +0200832 seq_printf(m, "Fence %d, pin count = %d, object = ",
833 i, dev_priv->fence_regs[i].pin_count);
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100834 if (obj == NULL)
Damien Lespiau267f0c92013-06-24 22:59:48 +0100835 seq_puts(m, "unused");
Chris Wilsonc2c347a92010-10-27 15:11:53 +0100836 else
Chris Wilson05394f32010-11-08 19:18:58 +0000837 describe_obj(m, obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +0100838 seq_putc(m, '\n');
Chris Wilsona6172a82009-02-11 14:26:38 +0000839 }
840
Chris Wilson05394f32010-11-08 19:18:58 +0000841 mutex_unlock(&dev->struct_mutex);
Chris Wilsona6172a82009-02-11 14:26:38 +0000842 return 0;
843}
844
Ben Gamari20172632009-02-17 20:08:50 -0500845static int i915_hws_info(struct seq_file *m, void *data)
846{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100847 struct drm_info_node *node = m->private;
Ben Gamari20172632009-02-17 20:08:50 -0500848 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300849 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +0100850 struct intel_engine_cs *ring;
Daniel Vetter1a240d42012-11-29 22:18:51 +0100851 const u32 *hws;
Chris Wilson4066c0a2010-10-29 21:00:54 +0100852 int i;
Ben Gamari20172632009-02-17 20:08:50 -0500853
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000854 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
Daniel Vetter1a240d42012-11-29 22:18:51 +0100855 hws = ring->status_page.page_addr;
Ben Gamari20172632009-02-17 20:08:50 -0500856 if (hws == NULL)
857 return 0;
858
859 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
860 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
861 i * 4,
862 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
863 }
864 return 0;
865}
866
Daniel Vetterd5442302012-04-27 15:17:40 +0200867static ssize_t
868i915_error_state_write(struct file *filp,
869 const char __user *ubuf,
870 size_t cnt,
871 loff_t *ppos)
872{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300873 struct i915_error_state_file_priv *error_priv = filp->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200874 struct drm_device *dev = error_priv->dev;
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200875 int ret;
Daniel Vetterd5442302012-04-27 15:17:40 +0200876
877 DRM_DEBUG_DRIVER("Resetting error state\n");
878
Daniel Vetter22bcfc62012-08-09 15:07:02 +0200879 ret = mutex_lock_interruptible(&dev->struct_mutex);
880 if (ret)
881 return ret;
882
Daniel Vetterd5442302012-04-27 15:17:40 +0200883 i915_destroy_error_state(dev);
884 mutex_unlock(&dev->struct_mutex);
885
886 return cnt;
887}
888
889static int i915_error_state_open(struct inode *inode, struct file *file)
890{
891 struct drm_device *dev = inode->i_private;
Daniel Vetterd5442302012-04-27 15:17:40 +0200892 struct i915_error_state_file_priv *error_priv;
Daniel Vetterd5442302012-04-27 15:17:40 +0200893
894 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
895 if (!error_priv)
896 return -ENOMEM;
897
898 error_priv->dev = dev;
899
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300900 i915_error_state_get(dev, error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200901
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300902 file->private_data = error_priv;
903
904 return 0;
Daniel Vetterd5442302012-04-27 15:17:40 +0200905}
906
907static int i915_error_state_release(struct inode *inode, struct file *file)
908{
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300909 struct i915_error_state_file_priv *error_priv = file->private_data;
Daniel Vetterd5442302012-04-27 15:17:40 +0200910
Mika Kuoppala95d5bfb2013-06-06 15:18:40 +0300911 i915_error_state_put(error_priv);
Daniel Vetterd5442302012-04-27 15:17:40 +0200912 kfree(error_priv);
913
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300914 return 0;
915}
916
917static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
918 size_t count, loff_t *pos)
919{
920 struct i915_error_state_file_priv *error_priv = file->private_data;
921 struct drm_i915_error_state_buf error_str;
922 loff_t tmp_pos = 0;
923 ssize_t ret_count = 0;
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300924 int ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300925
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300926 ret = i915_error_state_buf_init(&error_str, count, *pos);
927 if (ret)
928 return ret;
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300929
Mika Kuoppalafc16b482013-06-06 15:18:39 +0300930 ret = i915_error_state_to_str(&error_str, error_priv);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300931 if (ret)
932 goto out;
933
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300934 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
935 error_str.buf,
936 error_str.bytes);
937
938 if (ret_count < 0)
939 ret = ret_count;
940 else
941 *pos = error_str.start + ret_count;
942out:
Mika Kuoppala4dc955f2013-06-06 15:18:41 +0300943 i915_error_state_buf_release(&error_str);
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300944 return ret ?: ret_count;
Daniel Vetterd5442302012-04-27 15:17:40 +0200945}
946
947static const struct file_operations i915_error_state_fops = {
948 .owner = THIS_MODULE,
949 .open = i915_error_state_open,
Mika Kuoppalaedc3d882013-05-23 13:55:35 +0300950 .read = i915_error_state_read,
Daniel Vetterd5442302012-04-27 15:17:40 +0200951 .write = i915_error_state_write,
952 .llseek = default_llseek,
953 .release = i915_error_state_release,
954};
955
Kees Cook647416f2013-03-10 14:10:06 -0700956static int
957i915_next_seqno_get(void *data, u64 *val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200958{
Kees Cook647416f2013-03-10 14:10:06 -0700959 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300960 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala40633212012-12-04 15:12:00 +0200961 int ret;
962
963 ret = mutex_lock_interruptible(&dev->struct_mutex);
964 if (ret)
965 return ret;
966
Kees Cook647416f2013-03-10 14:10:06 -0700967 *val = dev_priv->next_seqno;
Mika Kuoppala40633212012-12-04 15:12:00 +0200968 mutex_unlock(&dev->struct_mutex);
969
Kees Cook647416f2013-03-10 14:10:06 -0700970 return 0;
Mika Kuoppala40633212012-12-04 15:12:00 +0200971}
972
Kees Cook647416f2013-03-10 14:10:06 -0700973static int
974i915_next_seqno_set(void *data, u64 val)
Mika Kuoppala40633212012-12-04 15:12:00 +0200975{
Kees Cook647416f2013-03-10 14:10:06 -0700976 struct drm_device *dev = data;
Mika Kuoppala40633212012-12-04 15:12:00 +0200977 int ret;
978
Mika Kuoppala40633212012-12-04 15:12:00 +0200979 ret = mutex_lock_interruptible(&dev->struct_mutex);
980 if (ret)
981 return ret;
982
Mika Kuoppalae94fbaa2012-12-19 11:13:09 +0200983 ret = i915_gem_set_seqno(dev, val);
Mika Kuoppala40633212012-12-04 15:12:00 +0200984 mutex_unlock(&dev->struct_mutex);
985
Kees Cook647416f2013-03-10 14:10:06 -0700986 return ret;
Mika Kuoppala40633212012-12-04 15:12:00 +0200987}
988
Kees Cook647416f2013-03-10 14:10:06 -0700989DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
990 i915_next_seqno_get, i915_next_seqno_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +0300991 "0x%llx\n");
Mika Kuoppala40633212012-12-04 15:12:00 +0200992
Jesse Barnesf97108d2010-01-29 11:27:07 -0800993static int i915_rstdby_delays(struct seq_file *m, void *unused)
994{
Damien Lespiau9f25d002014-05-13 15:30:28 +0100995 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800996 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +0300997 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -0700998 u16 crstanddelay;
999 int ret;
1000
1001 ret = mutex_lock_interruptible(&dev->struct_mutex);
1002 if (ret)
1003 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001004 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001005
1006 crstanddelay = I915_READ16(CRSTANDVID);
1007
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001008 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001009 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001010
1011 seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f));
1012
1013 return 0;
1014}
1015
Deepak Sadb4bd12014-03-31 11:30:02 +05301016static int i915_frequency_info(struct seq_file *m, void *unused)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001017{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001018 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001019 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001020 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001021 int ret = 0;
1022
1023 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001024
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001025 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1026
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001027 if (IS_GEN5(dev)) {
1028 u16 rgvswctl = I915_READ16(MEMSWCTL);
1029 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1030
1031 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1032 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1033 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1034 MEMSTAT_VID_SHIFT);
1035 seq_printf(m, "Current P-state: %d\n",
1036 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001037 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
1038 IS_BROADWELL(dev)) {
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001039 u32 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1040 u32 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1041 u32 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001042 u32 rpmodectl, rpinclimit, rpdeclimit;
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001043 u32 rpstat, cagf, reqf;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001044 u32 rpupei, rpcurup, rpprevup;
1045 u32 rpdownei, rpcurdown, rpprevdown;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001046 int max_freq;
1047
1048 /* RPSTAT1 is in the GT power well */
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001049 ret = mutex_lock_interruptible(&dev->struct_mutex);
1050 if (ret)
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001051 goto out;
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001052
Deepak Sc8d9a592013-11-23 14:55:42 +05301053 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001054
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001055 reqf = I915_READ(GEN6_RPNSWREQ);
1056 reqf &= ~GEN6_TURBO_DISABLE;
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001057 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001058 reqf >>= 24;
1059 else
1060 reqf >>= 25;
1061 reqf *= GT_FREQUENCY_MULTIPLIER;
1062
Chris Wilson0d8f9492014-03-27 09:06:14 +00001063 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1064 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1065 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1066
Jesse Barnesccab5c82011-01-18 15:49:25 -08001067 rpstat = I915_READ(GEN6_RPSTAT1);
1068 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1069 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1070 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1071 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1072 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1073 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07001074 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
Ben Widawskyf82855d2013-01-29 12:00:15 -08001075 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1076 else
1077 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
1078 cagf *= GT_FREQUENCY_MULTIPLIER;
Jesse Barnesccab5c82011-01-18 15:49:25 -08001079
Deepak Sc8d9a592013-11-23 14:55:42 +05301080 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawskyd1ebd8162011-04-25 20:11:50 +01001081 mutex_unlock(&dev->struct_mutex);
1082
Chris Wilson0d8f9492014-03-27 09:06:14 +00001083 seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
1084 I915_READ(GEN6_PMIER),
1085 I915_READ(GEN6_PMIMR),
1086 I915_READ(GEN6_PMISR),
1087 I915_READ(GEN6_PMIIR),
1088 I915_READ(GEN6_PMINTRMSK));
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001089 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001090 seq_printf(m, "Render p-state ratio: %d\n",
1091 (gt_perf_status & 0xff00) >> 8);
1092 seq_printf(m, "Render p-state VID: %d\n",
1093 gt_perf_status & 0xff);
1094 seq_printf(m, "Render p-state limit: %d\n",
1095 rp_state_limits & 0xff);
Chris Wilson0d8f9492014-03-27 09:06:14 +00001096 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1097 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1098 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1099 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
Chris Wilson8e8c06c2013-08-26 19:51:01 -03001100 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
Ben Widawskyf82855d2013-01-29 12:00:15 -08001101 seq_printf(m, "CAGF: %dMHz\n", cagf);
Jesse Barnesccab5c82011-01-18 15:49:25 -08001102 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1103 GEN6_CURICONT_MASK);
1104 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1105 GEN6_CURBSYTAVG_MASK);
1106 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1107 GEN6_CURBSYTAVG_MASK);
1108 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1109 GEN6_CURIAVG_MASK);
1110 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1111 GEN6_CURBSYTAVG_MASK);
1112 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1113 GEN6_CURBSYTAVG_MASK);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001114
1115 max_freq = (rp_state_cap & 0xff0000) >> 16;
1116 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001117 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001118
1119 max_freq = (rp_state_cap & 0xff00) >> 8;
1120 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001121 max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001122
1123 max_freq = rp_state_cap & 0xff;
1124 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
Ben Widawskyc8735b02012-09-07 19:43:39 -07001125 max_freq * GT_FREQUENCY_MULTIPLIER);
Ben Widawsky31c77382013-04-05 14:29:22 -07001126
1127 seq_printf(m, "Max overclocked frequency: %dMHz\n",
Ben Widawskyb39fb292014-03-19 18:31:11 -07001128 dev_priv->rps.max_freq * GT_FREQUENCY_MULTIPLIER);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001129 } else if (IS_VALLEYVIEW(dev)) {
1130 u32 freq_sts, val;
1131
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001132 mutex_lock(&dev_priv->rps.hw_lock);
Jani Nikula64936252013-05-22 15:36:20 +03001133 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001134 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1135 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1136
Chon Ming Leec5bd2bf2013-11-07 15:23:27 +08001137 val = valleyview_rps_max_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001138 seq_printf(m, "max GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001139 vlv_gpu_freq(dev_priv, val));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001140
Chon Ming Leec5bd2bf2013-11-07 15:23:27 +08001141 val = valleyview_rps_min_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07001142 seq_printf(m, "min GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001143 vlv_gpu_freq(dev_priv, val));
Jesse Barnes0a073b82013-04-17 15:54:58 -07001144
1145 seq_printf(m, "current GPU freq: %d MHz\n",
Ville Syrjälä2ec38152013-11-05 22:42:29 +02001146 vlv_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
Jesse Barnes259bd5d2013-04-22 15:59:30 -07001147 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001148 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001149 seq_puts(m, "no P-state info available\n");
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001150 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001151
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001152out:
1153 intel_runtime_pm_put(dev_priv);
1154 return ret;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001155}
1156
1157static int i915_delayfreq_table(struct seq_file *m, void *unused)
1158{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001159 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001160 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001161 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001162 u32 delayfreq;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001163 int ret, i;
1164
1165 ret = mutex_lock_interruptible(&dev->struct_mutex);
1166 if (ret)
1167 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001168 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001169
1170 for (i = 0; i < 16; i++) {
1171 delayfreq = I915_READ(PXVFREQ_BASE + i * 4);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001172 seq_printf(m, "P%02dVIDFREQ: 0x%08x (VID: %d)\n", i, delayfreq,
1173 (delayfreq & PXVFREQ_PX_MASK) >> PXVFREQ_PX_SHIFT);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001174 }
1175
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001176 intel_runtime_pm_put(dev_priv);
1177
Ben Widawsky616fdb52011-10-05 11:44:54 -07001178 mutex_unlock(&dev->struct_mutex);
1179
Jesse Barnesf97108d2010-01-29 11:27:07 -08001180 return 0;
1181}
1182
1183static inline int MAP_TO_MV(int map)
1184{
1185 return 1250 - (map * 25);
1186}
1187
1188static int i915_inttoext_table(struct seq_file *m, void *unused)
1189{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001190 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001191 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001192 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001193 u32 inttoext;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001194 int ret, i;
1195
1196 ret = mutex_lock_interruptible(&dev->struct_mutex);
1197 if (ret)
1198 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001199 intel_runtime_pm_get(dev_priv);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001200
1201 for (i = 1; i <= 32; i++) {
1202 inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4);
1203 seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext);
1204 }
1205
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001206 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001207 mutex_unlock(&dev->struct_mutex);
1208
Jesse Barnesf97108d2010-01-29 11:27:07 -08001209 return 0;
1210}
1211
Ben Widawsky4d855292011-12-12 19:34:16 -08001212static int ironlake_drpc_info(struct seq_file *m)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001213{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001214 struct drm_info_node *node = m->private;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001215 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001216 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001217 u32 rgvmodectl, rstdbyctl;
1218 u16 crstandvid;
1219 int ret;
1220
1221 ret = mutex_lock_interruptible(&dev->struct_mutex);
1222 if (ret)
1223 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001224 intel_runtime_pm_get(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001225
1226 rgvmodectl = I915_READ(MEMMODECTL);
1227 rstdbyctl = I915_READ(RSTDBYCTL);
1228 crstandvid = I915_READ16(CRSTANDVID);
1229
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001230 intel_runtime_pm_put(dev_priv);
Ben Widawsky616fdb52011-10-05 11:44:54 -07001231 mutex_unlock(&dev->struct_mutex);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001232
1233 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1234 "yes" : "no");
1235 seq_printf(m, "Boost freq: %d\n",
1236 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1237 MEMMODE_BOOST_FREQ_SHIFT);
1238 seq_printf(m, "HW control enabled: %s\n",
1239 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1240 seq_printf(m, "SW control enabled: %s\n",
1241 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1242 seq_printf(m, "Gated voltage change: %s\n",
1243 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1244 seq_printf(m, "Starting frequency: P%d\n",
1245 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001246 seq_printf(m, "Max P-state: P%d\n",
Jesse Barnesf97108d2010-01-29 11:27:07 -08001247 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001248 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1249 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1250 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1251 seq_printf(m, "Render standby enabled: %s\n",
1252 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
Damien Lespiau267f0c92013-06-24 22:59:48 +01001253 seq_puts(m, "Current RS state: ");
Jesse Barnes88271da2011-01-05 12:01:24 -08001254 switch (rstdbyctl & RSX_STATUS_MASK) {
1255 case RSX_STATUS_ON:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001256 seq_puts(m, "on\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001257 break;
1258 case RSX_STATUS_RC1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001259 seq_puts(m, "RC1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001260 break;
1261 case RSX_STATUS_RC1E:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001262 seq_puts(m, "RC1E\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001263 break;
1264 case RSX_STATUS_RS1:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001265 seq_puts(m, "RS1\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001266 break;
1267 case RSX_STATUS_RS2:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001268 seq_puts(m, "RS2 (RC6)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001269 break;
1270 case RSX_STATUS_RS3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001271 seq_puts(m, "RC3 (RC6+)\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001272 break;
1273 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001274 seq_puts(m, "unknown\n");
Jesse Barnes88271da2011-01-05 12:01:24 -08001275 break;
1276 }
Jesse Barnesf97108d2010-01-29 11:27:07 -08001277
1278 return 0;
1279}
1280
Deepak S669ab5a2014-01-10 15:18:26 +05301281static int vlv_drpc_info(struct seq_file *m)
1282{
1283
Damien Lespiau9f25d002014-05-13 15:30:28 +01001284 struct drm_info_node *node = m->private;
Deepak S669ab5a2014-01-10 15:18:26 +05301285 struct drm_device *dev = node->minor->dev;
1286 struct drm_i915_private *dev_priv = dev->dev_private;
1287 u32 rpmodectl1, rcctl1;
1288 unsigned fw_rendercount = 0, fw_mediacount = 0;
1289
Imre Deakd46c0512014-04-14 20:24:27 +03001290 intel_runtime_pm_get(dev_priv);
1291
Deepak S669ab5a2014-01-10 15:18:26 +05301292 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1293 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1294
Imre Deakd46c0512014-04-14 20:24:27 +03001295 intel_runtime_pm_put(dev_priv);
1296
Deepak S669ab5a2014-01-10 15:18:26 +05301297 seq_printf(m, "Video Turbo Mode: %s\n",
1298 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1299 seq_printf(m, "Turbo enabled: %s\n",
1300 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1301 seq_printf(m, "HW control enabled: %s\n",
1302 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1303 seq_printf(m, "SW control enabled: %s\n",
1304 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1305 GEN6_RP_MEDIA_SW_MODE));
1306 seq_printf(m, "RC6 Enabled: %s\n",
1307 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1308 GEN6_RC_CTL_EI_MODE(1))));
1309 seq_printf(m, "Render Power Well: %s\n",
1310 (I915_READ(VLV_GTLC_PW_STATUS) &
1311 VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
1312 seq_printf(m, "Media Power Well: %s\n",
1313 (I915_READ(VLV_GTLC_PW_STATUS) &
1314 VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
1315
Imre Deak9cc19be2014-04-14 20:24:24 +03001316 seq_printf(m, "Render RC6 residency since boot: %u\n",
1317 I915_READ(VLV_GT_RENDER_RC6));
1318 seq_printf(m, "Media RC6 residency since boot: %u\n",
1319 I915_READ(VLV_GT_MEDIA_RC6));
1320
Deepak S669ab5a2014-01-10 15:18:26 +05301321 spin_lock_irq(&dev_priv->uncore.lock);
1322 fw_rendercount = dev_priv->uncore.fw_rendercount;
1323 fw_mediacount = dev_priv->uncore.fw_mediacount;
1324 spin_unlock_irq(&dev_priv->uncore.lock);
1325
1326 seq_printf(m, "Forcewake Render Count = %u\n", fw_rendercount);
1327 seq_printf(m, "Forcewake Media Count = %u\n", fw_mediacount);
1328
1329
1330 return 0;
1331}
1332
1333
Ben Widawsky4d855292011-12-12 19:34:16 -08001334static int gen6_drpc_info(struct seq_file *m)
1335{
1336
Damien Lespiau9f25d002014-05-13 15:30:28 +01001337 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001338 struct drm_device *dev = node->minor->dev;
1339 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001340 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
Daniel Vetter93b525d2012-01-25 13:52:43 +01001341 unsigned forcewake_count;
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001342 int count = 0, ret;
Ben Widawsky4d855292011-12-12 19:34:16 -08001343
1344 ret = mutex_lock_interruptible(&dev->struct_mutex);
1345 if (ret)
1346 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001347 intel_runtime_pm_get(dev_priv);
Ben Widawsky4d855292011-12-12 19:34:16 -08001348
Chris Wilson907b28c2013-07-19 20:36:52 +01001349 spin_lock_irq(&dev_priv->uncore.lock);
1350 forcewake_count = dev_priv->uncore.forcewake_count;
1351 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter93b525d2012-01-25 13:52:43 +01001352
1353 if (forcewake_count) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001354 seq_puts(m, "RC information inaccurate because somebody "
1355 "holds a forcewake reference \n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001356 } else {
1357 /* NB: we cannot use forcewake, else we read the wrong values */
1358 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1359 udelay(10);
1360 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1361 }
1362
1363 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
Chris Wilsoned71f1b2013-07-19 20:36:56 +01001364 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
Ben Widawsky4d855292011-12-12 19:34:16 -08001365
1366 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1367 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1368 mutex_unlock(&dev->struct_mutex);
Ben Widawsky44cbd332012-11-06 14:36:36 +00001369 mutex_lock(&dev_priv->rps.hw_lock);
1370 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1371 mutex_unlock(&dev_priv->rps.hw_lock);
Ben Widawsky4d855292011-12-12 19:34:16 -08001372
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001373 intel_runtime_pm_put(dev_priv);
1374
Ben Widawsky4d855292011-12-12 19:34:16 -08001375 seq_printf(m, "Video Turbo Mode: %s\n",
1376 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1377 seq_printf(m, "HW control enabled: %s\n",
1378 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1379 seq_printf(m, "SW control enabled: %s\n",
1380 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1381 GEN6_RP_MEDIA_SW_MODE));
Eric Anholtfff24e22012-01-23 16:14:05 -08001382 seq_printf(m, "RC1e Enabled: %s\n",
Ben Widawsky4d855292011-12-12 19:34:16 -08001383 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1384 seq_printf(m, "RC6 Enabled: %s\n",
1385 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1386 seq_printf(m, "Deep RC6 Enabled: %s\n",
1387 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1388 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1389 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
Damien Lespiau267f0c92013-06-24 22:59:48 +01001390 seq_puts(m, "Current RC state: ");
Ben Widawsky4d855292011-12-12 19:34:16 -08001391 switch (gt_core_status & GEN6_RCn_MASK) {
1392 case GEN6_RC0:
1393 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
Damien Lespiau267f0c92013-06-24 22:59:48 +01001394 seq_puts(m, "Core Power Down\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001395 else
Damien Lespiau267f0c92013-06-24 22:59:48 +01001396 seq_puts(m, "on\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001397 break;
1398 case GEN6_RC3:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001399 seq_puts(m, "RC3\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001400 break;
1401 case GEN6_RC6:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001402 seq_puts(m, "RC6\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001403 break;
1404 case GEN6_RC7:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001405 seq_puts(m, "RC7\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001406 break;
1407 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001408 seq_puts(m, "Unknown\n");
Ben Widawsky4d855292011-12-12 19:34:16 -08001409 break;
1410 }
1411
1412 seq_printf(m, "Core Power Down: %s\n",
1413 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
Ben Widawskycce66a22012-03-27 18:59:38 -07001414
1415 /* Not exactly sure what this is */
1416 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1417 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1418 seq_printf(m, "RC6 residency since boot: %u\n",
1419 I915_READ(GEN6_GT_GFX_RC6));
1420 seq_printf(m, "RC6+ residency since boot: %u\n",
1421 I915_READ(GEN6_GT_GFX_RC6p));
1422 seq_printf(m, "RC6++ residency since boot: %u\n",
1423 I915_READ(GEN6_GT_GFX_RC6pp));
1424
Ben Widawskyecd8fae2012-09-26 10:34:02 -07001425 seq_printf(m, "RC6 voltage: %dmV\n",
1426 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1427 seq_printf(m, "RC6+ voltage: %dmV\n",
1428 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1429 seq_printf(m, "RC6++ voltage: %dmV\n",
1430 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
Ben Widawsky4d855292011-12-12 19:34:16 -08001431 return 0;
1432}
1433
1434static int i915_drpc_info(struct seq_file *m, void *unused)
1435{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001436 struct drm_info_node *node = m->private;
Ben Widawsky4d855292011-12-12 19:34:16 -08001437 struct drm_device *dev = node->minor->dev;
1438
Deepak S669ab5a2014-01-10 15:18:26 +05301439 if (IS_VALLEYVIEW(dev))
1440 return vlv_drpc_info(m);
1441 else if (IS_GEN6(dev) || IS_GEN7(dev))
Ben Widawsky4d855292011-12-12 19:34:16 -08001442 return gen6_drpc_info(m);
1443 else
1444 return ironlake_drpc_info(m);
1445}
1446
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001447static int i915_fbc_status(struct seq_file *m, void *unused)
1448{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001449 struct drm_info_node *node = m->private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001450 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001451 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001452
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01001453 if (!HAS_FBC(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001454 seq_puts(m, "FBC unsupported on this chipset\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001455 return 0;
1456 }
1457
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001458 intel_runtime_pm_get(dev_priv);
1459
Adam Jacksonee5382a2010-04-23 11:17:39 -04001460 if (intel_fbc_enabled(dev)) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001461 seq_puts(m, "FBC enabled\n");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001462 } else {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001463 seq_puts(m, "FBC disabled: ");
Ben Widawsky5c3fe8b2013-06-27 16:30:21 -07001464 switch (dev_priv->fbc.no_fbc_reason) {
Chris Wilson29ebf902013-07-27 17:23:55 +01001465 case FBC_OK:
1466 seq_puts(m, "FBC actived, but currently disabled in hardware");
1467 break;
1468 case FBC_UNSUPPORTED:
1469 seq_puts(m, "unsupported by this chipset");
1470 break;
Chris Wilsonbed4a672010-09-11 10:47:47 +01001471 case FBC_NO_OUTPUT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001472 seq_puts(m, "no outputs");
Chris Wilsonbed4a672010-09-11 10:47:47 +01001473 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001474 case FBC_STOLEN_TOO_SMALL:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001475 seq_puts(m, "not enough stolen memory");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001476 break;
1477 case FBC_UNSUPPORTED_MODE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001478 seq_puts(m, "mode not supported");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001479 break;
1480 case FBC_MODE_TOO_LARGE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001481 seq_puts(m, "mode too large");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001482 break;
1483 case FBC_BAD_PLANE:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001484 seq_puts(m, "FBC unsupported on plane");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001485 break;
1486 case FBC_NOT_TILED:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001487 seq_puts(m, "scanout buffer not tiled");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001488 break;
Jesse Barnes9c928d12010-07-23 15:20:00 -07001489 case FBC_MULTIPLE_PIPES:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001490 seq_puts(m, "multiple pipes are enabled");
Jesse Barnes9c928d12010-07-23 15:20:00 -07001491 break;
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001492 case FBC_MODULE_PARAM:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001493 seq_puts(m, "disabled per module param (default off)");
Jesse Barnesc1a9f042011-05-05 15:24:21 -07001494 break;
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001495 case FBC_CHIP_DEFAULT:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001496 seq_puts(m, "disabled per chip default");
Damien Lespiau8a5729a2013-06-24 16:22:02 +01001497 break;
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001498 default:
Damien Lespiau267f0c92013-06-24 22:59:48 +01001499 seq_puts(m, "unknown reason");
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001500 }
Damien Lespiau267f0c92013-06-24 22:59:48 +01001501 seq_putc(m, '\n');
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001502 }
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001503
1504 intel_runtime_pm_put(dev_priv);
1505
Jesse Barnesb5e50c32010-02-05 12:42:41 -08001506 return 0;
1507}
1508
Paulo Zanoni92d44622013-05-31 16:33:24 -03001509static int i915_ips_status(struct seq_file *m, void *unused)
1510{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001511 struct drm_info_node *node = m->private;
Paulo Zanoni92d44622013-05-31 16:33:24 -03001512 struct drm_device *dev = node->minor->dev;
1513 struct drm_i915_private *dev_priv = dev->dev_private;
1514
Damien Lespiauf5adf942013-06-24 18:29:34 +01001515 if (!HAS_IPS(dev)) {
Paulo Zanoni92d44622013-05-31 16:33:24 -03001516 seq_puts(m, "not supported\n");
1517 return 0;
1518 }
1519
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001520 intel_runtime_pm_get(dev_priv);
1521
Jesse Barnese59150d2014-01-07 13:30:45 -08001522 if (IS_BROADWELL(dev) || I915_READ(IPS_CTL) & IPS_ENABLE)
Paulo Zanoni92d44622013-05-31 16:33:24 -03001523 seq_puts(m, "enabled\n");
1524 else
1525 seq_puts(m, "disabled\n");
1526
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001527 intel_runtime_pm_put(dev_priv);
1528
Paulo Zanoni92d44622013-05-31 16:33:24 -03001529 return 0;
1530}
1531
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001532static int i915_sr_status(struct seq_file *m, void *unused)
1533{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001534 struct drm_info_node *node = m->private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001535 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001536 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001537 bool sr_enabled = false;
1538
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001539 intel_runtime_pm_get(dev_priv);
1540
Yuanhan Liu13982612010-12-15 15:42:31 +08001541 if (HAS_PCH_SPLIT(dev))
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001542 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001543 else if (IS_CRESTLINE(dev) || IS_I945G(dev) || IS_I945GM(dev))
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001544 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1545 else if (IS_I915GM(dev))
1546 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1547 else if (IS_PINEVIEW(dev))
1548 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
1549
Paulo Zanoni36623ef2014-02-21 13:52:23 -03001550 intel_runtime_pm_put(dev_priv);
1551
Chris Wilson5ba2aaa2010-08-19 18:04:08 +01001552 seq_printf(m, "self-refresh: %s\n",
1553 sr_enabled ? "enabled" : "disabled");
Jesse Barnes4a9bef32010-02-05 12:47:35 -08001554
1555 return 0;
1556}
1557
Jesse Barnes7648fa92010-05-20 14:28:11 -07001558static int i915_emon_status(struct seq_file *m, void *unused)
1559{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001560 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001561 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001562 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001563 unsigned long temp, chipset, gfx;
Chris Wilsonde227ef2010-07-03 07:58:38 +01001564 int ret;
1565
Chris Wilson582be6b2012-04-30 19:35:02 +01001566 if (!IS_GEN5(dev))
1567 return -ENODEV;
1568
Chris Wilsonde227ef2010-07-03 07:58:38 +01001569 ret = mutex_lock_interruptible(&dev->struct_mutex);
1570 if (ret)
1571 return ret;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001572
1573 temp = i915_mch_val(dev_priv);
1574 chipset = i915_chipset_val(dev_priv);
1575 gfx = i915_gfx_val(dev_priv);
Chris Wilsonde227ef2010-07-03 07:58:38 +01001576 mutex_unlock(&dev->struct_mutex);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001577
1578 seq_printf(m, "GMCH temp: %ld\n", temp);
1579 seq_printf(m, "Chipset power: %ld\n", chipset);
1580 seq_printf(m, "GFX power: %ld\n", gfx);
1581 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1582
1583 return 0;
1584}
1585
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001586static int i915_ring_freq_table(struct seq_file *m, void *unused)
1587{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001588 struct drm_info_node *node = m->private;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001589 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001590 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001591 int ret = 0;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001592 int gpu_freq, ia_freq;
1593
Jesse Barnes1c70c0c2011-06-29 13:34:36 -07001594 if (!(IS_GEN6(dev) || IS_GEN7(dev))) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001595 seq_puts(m, "unsupported on this chipset\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001596 return 0;
1597 }
1598
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001599 intel_runtime_pm_get(dev_priv);
1600
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07001601 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1602
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001603 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001604 if (ret)
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001605 goto out;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001606
Damien Lespiau267f0c92013-06-24 22:59:48 +01001607 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001608
Ben Widawskyb39fb292014-03-19 18:31:11 -07001609 for (gpu_freq = dev_priv->rps.min_freq_softlimit;
1610 gpu_freq <= dev_priv->rps.max_freq_softlimit;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001611 gpu_freq++) {
Ben Widawsky42c05262012-09-26 10:34:00 -07001612 ia_freq = gpu_freq;
1613 sandybridge_pcode_read(dev_priv,
1614 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1615 &ia_freq);
Chris Wilson3ebecd02013-04-12 19:10:13 +01001616 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
1617 gpu_freq * GT_FREQUENCY_MULTIPLIER,
1618 ((ia_freq >> 0) & 0xff) * 100,
1619 ((ia_freq >> 8) & 0xff) * 100);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001620 }
1621
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001622 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001623
Paulo Zanoni5bfa0192013-12-19 11:54:52 -02001624out:
1625 intel_runtime_pm_put(dev_priv);
1626 return ret;
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07001627}
1628
Jesse Barnes7648fa92010-05-20 14:28:11 -07001629static int i915_gfxec(struct seq_file *m, void *unused)
1630{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001631 struct drm_info_node *node = m->private;
Jesse Barnes7648fa92010-05-20 14:28:11 -07001632 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001633 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky616fdb52011-10-05 11:44:54 -07001634 int ret;
1635
1636 ret = mutex_lock_interruptible(&dev->struct_mutex);
1637 if (ret)
1638 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001639 intel_runtime_pm_get(dev_priv);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001640
1641 seq_printf(m, "GFXEC: %ld\n", (unsigned long)I915_READ(0x112f4));
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001642 intel_runtime_pm_put(dev_priv);
Jesse Barnes7648fa92010-05-20 14:28:11 -07001643
Ben Widawsky616fdb52011-10-05 11:44:54 -07001644 mutex_unlock(&dev->struct_mutex);
1645
Jesse Barnes7648fa92010-05-20 14:28:11 -07001646 return 0;
1647}
1648
Chris Wilson44834a62010-08-19 16:09:23 +01001649static int i915_opregion(struct seq_file *m, void *unused)
1650{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001651 struct drm_info_node *node = m->private;
Chris Wilson44834a62010-08-19 16:09:23 +01001652 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001653 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson44834a62010-08-19 16:09:23 +01001654 struct intel_opregion *opregion = &dev_priv->opregion;
Daniel Vetter0d38f002012-04-21 22:49:10 +02001655 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
Chris Wilson44834a62010-08-19 16:09:23 +01001656 int ret;
1657
Daniel Vetter0d38f002012-04-21 22:49:10 +02001658 if (data == NULL)
1659 return -ENOMEM;
1660
Chris Wilson44834a62010-08-19 16:09:23 +01001661 ret = mutex_lock_interruptible(&dev->struct_mutex);
1662 if (ret)
Daniel Vetter0d38f002012-04-21 22:49:10 +02001663 goto out;
Chris Wilson44834a62010-08-19 16:09:23 +01001664
Daniel Vetter0d38f002012-04-21 22:49:10 +02001665 if (opregion->header) {
1666 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1667 seq_write(m, data, OPREGION_SIZE);
1668 }
Chris Wilson44834a62010-08-19 16:09:23 +01001669
1670 mutex_unlock(&dev->struct_mutex);
1671
Daniel Vetter0d38f002012-04-21 22:49:10 +02001672out:
1673 kfree(data);
Chris Wilson44834a62010-08-19 16:09:23 +01001674 return 0;
1675}
1676
Chris Wilson37811fc2010-08-25 22:45:57 +01001677static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1678{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001679 struct drm_info_node *node = m->private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001680 struct drm_device *dev = node->minor->dev;
Daniel Vetter4520f532013-10-09 09:18:51 +02001681 struct intel_fbdev *ifbdev = NULL;
Chris Wilson37811fc2010-08-25 22:45:57 +01001682 struct intel_framebuffer *fb;
Chris Wilson37811fc2010-08-25 22:45:57 +01001683
Daniel Vetter4520f532013-10-09 09:18:51 +02001684#ifdef CONFIG_DRM_I915_FBDEV
1685 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson37811fc2010-08-25 22:45:57 +01001686
1687 ifbdev = dev_priv->fbdev;
1688 fb = to_intel_framebuffer(ifbdev->helper.fb);
1689
Daniel Vetter623f9782012-12-11 16:21:38 +01001690 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001691 fb->base.width,
1692 fb->base.height,
1693 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001694 fb->base.bits_per_pixel,
1695 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001696 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001697 seq_putc(m, '\n');
Daniel Vetter4520f532013-10-09 09:18:51 +02001698#endif
Chris Wilson37811fc2010-08-25 22:45:57 +01001699
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001700 mutex_lock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001701 list_for_each_entry(fb, &dev->mode_config.fb_list, base.head) {
Daniel Vetter131a56d2013-10-17 14:35:31 +02001702 if (ifbdev && &fb->base == ifbdev->helper.fb)
Chris Wilson37811fc2010-08-25 22:45:57 +01001703 continue;
1704
Daniel Vetter623f9782012-12-11 16:21:38 +01001705 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, refcount %d, obj ",
Chris Wilson37811fc2010-08-25 22:45:57 +01001706 fb->base.width,
1707 fb->base.height,
1708 fb->base.depth,
Daniel Vetter623f9782012-12-11 16:21:38 +01001709 fb->base.bits_per_pixel,
1710 atomic_read(&fb->base.refcount.refcount));
Chris Wilson05394f32010-11-08 19:18:58 +00001711 describe_obj(m, fb->obj);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001712 seq_putc(m, '\n');
Chris Wilson37811fc2010-08-25 22:45:57 +01001713 }
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001714 mutex_unlock(&dev->mode_config.fb_lock);
Chris Wilson37811fc2010-08-25 22:45:57 +01001715
1716 return 0;
1717}
1718
Ben Widawskye76d3632011-03-19 18:14:29 -07001719static int i915_context_status(struct seq_file *m, void *unused)
1720{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001721 struct drm_info_node *node = m->private;
Ben Widawskye76d3632011-03-19 18:14:29 -07001722 struct drm_device *dev = node->minor->dev;
Jani Nikulae277a1f2014-03-31 14:27:14 +03001723 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001724 struct intel_engine_cs *ring;
Oscar Mateo273497e2014-05-22 14:13:37 +01001725 struct intel_context *ctx;
Ben Widawskya168c292013-02-14 15:05:12 -08001726 int ret, i;
Ben Widawskye76d3632011-03-19 18:14:29 -07001727
Daniel Vetterf3d28872014-05-29 23:23:08 +02001728 ret = mutex_lock_interruptible(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001729 if (ret)
1730 return ret;
1731
Daniel Vetter3e373942012-11-02 19:55:04 +01001732 if (dev_priv->ips.pwrctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001733 seq_puts(m, "power context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001734 describe_obj(m, dev_priv->ips.pwrctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001735 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001736 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001737
Daniel Vetter3e373942012-11-02 19:55:04 +01001738 if (dev_priv->ips.renderctx) {
Damien Lespiau267f0c92013-06-24 22:59:48 +01001739 seq_puts(m, "render context ");
Daniel Vetter3e373942012-11-02 19:55:04 +01001740 describe_obj(m, dev_priv->ips.renderctx);
Damien Lespiau267f0c92013-06-24 22:59:48 +01001741 seq_putc(m, '\n');
Ben Widawskydc501fb2011-06-29 11:41:51 -07001742 }
Ben Widawskye76d3632011-03-19 18:14:29 -07001743
Ben Widawskya33afea2013-09-17 21:12:45 -07001744 list_for_each_entry(ctx, &dev_priv->context_list, link) {
Chris Wilsonb77f6992014-04-30 08:30:00 +01001745 if (ctx->obj == NULL)
1746 continue;
1747
Ben Widawskya33afea2013-09-17 21:12:45 -07001748 seq_puts(m, "HW context ");
Ben Widawsky3ccfd192013-09-18 19:03:18 -07001749 describe_ctx(m, ctx);
Ben Widawskya33afea2013-09-17 21:12:45 -07001750 for_each_ring(ring, dev_priv, i)
1751 if (ring->default_context == ctx)
1752 seq_printf(m, "(default context %s) ", ring->name);
1753
1754 describe_obj(m, ctx->obj);
1755 seq_putc(m, '\n');
Ben Widawskya168c292013-02-14 15:05:12 -08001756 }
1757
Daniel Vetterf3d28872014-05-29 23:23:08 +02001758 mutex_unlock(&dev->struct_mutex);
Ben Widawskye76d3632011-03-19 18:14:29 -07001759
1760 return 0;
1761}
1762
Ben Widawsky6d794d42011-04-25 11:25:56 -07001763static int i915_gen6_forcewake_count_info(struct seq_file *m, void *data)
1764{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001765 struct drm_info_node *node = m->private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001766 struct drm_device *dev = node->minor->dev;
1767 struct drm_i915_private *dev_priv = dev->dev_private;
Deepak S43709ba2013-11-23 14:55:44 +05301768 unsigned forcewake_count = 0, fw_rendercount = 0, fw_mediacount = 0;
Ben Widawsky6d794d42011-04-25 11:25:56 -07001769
Chris Wilson907b28c2013-07-19 20:36:52 +01001770 spin_lock_irq(&dev_priv->uncore.lock);
Deepak S43709ba2013-11-23 14:55:44 +05301771 if (IS_VALLEYVIEW(dev)) {
1772 fw_rendercount = dev_priv->uncore.fw_rendercount;
1773 fw_mediacount = dev_priv->uncore.fw_mediacount;
1774 } else
1775 forcewake_count = dev_priv->uncore.forcewake_count;
Chris Wilson907b28c2013-07-19 20:36:52 +01001776 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter9f1f46a2011-12-14 13:57:03 +01001777
Deepak S43709ba2013-11-23 14:55:44 +05301778 if (IS_VALLEYVIEW(dev)) {
1779 seq_printf(m, "fw_rendercount = %u\n", fw_rendercount);
1780 seq_printf(m, "fw_mediacount = %u\n", fw_mediacount);
1781 } else
1782 seq_printf(m, "forcewake count = %u\n", forcewake_count);
Ben Widawsky6d794d42011-04-25 11:25:56 -07001783
1784 return 0;
1785}
1786
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001787static const char *swizzle_string(unsigned swizzle)
1788{
Damien Lespiauaee56cf2013-06-24 22:59:49 +01001789 switch (swizzle) {
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001790 case I915_BIT_6_SWIZZLE_NONE:
1791 return "none";
1792 case I915_BIT_6_SWIZZLE_9:
1793 return "bit9";
1794 case I915_BIT_6_SWIZZLE_9_10:
1795 return "bit9/bit10";
1796 case I915_BIT_6_SWIZZLE_9_11:
1797 return "bit9/bit11";
1798 case I915_BIT_6_SWIZZLE_9_10_11:
1799 return "bit9/bit10/bit11";
1800 case I915_BIT_6_SWIZZLE_9_17:
1801 return "bit9/bit17";
1802 case I915_BIT_6_SWIZZLE_9_10_17:
1803 return "bit9/bit10/bit17";
1804 case I915_BIT_6_SWIZZLE_UNKNOWN:
Masanari Iida8a168ca2012-12-29 02:00:09 +09001805 return "unknown";
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001806 }
1807
1808 return "bug";
1809}
1810
1811static int i915_swizzle_info(struct seq_file *m, void *data)
1812{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001813 struct drm_info_node *node = m->private;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001814 struct drm_device *dev = node->minor->dev;
1815 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001816 int ret;
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001817
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001818 ret = mutex_lock_interruptible(&dev->struct_mutex);
1819 if (ret)
1820 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001821 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02001822
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001823 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
1824 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
1825 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
1826 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
1827
1828 if (IS_GEN3(dev) || IS_GEN4(dev)) {
1829 seq_printf(m, "DDC = 0x%08x\n",
1830 I915_READ(DCC));
1831 seq_printf(m, "C0DRB3 = 0x%04x\n",
1832 I915_READ16(C0DRB3));
1833 seq_printf(m, "C1DRB3 = 0x%04x\n",
1834 I915_READ16(C1DRB3));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001835 } else if (INTEL_INFO(dev)->gen >= 6) {
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001836 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
1837 I915_READ(MAD_DIMM_C0));
1838 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
1839 I915_READ(MAD_DIMM_C1));
1840 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
1841 I915_READ(MAD_DIMM_C2));
1842 seq_printf(m, "TILECTL = 0x%08x\n",
1843 I915_READ(TILECTL));
Ben Widawsky9d3203e2013-11-02 21:07:14 -07001844 if (IS_GEN8(dev))
1845 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
1846 I915_READ(GAMTARBMODE));
1847 else
1848 seq_printf(m, "ARB_MODE = 0x%08x\n",
1849 I915_READ(ARB_MODE));
Daniel Vetter3fa7d232012-01-31 16:47:56 +01001850 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
1851 I915_READ(DISP_ARB_CTL));
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001852 }
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001853 intel_runtime_pm_put(dev_priv);
Daniel Vetterea16a3c2011-12-14 13:57:16 +01001854 mutex_unlock(&dev->struct_mutex);
1855
1856 return 0;
1857}
1858
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001859static int per_file_ctx(int id, void *ptr, void *data)
1860{
Oscar Mateo273497e2014-05-22 14:13:37 +01001861 struct intel_context *ctx = ptr;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001862 struct seq_file *m = data;
1863 struct i915_hw_ppgtt *ppgtt = ctx_to_ppgtt(ctx);
1864
Oscar Mateof83d6512014-05-22 14:13:38 +01001865 if (i915_gem_context_is_default(ctx))
1866 seq_puts(m, " default context:\n");
1867 else
1868 seq_printf(m, " context %d:\n", ctx->id);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001869 ppgtt->debug_dump(ppgtt, m);
1870
1871 return 0;
1872}
1873
Ben Widawsky77df6772013-11-02 21:07:30 -07001874static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001875{
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001876 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001877 struct intel_engine_cs *ring;
Ben Widawsky77df6772013-11-02 21:07:30 -07001878 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1879 int unused, i;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001880
Ben Widawsky77df6772013-11-02 21:07:30 -07001881 if (!ppgtt)
1882 return;
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001883
Ben Widawsky77df6772013-11-02 21:07:30 -07001884 seq_printf(m, "Page directories: %d\n", ppgtt->num_pd_pages);
Ben Widawsky5abbcca2014-02-21 13:06:34 -08001885 seq_printf(m, "Page tables: %d\n", ppgtt->num_pd_entries);
Ben Widawsky77df6772013-11-02 21:07:30 -07001886 for_each_ring(ring, dev_priv, unused) {
1887 seq_printf(m, "%s\n", ring->name);
1888 for (i = 0; i < 4; i++) {
1889 u32 offset = 0x270 + i * 8;
1890 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
1891 pdp <<= 32;
1892 pdp |= I915_READ(ring->mmio_base + offset);
Ville Syrjäläa2a5b152014-03-31 18:17:16 +03001893 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
Ben Widawsky77df6772013-11-02 21:07:30 -07001894 }
1895 }
1896}
1897
1898static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
1899{
1900 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001901 struct intel_engine_cs *ring;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001902 struct drm_file *file;
Ben Widawsky77df6772013-11-02 21:07:30 -07001903 int i;
1904
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001905 if (INTEL_INFO(dev)->gen == 6)
1906 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
1907
Chris Wilsona2c7f6f2012-09-01 20:51:22 +01001908 for_each_ring(ring, dev_priv, i) {
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001909 seq_printf(m, "%s\n", ring->name);
1910 if (INTEL_INFO(dev)->gen == 7)
1911 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
1912 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
1913 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
1914 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
1915 }
1916 if (dev_priv->mm.aliasing_ppgtt) {
1917 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
1918
Damien Lespiau267f0c92013-06-24 22:59:48 +01001919 seq_puts(m, "aliasing PPGTT:\n");
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001920 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd_offset);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001921
Ben Widawsky87d60b62013-12-06 14:11:29 -08001922 ppgtt->debug_dump(ppgtt, m);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001923 } else
1924 return;
1925
1926 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
1927 struct drm_i915_file_private *file_priv = file->driver_priv;
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001928
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001929 seq_printf(m, "proc: %s\n",
1930 get_pid_task(file->pid, PIDTYPE_PID)->comm);
Ben Widawsky1c60fef2013-12-06 14:11:30 -08001931 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001932 }
1933 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
Ben Widawsky77df6772013-11-02 21:07:30 -07001934}
1935
1936static int i915_ppgtt_info(struct seq_file *m, void *data)
1937{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001938 struct drm_info_node *node = m->private;
Ben Widawsky77df6772013-11-02 21:07:30 -07001939 struct drm_device *dev = node->minor->dev;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001940 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky77df6772013-11-02 21:07:30 -07001941
1942 int ret = mutex_lock_interruptible(&dev->struct_mutex);
1943 if (ret)
1944 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001945 intel_runtime_pm_get(dev_priv);
Ben Widawsky77df6772013-11-02 21:07:30 -07001946
1947 if (INTEL_INFO(dev)->gen >= 8)
1948 gen8_ppgtt_info(m, dev);
1949 else if (INTEL_INFO(dev)->gen >= 6)
1950 gen6_ppgtt_info(m, dev);
1951
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001952 intel_runtime_pm_put(dev_priv);
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01001953 mutex_unlock(&dev->struct_mutex);
1954
1955 return 0;
1956}
1957
Ben Widawsky63573eb2013-07-04 11:02:07 -07001958static int i915_llc(struct seq_file *m, void *data)
1959{
Damien Lespiau9f25d002014-05-13 15:30:28 +01001960 struct drm_info_node *node = m->private;
Ben Widawsky63573eb2013-07-04 11:02:07 -07001961 struct drm_device *dev = node->minor->dev;
1962 struct drm_i915_private *dev_priv = dev->dev_private;
1963
1964 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
1965 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
1966 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
1967
1968 return 0;
1969}
1970
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001971static int i915_edp_psr_status(struct seq_file *m, void *data)
1972{
1973 struct drm_info_node *node = m->private;
1974 struct drm_device *dev = node->minor->dev;
1975 struct drm_i915_private *dev_priv = dev->dev_private;
Rodrigo Vivia031d702013-10-03 16:15:06 -03001976 u32 psrperf = 0;
1977 bool enabled = false;
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001978
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001979 intel_runtime_pm_get(dev_priv);
1980
Rodrigo Vivia031d702013-10-03 16:15:06 -03001981 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
1982 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
Rodrigo Vivi5755c782014-06-12 10:16:45 -07001983 seq_printf(m, "Enabled: %s\n", yesno(dev_priv->psr.enabled));
1984 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001985
Rodrigo Vivia031d702013-10-03 16:15:06 -03001986 enabled = HAS_PSR(dev) &&
1987 I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
Rodrigo Vivi5755c782014-06-12 10:16:45 -07001988 seq_printf(m, "HW Enabled & Active bit: %s\n", yesno(enabled));
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001989
Rodrigo Vivia031d702013-10-03 16:15:06 -03001990 if (HAS_PSR(dev))
1991 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
1992 EDP_PSR_PERF_CNT_MASK;
1993 seq_printf(m, "Performance_Counter: %u\n", psrperf);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001994
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02001995 intel_runtime_pm_put(dev_priv);
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03001996 return 0;
1997}
1998
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02001999static int i915_sink_crc(struct seq_file *m, void *data)
2000{
2001 struct drm_info_node *node = m->private;
2002 struct drm_device *dev = node->minor->dev;
2003 struct intel_encoder *encoder;
2004 struct intel_connector *connector;
2005 struct intel_dp *intel_dp = NULL;
2006 int ret;
2007 u8 crc[6];
2008
2009 drm_modeset_lock_all(dev);
2010 list_for_each_entry(connector, &dev->mode_config.connector_list,
2011 base.head) {
2012
2013 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2014 continue;
2015
Paulo Zanonib6ae3c72014-02-13 17:51:33 -02002016 if (!connector->base.encoder)
2017 continue;
2018
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02002019 encoder = to_intel_encoder(connector->base.encoder);
2020 if (encoder->type != INTEL_OUTPUT_EDP)
2021 continue;
2022
2023 intel_dp = enc_to_intel_dp(&encoder->base);
2024
2025 ret = intel_dp_sink_crc(intel_dp, crc);
2026 if (ret)
2027 goto out;
2028
2029 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2030 crc[0], crc[1], crc[2],
2031 crc[3], crc[4], crc[5]);
2032 goto out;
2033 }
2034 ret = -ENODEV;
2035out:
2036 drm_modeset_unlock_all(dev);
2037 return ret;
2038}
2039
Jesse Barnesec013e72013-08-20 10:29:23 +01002040static int i915_energy_uJ(struct seq_file *m, void *data)
2041{
2042 struct drm_info_node *node = m->private;
2043 struct drm_device *dev = node->minor->dev;
2044 struct drm_i915_private *dev_priv = dev->dev_private;
2045 u64 power;
2046 u32 units;
2047
2048 if (INTEL_INFO(dev)->gen < 6)
2049 return -ENODEV;
2050
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002051 intel_runtime_pm_get(dev_priv);
2052
Jesse Barnesec013e72013-08-20 10:29:23 +01002053 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2054 power = (power & 0x1f00) >> 8;
2055 units = 1000000 / (1 << power); /* convert to uJ */
2056 power = I915_READ(MCH_SECP_NRG_STTS);
2057 power *= units;
2058
Paulo Zanoni36623ef2014-02-21 13:52:23 -03002059 intel_runtime_pm_put(dev_priv);
2060
Jesse Barnesec013e72013-08-20 10:29:23 +01002061 seq_printf(m, "%llu", (long long unsigned)power);
Paulo Zanoni371db662013-08-19 13:18:10 -03002062
2063 return 0;
2064}
2065
2066static int i915_pc8_status(struct seq_file *m, void *unused)
2067{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002068 struct drm_info_node *node = m->private;
Paulo Zanoni371db662013-08-19 13:18:10 -03002069 struct drm_device *dev = node->minor->dev;
2070 struct drm_i915_private *dev_priv = dev->dev_private;
2071
Zhenyu Wang85b8d5c2014-04-01 19:39:48 -03002072 if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
Paulo Zanoni371db662013-08-19 13:18:10 -03002073 seq_puts(m, "not supported\n");
2074 return 0;
2075 }
2076
Paulo Zanoni86c4ec02014-02-21 13:52:24 -03002077 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
Paulo Zanoni371db662013-08-19 13:18:10 -03002078 seq_printf(m, "IRQs disabled: %s\n",
Paulo Zanoni5d584b22014-03-07 20:08:15 -03002079 yesno(dev_priv->pm.irqs_disabled));
Paulo Zanoni371db662013-08-19 13:18:10 -03002080
Jesse Barnesec013e72013-08-20 10:29:23 +01002081 return 0;
2082}
2083
Imre Deak1da51582013-11-25 17:15:35 +02002084static const char *power_domain_str(enum intel_display_power_domain domain)
2085{
2086 switch (domain) {
2087 case POWER_DOMAIN_PIPE_A:
2088 return "PIPE_A";
2089 case POWER_DOMAIN_PIPE_B:
2090 return "PIPE_B";
2091 case POWER_DOMAIN_PIPE_C:
2092 return "PIPE_C";
2093 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2094 return "PIPE_A_PANEL_FITTER";
2095 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2096 return "PIPE_B_PANEL_FITTER";
2097 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2098 return "PIPE_C_PANEL_FITTER";
2099 case POWER_DOMAIN_TRANSCODER_A:
2100 return "TRANSCODER_A";
2101 case POWER_DOMAIN_TRANSCODER_B:
2102 return "TRANSCODER_B";
2103 case POWER_DOMAIN_TRANSCODER_C:
2104 return "TRANSCODER_C";
2105 case POWER_DOMAIN_TRANSCODER_EDP:
2106 return "TRANSCODER_EDP";
Imre Deak319be8a2014-03-04 19:22:57 +02002107 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2108 return "PORT_DDI_A_2_LANES";
2109 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2110 return "PORT_DDI_A_4_LANES";
2111 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2112 return "PORT_DDI_B_2_LANES";
2113 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2114 return "PORT_DDI_B_4_LANES";
2115 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2116 return "PORT_DDI_C_2_LANES";
2117 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2118 return "PORT_DDI_C_4_LANES";
2119 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2120 return "PORT_DDI_D_2_LANES";
2121 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2122 return "PORT_DDI_D_4_LANES";
2123 case POWER_DOMAIN_PORT_DSI:
2124 return "PORT_DSI";
2125 case POWER_DOMAIN_PORT_CRT:
2126 return "PORT_CRT";
2127 case POWER_DOMAIN_PORT_OTHER:
2128 return "PORT_OTHER";
Imre Deak1da51582013-11-25 17:15:35 +02002129 case POWER_DOMAIN_VGA:
2130 return "VGA";
2131 case POWER_DOMAIN_AUDIO:
2132 return "AUDIO";
2133 case POWER_DOMAIN_INIT:
2134 return "INIT";
2135 default:
2136 WARN_ON(1);
2137 return "?";
2138 }
2139}
2140
2141static int i915_power_domain_info(struct seq_file *m, void *unused)
2142{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002143 struct drm_info_node *node = m->private;
Imre Deak1da51582013-11-25 17:15:35 +02002144 struct drm_device *dev = node->minor->dev;
2145 struct drm_i915_private *dev_priv = dev->dev_private;
2146 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2147 int i;
2148
2149 mutex_lock(&power_domains->lock);
2150
2151 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2152 for (i = 0; i < power_domains->power_well_count; i++) {
2153 struct i915_power_well *power_well;
2154 enum intel_display_power_domain power_domain;
2155
2156 power_well = &power_domains->power_wells[i];
2157 seq_printf(m, "%-25s %d\n", power_well->name,
2158 power_well->count);
2159
2160 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2161 power_domain++) {
2162 if (!(BIT(power_domain) & power_well->domains))
2163 continue;
2164
2165 seq_printf(m, " %-23s %d\n",
2166 power_domain_str(power_domain),
2167 power_domains->domain_use_count[power_domain]);
2168 }
2169 }
2170
2171 mutex_unlock(&power_domains->lock);
2172
2173 return 0;
2174}
2175
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002176static void intel_seq_print_mode(struct seq_file *m, int tabs,
2177 struct drm_display_mode *mode)
2178{
2179 int i;
2180
2181 for (i = 0; i < tabs; i++)
2182 seq_putc(m, '\t');
2183
2184 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",
2185 mode->base.id, mode->name,
2186 mode->vrefresh, mode->clock,
2187 mode->hdisplay, mode->hsync_start,
2188 mode->hsync_end, mode->htotal,
2189 mode->vdisplay, mode->vsync_start,
2190 mode->vsync_end, mode->vtotal,
2191 mode->type, mode->flags);
2192}
2193
2194static void intel_encoder_info(struct seq_file *m,
2195 struct intel_crtc *intel_crtc,
2196 struct intel_encoder *intel_encoder)
2197{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002198 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002199 struct drm_device *dev = node->minor->dev;
2200 struct drm_crtc *crtc = &intel_crtc->base;
2201 struct intel_connector *intel_connector;
2202 struct drm_encoder *encoder;
2203
2204 encoder = &intel_encoder->base;
2205 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
Jani Nikula8e329a02014-06-03 14:56:21 +03002206 encoder->base.id, encoder->name);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002207 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2208 struct drm_connector *connector = &intel_connector->base;
2209 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2210 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +03002211 connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002212 drm_get_connector_status_name(connector->status));
2213 if (connector->status == connector_status_connected) {
2214 struct drm_display_mode *mode = &crtc->mode;
2215 seq_printf(m, ", mode:\n");
2216 intel_seq_print_mode(m, 2, mode);
2217 } else {
2218 seq_putc(m, '\n');
2219 }
2220 }
2221}
2222
2223static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2224{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002225 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002226 struct drm_device *dev = node->minor->dev;
2227 struct drm_crtc *crtc = &intel_crtc->base;
2228 struct intel_encoder *intel_encoder;
2229
Matt Roper5aa8a932014-06-16 10:12:55 -07002230 if (crtc->primary->fb)
2231 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2232 crtc->primary->fb->base.id, crtc->x, crtc->y,
2233 crtc->primary->fb->width, crtc->primary->fb->height);
2234 else
2235 seq_puts(m, "\tprimary plane disabled\n");
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002236 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2237 intel_encoder_info(m, intel_crtc, intel_encoder);
2238}
2239
2240static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2241{
2242 struct drm_display_mode *mode = panel->fixed_mode;
2243
2244 seq_printf(m, "\tfixed mode:\n");
2245 intel_seq_print_mode(m, 2, mode);
2246}
2247
2248static void intel_dp_info(struct seq_file *m,
2249 struct intel_connector *intel_connector)
2250{
2251 struct intel_encoder *intel_encoder = intel_connector->encoder;
2252 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2253
2254 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2255 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2256 "no");
2257 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2258 intel_panel_info(m, &intel_connector->panel);
2259}
2260
2261static void intel_hdmi_info(struct seq_file *m,
2262 struct intel_connector *intel_connector)
2263{
2264 struct intel_encoder *intel_encoder = intel_connector->encoder;
2265 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2266
2267 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2268 "no");
2269}
2270
2271static void intel_lvds_info(struct seq_file *m,
2272 struct intel_connector *intel_connector)
2273{
2274 intel_panel_info(m, &intel_connector->panel);
2275}
2276
2277static void intel_connector_info(struct seq_file *m,
2278 struct drm_connector *connector)
2279{
2280 struct intel_connector *intel_connector = to_intel_connector(connector);
2281 struct intel_encoder *intel_encoder = intel_connector->encoder;
Jesse Barnesf103fc72014-02-20 12:39:57 -08002282 struct drm_display_mode *mode;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002283
2284 seq_printf(m, "connector %d: type %s, status: %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03002285 connector->base.id, connector->name,
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002286 drm_get_connector_status_name(connector->status));
2287 if (connector->status == connector_status_connected) {
2288 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2289 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2290 connector->display_info.width_mm,
2291 connector->display_info.height_mm);
2292 seq_printf(m, "\tsubpixel order: %s\n",
2293 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2294 seq_printf(m, "\tCEA rev: %d\n",
2295 connector->display_info.cea_rev);
2296 }
2297 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2298 intel_encoder->type == INTEL_OUTPUT_EDP)
2299 intel_dp_info(m, intel_connector);
2300 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2301 intel_hdmi_info(m, intel_connector);
2302 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2303 intel_lvds_info(m, intel_connector);
2304
Jesse Barnesf103fc72014-02-20 12:39:57 -08002305 seq_printf(m, "\tmodes:\n");
2306 list_for_each_entry(mode, &connector->modes, head)
2307 intel_seq_print_mode(m, 2, mode);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002308}
2309
Chris Wilson065f2ec2014-03-12 09:13:13 +00002310static bool cursor_active(struct drm_device *dev, int pipe)
2311{
2312 struct drm_i915_private *dev_priv = dev->dev_private;
2313 u32 state;
2314
2315 if (IS_845G(dev) || IS_I865G(dev))
2316 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002317 else
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002318 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002319
2320 return state;
2321}
2322
2323static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2324{
2325 struct drm_i915_private *dev_priv = dev->dev_private;
2326 u32 pos;
2327
Ville Syrjälä5efb3e22014-04-09 13:28:53 +03002328 pos = I915_READ(CURPOS(pipe));
Chris Wilson065f2ec2014-03-12 09:13:13 +00002329
2330 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2331 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2332 *x = -*x;
2333
2334 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2335 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2336 *y = -*y;
2337
2338 return cursor_active(dev, pipe);
2339}
2340
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002341static int i915_display_info(struct seq_file *m, void *unused)
2342{
Damien Lespiau9f25d002014-05-13 15:30:28 +01002343 struct drm_info_node *node = m->private;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002344 struct drm_device *dev = node->minor->dev;
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002345 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson065f2ec2014-03-12 09:13:13 +00002346 struct intel_crtc *crtc;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002347 struct drm_connector *connector;
2348
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002349 intel_runtime_pm_get(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002350 drm_modeset_lock_all(dev);
2351 seq_printf(m, "CRTC info\n");
2352 seq_printf(m, "---------\n");
Damien Lespiaud3fcc802014-05-13 23:32:22 +01002353 for_each_intel_crtc(dev, crtc) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002354 bool active;
2355 int x, y;
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002356
2357 seq_printf(m, "CRTC %d: pipe: %c, active: %s\n",
Chris Wilson065f2ec2014-03-12 09:13:13 +00002358 crtc->base.base.id, pipe_name(crtc->pipe),
2359 yesno(crtc->active));
Paulo Zanonia23dc652014-04-01 14:55:11 -03002360 if (crtc->active) {
Chris Wilson065f2ec2014-03-12 09:13:13 +00002361 intel_crtc_info(m, crtc);
2362
Paulo Zanonia23dc652014-04-01 14:55:11 -03002363 active = cursor_position(dev, crtc->pipe, &x, &y);
2364 seq_printf(m, "\tcursor visible? %s, position (%d, %d), addr 0x%08x, active? %s\n",
Chris Wilson4b0e3332014-05-30 16:35:26 +03002365 yesno(crtc->cursor_base),
Paulo Zanonia23dc652014-04-01 14:55:11 -03002366 x, y, crtc->cursor_addr,
2367 yesno(active));
2368 }
Daniel Vettercace8412014-05-22 17:56:31 +02002369
2370 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2371 yesno(!crtc->cpu_fifo_underrun_disabled),
2372 yesno(!crtc->pch_fifo_underrun_disabled));
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002373 }
2374
2375 seq_printf(m, "\n");
2376 seq_printf(m, "Connector info\n");
2377 seq_printf(m, "--------------\n");
2378 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2379 intel_connector_info(m, connector);
2380 }
2381 drm_modeset_unlock_all(dev);
Paulo Zanonib0e5ddf2014-04-01 14:55:10 -03002382 intel_runtime_pm_put(dev_priv);
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08002383
2384 return 0;
2385}
2386
Damien Lespiau07144422013-10-15 18:55:40 +01002387struct pipe_crc_info {
2388 const char *name;
2389 struct drm_device *dev;
2390 enum pipe pipe;
2391};
2392
2393static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
Shuang He8bf1e9f2013-10-15 18:55:27 +01002394{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002395 struct pipe_crc_info *info = inode->i_private;
2396 struct drm_i915_private *dev_priv = info->dev->dev_private;
2397 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2398
Daniel Vetter7eb1c492013-11-14 11:30:43 +01002399 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
2400 return -ENODEV;
2401
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002402 spin_lock_irq(&pipe_crc->lock);
2403
2404 if (pipe_crc->opened) {
2405 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002406 return -EBUSY; /* already open */
2407 }
2408
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002409 pipe_crc->opened = true;
Damien Lespiau07144422013-10-15 18:55:40 +01002410 filep->private_data = inode->i_private;
2411
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002412 spin_unlock_irq(&pipe_crc->lock);
2413
Damien Lespiau07144422013-10-15 18:55:40 +01002414 return 0;
2415}
2416
2417static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
2418{
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002419 struct pipe_crc_info *info = inode->i_private;
2420 struct drm_i915_private *dev_priv = info->dev->dev_private;
2421 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2422
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002423 spin_lock_irq(&pipe_crc->lock);
2424 pipe_crc->opened = false;
2425 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiaube5c7a92013-10-15 18:55:41 +01002426
Damien Lespiau07144422013-10-15 18:55:40 +01002427 return 0;
2428}
2429
2430/* (6 fields, 8 chars each, space separated (5) + '\n') */
2431#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
2432/* account for \'0' */
2433#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
2434
2435static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
2436{
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002437 assert_spin_locked(&pipe_crc->lock);
2438 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
2439 INTEL_PIPE_CRC_ENTRIES_NR);
Damien Lespiau07144422013-10-15 18:55:40 +01002440}
Shuang He8bf1e9f2013-10-15 18:55:27 +01002441
Damien Lespiau07144422013-10-15 18:55:40 +01002442static ssize_t
2443i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
2444 loff_t *pos)
2445{
2446 struct pipe_crc_info *info = filep->private_data;
2447 struct drm_device *dev = info->dev;
2448 struct drm_i915_private *dev_priv = dev->dev_private;
2449 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
2450 char buf[PIPE_CRC_BUFFER_LEN];
2451 int head, tail, n_entries, n;
2452 ssize_t bytes_read;
2453
2454 /*
2455 * Don't allow user space to provide buffers not big enough to hold
2456 * a line of data.
2457 */
2458 if (count < PIPE_CRC_LINE_LEN)
2459 return -EINVAL;
2460
2461 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
2462 return 0;
2463
2464 /* nothing to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002465 spin_lock_irq(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01002466 while (pipe_crc_data_count(pipe_crc) == 0) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002467 int ret;
Damien Lespiau07144422013-10-15 18:55:40 +01002468
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002469 if (filep->f_flags & O_NONBLOCK) {
2470 spin_unlock_irq(&pipe_crc->lock);
2471 return -EAGAIN;
2472 }
2473
2474 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
2475 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
2476 if (ret) {
2477 spin_unlock_irq(&pipe_crc->lock);
2478 return ret;
2479 }
Damien Lespiau07144422013-10-15 18:55:40 +01002480 }
2481
2482 /* We now have one or more entries to read */
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002483 head = pipe_crc->head;
2484 tail = pipe_crc->tail;
Damien Lespiau07144422013-10-15 18:55:40 +01002485 n_entries = min((size_t)CIRC_CNT(head, tail, INTEL_PIPE_CRC_ENTRIES_NR),
2486 count / PIPE_CRC_LINE_LEN);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002487 spin_unlock_irq(&pipe_crc->lock);
2488
Damien Lespiau07144422013-10-15 18:55:40 +01002489 bytes_read = 0;
2490 n = 0;
2491 do {
2492 struct intel_pipe_crc_entry *entry = &pipe_crc->entries[tail];
2493 int ret;
2494
2495 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
2496 "%8u %8x %8x %8x %8x %8x\n",
2497 entry->frame, entry->crc[0],
2498 entry->crc[1], entry->crc[2],
2499 entry->crc[3], entry->crc[4]);
2500
2501 ret = copy_to_user(user_buf + n * PIPE_CRC_LINE_LEN,
2502 buf, PIPE_CRC_LINE_LEN);
2503 if (ret == PIPE_CRC_LINE_LEN)
2504 return -EFAULT;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01002505
2506 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
2507 tail = (tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiau07144422013-10-15 18:55:40 +01002508 n++;
2509 } while (--n_entries);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002510
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002511 spin_lock_irq(&pipe_crc->lock);
2512 pipe_crc->tail = tail;
2513 spin_unlock_irq(&pipe_crc->lock);
2514
Damien Lespiau07144422013-10-15 18:55:40 +01002515 return bytes_read;
2516}
2517
2518static const struct file_operations i915_pipe_crc_fops = {
2519 .owner = THIS_MODULE,
2520 .open = i915_pipe_crc_open,
2521 .read = i915_pipe_crc_read,
2522 .release = i915_pipe_crc_release,
2523};
2524
2525static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
2526 {
2527 .name = "i915_pipe_A_crc",
2528 .pipe = PIPE_A,
2529 },
2530 {
2531 .name = "i915_pipe_B_crc",
2532 .pipe = PIPE_B,
2533 },
2534 {
2535 .name = "i915_pipe_C_crc",
2536 .pipe = PIPE_C,
2537 },
2538};
2539
2540static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
2541 enum pipe pipe)
2542{
2543 struct drm_device *dev = minor->dev;
2544 struct dentry *ent;
2545 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
2546
2547 info->dev = dev;
2548 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
2549 &i915_pipe_crc_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08002550 if (!ent)
2551 return -ENOMEM;
Damien Lespiau07144422013-10-15 18:55:40 +01002552
2553 return drm_add_fake_info_node(minor, ent, info);
Shuang He8bf1e9f2013-10-15 18:55:27 +01002554}
2555
Daniel Vettere8dfcf72013-10-16 11:51:54 +02002556static const char * const pipe_crc_sources[] = {
Daniel Vetter926321d2013-10-16 13:30:34 +02002557 "none",
2558 "plane1",
2559 "plane2",
2560 "pf",
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002561 "pipe",
Daniel Vetter3d099a02013-10-16 22:55:58 +02002562 "TV",
2563 "DP-B",
2564 "DP-C",
2565 "DP-D",
Daniel Vetter46a19182013-11-01 10:50:20 +01002566 "auto",
Daniel Vetter926321d2013-10-16 13:30:34 +02002567};
2568
2569static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
2570{
2571 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
2572 return pipe_crc_sources[source];
2573}
2574
Damien Lespiaubd9db022013-10-15 18:55:36 +01002575static int display_crc_ctl_show(struct seq_file *m, void *data)
Daniel Vetter926321d2013-10-16 13:30:34 +02002576{
2577 struct drm_device *dev = m->private;
2578 struct drm_i915_private *dev_priv = dev->dev_private;
2579 int i;
2580
2581 for (i = 0; i < I915_MAX_PIPES; i++)
2582 seq_printf(m, "%c %s\n", pipe_name(i),
2583 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
2584
2585 return 0;
2586}
2587
Damien Lespiaubd9db022013-10-15 18:55:36 +01002588static int display_crc_ctl_open(struct inode *inode, struct file *file)
Daniel Vetter926321d2013-10-16 13:30:34 +02002589{
2590 struct drm_device *dev = inode->i_private;
2591
Damien Lespiaubd9db022013-10-15 18:55:36 +01002592 return single_open(file, display_crc_ctl_show, dev);
Daniel Vetter926321d2013-10-16 13:30:34 +02002593}
2594
Daniel Vetter46a19182013-11-01 10:50:20 +01002595static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter52f843f2013-10-21 17:26:38 +02002596 uint32_t *val)
2597{
Daniel Vetter46a19182013-11-01 10:50:20 +01002598 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2599 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2600
2601 switch (*source) {
Daniel Vetter52f843f2013-10-21 17:26:38 +02002602 case INTEL_PIPE_CRC_SOURCE_PIPE:
2603 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
2604 break;
2605 case INTEL_PIPE_CRC_SOURCE_NONE:
2606 *val = 0;
2607 break;
2608 default:
2609 return -EINVAL;
2610 }
2611
2612 return 0;
2613}
2614
Daniel Vetter46a19182013-11-01 10:50:20 +01002615static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
2616 enum intel_pipe_crc_source *source)
2617{
2618 struct intel_encoder *encoder;
2619 struct intel_crtc *crtc;
Daniel Vetter26756802013-11-01 10:50:23 +01002620 struct intel_digital_port *dig_port;
Daniel Vetter46a19182013-11-01 10:50:20 +01002621 int ret = 0;
2622
2623 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2624
Daniel Vetter6e9f7982014-05-29 23:54:47 +02002625 drm_modeset_lock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01002626 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
2627 base.head) {
2628 if (!encoder->base.crtc)
2629 continue;
2630
2631 crtc = to_intel_crtc(encoder->base.crtc);
2632
2633 if (crtc->pipe != pipe)
2634 continue;
2635
2636 switch (encoder->type) {
2637 case INTEL_OUTPUT_TVOUT:
2638 *source = INTEL_PIPE_CRC_SOURCE_TV;
2639 break;
2640 case INTEL_OUTPUT_DISPLAYPORT:
2641 case INTEL_OUTPUT_EDP:
Daniel Vetter26756802013-11-01 10:50:23 +01002642 dig_port = enc_to_dig_port(&encoder->base);
2643 switch (dig_port->port) {
2644 case PORT_B:
2645 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
2646 break;
2647 case PORT_C:
2648 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
2649 break;
2650 case PORT_D:
2651 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
2652 break;
2653 default:
2654 WARN(1, "nonexisting DP port %c\n",
2655 port_name(dig_port->port));
2656 break;
2657 }
Daniel Vetter46a19182013-11-01 10:50:20 +01002658 break;
2659 }
2660 }
Daniel Vetter6e9f7982014-05-29 23:54:47 +02002661 drm_modeset_unlock_all(dev);
Daniel Vetter46a19182013-11-01 10:50:20 +01002662
2663 return ret;
2664}
2665
2666static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
2667 enum pipe pipe,
2668 enum intel_pipe_crc_source *source,
Daniel Vetter7ac01292013-10-18 16:37:06 +02002669 uint32_t *val)
2670{
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002671 struct drm_i915_private *dev_priv = dev->dev_private;
2672 bool need_stable_symbols = false;
2673
Daniel Vetter46a19182013-11-01 10:50:20 +01002674 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2675 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2676 if (ret)
2677 return ret;
2678 }
2679
2680 switch (*source) {
Daniel Vetter7ac01292013-10-18 16:37:06 +02002681 case INTEL_PIPE_CRC_SOURCE_PIPE:
2682 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
2683 break;
2684 case INTEL_PIPE_CRC_SOURCE_DP_B:
2685 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002686 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002687 break;
2688 case INTEL_PIPE_CRC_SOURCE_DP_C:
2689 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002690 need_stable_symbols = true;
Daniel Vetter7ac01292013-10-18 16:37:06 +02002691 break;
2692 case INTEL_PIPE_CRC_SOURCE_NONE:
2693 *val = 0;
2694 break;
2695 default:
2696 return -EINVAL;
2697 }
2698
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002699 /*
2700 * When the pipe CRC tap point is after the transcoders we need
2701 * to tweak symbol-level features to produce a deterministic series of
2702 * symbols for a given frame. We need to reset those features only once
2703 * a frame (instead of every nth symbol):
2704 * - DC-balance: used to ensure a better clock recovery from the data
2705 * link (SDVO)
2706 * - DisplayPort scrambling: used for EMI reduction
2707 */
2708 if (need_stable_symbols) {
2709 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2710
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002711 tmp |= DC_BALANCE_RESET_VLV;
2712 if (pipe == PIPE_A)
2713 tmp |= PIPE_A_SCRAMBLE_RESET;
2714 else
2715 tmp |= PIPE_B_SCRAMBLE_RESET;
2716
2717 I915_WRITE(PORT_DFT2_G4X, tmp);
2718 }
2719
Daniel Vetter7ac01292013-10-18 16:37:06 +02002720 return 0;
2721}
2722
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002723static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
Daniel Vetter46a19182013-11-01 10:50:20 +01002724 enum pipe pipe,
2725 enum intel_pipe_crc_source *source,
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002726 uint32_t *val)
2727{
Daniel Vetter84093602013-11-01 10:50:21 +01002728 struct drm_i915_private *dev_priv = dev->dev_private;
2729 bool need_stable_symbols = false;
2730
Daniel Vetter46a19182013-11-01 10:50:20 +01002731 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
2732 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
2733 if (ret)
2734 return ret;
2735 }
2736
2737 switch (*source) {
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002738 case INTEL_PIPE_CRC_SOURCE_PIPE:
2739 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
2740 break;
2741 case INTEL_PIPE_CRC_SOURCE_TV:
2742 if (!SUPPORTS_TV(dev))
2743 return -EINVAL;
2744 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
2745 break;
2746 case INTEL_PIPE_CRC_SOURCE_DP_B:
2747 if (!IS_G4X(dev))
2748 return -EINVAL;
2749 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002750 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002751 break;
2752 case INTEL_PIPE_CRC_SOURCE_DP_C:
2753 if (!IS_G4X(dev))
2754 return -EINVAL;
2755 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002756 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002757 break;
2758 case INTEL_PIPE_CRC_SOURCE_DP_D:
2759 if (!IS_G4X(dev))
2760 return -EINVAL;
2761 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
Daniel Vetter84093602013-11-01 10:50:21 +01002762 need_stable_symbols = true;
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002763 break;
2764 case INTEL_PIPE_CRC_SOURCE_NONE:
2765 *val = 0;
2766 break;
2767 default:
2768 return -EINVAL;
2769 }
2770
Daniel Vetter84093602013-11-01 10:50:21 +01002771 /*
2772 * When the pipe CRC tap point is after the transcoders we need
2773 * to tweak symbol-level features to produce a deterministic series of
2774 * symbols for a given frame. We need to reset those features only once
2775 * a frame (instead of every nth symbol):
2776 * - DC-balance: used to ensure a better clock recovery from the data
2777 * link (SDVO)
2778 * - DisplayPort scrambling: used for EMI reduction
2779 */
2780 if (need_stable_symbols) {
2781 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2782
2783 WARN_ON(!IS_G4X(dev));
2784
2785 I915_WRITE(PORT_DFT_I9XX,
2786 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
2787
2788 if (pipe == PIPE_A)
2789 tmp |= PIPE_A_SCRAMBLE_RESET;
2790 else
2791 tmp |= PIPE_B_SCRAMBLE_RESET;
2792
2793 I915_WRITE(PORT_DFT2_G4X, tmp);
2794 }
2795
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002796 return 0;
2797}
2798
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002799static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
2800 enum pipe pipe)
2801{
2802 struct drm_i915_private *dev_priv = dev->dev_private;
2803 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2804
2805 if (pipe == PIPE_A)
2806 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2807 else
2808 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2809 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
2810 tmp &= ~DC_BALANCE_RESET_VLV;
2811 I915_WRITE(PORT_DFT2_G4X, tmp);
2812
2813}
2814
Daniel Vetter84093602013-11-01 10:50:21 +01002815static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
2816 enum pipe pipe)
2817{
2818 struct drm_i915_private *dev_priv = dev->dev_private;
2819 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
2820
2821 if (pipe == PIPE_A)
2822 tmp &= ~PIPE_A_SCRAMBLE_RESET;
2823 else
2824 tmp &= ~PIPE_B_SCRAMBLE_RESET;
2825 I915_WRITE(PORT_DFT2_G4X, tmp);
2826
2827 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
2828 I915_WRITE(PORT_DFT_I9XX,
2829 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
2830 }
2831}
2832
Daniel Vetter46a19182013-11-01 10:50:20 +01002833static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002834 uint32_t *val)
2835{
Daniel Vetter46a19182013-11-01 10:50:20 +01002836 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2837 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
2838
2839 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002840 case INTEL_PIPE_CRC_SOURCE_PLANE1:
2841 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
2842 break;
2843 case INTEL_PIPE_CRC_SOURCE_PLANE2:
2844 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
2845 break;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002846 case INTEL_PIPE_CRC_SOURCE_PIPE:
2847 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
2848 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002849 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002850 *val = 0;
2851 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002852 default:
2853 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002854 }
2855
2856 return 0;
2857}
2858
Daniel Vetter46a19182013-11-01 10:50:20 +01002859static int ivb_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002860 uint32_t *val)
2861{
Daniel Vetter46a19182013-11-01 10:50:20 +01002862 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
2863 *source = INTEL_PIPE_CRC_SOURCE_PF;
2864
2865 switch (*source) {
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002866 case INTEL_PIPE_CRC_SOURCE_PLANE1:
2867 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
2868 break;
2869 case INTEL_PIPE_CRC_SOURCE_PLANE2:
2870 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
2871 break;
2872 case INTEL_PIPE_CRC_SOURCE_PF:
2873 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
2874 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002875 case INTEL_PIPE_CRC_SOURCE_NONE:
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002876 *val = 0;
2877 break;
Daniel Vetter3d099a02013-10-16 22:55:58 +02002878 default:
2879 return -EINVAL;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002880 }
2881
2882 return 0;
2883}
2884
Daniel Vetter926321d2013-10-16 13:30:34 +02002885static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
2886 enum intel_pipe_crc_source source)
2887{
2888 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiaucc3da172013-10-15 18:55:31 +01002889 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Borislav Petkov432f3342013-11-21 16:49:46 +01002890 u32 val = 0; /* shut up gcc */
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002891 int ret;
Daniel Vetter926321d2013-10-16 13:30:34 +02002892
Damien Lespiaucc3da172013-10-15 18:55:31 +01002893 if (pipe_crc->source == source)
2894 return 0;
2895
Damien Lespiauae676fc2013-10-15 18:55:32 +01002896 /* forbid changing the source without going back to 'none' */
2897 if (pipe_crc->source && source)
2898 return -EINVAL;
2899
Daniel Vetter52f843f2013-10-21 17:26:38 +02002900 if (IS_GEN2(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002901 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter52f843f2013-10-21 17:26:38 +02002902 else if (INTEL_INFO(dev)->gen < 5)
Daniel Vetter46a19182013-11-01 10:50:20 +01002903 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
Daniel Vetter7ac01292013-10-18 16:37:06 +02002904 else if (IS_VALLEYVIEW(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002905 ret = vlv_pipe_crc_ctl_reg(dev,pipe, &source, &val);
Daniel Vetter4b79ebf2013-10-16 22:55:59 +02002906 else if (IS_GEN5(dev) || IS_GEN6(dev))
Daniel Vetter46a19182013-11-01 10:50:20 +01002907 ret = ilk_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002908 else
Daniel Vetter46a19182013-11-01 10:50:20 +01002909 ret = ivb_pipe_crc_ctl_reg(&source, &val);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002910
2911 if (ret != 0)
2912 return ret;
2913
Damien Lespiau4b584362013-10-15 18:55:33 +01002914 /* none -> real source transition */
2915 if (source) {
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01002916 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
2917 pipe_name(pipe), pipe_crc_source_name(source));
2918
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002919 pipe_crc->entries = kzalloc(sizeof(*pipe_crc->entries) *
2920 INTEL_PIPE_CRC_ENTRIES_NR,
2921 GFP_KERNEL);
2922 if (!pipe_crc->entries)
2923 return -ENOMEM;
2924
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002925 spin_lock_irq(&pipe_crc->lock);
2926 pipe_crc->head = 0;
2927 pipe_crc->tail = 0;
2928 spin_unlock_irq(&pipe_crc->lock);
Damien Lespiau4b584362013-10-15 18:55:33 +01002929 }
2930
Damien Lespiaucc3da172013-10-15 18:55:31 +01002931 pipe_crc->source = source;
Daniel Vetter926321d2013-10-16 13:30:34 +02002932
Daniel Vetter926321d2013-10-16 13:30:34 +02002933 I915_WRITE(PIPE_CRC_CTL(pipe), val);
2934 POSTING_READ(PIPE_CRC_CTL(pipe));
2935
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002936 /* real source -> none transition */
2937 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002938 struct intel_pipe_crc_entry *entries;
Daniel Vettera33d7102014-06-06 08:22:08 +02002939 struct intel_crtc *crtc =
2940 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002941
Damien Lespiau7cd6ccf2013-10-15 18:55:38 +01002942 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
2943 pipe_name(pipe));
2944
Daniel Vettera33d7102014-06-06 08:22:08 +02002945 drm_modeset_lock(&crtc->base.mutex, NULL);
2946 if (crtc->active)
2947 intel_wait_for_vblank(dev, pipe);
2948 drm_modeset_unlock(&crtc->base.mutex);
Daniel Vetterbcf17ab2013-10-16 22:55:50 +02002949
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002950 spin_lock_irq(&pipe_crc->lock);
2951 entries = pipe_crc->entries;
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002952 pipe_crc->entries = NULL;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01002953 spin_unlock_irq(&pipe_crc->lock);
2954
2955 kfree(entries);
Daniel Vetter84093602013-11-01 10:50:21 +01002956
2957 if (IS_G4X(dev))
2958 g4x_undo_pipe_scramble_reset(dev, pipe);
Daniel Vetter8d2f24c2013-11-01 10:50:22 +01002959 else if (IS_VALLEYVIEW(dev))
2960 vlv_undo_pipe_scramble_reset(dev, pipe);
Damien Lespiaue5f75ac2013-10-15 18:55:34 +01002961 }
2962
Daniel Vetter926321d2013-10-16 13:30:34 +02002963 return 0;
2964}
2965
2966/*
2967 * Parse pipe CRC command strings:
Damien Lespiaub94dec82013-10-15 18:55:35 +01002968 * command: wsp* object wsp+ name wsp+ source wsp*
2969 * object: 'pipe'
2970 * name: (A | B | C)
Daniel Vetter926321d2013-10-16 13:30:34 +02002971 * source: (none | plane1 | plane2 | pf)
2972 * wsp: (#0x20 | #0x9 | #0xA)+
2973 *
2974 * eg.:
Damien Lespiaub94dec82013-10-15 18:55:35 +01002975 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
2976 * "pipe A none" -> Stop CRC
Daniel Vetter926321d2013-10-16 13:30:34 +02002977 */
Damien Lespiaubd9db022013-10-15 18:55:36 +01002978static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
Daniel Vetter926321d2013-10-16 13:30:34 +02002979{
2980 int n_words = 0;
2981
2982 while (*buf) {
2983 char *end;
2984
2985 /* skip leading white space */
2986 buf = skip_spaces(buf);
2987 if (!*buf)
2988 break; /* end of buffer */
2989
2990 /* find end of word */
2991 for (end = buf; *end && !isspace(*end); end++)
2992 ;
2993
2994 if (n_words == max_words) {
2995 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
2996 max_words);
2997 return -EINVAL; /* ran out of words[] before bytes */
2998 }
2999
3000 if (*end)
3001 *end++ = '\0';
3002 words[n_words++] = buf;
3003 buf = end;
3004 }
3005
3006 return n_words;
3007}
3008
Damien Lespiaub94dec82013-10-15 18:55:35 +01003009enum intel_pipe_crc_object {
3010 PIPE_CRC_OBJECT_PIPE,
3011};
3012
Daniel Vettere8dfcf72013-10-16 11:51:54 +02003013static const char * const pipe_crc_objects[] = {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003014 "pipe",
3015};
3016
3017static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003018display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
Damien Lespiaub94dec82013-10-15 18:55:35 +01003019{
3020 int i;
3021
3022 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3023 if (!strcmp(buf, pipe_crc_objects[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003024 *o = i;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003025 return 0;
3026 }
3027
3028 return -EINVAL;
3029}
3030
Damien Lespiaubd9db022013-10-15 18:55:36 +01003031static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
Daniel Vetter926321d2013-10-16 13:30:34 +02003032{
3033 const char name = buf[0];
3034
3035 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3036 return -EINVAL;
3037
3038 *pipe = name - 'A';
3039
3040 return 0;
3041}
3042
3043static int
Damien Lespiaubd9db022013-10-15 18:55:36 +01003044display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
Daniel Vetter926321d2013-10-16 13:30:34 +02003045{
3046 int i;
3047
3048 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3049 if (!strcmp(buf, pipe_crc_sources[i])) {
Damien Lespiaubd9db022013-10-15 18:55:36 +01003050 *s = i;
Daniel Vetter926321d2013-10-16 13:30:34 +02003051 return 0;
3052 }
3053
3054 return -EINVAL;
3055}
3056
Damien Lespiaubd9db022013-10-15 18:55:36 +01003057static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
Daniel Vetter926321d2013-10-16 13:30:34 +02003058{
Damien Lespiaub94dec82013-10-15 18:55:35 +01003059#define N_WORDS 3
Daniel Vetter926321d2013-10-16 13:30:34 +02003060 int n_words;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003061 char *words[N_WORDS];
Daniel Vetter926321d2013-10-16 13:30:34 +02003062 enum pipe pipe;
Damien Lespiaub94dec82013-10-15 18:55:35 +01003063 enum intel_pipe_crc_object object;
Daniel Vetter926321d2013-10-16 13:30:34 +02003064 enum intel_pipe_crc_source source;
3065
Damien Lespiaubd9db022013-10-15 18:55:36 +01003066 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
Damien Lespiaub94dec82013-10-15 18:55:35 +01003067 if (n_words != N_WORDS) {
3068 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3069 N_WORDS);
Daniel Vetter926321d2013-10-16 13:30:34 +02003070 return -EINVAL;
3071 }
3072
Damien Lespiaubd9db022013-10-15 18:55:36 +01003073 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003074 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003075 return -EINVAL;
3076 }
3077
Damien Lespiaubd9db022013-10-15 18:55:36 +01003078 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003079 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
3080 return -EINVAL;
3081 }
3082
Damien Lespiaubd9db022013-10-15 18:55:36 +01003083 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
Damien Lespiaub94dec82013-10-15 18:55:35 +01003084 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
Daniel Vetter926321d2013-10-16 13:30:34 +02003085 return -EINVAL;
3086 }
3087
3088 return pipe_crc_set_source(dev, pipe, source);
3089}
3090
Damien Lespiaubd9db022013-10-15 18:55:36 +01003091static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3092 size_t len, loff_t *offp)
Daniel Vetter926321d2013-10-16 13:30:34 +02003093{
3094 struct seq_file *m = file->private_data;
3095 struct drm_device *dev = m->private;
3096 char *tmpbuf;
3097 int ret;
3098
3099 if (len == 0)
3100 return 0;
3101
3102 if (len > PAGE_SIZE - 1) {
3103 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3104 PAGE_SIZE);
3105 return -E2BIG;
3106 }
3107
3108 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3109 if (!tmpbuf)
3110 return -ENOMEM;
3111
3112 if (copy_from_user(tmpbuf, ubuf, len)) {
3113 ret = -EFAULT;
3114 goto out;
3115 }
3116 tmpbuf[len] = '\0';
3117
Damien Lespiaubd9db022013-10-15 18:55:36 +01003118 ret = display_crc_ctl_parse(dev, tmpbuf, len);
Daniel Vetter926321d2013-10-16 13:30:34 +02003119
3120out:
3121 kfree(tmpbuf);
3122 if (ret < 0)
3123 return ret;
3124
3125 *offp += len;
3126 return len;
3127}
3128
Damien Lespiaubd9db022013-10-15 18:55:36 +01003129static const struct file_operations i915_display_crc_ctl_fops = {
Daniel Vetter926321d2013-10-16 13:30:34 +02003130 .owner = THIS_MODULE,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003131 .open = display_crc_ctl_open,
Daniel Vetter926321d2013-10-16 13:30:34 +02003132 .read = seq_read,
3133 .llseek = seq_lseek,
3134 .release = single_release,
Damien Lespiaubd9db022013-10-15 18:55:36 +01003135 .write = display_crc_ctl_write
Daniel Vetter926321d2013-10-16 13:30:34 +02003136};
3137
Ville Syrjälä369a1342014-01-22 14:36:08 +02003138static void wm_latency_show(struct seq_file *m, const uint16_t wm[5])
3139{
3140 struct drm_device *dev = m->private;
Damien Lespiau546c81f2014-05-13 15:30:26 +01003141 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003142 int level;
3143
3144 drm_modeset_lock_all(dev);
3145
3146 for (level = 0; level < num_levels; level++) {
3147 unsigned int latency = wm[level];
3148
3149 /* WM1+ latency values in 0.5us units */
3150 if (level > 0)
3151 latency *= 5;
3152
3153 seq_printf(m, "WM%d %u (%u.%u usec)\n",
3154 level, wm[level],
3155 latency / 10, latency % 10);
3156 }
3157
3158 drm_modeset_unlock_all(dev);
3159}
3160
3161static int pri_wm_latency_show(struct seq_file *m, void *data)
3162{
3163 struct drm_device *dev = m->private;
3164
3165 wm_latency_show(m, to_i915(dev)->wm.pri_latency);
3166
3167 return 0;
3168}
3169
3170static int spr_wm_latency_show(struct seq_file *m, void *data)
3171{
3172 struct drm_device *dev = m->private;
3173
3174 wm_latency_show(m, to_i915(dev)->wm.spr_latency);
3175
3176 return 0;
3177}
3178
3179static int cur_wm_latency_show(struct seq_file *m, void *data)
3180{
3181 struct drm_device *dev = m->private;
3182
3183 wm_latency_show(m, to_i915(dev)->wm.cur_latency);
3184
3185 return 0;
3186}
3187
3188static int pri_wm_latency_open(struct inode *inode, struct file *file)
3189{
3190 struct drm_device *dev = inode->i_private;
3191
3192 if (!HAS_PCH_SPLIT(dev))
3193 return -ENODEV;
3194
3195 return single_open(file, pri_wm_latency_show, dev);
3196}
3197
3198static int spr_wm_latency_open(struct inode *inode, struct file *file)
3199{
3200 struct drm_device *dev = inode->i_private;
3201
3202 if (!HAS_PCH_SPLIT(dev))
3203 return -ENODEV;
3204
3205 return single_open(file, spr_wm_latency_show, dev);
3206}
3207
3208static int cur_wm_latency_open(struct inode *inode, struct file *file)
3209{
3210 struct drm_device *dev = inode->i_private;
3211
3212 if (!HAS_PCH_SPLIT(dev))
3213 return -ENODEV;
3214
3215 return single_open(file, cur_wm_latency_show, dev);
3216}
3217
3218static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
3219 size_t len, loff_t *offp, uint16_t wm[5])
3220{
3221 struct seq_file *m = file->private_data;
3222 struct drm_device *dev = m->private;
3223 uint16_t new[5] = { 0 };
Damien Lespiau546c81f2014-05-13 15:30:26 +01003224 int num_levels = ilk_wm_max_level(dev) + 1;
Ville Syrjälä369a1342014-01-22 14:36:08 +02003225 int level;
3226 int ret;
3227 char tmp[32];
3228
3229 if (len >= sizeof(tmp))
3230 return -EINVAL;
3231
3232 if (copy_from_user(tmp, ubuf, len))
3233 return -EFAULT;
3234
3235 tmp[len] = '\0';
3236
3237 ret = sscanf(tmp, "%hu %hu %hu %hu %hu", &new[0], &new[1], &new[2], &new[3], &new[4]);
3238 if (ret != num_levels)
3239 return -EINVAL;
3240
3241 drm_modeset_lock_all(dev);
3242
3243 for (level = 0; level < num_levels; level++)
3244 wm[level] = new[level];
3245
3246 drm_modeset_unlock_all(dev);
3247
3248 return len;
3249}
3250
3251
3252static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
3253 size_t len, loff_t *offp)
3254{
3255 struct seq_file *m = file->private_data;
3256 struct drm_device *dev = m->private;
3257
3258 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.pri_latency);
3259}
3260
3261static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
3262 size_t len, loff_t *offp)
3263{
3264 struct seq_file *m = file->private_data;
3265 struct drm_device *dev = m->private;
3266
3267 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.spr_latency);
3268}
3269
3270static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
3271 size_t len, loff_t *offp)
3272{
3273 struct seq_file *m = file->private_data;
3274 struct drm_device *dev = m->private;
3275
3276 return wm_latency_write(file, ubuf, len, offp, to_i915(dev)->wm.cur_latency);
3277}
3278
3279static const struct file_operations i915_pri_wm_latency_fops = {
3280 .owner = THIS_MODULE,
3281 .open = pri_wm_latency_open,
3282 .read = seq_read,
3283 .llseek = seq_lseek,
3284 .release = single_release,
3285 .write = pri_wm_latency_write
3286};
3287
3288static const struct file_operations i915_spr_wm_latency_fops = {
3289 .owner = THIS_MODULE,
3290 .open = spr_wm_latency_open,
3291 .read = seq_read,
3292 .llseek = seq_lseek,
3293 .release = single_release,
3294 .write = spr_wm_latency_write
3295};
3296
3297static const struct file_operations i915_cur_wm_latency_fops = {
3298 .owner = THIS_MODULE,
3299 .open = cur_wm_latency_open,
3300 .read = seq_read,
3301 .llseek = seq_lseek,
3302 .release = single_release,
3303 .write = cur_wm_latency_write
3304};
3305
Kees Cook647416f2013-03-10 14:10:06 -07003306static int
3307i915_wedged_get(void *data, u64 *val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003308{
Kees Cook647416f2013-03-10 14:10:06 -07003309 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003310 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003311
Kees Cook647416f2013-03-10 14:10:06 -07003312 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003313
Kees Cook647416f2013-03-10 14:10:06 -07003314 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003315}
3316
Kees Cook647416f2013-03-10 14:10:06 -07003317static int
3318i915_wedged_set(void *data, u64 val)
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003319{
Kees Cook647416f2013-03-10 14:10:06 -07003320 struct drm_device *dev = data;
Imre Deakd46c0512014-04-14 20:24:27 +03003321 struct drm_i915_private *dev_priv = dev->dev_private;
3322
3323 intel_runtime_pm_get(dev_priv);
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003324
Mika Kuoppala58174462014-02-25 17:11:26 +02003325 i915_handle_error(dev, val,
3326 "Manually setting wedged to %llu", val);
Imre Deakd46c0512014-04-14 20:24:27 +03003327
3328 intel_runtime_pm_put(dev_priv);
3329
Kees Cook647416f2013-03-10 14:10:06 -07003330 return 0;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003331}
3332
Kees Cook647416f2013-03-10 14:10:06 -07003333DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
3334 i915_wedged_get, i915_wedged_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003335 "%llu\n");
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003336
Kees Cook647416f2013-03-10 14:10:06 -07003337static int
3338i915_ring_stop_get(void *data, u64 *val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003339{
Kees Cook647416f2013-03-10 14:10:06 -07003340 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003341 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003342
Kees Cook647416f2013-03-10 14:10:06 -07003343 *val = dev_priv->gpu_error.stop_rings;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003344
Kees Cook647416f2013-03-10 14:10:06 -07003345 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003346}
3347
Kees Cook647416f2013-03-10 14:10:06 -07003348static int
3349i915_ring_stop_set(void *data, u64 val)
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003350{
Kees Cook647416f2013-03-10 14:10:06 -07003351 struct drm_device *dev = data;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003352 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003353 int ret;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003354
Kees Cook647416f2013-03-10 14:10:06 -07003355 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003356
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003357 ret = mutex_lock_interruptible(&dev->struct_mutex);
3358 if (ret)
3359 return ret;
3360
Daniel Vetter99584db2012-11-14 17:14:04 +01003361 dev_priv->gpu_error.stop_rings = val;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003362 mutex_unlock(&dev->struct_mutex);
3363
Kees Cook647416f2013-03-10 14:10:06 -07003364 return 0;
Daniel Vettere5eb3d62012-05-03 14:48:16 +02003365}
3366
Kees Cook647416f2013-03-10 14:10:06 -07003367DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
3368 i915_ring_stop_get, i915_ring_stop_set,
3369 "0x%08llx\n");
Daniel Vetterd5442302012-04-27 15:17:40 +02003370
Chris Wilson094f9a52013-09-25 17:34:55 +01003371static int
3372i915_ring_missed_irq_get(void *data, u64 *val)
3373{
3374 struct drm_device *dev = data;
3375 struct drm_i915_private *dev_priv = dev->dev_private;
3376
3377 *val = dev_priv->gpu_error.missed_irq_rings;
3378 return 0;
3379}
3380
3381static int
3382i915_ring_missed_irq_set(void *data, u64 val)
3383{
3384 struct drm_device *dev = data;
3385 struct drm_i915_private *dev_priv = dev->dev_private;
3386 int ret;
3387
3388 /* Lock against concurrent debugfs callers */
3389 ret = mutex_lock_interruptible(&dev->struct_mutex);
3390 if (ret)
3391 return ret;
3392 dev_priv->gpu_error.missed_irq_rings = val;
3393 mutex_unlock(&dev->struct_mutex);
3394
3395 return 0;
3396}
3397
3398DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
3399 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
3400 "0x%08llx\n");
3401
3402static int
3403i915_ring_test_irq_get(void *data, u64 *val)
3404{
3405 struct drm_device *dev = data;
3406 struct drm_i915_private *dev_priv = dev->dev_private;
3407
3408 *val = dev_priv->gpu_error.test_irq_rings;
3409
3410 return 0;
3411}
3412
3413static int
3414i915_ring_test_irq_set(void *data, u64 val)
3415{
3416 struct drm_device *dev = data;
3417 struct drm_i915_private *dev_priv = dev->dev_private;
3418 int ret;
3419
3420 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
3421
3422 /* Lock against concurrent debugfs callers */
3423 ret = mutex_lock_interruptible(&dev->struct_mutex);
3424 if (ret)
3425 return ret;
3426
3427 dev_priv->gpu_error.test_irq_rings = val;
3428 mutex_unlock(&dev->struct_mutex);
3429
3430 return 0;
3431}
3432
3433DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
3434 i915_ring_test_irq_get, i915_ring_test_irq_set,
3435 "0x%08llx\n");
3436
Chris Wilsondd624af2013-01-15 12:39:35 +00003437#define DROP_UNBOUND 0x1
3438#define DROP_BOUND 0x2
3439#define DROP_RETIRE 0x4
3440#define DROP_ACTIVE 0x8
3441#define DROP_ALL (DROP_UNBOUND | \
3442 DROP_BOUND | \
3443 DROP_RETIRE | \
3444 DROP_ACTIVE)
Kees Cook647416f2013-03-10 14:10:06 -07003445static int
3446i915_drop_caches_get(void *data, u64 *val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003447{
Kees Cook647416f2013-03-10 14:10:06 -07003448 *val = DROP_ALL;
Chris Wilsondd624af2013-01-15 12:39:35 +00003449
Kees Cook647416f2013-03-10 14:10:06 -07003450 return 0;
Chris Wilsondd624af2013-01-15 12:39:35 +00003451}
3452
Kees Cook647416f2013-03-10 14:10:06 -07003453static int
3454i915_drop_caches_set(void *data, u64 val)
Chris Wilsondd624af2013-01-15 12:39:35 +00003455{
Kees Cook647416f2013-03-10 14:10:06 -07003456 struct drm_device *dev = data;
Chris Wilsondd624af2013-01-15 12:39:35 +00003457 struct drm_i915_private *dev_priv = dev->dev_private;
3458 struct drm_i915_gem_object *obj, *next;
Ben Widawskyca191b12013-07-31 17:00:14 -07003459 struct i915_address_space *vm;
3460 struct i915_vma *vma, *x;
Kees Cook647416f2013-03-10 14:10:06 -07003461 int ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003462
Ben Widawsky2f9fe5f2013-11-25 09:54:37 -08003463 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
Chris Wilsondd624af2013-01-15 12:39:35 +00003464
3465 /* No need to check and wait for gpu resets, only libdrm auto-restarts
3466 * on ioctls on -EAGAIN. */
3467 ret = mutex_lock_interruptible(&dev->struct_mutex);
3468 if (ret)
3469 return ret;
3470
3471 if (val & DROP_ACTIVE) {
3472 ret = i915_gpu_idle(dev);
3473 if (ret)
3474 goto unlock;
3475 }
3476
3477 if (val & (DROP_RETIRE | DROP_ACTIVE))
3478 i915_gem_retire_requests(dev);
3479
3480 if (val & DROP_BOUND) {
Ben Widawskyca191b12013-07-31 17:00:14 -07003481 list_for_each_entry(vm, &dev_priv->vm_list, global_link) {
3482 list_for_each_entry_safe(vma, x, &vm->inactive_list,
3483 mm_list) {
Ben Widawskyd7f46fc2013-12-06 14:10:55 -08003484 if (vma->pin_count)
Ben Widawskyca191b12013-07-31 17:00:14 -07003485 continue;
Ben Widawsky31a46c92013-07-31 16:59:55 -07003486
Ben Widawskyca191b12013-07-31 17:00:14 -07003487 ret = i915_vma_unbind(vma);
3488 if (ret)
3489 goto unlock;
3490 }
Ben Widawsky31a46c92013-07-31 16:59:55 -07003491 }
Chris Wilsondd624af2013-01-15 12:39:35 +00003492 }
3493
3494 if (val & DROP_UNBOUND) {
Ben Widawsky35c20a62013-05-31 11:28:48 -07003495 list_for_each_entry_safe(obj, next, &dev_priv->mm.unbound_list,
3496 global_list)
Chris Wilsondd624af2013-01-15 12:39:35 +00003497 if (obj->pages_pin_count == 0) {
3498 ret = i915_gem_object_put_pages(obj);
3499 if (ret)
3500 goto unlock;
3501 }
3502 }
3503
3504unlock:
3505 mutex_unlock(&dev->struct_mutex);
3506
Kees Cook647416f2013-03-10 14:10:06 -07003507 return ret;
Chris Wilsondd624af2013-01-15 12:39:35 +00003508}
3509
Kees Cook647416f2013-03-10 14:10:06 -07003510DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
3511 i915_drop_caches_get, i915_drop_caches_set,
3512 "0x%08llx\n");
Chris Wilsondd624af2013-01-15 12:39:35 +00003513
Kees Cook647416f2013-03-10 14:10:06 -07003514static int
3515i915_max_freq_get(void *data, u64 *val)
Jesse Barnes358733e2011-07-27 11:53:01 -07003516{
Kees Cook647416f2013-03-10 14:10:06 -07003517 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003518 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003519 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003520
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003521 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003522 return -ENODEV;
3523
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003524 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3525
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003526 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003527 if (ret)
3528 return ret;
Jesse Barnes358733e2011-07-27 11:53:01 -07003529
Jesse Barnes0a073b82013-04-17 15:54:58 -07003530 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07003531 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003532 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07003533 *val = dev_priv->rps.max_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003534 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07003535
Kees Cook647416f2013-03-10 14:10:06 -07003536 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07003537}
3538
Kees Cook647416f2013-03-10 14:10:06 -07003539static int
3540i915_max_freq_set(void *data, u64 val)
Jesse Barnes358733e2011-07-27 11:53:01 -07003541{
Kees Cook647416f2013-03-10 14:10:06 -07003542 struct drm_device *dev = data;
Jesse Barnes358733e2011-07-27 11:53:01 -07003543 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003544 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07003545 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003546
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003547 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003548 return -ENODEV;
Jesse Barnes358733e2011-07-27 11:53:01 -07003549
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003550 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3551
Kees Cook647416f2013-03-10 14:10:06 -07003552 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
Jesse Barnes358733e2011-07-27 11:53:01 -07003553
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003554 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003555 if (ret)
3556 return ret;
3557
Jesse Barnes358733e2011-07-27 11:53:01 -07003558 /*
3559 * Turbo will still be enabled, but won't go above the set value.
3560 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07003561 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02003562 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003563
3564 hw_max = valleyview_rps_max_freq(dev_priv);
3565 hw_min = valleyview_rps_min_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003566 } else {
3567 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003568
3569 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07003570 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003571 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003572 }
3573
Ben Widawskyb39fb292014-03-19 18:31:11 -07003574 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003575 mutex_unlock(&dev_priv->rps.hw_lock);
3576 return -EINVAL;
3577 }
3578
Ben Widawskyb39fb292014-03-19 18:31:11 -07003579 dev_priv->rps.max_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003580
3581 if (IS_VALLEYVIEW(dev))
3582 valleyview_set_rps(dev, val);
3583 else
3584 gen6_set_rps(dev, val);
3585
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003586 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes358733e2011-07-27 11:53:01 -07003587
Kees Cook647416f2013-03-10 14:10:06 -07003588 return 0;
Jesse Barnes358733e2011-07-27 11:53:01 -07003589}
3590
Kees Cook647416f2013-03-10 14:10:06 -07003591DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
3592 i915_max_freq_get, i915_max_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003593 "%llu\n");
Jesse Barnes358733e2011-07-27 11:53:01 -07003594
Kees Cook647416f2013-03-10 14:10:06 -07003595static int
3596i915_min_freq_get(void *data, u64 *val)
Jesse Barnes1523c312012-05-25 12:34:54 -07003597{
Kees Cook647416f2013-03-10 14:10:06 -07003598 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003599 struct drm_i915_private *dev_priv = dev->dev_private;
Kees Cook647416f2013-03-10 14:10:06 -07003600 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003601
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003602 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003603 return -ENODEV;
3604
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003605 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3606
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003607 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003608 if (ret)
3609 return ret;
Jesse Barnes1523c312012-05-25 12:34:54 -07003610
Jesse Barnes0a073b82013-04-17 15:54:58 -07003611 if (IS_VALLEYVIEW(dev))
Ben Widawskyb39fb292014-03-19 18:31:11 -07003612 *val = vlv_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003613 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07003614 *val = dev_priv->rps.min_freq_softlimit * GT_FREQUENCY_MULTIPLIER;
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003615 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003616
Kees Cook647416f2013-03-10 14:10:06 -07003617 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003618}
3619
Kees Cook647416f2013-03-10 14:10:06 -07003620static int
3621i915_min_freq_set(void *data, u64 val)
Jesse Barnes1523c312012-05-25 12:34:54 -07003622{
Kees Cook647416f2013-03-10 14:10:06 -07003623 struct drm_device *dev = data;
Jesse Barnes1523c312012-05-25 12:34:54 -07003624 struct drm_i915_private *dev_priv = dev->dev_private;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003625 u32 rp_state_cap, hw_max, hw_min;
Kees Cook647416f2013-03-10 14:10:06 -07003626 int ret;
Daniel Vetter004777c2012-08-09 15:07:01 +02003627
Tom O'Rourkedaa3afb2014-05-30 16:22:10 -07003628 if (INTEL_INFO(dev)->gen < 6)
Daniel Vetter004777c2012-08-09 15:07:01 +02003629 return -ENODEV;
Jesse Barnes1523c312012-05-25 12:34:54 -07003630
Tom O'Rourke5c9669c2013-09-16 14:56:43 -07003631 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
3632
Kees Cook647416f2013-03-10 14:10:06 -07003633 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
Jesse Barnes1523c312012-05-25 12:34:54 -07003634
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003635 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
Daniel Vetter004777c2012-08-09 15:07:01 +02003636 if (ret)
3637 return ret;
3638
Jesse Barnes1523c312012-05-25 12:34:54 -07003639 /*
3640 * Turbo will still be enabled, but won't go below the set value.
3641 */
Jesse Barnes0a073b82013-04-17 15:54:58 -07003642 if (IS_VALLEYVIEW(dev)) {
Ville Syrjälä2ec38152013-11-05 22:42:29 +02003643 val = vlv_freq_opcode(dev_priv, val);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003644
3645 hw_max = valleyview_rps_max_freq(dev_priv);
3646 hw_min = valleyview_rps_min_freq(dev_priv);
Jesse Barnes0a073b82013-04-17 15:54:58 -07003647 } else {
3648 do_div(val, GT_FREQUENCY_MULTIPLIER);
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003649
3650 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
Ben Widawskyb39fb292014-03-19 18:31:11 -07003651 hw_max = dev_priv->rps.max_freq;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003652 hw_min = (rp_state_cap >> 16) & 0xff;
Jesse Barnes0a073b82013-04-17 15:54:58 -07003653 }
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003654
Ben Widawskyb39fb292014-03-19 18:31:11 -07003655 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003656 mutex_unlock(&dev_priv->rps.hw_lock);
3657 return -EINVAL;
3658 }
3659
Ben Widawskyb39fb292014-03-19 18:31:11 -07003660 dev_priv->rps.min_freq_softlimit = val;
Jeff McGeedd0a1aa2014-02-04 11:32:31 -06003661
3662 if (IS_VALLEYVIEW(dev))
3663 valleyview_set_rps(dev, val);
3664 else
3665 gen6_set_rps(dev, val);
3666
Jesse Barnes4fc688c2012-11-02 11:14:01 -07003667 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes1523c312012-05-25 12:34:54 -07003668
Kees Cook647416f2013-03-10 14:10:06 -07003669 return 0;
Jesse Barnes1523c312012-05-25 12:34:54 -07003670}
3671
Kees Cook647416f2013-03-10 14:10:06 -07003672DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
3673 i915_min_freq_get, i915_min_freq_set,
Mika Kuoppala3a3b4f92013-04-12 12:10:05 +03003674 "%llu\n");
Jesse Barnes1523c312012-05-25 12:34:54 -07003675
Kees Cook647416f2013-03-10 14:10:06 -07003676static int
3677i915_cache_sharing_get(void *data, u64 *val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003678{
Kees Cook647416f2013-03-10 14:10:06 -07003679 struct drm_device *dev = data;
Jani Nikulae277a1f2014-03-31 14:27:14 +03003680 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003681 u32 snpcr;
Kees Cook647416f2013-03-10 14:10:06 -07003682 int ret;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003683
Daniel Vetter004777c2012-08-09 15:07:01 +02003684 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3685 return -ENODEV;
3686
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003687 ret = mutex_lock_interruptible(&dev->struct_mutex);
3688 if (ret)
3689 return ret;
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003690 intel_runtime_pm_get(dev_priv);
Daniel Vetter22bcfc62012-08-09 15:07:02 +02003691
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003692 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003693
3694 intel_runtime_pm_put(dev_priv);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003695 mutex_unlock(&dev_priv->dev->struct_mutex);
3696
Kees Cook647416f2013-03-10 14:10:06 -07003697 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003698
Kees Cook647416f2013-03-10 14:10:06 -07003699 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003700}
3701
Kees Cook647416f2013-03-10 14:10:06 -07003702static int
3703i915_cache_sharing_set(void *data, u64 val)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003704{
Kees Cook647416f2013-03-10 14:10:06 -07003705 struct drm_device *dev = data;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003706 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003707 u32 snpcr;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003708
Daniel Vetter004777c2012-08-09 15:07:01 +02003709 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
3710 return -ENODEV;
3711
Kees Cook647416f2013-03-10 14:10:06 -07003712 if (val > 3)
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003713 return -EINVAL;
3714
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003715 intel_runtime_pm_get(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07003716 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003717
3718 /* Update the cache sharing policy here as well */
3719 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
3720 snpcr &= ~GEN6_MBC_SNPCR_MASK;
3721 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
3722 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
3723
Paulo Zanonic8c8fb32013-11-27 18:21:54 -02003724 intel_runtime_pm_put(dev_priv);
Kees Cook647416f2013-03-10 14:10:06 -07003725 return 0;
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003726}
3727
Kees Cook647416f2013-03-10 14:10:06 -07003728DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
3729 i915_cache_sharing_get, i915_cache_sharing_set,
3730 "%llu\n");
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003731
Ben Widawsky6d794d42011-04-25 11:25:56 -07003732static int i915_forcewake_open(struct inode *inode, struct file *file)
3733{
3734 struct drm_device *dev = inode->i_private;
3735 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003736
Daniel Vetter075edca2012-01-24 09:44:28 +01003737 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003738 return 0;
3739
Deepak Sc8d9a592013-11-23 14:55:42 +05303740 gen6_gt_force_wake_get(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003741
3742 return 0;
3743}
3744
Ben Widawskyc43b5632012-04-16 14:07:40 -07003745static int i915_forcewake_release(struct inode *inode, struct file *file)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003746{
3747 struct drm_device *dev = inode->i_private;
3748 struct drm_i915_private *dev_priv = dev->dev_private;
3749
Daniel Vetter075edca2012-01-24 09:44:28 +01003750 if (INTEL_INFO(dev)->gen < 6)
Ben Widawsky6d794d42011-04-25 11:25:56 -07003751 return 0;
3752
Deepak Sc8d9a592013-11-23 14:55:42 +05303753 gen6_gt_force_wake_put(dev_priv, FORCEWAKE_ALL);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003754
3755 return 0;
3756}
3757
3758static const struct file_operations i915_forcewake_fops = {
3759 .owner = THIS_MODULE,
3760 .open = i915_forcewake_open,
3761 .release = i915_forcewake_release,
3762};
3763
3764static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
3765{
3766 struct drm_device *dev = minor->dev;
3767 struct dentry *ent;
3768
3769 ent = debugfs_create_file("i915_forcewake_user",
Ben Widawsky8eb57292011-05-11 15:10:58 -07003770 S_IRUSR,
Ben Widawsky6d794d42011-04-25 11:25:56 -07003771 root, dev,
3772 &i915_forcewake_fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003773 if (!ent)
3774 return -ENOMEM;
Ben Widawsky6d794d42011-04-25 11:25:56 -07003775
Ben Widawsky8eb57292011-05-11 15:10:58 -07003776 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
Ben Widawsky6d794d42011-04-25 11:25:56 -07003777}
3778
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003779static int i915_debugfs_create(struct dentry *root,
3780 struct drm_minor *minor,
3781 const char *name,
3782 const struct file_operations *fops)
Jesse Barnes358733e2011-07-27 11:53:01 -07003783{
3784 struct drm_device *dev = minor->dev;
3785 struct dentry *ent;
3786
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003787 ent = debugfs_create_file(name,
Jesse Barnes358733e2011-07-27 11:53:01 -07003788 S_IRUGO | S_IWUSR,
3789 root, dev,
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003790 fops);
Wei Yongjunf3c5fe92013-12-16 14:13:25 +08003791 if (!ent)
3792 return -ENOMEM;
Jesse Barnes358733e2011-07-27 11:53:01 -07003793
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003794 return drm_add_fake_info_node(minor, ent, fops);
Jesse Barnes07b7ddd2011-08-03 11:28:44 -07003795}
3796
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003797static const struct drm_info_list i915_debugfs_list[] = {
Chris Wilson311bd682011-01-13 19:06:50 +00003798 {"i915_capabilities", i915_capabilities, 0},
Chris Wilson73aa8082010-09-30 11:46:12 +01003799 {"i915_gem_objects", i915_gem_object_info, 0},
Chris Wilson08c18322011-01-10 00:00:24 +00003800 {"i915_gem_gtt", i915_gem_gtt_info, 0},
Chris Wilson1b502472012-04-24 15:47:30 +01003801 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003802 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
Ben Gamari433e12f2009-02-17 20:08:51 -05003803 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
Chris Wilson6d2b8882013-08-07 18:30:54 +01003804 {"i915_gem_stolen", i915_gem_stolen_list_info },
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01003805 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003806 {"i915_gem_request", i915_gem_request_info, 0},
3807 {"i915_gem_seqno", i915_gem_seqno_info, 0},
Chris Wilsona6172a82009-02-11 14:26:38 +00003808 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003809 {"i915_gem_interrupt", i915_interrupt_info, 0},
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003810 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
3811 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
3812 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
Xiang, Haihao9010ebf2013-05-29 09:22:36 -07003813 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
Jesse Barnesf97108d2010-01-29 11:27:07 -08003814 {"i915_rstdby_delays", i915_rstdby_delays, 0},
Deepak Sadb4bd12014-03-31 11:30:02 +05303815 {"i915_frequency_info", i915_frequency_info, 0},
Jesse Barnesf97108d2010-01-29 11:27:07 -08003816 {"i915_delayfreq_table", i915_delayfreq_table, 0},
3817 {"i915_inttoext_table", i915_inttoext_table, 0},
3818 {"i915_drpc_info", i915_drpc_info, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07003819 {"i915_emon_status", i915_emon_status, 0},
Jesse Barnes23b2f8b2011-06-28 13:04:16 -07003820 {"i915_ring_freq_table", i915_ring_freq_table, 0},
Jesse Barnes7648fa92010-05-20 14:28:11 -07003821 {"i915_gfxec", i915_gfxec, 0},
Jesse Barnesb5e50c32010-02-05 12:42:41 -08003822 {"i915_fbc_status", i915_fbc_status, 0},
Paulo Zanoni92d44622013-05-31 16:33:24 -03003823 {"i915_ips_status", i915_ips_status, 0},
Jesse Barnes4a9bef32010-02-05 12:47:35 -08003824 {"i915_sr_status", i915_sr_status, 0},
Chris Wilson44834a62010-08-19 16:09:23 +01003825 {"i915_opregion", i915_opregion, 0},
Chris Wilson37811fc2010-08-25 22:45:57 +01003826 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
Ben Widawskye76d3632011-03-19 18:14:29 -07003827 {"i915_context_status", i915_context_status, 0},
Ben Widawsky6d794d42011-04-25 11:25:56 -07003828 {"i915_gen6_forcewake_count", i915_gen6_forcewake_count_info, 0},
Daniel Vetterea16a3c2011-12-14 13:57:16 +01003829 {"i915_swizzle_info", i915_swizzle_info, 0},
Daniel Vetter3cf17fc2012-02-09 17:15:49 +01003830 {"i915_ppgtt_info", i915_ppgtt_info, 0},
Ben Widawsky63573eb2013-07-04 11:02:07 -07003831 {"i915_llc", i915_llc, 0},
Rodrigo Vivie91fd8c2013-07-11 18:44:59 -03003832 {"i915_edp_psr_status", i915_edp_psr_status, 0},
Rodrigo Vivid2e216d2014-01-24 13:36:17 -02003833 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
Jesse Barnesec013e72013-08-20 10:29:23 +01003834 {"i915_energy_uJ", i915_energy_uJ, 0},
Paulo Zanoni371db662013-08-19 13:18:10 -03003835 {"i915_pc8_status", i915_pc8_status, 0},
Imre Deak1da51582013-11-25 17:15:35 +02003836 {"i915_power_domain_info", i915_power_domain_info, 0},
Jesse Barnes53f5e3c2014-02-07 12:48:15 -08003837 {"i915_display_info", i915_display_info, 0},
Ben Gamari20172632009-02-17 20:08:50 -05003838};
Ben Gamari27c202a2009-07-01 22:26:52 -04003839#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
Ben Gamari20172632009-02-17 20:08:50 -05003840
Lespiau, Damien06c5bf82013-10-17 19:09:56 +01003841static const struct i915_debugfs_files {
Daniel Vetter34b96742013-07-04 20:49:44 +02003842 const char *name;
3843 const struct file_operations *fops;
3844} i915_debugfs_files[] = {
3845 {"i915_wedged", &i915_wedged_fops},
3846 {"i915_max_freq", &i915_max_freq_fops},
3847 {"i915_min_freq", &i915_min_freq_fops},
3848 {"i915_cache_sharing", &i915_cache_sharing_fops},
3849 {"i915_ring_stop", &i915_ring_stop_fops},
Chris Wilson094f9a52013-09-25 17:34:55 +01003850 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
3851 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02003852 {"i915_gem_drop_caches", &i915_drop_caches_fops},
3853 {"i915_error_state", &i915_error_state_fops},
3854 {"i915_next_seqno", &i915_next_seqno_fops},
Damien Lespiaubd9db022013-10-15 18:55:36 +01003855 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
Ville Syrjälä369a1342014-01-22 14:36:08 +02003856 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
3857 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
3858 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
Daniel Vetter34b96742013-07-04 20:49:44 +02003859};
3860
Damien Lespiau07144422013-10-15 18:55:40 +01003861void intel_display_crc_init(struct drm_device *dev)
3862{
3863 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb3783602013-11-14 11:30:42 +01003864 enum pipe pipe;
Damien Lespiau07144422013-10-15 18:55:40 +01003865
Daniel Vetterb3783602013-11-14 11:30:42 +01003866 for_each_pipe(pipe) {
3867 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Damien Lespiau07144422013-10-15 18:55:40 +01003868
Damien Lespiaud538bbd2013-10-21 14:29:30 +01003869 pipe_crc->opened = false;
3870 spin_lock_init(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01003871 init_waitqueue_head(&pipe_crc->wq);
3872 }
3873}
3874
Ben Gamari27c202a2009-07-01 22:26:52 -04003875int i915_debugfs_init(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05003876{
Daniel Vetter34b96742013-07-04 20:49:44 +02003877 int ret, i;
Chris Wilsonf3cd4742009-10-13 22:20:20 +01003878
Ben Widawsky6d794d42011-04-25 11:25:56 -07003879 ret = i915_forcewake_create(minor->debugfs_root, minor);
3880 if (ret)
3881 return ret;
Daniel Vetter6a9c3082011-12-14 13:57:11 +01003882
Damien Lespiau07144422013-10-15 18:55:40 +01003883 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
3884 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
3885 if (ret)
3886 return ret;
3887 }
3888
Daniel Vetter34b96742013-07-04 20:49:44 +02003889 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
3890 ret = i915_debugfs_create(minor->debugfs_root, minor,
3891 i915_debugfs_files[i].name,
3892 i915_debugfs_files[i].fops);
3893 if (ret)
3894 return ret;
3895 }
Mika Kuoppala40633212012-12-04 15:12:00 +02003896
Ben Gamari27c202a2009-07-01 22:26:52 -04003897 return drm_debugfs_create_files(i915_debugfs_list,
3898 I915_DEBUGFS_ENTRIES,
Ben Gamari20172632009-02-17 20:08:50 -05003899 minor->debugfs_root, minor);
3900}
3901
Ben Gamari27c202a2009-07-01 22:26:52 -04003902void i915_debugfs_cleanup(struct drm_minor *minor)
Ben Gamari20172632009-02-17 20:08:50 -05003903{
Daniel Vetter34b96742013-07-04 20:49:44 +02003904 int i;
3905
Ben Gamari27c202a2009-07-01 22:26:52 -04003906 drm_debugfs_remove_files(i915_debugfs_list,
3907 I915_DEBUGFS_ENTRIES, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01003908
Ben Widawsky6d794d42011-04-25 11:25:56 -07003909 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
3910 1, minor);
Damien Lespiau07144422013-10-15 18:55:40 +01003911
Daniel Vettere309a992013-10-16 22:55:51 +02003912 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
Damien Lespiau07144422013-10-15 18:55:40 +01003913 struct drm_info_list *info_list =
3914 (struct drm_info_list *)&i915_pipe_crc_data[i];
3915
3916 drm_debugfs_remove_files(info_list, 1, minor);
3917 }
3918
Daniel Vetter34b96742013-07-04 20:49:44 +02003919 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
3920 struct drm_info_list *info_list =
3921 (struct drm_info_list *) i915_debugfs_files[i].fops;
3922
3923 drm_debugfs_remove_files(info_list, 1, minor);
3924 }
Ben Gamari20172632009-02-17 20:08:50 -05003925}