]> rtime.felk.cvut.cz Git - jailhouse.git/blob - inmates/lib/x86/pm-timer.c
inmates: Map Comm Region always at 0x100000 for inmates framework
[jailhouse.git] / inmates / lib / x86 / pm-timer.c
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) Siemens AG, 2013
5  *
6  * Authors:
7  *  Jan Kiszka <jan.kiszka@siemens.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  */
12
13 #include <inmate.h>
14
15 #define NS_PER_SEC              1000000000UL
16
17 #define PM_TIMER_HZ             3579545
18 #define PM_TIMER_OVERFLOW       ((0x1000000 * 1000000000ULL) / PM_TIMER_HZ)
19
20 unsigned long read_pm_timer(void)
21 {
22         static unsigned long last, overflows;
23         unsigned long tmr;
24
25         tmr = (inl(comm_region->pm_timer_address) * NS_PER_SEC) / PM_TIMER_HZ;
26         if (tmr < last)
27                 overflows += PM_TIMER_OVERFLOW;
28         last = tmr;
29         return tmr + overflows;
30 }