Skip to content

Commit e6dfdc2

Browse files
aeglbp3tk0v
authored andcommitted
x86/cpu/vfm: Add new macros to work with (vendor/family/model) values
To avoid adding a slew of new macros for each new Intel CPU family switch over from providing CPU model number #defines to a new scheme that encodes vendor, family, and model in a single number. [ bp: s/casted/cast/g ] Signed-off-by: Tony Luck <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a9d0adc commit e6dfdc2

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

arch/x86/include/asm/cpu_device_id.h

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,39 @@
22
#ifndef _ASM_X86_CPU_DEVICE_ID
33
#define _ASM_X86_CPU_DEVICE_ID
44

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+
538
/*
639
* Declare drivers belonging to specific x86 CPUs
740
* Similar in spirit to pci_device_id and related PCI functions
@@ -49,6 +82,16 @@
4982
.driver_data = (unsigned long) _data \
5083
}
5184

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+
5295
/**
5396
* X86_MATCH_VENDOR_FAM_MODEL_FEATURE - Macro for CPU matching
5497
* @_vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
@@ -164,6 +207,56 @@
164207
X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(INTEL, 6, INTEL_FAM6_##model, \
165208
steppings, X86_FEATURE_ANY, data)
166209

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+
167260
/*
168261
* Match specific microcode revisions.
169262
*

0 commit comments

Comments
 (0)