xref: /linux/arch/x86/include/asm/cpu_device_id.h (revision ffcaa2172cc1a85ddb8b783de96d38ca8855e248)
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 #define X86_STEPPINGS(mins, maxs)    GENMASK(maxs, mins)
57 /**
58  * X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE - Base macro for CPU matching
59  * @_vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
60  *		The name is expanded to X86_VENDOR_@_vendor
61  * @_family:	The family number or X86_FAMILY_ANY
62  * @_model:	The model number, model constant or X86_MODEL_ANY
63  * @_steppings:	Bitmask for steppings, stepping constant or X86_STEPPING_ANY
64  * @_feature:	A X86_FEATURE bit or X86_FEATURE_ANY
65  * @_data:	Driver specific data or NULL. The internal storage
66  *		format is unsigned long. The supplied value, pointer
67  *		etc. is casted to unsigned long internally.
68  *
69  * Use only if you need all selectors. Otherwise use one of the shorter
70  * macros of the X86_MATCH_* family. If there is no matching shorthand
71  * macro, consider to add one. If you really need to wrap one of the macros
72  * into another macro at the usage site for good reasons, then please
73  * start this local macro with X86_MATCH to allow easy grepping.
74  */
75 #define X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(_vendor, _family, _model, \
76 						    _steppings, _feature, _data) { \
77 	.vendor		= X86_VENDOR_##_vendor,				\
78 	.family		= _family,					\
79 	.model		= _model,					\
80 	.steppings	= _steppings,					\
81 	.feature	= _feature,					\
82 	.driver_data	= (unsigned long) _data				\
83 }
84 
85 #define X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(_vendor, _family, _model, \
86 						    _steppings, _feature, _data) { \
87 	.vendor		= _vendor,					\
88 	.family		= _family,					\
89 	.model		= _model,					\
90 	.steppings	= _steppings,					\
91 	.feature	= _feature,					\
92 	.driver_data	= (unsigned long) _data				\
93 }
94 
95 /**
96  * X86_MATCH_VENDOR_FAM_MODEL_FEATURE - Macro for CPU matching
97  * @_vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
98  *		The name is expanded to X86_VENDOR_@_vendor
99  * @_family:	The family number or X86_FAMILY_ANY
100  * @_model:	The model number, model constant or X86_MODEL_ANY
101  * @_feature:	A X86_FEATURE bit or X86_FEATURE_ANY
102  * @_data:	Driver specific data or NULL. The internal storage
103  *		format is unsigned long. The supplied value, pointer
104  *		etc. is casted to unsigned long internally.
105  *
106  * The steppings arguments of X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE() is
107  * set to wildcards.
108  */
109 #define X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family, model, feature, data) \
110 	X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(vendor, family, model, \
111 						X86_STEPPING_ANY, feature, data)
112 
113 /**
114  * X86_MATCH_VENDOR_FAM_FEATURE - Macro for matching vendor, family and CPU feature
115  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
116  *		The name is expanded to X86_VENDOR_@vendor
117  * @family:	The family number or X86_FAMILY_ANY
118  * @feature:	A X86_FEATURE bit
119  * @data:	Driver specific data or NULL. The internal storage
120  *		format is unsigned long. The supplied value, pointer
121  *		etc. is casted to unsigned long internally.
122  *
123  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
124  * set to wildcards.
125  */
126 #define X86_MATCH_VENDOR_FAM_FEATURE(vendor, family, feature, data)	\
127 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family,		\
128 					   X86_MODEL_ANY, feature, data)
129 
130 /**
131  * X86_MATCH_VENDOR_FEATURE - Macro for matching vendor and CPU feature
132  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
133  *		The name is expanded to X86_VENDOR_@vendor
134  * @feature:	A X86_FEATURE bit
135  * @data:	Driver specific data or NULL. The internal storage
136  *		format is unsigned long. The supplied value, pointer
137  *		etc. is casted to unsigned long internally.
138  *
139  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
140  * set to wildcards.
141  */
142 #define X86_MATCH_VENDOR_FEATURE(vendor, feature, data)			\
143 	X86_MATCH_VENDOR_FAM_FEATURE(vendor, X86_FAMILY_ANY, feature, data)
144 
145 /**
146  * X86_MATCH_FEATURE - Macro for matching a CPU feature
147  * @feature:	A X86_FEATURE bit
148  * @data:	Driver specific data or NULL. The internal storage
149  *		format is unsigned long. The supplied value, pointer
150  *		etc. is casted to unsigned long internally.
151  *
152  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
153  * set to wildcards.
154  */
155 #define X86_MATCH_FEATURE(feature, data)				\
156 	X86_MATCH_VENDOR_FEATURE(ANY, feature, data)
157 
158 /**
159  * X86_MATCH_VENDOR_FAM_MODEL - Match vendor, family and model
160  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
161  *		The name is expanded to X86_VENDOR_@vendor
162  * @family:	The family number or X86_FAMILY_ANY
163  * @model:	The model number, model constant or X86_MODEL_ANY
164  * @data:	Driver specific data or NULL. The internal storage
165  *		format is unsigned long. The supplied value, pointer
166  *		etc. is casted to unsigned long internally.
167  *
168  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
169  * set to wildcards.
170  */
171 #define X86_MATCH_VENDOR_FAM_MODEL(vendor, family, model, data)		\
172 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family, model,	\
173 					   X86_FEATURE_ANY, data)
174 
175 /**
176  * X86_MATCH_VENDOR_FAM - Match vendor and family
177  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
178  *		The name is expanded to X86_VENDOR_@vendor
179  * @family:	The family number or X86_FAMILY_ANY
180  * @data:	Driver specific data or NULL. The internal storage
181  *		format is unsigned long. The supplied value, pointer
182  *		etc. is casted to unsigned long internally.
183  *
184  * All other missing arguments to X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
185  * set of wildcards.
186  */
187 #define X86_MATCH_VENDOR_FAM(vendor, family, data)			\
188 	X86_MATCH_VENDOR_FAM_MODEL(vendor, family, X86_MODEL_ANY, data)
189 
190 /**
191  * X86_MATCH_INTEL_FAM6_MODEL - Match vendor INTEL, family 6 and model
192  * @model:	The model name without the INTEL_FAM6_ prefix or ANY
193  *		The model name is expanded to INTEL_FAM6_@model internally
194  * @data:	Driver specific data or NULL. The internal storage
195  *		format is unsigned long. The supplied value, pointer
196  *		etc. is casted to unsigned long internally.
197  *
198  * The vendor is set to INTEL, the family to 6 and all other missing
199  * arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are set to wildcards.
200  *
201  * See X86_MATCH_VENDOR_FAM_MODEL_FEATURE() for further information.
202  */
203 #define X86_MATCH_INTEL_FAM6_MODEL(model, data)				\
204 	X86_MATCH_VENDOR_FAM_MODEL(INTEL, 6, INTEL_FAM6_##model, data)
205 
206 #define X86_MATCH_INTEL_FAM6_MODEL_STEPPINGS(model, steppings, data)	\
207 	X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(INTEL, 6, INTEL_FAM6_##model, \
208 						     steppings, X86_FEATURE_ANY, data)
209 
210 /**
211  * X86_MATCH_VFM - Match encoded vendor/family/model
212  * @vfm:	Encoded 8-bits each for vendor, family, model
213  * @data:	Driver specific data or NULL. The internal storage
214  *		format is unsigned long. The supplied value, pointer
215  *		etc. is cast to unsigned long internally.
216  *
217  * Stepping and feature are set to wildcards
218  */
219 #define X86_MATCH_VFM(vfm, data)			\
220 	X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(	\
221 		VFM_VENDOR(vfm),			\
222 		VFM_FAMILY(vfm),			\
223 		VFM_MODEL(vfm),				\
224 		X86_STEPPING_ANY, X86_FEATURE_ANY, data)
225 
226 /**
227  * X86_MATCH_VFM_STEPPINGS - Match encoded vendor/family/model/stepping
228  * @vfm:	Encoded 8-bits each for vendor, family, model
229  * @steppings:	Bitmask of steppings to match
230  * @data:	Driver specific data or NULL. The internal storage
231  *		format is unsigned long. The supplied value, pointer
232  *		etc. is cast to unsigned long internally.
233  *
234  * feature is set to wildcard
235  */
236 #define X86_MATCH_VFM_STEPPINGS(vfm, steppings, data)	\
237 	X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(	\
238 		VFM_VENDOR(vfm),			\
239 		VFM_FAMILY(vfm),			\
240 		VFM_MODEL(vfm),				\
241 		steppings, X86_FEATURE_ANY, data)
242 
243 /**
244  * X86_MATCH_VFM_FEATURE - Match encoded vendor/family/model/feature
245  * @vfm:	Encoded 8-bits each for vendor, family, model
246  * @feature:	A X86_FEATURE bit
247  * @data:	Driver specific data or NULL. The internal storage
248  *		format is unsigned long. The supplied value, pointer
249  *		etc. is cast to unsigned long internally.
250  *
251  * Steppings is set to wildcard
252  */
253 #define X86_MATCH_VFM_FEATURE(vfm, feature, data)	\
254 	X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(	\
255 		VFM_VENDOR(vfm),			\
256 		VFM_FAMILY(vfm),			\
257 		VFM_MODEL(vfm),				\
258 		X86_STEPPING_ANY, feature, data)
259 
260 /*
261  * Match specific microcode revisions.
262  *
263  * vendor/family/model/stepping must be all set.
264  *
265  * Only checks against the boot CPU.  When mixed-stepping configs are
266  * valid for a CPU model, add a quirk for every valid stepping and
267  * do the fine-tuning in the quirk handler.
268  */
269 
270 struct x86_cpu_desc {
271 	u8	x86_family;
272 	u8	x86_vendor;
273 	u8	x86_model;
274 	u8	x86_stepping;
275 	u32	x86_microcode_rev;
276 };
277 
278 #define INTEL_CPU_DESC(model, stepping, revision) {		\
279 	.x86_family		= 6,				\
280 	.x86_vendor		= X86_VENDOR_INTEL,		\
281 	.x86_model		= (model),			\
282 	.x86_stepping		= (stepping),			\
283 	.x86_microcode_rev	= (revision),			\
284 }
285 
286 #define AMD_CPU_DESC(fam, model, stepping, revision) {		\
287 	.x86_family		= (fam),			\
288 	.x86_vendor		= X86_VENDOR_AMD,		\
289 	.x86_model		= (model),			\
290 	.x86_stepping		= (stepping),			\
291 	.x86_microcode_rev	= (revision),			\
292 }
293 
294 extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
295 extern bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table);
296 
297 #endif /* _ASM_X86_CPU_DEVICE_ID */
298