summaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/cpu/mshyperv.c
blob: a58d8e64fc7ce331d0d1a56d823412f8b86ea179 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * HyperV  Detection code.
 *
 * Copyright (C) 2010, Novell, Inc.
 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 */

#include <linux/types.h>
#include <asm/processor.h>
#include <asm/hyperv.h>
#include <asm/mshyperv.h>


int ms_hyperv_platform(void)
{
	u32 eax, ebx, ecx, edx;
	char hyp_signature[13];

	cpuid(1, &eax, &ebx, &ecx, &edx);
	if (!(ecx & HYPERV_HYPERVISOR_PRESENT_BIT))
		return 0;

	cpuid(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS, &eax, &ebx, &ecx, &edx);
	*(u32 *)(hyp_signature + 0) = ebx;
	*(u32 *)(hyp_signature + 4) = ecx;
	*(u32 *)(hyp_signature + 8) = edx;

	if ((eax < HYPERV_CPUID_MIN) || (memcmp("Microsoft Hv", hyp_signature, 12)))
		return 0;
	return 1;
}

void __cpuinit ms_hyperv_set_feature_bits(struct cpuinfo_x86 *c)
{
	u32 eax, ebx, ecx, edx;

	c->x86_hyper_features = 0;
	/*
	 * Extract the features, recommendations etc.
	 * The first 9 bits will be used to track hypervisor features.
	 * The next 6 bits will be used to track the hypervisor
	 * recommendations.
	 */
	cpuid(HYPERV_CPUID_FEATURES, &eax, &ebx, &ecx, &edx);
	c->x86_hyper_features |= (eax & 0x1ff);

	cpuid(HYPERV_CPUID_ENLIGHTMENT_INFO, &eax, &ebx, &ecx, &edx);
	c->x86_hyper_features |= ((eax & 0x3f) << 9);
	printk(KERN_INFO "Detected HyperV with features: %x\n",
		c->x86_hyper_features);
}