xref: /kvm-unit-tests/lib/riscv/asm/timer.h (revision f372d35fb1bea99e401cc6eafc798aecfce29a07)
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 
11 static inline uint64_t timer_get_cycles(void)
12 {
13 	return csr_read(CSR_TIME);
14 }
15 
16 static inline void timer_irq_enable(void)
17 {
18 	csr_set(CSR_SIE, IE_TIE);
19 }
20 
21 static inline void timer_irq_disable(void)
22 {
23 	csr_clear(CSR_SIE, IE_TIE);
24 }
25 
26 #endif /* _ASMRISCV_TIMER_H_ */
27