xref: /kvm-unit-tests/lib/arm/delay.c (revision 0df901e0379da84a0eaec1daf464c699995dddf5)
1 /*
2  * Delay loops
3  *
4  * Copyright (C) 2016, Red Hat Inc, Andrew Jones <drjones@redhat.com>
5  *
6  * This work is licensed under the terms of the GNU LGPL, version 2.
7  */
8 #include <libcflat.h>
9 #include <asm/processor.h>
10 #include <asm/barrier.h>
11 #include <asm/delay.h>
12 
delay(u64 cycles)13 void delay(u64 cycles)
14 {
15 	u64 start = get_cntvct();
16 
17 	while ((get_cntvct() - start) < cycles)
18 		cpu_relax();
19 }
20 
udelay(unsigned long usec)21 void udelay(unsigned long usec)
22 {
23 	delay((u64)usec * get_cntfrq() / 1000000);
24 }
25 
mdelay(unsigned long msecs)26 void mdelay(unsigned long msecs)
27 {
28 	while (msecs--)
29 		udelay(1000);
30 }
31