xref: /linux/arch/x86/include/asm/cpu_device_id.h (revision 26fbb4c8c7c3ee9a4c3b4de555a8587b5a19154e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_CPU_DEVICE_ID
3 #define _ASM_X86_CPU_DEVICE_ID
4 
5 /*
6  * Declare drivers belonging to specific x86 CPUs
7  * Similar in spirit to pci_device_id and related PCI functions
8  *
9  * The wildcard initializers are in mod_devicetable.h because
10  * file2alias needs them. Sigh.
11  */
12 #include <linux/mod_devicetable.h>
13 /* Get the INTEL_FAM* model defines */
14 #include <asm/intel-family.h>
15 /* And the X86_VENDOR_* ones */
16 #include <asm/processor.h>
17 
18 /* Centaur FAM6 models */
19 #define X86_CENTAUR_FAM6_C7_A		0xa
20 #define X86_CENTAUR_FAM6_C7_D		0xd
21 #define X86_CENTAUR_FAM6_NANO		0xf
22 
23 #define X86_STEPPINGS(mins, maxs)    GENMASK(maxs, mins)
24 /**
25  * X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE - Base macro for CPU matching
26  * @_vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
27  *		The name is expanded to X86_VENDOR_@_vendor
28  * @_family:	The family number or X86_FAMILY_ANY
29  * @_model:	The model number, model constant or X86_MODEL_ANY
30  * @_steppings:	Bitmask for steppings, stepping constant or X86_STEPPING_ANY
31  * @_feature:	A X86_FEATURE bit or X86_FEATURE_ANY
32  * @_data:	Driver specific data or NULL. The internal storage
33  *		format is unsigned long. The supplied value, pointer
34  *		etc. is casted to unsigned long internally.
35  *
36  * Use only if you need all selectors. Otherwise use one of the shorter
37  * macros of the X86_MATCH_* family. If there is no matching shorthand
38  * macro, consider to add one. If you really need to wrap one of the macros
39  * into another macro at the usage site for good reasons, then please
40  * start this local macro with X86_MATCH to allow easy grepping.
41  */
42 #define X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(_vendor, _family, _model, \
43 						    _steppings, _feature, _data) { \
44 	.vendor		= X86_VENDOR_##_vendor,				\
45 	.family		= _family,					\
46 	.model		= _model,					\
47 	.steppings	= _steppings,					\
48 	.feature	= _feature,					\
49 	.driver_data	= (unsigned long) _data				\
50 }
51 
52 /**
53  * X86_MATCH_VENDOR_FAM_MODEL_FEATURE - Macro for CPU matching
54  * @_vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
55  *		The name is expanded to X86_VENDOR_@_vendor
56  * @_family:	The family number or X86_FAMILY_ANY
57  * @_model:	The model number, model constant or X86_MODEL_ANY
58  * @_feature:	A X86_FEATURE bit or X86_FEATURE_ANY
59  * @_data:	Driver specific data or NULL. The internal storage
60  *		format is unsigned long. The supplied value, pointer
61  *		etc. is casted to unsigned long internally.
62  *
63  * The steppings arguments of X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE() is
64  * set to wildcards.
65  */
66 #define X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family, model, feature, data) \
67 	X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(vendor, family, model, \
68 						X86_STEPPING_ANY, feature, data)
69 
70 /**
71  * X86_MATCH_VENDOR_FAM_FEATURE - Macro for matching vendor, family and CPU feature
72  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
73  *		The name is expanded to X86_VENDOR_@vendor
74  * @family:	The family number or X86_FAMILY_ANY
75  * @feature:	A X86_FEATURE bit
76  * @data:	Driver specific data or NULL. The internal storage
77  *		format is unsigned long. The supplied value, pointer
78  *		etc. is casted to unsigned long internally.
79  *
80  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
81  * set to wildcards.
82  */
83 #define X86_MATCH_VENDOR_FAM_FEATURE(vendor, family, feature, data)	\
84 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family,		\
85 					   X86_MODEL_ANY, feature, data)
86 
87 /**
88  * X86_MATCH_VENDOR_FEATURE - Macro for matching vendor and CPU feature
89  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
90  *		The name is expanded to X86_VENDOR_@vendor
91  * @feature:	A X86_FEATURE bit
92  * @data:	Driver specific data or NULL. The internal storage
93  *		format is unsigned long. The supplied value, pointer
94  *		etc. is casted to unsigned long internally.
95  *
96  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
97  * set to wildcards.
98  */
99 #define X86_MATCH_VENDOR_FEATURE(vendor, feature, data)			\
100 	X86_MATCH_VENDOR_FAM_FEATURE(vendor, X86_FAMILY_ANY, feature, data)
101 
102 /**
103  * X86_MATCH_FEATURE - Macro for matching a CPU feature
104  * @feature:	A X86_FEATURE bit
105  * @data:	Driver specific data or NULL. The internal storage
106  *		format is unsigned long. The supplied value, pointer
107  *		etc. is casted to unsigned long internally.
108  *
109  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
110  * set to wildcards.
111  */
112 #define X86_MATCH_FEATURE(feature, data)				\
113 	X86_MATCH_VENDOR_FEATURE(ANY, feature, data)
114 
115 /**
116  * X86_MATCH_VENDOR_FAM_MODEL - Match vendor, family and model
117  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
118  *		The name is expanded to X86_VENDOR_@vendor
119  * @family:	The family number or X86_FAMILY_ANY
120  * @model:	The model number, model constant or X86_MODEL_ANY
121  * @data:	Driver specific data or NULL. The internal storage
122  *		format is unsigned long. The supplied value, pointer
123  *		etc. is casted to unsigned long internally.
124  *
125  * All other missing arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
126  * set to wildcards.
127  */
128 #define X86_MATCH_VENDOR_FAM_MODEL(vendor, family, model, data)		\
129 	X86_MATCH_VENDOR_FAM_MODEL_FEATURE(vendor, family, model,	\
130 					   X86_FEATURE_ANY, data)
131 
132 /**
133  * X86_MATCH_VENDOR_FAM - Match vendor and family
134  * @vendor:	The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
135  *		The name is expanded to X86_VENDOR_@vendor
136  * @family:	The family number or X86_FAMILY_ANY
137  * @data:	Driver specific data or NULL. The internal storage
138  *		format is unsigned long. The supplied value, pointer
139  *		etc. is casted to unsigned long internally.
140  *
141  * All other missing arguments to X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are
142  * set of wildcards.
143  */
144 #define X86_MATCH_VENDOR_FAM(vendor, family, data)			\
145 	X86_MATCH_VENDOR_FAM_MODEL(vendor, family, X86_MODEL_ANY, data)
146 
147 /**
148  * X86_MATCH_INTEL_FAM6_MODEL - Match vendor INTEL, family 6 and model
149  * @model:	The model name without the INTEL_FAM6_ prefix or ANY
150  *		The model name is expanded to INTEL_FAM6_@model internally
151  * @data:	Driver specific data or NULL. The internal storage
152  *		format is unsigned long. The supplied value, pointer
153  *		etc. is casted to unsigned long internally.
154  *
155  * The vendor is set to INTEL, the family to 6 and all other missing
156  * arguments of X86_MATCH_VENDOR_FAM_MODEL_FEATURE() are set to wildcards.
157  *
158  * See X86_MATCH_VENDOR_FAM_MODEL_FEATURE() for further information.
159  */
160 #define X86_MATCH_INTEL_FAM6_MODEL(model, data)				\
161 	X86_MATCH_VENDOR_FAM_MODEL(INTEL, 6, INTEL_FAM6_##model, data)
162 
163 #define X86_MATCH_INTEL_FAM6_MODEL_STEPPINGS(model, steppings, data)	\
164 	X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(INTEL, 6, INTEL_FAM6_##model, \
165 						     steppings, X86_FEATURE_ANY, data)
166 
167 /*
168  * Match specific microcode revisions.
169  *
170  * vendor/family/model/stepping must be all set.
171  *
172  * Only checks against the boot CPU.  When mixed-stepping configs are
173  * valid for a CPU model, add a quirk for every valid stepping and
174  * do the fine-tuning in the quirk handler.
175  */
176 
177 struct x86_cpu_desc {
178 	u8	x86_family;
179 	u8	x86_vendor;
180 	u8	x86_model;
181 	u8	x86_stepping;
182 	u32	x86_microcode_rev;
183 };
184 
185 #define INTEL_CPU_DESC(model, stepping, revision) {		\
186 	.x86_family		= 6,				\
187 	.x86_vendor		= X86_VENDOR_INTEL,		\
188 	.x86_model		= (model),			\
189 	.x86_stepping		= (stepping),			\
190 	.x86_microcode_rev	= (revision),			\
191 }
192 
193 extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match);
194 extern bool x86_cpu_has_min_microcode_rev(const struct x86_cpu_desc *table);
195 
196 #endif /* _ASM_X86_CPU_DEVICE_ID */
197