xref: /kvm-unit-tests/lib/riscv/asm/timer.h (revision 17f6f2fd17935eb5e564f621c71244b4a3ddeafb)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef _ASMRISCV_TIMER_H_
3 #define _ASMRISCV_TIMER_H_
4 
5 #include <asm/csr.h>
6 
7 extern void timer_get_frequency(void);
8 extern void timer_start(unsigned long duration_us);
9 extern void timer_stop(void);
10 
timer_get_cycles(void)11 static inline uint64_t timer_get_cycles(void)
12 {
13 	return csr_read(CSR_TIME);
14 }
15 
timer_irq_enable(void)16 static inline void timer_irq_enable(void)
17 {
18 	csr_set(CSR_SIE, IE_TIE);
19 }
20 
timer_irq_disable(void)21 static inline void timer_irq_disable(void)
22 {
23 	csr_clear(CSR_SIE, IE_TIE);
24 }
25 
26 #endif /* _ASMRISCV_TIMER_H_ */
27