blob: c7ef131b9e4cbdd76f79687dac40dce4b922f93e [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2012 Regents of the University of California
4 */
5
6#ifndef _ASM_RISCV_TIMEX_H
7#define _ASM_RISCV_TIMEX_H
8
9#include <asm/csr.h>
10
11typedef unsigned long cycles_t;
12
13static inline cycles_t get_cycles(void)
14{
15 return csr_read(CSR_TIME);
16}
17#define get_cycles get_cycles
18
19#ifdef CONFIG_64BIT
20static inline u64 get_cycles64(void)
21{
22 return get_cycles();
23}
24#else /* CONFIG_64BIT */
25static inline u32 get_cycles_hi(void)
26{
27 return csr_read(CSR_TIMEH);
28}
29
30static inline u64 get_cycles64(void)
31{
32 u32 hi, lo;
33
34 do {
35 hi = get_cycles_hi();
36 lo = get_cycles();
37 } while (hi != get_cycles_hi());
38
39 return ((u64)hi << 32) | lo;
40}
41#endif /* CONFIG_64BIT */
42
43#define ARCH_HAS_READ_CURRENT_TIMER
44static inline int read_current_timer(unsigned long *timer_val)
45{
46 *timer_val = get_cycles();
47 return 0;
48}
49
50#endif /* _ASM_RISCV_TIMEX_H */