diff options
| -rw-r--r-- | arch/x86/kernel/cpu/mshyperv.c | 23 | ||||
| -rw-r--r-- | drivers/staging/hv/Makefile | 1 | ||||
| -rw-r--r-- | drivers/staging/hv/hv_timesource.c | 101 |
3 files changed, 23 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 | ||
| 41 | static 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 | |||
| 53 | static 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 | |||
| 39 | static void __init ms_hyperv_init_platform(void) | 60 | static 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 | ||
| 51 | const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = { | 74 | const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = { |
diff --git a/drivers/staging/hv/Makefile b/drivers/staging/hv/Makefile index e071c12c8f69..0f55ceee919b 100644 --- a/drivers/staging/hv/Makefile +++ b/drivers/staging/hv/Makefile | |||
| @@ -1,4 +1,3 @@ | |||
| 1 | obj-$(CONFIG_HYPERV) += hv_timesource.o | ||
| 2 | obj-$(CONFIG_HYPERV_STORAGE) += hv_storvsc.o | 1 | obj-$(CONFIG_HYPERV_STORAGE) += hv_storvsc.o |
| 3 | obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o | 2 | obj-$(CONFIG_HYPERV_NET) += hv_netvsc.o |
| 4 | obj-$(CONFIG_HYPERV_MOUSE) += hv_mouse.o | 3 | obj-$(CONFIG_HYPERV_MOUSE) += hv_mouse.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 | |||
| 36 | static 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 | |||
| 48 | static 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 | |||
| 63 | static const struct dmi_system_id __initconst | ||
| 64 | hv_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 | }; | ||
| 75 | MODULE_DEVICE_TABLE(dmi, hv_timesource_dmi_table); | ||
| 76 | |||
| 77 | static const struct pci_device_id __initconst | ||
| 78 | hv_timesource_pci_table[] __maybe_unused = { | ||
| 79 | { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */ | ||
| 80 | { 0 } | ||
| 81 | }; | ||
| 82 | MODULE_DEVICE_TABLE(pci, hv_timesource_pci_table); | ||
| 83 | |||
| 84 | |||
| 85 | static 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 | |||
| 98 | module_init(init_hv_clocksource); | ||
| 99 | MODULE_DESCRIPTION("HyperV based clocksource"); | ||
| 100 | MODULE_AUTHOR("K. Y. Srinivasan <ksrinivasan@novell.com>"); | ||
| 101 | MODULE_LICENSE("GPL"); | ||
