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