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_CPU -  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_CPU(_vendor, _family, _model, _steppings, _feature, _type, _data) { \
78 	.vendor		= _vendor,					\
79 	.family		= _family,					\
80 	.model		= _model,					\
81 	.steppings	= _steppings,					\
82 	.feature	= _feature,					\
83 	.flags		= X86_CPU_ID_FLAG_ENTRY_VALID,			\
84 	.type		= _type,					\
85 	.driver_data	= (unsigned long) _data				\
86 }
87 
88 /**
89  * X86_MATCH_VENDOR_FAM_FEATURE - Macro for matching vendor, family and CPU feature
90  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
91  *		The name is expanded to X86_VENDOR_@vendor
92  * @family:	The family number or X86_FAMILY_ANY
93  * @feature:	A X86_FEATURE bit
94  * @data:	Driver specific data or NULL. The internal storage
95  *		format is unsigned long. The supplied value, pointer
96  *		etc. is casted to unsigned long internally.
97  */
98 #define X86_MATCH_VENDOR_FAM_FEATURE(vendor, family, feature, data)		\
99 	X86_MATCH_CPU(X86_VENDOR_##vendor, family, X86_MODEL_ANY,		\
100 		      X86_STEPPING_ANY, feature, X86_CPU_TYPE_ANY, data)
101 
102 /**
103  * X86_MATCH_VENDOR_FEATURE - Macro for matching vendor and CPU feature
104  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
105  *		The name is expanded to X86_VENDOR_@vendor
106  * @feature:	A X86_FEATURE bit
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 #define X86_MATCH_VENDOR_FEATURE(vendor, feature, data)				\
112 	X86_MATCH_CPU(X86_VENDOR_##vendor, X86_FAMILY_ANY, X86_MODEL_ANY,	\
113 		      X86_STEPPING_ANY, feature, X86_CPU_TYPE_ANY, data)
114 
115 /**
116  * X86_MATCH_FEATURE - Macro for matching a CPU feature
117  * @feature:	A X86_FEATURE bit
118  * @data:	Driver specific data or NULL. The internal storage
119  *		format is unsigned long. The supplied value, pointer
120  *		etc. is casted to unsigned long internally.
121  */
122 #define X86_MATCH_FEATURE(feature, data)					\
123 	X86_MATCH_CPU(X86_VENDOR_ANY, X86_FAMILY_ANY, X86_MODEL_ANY,		\
124 		      X86_STEPPING_ANY, feature, X86_CPU_TYPE_ANY, data)
125 
126 /**
127  * X86_MATCH_VENDOR_FAM_MODEL - Match vendor, family and model
128  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
129  *		The name is expanded to X86_VENDOR_@vendor
130  * @family:	The family number or X86_FAMILY_ANY
131  * @model:	The model number, model constant or X86_MODEL_ANY
132  * @data:	Driver specific data or NULL. The internal storage
133  *		format is unsigned long. The supplied value, pointer
134  *		etc. is casted to unsigned long internally.
135  */
136 #define X86_MATCH_VENDOR_FAM_MODEL(vendor, family, model, data)			\
137 	X86_MATCH_CPU(X86_VENDOR_##vendor, family, model, X86_STEPPING_ANY,	\
138 		      X86_FEATURE_ANY, X86_CPU_TYPE_ANY, data)
139 
140 /**
141  * X86_MATCH_VENDOR_FAM - Match vendor and family
142  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
143  *		The name is expanded to X86_VENDOR_@vendor
144  * @family:	The family number or X86_FAMILY_ANY
145  * @data:	Driver specific data or NULL. The internal storage
146  *		format is unsigned long. The supplied value, pointer
147  *		etc. is casted to unsigned long internally.
148  */
149 #define X86_MATCH_VENDOR_FAM(vendor, family, data)				\
150 	X86_MATCH_CPU(X86_VENDOR_##vendor, family, X86_MODEL_ANY,		\
151 		      X86_STEPPING_ANY, X86_FEATURE_ANY, X86_CPU_TYPE_ANY, data)
152 
153 /**
154  * X86_MATCH_VFM - Match encoded vendor/family/model
155  * @vfm:	Encoded 8-bits each for vendor, family, model
156  * @data:	Driver specific data or NULL. The internal storage
157  *		format is unsigned long. The supplied value, pointer
158  *		etc. is cast to unsigned long internally.
159  */
160 #define X86_MATCH_VFM(vfm, data)						\
161 	X86_MATCH_CPU(VFM_VENDOR(vfm), VFM_FAMILY(vfm),	VFM_MODEL(vfm),		\
162 		      X86_STEPPING_ANY, X86_FEATURE_ANY, X86_CPU_TYPE_ANY, data)
163 
164 #define __X86_STEPPINGS(mins, maxs)    GENMASK(maxs, mins)
165 /**
166  * X86_MATCH_VFM_STEPS - Match encoded vendor/family/model and steppings
167  *			 range.
168  * @vfm:	Encoded 8-bits each for vendor, family, model
169  * @min_step:	Lowest stepping number to match
170  * @max_step:	Highest stepping number to match
171  * @data:	Driver specific data or NULL. The internal storage
172  *		format is unsigned long. The supplied value, pointer
173  *		etc. is cast to unsigned long internally.
174  */
175 #define X86_MATCH_VFM_STEPS(vfm, min_step, max_step, data)			\
176 	X86_MATCH_CPU(VFM_VENDOR(vfm), VFM_FAMILY(vfm), VFM_MODEL(vfm),		\
177 		      __X86_STEPPINGS(min_step, max_step), X86_FEATURE_ANY,	\
178 		      X86_CPU_TYPE_ANY, data)
179 
180 /**
181  * X86_MATCH_VFM_FEATURE - Match encoded vendor/family/model/feature
182  * @vfm:	Encoded 8-bits each for vendor, family, model
183  * @feature:	A X86_FEATURE bit
184  * @data:	Driver specific data or NULL. The internal storage
185  *		format is unsigned long. The supplied value, pointer
186  *		etc. is cast to unsigned long internally.
187  */
188 #define X86_MATCH_VFM_FEATURE(vfm, feature, data)				\
189 	X86_MATCH_CPU(VFM_VENDOR(vfm), VFM_FAMILY(vfm), VFM_MODEL(vfm),		\
190 		      X86_STEPPING_ANY, feature, X86_CPU_TYPE_ANY, data)
191 
192 /**
193  * X86_MATCH_VFM_CPU_TYPE - Match encoded vendor/family/model/type
194  * @vfm:	Encoded 8-bits each for vendor, family, model
195  * @type:	CPU type e.g. P-core, E-core
196  * @data:	Driver specific data or NULL. The internal storage
197  *		format is unsigned long. The supplied value, pointer
198  *		etc. is cast to unsigned long internally.
199  */
200 #define X86_MATCH_VFM_CPU_TYPE(vfm, type, data)				\
201 	X86_MATCH_CPU(VFM_VENDOR(vfm), VFM_FAMILY(vfm), VFM_MODEL(vfm),	\
202 		      X86_STEPPING_ANY, X86_FEATURE_ANY, type, data)
203 
204 extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
205 extern bool x86_match_min_microcode_rev(const struct x86_cpu_id *table);
206 
207 #endif /* _ASM_X86_CPU_DEVICE_ID */
208