aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKy Srinivasan <ksrinivasan@novell.com>2010-05-06 15:08:41 -0400
committerH. Peter Anvin <hpa@zytor.com>2010-05-06 21:24:15 -0400
commita2a47c6c3d1a7c01da4464b3b7be93b924f874c1 (patch)
treee647047bb37cce40777bf29c4aef8f92a56cdad8
parent097c1bd5673edaf2a162724636858b71f658fdd2 (diff)
x86: Detect running on a Microsoft HyperV system
This patch integrates HyperV detection within the framework currently used by VmWare. With this patch, we can avoid having to replicate the HyperV detection code in each of the Microsoft HyperV drivers. Reworked and tweaked by Greg K-H to build properly. Signed-off-by: K. Y. Srinivasan <ksrinivasan@novell.com> LKML-Reference: <20100506190841.GA1605@kroah.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@redhat.com> Cc: "H. Peter Anvin" <hpa@zytor.com> Cc: Vadim Rozenfeld <vrozenfe@redhat.com> Cc: Avi Kivity <avi@redhat.com> Cc: Gleb Natapov <gleb@redhat.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Cc: "K.Prasad" <prasad@linux.vnet.ibm.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Alan Cox <alan@linux.intel.com> Cc: Haiyang Zhang <haiyangz@microsoft.com> Cc: Hank Janssen <hjanssen@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--arch/x86/include/asm/hyperv.h6
-rw-r--r--arch/x86/include/asm/mshyperv.h7
-rw-r--r--arch/x86/include/asm/processor.h3
-rw-r--r--arch/x86/kernel/cpu/Makefile2
-rw-r--r--arch/x86/kernel/cpu/hypervisor.c10
-rw-r--r--arch/x86/kernel/cpu/mshyperv.c67
6 files changed, 91 insertions, 4 deletions
diff --git a/arch/x86/include/asm/hyperv.h b/arch/x86/include/asm/hyperv.h
index e153a2b3889a..46040473e122 100644
--- a/arch/x86/include/asm/hyperv.h
+++ b/arch/x86/include/asm/hyperv.h
@@ -14,6 +14,9 @@
14#define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004 14#define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004
15#define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005 15#define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005
16 16
17#define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000
18#define HYPERV_CPUID_MIN 0x40000005
19
17/* 20/*
18 * Feature identification. EAX indicates which features are available 21 * Feature identification. EAX indicates which features are available
19 * to the partition based upon the current partition privileges. 22 * to the partition based upon the current partition privileges.
@@ -129,6 +132,9 @@
129/* MSR used to provide vcpu index */ 132/* MSR used to provide vcpu index */
130#define HV_X64_MSR_VP_INDEX 0x40000002 133#define HV_X64_MSR_VP_INDEX 0x40000002
131 134
135/* MSR used to read the per-partition time reference counter */
136#define HV_X64_MSR_TIME_REF_COUNT 0x40000020
137
132/* Define the virtual APIC registers */ 138/* Define the virtual APIC registers */
133#define HV_X64_MSR_EOI 0x40000070 139#define HV_X64_MSR_EOI 0x40000070
134#define HV_X64_MSR_ICR 0x40000071 140#define HV_X64_MSR_ICR 0x40000071
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
new file mode 100644
index 000000000000..6cd8101d1344
--- /dev/null
+++ b/arch/x86/include/asm/mshyperv.h
@@ -0,0 +1,7 @@
1#ifndef ASM_X86__MSHYPER_H
2#define ASM_X86__MSHYPER_H
3
4int ms_hyperv_platform(void);
5void __cpuinit ms_hyperv_set_feature_bits(struct cpuinfo_x86 *c);
6
7#endif
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index b753ea59703a..597c041bd124 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -114,6 +114,8 @@ struct cpuinfo_x86 {
114 u16 cpu_index; 114 u16 cpu_index;
115#endif 115#endif
116 unsigned int x86_hyper_vendor; 116 unsigned int x86_hyper_vendor;
117 /* The layout of this field is hypervisor specific */
118 unsigned int x86_hyper_features;
117} __attribute__((__aligned__(SMP_CACHE_BYTES))); 119} __attribute__((__aligned__(SMP_CACHE_BYTES)));
118 120
119#define X86_VENDOR_INTEL 0 121#define X86_VENDOR_INTEL 0
@@ -129,6 +131,7 @@ struct cpuinfo_x86 {
129 131
130#define X86_HYPER_VENDOR_NONE 0 132#define X86_HYPER_VENDOR_NONE 0
131#define X86_HYPER_VENDOR_VMWARE 1 133#define X86_HYPER_VENDOR_VMWARE 1
134#define X86_HYPER_VENDOR_MSFT 2
132 135
133/* 136/*
134 * capabilities of CPUs 137 * capabilities of CPUs
diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
index c202b62f3671..3a785da34b6f 100644
--- a/arch/x86/kernel/cpu/Makefile
+++ b/arch/x86/kernel/cpu/Makefile
@@ -14,7 +14,7 @@ CFLAGS_common.o := $(nostackp)
14 14
15obj-y := intel_cacheinfo.o addon_cpuid_features.o 15obj-y := intel_cacheinfo.o addon_cpuid_features.o
16obj-y += proc.o capflags.o powerflags.o common.o 16obj-y += proc.o capflags.o powerflags.o common.o
17obj-y += vmware.o hypervisor.o sched.o 17obj-y += vmware.o hypervisor.o sched.o mshyperv.o
18 18
19obj-$(CONFIG_X86_32) += bugs.o cmpxchg.o 19obj-$(CONFIG_X86_32) += bugs.o cmpxchg.o
20obj-$(CONFIG_X86_64) += bugs_64.o 20obj-$(CONFIG_X86_64) += bugs_64.o
diff --git a/arch/x86/kernel/cpu/hypervisor.c b/arch/x86/kernel/cpu/hypervisor.c
index 08be922de33a..de3f4e0ce8eb 100644
--- a/arch/x86/kernel/cpu/hypervisor.c
+++ b/arch/x86/kernel/cpu/hypervisor.c
@@ -23,6 +23,7 @@
23 23
24#include <asm/processor.h> 24#include <asm/processor.h>
25#include <asm/vmware.h> 25#include <asm/vmware.h>
26#include <asm/mshyperv.h>
26#include <asm/hypervisor.h> 27#include <asm/hypervisor.h>
27 28
28static inline void __cpuinit 29static inline void __cpuinit
@@ -30,6 +31,8 @@ detect_hypervisor_vendor(struct cpuinfo_x86 *c)
30{ 31{
31 if (vmware_platform()) 32 if (vmware_platform())
32 c->x86_hyper_vendor = X86_HYPER_VENDOR_VMWARE; 33 c->x86_hyper_vendor = X86_HYPER_VENDOR_VMWARE;
34 else if (ms_hyperv_platform())
35 c->x86_hyper_vendor = X86_HYPER_VENDOR_MSFT;
33 else 36 else
34 c->x86_hyper_vendor = X86_HYPER_VENDOR_NONE; 37 c->x86_hyper_vendor = X86_HYPER_VENDOR_NONE;
35} 38}
@@ -37,10 +40,11 @@ detect_hypervisor_vendor(struct cpuinfo_x86 *c)
37static inline void __cpuinit 40static inline void __cpuinit
38hypervisor_set_feature_bits(struct cpuinfo_x86 *c) 41hypervisor_set_feature_bits(struct cpuinfo_x86 *c)
39{ 42{
40 if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE) { 43 if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_VMWARE)
41 vmware_set_feature_bits(c); 44 vmware_set_feature_bits(c);
42 return; 45 else if (boot_cpu_data.x86_hyper_vendor == X86_HYPER_VENDOR_MSFT)
43 } 46 ms_hyperv_set_feature_bits(c);
47 return;
44} 48}
45 49
46void __cpuinit init_hypervisor(struct cpuinfo_x86 *c) 50void __cpuinit init_hypervisor(struct cpuinfo_x86 *c)
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
new file mode 100644
index 000000000000..2443b61cdb17
--- /dev/null
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -0,0 +1,67 @@
1/*
2 * HyperV Detection code.
3 *
4 * Copyright (C) 2010, Novell, Inc.
5 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
15 * NON INFRINGEMENT. See the GNU General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <linux/types.h>
25#include <asm/processor.h>
26#include <asm/hyperv.h>
27#include <asm/mshyperv.h>
28
29
30int ms_hyperv_platform(void)
31{
32 u32 eax, ebx, ecx, edx;
33 char hyp_signature[13];
34
35 cpuid(1, &eax, &ebx, &ecx, &edx);
36 if (!(ecx & HYPERV_HYPERVISOR_PRESENT_BIT))
37 return 0;
38
39 cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS, &eax, &ebx, &ecx, &edx);
40 *(u32 *)(hyp_signature + 0) = ebx;
41 *(u32 *)(hyp_signature + 4) = ecx;
42 *(u32 *)(hyp_signature + 8) = edx;
43
44 if ((eax < HYPERV_CPUID_MIN) || (memcmp("Microsoft Hv", hyp_signature, 12)))
45 return 0;
46 return 1;
47}
48
49void __cpuinit ms_hyperv_set_feature_bits(struct cpuinfo_x86 *c)
50{
51 u32 eax, ebx, ecx, edx;
52
53 c->x86_hyper_features = 0;
54 /*
55 * Extract the features, recommendations etc.
56 * The first 9 bits will be used to track hypervisor features.
57 * The next 6 bits will be used to track the hypervisor
58 * recommendations.
59 */
60 cpuid(HYPERV_CPUID_FEATURES, &eax, &ebx, &ecx, &edx);
61 c->x86_hyper_features |= (eax & 0x1ff);
62
63 cpuid(HYPERV_CPUID_ENLIGHTMENT_INFO, &eax, &ebx, &ecx, &edx);
64 c->x86_hyper_features |= ((eax & 0x3f) << 9);
65 printk(KERN_INFO "Detected HyperV with features: %x\n",
66 c->x86_hyper_features);
67}