aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-05-07 19:57:28 -0400
committerH. Peter Anvin <hpa@zytor.com>2010-05-07 20:13:04 -0400
commite08cae4181af9483b04ecfac48f01c8e5a5f27bf (patch)
tree2cab8da747a6524694cc19f247d8bc4f157a601c
parent9fa02317429449e8176c9bb6da3ac00eb14d52d3 (diff)
x86: Clean up the hypervisor layer
Clean up the hypervisor layer and the hypervisor drivers, using an ops structure instead of an enumeration with if statements. The identity of the hypervisor, if needed, can be tested by testing the pointer value in x86_hyper. The MS-HyperV private state is moved into a normal global variable (it's per-system state, not per-CPU state). Being a normal bss variable, it will be left at all zero on non-HyperV platforms, and so can generally be tested for HyperV-specific features without additional qualification. Signed-off-by: H. Peter Anvin <hpa@zytor.com> Acked-by: Greg KH <greg@kroah.com> Cc: Hank Janssen <hjanssen@microsoft.com> Cc: Alok Kataria <akataria@vmware.com> Cc: Ky Srinivasan <ksrinivasan@novell.com> LKML-Reference: <4BE49778.6060800@zytor.com>
-rw-r--r--arch/x86/include/asm/hyperv.h5
-rw-r--r--arch/x86/include/asm/hypervisor.h27
-rw-r--r--arch/x86/include/asm/mshyperv.h15
-rw-r--r--arch/x86/include/asm/processor.h7
-rw-r--r--arch/x86/include/asm/vmware.h27
-rw-r--r--arch/x86/kernel/cpu/hypervisor.c56
-rw-r--r--arch/x86/kernel/cpu/mshyperv.c51
-rw-r--r--arch/x86/kernel/cpu/vmware.c36
8 files changed, 117 insertions, 107 deletions
diff --git a/arch/x86/include/asm/hyperv.h b/arch/x86/include/asm/hyperv.h
index 46040473e122..5df477ac3af7 100644
--- a/arch/x86/include/asm/hyperv.h
+++ b/arch/x86/include/asm/hyperv.h
@@ -1,5 +1,5 @@
1#ifndef _ASM_X86_KVM_HYPERV_H 1#ifndef _ASM_X86_HYPERV_H
2#define _ASM_X86_KVM_HYPERV_H 2#define _ASM_X86_HYPERV_H
3 3
4#include <linux/types.h> 4#include <linux/types.h>
5 5
@@ -16,6 +16,7 @@
16 16
17#define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000 17#define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000
18#define HYPERV_CPUID_MIN 0x40000005 18#define HYPERV_CPUID_MIN 0x40000005
19#define HYPERV_CPUID_MAX 0x4000ffff
19 20
20/* 21/*
21 * Feature identification. EAX indicates which features are available 22 * Feature identification. EAX indicates which features are available
diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h
index b78c0941e422..70abda7058c8 100644
--- a/arch/x86/include/asm/hypervisor.h
+++ b/arch/x86/include/asm/hypervisor.h
@@ -17,10 +17,33 @@
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 * 18 *
19 */ 19 */
20#ifndef ASM_X86__HYPERVISOR_H 20#ifndef _ASM_X86_HYPERVISOR_H
21#define ASM_X86__HYPERVISOR_H 21#define _ASM_X86_HYPERVISOR_H
22 22
23extern void init_hypervisor(struct cpuinfo_x86 *c); 23extern void init_hypervisor(struct cpuinfo_x86 *c);
24extern void init_hypervisor_platform(void); 24extern void init_hypervisor_platform(void);
25 25
26/*
27 * x86 hypervisor information
28 */
29struct hypervisor_x86 {
30 /* Hypervisor name */
31 const char *name;
32
33 /* Detection routine */
34 bool (*detect)(void);
35
36 /* Adjust CPU feature bits (run once per CPU) */
37 void (*set_cpu_features)(struct cpuinfo_x86 *);
38
39 /* Platform setup (run once per boot) */
40 void (*init_platform)(void);
41};
42
43extern const struct hypervisor_x86 *x86_hyper;
44
45/* Recognized hypervisors */
46extern const struct hypervisor_x86 x86_hyper_vmware;
47extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
48
26#endif 49#endif
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 6cd8101d1344..79ce5685ab64 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -1,7 +1,14 @@
1#ifndef ASM_X86__MSHYPER_H 1#ifndef _ASM_X86_MSHYPER_H
2#define ASM_X86__MSHYPER_H 2#define _ASM_X86_MSHYPER_H
3 3
4int ms_hyperv_platform(void); 4#include <linux/types.h>
5void __cpuinit ms_hyperv_set_feature_bits(struct cpuinfo_x86 *c); 5#include <asm/hyperv.h>
6
7struct ms_hyperv_info {
8 u32 features;
9 u32 hints;
10};
11
12extern struct ms_hyperv_info ms_hyperv;
6 13
7#endif 14#endif
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index 597c041bd124..e4f1dfb2d05b 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -113,9 +113,6 @@ struct cpuinfo_x86 {
113 /* Index into per_cpu list: */ 113 /* Index into per_cpu list: */
114 u16 cpu_index; 114 u16 cpu_index;
115#endif 115#endif
116 unsigned int x86_hyper_vendor;
117 /* The layout of this field is hypervisor specific */
118 unsigned int x86_hyper_features;
119} __attribute__((__aligned__(SMP_CACHE_BYTES))); 116} __attribute__((__aligned__(SMP_CACHE_BYTES)));
120 117
121#define X86_VENDOR_INTEL 0 118#define X86_VENDOR_INTEL 0
@@ -129,10 +126,6 @@ struct cpuinfo_x86 {
129 126
130#define X86_VENDOR_UNKNOWN 0xff 127#define X86_VENDOR_UNKNOWN 0xff
131 128
132#define X86_HYPER_VENDOR_NONE 0
133#define X86_HYPER_VENDOR_VMWARE 1
134#define X86_HYPER_VENDOR_MSFT 2
135
136/* 129/*
137 * capabilities of CPUs 130 * capabilities of CPUs
138 */ 131 */
diff --git a/arch/x86/include/asm/vmware.h b/arch/x86/include/asm/vmware.h
deleted file mode 100644
index e49ed6d2fd4e..000000000000
--- a/arch/x86/include/asm/vmware.h
+++ /dev/null
@@ -1,27 +0,0 @@
1/*
2 * Copyright (C) 2008, VMware, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 */
20#ifndef ASM_X86__VMWARE_H
21#define ASM_X86__VMWARE_H
22
23extern void vmware_platform_setup(void);
24extern int vmware_platform(void);
25extern void vmware_set_feature_bits(struct cpuinfo_x86 *c);
26
27#endif
diff --git a/arch/x86/kernel/cpu/hypervisor.c b/arch/x86/kernel/cpu/hypervisor.c
index de3f4e0ce8eb..87381759d3cb 100644
--- a/arch/x86/kernel/cpu/hypervisor.c
+++ b/arch/x86/kernel/cpu/hypervisor.c
@@ -22,40 +22,52 @@
22 */ 22 */
23 23
24#include <asm/processor.h> 24#include <asm/processor.h>
25#include <asm/vmware.h>
26#include <asm/mshyperv.h>
27#include <asm/hypervisor.h> 25#include <asm/hypervisor.h>
28 26
29static inline void __cpuinit 27/*
30detect_hypervisor_vendor(struct cpuinfo_x86 *c) 28 * Hypervisor detect order. This is specified explicitly here because
29 * some hypervisors might implement compatibility modes for other
30 * hypervisors and therefore need to be detected in specific sequence.
31 */
32static const __initconst struct hypervisor_x86 * const hypervisors[] =
31{ 33{
32 if (vmware_platform()) 34 &x86_hyper_vmware,
33 c->x86_hyper_vendor = X86_HYPER_VENDOR_VMWARE; 35 &x86_hyper_ms_hyperv,
34 else if (ms_hyperv_platform()) 36};
35 c->x86_hyper_vendor = X86_HYPER_VENDOR_MSFT;
36 else
37 c->x86_hyper_vendor = X86_HYPER_VENDOR_NONE;
38}
39 37
40static inline void __cpuinit 38const struct hypervisor_x86 *x86_hyper;
41hypervisor_set_feature_bits(struct cpuinfo_x86 *c) 39
40static inline void __init
41detect_hypervisor_vendor(void)
42{ 42{
43 if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE) 43 const struct hypervisor_x86 *h, * const *p;
44 vmware_set_feature_bits(c); 44
45 else if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_MSFT) 45 for (p = hypervisors; p < hypervisors + ARRAY_SIZE(hypervisors); p++) {
46 ms_hyperv_set_feature_bits(c); 46 h = *p;
47</