David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
3 | * Copyright (C) 2012 Regents of the University of California | ||||
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4 | */ |
5 | |||||
6 | #ifndef _ASM_RISCV_TIMEX_H | ||||
7 | #define _ASM_RISCV_TIMEX_H | ||||
8 | |||||
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 9 | #include <asm/csr.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 10 | |
11 | typedef unsigned long cycles_t; | ||||
12 | |||||
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 13 | static inline cycles_t get_cycles(void) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 14 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 15 | return csr_read(CSR_TIME); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 16 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 17 | #define get_cycles get_cycles |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 18 | |
19 | #ifdef CONFIG_64BIT | ||||
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 20 | static inline u64 get_cycles64(void) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 21 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 22 | return get_cycles(); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 23 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 24 | #else /* CONFIG_64BIT */ |
25 | static inline u32 get_cycles_hi(void) | ||||
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 26 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 27 | return csr_read(CSR_TIMEH); |
28 | } | ||||
29 | |||||
30 | static 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 | |||||
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 39 | return ((u64)hi << 32) | lo; |
40 | } | ||||
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 41 | #endif /* CONFIG_64BIT */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 42 | |
43 | #define ARCH_HAS_READ_CURRENT_TIMER | ||||
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 44 | static 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 */ |