xref: /linux/drivers/gpu/drm/xe/tests/xe_wa_test.c (revision 18fbf5151d2c0bfe433c7428eef03cabf5fdb2fa)
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_gt.h"
13 #include "xe_gt_mcr.h"
14 #include "xe_kunit_helpers.h"
15 #include "xe_pci_test.h"
16 #include "xe_reg_sr.h"
17 #include "xe_tuning.h"
18 #include "xe_wa.h"
19 
20 static int xe_wa_test_init(struct kunit *test)
21 {
22 	const struct xe_pci_fake_data *param = test->param_value;
23 	struct xe_pci_fake_data data = *param;
24 	struct device *dev;
25 	struct xe_device *xe;
26 	struct xe_gt *gt;
27 	int id;
28 	int ret;
29 
30 	dev = drm_kunit_helper_alloc_device(test);
31 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
32 
33 	xe = xe_kunit_helper_alloc_xe_device(test, dev);
34 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, xe);
35 
36 	test->priv = &data;
37 	ret = xe_pci_fake_device_init(xe);
38 	KUNIT_ASSERT_EQ(test, ret, 0);
39 
40 	/* Needed for sanitize_mcr(). */
41 	for_each_gt(gt, xe, id) {
42 		xe_gt_mcr_init_early(gt);
43 		xe_gt_mmio_init(gt);
44 	}
45 
46 	/* TODO: init hw engines for engine/LRC WAs */
47 	xe->drm.dev = dev;
48 	test->priv = xe;
49 
50 	return 0;
51 }
52 
53 static void xe_wa_gt(struct kunit *test)
54 {
55 	struct xe_device *xe = test->priv;
56 	struct xe_gt *gt;
57 	int id;
58 
59 	for_each_gt(gt, xe, id) {
60 		xe_reg_sr_init(&gt->reg_sr, "GT", xe);
61 
62 		xe_wa_process_gt(gt);
63 		xe_tuning_process_gt(gt);
64 
65 		KUNIT_EXPECT_EQ(test, gt->reg_sr.errors, 0);
66 	}
67 }
68 
69 static struct kunit_case xe_wa_tests[] = {
70 	KUNIT_CASE_PARAM(xe_wa_gt, xe_pci_fake_data_gen_params),
71 	{}
72 };
73 
74 static struct kunit_suite xe_rtp_test_suite = {
75 	.name = "xe_wa",
76 	.init = xe_wa_test_init,
77 	.test_cases = xe_wa_tests,
78 };
79 
80 kunit_test_suite(xe_rtp_test_suite);
81