1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_X86_CPU_DEVICE_ID 3 #define _ASM_X86_CPU_DEVICE_ID 4 5 /* 6 * Can't use <linux/bitfield.h> because it generates expressions that 7 * cannot be used in structure initializers. Bitfield construction 8 * here must match the union in struct cpuinfo_86: 9 * union { 10 * struct { 11 * __u8 x86_model; 12 * __u8 x86; 13 * __u8 x86_vendor; 14 * __u8 x86_reserved; 15 * }; 16 * __u32 x86_vfm; 17 * }; 18 */ 19 #define VFM_MODEL_BIT 0 20 #define VFM_FAMILY_BIT 8 21 #define VFM_VENDOR_BIT 16 22 #define VFM_RSVD_BIT 24 23 24 #define VFM_MODEL_MASK GENMASK(VFM_FAMILY_BIT - 1, VFM_MODEL_BIT) 25 #define VFM_FAMILY_MASK GENMASK(VFM_VENDOR_BIT - 1, VFM_FAMILY_BIT) 26 #define VFM_VENDOR_MASK GENMASK(VFM_RSVD_BIT - 1, VFM_VENDOR_BIT) 27 28 #define VFM_MODEL(vfm) (((vfm) & VFM_MODEL_MASK) >> VFM_MODEL_BIT) 29 #define VFM_FAMILY(vfm) (((vfm) & VFM_FAMILY_MASK) >> VFM_FAMILY_BIT) 30 #define VFM_VENDOR(vfm) (((vfm) & VFM_VENDOR_MASK) >> VFM_VENDOR_BIT) 31 32 #define VFM_MAKE(_vendor, _family, _model) ( \ 33 ((_model) << VFM_MODEL_BIT) | \ 34 ((_family) << VFM_FAMILY_BIT) | \ 35 ((_vendor) << VFM_VENDOR_BIT) \ 36 ) 37 38 /* 39 * Declare drivers belonging to specific x86 CPUs 40 * Similar in spirit to pci_device_id and related PCI functions 41 * 42 * The wildcard initializers are in mod_devicetable.h because 43 * file2alias needs them. Sigh. 44 */ 45 #include <linux/mod_devicetable.h> 46 /* Get the INTEL_FAM* model defines */ 47 #include <asm/intel-family.h> 48 /* And the X86_VENDOR_* ones */ 49 #include <asm/processor.h> 50 51 /* Centaur FAM6 models */ 52 #define X86_CENTAUR_FAM6_C7_A 0xa 53 #define X86_CENTAUR_FAM6_C7_D 0xd 54 #define X86_CENTAUR_FAM6_NANO 0xf 55 56 /* x86_cpu_id::flags */ 57 #define X86_CPU_ID_FLAG_ENTRY_VALID BIT(0) 58 59 #define X86_STEPPINGS(mins, maxs) GENMASK(maxs, mins) 60 /** 61 * X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE - Base macro for CPU matching 62 * @_vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 63 * The name is expanded to X86_VENDOR_@_vendor 64 * @_family: The family number or X86_FAMILY_ANY 65 * @_model: The model number, model constant or X86_MODEL_ANY 66 * @_steppings: Bitmask for steppings, stepping constant or X86_STEPPING_ANY 67 * @_feature: A X86_FEATURE bit or X86_FEATURE_ANY 68 * @_data: Driver specific data or NULL. The internal storage 69 * format is unsigned long. The supplied value, pointer 70 * etc. is casted to unsigned long internally. 71 * 72 * Use only if you need all selectors. Otherwise use one of the shorter 73 * macros of the X86_MATCH_* family. If there is no matching shorthand 74 * macro, consider to add one. If you really need to wrap one of the macros 75 * into another macro at the usage site for good reasons, then please 76 * start this local macro with X86_MATCH to allow easy grepping. 77 */ 78 #define X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(_vendor, _family, _model, \ 79 _steppings, _feature, _data) { \ 80 .vendor = X86_VENDOR_##_vendor, \ 81 .family = _family, \ 82 .model = _model, \ 83 .steppings = _steppings, \ 84 .feature = _feature, \ 85 .flags = X86_CPU_ID_FLAG_ENTRY_VALID, \ 86 .driver_data = (unsigned long) _data \ 87 } 88 89 #define X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(_vendor, _family, _model, \ 90 _steppings, _feature, _data) { \ 91 .vendor = _vendor, \ 92 .family = _family, \ 93 .model = _model, \ 94 .steppings = _steppings, \ 95 .feature = _feature, \ 96 .flags = X86_CPU_ID_FLAG_ENTRY_VALID, \ 97 .driver_data = (unsigned long) _data \ 98 } 99 100 /** 101 * X86_MATCH_VENDOR_FAM_MODEL_FEATURE - Macro for CPU matching 102 * @_vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 103 * The name is expanded to X86_VENDOR_@_vendor 104 * @_family: The family number or X86_FAMILY_ANY 105 * @_model: The model number, model constant or X86_MODEL_ANY 106 * @_feature: A X86_FEATURE bit or X86_FEATURE_ANY 107 * @_data: Driver specific data or NULL. The internal storage 108 * format is unsigned long. The supplied value, pointer 109 * etc. is casted to unsigned long internally. 110 * 111 * The steppings arguments of X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE() is 112 * set to wildcards. 113 */ 114 #define X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family, model, feature, data) \ 115 X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(vendor, family, model, \ 116 X86_STEPPING_ANY, feature, data) 117 118 /** 119 * X86_MATCH_VENDOR_FAM_FEATURE - Macro for matching vendor, family and CPU feature 120 * @vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 121 * The name is expanded to X86_VENDOR_@vendor 122 * @family: The family number or X86_FAMILY_ANY 123 * @feature: A X86_FEATURE bit 124 * @data: Driver specific data or NULL. The internal storage 125 * format is unsigned long. The supplied value, pointer 126 * etc. is casted to unsigned long internally. 127 * 128 * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are 129 * set to wildcards. 130 */ 131 #define X86_MATCH_VENDOR_FAM_FEATURE(vendor, family, feature, data) \ 132 X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family, \ 133 X86_MODEL_ANY, feature, data) 134 135 /** 136 * X86_MATCH_VENDOR_FEATURE - Macro for matching vendor and CPU feature 137 * @vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 138 * The name is expanded to X86_VENDOR_@vendor 139 * @feature: A X86_FEATURE bit 140 * @data: Driver specific data or NULL. The internal storage 141 * format is unsigned long. The supplied value, pointer 142 * etc. is casted to unsigned long internally. 143 * 144 * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are 145 * set to wildcards. 146 */ 147 #define X86_MATCH_VENDOR_FEATURE(vendor, feature, data) \ 148 X86_MATCH_VENDOR_FAM_FEATURE(vendor, X86_FAMILY_ANY, feature, data) 149 150 /** 151 * X86_MATCH_FEATURE - Macro for matching a CPU feature 152 * @feature: A X86_FEATURE bit 153 * @data: Driver specific data or NULL. The internal storage 154 * format is unsigned long. The supplied value, pointer 155 * etc. is casted to unsigned long internally. 156 * 157 * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are 158 * set to wildcards. 159 */ 160 #define X86_MATCH_FEATURE(feature, data) \ 161 X86_MATCH_VENDOR_FEATURE(ANY, feature, data) 162 163 /** 164 * X86_MATCH_VENDOR_FAM_MODEL - Match vendor, family and model 165 * @vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 166 * The name is expanded to X86_VENDOR_@vendor 167 * @family: The family number or X86_FAMILY_ANY 168 * @model: The model number, model constant or X86_MODEL_ANY 169 * @data: Driver specific data or NULL. The internal storage 170 * format is unsigned long. The supplied value, pointer 171 * etc. is casted to unsigned long internally. 172 * 173 * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are 174 * set to wildcards. 175 */ 176 #define X86_MATCH_VENDOR_FAM_MODEL(vendor, family, model, data) \ 177 X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family, model, \ 178 X86_FEATURE_ANY, data) 179 180 /** 181 * X86_MATCH_VENDOR_FAM - Match vendor and family 182 * @vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 183 * The name is expanded to X86_VENDOR_@vendor 184 * @family: The family number or X86_FAMILY_ANY 185 * @data: Driver specific data or NULL. The internal storage 186 * format is unsigned long. The supplied value, pointer 187 * etc. is casted to unsigned long internally. 188 * 189 * All other missing arguments to X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are 190 * set of wildcards. 191 */ 192 #define X86_MATCH_VENDOR_FAM(vendor, family, data) \ 193 X86_MATCH_VENDOR_FAM_MODEL(vendor, family, X86_MODEL_ANY, data) 194 195 /** 196 * X86_MATCH_VFM - Match encoded vendor/family/model 197 * @vfm: Encoded 8-bits each for vendor, family, model 198 * @data: Driver specific data or NULL. The internal storage 199 * format is unsigned long. The supplied value, pointer 200 * etc. is cast to unsigned long internally. 201 * 202 * Stepping and feature are set to wildcards 203 */ 204 #define X86_MATCH_VFM(vfm, data) \ 205 X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE( \ 206 VFM_VENDOR(vfm), \ 207 VFM_FAMILY(vfm), \ 208 VFM_MODEL(vfm), \ 209 X86_STEPPING_ANY, X86_FEATURE_ANY, data) 210 211 /** 212 * X86_MATCH_VFM_STEPPINGS - Match encoded vendor/family/model/stepping 213 * @vfm: Encoded 8-bits each for vendor, family, model 214 * @steppings: Bitmask of steppings to match 215 * @data: Driver specific data or NULL. The internal storage 216 * format is unsigned long. The supplied value, pointer 217 * etc. is cast to unsigned long internally. 218 * 219 * feature is set to wildcard 220 */ 221 #define X86_MATCH_VFM_STEPPINGS(vfm, steppings, data) \ 222 X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE( \ 223 VFM_VENDOR(vfm), \ 224 VFM_FAMILY(vfm), \ 225 VFM_MODEL(vfm), \ 226 steppings, X86_FEATURE_ANY, data) 227 228 /** 229 * X86_MATCH_VFM_FEATURE - Match encoded vendor/family/model/feature 230 * @vfm: Encoded 8-bits each for vendor, family, model 231 * @feature: A X86_FEATURE bit 232 * @data: Driver specific data or NULL. The internal storage 233 * format is unsigned long. The supplied value, pointer 234 * etc. is cast to unsigned long internally. 235 * 236 * Steppings is set to wildcard 237 */ 238 #define X86_MATCH_VFM_FEATURE(vfm, feature, data) \ 239 X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE( \ 240 VFM_VENDOR(vfm), \ 241 VFM_FAMILY(vfm), \ 242 VFM_MODEL(vfm), \ 243 X86_STEPPING_ANY, feature, data) 244 245 /* 246 * Match specific microcode revisions. 247 * 248 * vendor/family/model/stepping must be all set. 249 * 250 * Only checks against the boot CPU. When mixed-stepping configs are 251 * valid for a CPU model, add a quirk for every valid stepping and 252 * do the fine-tuning in the quirk handler. 253 */ 254 255 struct x86_cpu_desc { 256 u8 x86_family; 257 u8 x86_vendor; 258 u8 x86_model; 259 u8 x86_stepping; 260 u32 x86_microcode_rev; 261 }; 262 263 #define INTEL_CPU_DESC(vfm, stepping, revision) { \ 264 .x86_family = VFM_FAMILY(vfm), \ 265 .x86_vendor = VFM_VENDOR(vfm), \ 266 .x86_model = VFM_MODEL(vfm), \ 267 .x86_stepping = (stepping), \ 268 .x86_microcode_rev = (revision), \ 269 } 270 271 #define AMD_CPU_DESC(fam, model, stepping, revision) { \ 272 .x86_family = (fam), \ 273 .x86_vendor = X86_VENDOR_AMD, \ 274 .x86_model = (model), \ 275 .x86_stepping = (stepping), \ 276 .x86_microcode_rev = (revision), \ 277 } 278 279 extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match); 280 extern bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table); 281 282 #endif /* _ASM_X86_CPU_DEVICE_ID */ 283