x86/acpi: add a common interface for x86 cpu matching
PATCH v2 1/9 x86/acpi: add a common interface for x86 cpu matching
Add a common interface for matching the current cpu against an array of x86_cpu_ids. Also change mwait-idle.c to use it.
--- xen/arch/x86/cpu/common.c | 39 +++++++++++++++++++++++++++++++++++++++ xen/arch/x86/cpu/mwait-idle.c | 30 +++++++++++++----------------- xen/include/asm-x86/processor.h | 10 ++++++++++ 3 files changed, 62 insertions(+), 17 deletions(-)
xen/arch/x86/cpu/common.c +39 -0
@@ -45,6 +45,45 @@ unsigned int paddr_bits __read_mostly = 36;*/ u64 host_pat =0x050100070406 ; +/* +* x86_match_cpu - match the current CPU against an array of +* x86_cpu_ids +* @match: Pointer to array of x86_cpu_ids. Last entry terminated with +* {}. +* Return the entry if the current CPU matches the entries in the +* passed x86_cpu_id match table. Otherwise NULL. The match table +* contains vendor (X86_VENDOR_*), family, model and feature bits or +* respective wildcard entries. +* +* A typical table entry would be to match a specific CPU +* { X86_VENDOR_INTEL, 6, 0x12 } +* or to match a specific CPU feature +* { X86_FEATURE_MATCH(X86_FEATURE_FOOBAR) } +* +* This always matches against the boot cpu, assuming models and +features are +* consistent over all CPUs. +*/ +const struct x86_cpu_id *x86_match_cpu (const struct x86_cpu_id *match) +{ +const struct x86_cpu_id *m; +struct cpuinfo_x86 *c = &boot_cpu_data; + +for (m = match; m->vendor | m->family | m->model | m->feature; m++) { +if (c->x86_vendor != m->vendor) +continue ; +if (c->x86 != m->family) +continue ; +if (c->x86_model != m->model) +continue ; +if (!cpu_has (c, m->feature)) +continue ; +return m; + } +return NULL ; +} +EXPORT_SYMBOL (x86_match_cpu); +static unsigned int __cpuinitdata cleared_caps[NCAPINTS ];void __init setup_clear_cpu_cap (unsigned int cap)
xen/arch/x86/cpu/mwait-idle.c +13 -17
@@ -59,6 +59,8 @@#include <asm/hpet.h> #include <asm/mwait.h> #include <asm/msr.h> +#include <asm/processor.h> +#include <asm/cpufeature.h> #include <acpi/cpufreq/cpufreq.h> #define MWAIT_IDLE_VERSION "0.4"
@@ -656,12 +658,11 @@ static const struct idle_cpu idle_cpu_avn = { .disable_promotion_to_c1e = 1, }; -#define ICPU (model, cpu) { 6, model, &idle_cpu_##cpu } +#define ICPU (model, cpu) \ + { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, \ + (unsigned long)&idle_cpu_##cpu} -static struct intel_idle_id { -unsigned int family, model; -const struct idle_cpu *data; -} intel_idle_ids[]__initdata = { +static const struct x86_cpu_id intel_idle_ids[] = {ICPU (0x1a , nehalem),ICPU (0x1e , nehalem),ICPU (0x1f , nehalem),
@@ -722,23 +723,18 @@ static void __init mwait_idle_state_table_update(void)static int __init mwait_idle_probe (void ) {unsigned int eax, ebx, ecx; -const struct intel_idle_id *id; +const struct x86_cpu_id *id; -if (boot_cpu_data.x86_vendor !=X86_VENDOR_INTEL || - !boot_cpu_has (X86_FEATURE_MWAIT ) || - boot_cpu_data.cpuid_level <CPUID_MWAIT_LEAF ) -return -ENODEV ; - -for (id = intel_idle_ids; id->family; ++id) -if (id->family == boot_cpu_data.x86 && - id->model == boot_cpu_data.x86_model) -break ; -if (!id->family) { + id =x86_match_cpu (intel_idle_ids); +if (!id) {pr_debug (PREFIX "does not run on family %d model %d\n" , boot_cpu_data.x86, boot_cpu_data.x86_model);return -ENODEV ; } +if (boot_cpu_data.cpuid_level <CPUID_MWAIT_LEAF ) +return -ENODEV ; +cpuid (CPUID_MWAIT_LEAF , &eax, &ebx, &ecx, &mwait_substates); if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
@@ -753,7 +749,7 @@ static int __init mwait_idle_probe(void)pr_debug (PREFIX "MWAIT substates: %#x\n" , mwait_substates); - icpu = id->data; + icpu = (const struct idle_cpu *)id->driver_data; cpuidle_state_table = icpu->state_table;if (boot_cpu_has (X86_FEATURE_ARAT ))
xen/include/asm-x86/processor.h +10 -0
@@ -163,6 +163,14 @@ struct vcpu; pc; \ }) +struct x86_cpu_id { +__u16 vendor; +__u16 family; +__u16 model; +__u16 feature;/* bit index */ +__u64 driver_data; +}; +struct cpuinfo_x86 {__u8 x86;/* CPU family */ __u8 x86_vendor;/* CPU vendor */
@@ -204,6 +212,8 @@ extern u32 cpuid_ext_features;/* Maximum width of physical addresses supported by the hardware */ extern unsigned int paddr_bits; +extern const struct x86_cpu_id *x86_match_cpu (const struct x86_cpu_id *match); +extern void identify_cpu (struct cpuinfo_x86 *);extern void setup_clear_cpu_cap (unsigned int );extern void print_cpu_info (unsigned int cpu);
Signature · 1 line
1.9.1
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 13.05.16 at 09:49, <[email protected]> wrote:
xen/arch/x86/cpu/common.c +9
-0@@ -45,6 +45,45 @@ unsigned int paddr_bits __read_mostly = 36;*/ u64 host_pat =0x050100070406 ; +/* +* x86_match_cpu - match the current CPU against an array of +* x86_cpu_ids +* @match: Pointer to array of x86_cpu_ids. Last entry terminated with +* {}. +* Return the entry if the current CPU matches the entries in the +* passed x86_cpu_id match table. Otherwise NULL. The match table +* contains vendor (X86_VENDOR_*), family, model and feature bits or +* respective wildcard entries.
xen/arch/x86/cpu/common.c unsigned int paddr_bits __read_mostly = 36; · line 66
Quoted 10 lines
xen/arch/x86/cpu/common.c +10
-0+* +* A typical table entry would be to match a specific CPU +* { X86_VENDOR_INTEL, 6, 0x12 } +* or to match a specific CPU feature +* { X86_FEATURE_MATCH(X86_FEATURE_FOOBAR) } +* +* This always matches against the boot cpu, assuming models and+features are +* consistent over all CPUs. +*/ +const struct x86_cpu_id *x86_match_cpu (const struct x86_cpu_id *match)
const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id table[])
xen/arch/x86/cpu/common.c unsigned int paddr_bits __read_mostly = 36; · line 70
Quoted 3 lines
xen/arch/x86/cpu/common.c +3
-0+{ +const struct x86_cpu_id *m; +struct cpuinfo_x86 *c = &boot_cpu_data;
const
xen/arch/x86/cpu/common.c unsigned int paddr_bits __read_mostly = 36; · line 84
Quoted 13 lines
xen/arch/x86/cpu/common.c +13
-0+for (m = match; m->vendor | m->family | m->model | m->feature; m++) { +if (c->x86_vendor != m->vendor) +continue ; +if (c->x86 != m->family) +continue ; +if (c->x86_model != m->model) +continue ; +if (!cpu_has (c, m->feature)) +continue ; +return m; + } +return NULL ; +}
Please honor tab indentation used in the rest of this file.
xen/arch/x86/cpu/common.c unsigned int paddr_bits __read_mostly = 36; · line 85
Quoted 1 line
xen/arch/x86/cpu/common.c +1
-0+EXPORT_SYMBOL (x86_match_cpu);
???
xen/arch/x86/cpu/common.c unsigned int paddr_bits __read_mostly = 36; · line 87
Quoted 1 line
xen/arch/x86/cpu/common.c +0
-0static unsigned int __cpuinitdata cleared_caps[NCAPINTS ];
I also dislike the function being placed between two data definitions; I'd rather see this go (much) farther down in the file.
xen/arch/x86/cpu/mwait-idle.c line 63
Quoted 8 lines
xen/arch/x86/cpu/mwait-idle.c +2
-0@@ -59,6 +59,8 @@#include <asm/hpet.h> #include <asm/mwait.h> #include <asm/msr.h> +#include <asm/processor.h> +#include <asm/cpufeature.h>
The former alone would be sufficient.
Quoted 4 lines
xen/arch/x86/cpu/mwait-idle.c +0
-0@@ -656,12 +658,11 @@ static const struct idle_cpu idle_cpu_avn = { .disable_promotion_to_c1e = 1, };
xen/arch/x86/cpu/mwait-idle.c static const struct idle_cpu idle_cpu_avn = { · line 665
Quoted 10 lines
xen/arch/x86/cpu/mwait-idle.c +4
-5-#define ICPU (model, cpu) { 6, model, &idle_cpu_##cpu } +#define ICPU (model, cpu) \ + { X86_VENDOR_INTEL, 6, model, X86_FEATURE_MWAIT, \ + (unsigned long)&idle_cpu_##cpu} -static struct intel_idle_id { -unsigned int family, model; -const struct idle_cpu *data; -} intel_idle_ids[]__initdata = { +static const struct x86_cpu_id intel_idle_ids[] = {
__initconst
Quoted 9 lines
xen/arch/x86/cpu/mwait-idle.c +1
-3@@ -722,23 +723,18 @@ static void __init mwait_idle_state_table_update(void)static int __init mwait_idle_probe (void ) {unsigned int eax, ebx, ecx; -const struct intel_idle_id *id; +const struct x86_cpu_id *id; - if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL || - !boot_cpu_has(X86_FEATURE_MWAIT) ||
xen/arch/x86/cpu/mwait-idle.c static void __init mwait_idle_state_table_update(void) · line 729
Quoted 10 lines
xen/arch/x86/cpu/mwait-idle.c +2
-8- boot_cpu_data.cpuid_level < CPUID_MWAIT_LEAF) -return -ENODEV ; - -for (id = intel_idle_ids; id->family; ++id) -if (id->family == boot_cpu_data.x86 && - id->model == boot_cpu_data.x86_model) -break ; -if (!id->family) { + id =x86_match_cpu (intel_idle_ids); +if (!id) {
Please don't corrupt indentation.
xen/include/asm-x86/processor.h struct vcpu; · line 170
Quoted 11 lines
xen/include/asm-x86/processor.h +5
-0@@ -163,6 +163,14 @@ struct vcpu; pc; \ }) +struct x86_cpu_id { +__u16 vendor; +__u16 family; +__u16 model; +__u16 feature;/* bit index */
In order of preference we'd like to use uintNN_t, uNN, and only then __uNN (even if pre-existing code may violate this).
xen/include/asm-x86/processor.h struct vcpu; · line 171
Quoted 1 line
xen/include/asm-x86/processor.h +1
-0+__u64 driver_data;
void * please, avoiding casts.
xen/include/asm-x86/processor.h extern u32 cpuid_ext_features; · line 215
Quoted 5 lines
xen/include/asm-x86/processor.h +1
-0@@ -204,6 +212,8 @@ extern u32 cpuid_ext_features;/* Maximum width of physical addresses supported by the hardware */ extern unsigned int paddr_bits; +extern const struct x86_cpu_id *x86_match_cpu (const struct x86_cpu_id *match);
extern const struct x86_cpu_id *x86_match_cpu(const struct x86_cpu_id table[]);
Jan