History

x86/cpu: Add a steppings field to struct x86_cpu_id

Intel uses the same family/model for several CPUs. Sometimes the stepping must be checked to tell them apart. On x86 there can be at most 16 steppings. Add a steppings bitmask to x86_cpu_id and a X86_MATCH_VENDOR_FAMILY_MODEL_STEPPING_FEATURE macro and support for matching against family/model/stepping. [ bp: Massage. ]

Mark Gross committed 6 years ago

Commit e9d71441 parent ae83d0b3 files · +32 −4Browse files

Unified · Split

3 files
  1. arch/x86/include/asm/cpu_device_id.h +24 −3
  2. arch/x86/kernel/cpu/match.c +6 −1
  3. include/linux/mod_devicetable.h +2 −0
arch/x86/include/asm/cpu_device_id.h+24−3
@@ -20,12 +20,14 @@ · 19 unmodified lines
2020 #define X86_CENTAUR_FAM6_C7_D 0xd
2121 #define X86_CENTAUR_FAM6_NANO 0xf
2222
23+#define X86_STEPPINGS(mins, maxs) GENMASK(maxs, mins)
2324 /**
24− * X86_MATCH_VENDOR_FAM_MODEL_FEATURE - Base macro for CPU matching
25+ * X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE - Base macro for CPU matching
2526 * @_vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
2627 * The name is expanded to X86_VENDOR_@_vendor
2728 * @_family: The family number or X86_FAMILY_ANY
2829 * @_model: The model number, model constant or X86_MODEL_ANY
30+ * @_steppings: Bitmask for steppings, stepping constant or X86_STEPPING_ANY
2931 * @_feature: A X86_FEATURE bit or X86_FEATURE_ANY
3032 * @_data: Driver specific data or NULL. The internal storage
3133 * format is unsigned long. The supplied value, pointer
@@ -37,15 +39,34 @@ · 5 unmodified lines
3739 * into another macro at the usage site for good reasons, then please
3840 * start this local macro with X86_MATCH to allow easy grepping.
3941 */
40−#define X86_MATCH_VENDOR_FAM_MODEL_FEATURE(_vendor, _family, _model, \
41− _feature, _data) { \
42+#define X86_MATCH_VENDOR_FAM_MODEL_STEPPINGS_FEATURE(_vendor, _family, _model, \
43+ _steppings, _feature, _data) { \
4244 .vendor = X86_VENDOR_##_vendor, \
4345 .family = _family, \
4446 .model = _model, \
47+ .steppings = _steppings, \
4548 .feature = _feature, \
4649 .driver_data = (unsigned long) _data \
4750 }
4851
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+
4970 /**
5071 * X86_MATCH_VENDOR_FAM_FEATURE - Macro for matching vendor, family and CPU feature
5172 * @vendor: The vendor name, e.g. INTEL, AMD, HYGON, ..., ANY
arch/x86/kernel/cpu/match.c+6−1
@@ -39,13 +39,18 @@ const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id *match) · 38 unmodified lines
3939 const struct x86_cpu_id *m;
4040 struct cpuinfo_x86 *c = &boot_cpu_data;
4141
42− for (m = match; m->vendor | m->family | m->model | m->feature; m++) {
42+ for (m = match;
43+ m->vendor | m->family | m->model | m->steppings | m->feature;
44+ m++) {
4345 if (m->vendor != X86_VENDOR_ANY && c->x86_vendor != m->vendor)
4446 continue;
4547 if (m->family != X86_FAMILY_ANY && c->x86 != m->family)
4648 continue;
4749 if (m->model != X86_MODEL_ANY && c->x86_model != m->model)
4850 continue;
51+ if (m->steppings != X86_STEPPING_ANY &&
52+ !(BIT(c->x86_stepping) & m->steppings))
53+ continue;
4954 if (m->feature != X86_FEATURE_ANY && !cpu_has(c, m->feature))
5055 continue;
5156 return m;
include/linux/mod_devicetable.h+2−0
@@ -663,6 +663,7 @@ struct x86_cpu_id { · 662 unmodified lines
663663 __u16 vendor;
664664 __u16 family;
665665 __u16 model;
666+ __u16 steppings;
666667 __u16 feature; /* bit index */
667668 kernel_ulong_t driver_data;
668669 };
@@ -671,6 +672,7 @@ struct x86_cpu_id { · 2 unmodified lines
671672 #define X86_VENDOR_ANY 0xffff
672673 #define X86_FAMILY_ANY 0
673674 #define X86_MODEL_ANY 0
675+#define X86_STEPPING_ANY 0
674676 #define X86_FEATURE_ANY 0 /* Same as FPU, you can't test for that */
675677
676678 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t