xref: /linux/drivers/gpu/drm/xe/tests/xe_wa_test.c (revision c4bbe83d27c2446a033cc0381c3fb6be5e8c41c7)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright © 2023 Intel Corporation
4  */
5 
6 #include <drm/drm_drv.h>
7 #include <drm/drm_kunit_helpers.h>
8 
9 #include <kunit/test.h>
10 
11 #include "xe_device.h"
12 #include "xe_pci_test.h"
13 #include "xe_reg_sr.h"
14 #include "xe_tuning.h"
15 #include "xe_wa.h"
16 
17 struct platform_test_case {
18 	const char *name;
19 	enum xe_platform platform;
20 	enum xe_subplatform subplatform;
21 	u32 graphics_verx100;
22 	u32 media_verx100;
23 	struct xe_step_info step;
24 };
25 
26 #define PLATFORM_CASE(platform__, graphics_step__)				\
27 	{									\
28 		.name = #platform__ " (" #graphics_step__ ")",			\
29 		.platform = XE_ ## platform__,					\
30 		.subplatform = XE_SUBPLATFORM_NONE,				\
31 		.step = { .graphics = STEP_ ## graphics_step__ }		\
32 	}
33 
34 
35 #define SUBPLATFORM_CASE(platform__, subplatform__, graphics_step__)			\
36 	{										\
37 		.name = #platform__ "_" #subplatform__ " (" #graphics_step__ ")",	\
38 		.platform = XE_ ## platform__,						\
39 		.subplatform = XE_SUBPLATFORM_ ## platform__ ## _ ## subplatform__,	\
40 		.step = { .graphics = STEP_ ## graphics_step__ }			\
41 	}
42 
43 #define GMDID_CASE(platform__, graphics_verx100__, graphics_step__,		\
44 		   media_verx100__, media_step__)				\
45 	{									\
46 		.name = #platform__ " (g:" #graphics_step__ ", m:" #media_step__ ")",\
47 		.platform = XE_ ## platform__,					\
48 		.subplatform = XE_SUBPLATFORM_NONE,				\
49 		.graphics_verx100 = graphics_verx100__,				\
50 		.media_verx100 = media_verx100__,				\
51 		.step = { .graphics = STEP_ ## graphics_step__,			\
52 			   .media = STEP_ ## media_step__ }			\
53 	}
54 
55 static const struct platform_test_case cases[] = {
56 	PLATFORM_CASE(TIGERLAKE, B0),
57 	PLATFORM_CASE(DG1, A0),
58 	PLATFORM_CASE(DG1, B0),
59 	PLATFORM_CASE(ALDERLAKE_S, A0),
60 	PLATFORM_CASE(ALDERLAKE_S, B0),
61 	PLATFORM_CASE(ALDERLAKE_S, C0),
62 	PLATFORM_CASE(ALDERLAKE_S, D0),
63 	PLATFORM_CASE(ALDERLAKE_P, A0),
64 	PLATFORM_CASE(ALDERLAKE_P, B0),
65 	PLATFORM_CASE(ALDERLAKE_P, C0),
66 	SUBPLATFORM_CASE(ALDERLAKE_S, RPLS, D0),
67 	SUBPLATFORM_CASE(ALDERLAKE_P, RPLU, E0),
68 	SUBPLATFORM_CASE(DG2, G10, A0),
69 	SUBPLATFORM_CASE(DG2, G10, A1),
70 	SUBPLATFORM_CASE(DG2, G10, B0),
71 	SUBPLATFORM_CASE(DG2, G10, C0),
72 	SUBPLATFORM_CASE(DG2, G11, A0),
73 	SUBPLATFORM_CASE(DG2, G11, B0),
74 	SUBPLATFORM_CASE(DG2, G11, B1),
75 	SUBPLATFORM_CASE(DG2, G12, A0),
76 	SUBPLATFORM_CASE(DG2, G12, A1),
77 	PLATFORM_CASE(PVC, B0),
78 	PLATFORM_CASE(PVC, B1),
79 	PLATFORM_CASE(PVC, C0),
80 	GMDID_CASE(METEORLAKE, 1270, A0, 1300, A0),
81 	GMDID_CASE(METEORLAKE, 1271, A0, 1300, A0),
82 	GMDID_CASE(LUNARLAKE, 2004, A0, 2000, A0),
83 	GMDID_CASE(LUNARLAKE, 2004, B0, 2000, A0),
84 };
85 
86 static void platform_desc(const struct platform_test_case *t, char *desc)
87 {
88 	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
89 }
90 
91 KUNIT_ARRAY_PARAM(platform, cases, platform_desc);
92 
93 static int xe_wa_test_init(struct kunit *test)
94 {
95 	const struct platform_test_case *param = test->param_value;
96 	struct xe_pci_fake_data data = {
97 		.platform = param->platform,
98 		.subplatform = param->subplatform,
99 		.graphics_verx100 = param->graphics_verx100,
100 		.media_verx100 = param->media_verx100,
101 		.graphics_step = param->step.graphics,
102 		.media_step = param->step.media,
103 	};
104 	struct xe_device *xe;
105 	struct device *dev;
106 	int ret;
107 
108 	dev = drm_kunit_helper_alloc_device(test);
109 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
110 
111 	xe = drm_kunit_helper_alloc_drm_device(test, dev,
112 					       struct xe_device,
113 					       drm, DRIVER_GEM);
114 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe);
115 
116 	test->priv = &data;
117 	ret = xe_pci_fake_device_init(xe);
118 	KUNIT_ASSERT_EQ(test, ret, 0);
119 
120 	if (!param->graphics_verx100)
121 		xe->info.step = param->step;
122 
123 	/* TODO: init hw engines for engine/LRC WAs */
124 	xe->drm.dev = dev;
125 	test->priv = xe;
126 
127 	return 0;
128 }
129 
130 static void xe_wa_test_exit(struct kunit *test)
131 {
132 	struct xe_device *xe = test->priv;
133 
134 	drm_kunit_helper_free_device(test, xe->drm.dev);
135 }
136 
137 static void xe_wa_gt(struct kunit *test)
138 {
139 	struct xe_device *xe = test->priv;
140 	struct xe_gt *gt;
141 	int id;
142 
143 	for_each_gt(gt, xe, id) {
144 		xe_reg_sr_init(&gt->reg_sr, "GT", xe);
145 
146 		xe_wa_process_gt(gt);
147 		xe_tuning_process_gt(gt);
148 
149 		KUNIT_ASSERT_EQ(test, gt->reg_sr.errors, 0);
150 	}
151 }
152 
153 static struct kunit_case xe_wa_tests[] = {
154 	KUNIT_CASE_PARAM(xe_wa_gt, platform_gen_params),
155 	{}
156 };
157 
158 static struct kunit_suite xe_rtp_test_suite = {
159 	.name = "xe_wa",
160 	.init = xe_wa_test_init,
161 	.exit = xe_wa_test_exit,
162 	.test_cases = xe_wa_tests,
163 };
164 
165 kunit_test_suite(xe_rtp_test_suite);
166 
167 MODULE_AUTHOR("Intel Corporation");
168 MODULE_LICENSE("GPL");
169 MODULE_DESCRIPTION("xe_wa kunit test");
170 MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
171