thinkpad-acpi: handle HKEY 0x4010, 0x4011 events
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / hv / hv_timesource.c
blob0efb04915255dfb7a9d8544154922b2ce8704199
1 /*
2 * A clocksource for Linux running on HyperV.
5 * Copyright (C) 2010, Novell, Inc.
6 * Author : K. Y. Srinivasan <ksrinivasan@novell.com>
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.
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.
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.
23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/version.h>
26 #include <linux/clocksource.h>
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/pci.h>
30 #include <linux/dmi.h>
31 #include <asm/hyperv.h>
32 #include <asm/mshyperv.h>
33 #include <asm/hypervisor.h>
35 #define HV_CLOCK_SHIFT 22
37 static cycle_t read_hv_clock(struct clocksource *arg)
39 cycle_t current_tick;
41 * Read the partition counter to get the current tick count. This count
42 * is set to 0 when the partition is created and is incremented in
43 * 100 nanosecond units.
45 rdmsrl(HV_X64_MSR_TIME_REF_COUNT, current_tick);
46 return current_tick;
49 static struct clocksource hyperv_cs = {
50 .name = "hyperv_clocksource",
51 .rating = 400, /* use this when running on Hyperv*/
52 .read = read_hv_clock,
53 .mask = CLOCKSOURCE_MASK(64),
55 * The time ref counter in HyperV is in 100ns units.
56 * The definition of mult is:
57 * mult/2^shift = ns/cyc = 100
58 * mult = (100 << shift)
60 .mult = (100 << HV_CLOCK_SHIFT),
61 .shift = HV_CLOCK_SHIFT,
64 static const struct dmi_system_id __initconst
65 hv_timesource_dmi_table[] __maybe_unused = {
67 .ident = "Hyper-V",
68 .matches = {
69 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
70 DMI_MATCH(DMI_PRODUCT_NAME, "Virtual Machine"),
71 DMI_MATCH(DMI_BOARD_NAME, "Virtual Machine"),
74 { },
76 MODULE_DEVICE_TABLE(dmi, hv_timesource_dmi_table);
78 static const struct pci_device_id __initconst
79 hv_timesource_pci_table[] __maybe_unused = {
80 { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */
81 { 0 }
83 MODULE_DEVICE_TABLE(pci, hv_timesource_pci_table);
86 static int __init init_hv_clocksource(void)
88 if ((x86_hyper != &x86_hyper_ms_hyperv) ||
89 !(ms_hyperv.features & HV_X64_MSR_TIME_REF_COUNT_AVAILABLE))
90 return -ENODEV;
92 if (!dmi_check_system(hv_timesource_dmi_table))
93 return -ENODEV;
95 pr_info("Registering HyperV clock source\n");
96 return clocksource_register(&hyperv_cs);
99 module_init(init_hv_clocksource);
100 MODULE_DESCRIPTION("HyperV based clocksource");
101 MODULE_AUTHOR("K. Y. Srinivasan <ksrinivasan@novell.com>");
102 MODULE_LICENSE("GPL");