xref: /linux/drivers/gpu/drm/xe/tests/xe_wa_test.c (revision bba2c3615bd6cfee7456d1130f2e6b01b3f4e9ba)
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 	if (!param->graphics_verx100)
47 		xe->info.step = param->step;
48 
49 	/* TODO: init hw engines for engine/LRC WAs */
50 	xe->drm.dev = dev;
51 	test->priv = xe;
52 
53 	return 0;
54 }
55 
56 static void xe_wa_gt(struct kunit *test)
57 {
58 	struct xe_device *xe = test->priv;
59 	struct xe_gt *gt;
60 	int id;
61 
62 	for_each_gt(gt, xe, id) {
63 		xe_reg_sr_init(&gt->reg_sr, "GT", xe);
64 
65 		xe_wa_process_gt(gt);
66 		xe_tuning_process_gt(gt);
67 
68 		KUNIT_EXPECT_EQ(test, gt->reg_sr.errors, 0);
69 	}
70 }
71 
72 static struct kunit_case xe_wa_tests[] = {
73 	KUNIT_CASE_PARAM(xe_wa_gt, xe_pci_fake_data_gen_params),
74 	{}
75 };
76 
77 static struct kunit_suite xe_rtp_test_suite = {
78 	.name = "xe_wa",
79 	.init = xe_wa_test_init,
80 	.test_cases = xe_wa_tests,
81 };
82 
83 kunit_test_suite(xe_rtp_test_suite);
84