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