drm/core: Set mode to NULL when connectors in a set drops to 0.
[linux-2.6-block.git] / drivers / gpu / drm / i915 / i915_debugfs.c
CommitLineData
2017263e
BG
1/*
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>
b2c88f5b 30#include <linux/circ_buf.h>
926321d5 31#include <linux/ctype.h>
f3cd474b 32#include <linux/debugfs.h>
5a0e3ad6 33#include <linux/slab.h>
2d1a8a48 34#include <linux/export.h>
6d2b8885 35#include <linux/list_sort.h>
ec013e7f 36#include <asm/msr-index.h>
760285e7 37#include <drm/drmP.h>
4e5359cd 38#include "intel_drv.h"
e5c65260 39#include "intel_ringbuffer.h"
760285e7 40#include <drm/i915_drm.h>
2017263e
BG
41#include "i915_drv.h"
42
f13d3f73 43enum {
69dc4987 44 ACTIVE_LIST,
f13d3f73 45 INACTIVE_LIST,
d21d5975 46 PINNED_LIST,
f13d3f73 47};
2017263e 48
70d39fe4
CW
49static const char *yesno(int v)
50{
51 return v ? "yes" : "no";
52}
53
497666d8
DL
54/* 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
70d39fe4
CW
80static int i915_capabilities(struct seq_file *m, void *data)
81{
9f25d007 82 struct drm_info_node *node = m->private;
70d39fe4
CW
83 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);
03d00ac5 87 seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(dev));
79fc46df
DL
88#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
70d39fe4
CW
93
94 return 0;
95}
2017263e 96
05394f39 97static const char *get_pin_flag(struct drm_i915_gem_object *obj)
a6172a80 98{
baaa5cfb 99 if (obj->pin_display)
a6172a80
CW
100 return "p";
101 else
102 return " ";
103}
104
05394f39 105static const char *get_tiling_flag(struct drm_i915_gem_object *obj)
a6172a80 106{
0206e353
AJ
107 switch (obj->tiling_mode) {
108 default:
109 case I915_TILING_NONE: return " ";
110 case I915_TILING_X: return "X";
111 case I915_TILING_Y: return "Y";
112 }
a6172a80
CW
113}
114
1d693bcc
BW
115static inline const char *get_global_flag(struct drm_i915_gem_object *obj)
116{
aff43766 117 return i915_gem_obj_to_ggtt(obj) ? "g" : " ";
1d693bcc
BW
118}
119
ca1543be
TU
120static u64 i915_gem_obj_total_ggtt_size(struct drm_i915_gem_object *obj)
121{
122 u64 size = 0;
123 struct i915_vma *vma;
124
125 list_for_each_entry(vma, &obj->vma_list, vma_link) {
126 if (i915_is_ggtt(vma->vm) &&
127 drm_mm_node_allocated(&vma->node))
128 size += vma->node.size;
129 }
130
131 return size;
132}
133
37811fcc
CW
134static void
135describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
136{
b4716185
CW
137 struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
138 struct intel_engine_cs *ring;
1d693bcc 139 struct i915_vma *vma;
d7f46fc4 140 int pin_count = 0;
b4716185 141 int i;
d7f46fc4 142
b4716185 143 seq_printf(m, "%pK: %s%s%s%s %8zdKiB %02x %02x [ ",
37811fcc 144 &obj->base,
481a3d43 145 obj->active ? "*" : " ",
37811fcc
CW
146 get_pin_flag(obj),
147 get_tiling_flag(obj),
1d693bcc 148 get_global_flag(obj),
a05a5862 149 obj->base.size / 1024,
37811fcc 150 obj->base.read_domains,
b4716185
CW
151 obj->base.write_domain);
152 for_each_ring(ring, dev_priv, i)
153 seq_printf(m, "%x ",
154 i915_gem_request_get_seqno(obj->last_read_req[i]));
155 seq_printf(m, "] %x %x%s%s%s",
97b2a6a1
JH
156 i915_gem_request_get_seqno(obj->last_write_req),
157 i915_gem_request_get_seqno(obj->last_fenced_req),
0a4cd7c8 158 i915_cache_level_str(to_i915(obj->base.dev), obj->cache_level),
37811fcc
CW
159 obj->dirty ? " dirty" : "",
160 obj->madv == I915_MADV_DONTNEED ? " purgeable" : "");
161 if (obj->base.name)
162 seq_printf(m, " (name: %d)", obj->base.name);
ba0635ff 163 list_for_each_entry(vma, &obj->vma_list, vma_link) {
d7f46fc4
BW
164 if (vma->pin_count > 0)
165 pin_count++;
ba0635ff
DC
166 }
167 seq_printf(m, " (pinned x %d)", pin_count);
cc98b413
CW
168 if (obj->pin_display)
169 seq_printf(m, " (display)");
37811fcc
CW
170 if (obj->fence_reg != I915_FENCE_REG_NONE)
171 seq_printf(m, " (fence: %d)", obj->fence_reg);
1d693bcc 172 list_for_each_entry(vma, &obj->vma_list, vma_link) {
8d2fdc3f
TU
173 seq_printf(m, " (%sgtt offset: %08llx, size: %08llx",
174 i915_is_ggtt(vma->vm) ? "g" : "pp",
175 vma->node.start, vma->node.size);
176 if (i915_is_ggtt(vma->vm))
177 seq_printf(m, ", type: %u)", vma->ggtt_view.type);
1d693bcc 178 else
8d2fdc3f 179 seq_puts(m, ")");
1d693bcc 180 }
c1ad11fc 181 if (obj->stolen)
440fd528 182 seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
30154650 183 if (obj->pin_display || obj->fault_mappable) {
6299f992 184 char s[3], *t = s;
30154650 185 if (obj->pin_display)
6299f992
CW
186 *t++ = 'p';
187 if (obj->fault_mappable)
188 *t++ = 'f';
189 *t = '\0';
190 seq_printf(m, " (%s mappable)", s);
191 }
b4716185 192 if (obj->last_write_req != NULL)
41c52415 193 seq_printf(m, " (%s)",
b4716185 194 i915_gem_request_get_ring(obj->last_write_req)->name);
d5a81ef1
DV
195 if (obj->frontbuffer_bits)
196 seq_printf(m, " (frontbuffer: 0x%03x)", obj->frontbuffer_bits);
37811fcc
CW
197}
198
273497e5 199static void describe_ctx(struct seq_file *m, struct intel_context *ctx)
3ccfd19d 200{
ea0c76f8 201 seq_putc(m, ctx->legacy_hw_ctx.initialized ? 'I' : 'i');
3ccfd19d
BW
202 seq_putc(m, ctx->remap_slice ? 'R' : 'r');
203 seq_putc(m, ' ');
204}
205
433e12f7 206static int i915_gem_object_list_info(struct seq_file *m, void *data)
2017263e 207{
9f25d007 208 struct drm_info_node *node = m->private;
433e12f7
BG
209 uintptr_t list = (uintptr_t) node->info_ent->data;
210 struct list_head *head;
2017263e 211 struct drm_device *dev = node->minor->dev;
5cef07e1
BW
212 struct drm_i915_private *dev_priv = dev->dev_private;
213 struct i915_address_space *vm = &dev_priv->gtt.base;
ca191b13 214 struct i915_vma *vma;
c44ef60e 215 u64 total_obj_size, total_gtt_size;
8f2480fb 216 int count, ret;
de227ef0
CW
217
218 ret = mutex_lock_interruptible(&dev->struct_mutex);
219 if (ret)
220 return ret;
2017263e 221
ca191b13 222 /* FIXME: the user of this interface might want more than just GGTT */
433e12f7
BG
223 switch (list) {
224 case ACTIVE_LIST:
267f0c90 225 seq_puts(m, "Active:\n");
5cef07e1 226 head = &vm->active_list;
433e12f7
BG
227 break;
228 case INACTIVE_LIST:
267f0c90 229 seq_puts(m, "Inactive:\n");
5cef07e1 230 head = &vm->inactive_list;
433e12f7 231 break;
433e12f7 232 default:
de227ef0
CW
233 mutex_unlock(&dev->struct_mutex);
234 return -EINVAL;
2017263e 235 }
2017263e 236
8f2480fb 237 total_obj_size = total_gtt_size = count = 0;
ca191b13
BW
238 list_for_each_entry(vma, head, mm_list) {
239 seq_printf(m, " ");
240 describe_obj(m, vma->obj);
241 seq_printf(m, "\n");
242 total_obj_size += vma->obj->base.size;
243 total_gtt_size += vma->node.size;
8f2480fb 244 count++;
2017263e 245 }
de227ef0 246 mutex_unlock(&dev->struct_mutex);
5e118f41 247
c44ef60e 248 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
8f2480fb 249 count, total_obj_size, total_gtt_size);
2017263e
BG
250 return 0;
251}
252
6d2b8885
CW
253static int obj_rank_by_stolen(void *priv,
254 struct list_head *A, struct list_head *B)
255{
256 struct drm_i915_gem_object *a =
b25cb2f8 257 container_of(A, struct drm_i915_gem_object, obj_exec_link);
6d2b8885 258 struct drm_i915_gem_object *b =
b25cb2f8 259 container_of(B, struct drm_i915_gem_object, obj_exec_link);
6d2b8885
CW
260
261 return a->stolen->start - b->stolen->start;
262}
263
264static int i915_gem_stolen_list_info(struct seq_file *m, void *data)
265{
9f25d007 266 struct drm_info_node *node = m->private;
6d2b8885
CW
267 struct drm_device *dev = node->minor->dev;
268 struct drm_i915_private *dev_priv = dev->dev_private;
269 struct drm_i915_gem_object *obj;
c44ef60e 270 u64 total_obj_size, total_gtt_size;
6d2b8885
CW
271 LIST_HEAD(stolen);
272 int count, ret;
273
274 ret = mutex_lock_interruptible(&dev->struct_mutex);
275 if (ret)
276 return ret;
277
278 total_obj_size = total_gtt_size = count = 0;
279 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
280 if (obj->stolen == NULL)
281 continue;
282
b25cb2f8 283 list_add(&obj->obj_exec_link, &stolen);
6d2b8885
CW
284
285 total_obj_size += obj->base.size;
ca1543be 286 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
6d2b8885
CW
287 count++;
288 }
289 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
290 if (obj->stolen == NULL)
291 continue;
292
b25cb2f8 293 list_add(&obj->obj_exec_link, &stolen);
6d2b8885
CW
294
295 total_obj_size += obj->base.size;
296 count++;
297 }
298 list_sort(NULL, &stolen, obj_rank_by_stolen);
299 seq_puts(m, "Stolen:\n");
300 while (!list_empty(&stolen)) {
b25cb2f8 301 obj = list_first_entry(&stolen, typeof(*obj), obj_exec_link);
6d2b8885
CW
302 seq_puts(m, " ");
303 describe_obj(m, obj);
304 seq_putc(m, '\n');
b25cb2f8 305 list_del_init(&obj->obj_exec_link);
6d2b8885
CW
306 }
307 mutex_unlock(&dev->struct_mutex);
308
c44ef60e 309 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
6d2b8885
CW
310 count, total_obj_size, total_gtt_size);
311 return 0;
312}
313
6299f992
CW
314#define count_objects(list, member) do { \
315 list_for_each_entry(obj, list, member) { \
ca1543be 316 size += i915_gem_obj_total_ggtt_size(obj); \
6299f992
CW
317 ++count; \
318 if (obj->map_and_fenceable) { \
f343c5f6 319 mappable_size += i915_gem_obj_ggtt_size(obj); \
6299f992
CW
320 ++mappable_count; \
321 } \
322 } \
0206e353 323} while (0)
6299f992 324
2db8e9d6 325struct file_stats {
6313c204 326 struct drm_i915_file_private *file_priv;
c44ef60e
MK
327 unsigned long count;
328 u64 total, unbound;
329 u64 global, shared;
330 u64 active, inactive;
2db8e9d6
CW
331};
332
333static int per_file_stats(int id, void *ptr, void *data)
334{
335 struct drm_i915_gem_object *obj = ptr;
336 struct file_stats *stats = data;
6313c204 337 struct i915_vma *vma;
2db8e9d6
CW
338
339 stats->count++;
340 stats->total += obj->base.size;
341
c67a17e9
CW
342 if (obj->base.name || obj->base.dma_buf)
343 stats->shared += obj->base.size;
344
6313c204
CW
345 if (USES_FULL_PPGTT(obj->base.dev)) {
346 list_for_each_entry(vma, &obj->vma_list, vma_link) {
347 struct i915_hw_ppgtt *ppgtt;
348
349 if (!drm_mm_node_allocated(&vma->node))
350 continue;
351
352 if (i915_is_ggtt(vma->vm)) {
353 stats->global += obj->base.size;
354 continue;
355 }
356
357 ppgtt = container_of(vma->vm, struct i915_hw_ppgtt, base);
4d884705 358 if (ppgtt->file_priv != stats->file_priv)
6313c204
CW
359 continue;
360
41c52415 361 if (obj->active) /* XXX per-vma statistic */
6313c204
CW
362 stats->active += obj->base.size;
363 else
364 stats->inactive += obj->base.size;
365
366 return 0;
367 }
2db8e9d6 368 } else {
6313c204
CW
369 if (i915_gem_obj_ggtt_bound(obj)) {
370 stats->global += obj->base.size;
41c52415 371 if (obj->active)
6313c204
CW
372 stats->active += obj->base.size;
373 else
374 stats->inactive += obj->base.size;
375 return 0;
376 }
2db8e9d6
CW
377 }
378
6313c204
CW
379 if (!list_empty(&obj->global_list))
380 stats->unbound += obj->base.size;
381
2db8e9d6
CW
382 return 0;
383}
384
b0da1b79
CW
385#define print_file_stats(m, name, stats) do { \
386 if (stats.count) \
c44ef60e 387 seq_printf(m, "%s: %lu objects, %llu bytes (%llu active, %llu inactive, %llu global, %llu shared, %llu unbound)\n", \
b0da1b79
CW
388 name, \
389 stats.count, \
390 stats.total, \
391 stats.active, \
392 stats.inactive, \
393 stats.global, \
394 stats.shared, \
395 stats.unbound); \
396} while (0)
493018dc
BV
397
398static void print_batch_pool_stats(struct seq_file *m,
399 struct drm_i915_private *dev_priv)
400{
401 struct drm_i915_gem_object *obj;
402 struct file_stats stats;
06fbca71 403 struct intel_engine_cs *ring;
8d9d5744 404 int i, j;
493018dc
BV
405
406 memset(&stats, 0, sizeof(stats));
407
06fbca71 408 for_each_ring(ring, dev_priv, i) {
8d9d5744
CW
409 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
410 list_for_each_entry(obj,
411 &ring->batch_pool.cache_list[j],
412 batch_pool_link)
413 per_file_stats(0, obj, &stats);
414 }
06fbca71 415 }
493018dc 416
b0da1b79 417 print_file_stats(m, "[k]batch pool", stats);
493018dc
BV
418}
419
ca191b13
BW
420#define count_vmas(list, member) do { \
421 list_for_each_entry(vma, list, member) { \
ca1543be 422 size += i915_gem_obj_total_ggtt_size(vma->obj); \
ca191b13
BW
423 ++count; \
424 if (vma->obj->map_and_fenceable) { \
425 mappable_size += i915_gem_obj_ggtt_size(vma->obj); \
426 ++mappable_count; \
427 } \
428 } \
429} while (0)
430
431static int i915_gem_object_info(struct seq_file *m, void* data)
73aa808f 432{
9f25d007 433 struct drm_info_node *node = m->private;
73aa808f
CW
434 struct drm_device *dev = node->minor->dev;
435 struct drm_i915_private *dev_priv = dev->dev_private;
b7abb714 436 u32 count, mappable_count, purgeable_count;
c44ef60e 437 u64 size, mappable_size, purgeable_size;
6299f992 438 struct drm_i915_gem_object *obj;
5cef07e1 439 struct i915_address_space *vm = &dev_priv->gtt.base;
2db8e9d6 440 struct drm_file *file;
ca191b13 441 struct i915_vma *vma;
73aa808f
CW
442 int ret;
443
444 ret = mutex_lock_interruptible(&dev->struct_mutex);
445 if (ret)
446 return ret;
447
6299f992
CW
448 seq_printf(m, "%u objects, %zu bytes\n",
449 dev_priv->mm.object_count,
450 dev_priv->mm.object_memory);
451
452 size = count = mappable_size = mappable_count = 0;
35c20a60 453 count_objects(&dev_priv->mm.bound_list, global_list);
c44ef60e 454 seq_printf(m, "%u [%u] objects, %llu [%llu] bytes in gtt\n",
6299f992
CW
455 count, mappable_count, size, mappable_size);
456
457 size = count = mappable_size = mappable_count = 0;
ca191b13 458 count_vmas(&vm->active_list, mm_list);
c44ef60e 459 seq_printf(m, " %u [%u] active objects, %llu [%llu] bytes\n",
6299f992
CW
460 count, mappable_count, size, mappable_size);
461
6299f992 462 size = count = mappable_size = mappable_count = 0;
ca191b13 463 count_vmas(&vm->inactive_list, mm_list);
c44ef60e 464 seq_printf(m, " %u [%u] inactive objects, %llu [%llu] bytes\n",
6299f992
CW
465 count, mappable_count, size, mappable_size);
466
b7abb714 467 size = count = purgeable_size = purgeable_count = 0;
35c20a60 468 list_for_each_entry(obj, &dev_priv->mm.unbound_list, global_list) {
6c085a72 469 size += obj->base.size, ++count;
b7abb714
CW
470 if (obj->madv == I915_MADV_DONTNEED)
471 purgeable_size += obj->base.size, ++purgeable_count;
472 }
c44ef60e 473 seq_printf(m, "%u unbound objects, %llu bytes\n", count, size);
6c085a72 474
6299f992 475 size = count = mappable_size = mappable_count = 0;
35c20a60 476 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
6299f992 477 if (obj->fault_mappable) {
f343c5f6 478 size += i915_gem_obj_ggtt_size(obj);
6299f992
CW
479 ++count;
480 }
30154650 481 if (obj->pin_display) {
f343c5f6 482 mappable_size += i915_gem_obj_ggtt_size(obj);
6299f992
CW
483 ++mappable_count;
484 }
b7abb714
CW
485 if (obj->madv == I915_MADV_DONTNEED) {
486 purgeable_size += obj->base.size;
487 ++purgeable_count;
488 }
6299f992 489 }
c44ef60e 490 seq_printf(m, "%u purgeable objects, %llu bytes\n",
b7abb714 491 purgeable_count, purgeable_size);
c44ef60e 492 seq_printf(m, "%u pinned mappable objects, %llu bytes\n",
6299f992 493 mappable_count, mappable_size);
c44ef60e 494 seq_printf(m, "%u fault mappable objects, %llu bytes\n",
6299f992
CW
495 count, size);
496
c44ef60e 497 seq_printf(m, "%llu [%llu] gtt total\n",
853ba5d2 498 dev_priv->gtt.base.total,
c44ef60e 499 (u64)dev_priv->gtt.mappable_end - dev_priv->gtt.base.start);
73aa808f 500
493018dc
BV
501 seq_putc(m, '\n');
502 print_batch_pool_stats(m, dev_priv);
2db8e9d6
CW
503 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
504 struct file_stats stats;
3ec2f427 505 struct task_struct *task;
2db8e9d6
CW
506
507 memset(&stats, 0, sizeof(stats));
6313c204 508 stats.file_priv = file->driver_priv;
5b5ffff0 509 spin_lock(&file->table_lock);
2db8e9d6 510 idr_for_each(&file->object_idr, per_file_stats, &stats);
5b5ffff0 511 spin_unlock(&file->table_lock);
3ec2f427
TH
512 /*
513 * Although we have a valid reference on file->pid, that does
514 * not guarantee that the task_struct who called get_pid() is
515 * still alive (e.g. get_pid(current) => fork() => exit()).
516 * Therefore, we need to protect this ->comm access using RCU.
517 */
518 rcu_read_lock();
519 task = pid_task(file->pid, PIDTYPE_PID);
493018dc 520 print_file_stats(m, task ? task->comm : "<unknown>", stats);
3ec2f427 521 rcu_read_unlock();
2db8e9d6
CW
522 }
523
73aa808f
CW
524 mutex_unlock(&dev->struct_mutex);
525
526 return 0;
527}
528
aee56cff 529static int i915_gem_gtt_info(struct seq_file *m, void *data)
08c18323 530{
9f25d007 531 struct drm_info_node *node = m->private;
08c18323 532 struct drm_device *dev = node->minor->dev;
1b50247a 533 uintptr_t list = (uintptr_t) node->info_ent->data;
08c18323
CW
534 struct drm_i915_private *dev_priv = dev->dev_private;
535 struct drm_i915_gem_object *obj;
c44ef60e 536 u64 total_obj_size, total_gtt_size;
08c18323
CW
537 int count, ret;
538
539 ret = mutex_lock_interruptible(&dev->struct_mutex);
540 if (ret)
541 return ret;
542
543 total_obj_size = total_gtt_size = count = 0;
35c20a60 544 list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
d7f46fc4 545 if (list == PINNED_LIST && !i915_gem_obj_is_pinned(obj))
1b50247a
CW
546 continue;
547
267f0c90 548 seq_puts(m, " ");
08c18323 549 describe_obj(m, obj);
267f0c90 550 seq_putc(m, '\n');
08c18323 551 total_obj_size += obj->base.size;
ca1543be 552 total_gtt_size += i915_gem_obj_total_ggtt_size(obj);
08c18323
CW
553 count++;
554 }
555
556 mutex_unlock(&dev->struct_mutex);
557
c44ef60e 558 seq_printf(m, "Total %d objects, %llu bytes, %llu GTT size\n",
08c18323
CW
559 count, total_obj_size, total_gtt_size);
560
561 return 0;
562}
563
4e5359cd
SF
564static int i915_gem_pageflip_info(struct seq_file *m, void *data)
565{
9f25d007 566 struct drm_info_node *node = m->private;
4e5359cd 567 struct drm_device *dev = node->minor->dev;
d6bbafa1 568 struct drm_i915_private *dev_priv = dev->dev_private;
4e5359cd 569 struct intel_crtc *crtc;
8a270ebf
DV
570 int ret;
571
572 ret = mutex_lock_interruptible(&dev->struct_mutex);
573 if (ret)
574 return ret;
4e5359cd 575
d3fcc808 576 for_each_intel_crtc(dev, crtc) {
9db4a9c7
JB
577 const char pipe = pipe_name(crtc->pipe);
578 const char plane = plane_name(crtc->plane);
4e5359cd
SF
579 struct intel_unpin_work *work;
580
5e2d7afc 581 spin_lock_irq(&dev->event_lock);
4e5359cd
SF
582 work = crtc->unpin_work;
583 if (work == NULL) {
9db4a9c7 584 seq_printf(m, "No flip due on pipe %c (plane %c)\n",
4e5359cd
SF
585 pipe, plane);
586 } else {
d6bbafa1
CW
587 u32 addr;
588
e7d841ca 589 if (atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
9db4a9c7 590 seq_printf(m, "Flip queued on pipe %c (plane %c)\n",
4e5359cd
SF
591 pipe, plane);
592 } else {
9db4a9c7 593 seq_printf(m, "Flip pending (waiting for vsync) on pipe %c (plane %c)\n",
4e5359cd
SF
594 pipe, plane);
595 }
3a8a946e
DV
596 if (work->flip_queued_req) {
597 struct intel_engine_cs *ring =
598 i915_gem_request_get_ring(work->flip_queued_req);
599
20e28fba 600 seq_printf(m, "Flip queued on %s at seqno %x, next seqno %x [current breadcrumb %x], completed? %d\n",
3a8a946e 601 ring->name,
f06cc1b9 602 i915_gem_request_get_seqno(work->flip_queued_req),
d6bbafa1 603 dev_priv->next_seqno,
3a8a946e 604 ring->get_seqno(ring, true),
1b5a433a 605 i915_gem_request_completed(work->flip_queued_req, true));
d6bbafa1
CW
606 } else
607 seq_printf(m, "Flip not associated with any ring\n");
608 seq_printf(m, "Flip queued on frame %d, (was ready on frame %d), now %d\n",
609 work->flip_queued_vblank,
610 work->flip_ready_vblank,
1e3feefd 611 drm_crtc_vblank_count(&crtc->base));
4e5359cd 612 if (work->enable_stall_check)
267f0c90 613 seq_puts(m, "Stall check enabled, ");
4e5359cd 614 else
267f0c90 615 seq_puts(m, "Stall check waiting for page flip ioctl, ");
e7d841ca 616 seq_printf(m, "%d prepares\n", atomic_read(&work->pending));
4e5359cd 617
d6bbafa1
CW
618 if (INTEL_INFO(dev)->gen >= 4)
619 addr = I915_HI_DISPBASE(I915_READ(DSPSURF(crtc->plane)));
620 else
621 addr = I915_READ(DSPADDR(crtc->plane));
622 seq_printf(m, "Current scanout address 0x%08x\n", addr);
623
4e5359cd 624 if (work->pending_flip_obj) {
d6bbafa1
CW
625 seq_printf(m, "New framebuffer address 0x%08lx\n", (long)work->gtt_offset);
626 seq_printf(m, "MMIO update completed? %d\n", addr == work->gtt_offset);
4e5359cd
SF
627 }
628 }
5e2d7afc 629 spin_unlock_irq(&dev->event_lock);
4e5359cd
SF
630 }
631
8a270ebf
DV
632 mutex_unlock(&dev->struct_mutex);
633
4e5359cd
SF
634 return 0;
635}
636
493018dc
BV
637static int i915_gem_batch_pool_info(struct seq_file *m, void *data)
638{
639 struct drm_info_node *node = m->private;
640 struct drm_device *dev = node->minor->dev;
641 struct drm_i915_private *dev_priv = dev->dev_private;
642 struct drm_i915_gem_object *obj;
06fbca71 643 struct intel_engine_cs *ring;
8d9d5744
CW
644 int total = 0;
645 int ret, i, j;
493018dc
BV
646
647 ret = mutex_lock_interruptible(&dev->struct_mutex);
648 if (ret)
649 return ret;
650
06fbca71 651 for_each_ring(ring, dev_priv, i) {
8d9d5744
CW
652 for (j = 0; j < ARRAY_SIZE(ring->batch_pool.cache_list); j++) {
653 int count;
654
655 count = 0;
656 list_for_each_entry(obj,
657 &ring->batch_pool.cache_list[j],
658 batch_pool_link)
659 count++;
660 seq_printf(m, "%s cache[%d]: %d objects\n",
661 ring->name, j, count);
662
663 list_for_each_entry(obj,
664 &ring->batch_pool.cache_list[j],
665 batch_pool_link) {
666 seq_puts(m, " ");
667 describe_obj(m, obj);
668 seq_putc(m, '\n');
669 }
670
671 total += count;
06fbca71 672 }
493018dc
BV
673 }
674
8d9d5744 675 seq_printf(m, "total: %d\n", total);
493018dc
BV
676
677 mutex_unlock(&dev->struct_mutex);
678
679 return 0;
680}
681
2017263e
BG
682static int i915_gem_request_info(struct seq_file *m, void *data)
683{
9f25d007 684 struct drm_info_node *node = m->private;
2017263e 685 struct drm_device *dev = node->minor->dev;
e277a1f8 686 struct drm_i915_private *dev_priv = dev->dev_private;
a4872ba6 687 struct intel_engine_cs *ring;
eed29a5b 688 struct drm_i915_gem_request *req;
2d1070b2 689 int ret, any, i;
de227ef0
CW
690
691 ret = mutex_lock_interruptible(&dev->struct_mutex);
692 if (ret)
693 return ret;
2017263e 694
2d1070b2 695 any = 0;
a2c7f6fd 696 for_each_ring(ring, dev_priv, i) {
2d1070b2
CW
697 int count;
698
699 count = 0;
eed29a5b 700 list_for_each_entry(req, &ring->request_list, list)
2d1070b2
CW
701 count++;
702 if (count == 0)
a2c7f6fd
CW
703 continue;
704
2d1070b2 705 seq_printf(m, "%s requests: %d\n", ring->name, count);
eed29a5b 706 list_for_each_entry(req, &ring->request_list, list) {
2d1070b2
CW
707 struct task_struct *task;
708
709 rcu_read_lock();
710 task = NULL;
eed29a5b
DV
711 if (req->pid)
712 task = pid_task(req->pid, PIDTYPE_PID);
2d1070b2 713 seq_printf(m, " %x @ %d: %s [%d]\n",
eed29a5b
DV
714 req->seqno,
715 (int) (jiffies - req->emitted_jiffies),
2d1070b2
CW
716 task ? task->comm : "<unknown>",
717 task ? task->pid : -1);
718 rcu_read_unlock();
c2c347a9 719 }
2d1070b2
CW
720
721 any++;
2017263e 722 }
de227ef0
CW
723 mutex_unlock(&dev->struct_mutex);
724
2d1070b2 725 if (any == 0)
267f0c90 726 seq_puts(m, "No requests\n");
c2c347a9 727
2017263e
BG
728 return 0;
729}
730
b2223497 731static void i915_ring_seqno_info(struct seq_file *m,
a4872ba6 732 struct intel_engine_cs *ring)
b2223497
CW
733{
734 if (ring->get_seqno) {
20e28fba 735 seq_printf(m, "Current sequence (%s): %x\n",
b2eadbc8 736 ring->name, ring->get_seqno(ring, false));
b2223497
CW
737 }
738}
739
2017263e
BG
740static int i915_gem_seqno_info(struct seq_file *m, void *data)
741{
9f25d007 742 struct drm_info_node *node = m->private;
2017263e 743 struct drm_device *dev = node->minor->dev;
e277a1f8 744 struct drm_i915_private *dev_priv = dev->dev_private;
a4872ba6 745 struct intel_engine_cs *ring;
1ec14ad3 746 int ret, i;
de227ef0
CW
747
748 ret = mutex_lock_interruptible(&dev->struct_mutex);
749 if (ret)
750 return ret;
c8c8fb33 751 intel_runtime_pm_get(dev_priv);
2017263e 752
a2c7f6fd
CW
753 for_each_ring(ring, dev_priv, i)
754 i915_ring_seqno_info(m, ring);
de227ef0 755
c8c8fb33 756 intel_runtime_pm_put(dev_priv);
de227ef0
CW
757 mutex_unlock(&dev->struct_mutex);
758
2017263e
BG
759 return 0;
760}
761
762
763static int i915_interrupt_info(struct seq_file *m, void *data)
764{
9f25d007 765 struct drm_info_node *node = m->private;
2017263e 766 struct drm_device *dev = node->minor->dev;
e277a1f8 767 struct drm_i915_private *dev_priv = dev->dev_private;
a4872ba6 768 struct intel_engine_cs *ring;
9db4a9c7 769 int ret, i, pipe;
de227ef0
CW
770
771 ret = mutex_lock_interruptible(&dev->struct_mutex);
772 if (ret)
773 return ret;
c8c8fb33 774 intel_runtime_pm_get(dev_priv);
2017263e 775
74e1ca8c 776 if (IS_CHERRYVIEW(dev)) {
74e1ca8c
VS
777 seq_printf(m, "Master Interrupt Control:\t%08x\n",
778 I915_READ(GEN8_MASTER_IRQ));
779
780 seq_printf(m, "Display IER:\t%08x\n",
781 I915_READ(VLV_IER));
782 seq_printf(m, "Display IIR:\t%08x\n",
783 I915_READ(VLV_IIR));
784 seq_printf(m, "Display IIR_RW:\t%08x\n",
785 I915_READ(VLV_IIR_RW));
786 seq_printf(m, "Display IMR:\t%08x\n",
787 I915_READ(VLV_IMR));
055e393f 788 for_each_pipe(dev_priv, pipe)
74e1ca8c
VS
789 seq_printf(m, "Pipe %c stat:\t%08x\n",
790 pipe_name(pipe),
791 I915_READ(PIPESTAT(pipe)));
792
793 seq_printf(m, "Port hotplug:\t%08x\n",
794 I915_READ(PORT_HOTPLUG_EN));
795 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
796 I915_READ(VLV_DPFLIPSTAT));
797 seq_printf(m, "DPINVGTT:\t%08x\n",
798 I915_READ(DPINVGTT));
799
800 for (i = 0; i < 4; i++) {
801 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
802 i, I915_READ(GEN8_GT_IMR(i)));
803 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
804 i, I915_READ(GEN8_GT_IIR(i)));
805 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
806 i, I915_READ(GEN8_GT_IER(i)));
807 }
808
809 seq_printf(m, "PCU interrupt mask:\t%08x\n",
810 I915_READ(GEN8_PCU_IMR));
811 seq_printf(m, "PCU interrupt identity:\t%08x\n",
812 I915_READ(GEN8_PCU_IIR));
813 seq_printf(m, "PCU interrupt enable:\t%08x\n",
814 I915_READ(GEN8_PCU_IER));
815 } else if (INTEL_INFO(dev)->gen >= 8) {
a123f157
BW
816 seq_printf(m, "Master Interrupt Control:\t%08x\n",
817 I915_READ(GEN8_MASTER_IRQ));
818
819 for (i = 0; i < 4; i++) {
820 seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
821 i, I915_READ(GEN8_GT_IMR(i)));
822 seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
823 i, I915_READ(GEN8_GT_IIR(i)));
824 seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
825 i, I915_READ(GEN8_GT_IER(i)));
826 }
827
055e393f 828 for_each_pipe(dev_priv, pipe) {
f458ebbc 829 if (!intel_display_power_is_enabled(dev_priv,
22c59960
PZ
830 POWER_DOMAIN_PIPE(pipe))) {
831 seq_printf(m, "Pipe %c power disabled\n",
832 pipe_name(pipe));
833 continue;
834 }
a123f157 835 seq_printf(m, "Pipe %c IMR:\t%08x\n",
07d27e20
DL
836 pipe_name(pipe),
837 I915_READ(GEN8_DE_PIPE_IMR(pipe)));
a123f157 838 seq_printf(m, "Pipe %c IIR:\t%08x\n",
07d27e20
DL
839 pipe_name(pipe),
840 I915_READ(GEN8_DE_PIPE_IIR(pipe)));
a123f157 841 seq_printf(m, "Pipe %c IER:\t%08x\n",
07d27e20
DL
842 pipe_name(pipe),
843 I915_READ(GEN8_DE_PIPE_IER(pipe)));
a123f157
BW
844 }
845
846 seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
847 I915_READ(GEN8_DE_PORT_IMR));
848 seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
849 I915_READ(GEN8_DE_PORT_IIR));
850 seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
851 I915_READ(GEN8_DE_PORT_IER));
852
853 seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
854 I915_READ(GEN8_DE_MISC_IMR));
855 seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
856 I915_READ(GEN8_DE_MISC_IIR));
857 seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
858 I915_READ(GEN8_DE_MISC_IER));
859
860 seq_printf(m, "PCU interrupt mask:\t%08x\n",
861 I915_READ(GEN8_PCU_IMR));
862 seq_printf(m, "PCU interrupt identity:\t%08x\n",
863 I915_READ(GEN8_PCU_IIR));
864 seq_printf(m, "PCU interrupt enable:\t%08x\n",
865 I915_READ(GEN8_PCU_IER));
866 } else if (IS_VALLEYVIEW(dev)) {
7e231dbe
JB
867 seq_printf(m, "Display IER:\t%08x\n",
868 I915_READ(VLV_IER));
869 seq_printf(m, "Display IIR:\t%08x\n",
870 I915_READ(VLV_IIR));
871 seq_printf(m, "Display IIR_RW:\t%08x\n",
872 I915_READ(VLV_IIR_RW));
873 seq_printf(m, "Display IMR:\t%08x\n",
874 I915_READ(VLV_IMR));
055e393f 875 for_each_pipe(dev_priv, pipe)
7e231dbe
JB
876 seq_printf(m, "Pipe %c stat:\t%08x\n",
877 pipe_name(pipe),
878 I915_READ(PIPESTAT(pipe)));
879
880 seq_printf(m, "Master IER:\t%08x\n",
881 I915_READ(VLV_MASTER_IER));
882
883 seq_printf(m, "Render IER:\t%08x\n",
884 I915_READ(GTIER));
885 seq_printf(m, "Render IIR:\t%08x\n",
886 I915_READ(GTIIR));
887 seq_printf(m, "Render IMR:\t%08x\n",
888 I915_READ(GTIMR));
889
890 seq_printf(m, "PM IER:\t\t%08x\n",
891 I915_READ(GEN6_PMIER));
892 seq_printf(m, "PM IIR:\t\t%08x\n",
893 I915_READ(GEN6_PMIIR));
894 seq_printf(m, "PM IMR:\t\t%08x\n",
895 I915_READ(GEN6_PMIMR));
896
897 seq_printf(m, "Port hotplug:\t%08x\n",
898 I915_READ(PORT_HOTPLUG_EN));
899 seq_printf(m, "DPFLIPSTAT:\t%08x\n",
900 I915_READ(VLV_DPFLIPSTAT));
901 seq_printf(m, "DPINVGTT:\t%08x\n",
902 I915_READ(DPINVGTT));
903
904 } else if (!HAS_PCH_SPLIT(dev)) {
5f6a1695
ZW
905 seq_printf(m, "Interrupt enable: %08x\n",
906 I915_READ(IER));
907 seq_printf(m, "Interrupt identity: %08x\n",
908 I915_READ(IIR));
909 seq_printf(m, "Interrupt mask: %08x\n",
910 I915_READ(IMR));
055e393f 911 for_each_pipe(dev_priv, pipe)
9db4a9c7
JB
912 seq_printf(m, "Pipe %c stat: %08x\n",
913 pipe_name(pipe),
914 I915_READ(PIPESTAT(pipe)));
5f6a1695
ZW
915 } else {
916 seq_printf(m, "North Display Interrupt enable: %08x\n",
917 I915_READ(DEIER));
918 seq_printf(m, "North Display Interrupt identity: %08x\n",
919 I915_READ(DEIIR));
920 seq_printf(m, "North Display Interrupt mask: %08x\n",
921 I915_READ(DEIMR));
922 seq_printf(m, "South Display Interrupt enable: %08x\n",
923 I915_READ(SDEIER));
924 seq_printf(m, "South Display Interrupt identity: %08x\n",
925 I915_READ(SDEIIR));
926 seq_printf(m, "South Display Interrupt mask: %08x\n",
927 I915_READ(SDEIMR));
928 seq_printf(m, "Graphics Interrupt enable: %08x\n",
929 I915_READ(GTIER));
930 seq_printf(m, "Graphics Interrupt identity: %08x\n",
931 I915_READ(GTIIR));
932 seq_printf(m, "Graphics Interrupt mask: %08x\n",
933 I915_READ(GTIMR));
934 }
a2c7f6fd 935 for_each_ring(ring, dev_priv, i) {
a123f157 936 if (INTEL_INFO(dev)->gen >= 6) {
a2c7f6fd
CW
937 seq_printf(m,
938 "Graphics Interrupt mask (%s): %08x\n",
939 ring->name, I915_READ_IMR(ring));
9862e600 940 }
a2c7f6fd 941 i915_ring_seqno_info(m, ring);
9862e600 942 }
c8c8fb33 943 intel_runtime_pm_put(dev_priv);
de227ef0
CW
944 mutex_unlock(&dev->struct_mutex);
945
2017263e
BG
946 return 0;
947}
948
a6172a80
CW
949static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
950{
9f25d007 951 struct drm_info_node *node = m->private;
a6172a80 952 struct drm_device *dev = node->minor->dev;
e277a1f8 953 struct drm_i915_private *dev_priv = dev->dev_private;
de227ef0
CW
954 int i, ret;
955
956 ret = mutex_lock_interruptible(&dev->struct_mutex);
957 if (ret)
958 return ret;
a6172a80
CW
959
960 seq_printf(m, "Reserved fences = %d\n", dev_priv->fence_reg_start);
961 seq_printf(m, "Total fences = %d\n", dev_priv->num_fence_regs);
962 for (i = 0; i < dev_priv->num_fence_regs; i++) {
05394f39 963 struct drm_i915_gem_object *obj = dev_priv->fence_regs[i].obj;
a6172a80 964
6c085a72
CW
965 seq_printf(m, "Fence %d, pin count = %d, object = ",
966 i, dev_priv->fence_regs[i].pin_count);
c2c347a9 967 if (obj == NULL)
267f0c90 968 seq_puts(m, "unused");
c2c347a9 969 else
05394f39 970 describe_obj(m, obj);
267f0c90 971 seq_putc(m, '\n');
a6172a80
CW
972 }
973
05394f39 974 mutex_unlock(&dev->struct_mutex);
a6172a80
CW
975 return 0;
976}
977
2017263e
BG
978static int i915_hws_info(struct seq_file *m, void *data)
979{
9f25d007 980 struct drm_info_node *node = m->private;
2017263e 981 struct drm_device *dev = node->minor->dev;
e277a1f8 982 struct drm_i915_private *dev_priv = dev->dev_private;
a4872ba6 983 struct intel_engine_cs *ring;
1a240d4d 984 const u32 *hws;
4066c0ae
CW
985 int i;
986
1ec14ad3 987 ring = &dev_priv->ring[(uintptr_t)node->info_ent->data];
1a240d4d 988 hws = ring->status_page.page_addr;
2017263e
BG
989 if (hws == NULL)
990 return 0;
991
992 for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
993 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
994 i * 4,
995 hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
996 }
997 return 0;
998}
999
d5442303
DV
1000static ssize_t
1001i915_error_state_write(struct file *filp,
1002 const char __user *ubuf,
1003 size_t cnt,
1004 loff_t *ppos)
1005{
edc3d884 1006 struct i915_error_state_file_priv *error_priv = filp->private_data;
d5442303 1007 struct drm_device *dev = error_priv->dev;
22bcfc6a 1008 int ret;
d5442303
DV
1009
1010 DRM_DEBUG_DRIVER("Resetting error state\n");
1011
22bcfc6a
DV
1012 ret = mutex_lock_interruptible(&dev->struct_mutex);
1013 if (ret)
1014 return ret;
1015
d5442303
DV
1016 i915_destroy_error_state(dev);
1017 mutex_unlock(&dev->struct_mutex);
1018
1019 return cnt;
1020}
1021
1022static int i915_error_state_open(struct inode *inode, struct file *file)
1023{
1024 struct drm_device *dev = inode->i_private;
d5442303 1025 struct i915_error_state_file_priv *error_priv;
d5442303
DV
1026
1027 error_priv = kzalloc(sizeof(*error_priv), GFP_KERNEL);
1028 if (!error_priv)
1029 return -ENOMEM;
1030
1031 error_priv->dev = dev;
1032
95d5bfb3 1033 i915_error_state_get(dev, error_priv);
d5442303 1034
edc3d884
MK
1035 file->private_data = error_priv;
1036
1037 return 0;
d5442303
DV
1038}
1039
1040static int i915_error_state_release(struct inode *inode, struct file *file)
1041{
edc3d884 1042 struct i915_error_state_file_priv *error_priv = file->private_data;
d5442303 1043
95d5bfb3 1044 i915_error_state_put(error_priv);
d5442303
DV
1045 kfree(error_priv);
1046
edc3d884
MK
1047 return 0;
1048}
1049
4dc955f7
MK
1050static ssize_t i915_error_state_read(struct file *file, char __user *userbuf,
1051 size_t count, loff_t *pos)
1052{
1053 struct i915_error_state_file_priv *error_priv = file->private_data;
1054 struct drm_i915_error_state_buf error_str;
1055 loff_t tmp_pos = 0;
1056 ssize_t ret_count = 0;
1057 int ret;
1058
0a4cd7c8 1059 ret = i915_error_state_buf_init(&error_str, to_i915(error_priv->dev), count, *pos);
4dc955f7
MK
1060 if (ret)
1061 return ret;
edc3d884 1062
fc16b48b 1063 ret = i915_error_state_to_str(&error_str, error_priv);
edc3d884
MK
1064 if (ret)
1065 goto out;
1066
edc3d884
MK
1067 ret_count = simple_read_from_buffer(userbuf, count, &tmp_pos,
1068 error_str.buf,
1069 error_str.bytes);
1070
1071 if (ret_count < 0)
1072 ret = ret_count;
1073 else
1074 *pos = error_str.start + ret_count;
1075out:
4dc955f7 1076 i915_error_state_buf_release(&error_str);
edc3d884 1077 return ret ?: ret_count;
d5442303
DV
1078}
1079
1080static const struct file_operations i915_error_state_fops = {
1081 .owner = THIS_MODULE,
1082 .open = i915_error_state_open,
edc3d884 1083 .read = i915_error_state_read,
d5442303
DV
1084 .write = i915_error_state_write,
1085 .llseek = default_llseek,
1086 .release = i915_error_state_release,
1087};
1088
647416f9
KC
1089static int
1090i915_next_seqno_get(void *data, u64 *val)
40633219 1091{
647416f9 1092 struct drm_device *dev = data;
e277a1f8 1093 struct drm_i915_private *dev_priv = dev->dev_private;
40633219
MK
1094 int ret;
1095
1096 ret = mutex_lock_interruptible(&dev->struct_mutex);
1097 if (ret)
1098 return ret;
1099
647416f9 1100 *val = dev_priv->next_seqno;
40633219
MK
1101 mutex_unlock(&dev->struct_mutex);
1102
647416f9 1103 return 0;
40633219
MK
1104}
1105
647416f9
KC
1106static int
1107i915_next_seqno_set(void *data, u64 val)
1108{
1109 struct drm_device *dev = data;
40633219
MK
1110 int ret;
1111
40633219
MK
1112 ret = mutex_lock_interruptible(&dev->struct_mutex);
1113 if (ret)
1114 return ret;
1115
e94fbaa8 1116 ret = i915_gem_set_seqno(dev, val);
40633219
MK
1117 mutex_unlock(&dev->struct_mutex);
1118
647416f9 1119 return ret;
40633219
MK
1120}
1121
647416f9
KC
1122DEFINE_SIMPLE_ATTRIBUTE(i915_next_seqno_fops,
1123 i915_next_seqno_get, i915_next_seqno_set,
3a3b4f98 1124 "0x%llx\n");
40633219 1125
adb4bd12 1126static int i915_frequency_info(struct seq_file *m, void *unused)
f97108d1 1127{
9f25d007 1128 struct drm_info_node *node = m->private;
f97108d1 1129 struct drm_device *dev = node->minor->dev;
e277a1f8 1130 struct drm_i915_private *dev_priv = dev->dev_private;
c8c8fb33
PZ
1131 int ret = 0;
1132
1133 intel_runtime_pm_get(dev_priv);
3b8d8d91 1134
5c9669ce
TR
1135 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1136
3b8d8d91
JB
1137 if (IS_GEN5(dev)) {
1138 u16 rgvswctl = I915_READ16(MEMSWCTL);
1139 u16 rgvstat = I915_READ16(MEMSTAT_ILK);
1140
1141 seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
1142 seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
1143 seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
1144 MEMSTAT_VID_SHIFT);
1145 seq_printf(m, "Current P-state: %d\n",
1146 (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
daa3afb2 1147 } else if (IS_GEN6(dev) || (IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) ||
60260a5b 1148 IS_BROADWELL(dev) || IS_GEN9(dev)) {
35040562
BP
1149 u32 rp_state_limits;
1150 u32 gt_perf_status;
1151 u32 rp_state_cap;
0d8f9491 1152 u32 rpmodectl, rpinclimit, rpdeclimit;
8e8c06cd 1153 u32 rpstat, cagf, reqf;
ccab5c82
JB
1154 u32 rpupei, rpcurup, rpprevup;
1155 u32 rpdownei, rpcurdown, rpprevdown;
9dd3c605 1156 u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
3b8d8d91
JB
1157 int max_freq;
1158
35040562
BP
1159 rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
1160 if (IS_BROXTON(dev)) {
1161 rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
1162 gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
1163 } else {
1164 rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
1165 gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
1166 }
1167
3b8d8d91 1168 /* RPSTAT1 is in the GT power well */
d1ebd816
BW
1169 ret = mutex_lock_interruptible(&dev->struct_mutex);
1170 if (ret)
c8c8fb33 1171 goto out;
d1ebd816 1172
59bad947 1173 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
3b8d8d91 1174
8e8c06cd 1175 reqf = I915_READ(GEN6_RPNSWREQ);
60260a5b
AG
1176 if (IS_GEN9(dev))
1177 reqf >>= 23;
1178 else {
1179 reqf &= ~GEN6_TURBO_DISABLE;
1180 if (IS_HASWELL(dev) || IS_BROADWELL(dev))
1181 reqf >>= 24;
1182 else
1183 reqf >>= 25;
1184 }
7c59a9c1 1185 reqf = intel_gpu_freq(dev_priv, reqf);
8e8c06cd 1186
0d8f9491
CW
1187 rpmodectl = I915_READ(GEN6_RP_CONTROL);
1188 rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
1189 rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
1190
ccab5c82
JB
1191 rpstat = I915_READ(GEN6_RPSTAT1);
1192 rpupei = I915_READ(GEN6_RP_CUR_UP_EI);
1193 rpcurup = I915_READ(GEN6_RP_CUR_UP);
1194 rpprevup = I915_READ(GEN6_RP_PREV_UP);
1195 rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI);
1196 rpcurdown = I915_READ(GEN6_RP_CUR_DOWN);
1197 rpprevdown = I915_READ(GEN6_RP_PREV_DOWN);
60260a5b
AG
1198 if (IS_GEN9(dev))
1199 cagf = (rpstat & GEN9_CAGF_MASK) >> GEN9_CAGF_SHIFT;
1200 else if (IS_HASWELL(dev) || IS_BROADWELL(dev))
f82855d3
BW
1201 cagf = (rpstat & HSW_CAGF_MASK) >> HSW_CAGF_SHIFT;
1202 else
1203 cagf = (rpstat & GEN6_CAGF_MASK) >> GEN6_CAGF_SHIFT;
7c59a9c1 1204 cagf = intel_gpu_freq(dev_priv, cagf);
ccab5c82 1205
59bad947 1206 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
d1ebd816
BW
1207 mutex_unlock(&dev->struct_mutex);
1208
9dd3c605
PZ
1209 if (IS_GEN6(dev) || IS_GEN7(dev)) {
1210 pm_ier = I915_READ(GEN6_PMIER);
1211 pm_imr = I915_READ(GEN6_PMIMR);
1212 pm_isr = I915_READ(GEN6_PMISR);
1213 pm_iir = I915_READ(GEN6_PMIIR);
1214 pm_mask = I915_READ(GEN6_PMINTRMSK);
1215 } else {
1216 pm_ier = I915_READ(GEN8_GT_IER(2));
1217 pm_imr = I915_READ(GEN8_GT_IMR(2));
1218 pm_isr = I915_READ(GEN8_GT_ISR(2));
1219 pm_iir = I915_READ(GEN8_GT_IIR(2));
1220 pm_mask = I915_READ(GEN6_PMINTRMSK);
1221 }
0d8f9491 1222 seq_printf(m, "PM IER=0x%08x IMR=0x%08x ISR=0x%08x IIR=0x%08x, MASK=0x%08x\n",
9dd3c605 1223 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask);
3b8d8d91 1224 seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
3b8d8d91 1225 seq_printf(m, "Render p-state ratio: %d\n",
60260a5b 1226 (gt_perf_status & (IS_GEN9(dev) ? 0x1ff00 : 0xff00)) >> 8);
3b8d8d91
JB
1227 seq_printf(m, "Render p-state VID: %d\n",
1228 gt_perf_status & 0xff);
1229 seq_printf(m, "Render p-state limit: %d\n",
1230 rp_state_limits & 0xff);
0d8f9491
CW
1231 seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
1232 seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
1233 seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
1234 seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
8e8c06cd 1235 seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
f82855d3 1236 seq_printf(m, "CAGF: %dMHz\n", cagf);
ccab5c82
JB
1237 seq_printf(m, "RP CUR UP EI: %dus\n", rpupei &
1238 GEN6_CURICONT_MASK);
1239 seq_printf(m, "RP CUR UP: %dus\n", rpcurup &
1240 GEN6_CURBSYTAVG_MASK);
1241 seq_printf(m, "RP PREV UP: %dus\n", rpprevup &
1242 GEN6_CURBSYTAVG_MASK);
d86ed34a
CW
1243 seq_printf(m, "Up threshold: %d%%\n",
1244 dev_priv->rps.up_threshold);
1245
ccab5c82
JB
1246 seq_printf(m, "RP CUR DOWN EI: %dus\n", rpdownei &
1247 GEN6_CURIAVG_MASK);
1248 seq_printf(m, "RP CUR DOWN: %dus\n", rpcurdown &
1249 GEN6_CURBSYTAVG_MASK);
1250 seq_printf(m, "RP PREV DOWN: %dus\n", rpprevdown &
1251 GEN6_CURBSYTAVG_MASK);
d86ed34a
CW
1252 seq_printf(m, "Down threshold: %d%%\n",
1253 dev_priv->rps.down_threshold);
3b8d8d91 1254
35040562
BP
1255 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 0 :
1256 rp_state_cap >> 16) & 0xff;
60260a5b 1257 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
3b8d8d91 1258 seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
7c59a9c1 1259 intel_gpu_freq(dev_priv, max_freq));
3b8d8d91
JB
1260
1261 max_freq = (rp_state_cap & 0xff00) >> 8;
60260a5b 1262 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
3b8d8d91 1263 seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
7c59a9c1 1264 intel_gpu_freq(dev_priv, max_freq));
3b8d8d91 1265
35040562
BP
1266 max_freq = (IS_BROXTON(dev) ? rp_state_cap >> 16 :
1267 rp_state_cap >> 0) & 0xff;
60260a5b 1268 max_freq *= (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1);
3b8d8d91 1269 seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
7c59a9c1 1270 intel_gpu_freq(dev_priv, max_freq));
31c77388 1271 seq_printf(m, "Max overclocked frequency: %dMHz\n",
7c59a9c1 1272 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
aed242ff 1273
d86ed34a
CW
1274 seq_printf(m, "Current freq: %d MHz\n",
1275 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1276 seq_printf(m, "Actual freq: %d MHz\n", cagf);
aed242ff
CW
1277 seq_printf(m, "Idle freq: %d MHz\n",
1278 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
d86ed34a
CW
1279 seq_printf(m, "Min freq: %d MHz\n",
1280 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
1281 seq_printf(m, "Max freq: %d MHz\n",
1282 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
1283 seq_printf(m,
1284 "efficient (RPe) frequency: %d MHz\n",
1285 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
0a073b84 1286 } else if (IS_VALLEYVIEW(dev)) {
03af2045 1287 u32 freq_sts;
0a073b84 1288
259bd5d4 1289 mutex_lock(&dev_priv->rps.hw_lock);
64936258 1290 freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
0a073b84
JB
1291 seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
1292 seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
1293
d86ed34a
CW
1294 seq_printf(m, "actual GPU freq: %d MHz\n",
1295 intel_gpu_freq(dev_priv, (freq_sts >> 8) & 0xff));
1296
1297 seq_printf(m, "current GPU freq: %d MHz\n",
1298 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq));
1299
0a073b84 1300 seq_printf(m, "max GPU freq: %d MHz\n",
7c59a9c1 1301 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
0a073b84 1302
0a073b84 1303 seq_printf(m, "min GPU freq: %d MHz\n",
7c59a9c1 1304 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq));
03af2045 1305
aed242ff
CW
1306 seq_printf(m, "idle GPU freq: %d MHz\n",
1307 intel_gpu_freq(dev_priv, dev_priv->rps.idle_freq));
1308
7c59a9c1
VS
1309 seq_printf(m,
1310 "efficient (RPe) frequency: %d MHz\n",
1311 intel_gpu_freq(dev_priv, dev_priv->rps.efficient_freq));
259bd5d4 1312 mutex_unlock(&dev_priv->rps.hw_lock);
3b8d8d91 1313 } else {
267f0c90 1314 seq_puts(m, "no P-state info available\n");
3b8d8d91 1315 }
f97108d1 1316
c8c8fb33
PZ
1317out:
1318 intel_runtime_pm_put(dev_priv);
1319 return ret;
f97108d1
JB
1320}
1321
f654449a
CW
1322static int i915_hangcheck_info(struct seq_file *m, void *unused)
1323{
1324 struct drm_info_node *node = m->private;
ebbc7546
MK
1325 struct drm_device *dev = node->minor->dev;
1326 struct drm_i915_private *dev_priv = dev->dev_private;
f654449a 1327 struct intel_engine_cs *ring;
ebbc7546
MK
1328 u64 acthd[I915_NUM_RINGS];
1329 u32 seqno[I915_NUM_RINGS];
f654449a
CW
1330 int i;
1331
1332 if (!i915.enable_hangcheck) {
1333 seq_printf(m, "Hangcheck disabled\n");
1334 return 0;
1335 }
1336
ebbc7546
MK
1337 intel_runtime_pm_get(dev_priv);
1338
1339 for_each_ring(ring, dev_priv, i) {
1340 seqno[i] = ring->get_seqno(ring, false);
1341 acthd[i] = intel_ring_get_active_head(ring);
1342 }
1343
1344 intel_runtime_pm_put(dev_priv);
1345
f654449a
CW
1346 if (delayed_work_pending(&dev_priv->gpu_error.hangcheck_work)) {
1347 seq_printf(m, "Hangcheck active, fires in %dms\n",
1348 jiffies_to_msecs(dev_priv->gpu_error.hangcheck_work.timer.expires -
1349 jiffies));
1350 } else
1351 seq_printf(m, "Hangcheck inactive\n");
1352
1353 for_each_ring(ring, dev_priv, i) {
1354 seq_printf(m, "%s:\n", ring->name);
1355 seq_printf(m, "\tseqno = %x [current %x]\n",
ebbc7546 1356 ring->hangcheck.seqno, seqno[i]);
f654449a
CW
1357 seq_printf(m, "\tACTHD = 0x%08llx [current 0x%08llx]\n",
1358 (long long)ring->hangcheck.acthd,
ebbc7546 1359 (long long)acthd[i]);
f654449a
CW
1360 seq_printf(m, "\tmax ACTHD = 0x%08llx\n",
1361 (long long)ring->hangcheck.max_acthd);
ebbc7546
MK
1362 seq_printf(m, "\tscore = %d\n", ring->hangcheck.score);
1363 seq_printf(m, "\taction = %d\n", ring->hangcheck.action);
f654449a
CW
1364 }
1365
1366 return 0;
1367}
1368
4d85529d 1369static int ironlake_drpc_info(struct seq_file *m)
f97108d1 1370{
9f25d007 1371 struct drm_info_node *node = m->private;
f97108d1 1372 struct drm_device *dev = node->minor->dev;
e277a1f8 1373 struct drm_i915_private *dev_priv = dev->dev_private;
616fdb5a
BW
1374 u32 rgvmodectl, rstdbyctl;
1375 u16 crstandvid;
1376 int ret;
1377
1378 ret = mutex_lock_interruptible(&dev->struct_mutex);
1379 if (ret)
1380 return ret;
c8c8fb33 1381 intel_runtime_pm_get(dev_priv);
616fdb5a
BW
1382
1383 rgvmodectl = I915_READ(MEMMODECTL);
1384 rstdbyctl = I915_READ(RSTDBYCTL);
1385 crstandvid = I915_READ16(CRSTANDVID);
1386
c8c8fb33 1387 intel_runtime_pm_put(dev_priv);
616fdb5a 1388 mutex_unlock(&dev->struct_mutex);
f97108d1
JB
1389
1390 seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ?
1391 "yes" : "no");
1392 seq_printf(m, "Boost freq: %d\n",
1393 (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
1394 MEMMODE_BOOST_FREQ_SHIFT);
1395 seq_printf(m, "HW control enabled: %s\n",
1396 rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no");
1397 seq_printf(m, "SW control enabled: %s\n",
1398 rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no");
1399 seq_printf(m, "Gated voltage change: %s\n",
1400 rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no");
1401 seq_printf(m, "Starting frequency: P%d\n",
1402 (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
7648fa99 1403 seq_printf(m, "Max P-state: P%d\n",
f97108d1 1404 (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
7648fa99
JB
1405 seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
1406 seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
1407 seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
1408 seq_printf(m, "Render standby enabled: %s\n",
1409 (rstdbyctl & RCX_SW_EXIT) ? "no" : "yes");
267f0c90 1410 seq_puts(m, "Current RS state: ");
88271da3
JB
1411 switch (rstdbyctl & RSX_STATUS_MASK) {
1412 case RSX_STATUS_ON:
267f0c90 1413 seq_puts(m, "on\n");
88271da3
JB
1414 break;
1415 case RSX_STATUS_RC1:
267f0c90 1416 seq_puts(m, "RC1\n");
88271da3
JB
1417 break;
1418 case RSX_STATUS_RC1E:
267f0c90 1419 seq_puts(m, "RC1E\n");
88271da3
JB
1420 break;
1421 case RSX_STATUS_RS1:
267f0c90 1422 seq_puts(m, "RS1\n");
88271da3
JB
1423 break;
1424 case RSX_STATUS_RS2:
267f0c90 1425 seq_puts(m, "RS2 (RC6)\n");
88271da3
JB
1426 break;
1427 case RSX_STATUS_RS3:
267f0c90 1428 seq_puts(m, "RC3 (RC6+)\n");
88271da3
JB
1429 break;
1430 default:
267f0c90 1431 seq_puts(m, "unknown\n");
88271da3
JB
1432 break;
1433 }
f97108d1
JB
1434
1435 return 0;
1436}
1437
f65367b5 1438static int i915_forcewake_domains(struct seq_file *m, void *data)
669ab5aa 1439{
b2cff0db
CW
1440 struct drm_info_node *node = m->private;
1441 struct drm_device *dev = node->minor->dev;
1442 struct drm_i915_private *dev_priv = dev->dev_private;
1443 struct intel_uncore_forcewake_domain *fw_domain;
b2cff0db
CW
1444 int i;
1445
1446 spin_lock_irq(&dev_priv->uncore.lock);
1447 for_each_fw_domain(fw_domain, dev_priv, i) {
1448 seq_printf(m, "%s.wake_count = %u\n",
05a2fb15 1449 intel_uncore_forcewake_domain_to_str(i),
b2cff0db
CW
1450 fw_domain->wake_count);
1451 }
1452 spin_unlock_irq(&dev_priv->uncore.lock);
669ab5aa 1453
b2cff0db
CW
1454 return 0;
1455}
1456
1457static int vlv_drpc_info(struct seq_file *m)
1458{
9f25d007 1459 struct drm_info_node *node = m->private;
669ab5aa
D
1460 struct drm_device *dev = node->minor->dev;
1461 struct drm_i915_private *dev_priv = dev->dev_private;
6b312cd3 1462 u32 rpmodectl1, rcctl1, pw_status;
669ab5aa 1463
d46c0517
ID
1464 intel_runtime_pm_get(dev_priv);
1465
6b312cd3 1466 pw_status = I915_READ(VLV_GTLC_PW_STATUS);
669ab5aa
D
1467 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1468 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1469
d46c0517
ID
1470 intel_runtime_pm_put(dev_priv);
1471
669ab5aa
D
1472 seq_printf(m, "Video Turbo Mode: %s\n",
1473 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1474 seq_printf(m, "Turbo enabled: %s\n",
1475 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1476 seq_printf(m, "HW control enabled: %s\n",
1477 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1478 seq_printf(m, "SW control enabled: %s\n",
1479 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1480 GEN6_RP_MEDIA_SW_MODE));
1481 seq_printf(m, "RC6 Enabled: %s\n",
1482 yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
1483 GEN6_RC_CTL_EI_MODE(1))));
1484 seq_printf(m, "Render Power Well: %s\n",
6b312cd3 1485 (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
669ab5aa 1486 seq_printf(m, "Media Power Well: %s\n",
6b312cd3 1487 (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
669ab5aa 1488
9cc19be5
ID
1489 seq_printf(m, "Render RC6 residency since boot: %u\n",
1490 I915_READ(VLV_GT_RENDER_RC6));
1491 seq_printf(m, "Media RC6 residency since boot: %u\n",
1492 I915_READ(VLV_GT_MEDIA_RC6));
1493
f65367b5 1494 return i915_forcewake_domains(m, NULL);
669ab5aa
D
1495}
1496
4d85529d
BW
1497static int gen6_drpc_info(struct seq_file *m)
1498{
9f25d007 1499 struct drm_info_node *node = m->private;
4d85529d
BW
1500 struct drm_device *dev = node->minor->dev;
1501 struct drm_i915_private *dev_priv = dev->dev_private;
ecd8faea 1502 u32 rpmodectl1, gt_core_status, rcctl1, rc6vids = 0;
93b525dc 1503 unsigned forcewake_count;
aee56cff 1504 int count = 0, ret;
4d85529d
BW
1505
1506 ret = mutex_lock_interruptible(&dev->struct_mutex);
1507 if (ret)
1508 return ret;
c8c8fb33 1509 intel_runtime_pm_get(dev_priv);
4d85529d 1510
907b28c5 1511 spin_lock_irq(&dev_priv->uncore.lock);
b2cff0db 1512 forcewake_count = dev_priv->uncore.fw_domain[FW_DOMAIN_ID_RENDER].wake_count;
907b28c5 1513 spin_unlock_irq(&dev_priv->uncore.lock);
93b525dc
DV
1514
1515 if (forcewake_count) {
267f0c90
DL
1516 seq_puts(m, "RC information inaccurate because somebody "
1517 "holds a forcewake reference \n");
4d85529d
BW
1518 } else {
1519 /* NB: we cannot use forcewake, else we read the wrong values */
1520 while (count++ < 50 && (I915_READ_NOTRACE(FORCEWAKE_ACK) & 1))
1521 udelay(10);
1522 seq_printf(m, "RC information accurate: %s\n", yesno(count < 51));
1523 }
1524
1525 gt_core_status = readl(dev_priv->regs + GEN6_GT_CORE_STATUS);
ed71f1b4 1526 trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
4d85529d
BW
1527
1528 rpmodectl1 = I915_READ(GEN6_RP_CONTROL);
1529 rcctl1 = I915_READ(GEN6_RC_CONTROL);
1530 mutex_unlock(&dev->struct_mutex);
44cbd338
BW
1531 mutex_lock(&dev_priv->rps.hw_lock);
1532 sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS, &rc6vids);
1533 mutex_unlock(&dev_priv->rps.hw_lock);
4d85529d 1534
c8c8fb33
PZ
1535 intel_runtime_pm_put(dev_priv);
1536
4d85529d
BW
1537 seq_printf(m, "Video Turbo Mode: %s\n",
1538 yesno(rpmodectl1 & GEN6_RP_MEDIA_TURBO));
1539 seq_printf(m, "HW control enabled: %s\n",
1540 yesno(rpmodectl1 & GEN6_RP_ENABLE));
1541 seq_printf(m, "SW control enabled: %s\n",
1542 yesno((rpmodectl1 & GEN6_RP_MEDIA_MODE_MASK) ==
1543 GEN6_RP_MEDIA_SW_MODE));
fff24e21 1544 seq_printf(m, "RC1e Enabled: %s\n",
4d85529d
BW
1545 yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
1546 seq_printf(m, "RC6 Enabled: %s\n",
1547 yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
1548 seq_printf(m, "Deep RC6 Enabled: %s\n",
1549 yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
1550 seq_printf(m, "Deepest RC6 Enabled: %s\n",
1551 yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
267f0c90 1552 seq_puts(m, "Current RC state: ");
4d85529d
BW
1553 switch (gt_core_status & GEN6_RCn_MASK) {
1554 case GEN6_RC0:
1555 if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
267f0c90 1556 seq_puts(m, "Core Power Down\n");
4d85529d 1557 else
267f0c90 1558 seq_puts(m, "on\n");
4d85529d
BW
1559 break;
1560 case GEN6_RC3:
267f0c90 1561 seq_puts(m, "RC3\n");
4d85529d
BW
1562 break;
1563 case GEN6_RC6:
267f0c90 1564 seq_puts(m, "RC6\n");
4d85529d
BW
1565 break;
1566 case GEN6_RC7:
267f0c90 1567 seq_puts(m, "RC7\n");
4d85529d
BW
1568 break;
1569 default:
267f0c90 1570 seq_puts(m, "Unknown\n");
4d85529d
BW
1571 break;
1572 }
1573
1574 seq_printf(m, "Core Power Down: %s\n",
1575 yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
cce66a28
BW
1576
1577 /* Not exactly sure what this is */
1578 seq_printf(m, "RC6 \"Locked to RPn\" residency since boot: %u\n",
1579 I915_READ(GEN6_GT_GFX_RC6_LOCKED));
1580 seq_printf(m, "RC6 residency since boot: %u\n",
1581 I915_READ(GEN6_GT_GFX_RC6));
1582 seq_printf(m, "RC6+ residency since boot: %u\n",
1583 I915_READ(GEN6_GT_GFX_RC6p));
1584 seq_printf(m, "RC6++ residency since boot: %u\n",
1585 I915_READ(GEN6_GT_GFX_RC6pp));
1586
ecd8faea
BW
1587 seq_printf(m, "RC6 voltage: %dmV\n",
1588 GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
1589 seq_printf(m, "RC6+ voltage: %dmV\n",
1590 GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
1591 seq_printf(m, "RC6++ voltage: %dmV\n",
1592 GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
4d85529d
BW
1593 return 0;
1594}
1595
1596static int i915_drpc_info(struct seq_file *m, void *unused)
1597{
9f25d007 1598 struct drm_info_node *node = m->private;
4d85529d
BW
1599 struct drm_device *dev = node->minor->dev;
1600
669ab5aa
D
1601 if (IS_VALLEYVIEW(dev))
1602 return vlv_drpc_info(m);
ac66cf4b 1603 else if (INTEL_INFO(dev)->gen >= 6)
4d85529d
BW
1604 return gen6_drpc_info(m);
1605 else
1606 return ironlake_drpc_info(m);
1607}
1608
9a851789
DV
1609static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
1610{
1611 struct drm_info_node *node = m->private;
1612 struct drm_device *dev = node->minor->dev;
1613 struct drm_i915_private *dev_priv = dev->dev_private;
1614
1615 seq_printf(m, "FB tracking busy bits: 0x%08x\n",
1616 dev_priv->fb_tracking.busy_bits);
1617
1618 seq_printf(m, "FB tracking flip bits: 0x%08x\n",
1619 dev_priv->fb_tracking.flip_bits);
1620
1621 return 0;
1622}
1623
b5e50c3f
JB
1624static int i915_fbc_status(struct seq_file *m, void *unused)
1625{
9f25d007 1626 struct drm_info_node *node = m->private;
b5e50c3f 1627 struct drm_device *dev = node->minor->dev;
e277a1f8 1628 struct drm_i915_private *dev_priv = dev->dev_private;
b5e50c3f 1629
3a77c4c4 1630 if (!HAS_FBC(dev)) {
267f0c90 1631 seq_puts(m, "FBC unsupported on this chipset\n");
b5e50c3f
JB
1632 return 0;
1633 }
1634
36623ef8 1635 intel_runtime_pm_get(dev_priv);
25ad93fd 1636 mutex_lock(&dev_priv->fbc.lock);
36623ef8 1637
7733b49b 1638 if (intel_fbc_enabled(dev_priv))
267f0c90 1639 seq_puts(m, "FBC enabled\n");
2e8144a5
PZ
1640 else
1641 seq_printf(m, "FBC disabled: %s\n",
1642 intel_no_fbc_reason_str(dev_priv->fbc.no_fbc_reason));
36623ef8 1643
31b9df10
PZ
1644 if (INTEL_INFO(dev_priv)->gen >= 7)
1645 seq_printf(m, "Compressing: %s\n",
1646 yesno(I915_READ(FBC_STATUS2) &
1647 FBC_COMPRESSION_MASK));
1648
25ad93fd 1649 mutex_unlock(&dev_priv->fbc.lock);
36623ef8
PZ
1650 intel_runtime_pm_put(dev_priv);
1651
b5e50c3f
JB
1652 return 0;
1653}
1654
da46f936
RV
1655static int i915_fbc_fc_get(void *data, u64 *val)
1656{
1657 struct drm_device *dev = data;
1658 struct drm_i915_private *dev_priv = dev->dev_private;
1659
1660 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1661 return -ENODEV;
1662
da46f936 1663 *val = dev_priv->fbc.false_color;
da46f936
RV
1664
1665 return 0;
1666}
1667
1668static int i915_fbc_fc_set(void *data, u64 val)
1669{
1670 struct drm_device *dev = data;
1671 struct drm_i915_private *dev_priv = dev->dev_private;
1672 u32 reg;
1673
1674 if (INTEL_INFO(dev)->gen < 7 || !HAS_FBC(dev))
1675 return -ENODEV;
1676
25ad93fd 1677 mutex_lock(&dev_priv->fbc.lock);
da46f936
RV
1678
1679 reg = I915_READ(ILK_DPFC_CONTROL);
1680 dev_priv->fbc.false_color = val;
1681
1682 I915_WRITE(ILK_DPFC_CONTROL, val ?
1683 (reg | FBC_CTL_FALSE_COLOR) :
1684 (reg & ~FBC_CTL_FALSE_COLOR));
1685
25ad93fd 1686 mutex_unlock(&dev_priv->fbc.lock);
da46f936
RV
1687 return 0;
1688}
1689
1690DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_fc_fops,
1691 i915_fbc_fc_get, i915_fbc_fc_set,
1692 "%llu\n");
1693
92d44621
PZ
1694static int i915_ips_status(struct seq_file *m, void *unused)
1695{
9f25d007 1696 struct drm_info_node *node = m->private;
92d44621
PZ
1697 struct drm_device *dev = node->minor->dev;
1698 struct drm_i915_private *dev_priv = dev->dev_private;
1699
f5adf94e 1700 if (!HAS_IPS(dev)) {
92d44621
PZ
1701 seq_puts(m, "not supported\n");
1702 return 0;
1703 }
1704
36623ef8
PZ
1705 intel_runtime_pm_get(dev_priv);
1706
0eaa53f0
RV
1707 seq_printf(m, "Enabled by kernel parameter: %s\n",
1708 yesno(i915.enable_ips));
1709
1710 if (INTEL_INFO(dev)->gen >= 8) {
1711 seq_puts(m, "Currently: unknown\n");
1712 } else {
1713 if (I915_READ(IPS_CTL) & IPS_ENABLE)
1714 seq_puts(m, "Currently: enabled\n");
1715 else
1716 seq_puts(m, "Currently: disabled\n");
1717 }
92d44621 1718
36623ef8
PZ
1719 intel_runtime_pm_put(dev_priv);
1720
92d44621
PZ
1721 return 0;
1722}
1723
4a9bef37
JB
1724static int i915_sr_status(struct seq_file *m, void *unused)
1725{
9f25d007 1726 struct drm_info_node *node = m->private;
4a9bef37 1727 struct drm_device *dev = node->minor->dev;
e277a1f8 1728 struct drm_i915_private *dev_priv = dev->dev_private;
4a9bef37
JB
1729 bool sr_enabled = false;
1730
36623ef8
PZ
1731 intel_runtime_pm_get(dev_priv);
1732
1398261a 1733 if (HAS_PCH_SPLIT(dev))
5ba2aaaa 1734 sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
77b64555
ACO
1735 else if (IS_CRESTLINE(dev) || IS_G4X(dev) ||
1736 IS_I945G(dev) || IS_I945GM(dev))
4a9bef37
JB
1737 sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
1738 else if (IS_I915GM(dev))
1739 sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
1740 else if (IS_PINEVIEW(dev))
1741 sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
77b64555
ACO
1742 else if (IS_VALLEYVIEW(dev))
1743 sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
4a9bef37 1744
36623ef8
PZ
1745 intel_runtime_pm_put(dev_priv);
1746
5ba2aaaa
CW
1747 seq_printf(m, "self-refresh: %s\n",
1748 sr_enabled ? "enabled" : "disabled");
4a9bef37
JB
1749
1750 return 0;
1751}
1752
7648fa99
JB
1753static int i915_emon_status(struct seq_file *m, void *unused)
1754{
9f25d007 1755 struct drm_info_node *node = m->private;
7648fa99 1756 struct drm_device *dev = node->minor->dev;
e277a1f8 1757 struct drm_i915_private *dev_priv = dev->dev_private;
7648fa99 1758 unsigned long temp, chipset, gfx;
de227ef0
CW
1759 int ret;
1760
582be6b4
CW
1761 if (!IS_GEN5(dev))
1762 return -ENODEV;
1763
de227ef0
CW
1764 ret = mutex_lock_interruptible(&dev->struct_mutex);
1765 if (ret)
1766 return ret;
7648fa99
JB
1767
1768 temp = i915_mch_val(dev_priv);
1769 chipset = i915_chipset_val(dev_priv);
1770 gfx = i915_gfx_val(dev_priv);
de227ef0 1771 mutex_unlock(&dev->struct_mutex);
7648fa99
JB
1772
1773 seq_printf(m, "GMCH temp: %ld\n", temp);
1774 seq_printf(m, "Chipset power: %ld\n", chipset);
1775 seq_printf(m, "GFX power: %ld\n", gfx);
1776 seq_printf(m, "Total power: %ld\n", chipset + gfx);
1777
1778 return 0;
1779}
1780
23b2f8bb
JB
1781static int i915_ring_freq_table(struct seq_file *m, void *unused)
1782{
9f25d007 1783 struct drm_info_node *node = m->private;
23b2f8bb 1784 struct drm_device *dev = node->minor->dev;
e277a1f8 1785 struct drm_i915_private *dev_priv = dev->dev_private;
5bfa0199 1786 int ret = 0;
23b2f8bb 1787 int gpu_freq, ia_freq;
f936ec34 1788 unsigned int max_gpu_freq, min_gpu_freq;
23b2f8bb 1789
97d3308a 1790 if (!HAS_CORE_RING_FREQ(dev)) {
267f0c90 1791 seq_puts(m, "unsupported on this chipset\n");
23b2f8bb
JB
1792 return 0;
1793 }
1794
5bfa0199
PZ
1795 intel_runtime_pm_get(dev_priv);
1796
5c9669ce
TR
1797 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
1798
4fc688ce 1799 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
23b2f8bb 1800 if (ret)
5bfa0199 1801 goto out;
23b2f8bb 1802
f936ec34
AG
1803 if (IS_SKYLAKE(dev)) {
1804 /* Convert GT frequency to 50 HZ units */
1805 min_gpu_freq =
1806 dev_priv->rps.min_freq_softlimit / GEN9_FREQ_SCALER;
1807 max_gpu_freq =
1808 dev_priv->rps.max_freq_softlimit / GEN9_FREQ_SCALER;
1809 } else {
1810 min_gpu_freq = dev_priv->rps.min_freq_softlimit;
1811 max_gpu_freq = dev_priv->rps.max_freq_softlimit;
1812 }
1813
267f0c90 1814 seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
23b2f8bb 1815
f936ec34 1816 for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
42c0526c
BW
1817 ia_freq = gpu_freq;
1818 sandybridge_pcode_read(dev_priv,
1819 GEN6_PCODE_READ_MIN_FREQ_TABLE,
1820 &ia_freq);
3ebecd07 1821 seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
f936ec34
AG
1822 intel_gpu_freq(dev_priv, (gpu_freq *
1823 (IS_SKYLAKE(dev) ? GEN9_FREQ_SCALER : 1))),
3ebecd07
CW
1824 ((ia_freq >> 0) & 0xff) * 100,
1825 ((ia_freq >> 8) & 0xff) * 100);
23b2f8bb
JB
1826 }
1827
4fc688ce 1828 mutex_unlock(&dev_priv->rps.hw_lock);
23b2f8bb 1829
5bfa0199
PZ
1830out:
1831 intel_runtime_pm_put(dev_priv);
1832 return ret;
23b2f8bb
JB
1833}
1834
44834a67
CW
1835static int i915_opregion(struct seq_file *m, void *unused)
1836{
9f25d007 1837 struct drm_info_node *node = m->private;
44834a67 1838 struct drm_device *dev = node->minor->dev;
e277a1f8 1839 struct drm_i915_private *dev_priv = dev->dev_private;
44834a67 1840 struct intel_opregion *opregion = &dev_priv->opregion;
0d38f009 1841 void *data = kmalloc(OPREGION_SIZE, GFP_KERNEL);
44834a67
CW
1842 int ret;
1843
0d38f009
DV
1844 if (data == NULL)
1845 return -ENOMEM;
1846
44834a67
CW
1847 ret = mutex_lock_interruptible(&dev->struct_mutex);
1848 if (ret)
0d38f009 1849 goto out;
44834a67 1850
0d38f009
DV
1851 if (opregion->header) {
1852 memcpy_fromio(data, opregion->header, OPREGION_SIZE);
1853 seq_write(m, data, OPREGION_SIZE);
1854 }
44834a67
CW
1855
1856 mutex_unlock(&dev->struct_mutex);
1857
0d38f009
DV
1858out:
1859 kfree(data);
44834a67
CW
1860 return 0;
1861}
1862
37811fcc
CW
1863static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
1864{
9f25d007 1865 struct drm_info_node *node = m->private;
37811fcc 1866 struct drm_device *dev = node->minor->dev;
4520f53a 1867 struct intel_fbdev *ifbdev = NULL;
37811fcc 1868 struct intel_framebuffer *fb;
3a58ee10 1869 struct drm_framebuffer *drm_fb;
37811fcc 1870
4520f53a
DV
1871#ifdef CONFIG_DRM_I915_FBDEV
1872 struct drm_i915_private *dev_priv = dev->dev_private;
37811fcc
CW
1873
1874 ifbdev = dev_priv->fbdev;
1875 fb = to_intel_framebuffer(ifbdev->helper.fb);
1876
c1ca506d 1877 seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
37811fcc
CW
1878 fb->base.width,
1879 fb->base.height,
1880 fb->base.depth,
623f9783 1881 fb->base.bits_per_pixel,
c1ca506d 1882 fb->base.modifier[0],
623f9783 1883 atomic_read(&fb->base.refcount.refcount));
05394f39 1884 describe_obj(m, fb->obj);
267f0c90 1885 seq_putc(m, '\n');
4520f53a 1886#endif
37811fcc 1887
4b096ac1 1888 mutex_lock(&dev->mode_config.fb_lock);
3a58ee10
DV
1889 drm_for_each_fb(drm_fb, dev) {
1890 fb = to_intel_framebuffer(drm_fb);
131a56dc 1891 if (ifbdev && &fb->base == ifbdev->helper.fb)
37811fcc
CW
1892 continue;
1893
c1ca506d 1894 seq_printf(m, "user size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
37811fcc
CW
1895 fb->base.width,
1896 fb->base.height,
1897 fb->base.depth,
623f9783 1898 fb->base.bits_per_pixel,
c1ca506d 1899 fb->base.modifier[0],
623f9783 1900 atomic_read(&fb->base.refcount.refcount));
05394f39 1901 describe_obj(m, fb->obj);
267f0c90 1902 seq_putc(m, '\n');
37811fcc 1903 }
4b096ac1 1904 mutex_unlock(&dev->mode_config.fb_lock);
37811fcc
CW
1905
1906 return 0;
1907}
1908
c9fe99bd
OM
1909static void describe_ctx_ringbuf(struct seq_file *m,
1910 struct intel_ringbuffer *ringbuf)
1911{
1912 seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, last head: %d)",
1913 ringbuf->space, ringbuf->head, ringbuf->tail,
1914 ringbuf->last_retired_head);
1915}
1916
e76d3630
BW
1917static int i915_context_status(struct seq_file *m, void *unused)
1918{
9f25d007 1919 struct drm_info_node *node = m->private;
e76d3630 1920 struct drm_device *dev = node->minor->dev;
e277a1f8 1921 struct drm_i915_private *dev_priv = dev->dev_private;
a4872ba6 1922 struct intel_engine_cs *ring;
273497e5 1923 struct intel_context *ctx;
a168c293 1924 int ret, i;
e76d3630 1925
f3d28878 1926 ret = mutex_lock_interruptible(&dev->struct_mutex);
e76d3630
BW
1927 if (ret)
1928 return ret;
1929
a33afea5 1930 list_for_each_entry(ctx, &dev_priv->context_list, link) {
c9fe99bd
OM
1931 if (!i915.enable_execlists &&
1932 ctx->legacy_hw_ctx.rcs_state == NULL)
b77f6997
CW
1933 continue;
1934
a33afea5 1935 seq_puts(m, "HW context ");
3ccfd19d 1936 describe_ctx(m, ctx);
c9fe99bd 1937 for_each_ring(ring, dev_priv, i) {
a33afea5 1938 if (ring->default_context == ctx)
c9fe99bd
OM
1939 seq_printf(m, "(default context %s) ",
1940 ring->name);
1941 }
1942
1943 if (i915.enable_execlists) {
1944 seq_putc(m, '\n');
1945 for_each_ring(ring, dev_priv, i) {
1946 struct drm_i915_gem_object *ctx_obj =
1947 ctx->engine[i].state;
1948 struct intel_ringbuffer *ringbuf =
1949 ctx->engine[i].ringbuf;
1950
1951 seq_printf(m, "%s: ", ring->name);
1952 if (ctx_obj)
1953 describe_obj(m, ctx_obj);
1954 if (ringbuf)
1955 describe_ctx_ringbuf(m, ringbuf);
1956 seq_putc(m, '\n');
1957 }
1958 } else {
1959 describe_obj(m, ctx->legacy_hw_ctx.rcs_state);
1960 }
a33afea5 1961
a33afea5 1962 seq_putc(m, '\n');
a168c293
BW
1963 }
1964
f3d28878 1965 mutex_unlock(&dev->struct_mutex);
e76d3630
BW
1966
1967 return 0;
1968}
1969
064ca1d2
TD
1970static void i915_dump_lrc_obj(struct seq_file *m,
1971 struct intel_engine_cs *ring,
1972 struct drm_i915_gem_object *ctx_obj)
1973{
1974 struct page *page;
1975 uint32_t *reg_state;
1976 int j;
1977 unsigned long ggtt_offset = 0;
1978
1979 if (ctx_obj == NULL) {
1980 seq_printf(m, "Context on %s with no gem object\n",
1981 ring->name);
1982 return;
1983 }
1984
1985 seq_printf(m, "CONTEXT: %s %u\n", ring->name,
1986 intel_execlists_ctx_id(ctx_obj));
1987
1988 if (!i915_gem_obj_ggtt_bound(ctx_obj))
1989 seq_puts(m, "\tNot bound in GGTT\n");
1990 else
1991 ggtt_offset = i915_gem_obj_ggtt_offset(ctx_obj);
1992
1993 if (i915_gem_object_get_pages(ctx_obj)) {
1994 seq_puts(m, "\tFailed to get pages for context object\n");
1995 return;
1996 }
1997
1998 page = i915_gem_object_get_page(ctx_obj, 1);
1999 if (!WARN_ON(page == NULL)) {
2000 reg_state = kmap_atomic(page);
2001
2002 for (j = 0; j < 0x600 / sizeof(u32) / 4; j += 4) {
2003 seq_printf(m, "\t[0x%08lx] 0x%08x 0x%08x 0x%08x 0x%08x\n",
2004 ggtt_offset + 4096 + (j * 4),
2005 reg_state[j], reg_state[j + 1],
2006 reg_state[j + 2], reg_state[j + 3]);
2007 }
2008 kunmap_atomic(reg_state);
2009 }
2010
2011 seq_putc(m, '\n');
2012}
2013
c0ab1ae9
BW
2014static int i915_dump_lrc(struct seq_file *m, void *unused)
2015{
2016 struct drm_info_node *node = (struct drm_info_node *) m->private;
2017 struct drm_device *dev = node->minor->dev;
2018 struct drm_i915_private *dev_priv = dev->dev_private;
2019 struct intel_engine_cs *ring;
2020 struct intel_context *ctx;
2021 int ret, i;
2022
2023 if (!i915.enable_execlists) {
2024 seq_printf(m, "Logical Ring Contexts are disabled\n");
2025 return 0;
2026 }
2027
2028 ret = mutex_lock_interruptible(&dev->struct_mutex);
2029 if (ret)
2030 return ret;
2031
2032 list_for_each_entry(ctx, &dev_priv->context_list, link) {
2033 for_each_ring(ring, dev_priv, i) {
064ca1d2
TD
2034 if (ring->default_context != ctx)
2035 i915_dump_lrc_obj(m, ring,
2036 ctx->engine[i].state);
c0ab1ae9
BW
2037 }
2038 }
2039
2040 mutex_unlock(&dev->struct_mutex);
2041
2042 return 0;
2043}
2044
4ba70e44
OM
2045static int i915_execlists(struct seq_file *m, void *data)
2046{
2047 struct drm_info_node *node = (struct drm_info_node *)m->private;
2048 struct drm_device *dev = node->minor->dev;
2049 struct drm_i915_private *dev_priv = dev->dev_private;
2050 struct intel_engine_cs *ring;
2051 u32 status_pointer;
2052 u8 read_pointer;
2053 u8 write_pointer;
2054 u32 status;
2055 u32 ctx_id;
2056 struct list_head *cursor;
2057 int ring_id, i;
2058 int ret;
2059
2060 if (!i915.enable_execlists) {
2061 seq_puts(m, "Logical Ring Contexts are disabled\n");
2062 return 0;
2063 }
2064
2065 ret = mutex_lock_interruptible(&dev->struct_mutex);
2066 if (ret)
2067 return ret;
2068
fc0412ec
MT
2069 intel_runtime_pm_get(dev_priv);
2070
4ba70e44 2071 for_each_ring(ring, dev_priv, ring_id) {
6d3d8274 2072 struct drm_i915_gem_request *head_req = NULL;
4ba70e44
OM
2073 int count = 0;
2074 unsigned long flags;
2075
2076 seq_printf(m, "%s\n", ring->name);
2077
2078 status = I915_READ(RING_EXECLIST_STATUS(ring));
2079 ctx_id = I915_READ(RING_EXECLIST_STATUS(ring) + 4);
2080 seq_printf(m, "\tExeclist status: 0x%08X, context: %u\n",
2081 status, ctx_id);
2082
2083 status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring));
2084 seq_printf(m, "\tStatus pointer: 0x%08X\n", status_pointer);
2085
2086 read_pointer = ring->next_context_status_buffer;
2087 write_pointer = status_pointer & 0x07;
2088 if (read_pointer > write_pointer)
2089 write_pointer += 6;
2090 seq_printf(m, "\tRead pointer: 0x%08X, write pointer 0x%08X\n",
2091 read_pointer, write_pointer);
2092
2093 for (i = 0; i < 6; i++) {
2094 status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i);
2095 ctx_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + 8*i + 4);
2096
2097 seq_printf(m, "\tStatus buffer %d: 0x%08X, context: %u\n",
2098 i, status, ctx_id);
2099 }
2100
2101 spin_lock_irqsave(&ring->execlist_lock, flags);
2102 list_for_each(cursor, &ring->execlist_queue)
2103 count++;
2104 head_req = list_first_entry_or_null(&ring->execlist_queue,
6d3d8274 2105 struct drm_i915_gem_request, execlist_link);
4ba70e44
OM
2106 spin_unlock_irqrestore(&ring->execlist_lock, flags);
2107
2108 seq_printf(m, "\t%d requests in queue\n", count);
2109 if (head_req) {
2110 struct drm_i915_gem_object *ctx_obj;
2111
6d3d8274 2112 ctx_obj = head_req->ctx->engine[ring_id].state;
4ba70e44
OM
2113 seq_printf(m, "\tHead request id: %u\n",
2114 intel_execlists_ctx_id(ctx_obj));
2115 seq_printf(m, "\tHead request tail: %u\n",
6d3d8274 2116 head_req->tail);
4ba70e44
OM
2117 }
2118
2119 seq_putc(m, '\n');
2120 }
2121
fc0412ec 2122 intel_runtime_pm_put(dev_priv);
4ba70e44
OM
2123 mutex_unlock(&dev->struct_mutex);
2124
2125 return 0;
2126}
2127
ea16a3cd
DV
2128static const char *swizzle_string(unsigned swizzle)
2129{
aee56cff 2130 switch (swizzle) {
ea16a3cd
DV
2131 case I915_BIT_6_SWIZZLE_NONE:
2132 return "none";
2133 case I915_BIT_6_SWIZZLE_9:
2134 return "bit9";
2135 case I915_BIT_6_SWIZZLE_9_10:
2136 return "bit9/bit10";
2137 case I915_BIT_6_SWIZZLE_9_11:
2138 return "bit9/bit11";
2139 case I915_BIT_6_SWIZZLE_9_10_11:
2140 return "bit9/bit10/bit11";
2141 case I915_BIT_6_SWIZZLE_9_17:
2142 return "bit9/bit17";
2143 case I915_BIT_6_SWIZZLE_9_10_17:
2144 return "bit9/bit10/bit17";
2145 case I915_BIT_6_SWIZZLE_UNKNOWN:
8a168ca7 2146 return "unknown";
ea16a3cd
DV
2147 }
2148
2149 return "bug";
2150}
2151
2152static int i915_swizzle_info(struct seq_file *m, void *data)
2153{
9f25d007 2154 struct drm_info_node *node = m->private;
ea16a3cd
DV
2155 struct drm_device *dev = node->minor->dev;
2156 struct drm_i915_private *dev_priv = dev->dev_private;
22bcfc6a
DV
2157 int ret;
2158
2159 ret = mutex_lock_interruptible(&dev->struct_mutex);
2160 if (ret)
2161 return ret;
c8c8fb33 2162 intel_runtime_pm_get(dev_priv);
ea16a3cd 2163
ea16a3cd
DV
2164 seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
2165 swizzle_string(dev_priv->mm.bit_6_swizzle_x));
2166 seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
2167 swizzle_string(dev_priv->mm.bit_6_swizzle_y));
2168
2169 if (IS_GEN3(dev) || IS_GEN4(dev)) {
2170 seq_printf(m, "DDC = 0x%08x\n",
2171 I915_READ(DCC));
656bfa3a
DV
2172 seq_printf(m, "DDC2 = 0x%08x\n",
2173 I915_READ(DCC2));
ea16a3cd
DV
2174 seq_printf(m, "C0DRB3 = 0x%04x\n",
2175 I915_READ16(C0DRB3));
2176 seq_printf(m, "C1DRB3 = 0x%04x\n",
2177 I915_READ16(C1DRB3));
9d3203e1 2178 } else if (INTEL_INFO(dev)->gen >= 6) {
3fa7d235
DV
2179 seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
2180 I915_READ(MAD_DIMM_C0));
2181 seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
2182 I915_READ(MAD_DIMM_C1));
2183 seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
2184 I915_READ(MAD_DIMM_C2));
2185 seq_printf(m, "TILECTL = 0x%08x\n",
2186 I915_READ(TILECTL));
5907f5fb 2187 if (INTEL_INFO(dev)->gen >= 8)
9d3203e1
BW
2188 seq_printf(m, "GAMTARBMODE = 0x%08x\n",
2189 I915_READ(GAMTARBMODE));
2190 else
2191 seq_printf(m, "ARB_MODE = 0x%08x\n",
2192 I915_READ(ARB_MODE));
3fa7d235
DV
2193 seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
2194 I915_READ(DISP_ARB_CTL));
ea16a3cd 2195 }
656bfa3a
DV
2196
2197 if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
2198 seq_puts(m, "L-shaped memory detected\n");
2199
c8c8fb33 2200 intel_runtime_pm_put(dev_priv);
ea16a3cd
DV
2201 mutex_unlock(&dev->struct_mutex);
2202
2203 return 0;
2204}
2205
1c60fef5
BW
2206static int per_file_ctx(int id, void *ptr, void *data)
2207{
273497e5 2208 struct intel_context *ctx = ptr;
1c60fef5 2209 struct seq_file *m = data;
ae6c4806
DV
2210 struct i915_hw_ppgtt *ppgtt = ctx->ppgtt;
2211
2212 if (!ppgtt) {
2213 seq_printf(m, " no ppgtt for context %d\n",
2214 ctx->user_handle);
2215 return 0;
2216 }
1c60fef5 2217
f83d6518
OM
2218 if (i915_gem_context_is_default(ctx))
2219 seq_puts(m, " default context:\n");
2220 else
821d66dd 2221 seq_printf(m, " context %d:\n", ctx->user_handle);
1c60fef5
BW
2222 ppgtt->debug_dump(ppgtt, m);
2223
2224 return 0;
2225}
2226
77df6772 2227static void gen8_ppgtt_info(struct seq_file *m, struct drm_device *dev)
3cf17fc5 2228{
3cf17fc5 2229 struct drm_i915_private *dev_priv = dev->dev_private;
a4872ba6 2230 struct intel_engine_cs *ring;
77df6772
BW
2231 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2232 int unused, i;
3cf17fc5 2233
77df6772
BW
2234 if (!ppgtt)
2235 return;
2236
77df6772
BW
2237 for_each_ring(ring, dev_priv, unused) {
2238 seq_printf(m, "%s\n", ring->name);
2239 for (i = 0; i < 4; i++) {
2240 u32 offset = 0x270 + i * 8;
2241 u64 pdp = I915_READ(ring->mmio_base + offset + 4);
2242 pdp <<= 32;
2243 pdp |= I915_READ(ring->mmio_base + offset);
a2a5b15c 2244 seq_printf(m, "\tPDP%d 0x%016llx\n", i, pdp);
77df6772
BW
2245 }
2246 }
2247}
2248
2249static void gen6_ppgtt_info(struct seq_file *m, struct drm_device *dev)
2250{
2251 struct drm_i915_private *dev_priv = dev->dev_private;
a4872ba6 2252 struct intel_engine_cs *ring;
1c60fef5 2253 struct drm_file *file;
77df6772 2254 int i;
3cf17fc5 2255
3cf17fc5
DV
2256 if (INTEL_INFO(dev)->gen == 6)
2257 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(GFX_MODE));
2258
a2c7f6fd 2259 for_each_ring(ring, dev_priv, i) {
3cf17fc5
DV
2260 seq_printf(m, "%s\n", ring->name);
2261 if (INTEL_INFO(dev)->gen == 7)
2262 seq_printf(m, "GFX_MODE: 0x%08x\n", I915_READ(RING_MODE_GEN7(ring)));
2263 seq_printf(m, "PP_DIR_BASE: 0x%08x\n", I915_READ(RING_PP_DIR_BASE(ring)));
2264 seq_printf(m, "PP_DIR_BASE_READ: 0x%08x\n", I915_READ(RING_PP_DIR_BASE_READ(ring)));
2265 seq_printf(m, "PP_DIR_DCLV: 0x%08x\n", I915_READ(RING_PP_DIR_DCLV(ring)));
2266 }
2267 if (dev_priv->mm.aliasing_ppgtt) {
2268 struct i915_hw_ppgtt *ppgtt = dev_priv->mm.aliasing_ppgtt;
2269
267f0c90 2270 seq_puts(m, "aliasing PPGTT:\n");
44159ddb 2271 seq_printf(m, "pd gtt offset: 0x%08x\n", ppgtt->pd.base.ggtt_offset);
1c60fef5 2272
87d60b63 2273 ppgtt->debug_dump(ppgtt, m);
ae6c4806 2274 }
1c60fef5
BW
2275
2276 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2277 struct drm_i915_file_private *file_priv = file->driver_priv;
1c60fef5 2278
1c60fef5
BW
2279 seq_printf(m, "proc: %s\n",
2280 get_pid_task(file->pid, PIDTYPE_PID)->comm);
1c60fef5 2281 idr_for_each(&file_priv->context_idr, per_file_ctx, m);
3cf17fc5
DV
2282 }
2283 seq_printf(m, "ECOCHK: 0x%08x\n", I915_READ(GAM_ECOCHK));
77df6772
BW
2284}
2285
2286static int i915_ppgtt_info(struct seq_file *m, void *data)
2287{
9f25d007 2288 struct drm_info_node *node = m->private;
77df6772 2289 struct drm_device *dev = node->minor->dev;
c8c8fb33 2290 struct drm_i915_private *dev_priv = dev->dev_private;
77df6772
BW
2291
2292 int ret = mutex_lock_interruptible(&dev->struct_mutex);
2293 if (ret)
2294 return ret;
c8c8fb33 2295 intel_runtime_pm_get(dev_priv);
77df6772
BW
2296
2297 if (INTEL_INFO(dev)->gen >= 8)
2298 gen8_ppgtt_info(m, dev);
2299 else if (INTEL_INFO(dev)->gen >= 6)
2300 gen6_ppgtt_info(m, dev);
2301
c8c8fb33 2302 intel_runtime_pm_put(dev_priv);
3cf17fc5
DV
2303 mutex_unlock(&dev->struct_mutex);
2304
2305 return 0;
2306}
2307
f5a4c67d
CW
2308static int count_irq_waiters(struct drm_i915_private *i915)
2309{
2310 struct intel_engine_cs *ring;
2311 int count = 0;
2312 int i;
2313
2314 for_each_ring(ring, i915, i)
2315 count += ring->irq_refcount;
2316
2317 return count;
2318}
2319
1854d5ca
CW
2320static int i915_rps_boost_info(struct seq_file *m, void *data)
2321{
2322 struct drm_info_node *node = m->private;
2323 struct drm_device *dev = node->minor->dev;
2324 struct drm_i915_private *dev_priv = dev->dev_private;
2325 struct drm_file *file;
1854d5ca 2326
f5a4c67d
CW
2327 seq_printf(m, "RPS enabled? %d\n", dev_priv->rps.enabled);
2328 seq_printf(m, "GPU busy? %d\n", dev_priv->mm.busy);
2329 seq_printf(m, "CPU waiting? %d\n", count_irq_waiters(dev_priv));
2330 seq_printf(m, "Frequency requested %d; min hard:%d, soft:%d; max soft:%d, hard:%d\n",
2331 intel_gpu_freq(dev_priv, dev_priv->rps.cur_freq),
2332 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq),
2333 intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit),
2334 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit),
2335 intel_gpu_freq(dev_priv, dev_priv->rps.max_freq));
8d3afd7d 2336 spin_lock(&dev_priv->rps.client_lock);
1854d5ca
CW
2337 list_for_each_entry_reverse(file, &dev->filelist, lhead) {
2338 struct drm_i915_file_private *file_priv = file->driver_priv;
2339 struct task_struct *task;
2340
2341 rcu_read_lock();
2342 task = pid_task(file->pid, PIDTYPE_PID);
2343 seq_printf(m, "%s [%d]: %d boosts%s\n",
2344 task ? task->comm : "<unknown>",
2345 task ? task->pid : -1,
2e1b8730
CW
2346 file_priv->rps.boosts,
2347 list_empty(&file_priv->rps.link) ? "" : ", active");
1854d5ca
CW
2348 rcu_read_unlock();
2349 }
2e1b8730
CW
2350 seq_printf(m, "Semaphore boosts: %d%s\n",
2351 dev_priv->rps.semaphores.boosts,
2352 list_empty(&dev_priv->rps.semaphores.link) ? "" : ", active");
2353 seq_printf(m, "MMIO flip boosts: %d%s\n",
2354 dev_priv->rps.mmioflips.boosts,
2355 list_empty(&dev_priv->rps.mmioflips.link) ? "" : ", active");
1854d5ca 2356 seq_printf(m, "Kernel boosts: %d\n", dev_priv->rps.boosts);
8d3afd7d 2357 spin_unlock(&dev_priv->rps.client_lock);
1854d5ca 2358
8d3afd7d 2359 return 0;
1854d5ca
CW
2360}
2361
63573eb7
BW
2362static int i915_llc(struct seq_file *m, void *data)
2363{
9f25d007 2364 struct drm_info_node *node = m->private;
63573eb7
BW
2365 struct drm_device *dev = node->minor->dev;
2366 struct drm_i915_private *dev_priv = dev->dev_private;
2367
2368 /* Size calculation for LLC is a bit of a pain. Ignore for now. */
2369 seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev)));
2370 seq_printf(m, "eLLC: %zuMB\n", dev_priv->ellc_size);
2371
2372 return 0;
2373}
2374
e91fd8c6
RV
2375static int i915_edp_psr_status(struct seq_file *m, void *data)
2376{
2377 struct drm_info_node *node = m->private;
2378 struct drm_device *dev = node->minor->dev;
2379 struct drm_i915_private *dev_priv = dev->dev_private;
a031d709 2380 u32 psrperf = 0;
a6cbdb8e
RV
2381 u32 stat[3];
2382 enum pipe pipe;
a031d709 2383 bool enabled = false;
e91fd8c6 2384
3553a8ea
DL
2385 if (!HAS_PSR(dev)) {
2386 seq_puts(m, "PSR not supported\n");
2387 return 0;
2388 }
2389
c8c8fb33
PZ
2390 intel_runtime_pm_get(dev_priv);
2391
fa128fa6 2392 mutex_lock(&dev_priv->psr.lock);
a031d709
RV
2393 seq_printf(m, "Sink_Support: %s\n", yesno(dev_priv->psr.sink_support));
2394 seq_printf(m, "Source_OK: %s\n", yesno(dev_priv->psr.source_ok));
2807cf69 2395 seq_printf(m, "Enabled: %s\n", yesno((bool)dev_priv->psr.enabled));
5755c78f 2396 seq_printf(m, "Active: %s\n", yesno(dev_priv->psr.active));
fa128fa6
DV
2397 seq_printf(m, "Busy frontbuffer bits: 0x%03x\n",
2398 dev_priv->psr.busy_frontbuffer_bits);
2399 seq_printf(m, "Re-enable work scheduled: %s\n",
2400 yesno(work_busy(&dev_priv->psr.work.work)));
e91fd8c6 2401
3553a8ea
DL
2402 if (HAS_DDI(dev))
2403 enabled = I915_READ(EDP_PSR_CTL(dev)) & EDP_PSR_ENABLE;
2404 else {
2405 for_each_pipe(dev_priv, pipe) {
2406 stat[pipe] = I915_READ(VLV_PSRSTAT(pipe)) &
2407 VLV_EDP_PSR_CURR_STATE_MASK;
2408 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2409 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2410 enabled = true;
a6cbdb8e
RV
2411 }
2412 }
2413 seq_printf(m, "HW Enabled & Active bit: %s", yesno(enabled));
2414
2415 if (!HAS_DDI(dev))
2416 for_each_pipe(dev_priv, pipe) {
2417 if ((stat[pipe] == VLV_EDP_PSR_ACTIVE_NORFB_UP) ||
2418 (stat[pipe] == VLV_EDP_PSR_ACTIVE_SF_UPDATE))
2419 seq_printf(m, " pipe %c", pipe_name(pipe));
2420 }
2421 seq_puts(m, "\n");
e91fd8c6 2422
a6cbdb8e 2423 /* CHV PSR has no kind of performance counter */
3553a8ea 2424 if (HAS_DDI(dev)) {
a031d709
RV
2425 psrperf = I915_READ(EDP_PSR_PERF_CNT(dev)) &
2426 EDP_PSR_PERF_CNT_MASK;
a6cbdb8e
RV
2427
2428 seq_printf(m, "Performance_Counter: %u\n", psrperf);
2429 }
fa128fa6 2430 mutex_unlock(&dev_priv->psr.lock);
e91fd8c6 2431
c8c8fb33 2432 intel_runtime_pm_put(dev_priv);
e91fd8c6
RV
2433 return 0;
2434}
2435
d2e216d0
RV
2436static int i915_sink_crc(struct seq_file *m, void *data)
2437{
2438 struct drm_info_node *node = m->private;
2439 struct drm_device *dev = node->minor->dev;
2440 struct intel_encoder *encoder;
2441 struct intel_connector *connector;
2442 struct intel_dp *intel_dp = NULL;
2443 int ret;
2444 u8 crc[6];
2445
2446 drm_modeset_lock_all(dev);
aca5e361 2447 for_each_intel_connector(dev, connector) {
d2e216d0
RV
2448
2449 if (connector->base.dpms != DRM_MODE_DPMS_ON)
2450 continue;
2451
b6ae3c7c
PZ
2452 if (!connector->base.encoder)
2453 continue;
2454
d2e216d0
RV
2455 encoder = to_intel_encoder(connector->base.encoder);
2456 if (encoder->type != INTEL_OUTPUT_EDP)
2457 continue;
2458
2459 intel_dp = enc_to_intel_dp(&encoder->base);
2460
2461 ret = intel_dp_sink_crc(intel_dp, crc);
2462 if (ret)
2463 goto out;
2464
2465 seq_printf(m, "%02x%02x%02x%02x%02x%02x\n",
2466 crc[0], crc[1], crc[2],
2467 crc[3], crc[4], crc[5]);
2468 goto out;
2469 }
2470 ret = -ENODEV;
2471out:
2472 drm_modeset_unlock_all(dev);
2473 return ret;
2474}
2475
ec013e7f
JB
2476static int i915_energy_uJ(struct seq_file *m, void *data)
2477{
2478 struct drm_info_node *node = m->private;
2479 struct drm_device *dev = node->minor->dev;
2480 struct drm_i915_private *dev_priv = dev->dev_private;
2481 u64 power;
2482 u32 units;
2483
2484 if (INTEL_INFO(dev)->gen < 6)
2485 return -ENODEV;
2486
36623ef8
PZ
2487 intel_runtime_pm_get(dev_priv);
2488
ec013e7f
JB
2489 rdmsrl(MSR_RAPL_POWER_UNIT, power);
2490 power = (power & 0x1f00) >> 8;
2491 units = 1000000 / (1 << power); /* convert to uJ */
2492 power = I915_READ(MCH_SECP_NRG_STTS);
2493 power *= units;
2494
36623ef8
PZ
2495 intel_runtime_pm_put(dev_priv);
2496
ec013e7f 2497 seq_printf(m, "%llu", (long long unsigned)power);
371db66a
PZ
2498
2499 return 0;
2500}
2501
6455c870 2502static int i915_runtime_pm_status(struct seq_file *m, void *unused)
371db66a 2503{
9f25d007 2504 struct drm_info_node *node = m->private;
371db66a
PZ
2505 struct drm_device *dev = node->minor->dev;
2506 struct drm_i915_private *dev_priv = dev->dev_private;
2507
6455c870 2508 if (!HAS_RUNTIME_PM(dev)) {
371db66a
PZ
2509 seq_puts(m, "not supported\n");
2510 return 0;
2511 }
2512
86c4ec0d 2513 seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->mm.busy));
371db66a 2514 seq_printf(m, "IRQs disabled: %s\n",
9df7575f 2515 yesno(!intel_irqs_enabled(dev_priv)));
0d804184 2516#ifdef CONFIG_PM
a6aaec8b
DL
2517 seq_printf(m, "Usage count: %d\n",
2518 atomic_read(&dev->dev->power.usage_count));
0d804184
CW
2519#else
2520 seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
2521#endif
371db66a 2522
ec013e7f
JB
2523 return 0;
2524}
2525
1da51581
ID
2526static const char *power_domain_str(enum intel_display_power_domain domain)
2527{
2528 switch (domain) {
2529 case POWER_DOMAIN_PIPE_A:
2530 return "PIPE_A";
2531 case POWER_DOMAIN_PIPE_B:
2532 return "PIPE_B";
2533 case POWER_DOMAIN_PIPE_C:
2534 return "PIPE_C";
2535 case POWER_DOMAIN_PIPE_A_PANEL_FITTER:
2536 return "PIPE_A_PANEL_FITTER";
2537 case POWER_DOMAIN_PIPE_B_PANEL_FITTER:
2538 return "PIPE_B_PANEL_FITTER";
2539 case POWER_DOMAIN_PIPE_C_PANEL_FITTER:
2540 return "PIPE_C_PANEL_FITTER";
2541 case POWER_DOMAIN_TRANSCODER_A:
2542 return "TRANSCODER_A";
2543 case POWER_DOMAIN_TRANSCODER_B:
2544 return "TRANSCODER_B";
2545 case POWER_DOMAIN_TRANSCODER_C:
2546 return "TRANSCODER_C";
2547 case POWER_DOMAIN_TRANSCODER_EDP:
2548 return "TRANSCODER_EDP";
319be8ae
ID
2549 case POWER_DOMAIN_PORT_DDI_A_2_LANES:
2550 return "PORT_DDI_A_2_LANES";
2551 case POWER_DOMAIN_PORT_DDI_A_4_LANES:
2552 return "PORT_DDI_A_4_LANES";
2553 case POWER_DOMAIN_PORT_DDI_B_2_LANES:
2554 return "PORT_DDI_B_2_LANES";
2555 case POWER_DOMAIN_PORT_DDI_B_4_LANES:
2556 return "PORT_DDI_B_4_LANES";
2557 case POWER_DOMAIN_PORT_DDI_C_2_LANES:
2558 return "PORT_DDI_C_2_LANES";
2559 case POWER_DOMAIN_PORT_DDI_C_4_LANES:
2560 return "PORT_DDI_C_4_LANES";
2561 case POWER_DOMAIN_PORT_DDI_D_2_LANES:
2562 return "PORT_DDI_D_2_LANES";
2563 case POWER_DOMAIN_PORT_DDI_D_4_LANES:
2564 return "PORT_DDI_D_4_LANES";
2565 case POWER_DOMAIN_PORT_DSI:
2566 return "PORT_DSI";
2567 case POWER_DOMAIN_PORT_CRT:
2568 return "PORT_CRT";
2569 case POWER_DOMAIN_PORT_OTHER:
2570 return "PORT_OTHER";
1da51581
ID
2571 case POWER_DOMAIN_VGA:
2572 return "VGA";
2573 case POWER_DOMAIN_AUDIO:
2574 return "AUDIO";
bd2bb1b9
PZ
2575 case POWER_DOMAIN_PLLS:
2576 return "PLLS";
1407121a
S
2577 case POWER_DOMAIN_AUX_A:
2578 return "AUX_A";
2579 case POWER_DOMAIN_AUX_B:
2580 return "AUX_B";
2581 case POWER_DOMAIN_AUX_C:
2582 return "AUX_C";
2583 case POWER_DOMAIN_AUX_D:
2584 return "AUX_D";
1da51581
ID
2585 case POWER_DOMAIN_INIT:
2586 return "INIT";
2587 default:
5f77eeb0 2588 MISSING_CASE(domain);
1da51581
ID
2589 return "?";
2590 }
2591}
2592
2593static int i915_power_domain_info(struct seq_file *m, void *unused)
2594{
9f25d007 2595 struct drm_info_node *node = m->private;
1da51581
ID
2596 struct drm_device *dev = node->minor->dev;
2597 struct drm_i915_private *dev_priv = dev->dev_private;
2598 struct i915_power_domains *power_domains = &dev_priv->power_domains;
2599 int i;
2600
2601 mutex_lock(&power_domains->lock);
2602
2603 seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
2604 for (i = 0; i < power_domains->power_well_count; i++) {
2605 struct i915_power_well *power_well;
2606 enum intel_display_power_domain power_domain;
2607
2608 power_well = &power_domains->power_wells[i];
2609 seq_printf(m, "%-25s %d\n", power_well->name,
2610 power_well->count);
2611
2612 for (power_domain = 0; power_domain < POWER_DOMAIN_NUM;
2613 power_domain++) {
2614 if (!(BIT(power_domain) & power_well->domains))
2615 continue;
2616
2617 seq_printf(m, " %-23s %d\n",
2618 power_domain_str(power_domain),
2619 power_domains->domain_use_count[power_domain]);
2620 }
2621 }
2622
2623 mutex_unlock(&power_domains->lock);
2624
2625 return 0;
2626}
2627
53f5e3ca
JB
2628static void intel_seq_print_mode(struct seq_file *m, int tabs,
2629 struct drm_display_mode *mode)
2630{
2631 int i;
2632
2633 for (i = 0; i < tabs; i++)
2634 seq_putc(m, '\t');
2635
2636 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",
2637 mode->base.id, mode->name,
2638 mode->vrefresh, mode->clock,
2639 mode->hdisplay, mode->hsync_start,
2640 mode->hsync_end, mode->htotal,
2641 mode->vdisplay, mode->vsync_start,
2642 mode->vsync_end, mode->vtotal,
2643 mode->type, mode->flags);
2644}
2645
2646static void intel_encoder_info(struct seq_file *m,
2647 struct intel_crtc *intel_crtc,
2648 struct intel_encoder *intel_encoder)
2649{
9f25d007 2650 struct drm_info_node *node = m->private;
53f5e3ca
JB
2651 struct drm_device *dev = node->minor->dev;
2652 struct drm_crtc *crtc = &intel_crtc->base;
2653 struct intel_connector *intel_connector;
2654 struct drm_encoder *encoder;
2655
2656 encoder = &intel_encoder->base;
2657 seq_printf(m, "\tencoder %d: type: %s, connectors:\n",
8e329a03 2658 encoder->base.id, encoder->name);
53f5e3ca
JB
2659 for_each_connector_on_encoder(dev, encoder, intel_connector) {
2660 struct drm_connector *connector = &intel_connector->base;
2661 seq_printf(m, "\t\tconnector %d: type: %s, status: %s",
2662 connector->base.id,
c23cc417 2663 connector->name,
53f5e3ca
JB
2664 drm_get_connector_status_name(connector->status));
2665 if (connector->status == connector_status_connected) {
2666 struct drm_display_mode *mode = &crtc->mode;
2667 seq_printf(m, ", mode:\n");
2668 intel_seq_print_mode(m, 2, mode);
2669 } else {
2670 seq_putc(m, '\n');
2671 }
2672 }
2673}
2674
2675static void intel_crtc_info(struct seq_file *m, struct intel_crtc *intel_crtc)
2676{
9f25d007 2677 struct drm_info_node *node = m->private;
53f5e3ca
JB
2678 struct drm_device *dev = node->minor->dev;
2679 struct drm_crtc *crtc = &intel_crtc->base;
2680 struct intel_encoder *intel_encoder;
2681
5aa8a937
MR
2682 if (crtc->primary->fb)
2683 seq_printf(m, "\tfb: %d, pos: %dx%d, size: %dx%d\n",
2684 crtc->primary->fb->base.id, crtc->x, crtc->y,
2685 crtc->primary->fb->width, crtc->primary->fb->height);
2686 else
2687 seq_puts(m, "\tprimary plane disabled\n");
53f5e3ca
JB
2688 for_each_encoder_on_crtc(dev, crtc, intel_encoder)
2689 intel_encoder_info(m, intel_crtc, intel_encoder);
2690}
2691
2692static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
2693{
2694 struct drm_display_mode *mode = panel->fixed_mode;
2695
2696 seq_printf(m, "\tfixed mode:\n");
2697 intel_seq_print_mode(m, 2, mode);
2698}
2699
2700static void intel_dp_info(struct seq_file *m,
2701 struct intel_connector *intel_connector)
2702{
2703 struct intel_encoder *intel_encoder = intel_connector->encoder;
2704 struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
2705
2706 seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
2707 seq_printf(m, "\taudio support: %s\n", intel_dp->has_audio ? "yes" :
2708 "no");
2709 if (intel_encoder->type == INTEL_OUTPUT_EDP)
2710 intel_panel_info(m, &intel_connector->panel);
2711}
2712
2713static void intel_hdmi_info(struct seq_file *m,
2714 struct intel_connector *intel_connector)
2715{
2716 struct intel_encoder *intel_encoder = intel_connector->encoder;
2717 struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&intel_encoder->base);
2718
2719 seq_printf(m, "\taudio support: %s\n", intel_hdmi->has_audio ? "yes" :
2720 "no");
2721}
2722
2723static void intel_lvds_info(struct seq_file *m,
2724 struct intel_connector *intel_connector)
2725{
2726 intel_panel_info(m, &intel_connector->panel);
2727}
2728
2729static void intel_connector_info(struct seq_file *m,
2730 struct drm_connector *connector)
2731{
2732 struct intel_connector *intel_connector = to_intel_connector(connector);
2733 struct intel_encoder *intel_encoder = intel_connector->encoder;
f103fc7d 2734 struct drm_display_mode *mode;
53f5e3ca
JB
2735
2736 seq_printf(m, "connector %d: type %s, status: %s\n",
c23cc417 2737 connector->base.id, connector->name,
53f5e3ca
JB
2738 drm_get_connector_status_name(connector->status));
2739 if (connector->status == connector_status_connected) {
2740 seq_printf(m, "\tname: %s\n", connector->display_info.name);
2741 seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
2742 connector->display_info.width_mm,
2743 connector->display_info.height_mm);
2744 seq_printf(m, "\tsubpixel order: %s\n",
2745 drm_get_subpixel_order_name(connector->display_info.subpixel_order));
2746 seq_printf(m, "\tCEA rev: %d\n",
2747 connector->display_info.cea_rev);
2748 }
36cd7444
DA
2749 if (intel_encoder) {
2750 if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
2751 intel_encoder->type == INTEL_OUTPUT_EDP)
2752 intel_dp_info(m, intel_connector);
2753 else if (intel_encoder->type == INTEL_OUTPUT_HDMI)
2754 intel_hdmi_info(m, intel_connector);
2755 else if (intel_encoder->type == INTEL_OUTPUT_LVDS)
2756 intel_lvds_info(m, intel_connector);
2757 }
53f5e3ca 2758
f103fc7d
JB
2759 seq_printf(m, "\tmodes:\n");
2760 list_for_each_entry(mode, &connector->modes, head)
2761 intel_seq_print_mode(m, 2, mode);
53f5e3ca
JB
2762}
2763
065f2ec2
CW
2764static bool cursor_active(struct drm_device *dev, int pipe)
2765{
2766 struct drm_i915_private *dev_priv = dev->dev_private;
2767 u32 state;
2768
2769 if (IS_845G(dev) || IS_I865G(dev))
2770 state = I915_READ(_CURACNTR) & CURSOR_ENABLE;
065f2ec2 2771 else
5efb3e28 2772 state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE;
065f2ec2
CW
2773
2774 return state;
2775}
2776
2777static bool cursor_position(struct drm_device *dev, int pipe, int *x, int *y)
2778{
2779 struct drm_i915_private *dev_priv = dev->dev_private;
2780 u32 pos;
2781
5efb3e28 2782 pos = I915_READ(CURPOS(pipe));
065f2ec2
CW
2783
2784 *x = (pos >> CURSOR_X_SHIFT) & CURSOR_POS_MASK;
2785 if (pos & (CURSOR_POS_SIGN << CURSOR_X_SHIFT))
2786 *x = -*x;
2787
2788 *y = (pos >> CURSOR_Y_SHIFT) & CURSOR_POS_MASK;
2789 if (pos & (CURSOR_POS_SIGN << CURSOR_Y_SHIFT))
2790 *y = -*y;
2791
2792 return cursor_active(dev, pipe);
2793}
2794
53f5e3ca
JB
2795static int i915_display_info(struct seq_file *m, void *unused)
2796{
9f25d007 2797 struct drm_info_node *node = m->private;
53f5e3ca 2798 struct drm_device *dev = node->minor->dev;
b0e5ddf3 2799 struct drm_i915_private *dev_priv = dev->dev_private;
065f2ec2 2800 struct intel_crtc *crtc;
53f5e3ca
JB
2801 struct drm_connector *connector;
2802
b0e5ddf3 2803 intel_runtime_pm_get(dev_priv);
53f5e3ca
JB
2804 drm_modeset_lock_all(dev);
2805 seq_printf(m, "CRTC info\n");
2806 seq_printf(m, "---------\n");
d3fcc808 2807 for_each_intel_crtc(dev, crtc) {
065f2ec2 2808 bool active;
f77076c9 2809 struct intel_crtc_state *pipe_config;
065f2ec2 2810 int x, y;
53f5e3ca 2811
f77076c9
ML
2812 pipe_config = to_intel_crtc_state(crtc->base.state);
2813
57127efa 2814 seq_printf(m, "CRTC %d: pipe: %c, active=%s (size=%dx%d)\n",
065f2ec2 2815 crtc->base.base.id, pipe_name(crtc->pipe),
f77076c9
ML
2816 yesno(pipe_config->base.active),
2817 pipe_config->pipe_src_w, pipe_config->pipe_src_h);
2818 if (pipe_config->base.active) {
065f2ec2
CW
2819 intel_crtc_info(m, crtc);
2820
a23dc658 2821 active = cursor_position(dev, crtc->pipe, &x, &y);
57127efa 2822 seq_printf(m, "\tcursor visible? %s, position (%d, %d), size %dx%d, addr 0x%08x, active? %s\n",
4b0e333e 2823 yesno(crtc->cursor_base),
3dd512fb
MR
2824 x, y, crtc->base.cursor->state->crtc_w,
2825 crtc->base.cursor->state->crtc_h,
57127efa 2826 crtc->cursor_addr, yesno(active));
a23dc658 2827 }
cace841c
DV
2828
2829 seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s \n",
2830 yesno(!crtc->cpu_fifo_underrun_disabled),
2831 yesno(!crtc->pch_fifo_underrun_disabled));
53f5e3ca
JB
2832 }
2833
2834 seq_printf(m, "\n");
2835 seq_printf(m, "Connector info\n");
2836 seq_printf(m, "--------------\n");
2837 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2838 intel_connector_info(m, connector);
2839 }
2840 drm_modeset_unlock_all(dev);
b0e5ddf3 2841 intel_runtime_pm_put(dev_priv);
53f5e3ca
JB
2842
2843 return 0;
2844}
2845
e04934cf
BW
2846static int i915_semaphore_status(struct seq_file *m, void *unused)
2847{
2848 struct drm_info_node *node = (struct drm_info_node *) m->private;
2849 struct drm_device *dev = node->minor->dev;
2850 struct drm_i915_private *dev_priv = dev->dev_private;
2851 struct intel_engine_cs *ring;
2852 int num_rings = hweight32(INTEL_INFO(dev)->ring_mask);
2853 int i, j, ret;
2854
2855 if (!i915_semaphore_is_enabled(dev)) {
2856 seq_puts(m, "Semaphores are disabled\n");
2857 return 0;
2858 }
2859
2860 ret = mutex_lock_interruptible(&dev->struct_mutex);
2861 if (ret)
2862 return ret;
03872064 2863 intel_runtime_pm_get(dev_priv);
e04934cf
BW
2864
2865 if (IS_BROADWELL(dev)) {
2866 struct page *page;
2867 uint64_t *seqno;
2868
2869 page = i915_gem_object_get_page(dev_priv->semaphore_obj, 0);
2870
2871 seqno = (uint64_t *)kmap_atomic(page);
2872 for_each_ring(ring, dev_priv, i) {
2873 uint64_t offset;
2874
2875 seq_printf(m, "%s\n", ring->name);
2876
2877 seq_puts(m, " Last signal:");
2878 for (j = 0; j < num_rings; j++) {
2879 offset = i * I915_NUM_RINGS + j;
2880 seq_printf(m, "0x%08llx (0x%02llx) ",
2881 seqno[offset], offset * 8);
2882 }
2883 seq_putc(m, '\n');
2884
2885 seq_puts(m, " Last wait: ");
2886 for (j = 0; j < num_rings; j++) {
2887 offset = i + (j * I915_NUM_RINGS);
2888 seq_printf(m, "0x%08llx (0x%02llx) ",
2889 seqno[offset], offset * 8);
2890 }
2891 seq_putc(m, '\n');
2892
2893 }
2894 kunmap_atomic(seqno);
2895 } else {
2896 seq_puts(m, " Last signal:");
2897 for_each_ring(ring, dev_priv, i)
2898 for (j = 0; j < num_rings; j++)
2899 seq_printf(m, "0x%08x\n",
2900 I915_READ(ring->semaphore.mbox.signal[j]));
2901 seq_putc(m, '\n');
2902 }
2903
2904 seq_puts(m, "\nSync seqno:\n");
2905 for_each_ring(ring, dev_priv, i) {
2906 for (j = 0; j < num_rings; j++) {
2907 seq_printf(m, " 0x%08x ", ring->semaphore.sync_seqno[j]);
2908 }
2909 seq_putc(m, '\n');
2910 }
2911 seq_putc(m, '\n');
2912
03872064 2913 intel_runtime_pm_put(dev_priv);
e04934cf
BW
2914 mutex_unlock(&dev->struct_mutex);
2915 return 0;
2916}
2917
728e29d7
DV
2918static int i915_shared_dplls_info(struct seq_file *m, void *unused)
2919{
2920 struct drm_info_node *node = (struct drm_info_node *) m->private;
2921 struct drm_device *dev = node->minor->dev;
2922 struct drm_i915_private *dev_priv = dev->dev_private;
2923 int i;
2924
2925 drm_modeset_lock_all(dev);
2926 for (i = 0; i < dev_priv->num_shared_dpll; i++) {
2927 struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
2928
2929 seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->name, pll->id);
1e6f2ddc 2930 seq_printf(m, " crtc_mask: 0x%08x, active: %d, on: %s\n",
3e369b76 2931 pll->config.crtc_mask, pll->active, yesno(pll->on));
728e29d7 2932 seq_printf(m, " tracked hardware state:\n");
3e369b76
ACO
2933 seq_printf(m, " dpll: 0x%08x\n", pll->config.hw_state.dpll);
2934 seq_printf(m, " dpll_md: 0x%08x\n",
2935 pll->config.hw_state.dpll_md);
2936 seq_printf(m, " fp0: 0x%08x\n", pll->config.hw_state.fp0);
2937 seq_printf(m, " fp1: 0x%08x\n", pll->config.hw_state.fp1);
2938 seq_printf(m, " wrpll: 0x%08x\n", pll->config.hw_state.wrpll);
728e29d7
DV
2939 }
2940 drm_modeset_unlock_all(dev);
2941
2942 return 0;
2943}
2944
1ed1ef9d 2945static int i915_wa_registers(struct seq_file *m, void *unused)
888b5995
AS
2946{
2947 int i;
2948 int ret;
2949 struct drm_info_node *node = (struct drm_info_node *) m->private;
2950 struct drm_device *dev = node->minor->dev;
2951 struct drm_i915_private *dev_priv = dev->dev_private;
2952
888b5995
AS
2953 ret = mutex_lock_interruptible(&dev->struct_mutex);
2954 if (ret)
2955 return ret;
2956
2957 intel_runtime_pm_get(dev_priv);
2958
7225342a
MK
2959 seq_printf(m, "Workarounds applied: %d\n", dev_priv->workarounds.count);
2960 for (i = 0; i < dev_priv->workarounds.count; ++i) {
2fa60f6d
MK
2961 u32 addr, mask, value, read;
2962 bool ok;
888b5995 2963
7225342a
MK
2964 addr = dev_priv->workarounds.reg[i].addr;
2965 mask = dev_priv->workarounds.reg[i].mask;
2fa60f6d
MK
2966 value = dev_priv->workarounds.reg[i].value;
2967 read = I915_READ(addr);
2968 ok = (value & mask) == (read & mask);
2969 seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X, read: 0x%08x, status: %s\n",
2970 addr, value, mask, read, ok ? "OK" : "FAIL");
888b5995
AS
2971 }
2972
2973 intel_runtime_pm_put(dev_priv);
2974 mutex_unlock(&dev->struct_mutex);
2975
2976 return 0;
2977}
2978
c5511e44
DL
2979static int i915_ddb_info(struct seq_file *m, void *unused)
2980{
2981 struct drm_info_node *node = m->private;
2982 struct drm_device *dev = node->minor->dev;
2983 struct drm_i915_private *dev_priv = dev->dev_private;
2984 struct skl_ddb_allocation *ddb;
2985 struct skl_ddb_entry *entry;
2986 enum pipe pipe;
2987 int plane;
2988
2fcffe19
DL
2989 if (INTEL_INFO(dev)->gen < 9)
2990 return 0;
2991
c5511e44
DL
2992 drm_modeset_lock_all(dev);
2993
2994 ddb = &dev_priv->wm.skl_hw.ddb;
2995
2996 seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
2997
2998 for_each_pipe(dev_priv, pipe) {
2999 seq_printf(m, "Pipe %c\n", pipe_name(pipe));
3000
dd740780 3001 for_each_plane(dev_priv, pipe, plane) {
c5511e44
DL
3002 entry = &ddb->plane[pipe][plane];
3003 seq_printf(m, " Plane%-8d%8u%8u%8u\n", plane + 1,
3004 entry->start, entry->end,
3005 skl_ddb_entry_size(entry));
3006 }
3007
3008 entry = &ddb->cursor[pipe];
3009 seq_printf(m, " %-13s%8u%8u%8u\n", "Cursor", entry->start,
3010 entry->end, skl_ddb_entry_size(entry));
3011 }
3012
3013 drm_modeset_unlock_all(dev);
3014
3015 return 0;
3016}
3017
a54746e3
VK
3018static void drrs_status_per_crtc(struct seq_file *m,
3019 struct drm_device *dev, struct intel_crtc *intel_crtc)
3020{
3021 struct intel_encoder *intel_encoder;
3022 struct drm_i915_private *dev_priv = dev->dev_private;
3023 struct i915_drrs *drrs = &dev_priv->drrs;
3024 int vrefresh = 0;
3025
3026 for_each_encoder_on_crtc(dev, &intel_crtc->base, intel_encoder) {
3027 /* Encoder connected on this CRTC */
3028 switch (intel_encoder->type) {
3029 case INTEL_OUTPUT_EDP:
3030 seq_puts(m, "eDP:\n");
3031 break;
3032 case INTEL_OUTPUT_DSI:
3033 seq_puts(m, "DSI:\n");
3034 break;
3035 case INTEL_OUTPUT_HDMI:
3036 seq_puts(m, "HDMI:\n");
3037 break;
3038 case INTEL_OUTPUT_DISPLAYPORT:
3039 seq_puts(m, "DP:\n");
3040 break;
3041 default:
3042 seq_printf(m, "Other encoder (id=%d).\n",
3043 intel_encoder->type);
3044 return;
3045 }
3046 }
3047
3048 if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
3049 seq_puts(m, "\tVBT: DRRS_type: Static");
3050 else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
3051 seq_puts(m, "\tVBT: DRRS_type: Seamless");
3052 else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
3053 seq_puts(m, "\tVBT: DRRS_type: None");
3054 else
3055 seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
3056
3057 seq_puts(m, "\n\n");
3058
f77076c9 3059 if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
a54746e3
VK
3060 struct intel_panel *panel;
3061
3062 mutex_lock(&drrs->mutex);
3063 /* DRRS Supported */
3064 seq_puts(m, "\tDRRS Supported: Yes\n");
3065
3066 /* disable_drrs() will make drrs->dp NULL */
3067 if (!drrs->dp) {
3068 seq_puts(m, "Idleness DRRS: Disabled");
3069 mutex_unlock(&drrs->mutex);
3070 return;
3071 }
3072
3073 panel = &drrs->dp->attached_connector->panel;
3074 seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
3075 drrs->busy_frontbuffer_bits);
3076
3077 seq_puts(m, "\n\t\t");
3078 if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
3079 seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
3080 vrefresh = panel->fixed_mode->vrefresh;
3081 } else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
3082 seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
3083 vrefresh = panel->downclock_mode->vrefresh;
3084 } else {
3085 seq_printf(m, "DRRS_State: Unknown(%d)\n",
3086 drrs->refresh_rate_type);
3087 mutex_unlock(&drrs->mutex);
3088 return;
3089 }
3090 seq_printf(m, "\t\tVrefresh: %d", vrefresh);
3091
3092 seq_puts(m, "\n\t\t");
3093 mutex_unlock(&drrs->mutex);
3094 } else {
3095 /* DRRS not supported. Print the VBT parameter*/
3096 seq_puts(m, "\tDRRS Supported : No");
3097 }
3098 seq_puts(m, "\n");
3099}
3100
3101static int i915_drrs_status(struct seq_file *m, void *unused)
3102{
3103 struct drm_info_node *node = m->private;
3104 struct drm_device *dev = node->minor->dev;
3105 struct intel_crtc *intel_crtc;
3106 int active_crtc_cnt = 0;
3107
3108 for_each_intel_crtc(dev, intel_crtc) {
3109 drm_modeset_lock(&intel_crtc->base.mutex, NULL);
3110
f77076c9 3111 if (intel_crtc->base.state->active) {
a54746e3
VK
3112 active_crtc_cnt++;
3113 seq_printf(m, "\nCRTC %d: ", active_crtc_cnt);
3114
3115 drrs_status_per_crtc(m, dev, intel_crtc);
3116 }
3117
3118 drm_modeset_unlock(&intel_crtc->base.mutex);
3119 }
3120
3121 if (!active_crtc_cnt)
3122 seq_puts(m, "No active crtc found\n");
3123
3124 return 0;
3125}
3126
07144428
DL
3127struct pipe_crc_info {
3128 const char *name;
3129 struct drm_device *dev;
3130 enum pipe pipe;
3131};
3132
11bed958
DA
3133static int i915_dp_mst_info(struct seq_file *m, void *unused)
3134{
3135 struct drm_info_node *node = (struct drm_info_node *) m->private;
3136 struct drm_device *dev = node->minor->dev;
3137 struct drm_encoder *encoder;
3138 struct intel_encoder *intel_encoder;
3139 struct intel_digital_port *intel_dig_port;
3140 drm_modeset_lock_all(dev);
3141 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
3142 intel_encoder = to_intel_encoder(encoder);
3143 if (intel_encoder->type != INTEL_OUTPUT_DISPLAYPORT)
3144 continue;
3145 intel_dig_port = enc_to_dig_port(encoder);
3146 if (!intel_dig_port->dp.can_mst)
3147 continue;
3148
3149 drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
3150 }
3151 drm_modeset_unlock_all(dev);
3152 return 0;
3153}
3154
07144428
DL
3155static int i915_pipe_crc_open(struct inode *inode, struct file *filep)
3156{
be5c7a90
DL
3157 struct pipe_crc_info *info = inode->i_private;
3158 struct drm_i915_private *dev_priv = info->dev->dev_private;
3159 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3160
7eb1c496
DV
3161 if (info->pipe >= INTEL_INFO(info->dev)->num_pipes)
3162 return -ENODEV;
3163
d538bbdf
DL
3164 spin_lock_irq(&pipe_crc->lock);
3165
3166 if (pipe_crc->opened) {
3167 spin_unlock_irq(&pipe_crc->lock);
be5c7a90
DL
3168 return -EBUSY; /* already open */
3169 }
3170
d538bbdf 3171 pipe_crc->opened = true;
07144428
DL
3172 filep->private_data = inode->i_private;
3173
d538bbdf
DL
3174 spin_unlock_irq(&pipe_crc->lock);
3175
07144428
DL
3176 return 0;
3177}
3178
3179static int i915_pipe_crc_release(struct inode *inode, struct file *filep)
3180{
be5c7a90
DL
3181 struct pipe_crc_info *info = inode->i_private;
3182 struct drm_i915_private *dev_priv = info->dev->dev_private;
3183 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3184
d538bbdf
DL
3185 spin_lock_irq(&pipe_crc->lock);
3186 pipe_crc->opened = false;
3187 spin_unlock_irq(&pipe_crc->lock);
be5c7a90 3188
07144428
DL
3189 return 0;
3190}
3191
3192/* (6 fields, 8 chars each, space separated (5) + '\n') */
3193#define PIPE_CRC_LINE_LEN (6 * 8 + 5 + 1)
3194/* account for \'0' */
3195#define PIPE_CRC_BUFFER_LEN (PIPE_CRC_LINE_LEN + 1)
3196
3197static int pipe_crc_data_count(struct intel_pipe_crc *pipe_crc)
8bf1e9f1 3198{
d538bbdf
DL
3199 assert_spin_locked(&pipe_crc->lock);
3200 return CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3201 INTEL_PIPE_CRC_ENTRIES_NR);
07144428
DL
3202}
3203
3204static ssize_t
3205i915_pipe_crc_read(struct file *filep, char __user *user_buf, size_t count,
3206 loff_t *pos)
3207{
3208 struct pipe_crc_info *info = filep->private_data;
3209 struct drm_device *dev = info->dev;
3210 struct drm_i915_private *dev_priv = dev->dev_private;
3211 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[info->pipe];
3212 char buf[PIPE_CRC_BUFFER_LEN];
9ad6d99f 3213 int n_entries;
07144428
DL
3214 ssize_t bytes_read;
3215
3216 /*
3217 * Don't allow user space to provide buffers not big enough to hold
3218 * a line of data.
3219 */
3220 if (count < PIPE_CRC_LINE_LEN)
3221 return -EINVAL;
3222
3223 if (pipe_crc->source == INTEL_PIPE_CRC_SOURCE_NONE)
8bf1e9f1 3224 return 0;
07144428
DL
3225
3226 /* nothing to read */
d538bbdf 3227 spin_lock_irq(&pipe_crc->lock);
07144428 3228 while (pipe_crc_data_count(pipe_crc) == 0) {
d538bbdf
DL
3229 int ret;
3230
3231 if (filep->f_flags & O_NONBLOCK) {
3232 spin_unlock_irq(&pipe_crc->lock);
07144428 3233 return -EAGAIN;
d538bbdf 3234 }
07144428 3235
d538bbdf
DL
3236 ret = wait_event_interruptible_lock_irq(pipe_crc->wq,
3237 pipe_crc_data_count(pipe_crc), pipe_crc->lock);
3238 if (ret) {
3239 spin_unlock_irq(&pipe_crc->lock);
3240 return ret;
3241 }
8bf1e9f1
SH
3242 }
3243
07144428 3244 /* We now have one or more entries to read */
9ad6d99f 3245 n_entries = count / PIPE_CRC_LINE_LEN;
d538bbdf 3246
07144428 3247 bytes_read = 0;
9ad6d99f
VS
3248 while (n_entries > 0) {
3249 struct intel_pipe_crc_entry *entry =
3250 &pipe_crc->entries[pipe_crc->tail];
07144428 3251 int ret;
8bf1e9f1 3252
9ad6d99f
VS
3253 if (CIRC_CNT(pipe_crc->head, pipe_crc->tail,
3254 INTEL_PIPE_CRC_ENTRIES_NR) < 1)
3255 break;
3256
3257 BUILD_BUG_ON_NOT_POWER_OF_2(INTEL_PIPE_CRC_ENTRIES_NR);
3258 pipe_crc->tail = (pipe_crc->tail + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
3259
07144428
DL
3260 bytes_read += snprintf(buf, PIPE_CRC_BUFFER_LEN,
3261 "%8u %8x %8x %8x %8x %8x\n",
3262 entry->frame, entry->crc[0],
3263 entry->crc[1], entry->crc[2],
3264 entry->crc[3], entry->crc[4]);
3265
9ad6d99f
VS
3266 spin_unlock_irq(&pipe_crc->lock);
3267
3268 ret = copy_to_user(user_buf, buf, PIPE_CRC_LINE_LEN);
07144428
DL
3269 if (ret == PIPE_CRC_LINE_LEN)
3270 return -EFAULT;
b2c88f5b 3271
9ad6d99f
VS
3272 user_buf += PIPE_CRC_LINE_LEN;
3273 n_entries--;
3274
3275 spin_lock_irq(&pipe_crc->lock);
3276 }
8bf1e9f1 3277
d538bbdf
DL
3278 spin_unlock_irq(&pipe_crc->lock);
3279
07144428
DL
3280 return bytes_read;
3281}
3282
3283static const struct file_operations i915_pipe_crc_fops = {
3284 .owner = THIS_MODULE,
3285 .open = i915_pipe_crc_open,
3286 .read = i915_pipe_crc_read,
3287 .release = i915_pipe_crc_release,
3288};
3289
3290static struct pipe_crc_info i915_pipe_crc_data[I915_MAX_PIPES] = {
3291 {
3292 .name = "i915_pipe_A_crc",
3293 .pipe = PIPE_A,
3294 },
3295 {
3296 .name = "i915_pipe_B_crc",
3297 .pipe = PIPE_B,
3298 },
3299 {
3300 .name = "i915_pipe_C_crc",
3301 .pipe = PIPE_C,
3302 },
3303};
3304
3305static int i915_pipe_crc_create(struct dentry *root, struct drm_minor *minor,
3306 enum pipe pipe)
3307{
3308 struct drm_device *dev = minor->dev;
3309 struct dentry *ent;
3310 struct pipe_crc_info *info = &i915_pipe_crc_data[pipe];
3311
3312 info->dev = dev;
3313 ent = debugfs_create_file(info->name, S_IRUGO, root, info,
3314 &i915_pipe_crc_fops);
f3c5fe97
WY
3315 if (!ent)
3316 return -ENOMEM;
07144428
DL
3317
3318 return drm_add_fake_info_node(minor, ent, info);
8bf1e9f1
SH
3319}
3320
e8dfcf78 3321static const char * const pipe_crc_sources[] = {
926321d5
DV
3322 "none",
3323 "plane1",
3324 "plane2",
3325 "pf",
5b3a856b 3326 "pipe",
3d099a05
DV
3327 "TV",
3328 "DP-B",
3329 "DP-C",
3330 "DP-D",
46a19188 3331 "auto",
926321d5
DV
3332};
3333
3334static const char *pipe_crc_source_name(enum intel_pipe_crc_source source)
3335{
3336 BUILD_BUG_ON(ARRAY_SIZE(pipe_crc_sources) != INTEL_PIPE_CRC_SOURCE_MAX);
3337 return pipe_crc_sources[source];
3338}
3339
bd9db02f 3340static int display_crc_ctl_show(struct seq_file *m, void *data)
926321d5
DV
3341{
3342 struct drm_device *dev = m->private;
3343 struct drm_i915_private *dev_priv = dev->dev_private;
3344 int i;
3345
3346 for (i = 0; i < I915_MAX_PIPES; i++)
3347 seq_printf(m, "%c %s\n", pipe_name(i),
3348 pipe_crc_source_name(dev_priv->pipe_crc[i].source));
3349
3350 return 0;
3351}
3352
bd9db02f 3353static int display_crc_ctl_open(struct inode *inode, struct file *file)
926321d5
DV
3354{
3355 struct drm_device *dev = inode->i_private;
3356
bd9db02f 3357 return single_open(file, display_crc_ctl_show, dev);
926321d5
DV
3358}
3359
46a19188 3360static int i8xx_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
52f843f6
DV
3361 uint32_t *val)
3362{
46a19188
DV
3363 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3364 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3365
3366 switch (*source) {
52f843f6
DV
3367 case INTEL_PIPE_CRC_SOURCE_PIPE:
3368 *val = PIPE_CRC_ENABLE | PIPE_CRC_INCLUDE_BORDER_I8XX;
3369 break;
3370 case INTEL_PIPE_CRC_SOURCE_NONE:
3371 *val = 0;
3372 break;
3373 default:
3374 return -EINVAL;
3375 }
3376
3377 return 0;
3378}
3379
46a19188
DV
3380static int i9xx_pipe_crc_auto_source(struct drm_device *dev, enum pipe pipe,
3381 enum intel_pipe_crc_source *source)
3382{
3383 struct intel_encoder *encoder;
3384 struct intel_crtc *crtc;
26756809 3385 struct intel_digital_port *dig_port;
46a19188
DV
3386 int ret = 0;
3387
3388 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3389
6e9f798d 3390 drm_modeset_lock_all(dev);
b2784e15 3391 for_each_intel_encoder(dev, encoder) {
46a19188
DV
3392 if (!encoder->base.crtc)
3393 continue;
3394
3395 crtc = to_intel_crtc(encoder->base.crtc);
3396
3397 if (crtc->pipe != pipe)
3398 continue;
3399
3400 switch (encoder->type) {
3401 case INTEL_OUTPUT_TVOUT:
3402 *source = INTEL_PIPE_CRC_SOURCE_TV;
3403 break;
3404 case INTEL_OUTPUT_DISPLAYPORT:
3405 case INTEL_OUTPUT_EDP:
26756809
DV
3406 dig_port = enc_to_dig_port(&encoder->base);
3407 switch (dig_port->port) {
3408 case PORT_B:
3409 *source = INTEL_PIPE_CRC_SOURCE_DP_B;
3410 break;
3411 case PORT_C:
3412 *source = INTEL_PIPE_CRC_SOURCE_DP_C;
3413 break;
3414 case PORT_D:
3415 *source = INTEL_PIPE_CRC_SOURCE_DP_D;
3416 break;
3417 default:
3418 WARN(1, "nonexisting DP port %c\n",
3419 port_name(dig_port->port));
3420 break;
3421 }
46a19188 3422 break;
6847d71b
PZ
3423 default:
3424 break;
46a19188
DV
3425 }
3426 }
6e9f798d 3427 drm_modeset_unlock_all(dev);
46a19188
DV
3428
3429 return ret;
3430}
3431
3432static int vlv_pipe_crc_ctl_reg(struct drm_device *dev,
3433 enum pipe pipe,
3434 enum intel_pipe_crc_source *source,
7ac0129b
DV
3435 uint32_t *val)
3436{
8d2f24ca
DV
3437 struct drm_i915_private *dev_priv = dev->dev_private;
3438 bool need_stable_symbols = false;
3439
46a19188
DV
3440 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3441 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3442 if (ret)
3443 return ret;
3444 }
3445
3446 switch (*source) {
7ac0129b
DV
3447 case INTEL_PIPE_CRC_SOURCE_PIPE:
3448 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_VLV;
3449 break;
3450 case INTEL_PIPE_CRC_SOURCE_DP_B:
3451 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_VLV;
8d2f24ca 3452 need_stable_symbols = true;
7ac0129b
DV
3453 break;
3454 case INTEL_PIPE_CRC_SOURCE_DP_C:
3455 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_VLV;
8d2f24ca 3456 need_stable_symbols = true;
7ac0129b 3457 break;
2be57922
VS
3458 case INTEL_PIPE_CRC_SOURCE_DP_D:
3459 if (!IS_CHERRYVIEW(dev))
3460 return -EINVAL;
3461 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_VLV;
3462 need_stable_symbols = true;
3463 break;
7ac0129b
DV
3464 case INTEL_PIPE_CRC_SOURCE_NONE:
3465 *val = 0;
3466 break;
3467 default:
3468 return -EINVAL;
3469 }
3470
8d2f24ca
DV
3471 /*
3472 * When the pipe CRC tap point is after the transcoders we need
3473 * to tweak symbol-level features to produce a deterministic series of
3474 * symbols for a given frame. We need to reset those features only once
3475 * a frame (instead of every nth symbol):
3476 * - DC-balance: used to ensure a better clock recovery from the data
3477 * link (SDVO)
3478 * - DisplayPort scrambling: used for EMI reduction
3479 */
3480 if (need_stable_symbols) {
3481 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3482
8d2f24ca 3483 tmp |= DC_BALANCE_RESET_VLV;
eb736679
VS
3484 switch (pipe) {
3485 case PIPE_A:
8d2f24ca 3486 tmp |= PIPE_A_SCRAMBLE_RESET;
eb736679
VS
3487 break;
3488 case PIPE_B:
8d2f24ca 3489 tmp |= PIPE_B_SCRAMBLE_RESET;
eb736679
VS
3490 break;
3491 case PIPE_C:
3492 tmp |= PIPE_C_SCRAMBLE_RESET;
3493 break;
3494 default:
3495 return -EINVAL;
3496 }
8d2f24ca
DV
3497 I915_WRITE(PORT_DFT2_G4X, tmp);
3498 }
3499
7ac0129b
DV
3500 return 0;
3501}
3502
4b79ebf7 3503static int i9xx_pipe_crc_ctl_reg(struct drm_device *dev,
46a19188
DV
3504 enum pipe pipe,
3505 enum intel_pipe_crc_source *source,
4b79ebf7
DV
3506 uint32_t *val)
3507{
84093603
DV
3508 struct drm_i915_private *dev_priv = dev->dev_private;
3509 bool need_stable_symbols = false;
3510
46a19188
DV
3511 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO) {
3512 int ret = i9xx_pipe_crc_auto_source(dev, pipe, source);
3513 if (ret)
3514 return ret;
3515 }
3516
3517 switch (*source) {
4b79ebf7
DV
3518 case INTEL_PIPE_CRC_SOURCE_PIPE:
3519 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_I9XX;
3520 break;
3521 case INTEL_PIPE_CRC_SOURCE_TV:
3522 if (!SUPPORTS_TV(dev))
3523 return -EINVAL;
3524 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_TV_PRE;
3525 break;
3526 case INTEL_PIPE_CRC_SOURCE_DP_B:
3527 if (!IS_G4X(dev))
3528 return -EINVAL;
3529 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_B_G4X;
84093603 3530 need_stable_symbols = true;
4b79ebf7
DV
3531 break;
3532 case INTEL_PIPE_CRC_SOURCE_DP_C:
3533 if (!IS_G4X(dev))
3534 return -EINVAL;
3535 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_C_G4X;
84093603 3536 need_stable_symbols = true;
4b79ebf7
DV
3537 break;
3538 case INTEL_PIPE_CRC_SOURCE_DP_D:
3539 if (!IS_G4X(dev))
3540 return -EINVAL;
3541 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_DP_D_G4X;
84093603 3542 need_stable_symbols = true;
4b79ebf7
DV
3543 break;
3544 case INTEL_PIPE_CRC_SOURCE_NONE:
3545 *val = 0;
3546 break;
3547 default:
3548 return -EINVAL;
3549 }
3550
84093603
DV
3551 /*
3552 * When the pipe CRC tap point is after the transcoders we need
3553 * to tweak symbol-level features to produce a deterministic series of
3554 * symbols for a given frame. We need to reset those features only once
3555 * a frame (instead of every nth symbol):
3556 * - DC-balance: used to ensure a better clock recovery from the data
3557 * link (SDVO)
3558 * - DisplayPort scrambling: used for EMI reduction
3559 */
3560 if (need_stable_symbols) {
3561 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3562
3563 WARN_ON(!IS_G4X(dev));
3564
3565 I915_WRITE(PORT_DFT_I9XX,
3566 I915_READ(PORT_DFT_I9XX) | DC_BALANCE_RESET);
3567
3568 if (pipe == PIPE_A)
3569 tmp |= PIPE_A_SCRAMBLE_RESET;
3570 else
3571 tmp |= PIPE_B_SCRAMBLE_RESET;
3572
3573 I915_WRITE(PORT_DFT2_G4X, tmp);
3574 }
3575
4b79ebf7
DV
3576 return 0;
3577}
3578
8d2f24ca
DV
3579static void vlv_undo_pipe_scramble_reset(struct drm_device *dev,
3580 enum pipe pipe)
3581{
3582 struct drm_i915_private *dev_priv = dev->dev_private;
3583 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3584
eb736679
VS
3585 switch (pipe) {
3586 case PIPE_A:
8d2f24ca 3587 tmp &= ~PIPE_A_SCRAMBLE_RESET;
eb736679
VS
3588 break;
3589 case PIPE_B:
8d2f24ca 3590 tmp &= ~PIPE_B_SCRAMBLE_RESET;
eb736679
VS
3591 break;
3592 case PIPE_C:
3593 tmp &= ~PIPE_C_SCRAMBLE_RESET;
3594 break;
3595 default:
3596 return;
3597 }
8d2f24ca
DV
3598 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK))
3599 tmp &= ~DC_BALANCE_RESET_VLV;
3600 I915_WRITE(PORT_DFT2_G4X, tmp);
3601
3602}
3603
84093603
DV
3604static void g4x_undo_pipe_scramble_reset(struct drm_device *dev,
3605 enum pipe pipe)
3606{
3607 struct drm_i915_private *dev_priv = dev->dev_private;
3608 uint32_t tmp = I915_READ(PORT_DFT2_G4X);
3609
3610 if (pipe == PIPE_A)
3611 tmp &= ~PIPE_A_SCRAMBLE_RESET;
3612 else
3613 tmp &= ~PIPE_B_SCRAMBLE_RESET;
3614 I915_WRITE(PORT_DFT2_G4X, tmp);
3615
3616 if (!(tmp & PIPE_SCRAMBLE_RESET_MASK)) {
3617 I915_WRITE(PORT_DFT_I9XX,
3618 I915_READ(PORT_DFT_I9XX) & ~DC_BALANCE_RESET);
3619 }
3620}
3621
46a19188 3622static int ilk_pipe_crc_ctl_reg(enum intel_pipe_crc_source *source,
5b3a856b
DV
3623 uint32_t *val)
3624{
46a19188
DV
3625 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3626 *source = INTEL_PIPE_CRC_SOURCE_PIPE;
3627
3628 switch (*source) {
5b3a856b
DV
3629 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3630 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_ILK;
3631 break;
3632 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3633 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_ILK;
3634 break;
5b3a856b
DV
3635 case INTEL_PIPE_CRC_SOURCE_PIPE:
3636 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PIPE_ILK;
3637 break;
3d099a05 3638 case INTEL_PIPE_CRC_SOURCE_NONE:
5b3a856b
DV
3639 *val = 0;
3640 break;
3d099a05
DV
3641 default:
3642 return -EINVAL;
5b3a856b
DV
3643 }
3644
3645 return 0;
3646}
3647
fabf6e51
DV
3648static void hsw_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3649{
3650 struct drm_i915_private *dev_priv = dev->dev_private;
3651 struct intel_crtc *crtc =
3652 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
f77076c9 3653 struct intel_crtc_state *pipe_config;
fabf6e51
DV
3654
3655 drm_modeset_lock_all(dev);
f77076c9
ML
3656 pipe_config = to_intel_crtc_state(crtc->base.state);
3657
fabf6e51
DV
3658 /*
3659 * If we use the eDP transcoder we need to make sure that we don't
3660 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3661 * relevant on hsw with pipe A when using the always-on power well
3662 * routing.
3663 */
f77076c9
ML
3664 if (pipe_config->cpu_transcoder == TRANSCODER_EDP &&
3665 !pipe_config->pch_pfit.enabled) {
3666 bool active = pipe_config->base.active;
1b509259 3667
f77076c9 3668 if (active) {
1b509259 3669 intel_crtc_control(&crtc->base, false);
f77076c9
ML
3670 pipe_config = to_intel_crtc_state(crtc->base.state);
3671 }
1b509259 3672
f77076c9 3673 pipe_config->pch_pfit.force_thru = true;
fabf6e51
DV
3674
3675 intel_display_power_get(dev_priv,
3676 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
3677
1b509259
ML
3678 if (active)
3679 intel_crtc_control(&crtc->base, true);
fabf6e51
DV
3680 }
3681 drm_modeset_unlock_all(dev);
3682}
3683
3684static void hsw_undo_trans_edp_pipe_A_crc_wa(struct drm_device *dev)
3685{
3686 struct drm_i915_private *dev_priv = dev->dev_private;
3687 struct intel_crtc *crtc =
3688 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_A]);
f77076c9 3689 struct intel_crtc_state *pipe_config;
fabf6e51
DV
3690
3691 drm_modeset_lock_all(dev);
3692 /*
3693 * If we use the eDP transcoder we need to make sure that we don't
3694 * bypass the pfit, since otherwise the pipe CRC source won't work. Only
3695 * relevant on hsw with pipe A when using the always-on power well
3696 * routing.
3697 */
f77076c9
ML
3698 pipe_config = to_intel_crtc_state(crtc->base.state);
3699 if (pipe_config->pch_pfit.force_thru) {
3700 bool active = pipe_config->base.active;
fabf6e51 3701
f77076c9 3702 if (active) {
1b509259 3703 intel_crtc_control(&crtc->base, false);
f77076c9
ML
3704 pipe_config = to_intel_crtc_state(crtc->base.state);
3705 }
fabf6e51 3706
f77076c9 3707 pipe_config->pch_pfit.force_thru = false;
fabf6e51
DV
3708
3709 intel_display_power_put(dev_priv,
3710 POWER_DOMAIN_PIPE_PANEL_FITTER(PIPE_A));
1b509259
ML
3711
3712 if (active)
3713 intel_crtc_control(&crtc->base, true);
fabf6e51
DV
3714 }
3715 drm_modeset_unlock_all(dev);
3716}
3717
3718static int ivb_pipe_crc_ctl_reg(struct drm_device *dev,
3719 enum pipe pipe,
3720 enum intel_pipe_crc_source *source,
5b3a856b
DV
3721 uint32_t *val)
3722{
46a19188
DV
3723 if (*source == INTEL_PIPE_CRC_SOURCE_AUTO)
3724 *source = INTEL_PIPE_CRC_SOURCE_PF;
3725
3726 switch (*source) {
5b3a856b
DV
3727 case INTEL_PIPE_CRC_SOURCE_PLANE1:
3728 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PRIMARY_IVB;
3729 break;
3730 case INTEL_PIPE_CRC_SOURCE_PLANE2:
3731 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_SPRITE_IVB;
3732 break;
3733 case INTEL_PIPE_CRC_SOURCE_PF:
fabf6e51
DV
3734 if (IS_HASWELL(dev) && pipe == PIPE_A)
3735 hsw_trans_edp_pipe_A_crc_wa(dev);
3736
5b3a856b
DV
3737 *val = PIPE_CRC_ENABLE | PIPE_CRC_SOURCE_PF_IVB;
3738 break;
3d099a05 3739 case INTEL_PIPE_CRC_SOURCE_NONE:
5b3a856b
DV
3740 *val = 0;
3741 break;
3d099a05
DV
3742 default:
3743 return -EINVAL;
5b3a856b
DV
3744 }
3745
3746 return 0;
3747}
3748
926321d5
DV
3749static int pipe_crc_set_source(struct drm_device *dev, enum pipe pipe,
3750 enum intel_pipe_crc_source source)
3751{
3752 struct drm_i915_private *dev_priv = dev->dev_private;
cc3da175 3753 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
8c740dce
PZ
3754 struct intel_crtc *crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev,
3755 pipe));
432f3342 3756 u32 val = 0; /* shut up gcc */
5b3a856b 3757 int ret;
926321d5 3758
cc3da175
DL
3759 if (pipe_crc->source == source)
3760 return 0;
3761
ae676fcd
DL
3762 /* forbid changing the source without going back to 'none' */
3763 if (pipe_crc->source && source)
3764 return -EINVAL;
3765
9d8b0588
DV
3766 if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PIPE(pipe))) {
3767 DRM_DEBUG_KMS("Trying to capture CRC while pipe is off\n");
3768 return -EIO;
3769 }
3770
52f843f6 3771 if (IS_GEN2(dev))
46a19188 3772 ret = i8xx_pipe_crc_ctl_reg(&source, &val);
52f843f6 3773 else if (INTEL_INFO(dev)->gen < 5)
46a19188 3774 ret = i9xx_pipe_crc_ctl_reg(dev, pipe, &source, &val);
7ac0129b 3775 else if (IS_VALLEYVIEW(dev))
fabf6e51 3776 ret = vlv_pipe_crc_ctl_reg(dev, pipe, &source, &val);
4b79ebf7 3777 else if (IS_GEN5(dev) || IS_GEN6(dev))
46a19188 3778 ret = ilk_pipe_crc_ctl_reg(&source, &val);
5b3a856b 3779 else
fabf6e51 3780 ret = ivb_pipe_crc_ctl_reg(dev, pipe, &source, &val);
5b3a856b
DV
3781
3782 if (ret != 0)
3783 return ret;
3784
4b584369
DL
3785 /* none -> real source transition */
3786 if (source) {
4252fbc3
VS
3787 struct intel_pipe_crc_entry *entries;
3788
7cd6ccff
DL
3789 DRM_DEBUG_DRIVER("collecting CRCs for pipe %c, %s\n",
3790 pipe_name(pipe), pipe_crc_source_name(source));
3791
3cf54b34
VS
3792 entries = kcalloc(INTEL_PIPE_CRC_ENTRIES_NR,
3793 sizeof(pipe_crc->entries[0]),
4252fbc3
VS
3794 GFP_KERNEL);
3795 if (!entries)
e5f75aca
DL
3796 return -ENOMEM;
3797
8c740dce
PZ
3798 /*
3799 * When IPS gets enabled, the pipe CRC changes. Since IPS gets
3800 * enabled and disabled dynamically based on package C states,
3801 * user space can't make reliable use of the CRCs, so let's just
3802 * completely disable it.
3803 */
3804 hsw_disable_ips(crtc);
3805
d538bbdf 3806 spin_lock_irq(&pipe_crc->lock);
64387b61 3807 kfree(pipe_crc->entries);
4252fbc3 3808 pipe_crc->entries = entries;
d538bbdf
DL
3809 pipe_crc->head = 0;
3810 pipe_crc->tail = 0;
3811 spin_unlock_irq(&pipe_crc->lock);
4b584369
DL
3812 }
3813
cc3da175 3814 pipe_crc->source = source;
926321d5 3815
926321d5
DV
3816 I915_WRITE(PIPE_CRC_CTL(pipe), val);
3817 POSTING_READ(PIPE_CRC_CTL(pipe));
3818
e5f75aca
DL
3819 /* real source -> none transition */
3820 if (source == INTEL_PIPE_CRC_SOURCE_NONE) {
d538bbdf 3821 struct intel_pipe_crc_entry *entries;
a33d7105
DV
3822 struct intel_crtc *crtc =
3823 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
d538bbdf 3824
7cd6ccff
DL
3825 DRM_DEBUG_DRIVER("stopping CRCs for pipe %c\n",
3826 pipe_name(pipe));
3827
a33d7105 3828 drm_modeset_lock(&crtc->base.mutex, NULL);
f77076c9 3829 if (crtc->base.state->active)
a33d7105
DV
3830 intel_wait_for_vblank(dev, pipe);
3831 drm_modeset_unlock(&crtc->base.mutex);
bcf17ab2 3832
d538bbdf
DL
3833 spin_lock_irq(&pipe_crc->lock);
3834 entries = pipe_crc->entries;
e5f75aca 3835 pipe_crc->entries = NULL;
9ad6d99f
VS
3836 pipe_crc->head = 0;
3837 pipe_crc->tail = 0;
d538bbdf
DL
3838 spin_unlock_irq(&pipe_crc->lock);
3839
3840 kfree(entries);
84093603
DV
3841
3842 if (IS_G4X(dev))
3843 g4x_undo_pipe_scramble_reset(dev, pipe);
8d2f24ca
DV
3844 else if (IS_VALLEYVIEW(dev))
3845 vlv_undo_pipe_scramble_reset(dev, pipe);
fabf6e51
DV
3846 else if (IS_HASWELL(dev) && pipe == PIPE_A)
3847 hsw_undo_trans_edp_pipe_A_crc_wa(dev);
8c740dce
PZ
3848
3849 hsw_enable_ips(crtc);
e5f75aca
DL
3850 }
3851
926321d5
DV
3852 return 0;
3853}
3854
3855/*
3856 * Parse pipe CRC command strings:
b94dec87
DL
3857 * command: wsp* object wsp+ name wsp+ source wsp*
3858 * object: 'pipe'
3859 * name: (A | B | C)
926321d5
DV
3860 * source: (none | plane1 | plane2 | pf)
3861 * wsp: (#0x20 | #0x9 | #0xA)+
3862 *
3863 * eg.:
b94dec87
DL
3864 * "pipe A plane1" -> Start CRC computations on plane1 of pipe A
3865 * "pipe A none" -> Stop CRC
926321d5 3866 */
bd9db02f 3867static int display_crc_ctl_tokenize(char *buf, char *words[], int max_words)
926321d5
DV
3868{
3869 int n_words = 0;
3870
3871 while (*buf) {
3872 char *end;
3873
3874 /* skip leading white space */
3875 buf = skip_spaces(buf);
3876 if (!*buf)
3877 break; /* end of buffer */
3878
3879 /* find end of word */
3880 for (end = buf; *end && !isspace(*end); end++)
3881 ;
3882
3883 if (n_words == max_words) {
3884 DRM_DEBUG_DRIVER("too many words, allowed <= %d\n",
3885 max_words);
3886 return -EINVAL; /* ran out of words[] before bytes */
3887 }
3888
3889 if (*end)
3890 *end++ = '\0';
3891 words[n_words++] = buf;
3892 buf = end;
3893 }
3894
3895 return n_words;
3896}
3897
b94dec87
DL
3898enum intel_pipe_crc_object {
3899 PIPE_CRC_OBJECT_PIPE,
3900};
3901
e8dfcf78 3902static const char * const pipe_crc_objects[] = {
b94dec87
DL
3903 "pipe",
3904};
3905
3906static int
bd9db02f 3907display_crc_ctl_parse_object(const char *buf, enum intel_pipe_crc_object *o)
b94dec87
DL
3908{
3909 int i;
3910
3911 for (i = 0; i < ARRAY_SIZE(pipe_crc_objects); i++)
3912 if (!strcmp(buf, pipe_crc_objects[i])) {
bd9db02f 3913 *o = i;
b94dec87
DL
3914 return 0;
3915 }
3916
3917 return -EINVAL;
3918}
3919
bd9db02f 3920static int display_crc_ctl_parse_pipe(const char *buf, enum pipe *pipe)
926321d5
DV
3921{
3922 const char name = buf[0];
3923
3924 if (name < 'A' || name >= pipe_name(I915_MAX_PIPES))
3925 return -EINVAL;
3926
3927 *pipe = name - 'A';
3928
3929 return 0;
3930}
3931
3932static int
bd9db02f 3933display_crc_ctl_parse_source(const char *buf, enum intel_pipe_crc_source *s)
926321d5
DV
3934{
3935 int i;
3936
3937 for (i = 0; i < ARRAY_SIZE(pipe_crc_sources); i++)
3938 if (!strcmp(buf, pipe_crc_sources[i])) {
bd9db02f 3939 *s = i;
926321d5
DV
3940 return 0;
3941 }
3942
3943 return -EINVAL;
3944}
3945
bd9db02f 3946static int display_crc_ctl_parse(struct drm_device *dev, char *buf, size_t len)
926321d5 3947{
b94dec87 3948#define N_WORDS 3
926321d5 3949 int n_words;
b94dec87 3950 char *words[N_WORDS];
926321d5 3951 enum pipe pipe;
b94dec87 3952 enum intel_pipe_crc_object object;
926321d5
DV
3953 enum intel_pipe_crc_source source;
3954
bd9db02f 3955 n_words = display_crc_ctl_tokenize(buf, words, N_WORDS);
b94dec87
DL
3956 if (n_words != N_WORDS) {
3957 DRM_DEBUG_DRIVER("tokenize failed, a command is %d words\n",
3958 N_WORDS);
3959 return -EINVAL;
3960 }
3961
bd9db02f 3962 if (display_crc_ctl_parse_object(words[0], &object) < 0) {
b94dec87 3963 DRM_DEBUG_DRIVER("unknown object %s\n", words[0]);
926321d5
DV
3964 return -EINVAL;
3965 }
3966
bd9db02f 3967 if (display_crc_ctl_parse_pipe(words[1], &pipe) < 0) {
b94dec87 3968 DRM_DEBUG_DRIVER("unknown pipe %s\n", words[1]);
926321d5
DV
3969 return -EINVAL;
3970 }
3971
bd9db02f 3972 if (display_crc_ctl_parse_source(words[2], &source) < 0) {
b94dec87 3973 DRM_DEBUG_DRIVER("unknown source %s\n", words[2]);
926321d5
DV
3974 return -EINVAL;
3975 }
3976
3977 return pipe_crc_set_source(dev, pipe, source);
3978}
3979
bd9db02f
DL
3980static ssize_t display_crc_ctl_write(struct file *file, const char __user *ubuf,
3981 size_t len, loff_t *offp)
926321d5
DV
3982{
3983 struct seq_file *m = file->private_data;
3984 struct drm_device *dev = m->private;
3985 char *tmpbuf;
3986 int ret;
3987
3988 if (len == 0)
3989 return 0;
3990
3991 if (len > PAGE_SIZE - 1) {
3992 DRM_DEBUG_DRIVER("expected <%lu bytes into pipe crc control\n",
3993 PAGE_SIZE);
3994 return -E2BIG;
3995 }
3996
3997 tmpbuf = kmalloc(len + 1, GFP_KERNEL);
3998 if (!tmpbuf)
3999 return -ENOMEM;
4000
4001 if (copy_from_user(tmpbuf, ubuf, len)) {
4002 ret = -EFAULT;
4003 goto out;
4004 }
4005 tmpbuf[len] = '\0';
4006
bd9db02f 4007 ret = display_crc_ctl_parse(dev, tmpbuf, len);
926321d5
DV
4008
4009out:
4010 kfree(tmpbuf);
4011 if (ret < 0)
4012 return ret;
4013
4014 *offp += len;
4015 return len;
4016}
4017
bd9db02f 4018static const struct file_operations i915_display_crc_ctl_fops = {
926321d5 4019 .owner = THIS_MODULE,
bd9db02f 4020 .open = display_crc_ctl_open,
926321d5
DV
4021 .read = seq_read,
4022 .llseek = seq_lseek,
4023 .release = single_release,
bd9db02f 4024 .write = display_crc_ctl_write
926321d5
DV
4025};
4026
eb3394fa
TP
4027static ssize_t i915_displayport_test_active_write(struct file *file,
4028 const char __user *ubuf,
4029 size_t len, loff_t *offp)
4030{
4031 char *input_buffer;
4032 int status = 0;
4033 struct seq_file *m;
4034 struct drm_device *dev;
4035 struct drm_connector *connector;
4036 struct list_head *connector_list;
4037 struct intel_dp *intel_dp;
4038 int val = 0;
4039
4040 m = file->private_data;
4041 if (!m) {
4042 status = -ENODEV;
4043 return status;
4044 }
4045 dev = m->private;
4046
4047 if (!dev) {
4048 status = -ENODEV;
4049 return status;
4050 }
4051 connector_list = &dev->mode_config.connector_list;
4052
4053 if (len == 0)
4054 return 0;
4055
4056 input_buffer = kmalloc(len + 1, GFP_KERNEL);
4057 if (!input_buffer)
4058 return -ENOMEM;
4059
4060 if (copy_from_user(input_buffer, ubuf, len)) {
4061 status = -EFAULT;
4062 goto out;
4063 }
4064
4065 input_buffer[len] = '\0';
4066 DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
4067
4068 list_for_each_entry(connector, connector_list, head) {
4069
4070 if (connector->connector_type !=
4071 DRM_MODE_CONNECTOR_DisplayPort)
4072 continue;
4073
4074 if (connector->connector_type ==
4075 DRM_MODE_CONNECTOR_DisplayPort &&
4076 connector->status == connector_status_connected &&
4077 connector->encoder != NULL) {
4078 intel_dp = enc_to_intel_dp(connector->encoder);
4079 status = kstrtoint(input_buffer, 10, &val);
4080 if (status < 0)
4081 goto out;
4082 DRM_DEBUG_DRIVER("Got %d for test active\n", val);
4083 /* To prevent erroneous activation of the compliance
4084 * testing code, only accept an actual value of 1 here
4085 */
4086 if (val == 1)
4087 intel_dp->compliance_test_active = 1;
4088 else
4089 intel_dp->compliance_test_active = 0;
4090 }
4091 }
4092out:
4093 kfree(input_buffer);
4094 if (status < 0)
4095 return status;
4096
4097 *offp += len;
4098 return len;
4099}
4100
4101static int i915_displayport_test_active_show(struct seq_file *m, void *data)
4102{
4103 struct drm_device *dev = m->private;
4104 struct drm_connector *connector;
4105 struct list_head *connector_list = &dev->mode_config.connector_list;
4106 struct intel_dp *intel_dp;
4107
4108 if (!dev)
4109 return -ENODEV;
4110
4111 list_for_each_entry(connector, connector_list, head) {
4112
4113 if (connector->connector_type !=
4114 DRM_MODE_CONNECTOR_DisplayPort)
4115 continue;
4116
4117 if (connector->status == connector_status_connected &&
4118 connector->encoder != NULL) {
4119 intel_dp = enc_to_intel_dp(connector->encoder);
4120 if (intel_dp->compliance_test_active)
4121 seq_puts(m, "1");
4122 else
4123 seq_puts(m, "0");
4124 } else
4125 seq_puts(m, "0");
4126 }
4127
4128 return 0;
4129}
4130
4131static int i915_displayport_test_active_open(struct inode *inode,
4132 struct file *file)
4133{
4134 struct drm_device *dev = inode->i_private;
4135
4136 return single_open(file, i915_displayport_test_active_show, dev);
4137}
4138
4139static const struct file_operations i915_displayport_test_active_fops = {
4140 .owner = THIS_MODULE,
4141 .open = i915_displayport_test_active_open,
4142 .read = seq_read,
4143 .llseek = seq_lseek,
4144 .release = single_release,
4145 .write = i915_displayport_test_active_write
4146};
4147
4148static int i915_displayport_test_data_show(struct seq_file *m, void *data)
4149{
4150 struct drm_device *dev = m->private;
4151 struct drm_connector *connector;
4152 struct list_head *connector_list = &dev->mode_config.connector_list;
4153 struct intel_dp *intel_dp;
4154
4155 if (!dev)
4156 return -ENODEV;
4157
4158 list_for_each_entry(connector, connector_list, head) {
4159
4160 if (connector->connector_type !=
4161 DRM_MODE_CONNECTOR_DisplayPort)
4162 continue;
4163
4164 if (connector->status == connector_status_connected &&
4165 connector->encoder != NULL) {
4166 intel_dp = enc_to_intel_dp(connector->encoder);
4167 seq_printf(m, "%lx", intel_dp->compliance_test_data);
4168 } else
4169 seq_puts(m, "0");
4170 }
4171
4172 return 0;
4173}
4174static int i915_displayport_test_data_open(struct inode *inode,
4175 struct file *file)
4176{
4177 struct drm_device *dev = inode->i_private;
4178
4179 return single_open(file, i915_displayport_test_data_show, dev);
4180}
4181
4182static const struct file_operations i915_displayport_test_data_fops = {
4183 .owner = THIS_MODULE,
4184 .open = i915_displayport_test_data_open,
4185 .read = seq_read,
4186 .llseek = seq_lseek,
4187 .release = single_release
4188};
4189
4190static int i915_displayport_test_type_show(struct seq_file *m, void *data)
4191{
4192 struct drm_device *dev = m->private;
4193 struct drm_connector *connector;
4194 struct list_head *connector_list = &dev->mode_config.connector_list;
4195 struct intel_dp *intel_dp;
4196
4197 if (!dev)
4198 return -ENODEV;
4199
4200 list_for_each_entry(connector, connector_list, head) {
4201
4202 if (connector->connector_type !=
4203 DRM_MODE_CONNECTOR_DisplayPort)
4204 continue;
4205
4206 if (connector->status == connector_status_connected &&
4207 connector->encoder != NULL) {
4208 intel_dp = enc_to_intel_dp(connector->encoder);
4209 seq_printf(m, "%02lx", intel_dp->compliance_test_type);
4210 } else
4211 seq_puts(m, "0");
4212 }
4213
4214 return 0;
4215}
4216
4217static int i915_displayport_test_type_open(struct inode *inode,
4218 struct file *file)
4219{
4220 struct drm_device *dev = inode->i_private;
4221
4222 return single_open(file, i915_displayport_test_type_show, dev);
4223}
4224
4225static const struct file_operations i915_displayport_test_type_fops = {
4226 .owner = THIS_MODULE,
4227 .open = i915_displayport_test_type_open,
4228 .read = seq_read,
4229 .llseek = seq_lseek,
4230 .release = single_release
4231};
4232
97e94b22 4233static void wm_latency_show(struct seq_file *m, const uint16_t wm[8])
369a1342
VS
4234{
4235 struct drm_device *dev = m->private;
369a1342 4236 int level;
de38b95c
VS
4237 int num_levels;
4238
4239 if (IS_CHERRYVIEW(dev))
4240 num_levels = 3;
4241 else if (IS_VALLEYVIEW(dev))
4242 num_levels = 1;
4243 else
4244 num_levels = ilk_wm_max_level(dev) + 1;
369a1342
VS
4245
4246 drm_modeset_lock_all(dev);
4247
4248 for (level = 0; level < num_levels; level++) {
4249 unsigned int latency = wm[level];
4250
97e94b22
DL
4251 /*
4252 * - WM1+ latency values in 0.5us units
de38b95c 4253 * - latencies are in us on gen9/vlv/chv
97e94b22 4254 */
de38b95c 4255 if (INTEL_INFO(dev)->gen >= 9 || IS_VALLEYVIEW(dev))
97e94b22
DL
4256 latency *= 10;
4257 else if (level > 0)
369a1342
VS
4258 latency *= 5;
4259
4260 seq_printf(m, "WM%d %u (%u.%u usec)\n",
97e94b22 4261 level, wm[level], latency / 10, latency % 10);
369a1342
VS
4262 }
4263
4264 drm_modeset_unlock_all(dev);
4265}
4266
4267static int pri_wm_latency_show(struct seq_file *m, void *data)
4268{
4269 struct drm_device *dev = m->private;
97e94b22
DL
4270 struct drm_i915_private *dev_priv = dev->dev_private;
4271 const uint16_t *latencies;
4272
4273 if (INTEL_INFO(dev)->gen >= 9)
4274 latencies = dev_priv->wm.skl_latency;
4275 else
4276 latencies = to_i915(dev)->wm.pri_latency;
369a1342 4277
97e94b22 4278 wm_latency_show(m, latencies);
369a1342
VS
4279
4280 return 0;
4281}
4282
4283static int spr_wm_latency_show(struct seq_file *m, void *data)
4284{
4285 struct drm_device *dev = m->private;
97e94b22
DL
4286 struct drm_i915_private *dev_priv = dev->dev_private;
4287 const uint16_t *latencies;
4288
4289 if (INTEL_INFO(dev)->gen >= 9)
4290 latencies = dev_priv->wm.skl_latency;
4291 else
4292 latencies = to_i915(dev)->wm.spr_latency;
369a1342 4293
97e94b22 4294 wm_latency_show(m, latencies);
369a1342
VS
4295
4296 return 0;
4297}
4298
4299static int cur_wm_latency_show(struct seq_file *m, void *data)
4300{
4301 struct drm_device *dev = m->private;
97e94b22
DL
4302 struct drm_i915_private *dev_priv = dev->dev_private;
4303 const uint16_t *latencies;
4304
4305 if (INTEL_INFO(dev)->gen >= 9)
4306 latencies = dev_priv->wm.skl_latency;
4307 else
4308 latencies = to_i915(dev)->wm.cur_latency;
369a1342 4309
97e94b22 4310 wm_latency_show(m, latencies);
369a1342
VS
4311
4312 return 0;
4313}
4314
4315static int pri_wm_latency_open(struct inode *inode, struct file *file)
4316{
4317 struct drm_device *dev = inode->i_private;
4318
de38b95c 4319 if (INTEL_INFO(dev)->gen < 5)
369a1342
VS
4320 return -ENODEV;
4321
4322 return single_open(file, pri_wm_latency_show, dev);
4323}
4324
4325static int spr_wm_latency_open(struct inode *inode, struct file *file)
4326{
4327 struct drm_device *dev = inode->i_private;
4328
9ad0257c 4329 if (HAS_GMCH_DISPLAY(dev))
369a1342
VS
4330 return -ENODEV;
4331
4332 return single_open(file, spr_wm_latency_show, dev);
4333}
4334
4335static int cur_wm_latency_open(struct inode *inode, struct file *file)
4336{
4337 struct drm_device *dev = inode->i_private;
4338
9ad0257c 4339 if (HAS_GMCH_DISPLAY(dev))
369a1342
VS
4340 return -ENODEV;
4341
4342 return single_open(file, cur_wm_latency_show, dev);
4343}
4344
4345static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
97e94b22 4346 size_t len, loff_t *offp, uint16_t wm[8])
369a1342
VS
4347{
4348 struct seq_file *m = file->private_data;
4349 struct drm_device *dev = m->private;
97e94b22 4350 uint16_t new[8] = { 0 };
de38b95c 4351 int num_levels;
369a1342
VS
4352 int level;
4353 int ret;
4354 char tmp[32];
4355
de38b95c
VS
4356 if (IS_CHERRYVIEW(dev))
4357 num_levels = 3;
4358 else if (IS_VALLEYVIEW(dev))
4359 num_levels = 1;
4360 else
4361 num_levels = ilk_wm_max_level(dev) + 1;
4362
369a1342
VS
4363 if (len >= sizeof(tmp))
4364 return -EINVAL;
4365
4366 if (copy_from_user(tmp, ubuf, len))
4367 return -EFAULT;
4368
4369 tmp[len] = '\0';
4370
97e94b22
DL
4371 ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
4372 &new[0], &new[1], &new[2], &new[3],
4373 &new[4], &new[5], &new[6], &new[7]);
369a1342
VS
4374 if (ret != num_levels)
4375 return -EINVAL;
4376
4377 drm_modeset_lock_all(dev);
4378
4379 for (level = 0; level < num_levels; level++)
4380 wm[level] = new[level];
4381
4382 drm_modeset_unlock_all(dev);
4383
4384 return len;
4385}
4386
4387
4388static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
4389 size_t len, loff_t *offp)
4390{
4391 struct seq_file *m = file->private_data;
4392 struct drm_device *dev = m->private;
97e94b22
DL
4393 struct drm_i915_private *dev_priv = dev->dev_private;
4394 uint16_t *latencies;
369a1342 4395
97e94b22
DL
4396 if (INTEL_INFO(dev)->gen >= 9)
4397 latencies = dev_priv->wm.skl_latency;
4398 else
4399 latencies = to_i915(dev)->wm.pri_latency;
4400
4401 return wm_latency_write(file, ubuf, len, offp, latencies);
369a1342
VS
4402}
4403
4404static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
4405 size_t len, loff_t *offp)
4406{
4407 struct seq_file *m = file->private_data;
4408 struct drm_device *dev = m->private;
97e94b22
DL
4409 struct drm_i915_private *dev_priv = dev->dev_private;
4410 uint16_t *latencies;
369a1342 4411
97e94b22
DL
4412 if (INTEL_INFO(dev)->gen >= 9)
4413 latencies = dev_priv->wm.skl_latency;
4414 else
4415 latencies = to_i915(dev)->wm.spr_latency;
4416
4417 return wm_latency_write(file, ubuf, len, offp, latencies);
369a1342
VS
4418}
4419
4420static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
4421 size_t len, loff_t *offp)
4422{
4423 struct seq_file *m = file->private_data;
4424 struct drm_device *dev = m->private;
97e94b22
DL
4425 struct drm_i915_private *dev_priv = dev->dev_private;
4426 uint16_t *latencies;
4427
4428 if (INTEL_INFO(dev)->gen >= 9)
4429 latencies = dev_priv->wm.skl_latency;
4430 else
4431 latencies = to_i915(dev)->wm.cur_latency;
369a1342 4432
97e94b22 4433 return wm_latency_write(file, ubuf, len, offp, latencies);
369a1342
VS
4434}
4435
4436static const struct file_operations i915_pri_wm_latency_fops = {
4437 .owner = THIS_MODULE,
4438 .open = pri_wm_latency_open,
4439 .read = seq_read,
4440 .llseek = seq_lseek,
4441 .release = single_release,
4442 .write = pri_wm_latency_write
4443};
4444
4445static const struct file_operations i915_spr_wm_latency_fops = {
4446 .owner = THIS_MODULE,
4447 .open = spr_wm_latency_open,
4448 .read = seq_read,
4449 .llseek = seq_lseek,
4450 .release = single_release,
4451 .write = spr_wm_latency_write
4452};
4453
4454static const struct file_operations i915_cur_wm_latency_fops = {
4455 .owner = THIS_MODULE,
4456 .open = cur_wm_latency_open,
4457 .read = seq_read,
4458 .llseek = seq_lseek,
4459 .release = single_release,
4460 .write = cur_wm_latency_write
4461};
4462
647416f9
KC
4463static int
4464i915_wedged_get(void *data, u64 *val)
f3cd474b 4465{
647416f9 4466 struct drm_device *dev = data;
e277a1f8 4467 struct drm_i915_private *dev_priv = dev->dev_private;
f3cd474b 4468
647416f9 4469 *val = atomic_read(&dev_priv->gpu_error.reset_counter);
f3cd474b 4470
647416f9 4471 return 0;
f3cd474b
CW
4472}
4473
647416f9
KC
4474static int
4475i915_wedged_set(void *data, u64 val)
f3cd474b 4476{
647416f9 4477 struct drm_device *dev = data;
d46c0517
ID
4478 struct drm_i915_private *dev_priv = dev->dev_private;
4479
b8d24a06
MK
4480 /*
4481 * There is no safeguard against this debugfs entry colliding
4482 * with the hangcheck calling same i915_handle_error() in
4483 * parallel, causing an explosion. For now we assume that the
4484 * test harness is responsible enough not to inject gpu hangs
4485 * while it is writing to 'i915_wedged'
4486 */
4487
4488 if (i915_reset_in_progress(&dev_priv->gpu_error))
4489 return -EAGAIN;
4490
d46c0517 4491 intel_runtime_pm_get(dev_priv);
f3cd474b 4492
58174462
MK
4493 i915_handle_error(dev, val,
4494 "Manually setting wedged to %llu", val);
d46c0517
ID
4495
4496 intel_runtime_pm_put(dev_priv);
4497
647416f9 4498 return 0;
f3cd474b
CW
4499}
4500
647416f9
KC
4501DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
4502 i915_wedged_get, i915_wedged_set,
3a3b4f98 4503 "%llu\n");
f3cd474b 4504
647416f9
KC
4505static int
4506i915_ring_stop_get(void *data, u64 *val)
e5eb3d63 4507{
647416f9 4508 struct drm_device *dev = data;
e277a1f8 4509 struct drm_i915_private *dev_priv = dev->dev_private;
e5eb3d63 4510
647416f9 4511 *val = dev_priv->gpu_error.stop_rings;
e5eb3d63 4512
647416f9 4513 return 0;
e5eb3d63
DV
4514}
4515
647416f9
KC
4516static int
4517i915_ring_stop_set(void *data, u64 val)
e5eb3d63 4518{
647416f9 4519 struct drm_device *dev = data;
e5eb3d63 4520 struct drm_i915_private *dev_priv = dev->dev_private;
647416f9 4521 int ret;
e5eb3d63 4522
647416f9 4523 DRM_DEBUG_DRIVER("Stopping rings 0x%08llx\n", val);
e5eb3d63 4524
22bcfc6a
DV
4525 ret = mutex_lock_interruptible(&dev->struct_mutex);
4526 if (ret)
4527 return ret;
4528
99584db3 4529 dev_priv->gpu_error.stop_rings = val;
e5eb3d63
DV
4530 mutex_unlock(&dev->struct_mutex);
4531
647416f9 4532 return 0;
e5eb3d63
DV
4533}
4534
647416f9
KC
4535DEFINE_SIMPLE_ATTRIBUTE(i915_ring_stop_fops,
4536 i915_ring_stop_get, i915_ring_stop_set,
4537 "0x%08llx\n");
d5442303 4538
094f9a54
CW
4539static int
4540i915_ring_missed_irq_get(void *data, u64 *val)
4541{
4542 struct drm_device *dev = data;
4543 struct drm_i915_private *dev_priv = dev->dev_private;
4544
4545 *val = dev_priv->gpu_error.missed_irq_rings;
4546 return 0;
4547}
4548
4549static int
4550i915_ring_missed_irq_set(void *data, u64 val)
4551{
4552 struct drm_device *dev = data;
4553 struct drm_i915_private *dev_priv = dev->dev_private;
4554 int ret;
4555
4556 /* Lock against concurrent debugfs callers */
4557 ret = mutex_lock_interruptible(&dev->struct_mutex);
4558 if (ret)
4559 return ret;
4560 dev_priv->gpu_error.missed_irq_rings = val;
4561 mutex_unlock(&dev->struct_mutex);
4562
4563 return 0;
4564}
4565
4566DEFINE_SIMPLE_ATTRIBUTE(i915_ring_missed_irq_fops,
4567 i915_ring_missed_irq_get, i915_ring_missed_irq_set,
4568 "0x%08llx\n");
4569
4570static int
4571i915_ring_test_irq_get(void *data, u64 *val)
4572{
4573 struct drm_device *dev = data;
4574 struct drm_i915_private *dev_priv = dev->dev_private;
4575
4576 *val = dev_priv->gpu_error.test_irq_rings;
4577
4578 return 0;
4579}
4580
4581static int
4582i915_ring_test_irq_set(void *data, u64 val)
4583{
4584 struct drm_device *dev = data;
4585 struct drm_i915_private *dev_priv = dev->dev_private;
4586 int ret;
4587
4588 DRM_DEBUG_DRIVER("Masking interrupts on rings 0x%08llx\n", val);
4589
4590 /* Lock against concurrent debugfs callers */
4591 ret = mutex_lock_interruptible(&dev->struct_mutex);
4592 if (ret)
4593 return ret;
4594
4595 dev_priv->gpu_error.test_irq_rings = val;
4596 mutex_unlock(&dev->struct_mutex);
4597
4598 return 0;
4599}
4600
4601DEFINE_SIMPLE_ATTRIBUTE(i915_ring_test_irq_fops,
4602 i915_ring_test_irq_get, i915_ring_test_irq_set,
4603 "0x%08llx\n");
4604
dd624afd
CW
4605#define DROP_UNBOUND 0x1
4606#define DROP_BOUND 0x2
4607#define DROP_RETIRE 0x4
4608#define DROP_ACTIVE 0x8
4609#define DROP_ALL (DROP_UNBOUND | \
4610 DROP_BOUND | \
4611 DROP_RETIRE | \
4612 DROP_ACTIVE)
647416f9
KC
4613static int
4614i915_drop_caches_get(void *data, u64 *val)
dd624afd 4615{
647416f9 4616 *val = DROP_ALL;
dd624afd 4617
647416f9 4618 return 0;
dd624afd
CW
4619}
4620
647416f9
KC
4621static int
4622i915_drop_caches_set(void *data, u64 val)
dd624afd 4623{
647416f9 4624 struct drm_device *dev = data;
dd624afd 4625 struct drm_i915_private *dev_priv = dev->dev_private;
647416f9 4626 int ret;
dd624afd 4627
2f9fe5ff 4628 DRM_DEBUG("Dropping caches: 0x%08llx\n", val);
dd624afd
CW
4629
4630 /* No need to check and wait for gpu resets, only libdrm auto-restarts
4631 * on ioctls on -EAGAIN. */
4632 ret = mutex_lock_interruptible(&dev->struct_mutex);
4633 if (ret)
4634 return ret;
4635
4636 if (val & DROP_ACTIVE) {
4637 ret = i915_gpu_idle(dev);
4638 if (ret)
4639 goto unlock;
4640 }
4641
4642 if (val & (DROP_RETIRE | DROP_ACTIVE))
4643 i915_gem_retire_requests(dev);
4644
21ab4e74
CW
4645 if (val & DROP_BOUND)
4646 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_BOUND);
4ad72b7f 4647
21ab4e74
CW
4648 if (val & DROP_UNBOUND)
4649 i915_gem_shrink(dev_priv, LONG_MAX, I915_SHRINK_UNBOUND);
dd624afd
CW
4650
4651unlock:
4652 mutex_unlock(&dev->struct_mutex);
4653
647416f9 4654 return ret;
dd624afd
CW
4655}
4656
647416f9
KC
4657DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
4658 i915_drop_caches_get, i915_drop_caches_set,
4659 "0x%08llx\n");
dd624afd 4660
647416f9
KC
4661static int
4662i915_max_freq_get(void *data, u64 *val)
358733e9 4663{
647416f9 4664 struct drm_device *dev = data;
e277a1f8 4665 struct drm_i915_private *dev_priv = dev->dev_private;
647416f9 4666 int ret;
004777cb 4667
daa3afb2 4668 if (INTEL_INFO(dev)->gen < 6)
004777cb
DV
4669 return -ENODEV;
4670
5c9669ce
TR
4671 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4672
4fc688ce 4673 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
004777cb
DV
4674 if (ret)
4675 return ret;
358733e9 4676
7c59a9c1 4677 *val = intel_gpu_freq(dev_priv, dev_priv->rps.max_freq_softlimit);
4fc688ce 4678 mutex_unlock(&dev_priv->rps.hw_lock);
358733e9 4679
647416f9 4680 return 0;
358733e9
JB
4681}
4682
647416f9
KC
4683static int
4684i915_max_freq_set(void *data, u64 val)
358733e9 4685{
647416f9 4686 struct drm_device *dev = data;
358733e9 4687 struct drm_i915_private *dev_priv = dev->dev_private;
bc4d91f6 4688 u32 hw_max, hw_min;
647416f9 4689 int ret;
004777cb 4690
daa3afb2 4691 if (INTEL_INFO(dev)->gen < 6)
004777cb 4692 return -ENODEV;
358733e9 4693
5c9669ce
TR
4694 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4695
647416f9 4696 DRM_DEBUG_DRIVER("Manually setting max freq to %llu\n", val);
358733e9 4697
4fc688ce 4698 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
004777cb
DV
4699 if (ret)
4700 return ret;
4701
358733e9
JB
4702 /*
4703 * Turbo will still be enabled, but won't go above the set value.
4704 */
bc4d91f6 4705 val = intel_freq_opcode(dev_priv, val);
dd0a1aa1 4706
bc4d91f6
AG
4707 hw_max = dev_priv->rps.max_freq;
4708 hw_min = dev_priv->rps.min_freq;
dd0a1aa1 4709
b39fb297 4710 if (val < hw_min || val > hw_max || val < dev_priv->rps.min_freq_softlimit) {
dd0a1aa1
JM
4711 mutex_unlock(&dev_priv->rps.hw_lock);
4712 return -EINVAL;
0a073b84
JB
4713 }
4714
b39fb297 4715 dev_priv->rps.max_freq_softlimit = val;
dd0a1aa1 4716
ffe02b40 4717 intel_set_rps(dev, val);
dd0a1aa1 4718
4fc688ce 4719 mutex_unlock(&dev_priv->rps.hw_lock);
358733e9 4720
647416f9 4721 return 0;
358733e9
JB
4722}
4723
647416f9
KC
4724DEFINE_SIMPLE_ATTRIBUTE(i915_max_freq_fops,
4725 i915_max_freq_get, i915_max_freq_set,
3a3b4f98 4726 "%llu\n");
358733e9 4727
647416f9
KC
4728static int
4729i915_min_freq_get(void *data, u64 *val)
1523c310 4730{
647416f9 4731 struct drm_device *dev = data;
e277a1f8 4732 struct drm_i915_private *dev_priv = dev->dev_private;
647416f9 4733 int ret;
004777cb 4734
daa3afb2 4735 if (INTEL_INFO(dev)->gen < 6)
004777cb
DV
4736 return -ENODEV;
4737
5c9669ce
TR
4738 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4739
4fc688ce 4740 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
004777cb
DV
4741 if (ret)
4742 return ret;
1523c310 4743
7c59a9c1 4744 *val = intel_gpu_freq(dev_priv, dev_priv->rps.min_freq_softlimit);
4fc688ce 4745 mutex_unlock(&dev_priv->rps.hw_lock);
1523c310 4746
647416f9 4747 return 0;
1523c310
JB
4748}
4749
647416f9
KC
4750static int
4751i915_min_freq_set(void *data, u64 val)
1523c310 4752{
647416f9 4753 struct drm_device *dev = data;
1523c310 4754 struct drm_i915_private *dev_priv = dev->dev_private;
bc4d91f6 4755 u32 hw_max, hw_min;
647416f9 4756 int ret;
004777cb 4757
daa3afb2 4758 if (INTEL_INFO(dev)->gen < 6)
004777cb 4759 return -ENODEV;
1523c310 4760
5c9669ce
TR
4761 flush_delayed_work(&dev_priv->rps.delayed_resume_work);
4762
647416f9 4763 DRM_DEBUG_DRIVER("Manually setting min freq to %llu\n", val);
1523c310 4764
4fc688ce 4765 ret = mutex_lock_interruptible(&dev_priv->rps.hw_lock);
004777cb
DV
4766 if (ret)
4767 return ret;
4768
1523c310
JB
4769 /*
4770 * Turbo will still be enabled, but won't go below the set value.
4771 */
bc4d91f6 4772 val = intel_freq_opcode(dev_priv, val);
dd0a1aa1 4773
bc4d91f6
AG
4774 hw_max = dev_priv->rps.max_freq;
4775 hw_min = dev_priv->rps.min_freq;
dd0a1aa1 4776
b39fb297 4777 if (val < hw_min || val > hw_max || val > dev_priv->rps.max_freq_softlimit) {
dd0a1aa1
JM
4778 mutex_unlock(&dev_priv->rps.hw_lock);
4779 return -EINVAL;
0a073b84 4780 }
dd0a1aa1 4781
b39fb297 4782 dev_priv->rps.min_freq_softlimit = val;
dd0a1aa1 4783
ffe02b40 4784 intel_set_rps(dev, val);
dd0a1aa1 4785
4fc688ce 4786 mutex_unlock(&dev_priv->rps.hw_lock);
1523c310 4787
647416f9 4788 return 0;
1523c310
JB
4789}
4790
647416f9
KC
4791DEFINE_SIMPLE_ATTRIBUTE(i915_min_freq_fops,
4792 i915_min_freq_get, i915_min_freq_set,
3a3b4f98 4793 "%llu\n");
1523c310 4794
647416f9
KC
4795static int
4796i915_cache_sharing_get(void *data, u64 *val)
07b7ddd9 4797{
647416f9 4798 struct drm_device *dev = data;
e277a1f8 4799 struct drm_i915_private *dev_priv = dev->dev_private;
07b7ddd9 4800 u32 snpcr;
647416f9 4801 int ret;
07b7ddd9 4802
004777cb
DV
4803 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4804 return -ENODEV;
4805
22bcfc6a
DV
4806 ret = mutex_lock_interruptible(&dev->struct_mutex);
4807 if (ret)
4808 return ret;
c8c8fb33 4809 intel_runtime_pm_get(dev_priv);
22bcfc6a 4810
07b7ddd9 4811 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
c8c8fb33
PZ
4812
4813 intel_runtime_pm_put(dev_priv);
07b7ddd9
JB
4814 mutex_unlock(&dev_priv->dev->struct_mutex);
4815
647416f9 4816 *val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
07b7ddd9 4817
647416f9 4818 return 0;
07b7ddd9
JB
4819}
4820
647416f9
KC
4821static int
4822i915_cache_sharing_set(void *data, u64 val)
07b7ddd9 4823{
647416f9 4824 struct drm_device *dev = data;
07b7ddd9 4825 struct drm_i915_private *dev_priv = dev->dev_private;
07b7ddd9 4826 u32 snpcr;
07b7ddd9 4827
004777cb
DV
4828 if (!(IS_GEN6(dev) || IS_GEN7(dev)))
4829 return -ENODEV;
4830
647416f9 4831 if (val > 3)
07b7ddd9
JB
4832 return -EINVAL;
4833
c8c8fb33 4834 intel_runtime_pm_get(dev_priv);
647416f9 4835 DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
07b7ddd9
JB
4836
4837 /* Update the cache sharing policy here as well */
4838 snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
4839 snpcr &= ~GEN6_MBC_SNPCR_MASK;
4840 snpcr |= (val << GEN6_MBC_SNPCR_SHIFT);
4841 I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
4842
c8c8fb33 4843 intel_runtime_pm_put(dev_priv);
647416f9 4844 return 0;
07b7ddd9
JB
4845}
4846
647416f9
KC
4847DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
4848 i915_cache_sharing_get, i915_cache_sharing_set,
4849 "%llu\n");
07b7ddd9 4850
5d39525a
JM
4851struct sseu_dev_status {
4852 unsigned int slice_total;
4853 unsigned int subslice_total;
4854 unsigned int subslice_per_slice;
4855 unsigned int eu_total;
4856 unsigned int eu_per_subslice;
4857};
4858
4859static void cherryview_sseu_device_status(struct drm_device *dev,
4860 struct sseu_dev_status *stat)
4861{
4862 struct drm_i915_private *dev_priv = dev->dev_private;
4863 const int ss_max = 2;
4864 int ss;
4865 u32 sig1[ss_max], sig2[ss_max];
4866
4867 sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
4868 sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
4869 sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
4870 sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
4871
4872 for (ss = 0; ss < ss_max; ss++) {
4873 unsigned int eu_cnt;
4874
4875 if (sig1[ss] & CHV_SS_PG_ENABLE)
4876 /* skip disabled subslice */
4877 continue;
4878
4879 stat->slice_total = 1;
4880 stat->subslice_per_slice++;
4881 eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
4882 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
4883 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
4884 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
4885 stat->eu_total += eu_cnt;
4886 stat->eu_per_subslice = max(stat->eu_per_subslice, eu_cnt);
4887 }
4888 stat->subslice_total = stat->subslice_per_slice;
4889}
4890
4891static void gen9_sseu_device_status(struct drm_device *dev,
4892 struct sseu_dev_status *stat)
4893{
4894 struct drm_i915_private *dev_priv = dev->dev_private;
1c046bc1 4895 int s_max = 3, ss_max = 4;
5d39525a
JM
4896 int s, ss;
4897 u32 s_reg[s_max], eu_reg[2*s_max], eu_mask[2];
4898
1c046bc1
JM
4899 /* BXT has a single slice and at most 3 subslices. */
4900 if (IS_BROXTON(dev)) {
4901 s_max = 1;
4902 ss_max = 3;
4903 }
4904
4905 for (s = 0; s < s_max; s++) {
4906 s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
4907 eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
4908 eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
4909 }
4910
5d39525a
JM
4911 eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
4912 GEN9_PGCTL_SSA_EU19_ACK |
4913 GEN9_PGCTL_SSA_EU210_ACK |
4914 GEN9_PGCTL_SSA_EU311_ACK;
4915 eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
4916 GEN9_PGCTL_SSB_EU19_ACK |
4917 GEN9_PGCTL_SSB_EU210_ACK |
4918 GEN9_PGCTL_SSB_EU311_ACK;
4919
4920 for (s = 0; s < s_max; s++) {
1c046bc1
JM
4921 unsigned int ss_cnt = 0;
4922
5d39525a
JM
4923 if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
4924 /* skip disabled slice */
4925 continue;
4926
4927 stat->slice_total++;
1c046bc1
JM
4928
4929 if (IS_SKYLAKE(dev))
4930 ss_cnt = INTEL_INFO(dev)->subslice_per_slice;
4931
5d39525a
JM
4932 for (ss = 0; ss < ss_max; ss++) {
4933 unsigned int eu_cnt;
4934
1c046bc1
JM
4935 if (IS_BROXTON(dev) &&
4936 !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
4937 /* skip disabled subslice */
4938 continue;
4939
4940 if (IS_BROXTON(dev))
4941 ss_cnt++;
4942
5d39525a
JM
4943 eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
4944 eu_mask[ss%2]);
4945 stat->eu_total += eu_cnt;
4946 stat->eu_per_subslice = max(stat->eu_per_subslice,
4947 eu_cnt);
4948 }
1c046bc1
JM
4949
4950 stat->subslice_total += ss_cnt;
4951 stat->subslice_per_slice = max(stat->subslice_per_slice,
4952 ss_cnt);
5d39525a
JM
4953 }
4954}
4955
3873218f
JM
4956static int i915_sseu_status(struct seq_file *m, void *unused)
4957{
4958 struct drm_info_node *node = (struct drm_info_node *) m->private;
4959 struct drm_device *dev = node->minor->dev;
5d39525a 4960 struct sseu_dev_status stat;
3873218f 4961
5575f03a 4962 if ((INTEL_INFO(dev)->gen < 8) || IS_BROADWELL(dev))
3873218f
JM
4963 return -ENODEV;
4964
4965 seq_puts(m, "SSEU Device Info\n");
4966 seq_printf(m, " Available Slice Total: %u\n",
4967 INTEL_INFO(dev)->slice_total);
4968 seq_printf(m, " Available Subslice Total: %u\n",
4969 INTEL_INFO(dev)->subslice_total);
4970 seq_printf(m, " Available Subslice Per Slice: %u\n",
4971 INTEL_INFO(dev)->subslice_per_slice);
4972 seq_printf(m, " Available EU Total: %u\n",
4973 INTEL_INFO(dev)->eu_total);
4974 seq_printf(m, " Available EU Per Subslice: %u\n",
4975 INTEL_INFO(dev)->eu_per_subslice);
4976 seq_printf(m, " Has Slice Power Gating: %s\n",
4977 yesno(INTEL_INFO(dev)->has_slice_pg));
4978 seq_printf(m, " Has Subslice Power Gating: %s\n",
4979 yesno(INTEL_INFO(dev)->has_subslice_pg));
4980 seq_printf(m, " Has EU Power Gating: %s\n",
4981 yesno(INTEL_INFO(dev)->has_eu_pg));
4982
7f992aba 4983 seq_puts(m, "SSEU Device Status\n");
5d39525a 4984 memset(&stat, 0, sizeof(stat));
5575f03a 4985 if (IS_CHERRYVIEW(dev)) {
5d39525a 4986 cherryview_sseu_device_status(dev, &stat);
1c046bc1 4987 } else if (INTEL_INFO(dev)->gen >= 9) {
5d39525a 4988 gen9_sseu_device_status(dev, &stat);
7f992aba 4989 }
5d39525a
JM
4990 seq_printf(m, " Enabled Slice Total: %u\n",
4991 stat.slice_total);
4992 seq_printf(m, " Enabled Subslice Total: %u\n",
4993 stat.subslice_total);
4994 seq_printf(m, " Enabled Subslice Per Slice: %u\n",
4995 stat.subslice_per_slice);
4996 seq_printf(m, " Enabled EU Total: %u\n",
4997 stat.eu_total);
4998 seq_printf(m, " Enabled EU Per Subslice: %u\n",
4999 stat.eu_per_subslice);
7f992aba 5000
3873218f
JM
5001 return 0;
5002}
5003
6d794d42
BW
5004static int i915_forcewake_open(struct inode *inode, struct file *file)
5005{
5006 struct drm_device *dev = inode->i_private;
5007 struct drm_i915_private *dev_priv = dev->dev_private;
6d794d42 5008
075edca4 5009 if (INTEL_INFO(dev)->gen < 6)
6d794d42
BW
5010 return 0;
5011
6daccb0b 5012 intel_runtime_pm_get(dev_priv);
59bad947 5013 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
6d794d42
BW
5014
5015 return 0;
5016}
5017
c43b5634 5018static int i915_forcewake_release(struct inode *inode, struct file *file)
6d794d42
BW
5019{
5020 struct drm_device *dev = inode->i_private;
5021 struct drm_i915_private *dev_priv = dev->dev_private;
5022
075edca4 5023 if (INTEL_INFO(dev)->gen < 6)
6d794d42
BW
5024 return 0;
5025
59bad947 5026 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
6daccb0b 5027 intel_runtime_pm_put(dev_priv);
6d794d42
BW
5028
5029 return 0;
5030}
5031
5032static const struct file_operations i915_forcewake_fops = {
5033 .owner = THIS_MODULE,
5034 .open = i915_forcewake_open,
5035 .release = i915_forcewake_release,
5036};
5037
5038static int i915_forcewake_create(struct dentry *root, struct drm_minor *minor)
5039{
5040 struct drm_device *dev = minor->dev;
5041 struct dentry *ent;
5042
5043 ent = debugfs_create_file("i915_forcewake_user",
8eb57294 5044 S_IRUSR,
6d794d42
BW
5045 root, dev,
5046 &i915_forcewake_fops);
f3c5fe97
WY
5047 if (!ent)
5048 return -ENOMEM;
6d794d42 5049
8eb57294 5050 return drm_add_fake_info_node(minor, ent, &i915_forcewake_fops);
6d794d42
BW
5051}
5052
6a9c308d
DV
5053static int i915_debugfs_create(struct dentry *root,
5054 struct drm_minor *minor,
5055 const char *name,
5056 const struct file_operations *fops)
07b7ddd9
JB
5057{
5058 struct drm_device *dev = minor->dev;
5059 struct dentry *ent;
5060
6a9c308d 5061 ent = debugfs_create_file(name,
07b7ddd9
JB
5062 S_IRUGO | S_IWUSR,
5063 root, dev,
6a9c308d 5064 fops);
f3c5fe97
WY
5065 if (!ent)
5066 return -ENOMEM;
07b7ddd9 5067
6a9c308d 5068 return drm_add_fake_info_node(minor, ent, fops);
07b7ddd9
JB
5069}
5070
06c5bf8c 5071static const struct drm_info_list i915_debugfs_list[] = {
311bd68e 5072 {"i915_capabilities", i915_capabilities, 0},
73aa808f 5073 {"i915_gem_objects", i915_gem_object_info, 0},
08c18323 5074 {"i915_gem_gtt", i915_gem_gtt_info, 0},
1b50247a 5075 {"i915_gem_pinned", i915_gem_gtt_info, 0, (void *) PINNED_LIST},
433e12f7 5076 {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
433e12f7 5077 {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
6d2b8885 5078 {"i915_gem_stolen", i915_gem_stolen_list_info },
4e5359cd 5079 {"i915_gem_pageflip", i915_gem_pageflip_info, 0},
2017263e
BG
5080 {"i915_gem_request", i915_gem_request_info, 0},
5081 {"i915_gem_seqno", i915_gem_seqno_info, 0},
a6172a80 5082 {"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
2017263e 5083 {"i915_gem_interrupt", i915_interrupt_info, 0},
1ec14ad3
CW
5084 {"i915_gem_hws", i915_hws_info, 0, (void *)RCS},
5085 {"i915_gem_hws_blt", i915_hws_info, 0, (void *)BCS},
5086 {"i915_gem_hws_bsd", i915_hws_info, 0, (void *)VCS},
9010ebfd 5087 {"i915_gem_hws_vebox", i915_hws_info, 0, (void *)VECS},
493018dc 5088 {"i915_gem_batch_pool", i915_gem_batch_pool_info, 0},
adb4bd12 5089 {"i915_frequency_info", i915_frequency_info, 0},
f654449a 5090 {"i915_hangcheck_info", i915_hangcheck_info, 0},
f97108d1 5091 {"i915_drpc_info", i915_drpc_info, 0},
7648fa99 5092 {"i915_emon_status", i915_emon_status, 0},
23b2f8bb 5093 {"i915_ring_freq_table", i915_ring_freq_table, 0},
9a851789 5094 {"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
b5e50c3f 5095 {"i915_fbc_status", i915_fbc_status, 0},
92d44621 5096 {"i915_ips_status", i915_ips_status, 0},
4a9bef37 5097 {"i915_sr_status", i915_sr_status, 0},
44834a67 5098 {"i915_opregion", i915_opregion, 0},
37811fcc 5099 {"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
e76d3630 5100 {"i915_context_status", i915_context_status, 0},
c0ab1ae9 5101 {"i915_dump_lrc", i915_dump_lrc, 0},
4ba70e44 5102 {"i915_execlists", i915_execlists, 0},
f65367b5 5103 {"i915_forcewake_domains", i915_forcewake_domains, 0},
ea16a3cd 5104 {"i915_swizzle_info", i915_swizzle_info, 0},
3cf17fc5 5105 {"i915_ppgtt_info", i915_ppgtt_info, 0},
63573eb7 5106 {"i915_llc", i915_llc, 0},
e91fd8c6 5107 {"i915_edp_psr_status", i915_edp_psr_status, 0},
d2e216d0 5108 {"i915_sink_crc_eDP1", i915_sink_crc, 0},
ec013e7f 5109 {"i915_energy_uJ", i915_energy_uJ, 0},
6455c870 5110 {"i915_runtime_pm_status", i915_runtime_pm_status, 0},
1da51581 5111 {"i915_power_domain_info", i915_power_domain_info, 0},
53f5e3ca 5112 {"i915_display_info", i915_display_info, 0},
e04934cf 5113 {"i915_semaphore_status", i915_semaphore_status, 0},
728e29d7 5114 {"i915_shared_dplls_info", i915_shared_dplls_info, 0},
11bed958 5115 {"i915_dp_mst_info", i915_dp_mst_info, 0},
1ed1ef9d 5116 {"i915_wa_registers", i915_wa_registers, 0},
c5511e44 5117 {"i915_ddb_info", i915_ddb_info, 0},
3873218f 5118 {"i915_sseu_status", i915_sseu_status, 0},
a54746e3 5119 {"i915_drrs_status", i915_drrs_status, 0},
1854d5ca 5120 {"i915_rps_boost_info", i915_rps_boost_info, 0},
2017263e 5121};
27c202ad 5122#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
2017263e 5123
06c5bf8c 5124static const struct i915_debugfs_files {
34b9674c
DV
5125 const char *name;
5126 const struct file_operations *fops;
5127} i915_debugfs_files[] = {
5128 {"i915_wedged", &i915_wedged_fops},
5129 {"i915_max_freq", &i915_max_freq_fops},
5130 {"i915_min_freq", &i915_min_freq_fops},
5131 {"i915_cache_sharing", &i915_cache_sharing_fops},
5132 {"i915_ring_stop", &i915_ring_stop_fops},
094f9a54
CW
5133 {"i915_ring_missed_irq", &i915_ring_missed_irq_fops},
5134 {"i915_ring_test_irq", &i915_ring_test_irq_fops},
34b9674c
DV
5135 {"i915_gem_drop_caches", &i915_drop_caches_fops},
5136 {"i915_error_state", &i915_error_state_fops},
5137 {"i915_next_seqno", &i915_next_seqno_fops},
bd9db02f 5138 {"i915_display_crc_ctl", &i915_display_crc_ctl_fops},
369a1342
VS
5139 {"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
5140 {"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
5141 {"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
da46f936 5142 {"i915_fbc_false_color", &i915_fbc_fc_fops},
eb3394fa
TP
5143 {"i915_dp_test_data", &i915_displayport_test_data_fops},
5144 {"i915_dp_test_type", &i915_displayport_test_type_fops},
5145 {"i915_dp_test_active", &i915_displayport_test_active_fops}
34b9674c
DV
5146};
5147
07144428
DL
5148void intel_display_crc_init(struct drm_device *dev)
5149{
5150 struct drm_i915_private *dev_priv = dev->dev_private;
b378360e 5151 enum pipe pipe;
07144428 5152
055e393f 5153 for_each_pipe(dev_priv, pipe) {
b378360e 5154 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
07144428 5155
d538bbdf
DL
5156 pipe_crc->opened = false;
5157 spin_lock_init(&pipe_crc->lock);
07144428
DL
5158 init_waitqueue_head(&pipe_crc->wq);
5159 }
5160}
5161
27c202ad 5162int i915_debugfs_init(struct drm_minor *minor)
2017263e 5163{
34b9674c 5164 int ret, i;
f3cd474b 5165
6d794d42 5166 ret = i915_forcewake_create(minor->debugfs_root, minor);
358733e9
JB
5167 if (ret)
5168 return ret;
6a9c308d 5169
07144428
DL
5170 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
5171 ret = i915_pipe_crc_create(minor->debugfs_root, minor, i);
5172 if (ret)
5173 return ret;
5174 }
5175
34b9674c
DV
5176 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5177 ret = i915_debugfs_create(minor->debugfs_root, minor,
5178 i915_debugfs_files[i].name,
5179 i915_debugfs_files[i].fops);
5180 if (ret)
5181 return ret;
5182 }
40633219 5183
27c202ad
BG
5184 return drm_debugfs_create_files(i915_debugfs_list,
5185 I915_DEBUGFS_ENTRIES,
2017263e
BG
5186 minor->debugfs_root, minor);
5187}
5188
27c202ad 5189void i915_debugfs_cleanup(struct drm_minor *minor)
2017263e 5190{
34b9674c
DV
5191 int i;
5192
27c202ad
BG
5193 drm_debugfs_remove_files(i915_debugfs_list,
5194 I915_DEBUGFS_ENTRIES, minor);
07144428 5195
6d794d42
BW
5196 drm_debugfs_remove_files((struct drm_info_list *) &i915_forcewake_fops,
5197 1, minor);
07144428 5198
e309a997 5199 for (i = 0; i < ARRAY_SIZE(i915_pipe_crc_data); i++) {
07144428
DL
5200 struct drm_info_list *info_list =
5201 (struct drm_info_list *)&i915_pipe_crc_data[i];
5202
5203 drm_debugfs_remove_files(info_list, 1, minor);
5204 }
5205
34b9674c
DV
5206 for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
5207 struct drm_info_list *info_list =
5208 (struct drm_info_list *) i915_debugfs_files[i].fops;
5209
5210 drm_debugfs_remove_files(info_list, 1, minor);
5211 }
2017263e 5212}
aa7471d2
JN
5213
5214struct dpcd_block {
5215 /* DPCD dump start address. */
5216 unsigned int offset;
5217 /* DPCD dump end address, inclusive. If unset, .size will be used. */
5218 unsigned int end;
5219 /* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
5220 size_t size;
5221 /* Only valid for eDP. */
5222 bool edp;
5223};
5224
5225static const struct dpcd_block i915_dpcd_debug[] = {
5226 { .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
5227 { .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
5228 { .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
5229 { .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
5230 { .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
5231 { .offset = DP_SET_POWER },
5232 { .offset = DP_EDP_DPCD_REV },
5233 { .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
5234 { .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
5235 { .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
5236};
5237
5238static int i915_dpcd_show(struct seq_file *m, void *data)
5239{
5240 struct drm_connector *connector = m->private;
5241 struct intel_dp *intel_dp =
5242 enc_to_intel_dp(&intel_attached_encoder(connector)->base);
5243 uint8_t buf[16];
5244 ssize_t err;
5245 int i;
5246
5c1a8875
MK
5247 if (connector->status != connector_status_connected)
5248 return -ENODEV;
5249
aa7471d2
JN
5250 for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
5251 const struct dpcd_block *b = &i915_dpcd_debug[i];
5252 size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
5253
5254 if (b->edp &&
5255 connector->connector_type != DRM_MODE_CONNECTOR_eDP)
5256 continue;
5257
5258 /* low tech for now */
5259 if (WARN_ON(size > sizeof(buf)))
5260 continue;
5261
5262 err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
5263 if (err <= 0) {
5264 DRM_ERROR("dpcd read (%zu bytes at %u) failed (%zd)\n",
5265 size, b->offset, err);
5266 continue;
5267 }
5268
5269 seq_printf(m, "%04x: %*ph\n", b->offset, (int) size, buf);
b3f9d7d7 5270 }
aa7471d2
JN
5271
5272 return 0;
5273}
5274
5275static int i915_dpcd_open(struct inode *inode, struct file *file)
5276{
5277 return single_open(file, i915_dpcd_show, inode->i_private);
5278}
5279
5280static const struct file_operations i915_dpcd_fops = {
5281 .owner = THIS_MODULE,
5282 .open = i915_dpcd_open,
5283 .read = seq_read,
5284 .llseek = seq_lseek,
5285 .release = single_release,
5286};
5287
5288/**
5289 * i915_debugfs_connector_add - add i915 specific connector debugfs files
5290 * @connector: pointer to a registered drm_connector
5291 *
5292 * Cleanup will be done by drm_connector_unregister() through a call to
5293 * drm_debugfs_connector_remove().
5294 *
5295 * Returns 0 on success, negative error codes on error.
5296 */
5297int i915_debugfs_connector_add(struct drm_connector *connector)
5298{
5299 struct dentry *root = connector->debugfs_entry;
5300
5301 /* The connector must have been registered beforehands. */
5302 if (!root)
5303 return -ENODEV;
5304
5305 if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
5306 connector->connector_type == DRM_MODE_CONNECTOR_eDP)
5307 debugfs_create_file("i915_dpcd", S_IRUGO, root, connector,
5308 &i915_dpcd_fops);
5309
5310 return 0;
5311}