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_INTEL_FAM6_MODEL - Match vendor INTEL, family 6 and model
197  * @model:	The model name without the INTEL_FAM6_ prefix or ANY
198  *		The model name is expanded to INTEL_FAM6_@model internally
199  * @data:	Driver specific data or NULL. The internal storage
200  *		format is unsigned long. The supplied value, pointer
201  *		etc. is casted to unsigned long internally.
202  *
203  * The vendor is set to INTEL, the family to 6 and all other missing
204  * arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are set to wildcards.
205  *
206  * See X86_MATCH_VENDOR_FAM_MODEL_FEATURE() for further information.
207  */
208 #define X86_MATCH_INTEL_FAM6_MODEL(model, data)				\
209 	X86_MATCH_VENDOR_FAM_MODEL(INTEL, 6, INTEL_FAM6_##model, data)
210 
211 #define X86_MATCH_INTEL_FAM6_MODEL_STEPPINGS(model, steppings, data)	\
212 	X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(INTEL, 6, INTEL_FAM6_##model, \
213 						     steppings, X86_FEATURE_ANY, data)
214 
215 /**
216  * X86_MATCH_VFM - Match encoded vendor/family/model
217  * @vfm:	Encoded 8-bits each for vendor, family, model
218  * @data:	Driver specific data or NULL. The internal storage
219  *		format is unsigned long. The supplied value, pointer
220  *		etc. is cast to unsigned long internally.
221  *
222  * Stepping and feature are set to wildcards
223  */
224 #define X86_MATCH_VFM(vfm, data)			\
225 	X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(	\
226 		VFM_VENDOR(vfm),			\
227 		VFM_FAMILY(vfm),			\
228 		VFM_MODEL(vfm),				\
229 		X86_STEPPING_ANY, X86_FEATURE_ANY, data)
230 
231 /**
232  * X86_MATCH_VFM_STEPPINGS - Match encoded vendor/family/model/stepping
233  * @vfm:	Encoded 8-bits each for vendor, family, model
234  * @steppings:	Bitmask of steppings to match
235  * @data:	Driver specific data or NULL. The internal storage
236  *		format is unsigned long. The supplied value, pointer
237  *		etc. is cast to unsigned long internally.
238  *
239  * feature is set to wildcard
240  */
241 #define X86_MATCH_VFM_STEPPINGS(vfm, steppings, data)	\
242 	X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(	\
243 		VFM_VENDOR(vfm),			\
244 		VFM_FAMILY(vfm),			\
245 		VFM_MODEL(vfm),				\
246 		steppings, X86_FEATURE_ANY, data)
247 
248 /**
249  * X86_MATCH_VFM_FEATURE - Match encoded vendor/family/model/feature
250  * @vfm:	Encoded 8-bits each for vendor, family, model
251  * @feature:	A X86_FEATURE bit
252  * @data:	Driver specific data or NULL. The internal storage
253  *		format is unsigned long. The supplied value, pointer
254  *		etc. is cast to unsigned long internally.
255  *
256  * Steppings is set to wildcard
257  */
258 #define X86_MATCH_VFM_FEATURE(vfm, feature, data)	\
259 	X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(	\
260 		VFM_VENDOR(vfm),			\
261 		VFM_FAMILY(vfm),			\
262 		VFM_MODEL(vfm),				\
263 		X86_STEPPING_ANY, feature, data)
264 
265 /*
266  * Match specific microcode revisions.
267  *
268  * vendor/family/model/stepping must be all set.
269  *
270  * Only checks against the boot CPU.  When mixed-stepping configs are
271  * valid for a CPU model, add a quirk for every valid stepping and
272  * do the fine-tuning in the quirk handler.
273  */
274 
275 struct x86_cpu_desc {
276 	u8	x86_family;
277 	u8	x86_vendor;
278 	u8	x86_model;
279 	u8	x86_stepping;
280 	u32	x86_microcode_rev;
281 };
282 
283 #define INTEL_CPU_DESC(model, stepping, revision) {		\
284 	.x86_family		= 6,				\
285 	.x86_vendor		= X86_VENDOR_INTEL,		\
286 	.x86_model		= (model),			\
287 	.x86_stepping		= (stepping),			\
288 	.x86_microcode_rev	= (revision),			\
289 }
290 
291 extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
292 extern bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table);
293 
294 #endif /* _ASM_X86_CPU_DEVICE_ID */
295