1 | // SPDX-License-Identifier: GPL-3.0-or-later |
---|---|
2 | |
3 | #pragma once |
4 | |
5 | #include <mos/mos_global.h> |
6 | #include <mos/types.h> |
7 | |
8 | should_inline u64 rdtsc(void) |
9 | { |
10 | u64 a, d; |
11 | __asm__ volatile("rdtsc": "=a"(a), "=d"(d) : : "memory"); |
12 | return (d << 32) | a; |
13 | } |
14 | |
15 | should_inline void mdelay(u64 ms) |
16 | { |
17 | u64 end = rdtsc() + ms * 2000 * 1000; |
18 | while (rdtsc() < end) |
19 | ; |
20 | } |
21 | |
22 | should_inline void udelay(u64 us) |
23 | { |
24 | u64 end = rdtsc() + us * 2000; |
25 | while (rdtsc() < end) |
26 | ; |
27 | } |
28 |