Home | History | Annotate | Line # | Download | only in i915
      1  1.5  riastrad /*	$NetBSD: i915_debugfs.c,v 1.5 2021/12/18 23:45:28 riastradh Exp $	*/
      2  1.3  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright  2008 Intel Corporation
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      7  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
      8  1.1  riastrad  * to deal in the Software without restriction, including without limitation
      9  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     10  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     11  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     12  1.1  riastrad  *
     13  1.1  riastrad  * The above copyright notice and this permission notice (including the next
     14  1.1  riastrad  * paragraph) shall be included in all copies or substantial portions of the
     15  1.1  riastrad  * Software.
     16  1.1  riastrad  *
     17  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     18  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     19  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     20  1.1  riastrad  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     21  1.1  riastrad  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     22  1.1  riastrad  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     23  1.1  riastrad  * IN THE SOFTWARE.
     24  1.1  riastrad  *
     25  1.1  riastrad  * Authors:
     26  1.1  riastrad  *    Eric Anholt <eric (at) anholt.net>
     27  1.1  riastrad  *    Keith Packard <keithp (at) keithp.com>
     28  1.1  riastrad  *
     29  1.1  riastrad  */
     30  1.1  riastrad 
     31  1.3  riastrad #include <sys/cdefs.h>
     32  1.5  riastrad __KERNEL_RCSID(0, "$NetBSD: i915_debugfs.c,v 1.5 2021/12/18 23:45:28 riastradh Exp $");
     33  1.3  riastrad 
     34  1.5  riastrad #include <linux/sched/mm.h>
     35  1.5  riastrad #include <linux/sort.h>
     36  1.1  riastrad 
     37  1.5  riastrad #include <drm/drm_debugfs.h>
     38  1.5  riastrad #include <drm/drm_fourcc.h>
     39  1.2      matt 
     40  1.5  riastrad #include "display/intel_display_types.h"
     41  1.5  riastrad #include "display/intel_dp.h"
     42  1.5  riastrad #include "display/intel_fbc.h"
     43  1.5  riastrad #include "display/intel_hdcp.h"
     44  1.5  riastrad #include "display/intel_hdmi.h"
     45  1.5  riastrad #include "display/intel_psr.h"
     46  1.5  riastrad 
     47  1.5  riastrad #include "gem/i915_gem_context.h"
     48  1.5  riastrad #include "gt/intel_gt_pm.h"
     49  1.5  riastrad #include "gt/intel_gt_requests.h"
     50  1.5  riastrad #include "gt/intel_reset.h"
     51  1.5  riastrad #include "gt/intel_rc6.h"
     52  1.5  riastrad #include "gt/intel_rps.h"
     53  1.5  riastrad #include "gt/uc/intel_guc_submission.h"
     54  1.5  riastrad 
     55  1.5  riastrad #include "i915_debugfs.h"
     56  1.5  riastrad #include "i915_irq.h"
     57  1.5  riastrad #include "i915_trace.h"
     58  1.5  riastrad #include "intel_csr.h"
     59  1.5  riastrad #include "intel_pm.h"
     60  1.5  riastrad #include "intel_sideband.h"
     61  1.2      matt 
     62  1.5  riastrad static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
     63  1.5  riastrad {
     64  1.5  riastrad 	return to_i915(node->minor->dev);
     65  1.2      matt }
     66  1.2      matt 
     67  1.1  riastrad static int i915_capabilities(struct seq_file *m, void *data)
     68  1.1  riastrad {
     69  1.5  riastrad 	struct drm_i915_private *i915 = node_to_i915(m->private);
     70  1.5  riastrad 	struct drm_printer p = drm_seq_file_printer(m);
     71  1.5  riastrad 
     72  1.5  riastrad 	seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(i915));
     73  1.5  riastrad 
     74  1.5  riastrad 	intel_device_info_print_static(INTEL_INFO(i915), &p);
     75  1.5  riastrad 	intel_device_info_print_runtime(RUNTIME_INFO(i915), &p);
     76  1.5  riastrad 	intel_driver_caps_print(&i915->caps, &p);
     77  1.1  riastrad 
     78  1.5  riastrad 	kernel_param_lock(THIS_MODULE);
     79  1.5  riastrad 	i915_params_dump(&i915_modparams, &p);
     80  1.5  riastrad 	kernel_param_unlock(THIS_MODULE);
     81  1.1  riastrad 
     82  1.1  riastrad 	return 0;
     83  1.1  riastrad }
     84  1.1  riastrad 
     85  1.5  riastrad static char get_tiling_flag(struct drm_i915_gem_object *obj)
     86  1.1  riastrad {
     87  1.5  riastrad 	switch (i915_gem_object_get_tiling(obj)) {
     88  1.5  riastrad 	default:
     89  1.5  riastrad 	case I915_TILING_NONE: return ' ';
     90  1.5  riastrad 	case I915_TILING_X: return 'X';
     91  1.5  riastrad 	case I915_TILING_Y: return 'Y';
     92  1.5  riastrad 	}
     93  1.1  riastrad }
     94  1.1  riastrad 
     95  1.5  riastrad static char get_global_flag(struct drm_i915_gem_object *obj)
     96  1.1  riastrad {
     97  1.5  riastrad 	return READ_ONCE(obj->userfault_count) ? 'g' : ' ';
     98  1.1  riastrad }
     99  1.1  riastrad 
    100  1.5  riastrad static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
    101  1.1  riastrad {
    102  1.5  riastrad 	return obj->mm.mapping ? 'M' : ' ';
    103  1.3  riastrad }
    104  1.3  riastrad 
    105  1.5  riastrad static const char *
    106  1.5  riastrad stringify_page_sizes(unsigned int page_sizes, char *buf, size_t len)
    107  1.3  riastrad {
    108  1.5  riastrad 	size_t x = 0;
    109  1.5  riastrad 
    110  1.5  riastrad 	switch (page_sizes) {
    111  1.5  riastrad 	case 0:
    112  1.5  riastrad 		return "";
    113  1.5  riastrad 	case I915_GTT_PAGE_SIZE_4K:
    114  1.5  riastrad 		return "4K";
    115  1.5  riastrad 	case I915_GTT_PAGE_SIZE_64K:
    116  1.5  riastrad 		return "64K";
    117  1.5  riastrad 	case I915_GTT_PAGE_SIZE_2M:
    118  1.5  riastrad 		return "2M";
    119  1.5  riastrad 	default:
    120  1.5  riastrad 		if (!buf)
    121  1.5  riastrad 			return "M";
    122  1.5  riastrad 
    123  1.5  riastrad 		if (page_sizes & I915_GTT_PAGE_SIZE_2M)
    124  1.5  riastrad 			x += snprintf(buf + x, len - x, "2M, ");
    125  1.5  riastrad 		if (page_sizes & I915_GTT_PAGE_SIZE_64K)
    126  1.5  riastrad 			x += snprintf(buf + x, len - x, "64K, ");
    127  1.5  riastrad 		if (page_sizes & I915_GTT_PAGE_SIZE_4K)
    128  1.5  riastrad 			x += snprintf(buf + x, len - x, "4K, ");
    129  1.5  riastrad 		buf[x-2] = '\0';
    130  1.3  riastrad 
    131  1.5  riastrad 		return buf;
    132  1.3  riastrad 	}
    133  1.1  riastrad }
    134  1.1  riastrad 
    135  1.1  riastrad static void
    136  1.1  riastrad describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
    137  1.1  riastrad {
    138  1.3  riastrad 	struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
    139  1.5  riastrad 	struct intel_engine_cs *engine;
    140  1.2      matt 	struct i915_vma *vma;
    141  1.2      matt 	int pin_count = 0;
    142  1.2      matt 
    143  1.5  riastrad 	seq_printf(m, "%pK: %c%c%c %8zdKiB %02x %02x %s%s%s",
    144  1.1  riastrad 		   &obj->base,
    145  1.1  riastrad 		   get_tiling_flag(obj),
    146  1.2      matt 		   get_global_flag(obj),
    147  1.5  riastrad 		   get_pin_mapped_flag(obj),
    148  1.1  riastrad 		   obj->base.size / 1024,
    149  1.5  riastrad 		   obj->read_domains,
    150  1.5  riastrad 		   obj->write_domain,
    151  1.5  riastrad 		   i915_cache_level_str(dev_priv, obj->cache_level),
    152  1.5  riastrad 		   obj->mm.dirty ? " dirty" : "",
    153  1.5  riastrad 		   obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
    154  1.1  riastrad 	if (obj->base.name)
    155  1.1  riastrad 		seq_printf(m, " (name: %d)", obj->base.name);
    156  1.2      matt 
    157  1.5  riastrad 	spin_lock(&obj->vma.lock);
    158  1.5  riastrad 	list_for_each_entry(vma, &obj->vma.list, obj_link) {
    159  1.5  riastrad 		if (!drm_mm_node_allocated(&vma->node))
    160  1.5  riastrad 			continue;
    161  1.1  riastrad 
    162  1.5  riastrad 		spin_unlock(&obj->vma.lock);
    163  1.1  riastrad 
    164  1.5  riastrad 		if (i915_vma_is_pinned(vma))
    165  1.5  riastrad 			pin_count++;
    166  1.1  riastrad 
    167  1.5  riastrad 		seq_printf(m, " (%sgtt offset: %08llx, size: %08llx, pages: %s",
    168  1.5  riastrad 			   i915_vma_is_ggtt(vma) ? "g" : "pp",
    169  1.5  riastrad 			   vma->node.start, vma->node.size,
    170  1.5  riastrad 			   stringify_page_sizes(vma->page_sizes.gtt, NULL, 0));
    171  1.5  riastrad 		if (i915_vma_is_ggtt(vma)) {
    172  1.5  riastrad 			switch (vma->ggtt_view.type) {
    173  1.5  riastrad 			case I915_GGTT_VIEW_NORMAL:
    174  1.5  riastrad 				seq_puts(m, ", normal");
    175  1.5  riastrad 				break;
    176  1.2      matt 
    177  1.5  riastrad 			case I915_GGTT_VIEW_PARTIAL:
    178  1.5  riastrad 				seq_printf(m, ", partial [%08llx+%x]",
    179  1.5  riastrad 					   vma->ggtt_view.partial.offset << PAGE_SHIFT,
    180  1.5  riastrad 					   vma->ggtt_view.partial.size << PAGE_SHIFT);
    181  1.5  riastrad 				break;
    182  1.2      matt 
    183  1.5  riastrad 			case I915_GGTT_VIEW_ROTATED:
    184  1.5  riastrad 				seq_printf(m, ", rotated [(%ux%u, stride=%u, offset=%u), (%ux%u, stride=%u, offset=%u)]",
    185  1.5  riastrad 					   vma->ggtt_view.rotated.plane[0].width,
    186  1.5  riastrad 					   vma->ggtt_view.rotated.plane[0].height,
    187  1.5  riastrad 					   vma->ggtt_view.rotated.plane[0].stride,
    188  1.5  riastrad 					   vma->ggtt_view.rotated.plane[0].offset,
    189  1.5  riastrad 					   vma->ggtt_view.rotated.plane[1].width,
    190  1.5  riastrad 					   vma->ggtt_view.rotated.plane[1].height,
    191  1.5  riastrad 					   vma->ggtt_view.rotated.plane[1].stride,
    192  1.5  riastrad 					   vma->ggtt_view.rotated.plane[1].offset);
    193  1.5  riastrad 				break;
    194  1.2      matt 
    195  1.5  riastrad 			case I915_GGTT_VIEW_REMAPPED:
    196  1.5  riastrad 				seq_printf(m, ", remapped [(%ux%u, stride=%u, offset=%u), (%ux%u, stride=%u, offset=%u)]",
    197  1.5  riastrad 					   vma->ggtt_view.remapped.plane[0].width,
    198  1.5  riastrad 					   vma->ggtt_view.remapped.plane[0].height,
    199  1.5  riastrad 					   vma->ggtt_view.remapped.plane[0].stride,
    200  1.5  riastrad 					   vma->ggtt_view.remapped.plane[0].offset,
    201  1.5  riastrad 					   vma->ggtt_view.remapped.plane[1].width,
    202  1.5  riastrad 					   vma->ggtt_view.remapped.plane[1].height,
    203  1.5  riastrad 					   vma->ggtt_view.remapped.plane[1].stride,
    204  1.5  riastrad 					   vma->ggtt_view.remapped.plane[1].offset);
    205  1.5  riastrad 				break;
    206  1.2      matt 
    207  1.5  riastrad 			default:
    208  1.5  riastrad 				MISSING_CASE(vma->ggtt_view.type);
    209  1.5  riastrad 				break;
    210  1.5  riastrad 			}
    211  1.5  riastrad 		}
    212  1.5  riastrad 		if (vma->fence)
    213  1.5  riastrad 			seq_printf(m, " , fence: %d", vma->fence->id);
    214  1.5  riastrad 		seq_puts(m, ")");
    215  1.2      matt 
    216  1.5  riastrad 		spin_lock(&obj->vma.lock);
    217  1.2      matt 	}
    218  1.5  riastrad 	spin_unlock(&obj->vma.lock);
    219  1.2      matt 
    220  1.5  riastrad 	seq_printf(m, " (pinned x %d)", pin_count);
    221  1.5  riastrad 	if (obj->stolen)
    222  1.5  riastrad 		seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
    223  1.5  riastrad 	if (i915_gem_object_is_framebuffer(obj))
    224  1.5  riastrad 		seq_printf(m, " (fb)");
    225  1.1  riastrad 
    226  1.5  riastrad 	engine = i915_gem_object_last_write_engine(obj);
    227  1.5  riastrad 	if (engine)
    228  1.5  riastrad 		seq_printf(m, " (%s)", engine->name);
    229  1.1  riastrad }
    230  1.1  riastrad 
    231  1.2      matt struct file_stats {
    232  1.5  riastrad 	struct i915_address_space *vm;
    233  1.3  riastrad 	unsigned long count;
    234  1.3  riastrad 	u64 total, unbound;
    235  1.3  riastrad 	u64 active, inactive;
    236  1.5  riastrad 	u64 closed;
    237  1.2      matt };
    238  1.2      matt 
    239  1.2      matt static int per_file_stats(int id, void *ptr, void *data)
    240  1.2      matt {
    241  1.2      matt 	struct drm_i915_gem_object *obj = ptr;
    242  1.2      matt 	struct file_stats *stats = data;
    243  1.2      matt 	struct i915_vma *vma;
    244  1.2      matt 
    245  1.5  riastrad 	if (!kref_get_unless_zero(&obj->base.refcount))
    246  1.5  riastrad 		return 0;
    247  1.5  riastrad 
    248  1.2      matt 	stats->count++;
    249  1.2      matt 	stats->total += obj->base.size;
    250  1.5  riastrad 	if (!atomic_read(&obj->bind_count))
    251  1.5  riastrad 		stats->unbound += obj->base.size;
    252  1.2      matt 
    253  1.5  riastrad 	spin_lock(&obj->vma.lock);
    254  1.5  riastrad 	if (!stats->vm) {
    255  1.5  riastrad 		for_each_ggtt_vma(vma, obj) {
    256  1.2      matt 			if (!drm_mm_node_allocated(&vma->node))
    257  1.2      matt 				continue;
    258  1.2      matt 
    259  1.5  riastrad 			if (i915_vma_is_active(vma))
    260  1.5  riastrad 				stats->active += vma->node.size;
    261  1.2      matt 			else
    262  1.5  riastrad 				stats->inactive += vma->node.size;
    263  1.2      matt 
    264  1.5  riastrad 			if (i915_vma_is_closed(vma))
    265  1.5  riastrad 				stats->closed += vma->node.size;
    266  1.2      matt 		}
    267  1.2      matt 	} else {
    268  1.5  riastrad 		struct rb_node *p = obj->vma.tree.rb_node;
    269  1.5  riastrad 
    270  1.5  riastrad 		while (p) {
    271  1.5  riastrad 			long cmp;
    272  1.5  riastrad 
    273  1.5  riastrad 			vma = rb_entry(p, typeof(*vma), obj_node);
    274  1.5  riastrad 			cmp = i915_vma_compare(vma, stats->vm, NULL);
    275  1.5  riastrad 			if (cmp == 0) {
    276  1.5  riastrad 				if (drm_mm_node_allocated(&vma->node)) {
    277  1.5  riastrad 					if (i915_vma_is_active(vma))
    278  1.5  riastrad 						stats->active += vma->node.size;
    279  1.5  riastrad 					else
    280  1.5  riastrad 						stats->inactive += vma->node.size;
    281  1.5  riastrad 
    282  1.5  riastrad 					if (i915_vma_is_closed(vma))
    283  1.5  riastrad 						stats->closed += vma->node.size;
    284  1.5  riastrad 				}
    285  1.5  riastrad 				break;
    286  1.5  riastrad 			}
    287  1.5  riastrad 			if (cmp < 0)
    288  1.5  riastrad 				p = p->rb_right;
    289  1.2      matt 			else
    290  1.5  riastrad 				p = p->rb_left;
    291  1.2      matt 		}
    292  1.2      matt 	}
    293  1.5  riastrad 	spin_unlock(&obj->vma.lock);
    294  1.2      matt 
    295  1.5  riastrad 	i915_gem_object_put(obj);
    296  1.2      matt 	return 0;
    297  1.2      matt }
    298  1.2      matt 
    299  1.3  riastrad #define print_file_stats(m, name, stats) do { \
    300  1.3  riastrad 	if (stats.count) \
    301  1.5  riastrad 		seq_printf(m, "%s: %lu objects, %llu bytes (%llu active, %llu inactive, %llu unbound, %llu closed)\n", \
    302  1.3  riastrad 			   name, \
    303  1.3  riastrad 			   stats.count, \
    304  1.3  riastrad 			   stats.total, \
    305  1.3  riastrad 			   stats.active, \
    306  1.3  riastrad 			   stats.inactive, \
    307  1.5  riastrad 			   stats.unbound, \
    308  1.5  riastrad 			   stats.closed); \
    309  1.3  riastrad } while (0)
    310  1.3  riastrad 
    311  1.5  riastrad static void print_context_stats(struct seq_file *m,
    312  1.5  riastrad 				struct drm_i915_private *i915)
    313  1.3  riastrad {
    314  1.5  riastrad 	struct file_stats kstats = {};
    315  1.5  riastrad 	struct i915_gem_context *ctx, *cn;
    316  1.3  riastrad 
    317  1.5  riastrad 	spin_lock(&i915->gem.contexts.lock);
    318  1.5  riastrad 	list_for_each_entry_safe(ctx, cn, &i915->gem.contexts.list, link) {
    319  1.5  riastrad 		struct i915_gem_engines_iter it;
    320  1.5  riastrad 		struct intel_context *ce;
    321  1.3  riastrad 
    322  1.5  riastrad 		if (!kref_get_unless_zero(&ctx->ref))
    323  1.5  riastrad 			continue;
    324  1.1  riastrad 
    325  1.5  riastrad 		spin_unlock(&i915->gem.contexts.lock);
    326  1.1  riastrad 
    327  1.5  riastrad 		for_each_gem_engine(ce,
    328  1.5  riastrad 				    i915_gem_context_lock_engines(ctx), it) {
    329  1.5  riastrad 			if (intel_context_pin_if_active(ce)) {
    330  1.5  riastrad 				rcu_read_lock();
    331  1.5  riastrad 				if (ce->state)
    332  1.5  riastrad 					per_file_stats(0,
    333  1.5  riastrad 						       ce->state->obj, &kstats);
    334  1.5  riastrad 				per_file_stats(0, ce->ring->vma->obj, &kstats);
    335  1.5  riastrad 				rcu_read_unlock();
    336  1.5  riastrad 				intel_context_unpin(ce);
    337  1.5  riastrad 			}
    338  1.1  riastrad 		}
    339  1.5  riastrad 		i915_gem_context_unlock_engines(ctx);
    340  1.2      matt 
    341  1.5  riastrad 		if (!IS_ERR_OR_NULL(ctx->file_priv)) {
    342  1.5  riastrad 			struct file_stats stats = {
    343  1.5  riastrad 				.vm = rcu_access_pointer(ctx->vm),
    344  1.5  riastrad 			};
    345  1.5  riastrad 			struct drm_file *file = ctx->file_priv->file;
    346  1.5  riastrad 			struct task_struct *task;
    347  1.5  riastrad 			char name[80];
    348  1.1  riastrad 
    349  1.5  riastrad 			rcu_read_lock();
    350  1.5  riastrad 			idr_for_each(&file->object_idr, per_file_stats, &stats);
    351  1.5  riastrad 			rcu_read_unlock();
    352  1.1  riastrad 
    353  1.5  riastrad 			rcu_read_lock();
    354  1.5  riastrad 			task = pid_task(ctx->pid ?: file->pid, PIDTYPE_PID);
    355  1.5  riastrad 			snprintf(name, sizeof(name), "%s",
    356  1.5  riastrad 				 task ? task->comm : "<unknown>");
    357  1.5  riastrad 			rcu_read_unlock();
    358  1.1  riastrad 
    359  1.5  riastrad 			print_file_stats(m, name, stats);
    360  1.5  riastrad 		}
    361  1.1  riastrad 
    362  1.5  riastrad 		spin_lock(&i915->gem.contexts.lock);
    363  1.5  riastrad 		list_safe_reset_next(ctx, cn, link);
    364  1.5  riastrad 		i915_gem_context_put(ctx);
    365  1.3  riastrad 	}
    366  1.5  riastrad 	spin_unlock(&i915->gem.contexts.lock);
    367  1.3  riastrad 
    368  1.5  riastrad 	print_file_stats(m, "[k]contexts", kstats);
    369  1.3  riastrad }
    370  1.3  riastrad 
    371  1.5  riastrad static int i915_gem_object_info(struct seq_file *m, void *data)
    372  1.3  riastrad {
    373  1.5  riastrad 	struct drm_i915_private *i915 = node_to_i915(m->private);
    374  1.5  riastrad 	struct intel_memory_region *mr;
    375  1.5  riastrad 	enum intel_region_id id;
    376  1.3  riastrad 
    377  1.5  riastrad 	seq_printf(m, "%u shrinkable [%u free] objects, %llu bytes\n",
    378  1.5  riastrad 		   i915->mm.shrink_count,
    379  1.5  riastrad 		   atomic_read(&i915->mm.free_count),
    380  1.5  riastrad 		   i915->mm.shrink_memory);
    381  1.5  riastrad 	for_each_memory_region(mr, i915, id)
    382  1.5  riastrad 		seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
    383  1.5  riastrad 			   mr->name, &mr->total, &mr->avail);
    384  1.5  riastrad 	seq_putc(m, '\n');
    385  1.3  riastrad 
    386  1.5  riastrad 	print_context_stats(m, i915);
    387  1.3  riastrad 
    388  1.1  riastrad 	return 0;
    389  1.1  riastrad }
    390  1.1  riastrad 
    391  1.5  riastrad static void gen8_display_interrupt_info(struct seq_file *m)
    392  1.1  riastrad {
    393  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
    394  1.5  riastrad 	enum pipe pipe;
    395  1.1  riastrad 
    396  1.5  riastrad 	for_each_pipe(dev_priv, pipe) {
    397  1.5  riastrad 		enum intel_display_power_domain power_domain;
    398  1.5  riastrad 		intel_wakeref_t wakeref;
    399  1.1  riastrad 
    400  1.5  riastrad 		power_domain = POWER_DOMAIN_PIPE(pipe);
    401  1.5  riastrad 		wakeref = intel_display_power_get_if_enabled(dev_priv,
    402  1.5  riastrad 							     power_domain);
    403  1.5  riastrad 		if (!wakeref) {
    404  1.5  riastrad 			seq_printf(m, "Pipe %c power disabled\n",
    405  1.5  riastrad 				   pipe_name(pipe));
    406  1.1  riastrad 			continue;
    407  1.1  riastrad 		}
    408  1.5  riastrad 		seq_printf(m, "Pipe %c IMR:\t%08x\n",
    409  1.5  riastrad 			   pipe_name(pipe),
    410  1.5  riastrad 			   I915_READ(GEN8_DE_PIPE_IMR(pipe)));
    411  1.5  riastrad 		seq_printf(m, "Pipe %c IIR:\t%08x\n",
    412  1.5  riastrad 			   pipe_name(pipe),
    413  1.5  riastrad 			   I915_READ(GEN8_DE_PIPE_IIR(pipe)));
    414  1.5  riastrad 		seq_printf(m, "Pipe %c IER:\t%08x\n",
    415  1.5  riastrad 			   pipe_name(pipe),
    416  1.5  riastrad 			   I915_READ(GEN8_DE_PIPE_IER(pipe)));
    417  1.5  riastrad 
    418  1.5  riastrad 		intel_display_power_put(dev_priv, power_domain, wakeref);
    419  1.5  riastrad 	}
    420  1.5  riastrad 
    421  1.5  riastrad 	seq_printf(m, "Display Engine port interrupt mask:\t%08x\n",
    422  1.5  riastrad 		   I915_READ(GEN8_DE_PORT_IMR));
    423  1.5  riastrad 	seq_printf(m, "Display Engine port interrupt identity:\t%08x\n",
    424  1.5  riastrad 		   I915_READ(GEN8_DE_PORT_IIR));
    425  1.5  riastrad 	seq_printf(m, "Display Engine port interrupt enable:\t%08x\n",
    426  1.5  riastrad 		   I915_READ(GEN8_DE_PORT_IER));
    427  1.5  riastrad 
    428  1.5  riastrad 	seq_printf(m, "Display Engine misc interrupt mask:\t%08x\n",
    429  1.5  riastrad 		   I915_READ(GEN8_DE_MISC_IMR));
    430  1.5  riastrad 	seq_printf(m, "Display Engine misc interrupt identity:\t%08x\n",
    431  1.5  riastrad 		   I915_READ(GEN8_DE_MISC_IIR));
    432  1.5  riastrad 	seq_printf(m, "Display Engine misc interrupt enable:\t%08x\n",
    433  1.5  riastrad 		   I915_READ(GEN8_DE_MISC_IER));
    434  1.5  riastrad 
    435  1.5  riastrad 	seq_printf(m, "PCU interrupt mask:\t%08x\n",
    436  1.5  riastrad 		   I915_READ(GEN8_PCU_IMR));
    437  1.5  riastrad 	seq_printf(m, "PCU interrupt identity:\t%08x\n",
    438  1.5  riastrad 		   I915_READ(GEN8_PCU_IIR));
    439  1.5  riastrad 	seq_printf(m, "PCU interrupt enable:\t%08x\n",
    440  1.5  riastrad 		   I915_READ(GEN8_PCU_IER));
    441  1.1  riastrad }
    442  1.1  riastrad 
    443  1.5  riastrad static int i915_interrupt_info(struct seq_file *m, void *data)
    444  1.1  riastrad {
    445  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
    446  1.5  riastrad 	struct intel_engine_cs *engine;
    447  1.5  riastrad 	intel_wakeref_t wakeref;
    448  1.5  riastrad 	int i, pipe;
    449  1.1  riastrad 
    450  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
    451  1.1  riastrad 
    452  1.5  riastrad 	if (IS_CHERRYVIEW(dev_priv)) {
    453  1.5  riastrad 		intel_wakeref_t pref;
    454  1.2      matt 
    455  1.3  riastrad 		seq_printf(m, "Master Interrupt Control:\t%08x\n",
    456  1.3  riastrad 			   I915_READ(GEN8_MASTER_IRQ));
    457  1.3  riastrad 
    458  1.3  riastrad 		seq_printf(m, "Display IER:\t%08x\n",
    459  1.3  riastrad 			   I915_READ(VLV_IER));
    460  1.3  riastrad 		seq_printf(m, "Display IIR:\t%08x\n",
    461  1.3  riastrad 			   I915_READ(VLV_IIR));
    462  1.3  riastrad 		seq_printf(m, "Display IIR_RW:\t%08x\n",
    463  1.3  riastrad 			   I915_READ(VLV_IIR_RW));
    464  1.3  riastrad 		seq_printf(m, "Display IMR:\t%08x\n",
    465  1.3  riastrad 			   I915_READ(VLV_IMR));
    466  1.5  riastrad 		for_each_pipe(dev_priv, pipe) {
    467  1.5  riastrad 			enum intel_display_power_domain power_domain;
    468  1.5  riastrad 
    469  1.5  riastrad 			power_domain = POWER_DOMAIN_PIPE(pipe);
    470  1.5  riastrad 			pref = intel_display_power_get_if_enabled(dev_priv,
    471  1.5  riastrad 								  power_domain);
    472  1.5  riastrad 			if (!pref) {
    473  1.5  riastrad 				seq_printf(m, "Pipe %c power disabled\n",
    474  1.5  riastrad 					   pipe_name(pipe));
    475  1.5  riastrad 				continue;
    476  1.5  riastrad 			}
    477  1.5  riastrad 
    478  1.3  riastrad 			seq_printf(m, "Pipe %c stat:\t%08x\n",
    479  1.3  riastrad 				   pipe_name(pipe),
    480  1.3  riastrad 				   I915_READ(PIPESTAT(pipe)));
    481  1.3  riastrad 
    482  1.5  riastrad 			intel_display_power_put(dev_priv, power_domain, pref);
    483  1.5  riastrad 		}
    484  1.5  riastrad 
    485  1.5  riastrad 		pref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
    486  1.3  riastrad 		seq_printf(m, "Port hotplug:\t%08x\n",
    487  1.3  riastrad 			   I915_READ(PORT_HOTPLUG_EN));
    488  1.3  riastrad 		seq_printf(m, "DPFLIPSTAT:\t%08x\n",
    489  1.3  riastrad 			   I915_READ(VLV_DPFLIPSTAT));
    490  1.3  riastrad 		seq_printf(m, "DPINVGTT:\t%08x\n",
    491  1.3  riastrad 			   I915_READ(DPINVGTT));
    492  1.5  riastrad 		intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, pref);
    493  1.3  riastrad 
    494  1.3  riastrad 		for (i = 0; i < 4; i++) {
    495  1.3  riastrad 			seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
    496  1.3  riastrad 				   i, I915_READ(GEN8_GT_IMR(i)));
    497  1.3  riastrad 			seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
    498  1.3  riastrad 				   i, I915_READ(GEN8_GT_IIR(i)));
    499  1.3  riastrad 			seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
    500  1.3  riastrad 				   i, I915_READ(GEN8_GT_IER(i)));
    501  1.3  riastrad 		}
    502  1.3  riastrad 
    503  1.3  riastrad 		seq_printf(m, "PCU interrupt mask:\t%08x\n",
    504  1.3  riastrad 			   I915_READ(GEN8_PCU_IMR));
    505  1.3  riastrad 		seq_printf(m, "PCU interrupt identity:\t%08x\n",
    506  1.3  riastrad 			   I915_READ(GEN8_PCU_IIR));
    507  1.3  riastrad 		seq_printf(m, "PCU interrupt enable:\t%08x\n",
    508  1.3  riastrad 			   I915_READ(GEN8_PCU_IER));
    509  1.5  riastrad 	} else if (INTEL_GEN(dev_priv) >= 11) {
    510  1.5  riastrad 		seq_printf(m, "Master Interrupt Control:  %08x\n",
    511  1.5  riastrad 			   I915_READ(GEN11_GFX_MSTR_IRQ));
    512  1.5  riastrad 
    513  1.5  riastrad 		seq_printf(m, "Render/Copy Intr Enable:   %08x\n",
    514  1.5  riastrad 			   I915_READ(GEN11_RENDER_COPY_INTR_ENABLE));
    515  1.5  riastrad 		seq_printf(m, "VCS/VECS Intr Enable:      %08x\n",
    516  1.5  riastrad 			   I915_READ(GEN11_VCS_VECS_INTR_ENABLE));
    517  1.5  riastrad 		seq_printf(m, "GUC/SG Intr Enable:\t   %08x\n",
    518  1.5  riastrad 			   I915_READ(GEN11_GUC_SG_INTR_ENABLE));
    519  1.5  riastrad 		seq_printf(m, "GPM/WGBOXPERF Intr Enable: %08x\n",
    520  1.5  riastrad 			   I915_READ(GEN11_GPM_WGBOXPERF_INTR_ENABLE));
    521  1.5  riastrad 		seq_printf(m, "Crypto Intr Enable:\t   %08x\n",
    522  1.5  riastrad 			   I915_READ(GEN11_CRYPTO_RSVD_INTR_ENABLE));
    523  1.5  riastrad 		seq_printf(m, "GUnit/CSME Intr Enable:\t   %08x\n",
    524  1.5  riastrad 			   I915_READ(GEN11_GUNIT_CSME_INTR_ENABLE));
    525  1.5  riastrad 
    526  1.5  riastrad 		seq_printf(m, "Display Interrupt Control:\t%08x\n",
    527  1.5  riastrad 			   I915_READ(GEN11_DISPLAY_INT_CTL));
    528  1.5  riastrad 
    529  1.5  riastrad 		gen8_display_interrupt_info(m);
    530  1.5  riastrad 	} else if (INTEL_GEN(dev_priv) >= 8) {
    531  1.2      matt 		seq_printf(m, "Master Interrupt Control:\t%08x\n",
    532  1.2      matt 			   I915_READ(GEN8_MASTER_IRQ));
    533  1.2      matt 
    534  1.2      matt 		for (i = 0; i < 4; i++) {
    535  1.2      matt 			seq_printf(m, "GT Interrupt IMR %d:\t%08x\n",
    536  1.2      matt 				   i, I915_READ(GEN8_GT_IMR(i)));
    537  1.2      matt 			seq_printf(m, "GT Interrupt IIR %d:\t%08x\n",
    538  1.2      matt 				   i, I915_READ(GEN8_GT_IIR(i)));
    539  1.2      matt 			seq_printf(m, "GT Interrupt IER %d:\t%08x\n",
    540  1.2      matt 				   i, I915_READ(GEN8_GT_IER(i)));
    541  1.2      matt 		}
    542  1.1  riastrad 
    543  1.5  riastrad 		gen8_display_interrupt_info(m);
    544  1.5  riastrad 	} else if (IS_VALLEYVIEW(dev_priv)) {
    545  1.5  riastrad 		intel_wakeref_t pref;
    546  1.2      matt 
    547  1.1  riastrad 		seq_printf(m, "Display IER:\t%08x\n",
    548  1.1  riastrad 			   I915_READ(VLV_IER));
    549  1.1  riastrad 		seq_printf(m, "Display IIR:\t%08x\n",
    550  1.1  riastrad 			   I915_READ(VLV_IIR));
    551  1.1  riastrad 		seq_printf(m, "Display IIR_RW:\t%08x\n",
    552  1.1  riastrad 			   I915_READ(VLV_IIR_RW));
    553  1.1  riastrad 		seq_printf(m, "Display IMR:\t%08x\n",
    554  1.1  riastrad 			   I915_READ(VLV_IMR));
    555  1.5  riastrad 		for_each_pipe(dev_priv, pipe) {
    556  1.5  riastrad 			enum intel_display_power_domain power_domain;
    557  1.5  riastrad 
    558  1.5  riastrad 			power_domain = POWER_DOMAIN_PIPE(pipe);
    559  1.5  riastrad 			pref = intel_display_power_get_if_enabled(dev_priv,
    560  1.5  riastrad 								  power_domain);
    561  1.5  riastrad 			if (!pref) {
    562  1.5  riastrad 				seq_printf(m, "Pipe %c power disabled\n",
    563  1.5  riastrad 					   pipe_name(pipe));
    564  1.5  riastrad 				continue;
    565  1.5  riastrad 			}
    566  1.5  riastrad 
    567  1.1  riastrad 			seq_printf(m, "Pipe %c stat:\t%08x\n",
    568  1.1  riastrad 				   pipe_name(pipe),
    569  1.1  riastrad 				   I915_READ(PIPESTAT(pipe)));
    570  1.5  riastrad 			intel_display_power_put(dev_priv, power_domain, pref);
    571  1.5  riastrad 		}
    572  1.1  riastrad 
    573  1.1  riastrad 		seq_printf(m, "Master IER:\t%08x\n",
    574  1.1  riastrad 			   I915_READ(VLV_MASTER_IER));
    575  1.1  riastrad 
    576  1.1  riastrad 		seq_printf(m, "Render IER:\t%08x\n",
    577  1.1  riastrad 			   I915_READ(GTIER));
    578  1.1  riastrad 		seq_printf(m, "Render IIR:\t%08x\n",
    579  1.1  riastrad 			   I915_READ(GTIIR));
    580  1.1  riastrad 		seq_printf(m, "Render IMR:\t%08x\n",
    581  1.1  riastrad 			   I915_READ(GTIMR));
    582  1.1  riastrad 
    583  1.1  riastrad 		seq_printf(m, "PM IER:\t\t%08x\n",
    584  1.1  riastrad 			   I915_READ(GEN6_PMIER));
    585  1.1  riastrad 		seq_printf(m, "PM IIR:\t\t%08x\n",
    586  1.1  riastrad 			   I915_READ(GEN6_PMIIR));
    587  1.1  riastrad 		seq_printf(m, "PM IMR:\t\t%08x\n",
    588  1.1  riastrad 			   I915_READ(GEN6_PMIMR));
    589  1.1  riastrad 
    590  1.5  riastrad 		pref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
    591  1.1  riastrad 		seq_printf(m, "Port hotplug:\t%08x\n",
    592  1.1  riastrad 			   I915_READ(PORT_HOTPLUG_EN));
    593  1.1  riastrad 		seq_printf(m, "DPFLIPSTAT:\t%08x\n",
    594  1.1  riastrad 			   I915_READ(VLV_DPFLIPSTAT));
    595  1.1  riastrad 		seq_printf(m, "DPINVGTT:\t%08x\n",
    596  1.1  riastrad 			   I915_READ(DPINVGTT));
    597  1.5  riastrad 		intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, pref);
    598  1.1  riastrad 
    599  1.5  riastrad 	} else if (!HAS_PCH_SPLIT(dev_priv)) {
    600  1.1  riastrad 		seq_printf(m, "Interrupt enable:    %08x\n",
    601  1.5  riastrad 			   I915_READ(GEN2_IER));
    602  1.1  riastrad 		seq_printf(m, "Interrupt identity:  %08x\n",
    603  1.5  riastrad 			   I915_READ(GEN2_IIR));
    604  1.1  riastrad 		seq_printf(m, "Interrupt mask:      %08x\n",
    605  1.5  riastrad 			   I915_READ(GEN2_IMR));
    606  1.3  riastrad 		for_each_pipe(dev_priv, pipe)
    607  1.1  riastrad 			seq_printf(m, "Pipe %c stat:         %08x\n",
    608  1.1  riastrad 				   pipe_name(pipe),
    609  1.1  riastrad 				   I915_READ(PIPESTAT(pipe)));
    610  1.1  riastrad 	} else {
    611  1.1  riastrad 		seq_printf(m, "North Display Interrupt enable:		%08x\n",
    612  1.1  riastrad 			   I915_READ(DEIER));
    613  1.1  riastrad 		seq_printf(m, "North Display Interrupt identity:	%08x\n",
    614  1.1  riastrad 			   I915_READ(DEIIR));
    615  1.1  riastrad 		seq_printf(m, "North Display Interrupt mask:		%08x\n",
    616  1.1  riastrad 			   I915_READ(DEIMR));
    617  1.1  riastrad 		seq_printf(m, "South Display Interrupt enable:		%08x\n",
    618  1.1  riastrad 			   I915_READ(SDEIER));
    619  1.1  riastrad 		seq_printf(m, "South Display Interrupt identity:	%08x\n",
    620  1.1  riastrad 			   I915_READ(SDEIIR));
    621  1.1  riastrad 		seq_printf(m, "South Display Interrupt mask:		%08x\n",
    622  1.1  riastrad 			   I915_READ(SDEIMR));
    623  1.1  riastrad 		seq_printf(m, "Graphics Interrupt enable:		%08x\n",
    624  1.1  riastrad 			   I915_READ(GTIER));
    625  1.1  riastrad 		seq_printf(m, "Graphics Interrupt identity:		%08x\n",
    626  1.1  riastrad 			   I915_READ(GTIIR));
    627  1.1  riastrad 		seq_printf(m, "Graphics Interrupt mask:		%08x\n",
    628  1.1  riastrad 			   I915_READ(GTIMR));
    629  1.1  riastrad 	}
    630  1.5  riastrad 
    631  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 11) {
    632  1.5  riastrad 		seq_printf(m, "RCS Intr Mask:\t %08x\n",
    633  1.5  riastrad 			   I915_READ(GEN11_RCS0_RSVD_INTR_MASK));
    634  1.5  riastrad 		seq_printf(m, "BCS Intr Mask:\t %08x\n",
    635  1.5  riastrad 			   I915_READ(GEN11_BCS_RSVD_INTR_MASK));
    636  1.5  riastrad 		seq_printf(m, "VCS0/VCS1 Intr Mask:\t %08x\n",
    637  1.5  riastrad 			   I915_READ(GEN11_VCS0_VCS1_INTR_MASK));
    638  1.5  riastrad 		seq_printf(m, "VCS2/VCS3 Intr Mask:\t %08x\n",
    639  1.5  riastrad 			   I915_READ(GEN11_VCS2_VCS3_INTR_MASK));
    640  1.5  riastrad 		seq_printf(m, "VECS0/VECS1 Intr Mask:\t %08x\n",
    641  1.5  riastrad 			   I915_READ(GEN11_VECS0_VECS1_INTR_MASK));
    642  1.5  riastrad 		seq_printf(m, "GUC/SG Intr Mask:\t %08x\n",
    643  1.5  riastrad 			   I915_READ(GEN11_GUC_SG_INTR_MASK));
    644  1.5  riastrad 		seq_printf(m, "GPM/WGBOXPERF Intr Mask: %08x\n",
    645  1.5  riastrad 			   I915_READ(GEN11_GPM_WGBOXPERF_INTR_MASK));
    646  1.5  riastrad 		seq_printf(m, "Crypto Intr Mask:\t %08x\n",
    647  1.5  riastrad 			   I915_READ(GEN11_CRYPTO_RSVD_INTR_MASK));
    648  1.5  riastrad 		seq_printf(m, "Gunit/CSME Intr Mask:\t %08x\n",
    649  1.5  riastrad 			   I915_READ(GEN11_GUNIT_CSME_INTR_MASK));
    650  1.5  riastrad 
    651  1.5  riastrad 	} else if (INTEL_GEN(dev_priv) >= 6) {
    652  1.5  riastrad 		for_each_uabi_engine(engine, dev_priv) {
    653  1.1  riastrad 			seq_printf(m,
    654  1.1  riastrad 				   "Graphics Interrupt mask (%s):	%08x\n",
    655  1.5  riastrad 				   engine->name, ENGINE_READ(engine, RING_IMR));
    656  1.1  riastrad 		}
    657  1.1  riastrad 	}
    658  1.5  riastrad 
    659  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
    660  1.1  riastrad 
    661  1.1  riastrad 	return 0;
    662  1.1  riastrad }
    663  1.1  riastrad 
    664  1.1  riastrad static int i915_gem_fence_regs_info(struct seq_file *m, void *data)
    665  1.1  riastrad {
    666  1.5  riastrad 	struct drm_i915_private *i915 = node_to_i915(m->private);
    667  1.5  riastrad 	unsigned int i;
    668  1.1  riastrad 
    669  1.5  riastrad 	seq_printf(m, "Total fences = %d\n", i915->ggtt.num_fences);
    670  1.1  riastrad 
    671  1.5  riastrad 	rcu_read_lock();
    672  1.5  riastrad 	for (i = 0; i < i915->ggtt.num_fences; i++) {
    673  1.5  riastrad 		struct i915_fence_reg *reg = &i915->ggtt.fence_regs[i];
    674  1.5  riastrad 		struct i915_vma *vma = reg->vma;
    675  1.1  riastrad 
    676  1.1  riastrad 		seq_printf(m, "Fence %d, pin count = %d, object = ",
    677  1.5  riastrad 			   i, atomic_read(&reg->pin_count));
    678  1.5  riastrad 		if (!vma)
    679  1.2      matt 			seq_puts(m, "unused");
    680  1.1  riastrad 		else
    681  1.5  riastrad 			describe_obj(m, vma->obj);
    682  1.2      matt 		seq_putc(m, '\n');
    683  1.1  riastrad 	}
    684  1.5  riastrad 	rcu_read_unlock();
    685  1.1  riastrad 
    686  1.1  riastrad 	return 0;
    687  1.1  riastrad }
    688  1.1  riastrad 
    689  1.5  riastrad #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
    690  1.5  riastrad static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
    691  1.5  riastrad 			      size_t count, loff_t *pos)
    692  1.1  riastrad {
    693  1.5  riastrad 	struct i915_gpu_coredump *error;
    694  1.5  riastrad 	ssize_t ret;
    695  1.5  riastrad 	void *buf;
    696  1.1  riastrad 
    697  1.5  riastrad 	error = file->private_data;
    698  1.5  riastrad 	if (!error)
    699  1.1  riastrad 		return 0;
    700  1.1  riastrad 
    701  1.5  riastrad 	/* Bounce buffer required because of kernfs __user API convenience. */
    702  1.5  riastrad 	buf = kmalloc(count, GFP_KERNEL);
    703  1.5  riastrad 	if (!buf)
    704  1.5  riastrad 		return -ENOMEM;
    705  1.5  riastrad 
    706  1.5  riastrad 	ret = i915_gpu_coredump_copy_to_buffer(error, buf, *pos, count);
    707  1.5  riastrad 	if (ret <= 0)
    708  1.5  riastrad 		goto out;
    709  1.5  riastrad 
    710  1.5  riastrad 	if (!copy_to_user(ubuf, buf, ret))
    711  1.5  riastrad 		*pos += ret;
    712  1.5  riastrad 	else
    713  1.5  riastrad 		ret = -EFAULT;
    714  1.5  riastrad 
    715  1.5  riastrad out:
    716  1.5  riastrad 	kfree(buf);
    717  1.5  riastrad 	return ret;
    718  1.1  riastrad }
    719  1.1  riastrad 
    720  1.5  riastrad static int gpu_state_release(struct inode *inode, struct file *file)
    721  1.5  riastrad {
    722  1.5  riastrad 	i915_gpu_coredump_put(file->private_data);
    723  1.5  riastrad 	return 0;
    724  1.5  riastrad }
    725  1.5  riastrad 
    726  1.5  riastrad static int i915_gpu_info_open(struct inode *inode, struct file *file)
    727  1.5  riastrad {
    728  1.5  riastrad 	struct drm_i915_private *i915 = inode->i_private;
    729  1.5  riastrad 	struct i915_gpu_coredump *gpu;
    730  1.5  riastrad 	intel_wakeref_t wakeref;
    731  1.5  riastrad 
    732  1.5  riastrad 	gpu = NULL;
    733  1.5  riastrad 	with_intel_runtime_pm(&i915->runtime_pm, wakeref)
    734  1.5  riastrad 		gpu = i915_gpu_coredump(i915);
    735  1.5  riastrad 	if (IS_ERR(gpu))
    736  1.5  riastrad 		return PTR_ERR(gpu);
    737  1.5  riastrad 
    738  1.5  riastrad 	file->private_data = gpu;
    739  1.5  riastrad 	return 0;
    740  1.5  riastrad }
    741  1.5  riastrad 
    742  1.5  riastrad static const struct file_operations i915_gpu_info_fops = {
    743  1.5  riastrad 	.owner = THIS_MODULE,
    744  1.5  riastrad 	.open = i915_gpu_info_open,
    745  1.5  riastrad 	.read = gpu_state_read,
    746  1.5  riastrad 	.llseek = default_llseek,
    747  1.5  riastrad 	.release = gpu_state_release,
    748  1.5  riastrad };
    749  1.5  riastrad 
    750  1.1  riastrad static ssize_t
    751  1.1  riastrad i915_error_state_write(struct file *filp,
    752  1.1  riastrad 		       const char __user *ubuf,
    753  1.1  riastrad 		       size_t cnt,
    754  1.1  riastrad 		       loff_t *ppos)
    755  1.1  riastrad {
    756  1.5  riastrad 	struct i915_gpu_coredump *error = filp->private_data;
    757  1.5  riastrad 
    758  1.5  riastrad 	if (!error)
    759  1.5  riastrad 		return 0;
    760  1.1  riastrad 
    761  1.1  riastrad 	DRM_DEBUG_DRIVER("Resetting error state\n");
    762  1.5  riastrad 	i915_reset_error_state(error->i915);
    763  1.1  riastrad 
    764  1.1  riastrad 	return cnt;
    765  1.1  riastrad }
    766  1.1  riastrad 
    767  1.1  riastrad static int i915_error_state_open(struct inode *inode, struct file *file)
    768  1.1  riastrad {
    769  1.5  riastrad 	struct i915_gpu_coredump *error;
    770  1.1  riastrad 
    771  1.5  riastrad 	error = i915_first_error_state(inode->i_private);
    772  1.5  riastrad 	if (IS_ERR(error))
    773  1.5  riastrad 		return PTR_ERR(error);
    774  1.1  riastrad 
    775  1.5  riastrad 	file->private_data  = error;
    776  1.2      matt 	return 0;
    777  1.2      matt }
    778  1.2      matt 
    779  1.1  riastrad static const struct file_operations i915_error_state_fops = {
    780  1.1  riastrad 	.owner = THIS_MODULE,
    781  1.1  riastrad 	.open = i915_error_state_open,
    782  1.5  riastrad 	.read = gpu_state_read,
    783  1.1  riastrad 	.write = i915_error_state_write,
    784  1.1  riastrad 	.llseek = default_llseek,
    785  1.5  riastrad 	.release = gpu_state_release,
    786  1.1  riastrad };
    787  1.5  riastrad #endif
    788  1.1  riastrad 
    789  1.5  riastrad static int i915_frequency_info(struct seq_file *m, void *unused)
    790  1.2      matt {
    791  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
    792  1.5  riastrad 	struct intel_uncore *uncore = &dev_priv->uncore;
    793  1.5  riastrad 	struct intel_rps *rps = &dev_priv->gt.rps;
    794  1.5  riastrad 	intel_wakeref_t wakeref;
    795  1.5  riastrad 	int ret = 0;
    796  1.2      matt 
    797  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
    798  1.2      matt 
    799  1.5  riastrad 	if (IS_GEN(dev_priv, 5)) {
    800  1.5  riastrad 		u16 rgvswctl = intel_uncore_read16(uncore, MEMSWCTL);
    801  1.5  riastrad 		u16 rgvstat = intel_uncore_read16(uncore, MEMSTAT_ILK);
    802  1.2      matt 
    803  1.5  riastrad 		seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
    804  1.5  riastrad 		seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
    805  1.5  riastrad 		seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
    806  1.5  riastrad 			   MEMSTAT_VID_SHIFT);
    807  1.5  riastrad 		seq_printf(m, "Current P-state: %d\n",
    808  1.5  riastrad 			   (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
    809  1.5  riastrad 	} else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
    810  1.5  riastrad 		u32 rpmodectl, freq_sts;
    811  1.2      matt 
    812  1.5  riastrad 		rpmodectl = I915_READ(GEN6_RP_CONTROL);
    813  1.5  riastrad 		seq_printf(m, "Video Turbo Mode: %s\n",
    814  1.5  riastrad 			   yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
    815  1.5  riastrad 		seq_printf(m, "HW control enabled: %s\n",
    816  1.5  riastrad 			   yesno(rpmodectl & GEN6_RP_ENABLE));
    817  1.5  riastrad 		seq_printf(m, "SW control enabled: %s\n",
    818  1.5  riastrad 			   yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
    819  1.5  riastrad 				  GEN6_RP_MEDIA_SW_MODE));
    820  1.2      matt 
    821  1.5  riastrad 		vlv_punit_get(dev_priv);
    822  1.5  riastrad 		freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
    823  1.5  riastrad 		vlv_punit_put(dev_priv);
    824  1.2      matt 
    825  1.5  riastrad 		seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
    826  1.5  riastrad 		seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);
    827  1.2      matt 
    828  1.5  riastrad 		seq_printf(m, "actual GPU freq: %d MHz\n",
    829  1.5  riastrad 			   intel_gpu_freq(rps, (freq_sts >> 8) & 0xff));
    830  1.2      matt 
    831  1.5  riastrad 		seq_printf(m, "current GPU freq: %d MHz\n",
    832  1.5  riastrad 			   intel_gpu_freq(rps, rps->cur_freq));
    833  1.2      matt 
    834  1.5  riastrad 		seq_printf(m, "max GPU freq: %d MHz\n",
    835  1.5  riastrad 			   intel_gpu_freq(rps, rps->max_freq));
    836  1.2      matt 
    837  1.5  riastrad 		seq_printf(m, "min GPU freq: %d MHz\n",
    838  1.5  riastrad 			   intel_gpu_freq(rps, rps->min_freq));
    839  1.2      matt 
    840  1.5  riastrad 		seq_printf(m, "idle GPU freq: %d MHz\n",
    841  1.5  riastrad 			   intel_gpu_freq(rps, rps->idle_freq));
    842  1.1  riastrad 
    843  1.5  riastrad 		seq_printf(m,
    844  1.5  riastrad 			   "efficient (RPe) frequency: %d MHz\n",
    845  1.5  riastrad 			   intel_gpu_freq(rps, rps->efficient_freq));
    846  1.5  riastrad 	} else if (INTEL_GEN(dev_priv) >= 6) {
    847  1.3  riastrad 		u32 rp_state_limits;
    848  1.3  riastrad 		u32 gt_perf_status;
    849  1.3  riastrad 		u32 rp_state_cap;
    850  1.3  riastrad 		u32 rpmodectl, rpinclimit, rpdeclimit;
    851  1.2      matt 		u32 rpstat, cagf, reqf;
    852  1.1  riastrad 		u32 rpupei, rpcurup, rpprevup;
    853  1.1  riastrad 		u32 rpdownei, rpcurdown, rpprevdown;
    854  1.3  riastrad 		u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
    855  1.1  riastrad 		int max_freq;
    856  1.1  riastrad 
    857  1.3  riastrad 		rp_state_limits = I915_READ(GEN6_RP_STATE_LIMITS);
    858  1.5  riastrad 		if (IS_GEN9_LP(dev_priv)) {
    859  1.3  riastrad 			rp_state_cap = I915_READ(BXT_RP_STATE_CAP);
    860  1.3  riastrad 			gt_perf_status = I915_READ(BXT_GT_PERF_STATUS);
    861  1.3  riastrad 		} else {
    862  1.3  riastrad 			rp_state_cap = I915_READ(GEN6_RP_STATE_CAP);
    863  1.3  riastrad 			gt_perf_status = I915_READ(GEN6_GT_PERF_STATUS);
    864  1.3  riastrad 		}
    865  1.3  riastrad 
    866  1.1  riastrad 		/* RPSTAT1 is in the GT power well */
    867  1.5  riastrad 		intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL);
    868  1.1  riastrad 
    869  1.2      matt 		reqf = I915_READ(GEN6_RPNSWREQ);
    870  1.5  riastrad 		if (INTEL_GEN(dev_priv) >= 9)
    871  1.3  riastrad 			reqf >>= 23;
    872  1.3  riastrad 		else {
    873  1.3  riastrad 			reqf &= ~GEN6_TURBO_DISABLE;
    874  1.5  riastrad 			if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
    875  1.3  riastrad 				reqf >>= 24;
    876  1.3  riastrad 			else
    877  1.3  riastrad 				reqf >>= 25;
    878  1.3  riastrad 		}
    879  1.5  riastrad 		reqf = intel_gpu_freq(rps, reqf);
    880  1.3  riastrad 
    881  1.3  riastrad 		rpmodectl = I915_READ(GEN6_RP_CONTROL);
    882  1.3  riastrad 		rpinclimit = I915_READ(GEN6_RP_UP_THRESHOLD);
    883  1.3  riastrad 		rpdeclimit = I915_READ(GEN6_RP_DOWN_THRESHOLD);
    884  1.1  riastrad 
    885  1.1  riastrad 		rpstat = I915_READ(GEN6_RPSTAT1);
    886  1.5  riastrad 		rpupei = I915_READ(GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
    887  1.5  riastrad 		rpcurup = I915_READ(GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
    888  1.5  riastrad 		rpprevup = I915_READ(GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
    889  1.5  riastrad 		rpdownei = I915_READ(GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
    890  1.5  riastrad 		rpcurdown = I915_READ(GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
    891  1.5  riastrad 		rpprevdown = I915_READ(GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
    892  1.5  riastrad 		cagf = intel_rps_read_actual_frequency(rps);
    893  1.5  riastrad 
    894  1.5  riastrad 		intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL);
    895  1.5  riastrad 
    896  1.5  riastrad 		if (INTEL_GEN(dev_priv) >= 11) {
    897  1.5  riastrad 			pm_ier = I915_READ(GEN11_GPM_WGBOXPERF_INTR_ENABLE);
    898  1.5  riastrad 			pm_imr = I915_READ(GEN11_GPM_WGBOXPERF_INTR_MASK);
    899  1.5  riastrad 			/*
    900  1.5  riastrad 			 * The equivalent to the PM ISR & IIR cannot be read
    901  1.5  riastrad 			 * without affecting the current state of the system
    902  1.5  riastrad 			 */
    903  1.5  riastrad 			pm_isr = 0;
    904  1.5  riastrad 			pm_iir = 0;
    905  1.5  riastrad 		} else if (INTEL_GEN(dev_priv) >= 8) {
    906  1.5  riastrad 			pm_ier = I915_READ(GEN8_GT_IER(2));
    907  1.5  riastrad 			pm_imr = I915_READ(GEN8_GT_IMR(2));
    908  1.5  riastrad 			pm_isr = I915_READ(GEN8_GT_ISR(2));
    909  1.5  riastrad 			pm_iir = I915_READ(GEN8_GT_IIR(2));
    910  1.5  riastrad 		} else {
    911  1.3  riastrad 			pm_ier = I915_READ(GEN6_PMIER);
    912  1.3  riastrad 			pm_imr = I915_READ(GEN6_PMIMR);
    913  1.3  riastrad 			pm_isr = I915_READ(GEN6_PMISR);
    914  1.3  riastrad 			pm_iir = I915_READ(GEN6_PMIIR);
    915  1.3  riastrad 		}
    916  1.5  riastrad 		pm_mask = I915_READ(GEN6_PMINTRMSK);
    917  1.5  riastrad 
    918  1.5  riastrad 		seq_printf(m, "Video Turbo Mode: %s\n",
    919  1.5  riastrad 			   yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
    920  1.5  riastrad 		seq_printf(m, "HW control enabled: %s\n",
    921  1.5  riastrad 			   yesno(rpmodectl & GEN6_RP_ENABLE));
    922  1.5  riastrad 		seq_printf(m, "SW control enabled: %s\n",
    923  1.5  riastrad 			   yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
    924  1.5  riastrad 				  GEN6_RP_MEDIA_SW_MODE));
    925  1.5  riastrad 
    926  1.5  riastrad 		seq_printf(m, "PM IER=0x%08x IMR=0x%08x, MASK=0x%08x\n",
    927  1.5  riastrad 			   pm_ier, pm_imr, pm_mask);
    928  1.5  riastrad 		if (INTEL_GEN(dev_priv) <= 10)
    929  1.5  riastrad 			seq_printf(m, "PM ISR=0x%08x IIR=0x%08x\n",
    930  1.5  riastrad 				   pm_isr, pm_iir);
    931  1.5  riastrad 		seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n",
    932  1.5  riastrad 			   rps->pm_intrmsk_mbz);
    933  1.1  riastrad 		seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
    934  1.1  riastrad 		seq_printf(m, "Render p-state ratio: %d\n",
    935  1.5  riastrad 			   (gt_perf_status & (INTEL_GEN(dev_priv) >= 9 ? 0x1ff00 : 0xff00)) >> 8);
    936  1.1  riastrad 		seq_printf(m, "Render p-state VID: %d\n",
    937  1.1  riastrad 			   gt_perf_status & 0xff);
    938  1.1  riastrad 		seq_printf(m, "Render p-state limit: %d\n",
    939  1.1  riastrad 			   rp_state_limits & 0xff);
    940  1.3  riastrad 		seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
    941  1.3  riastrad 		seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
    942  1.3  riastrad 		seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
    943  1.3  riastrad 		seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
    944  1.2      matt 		seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
    945  1.2      matt 		seq_printf(m, "CAGF: %dMHz\n", cagf);
    946  1.5  riastrad 		seq_printf(m, "RP CUR UP EI: %d (%dus)\n",
    947  1.5  riastrad 			   rpupei, GT_PM_INTERVAL_TO_US(dev_priv, rpupei));
    948  1.5  riastrad 		seq_printf(m, "RP CUR UP: %d (%dus)\n",
    949  1.5  riastrad 			   rpcurup, GT_PM_INTERVAL_TO_US(dev_priv, rpcurup));
    950  1.5  riastrad 		seq_printf(m, "RP PREV UP: %d (%dus)\n",
    951  1.5  riastrad 			   rpprevup, GT_PM_INTERVAL_TO_US(dev_priv, rpprevup));
    952  1.3  riastrad 		seq_printf(m, "Up threshold: %d%%\n",
    953  1.5  riastrad 			   rps->power.up_threshold);
    954  1.3  riastrad 
    955  1.5  riastrad 		seq_printf(m, "RP CUR DOWN EI: %d (%dus)\n",
    956  1.5  riastrad 			   rpdownei, GT_PM_INTERVAL_TO_US(dev_priv, rpdownei));
    957  1.5  riastrad 		seq_printf(m, "RP CUR DOWN: %d (%dus)\n",
    958  1.5  riastrad 			   rpcurdown, GT_PM_INTERVAL_TO_US(dev_priv, rpcurdown));
    959  1.5  riastrad 		seq_printf(m, "RP PREV DOWN: %d (%dus)\n",
    960  1.5  riastrad 			   rpprevdown, GT_PM_INTERVAL_TO_US(dev_priv, rpprevdown));
    961  1.3  riastrad 		seq_printf(m, "Down threshold: %d%%\n",
    962  1.5  riastrad 			   rps->power.down_threshold);
    963  1.1  riastrad 
    964  1.5  riastrad 		max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
    965  1.3  riastrad 			    rp_state_cap >> 16) & 0xff;
    966  1.5  riastrad 		max_freq *= (IS_GEN9_BC(dev_priv) ||
    967  1.5  riastrad 			     INTEL_GEN(dev_priv) >= 10 ? GEN9_FREQ_SCALER : 1);
    968  1.1  riastrad 		seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
    969  1.5  riastrad 			   intel_gpu_freq(rps, max_freq));
    970  1.1  riastrad 
    971  1.1  riastrad 		max_freq = (rp_state_cap & 0xff00) >> 8;
    972  1.5  riastrad 		max_freq *= (IS_GEN9_BC(dev_priv) ||
    973  1.5  riastrad 			     INTEL_GEN(dev_priv) >= 10 ? GEN9_FREQ_SCALER : 1);
    974  1.1  riastrad 		seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
    975  1.5  riastrad 			   intel_gpu_freq(rps, max_freq));
    976  1.1  riastrad 
    977  1.5  riastrad 		max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
    978  1.3  riastrad 			    rp_state_cap >> 0) & 0xff;
    979  1.5  riastrad 		max_freq *= (IS_GEN9_BC(dev_priv) ||
    980  1.5  riastrad 			     INTEL_GEN(dev_priv) >= 10 ? GEN9_FREQ_SCALER : 1);
    981  1.1  riastrad 		seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
    982  1.5  riastrad 			   intel_gpu_freq(rps, max_freq));
    983  1.3  riastrad 		seq_printf(m, "Max overclocked frequency: %dMHz\n",
    984  1.5  riastrad 			   intel_gpu_freq(rps, rps->max_freq));
    985  1.2      matt 
    986  1.3  riastrad 		seq_printf(m, "Current freq: %d MHz\n",
    987  1.5  riastrad 			   intel_gpu_freq(rps, rps->cur_freq));
    988  1.3  riastrad 		seq_printf(m, "Actual freq: %d MHz\n", cagf);
    989  1.3  riastrad 		seq_printf(m, "Idle freq: %d MHz\n",
    990  1.5  riastrad 			   intel_gpu_freq(rps, rps->idle_freq));
    991  1.3  riastrad 		seq_printf(m, "Min freq: %d MHz\n",
    992  1.5  riastrad 			   intel_gpu_freq(rps, rps->min_freq));
    993  1.5  riastrad 		seq_printf(m, "Boost freq: %d MHz\n",
    994  1.5  riastrad 			   intel_gpu_freq(rps, rps->boost_freq));
    995  1.3  riastrad 		seq_printf(m, "Max freq: %d MHz\n",
    996  1.5  riastrad 			   intel_gpu_freq(rps, rps->max_freq));
    997  1.3  riastrad 		seq_printf(m,
    998  1.3  riastrad 			   "efficient (RPe) frequency: %d MHz\n",
    999  1.5  riastrad 			   intel_gpu_freq(rps, rps->efficient_freq));
   1000  1.1  riastrad 	} else {
   1001  1.2      matt 		seq_puts(m, "no P-state info available\n");
   1002  1.1  riastrad 	}
   1003  1.1  riastrad 
   1004  1.5  riastrad 	seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
   1005  1.3  riastrad 	seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
   1006  1.3  riastrad 	seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);
   1007  1.3  riastrad 
   1008  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
   1009  1.2      matt 	return ret;
   1010  1.1  riastrad }
   1011  1.1  riastrad 
   1012  1.5  riastrad static int ilk_drpc_info(struct seq_file *m)
   1013  1.1  riastrad {
   1014  1.5  riastrad 	struct drm_i915_private *i915 = node_to_i915(m->private);
   1015  1.5  riastrad 	struct intel_uncore *uncore = &i915->uncore;
   1016  1.1  riastrad 	u32 rgvmodectl, rstdbyctl;
   1017  1.1  riastrad 	u16 crstandvid;
   1018  1.1  riastrad 
   1019  1.5  riastrad 	rgvmodectl = intel_uncore_read(uncore, MEMMODECTL);
   1020  1.5  riastrad 	rstdbyctl = intel_uncore_read(uncore, RSTDBYCTL);
   1021  1.5  riastrad 	crstandvid = intel_uncore_read16(uncore, CRSTANDVID);
   1022  1.1  riastrad 
   1023  1.3  riastrad 	seq_printf(m, "HD boost: %s\n", yesno(rgvmodectl & MEMMODE_BOOST_EN));
   1024  1.1  riastrad 	seq_printf(m, "Boost freq: %d\n",
   1025  1.1  riastrad 		   (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >>
   1026  1.1  riastrad 		   MEMMODE_BOOST_FREQ_SHIFT);
   1027  1.1  riastrad 	seq_printf(m, "HW control enabled: %s\n",
   1028  1.3  riastrad 		   yesno(rgvmodectl & MEMMODE_HWIDLE_EN));
   1029  1.1  riastrad 	seq_printf(m, "SW control enabled: %s\n",
   1030  1.3  riastrad 		   yesno(rgvmodectl & MEMMODE_SWMODE_EN));
   1031  1.1  riastrad 	seq_printf(m, "Gated voltage change: %s\n",
   1032  1.3  riastrad 		   yesno(rgvmodectl & MEMMODE_RCLK_GATE));
   1033  1.1  riastrad 	seq_printf(m, "Starting frequency: P%d\n",
   1034  1.1  riastrad 		   (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT);
   1035  1.1  riastrad 	seq_printf(m, "Max P-state: P%d\n",
   1036  1.1  riastrad 		   (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT);
   1037  1.1  riastrad 	seq_printf(m, "Min P-state: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK));
   1038  1.1  riastrad 	seq_printf(m, "RS1 VID: %d\n", (crstandvid & 0x3f));
   1039  1.1  riastrad 	seq_printf(m, "RS2 VID: %d\n", ((crstandvid >> 8) & 0x3f));
   1040  1.1  riastrad 	seq_printf(m, "Render standby enabled: %s\n",
   1041  1.3  riastrad 		   yesno(!(rstdbyctl & RCX_SW_EXIT)));
   1042  1.2      matt 	seq_puts(m, "Current RS state: ");
   1043  1.1  riastrad 	switch (rstdbyctl & RSX_STATUS_MASK) {
   1044  1.1  riastrad 	case RSX_STATUS_ON:
   1045  1.2      matt 		seq_puts(m, "on\n");
   1046  1.1  riastrad 		break;
   1047  1.1  riastrad 	case RSX_STATUS_RC1:
   1048  1.2      matt 		seq_puts(m, "RC1\n");
   1049  1.1  riastrad 		break;
   1050  1.1  riastrad 	case RSX_STATUS_RC1E:
   1051  1.2      matt 		seq_puts(m, "RC1E\n");
   1052  1.1  riastrad 		break;
   1053  1.1  riastrad 	case RSX_STATUS_RS1:
   1054  1.2      matt 		seq_puts(m, "RS1\n");
   1055  1.1  riastrad 		break;
   1056  1.1  riastrad 	case RSX_STATUS_RS2:
   1057  1.2      matt 		seq_puts(m, "RS2 (RC6)\n");
   1058  1.1  riastrad 		break;
   1059  1.1  riastrad 	case RSX_STATUS_RS3:
   1060  1.2      matt 		seq_puts(m, "RC3 (RC6+)\n");
   1061  1.1  riastrad 		break;
   1062  1.1  riastrad 	default:
   1063  1.2      matt 		seq_puts(m, "unknown\n");
   1064  1.1  riastrad 		break;
   1065  1.1  riastrad 	}
   1066  1.1  riastrad 
   1067  1.1  riastrad 	return 0;
   1068  1.1  riastrad }
   1069  1.1  riastrad 
   1070  1.3  riastrad static int i915_forcewake_domains(struct seq_file *m, void *data)
   1071  1.3  riastrad {
   1072  1.5  riastrad 	struct drm_i915_private *i915 = node_to_i915(m->private);
   1073  1.5  riastrad 	struct intel_uncore *uncore = &i915->uncore;
   1074  1.3  riastrad 	struct intel_uncore_forcewake_domain *fw_domain;
   1075  1.5  riastrad 	unsigned int tmp;
   1076  1.5  riastrad 
   1077  1.5  riastrad 	seq_printf(m, "user.bypass_count = %u\n",
   1078  1.5  riastrad 		   uncore->user_forcewake_count);
   1079  1.3  riastrad 
   1080  1.5  riastrad 	for_each_fw_domain(fw_domain, uncore, tmp)
   1081  1.3  riastrad 		seq_printf(m, "%s.wake_count = %u\n",
   1082  1.5  riastrad 			   intel_uncore_forcewake_domain_to_str(fw_domain->id),
   1083  1.5  riastrad 			   READ_ONCE(fw_domain->wake_count));
   1084  1.3  riastrad 
   1085  1.3  riastrad 	return 0;
   1086  1.3  riastrad }
   1087  1.3  riastrad 
   1088  1.5  riastrad static void print_rc6_res(struct seq_file *m,
   1089  1.5  riastrad 			  const char *title,
   1090  1.5  riastrad 			  const i915_reg_t reg)
   1091  1.5  riastrad {
   1092  1.5  riastrad 	struct drm_i915_private *i915 = node_to_i915(m->private);
   1093  1.5  riastrad 	intel_wakeref_t wakeref;
   1094  1.5  riastrad 
   1095  1.5  riastrad 	with_intel_runtime_pm(&i915->runtime_pm, wakeref)
   1096  1.5  riastrad 		seq_printf(m, "%s %u (%llu us)\n", title,
   1097  1.5  riastrad 			   intel_uncore_read(&i915->uncore, reg),
   1098  1.5  riastrad 			   intel_rc6_residency_us(&i915->gt.rc6, reg));
   1099  1.5  riastrad }
   1100  1.5  riastrad 
   1101  1.2      matt static int vlv_drpc_info(struct seq_file *m)
   1102  1.1  riastrad {
   1103  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1104  1.5  riastrad 	u32 rcctl1, pw_status;
   1105  1.1  riastrad 
   1106  1.3  riastrad 	pw_status = I915_READ(VLV_GTLC_PW_STATUS);
   1107  1.2      matt 	rcctl1 = I915_READ(GEN6_RC_CONTROL);
   1108  1.2      matt 
   1109  1.2      matt 	seq_printf(m, "RC6 Enabled: %s\n",
   1110  1.2      matt 		   yesno(rcctl1 & (GEN7_RC_CTL_TO_MODE |
   1111  1.2      matt 					GEN6_RC_CTL_EI_MODE(1))));
   1112  1.2      matt 	seq_printf(m, "Render Power Well: %s\n",
   1113  1.3  riastrad 		   (pw_status & VLV_GTLC_PW_RENDER_STATUS_MASK) ? "Up" : "Down");
   1114  1.2      matt 	seq_printf(m, "Media Power Well: %s\n",
   1115  1.3  riastrad 		   (pw_status & VLV_GTLC_PW_MEDIA_STATUS_MASK) ? "Up" : "Down");
   1116  1.2      matt 
   1117  1.5  riastrad 	print_rc6_res(m, "Render RC6 residency since boot:", VLV_GT_RENDER_RC6);
   1118  1.5  riastrad 	print_rc6_res(m, "Media RC6 residency since boot:", VLV_GT_MEDIA_RC6);
   1119  1.2      matt 
   1120  1.3  riastrad 	return i915_forcewake_domains(m, NULL);
   1121  1.2      matt }
   1122  1.2      matt 
   1123  1.2      matt static int gen6_drpc_info(struct seq_file *m)
   1124  1.2      matt {
   1125  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1126  1.5  riastrad 	u32 gt_core_status, rcctl1, rc6vids = 0;
   1127  1.5  riastrad 	u32 gen9_powergate_enable = 0, gen9_powergate_status = 0;
   1128  1.1  riastrad 
   1129  1.5  riastrad 	gt_core_status = I915_READ_FW(GEN6_GT_CORE_STATUS);
   1130  1.2      matt 	trace_i915_reg_rw(false, GEN6_GT_CORE_STATUS, gt_core_status, 4, true);
   1131  1.1  riastrad 
   1132  1.1  riastrad 	rcctl1 = I915_READ(GEN6_RC_CONTROL);
   1133  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 9) {
   1134  1.5  riastrad 		gen9_powergate_enable = I915_READ(GEN9_PG_ENABLE);
   1135  1.5  riastrad 		gen9_powergate_status = I915_READ(GEN9_PWRGT_DOMAIN_STATUS);
   1136  1.5  riastrad 	}
   1137  1.1  riastrad 
   1138  1.5  riastrad 	if (INTEL_GEN(dev_priv) <= 7)
   1139  1.5  riastrad 		sandybridge_pcode_read(dev_priv, GEN6_PCODE_READ_RC6VIDS,
   1140  1.5  riastrad 				       &rc6vids, NULL);
   1141  1.2      matt 
   1142  1.1  riastrad 	seq_printf(m, "RC1e Enabled: %s\n",
   1143  1.1  riastrad 		   yesno(rcctl1 & GEN6_RC_CTL_RC1e_ENABLE));
   1144  1.1  riastrad 	seq_printf(m, "RC6 Enabled: %s\n",
   1145  1.1  riastrad 		   yesno(rcctl1 & GEN6_RC_CTL_RC6_ENABLE));
   1146  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 9) {
   1147  1.5  riastrad 		seq_printf(m, "Render Well Gating Enabled: %s\n",
   1148  1.5  riastrad 			yesno(gen9_powergate_enable & GEN9_RENDER_PG_ENABLE));
   1149  1.5  riastrad 		seq_printf(m, "Media Well Gating Enabled: %s\n",
   1150  1.5  riastrad 			yesno(gen9_powergate_enable & GEN9_MEDIA_PG_ENABLE));
   1151  1.5  riastrad 	}
   1152  1.1  riastrad 	seq_printf(m, "Deep RC6 Enabled: %s\n",
   1153  1.1  riastrad 		   yesno(rcctl1 & GEN6_RC_CTL_RC6p_ENABLE));
   1154  1.1  riastrad 	seq_printf(m, "Deepest RC6 Enabled: %s\n",
   1155  1.1  riastrad 		   yesno(rcctl1 & GEN6_RC_CTL_RC6pp_ENABLE));
   1156  1.2      matt 	seq_puts(m, "Current RC state: ");
   1157  1.1  riastrad 	switch (gt_core_status & GEN6_RCn_MASK) {
   1158  1.1  riastrad 	case GEN6_RC0:
   1159  1.1  riastrad 		if (gt_core_status & GEN6_CORE_CPD_STATE_MASK)
   1160  1.2      matt 			seq_puts(m, "Core Power Down\n");
   1161  1.1  riastrad 		else
   1162  1.2      matt 			seq_puts(m, "on\n");
   1163  1.1  riastrad 		break;
   1164  1.1  riastrad 	case GEN6_RC3:
   1165  1.2      matt 		seq_puts(m, "RC3\n");
   1166  1.1  riastrad 		break;
   1167  1.1  riastrad 	case GEN6_RC6:
   1168  1.2      matt 		seq_puts(m, "RC6\n");
   1169  1.1  riastrad 		break;
   1170  1.1  riastrad 	case GEN6_RC7:
   1171  1.2      matt 		seq_puts(m, "RC7\n");
   1172  1.1  riastrad 		break;
   1173  1.1  riastrad 	default:
   1174  1.2      matt 		seq_puts(m, "Unknown\n");
   1175  1.1  riastrad 		break;
   1176  1.1  riastrad 	}
   1177  1.1  riastrad 
   1178  1.1  riastrad 	seq_printf(m, "Core Power Down: %s\n",
   1179  1.1  riastrad 		   yesno(gt_core_status & GEN6_CORE_CPD_STATE_MASK));
   1180  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 9) {
   1181  1.5  riastrad 		seq_printf(m, "Render Power Well: %s\n",
   1182  1.5  riastrad 			(gen9_powergate_status &
   1183  1.5  riastrad 			 GEN9_PWRGT_RENDER_STATUS_MASK) ? "Up" : "Down");
   1184  1.5  riastrad 		seq_printf(m, "Media Power Well: %s\n",
   1185  1.5  riastrad 			(gen9_powergate_status &
   1186  1.5  riastrad 			 GEN9_PWRGT_MEDIA_STATUS_MASK) ? "Up" : "Down");
   1187  1.5  riastrad 	}
   1188  1.1  riastrad 
   1189  1.1  riastrad 	/* Not exactly sure what this is */
   1190  1.5  riastrad 	print_rc6_res(m, "RC6 \"Locked to RPn\" residency since boot:",
   1191  1.5  riastrad 		      GEN6_GT_GFX_RC6_LOCKED);
   1192  1.5  riastrad 	print_rc6_res(m, "RC6 residency since boot:", GEN6_GT_GFX_RC6);
   1193  1.5  riastrad 	print_rc6_res(m, "RC6+ residency since boot:", GEN6_GT_GFX_RC6p);
   1194  1.5  riastrad 	print_rc6_res(m, "RC6++ residency since boot:", GEN6_GT_GFX_RC6pp);
   1195  1.5  riastrad 
   1196  1.5  riastrad 	if (INTEL_GEN(dev_priv) <= 7) {
   1197  1.5  riastrad 		seq_printf(m, "RC6   voltage: %dmV\n",
   1198  1.5  riastrad 			   GEN6_DECODE_RC6_VID(((rc6vids >> 0) & 0xff)));
   1199  1.5  riastrad 		seq_printf(m, "RC6+  voltage: %dmV\n",
   1200  1.5  riastrad 			   GEN6_DECODE_RC6_VID(((rc6vids >> 8) & 0xff)));
   1201  1.5  riastrad 		seq_printf(m, "RC6++ voltage: %dmV\n",
   1202  1.5  riastrad 			   GEN6_DECODE_RC6_VID(((rc6vids >> 16) & 0xff)));
   1203  1.5  riastrad 	}
   1204  1.5  riastrad 
   1205  1.5  riastrad 	return i915_forcewake_domains(m, NULL);
   1206  1.1  riastrad }
   1207  1.1  riastrad 
   1208  1.1  riastrad static int i915_drpc_info(struct seq_file *m, void *unused)
   1209  1.1  riastrad {
   1210  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1211  1.5  riastrad 	intel_wakeref_t wakeref;
   1212  1.5  riastrad 	int err = -ENODEV;
   1213  1.5  riastrad 
   1214  1.5  riastrad 	with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) {
   1215  1.5  riastrad 		if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
   1216  1.5  riastrad 			err = vlv_drpc_info(m);
   1217  1.5  riastrad 		else if (INTEL_GEN(dev_priv) >= 6)
   1218  1.5  riastrad 			err = gen6_drpc_info(m);
   1219  1.5  riastrad 		else
   1220  1.5  riastrad 			err = ilk_drpc_info(m);
   1221  1.5  riastrad 	}
   1222  1.1  riastrad 
   1223  1.5  riastrad 	return err;
   1224  1.1  riastrad }
   1225  1.1  riastrad 
   1226  1.3  riastrad static int i915_frontbuffer_tracking(struct seq_file *m, void *unused)
   1227  1.3  riastrad {
   1228  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1229  1.3  riastrad 
   1230  1.3  riastrad 	seq_printf(m, "FB tracking busy bits: 0x%08x\n",
   1231  1.3  riastrad 		   dev_priv->fb_tracking.busy_bits);
   1232  1.3  riastrad 
   1233  1.3  riastrad 	seq_printf(m, "FB tracking flip bits: 0x%08x\n",
   1234  1.3  riastrad 		   dev_priv->fb_tracking.flip_bits);
   1235  1.3  riastrad 
   1236  1.3  riastrad 	return 0;
   1237  1.3  riastrad }
   1238  1.3  riastrad 
   1239  1.1  riastrad static int i915_fbc_status(struct seq_file *m, void *unused)
   1240  1.1  riastrad {
   1241  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1242  1.5  riastrad 	struct intel_fbc *fbc = &dev_priv->fbc;
   1243  1.5  riastrad 	intel_wakeref_t wakeref;
   1244  1.1  riastrad 
   1245  1.5  riastrad 	if (!HAS_FBC(dev_priv))
   1246  1.5  riastrad 		return -ENODEV;
   1247  1.1  riastrad 
   1248  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
   1249  1.5  riastrad 	mutex_lock(&fbc->lock);
   1250  1.2      matt 
   1251  1.5  riastrad 	if (intel_fbc_is_active(dev_priv))
   1252  1.2      matt 		seq_puts(m, "FBC enabled\n");
   1253  1.3  riastrad 	else
   1254  1.5  riastrad 		seq_printf(m, "FBC disabled: %s\n", fbc->no_fbc_reason);
   1255  1.5  riastrad 
   1256  1.5  riastrad 	if (intel_fbc_is_active(dev_priv)) {
   1257  1.5  riastrad 		u32 mask;
   1258  1.3  riastrad 
   1259  1.5  riastrad 		if (INTEL_GEN(dev_priv) >= 8)
   1260  1.5  riastrad 			mask = I915_READ(IVB_FBC_STATUS2) & BDW_FBC_COMP_SEG_MASK;
   1261  1.5  riastrad 		else if (INTEL_GEN(dev_priv) >= 7)
   1262  1.5  riastrad 			mask = I915_READ(IVB_FBC_STATUS2) & IVB_FBC_COMP_SEG_MASK;
   1263  1.5  riastrad 		else if (INTEL_GEN(dev_priv) >= 5)
   1264  1.5  riastrad 			mask = I915_READ(ILK_DPFC_STATUS) & ILK_DPFC_COMP_SEG_MASK;
   1265  1.5  riastrad 		else if (IS_G4X(dev_priv))
   1266  1.5  riastrad 			mask = I915_READ(DPFC_STATUS) & DPFC_COMP_SEG_MASK;
   1267  1.5  riastrad 		else
   1268  1.5  riastrad 			mask = I915_READ(FBC_STATUS) & (FBC_STAT_COMPRESSING |
   1269  1.5  riastrad 							FBC_STAT_COMPRESSED);
   1270  1.5  riastrad 
   1271  1.5  riastrad 		seq_printf(m, "Compressing: %s\n", yesno(mask));
   1272  1.5  riastrad 	}
   1273  1.2      matt 
   1274  1.5  riastrad 	mutex_unlock(&fbc->lock);
   1275  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
   1276  1.2      matt 
   1277  1.2      matt 	return 0;
   1278  1.2      matt }
   1279  1.2      matt 
   1280  1.5  riastrad static int i915_fbc_false_color_get(void *data, u64 *val)
   1281  1.3  riastrad {
   1282  1.5  riastrad 	struct drm_i915_private *dev_priv = data;
   1283  1.3  riastrad 
   1284  1.5  riastrad 	if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
   1285  1.3  riastrad 		return -ENODEV;
   1286  1.3  riastrad 
   1287  1.3  riastrad 	*val = dev_priv->fbc.false_color;
   1288  1.3  riastrad 
   1289  1.3  riastrad 	return 0;
   1290  1.3  riastrad }
   1291  1.3  riastrad 
   1292  1.5  riastrad static int i915_fbc_false_color_set(void *data, u64 val)
   1293  1.3  riastrad {
   1294  1.5  riastrad 	struct drm_i915_private *dev_priv = data;
   1295  1.3  riastrad 	u32 reg;
   1296  1.3  riastrad 
   1297  1.5  riastrad 	if (INTEL_GEN(dev_priv) < 7 || !HAS_FBC(dev_priv))
   1298  1.3  riastrad 		return -ENODEV;
   1299  1.3  riastrad 
   1300  1.3  riastrad 	mutex_lock(&dev_priv->fbc.lock);
   1301  1.3  riastrad 
   1302  1.3  riastrad 	reg = I915_READ(ILK_DPFC_CONTROL);
   1303  1.3  riastrad 	dev_priv->fbc.false_color = val;
   1304  1.3  riastrad 
   1305  1.3  riastrad 	I915_WRITE(ILK_DPFC_CONTROL, val ?
   1306  1.3  riastrad 		   (reg | FBC_CTL_FALSE_COLOR) :
   1307  1.3  riastrad 		   (reg & ~FBC_CTL_FALSE_COLOR));
   1308  1.3  riastrad 
   1309  1.3  riastrad 	mutex_unlock(&dev_priv->fbc.lock);
   1310  1.3  riastrad 	return 0;
   1311  1.3  riastrad }
   1312  1.3  riastrad 
   1313  1.5  riastrad DEFINE_SIMPLE_ATTRIBUTE(i915_fbc_false_color_fops,
   1314  1.5  riastrad 			i915_fbc_false_color_get, i915_fbc_false_color_set,
   1315  1.3  riastrad 			"%llu\n");
   1316  1.3  riastrad 
   1317  1.2      matt static int i915_ips_status(struct seq_file *m, void *unused)
   1318  1.2      matt {
   1319  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1320  1.5  riastrad 	intel_wakeref_t wakeref;
   1321  1.2      matt 
   1322  1.5  riastrad 	if (!HAS_IPS(dev_priv))
   1323  1.5  riastrad 		return -ENODEV;
   1324  1.2      matt 
   1325  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
   1326  1.2      matt 
   1327  1.3  riastrad 	seq_printf(m, "Enabled by kernel parameter: %s\n",
   1328  1.5  riastrad 		   yesno(i915_modparams.enable_ips));
   1329  1.3  riastrad 
   1330  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 8) {
   1331  1.3  riastrad 		seq_puts(m, "Currently: unknown\n");
   1332  1.3  riastrad 	} else {
   1333  1.3  riastrad 		if (I915_READ(IPS_CTL) & IPS_ENABLE)
   1334  1.3  riastrad 			seq_puts(m, "Currently: enabled\n");
   1335  1.3  riastrad 		else
   1336  1.3  riastrad 			seq_puts(m, "Currently: disabled\n");
   1337  1.3  riastrad 	}
   1338  1.2      matt 
   1339  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
   1340  1.2      matt 
   1341  1.1  riastrad 	return 0;
   1342  1.1  riastrad }
   1343  1.1  riastrad 
   1344  1.1  riastrad static int i915_sr_status(struct seq_file *m, void *unused)
   1345  1.1  riastrad {
   1346  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1347  1.5  riastrad 	intel_wakeref_t wakeref;
   1348  1.1  riastrad 	bool sr_enabled = false;
   1349  1.1  riastrad 
   1350  1.5  riastrad 	wakeref = intel_display_power_get(dev_priv, POWER_DOMAIN_INIT);
   1351  1.2      matt 
   1352  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 9)
   1353  1.5  riastrad 		/* no global SR status; inspect per-plane WM */;
   1354  1.5  riastrad 	else if (HAS_PCH_SPLIT(dev_priv))
   1355  1.1  riastrad 		sr_enabled = I915_READ(WM1_LP_ILK) & WM1_LP_SR_EN;
   1356  1.5  riastrad 	else if (IS_I965GM(dev_priv) || IS_G4X(dev_priv) ||
   1357  1.5  riastrad 		 IS_I945G(dev_priv) || IS_I945GM(dev_priv))
   1358  1.1  riastrad 		sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN;
   1359  1.5  riastrad 	else if (IS_I915GM(dev_priv))
   1360  1.1  riastrad 		sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN;
   1361  1.5  riastrad 	else if (IS_PINEVIEW(dev_priv))
   1362  1.1  riastrad 		sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN;
   1363  1.5  riastrad 	else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
   1364  1.3  riastrad 		sr_enabled = I915_READ(FW_BLC_SELF_VLV) & FW_CSPWRDWNEN;
   1365  1.1  riastrad 
   1366  1.5  riastrad 	intel_display_power_put(dev_priv, POWER_DOMAIN_INIT, wakeref);
   1367  1.1  riastrad 
   1368  1.5  riastrad 	seq_printf(m, "self-refresh: %s\n", enableddisabled(sr_enabled));
   1369  1.1  riastrad 
   1370  1.1  riastrad 	return 0;
   1371  1.1  riastrad }
   1372  1.1  riastrad 
   1373  1.1  riastrad static int i915_ring_freq_table(struct seq_file *m, void *unused)
   1374  1.1  riastrad {
   1375  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1376  1.5  riastrad 	struct intel_rps *rps = &dev_priv->gt.rps;
   1377  1.5  riastrad 	unsigned int max_gpu_freq, min_gpu_freq;
   1378  1.5  riastrad 	intel_wakeref_t wakeref;
   1379  1.1  riastrad 	int gpu_freq, ia_freq;
   1380  1.1  riastrad 
   1381  1.5  riastrad 	if (!HAS_LLC(dev_priv))
   1382  1.5  riastrad 		return -ENODEV;
   1383  1.1  riastrad 
   1384  1.5  riastrad 	min_gpu_freq = rps->min_freq;
   1385  1.5  riastrad 	max_gpu_freq = rps->max_freq;
   1386  1.5  riastrad 	if (IS_GEN9_BC(dev_priv) || INTEL_GEN(dev_priv) >= 10) {
   1387  1.3  riastrad 		/* Convert GT frequency to 50 HZ units */
   1388  1.5  riastrad 		min_gpu_freq /= GEN9_FREQ_SCALER;
   1389  1.5  riastrad 		max_gpu_freq /= GEN9_FREQ_SCALER;
   1390  1.3  riastrad 	}
   1391  1.3  riastrad 
   1392  1.2      matt 	seq_puts(m, "GPU freq (MHz)\tEffective CPU freq (MHz)\tEffective Ring freq (MHz)\n");
   1393  1.1  riastrad 
   1394  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
   1395  1.3  riastrad 	for (gpu_freq = min_gpu_freq; gpu_freq <= max_gpu_freq; gpu_freq++) {
   1396  1.1  riastrad 		ia_freq = gpu_freq;
   1397  1.1  riastrad 		sandybridge_pcode_read(dev_priv,
   1398  1.1  riastrad 				       GEN6_PCODE_READ_MIN_FREQ_TABLE,
   1399  1.5  riastrad 				       &ia_freq, NULL);
   1400  1.2      matt 		seq_printf(m, "%d\t\t%d\t\t\t\t%d\n",
   1401  1.5  riastrad 			   intel_gpu_freq(rps,
   1402  1.5  riastrad 					  (gpu_freq *
   1403  1.5  riastrad 					   (IS_GEN9_BC(dev_priv) ||
   1404  1.5  riastrad 					    INTEL_GEN(dev_priv) >= 10 ?
   1405  1.5  riastrad 					    GEN9_FREQ_SCALER : 1))),
   1406  1.2      matt 			   ((ia_freq >> 0) & 0xff) * 100,
   1407  1.2      matt 			   ((ia_freq >> 8) & 0xff) * 100);
   1408  1.1  riastrad 	}
   1409  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
   1410  1.1  riastrad 
   1411  1.5  riastrad 	return 0;
   1412  1.1  riastrad }
   1413  1.1  riastrad 
   1414  1.1  riastrad static int i915_opregion(struct seq_file *m, void *unused)
   1415  1.1  riastrad {
   1416  1.5  riastrad 	struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
   1417  1.1  riastrad 
   1418  1.5  riastrad 	if (opregion->header)
   1419  1.5  riastrad 		seq_write(m, opregion->header, OPREGION_SIZE);
   1420  1.1  riastrad 
   1421  1.5  riastrad 	return 0;
   1422  1.5  riastrad }
   1423  1.1  riastrad 
   1424  1.5  riastrad static int i915_vbt(struct seq_file *m, void *unused)
   1425  1.5  riastrad {
   1426  1.5  riastrad 	struct intel_opregion *opregion = &node_to_i915(m->private)->opregion;
   1427  1.1  riastrad 
   1428  1.5  riastrad 	if (opregion->vbt)
   1429  1.5  riastrad 		seq_write(m, opregion->vbt, opregion->vbt_size);
   1430  1.1  riastrad 
   1431  1.1  riastrad 	return 0;
   1432  1.1  riastrad }
   1433  1.1  riastrad 
   1434  1.1  riastrad static int i915_gem_framebuffer_info(struct seq_file *m, void *data)
   1435  1.1  riastrad {
   1436  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1437  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   1438  1.5  riastrad 	struct intel_framebuffer *fbdev_fb = NULL;
   1439  1.3  riastrad 	struct drm_framebuffer *drm_fb;
   1440  1.1  riastrad 
   1441  1.3  riastrad #ifdef CONFIG_DRM_FBDEV_EMULATION
   1442  1.5  riastrad 	if (dev_priv->fbdev && dev_priv->fbdev->helper.fb) {
   1443  1.5  riastrad 		fbdev_fb = to_intel_framebuffer(dev_priv->fbdev->helper.fb);
   1444  1.1  riastrad 
   1445  1.5  riastrad 		seq_printf(m, "fbcon size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
   1446  1.5  riastrad 			   fbdev_fb->base.width,
   1447  1.5  riastrad 			   fbdev_fb->base.height,
   1448  1.5  riastrad 			   fbdev_fb->base.format->depth,
   1449  1.5  riastrad 			   fbdev_fb->base.format->cpp[0] * 8,
   1450  1.5  riastrad 			   fbdev_fb->base.modifier,
   1451  1.5  riastrad 			   drm_framebuffer_read_refcount(&fbdev_fb->base));
   1452  1.5  riastrad 		describe_obj(m, intel_fb_obj(&fbdev_fb->base));
   1453  1.5  riastrad 		seq_putc(m, '\n');
   1454  1.5  riastrad 	}
   1455  1.2      matt #endif
   1456  1.1  riastrad 
   1457  1.2      matt 	mutex_lock(&dev->mode_config.fb_lock);
   1458  1.3  riastrad 	drm_for_each_fb(drm_fb, dev) {
   1459  1.5  riastrad 		struct intel_framebuffer *fb = to_intel_framebuffer(drm_fb);
   1460  1.5  riastrad 		if (fb == fbdev_fb)
   1461  1.1  riastrad 			continue;
   1462  1.1  riastrad 
   1463  1.3  riastrad 		seq_printf(m, "user size: %d x %d, depth %d, %d bpp, modifier 0x%llx, refcount %d, obj ",
   1464  1.1  riastrad 			   fb->base.width,
   1465  1.1  riastrad 			   fb->base.height,
   1466  1.5  riastrad 			   fb->base.format->depth,
   1467  1.5  riastrad 			   fb->base.format->cpp[0] * 8,
   1468  1.5  riastrad 			   fb->base.modifier,
   1469  1.5  riastrad 			   drm_framebuffer_read_refcount(&fb->base));
   1470  1.5  riastrad 		describe_obj(m, intel_fb_obj(&fb->base));
   1471  1.2      matt 		seq_putc(m, '\n');
   1472  1.1  riastrad 	}
   1473  1.2      matt 	mutex_unlock(&dev->mode_config.fb_lock);
   1474  1.1  riastrad 
   1475  1.1  riastrad 	return 0;
   1476  1.1  riastrad }
   1477  1.1  riastrad 
   1478  1.5  riastrad static void describe_ctx_ring(struct seq_file *m, struct intel_ring *ring)
   1479  1.3  riastrad {
   1480  1.5  riastrad 	seq_printf(m, " (ringbuffer, space: %d, head: %u, tail: %u, emit: %u)",
   1481  1.5  riastrad 		   ring->space, ring->head, ring->tail, ring->emit);
   1482  1.3  riastrad }
   1483  1.3  riastrad 
   1484  1.1  riastrad static int i915_context_status(struct seq_file *m, void *unused)
   1485  1.1  riastrad {
   1486  1.5  riastrad 	struct drm_i915_private *i915 = node_to_i915(m->private);
   1487  1.5  riastrad 	struct i915_gem_context *ctx, *cn;
   1488  1.1  riastrad 
   1489  1.5  riastrad 	spin_lock(&i915->gem.contexts.lock);
   1490  1.5  riastrad 	list_for_each_entry_safe(ctx, cn, &i915->gem.contexts.list, link) {
   1491  1.5  riastrad 		struct i915_gem_engines_iter it;
   1492  1.5  riastrad 		struct intel_context *ce;
   1493  1.1  riastrad 
   1494  1.5  riastrad 		if (!kref_get_unless_zero(&ctx->ref))
   1495  1.3  riastrad 			continue;
   1496  1.1  riastrad 
   1497  1.5  riastrad 		spin_unlock(&i915->gem.contexts.lock);
   1498  1.5  riastrad 
   1499  1.2      matt 		seq_puts(m, "HW context ");
   1500  1.5  riastrad 		if (ctx->pid) {
   1501  1.5  riastrad 			struct task_struct *task;
   1502  1.5  riastrad 
   1503  1.5  riastrad 			task = get_pid_task(ctx->pid, PIDTYPE_PID);
   1504  1.5  riastrad 			if (task) {
   1505  1.5  riastrad 				seq_printf(m, "(%s [%d]) ",
   1506  1.5  riastrad 					   task->comm, task->pid);
   1507  1.5  riastrad 				put_task_struct(task);
   1508  1.5  riastrad 			}
   1509  1.5  riastrad 		} else if (IS_ERR(ctx->file_priv)) {
   1510  1.5  riastrad 			seq_puts(m, "(deleted) ");
   1511  1.5  riastrad 		} else {
   1512  1.5  riastrad 			seq_puts(m, "(kernel) ");
   1513  1.3  riastrad 		}
   1514  1.3  riastrad 
   1515  1.5  riastrad 		seq_putc(m, ctx->remap_slice ? 'R' : 'r');
   1516  1.5  riastrad 		seq_putc(m, '\n');
   1517  1.5  riastrad 
   1518  1.5  riastrad 		for_each_gem_engine(ce,
   1519  1.5  riastrad 				    i915_gem_context_lock_engines(ctx), it) {
   1520  1.5  riastrad 			if (intel_context_pin_if_active(ce)) {
   1521  1.5  riastrad 				seq_printf(m, "%s: ", ce->engine->name);
   1522  1.5  riastrad 				if (ce->state)
   1523  1.5  riastrad 					describe_obj(m, ce->state->obj);
   1524  1.5  riastrad 				describe_ctx_ring(m, ce->ring);
   1525  1.3  riastrad 				seq_putc(m, '\n');
   1526  1.5  riastrad 				intel_context_unpin(ce);
   1527  1.3  riastrad 			}
   1528  1.3  riastrad 		}
   1529  1.5  riastrad 		i915_gem_context_unlock_engines(ctx);
   1530  1.2      matt 
   1531  1.2      matt 		seq_putc(m, '\n');
   1532  1.5  riastrad 
   1533  1.5  riastrad 		spin_lock(&i915->gem.contexts.lock);
   1534  1.5  riastrad 		list_safe_reset_next(ctx, cn, link);
   1535  1.5  riastrad 		i915_gem_context_put(ctx);
   1536  1.1  riastrad 	}
   1537  1.5  riastrad 	spin_unlock(&i915->gem.contexts.lock);
   1538  1.1  riastrad 
   1539  1.1  riastrad 	return 0;
   1540  1.1  riastrad }
   1541  1.1  riastrad 
   1542  1.1  riastrad static const char *swizzle_string(unsigned swizzle)
   1543  1.1  riastrad {
   1544  1.2      matt 	switch (swizzle) {
   1545  1.1  riastrad 	case I915_BIT_6_SWIZZLE_NONE:
   1546  1.1  riastrad 		return "none";
   1547  1.1  riastrad 	case I915_BIT_6_SWIZZLE_9:
   1548  1.1  riastrad 		return "bit9";
   1549  1.1  riastrad 	case I915_BIT_6_SWIZZLE_9_10:
   1550  1.1  riastrad 		return "bit9/bit10";
   1551  1.1  riastrad 	case I915_BIT_6_SWIZZLE_9_11:
   1552  1.1  riastrad 		return "bit9/bit11";
   1553  1.1  riastrad 	case I915_BIT_6_SWIZZLE_9_10_11:
   1554  1.1  riastrad 		return "bit9/bit10/bit11";
   1555  1.1  riastrad 	case I915_BIT_6_SWIZZLE_9_17:
   1556  1.1  riastrad 		return "bit9/bit17";
   1557  1.1  riastrad 	case I915_BIT_6_SWIZZLE_9_10_17:
   1558  1.1  riastrad 		return "bit9/bit10/bit17";
   1559  1.1  riastrad 	case I915_BIT_6_SWIZZLE_UNKNOWN:
   1560  1.2      matt 		return "unknown";
   1561  1.1  riastrad 	}
   1562  1.1  riastrad 
   1563  1.1  riastrad 	return "bug";
   1564  1.1  riastrad }
   1565  1.1  riastrad 
   1566  1.1  riastrad static int i915_swizzle_info(struct seq_file *m, void *data)
   1567  1.1  riastrad {
   1568  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1569  1.5  riastrad 	struct intel_uncore *uncore = &dev_priv->uncore;
   1570  1.5  riastrad 	intel_wakeref_t wakeref;
   1571  1.1  riastrad 
   1572  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
   1573  1.1  riastrad 
   1574  1.1  riastrad 	seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
   1575  1.5  riastrad 		   swizzle_string(dev_priv->ggtt.bit_6_swizzle_x));
   1576  1.1  riastrad 	seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
   1577  1.5  riastrad 		   swizzle_string(dev_priv->ggtt.bit_6_swizzle_y));
   1578  1.1  riastrad 
   1579  1.5  riastrad 	if (IS_GEN_RANGE(dev_priv, 3, 4)) {
   1580  1.1  riastrad 		seq_printf(m, "DDC = 0x%08x\n",
   1581  1.5  riastrad 			   intel_uncore_read(uncore, DCC));
   1582  1.3  riastrad 		seq_printf(m, "DDC2 = 0x%08x\n",
   1583  1.5  riastrad 			   intel_uncore_read(uncore, DCC2));
   1584  1.1  riastrad 		seq_printf(m, "C0DRB3 = 0x%04x\n",
   1585  1.5  riastrad 			   intel_uncore_read16(uncore, C0DRB3));
   1586  1.1  riastrad 		seq_printf(m, "C1DRB3 = 0x%04x\n",
   1587  1.5  riastrad 			   intel_uncore_read16(uncore, C1DRB3));
   1588  1.5  riastrad 	} else if (INTEL_GEN(dev_priv) >= 6) {
   1589  1.1  riastrad 		seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
   1590  1.5  riastrad 			   intel_uncore_read(uncore, MAD_DIMM_C0));
   1591  1.1  riastrad 		seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
   1592  1.5  riastrad 			   intel_uncore_read(uncore, MAD_DIMM_C1));
   1593  1.1  riastrad 		seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
   1594  1.5  riastrad 			   intel_uncore_read(uncore, MAD_DIMM_C2));
   1595  1.1  riastrad 		seq_printf(m, "TILECTL = 0x%08x\n",
   1596  1.5  riastrad 			   intel_uncore_read(uncore, TILECTL));
   1597  1.5  riastrad 		if (INTEL_GEN(dev_priv) >= 8)
   1598  1.2      matt 			seq_printf(m, "GAMTARBMODE = 0x%08x\n",
   1599  1.5  riastrad 				   intel_uncore_read(uncore, GAMTARBMODE));
   1600  1.2      matt 		else
   1601  1.2      matt 			seq_printf(m, "ARB_MODE = 0x%08x\n",
   1602  1.5  riastrad 				   intel_uncore_read(uncore, ARB_MODE));
   1603  1.1  riastrad 		seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
   1604  1.5  riastrad 			   intel_uncore_read(uncore, DISP_ARB_CTL));
   1605  1.1  riastrad 	}
   1606  1.3  riastrad 
   1607  1.3  riastrad 	if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
   1608  1.3  riastrad 		seq_puts(m, "L-shaped memory detected\n");
   1609  1.3  riastrad 
   1610  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
   1611  1.1  riastrad 
   1612  1.1  riastrad 	return 0;
   1613  1.1  riastrad }
   1614  1.1  riastrad 
   1615  1.5  riastrad static const char *rps_power_to_str(unsigned int power)
   1616  1.5  riastrad {
   1617  1.5  riastrad 	static const char * const strings[] = {
   1618  1.5  riastrad 		[LOW_POWER] = "low power",
   1619  1.5  riastrad 		[BETWEEN] = "mixed",
   1620  1.5  riastrad 		[HIGH_POWER] = "high power",
   1621  1.5  riastrad 	};
   1622  1.5  riastrad 
   1623  1.5  riastrad 	if (power >= ARRAY_SIZE(strings) || !strings[power])
   1624  1.5  riastrad 		return "unknown";
   1625  1.5  riastrad 
   1626  1.5  riastrad 	return strings[power];
   1627  1.5  riastrad }
   1628  1.5  riastrad 
   1629  1.5  riastrad static int i915_rps_boost_info(struct seq_file *m, void *data)
   1630  1.2      matt {
   1631  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1632  1.5  riastrad 	struct intel_rps *rps = &dev_priv->gt.rps;
   1633  1.3  riastrad 
   1634  1.5  riastrad 	seq_printf(m, "RPS enabled? %d\n", rps->enabled);
   1635  1.5  riastrad 	seq_printf(m, "GPU busy? %s\n", yesno(dev_priv->gt.awake));
   1636  1.5  riastrad 	seq_printf(m, "Boosts outstanding? %d\n",
   1637  1.5  riastrad 		   atomic_read(&rps->num_waiters));
   1638  1.5  riastrad 	seq_printf(m, "Interactive? %d\n", READ_ONCE(rps->power.interactive));
   1639  1.5  riastrad 	seq_printf(m, "Frequency requested %d, actual %d\n",
   1640  1.5  riastrad 		   intel_gpu_freq(rps, rps->cur_freq),
   1641  1.5  riastrad 		   intel_rps_read_actual_frequency(rps));
   1642  1.5  riastrad 	seq_printf(m, "  min hard:%d, soft:%d; max soft:%d, hard:%d\n",
   1643  1.5  riastrad 		   intel_gpu_freq(rps, rps->min_freq),
   1644  1.5  riastrad 		   intel_gpu_freq(rps, rps->min_freq_softlimit),
   1645  1.5  riastrad 		   intel_gpu_freq(rps, rps->max_freq_softlimit),
   1646  1.5  riastrad 		   intel_gpu_freq(rps, rps->max_freq));
   1647  1.5  riastrad 	seq_printf(m, "  idle:%d, efficient:%d, boost:%d\n",
   1648  1.5  riastrad 		   intel_gpu_freq(rps, rps->idle_freq),
   1649  1.5  riastrad 		   intel_gpu_freq(rps, rps->efficient_freq),
   1650  1.5  riastrad 		   intel_gpu_freq(rps, rps->boost_freq));
   1651  1.5  riastrad 
   1652  1.5  riastrad 	seq_printf(m, "Wait boosts: %d\n", atomic_read(&rps->boosts));
   1653  1.5  riastrad 
   1654  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 6 && rps->enabled && dev_priv->gt.awake) {
   1655  1.5  riastrad 		u32 rpup, rpupei;
   1656  1.5  riastrad 		u32 rpdown, rpdownei;
   1657  1.5  riastrad 
   1658  1.5  riastrad 		intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL);
   1659  1.5  riastrad 		rpup = I915_READ_FW(GEN6_RP_CUR_UP) & GEN6_RP_EI_MASK;
   1660  1.5  riastrad 		rpupei = I915_READ_FW(GEN6_RP_CUR_UP_EI) & GEN6_RP_EI_MASK;
   1661  1.5  riastrad 		rpdown = I915_READ_FW(GEN6_RP_CUR_DOWN) & GEN6_RP_EI_MASK;
   1662  1.5  riastrad 		rpdownei = I915_READ_FW(GEN6_RP_CUR_DOWN_EI) & GEN6_RP_EI_MASK;
   1663  1.5  riastrad 		intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL);
   1664  1.5  riastrad 
   1665  1.5  riastrad 		seq_printf(m, "\nRPS Autotuning (current \"%s\" window):\n",
   1666  1.5  riastrad 			   rps_power_to_str(rps->power.mode));
   1667  1.5  riastrad 		seq_printf(m, "  Avg. up: %d%% [above threshold? %d%%]\n",
   1668  1.5  riastrad 			   rpup && rpupei ? 100 * rpup / rpupei : 0,
   1669  1.5  riastrad 			   rps->power.up_threshold);
   1670  1.5  riastrad 		seq_printf(m, "  Avg. down: %d%% [below threshold? %d%%]\n",
   1671  1.5  riastrad 			   rpdown && rpdownei ? 100 * rpdown / rpdownei : 0,
   1672  1.5  riastrad 			   rps->power.down_threshold);
   1673  1.5  riastrad 	} else {
   1674  1.5  riastrad 		seq_puts(m, "\nRPS Autotuning inactive\n");
   1675  1.3  riastrad 	}
   1676  1.2      matt 
   1677  1.5  riastrad 	return 0;
   1678  1.5  riastrad }
   1679  1.5  riastrad 
   1680  1.5  riastrad static int i915_llc(struct seq_file *m, void *data)
   1681  1.5  riastrad {
   1682  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1683  1.5  riastrad 	const bool edram = INTEL_GEN(dev_priv) > 8;
   1684  1.5  riastrad 
   1685  1.5  riastrad 	seq_printf(m, "LLC: %s\n", yesno(HAS_LLC(dev_priv)));
   1686  1.5  riastrad 	seq_printf(m, "%s: %uMB\n", edram ? "eDRAM" : "eLLC",
   1687  1.5  riastrad 		   dev_priv->edram_size_mb);
   1688  1.2      matt 
   1689  1.2      matt 	return 0;
   1690  1.2      matt }
   1691  1.2      matt 
   1692  1.5  riastrad static int i915_huc_load_status_info(struct seq_file *m, void *data)
   1693  1.1  riastrad {
   1694  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1695  1.5  riastrad 	intel_wakeref_t wakeref;
   1696  1.5  riastrad 	struct drm_printer p;
   1697  1.5  riastrad 
   1698  1.5  riastrad 	if (!HAS_GT_UC(dev_priv))
   1699  1.5  riastrad 		return -ENODEV;
   1700  1.2      matt 
   1701  1.5  riastrad 	p = drm_seq_file_printer(m);
   1702  1.5  riastrad 	intel_uc_fw_dump(&dev_priv->gt.uc.huc.fw, &p);
   1703  1.5  riastrad 
   1704  1.5  riastrad 	with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref)
   1705  1.5  riastrad 		seq_printf(m, "\nHuC status 0x%08x:\n", I915_READ(HUC_STATUS2));
   1706  1.2      matt 
   1707  1.5  riastrad 	return 0;
   1708  1.2      matt }
   1709  1.1  riastrad 
   1710  1.5  riastrad static int i915_guc_load_status_info(struct seq_file *m, void *data)
   1711  1.2      matt {
   1712  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1713  1.5  riastrad 	intel_wakeref_t wakeref;
   1714  1.5  riastrad 	struct drm_printer p;
   1715  1.5  riastrad 
   1716  1.5  riastrad 	if (!HAS_GT_UC(dev_priv))
   1717  1.5  riastrad 		return -ENODEV;
   1718  1.5  riastrad 
   1719  1.5  riastrad 	p = drm_seq_file_printer(m);
   1720  1.5  riastrad 	intel_uc_fw_dump(&dev_priv->gt.uc.guc.fw, &p);
   1721  1.1  riastrad 
   1722  1.5  riastrad 	with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) {
   1723  1.5  riastrad 		u32 tmp = I915_READ(GUC_STATUS);
   1724  1.5  riastrad 		u32 i;
   1725  1.1  riastrad 
   1726  1.5  riastrad 		seq_printf(m, "\nGuC status 0x%08x:\n", tmp);
   1727  1.5  riastrad 		seq_printf(m, "\tBootrom status = 0x%x\n",
   1728  1.5  riastrad 			   (tmp & GS_BOOTROM_MASK) >> GS_BOOTROM_SHIFT);
   1729  1.5  riastrad 		seq_printf(m, "\tuKernel status = 0x%x\n",
   1730  1.5  riastrad 			   (tmp & GS_UKERNEL_MASK) >> GS_UKERNEL_SHIFT);
   1731  1.5  riastrad 		seq_printf(m, "\tMIA Core status = 0x%x\n",
   1732  1.5  riastrad 			   (tmp & GS_MIA_MASK) >> GS_MIA_SHIFT);
   1733  1.5  riastrad 		seq_puts(m, "\nScratch registers:\n");
   1734  1.5  riastrad 		for (i = 0; i < 16; i++) {
   1735  1.5  riastrad 			seq_printf(m, "\t%2d: \t0x%x\n",
   1736  1.5  riastrad 				   i, I915_READ(SOFT_SCRATCH(i)));
   1737  1.5  riastrad 		}
   1738  1.1  riastrad 	}
   1739  1.1  riastrad 
   1740  1.5  riastrad 	return 0;
   1741  1.5  riastrad }
   1742  1.2      matt 
   1743  1.5  riastrad static const char *
   1744  1.5  riastrad stringify_guc_log_type(enum guc_log_buffer_type type)
   1745  1.5  riastrad {
   1746  1.5  riastrad 	switch (type) {
   1747  1.5  riastrad 	case GUC_ISR_LOG_BUFFER:
   1748  1.5  riastrad 		return "ISR";
   1749  1.5  riastrad 	case GUC_DPC_LOG_BUFFER:
   1750  1.5  riastrad 		return "DPC";
   1751  1.5  riastrad 	case GUC_CRASH_DUMP_LOG_BUFFER:
   1752  1.5  riastrad 		return "CRASH";
   1753  1.5  riastrad 	default:
   1754  1.5  riastrad 		MISSING_CASE(type);
   1755  1.3  riastrad 	}
   1756  1.2      matt 
   1757  1.5  riastrad 	return "";
   1758  1.2      matt }
   1759  1.2      matt 
   1760  1.5  riastrad static void i915_guc_log_info(struct seq_file *m,
   1761  1.5  riastrad 			      struct drm_i915_private *dev_priv)
   1762  1.2      matt {
   1763  1.5  riastrad 	struct intel_guc_log *log = &dev_priv->gt.uc.guc.log;
   1764  1.5  riastrad 	enum guc_log_buffer_type type;
   1765  1.2      matt 
   1766  1.5  riastrad 	if (!intel_guc_log_relay_created(log)) {
   1767  1.5  riastrad 		seq_puts(m, "GuC log relay not created\n");
   1768  1.5  riastrad 		return;
   1769  1.5  riastrad 	}
   1770  1.2      matt 
   1771  1.5  riastrad 	seq_puts(m, "GuC logging stats:\n");
   1772  1.3  riastrad 
   1773  1.5  riastrad 	seq_printf(m, "\tRelay full count: %u\n",
   1774  1.5  riastrad 		   log->relay.full_count);
   1775  1.1  riastrad 
   1776  1.5  riastrad 	for (type = GUC_ISR_LOG_BUFFER; type < GUC_MAX_LOG_BUFFER; type++) {
   1777  1.5  riastrad 		seq_printf(m, "\t%s:\tflush count %10u, overflow count %10u\n",
   1778  1.5  riastrad 			   stringify_guc_log_type(type),
   1779  1.5  riastrad 			   log->stats[type].flush,
   1780  1.5  riastrad 			   log->stats[type].sampled_overflow);
   1781  1.5  riastrad 	}
   1782  1.3  riastrad }
   1783  1.3  riastrad 
   1784  1.5  riastrad static int i915_guc_info(struct seq_file *m, void *data)
   1785  1.3  riastrad {
   1786  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1787  1.5  riastrad 
   1788  1.5  riastrad 	if (!USES_GUC(dev_priv))
   1789  1.5  riastrad 		return -ENODEV;
   1790  1.5  riastrad 
   1791  1.5  riastrad 	i915_guc_log_info(m, dev_priv);
   1792  1.3  riastrad 
   1793  1.5  riastrad 	/* Add more as required ... */
   1794  1.3  riastrad 
   1795  1.5  riastrad 	return 0;
   1796  1.3  riastrad }
   1797  1.3  riastrad 
   1798  1.5  riastrad static int i915_guc_stage_pool(struct seq_file *m, void *data)
   1799  1.3  riastrad {
   1800  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   1801  1.5  riastrad 	const struct intel_guc *guc = &dev_priv->gt.uc.guc;
   1802  1.5  riastrad 	struct guc_stage_desc *desc = guc->stage_desc_pool_vaddr;
   1803  1.5  riastrad 	int index;
   1804  1.5  riastrad 
   1805  1.5  riastrad 	if (!USES_GUC_SUBMISSION(dev_priv))
   1806  1.5  riastrad 		return -ENODEV;
   1807  1.5  riastrad 
   1808  1.5  riastrad 	for (index = 0; index < GUC_MAX_STAGE_DESCRIPTORS; index++, desc++) {
   1809  1.5  riastrad 		struct intel_engine_cs *engine;
   1810  1.5  riastrad 
   1811  1.5  riastrad 		if (!(desc->attribute & GUC_STAGE_DESC_ATTR_ACTIVE))
   1812  1.5  riastrad 			continue;
   1813  1.5  riastrad 
   1814  1.5  riastrad 		seq_printf(m, "GuC stage descriptor %u:\n", index);
   1815  1.5  riastrad 		seq_printf(m, "\tIndex: %u\n", desc->stage_id);
   1816  1.5  riastrad 		seq_printf(m, "\tAttribute: 0x%x\n", desc->attribute);
   1817  1.5  riastrad 		seq_printf(m, "\tPriority: %d\n", desc->priority);
   1818  1.5  riastrad 		seq_printf(m, "\tDoorbell id: %d\n", desc->db_id);
   1819  1.5  riastrad 		seq_printf(m, "\tEngines used: 0x%x\n",
   1820  1.5  riastrad 			   desc->engines_used);
   1821  1.5  riastrad 		seq_printf(m, "\tDoorbell trigger phy: 0x%llx, cpu: 0x%llx, uK: 0x%x\n",
   1822  1.5  riastrad 			   desc->db_trigger_phy,
   1823  1.5  riastrad 			   desc->db_trigger_cpu,
   1824  1.5  riastrad 			   desc->db_trigger_uk);
   1825  1.5  riastrad 		seq_printf(m, "\tProcess descriptor: 0x%x\n",
   1826  1.5  riastrad 			   desc->process_desc);
   1827  1.5  riastrad 		seq_printf(m, "\tWorkqueue address: 0x%x, size: 0x%x\n",
   1828  1.5  riastrad 			   desc->wq_addr, desc->wq_size);
   1829  1.5  riastrad 		seq_putc(m, '\n');
   1830  1.5  riastrad 
   1831  1.5  riastrad 		for_each_uabi_engine(engine, dev_priv) {
   1832  1.5  riastrad 			u32 guc_engine_id = engine->guc_id;
   1833  1.5  riastrad 			struct guc_execlist_context *lrc =
   1834  1.5  riastrad 						&desc->lrc[guc_engine_id];
   1835  1.5  riastrad 
   1836  1.5  riastrad 			seq_printf(m, "\t%s LRC:\n", engine->name);
   1837  1.5  riastrad 			seq_printf(m, "\t\tContext desc: 0x%x\n",
   1838  1.5  riastrad 				   lrc->context_desc);
   1839  1.5  riastrad 			seq_printf(m, "\t\tContext id: 0x%x\n", lrc->context_id);
   1840  1.5  riastrad 			seq_printf(m, "\t\tLRCA: 0x%x\n", lrc->ring_lrca);
   1841  1.5  riastrad 			seq_printf(m, "\t\tRing begin: 0x%x\n", lrc->ring_begin);
   1842  1.5  riastrad 			seq_printf(m, "\t\tRing end: 0x%x\n", lrc->ring_end);
   1843  1.5  riastrad 			seq_putc(m, '\n');
   1844  1.5  riastrad 		}
   1845  1.5  riastrad 	}
   1846  1.3  riastrad 
   1847  1.1  riastrad 	return 0;
   1848  1.1  riastrad }
   1849  1.1  riastrad 
   1850  1.5  riastrad static int i915_guc_log_dump(struct seq_file *m, void *data)
   1851  1.1  riastrad {
   1852  1.3  riastrad 	struct drm_info_node *node = m->private;
   1853  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(node);
   1854  1.5  riastrad 	bool dump_load_err = !!node->info_ent->data;
   1855  1.5  riastrad 	struct drm_i915_gem_object *obj = NULL;
   1856  1.5  riastrad 	u32 *log;
   1857  1.5  riastrad 	int i = 0;
   1858  1.5  riastrad 
   1859  1.5  riastrad 	if (!HAS_GT_UC(dev_priv))
   1860  1.5  riastrad 		return -ENODEV;
   1861  1.5  riastrad 
   1862  1.5  riastrad 	if (dump_load_err)
   1863  1.5  riastrad 		obj = dev_priv->gt.uc.load_err_log;
   1864  1.5  riastrad 	else if (dev_priv->gt.uc.guc.log.vma)
   1865  1.5  riastrad 		obj = dev_priv->gt.uc.guc.log.vma->obj;
   1866  1.5  riastrad 
   1867  1.5  riastrad 	if (!obj)
   1868  1.5  riastrad 		return 0;
   1869  1.5  riastrad 
   1870  1.5  riastrad 	log = i915_gem_object_pin_map(obj, I915_MAP_WC);
   1871  1.5  riastrad 	if (IS_ERR(log)) {
   1872  1.5  riastrad 		DRM_DEBUG("Failed to pin object\n");
   1873  1.5  riastrad 		seq_puts(m, "(log data unaccessible)\n");
   1874  1.5  riastrad 		return PTR_ERR(log);
   1875  1.5  riastrad 	}
   1876  1.5  riastrad 
   1877  1.5  riastrad 	for (i = 0; i < obj->base.size / sizeof(u32); i += 4)
   1878  1.5  riastrad 		seq_printf(m, "0x%08x 0x%08x 0x%08x 0x%08x\n",
   1879  1.5  riastrad 			   *(log + i), *(log + i + 1),
   1880  1.5  riastrad 			   *(log + i + 2), *(log + i + 3));
   1881  1.1  riastrad 
   1882  1.5  riastrad 	seq_putc(m, '\n');
   1883  1.5  riastrad 
   1884  1.5  riastrad 	i915_gem_object_unpin_map(obj);
   1885  1.3  riastrad 
   1886  1.3  riastrad 	return 0;
   1887  1.3  riastrad }
   1888  1.3  riastrad 
   1889  1.5  riastrad static int i915_guc_log_level_get(void *data, u64 *val)
   1890  1.3  riastrad {
   1891  1.5  riastrad 	struct drm_i915_private *dev_priv = data;
   1892  1.1  riastrad 
   1893  1.5  riastrad 	if (!USES_GUC(dev_priv))
   1894  1.5  riastrad 		return -ENODEV;
   1895  1.1  riastrad 
   1896  1.5  riastrad 	*val = intel_guc_log_get_level(&dev_priv->gt.uc.guc.log);
   1897  1.3  riastrad 
   1898  1.3  riastrad 	return 0;
   1899  1.3  riastrad }
   1900  1.3  riastrad 
   1901  1.5  riastrad static int i915_guc_log_level_set(void *data, u64 val)
   1902  1.5  riastrad {
   1903  1.5  riastrad 	struct drm_i915_private *dev_priv = data;
   1904  1.5  riastrad 
   1905  1.5  riastrad 	if (!USES_GUC(dev_priv))
   1906  1.5  riastrad 		return -ENODEV;
   1907  1.5  riastrad 
   1908  1.5  riastrad 	return intel_guc_log_set_level(&dev_priv->gt.uc.guc.log, val);
   1909  1.5  riastrad }
   1910  1.5  riastrad 
   1911  1.5  riastrad DEFINE_SIMPLE_ATTRIBUTE(i915_guc_log_level_fops,
   1912  1.5  riastrad 			i915_guc_log_level_get, i915_guc_log_level_set,
   1913  1.5  riastrad 			"%lld\n");
   1914  1.5  riastrad 
   1915  1.5  riastrad static int i915_guc_log_relay_open(struct inode *inode, struct file *file)
   1916  1.5  riastrad {
   1917  1.5  riastrad 	struct drm_i915_private *i915 = inode->i_private;
   1918  1.5  riastrad 	struct intel_guc *guc = &i915->gt.uc.guc;
   1919  1.5  riastrad 	struct intel_guc_log *log = &guc->log;
   1920  1.5  riastrad 
   1921  1.5  riastrad 	if (!intel_guc_is_running(guc))
   1922  1.5  riastrad 		return -ENODEV;
   1923  1.5  riastrad 
   1924  1.5  riastrad 	file->private_data = log;
   1925  1.5  riastrad 
   1926  1.5  riastrad 	return intel_guc_log_relay_open(log);
   1927  1.3  riastrad }
   1928  1.1  riastrad 
   1929  1.5  riastrad static ssize_t
   1930  1.5  riastrad i915_guc_log_relay_write(struct file *filp,
   1931  1.5  riastrad 			 const char __user *ubuf,
   1932  1.5  riastrad 			 size_t cnt,
   1933  1.5  riastrad 			 loff_t *ppos)
   1934  1.3  riastrad {
   1935  1.5  riastrad 	struct intel_guc_log *log = filp->private_data;
   1936  1.5  riastrad 	int val;
   1937  1.5  riastrad 	int ret;
   1938  1.2      matt 
   1939  1.5  riastrad 	ret = kstrtoint_from_user(ubuf, cnt, 0, &val);
   1940  1.5  riastrad 	if (ret < 0)
   1941  1.5  riastrad 		return ret;
   1942  1.2      matt 
   1943  1.5  riastrad 	/*
   1944  1.5  riastrad 	 * Enable and start the guc log relay on value of 1.
   1945  1.5  riastrad 	 * Flush log relay for any other value.
   1946  1.5  riastrad 	 */
   1947  1.5  riastrad 	if (val == 1)
   1948  1.5  riastrad 		ret = intel_guc_log_relay_start(log);
   1949  1.5  riastrad 	else
   1950  1.5  riastrad 		intel_guc_log_relay_flush(log);
   1951  1.1  riastrad 
   1952  1.5  riastrad 	return ret ?: cnt;
   1953  1.5  riastrad }
   1954  1.1  riastrad 
   1955  1.5  riastrad static int i915_guc_log_relay_release(struct inode *inode, struct file *file)
   1956  1.5  riastrad {
   1957  1.5  riastrad 	struct drm_i915_private *i915 = inode->i_private;
   1958  1.5  riastrad 	struct intel_guc *guc = &i915->gt.uc.guc;
   1959  1.1  riastrad 
   1960  1.5  riastrad 	intel_guc_log_relay_close(&guc->log);
   1961  1.1  riastrad 	return 0;
   1962  1.1  riastrad }
   1963  1.1  riastrad 
   1964  1.5  riastrad static const struct file_operations i915_guc_log_relay_fops = {
   1965  1.5  riastrad 	.owner = THIS_MODULE,
   1966  1.5  riastrad 	.open = i915_guc_log_relay_open,
   1967  1.5  riastrad 	.write = i915_guc_log_relay_write,
   1968  1.5  riastrad 	.release = i915_guc_log_relay_release,
   1969  1.5  riastrad };
   1970  1.5  riastrad 
   1971  1.5  riastrad static int i915_psr_sink_status_show(struct seq_file *m, void *data)
   1972  1.2      matt {
   1973  1.5  riastrad 	u8 val;
   1974  1.5  riastrad 	static const char * const sink_status[] = {
   1975  1.5  riastrad 		"inactive",
   1976  1.5  riastrad 		"transition to active, capture and display",
   1977  1.5  riastrad 		"active, display from RFB",
   1978  1.5  riastrad 		"active, capture and display on sink device timings",
   1979  1.5  riastrad 		"transition to inactive, capture and display, timing re-sync",
   1980  1.5  riastrad 		"reserved",
   1981  1.5  riastrad 		"reserved",
   1982  1.5  riastrad 		"sink internal error",
   1983  1.5  riastrad 	};
   1984  1.5  riastrad 	struct drm_connector *connector = m->private;
   1985  1.5  riastrad 	struct drm_i915_private *dev_priv = to_i915(connector->dev);
   1986  1.5  riastrad 	struct intel_dp *intel_dp =
   1987  1.5  riastrad 		enc_to_intel_dp(intel_attached_encoder(to_intel_connector(connector)));
   1988  1.5  riastrad 	int ret;
   1989  1.5  riastrad 
   1990  1.5  riastrad 	if (!CAN_PSR(dev_priv)) {
   1991  1.5  riastrad 		seq_puts(m, "PSR Unsupported\n");
   1992  1.5  riastrad 		return -ENODEV;
   1993  1.5  riastrad 	}
   1994  1.3  riastrad 
   1995  1.5  riastrad 	if (connector->status != connector_status_connected)
   1996  1.5  riastrad 		return -ENODEV;
   1997  1.3  riastrad 
   1998  1.5  riastrad 	ret = drm_dp_dpcd_readb(&intel_dp->aux, DP_PSR_STATUS, &val);
   1999  1.3  riastrad 
   2000  1.5  riastrad 	if (ret == 1) {
   2001  1.5  riastrad 		const char *str = "unknown";
   2002  1.3  riastrad 
   2003  1.5  riastrad 		val &= DP_PSR_SINK_STATE_MASK;
   2004  1.5  riastrad 		if (val < ARRAY_SIZE(sink_status))
   2005  1.5  riastrad 			str = sink_status[val];
   2006  1.5  riastrad 		seq_printf(m, "Sink PSR status: 0x%x [%s]\n", val, str);
   2007  1.5  riastrad 	} else {
   2008  1.5  riastrad 		return ret;
   2009  1.3  riastrad 	}
   2010  1.1  riastrad 
   2011  1.5  riastrad 	return 0;
   2012  1.5  riastrad }
   2013  1.5  riastrad DEFINE_SHOW_ATTRIBUTE(i915_psr_sink_status);
   2014  1.5  riastrad 
   2015  1.5  riastrad static void
   2016  1.5  riastrad psr_source_status(struct drm_i915_private *dev_priv, struct seq_file *m)
   2017  1.5  riastrad {
   2018  1.5  riastrad 	u32 val, status_val;
   2019  1.5  riastrad 	const char *status = "unknown";
   2020  1.5  riastrad 
   2021  1.5  riastrad 	if (dev_priv->psr.psr2_enabled) {
   2022  1.5  riastrad 		static const char * const live_status[] = {
   2023  1.5  riastrad 			"IDLE",
   2024  1.5  riastrad 			"CAPTURE",
   2025  1.5  riastrad 			"CAPTURE_FS",
   2026  1.5  riastrad 			"SLEEP",
   2027  1.5  riastrad 			"BUFON_FW",
   2028  1.5  riastrad 			"ML_UP",
   2029  1.5  riastrad 			"SU_STANDBY",
   2030  1.5  riastrad 			"FAST_SLEEP",
   2031  1.5  riastrad 			"DEEP_SLEEP",
   2032  1.5  riastrad 			"BUF_ON",
   2033  1.5  riastrad 			"TG_ON"
   2034  1.5  riastrad 		};
   2035  1.5  riastrad 		val = I915_READ(EDP_PSR2_STATUS(dev_priv->psr.transcoder));
   2036  1.5  riastrad 		status_val = (val & EDP_PSR2_STATUS_STATE_MASK) >>
   2037  1.5  riastrad 			      EDP_PSR2_STATUS_STATE_SHIFT;
   2038  1.5  riastrad 		if (status_val < ARRAY_SIZE(live_status))
   2039  1.5  riastrad 			status = live_status[status_val];
   2040  1.5  riastrad 	} else {
   2041  1.5  riastrad 		static const char * const live_status[] = {
   2042  1.5  riastrad 			"IDLE",
   2043  1.5  riastrad 			"SRDONACK",
   2044  1.5  riastrad 			"SRDENT",
   2045  1.5  riastrad 			"BUFOFF",
   2046  1.5  riastrad 			"BUFON",
   2047  1.5  riastrad 			"AUXACK",
   2048  1.5  riastrad 			"SRDOFFACK",
   2049  1.5  riastrad 			"SRDENT_ON",
   2050  1.5  riastrad 		};
   2051  1.5  riastrad 		val = I915_READ(EDP_PSR_STATUS(dev_priv->psr.transcoder));
   2052  1.5  riastrad 		status_val = (val & EDP_PSR_STATUS_STATE_MASK) >>
   2053  1.5  riastrad 			      EDP_PSR_STATUS_STATE_SHIFT;
   2054  1.5  riastrad 		if (status_val < ARRAY_SIZE(live_status))
   2055  1.5  riastrad 			status = live_status[status_val];
   2056  1.5  riastrad 	}
   2057  1.1  riastrad 
   2058  1.5  riastrad 	seq_printf(m, "Source PSR status: %s [0x%08x]\n", status, val);
   2059  1.1  riastrad }
   2060  1.1  riastrad 
   2061  1.2      matt static int i915_edp_psr_status(struct seq_file *m, void *data)
   2062  1.2      matt {
   2063  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2064  1.5  riastrad 	struct i915_psr *psr = &dev_priv->psr;
   2065  1.5  riastrad 	intel_wakeref_t wakeref;
   2066  1.5  riastrad 	const char *status;
   2067  1.5  riastrad 	bool enabled;
   2068  1.5  riastrad 	u32 val;
   2069  1.5  riastrad 
   2070  1.5  riastrad 	if (!HAS_PSR(dev_priv))
   2071  1.5  riastrad 		return -ENODEV;
   2072  1.5  riastrad 
   2073  1.5  riastrad 	seq_printf(m, "Sink support: %s", yesno(psr->sink_support));
   2074  1.5  riastrad 	if (psr->dp)
   2075  1.5  riastrad 		seq_printf(m, " [0x%02x]", psr->dp->psr_dpcd[0]);
   2076  1.5  riastrad 	seq_puts(m, "\n");
   2077  1.1  riastrad 
   2078  1.5  riastrad 	if (!psr->sink_support)
   2079  1.3  riastrad 		return 0;
   2080  1.5  riastrad 
   2081  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
   2082  1.5  riastrad 	mutex_lock(&psr->lock);
   2083  1.5  riastrad 
   2084  1.5  riastrad 	if (psr->enabled)
   2085  1.5  riastrad 		status = psr->psr2_enabled ? "PSR2 enabled" : "PSR1 enabled";
   2086  1.5  riastrad 	else
   2087  1.5  riastrad 		status = "disabled";
   2088  1.5  riastrad 	seq_printf(m, "PSR mode: %s\n", status);
   2089  1.5  riastrad 
   2090  1.5  riastrad 	if (!psr->enabled) {
   2091  1.5  riastrad 		seq_printf(m, "PSR sink not reliable: %s\n",
   2092  1.5  riastrad 			   yesno(psr->sink_not_reliable));
   2093  1.5  riastrad 
   2094  1.5  riastrad 		goto unlock;
   2095  1.5  riastrad 	}
   2096  1.5  riastrad 
   2097  1.5  riastrad 	if (psr->psr2_enabled) {
   2098  1.5  riastrad 		val = I915_READ(EDP_PSR2_CTL(dev_priv->psr.transcoder));
   2099  1.5  riastrad 		enabled = val & EDP_PSR2_ENABLE;
   2100  1.5  riastrad 	} else {
   2101  1.5  riastrad 		val = I915_READ(EDP_PSR_CTL(dev_priv->psr.transcoder));
   2102  1.5  riastrad 		enabled = val & EDP_PSR_ENABLE;
   2103  1.3  riastrad 	}
   2104  1.5  riastrad 	seq_printf(m, "Source PSR ctl: %s [0x%08x]\n",
   2105  1.5  riastrad 		   enableddisabled(enabled), val);
   2106  1.5  riastrad 	psr_source_status(dev_priv, m);
   2107  1.5  riastrad 	seq_printf(m, "Busy frontbuffer bits: 0x%08x\n",
   2108  1.5  riastrad 		   psr->busy_frontbuffer_bits);
   2109  1.3  riastrad 
   2110  1.5  riastrad 	/*
   2111  1.5  riastrad 	 * SKL+ Perf counter is reset to 0 everytime DC state is entered
   2112  1.5  riastrad 	 */
   2113  1.5  riastrad 	if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
   2114  1.5  riastrad 		val = I915_READ(EDP_PSR_PERF_CNT(dev_priv->psr.transcoder));
   2115  1.5  riastrad 		val &= EDP_PSR_PERF_CNT_MASK;
   2116  1.5  riastrad 		seq_printf(m, "Performance counter: %u\n", val);
   2117  1.5  riastrad 	}
   2118  1.1  riastrad 
   2119  1.5  riastrad 	if (psr->debug & I915_PSR_DEBUG_IRQ) {
   2120  1.5  riastrad 		seq_printf(m, "Last attempted entry at: %lld\n",
   2121  1.5  riastrad 			   psr->last_entry_attempt);
   2122  1.5  riastrad 		seq_printf(m, "Last exit at: %lld\n", psr->last_exit);
   2123  1.3  riastrad 	}
   2124  1.1  riastrad 
   2125  1.5  riastrad 	if (psr->psr2_enabled) {
   2126  1.5  riastrad 		u32 su_frames_val[3];
   2127  1.5  riastrad 		int frame;
   2128  1.5  riastrad 
   2129  1.5  riastrad 		/*
   2130  1.5  riastrad 		 * Reading all 3 registers before hand to minimize crossing a
   2131  1.5  riastrad 		 * frame boundary between register reads
   2132  1.5  riastrad 		 */
   2133  1.5  riastrad 		for (frame = 0; frame < PSR2_SU_STATUS_FRAMES; frame += 3) {
   2134  1.5  riastrad 			val = I915_READ(PSR2_SU_STATUS(dev_priv->psr.transcoder,
   2135  1.5  riastrad 						       frame));
   2136  1.5  riastrad 			su_frames_val[frame / 3] = val;
   2137  1.3  riastrad 		}
   2138  1.1  riastrad 
   2139  1.5  riastrad 		seq_puts(m, "Frame:\tPSR2 SU blocks:\n");
   2140  1.5  riastrad 
   2141  1.5  riastrad 		for (frame = 0; frame < PSR2_SU_STATUS_FRAMES; frame++) {
   2142  1.5  riastrad 			u32 su_blocks;
   2143  1.3  riastrad 
   2144  1.5  riastrad 			su_blocks = su_frames_val[frame / 3] &
   2145  1.5  riastrad 				    PSR2_SU_STATUS_MASK(frame);
   2146  1.5  riastrad 			su_blocks = su_blocks >> PSR2_SU_STATUS_SHIFT(frame);
   2147  1.5  riastrad 			seq_printf(m, "%d\t%d\n", frame, su_blocks);
   2148  1.5  riastrad 		}
   2149  1.3  riastrad 	}
   2150  1.1  riastrad 
   2151  1.5  riastrad unlock:
   2152  1.5  riastrad 	mutex_unlock(&psr->lock);
   2153  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
   2154  1.5  riastrad 
   2155  1.2      matt 	return 0;
   2156  1.1  riastrad }
   2157  1.1  riastrad 
   2158  1.5  riastrad static int
   2159  1.5  riastrad i915_edp_psr_debug_set(void *data, u64 val)
   2160  1.2      matt {
   2161  1.5  riastrad 	struct drm_i915_private *dev_priv = data;
   2162  1.5  riastrad 	intel_wakeref_t wakeref;
   2163  1.2      matt 	int ret;
   2164  1.2      matt 
   2165  1.5  riastrad 	if (!CAN_PSR(dev_priv))
   2166  1.5  riastrad 		return -ENODEV;
   2167  1.5  riastrad 
   2168  1.5  riastrad 	DRM_DEBUG_KMS("Setting PSR debug to %llx\n", val);
   2169  1.5  riastrad 
   2170  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
   2171  1.2      matt 
   2172  1.5  riastrad 	ret = intel_psr_debug_set(dev_priv, val);
   2173  1.2      matt 
   2174  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
   2175  1.1  riastrad 
   2176  1.5  riastrad 	return ret;
   2177  1.5  riastrad }
   2178  1.1  riastrad 
   2179  1.5  riastrad static int
   2180  1.5  riastrad i915_edp_psr_debug_get(void *data, u64 *val)
   2181  1.5  riastrad {
   2182  1.5  riastrad 	struct drm_i915_private *dev_priv = data;
   2183  1.1  riastrad 
   2184  1.5  riastrad 	if (!CAN_PSR(dev_priv))
   2185  1.5  riastrad 		return -ENODEV;
   2186  1.1  riastrad 
   2187  1.5  riastrad 	*val = READ_ONCE(dev_priv->psr.debug);
   2188  1.5  riastrad 	return 0;
   2189  1.1  riastrad }
   2190  1.1  riastrad 
   2191  1.5  riastrad DEFINE_SIMPLE_ATTRIBUTE(i915_edp_psr_debug_fops,
   2192  1.5  riastrad 			i915_edp_psr_debug_get, i915_edp_psr_debug_set,
   2193  1.5  riastrad 			"%llu\n");
   2194  1.5  riastrad 
   2195  1.2      matt static int i915_energy_uJ(struct seq_file *m, void *data)
   2196  1.1  riastrad {
   2197  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2198  1.5  riastrad 	unsigned long long power;
   2199  1.5  riastrad 	intel_wakeref_t wakeref;
   2200  1.2      matt 	u32 units;
   2201  1.1  riastrad 
   2202  1.5  riastrad 	if (INTEL_GEN(dev_priv) < 6)
   2203  1.2      matt 		return -ENODEV;
   2204  1.1  riastrad 
   2205  1.5  riastrad 	if (rdmsrl_safe(MSR_RAPL_POWER_UNIT, &power))
   2206  1.5  riastrad 		return -ENODEV;
   2207  1.1  riastrad 
   2208  1.5  riastrad 	units = (power & 0x1f00) >> 8;
   2209  1.5  riastrad 	with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref)
   2210  1.5  riastrad 		power = I915_READ(MCH_SECP_NRG_STTS);
   2211  1.1  riastrad 
   2212  1.5  riastrad 	power = (1000000 * power) >> units; /* convert to uJ */
   2213  1.5  riastrad 	seq_printf(m, "%llu", power);
   2214  1.1  riastrad 
   2215  1.2      matt 	return 0;
   2216  1.1  riastrad }
   2217  1.1  riastrad 
   2218  1.3  riastrad static int i915_runtime_pm_status(struct seq_file *m, void *unused)
   2219  1.2      matt {
   2220  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2221  1.5  riastrad 	struct pci_dev *pdev = dev_priv->drm.pdev;
   2222  1.5  riastrad 
   2223  1.5  riastrad 	if (!HAS_RUNTIME_PM(dev_priv))
   2224  1.5  riastrad 		seq_puts(m, "Runtime power management not supported\n");
   2225  1.1  riastrad 
   2226  1.5  riastrad 	seq_printf(m, "Runtime power status: %s\n",
   2227  1.5  riastrad 		   enableddisabled(!dev_priv->power_domains.wakeref));
   2228  1.1  riastrad 
   2229  1.5  riastrad 	seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
   2230  1.2      matt 	seq_printf(m, "IRQs disabled: %s\n",
   2231  1.3  riastrad 		   yesno(!intel_irqs_enabled(dev_priv)));
   2232  1.3  riastrad #ifdef CONFIG_PM
   2233  1.3  riastrad 	seq_printf(m, "Usage count: %d\n",
   2234  1.5  riastrad 		   atomic_read(&dev_priv->drm.dev->power.usage_count));
   2235  1.3  riastrad #else
   2236  1.3  riastrad 	seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
   2237  1.3  riastrad #endif
   2238  1.5  riastrad 	seq_printf(m, "PCI device power state: %s [%d]\n",
   2239  1.5  riastrad 		   pci_power_name(pdev->current_state),
   2240  1.5  riastrad 		   pdev->current_state);
   2241  1.5  riastrad 
   2242  1.5  riastrad 	if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)) {
   2243  1.5  riastrad 		struct drm_printer p = drm_seq_file_printer(m);
   2244  1.5  riastrad 
   2245  1.5  riastrad 		print_intel_runtime_pm_wakeref(&dev_priv->runtime_pm, &p);
   2246  1.5  riastrad 	}
   2247  1.1  riastrad 
   2248  1.2      matt 	return 0;
   2249  1.2      matt }
   2250  1.1  riastrad 
   2251  1.5  riastrad static int i915_power_domain_info(struct seq_file *m, void *unused)
   2252  1.2      matt {
   2253  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2254  1.2      matt 	struct i915_power_domains *power_domains = &dev_priv->power_domains;
   2255  1.2      matt 	int i;
   2256  1.1  riastrad 
   2257  1.2      matt 	mutex_lock(&power_domains->lock);
   2258  1.1  riastrad 
   2259  1.2      matt 	seq_printf(m, "%-25s %s\n", "Power well/domain", "Use count");
   2260  1.2      matt 	for (i = 0; i < power_domains->power_well_count; i++) {
   2261  1.2      matt 		struct i915_power_well *power_well;
   2262  1.2      matt 		enum intel_display_power_domain power_domain;
   2263  1.2      matt 
   2264  1.2      matt 		power_well = &power_domains->power_wells[i];
   2265  1.5  riastrad 		seq_printf(m, "%-25s %d\n", power_well->desc->name,
   2266  1.2      matt 			   power_well->count);
   2267  1.2      matt 
   2268  1.5  riastrad 		for_each_power_domain(power_domain, power_well->desc->domains)
   2269  1.2      matt 			seq_printf(m, "  %-23s %d\n",
   2270  1.5  riastrad 				 intel_display_power_domain_str(power_domain),
   2271  1.2      matt 				 power_domains->domain_use_count[power_domain]);
   2272  1.1  riastrad 	}
   2273  1.1  riastrad 
   2274  1.2      matt 	mutex_unlock(&power_domains->lock);
   2275  1.1  riastrad 
   2276  1.2      matt 	return 0;
   2277  1.2      matt }
   2278  1.1  riastrad 
   2279  1.5  riastrad static int i915_dmc_info(struct seq_file *m, void *unused)
   2280  1.5  riastrad {
   2281  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2282  1.5  riastrad 	intel_wakeref_t wakeref;
   2283  1.5  riastrad 	struct intel_csr *csr;
   2284  1.5  riastrad 	i915_reg_t dc5_reg, dc6_reg = {};
   2285  1.5  riastrad 
   2286  1.5  riastrad 	if (!HAS_CSR(dev_priv))
   2287  1.5  riastrad 		return -ENODEV;
   2288  1.5  riastrad 
   2289  1.5  riastrad 	csr = &dev_priv->csr;
   2290  1.5  riastrad 
   2291  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
   2292  1.5  riastrad 
   2293  1.5  riastrad 	seq_printf(m, "fw loaded: %s\n", yesno(csr->dmc_payload != NULL));
   2294  1.5  riastrad 	seq_printf(m, "path: %s\n", csr->fw_path);
   2295  1.5  riastrad 
   2296  1.5  riastrad 	if (!csr->dmc_payload)
   2297  1.5  riastrad 		goto out;
   2298  1.5  riastrad 
   2299  1.5  riastrad 	seq_printf(m, "version: %d.%d\n", CSR_VERSION_MAJOR(csr->version),
   2300  1.5  riastrad 		   CSR_VERSION_MINOR(csr->version));
   2301  1.5  riastrad 
   2302  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 12) {
   2303  1.5  riastrad 		dc5_reg = TGL_DMC_DEBUG_DC5_COUNT;
   2304  1.5  riastrad 		dc6_reg = TGL_DMC_DEBUG_DC6_COUNT;
   2305  1.5  riastrad 		/*
   2306  1.5  riastrad 		 * NOTE: DMC_DEBUG3 is a general purpose reg.
   2307  1.5  riastrad 		 * According to B.Specs:49196 DMC f/w reuses DC5/6 counter
   2308  1.5  riastrad 		 * reg for DC3CO debugging and validation,
   2309  1.5  riastrad 		 * but TGL DMC f/w is using DMC_DEBUG3 reg for DC3CO counter.
   2310  1.5  riastrad 		 */
   2311  1.5  riastrad 		seq_printf(m, "DC3CO count: %d\n", I915_READ(DMC_DEBUG3));
   2312  1.5  riastrad 	} else {
   2313  1.5  riastrad 		dc5_reg = IS_BROXTON(dev_priv) ? BXT_CSR_DC3_DC5_COUNT :
   2314  1.5  riastrad 						 SKL_CSR_DC3_DC5_COUNT;
   2315  1.5  riastrad 		if (!IS_GEN9_LP(dev_priv))
   2316  1.5  riastrad 			dc6_reg = SKL_CSR_DC5_DC6_COUNT;
   2317  1.5  riastrad 	}
   2318  1.5  riastrad 
   2319  1.5  riastrad 	seq_printf(m, "DC3 -> DC5 count: %d\n", I915_READ(dc5_reg));
   2320  1.5  riastrad 	if (dc6_reg.reg)
   2321  1.5  riastrad 		seq_printf(m, "DC5 -> DC6 count: %d\n", I915_READ(dc6_reg));
   2322  1.5  riastrad 
   2323  1.5  riastrad out:
   2324  1.5  riastrad 	seq_printf(m, "program base: 0x%08x\n", I915_READ(CSR_PROGRAM(0)));
   2325  1.5  riastrad 	seq_printf(m, "ssp base: 0x%08x\n", I915_READ(CSR_SSP_BASE));
   2326  1.5  riastrad 	seq_printf(m, "htp: 0x%08x\n", I915_READ(CSR_HTP_SKL));
   2327  1.5  riastrad 
   2328  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
   2329  1.5  riastrad 
   2330  1.5  riastrad 	return 0;
   2331  1.5  riastrad }
   2332  1.5  riastrad 
   2333  1.2      matt static void intel_seq_print_mode(struct seq_file *m, int tabs,
   2334  1.5  riastrad 				 const struct drm_display_mode *mode)
   2335  1.2      matt {
   2336  1.2      matt 	int i;
   2337  1.1  riastrad 
   2338  1.2      matt 	for (i = 0; i < tabs; i++)
   2339  1.2      matt 		seq_putc(m, '\t');
   2340  1.1  riastrad 
   2341  1.5  riastrad 	seq_printf(m, DRM_MODE_FMT "\n", DRM_MODE_ARG(mode));
   2342  1.2      matt }
   2343  1.2      matt 
   2344  1.2      matt static void intel_encoder_info(struct seq_file *m,
   2345  1.5  riastrad 			       struct intel_crtc *crtc,
   2346  1.5  riastrad 			       struct intel_encoder *encoder)
   2347  1.2      matt {
   2348  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2349  1.5  riastrad 	struct drm_connector_list_iter conn_iter;
   2350  1.5  riastrad 	struct drm_connector *connector;
   2351  1.5  riastrad 
   2352  1.5  riastrad 	seq_printf(m, "\t[ENCODER:%d:%s]: connectors:\n",
   2353  1.5  riastrad 		   encoder->base.base.id, encoder->base.name);
   2354  1.5  riastrad 
   2355  1.5  riastrad 	drm_connector_list_iter_begin(&dev_priv->drm, &conn_iter);
   2356  1.5  riastrad 	drm_for_each_connector_iter(connector, &conn_iter) {
   2357  1.5  riastrad 		const struct drm_connector_state *conn_state =
   2358  1.5  riastrad 			connector->state;
   2359  1.5  riastrad 
   2360  1.5  riastrad 		if (conn_state->best_encoder != &encoder->base)
   2361  1.5  riastrad 			continue;
   2362  1.5  riastrad 
   2363  1.5  riastrad 		seq_printf(m, "\t\t[CONNECTOR:%d:%s]\n",
   2364  1.5  riastrad 			   connector->base.id, connector->name);
   2365  1.2      matt 	}
   2366  1.5  riastrad 	drm_connector_list_iter_end(&conn_iter);
   2367  1.1  riastrad }
   2368  1.1  riastrad 
   2369  1.5  riastrad static void intel_panel_info(struct seq_file *m, struct intel_panel *panel)
   2370  1.1  riastrad {
   2371  1.5  riastrad 	const struct drm_display_mode *mode = panel->fixed_mode;
   2372  1.1  riastrad 
   2373  1.5  riastrad 	seq_printf(m, "\tfixed mode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(mode));
   2374  1.2      matt }
   2375  1.1  riastrad 
   2376  1.5  riastrad static void intel_hdcp_info(struct seq_file *m,
   2377  1.5  riastrad 			    struct intel_connector *intel_connector)
   2378  1.2      matt {
   2379  1.5  riastrad 	bool hdcp_cap, hdcp2_cap;
   2380  1.5  riastrad 
   2381  1.5  riastrad 	hdcp_cap = intel_hdcp_capable(intel_connector);
   2382  1.5  riastrad 	hdcp2_cap = intel_hdcp2_capable(intel_connector);
   2383  1.5  riastrad 
   2384  1.5  riastrad 	if (hdcp_cap)
   2385  1.5  riastrad 		seq_puts(m, "HDCP1.4 ");
   2386  1.5  riastrad 	if (hdcp2_cap)
   2387  1.5  riastrad 		seq_puts(m, "HDCP2.2 ");
   2388  1.5  riastrad 
   2389  1.5  riastrad 	if (!hdcp_cap && !hdcp2_cap)
   2390  1.5  riastrad 		seq_puts(m, "None");
   2391  1.1  riastrad 
   2392  1.5  riastrad 	seq_puts(m, "\n");
   2393  1.2      matt }
   2394  1.1  riastrad 
   2395  1.2      matt static void intel_dp_info(struct seq_file *m,
   2396  1.2      matt 			  struct intel_connector *intel_connector)
   2397  1.2      matt {
   2398  1.2      matt 	struct intel_encoder *intel_encoder = intel_connector->encoder;
   2399  1.5  riastrad 	struct intel_dp *intel_dp = enc_to_intel_dp(intel_encoder);
   2400  1.1  riastrad 
   2401  1.2      matt 	seq_printf(m, "\tDPCD rev: %x\n", intel_dp->dpcd[DP_DPCD_REV]);
   2402  1.3  riastrad 	seq_printf(m, "\taudio support: %s\n", yesno(intel_dp->has_audio));
   2403  1.5  riastrad 	if (intel_connector->base.connector_type == DRM_MODE_CONNECTOR_eDP)
   2404  1.2      matt 		intel_panel_info(m, &intel_connector->panel);
   2405  1.5  riastrad 
   2406  1.5  riastrad 	drm_dp_downstream_debug(m, intel_dp->dpcd, intel_dp->downstream_ports,
   2407  1.5  riastrad 				&intel_dp->aux);
   2408  1.5  riastrad 	if (intel_connector->hdcp.shim) {
   2409  1.5  riastrad 		seq_puts(m, "\tHDCP version: ");
   2410  1.5  riastrad 		intel_hdcp_info(m, intel_connector);
   2411  1.5  riastrad 	}
   2412  1.5  riastrad }
   2413  1.5  riastrad 
   2414  1.5  riastrad static void intel_dp_mst_info(struct seq_file *m,
   2415  1.5  riastrad 			  struct intel_connector *intel_connector)
   2416  1.5  riastrad {
   2417  1.5  riastrad 	struct intel_encoder *intel_encoder = intel_connector->encoder;
   2418  1.5  riastrad 	struct intel_dp_mst_encoder *intel_mst =
   2419  1.5  riastrad 		enc_to_mst(intel_encoder);
   2420  1.5  riastrad 	struct intel_digital_port *intel_dig_port = intel_mst->primary;
   2421  1.5  riastrad 	struct intel_dp *intel_dp = &intel_dig_port->dp;
   2422  1.5  riastrad 	bool has_audio = drm_dp_mst_port_has_audio(&intel_dp->mst_mgr,
   2423  1.5  riastrad 					intel_connector->port);
   2424  1.5  riastrad 
   2425  1.5  riastrad 	seq_printf(m, "\taudio support: %s\n", yesno(has_audio));
   2426  1.1  riastrad }
   2427  1.1  riastrad 
   2428  1.2      matt static void intel_hdmi_info(struct seq_file *m,
   2429  1.2      matt 			    struct intel_connector *intel_connector)
   2430  1.1  riastrad {
   2431  1.2      matt 	struct intel_encoder *intel_encoder = intel_connector->encoder;
   2432  1.5  riastrad 	struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(intel_encoder);
   2433  1.1  riastrad 
   2434  1.3  riastrad 	seq_printf(m, "\taudio support: %s\n", yesno(intel_hdmi->has_audio));
   2435  1.5  riastrad 	if (intel_connector->hdcp.shim) {
   2436  1.5  riastrad 		seq_puts(m, "\tHDCP version: ");
   2437  1.5  riastrad 		intel_hdcp_info(m, intel_connector);
   2438  1.5  riastrad 	}
   2439  1.2      matt }
   2440  1.1  riastrad 
   2441  1.2      matt static void intel_lvds_info(struct seq_file *m,
   2442  1.2      matt 			    struct intel_connector *intel_connector)
   2443  1.2      matt {
   2444  1.2      matt 	intel_panel_info(m, &intel_connector->panel);
   2445  1.2      matt }
   2446  1.1  riastrad 
   2447  1.2      matt static void intel_connector_info(struct seq_file *m,
   2448  1.2      matt 				 struct drm_connector *connector)
   2449  1.2      matt {
   2450  1.2      matt 	struct intel_connector *intel_connector = to_intel_connector(connector);
   2451  1.5  riastrad 	const struct drm_connector_state *conn_state = connector->state;
   2452  1.5  riastrad 	struct intel_encoder *encoder =
   2453  1.5  riastrad 		to_intel_encoder(conn_state->best_encoder);
   2454  1.5  riastrad 	const struct drm_display_mode *mode;
   2455  1.1  riastrad 
   2456  1.5  riastrad 	seq_printf(m, "[CONNECTOR:%d:%s]: status: %s\n",
   2457  1.3  riastrad 		   connector->base.id, connector->name,
   2458  1.2      matt 		   drm_get_connector_status_name(connector->status));
   2459  1.5  riastrad 
   2460  1.5  riastrad 	if (connector->status == connector_status_disconnected)
   2461  1.5  riastrad 		return;
   2462  1.5  riastrad 
   2463  1.5  riastrad 	seq_printf(m, "\tphysical dimensions: %dx%dmm\n",
   2464  1.5  riastrad 		   connector->display_info.width_mm,
   2465  1.5  riastrad 		   connector->display_info.height_mm);
   2466  1.5  riastrad 	seq_printf(m, "\tsubpixel order: %s\n",
   2467  1.5  riastrad 		   drm_get_subpixel_order_name(connector->display_info.subpixel_order));
   2468  1.5  riastrad 	seq_printf(m, "\tCEA rev: %d\n", connector->display_info.cea_rev);
   2469  1.5  riastrad 
   2470  1.5  riastrad 	if (!encoder)
   2471  1.5  riastrad 		return;
   2472  1.5  riastrad 
   2473  1.5  riastrad 	switch (connector->connector_type) {
   2474  1.5  riastrad 	case DRM_MODE_CONNECTOR_DisplayPort:
   2475  1.5  riastrad 	case DRM_MODE_CONNECTOR_eDP:
   2476  1.5  riastrad 		if (encoder->type == INTEL_OUTPUT_DP_MST)
   2477  1.5  riastrad 			intel_dp_mst_info(m, intel_connector);
   2478  1.5  riastrad 		else
   2479  1.3  riastrad 			intel_dp_info(m, intel_connector);
   2480  1.5  riastrad 		break;
   2481  1.5  riastrad 	case DRM_MODE_CONNECTOR_LVDS:
   2482  1.5  riastrad 		if (encoder->type == INTEL_OUTPUT_LVDS)
   2483  1.5  riastrad 			intel_lvds_info(m, intel_connector);
   2484  1.5  riastrad 		break;
   2485  1.5  riastrad 	case DRM_MODE_CONNECTOR_HDMIA:
   2486  1.5  riastrad 		if (encoder->type == INTEL_OUTPUT_HDMI ||
   2487  1.5  riastrad 		    encoder->type == INTEL_OUTPUT_DDI)
   2488  1.3  riastrad 			intel_hdmi_info(m, intel_connector);
   2489  1.5  riastrad 		break;
   2490  1.5  riastrad 	default:
   2491  1.5  riastrad 		break;
   2492  1.3  riastrad 	}
   2493  1.1  riastrad 
   2494  1.2      matt 	seq_printf(m, "\tmodes:\n");
   2495  1.2      matt 	list_for_each_entry(mode, &connector->modes, head)
   2496  1.2      matt 		intel_seq_print_mode(m, 2, mode);
   2497  1.2      matt }
   2498  1.1  riastrad 
   2499  1.5  riastrad static const char *plane_type(enum drm_plane_type type)
   2500  1.5  riastrad {
   2501  1.5  riastrad 	switch (type) {
   2502  1.5  riastrad 	case DRM_PLANE_TYPE_OVERLAY:
   2503  1.5  riastrad 		return "OVL";
   2504  1.5  riastrad 	case DRM_PLANE_TYPE_PRIMARY:
   2505  1.5  riastrad 		return "PRI";
   2506  1.5  riastrad 	case DRM_PLANE_TYPE_CURSOR:
   2507  1.5  riastrad 		return "CUR";
   2508  1.5  riastrad 	/*
   2509  1.5  riastrad 	 * Deliberately omitting default: to generate compiler warnings
   2510  1.5  riastrad 	 * when a new drm_plane_type gets added.
   2511  1.5  riastrad 	 */
   2512  1.5  riastrad 	}
   2513  1.5  riastrad 
   2514  1.5  riastrad 	return "unknown";
   2515  1.5  riastrad }
   2516  1.5  riastrad 
   2517  1.5  riastrad static void plane_rotation(char *buf, size_t bufsize, unsigned int rotation)
   2518  1.5  riastrad {
   2519  1.5  riastrad 	/*
   2520  1.5  riastrad 	 * According to doc only one DRM_MODE_ROTATE_ is allowed but this
   2521  1.5  riastrad 	 * will print them all to visualize if the values are misused
   2522  1.5  riastrad 	 */
   2523  1.5  riastrad 	snprintf(buf, bufsize,
   2524  1.5  riastrad 		 "%s%s%s%s%s%s(0x%08x)",
   2525  1.5  riastrad 		 (rotation & DRM_MODE_ROTATE_0) ? "0 " : "",
   2526  1.5  riastrad 		 (rotation & DRM_MODE_ROTATE_90) ? "90 " : "",
   2527  1.5  riastrad 		 (rotation & DRM_MODE_ROTATE_180) ? "180 " : "",
   2528  1.5  riastrad 		 (rotation & DRM_MODE_ROTATE_270) ? "270 " : "",
   2529  1.5  riastrad 		 (rotation & DRM_MODE_REFLECT_X) ? "FLIPX " : "",
   2530  1.5  riastrad 		 (rotation & DRM_MODE_REFLECT_Y) ? "FLIPY " : "",
   2531  1.5  riastrad 		 rotation);
   2532  1.5  riastrad }
   2533  1.5  riastrad 
   2534  1.5  riastrad static void intel_plane_uapi_info(struct seq_file *m, struct intel_plane *plane)
   2535  1.5  riastrad {
   2536  1.5  riastrad 	const struct intel_plane_state *plane_state =
   2537  1.5  riastrad 		to_intel_plane_state(plane->base.state);
   2538  1.5  riastrad 	const struct drm_framebuffer *fb = plane_state->uapi.fb;
   2539  1.5  riastrad 	struct drm_format_name_buf format_name;
   2540  1.5  riastrad 	struct drm_rect src, dst;
   2541  1.5  riastrad 	char rot_str[48];
   2542  1.5  riastrad 
   2543  1.5  riastrad 	src = drm_plane_state_src(&plane_state->uapi);
   2544  1.5  riastrad 	dst = drm_plane_state_dest(&plane_state->uapi);
   2545  1.5  riastrad 
   2546  1.5  riastrad 	if (fb)
   2547  1.5  riastrad 		drm_get_format_name(fb->format->format, &format_name);
   2548  1.5  riastrad 
   2549  1.5  riastrad 	plane_rotation(rot_str, sizeof(rot_str),
   2550  1.5  riastrad 		       plane_state->uapi.rotation);
   2551  1.5  riastrad 
   2552  1.5  riastrad 	seq_printf(m, "\t\tuapi: fb=%d,%s,%dx%d, src=" DRM_RECT_FP_FMT ", dst=" DRM_RECT_FMT ", rotation=%s\n",
   2553  1.5  riastrad 		   fb ? fb->base.id : 0, fb ? format_name.str : "n/a",
   2554  1.5  riastrad 		   fb ? fb->width : 0, fb ? fb->height : 0,
   2555  1.5  riastrad 		   DRM_RECT_FP_ARG(&src),
   2556  1.5  riastrad 		   DRM_RECT_ARG(&dst),
   2557  1.5  riastrad 		   rot_str);
   2558  1.5  riastrad }
   2559  1.5  riastrad 
   2560  1.5  riastrad static void intel_plane_hw_info(struct seq_file *m, struct intel_plane *plane)
   2561  1.5  riastrad {
   2562  1.5  riastrad 	const struct intel_plane_state *plane_state =
   2563  1.5  riastrad 		to_intel_plane_state(plane->base.state);
   2564  1.5  riastrad 	const struct drm_framebuffer *fb = plane_state->hw.fb;
   2565  1.5  riastrad 	struct drm_format_name_buf format_name;
   2566  1.5  riastrad 	char rot_str[48];
   2567  1.5  riastrad 
   2568  1.5  riastrad 	if (!fb)
   2569  1.5  riastrad 		return;
   2570  1.5  riastrad 
   2571  1.5  riastrad 	drm_get_format_name(fb->format->format, &format_name);
   2572  1.5  riastrad 
   2573  1.5  riastrad 	plane_rotation(rot_str, sizeof(rot_str),
   2574  1.5  riastrad 		       plane_state->hw.rotation);
   2575  1.5  riastrad 
   2576  1.5  riastrad 	seq_printf(m, "\t\thw: fb=%d,%s,%dx%d, visible=%s, src=" DRM_RECT_FP_FMT ", dst=" DRM_RECT_FMT ", rotation=%s\n",
   2577  1.5  riastrad 		   fb->base.id, format_name.str,
   2578  1.5  riastrad 		   fb->width, fb->height,
   2579  1.5  riastrad 		   yesno(plane_state->uapi.visible),
   2580  1.5  riastrad 		   DRM_RECT_FP_ARG(&plane_state->uapi.src),
   2581  1.5  riastrad 		   DRM_RECT_ARG(&plane_state->uapi.dst),
   2582  1.5  riastrad 		   rot_str);
   2583  1.5  riastrad }
   2584  1.5  riastrad 
   2585  1.5  riastrad static void intel_plane_info(struct seq_file *m, struct intel_crtc *crtc)
   2586  1.5  riastrad {
   2587  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2588  1.5  riastrad 	struct intel_plane *plane;
   2589  1.5  riastrad 
   2590  1.5  riastrad 	for_each_intel_plane_on_crtc(&dev_priv->drm, crtc, plane) {
   2591  1.5  riastrad 		seq_printf(m, "\t[PLANE:%d:%s]: type=%s\n",
   2592  1.5  riastrad 			   plane->base.base.id, plane->base.name,
   2593  1.5  riastrad 			   plane_type(plane->base.type));
   2594  1.5  riastrad 		intel_plane_uapi_info(m, plane);
   2595  1.5  riastrad 		intel_plane_hw_info(m, plane);
   2596  1.5  riastrad 	}
   2597  1.5  riastrad }
   2598  1.5  riastrad 
   2599  1.5  riastrad static void intel_scaler_info(struct seq_file *m, struct intel_crtc *crtc)
   2600  1.2      matt {
   2601  1.5  riastrad 	const struct intel_crtc_state *crtc_state =
   2602  1.5  riastrad 		to_intel_crtc_state(crtc->base.state);
   2603  1.5  riastrad 	int num_scalers = crtc->num_scalers;
   2604  1.5  riastrad 	int i;
   2605  1.1  riastrad 
   2606  1.5  riastrad 	/* Not all platformas have a scaler */
   2607  1.5  riastrad 	if (num_scalers) {
   2608  1.5  riastrad 		seq_printf(m, "\tnum_scalers=%d, scaler_users=%x scaler_id=%d",
   2609  1.5  riastrad 			   num_scalers,
   2610  1.5  riastrad 			   crtc_state->scaler_state.scaler_users,
   2611  1.5  riastrad 			   crtc_state->scaler_state.scaler_id);
   2612  1.5  riastrad 
   2613  1.5  riastrad 		for (i = 0; i < num_scalers; i++) {
   2614  1.5  riastrad 			const struct intel_scaler *sc =
   2615  1.5  riastrad 				&crtc_state->scaler_state.scalers[i];
   2616  1.1  riastrad 
   2617  1.5  riastrad 			seq_printf(m, ", scalers[%d]: use=%s, mode=%x",
   2618  1.5  riastrad 				   i, yesno(sc->in_use), sc->mode);
   2619  1.5  riastrad 		}
   2620  1.5  riastrad 		seq_puts(m, "\n");
   2621  1.5  riastrad 	} else {
   2622  1.5  riastrad 		seq_puts(m, "\tNo scalers available on this platform\n");
   2623  1.5  riastrad 	}
   2624  1.1  riastrad }
   2625  1.1  riastrad 
   2626  1.5  riastrad static void intel_crtc_info(struct seq_file *m, struct intel_crtc *crtc)
   2627  1.2      matt {
   2628  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2629  1.5  riastrad 	const struct intel_crtc_state *crtc_state =
   2630  1.5  riastrad 		to_intel_crtc_state(crtc->base.state);
   2631  1.5  riastrad 	struct intel_encoder *encoder;
   2632  1.5  riastrad 
   2633  1.5  riastrad 	seq_printf(m, "[CRTC:%d:%s]:\n",
   2634  1.5  riastrad 		   crtc->base.base.id, crtc->base.name);
   2635  1.5  riastrad 
   2636  1.5  riastrad 	seq_printf(m, "\tuapi: enable=%s, active=%s, mode=" DRM_MODE_FMT "\n",
   2637  1.5  riastrad 		   yesno(crtc_state->uapi.enable),
   2638  1.5  riastrad 		   yesno(crtc_state->uapi.active),
   2639  1.5  riastrad 		   DRM_MODE_ARG(&crtc_state->uapi.mode));
   2640  1.5  riastrad 
   2641  1.5  riastrad 	if (crtc_state->hw.enable) {
   2642  1.5  riastrad 		seq_printf(m, "\thw: active=%s, adjusted_mode=" DRM_MODE_FMT "\n",
   2643  1.5  riastrad 			   yesno(crtc_state->hw.active),
   2644  1.5  riastrad 			   DRM_MODE_ARG(&crtc_state->hw.adjusted_mode));
   2645  1.1  riastrad 
   2646  1.5  riastrad 		seq_printf(m, "\tpipe src size=%dx%d, dither=%s, bpp=%d\n",
   2647  1.5  riastrad 			   crtc_state->pipe_src_w, crtc_state->pipe_src_h,
   2648  1.5  riastrad 			   yesno(crtc_state->dither), crtc_state->pipe_bpp);
   2649  1.2      matt 
   2650  1.5  riastrad 		intel_scaler_info(m, crtc);
   2651  1.5  riastrad 	}
   2652  1.5  riastrad 
   2653  1.5  riastrad 	for_each_intel_encoder_mask(&dev_priv->drm, encoder,
   2654  1.5  riastrad 				    crtc_state->uapi.encoder_mask)
   2655  1.5  riastrad 		intel_encoder_info(m, crtc, encoder);
   2656  1.2      matt 
   2657  1.5  riastrad 	intel_plane_info(m, crtc);
   2658  1.2      matt 
   2659  1.5  riastrad 	seq_printf(m, "\tunderrun reporting: cpu=%s pch=%s\n",
   2660  1.5  riastrad 		   yesno(!crtc->cpu_fifo_underrun_disabled),
   2661  1.5  riastrad 		   yesno(!crtc->pch_fifo_underrun_disabled));
   2662  1.2      matt }
   2663  1.2      matt 
   2664  1.2      matt static int i915_display_info(struct seq_file *m, void *unused)
   2665  1.2      matt {
   2666  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2667  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   2668  1.2      matt 	struct intel_crtc *crtc;
   2669  1.2      matt 	struct drm_connector *connector;
   2670  1.5  riastrad 	struct drm_connector_list_iter conn_iter;
   2671  1.5  riastrad 	intel_wakeref_t wakeref;
   2672  1.5  riastrad 
   2673  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
   2674  1.2      matt 
   2675  1.2      matt 	drm_modeset_lock_all(dev);
   2676  1.5  riastrad 
   2677  1.2      matt 	seq_printf(m, "CRTC info\n");
   2678  1.2      matt 	seq_printf(m, "---------\n");
   2679  1.5  riastrad 	for_each_intel_crtc(dev, crtc)
   2680  1.5  riastrad 		intel_crtc_info(m, crtc);
   2681  1.2      matt 
   2682  1.2      matt 	seq_printf(m, "\n");
   2683  1.2      matt 	seq_printf(m, "Connector info\n");
   2684  1.2      matt 	seq_printf(m, "--------------\n");
   2685  1.5  riastrad 	drm_connector_list_iter_begin(dev, &conn_iter);
   2686  1.5  riastrad 	drm_for_each_connector_iter(connector, &conn_iter)
   2687  1.2      matt 		intel_connector_info(m, connector);
   2688  1.5  riastrad 	drm_connector_list_iter_end(&conn_iter);
   2689  1.5  riastrad 
   2690  1.2      matt 	drm_modeset_unlock_all(dev);
   2691  1.5  riastrad 
   2692  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
   2693  1.2      matt 
   2694  1.2      matt 	return 0;
   2695  1.2      matt }
   2696  1.2      matt 
   2697  1.5  riastrad static int i915_engine_info(struct seq_file *m, void *unused)
   2698  1.3  riastrad {
   2699  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2700  1.5  riastrad 	struct intel_engine_cs *engine;
   2701  1.5  riastrad 	intel_wakeref_t wakeref;
   2702  1.5  riastrad 	struct drm_printer p;
   2703  1.3  riastrad 
   2704  1.5  riastrad 	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
   2705  1.3  riastrad 
   2706  1.5  riastrad 	seq_printf(m, "GT awake? %s [%d]\n",
   2707  1.5  riastrad 		   yesno(dev_priv->gt.awake),
   2708  1.5  riastrad 		   atomic_read(&dev_priv->gt.wakeref.count));
   2709  1.5  riastrad 	seq_printf(m, "CS timestamp frequency: %u kHz\n",
   2710  1.5  riastrad 		   RUNTIME_INFO(dev_priv)->cs_timestamp_frequency_khz);
   2711  1.3  riastrad 
   2712  1.5  riastrad 	p = drm_seq_file_printer(m);
   2713  1.5  riastrad 	for_each_uabi_engine(engine, dev_priv)
   2714  1.5  riastrad 		intel_engine_dump(engine, &p, "%s\n", engine->name);
   2715  1.3  riastrad 
   2716  1.5  riastrad 	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
   2717  1.3  riastrad 
   2718  1.5  riastrad 	return 0;
   2719  1.5  riastrad }
   2720  1.3  riastrad 
   2721  1.5  riastrad static int i915_rcs_topology(struct seq_file *m, void *unused)
   2722  1.5  riastrad {
   2723  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2724  1.5  riastrad 	struct drm_printer p = drm_seq_file_printer(m);
   2725  1.3  riastrad 
   2726  1.5  riastrad 	intel_device_info_print_topology(&RUNTIME_INFO(dev_priv)->sseu, &p);
   2727  1.3  riastrad 
   2728  1.5  riastrad 	return 0;
   2729  1.5  riastrad }
   2730  1.3  riastrad 
   2731  1.5  riastrad static int i915_shrinker_info(struct seq_file *m, void *unused)
   2732  1.5  riastrad {
   2733  1.5  riastrad 	struct drm_i915_private *i915 = node_to_i915(m->private);
   2734  1.3  riastrad 
   2735  1.5  riastrad 	seq_printf(m, "seeks = %d\n", i915->mm.shrinker.seeks);
   2736  1.5  riastrad 	seq_printf(m, "batch = %lu\n", i915->mm.shrinker.batch);
   2737  1.3  riastrad 
   2738  1.3  riastrad 	return 0;
   2739  1.3  riastrad }
   2740  1.3  riastrad 
   2741  1.3  riastrad static int i915_shared_dplls_info(struct seq_file *m, void *unused)
   2742  1.3  riastrad {
   2743  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2744  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   2745  1.3  riastrad 	int i;
   2746  1.3  riastrad 
   2747  1.3  riastrad 	drm_modeset_lock_all(dev);
   2748  1.3  riastrad 	for (i = 0; i < dev_priv->num_shared_dpll; i++) {
   2749  1.3  riastrad 		struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i];
   2750  1.3  riastrad 
   2751  1.5  riastrad 		seq_printf(m, "DPLL%i: %s, id: %i\n", i, pll->info->name,
   2752  1.5  riastrad 			   pll->info->id);
   2753  1.5  riastrad 		seq_printf(m, " crtc_mask: 0x%08x, active: 0x%x, on: %s\n",
   2754  1.5  riastrad 			   pll->state.crtc_mask, pll->active_mask, yesno(pll->on));
   2755  1.3  riastrad 		seq_printf(m, " tracked hardware state:\n");
   2756  1.5  riastrad 		seq_printf(m, " dpll:    0x%08x\n", pll->state.hw_state.dpll);
   2757  1.3  riastrad 		seq_printf(m, " dpll_md: 0x%08x\n",
   2758  1.5  riastrad 			   pll->state.hw_state.dpll_md);
   2759  1.5  riastrad 		seq_printf(m, " fp0:     0x%08x\n", pll->state.hw_state.fp0);
   2760  1.5  riastrad 		seq_printf(m, " fp1:     0x%08x\n", pll->state.hw_state.fp1);
   2761  1.5  riastrad 		seq_printf(m, " wrpll:   0x%08x\n", pll->state.hw_state.wrpll);
   2762  1.5  riastrad 		seq_printf(m, " cfgcr0:  0x%08x\n", pll->state.hw_state.cfgcr0);
   2763  1.5  riastrad 		seq_printf(m, " cfgcr1:  0x%08x\n", pll->state.hw_state.cfgcr1);
   2764  1.5  riastrad 		seq_printf(m, " mg_refclkin_ctl:        0x%08x\n",
   2765  1.5  riastrad 			   pll->state.hw_state.mg_refclkin_ctl);
   2766  1.5  riastrad 		seq_printf(m, " mg_clktop2_coreclkctl1: 0x%08x\n",
   2767  1.5  riastrad 			   pll->state.hw_state.mg_clktop2_coreclkctl1);
   2768  1.5  riastrad 		seq_printf(m, " mg_clktop2_hsclkctl:    0x%08x\n",
   2769  1.5  riastrad 			   pll->state.hw_state.mg_clktop2_hsclkctl);
   2770  1.5  riastrad 		seq_printf(m, " mg_pll_div0:  0x%08x\n",
   2771  1.5  riastrad 			   pll->state.hw_state.mg_pll_div0);
   2772  1.5  riastrad 		seq_printf(m, " mg_pll_div1:  0x%08x\n",
   2773  1.5  riastrad 			   pll->state.hw_state.mg_pll_div1);
   2774  1.5  riastrad 		seq_printf(m, " mg_pll_lf:    0x%08x\n",
   2775  1.5  riastrad 			   pll->state.hw_state.mg_pll_lf);
   2776  1.5  riastrad 		seq_printf(m, " mg_pll_frac_lock: 0x%08x\n",
   2777  1.5  riastrad 			   pll->state.hw_state.mg_pll_frac_lock);
   2778  1.5  riastrad 		seq_printf(m, " mg_pll_ssc:   0x%08x\n",
   2779  1.5  riastrad 			   pll->state.hw_state.mg_pll_ssc);
   2780  1.5  riastrad 		seq_printf(m, " mg_pll_bias:  0x%08x\n",
   2781  1.5  riastrad 			   pll->state.hw_state.mg_pll_bias);
   2782  1.5  riastrad 		seq_printf(m, " mg_pll_tdc_coldst_bias: 0x%08x\n",
   2783  1.5  riastrad 			   pll->state.hw_state.mg_pll_tdc_coldst_bias);
   2784  1.3  riastrad 	}
   2785  1.3  riastrad 	drm_modeset_unlock_all(dev);
   2786  1.3  riastrad 
   2787  1.3  riastrad 	return 0;
   2788  1.3  riastrad }
   2789  1.3  riastrad 
   2790  1.3  riastrad static int i915_wa_registers(struct seq_file *m, void *unused)
   2791  1.3  riastrad {
   2792  1.5  riastrad 	struct drm_i915_private *i915 = node_to_i915(m->private);
   2793  1.5  riastrad 	struct intel_engine_cs *engine;
   2794  1.5  riastrad 
   2795  1.5  riastrad 	for_each_uabi_engine(engine, i915) {
   2796  1.5  riastrad 		const struct i915_wa_list *wal = &engine->ctx_wa_list;
   2797  1.5  riastrad 		const struct i915_wa *wa;
   2798  1.5  riastrad 		unsigned int count;
   2799  1.5  riastrad 
   2800  1.5  riastrad 		count = wal->count;
   2801  1.5  riastrad 		if (!count)
   2802  1.5  riastrad 			continue;
   2803  1.3  riastrad 
   2804  1.5  riastrad 		seq_printf(m, "%s: Workarounds applied: %u\n",
   2805  1.5  riastrad 			   engine->name, count);
   2806  1.3  riastrad 
   2807  1.5  riastrad 		for (wa = wal->list; count--; wa++)
   2808  1.5  riastrad 			seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X\n",
   2809  1.5  riastrad 				   i915_mmio_reg_offset(wa->reg),
   2810  1.5  riastrad 				   wa->val, wa->mask);
   2811  1.3  riastrad 
   2812  1.5  riastrad 		seq_printf(m, "\n");
   2813  1.3  riastrad 	}
   2814  1.3  riastrad 
   2815  1.5  riastrad 	return 0;
   2816  1.5  riastrad }
   2817  1.5  riastrad 
   2818  1.5  riastrad static int i915_ipc_status_show(struct seq_file *m, void *data)
   2819  1.5  riastrad {
   2820  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   2821  1.3  riastrad 
   2822  1.5  riastrad 	seq_printf(m, "Isochronous Priority Control: %s\n",
   2823  1.5  riastrad 			yesno(dev_priv->ipc_enabled));
   2824  1.3  riastrad 	return 0;
   2825  1.3  riastrad }
   2826  1.3  riastrad 
   2827  1.5  riastrad static int i915_ipc_status_open(struct inode *inode, struct file *file)
   2828  1.5  riastrad {
   2829  1.5  riastrad 	struct drm_i915_private *dev_priv = inode->i_private;
   2830  1.5  riastrad 
   2831  1.5  riastrad 	if (!HAS_IPC(dev_priv))
   2832  1.5  riastrad 		return -ENODEV;
   2833  1.5  riastrad 
   2834  1.5  riastrad 	return single_open(file, i915_ipc_status_show, dev_priv);
   2835  1.5  riastrad }
   2836  1.5  riastrad 
   2837  1.5  riastrad static ssize_t i915_ipc_status_write(struct file *file, const char __user *ubuf,
   2838  1.5  riastrad 				     size_t len, loff_t *offp)
   2839  1.5  riastrad {
   2840  1.5  riastrad 	struct seq_file *m = file->private_data;
   2841  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   2842  1.5  riastrad 	intel_wakeref_t wakeref;
   2843  1.5  riastrad 	bool enable;
   2844  1.5  riastrad 	int ret;
   2845  1.5  riastrad 
   2846  1.5  riastrad 	ret = kstrtobool_from_user(ubuf, len, &enable);
   2847  1.5  riastrad 	if (ret < 0)
   2848  1.5  riastrad 		return ret;
   2849  1.5  riastrad 
   2850  1.5  riastrad 	with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) {
   2851  1.5  riastrad 		if (!dev_priv->ipc_enabled && enable)
   2852  1.5  riastrad 			DRM_INFO("Enabling IPC: WM will be proper only after next commit\n");
   2853  1.5  riastrad 		dev_priv->wm.distrust_bios_wm = true;
   2854  1.5  riastrad 		dev_priv->ipc_enabled = enable;
   2855  1.5  riastrad 		intel_enable_ipc(dev_priv);
   2856  1.5  riastrad 	}
   2857  1.5  riastrad 
   2858  1.5  riastrad 	return len;
   2859  1.5  riastrad }
   2860  1.5  riastrad 
   2861  1.5  riastrad static const struct file_operations i915_ipc_status_fops = {
   2862  1.5  riastrad 	.owner = THIS_MODULE,
   2863  1.5  riastrad 	.open = i915_ipc_status_open,
   2864  1.5  riastrad 	.read = seq_read,
   2865  1.5  riastrad 	.llseek = seq_lseek,
   2866  1.5  riastrad 	.release = single_release,
   2867  1.5  riastrad 	.write = i915_ipc_status_write
   2868  1.5  riastrad };
   2869  1.5  riastrad 
   2870  1.3  riastrad static int i915_ddb_info(struct seq_file *m, void *unused)
   2871  1.3  riastrad {
   2872  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2873  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   2874  1.3  riastrad 	struct skl_ddb_entry *entry;
   2875  1.5  riastrad 	struct intel_crtc *crtc;
   2876  1.3  riastrad 
   2877  1.5  riastrad 	if (INTEL_GEN(dev_priv) < 9)
   2878  1.5  riastrad 		return -ENODEV;
   2879  1.3  riastrad 
   2880  1.3  riastrad 	drm_modeset_lock_all(dev);
   2881  1.3  riastrad 
   2882  1.5  riastrad 	seq_printf(m, "%-15s%8s%8s%8s\n", "", "Start", "End", "Size");
   2883  1.3  riastrad 
   2884  1.5  riastrad 	for_each_intel_crtc(&dev_priv->drm, crtc) {
   2885  1.5  riastrad 		struct intel_crtc_state *crtc_state =
   2886  1.5  riastrad 			to_intel_crtc_state(crtc->base.state);
   2887  1.5  riastrad 		enum pipe pipe = crtc->pipe;
   2888  1.5  riastrad 		enum plane_id plane_id;
   2889  1.3  riastrad 
   2890  1.3  riastrad 		seq_printf(m, "Pipe %c\n", pipe_name(pipe));
   2891  1.3  riastrad 
   2892  1.5  riastrad 		for_each_plane_id_on_crtc(crtc, plane_id) {
   2893  1.5  riastrad 			entry = &crtc_state->wm.skl.plane_ddb_y[plane_id];
   2894  1.5  riastrad 			seq_printf(m, "  Plane%-8d%8u%8u%8u\n", plane_id + 1,
   2895  1.3  riastrad 				   entry->start, entry->end,
   2896  1.3  riastrad 				   skl_ddb_entry_size(entry));
   2897  1.3  riastrad 		}
   2898  1.3  riastrad 
   2899  1.5  riastrad 		entry = &crtc_state->wm.skl.plane_ddb_y[PLANE_CURSOR];
   2900  1.3  riastrad 		seq_printf(m, "  %-13s%8u%8u%8u\n", "Cursor", entry->start,
   2901  1.3  riastrad 			   entry->end, skl_ddb_entry_size(entry));
   2902  1.3  riastrad 	}
   2903  1.3  riastrad 
   2904  1.3  riastrad 	drm_modeset_unlock_all(dev);
   2905  1.3  riastrad 
   2906  1.3  riastrad 	return 0;
   2907  1.3  riastrad }
   2908  1.3  riastrad 
   2909  1.3  riastrad static void drrs_status_per_crtc(struct seq_file *m,
   2910  1.5  riastrad 				 struct drm_device *dev,
   2911  1.5  riastrad 				 struct intel_crtc *intel_crtc)
   2912  1.3  riastrad {
   2913  1.5  riastrad 	struct drm_i915_private *dev_priv = to_i915(dev);
   2914  1.3  riastrad 	struct i915_drrs *drrs = &dev_priv->drrs;
   2915  1.3  riastrad 	int vrefresh = 0;
   2916  1.5  riastrad 	struct drm_connector *connector;
   2917  1.5  riastrad 	struct drm_connector_list_iter conn_iter;
   2918  1.5  riastrad 
   2919  1.5  riastrad 	drm_connector_list_iter_begin(dev, &conn_iter);
   2920  1.5  riastrad 	drm_for_each_connector_iter(connector, &conn_iter) {
   2921  1.5  riastrad 		if (connector->state->crtc != &intel_crtc->base)
   2922  1.5  riastrad 			continue;
   2923  1.3  riastrad 
   2924  1.5  riastrad 		seq_printf(m, "%s:\n", connector->name);
   2925  1.3  riastrad 	}
   2926  1.5  riastrad 	drm_connector_list_iter_end(&conn_iter);
   2927  1.3  riastrad 
   2928  1.3  riastrad 	if (dev_priv->vbt.drrs_type == STATIC_DRRS_SUPPORT)
   2929  1.3  riastrad 		seq_puts(m, "\tVBT: DRRS_type: Static");
   2930  1.3  riastrad 	else if (dev_priv->vbt.drrs_type == SEAMLESS_DRRS_SUPPORT)
   2931  1.3  riastrad 		seq_puts(m, "\tVBT: DRRS_type: Seamless");
   2932  1.3  riastrad 	else if (dev_priv->vbt.drrs_type == DRRS_NOT_SUPPORTED)
   2933  1.3  riastrad 		seq_puts(m, "\tVBT: DRRS_type: None");
   2934  1.3  riastrad 	else
   2935  1.3  riastrad 		seq_puts(m, "\tVBT: DRRS_type: FIXME: Unrecognized Value");
   2936  1.3  riastrad 
   2937  1.3  riastrad 	seq_puts(m, "\n\n");
   2938  1.3  riastrad 
   2939  1.3  riastrad 	if (to_intel_crtc_state(intel_crtc->base.state)->has_drrs) {
   2940  1.3  riastrad 		struct intel_panel *panel;
   2941  1.3  riastrad 
   2942  1.3  riastrad 		mutex_lock(&drrs->mutex);
   2943  1.3  riastrad 		/* DRRS Supported */
   2944  1.3  riastrad 		seq_puts(m, "\tDRRS Supported: Yes\n");
   2945  1.3  riastrad 
   2946  1.3  riastrad 		/* disable_drrs() will make drrs->dp NULL */
   2947  1.3  riastrad 		if (!drrs->dp) {
   2948  1.5  riastrad 			seq_puts(m, "Idleness DRRS: Disabled\n");
   2949  1.5  riastrad 			if (dev_priv->psr.enabled)
   2950  1.5  riastrad 				seq_puts(m,
   2951  1.5  riastrad 				"\tAs PSR is enabled, DRRS is not enabled\n");
   2952  1.3  riastrad 			mutex_unlock(&drrs->mutex);
   2953  1.3  riastrad 			return;
   2954  1.3  riastrad 		}
   2955  1.3  riastrad 
   2956  1.3  riastrad 		panel = &drrs->dp->attached_connector->panel;
   2957  1.3  riastrad 		seq_printf(m, "\t\tBusy_frontbuffer_bits: 0x%X",
   2958  1.3  riastrad 					drrs->busy_frontbuffer_bits);
   2959  1.3  riastrad 
   2960  1.3  riastrad 		seq_puts(m, "\n\t\t");
   2961  1.3  riastrad 		if (drrs->refresh_rate_type == DRRS_HIGH_RR) {
   2962  1.3  riastrad 			seq_puts(m, "DRRS_State: DRRS_HIGH_RR\n");
   2963  1.3  riastrad 			vrefresh = panel->fixed_mode->vrefresh;
   2964  1.3  riastrad 		} else if (drrs->refresh_rate_type == DRRS_LOW_RR) {
   2965  1.3  riastrad 			seq_puts(m, "DRRS_State: DRRS_LOW_RR\n");
   2966  1.3  riastrad 			vrefresh = panel->downclock_mode->vrefresh;
   2967  1.3  riastrad 		} else {
   2968  1.3  riastrad 			seq_printf(m, "DRRS_State: Unknown(%d)\n",
   2969  1.3  riastrad 						drrs->refresh_rate_type);
   2970  1.3  riastrad 			mutex_unlock(&drrs->mutex);
   2971  1.3  riastrad 			return;
   2972  1.3  riastrad 		}
   2973  1.3  riastrad 		seq_printf(m, "\t\tVrefresh: %d", vrefresh);
   2974  1.3  riastrad 
   2975  1.3  riastrad 		seq_puts(m, "\n\t\t");
   2976  1.3  riastrad 		mutex_unlock(&drrs->mutex);
   2977  1.3  riastrad 	} else {
   2978  1.3  riastrad 		/* DRRS not supported. Print the VBT parameter*/
   2979  1.3  riastrad 		seq_puts(m, "\tDRRS Supported : No");
   2980  1.3  riastrad 	}
   2981  1.3  riastrad 	seq_puts(m, "\n");
   2982  1.3  riastrad }
   2983  1.3  riastrad 
   2984  1.3  riastrad static int i915_drrs_status(struct seq_file *m, void *unused)
   2985  1.3  riastrad {
   2986  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   2987  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   2988  1.3  riastrad 	struct intel_crtc *intel_crtc;
   2989  1.3  riastrad 	int active_crtc_cnt = 0;
   2990  1.3  riastrad 
   2991  1.5  riastrad 	drm_modeset_lock_all(dev);
   2992  1.3  riastrad 	for_each_intel_crtc(dev, intel_crtc) {
   2993  1.3  riastrad 		if (intel_crtc->base.state->active) {
   2994  1.3  riastrad 			active_crtc_cnt++;
   2995  1.3  riastrad 			seq_printf(m, "\nCRTC %d:  ", active_crtc_cnt);
   2996  1.3  riastrad 
   2997  1.3  riastrad 			drrs_status_per_crtc(m, dev, intel_crtc);
   2998  1.3  riastrad 		}
   2999  1.3  riastrad 	}
   3000  1.5  riastrad 	drm_modeset_unlock_all(dev);
   3001  1.3  riastrad 
   3002  1.3  riastrad 	if (!active_crtc_cnt)
   3003  1.3  riastrad 		seq_puts(m, "No active crtc found\n");
   3004  1.3  riastrad 
   3005  1.3  riastrad 	return 0;
   3006  1.3  riastrad }
   3007  1.3  riastrad 
   3008  1.3  riastrad static int i915_dp_mst_info(struct seq_file *m, void *unused)
   3009  1.3  riastrad {
   3010  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   3011  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   3012  1.3  riastrad 	struct intel_encoder *intel_encoder;
   3013  1.3  riastrad 	struct intel_digital_port *intel_dig_port;
   3014  1.5  riastrad 	struct drm_connector *connector;
   3015  1.5  riastrad 	struct drm_connector_list_iter conn_iter;
   3016  1.5  riastrad 
   3017  1.5  riastrad 	drm_connector_list_iter_begin(dev, &conn_iter);
   3018  1.5  riastrad 	drm_for_each_connector_iter(connector, &conn_iter) {
   3019  1.5  riastrad 		if (connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort)
   3020  1.5  riastrad 			continue;
   3021  1.5  riastrad 
   3022  1.5  riastrad 		intel_encoder = intel_attached_encoder(to_intel_connector(connector));
   3023  1.5  riastrad 		if (!intel_encoder || intel_encoder->type == INTEL_OUTPUT_DP_MST)
   3024  1.3  riastrad 			continue;
   3025  1.5  riastrad 
   3026  1.5  riastrad 		intel_dig_port = enc_to_dig_port(intel_encoder);
   3027  1.3  riastrad 		if (!intel_dig_port->dp.can_mst)
   3028  1.3  riastrad 			continue;
   3029  1.3  riastrad 
   3030  1.5  riastrad 		seq_printf(m, "MST Source Port [ENCODER:%d:%s]\n",
   3031  1.5  riastrad 			   intel_dig_port->base.base.base.id,
   3032  1.5  riastrad 			   intel_dig_port->base.base.name);
   3033  1.3  riastrad 		drm_dp_mst_dump_topology(m, &intel_dig_port->dp.mst_mgr);
   3034  1.3  riastrad 	}
   3035  1.5  riastrad 	drm_connector_list_iter_end(&conn_iter);
   3036  1.5  riastrad 
   3037  1.3  riastrad 	return 0;
   3038  1.3  riastrad }
   3039  1.3  riastrad 
   3040  1.5  riastrad static ssize_t i915_displayport_test_active_write(struct file *file,
   3041  1.5  riastrad 						  const char __user *ubuf,
   3042  1.5  riastrad 						  size_t len, loff_t *offp)
   3043  1.2      matt {
   3044  1.5  riastrad 	char *input_buffer;
   3045  1.5  riastrad 	int status = 0;
   3046  1.5  riastrad 	struct drm_device *dev;
   3047  1.5  riastrad 	struct drm_connector *connector;
   3048  1.5  riastrad 	struct drm_connector_list_iter conn_iter;
   3049  1.5  riastrad 	struct intel_dp *intel_dp;
   3050  1.5  riastrad 	int val = 0;
   3051  1.2      matt 
   3052  1.5  riastrad 	dev = ((struct seq_file *)file->private_data)->private;
   3053  1.2      matt 
   3054  1.5  riastrad 	if (len == 0)
   3055  1.5  riastrad 		return 0;
   3056  1.2      matt 
   3057  1.5  riastrad 	input_buffer = memdup_user_nul(ubuf, len);
   3058  1.5  riastrad 	if (IS_ERR(input_buffer))
   3059  1.5  riastrad 		return PTR_ERR(input_buffer);
   3060  1.2      matt 
   3061  1.5  riastrad 	DRM_DEBUG_DRIVER("Copied %d bytes from user\n", (unsigned int)len);
   3062  1.2      matt 
   3063  1.5  riastrad 	drm_connector_list_iter_begin(dev, &conn_iter);
   3064  1.5  riastrad 	drm_for_each_connector_iter(connector, &conn_iter) {
   3065  1.5  riastrad 		struct intel_encoder *encoder;
   3066  1.2      matt 
   3067  1.5  riastrad 		if (connector->connector_type !=
   3068  1.5  riastrad 		    DRM_MODE_CONNECTOR_DisplayPort)
   3069  1.5  riastrad 			continue;
   3070  1.2      matt 
   3071  1.5  riastrad 		encoder = to_intel_encoder(connector->encoder);
   3072  1.5  riastrad 		if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
   3073  1.5  riastrad 			continue;
   3074  1.2      matt 
   3075  1.5  riastrad 		if (encoder && connector->status == connector_status_connected) {
   3076  1.5  riastrad 			intel_dp = enc_to_intel_dp(encoder);
   3077  1.5  riastrad 			status = kstrtoint(input_buffer, 10, &val);
   3078  1.5  riastrad 			if (status < 0)
   3079  1.5  riastrad 				break;
   3080  1.5  riastrad 			DRM_DEBUG_DRIVER("Got %d for test active\n", val);
   3081  1.5  riastrad 			/* To prevent erroneous activation of the compliance
   3082  1.5  riastrad 			 * testing code, only accept an actual value of 1 here
   3083  1.5  riastrad 			 */
   3084  1.5  riastrad 			if (val == 1)
   3085  1.5  riastrad 				intel_dp->compliance.test_active = true;
   3086  1.5  riastrad 			else
   3087  1.5  riastrad 				intel_dp->compliance.test_active = false;
   3088  1.5  riastrad 		}
   3089  1.5  riastrad 	}
   3090  1.5  riastrad 	drm_connector_list_iter_end(&conn_iter);
   3091  1.5  riastrad 	kfree(input_buffer);
   3092  1.3  riastrad 	if (status < 0)
   3093  1.3  riastrad 		return status;
   3094  1.3  riastrad 
   3095  1.3  riastrad 	*offp += len;
   3096  1.3  riastrad 	return len;
   3097  1.3  riastrad }
   3098  1.3  riastrad 
   3099  1.3  riastrad static int i915_displayport_test_active_show(struct seq_file *m, void *data)
   3100  1.3  riastrad {
   3101  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3102  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   3103  1.3  riastrad 	struct drm_connector *connector;
   3104  1.5  riastrad 	struct drm_connector_list_iter conn_iter;
   3105  1.3  riastrad 	struct intel_dp *intel_dp;
   3106  1.3  riastrad 
   3107  1.5  riastrad 	drm_connector_list_iter_begin(dev, &conn_iter);
   3108  1.5  riastrad 	drm_for_each_connector_iter(connector, &conn_iter) {
   3109  1.5  riastrad 		struct intel_encoder *encoder;
   3110  1.3  riastrad 
   3111  1.3  riastrad 		if (connector->connector_type !=
   3112  1.3  riastrad 		    DRM_MODE_CONNECTOR_DisplayPort)
   3113  1.3  riastrad 			continue;
   3114  1.3  riastrad 
   3115  1.5  riastrad 		encoder = to_intel_encoder(connector->encoder);
   3116  1.5  riastrad 		if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
   3117  1.5  riastrad 			continue;
   3118  1.5  riastrad 
   3119  1.5  riastrad 		if (encoder && connector->status == connector_status_connected) {
   3120  1.5  riastrad 			intel_dp = enc_to_intel_dp(encoder);
   3121  1.5  riastrad 			if (intel_dp->compliance.test_active)
   3122  1.3  riastrad 				seq_puts(m, "1");
   3123  1.3  riastrad 			else
   3124  1.3  riastrad 				seq_puts(m, "0");
   3125  1.3  riastrad 		} else
   3126  1.3  riastrad 			seq_puts(m, "0");
   3127  1.3  riastrad 	}
   3128  1.5  riastrad 	drm_connector_list_iter_end(&conn_iter);
   3129  1.3  riastrad 
   3130  1.3  riastrad 	return 0;
   3131  1.3  riastrad }
   3132  1.3  riastrad 
   3133  1.3  riastrad static int i915_displayport_test_active_open(struct inode *inode,
   3134  1.5  riastrad 					     struct file *file)
   3135  1.3  riastrad {
   3136  1.5  riastrad 	return single_open(file, i915_displayport_test_active_show,
   3137  1.5  riastrad 			   inode->i_private);
   3138  1.3  riastrad }
   3139  1.3  riastrad 
   3140  1.3  riastrad static const struct file_operations i915_displayport_test_active_fops = {
   3141  1.3  riastrad 	.owner = THIS_MODULE,
   3142  1.3  riastrad 	.open = i915_displayport_test_active_open,
   3143  1.3  riastrad 	.read = seq_read,
   3144  1.3  riastrad 	.llseek = seq_lseek,
   3145  1.3  riastrad 	.release = single_release,
   3146  1.3  riastrad 	.write = i915_displayport_test_active_write
   3147  1.3  riastrad };
   3148  1.3  riastrad 
   3149  1.3  riastrad static int i915_displayport_test_data_show(struct seq_file *m, void *data)
   3150  1.3  riastrad {
   3151  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3152  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   3153  1.3  riastrad 	struct drm_connector *connector;
   3154  1.5  riastrad 	struct drm_connector_list_iter conn_iter;
   3155  1.3  riastrad 	struct intel_dp *intel_dp;
   3156  1.3  riastrad 
   3157  1.5  riastrad 	drm_connector_list_iter_begin(dev, &conn_iter);
   3158  1.5  riastrad 	drm_for_each_connector_iter(connector, &conn_iter) {
   3159  1.5  riastrad 		struct intel_encoder *encoder;
   3160  1.3  riastrad 
   3161  1.3  riastrad 		if (connector->connector_type !=
   3162  1.3  riastrad 		    DRM_MODE_CONNECTOR_DisplayPort)
   3163  1.3  riastrad 			continue;
   3164  1.3  riastrad 
   3165  1.5  riastrad 		encoder = to_intel_encoder(connector->encoder);
   3166  1.5  riastrad 		if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
   3167  1.5  riastrad 			continue;
   3168  1.5  riastrad 
   3169  1.5  riastrad 		if (encoder && connector->status == connector_status_connected) {
   3170  1.5  riastrad 			intel_dp = enc_to_intel_dp(encoder);
   3171  1.5  riastrad 			if (intel_dp->compliance.test_type ==
   3172  1.5  riastrad 			    DP_TEST_LINK_EDID_READ)
   3173  1.5  riastrad 				seq_printf(m, "%lx",
   3174  1.5  riastrad 					   intel_dp->compliance.test_data.edid);
   3175  1.5  riastrad 			else if (intel_dp->compliance.test_type ==
   3176  1.5  riastrad 				 DP_TEST_LINK_VIDEO_PATTERN) {
   3177  1.5  riastrad 				seq_printf(m, "hdisplay: %d\n",
   3178  1.5  riastrad 					   intel_dp->compliance.test_data.hdisplay);
   3179  1.5  riastrad 				seq_printf(m, "vdisplay: %d\n",
   3180  1.5  riastrad 					   intel_dp->compliance.test_data.vdisplay);
   3181  1.5  riastrad 				seq_printf(m, "bpc: %u\n",
   3182  1.5  riastrad 					   intel_dp->compliance.test_data.bpc);
   3183  1.5  riastrad 			}
   3184  1.3  riastrad 		} else
   3185  1.3  riastrad 			seq_puts(m, "0");
   3186  1.3  riastrad 	}
   3187  1.5  riastrad 	drm_connector_list_iter_end(&conn_iter);
   3188  1.3  riastrad 
   3189  1.3  riastrad 	return 0;
   3190  1.3  riastrad }
   3191  1.5  riastrad DEFINE_SHOW_ATTRIBUTE(i915_displayport_test_data);
   3192  1.3  riastrad 
   3193  1.3  riastrad static int i915_displayport_test_type_show(struct seq_file *m, void *data)
   3194  1.3  riastrad {
   3195  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3196  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   3197  1.3  riastrad 	struct drm_connector *connector;
   3198  1.5  riastrad 	struct drm_connector_list_iter conn_iter;
   3199  1.3  riastrad 	struct intel_dp *intel_dp;
   3200  1.3  riastrad 
   3201  1.5  riastrad 	drm_connector_list_iter_begin(dev, &conn_iter);
   3202  1.5  riastrad 	drm_for_each_connector_iter(connector, &conn_iter) {
   3203  1.5  riastrad 		struct intel_encoder *encoder;
   3204  1.3  riastrad 
   3205  1.3  riastrad 		if (connector->connector_type !=
   3206  1.3  riastrad 		    DRM_MODE_CONNECTOR_DisplayPort)
   3207  1.3  riastrad 			continue;
   3208  1.3  riastrad 
   3209  1.5  riastrad 		encoder = to_intel_encoder(connector->encoder);
   3210  1.5  riastrad 		if (encoder && encoder->type == INTEL_OUTPUT_DP_MST)
   3211  1.5  riastrad 			continue;
   3212  1.5  riastrad 
   3213  1.5  riastrad 		if (encoder && connector->status == connector_status_connected) {
   3214  1.5  riastrad 			intel_dp = enc_to_intel_dp(encoder);
   3215  1.5  riastrad 			seq_printf(m, "%02lx", intel_dp->compliance.test_type);
   3216  1.3  riastrad 		} else
   3217  1.3  riastrad 			seq_puts(m, "0");
   3218  1.3  riastrad 	}
   3219  1.5  riastrad 	drm_connector_list_iter_end(&conn_iter);
   3220  1.3  riastrad 
   3221  1.3  riastrad 	return 0;
   3222  1.3  riastrad }
   3223  1.5  riastrad DEFINE_SHOW_ATTRIBUTE(i915_displayport_test_type);
   3224  1.3  riastrad 
   3225  1.5  riastrad static void wm_latency_show(struct seq_file *m, const u16 wm[8])
   3226  1.2      matt {
   3227  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3228  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   3229  1.2      matt 	int level;
   3230  1.3  riastrad 	int num_levels;
   3231  1.3  riastrad 
   3232  1.5  riastrad 	if (IS_CHERRYVIEW(dev_priv))
   3233  1.3  riastrad 		num_levels = 3;
   3234  1.5  riastrad 	else if (IS_VALLEYVIEW(dev_priv))
   3235  1.3  riastrad 		num_levels = 1;
   3236  1.5  riastrad 	else if (IS_G4X(dev_priv))
   3237  1.5  riastrad 		num_levels = 3;
   3238  1.3  riastrad 	else
   3239  1.5  riastrad 		num_levels = ilk_wm_max_level(dev_priv) + 1;
   3240  1.2      matt 
   3241  1.2      matt 	drm_modeset_lock_all(dev);
   3242  1.2      matt 
   3243  1.2      matt 	for (level = 0; level < num_levels; level++) {
   3244  1.2      matt 		unsigned int latency = wm[level];
   3245  1.2      matt 
   3246  1.3  riastrad 		/*
   3247  1.3  riastrad 		 * - WM1+ latency values in 0.5us units
   3248  1.3  riastrad 		 * - latencies are in us on gen9/vlv/chv
   3249  1.3  riastrad 		 */
   3250  1.5  riastrad 		if (INTEL_GEN(dev_priv) >= 9 ||
   3251  1.5  riastrad 		    IS_VALLEYVIEW(dev_priv) ||
   3252  1.5  riastrad 		    IS_CHERRYVIEW(dev_priv) ||
   3253  1.5  riastrad 		    IS_G4X(dev_priv))
   3254  1.3  riastrad 			latency *= 10;
   3255  1.3  riastrad 		else if (level > 0)
   3256  1.2      matt 			latency *= 5;
   3257  1.2      matt 
   3258  1.2      matt 		seq_printf(m, "WM%d %u (%u.%u usec)\n",
   3259  1.3  riastrad 			   level, wm[level], latency / 10, latency % 10);
   3260  1.2      matt 	}
   3261  1.2      matt 
   3262  1.2      matt 	drm_modeset_unlock_all(dev);
   3263  1.2      matt }
   3264  1.2      matt 
   3265  1.2      matt static int pri_wm_latency_show(struct seq_file *m, void *data)
   3266  1.2      matt {
   3267  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3268  1.5  riastrad 	const u16 *latencies;
   3269  1.3  riastrad 
   3270  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 9)
   3271  1.3  riastrad 		latencies = dev_priv->wm.skl_latency;
   3272  1.3  riastrad 	else
   3273  1.5  riastrad 		latencies = dev_priv->wm.pri_latency;
   3274  1.2      matt 
   3275  1.3  riastrad 	wm_latency_show(m, latencies);
   3276  1.2      matt 
   3277  1.2      matt 	return 0;
   3278  1.2      matt }
   3279  1.2      matt 
   3280  1.2      matt static int spr_wm_latency_show(struct seq_file *m, void *data)
   3281  1.2      matt {
   3282  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3283  1.5  riastrad 	const u16 *latencies;
   3284  1.2      matt 
   3285  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 9)
   3286  1.3  riastrad 		latencies = dev_priv->wm.skl_latency;
   3287  1.3  riastrad 	else
   3288  1.5  riastrad 		latencies = dev_priv->wm.spr_latency;
   3289  1.3  riastrad 
   3290  1.3  riastrad 	wm_latency_show(m, latencies);
   3291  1.2      matt 
   3292  1.2      matt 	return 0;
   3293  1.2      matt }
   3294  1.2      matt 
   3295  1.2      matt static int cur_wm_latency_show(struct seq_file *m, void *data)
   3296  1.2      matt {
   3297  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3298  1.5  riastrad 	const u16 *latencies;
   3299  1.3  riastrad 
   3300  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 9)
   3301  1.3  riastrad 		latencies = dev_priv->wm.skl_latency;
   3302  1.3  riastrad 	else
   3303  1.5  riastrad 		latencies = dev_priv->wm.cur_latency;
   3304  1.2      matt 
   3305  1.3  riastrad 	wm_latency_show(m, latencies);
   3306  1.2      matt 
   3307  1.2      matt 	return 0;
   3308  1.2      matt }
   3309  1.2      matt 
   3310  1.2      matt static int pri_wm_latency_open(struct inode *inode, struct file *file)
   3311  1.2      matt {
   3312  1.5  riastrad 	struct drm_i915_private *dev_priv = inode->i_private;
   3313  1.2      matt 
   3314  1.5  riastrad 	if (INTEL_GEN(dev_priv) < 5 && !IS_G4X(dev_priv))
   3315  1.2      matt 		return -ENODEV;
   3316  1.2      matt 
   3317  1.5  riastrad 	return single_open(file, pri_wm_latency_show, dev_priv);
   3318  1.2      matt }
   3319  1.2      matt 
   3320  1.2      matt static int spr_wm_latency_open(struct inode *inode, struct file *file)
   3321  1.2      matt {
   3322  1.5  riastrad 	struct drm_i915_private *dev_priv = inode->i_private;
   3323  1.2      matt 
   3324  1.5  riastrad 	if (HAS_GMCH(dev_priv))
   3325  1.2      matt 		return -ENODEV;
   3326  1.2      matt 
   3327  1.5  riastrad 	return single_open(file, spr_wm_latency_show, dev_priv);
   3328  1.2      matt }
   3329  1.2      matt 
   3330  1.2      matt static int cur_wm_latency_open(struct inode *inode, struct file *file)
   3331  1.2      matt {
   3332  1.5  riastrad 	struct drm_i915_private *dev_priv = inode->i_private;
   3333  1.2      matt 
   3334  1.5  riastrad 	if (HAS_GMCH(dev_priv))
   3335  1.2      matt 		return -ENODEV;
   3336  1.2      matt 
   3337  1.5  riastrad 	return single_open(file, cur_wm_latency_show, dev_priv);
   3338  1.2      matt }
   3339  1.2      matt 
   3340  1.2      matt static ssize_t wm_latency_write(struct file *file, const char __user *ubuf,
   3341  1.5  riastrad 				size_t len, loff_t *offp, u16 wm[8])
   3342  1.2      matt {
   3343  1.2      matt 	struct seq_file *m = file->private_data;
   3344  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3345  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   3346  1.5  riastrad 	u16 new[8] = { 0 };
   3347  1.3  riastrad 	int num_levels;
   3348  1.2      matt 	int level;
   3349  1.2      matt 	int ret;
   3350  1.2      matt 	char tmp[32];
   3351  1.2      matt 
   3352  1.5  riastrad 	if (IS_CHERRYVIEW(dev_priv))
   3353  1.3  riastrad 		num_levels = 3;
   3354  1.5  riastrad 	else if (IS_VALLEYVIEW(dev_priv))
   3355  1.3  riastrad 		num_levels = 1;
   3356  1.5  riastrad 	else if (IS_G4X(dev_priv))
   3357  1.5  riastrad 		num_levels = 3;
   3358  1.3  riastrad 	else
   3359  1.5  riastrad 		num_levels = ilk_wm_max_level(dev_priv) + 1;
   3360  1.3  riastrad 
   3361  1.2      matt 	if (len >= sizeof(tmp))
   3362  1.2      matt 		return -EINVAL;
   3363  1.2      matt 
   3364  1.2      matt 	if (copy_from_user(tmp, ubuf, len))
   3365  1.2      matt 		return -EFAULT;
   3366  1.2      matt 
   3367  1.2      matt 	tmp[len] = '\0';
   3368  1.2      matt 
   3369  1.3  riastrad 	ret = sscanf(tmp, "%hu %hu %hu %hu %hu %hu %hu %hu",
   3370  1.3  riastrad 		     &new[0], &new[1], &new[2], &new[3],
   3371  1.3  riastrad 		     &new[4], &new[5], &new[6], &new[7]);
   3372  1.2      matt 	if (ret != num_levels)
   3373  1.2      matt 		return -EINVAL;
   3374  1.2      matt 
   3375  1.2      matt 	drm_modeset_lock_all(dev);
   3376  1.2      matt 
   3377  1.2      matt 	for (level = 0; level < num_levels; level++)
   3378  1.2      matt 		wm[level] = new[level];
   3379  1.2      matt 
   3380  1.2      matt 	drm_modeset_unlock_all(dev);
   3381  1.2      matt 
   3382  1.2      matt 	return len;
   3383  1.2      matt }
   3384  1.2      matt 
   3385  1.2      matt 
   3386  1.2      matt static ssize_t pri_wm_latency_write(struct file *file, const char __user *ubuf,
   3387  1.2      matt 				    size_t len, loff_t *offp)
   3388  1.2      matt {
   3389  1.2      matt 	struct seq_file *m = file->private_data;
   3390  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3391  1.5  riastrad 	u16 *latencies;
   3392  1.3  riastrad 
   3393  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 9)
   3394  1.3  riastrad 		latencies = dev_priv->wm.skl_latency;
   3395  1.3  riastrad 	else
   3396  1.5  riastrad 		latencies = dev_priv->wm.pri_latency;
   3397  1.2      matt 
   3398  1.3  riastrad 	return wm_latency_write(file, ubuf, len, offp, latencies);
   3399  1.2      matt }
   3400  1.2      matt 
   3401  1.2      matt static ssize_t spr_wm_latency_write(struct file *file, const char __user *ubuf,
   3402  1.2      matt 				    size_t len, loff_t *offp)
   3403  1.2      matt {
   3404  1.2      matt 	struct seq_file *m = file->private_data;
   3405  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3406  1.5  riastrad 	u16 *latencies;
   3407  1.2      matt 
   3408  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 9)
   3409  1.3  riastrad 		latencies = dev_priv->wm.skl_latency;
   3410  1.3  riastrad 	else
   3411  1.5  riastrad 		latencies = dev_priv->wm.spr_latency;
   3412  1.3  riastrad 
   3413  1.3  riastrad 	return wm_latency_write(file, ubuf, len, offp, latencies);
   3414  1.2      matt }
   3415  1.2      matt 
   3416  1.2      matt static ssize_t cur_wm_latency_write(struct file *file, const char __user *ubuf,
   3417  1.2      matt 				    size_t len, loff_t *offp)
   3418  1.2      matt {
   3419  1.2      matt 	struct seq_file *m = file->private_data;
   3420  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3421  1.5  riastrad 	u16 *latencies;
   3422  1.3  riastrad 
   3423  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 9)
   3424  1.3  riastrad 		latencies = dev_priv->wm.skl_latency;
   3425  1.3  riastrad 	else
   3426  1.5  riastrad 		latencies = dev_priv->wm.cur_latency;
   3427  1.2      matt 
   3428  1.3  riastrad 	return wm_latency_write(file, ubuf, len, offp, latencies);
   3429  1.2      matt }
   3430  1.2      matt 
   3431  1.2      matt static const struct file_operations i915_pri_wm_latency_fops = {
   3432  1.2      matt 	.owner = THIS_MODULE,
   3433  1.2      matt 	.open = pri_wm_latency_open,
   3434  1.2      matt 	.read = seq_read,
   3435  1.2      matt 	.llseek = seq_lseek,
   3436  1.2      matt 	.release = single_release,
   3437  1.2      matt 	.write = pri_wm_latency_write
   3438  1.2      matt };
   3439  1.2      matt 
   3440  1.2      matt static const struct file_operations i915_spr_wm_latency_fops = {
   3441  1.2      matt 	.owner = THIS_MODULE,
   3442  1.2      matt 	.open = spr_wm_latency_open,
   3443  1.2      matt 	.read = seq_read,
   3444  1.2      matt 	.llseek = seq_lseek,
   3445  1.2      matt 	.release = single_release,
   3446  1.2      matt 	.write = spr_wm_latency_write
   3447  1.2      matt };
   3448  1.2      matt 
   3449  1.2      matt static const struct file_operations i915_cur_wm_latency_fops = {
   3450  1.2      matt 	.owner = THIS_MODULE,
   3451  1.2      matt 	.open = cur_wm_latency_open,
   3452  1.2      matt 	.read = seq_read,
   3453  1.2      matt 	.llseek = seq_lseek,
   3454  1.2      matt 	.release = single_release,
   3455  1.2      matt 	.write = cur_wm_latency_write
   3456  1.2      matt };
   3457  1.2      matt 
   3458  1.2      matt static int
   3459  1.2      matt i915_wedged_get(void *data, u64 *val)
   3460  1.2      matt {
   3461  1.5  riastrad 	struct drm_i915_private *i915 = data;
   3462  1.5  riastrad 	int ret = intel_gt_terminally_wedged(&i915->gt);
   3463  1.2      matt 
   3464  1.5  riastrad 	switch (ret) {
   3465  1.5  riastrad 	case -EIO:
   3466  1.5  riastrad 		*val = 1;
   3467  1.5  riastrad 		return 0;
   3468  1.5  riastrad 	case 0:
   3469  1.5  riastrad 		*val = 0;
   3470  1.5  riastrad 		return 0;
   3471  1.5  riastrad 	default:
   3472  1.5  riastrad 		return ret;
   3473  1.5  riastrad 	}
   3474  1.2      matt }
   3475  1.2      matt 
   3476  1.2      matt static int
   3477  1.2      matt i915_wedged_set(void *data, u64 val)
   3478  1.2      matt {
   3479  1.5  riastrad 	struct drm_i915_private *i915 = data;
   3480  1.3  riastrad 
   3481  1.5  riastrad 	/* Flush any previous reset before applying for a new one */
   3482  1.5  riastrad 	wait_event(i915->gt.reset.queue,
   3483  1.5  riastrad 		   !test_bit(I915_RESET_BACKOFF, &i915->gt.reset.flags));
   3484  1.3  riastrad 
   3485  1.5  riastrad 	intel_gt_handle_error(&i915->gt, val, I915_ERROR_CAPTURE,
   3486  1.5  riastrad 			      "Manually set wedged engine mask = %llx", val);
   3487  1.2      matt 	return 0;
   3488  1.2      matt }
   3489  1.2      matt 
   3490  1.2      matt DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
   3491  1.2      matt 			i915_wedged_get, i915_wedged_set,
   3492  1.2      matt 			"%llu\n");
   3493  1.2      matt 
   3494  1.2      matt static int
   3495  1.5  riastrad i915_perf_noa_delay_set(void *data, u64 val)
   3496  1.2      matt {
   3497  1.5  riastrad 	struct drm_i915_private *i915 = data;
   3498  1.5  riastrad 	const u32 clk = RUNTIME_INFO(i915)->cs_timestamp_frequency_khz;
   3499  1.2      matt 
   3500  1.5  riastrad 	/*
   3501  1.5  riastrad 	 * This would lead to infinite waits as we're doing timestamp
   3502  1.5  riastrad 	 * difference on the CS with only 32bits.
   3503  1.5  riastrad 	 */
   3504  1.5  riastrad 	if (val > mul_u32_u32(U32_MAX, clk))
   3505  1.5  riastrad 		return -EINVAL;
   3506  1.2      matt 
   3507  1.5  riastrad 	atomic64_set(&i915->perf.noa_programming_delay, val);
   3508  1.2      matt 	return 0;
   3509  1.2      matt }
   3510  1.2      matt 
   3511  1.2      matt static int
   3512  1.5  riastrad i915_perf_noa_delay_get(void *data, u64 *val)
   3513  1.2      matt {
   3514  1.5  riastrad 	struct drm_i915_private *i915 = data;
   3515  1.2      matt 
   3516  1.5  riastrad 	*val = atomic64_read(&i915->perf.noa_programming_delay);
   3517  1.2      matt 	return 0;
   3518  1.2      matt }
   3519  1.2      matt 
   3520  1.5  riastrad DEFINE_SIMPLE_ATTRIBUTE(i915_perf_noa_delay_fops,
   3521  1.5  riastrad 			i915_perf_noa_delay_get,
   3522  1.5  riastrad 			i915_perf_noa_delay_set,
   3523  1.5  riastrad 			"%llu\n");
   3524  1.2      matt 
   3525  1.5  riastrad #define DROP_UNBOUND	BIT(0)
   3526  1.5  riastrad #define DROP_BOUND	BIT(1)
   3527  1.5  riastrad #define DROP_RETIRE	BIT(2)
   3528  1.5  riastrad #define DROP_ACTIVE	BIT(3)
   3529  1.5  riastrad #define DROP_FREED	BIT(4)
   3530  1.5  riastrad #define DROP_SHRINK_ALL	BIT(5)
   3531  1.5  riastrad #define DROP_IDLE	BIT(6)
   3532  1.5  riastrad #define DROP_RESET_ACTIVE	BIT(7)
   3533  1.5  riastrad #define DROP_RESET_SEQNO	BIT(8)
   3534  1.5  riastrad #define DROP_RCU	BIT(9)
   3535  1.5  riastrad #define DROP_ALL (DROP_UNBOUND	| \
   3536  1.5  riastrad 		  DROP_BOUND	| \
   3537  1.5  riastrad 		  DROP_RETIRE	| \
   3538  1.5  riastrad 		  DROP_ACTIVE	| \
   3539  1.5  riastrad 		  DROP_FREED	| \
   3540  1.5  riastrad 		  DROP_SHRINK_ALL |\
   3541  1.5  riastrad 		  DROP_IDLE	| \
   3542  1.5  riastrad 		  DROP_RESET_ACTIVE | \
   3543  1.5  riastrad 		  DROP_RESET_SEQNO | \
   3544  1.5  riastrad 		  DROP_RCU)
   3545  1.2      matt static int
   3546  1.5  riastrad i915_drop_caches_get(void *data, u64 *val)
   3547  1.2      matt {
   3548  1.5  riastrad 	*val = DROP_ALL;
   3549  1.2      matt 
   3550  1.2      matt 	return 0;
   3551  1.2      matt }
   3552  1.2      matt static int
   3553  1.5  riastrad gt_drop_caches(struct intel_gt *gt, u64 val)
   3554  1.2      matt {
   3555  1.2      matt 	int ret;
   3556  1.2      matt 
   3557  1.5  riastrad 	if (val & DROP_RESET_ACTIVE &&
   3558  1.5  riastrad 	    wait_for(intel_engines_are_idle(gt), I915_IDLE_ENGINES_TIMEOUT))
   3559  1.5  riastrad 		intel_gt_set_wedged(gt);
   3560  1.2      matt 
   3561  1.5  riastrad 	if (val & DROP_RETIRE)
   3562  1.5  riastrad 		intel_gt_retire_requests(gt);
   3563  1.2      matt 
   3564  1.5  riastrad 	if (val & (DROP_IDLE | DROP_ACTIVE)) {
   3565  1.5  riastrad 		ret = intel_gt_wait_for_idle(gt, MAX_SCHEDULE_TIMEOUT);
   3566  1.5  riastrad 		if (ret)
   3567  1.5  riastrad 			return ret;
   3568  1.5  riastrad 	}
   3569  1.2      matt 
   3570  1.5  riastrad 	if (val & DROP_IDLE) {
   3571  1.5  riastrad 		ret = intel_gt_pm_wait_for_idle(gt);
   3572  1.5  riastrad 		if (ret)
   3573  1.5  riastrad 			return ret;
   3574  1.5  riastrad 	}
   3575  1.2      matt 
   3576  1.5  riastrad 	if (val & DROP_RESET_ACTIVE && intel_gt_terminally_wedged(gt))
   3577  1.5  riastrad 		intel_gt_handle_error(gt, ALL_ENGINES, 0, NULL);
   3578  1.2      matt 
   3579  1.2      matt 	return 0;
   3580  1.2      matt }
   3581  1.2      matt 
   3582  1.2      matt static int
   3583  1.5  riastrad i915_drop_caches_set(void *data, u64 val)
   3584  1.2      matt {
   3585  1.5  riastrad 	struct drm_i915_private *i915 = data;
   3586  1.2      matt 	int ret;
   3587  1.2      matt 
   3588  1.5  riastrad 	DRM_DEBUG("Dropping caches: 0x%08llx [0x%08llx]\n",
   3589  1.5  riastrad 		  val, val & DROP_ALL);
   3590  1.2      matt 
   3591  1.5  riastrad 	ret = gt_drop_caches(&i915->gt, val);
   3592  1.2      matt 	if (ret)
   3593  1.2      matt 		return ret;
   3594  1.2      matt 
   3595  1.5  riastrad 	fs_reclaim_acquire(GFP_KERNEL);
   3596  1.5  riastrad 	if (val & DROP_BOUND)
   3597  1.5  riastrad 		i915_gem_shrink(i915, LONG_MAX, NULL, I915_SHRINK_BOUND);
   3598  1.5  riastrad 
   3599  1.5  riastrad 	if (val & DROP_UNBOUND)
   3600  1.5  riastrad 		i915_gem_shrink(i915, LONG_MAX, NULL, I915_SHRINK_UNBOUND);
   3601  1.5  riastrad 
   3602  1.5  riastrad 	if (val & DROP_SHRINK_ALL)
   3603  1.5  riastrad 		i915_gem_shrink_all(i915);
   3604  1.5  riastrad 	fs_reclaim_release(GFP_KERNEL);
   3605  1.5  riastrad 
   3606  1.5  riastrad 	if (val & DROP_RCU)
   3607  1.5  riastrad 		rcu_barrier();
   3608  1.5  riastrad 
   3609  1.5  riastrad 	if (val & DROP_FREED)
   3610  1.5  riastrad 		i915_gem_drain_freed_objects(i915);
   3611  1.2      matt 
   3612  1.2      matt 	return 0;
   3613  1.2      matt }
   3614  1.2      matt 
   3615  1.5  riastrad DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
   3616  1.5  riastrad 			i915_drop_caches_get, i915_drop_caches_set,
   3617  1.2      matt 			"0x%08llx\n");
   3618  1.2      matt 
   3619  1.2      matt static int
   3620  1.5  riastrad i915_cache_sharing_get(void *data, u64 *val)
   3621  1.2      matt {
   3622  1.5  riastrad 	struct drm_i915_private *dev_priv = data;
   3623  1.5  riastrad 	intel_wakeref_t wakeref;
   3624  1.5  riastrad 	u32 snpcr = 0;
   3625  1.5  riastrad 
   3626  1.5  riastrad 	if (!(IS_GEN_RANGE(dev_priv, 6, 7)))
   3627  1.5  riastrad 		return -ENODEV;
   3628  1.5  riastrad 
   3629  1.5  riastrad 	with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref)
   3630  1.5  riastrad 		snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
   3631  1.5  riastrad 
   3632  1.5  riastrad 	*val = (snpcr & GEN6_MBC_SNPCR_MASK) >> GEN6_MBC_SNPCR_SHIFT;
   3633  1.2      matt 
   3634  1.2      matt 	return 0;
   3635  1.2      matt }
   3636  1.2      matt 
   3637  1.2      matt static int
   3638  1.5  riastrad i915_cache_sharing_set(void *data, u64 val)
   3639  1.2      matt {
   3640  1.5  riastrad 	struct drm_i915_private *dev_priv = data;
   3641  1.5  riastrad 	intel_wakeref_t wakeref;
   3642  1.5  riastrad 
   3643  1.5  riastrad 	if (!(IS_GEN_RANGE(dev_priv, 6, 7)))
   3644  1.5  riastrad 		return -ENODEV;
   3645  1.2      matt 
   3646  1.5  riastrad 	if (val > 3)
   3647  1.5  riastrad 		return -EINVAL;
   3648  1.2      matt 
   3649  1.5  riastrad 	DRM_DEBUG_DRIVER("Manually setting uncore sharing to %llu\n", val);
   3650  1.5  riastrad 	with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) {
   3651  1.5  riastrad 		u32 snpcr;
   3652  1.2      matt 
   3653  1.5  riastrad 		/* Update the cache sharing policy here as well */
   3654  1.5  riastrad 		snpcr = I915_READ(GEN6_MBCUNIT_SNPCR);
   3655  1.5  riastrad 		snpcr &= ~GEN6_MBC_SNPCR_MASK;
   3656  1.5  riastrad 		snpcr |= val << GEN6_MBC_SNPCR_SHIFT;
   3657  1.5  riastrad 		I915_WRITE(GEN6_MBCUNIT_SNPCR, snpcr);
   3658  1.2      matt 	}
   3659  1.2      matt 
   3660  1.5  riastrad 	return 0;
   3661  1.5  riastrad }
   3662  1.5  riastrad 
   3663  1.5  riastrad static void
   3664  1.5  riastrad intel_sseu_copy_subslices(const struct sseu_dev_info *sseu, int slice,
   3665  1.5  riastrad 			  u8 *to_mask)
   3666  1.5  riastrad {
   3667  1.5  riastrad 	int offset = slice * sseu->ss_stride;
   3668  1.5  riastrad 
   3669  1.5  riastrad 	memcpy(&to_mask[offset], &sseu->subslice_mask[offset], sseu->ss_stride);
   3670  1.5  riastrad }
   3671  1.5  riastrad 
   3672  1.5  riastrad DEFINE_SIMPLE_ATTRIBUTE(i915_cache_sharing_fops,
   3673  1.5  riastrad 			i915_cache_sharing_get, i915_cache_sharing_set,
   3674  1.5  riastrad 			"%llu\n");
   3675  1.5  riastrad 
   3676  1.5  riastrad static void cherryview_sseu_device_status(struct drm_i915_private *dev_priv,
   3677  1.5  riastrad 					  struct sseu_dev_info *sseu)
   3678  1.5  riastrad {
   3679  1.5  riastrad #define SS_MAX 2
   3680  1.5  riastrad 	const int ss_max = SS_MAX;
   3681  1.5  riastrad 	u32 sig1[SS_MAX], sig2[SS_MAX];
   3682  1.5  riastrad 	int ss;
   3683  1.2      matt 
   3684  1.5  riastrad 	sig1[0] = I915_READ(CHV_POWER_SS0_SIG1);
   3685  1.5  riastrad 	sig1[1] = I915_READ(CHV_POWER_SS1_SIG1);
   3686  1.5  riastrad 	sig2[0] = I915_READ(CHV_POWER_SS0_SIG2);
   3687  1.5  riastrad 	sig2[1] = I915_READ(CHV_POWER_SS1_SIG2);
   3688  1.2      matt 
   3689  1.5  riastrad 	for (ss = 0; ss < ss_max; ss++) {
   3690  1.5  riastrad 		unsigned int eu_cnt;
   3691  1.2      matt 
   3692  1.5  riastrad 		if (sig1[ss] & CHV_SS_PG_ENABLE)
   3693  1.5  riastrad 			/* skip disabled subslice */
   3694  1.5  riastrad 			continue;
   3695  1.2      matt 
   3696  1.5  riastrad 		sseu->slice_mask = BIT(0);
   3697  1.5  riastrad 		sseu->subslice_mask[0] |= BIT(ss);
   3698  1.5  riastrad 		eu_cnt = ((sig1[ss] & CHV_EU08_PG_ENABLE) ? 0 : 2) +
   3699  1.5  riastrad 			 ((sig1[ss] & CHV_EU19_PG_ENABLE) ? 0 : 2) +
   3700  1.5  riastrad 			 ((sig1[ss] & CHV_EU210_PG_ENABLE) ? 0 : 2) +
   3701  1.5  riastrad 			 ((sig2[ss] & CHV_EU311_PG_ENABLE) ? 0 : 2);
   3702  1.5  riastrad 		sseu->eu_total += eu_cnt;
   3703  1.5  riastrad 		sseu->eu_per_subslice = max_t(unsigned int,
   3704  1.5  riastrad 					      sseu->eu_per_subslice, eu_cnt);
   3705  1.5  riastrad 	}
   3706  1.5  riastrad #undef SS_MAX
   3707  1.2      matt }
   3708  1.2      matt 
   3709  1.5  riastrad static void gen10_sseu_device_status(struct drm_i915_private *dev_priv,
   3710  1.5  riastrad 				     struct sseu_dev_info *sseu)
   3711  1.5  riastrad {
   3712  1.5  riastrad #define SS_MAX 6
   3713  1.5  riastrad 	const struct intel_runtime_info *info = RUNTIME_INFO(dev_priv);
   3714  1.5  riastrad 	u32 s_reg[SS_MAX], eu_reg[2 * SS_MAX], eu_mask[2];
   3715  1.5  riastrad 	int s, ss;
   3716  1.5  riastrad 
   3717  1.5  riastrad 	for (s = 0; s < info->sseu.max_slices; s++) {
   3718  1.5  riastrad 		/*
   3719  1.5  riastrad 		 * FIXME: Valid SS Mask respects the spec and read
   3720  1.5  riastrad 		 * only valid bits for those registers, excluding reserved
   3721  1.5  riastrad 		 * although this seems wrong because it would leave many
   3722  1.5  riastrad 		 * subslices without ACK.
   3723  1.5  riastrad 		 */
   3724  1.5  riastrad 		s_reg[s] = I915_READ(GEN10_SLICE_PGCTL_ACK(s)) &
   3725  1.5  riastrad 			GEN10_PGCTL_VALID_SS_MASK(s);
   3726  1.5  riastrad 		eu_reg[2 * s] = I915_READ(GEN10_SS01_EU_PGCTL_ACK(s));
   3727  1.5  riastrad 		eu_reg[2 * s + 1] = I915_READ(GEN10_SS23_EU_PGCTL_ACK(s));
   3728  1.5  riastrad 	}
   3729  1.2      matt 
   3730  1.5  riastrad 	eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
   3731  1.5  riastrad 		     GEN9_PGCTL_SSA_EU19_ACK |
   3732  1.5  riastrad 		     GEN9_PGCTL_SSA_EU210_ACK |
   3733  1.5  riastrad 		     GEN9_PGCTL_SSA_EU311_ACK;
   3734  1.5  riastrad 	eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
   3735  1.5  riastrad 		     GEN9_PGCTL_SSB_EU19_ACK |
   3736  1.5  riastrad 		     GEN9_PGCTL_SSB_EU210_ACK |
   3737  1.5  riastrad 		     GEN9_PGCTL_SSB_EU311_ACK;
   3738  1.2      matt 
   3739  1.5  riastrad 	for (s = 0; s < info->sseu.max_slices; s++) {
   3740  1.5  riastrad 		if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
   3741  1.5  riastrad 			/* skip disabled slice */
   3742  1.5  riastrad 			continue;
   3743  1.2      matt 
   3744  1.5  riastrad 		sseu->slice_mask |= BIT(s);
   3745  1.5  riastrad 		intel_sseu_copy_subslices(&info->sseu, s, sseu->subslice_mask);
   3746  1.2      matt 
   3747  1.5  riastrad 		for (ss = 0; ss < info->sseu.max_subslices; ss++) {
   3748  1.5  riastrad 			unsigned int eu_cnt;
   3749  1.2      matt 
   3750  1.5  riastrad 			if (info->sseu.has_subslice_pg &&
   3751  1.5  riastrad 			    !(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
   3752  1.5  riastrad 				/* skip disabled subslice */
   3753  1.5  riastrad 				continue;
   3754  1.2      matt 
   3755  1.5  riastrad 			eu_cnt = 2 * hweight32(eu_reg[2 * s + ss / 2] &
   3756  1.5  riastrad 					       eu_mask[ss % 2]);
   3757  1.5  riastrad 			sseu->eu_total += eu_cnt;
   3758  1.5  riastrad 			sseu->eu_per_subslice = max_t(unsigned int,
   3759  1.5  riastrad 						      sseu->eu_per_subslice,
   3760  1.5  riastrad 						      eu_cnt);
   3761  1.5  riastrad 		}
   3762  1.5  riastrad 	}
   3763  1.5  riastrad #undef SS_MAX
   3764  1.2      matt }
   3765  1.2      matt 
   3766  1.5  riastrad static void gen9_sseu_device_status(struct drm_i915_private *dev_priv,
   3767  1.5  riastrad 				    struct sseu_dev_info *sseu)
   3768  1.2      matt {
   3769  1.5  riastrad #define SS_MAX 3
   3770  1.5  riastrad 	const struct intel_runtime_info *info = RUNTIME_INFO(dev_priv);
   3771  1.5  riastrad 	u32 s_reg[SS_MAX], eu_reg[2 * SS_MAX], eu_mask[2];
   3772  1.5  riastrad 	int s, ss;
   3773  1.5  riastrad 
   3774  1.5  riastrad 	for (s = 0; s < info->sseu.max_slices; s++) {
   3775  1.5  riastrad 		s_reg[s] = I915_READ(GEN9_SLICE_PGCTL_ACK(s));
   3776  1.5  riastrad 		eu_reg[2*s] = I915_READ(GEN9_SS01_EU_PGCTL_ACK(s));
   3777  1.5  riastrad 		eu_reg[2*s + 1] = I915_READ(GEN9_SS23_EU_PGCTL_ACK(s));
   3778  1.5  riastrad 	}
   3779  1.5  riastrad 
   3780  1.5  riastrad 	eu_mask[0] = GEN9_PGCTL_SSA_EU08_ACK |
   3781  1.5  riastrad 		     GEN9_PGCTL_SSA_EU19_ACK |
   3782  1.5  riastrad 		     GEN9_PGCTL_SSA_EU210_ACK |
   3783  1.5  riastrad 		     GEN9_PGCTL_SSA_EU311_ACK;
   3784  1.5  riastrad 	eu_mask[1] = GEN9_PGCTL_SSB_EU08_ACK |
   3785  1.5  riastrad 		     GEN9_PGCTL_SSB_EU19_ACK |
   3786  1.5  riastrad 		     GEN9_PGCTL_SSB_EU210_ACK |
   3787  1.5  riastrad 		     GEN9_PGCTL_SSB_EU311_ACK;
   3788  1.1  riastrad 
   3789  1.5  riastrad 	for (s = 0; s < info->sseu.max_slices; s++) {
   3790  1.5  riastrad 		if ((s_reg[s] & GEN9_PGCTL_SLICE_ACK) == 0)
   3791  1.5  riastrad 			/* skip disabled slice */
   3792  1.5  riastrad 			continue;
   3793  1.1  riastrad 
   3794  1.5  riastrad 		sseu->slice_mask |= BIT(s);
   3795  1.2      matt 
   3796  1.5  riastrad 		if (IS_GEN9_BC(dev_priv))
   3797  1.5  riastrad 			intel_sseu_copy_subslices(&info->sseu, s,
   3798  1.5  riastrad 						  sseu->subslice_mask);
   3799  1.2      matt 
   3800  1.5  riastrad 		for (ss = 0; ss < info->sseu.max_subslices; ss++) {
   3801  1.5  riastrad 			unsigned int eu_cnt;
   3802  1.5  riastrad 			u8 ss_idx = s * info->sseu.ss_stride +
   3803  1.5  riastrad 				    ss / BITS_PER_BYTE;
   3804  1.1  riastrad 
   3805  1.5  riastrad 			if (IS_GEN9_LP(dev_priv)) {
   3806  1.5  riastrad 				if (!(s_reg[s] & (GEN9_PGCTL_SS_ACK(ss))))
   3807  1.5  riastrad 					/* skip disabled subslice */
   3808  1.5  riastrad 					continue;
   3809  1.2      matt 
   3810  1.5  riastrad 				sseu->subslice_mask[ss_idx] |=
   3811  1.5  riastrad 					BIT(ss % BITS_PER_BYTE);
   3812  1.5  riastrad 			}
   3813  1.2      matt 
   3814  1.5  riastrad 			eu_cnt = 2 * hweight32(eu_reg[2*s + ss/2] &
   3815  1.5  riastrad 					       eu_mask[ss%2]);
   3816  1.5  riastrad 			sseu->eu_total += eu_cnt;
   3817  1.5  riastrad 			sseu->eu_per_subslice = max_t(unsigned int,
   3818  1.5  riastrad 						      sseu->eu_per_subslice,
   3819  1.5  riastrad 						      eu_cnt);
   3820  1.5  riastrad 		}
   3821  1.2      matt 	}
   3822  1.5  riastrad #undef SS_MAX
   3823  1.5  riastrad }
   3824  1.5  riastrad 
   3825  1.5  riastrad static void bdw_sseu_device_status(struct drm_i915_private *dev_priv,
   3826  1.5  riastrad 				   struct sseu_dev_info *sseu)
   3827  1.5  riastrad {
   3828  1.5  riastrad 	const struct intel_runtime_info *info = RUNTIME_INFO(dev_priv);
   3829  1.5  riastrad 	u32 slice_info = I915_READ(GEN8_GT_SLICE_INFO);
   3830  1.5  riastrad 	int s;
   3831  1.2      matt 
   3832  1.5  riastrad 	sseu->slice_mask = slice_info & GEN8_LSLICESTAT_MASK;
   3833  1.2      matt 
   3834  1.5  riastrad 	if (sseu->slice_mask) {
   3835  1.5  riastrad 		sseu->eu_per_subslice = info->sseu.eu_per_subslice;
   3836  1.5  riastrad 		for (s = 0; s < fls(sseu->slice_mask); s++)
   3837  1.5  riastrad 			intel_sseu_copy_subslices(&info->sseu, s,
   3838  1.5  riastrad 						  sseu->subslice_mask);
   3839  1.5  riastrad 		sseu->eu_total = sseu->eu_per_subslice *
   3840  1.5  riastrad 				 intel_sseu_subslice_total(sseu);
   3841  1.2      matt 
   3842  1.5  riastrad 		/* subtract fused off EU(s) from enabled slice(s) */
   3843  1.5  riastrad 		for (s = 0; s < fls(sseu->slice_mask); s++) {
   3844  1.5  riastrad 			u8 subslice_7eu = info->sseu.subslice_7eu[s];
   3845  1.2      matt 
   3846  1.5  riastrad 			sseu->eu_total -= hweight8(subslice_7eu);
   3847  1.5  riastrad 		}
   3848  1.5  riastrad 	}
   3849  1.2      matt }
   3850  1.2      matt 
   3851  1.5  riastrad static void i915_print_sseu_info(struct seq_file *m, bool is_available_info,
   3852  1.5  riastrad 				 const struct sseu_dev_info *sseu)
   3853  1.2      matt {
   3854  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   3855  1.5  riastrad 	const char *type = is_available_info ? "Available" : "Enabled";
   3856  1.5  riastrad 	int s;
   3857  1.2      matt 
   3858  1.5  riastrad 	seq_printf(m, "  %s Slice Mask: %04x\n", type,
   3859  1.5  riastrad 		   sseu->slice_mask);
   3860  1.5  riastrad 	seq_printf(m, "  %s Slice Total: %u\n", type,
   3861  1.5  riastrad 		   hweight8(sseu->slice_mask));
   3862  1.5  riastrad 	seq_printf(m, "  %s Subslice Total: %u\n", type,
   3863  1.5  riastrad 		   intel_sseu_subslice_total(sseu));
   3864  1.5  riastrad 	for (s = 0; s < fls(sseu->slice_mask); s++) {
   3865  1.5  riastrad 		seq_printf(m, "  %s Slice%i subslices: %u\n", type,
   3866  1.5  riastrad 			   s, intel_sseu_subslices_per_slice(sseu, s));
   3867  1.5  riastrad 	}
   3868  1.5  riastrad 	seq_printf(m, "  %s EU Total: %u\n", type,
   3869  1.5  riastrad 		   sseu->eu_total);
   3870  1.5  riastrad 	seq_printf(m, "  %s EU Per Subslice: %u\n", type,
   3871  1.5  riastrad 		   sseu->eu_per_subslice);
   3872  1.2      matt 
   3873  1.5  riastrad 	if (!is_available_info)
   3874  1.5  riastrad 		return;
   3875  1.1  riastrad 
   3876  1.5  riastrad 	seq_printf(m, "  Has Pooled EU: %s\n", yesno(HAS_POOLED_EU(dev_priv)));
   3877  1.5  riastrad 	if (HAS_POOLED_EU(dev_priv))
   3878  1.5  riastrad 		seq_printf(m, "  Min EU in pool: %u\n", sseu->min_eu_in_pool);
   3879  1.1  riastrad 
   3880  1.5  riastrad 	seq_printf(m, "  Has Slice Power Gating: %s\n",
   3881  1.5  riastrad 		   yesno(sseu->has_slice_pg));
   3882  1.5  riastrad 	seq_printf(m, "  Has Subslice Power Gating: %s\n",
   3883  1.5  riastrad 		   yesno(sseu->has_subslice_pg));
   3884  1.5  riastrad 	seq_printf(m, "  Has EU Power Gating: %s\n",
   3885  1.5  riastrad 		   yesno(sseu->has_eu_pg));
   3886  1.1  riastrad }
   3887  1.1  riastrad 
   3888  1.5  riastrad static int i915_sseu_status(struct seq_file *m, void *unused)
   3889  1.1  riastrad {
   3890  1.5  riastrad 	struct drm_i915_private *dev_priv = node_to_i915(m->private);
   3891  1.5  riastrad 	const struct intel_runtime_info *info = RUNTIME_INFO(dev_priv);
   3892  1.5  riastrad 	struct sseu_dev_info sseu;
   3893  1.5  riastrad 	intel_wakeref_t wakeref;
   3894  1.1  riastrad 
   3895  1.5  riastrad 	if (INTEL_GEN(dev_priv) < 8)
   3896  1.1  riastrad 		return -ENODEV;
   3897  1.1  riastrad 
   3898  1.5  riastrad 	seq_puts(m, "SSEU Device Info\n");
   3899  1.5  riastrad 	i915_print_sseu_info(m, true, &info->sseu);
   3900  1.2      matt 
   3901  1.5  riastrad 	seq_puts(m, "SSEU Device Status\n");
   3902  1.5  riastrad 	memset(&sseu, 0, sizeof(sseu));
   3903  1.5  riastrad 	intel_sseu_set_info(&sseu, info->sseu.max_slices,
   3904  1.5  riastrad 			    info->sseu.max_subslices,
   3905  1.5  riastrad 			    info->sseu.max_eus_per_subslice);
   3906  1.5  riastrad 
   3907  1.5  riastrad 	with_intel_runtime_pm(&dev_priv->runtime_pm, wakeref) {
   3908  1.5  riastrad 		if (IS_CHERRYVIEW(dev_priv))
   3909  1.5  riastrad 			cherryview_sseu_device_status(dev_priv, &sseu);
   3910  1.5  riastrad 		else if (IS_BROADWELL(dev_priv))
   3911  1.5  riastrad 			bdw_sseu_device_status(dev_priv, &sseu);
   3912  1.5  riastrad 		else if (IS_GEN(dev_priv, 9))
   3913  1.5  riastrad 			gen9_sseu_device_status(dev_priv, &sseu);
   3914  1.5  riastrad 		else if (INTEL_GEN(dev_priv) >= 10)
   3915  1.5  riastrad 			gen10_sseu_device_status(dev_priv, &sseu);
   3916  1.5  riastrad 	}
   3917  1.2      matt 
   3918  1.5  riastrad 	i915_print_sseu_info(m, false, &sseu);
   3919  1.2      matt 
   3920  1.5  riastrad 	return 0;
   3921  1.5  riastrad }
   3922  1.1  riastrad 
   3923  1.5  riastrad static int i915_forcewake_open(struct inode *inode, struct file *file)
   3924  1.5  riastrad {
   3925  1.5  riastrad 	struct drm_i915_private *i915 = inode->i_private;
   3926  1.5  riastrad 	struct intel_gt *gt = &i915->gt;
   3927  1.1  riastrad 
   3928  1.5  riastrad 	atomic_inc(&gt->user_wakeref);
   3929  1.5  riastrad 	intel_gt_pm_get(gt);
   3930  1.5  riastrad 	if (INTEL_GEN(i915) >= 6)
   3931  1.5  riastrad 		intel_uncore_forcewake_user_get(gt->uncore);
   3932  1.2      matt 
   3933  1.5  riastrad 	return 0;
   3934  1.5  riastrad }
   3935  1.2      matt 
   3936  1.5  riastrad static int i915_forcewake_release(struct inode *inode, struct file *file)
   3937  1.5  riastrad {
   3938  1.5  riastrad 	struct drm_i915_private *i915 = inode->i_private;
   3939  1.5  riastrad 	struct intel_gt *gt = &i915->gt;
   3940  1.2      matt 
   3941  1.5  riastrad 	if (INTEL_GEN(i915) >= 6)
   3942  1.5  riastrad 		intel_uncore_forcewake_user_put(&i915->uncore);
   3943  1.5  riastrad 	intel_gt_pm_put(gt);
   3944  1.5  riastrad 	atomic_dec(&gt->user_wakeref);
   3945  1.2      matt 
   3946  1.2      matt 	return 0;
   3947  1.2      matt }
   3948  1.2      matt 
   3949  1.5  riastrad static const struct file_operations i915_forcewake_fops = {
   3950  1.5  riastrad 	.owner = THIS_MODULE,
   3951  1.5  riastrad 	.open = i915_forcewake_open,
   3952  1.5  riastrad 	.release = i915_forcewake_release,
   3953  1.5  riastrad };
   3954  1.2      matt 
   3955  1.5  riastrad static int i915_hpd_storm_ctl_show(struct seq_file *m, void *data)
   3956  1.2      matt {
   3957  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3958  1.5  riastrad 	struct i915_hotplug *hotplug = &dev_priv->hotplug;
   3959  1.1  riastrad 
   3960  1.5  riastrad 	/* Synchronize with everything first in case there's been an HPD
   3961  1.5  riastrad 	 * storm, but we haven't finished handling it in the kernel yet
   3962  1.5  riastrad 	 */
   3963  1.5  riastrad 	intel_synchronize_irq(dev_priv);
   3964  1.5  riastrad 	flush_work(&dev_priv->hotplug.dig_port_work);
   3965  1.5  riastrad 	flush_delayed_work(&dev_priv->hotplug.hotplug_work);
   3966  1.2      matt 
   3967  1.5  riastrad 	seq_printf(m, "Threshold: %d\n", hotplug->hpd_storm_threshold);
   3968  1.5  riastrad 	seq_printf(m, "Detected: %s\n",
   3969  1.5  riastrad 		   yesno(delayed_work_pending(&hotplug->reenable_work)));
   3970  1.2      matt 
   3971  1.2      matt 	return 0;
   3972  1.1  riastrad }
   3973  1.1  riastrad 
   3974  1.5  riastrad static ssize_t i915_hpd_storm_ctl_write(struct file *file,
   3975  1.5  riastrad 					const char __user *ubuf, size_t len,
   3976  1.5  riastrad 					loff_t *offp)
   3977  1.1  riastrad {
   3978  1.5  riastrad 	struct seq_file *m = file->private_data;
   3979  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   3980  1.5  riastrad 	struct i915_hotplug *hotplug = &dev_priv->hotplug;
   3981  1.5  riastrad 	unsigned int new_threshold;
   3982  1.5  riastrad 	int i;
   3983  1.5  riastrad 	char *newline;
   3984  1.5  riastrad 	char tmp[16];
   3985  1.5  riastrad 
   3986  1.5  riastrad 	if (len >= sizeof(tmp))
   3987  1.5  riastrad 		return -EINVAL;
   3988  1.5  riastrad 
   3989  1.5  riastrad 	if (copy_from_user(tmp, ubuf, len))
   3990  1.5  riastrad 		return -EFAULT;
   3991  1.2      matt 
   3992  1.5  riastrad 	tmp[len] = '\0';
   3993  1.1  riastrad 
   3994  1.5  riastrad 	/* Strip newline, if any */
   3995  1.5  riastrad 	newline = strchr(tmp, '\n');
   3996  1.5  riastrad 	if (newline)
   3997  1.5  riastrad 		*newline = '\0';
   3998  1.5  riastrad 
   3999  1.5  riastrad 	if (strcmp(tmp, "reset") == 0)
   4000  1.5  riastrad 		new_threshold = HPD_STORM_DEFAULT_THRESHOLD;
   4001  1.5  riastrad 	else if (kstrtouint(tmp, 10, &new_threshold) != 0)
   4002  1.2      matt 		return -EINVAL;
   4003  1.1  riastrad 
   4004  1.5  riastrad 	if (new_threshold > 0)
   4005  1.5  riastrad 		DRM_DEBUG_KMS("Setting HPD storm detection threshold to %d\n",
   4006  1.5  riastrad 			      new_threshold);
   4007  1.5  riastrad 	else
   4008  1.5  riastrad 		DRM_DEBUG_KMS("Disabling HPD storm detection\n");
   4009  1.5  riastrad 
   4010  1.5  riastrad 	spin_lock_irq(&dev_priv->irq_lock);
   4011  1.5  riastrad 	hotplug->hpd_storm_threshold = new_threshold;
   4012  1.5  riastrad 	/* Reset the HPD storm stats so we don't accidentally trigger a storm */
   4013  1.5  riastrad 	for_each_hpd_pin(i)
   4014  1.5  riastrad 		hotplug->stats[i].count = 0;
   4015  1.5  riastrad 	spin_unlock_irq(&dev_priv->irq_lock);
   4016  1.1  riastrad 
   4017  1.5  riastrad 	/* Re-enable hpd immediately if we were in an irq storm */
   4018  1.5  riastrad 	flush_delayed_work(&dev_priv->hotplug.reenable_work);
   4019  1.1  riastrad 
   4020  1.5  riastrad 	return len;
   4021  1.1  riastrad }
   4022  1.1  riastrad 
   4023  1.5  riastrad static int i915_hpd_storm_ctl_open(struct inode *inode, struct file *file)
   4024  1.5  riastrad {
   4025  1.5  riastrad 	return single_open(file, i915_hpd_storm_ctl_show, inode->i_private);
   4026  1.5  riastrad }
   4027  1.2      matt 
   4028  1.5  riastrad static const struct file_operations i915_hpd_storm_ctl_fops = {
   4029  1.5  riastrad 	.owner = THIS_MODULE,
   4030  1.5  riastrad 	.open = i915_hpd_storm_ctl_open,
   4031  1.5  riastrad 	.read = seq_read,
   4032  1.5  riastrad 	.llseek = seq_lseek,
   4033  1.5  riastrad 	.release = single_release,
   4034  1.5  riastrad 	.write = i915_hpd_storm_ctl_write
   4035  1.3  riastrad };
   4036  1.3  riastrad 
   4037  1.5  riastrad static int i915_hpd_short_storm_ctl_show(struct seq_file *m, void *data)
   4038  1.3  riastrad {
   4039  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   4040  1.3  riastrad 
   4041  1.5  riastrad 	seq_printf(m, "Enabled: %s\n",
   4042  1.5  riastrad 		   yesno(dev_priv->hotplug.hpd_short_storm_enabled));
   4043  1.3  riastrad 
   4044  1.5  riastrad 	return 0;
   4045  1.5  riastrad }
   4046  1.3  riastrad 
   4047  1.5  riastrad static int
   4048  1.5  riastrad i915_hpd_short_storm_ctl_open(struct inode *inode, struct file *file)
   4049  1.5  riastrad {
   4050  1.5  riastrad 	return single_open(file, i915_hpd_short_storm_ctl_show,
   4051  1.5  riastrad 			   inode->i_private);
   4052  1.3  riastrad }
   4053  1.3  riastrad 
   4054  1.5  riastrad static ssize_t i915_hpd_short_storm_ctl_write(struct file *file,
   4055  1.5  riastrad 					      const char __user *ubuf,
   4056  1.5  riastrad 					      size_t len, loff_t *offp)
   4057  1.3  riastrad {
   4058  1.5  riastrad 	struct seq_file *m = file->private_data;
   4059  1.5  riastrad 	struct drm_i915_private *dev_priv = m->private;
   4060  1.5  riastrad 	struct i915_hotplug *hotplug = &dev_priv->hotplug;
   4061  1.5  riastrad 	char *newline;
   4062  1.5  riastrad 	char tmp[16];
   4063  1.5  riastrad 	int i;
   4064  1.5  riastrad 	bool new_state;
   4065  1.5  riastrad 
   4066  1.5  riastrad 	if (len >= sizeof(tmp))
   4067  1.5  riastrad 		return -EINVAL;
   4068  1.3  riastrad 
   4069  1.5  riastrad 	if (copy_from_user(tmp, ubuf, len))
   4070  1.5  riastrad 		return -EFAULT;
   4071  1.3  riastrad 
   4072  1.5  riastrad 	tmp[len] = '\0';
   4073  1.3  riastrad 
   4074  1.5  riastrad 	/* Strip newline, if any */
   4075  1.5  riastrad 	newline = strchr(tmp, '\n');
   4076  1.5  riastrad 	if (newline)
   4077  1.5  riastrad 		*newline = '\0';
   4078  1.5  riastrad 
   4079  1.5  riastrad 	/* Reset to the "default" state for this system */
   4080  1.5  riastrad 	if (strcmp(tmp, "reset") == 0)
   4081  1.5  riastrad 		new_state = !HAS_DP_MST(dev_priv);
   4082  1.5  riastrad 	else if (kstrtobool(tmp, &new_state) != 0)
   4083  1.5  riastrad 		return -EINVAL;
   4084  1.3  riastrad 
   4085  1.5  riastrad 	DRM_DEBUG_KMS("%sabling HPD short storm detection\n",
   4086  1.5  riastrad 		      new_state ? "En" : "Dis");
   4087  1.3  riastrad 
   4088  1.5  riastrad 	spin_lock_irq(&dev_priv->irq_lock);
   4089  1.5  riastrad 	hotplug->hpd_short_storm_enabled = new_state;
   4090  1.5  riastrad 	/* Reset the HPD storm stats so we don't accidentally trigger a storm */
   4091  1.5  riastrad 	for_each_hpd_pin(i)
   4092  1.5  riastrad 		hotplug->stats[i].count = 0;
   4093  1.5  riastrad 	spin_unlock_irq(&dev_priv->irq_lock);
   4094  1.3  riastrad 
   4095  1.5  riastrad 	/* Re-enable hpd immediately if we were in an irq storm */
   4096  1.5  riastrad 	flush_delayed_work(&dev_priv->hotplug.reenable_work);
   4097  1.3  riastrad 
   4098  1.5  riastrad 	return len;
   4099  1.5  riastrad }
   4100  1.3  riastrad 
   4101  1.5  riastrad static const struct file_operations i915_hpd_short_storm_ctl_fops = {
   4102  1.5  riastrad 	.owner = THIS_MODULE,
   4103  1.5  riastrad 	.open = i915_hpd_short_storm_ctl_open,
   4104  1.5  riastrad 	.read = seq_read,
   4105  1.5  riastrad 	.llseek = seq_lseek,
   4106  1.5  riastrad 	.release = single_release,
   4107  1.5  riastrad 	.write = i915_hpd_short_storm_ctl_write,
   4108  1.5  riastrad };
   4109  1.3  riastrad 
   4110  1.5  riastrad static int i915_drrs_ctl_set(void *data, u64 val)
   4111  1.5  riastrad {
   4112  1.5  riastrad 	struct drm_i915_private *dev_priv = data;
   4113  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   4114  1.5  riastrad 	struct intel_crtc *crtc;
   4115  1.3  riastrad 
   4116  1.5  riastrad 	if (INTEL_GEN(dev_priv) < 7)
   4117  1.5  riastrad 		return -ENODEV;
   4118  1.3  riastrad 
   4119  1.5  riastrad 	for_each_intel_crtc(dev, crtc) {
   4120  1.5  riastrad 		struct drm_connector_list_iter conn_iter;
   4121  1.5  riastrad 		struct intel_crtc_state *crtc_state;
   4122  1.5  riastrad 		struct drm_connector *connector;
   4123  1.5  riastrad 		struct drm_crtc_commit *commit;
   4124  1.5  riastrad 		int ret;
   4125  1.3  riastrad 
   4126  1.5  riastrad 		ret = drm_modeset_lock_single_interruptible(&crtc->base.mutex);
   4127  1.5  riastrad 		if (ret)
   4128  1.5  riastrad 			return ret;
   4129  1.3  riastrad 
   4130  1.5  riastrad 		crtc_state = to_intel_crtc_state(crtc->base.state);
   4131  1.3  riastrad 
   4132  1.5  riastrad 		if (!crtc_state->hw.active ||
   4133  1.5  riastrad 		    !crtc_state->has_drrs)
   4134  1.5  riastrad 			goto out;
   4135  1.3  riastrad 
   4136  1.5  riastrad 		commit = crtc_state->uapi.commit;
   4137  1.5  riastrad 		if (commit) {
   4138  1.5  riastrad 			ret = wait_for_completion_interruptible(&commit->hw_done);
   4139  1.5  riastrad 			if (ret)
   4140  1.5  riastrad 				goto out;
   4141  1.5  riastrad 		}
   4142  1.3  riastrad 
   4143  1.5  riastrad 		drm_connector_list_iter_begin(dev, &conn_iter);
   4144  1.5  riastrad 		drm_for_each_connector_iter(connector, &conn_iter) {
   4145  1.5  riastrad 			struct intel_encoder *encoder;
   4146  1.5  riastrad 			struct intel_dp *intel_dp;
   4147  1.3  riastrad 
   4148  1.5  riastrad 			if (!(crtc_state->uapi.connector_mask &
   4149  1.5  riastrad 			      drm_connector_mask(connector)))
   4150  1.5  riastrad 				continue;
   4151  1.3  riastrad 
   4152  1.5  riastrad 			encoder = intel_attached_encoder(to_intel_connector(connector));
   4153  1.5  riastrad 			if (encoder->type != INTEL_OUTPUT_EDP)
   4154  1.5  riastrad 				continue;
   4155  1.3  riastrad 
   4156  1.5  riastrad 			DRM_DEBUG_DRIVER("Manually %sabling DRRS. %llu\n",
   4157  1.5  riastrad 						val ? "en" : "dis", val);
   4158  1.3  riastrad 
   4159  1.5  riastrad 			intel_dp = enc_to_intel_dp(encoder);
   4160  1.5  riastrad 			if (val)
   4161  1.5  riastrad 				intel_edp_drrs_enable(intel_dp,
   4162  1.5  riastrad 						      crtc_state);
   4163  1.5  riastrad 			else
   4164  1.5  riastrad 				intel_edp_drrs_disable(intel_dp,
   4165  1.5  riastrad 						       crtc_state);
   4166  1.5  riastrad 		}
   4167  1.5  riastrad 		drm_connector_list_iter_end(&conn_iter);
   4168  1.3  riastrad 
   4169  1.5  riastrad out:
   4170  1.5  riastrad 		drm_modeset_unlock(&crtc->base.mutex);
   4171  1.5  riastrad 		if (ret)
   4172  1.5  riastrad 			return ret;
   4173  1.5  riastrad 	}
   4174  1.3  riastrad 
   4175  1.3  riastrad 	return 0;
   4176  1.3  riastrad }
   4177  1.3  riastrad 
   4178  1.5  riastrad DEFINE_SIMPLE_ATTRIBUTE(i915_drrs_ctl_fops, NULL, i915_drrs_ctl_set, "%llu\n");
   4179  1.5  riastrad 
   4180  1.5  riastrad static ssize_t
   4181  1.5  riastrad i915_fifo_underrun_reset_write(struct file *filp,
   4182  1.5  riastrad 			       const char __user *ubuf,
   4183  1.5  riastrad 			       size_t cnt, loff_t *ppos)
   4184  1.1  riastrad {
   4185  1.5  riastrad 	struct drm_i915_private *dev_priv = filp->private_data;
   4186  1.5  riastrad 	struct intel_crtc *intel_crtc;
   4187  1.5  riastrad 	struct drm_device *dev = &dev_priv->drm;
   4188  1.5  riastrad 	int ret;
   4189  1.5  riastrad 	bool reset;
   4190  1.1  riastrad 
   4191  1.5  riastrad 	ret = kstrtobool_from_user(ubuf, cnt, &reset);
   4192  1.5  riastrad 	if (ret)
   4193  1.5  riastrad 		return ret;
   4194  1.1  riastrad 
   4195  1.5  riastrad 	if (!reset)
   4196  1.5  riastrad 		return cnt;
   4197  1.1  riastrad 
   4198  1.5  riastrad 	for_each_intel_crtc(dev, intel_crtc) {
   4199  1.5  riastrad 		struct drm_crtc_commit *commit;
   4200  1.5  riastrad 		struct intel_crtc_state *crtc_state;
   4201  1.1  riastrad 
   4202  1.5  riastrad 		ret = drm_modeset_lock_single_interruptible(&intel_crtc->base.mutex);
   4203  1.5  riastrad 		if (ret)
   4204  1.5  riastrad 			return ret;
   4205  1.1  riastrad 
   4206  1.5  riastrad 		crtc_state = to_intel_crtc_state(intel_crtc->base.state);
   4207  1.5  riastrad 		commit = crtc_state->uapi.commit;
   4208  1.5  riastrad 		if (commit) {
   4209  1.5  riastrad 			ret = wait_for_completion_interruptible(&commit->hw_done);
   4210  1.5  riastrad 			if (!ret)
   4211  1.5  riastrad 				ret = wait_for_completion_interruptible(&commit->flip_done);
   4212  1.5  riastrad 		}
   4213  1.1  riastrad 
   4214  1.5  riastrad 		if (!ret && crtc_state->hw.active) {
   4215  1.5  riastrad 			DRM_DEBUG_KMS("Re-arming FIFO underruns on pipe %c\n",
   4216  1.5  riastrad 				      pipe_name(intel_crtc->pipe));
   4217  1.1  riastrad 
   4218  1.5  riastrad 			intel_crtc_arm_fifo_underrun(intel_crtc, crtc_state);
   4219  1.5  riastrad 		}
   4220  1.1  riastrad 
   4221  1.5  riastrad 		drm_modeset_unlock(&intel_crtc->base.mutex);
   4222  1.1  riastrad 
   4223  1.5  riastrad 		if (ret)
   4224  1.5  riastrad 			return ret;
   4225  1.5  riastrad 	}
   4226  1.1  riastrad 
   4227  1.5  riastrad 	ret = intel_fbc_reset_underrun(dev_priv);
   4228  1.5  riastrad 	if (ret)
   4229  1.5  riastrad 		return ret;
   4230  1.1  riastrad 
   4231  1.5  riastrad 	return cnt;
   4232  1.1  riastrad }
   4233  1.1  riastrad 
   4234  1.5  riastrad static const struct file_operations i915_fifo_underrun_reset_ops = {
   4235  1.5  riastrad 	.owner = THIS_MODULE,
   4236  1.5  riastrad 	.open = simple_open,
   4237  1.5  riastrad 	.write = i915_fifo_underrun_reset_write,
   4238  1.5  riastrad 	.llseek = default_llseek,
   4239  1.5  riastrad };
   4240  1.1  riastrad 
   4241  1.2      matt static const struct drm_info_list i915_debugfs_list[] = {
   4242  1.1  riastrad 	{"i915_capabilities", i915_capabilities, 0},
   4243  1.1  riastrad 	{"i915_gem_objects", i915_gem_object_info, 0},
   4244  1.1  riastrad 	{"i915_gem_fence_regs", i915_gem_fence_regs_info, 0},
   4245  1.1  riastrad 	{"i915_gem_interrupt", i915_interrupt_info, 0},
   4246  1.3  riastrad 	{"i915_guc_info", i915_guc_info, 0},
   4247  1.3  riastrad 	{"i915_guc_load_status", i915_guc_load_status_info, 0},
   4248  1.3  riastrad 	{"i915_guc_log_dump", i915_guc_log_dump, 0},
   4249  1.5  riastrad 	{"i915_guc_load_err_log_dump", i915_guc_log_dump, 0, (void *)1},
   4250  1.5  riastrad 	{"i915_guc_stage_pool", i915_guc_stage_pool, 0},
   4251  1.5  riastrad 	{"i915_huc_load_status", i915_huc_load_status_info, 0},
   4252  1.3  riastrad 	{"i915_frequency_info", i915_frequency_info, 0},
   4253  1.1  riastrad 	{"i915_drpc_info", i915_drpc_info, 0},
   4254  1.1  riastrad 	{"i915_ring_freq_table", i915_ring_freq_table, 0},
   4255  1.3  riastrad 	{"i915_frontbuffer_tracking", i915_frontbuffer_tracking, 0},
   4256  1.1  riastrad 	{"i915_fbc_status", i915_fbc_status, 0},
   4257  1.2      matt 	{"i915_ips_status", i915_ips_status, 0},
   4258  1.1  riastrad 	{"i915_sr_status", i915_sr_status, 0},
   4259  1.1  riastrad 	{"i915_opregion", i915_opregion, 0},
   4260  1.5  riastrad 	{"i915_vbt", i915_vbt, 0},
   4261  1.1  riastrad 	{"i915_gem_framebuffer", i915_gem_framebuffer_info, 0},
   4262  1.1  riastrad 	{"i915_context_status", i915_context_status, 0},
   4263  1.3  riastrad 	{"i915_forcewake_domains", i915_forcewake_domains, 0},
   4264  1.1  riastrad 	{"i915_swizzle_info", i915_swizzle_info, 0},
   4265  1.2      matt 	{"i915_llc", i915_llc, 0},
   4266  1.2      matt 	{"i915_edp_psr_status", i915_edp_psr_status, 0},
   4267  1.2      matt 	{"i915_energy_uJ", i915_energy_uJ, 0},
   4268  1.3  riastrad 	{"i915_runtime_pm_status", i915_runtime_pm_status, 0},
   4269  1.2      matt 	{"i915_power_domain_info", i915_power_domain_info, 0},
   4270  1.5  riastrad 	{"i915_dmc_info", i915_dmc_info, 0},
   4271  1.2      matt 	{"i915_display_info", i915_display_info, 0},
   4272  1.5  riastrad 	{"i915_engine_info", i915_engine_info, 0},
   4273  1.5  riastrad 	{"i915_rcs_topology", i915_rcs_topology, 0},
   4274  1.5  riastrad 	{"i915_shrinker_info", i915_shrinker_info, 0},
   4275  1.3  riastrad 	{"i915_shared_dplls_info", i915_shared_dplls_info, 0},
   4276  1.3  riastrad 	{"i915_dp_mst_info", i915_dp_mst_info, 0},
   4277  1.3  riastrad 	{"i915_wa_registers", i915_wa_registers, 0},
   4278  1.3  riastrad 	{"i915_ddb_info", i915_ddb_info, 0},
   4279  1.3  riastrad 	{"i915_sseu_status", i915_sseu_status, 0},
   4280  1.3  riastrad 	{"i915_drrs_status", i915_drrs_status, 0},
   4281  1.3  riastrad 	{"i915_rps_boost_info", i915_rps_boost_info, 0},
   4282  1.1  riastrad };
   4283  1.1  riastrad #define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
   4284  1.1  riastrad 
   4285  1.2      matt static const struct i915_debugfs_files {
   4286  1.2      matt 	const char *name;
   4287  1.2      matt 	const struct file_operations *fops;
   4288  1.2      matt } i915_debugfs_files[] = {
   4289  1.5  riastrad 	{"i915_perf_noa_delay", &i915_perf_noa_delay_fops},
   4290  1.2      matt 	{"i915_wedged", &i915_wedged_fops},
   4291  1.2      matt 	{"i915_cache_sharing", &i915_cache_sharing_fops},
   4292  1.2      matt 	{"i915_gem_drop_caches", &i915_drop_caches_fops},
   4293  1.5  riastrad #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
   4294  1.2      matt 	{"i915_error_state", &i915_error_state_fops},
   4295  1.5  riastrad 	{"i915_gpu_info", &i915_gpu_info_fops},
   4296  1.5  riastrad #endif
   4297  1.5  riastrad 	{"i915_fifo_underrun_reset", &i915_fifo_underrun_reset_ops},
   4298  1.2      matt 	{"i915_pri_wm_latency", &i915_pri_wm_latency_fops},
   4299  1.2      matt 	{"i915_spr_wm_latency", &i915_spr_wm_latency_fops},
   4300  1.2      matt 	{"i915_cur_wm_latency", &i915_cur_wm_latency_fops},
   4301  1.5  riastrad 	{"i915_fbc_false_color", &i915_fbc_false_color_fops},
   4302  1.3  riastrad 	{"i915_dp_test_data", &i915_displayport_test_data_fops},
   4303  1.3  riastrad 	{"i915_dp_test_type", &i915_displayport_test_type_fops},
   4304  1.5  riastrad 	{"i915_dp_test_active", &i915_displayport_test_active_fops},
   4305  1.5  riastrad 	{"i915_guc_log_level", &i915_guc_log_level_fops},
   4306  1.5  riastrad 	{"i915_guc_log_relay", &i915_guc_log_relay_fops},
   4307  1.5  riastrad 	{"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops},
   4308  1.5  riastrad 	{"i915_hpd_short_storm_ctl", &i915_hpd_short_storm_ctl_fops},
   4309  1.5  riastrad 	{"i915_ipc_status", &i915_ipc_status_fops},
   4310  1.5  riastrad 	{"i915_drrs_ctl", &i915_drrs_ctl_fops},
   4311  1.5  riastrad 	{"i915_edp_psr_debug", &i915_edp_psr_debug_fops}
   4312  1.2      matt };
   4313  1.2      matt 
   4314  1.5  riastrad int i915_debugfs_register(struct drm_i915_private *dev_priv)
   4315  1.1  riastrad {
   4316  1.5  riastrad 	struct drm_minor *minor = dev_priv->drm.primary;
   4317  1.5  riastrad 	int i;
   4318  1.1  riastrad 
   4319  1.5  riastrad 	debugfs_create_file("i915_forcewake_user", S_IRUSR, minor->debugfs_root,
   4320  1.5  riastrad 			    to_i915(minor->dev), &i915_forcewake_fops);
   4321  1.1  riastrad 
   4322  1.2      matt 	for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
   4323  1.5  riastrad 		debugfs_create_file(i915_debugfs_files[i].name,
   4324  1.5  riastrad 				    S_IRUGO | S_IWUSR,
   4325  1.5  riastrad 				    minor->debugfs_root,
   4326  1.5  riastrad 				    to_i915(minor->dev),
   4327  1.5  riastrad 				    i915_debugfs_files[i].fops);
   4328  1.2      matt 	}
   4329  1.1  riastrad 
   4330  1.1  riastrad 	return drm_debugfs_create_files(i915_debugfs_list,
   4331  1.1  riastrad 					I915_DEBUGFS_ENTRIES,
   4332  1.1  riastrad 					minor->debugfs_root, minor);
   4333  1.1  riastrad }
   4334  1.1  riastrad 
   4335  1.3  riastrad struct dpcd_block {
   4336  1.3  riastrad 	/* DPCD dump start address. */
   4337  1.3  riastrad 	unsigned int offset;
   4338  1.3  riastrad 	/* DPCD dump end address, inclusive. If unset, .size will be used. */
   4339  1.3  riastrad 	unsigned int end;
   4340  1.3  riastrad 	/* DPCD dump size. Used if .end is unset. If unset, defaults to 1. */
   4341  1.3  riastrad 	size_t size;
   4342  1.3  riastrad 	/* Only valid for eDP. */
   4343  1.3  riastrad 	bool edp;
   4344  1.3  riastrad };
   4345  1.3  riastrad 
   4346  1.3  riastrad static const struct dpcd_block i915_dpcd_debug[] = {
   4347  1.3  riastrad 	{ .offset = DP_DPCD_REV, .size = DP_RECEIVER_CAP_SIZE },
   4348  1.3  riastrad 	{ .offset = DP_PSR_SUPPORT, .end = DP_PSR_CAPS },
   4349  1.3  riastrad 	{ .offset = DP_DOWNSTREAM_PORT_0, .size = 16 },
   4350  1.3  riastrad 	{ .offset = DP_LINK_BW_SET, .end = DP_EDP_CONFIGURATION_SET },
   4351  1.3  riastrad 	{ .offset = DP_SINK_COUNT, .end = DP_ADJUST_REQUEST_LANE2_3 },
   4352  1.3  riastrad 	{ .offset = DP_SET_POWER },
   4353  1.3  riastrad 	{ .offset = DP_EDP_DPCD_REV },
   4354  1.3  riastrad 	{ .offset = DP_EDP_GENERAL_CAP_1, .end = DP_EDP_GENERAL_CAP_3 },
   4355  1.3  riastrad 	{ .offset = DP_EDP_DISPLAY_CONTROL_REGISTER, .end = DP_EDP_BACKLIGHT_FREQ_CAP_MAX_LSB },
   4356  1.3  riastrad 	{ .offset = DP_EDP_DBC_MINIMUM_BRIGHTNESS_SET, .end = DP_EDP_DBC_MAXIMUM_BRIGHTNESS_SET },
   4357  1.3  riastrad };
   4358  1.3  riastrad 
   4359  1.3  riastrad static int i915_dpcd_show(struct seq_file *m, void *data)
   4360  1.3  riastrad {
   4361  1.3  riastrad 	struct drm_connector *connector = m->private;
   4362  1.3  riastrad 	struct intel_dp *intel_dp =
   4363  1.5  riastrad 		enc_to_intel_dp(intel_attached_encoder(to_intel_connector(connector)));
   4364  1.5  riastrad 	u8 buf[16];
   4365  1.3  riastrad 	ssize_t err;
   4366  1.3  riastrad 	int i;
   4367  1.3  riastrad 
   4368  1.3  riastrad 	if (connector->status != connector_status_connected)
   4369  1.3  riastrad 		return -ENODEV;
   4370  1.3  riastrad 
   4371  1.3  riastrad 	for (i = 0; i < ARRAY_SIZE(i915_dpcd_debug); i++) {
   4372  1.3  riastrad 		const struct dpcd_block *b = &i915_dpcd_debug[i];
   4373  1.3  riastrad 		size_t size = b->end ? b->end - b->offset + 1 : (b->size ?: 1);
   4374  1.3  riastrad 
   4375  1.3  riastrad 		if (b->edp &&
   4376  1.3  riastrad 		    connector->connector_type != DRM_MODE_CONNECTOR_eDP)
   4377  1.3  riastrad 			continue;
   4378  1.3  riastrad 
   4379  1.3  riastrad 		/* low tech for now */
   4380  1.3  riastrad 		if (WARN_ON(size > sizeof(buf)))
   4381  1.3  riastrad 			continue;
   4382  1.3  riastrad 
   4383  1.3  riastrad 		err = drm_dp_dpcd_read(&intel_dp->aux, b->offset, buf, size);
   4384  1.5  riastrad 		if (err < 0)
   4385  1.5  riastrad 			seq_printf(m, "%04x: ERROR %d\n", b->offset, (int)err);
   4386  1.5  riastrad 		else
   4387  1.5  riastrad 			seq_printf(m, "%04x: %*ph\n", b->offset, (int)err, buf);
   4388  1.5  riastrad 	}
   4389  1.5  riastrad 
   4390  1.5  riastrad 	return 0;
   4391  1.5  riastrad }
   4392  1.5  riastrad DEFINE_SHOW_ATTRIBUTE(i915_dpcd);
   4393  1.5  riastrad 
   4394  1.5  riastrad static int i915_panel_show(struct seq_file *m, void *data)
   4395  1.5  riastrad {
   4396  1.5  riastrad 	struct drm_connector *connector = m->private;
   4397  1.5  riastrad 	struct intel_dp *intel_dp =
   4398  1.5  riastrad 		enc_to_intel_dp(intel_attached_encoder(to_intel_connector(connector)));
   4399  1.5  riastrad 
   4400  1.5  riastrad 	if (connector->status != connector_status_connected)
   4401  1.5  riastrad 		return -ENODEV;
   4402  1.5  riastrad 
   4403  1.5  riastrad 	seq_printf(m, "Panel power up delay: %d\n",
   4404  1.5  riastrad 		   intel_dp->panel_power_up_delay);
   4405  1.5  riastrad 	seq_printf(m, "Panel power down delay: %d\n",
   4406  1.5  riastrad 		   intel_dp->panel_power_down_delay);
   4407  1.5  riastrad 	seq_printf(m, "Backlight on delay: %d\n",
   4408  1.5  riastrad 		   intel_dp->backlight_on_delay);
   4409  1.5  riastrad 	seq_printf(m, "Backlight off delay: %d\n",
   4410  1.5  riastrad 		   intel_dp->backlight_off_delay);
   4411  1.5  riastrad 
   4412  1.5  riastrad 	return 0;
   4413  1.5  riastrad }
   4414  1.5  riastrad DEFINE_SHOW_ATTRIBUTE(i915_panel);
   4415  1.5  riastrad 
   4416  1.5  riastrad static int i915_hdcp_sink_capability_show(struct seq_file *m, void *data)
   4417  1.5  riastrad {
   4418  1.5  riastrad 	struct drm_connector *connector = m->private;
   4419  1.5  riastrad 	struct intel_connector *intel_connector = to_intel_connector(connector);
   4420  1.5  riastrad 
   4421  1.5  riastrad 	if (connector->status != connector_status_connected)
   4422  1.5  riastrad 		return -ENODEV;
   4423  1.5  riastrad 
   4424  1.5  riastrad 	/* HDCP is supported by connector */
   4425  1.5  riastrad 	if (!intel_connector->hdcp.shim)
   4426  1.5  riastrad 		return -EINVAL;
   4427  1.5  riastrad 
   4428  1.5  riastrad 	seq_printf(m, "%s:%d HDCP version: ", connector->name,
   4429  1.5  riastrad 		   connector->base.id);
   4430  1.5  riastrad 	intel_hdcp_info(m, intel_connector);
   4431  1.5  riastrad 
   4432  1.5  riastrad 	return 0;
   4433  1.5  riastrad }
   4434  1.5  riastrad DEFINE_SHOW_ATTRIBUTE(i915_hdcp_sink_capability);
   4435  1.5  riastrad 
   4436  1.5  riastrad static int i915_dsc_fec_support_show(struct seq_file *m, void *data)
   4437  1.5  riastrad {
   4438  1.5  riastrad 	struct drm_connector *connector = m->private;
   4439  1.5  riastrad 	struct drm_device *dev = connector->dev;
   4440  1.5  riastrad 	struct drm_crtc *crtc;
   4441  1.5  riastrad 	struct intel_dp *intel_dp;
   4442  1.5  riastrad 	struct drm_modeset_acquire_ctx ctx;
   4443  1.5  riastrad 	struct intel_crtc_state *crtc_state = NULL;
   4444  1.5  riastrad 	int ret = 0;
   4445  1.5  riastrad 	bool try_again = false;
   4446  1.5  riastrad 
   4447  1.5  riastrad 	drm_modeset_acquire_init(&ctx, DRM_MODESET_ACQUIRE_INTERRUPTIBLE);
   4448  1.5  riastrad 
   4449  1.5  riastrad 	do {
   4450  1.5  riastrad 		try_again = false;
   4451  1.5  riastrad 		ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
   4452  1.5  riastrad 				       &ctx);
   4453  1.5  riastrad 		if (ret) {
   4454  1.5  riastrad 			if (ret == -EDEADLK && !drm_modeset_backoff(&ctx)) {
   4455  1.5  riastrad 				try_again = true;
   4456  1.5  riastrad 				continue;
   4457  1.5  riastrad 			}
   4458  1.5  riastrad 			break;
   4459  1.5  riastrad 		}
   4460  1.5  riastrad 		crtc = connector->state->crtc;
   4461  1.5  riastrad 		if (connector->status != connector_status_connected || !crtc) {
   4462  1.5  riastrad 			ret = -ENODEV;
   4463  1.5  riastrad 			break;
   4464  1.5  riastrad 		}
   4465  1.5  riastrad 		ret = drm_modeset_lock(&crtc->mutex, &ctx);
   4466  1.5  riastrad 		if (ret == -EDEADLK) {
   4467  1.5  riastrad 			ret = drm_modeset_backoff(&ctx);
   4468  1.5  riastrad 			if (!ret) {
   4469  1.5  riastrad 				try_again = true;
   4470  1.5  riastrad 				continue;
   4471  1.5  riastrad 			}
   4472  1.5  riastrad 			break;
   4473  1.5  riastrad 		} else if (ret) {
   4474  1.5  riastrad 			break;
   4475  1.3  riastrad 		}
   4476  1.5  riastrad 		intel_dp = enc_to_intel_dp(intel_attached_encoder(to_intel_connector(connector)));
   4477  1.5  riastrad 		crtc_state = to_intel_crtc_state(crtc->state);
   4478  1.5  riastrad 		seq_printf(m, "DSC_Enabled: %s\n",
   4479  1.5  riastrad 			   yesno(crtc_state->dsc.compression_enable));
   4480  1.5  riastrad 		seq_printf(m, "DSC_Sink_Support: %s\n",
   4481  1.5  riastrad 			   yesno(drm_dp_sink_supports_dsc(intel_dp->dsc_dpcd)));
   4482  1.5  riastrad 		seq_printf(m, "Force_DSC_Enable: %s\n",
   4483  1.5  riastrad 			   yesno(intel_dp->force_dsc_en));
   4484  1.5  riastrad 		if (!intel_dp_is_edp(intel_dp))
   4485  1.5  riastrad 			seq_printf(m, "FEC_Sink_Support: %s\n",
   4486  1.5  riastrad 				   yesno(drm_dp_sink_supports_fec(intel_dp->fec_capable)));
   4487  1.5  riastrad 	} while (try_again);
   4488  1.5  riastrad 
   4489  1.5  riastrad 	drm_modeset_drop_locks(&ctx);
   4490  1.5  riastrad 	drm_modeset_acquire_fini(&ctx);
   4491  1.5  riastrad 
   4492  1.5  riastrad 	return ret;
   4493  1.5  riastrad }
   4494  1.5  riastrad 
   4495  1.5  riastrad static ssize_t i915_dsc_fec_support_write(struct file *file,
   4496  1.5  riastrad 					  const char __user *ubuf,
   4497  1.5  riastrad 					  size_t len, loff_t *offp)
   4498  1.5  riastrad {
   4499  1.5  riastrad 	bool dsc_enable = false;
   4500  1.5  riastrad 	int ret;
   4501  1.5  riastrad 	struct drm_connector *connector =
   4502  1.5  riastrad 		((struct seq_file *)file->private_data)->private;
   4503  1.5  riastrad 	struct intel_encoder *encoder = intel_attached_encoder(to_intel_connector(connector));
   4504  1.5  riastrad 	struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
   4505  1.5  riastrad 
   4506  1.5  riastrad 	if (len == 0)
   4507  1.5  riastrad 		return 0;
   4508  1.5  riastrad 
   4509  1.5  riastrad 	DRM_DEBUG_DRIVER("Copied %zu bytes from user to force DSC\n",
   4510  1.5  riastrad 			 len);
   4511  1.5  riastrad 
   4512  1.5  riastrad 	ret = kstrtobool_from_user(ubuf, len, &dsc_enable);
   4513  1.5  riastrad 	if (ret < 0)
   4514  1.5  riastrad 		return ret;
   4515  1.3  riastrad 
   4516  1.5  riastrad 	DRM_DEBUG_DRIVER("Got %s for DSC Enable\n",
   4517  1.5  riastrad 			 (dsc_enable) ? "true" : "false");
   4518  1.5  riastrad 	intel_dp->force_dsc_en = dsc_enable;
   4519  1.3  riastrad 
   4520  1.5  riastrad 	*offp += len;
   4521  1.5  riastrad 	return len;
   4522  1.3  riastrad }
   4523  1.3  riastrad 
   4524  1.5  riastrad static int i915_dsc_fec_support_open(struct inode *inode,
   4525  1.5  riastrad 				     struct file *file)
   4526  1.3  riastrad {
   4527  1.5  riastrad 	return single_open(file, i915_dsc_fec_support_show,
   4528  1.5  riastrad 			   inode->i_private);
   4529  1.3  riastrad }
   4530  1.3  riastrad 
   4531  1.5  riastrad static const struct file_operations i915_dsc_fec_support_fops = {
   4532  1.3  riastrad 	.owner = THIS_MODULE,
   4533  1.5  riastrad 	.open = i915_dsc_fec_support_open,
   4534  1.3  riastrad 	.read = seq_read,
   4535  1.3  riastrad 	.llseek = seq_lseek,
   4536  1.3  riastrad 	.release = single_release,
   4537  1.5  riastrad 	.write = i915_dsc_fec_support_write
   4538  1.3  riastrad };
   4539  1.3  riastrad 
   4540  1.3  riastrad /**
   4541  1.3  riastrad  * i915_debugfs_connector_add - add i915 specific connector debugfs files
   4542  1.3  riastrad  * @connector: pointer to a registered drm_connector
   4543  1.3  riastrad  *
   4544  1.3  riastrad  * Cleanup will be done by drm_connector_unregister() through a call to
   4545  1.3  riastrad  * drm_debugfs_connector_remove().
   4546  1.3  riastrad  *
   4547  1.3  riastrad  * Returns 0 on success, negative error codes on error.
   4548  1.3  riastrad  */
   4549  1.3  riastrad int i915_debugfs_connector_add(struct drm_connector *connector)
   4550  1.3  riastrad {
   4551  1.3  riastrad 	struct dentry *root = connector->debugfs_entry;
   4552  1.5  riastrad 	struct drm_i915_private *dev_priv = to_i915(connector->dev);
   4553  1.3  riastrad 
   4554  1.3  riastrad 	/* The connector must have been registered beforehands. */
   4555  1.3  riastrad 	if (!root)
   4556  1.3  riastrad 		return -ENODEV;
   4557  1.3  riastrad 
   4558  1.3  riastrad 	if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
   4559  1.3  riastrad 	    connector->connector_type == DRM_MODE_CONNECTOR_eDP)
   4560  1.5  riastrad 		debugfs_create_file("i915_dpcd", S_IRUGO, root,
   4561  1.5  riastrad 				    connector, &i915_dpcd_fops);
   4562  1.5  riastrad 
   4563  1.5  riastrad 	if (connector->connector_type == DRM_MODE_CONNECTOR_eDP) {
   4564  1.5  riastrad 		debugfs_create_file("i915_panel_timings", S_IRUGO, root,
   4565  1.5  riastrad 				    connector, &i915_panel_fops);
   4566  1.5  riastrad 		debugfs_create_file("i915_psr_sink_status", S_IRUGO, root,
   4567  1.5  riastrad 				    connector, &i915_psr_sink_status_fops);
   4568  1.5  riastrad 	}
   4569  1.5  riastrad 
   4570  1.5  riastrad 	if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
   4571  1.5  riastrad 	    connector->connector_type == DRM_MODE_CONNECTOR_HDMIA ||
   4572  1.5  riastrad 	    connector->connector_type == DRM_MODE_CONNECTOR_HDMIB) {
   4573  1.5  riastrad 		debugfs_create_file("i915_hdcp_sink_capability", S_IRUGO, root,
   4574  1.5  riastrad 				    connector, &i915_hdcp_sink_capability_fops);
   4575  1.5  riastrad 	}
   4576  1.5  riastrad 
   4577  1.5  riastrad 	if (INTEL_GEN(dev_priv) >= 10 &&
   4578  1.5  riastrad 	    (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort ||
   4579  1.5  riastrad 	     connector->connector_type == DRM_MODE_CONNECTOR_eDP))
   4580  1.5  riastrad 		debugfs_create_file("i915_dsc_fec_support", S_IRUGO, root,
   4581  1.5  riastrad 				    connector, &i915_dsc_fec_support_fops);
   4582  1.3  riastrad 
   4583  1.3  riastrad 	return 0;
   4584  1.3  riastrad }
   4585