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 #include <linux/device-id/x86_cpu.h> 43 /* Get the INTEL_FAM* model defines */ 44 #include <asm/intel-family.h> 45 /* And the X86_VENDOR_* ones */ 46 #include <asm/processor.h> 47 48 /* Centaur FAM6 models */ 49 #define X86_CENTAUR_FAM6_C7_A 0xa 50 #define X86_CENTAUR_FAM6_C7_D 0xd 51 #define X86_CENTAUR_FAM6_NANO 0xf 52 53 /* x86_cpu_id::flags */ 54 #define X86_CPU_ID_FLAG_ENTRY_VALID BIT(0) 55 56 /** 57 * X86_MATCH_CPU - Base macro for CPU matching 58 * @_vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 59 * The name is expanded to X86_VENDOR_@_vendor 60 * @_family: The family number or X86_FAMILY_ANY 61 * @_model: The model number, model constant or X86_MODEL_ANY 62 * @_steppings: Bitmask for steppings, stepping constant or X86_STEPPING_ANY 63 * @_feature: A X86_FEATURE bit or X86_FEATURE_ANY 64 * @_data: Driver specific data or NULL. The internal storage 65 * format is unsigned long. The supplied value, pointer 66 * etc. is casted to unsigned long internally. 67 * 68 * Use only if you need all selectors. Otherwise use one of the shorter 69 * macros of the X86_MATCH_* family. If there is no matching shorthand 70 * macro, consider to add one. If you really need to wrap one of the macros 71 * into another macro at the usage site for good reasons, then please 72 * start this local macro with X86_MATCH to allow easy grepping. 73 */ 74 #define X86_MATCH_CPU(_vendor, _family, _model, _steppings, _feature, _type, _data) { \ 75 .vendor = _vendor, \ 76 .family = _family, \ 77 .model = _model, \ 78 .steppings = _steppings, \ 79 .feature = _feature, \ 80 .flags = X86_CPU_ID_FLAG_ENTRY_VALID, \ 81 .type = _type, \ 82 .driver_data = (unsigned long) _data \ 83 } 84 85 /** 86 * X86_MATCH_VENDOR_FAM_FEATURE - Macro for matching vendor, family and CPU feature 87 * @vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 88 * The name is expanded to X86_VENDOR_@vendor 89 * @family: The family number or X86_FAMILY_ANY 90 * @feature: A X86_FEATURE bit 91 * @data: Driver specific data or NULL. The internal storage 92 * format is unsigned long. The supplied value, pointer 93 * etc. is casted to unsigned long internally. 94 */ 95 #define X86_MATCH_VENDOR_FAM_FEATURE(vendor, family, feature, data) \ 96 X86_MATCH_CPU(X86_VENDOR_##vendor, family, X86_MODEL_ANY, \ 97 X86_STEPPING_ANY, feature, X86_CPU_TYPE_ANY, data) 98 99 /** 100 * X86_MATCH_VENDOR_FEATURE - Macro for matching vendor and CPU feature 101 * @vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 102 * The name is expanded to X86_VENDOR_@vendor 103 * @feature: A X86_FEATURE bit 104 * @data: Driver specific data or NULL. The internal storage 105 * format is unsigned long. The supplied value, pointer 106 * etc. is casted to unsigned long internally. 107 */ 108 #define X86_MATCH_VENDOR_FEATURE(vendor, feature, data) \ 109 X86_MATCH_CPU(X86_VENDOR_##vendor, X86_FAMILY_ANY, X86_MODEL_ANY, \ 110 X86_STEPPING_ANY, feature, X86_CPU_TYPE_ANY, data) 111 112 /** 113 * X86_MATCH_FEATURE - Macro for matching a CPU feature 114 * @feature: A X86_FEATURE bit 115 * @data: Driver specific data or NULL. The internal storage 116 * format is unsigned long. The supplied value, pointer 117 * etc. is casted to unsigned long internally. 118 */ 119 #define X86_MATCH_FEATURE(feature, data) \ 120 X86_MATCH_CPU(X86_VENDOR_ANY, X86_FAMILY_ANY, X86_MODEL_ANY, \ 121 X86_STEPPING_ANY, feature, X86_CPU_TYPE_ANY, data) 122 123 /** 124 * X86_MATCH_VENDOR_FAM_MODEL - Match vendor, family and model 125 * @vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 126 * The name is expanded to X86_VENDOR_@vendor 127 * @family: The family number or X86_FAMILY_ANY 128 * @model: The model number, model constant or X86_MODEL_ANY 129 * @data: Driver specific data or NULL. The internal storage 130 * format is unsigned long. The supplied value, pointer 131 * etc. is casted to unsigned long internally. 132 */ 133 #define X86_MATCH_VENDOR_FAM_MODEL(vendor, family, model, data) \ 134 X86_MATCH_CPU(X86_VENDOR_##vendor, family, model, X86_STEPPING_ANY, \ 135 X86_FEATURE_ANY, X86_CPU_TYPE_ANY, data) 136 137 /** 138 * X86_MATCH_VENDOR_FAM - Match vendor and family 139 * @vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY 140 * The name is expanded to X86_VENDOR_@vendor 141 * @family: The family number or X86_FAMILY_ANY 142 * @data: Driver specific data or NULL. The internal storage 143 * format is unsigned long. The supplied value, pointer 144 * etc. is casted to unsigned long internally. 145 */ 146 #define X86_MATCH_VENDOR_FAM(vendor, family, data) \ 147 X86_MATCH_CPU(X86_VENDOR_##vendor, family, X86_MODEL_ANY, \ 148 X86_STEPPING_ANY, X86_FEATURE_ANY, X86_CPU_TYPE_ANY, data) 149 150 /** 151 * X86_MATCH_VFM - Match encoded vendor/family/model 152 * @vfm: Encoded 8-bits each for vendor, family, model 153 * @data: Driver specific data or NULL. The internal storage 154 * format is unsigned long. The supplied value, pointer 155 * etc. is cast to unsigned long internally. 156 */ 157 #define X86_MATCH_VFM(vfm, data) \ 158 X86_MATCH_CPU(VFM_VENDOR(vfm), VFM_FAMILY(vfm), VFM_MODEL(vfm), \ 159 X86_STEPPING_ANY, X86_FEATURE_ANY, X86_CPU_TYPE_ANY, data) 160 161 #define __X86_STEPPINGS(mins, maxs) GENMASK(maxs, mins) 162 /** 163 * X86_MATCH_VFM_STEPS - Match encoded vendor/family/model and steppings 164 * range. 165 * @vfm: Encoded 8-bits each for vendor, family, model 166 * @min_step: Lowest stepping number to match 167 * @max_step: Highest stepping number to match 168 * @data: Driver specific data or NULL. The internal storage 169 * format is unsigned long. The supplied value, pointer 170 * etc. is cast to unsigned long internally. 171 */ 172 #define X86_MATCH_VFM_STEPS(vfm, min_step, max_step, data) \ 173 X86_MATCH_CPU(VFM_VENDOR(vfm), VFM_FAMILY(vfm), VFM_MODEL(vfm), \ 174 __X86_STEPPINGS(min_step, max_step), X86_FEATURE_ANY, \ 175 X86_CPU_TYPE_ANY, data) 176 177 /** 178 * X86_MATCH_VFM_FEATURE - Match encoded vendor/family/model/feature 179 * @vfm: Encoded 8-bits each for vendor, family, model 180 * @feature: A X86_FEATURE bit 181 * @data: Driver specific data or NULL. The internal storage 182 * format is unsigned long. The supplied value, pointer 183 * etc. is cast to unsigned long internally. 184 */ 185 #define X86_MATCH_VFM_FEATURE(vfm, feature, data) \ 186 X86_MATCH_CPU(VFM_VENDOR(vfm), VFM_FAMILY(vfm), VFM_MODEL(vfm), \ 187 X86_STEPPING_ANY, feature, X86_CPU_TYPE_ANY, data) 188 189 /** 190 * X86_MATCH_VFM_CPU_TYPE - Match encoded vendor/family/model/type 191 * @vfm: Encoded 8-bits each for vendor, family, model 192 * @type: CPU type e.g. P-core, E-core 193 * @data: Driver specific data or NULL. The internal storage 194 * format is unsigned long. The supplied value, pointer 195 * etc. is cast to unsigned long internally. 196 */ 197 #define X86_MATCH_VFM_CPU_TYPE(vfm, type, data) \ 198 X86_MATCH_CPU(VFM_VENDOR(vfm), VFM_FAMILY(vfm), VFM_MODEL(vfm), \ 199 X86_STEPPING_ANY, X86_FEATURE_ANY, type, data) 200 201 extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match); 202 extern bool x86_match_min_microcode_rev(const struct x86_cpu_id *table); 203 204 #endif /* _ASM_X86_CPU_DEVICE_ID */ 205