xref: /linux/arch/x86/include/asm/cpu_device_id.h (revision f96a974170b749e3a56844e25b31d46a7233b6f6)
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 /**
60  * X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE - Base macro for CPU matching
61  * @_vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
62  *		The name is expanded to X86_VENDOR_@_vendor
63  * @_family:	The family number or X86_FAMILY_ANY
64  * @_model:	The model number, model constant or X86_MODEL_ANY
65  * @_steppings:	Bitmask for steppings, stepping constant or X86_STEPPING_ANY
66  * @_feature:	A X86_FEATURE bit or X86_FEATURE_ANY
67  * @_data:	Driver specific data or NULL. The internal storage
68  *		format is unsigned long. The supplied value, pointer
69  *		etc. is casted to unsigned long internally.
70  *
71  * Use only if you need all selectors. Otherwise use one of the shorter
72  * macros of the X86_MATCH_* family. If there is no matching shorthand
73  * macro, consider to add one. If you really need to wrap one of the macros
74  * into another macro at the usage site for good reasons, then please
75  * start this local macro with X86_MATCH to allow easy grepping.
76  */
77 #define X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(_vendor, _family, _model, \
78 						    _steppings, _feature, _data) { \
79 	.vendor		= X86_VENDOR_##_vendor,				\
80 	.family		= _family,					\
81 	.model		= _model,					\
82 	.steppings	= _steppings,					\
83 	.feature	= _feature,					\
84 	.flags		= X86_CPU_ID_FLAG_ENTRY_VALID,			\
85 	.driver_data	= (unsigned long) _data				\
86 }
87 
88 #define X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(_vendor, _family, _model, \
89 						    _steppings, _feature, _data) { \
90 	.vendor		= _vendor,					\
91 	.family		= _family,					\
92 	.model		= _model,					\
93 	.steppings	= _steppings,					\
94 	.feature	= _feature,					\
95 	.flags		= X86_CPU_ID_FLAG_ENTRY_VALID,			\
96 	.driver_data	= (unsigned long) _data				\
97 }
98 
99 /**
100  * X86_MATCH_VENDOR_FAM_MODEL_FEATURE - Macro for CPU matching
101  * @_vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
102  *		The name is expanded to X86_VENDOR_@_vendor
103  * @_family:	The family number or X86_FAMILY_ANY
104  * @_model:	The model number, model constant or X86_MODEL_ANY
105  * @_feature:	A X86_FEATURE bit or X86_FEATURE_ANY
106  * @_data:	Driver specific data or NULL. The internal storage
107  *		format is unsigned long. The supplied value, pointer
108  *		etc. is casted to unsigned long internally.
109  *
110  * The steppings arguments of X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE() is
111  * set to wildcards.
112  */
113 #define X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family, model, feature, data) \
114 	X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(vendor, family, model, \
115 						X86_STEPPING_ANY, feature, data)
116 
117 /**
118  * X86_MATCH_VENDOR_FAM_FEATURE - Macro for matching vendor, family and CPU feature
119  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
120  *		The name is expanded to X86_VENDOR_@vendor
121  * @family:	The family number or X86_FAMILY_ANY
122  * @feature:	A X86_FEATURE bit
123  * @data:	Driver specific data or NULL. The internal storage
124  *		format is unsigned long. The supplied value, pointer
125  *		etc. is casted to unsigned long internally.
126  *
127  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
128  * set to wildcards.
129  */
130 #define X86_MATCH_VENDOR_FAM_FEATURE(vendor, family, feature, data)	\
131 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family,		\
132 					   X86_MODEL_ANY, feature, data)
133 
134 /**
135  * X86_MATCH_VENDOR_FEATURE - Macro for matching vendor and CPU feature
136  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
137  *		The name is expanded to X86_VENDOR_@vendor
138  * @feature:	A X86_FEATURE bit
139  * @data:	Driver specific data or NULL. The internal storage
140  *		format is unsigned long. The supplied value, pointer
141  *		etc. is casted to unsigned long internally.
142  *
143  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
144  * set to wildcards.
145  */
146 #define X86_MATCH_VENDOR_FEATURE(vendor, feature, data)			\
147 	X86_MATCH_VENDOR_FAM_FEATURE(vendor, X86_FAMILY_ANY, feature, data)
148 
149 /**
150  * X86_MATCH_FEATURE - Macro for matching a CPU feature
151  * @feature:	A X86_FEATURE bit
152  * @data:	Driver specific data or NULL. The internal storage
153  *		format is unsigned long. The supplied value, pointer
154  *		etc. is casted to unsigned long internally.
155  *
156  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
157  * set to wildcards.
158  */
159 #define X86_MATCH_FEATURE(feature, data)				\
160 	X86_MATCH_VENDOR_FEATURE(ANY, feature, data)
161 
162 /**
163  * X86_MATCH_VENDOR_FAM_MODEL - Match vendor, family and model
164  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
165  *		The name is expanded to X86_VENDOR_@vendor
166  * @family:	The family number or X86_FAMILY_ANY
167  * @model:	The model number, model constant or X86_MODEL_ANY
168  * @data:	Driver specific data or NULL. The internal storage
169  *		format is unsigned long. The supplied value, pointer
170  *		etc. is casted to unsigned long internally.
171  *
172  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
173  * set to wildcards.
174  */
175 #define X86_MATCH_VENDOR_FAM_MODEL(vendor, family, model, data)		\
176 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family, model,	\
177 					   X86_FEATURE_ANY, data)
178 
179 /**
180  * X86_MATCH_VENDOR_FAM - Match vendor and family
181  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
182  *		The name is expanded to X86_VENDOR_@vendor
183  * @family:	The family number or X86_FAMILY_ANY
184  * @data:	Driver specific data or NULL. The internal storage
185  *		format is unsigned long. The supplied value, pointer
186  *		etc. is casted to unsigned long internally.
187  *
188  * All other missing arguments to X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
189  * set of wildcards.
190  */
191 #define X86_MATCH_VENDOR_FAM(vendor, family, data)			\
192 	X86_MATCH_VENDOR_FAM_MODEL(vendor, family, X86_MODEL_ANY, data)
193 
194 /**
195  * X86_MATCH_VFM - Match encoded vendor/family/model
196  * @vfm:	Encoded 8-bits each for vendor, family, model
197  * @data:	Driver specific data or NULL. The internal storage
198  *		format is unsigned long. The supplied value, pointer
199  *		etc. is cast to unsigned long internally.
200  *
201  * Stepping and feature are set to wildcards
202  */
203 #define X86_MATCH_VFM(vfm, data)			\
204 	X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(	\
205 		VFM_VENDOR(vfm),			\
206 		VFM_FAMILY(vfm),			\
207 		VFM_MODEL(vfm),				\
208 		X86_STEPPING_ANY, X86_FEATURE_ANY, data)
209 
210 #define __X86_STEPPINGS(mins, maxs)    GENMASK(maxs, mins)
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_STEPS(vfm, min_step, max_step, data)	\
222 	X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(		\
223 		VFM_VENDOR(vfm),				\
224 		VFM_FAMILY(vfm),				\
225 		VFM_MODEL(vfm),					\
226 		__X86_STEPPINGS(min_step, max_step),		\
227 		X86_FEATURE_ANY, data)
228 
229 /**
230  * X86_MATCH_VFM_FEATURE - Match encoded vendor/family/model/feature
231  * @vfm:	Encoded 8-bits each for vendor, family, model
232  * @feature:	A X86_FEATURE bit
233  * @data:	Driver specific data or NULL. The internal storage
234  *		format is unsigned long. The supplied value, pointer
235  *		etc. is cast to unsigned long internally.
236  *
237  * Steppings is set to wildcard
238  */
239 #define X86_MATCH_VFM_FEATURE(vfm, feature, data)	\
240 	X86_MATCH_VENDORID_FAM_MODEL_STEPPINGS_FEATURE(	\
241 		VFM_VENDOR(vfm),			\
242 		VFM_FAMILY(vfm),			\
243 		VFM_MODEL(vfm),				\
244 		X86_STEPPING_ANY, feature, data)
245 
246 extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
247 extern bool x86_match_min_microcode_rev(const struct x86_cpu_id *table);
248 
249 #endif /* _ASM_X86_CPU_DEVICE_ID */
250