Linux 5.6.13
[linux/fpc-iii.git] / arch / riscv / include / asm / timex.h
blobbad2a7c2cda52ee352daa2d954389429bdf3ec28
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2012 Regents of the University of California
4 */
6 #ifndef _ASM_RISCV_TIMEX_H
7 #define _ASM_RISCV_TIMEX_H
9 #include <asm/csr.h>
10 #include <asm/mmio.h>
12 typedef unsigned long cycles_t;
14 extern u64 __iomem *riscv_time_val;
15 extern u64 __iomem *riscv_time_cmp;
17 #ifdef CONFIG_64BIT
18 #define mmio_get_cycles() readq_relaxed(riscv_time_val)
19 #else
20 #define mmio_get_cycles() readl_relaxed(riscv_time_val)
21 #define mmio_get_cycles_hi() readl_relaxed(((u32 *)riscv_time_val) + 1)
22 #endif
24 static inline cycles_t get_cycles(void)
26 if (IS_ENABLED(CONFIG_RISCV_SBI))
27 return csr_read(CSR_TIME);
28 return mmio_get_cycles();
30 #define get_cycles get_cycles
32 #ifdef CONFIG_64BIT
33 static inline u64 get_cycles64(void)
35 return get_cycles();
37 #else /* CONFIG_64BIT */
38 static inline u32 get_cycles_hi(void)
40 if (IS_ENABLED(CONFIG_RISCV_SBI))
41 return csr_read(CSR_TIMEH);
42 return mmio_get_cycles_hi();
45 static inline u64 get_cycles64(void)
47 u32 hi, lo;
49 do {
50 hi = get_cycles_hi();
51 lo = get_cycles();
52 } while (hi != get_cycles_hi());
54 return ((u64)hi << 32) | lo;
56 #endif /* CONFIG_64BIT */
58 #define ARCH_HAS_READ_CURRENT_TIMER
59 static inline int read_current_timer(unsigned long *timer_val)
61 *timer_val = get_cycles();
62 return 0;
65 #endif /* _ASM_RISCV_TIMEX_H */