x86/kvm: Pass stable clocksource to guests when running nested on Hyper-V
[linux/fpc-iii.git] / arch / arm64 / lib / delay.c
blobe48ac402e7be131781fc2e5befd769118bffacec
1 /*
2 * Delay loops based on the OpenRISC implementation.
4 * Copyright (C) 2012 ARM Limited
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Author: Will Deacon <will.deacon@arm.com>
21 #include <linux/delay.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/timex.h>
27 #include <clocksource/arm_arch_timer.h>
29 #define USECS_TO_CYCLES(time_usecs) \
30 xloops_to_cycles((time_usecs) * 0x10C7UL)
32 static inline unsigned long xloops_to_cycles(unsigned long xloops)
34 return (xloops * loops_per_jiffy * HZ) >> 32;
37 void __delay(unsigned long cycles)
39 cycles_t start = get_cycles();
41 if (arch_timer_evtstrm_available()) {
42 const cycles_t timer_evt_period =
43 USECS_TO_CYCLES(ARCH_TIMER_EVT_STREAM_PERIOD_US);
45 while ((get_cycles() - start + timer_evt_period) < cycles)
46 wfe();
49 while ((get_cycles() - start) < cycles)
50 cpu_relax();
52 EXPORT_SYMBOL(__delay);
54 inline void __const_udelay(unsigned long xloops)
56 __delay(xloops_to_cycles(xloops));
58 EXPORT_SYMBOL(__const_udelay);
60 void __udelay(unsigned long usecs)
62 __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
64 EXPORT_SYMBOL(__udelay);
66 void __ndelay(unsigned long nsecs)
68 __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
70 EXPORT_SYMBOL(__ndelay);