File: xe_configfs.c

package info (click to toggle)
intel-gpu-tools 2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 63,360 kB
  • sloc: xml: 781,458; ansic: 360,567; python: 8,336; yacc: 2,781; perl: 1,196; sh: 1,177; lex: 487; asm: 227; lisp: 35; makefile: 30
file content (360 lines) | stat: -rw-r--r-- 9,485 bytes parent folder | download
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// SPDX-License-Identifier: MIT
/*
 * Copyright © 2025 Intel Corporation
 */
#include <limits.h>

#include "igt.h"
#include "igt_configfs.h"
#include "igt_device.h"
#include "igt_fs.h"
#include "igt_kmod.h"
#include "igt_sriov_device.h"
#include "igt_sysfs.h"
#include "xe/xe_query.h"

/**
 * TEST: Check configfs userspace API
 * Category: Core
 * Mega feature: General Core features
 * Sub-category: uapi
 * Functionality: configfs
 * Description: validate configfs entries
 * Test category: functionality test
 */

static char bus_addr[NAME_MAX];
static struct pci_device *pci_dev;

static bool check_registers(const uint32_t reg[], const uint32_t val[],
			    size_t max)
{
	struct intel_mmio_data mmio_data = { };
	bool ret = false;

	intel_register_access_init(&mmio_data, pci_dev, 0);

	for (int i = 0; i < max && reg[i]; i++) {
		uint32_t v = intel_register_read(&mmio_data, reg[i]);

		if (v != val[i]) {
			igt_debug("Expecting [%x]=%x but found %x\n",
				  reg[i], val[i], v);
			goto out;
		}
	}

	ret = true;

out:
	intel_register_access_fini(&mmio_data);
	return ret;
}

static void restore(int sig)
{
	int configfs_fd;

	igt_kmod_unbind("xe", bus_addr);

	/* Drop all custom configfs settings from subtests */
	configfs_fd = igt_configfs_open("xe");
	if (configfs_fd >= 0)
		igt_fs_remove_dir(configfs_fd, bus_addr);
	close(configfs_fd);

	/* Bind again a clean driver with no custom settings */
	igt_kmod_bind("xe", bus_addr);
}

static void set_survivability_mode(int configfs_device_fd, bool value)
{
	igt_kmod_unbind("xe", bus_addr);
	igt_sysfs_set_boolean(configfs_device_fd, "survivability_mode", value);
	igt_kmod_bind("xe", bus_addr);
}

/**
 * SUBTEST: survivability-mode
 * Description: Validate survivability mode by setting configfs
 */
static void test_survivability_mode(int configfs_device_fd)
{
	char path[PATH_MAX];
	int fd;

	/* Enable survivability mode */
	set_survivability_mode(configfs_device_fd, true);

	/* check presence of survivability mode sysfs */
	snprintf(path, PATH_MAX, "/sys/bus/pci/devices/%s/survivability_mode", bus_addr);

	fd = open(path, O_RDONLY);
	igt_assert_f(fd >= 0, "Survivability mode not set\n");
	close(fd);
}

/**
 * SUBTEST: engines-allowed-invalid
 * Description: Validate engines_allowed attribute for invalid values
 */
static void test_engines_allowed_invalid(int configfs_device_fd)
{
	static const char *values[] = {
		"xcs0",
		"abcsdcs0",
		"rcs0,abcsdcs0",
		"rcs9",
		"rcs10",
		"rcs0asdf",
	};

	/*
	 * These only test if engine parsing is correct, so just make sure
	 * there's no device bound
	 */
	igt_kmod_unbind("xe", bus_addr);

	for (size_t i = 0; i < ARRAY_SIZE(values); i++) {
		const char *v = values[i];

		igt_debug("Writing '%s' to engines_allowed\n", v);
		igt_assert(!igt_sysfs_set(configfs_device_fd, "engines_allowed", v));
	}
}

/**
 * SUBTEST: engines-allowed
 * Description: Validate engines_allowed attribute
 */
static void test_engines_allowed(int configfs_device_fd)
{
	static const char *values[] = {
		"rcs0", "rcs*", "rcs0,bcs0", "bcs0,rcs0",
		"bcs0\nrcs0", "bcs0\nrcs0\n",
		"rcs000",
	};

	/*
	 * These only test if engine parsing is correct, so just make sure
	 * there's no device bound
	 */
	igt_kmod_unbind("xe", bus_addr);

	for (size_t i = 0; i < ARRAY_SIZE(values); i++) {
		const char *v = values[i];

		igt_debug("Writing '%s' to engines_allowed\n", v);
		igt_assert(igt_sysfs_set(configfs_device_fd, "engines_allowed", v));
	}
}

/**
 * SUBTEST: ctx-restore-post-bb-invalid
 * Description: Validate ctx_restore_post_bb attribute for invalid values
 *
 * SUBTEST: ctx-restore-mid-bb-invalid
 * Description: Validate ctx_restore_mid_bb attribute for invalid values
 */
static void test_ctx_restore_invalid(int configfs_device_fd, const char *type)
{
	static const struct value {
		const char *test;
		const char *in;
	} values[] = {
		{ .test = "invalid-engine",
		  .in = "foobar cmd 11000001 4F100 DEADBEEF",
		},
		{ .test = "invalid-type",
		  .in = "rcs 11000001 4F100 DEADBEEF",
		},
		{ .test = "invalid-number",
		  .in = "rcs cmd 1100000g 4F100 DEADBEEF",
		},
		{ .test = "invalid-number",
		  .in = "rcs cmd 1100000g 4F100 DEADBEEF",
		},
		{ .test = "invalid-reg-addr-only",
		  .in = "rcs reg 4F100",
		},
	};
	char buf[4096] = { };
	char file[64] = { };

	snprintf(file, sizeof(file), "ctx_restore_%s_bb", type);
	igt_sysfs_set(configfs_device_fd, "ctx_restore_post_bb", "");

	/*
	 * These only test if command parsing is correct,
	 * so just make sure there's no device bound
	 */
	igt_kmod_unbind("xe", bus_addr);

	for (size_t i = 0; i < ARRAY_SIZE(values); i++) {
		const struct value *v = &values[i];

		igt_info("Test %s\n", v->test);
		igt_debug("bb '%s'\n", v->in);
		igt_assert(!igt_sysfs_set(configfs_device_fd, file, v->in));
		igt_assert(igt_sysfs_read(configfs_device_fd, file, buf,
					  sizeof(buf) - 1));
		if (strcmp(buf, "")) {
			igt_debug("Expecting empty bb, but found '%s'\n", buf);
			igt_fail(IGT_EXIT_FAILURE);
		}
	}
}

/**
 * SUBTEST: ctx-restore-post-bb
 * Description: Validate ctx_restore_post_bb attribute
 *
 * SUBTEST: ctx-restore-mid-bb
 * Description: Validate ctx_restore_mid_bb attribute
 */
static void test_ctx_restore(int configfs_device_fd, const char *type)
{
	static const struct value {
		const char *test;
		const char *in;
		const char *out;
		uint32_t reg[4];
		uint32_t reg_val[4];
	} values[] = {
		/*
		 * values for the registers just keep incrementing on different
		 * tests to avoid having tests passing just because the
		 * previous execution set a specific value in the HW
		 */
		{ .test = "cmd-single",
		  .in = "rcs cmd 11000001 4F100 DEA0BEE0",
		  .out = "rcs: 11000001 0004f100 dea0bee0\n",
		  .reg = { 0x4f100 },
		  .reg_val = { 0xdea0bee0 },
		},
		{ .test = "cmd-single-multi-values",
		  .in = "rcs cmd 11000003 4F100 DEA1BEE1 4F104 DEA2BEE2",
		  .out = "rcs: 11000003 0004f100 dea1bee1 0004f104 dea2bee2\n",
		  .reg = { 0x4f100, 0x4f104 },
		  .reg_val = { 0xdea1bee1, 0xdea2bee2 },
		},
		{ .test = "cmd-multi",
		  .in = "rcs cmd 11000001 4F100 DEA3BEE3\n"
			"rcs cmd 11000001 4F104 DEA4BEE4",
		  .out = "rcs: 11000001 0004f100 dea3bee3 11000001 0004f104 dea4bee4\n",
		  .reg = { 0x4f100, 0x4f104 },
		  .reg_val = { 0xdea3bee3, 0xdea4bee4 },
		},
		{ .test = "reg-single",
		  .in = "rcs reg 4F100 DEA5BEE5",
		  .out = "rcs: 11000001 0004f100 dea5bee5\n",
		  .reg = { 0x4f100 },
		  .reg_val = { 0xdea5bee5 },
		},
		{ .test = "reg-multi",
		  .in = "rcs reg 4F100 DEA6BEE6\n"
			"rcs reg 4F104 DEA7BEE7",
		  .out = "rcs: 11000001 0004f100 dea6bee6 11000001 0004f104 dea7bee7\n",
		  .reg = { 0x4f100, 0x4f104 },
		  .reg_val = { 0xdea6bee6, 0xdea7bee7 },
		},
	};
	char buf[4096] = { };
	char file[64] = { };

	snprintf(file, sizeof(file), "ctx_restore_%s_bb", type);

	for (size_t i = 0; i < ARRAY_SIZE(values); i++) {
		const struct value *v = &values[i];

		igt_kmod_unbind("xe", bus_addr);

		igt_info("Test %s\n", v->test);
		igt_debug("bb '%s'\n", v->in);
		igt_assert(igt_sysfs_set(configfs_device_fd, file, v->in));

		igt_assert(igt_sysfs_read(configfs_device_fd, file, buf,
					  sizeof(buf) - 1));
		if (strcmp(v->out, buf)) {
			igt_debug("Expecting '%s' but found '%s'\n", v->out, buf);
			igt_fail(IGT_EXIT_FAILURE);
		}

		igt_kmod_bind("xe", bus_addr);
		igt_assert(check_registers(v->reg, v->reg_val, sizeof(v->reg)));
	}
}

static void set_bus_addr(int fd)
{
	pci_dev = igt_device_get_pci_device(fd);
	snprintf(bus_addr, sizeof(bus_addr), "%04x:%02x:%02x.%01x",
		 pci_dev->domain, pci_dev->bus, pci_dev->dev, pci_dev->func);
}

static int create_device_configfs_group(int configfs_fd)
{
	mode_t mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
	int configfs_device_fd;

	configfs_device_fd = igt_fs_create_dir(configfs_fd, bus_addr, mode);
	igt_assert(configfs_device_fd);

	return configfs_device_fd;
}

igt_main
{
	int fd, configfs_fd, configfs_device_fd;
	uint32_t devid;
	bool is_vf_device;

	igt_fixture {
		fd = drm_open_driver(DRIVER_XE);
		devid = intel_get_drm_devid(fd);
		is_vf_device = intel_is_vf_device(fd);
		set_bus_addr(fd);
		drm_close_driver(fd);

		configfs_fd = igt_configfs_open("xe");
		igt_require(configfs_fd != -1);
		configfs_device_fd = create_device_configfs_group(configfs_fd);
		igt_install_exit_handler(restore);
	}

	igt_describe("Validate survivability mode");
	igt_subtest("survivability-mode") {
		igt_require(IS_BATTLEMAGE(devid));
		igt_require_f(!is_vf_device, "survivability mode not supported in VF\n");
		test_survivability_mode(configfs_device_fd);
	}

	igt_describe("Validate engines_allowed with invalid options");
	igt_subtest("engines-allowed-invalid")
		test_engines_allowed_invalid(configfs_device_fd);

	igt_describe("Validate engines_allowed");
	igt_subtest("engines-allowed")
		test_engines_allowed(configfs_device_fd);

	igt_describe("Validate ctx_restore_post_bb with invalid options");
	igt_subtest("ctx-restore-post-bb-invalid")
		test_ctx_restore_invalid(configfs_device_fd, "post");

	igt_describe("Validate ctx_restore_post_bb");
	igt_subtest("ctx-restore-post-bb")
		test_ctx_restore(configfs_device_fd, "post");

	igt_describe("Validate ctx_restore_mid_bb with invalid options");
	igt_subtest("ctx-restore-mid-bb-invalid")
		test_ctx_restore_invalid(configfs_device_fd, "mid");

	igt_describe("Validate ctx_restore_mid_bb");
	igt_subtest("ctx-restore-mid-bb")
		test_ctx_restore(configfs_device_fd, "mid");

	igt_fixture {
		close(configfs_device_fd);
		close(configfs_fd);
	}
}