xref: /aosp_15_r20/external/coreboot/payloads/libpayload/include/delay.h (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 #ifndef LIBPAYLOAD_DELAY_H
4 #define LIBPAYLOAD_DELAY_H
5 
6 #include <stdint.h>
7 
8 #define NSECS_PER_SEC 1000000000
9 #define USECS_PER_SEC 1000000
10 #define MSECS_PER_SEC 1000
11 #define NSECS_PER_MSEC (NSECS_PER_SEC / MSECS_PER_SEC)
12 #define NSECS_PER_USEC (NSECS_PER_SEC / USECS_PER_SEC)
13 #define USECS_PER_MSEC (USECS_PER_SEC / MSECS_PER_SEC)
14 
15 unsigned int get_cpu_speed(void);
16 
17 void arch_ndelay(uint64_t n);
18 
19 /**
20  * Delay for a specified number of nanoseconds.
21  *
22  * @param ns Number of nanoseconds to delay for.
23  */
ndelay(unsigned int ns)24 static inline void ndelay(unsigned int ns)
25 {
26 	arch_ndelay((uint64_t)ns);
27 }
28 
29 /**
30  * Delay for a specified number of microseconds.
31  *
32  * @param us Number of microseconds to delay for.
33  */
udelay(unsigned int us)34 static inline void udelay(unsigned int us)
35 {
36 	arch_ndelay((uint64_t)us * NSECS_PER_USEC);
37 }
38 
39 /**
40  * Delay for a specified number of milliseconds.
41  *
42  * @param ms Number of milliseconds to delay for.
43  */
mdelay(unsigned int ms)44 static inline void mdelay(unsigned int ms)
45 {
46 	arch_ndelay((uint64_t)ms * NSECS_PER_MSEC);
47 }
48 
49 /**
50  * Delay for a specified number of seconds.
51  *
52  * @param s Number of seconds to delay for.
53  */
delay(unsigned int s)54 static inline void delay(unsigned int s)
55 {
56 	arch_ndelay((uint64_t)s * NSECS_PER_SEC);
57 }
58 
59 #endif /* LIBPAYLOAD_DELAY_H */
60