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