aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorK. Y. Srinivasan <kys@microsoft.com>2011-09-07 18:25:10 -0400
committerThomas Gleixner <tglx@linutronix.de>2011-09-08 04:33:59 -0400
commit6f4151c89b7d036c755d8cf74729e09b76fa6676 (patch)
treec86026f4c56764596f5425892850f89cbc77ffb3
parentddf28352b80c86754a6424e3a61e8bdf9213b3c7 (diff)
x86: Hyper-V: Integrate the clocksource with Hyper-V detection code
The Hyper-V clocksource driver is best integrated with Hyper-V detection code since: (a) Linux guests running on Hyper-V require it (b) Integration into that code significanly reduces code size Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> Cc: gregkh@suse.de Cc: devel@linuxdriverproject.org Cc: virtualization@lists.osdl.org Link: http://lkml.kernel.org/r/1315434310-4827-1-git-send-email-kys@microsoft.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
-rw-r--r--arch/x86/kernel/cpu/mshyperv.c23
-rw-r--r--drivers/staging/hv/Makefile2
-rw-r--r--drivers/staging/hv/hv_timesource.c101
3 files changed, 24 insertions, 102 deletions
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index d944bf6c50e9..0a630dd4b620 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -11,6 +11,8 @@
11 */ 11 */
12 12
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/time.h>
15#include <linux/clocksource.h>
14#include <linux/module.h> 16#include <linux/module.h>
15#include <asm/processor.h> 17#include <asm/processor.h>
16#include <asm/hypervisor.h> 18#include <asm/hypervisor.h>
@@ -36,6 +38,25 @@ static bool __init ms_hyperv_platform(void)
36 !memcmp("Microsoft Hv", hyp_signature, 12); 38 !memcmp("Microsoft Hv", hyp_signature, 12);
37} 39}
38 40
41static cycle_t read_hv_clock(struct clocksource *arg)
42{
43 cycle_t current_tick;
44 /*
45 * Read the partition counter to get the current tick count. This count
46 * is set to 0 when the partition is created and is incremented in
47 * 100 nanosecond units.
48 */
49 rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick);
50 return current_tick;
51}
52
53static struct clocksource hyperv_cs = {
54 .name = "hyperv_clocksource",
55 .rating = 400, /* use this when running on Hyperv*/
56 .read = read_hv_clock,
57 .mask = CLOCKSOURCE_MASK(64),
58};
59
39static void __init ms_hyperv_init_platform(void) 60static void __init ms_hyperv_init_platform(void)
40{ 61{
41 /* 62 /*
@@ -46,6 +67,8 @@ static void __init ms_hyperv_init_platform(void)
46 67
47 printk(KERN_INFO "HyperV: features 0x%x, hints 0x%x\n", 68 printk(KERN_INFO "HyperV: features 0x%x, hints 0x%x\n",
48 ms_hyperv.features, ms_hyperv.hints); 69 ms_hyperv.features, ms_hyperv.hints);
70
71 clocksource_register_hz(&hyperv_cs, NSEC_PER_SEC/100);
49} 72}
50 73
51const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = { 74const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
diff --git a/drivers/staging/hv/Makefile b/drivers/staging/hv/Makefile
index 30046743a0b4..14e3c6a14ea4 100644
--- a/drivers/staging/hv/Makefile
+++ b/drivers/staging/hv/Makefile
@@ -1,4 +1,4 @@
1obj-$(CONFIG_HYPERV) += hv_vmbus.o hv_timesource.o 1obj-$(CONFIG_HYPERV) += hv_vmbus.o
2obj-$(CONFIG_HYPERV_STORAGE) += hv_storvsc.o 2obj-$(CONFIG_HYPERV_STORAGE) += hv_storvsc.o
3obj-$(CONFIG_HYPERV_BLOCK) += hv_blkvsc.o 3obj-$(CONFIG_HYPERV_BLOCK) += hv_blkvsc.o
4obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o 4obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o
diff --git a/drivers/staging/hv/hv_timesource.c b/drivers/staging/hv/hv_timesource.c
deleted file mode 100644
index 2b0f9aaf9122..000000000000
--- a/drivers/staging/hv/hv_timesource.c
+++ /dev/null
@@ -1,101 +0,0 @@
1/*
2 * A clocksource for Linux running on HyperV.
3 *
4 *
5 * Copyright (C) 2010, Novell, Inc.
6 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
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#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
24
25#include <linux/clocksource.h>
26#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/pci.h>
29#include <linux/dmi.h>
30#include <asm/hyperv.h>
31#include <asm/mshyperv.h>
32#include <asm/hypervisor.h>
33
34#define HV_CLOCK_SHIFT 22
35
36static cycle_t read_hv_clock(struct clocksource *arg)
37{
38 cycle_t current_tick;
39 /*
40 * Read the partition counter to get the current tick count. This count
41 * is set to 0 when the partition is created and is incremented in
42 * 100 nanosecond units.
43 */
44 rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick);
45 return current_tick;
46}
47
48static struct clocksource hyperv_cs = {
49 .name = "hyperv_clocksource",
50 .rating = 400, /* use this when running on Hyperv*/
51 .read = read_hv_clock,
52 .mask = CLOCKSOURCE_MASK(64),
53 /*
54 * The time ref counter in HyperV is in 100ns units.
55 * The definition of mult is:
56 * mult/2^shift = ns/cyc = 100
57 * mult = (100 << shift)
58 */
59 .mult = (100 << HV_CLOCK_SHIFT),
60 .shift = HV_CLOCK_SHIFT,
61};
62
63static const struct dmi_system_id __initconst
64hv_timesource_dmi_table[] __maybe_unused = {
65 {
66 .ident = "Hyper-V",
67 .matches = {
68 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
69 DMI_MATCH(DMI_PRODUCT_NAME, "Virtual Machine"),
70 DMI_MATCH(DMI_BOARD_NAME, "Virtual Machine"),
71 },
72 },
73 { },
74};
75MODULE_DEVICE_TABLE(dmi, hv_timesource_dmi_table);
76
77static const struct pci_device_id __initconst
78hv_timesource_pci_table[] __maybe_unused = {
79 { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
80 { 0 }
81};
82MODULE_DEVICE_TABLE(pci, hv_timesource_pci_table);
83
84
85static int __init init_hv_clocksource(void)
86{
87 if ((x86_hyper != &x86_hyper_ms_hyperv) ||
88 !(ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE))
89 return -ENODEV;
90
91 if (!dmi_check_system(hv_timesource_dmi_table))
92 return -ENODEV;
93
94 pr_info("Registering HyperV clock source\n");
95 return clocksource_register(&hyperv_cs);
96}
97
98module_init(init_hv_clocksource);
99MODULE_DESCRIPTION("HyperV based clocksource");
100MODULE_AUTHOR("K. Y. Srinivasan <ksrinivasan@novell.com>");
101MODULE_LICENSE("GPL");