i915_debugfs.c 30.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Copyright © 2008 Intel Corporation
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * Authors:
 *    Eric Anholt <eric@anholt.net>
 *    Keith Packard <keithp@keithp.com>
 *
 */

29
#include <linux/sched/mm.h>
30 31
#include <linux/sort.h>

32
#include <drm/drm_debugfs.h>
33

34
#include "gem/i915_gem_context.h"
35
#include "gt/intel_gt_buffer_pool.h"
36
#include "gt/intel_gt_clock_utils.h"
37
#include "gt/intel_gt.h"
38
#include "gt/intel_gt_pm.h"
39
#include "gt/intel_gt_requests.h"
40
#include "gt/intel_reset.h"
41
#include "gt/intel_rc6.h"
42
#include "gt/intel_rps.h"
43
#include "gt/intel_sseu_debugfs.h"
44

45
#include "i915_debugfs.h"
46
#include "i915_debugfs_params.h"
47
#include "i915_irq.h"
48
#include "i915_scheduler.h"
49
#include "i915_trace.h"
50
#include "intel_pm.h"
51
#include "intel_sideband.h"
52

53 54 55 56 57
static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
{
	return to_i915(node->minor->dev);
}

58 59
static int i915_capabilities(struct seq_file *m, void *data)
{
60
	struct drm_i915_private *i915 = node_to_i915(m->private);
61
	struct drm_printer p = drm_seq_file_printer(m);
62

63
	seq_printf(m, "pch: %d\n", INTEL_PCH_TYPE(i915));
64

65 66
	intel_device_info_print_static(INTEL_INFO(i915), &p);
	intel_device_info_print_runtime(RUNTIME_INFO(i915), &p);
67
	intel_gt_info_print(&i915->gt.info, &p);
68
	intel_driver_caps_print(&i915->caps, &p);
69

70
	kernel_param_lock(THIS_MODULE);
71
	i915_params_dump(&i915->params, &p);
72 73
	kernel_param_unlock(THIS_MODULE);

74 75
	return 0;
}
76

77
static char get_tiling_flag(struct drm_i915_gem_object *obj)
78
{
79
	switch (i915_gem_object_get_tiling(obj)) {
80
	default:
81 82 83
	case I915_TILING_NONE: return ' ';
	case I915_TILING_X: return 'X';
	case I915_TILING_Y: return 'Y';
84
	}
85 86
}

87
static char get_global_flag(struct drm_i915_gem_object *obj)
88
{
89
	return READ_ONCE(obj->userfault_count) ? 'g' : ' ';
90 91
}

92
static char get_pin_mapped_flag(struct drm_i915_gem_object *obj)
B
Ben Widawsky 已提交
93
{
C
Chris Wilson 已提交
94
	return obj->mm.mapping ? 'M' : ' ';
B
Ben Widawsky 已提交
95 96
}

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
static const char *
stringify_page_sizes(unsigned int page_sizes, char *buf, size_t len)
{
	size_t x = 0;

	switch (page_sizes) {
	case 0:
		return "";
	case I915_GTT_PAGE_SIZE_4K:
		return "4K";
	case I915_GTT_PAGE_SIZE_64K:
		return "64K";
	case I915_GTT_PAGE_SIZE_2M:
		return "2M";
	default:
		if (!buf)
			return "M";

		if (page_sizes & I915_GTT_PAGE_SIZE_2M)
			x += snprintf(buf + x, len - x, "2M, ");
		if (page_sizes & I915_GTT_PAGE_SIZE_64K)
			x += snprintf(buf + x, len - x, "64K, ");
		if (page_sizes & I915_GTT_PAGE_SIZE_4K)
			x += snprintf(buf + x, len - x, "4K, ");
		buf[x-2] = '\0';

		return buf;
	}
}

127 128 129 130 131 132 133 134 135 136 137
static const char *stringify_vma_type(const struct i915_vma *vma)
{
	if (i915_vma_is_ggtt(vma))
		return "ggtt";

	if (i915_vma_is_dpt(vma))
		return "dpt";

	return "ppgtt";
}

138 139
void
i915_debugfs_describe_obj(struct seq_file *m, struct drm_i915_gem_object *obj)
140
{
141
	struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
142
	struct intel_engine_cs *engine;
B
Ben Widawsky 已提交
143
	struct i915_vma *vma;
B
Ben Widawsky 已提交
144 145
	int pin_count = 0;

146
	seq_printf(m, "%pK: %c%c%c %8zdKiB %02x %02x %s%s%s",
147 148
		   &obj->base,
		   get_tiling_flag(obj),
B
Ben Widawsky 已提交
149
		   get_global_flag(obj),
150
		   get_pin_mapped_flag(obj),
151
		   obj->base.size / 1024,
152 153
		   obj->read_domains,
		   obj->write_domain,
154
		   i915_cache_level_str(dev_priv, obj->cache_level),
C
Chris Wilson 已提交
155 156
		   obj->mm.dirty ? " dirty" : "",
		   obj->mm.madv == I915_MADV_DONTNEED ? " purgeable" : "");
157 158
	if (obj->base.name)
		seq_printf(m, " (name: %d)", obj->base.name);
159 160

	spin_lock(&obj->vma.lock);
161
	list_for_each_entry(vma, &obj->vma.list, obj_link) {
162 163 164
		if (!drm_mm_node_allocated(&vma->node))
			continue;

165 166 167 168 169
		spin_unlock(&obj->vma.lock);

		if (i915_vma_is_pinned(vma))
			pin_count++;

170 171
		seq_printf(m, " (%s offset: %08llx, size: %08llx, pages: %s",
			   stringify_vma_type(vma),
172 173
			   vma->node.start, vma->node.size,
			   stringify_page_sizes(vma->page_sizes.gtt, NULL, 0));
174
		if (i915_vma_is_ggtt(vma) || i915_vma_is_dpt(vma)) {
175 176 177 178 179 180 181
			switch (vma->ggtt_view.type) {
			case I915_GGTT_VIEW_NORMAL:
				seq_puts(m, ", normal");
				break;

			case I915_GGTT_VIEW_PARTIAL:
				seq_printf(m, ", partial [%08llx+%x]",
182 183
					   vma->ggtt_view.partial.offset << PAGE_SHIFT,
					   vma->ggtt_view.partial.size << PAGE_SHIFT);
184 185 186
				break;

			case I915_GGTT_VIEW_ROTATED:
187
				seq_printf(m, ", rotated [(%ux%u, src_stride=%u, dst_stride=%u, offset=%u), (%ux%u, src_stride=%u, dst_stride=%u, offset=%u)]",
188 189
					   vma->ggtt_view.rotated.plane[0].width,
					   vma->ggtt_view.rotated.plane[0].height,
190
					   vma->ggtt_view.rotated.plane[0].src_stride,
191
					   vma->ggtt_view.rotated.plane[0].dst_stride,
192 193 194
					   vma->ggtt_view.rotated.plane[0].offset,
					   vma->ggtt_view.rotated.plane[1].width,
					   vma->ggtt_view.rotated.plane[1].height,
195
					   vma->ggtt_view.rotated.plane[1].src_stride,
196
					   vma->ggtt_view.rotated.plane[1].dst_stride,
197
					   vma->ggtt_view.rotated.plane[1].offset);
198 199
				break;

200
			case I915_GGTT_VIEW_REMAPPED:
201
				seq_printf(m, ", remapped [(%ux%u, src_stride=%u, dst_stride=%u, offset=%u), (%ux%u, src_stride=%u, dst_stride=%u, offset=%u)]",
202 203
					   vma->ggtt_view.remapped.plane[0].width,
					   vma->ggtt_view.remapped.plane[0].height,
204
					   vma->ggtt_view.remapped.plane[0].src_stride,
205
					   vma->ggtt_view.remapped.plane[0].dst_stride,
206 207 208
					   vma->ggtt_view.remapped.plane[0].offset,
					   vma->ggtt_view.remapped.plane[1].width,
					   vma->ggtt_view.remapped.plane[1].height,
209
					   vma->ggtt_view.remapped.plane[1].src_stride,
210
					   vma->ggtt_view.remapped.plane[1].dst_stride,
211 212 213
					   vma->ggtt_view.remapped.plane[1].offset);
				break;

214 215 216 217 218
			default:
				MISSING_CASE(vma->ggtt_view.type);
				break;
			}
		}
219
		if (vma->fence)
220
			seq_printf(m, " , fence: %d", vma->fence->id);
221
		seq_puts(m, ")");
222 223

		spin_lock(&obj->vma.lock);
B
Ben Widawsky 已提交
224
	}
225 226 227
	spin_unlock(&obj->vma.lock);

	seq_printf(m, " (pinned x %d)", pin_count);
228
	if (i915_gem_object_is_stolen(obj))
229
		seq_printf(m, " (stolen: %08llx)", obj->stolen->start);
230 231
	if (i915_gem_object_is_framebuffer(obj))
		seq_printf(m, " (fb)");
232

233
	engine = i915_gem_object_last_write_engine(obj);
234 235
	if (engine)
		seq_printf(m, " (%s)", engine->name);
236 237
}

238
static int i915_gem_object_info(struct seq_file *m, void *data)
239
{
240
	struct drm_i915_private *i915 = node_to_i915(m->private);
241 242
	struct intel_memory_region *mr;
	enum intel_region_id id;
243

244
	seq_printf(m, "%u shrinkable [%u free] objects, %llu bytes\n",
245
		   i915->mm.shrink_count,
246
		   atomic_read(&i915->mm.free_count),
247
		   i915->mm.shrink_memory);
248 249 250
	for_each_memory_region(mr, i915, id)
		seq_printf(m, "%s: total:%pa, available:%pa bytes\n",
			   mr->name, &mr->total, &mr->avail);
251 252 253 254

	return 0;
}

255
#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
256 257
static ssize_t gpu_state_read(struct file *file, char __user *ubuf,
			      size_t count, loff_t *pos)
258
{
259
	struct i915_gpu_coredump *error;
260
	ssize_t ret;
C
Chris Wilson 已提交
261
	void *buf;
262

C
Chris Wilson 已提交
263
	error = file->private_data;
264 265
	if (!error)
		return 0;
266

C
Chris Wilson 已提交
267 268 269 270
	/* Bounce buffer required because of kernfs __user API convenience. */
	buf = kmalloc(count, GFP_KERNEL);
	if (!buf)
		return -ENOMEM;
271

272
	ret = i915_gpu_coredump_copy_to_buffer(error, buf, *pos, count);
C
Chris Wilson 已提交
273
	if (ret <= 0)
274
		goto out;
275

C
Chris Wilson 已提交
276 277 278 279
	if (!copy_to_user(ubuf, buf, ret))
		*pos += ret;
	else
		ret = -EFAULT;
280

281
out:
C
Chris Wilson 已提交
282
	kfree(buf);
283 284
	return ret;
}
285

286 287
static int gpu_state_release(struct inode *inode, struct file *file)
{
288
	i915_gpu_coredump_put(file->private_data);
289
	return 0;
290 291
}

292
static int i915_gpu_info_open(struct inode *inode, struct file *file)
293
{
294
	struct drm_i915_private *i915 = inode->i_private;
295
	struct i915_gpu_coredump *gpu;
296
	intel_wakeref_t wakeref;
297

298
	gpu = NULL;
299
	with_intel_runtime_pm(&i915->runtime_pm, wakeref)
300
		gpu = i915_gpu_coredump(&i915->gt, ALL_ENGINES);
301 302
	if (IS_ERR(gpu))
		return PTR_ERR(gpu);
303

304
	file->private_data = gpu;
305 306 307
	return 0;
}

308 309 310 311 312 313 314 315 316 317 318 319 320
static const struct file_operations i915_gpu_info_fops = {
	.owner = THIS_MODULE,
	.open = i915_gpu_info_open,
	.read = gpu_state_read,
	.llseek = default_llseek,
	.release = gpu_state_release,
};

static ssize_t
i915_error_state_write(struct file *filp,
		       const char __user *ubuf,
		       size_t cnt,
		       loff_t *ppos)
321
{
322
	struct i915_gpu_coredump *error = filp->private_data;
323

324 325
	if (!error)
		return 0;
326

327
	drm_dbg(&error->i915->drm, "Resetting error state\n");
328
	i915_reset_error_state(error->i915);
329

330 331
	return cnt;
}
332

333 334
static int i915_error_state_open(struct inode *inode, struct file *file)
{
335
	struct i915_gpu_coredump *error;
336 337 338 339 340 341

	error = i915_first_error_state(inode->i_private);
	if (IS_ERR(error))
		return PTR_ERR(error);

	file->private_data  = error;
342
	return 0;
343 344 345 346 347
}

static const struct file_operations i915_error_state_fops = {
	.owner = THIS_MODULE,
	.open = i915_error_state_open,
348
	.read = gpu_state_read,
349 350
	.write = i915_error_state_write,
	.llseek = default_llseek,
351
	.release = gpu_state_release,
352
};
353 354
#endif

355
static int i915_frequency_info(struct seq_file *m, void *unused)
356
{
357
	struct drm_i915_private *dev_priv = node_to_i915(m->private);
358
	struct intel_uncore *uncore = &dev_priv->uncore;
359
	struct intel_rps *rps = &dev_priv->gt.rps;
360
	intel_wakeref_t wakeref;
361

362
	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);
363

364
	if (GRAPHICS_VER(dev_priv) == 5) {
365 366
		u16 rgvswctl = intel_uncore_read16(uncore, MEMSWCTL);
		u16 rgvstat = intel_uncore_read16(uncore, MEMSTAT_ILK);
367 368 369 370 371 372 373

		seq_printf(m, "Requested P-state: %d\n", (rgvswctl >> 8) & 0xf);
		seq_printf(m, "Requested VID: %d\n", rgvswctl & 0x3f);
		seq_printf(m, "Current VID: %d\n", (rgvstat & MEMSTAT_VID_MASK) >>
			   MEMSTAT_VID_SHIFT);
		seq_printf(m, "Current P-state: %d\n",
			   (rgvstat & MEMSTAT_PSTATE_MASK) >> MEMSTAT_PSTATE_SHIFT);
374
	} else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
375
		u32 rpmodectl, freq_sts;
376

377
		rpmodectl = intel_uncore_read(&dev_priv->uncore, GEN6_RP_CONTROL);
378 379 380 381 382 383 384 385
		seq_printf(m, "Video Turbo Mode: %s\n",
			   yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
		seq_printf(m, "HW control enabled: %s\n",
			   yesno(rpmodectl & GEN6_RP_ENABLE));
		seq_printf(m, "SW control enabled: %s\n",
			   yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
				  GEN6_RP_MEDIA_SW_MODE));

386
		vlv_punit_get(dev_priv);
387
		freq_sts = vlv_punit_read(dev_priv, PUNIT_REG_GPU_FREQ_STS);
388 389
		vlv_punit_put(dev_priv);

390 391 392 393
		seq_printf(m, "PUNIT_REG_GPU_FREQ_STS: 0x%08x\n", freq_sts);
		seq_printf(m, "DDR freq: %d MHz\n", dev_priv->mem_freq);

		seq_printf(m, "actual GPU freq: %d MHz\n",
394
			   intel_gpu_freq(rps, (freq_sts >> 8) & 0xff));
395 396

		seq_printf(m, "current GPU freq: %d MHz\n",
397
			   intel_gpu_freq(rps, rps->cur_freq));
398 399

		seq_printf(m, "max GPU freq: %d MHz\n",
400
			   intel_gpu_freq(rps, rps->max_freq));
401 402

		seq_printf(m, "min GPU freq: %d MHz\n",
403
			   intel_gpu_freq(rps, rps->min_freq));
404 405

		seq_printf(m, "idle GPU freq: %d MHz\n",
406
			   intel_gpu_freq(rps, rps->idle_freq));
407 408 409

		seq_printf(m,
			   "efficient (RPe) frequency: %d MHz\n",
410
			   intel_gpu_freq(rps, rps->efficient_freq));
411
	} else if (GRAPHICS_VER(dev_priv) >= 6) {
412 413 414
		u32 rp_state_limits;
		u32 gt_perf_status;
		u32 rp_state_cap;
415
		u32 rpmodectl, rpinclimit, rpdeclimit;
416
		u32 rpstat, cagf, reqf;
417 418
		u32 rpupei, rpcurup, rpprevup;
		u32 rpdownei, rpcurdown, rpprevdown;
419
		u32 pm_ier, pm_imr, pm_isr, pm_iir, pm_mask;
420 421
		int max_freq;

422
		rp_state_limits = intel_uncore_read(&dev_priv->uncore, GEN6_RP_STATE_LIMITS);
423 424
		rp_state_cap = intel_rps_read_state_cap(rps);
		if (IS_GEN9_LP(dev_priv))
425
			gt_perf_status = intel_uncore_read(&dev_priv->uncore, BXT_GT_PERF_STATUS);
426
		else
427
			gt_perf_status = intel_uncore_read(&dev_priv->uncore, GEN6_GT_PERF_STATUS);
428

429
		/* RPSTAT1 is in the GT power well */
430
		intel_uncore_forcewake_get(&dev_priv->uncore, FORCEWAKE_ALL);
431

432
		reqf = intel_uncore_read(&dev_priv->uncore, GEN6_RPNSWREQ);
433
		if (GRAPHICS_VER(dev_priv) >= 9)
434 435 436
			reqf >>= 23;
		else {
			reqf &= ~GEN6_TURBO_DISABLE;
437
			if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv))
438 439 440 441
				reqf >>= 24;
			else
				reqf >>= 25;
		}
442
		reqf = intel_gpu_freq(rps, reqf);
443

444 445 446 447 448 449 450 451 452 453 454
		rpmodectl = intel_uncore_read(&dev_priv->uncore, GEN6_RP_CONTROL);
		rpinclimit = intel_uncore_read(&dev_priv->uncore, GEN6_RP_UP_THRESHOLD);
		rpdeclimit = intel_uncore_read(&dev_priv->uncore, GEN6_RP_DOWN_THRESHOLD);

		rpstat = intel_uncore_read(&dev_priv->uncore, GEN6_RPSTAT1);
		rpupei = intel_uncore_read(&dev_priv->uncore, GEN6_RP_CUR_UP_EI) & GEN6_CURICONT_MASK;
		rpcurup = intel_uncore_read(&dev_priv->uncore, GEN6_RP_CUR_UP) & GEN6_CURBSYTAVG_MASK;
		rpprevup = intel_uncore_read(&dev_priv->uncore, GEN6_RP_PREV_UP) & GEN6_CURBSYTAVG_MASK;
		rpdownei = intel_uncore_read(&dev_priv->uncore, GEN6_RP_CUR_DOWN_EI) & GEN6_CURIAVG_MASK;
		rpcurdown = intel_uncore_read(&dev_priv->uncore, GEN6_RP_CUR_DOWN) & GEN6_CURBSYTAVG_MASK;
		rpprevdown = intel_uncore_read(&dev_priv->uncore, GEN6_RP_PREV_DOWN) & GEN6_CURBSYTAVG_MASK;
455
		cagf = intel_rps_read_actual_frequency(rps);
456

457
		intel_uncore_forcewake_put(&dev_priv->uncore, FORCEWAKE_ALL);
458

459
		if (GRAPHICS_VER(dev_priv) >= 11) {
460 461
			pm_ier = intel_uncore_read(&dev_priv->uncore, GEN11_GPM_WGBOXPERF_INTR_ENABLE);
			pm_imr = intel_uncore_read(&dev_priv->uncore, GEN11_GPM_WGBOXPERF_INTR_MASK);
462 463 464 465 466 467
			/*
			 * The equivalent to the PM ISR & IIR cannot be read
			 * without affecting the current state of the system
			 */
			pm_isr = 0;
			pm_iir = 0;
468
		} else if (GRAPHICS_VER(dev_priv) >= 8) {
469 470 471 472
			pm_ier = intel_uncore_read(&dev_priv->uncore, GEN8_GT_IER(2));
			pm_imr = intel_uncore_read(&dev_priv->uncore, GEN8_GT_IMR(2));
			pm_isr = intel_uncore_read(&dev_priv->uncore, GEN8_GT_ISR(2));
			pm_iir = intel_uncore_read(&dev_priv->uncore, GEN8_GT_IIR(2));
473
		} else {
474 475 476 477
			pm_ier = intel_uncore_read(&dev_priv->uncore, GEN6_PMIER);
			pm_imr = intel_uncore_read(&dev_priv->uncore, GEN6_PMIMR);
			pm_isr = intel_uncore_read(&dev_priv->uncore, GEN6_PMISR);
			pm_iir = intel_uncore_read(&dev_priv->uncore, GEN6_PMIIR);
478
		}
479
		pm_mask = intel_uncore_read(&dev_priv->uncore, GEN6_PMINTRMSK);
480

481 482 483 484 485 486 487
		seq_printf(m, "Video Turbo Mode: %s\n",
			   yesno(rpmodectl & GEN6_RP_MEDIA_TURBO));
		seq_printf(m, "HW control enabled: %s\n",
			   yesno(rpmodectl & GEN6_RP_ENABLE));
		seq_printf(m, "SW control enabled: %s\n",
			   yesno((rpmodectl & GEN6_RP_MEDIA_MODE_MASK) ==
				  GEN6_RP_MEDIA_SW_MODE));
488 489 490

		seq_printf(m, "PM IER=0x%08x IMR=0x%08x, MASK=0x%08x\n",
			   pm_ier, pm_imr, pm_mask);
491
		if (GRAPHICS_VER(dev_priv) <= 10)
492 493
			seq_printf(m, "PM ISR=0x%08x IIR=0x%08x\n",
				   pm_isr, pm_iir);
494
		seq_printf(m, "pm_intrmsk_mbz: 0x%08x\n",
495
			   rps->pm_intrmsk_mbz);
496 497
		seq_printf(m, "GT_PERF_STATUS: 0x%08x\n", gt_perf_status);
		seq_printf(m, "Render p-state ratio: %d\n",
498
			   (gt_perf_status & (GRAPHICS_VER(dev_priv) >= 9 ? 0x1ff00 : 0xff00)) >> 8);
499 500 501 502
		seq_printf(m, "Render p-state VID: %d\n",
			   gt_perf_status & 0xff);
		seq_printf(m, "Render p-state limit: %d\n",
			   rp_state_limits & 0xff);
503 504 505 506
		seq_printf(m, "RPSTAT1: 0x%08x\n", rpstat);
		seq_printf(m, "RPMODECTL: 0x%08x\n", rpmodectl);
		seq_printf(m, "RPINCLIMIT: 0x%08x\n", rpinclimit);
		seq_printf(m, "RPDECLIMIT: 0x%08x\n", rpdeclimit);
507
		seq_printf(m, "RPNSWREQ: %dMHz\n", reqf);
B
Ben Widawsky 已提交
508
		seq_printf(m, "CAGF: %dMHz\n", cagf);
509
		seq_printf(m, "RP CUR UP EI: %d (%lldns)\n",
510 511
			   rpupei,
			   intel_gt_pm_interval_to_ns(&dev_priv->gt, rpupei));
512
		seq_printf(m, "RP CUR UP: %d (%lldun)\n",
513 514
			   rpcurup,
			   intel_gt_pm_interval_to_ns(&dev_priv->gt, rpcurup));
515
		seq_printf(m, "RP PREV UP: %d (%lldns)\n",
516 517
			   rpprevup,
			   intel_gt_pm_interval_to_ns(&dev_priv->gt, rpprevup));
C
Chris Wilson 已提交
518 519
		seq_printf(m, "Up threshold: %d%%\n",
			   rps->power.up_threshold);
520

521
		seq_printf(m, "RP CUR DOWN EI: %d (%lldns)\n",
522 523 524
			   rpdownei,
			   intel_gt_pm_interval_to_ns(&dev_priv->gt,
						      rpdownei));
525
		seq_printf(m, "RP CUR DOWN: %d (%lldns)\n",
526 527 528
			   rpcurdown,
			   intel_gt_pm_interval_to_ns(&dev_priv->gt,
						      rpcurdown));
529
		seq_printf(m, "RP PREV DOWN: %d (%lldns)\n",
530 531 532
			   rpprevdown,
			   intel_gt_pm_interval_to_ns(&dev_priv->gt,
						      rpprevdown));
C
Chris Wilson 已提交
533 534
		seq_printf(m, "Down threshold: %d%%\n",
			   rps->power.down_threshold);
535

536
		max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 0 :
537
			    rp_state_cap >> 16) & 0xff;
538
		max_freq *= (IS_GEN9_BC(dev_priv) ||
539
			     GRAPHICS_VER(dev_priv) >= 10 ? GEN9_FREQ_SCALER : 1);
540
		seq_printf(m, "Lowest (RPN) frequency: %dMHz\n",
541
			   intel_gpu_freq(rps, max_freq));
542 543

		max_freq = (rp_state_cap & 0xff00) >> 8;
544
		max_freq *= (IS_GEN9_BC(dev_priv) ||
545
			     GRAPHICS_VER(dev_priv) >= 10 ? GEN9_FREQ_SCALER : 1);
546
		seq_printf(m, "Nominal (RP1) frequency: %dMHz\n",
547
			   intel_gpu_freq(rps, max_freq));
548

549
		max_freq = (IS_GEN9_LP(dev_priv) ? rp_state_cap >> 16 :
550
			    rp_state_cap >> 0) & 0xff;
551
		max_freq *= (IS_GEN9_BC(dev_priv) ||
552
			     GRAPHICS_VER(dev_priv) >= 10 ? GEN9_FREQ_SCALER : 1);
553
		seq_printf(m, "Max non-overclocked (RP0) frequency: %dMHz\n",
554
			   intel_gpu_freq(rps, max_freq));
555
		seq_printf(m, "Max overclocked frequency: %dMHz\n",
556
			   intel_gpu_freq(rps, rps->max_freq));
557

558
		seq_printf(m, "Current freq: %d MHz\n",
559
			   intel_gpu_freq(rps, rps->cur_freq));
560
		seq_printf(m, "Actual freq: %d MHz\n", cagf);
561
		seq_printf(m, "Idle freq: %d MHz\n",
562
			   intel_gpu_freq(rps, rps->idle_freq));
563
		seq_printf(m, "Min freq: %d MHz\n",
564
			   intel_gpu_freq(rps, rps->min_freq));
565
		seq_printf(m, "Boost freq: %d MHz\n",
566
			   intel_gpu_freq(rps, rps->boost_freq));
567
		seq_printf(m, "Max freq: %d MHz\n",
568
			   intel_gpu_freq(rps, rps->max_freq));
569 570
		seq_printf(m,
			   "efficient (RPe) frequency: %d MHz\n",
571
			   intel_gpu_freq(rps, rps->efficient_freq));
572
	} else {
573
		seq_puts(m, "no P-state info available\n");
574
	}
575

576
	seq_printf(m, "Current CD clock frequency: %d kHz\n", dev_priv->cdclk.hw.cdclk);
577 578 579
	seq_printf(m, "Max CD clock frequency: %d kHz\n", dev_priv->max_cdclk_freq);
	seq_printf(m, "Max pixel clock frequency: %d kHz\n", dev_priv->max_dotclk_freq);

580
	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
Z
Zou Wei 已提交
581
	return 0;
582 583
}

584 585
static const char *swizzle_string(unsigned swizzle)
{
586
	switch (swizzle) {
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
	case I915_BIT_6_SWIZZLE_NONE:
		return "none";
	case I915_BIT_6_SWIZZLE_9:
		return "bit9";
	case I915_BIT_6_SWIZZLE_9_10:
		return "bit9/bit10";
	case I915_BIT_6_SWIZZLE_9_11:
		return "bit9/bit11";
	case I915_BIT_6_SWIZZLE_9_10_11:
		return "bit9/bit10/bit11";
	case I915_BIT_6_SWIZZLE_9_17:
		return "bit9/bit17";
	case I915_BIT_6_SWIZZLE_9_10_17:
		return "bit9/bit10/bit17";
	case I915_BIT_6_SWIZZLE_UNKNOWN:
602
		return "unknown";
603 604 605 606 607 608 609
	}

	return "bug";
}

static int i915_swizzle_info(struct seq_file *m, void *data)
{
610
	struct drm_i915_private *dev_priv = node_to_i915(m->private);
611
	struct intel_uncore *uncore = &dev_priv->uncore;
612
	intel_wakeref_t wakeref;
613

614
	seq_printf(m, "bit6 swizzle for X-tiling = %s\n",
615
		   swizzle_string(dev_priv->ggtt.bit_6_swizzle_x));
616
	seq_printf(m, "bit6 swizzle for Y-tiling = %s\n",
617
		   swizzle_string(dev_priv->ggtt.bit_6_swizzle_y));
618

619 620 621 622
	if (dev_priv->quirks & QUIRK_PIN_SWIZZLED_PAGES)
		seq_puts(m, "L-shaped memory detected\n");

	/* On BDW+, swizzling is not used. See detect_bit_6_swizzle() */
623
	if (GRAPHICS_VER(dev_priv) >= 8 || IS_VALLEYVIEW(dev_priv))
624 625 626 627
		return 0;

	wakeref = intel_runtime_pm_get(&dev_priv->runtime_pm);

628
	if (IS_GRAPHICS_VER(dev_priv, 3, 4)) {
629
		seq_printf(m, "DDC = 0x%08x\n",
630
			   intel_uncore_read(uncore, DCC));
631
		seq_printf(m, "DDC2 = 0x%08x\n",
632
			   intel_uncore_read(uncore, DCC2));
633
		seq_printf(m, "C0DRB3 = 0x%04x\n",
634
			   intel_uncore_read16(uncore, C0DRB3_BW));
635
		seq_printf(m, "C1DRB3 = 0x%04x\n",
636
			   intel_uncore_read16(uncore, C1DRB3_BW));
637
	} else if (INTEL_GEN(dev_priv) >= 6) {
638
		seq_printf(m, "MAD_DIMM_C0 = 0x%08x\n",
639
			   intel_uncore_read(uncore, MAD_DIMM_C0));
640
		seq_printf(m, "MAD_DIMM_C1 = 0x%08x\n",
641
			   intel_uncore_read(uncore, MAD_DIMM_C1));
642
		seq_printf(m, "MAD_DIMM_C2 = 0x%08x\n",
643
			   intel_uncore_read(uncore, MAD_DIMM_C2));
644
		seq_printf(m, "TILECTL = 0x%08x\n",
645
			   intel_uncore_read(uncore, TILECTL));
646
		if (GRAPHICS_VER(dev_priv) >= 8)
B
Ben Widawsky 已提交
647
			seq_printf(m, "GAMTARBMODE = 0x%08x\n",
648
				   intel_uncore_read(uncore, GAMTARBMODE));
B
Ben Widawsky 已提交
649 650
		else
			seq_printf(m, "ARB_MODE = 0x%08x\n",
651
				   intel_uncore_read(uncore, ARB_MODE));
652
		seq_printf(m, "DISP_ARB_CTL = 0x%08x\n",
653
			   intel_uncore_read(uncore, DISP_ARB_CTL));
654
	}
655

656
	intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
657 658 659 660

	return 0;
}

661 662
static int i915_rps_boost_info(struct seq_file *m, void *data)
{
663
	struct drm_i915_private *dev_priv = node_to_i915(m->private);
664
	struct intel_rps *rps = &dev_priv->gt.rps;
665

666 667
	seq_printf(m, "RPS enabled? %s\n", yesno(intel_rps_is_enabled(rps)));
	seq_printf(m, "RPS active? %s\n", yesno(intel_rps_is_active(rps)));
668
	seq_printf(m, "GPU busy? %s\n", yesno(dev_priv->gt.awake));
669
	seq_printf(m, "Boosts outstanding? %d\n",
670
		   atomic_read(&rps->num_waiters));
C
Chris Wilson 已提交
671
	seq_printf(m, "Interactive? %d\n", READ_ONCE(rps->power.interactive));
672
	seq_printf(m, "Frequency requested %d, actual %d\n",
673
		   intel_gpu_freq(rps, rps->cur_freq),
674
		   intel_rps_read_actual_frequency(rps));
675
	seq_printf(m, "  min hard:%d, soft:%d; max soft:%d, hard:%d\n",
676 677 678 679
		   intel_gpu_freq(rps, rps->min_freq),
		   intel_gpu_freq(rps, rps->min_freq_softlimit),
		   intel_gpu_freq(rps, rps->max_freq_softlimit),
		   intel_gpu_freq(rps, rps->max_freq));
680
	seq_printf(m, "  idle:%d, efficient:%d, boost:%d\n",
681 682 683
		   intel_gpu_freq(rps, rps->idle_freq),
		   intel_gpu_freq(rps, rps->efficient_freq),
		   intel_gpu_freq(rps, rps->boost_freq));
684

685
	seq_printf(m, "Wait boosts: %d\n", READ_ONCE(rps->boosts));
686

687 688 689
	return 0;
}

690
static int i915_runtime_pm_status(struct seq_file *m, void *unused)
691
{
692
	struct drm_i915_private *dev_priv = node_to_i915(m->private);
693
	struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev);
694

695 696
	if (!HAS_RUNTIME_PM(dev_priv))
		seq_puts(m, "Runtime power management not supported\n");
697

698
	seq_printf(m, "Runtime power status: %s\n",
699
		   enableddisabled(!dev_priv->power_domains.init_wakeref));
700

701
	seq_printf(m, "GPU idle: %s\n", yesno(!dev_priv->gt.awake));
702
	seq_printf(m, "IRQs disabled: %s\n",
703
		   yesno(!intel_irqs_enabled(dev_priv)));
704
#ifdef CONFIG_PM
705
	seq_printf(m, "Usage count: %d\n",
706
		   atomic_read(&dev_priv->drm.dev->power.usage_count));
707 708 709
#else
	seq_printf(m, "Device Power Management (CONFIG_PM) disabled\n");
#endif
710
	seq_printf(m, "PCI device power state: %s [%d]\n",
D
David Weinehall 已提交
711 712
		   pci_power_name(pdev->current_state),
		   pdev->current_state);
713

714 715 716
	if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)) {
		struct drm_printer p = drm_seq_file_printer(m);

717
		print_intel_runtime_pm_wakeref(&dev_priv->runtime_pm, &p);
718 719
	}

720 721 722
	return 0;
}

723
static int i915_engine_info(struct seq_file *m, void *unused)
724
{
725
	struct drm_i915_private *i915 = node_to_i915(m->private);
726 727 728
	struct intel_engine_cs *engine;
	intel_wakeref_t wakeref;
	struct drm_printer p;
729

730
	wakeref = intel_runtime_pm_get(&i915->runtime_pm);
731

732
	seq_printf(m, "GT awake? %s [%d], %llums\n",
733
		   yesno(i915->gt.awake),
734 735
		   atomic_read(&i915->gt.wakeref.count),
		   ktime_to_ms(intel_gt_get_awake_time(&i915->gt)));
736 737 738
	seq_printf(m, "CS timestamp frequency: %u Hz, %d ns\n",
		   i915->gt.clock_frequency,
		   i915->gt.clock_period_ns);
739

740
	p = drm_seq_file_printer(m);
741
	for_each_uabi_engine(engine, i915)
742
		intel_engine_dump(engine, &p, "%s\n", engine->name);
743

744
	intel_gt_show_timelines(&i915->gt, &p, i915_request_show_with_schedule);
745 746

	intel_runtime_pm_put(&i915->runtime_pm, wakeref);
747 748 749 750

	return 0;
}

751
static int i915_wa_registers(struct seq_file *m, void *unused)
752
{
753 754
	struct drm_i915_private *i915 = node_to_i915(m->private);
	struct intel_engine_cs *engine;
755

756 757 758 759
	for_each_uabi_engine(engine, i915) {
		const struct i915_wa_list *wal = &engine->ctx_wa_list;
		const struct i915_wa *wa;
		unsigned int count;
760

761 762 763
		count = wal->count;
		if (!count)
			continue;
764

765 766
		seq_printf(m, "%s: Workarounds applied: %u\n",
			   engine->name, count);
767

768 769 770 771
		for (wa = wal->list; count--; wa++)
			seq_printf(m, "0x%X: 0x%08X, mask: 0x%08X\n",
				   i915_mmio_reg_offset(wa->reg),
				   wa->set, wa->clr);
772

773 774
		seq_printf(m, "\n");
	}
775

776
	return 0;
777 778
}

779 780
static int
i915_wedged_get(void *data, u64 *val)
781
{
782 783
	struct drm_i915_private *i915 = data;
	int ret = intel_gt_terminally_wedged(&i915->gt);
784

785 786 787 788 789 790 791 792 793 794
	switch (ret) {
	case -EIO:
		*val = 1;
		return 0;
	case 0:
		*val = 0;
		return 0;
	default:
		return ret;
	}
795 796
}

797 798
static int
i915_wedged_set(void *data, u64 val)
799
{
800
	struct drm_i915_private *i915 = data;
801

802
	/* Flush any previous reset before applying for a new one */
803 804
	wait_event(i915->gt.reset.queue,
		   !test_bit(I915_RESET_BACKOFF, &i915->gt.reset.flags));
805

806 807
	intel_gt_handle_error(&i915->gt, val, I915_ERROR_CAPTURE,
			      "Manually set wedged engine mask = %llx", val);
808
	return 0;
809 810
}

811 812
DEFINE_SIMPLE_ATTRIBUTE(i915_wedged_fops,
			i915_wedged_get, i915_wedged_set,
813
			"%llu\n");
814

815 816 817 818 819 820 821 822 823
static int
i915_perf_noa_delay_set(void *data, u64 val)
{
	struct drm_i915_private *i915 = data;

	/*
	 * This would lead to infinite waits as we're doing timestamp
	 * difference on the CS with only 32bits.
	 */
824
	if (intel_gt_ns_to_clock_interval(&i915->gt, val) > U32_MAX)
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
		return -EINVAL;

	atomic64_set(&i915->perf.noa_programming_delay, val);
	return 0;
}

static int
i915_perf_noa_delay_get(void *data, u64 *val)
{
	struct drm_i915_private *i915 = data;

	*val = atomic64_read(&i915->perf.noa_programming_delay);
	return 0;
}

DEFINE_SIMPLE_ATTRIBUTE(i915_perf_noa_delay_fops,
			i915_perf_noa_delay_get,
			i915_perf_noa_delay_set,
			"%llu\n");

845 846 847 848 849 850 851
#define DROP_UNBOUND	BIT(0)
#define DROP_BOUND	BIT(1)
#define DROP_RETIRE	BIT(2)
#define DROP_ACTIVE	BIT(3)
#define DROP_FREED	BIT(4)
#define DROP_SHRINK_ALL	BIT(5)
#define DROP_IDLE	BIT(6)
852 853
#define DROP_RESET_ACTIVE	BIT(7)
#define DROP_RESET_SEQNO	BIT(8)
854
#define DROP_RCU	BIT(9)
855 856 857 858
#define DROP_ALL (DROP_UNBOUND	| \
		  DROP_BOUND	| \
		  DROP_RETIRE	| \
		  DROP_ACTIVE	| \
859
		  DROP_FREED	| \
860
		  DROP_SHRINK_ALL |\
861 862
		  DROP_IDLE	| \
		  DROP_RESET_ACTIVE | \
863 864
		  DROP_RESET_SEQNO | \
		  DROP_RCU)
865 866
static int
i915_drop_caches_get(void *data, u64 *val)
867
{
868
	*val = DROP_ALL;
869

870
	return 0;
871
}
872
static int
873
gt_drop_caches(struct intel_gt *gt, u64 val)
874
{
875
	int ret;
876

877
	if (val & DROP_RESET_ACTIVE &&
878 879
	    wait_for(intel_engines_are_idle(gt), I915_IDLE_ENGINES_TIMEOUT))
		intel_gt_set_wedged(gt);
880

881
	if (val & DROP_RETIRE)
882
		intel_gt_retire_requests(gt);
883

884
	if (val & (DROP_IDLE | DROP_ACTIVE)) {
885
		ret = intel_gt_wait_for_idle(gt, MAX_SCHEDULE_TIMEOUT);
886
		if (ret)
887
			return ret;
888
	}
889

890
	if (val & DROP_IDLE) {
891
		ret = intel_gt_pm_wait_for_idle(gt);
892 893
		if (ret)
			return ret;
894 895
	}

896 897
	if (val & DROP_RESET_ACTIVE && intel_gt_terminally_wedged(gt))
		intel_gt_handle_error(gt, ALL_ENGINES, 0, NULL);
898

899 900 901
	if (val & DROP_FREED)
		intel_gt_flush_buffer_pool(gt);

902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
	return 0;
}

static int
i915_drop_caches_set(void *data, u64 val)
{
	struct drm_i915_private *i915 = data;
	int ret;

	DRM_DEBUG("Dropping caches: 0x%08llx [0x%08llx]\n",
		  val, val & DROP_ALL);

	ret = gt_drop_caches(&i915->gt, val);
	if (ret)
		return ret;

918
	fs_reclaim_acquire(GFP_KERNEL);
919
	if (val & DROP_BOUND)
920
		i915_gem_shrink(NULL, i915, LONG_MAX, NULL, I915_SHRINK_BOUND);
921

922
	if (val & DROP_UNBOUND)
923
		i915_gem_shrink(NULL, i915, LONG_MAX, NULL, I915_SHRINK_UNBOUND);
924

925
	if (val & DROP_SHRINK_ALL)
926
		i915_gem_shrink_all(i915);
927
	fs_reclaim_release(GFP_KERNEL);
928

929 930 931
	if (val & DROP_RCU)
		rcu_barrier();

932
	if (val & DROP_FREED)
933
		i915_gem_drain_freed_objects(i915);
934

935
	return 0;
936 937
}

938 939 940
DEFINE_SIMPLE_ATTRIBUTE(i915_drop_caches_fops,
			i915_drop_caches_get, i915_drop_caches_set,
			"0x%08llx\n");
941

942 943
static int i915_sseu_status(struct seq_file *m, void *unused)
{
944 945
	struct drm_i915_private *i915 = node_to_i915(m->private);
	struct intel_gt *gt = &i915->gt;
946

947
	return intel_sseu_status(m, gt);
948 949
}

950 951
static int i915_forcewake_open(struct inode *inode, struct file *file)
{
952
	struct drm_i915_private *i915 = inode->i_private;
953
	struct intel_gt *gt = &i915->gt;
954

955 956
	atomic_inc(&gt->user_wakeref);
	intel_gt_pm_get(gt);
957
	if (GRAPHICS_VER(i915) >= 6)
958
		intel_uncore_forcewake_user_get(gt->uncore);
959 960 961 962

	return 0;
}

963
static int i915_forcewake_release(struct inode *inode, struct file *file)
964
{
965
	struct drm_i915_private *i915 = inode->i_private;
966
	struct intel_gt *gt = &i915->gt;
967

968
	if (GRAPHICS_VER(i915) >= 6)
969 970 971
		intel_uncore_forcewake_user_put(&i915->uncore);
	intel_gt_pm_put(gt);
	atomic_dec(&gt->user_wakeref);
972 973 974 975 976 977 978 979 980 981

	return 0;
}

static const struct file_operations i915_forcewake_fops = {
	.owner = THIS_MODULE,
	.open = i915_forcewake_open,
	.release = i915_forcewake_release,
};

982
static const struct drm_info_list i915_debugfs_list[] = {
C
Chris Wilson 已提交
983
	{"i915_capabilities", i915_capabilities, 0},
984
	{"i915_gem_objects", i915_gem_object_info, 0},
985
	{"i915_frequency_info", i915_frequency_info, 0},
986
	{"i915_swizzle_info", i915_swizzle_info, 0},
987
	{"i915_runtime_pm_status", i915_runtime_pm_status, 0},
988
	{"i915_engine_info", i915_engine_info, 0},
989
	{"i915_wa_registers", i915_wa_registers, 0},
990
	{"i915_sseu_status", i915_sseu_status, 0},
991
	{"i915_rps_boost_info", i915_rps_boost_info, 0},
992
};
993
#define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list)
994

995
static const struct i915_debugfs_files {
996 997 998
	const char *name;
	const struct file_operations *fops;
} i915_debugfs_files[] = {
999
	{"i915_perf_noa_delay", &i915_perf_noa_delay_fops},
1000 1001
	{"i915_wedged", &i915_wedged_fops},
	{"i915_gem_drop_caches", &i915_drop_caches_fops},
1002
#if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
1003
	{"i915_error_state", &i915_error_state_fops},
1004
	{"i915_gpu_info", &i915_gpu_info_fops},
1005
#endif
1006 1007
};

1008
void i915_debugfs_register(struct drm_i915_private *dev_priv)
1009
{
1010
	struct drm_minor *minor = dev_priv->drm.primary;
1011
	int i;
1012

1013 1014
	i915_debugfs_params(dev_priv);

1015 1016
	debugfs_create_file("i915_forcewake_user", S_IRUSR, minor->debugfs_root,
			    to_i915(minor->dev), &i915_forcewake_fops);
1017
	for (i = 0; i < ARRAY_SIZE(i915_debugfs_files); i++) {
1018 1019 1020 1021 1022
		debugfs_create_file(i915_debugfs_files[i].name,
				    S_IRUGO | S_IWUSR,
				    minor->debugfs_root,
				    to_i915(minor->dev),
				    i915_debugfs_files[i].fops);
1023
	}
1024

1025 1026 1027
	drm_debugfs_create_files(i915_debugfs_list,
				 I915_DEBUGFS_ENTRIES,
				 minor->debugfs_root, minor);
1028
}