1 /*
2  * SPDX-License-Identifier: GPL-2.0
3  *
4  * Copyright © 2018 Intel Corporation
5  */
6 
7 #include "../i915_selftest.h"
8 
9 static int intel_mmio_bases_check(void *arg)
10 {
11 	int i, j;
12 
13 	for (i = 0; i < ARRAY_SIZE(intel_engines); i++) {
14 		const struct engine_info *info = &intel_engines[i];
15 		char name[INTEL_ENGINE_CS_MAX_NAME];
16 		u8 prev = U8_MAX;
17 
18 		__sprint_engine_name(name, info);
19 
20 		for (j = 0; j < MAX_MMIO_BASES; j++) {
21 			u8 gen = info->mmio_bases[j].gen;
22 			u32 base = info->mmio_bases[j].base;
23 
24 			if (gen >= prev) {
25 				pr_err("%s: %s: mmio base for gen %x "
26 					"is before the one for gen %x\n",
27 				       __func__, name, prev, gen);
28 				return -EINVAL;
29 			}
30 
31 			if (gen == 0)
32 				break;
33 
34 			if (!base) {
35 				pr_err("%s: %s: invalid mmio base (%x) "
36 					"for gen %x at entry %u\n",
37 				       __func__, name, base, gen, j);
38 				return -EINVAL;
39 			}
40 
41 			prev = gen;
42 		}
43 
44 		pr_info("%s: min gen supported for %s = %d\n",
45 			__func__, name, prev);
46 	}
47 
48 	return 0;
49 }
50 
51 int intel_engine_cs_mock_selftests(void)
52 {
53 	static const struct i915_subtest tests[] = {
54 		SUBTEST(intel_mmio_bases_check),
55 	};
56 
57 	return i915_subtests(tests, NULL);
58 }
59