1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 Regents of the University of California
6 #ifndef _ASM_RISCV_TIMEX_H
7 #define _ASM_RISCV_TIMEX_H
12 typedef unsigned long cycles_t
;
14 extern u64 __iomem
*riscv_time_val
;
15 extern u64 __iomem
*riscv_time_cmp
;
18 #define mmio_get_cycles() readq_relaxed(riscv_time_val)
20 #define mmio_get_cycles() readl_relaxed(riscv_time_val)
21 #define mmio_get_cycles_hi() readl_relaxed(((u32 *)riscv_time_val) + 1)
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
33 static inline u64
get_cycles64(void)
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)
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();
65 #endif /* _ASM_RISCV_TIMEX_H */