1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2022 Intel Corporation 4 */ 5 6 #include "xe_step.h" 7 8 #include <drm/drm_print.h> 9 #include <kunit/visibility.h> 10 #include <linux/bitfield.h> 11 12 #include "xe_device_types.h" 13 #include "xe_platform_types.h" 14 15 /* 16 * Provide mapping between PCI's revision ID to the individual GMD 17 * (Graphics/Media/Display) stepping values that can be compared numerically. 18 * 19 * Some platforms may have unusual ways of mapping PCI revision ID to GMD 20 * steppings. E.g., in some cases a higher PCI revision may translate to a 21 * lower stepping of the GT and/or display IP. 22 * 23 * Also note that some revisions/steppings may have been set aside as 24 * placeholders but never materialized in real hardware; in those cases there 25 * may be jumps in the revision IDs or stepping values in the tables below. 26 */ 27 28 /* 29 * Some platforms always have the same stepping value for GT and display; 30 * use a macro to define these to make it easier to identify the platforms 31 * where the two steppings can deviate. 32 */ 33 #define COMMON_STEP(x_) \ 34 .graphics = STEP_##x_, \ 35 .media = STEP_##x_ 36 37 __diag_push(); 38 __diag_ignore_all("-Woverride-init", "Allow field overrides in table"); 39 40 /* Same GT stepping between tgl_uy_revids and tgl_revids don't mean the same HW */ 41 static const struct xe_step_info tgl_revids[] = { 42 [0] = { COMMON_STEP(A0) }, 43 [1] = { COMMON_STEP(B0) }, 44 }; 45 46 static const struct xe_step_info dg1_revids[] = { 47 [0] = { COMMON_STEP(A0) }, 48 [1] = { COMMON_STEP(B0) }, 49 }; 50 51 static const struct xe_step_info adls_revids[] = { 52 [0x0] = { COMMON_STEP(A0) }, 53 [0x1] = { COMMON_STEP(A0) }, 54 [0x4] = { COMMON_STEP(B0) }, 55 [0x8] = { COMMON_STEP(C0) }, 56 [0xC] = { COMMON_STEP(D0) }, 57 }; 58 59 static const struct xe_step_info adls_rpls_revids[] = { 60 [0x4] = { COMMON_STEP(D0) }, 61 [0xC] = { COMMON_STEP(D0) }, 62 }; 63 64 static const struct xe_step_info adlp_revids[] = { 65 [0x0] = { COMMON_STEP(A0) }, 66 [0x4] = { COMMON_STEP(B0) }, 67 [0x8] = { COMMON_STEP(C0) }, 68 [0xC] = { COMMON_STEP(C0) }, 69 }; 70 71 static const struct xe_step_info adlp_rpl_revids[] = { 72 [0x4] = { COMMON_STEP(C0) }, 73 }; 74 75 static const struct xe_step_info adln_revids[] = { 76 [0x0] = { COMMON_STEP(A0) }, 77 }; 78 79 static const struct xe_step_info dg2_g10_revid_step_tbl[] = { 80 [0x0] = { COMMON_STEP(A0) }, 81 [0x1] = { COMMON_STEP(A1) }, 82 [0x4] = { COMMON_STEP(B0) }, 83 [0x8] = { COMMON_STEP(C0) }, 84 }; 85 86 static const struct xe_step_info dg2_g11_revid_step_tbl[] = { 87 [0x0] = { COMMON_STEP(A0) }, 88 [0x4] = { COMMON_STEP(B0) }, 89 [0x5] = { COMMON_STEP(B1) }, 90 }; 91 92 static const struct xe_step_info dg2_g12_revid_step_tbl[] = { 93 [0x0] = { COMMON_STEP(A0) }, 94 [0x1] = { COMMON_STEP(A1) }, 95 }; 96 97 static const struct xe_step_info pvc_revid_step_tbl[] = { 98 [0x5] = { .graphics = STEP_B0 }, 99 [0x6] = { .graphics = STEP_B1 }, 100 [0x7] = { .graphics = STEP_C0 }, 101 }; 102 103 static const int pvc_basedie_subids[] = { 104 [0x3] = STEP_B0, 105 [0x4] = STEP_B1, 106 [0x5] = STEP_B3, 107 }; 108 109 __diag_pop(); 110 111 /** 112 * xe_step_pre_gmdid_get - Determine IP steppings from PCI revid 113 * @xe: Xe device 114 * 115 * Convert the PCI revid into proper IP steppings. This should only be 116 * used on platforms that do not have GMD_ID support. 117 */ 118 struct xe_step_info xe_step_pre_gmdid_get(struct xe_device *xe) 119 { 120 const struct xe_step_info *revids = NULL; 121 struct xe_step_info step = {}; 122 u16 revid = xe->info.revid; 123 int size = 0; 124 const int *basedie_info = NULL; 125 int basedie_size = 0; 126 int baseid = 0; 127 128 if (xe->info.platform == XE_PVC) { 129 baseid = FIELD_GET(GENMASK(5, 3), xe->info.revid); 130 revid = FIELD_GET(GENMASK(2, 0), xe->info.revid); 131 revids = pvc_revid_step_tbl; 132 size = ARRAY_SIZE(pvc_revid_step_tbl); 133 basedie_info = pvc_basedie_subids; 134 basedie_size = ARRAY_SIZE(pvc_basedie_subids); 135 } else if (xe->info.subplatform == XE_SUBPLATFORM_DG2_G10) { 136 revids = dg2_g10_revid_step_tbl; 137 size = ARRAY_SIZE(dg2_g10_revid_step_tbl); 138 } else if (xe->info.subplatform == XE_SUBPLATFORM_DG2_G11) { 139 revids = dg2_g11_revid_step_tbl; 140 size = ARRAY_SIZE(dg2_g11_revid_step_tbl); 141 } else if (xe->info.subplatform == XE_SUBPLATFORM_DG2_G12) { 142 revids = dg2_g12_revid_step_tbl; 143 size = ARRAY_SIZE(dg2_g12_revid_step_tbl); 144 } else if (xe->info.platform == XE_ALDERLAKE_N) { 145 revids = adln_revids; 146 size = ARRAY_SIZE(adln_revids); 147 } else if (xe->info.subplatform == XE_SUBPLATFORM_ALDERLAKE_S_RPLS) { 148 revids = adls_rpls_revids; 149 size = ARRAY_SIZE(adls_rpls_revids); 150 } else if (xe->info.subplatform == XE_SUBPLATFORM_ALDERLAKE_P_RPLU) { 151 revids = adlp_rpl_revids; 152 size = ARRAY_SIZE(adlp_rpl_revids); 153 } else if (xe->info.platform == XE_ALDERLAKE_P) { 154 revids = adlp_revids; 155 size = ARRAY_SIZE(adlp_revids); 156 } else if (xe->info.platform == XE_ALDERLAKE_S) { 157 revids = adls_revids; 158 size = ARRAY_SIZE(adls_revids); 159 } else if (xe->info.platform == XE_DG1) { 160 revids = dg1_revids; 161 size = ARRAY_SIZE(dg1_revids); 162 } else if (xe->info.platform == XE_TIGERLAKE) { 163 revids = tgl_revids; 164 size = ARRAY_SIZE(tgl_revids); 165 } 166 167 /* Not using the stepping scheme for the platform yet. */ 168 if (!revids) 169 return step; 170 171 if (revid < size && revids[revid].graphics != STEP_NONE) { 172 step = revids[revid]; 173 } else { 174 drm_warn(&xe->drm, "Unknown revid 0x%02x\n", revid); 175 176 /* 177 * If we hit a gap in the revid array, use the information for 178 * the next revid. 179 * 180 * This may be wrong in all sorts of ways, especially if the 181 * steppings in the array are not monotonically increasing, but 182 * it's better than defaulting to 0. 183 */ 184 while (revid < size && revids[revid].graphics == STEP_NONE) 185 revid++; 186 187 if (revid < size) { 188 drm_dbg(&xe->drm, "Using steppings for revid 0x%02x\n", 189 revid); 190 step = revids[revid]; 191 } else { 192 drm_dbg(&xe->drm, "Using future steppings\n"); 193 step.graphics = STEP_FUTURE; 194 } 195 } 196 197 drm_WARN_ON(&xe->drm, step.graphics == STEP_NONE); 198 199 if (basedie_info && basedie_size) { 200 if (baseid < basedie_size && basedie_info[baseid] != STEP_NONE) { 201 step.basedie = basedie_info[baseid]; 202 } else { 203 drm_warn(&xe->drm, "Unknown baseid 0x%02x\n", baseid); 204 step.basedie = STEP_FUTURE; 205 } 206 } 207 208 return step; 209 } 210 211 /** 212 * xe_step_gmdid_get - Determine IP steppings from GMD_ID revid fields 213 * @xe: Xe device 214 * @graphics_gmdid_revid: value of graphics GMD_ID register's revid field 215 * @media_gmdid_revid: value of media GMD_ID register's revid field 216 * 217 * Convert the revid fields of the GMD_ID registers into proper IP steppings. 218 * 219 * GMD_ID revid values are currently expected to have consistent meanings on 220 * all platforms: major steppings (A0, B0, etc.) are 4 apart, with minor 221 * steppings (A1, A2, etc.) taking the values in between. 222 */ 223 struct xe_step_info xe_step_gmdid_get(struct xe_device *xe, 224 u32 graphics_gmdid_revid, 225 u32 media_gmdid_revid) 226 { 227 struct xe_step_info step = { 228 .graphics = STEP_A0 + graphics_gmdid_revid, 229 .media = STEP_A0 + media_gmdid_revid, 230 }; 231 232 if (step.graphics >= STEP_FUTURE) { 233 step.graphics = STEP_FUTURE; 234 drm_dbg(&xe->drm, "Graphics GMD_ID revid value %d treated as future stepping\n", 235 graphics_gmdid_revid); 236 } 237 238 if (step.media >= STEP_FUTURE) { 239 step.media = STEP_FUTURE; 240 drm_dbg(&xe->drm, "Media GMD_ID revid value %d treated as future stepping\n", 241 media_gmdid_revid); 242 } 243 244 return step; 245 } 246 247 #define STEP_NAME_CASE(name) \ 248 case STEP_##name: \ 249 return #name; 250 251 const char *xe_step_name(enum xe_step step) 252 { 253 switch (step) { 254 STEP_NAME_LIST(STEP_NAME_CASE); 255 256 default: 257 return "**"; 258 } 259 } 260 EXPORT_SYMBOL_IF_KUNIT(xe_step_name); 261