timex.h (c95baf12f5077419db01313ab61c2aac007d40cd) | timex.h (2bc3fc877aa9c4c8b80cc49f66dfcb7e4857a128) |
---|---|
1/* 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> | 1/* 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#include <asm/mmio.h> | |
11 12typedef unsigned long cycles_t; 13 | 10 11typedef unsigned long cycles_t; 12 |
14extern u64 __iomem *riscv_time_val; 15extern u64 __iomem *riscv_time_cmp; 16 17#ifdef CONFIG_64BIT 18#define mmio_get_cycles() readq_relaxed(riscv_time_val) 19#else 20#define mmio_get_cycles() readl_relaxed(riscv_time_val) 21#define mmio_get_cycles_hi() readl_relaxed(((u32 *)riscv_time_val) + 1) 22#endif 23 | |
24static inline cycles_t get_cycles(void) 25{ | 13static inline cycles_t get_cycles(void) 14{ |
26 if (IS_ENABLED(CONFIG_RISCV_SBI)) 27 return csr_read(CSR_TIME); 28 return mmio_get_cycles(); | 15 return csr_read(CSR_TIME); |
29} 30#define get_cycles get_cycles 31 | 16} 17#define get_cycles get_cycles 18 |
19static inline u32 get_cycles_hi(void) 20{ 21 return csr_read(CSR_TIMEH); 22} 23#define get_cycles_hi get_cycles_hi 24 |
|
32#ifdef CONFIG_64BIT 33static inline u64 get_cycles64(void) 34{ 35 return get_cycles(); 36} 37#else /* CONFIG_64BIT */ | 25#ifdef CONFIG_64BIT 26static inline u64 get_cycles64(void) 27{ 28 return get_cycles(); 29} 30#else /* CONFIG_64BIT */ |
38static inline u32 get_cycles_hi(void) 39{ 40 if (IS_ENABLED(CONFIG_RISCV_SBI)) 41 return csr_read(CSR_TIMEH); 42 return mmio_get_cycles_hi(); 43} 44 | |
45static inline u64 get_cycles64(void) 46{ 47 u32 hi, lo; 48 49 do { 50 hi = get_cycles_hi(); 51 lo = get_cycles(); 52 } while (hi != get_cycles_hi()); --- 13 unchanged lines hidden --- | 31static inline u64 get_cycles64(void) 32{ 33 u32 hi, lo; 34 35 do { 36 hi = get_cycles_hi(); 37 lo = get_cycles(); 38 } while (hi != get_cycles_hi()); --- 13 unchanged lines hidden --- |