intel_gt_debugfs.c 2.6 KB
Newer Older
1 2 3 4 5 6 7
// SPDX-License-Identifier: MIT
/*
 * Copyright © 2019 Intel Corporation
 */

#include <linux/debugfs.h>

8
#include "i915_drv.h"
9
#include "intel_gt.h"
10
#include "intel_gt_debugfs.h"
11
#include "intel_gt_engines_debugfs.h"
12
#include "intel_gt_mcr.h"
13
#include "intel_gt_pm_debugfs.h"
14
#include "intel_sseu_debugfs.h"
15
#include "uc/intel_uc_debugfs.h"
16

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
int intel_gt_debugfs_reset_show(struct intel_gt *gt, u64 *val)
{
	int ret = intel_gt_terminally_wedged(gt);

	switch (ret) {
	case -EIO:
		*val = 1;
		return 0;
	case 0:
		*val = 0;
		return 0;
	default:
		return ret;
	}
}

33
void intel_gt_debugfs_reset_store(struct intel_gt *gt, u64 val)
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
{
	/* Flush any previous reset before applying for a new one */
	wait_event(gt->reset.queue,
		   !test_bit(I915_RESET_BACKOFF, &gt->reset.flags));

	intel_gt_handle_error(gt, val, I915_ERROR_CAPTURE,
			      "Manually reset engine mask to %llx", val);
}

/*
 * keep the interface clean where the first parameter
 * is a 'struct intel_gt *' instead of 'void *'
 */
static int __intel_gt_debugfs_reset_show(void *data, u64 *val)
{
	return intel_gt_debugfs_reset_show(data, val);
}

static int __intel_gt_debugfs_reset_store(void *data, u64 val)
{
54 55 56
	intel_gt_debugfs_reset_store(data, val);

	return 0;
57 58 59 60 61
}

DEFINE_SIMPLE_ATTRIBUTE(reset_fops, __intel_gt_debugfs_reset_show,
			__intel_gt_debugfs_reset_store, "%llu\n");

62 63 64 65 66
static int steering_show(struct seq_file *m, void *data)
{
	struct drm_printer p = drm_seq_file_printer(m);
	struct intel_gt *gt = m->private;

67
	intel_gt_mcr_report_steering(&p, gt, true);
68 69 70 71 72

	return 0;
}
DEFINE_INTEL_GT_DEBUGFS_ATTRIBUTE(steering);

73 74 75 76
static void gt_debugfs_register(struct intel_gt *gt, struct dentry *root)
{
	static const struct intel_gt_debugfs_file files[] = {
		{ "reset", &reset_fops, NULL },
77
		{ "steering", &steering_fops },
78 79 80 81 82
	};

	intel_gt_debugfs_register_files(root, files, ARRAY_SIZE(files), gt);
}

83
void intel_gt_debugfs_register(struct intel_gt *gt)
84 85 86 87 88 89 90 91 92 93
{
	struct dentry *root;

	if (!gt->i915->drm.primary->debugfs_root)
		return;

	root = debugfs_create_dir("gt", gt->i915->drm.primary->debugfs_root);
	if (IS_ERR(root))
		return;

94 95
	gt_debugfs_register(gt, root);

96
	intel_gt_engines_debugfs_register(gt, root);
97
	intel_gt_pm_debugfs_register(gt, root);
98
	intel_sseu_debugfs_register(gt, root);
99 100

	intel_uc_debugfs_register(&gt->uc, root);
101 102
}

103
void intel_gt_debugfs_register_files(struct dentry *root,
104
				     const struct intel_gt_debugfs_file *files,
105
				     unsigned long count, void *data)
106 107
{
	while (count--) {
108
		umode_t mode = files->fops->write ? 0644 : 0444;
109

110
		if (!files->eval || files->eval(data))
111
			debugfs_create_file(files->name,
112
					    mode, root, data,
113 114 115 116 117
					    files->fops);

		files++;
	}
}