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
18struct 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
56static 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(LUNARLAKE, 2004, A0, 2000, A0),
75	GMDID_CASE(LUNARLAKE, 2004, B0, 2000, A0),
76};
77
78static void platform_desc(const struct platform_test_case *t, char *desc)
79{
80	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
81}
82
83KUNIT_ARRAY_PARAM(platform, cases, platform_desc);
84
85static int xe_wa_test_init(struct kunit *test)
86{
87	const struct platform_test_case *param = test->param_value;
88	struct xe_pci_fake_data data = {
89		.platform = param->platform,
90		.subplatform = param->subplatform,
91		.graphics_verx100 = param->graphics_verx100,
92		.media_verx100 = param->media_verx100,
93		.graphics_step = param->step.graphics,
94		.media_step = param->step.media,
95	};
96	struct xe_device *xe;
97	struct device *dev;
98	int ret;
99
100	dev = drm_kunit_helper_alloc_device(test);
101	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
102
103	xe = xe_kunit_helper_alloc_xe_device(test, dev);
104	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe);
105
106	test->priv = &data;
107	ret = xe_pci_fake_device_init(xe);
108	KUNIT_ASSERT_EQ(test, ret, 0);
109
110	if (!param->graphics_verx100)
111		xe->info.step = param->step;
112
113	/* TODO: init hw engines for engine/LRC WAs */
114	xe->drm.dev = dev;
115	test->priv = xe;
116
117	return 0;
118}
119
120static void xe_wa_test_exit(struct kunit *test)
121{
122	struct xe_device *xe = test->priv;
123
124	drm_kunit_helper_free_device(test, xe->drm.dev);
125}
126
127static void xe_wa_gt(struct kunit *test)
128{
129	struct xe_device *xe = test->priv;
130	struct xe_gt *gt;
131	int id;
132
133	for_each_gt(gt, xe, id) {
134		xe_reg_sr_init(&gt->reg_sr, "GT", xe);
135
136		xe_wa_process_gt(gt);
137		xe_tuning_process_gt(gt);
138
139		KUNIT_ASSERT_EQ(test, gt->reg_sr.errors, 0);
140	}
141}
142
143static struct kunit_case xe_wa_tests[] = {
144	KUNIT_CASE_PARAM(xe_wa_gt, platform_gen_params),
145	{}
146};
147
148static struct kunit_suite xe_rtp_test_suite = {
149	.name = "xe_wa",
150	.init = xe_wa_test_init,
151	.exit = xe_wa_test_exit,
152	.test_cases = xe_wa_tests,
153};
154
155kunit_test_suite(xe_rtp_test_suite);
156