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