summaryrefslogtreecommitdiff
path: root/mali_kbase/mali_kbase_pbha_debugfs.c
blob: 1cc29c700e5a07a6d6937b35cf3075dbaec7b75f (plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
/*
 *
 * (C) COPYRIGHT 2021-2022 ARM Limited. All rights reserved.
 *
 * This program is free software and is provided to you under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation, and any use by you of this program is subject to the terms
 * of such GNU license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you can access it online at
 * http://www.gnu.org/licenses/gpl-2.0.html.
 *
 */

#include "mali_kbase_pbha_debugfs.h"
#include "mali_kbase_pbha.h"
#include <device/mali_kbase_device.h>
#include <mali_kbase_reset_gpu.h>
#include <mali_kbase.h>

#if MALI_USE_CSF
#include "backend/gpu/mali_kbase_pm_internal.h"
#endif

static int int_id_overrides_show(struct seq_file *sfile, void *data)
{
	struct kbase_device *kbdev = sfile->private;
	int i;

	kbase_pm_context_active(kbdev);

	/* Minimal header for readability */
	seq_puts(sfile, "// R   W\n");
	for (i = 0; i < SYSC_ALLOC_COUNT; ++i) {
		int j;
		u32 reg = kbase_reg_read(kbdev, GPU_CONTROL_REG(SYSC_ALLOC(i)));

		for (j = 0; j < sizeof(u32); ++j) {
			u8 r_val;
			u8 w_val;

			switch (j) {
			case 0:
				r_val = SYSC_ALLOC_R_SYSC_ALLOC0_GET(reg);
				w_val = SYSC_ALLOC_W_SYSC_ALLOC0_GET(reg);
				break;
			case 1:
				r_val = SYSC_ALLOC_R_SYSC_ALLOC1_GET(reg);
				w_val = SYSC_ALLOC_W_SYSC_ALLOC1_GET(reg);
				break;
			case 2:
				r_val = SYSC_ALLOC_R_SYSC_ALLOC2_GET(reg);
				w_val = SYSC_ALLOC_W_SYSC_ALLOC2_GET(reg);
				break;
			case 3:
				r_val = SYSC_ALLOC_R_SYSC_ALLOC3_GET(reg);
				w_val = SYSC_ALLOC_W_SYSC_ALLOC3_GET(reg);
				break;
			}
			seq_printf(sfile, "%2zu 0x%x 0x%x\n",
				   (i * sizeof(u32)) + j, r_val, w_val);
		}
	}
	kbase_pm_context_idle(kbdev);

	return 0;
}

static ssize_t int_id_overrides_write(struct file *file,
				      const char __user *ubuf, size_t count,
				      loff_t *ppos)
{
	struct seq_file *sfile = file->private_data;
	struct kbase_device *kbdev = sfile->private;
	char raw_str[128];
	unsigned int id;
	unsigned int r_val;
	unsigned int w_val;

	if (count >= sizeof(raw_str))
		return -E2BIG;
	if (copy_from_user(raw_str, ubuf, count))
		return -EINVAL;
	raw_str[count] = '\0';

	if (sscanf(raw_str, "%u %x %x", &id, &r_val, &w_val) != 3)
		return -EINVAL;

	if (kbase_pbha_record_settings(kbdev, true, id, r_val, w_val))
		return -EINVAL;

	/* This is a debugfs config write, so reset GPU such that changes take effect ASAP */
	kbase_pm_context_active(kbdev);
	if (kbase_prepare_to_reset_gpu(kbdev, RESET_FLAGS_NONE))
		kbase_reset_gpu(kbdev);
	kbase_pm_context_idle(kbdev);

	return count;
}

static int int_id_overrides_open(struct inode *in, struct file *file)
{
	return single_open(file, int_id_overrides_show, in->i_private);
}

#if MALI_USE_CSF
/**
 * propagate_bits_show - Read PBHA bits from L2_CONFIG out to debugfs.
 *
 * @sfile: The debugfs entry.
 * @data: Data associated with the entry.
 *
 * Return: 0 in all cases.
 */
static int propagate_bits_show(struct seq_file *sfile, void *data)
{
	struct kbase_device *kbdev = sfile->private;
	u32 l2_config_val;

	kbase_csf_scheduler_pm_active(kbdev);
	kbase_pm_wait_for_l2_powered(kbdev);
	l2_config_val = L2_CONFIG_PBHA_HWU_GET(kbase_reg_read(kbdev, GPU_CONTROL_REG(L2_CONFIG)));
	kbase_csf_scheduler_pm_idle(kbdev);

	seq_printf(sfile, "PBHA Propagate Bits: 0x%x\n", l2_config_val);
	return 0;
}

static int propagate_bits_open(struct inode *in, struct file *file)
{
	return single_open(file, propagate_bits_show, in->i_private);
}

/**
 * propagate_bits_write - Write input value from debugfs to PBHA bits of L2_CONFIG register.
 *
 * @file:     Pointer to file struct of debugfs node.
 * @ubuf:     Pointer to user buffer with value to be written.
 * @count:    Size of user buffer.
 * @ppos:     Not used.
 *
 * Return: Size of buffer passed in when successful, but error code E2BIG/EINVAL otherwise.
 */
static ssize_t propagate_bits_write(struct file *file, const char __user *ubuf, size_t count,
				    loff_t *ppos)
{
	struct seq_file *sfile = file->private_data;
	struct kbase_device *kbdev = sfile->private;
	/* 32 characters should be enough for the input string in any base */
	char raw_str[32];
	unsigned long propagate_bits;

	if (count >= sizeof(raw_str))
		return -E2BIG;
	if (copy_from_user(raw_str, ubuf, count))
		return -EINVAL;
	raw_str[count] = '\0';
	if (kstrtoul(raw_str, 0, &propagate_bits))
		return -EINVAL;

	/* Check propagate_bits input argument does not
	 * exceed the maximum size of the propagate_bits mask.
	 */
	if (propagate_bits > (L2_CONFIG_PBHA_HWU_MASK >> L2_CONFIG_PBHA_HWU_SHIFT))
		return -EINVAL;
	/* Cast to u8 is safe as check is done already to ensure size is within
	 * correct limits.
	 */
	kbdev->pbha_propagate_bits = (u8)propagate_bits;

	/* GPU Reset will set new values in L2 config */
	if (kbase_prepare_to_reset_gpu(kbdev, RESET_FLAGS_NONE)) {
		kbase_reset_gpu(kbdev);
		kbase_reset_gpu_wait(kbdev);
	}

	return count;
}

static const struct file_operations pbha_propagate_bits_fops = {
	.owner = THIS_MODULE,
	.open = propagate_bits_open,
	.read = seq_read,
	.write = propagate_bits_write,
	.llseek = seq_lseek,
	.release = single_release,
};
#endif /* MALI_USE_CSF */

static const struct file_operations pbha_int_id_overrides_fops = {
	.owner = THIS_MODULE,
	.open = int_id_overrides_open,
	.read = seq_read,
	.write = int_id_overrides_write,
	.llseek = seq_lseek,
	.release = single_release,
};

void kbase_pbha_debugfs_init(struct kbase_device *kbdev)
{
	if (kbasep_pbha_supported(kbdev)) {
		const mode_t mode = 0644;
		struct dentry *debugfs_pbha_dir = debugfs_create_dir(
			"pbha", kbdev->mali_debugfs_directory);

		if (IS_ERR_OR_NULL(debugfs_pbha_dir)) {
			dev_err(kbdev->dev,
				"Couldn't create mali debugfs page-based hardware attributes directory\n");
			return;
		}

		debugfs_create_file("int_id_overrides", mode, debugfs_pbha_dir,
				    kbdev, &pbha_int_id_overrides_fops);
#if MALI_USE_CSF
		if (kbase_hw_has_feature(kbdev, BASE_HW_FEATURE_PBHA_HWU))
			debugfs_create_file("propagate_bits", mode, debugfs_pbha_dir, kbdev,
					    &pbha_propagate_bits_fops);
#endif /* MALI_USE_CSF */
	}
}