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_platform_get - Determine platform-level stepping from PCI revid 113 * @platform: The Xe platform 114 * @revid: The PCI revid 115 * @step: Pointer to the step struct to update 116 * 117 * Convert the PCI revid into a platform-level stepping value and store that 118 * in @step->platform. 119 */ 120 void xe_step_platform_get(enum xe_platform platform, u8 revid, struct xe_step_info *step) 121 { 122 /* 123 * Not all platforms map PCI revid directly into our symbolic stepping 124 * enumeration. Some platforms will have a single PCI revid used for a 125 * range platform level steppings and some might even require specific 126 * mappings. So prefer to err on the side of caution and include only 127 * the platforms from which we need the stepping info for workaround 128 * checks. 129 */ 130 131 if (platform == XE_NOVALAKE_P) 132 step->platform = STEP_A0 + revid; 133 } 134 135 /** 136 * xe_step_pre_gmdid_get - Determine IP steppings from PCI revid 137 * @xe: Xe device 138 * @step: Pointer to the step struct to update 139 * 140 * Convert the PCI revid into proper IP steppings and update @step->basedie, 141 * @step->graphics and @step->media accordingly. 142 * 143 * This should only be used on platforms that do not have GMD_ID support. 144 */ 145 void xe_step_pre_gmdid_get(struct xe_device *xe, struct xe_step_info *step) 146 { 147 const struct xe_step_info *revids = NULL; 148 u16 revid = xe->info.revid; 149 int size = 0; 150 const int *basedie_info = NULL; 151 int basedie_size = 0; 152 int baseid = 0; 153 u8 graphics = STEP_NONE; 154 u8 media = STEP_NONE; 155 u8 basedie = STEP_NONE; 156 157 if (xe->info.platform == XE_PVC) { 158 baseid = FIELD_GET(GENMASK(5, 3), xe->info.revid); 159 revid = FIELD_GET(GENMASK(2, 0), xe->info.revid); 160 revids = pvc_revid_step_tbl; 161 size = ARRAY_SIZE(pvc_revid_step_tbl); 162 basedie_info = pvc_basedie_subids; 163 basedie_size = ARRAY_SIZE(pvc_basedie_subids); 164 } else if (xe->info.subplatform == XE_SUBPLATFORM_DG2_G10) { 165 revids = dg2_g10_revid_step_tbl; 166 size = ARRAY_SIZE(dg2_g10_revid_step_tbl); 167 } else if (xe->info.subplatform == XE_SUBPLATFORM_DG2_G11) { 168 revids = dg2_g11_revid_step_tbl; 169 size = ARRAY_SIZE(dg2_g11_revid_step_tbl); 170 } else if (xe->info.subplatform == XE_SUBPLATFORM_DG2_G12) { 171 revids = dg2_g12_revid_step_tbl; 172 size = ARRAY_SIZE(dg2_g12_revid_step_tbl); 173 } else if (xe->info.platform == XE_ALDERLAKE_N) { 174 revids = adln_revids; 175 size = ARRAY_SIZE(adln_revids); 176 } else if (xe->info.subplatform == XE_SUBPLATFORM_ALDERLAKE_S_RPLS) { 177 revids = adls_rpls_revids; 178 size = ARRAY_SIZE(adls_rpls_revids); 179 } else if (xe->info.subplatform == XE_SUBPLATFORM_ALDERLAKE_P_RPLU) { 180 revids = adlp_rpl_revids; 181 size = ARRAY_SIZE(adlp_rpl_revids); 182 } else if (xe->info.platform == XE_ALDERLAKE_P) { 183 revids = adlp_revids; 184 size = ARRAY_SIZE(adlp_revids); 185 } else if (xe->info.platform == XE_ALDERLAKE_S) { 186 revids = adls_revids; 187 size = ARRAY_SIZE(adls_revids); 188 } else if (xe->info.platform == XE_DG1) { 189 revids = dg1_revids; 190 size = ARRAY_SIZE(dg1_revids); 191 } else if (xe->info.platform == XE_TIGERLAKE) { 192 revids = tgl_revids; 193 size = ARRAY_SIZE(tgl_revids); 194 } 195 196 /* Not using the stepping scheme for the platform yet. */ 197 if (!revids) 198 goto done; 199 200 if (revid < size && revids[revid].graphics != STEP_NONE) { 201 graphics = revids[revid].graphics; 202 media = revids[revid].media; 203 basedie = revids[revid].basedie; 204 } else { 205 drm_warn(&xe->drm, "Unknown revid 0x%02x\n", revid); 206 207 /* 208 * If we hit a gap in the revid array, use the information for 209 * the next revid. 210 * 211 * This may be wrong in all sorts of ways, especially if the 212 * steppings in the array are not monotonically increasing, but 213 * it's better than defaulting to 0. 214 */ 215 while (revid < size && revids[revid].graphics == STEP_NONE) 216 revid++; 217 218 if (revid < size) { 219 drm_dbg(&xe->drm, "Using steppings for revid 0x%02x\n", 220 revid); 221 graphics = revids[revid].graphics; 222 media = revids[revid].media; 223 basedie = revids[revid].basedie; 224 } else { 225 drm_dbg(&xe->drm, "Using future steppings\n"); 226 graphics = STEP_FUTURE; 227 } 228 } 229 230 drm_WARN_ON(&xe->drm, graphics == STEP_NONE); 231 232 if (basedie_info && basedie_size) { 233 if (baseid < basedie_size && basedie_info[baseid] != STEP_NONE) { 234 basedie = basedie_info[baseid]; 235 } else { 236 drm_warn(&xe->drm, "Unknown baseid 0x%02x\n", baseid); 237 basedie = STEP_FUTURE; 238 } 239 } 240 241 done: 242 step->graphics = graphics; 243 step->media = media; 244 step->basedie = basedie; 245 } 246 247 /** 248 * xe_step_gmdid_get - Determine IP steppings from GMD_ID revid fields 249 * @xe: Xe device 250 * @graphics_gmdid_revid: value of graphics GMD_ID register's revid field 251 * @media_gmdid_revid: value of media GMD_ID register's revid field 252 * @step: Poninter to the step struct to update. 253 * 254 * Convert the revid fields of the GMD_ID registers into proper IP steppings 255 * and update @step->graphics and @step->media accordingly. 256 * 257 * GMD_ID revid values are currently expected to have consistent meanings on 258 * all platforms: major steppings (A0, B0, etc.) are 4 apart, with minor 259 * steppings (A1, A2, etc.) taking the values in between. 260 */ 261 void xe_step_gmdid_get(struct xe_device *xe, 262 u32 graphics_gmdid_revid, 263 u32 media_gmdid_revid, 264 struct xe_step_info *step) 265 { 266 u8 graphics = STEP_A0 + graphics_gmdid_revid; 267 u8 media = STEP_A0 + media_gmdid_revid; 268 269 if (graphics >= STEP_FUTURE) { 270 graphics = STEP_FUTURE; 271 drm_dbg(&xe->drm, "Graphics GMD_ID revid value %d treated as future stepping\n", 272 graphics_gmdid_revid); 273 } 274 275 if (media >= STEP_FUTURE) { 276 media = STEP_FUTURE; 277 drm_dbg(&xe->drm, "Media GMD_ID revid value %d treated as future stepping\n", 278 media_gmdid_revid); 279 } 280 281 step->graphics = graphics; 282 step->media = media; 283 } 284 285 #define STEP_NAME_CASE(name) \ 286 case STEP_##name: \ 287 return #name; 288 289 const char *xe_step_name(enum intel_step step) 290 { 291 switch (step) { 292 STEP_NAME_LIST(STEP_NAME_CASE); 293 294 default: 295 return "**"; 296 } 297 } 298 EXPORT_SYMBOL_IF_KUNIT(xe_step_name); 299