2019-05-29 21:18:00 +07:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2017-07-11 08:05:09 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Regents of the University of California
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ASM_RISCV_TIMEX_H
|
|
|
|
#define _ASM_RISCV_TIMEX_H
|
|
|
|
|
2019-08-21 21:58:36 +07:00
|
|
|
#include <asm/csr.h>
|
2019-10-28 19:10:37 +07:00
|
|
|
#include <asm/mmio.h>
|
2017-07-11 08:05:09 +07:00
|
|
|
|
|
|
|
typedef unsigned long cycles_t;
|
|
|
|
|
2019-10-28 19:10:37 +07:00
|
|
|
extern u64 __iomem *riscv_time_val;
|
|
|
|
extern u64 __iomem *riscv_time_cmp;
|
|
|
|
|
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
#define mmio_get_cycles() readq_relaxed(riscv_time_val)
|
|
|
|
#else
|
|
|
|
#define mmio_get_cycles() readl_relaxed(riscv_time_val)
|
|
|
|
#define mmio_get_cycles_hi() readl_relaxed(((u32 *)riscv_time_val) + 1)
|
|
|
|
#endif
|
|
|
|
|
2019-08-21 21:58:36 +07:00
|
|
|
static inline cycles_t get_cycles(void)
|
2017-07-11 08:05:09 +07:00
|
|
|
{
|
2019-10-28 19:10:37 +07:00
|
|
|
if (IS_ENABLED(CONFIG_RISCV_SBI))
|
|
|
|
return csr_read(CSR_TIME);
|
|
|
|
return mmio_get_cycles();
|
2017-07-11 08:05:09 +07:00
|
|
|
}
|
2019-08-21 21:58:36 +07:00
|
|
|
#define get_cycles get_cycles
|
2017-07-11 08:05:09 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_64BIT
|
2019-08-21 21:58:36 +07:00
|
|
|
static inline u64 get_cycles64(void)
|
|
|
|
{
|
|
|
|
return get_cycles();
|
|
|
|
}
|
|
|
|
#else /* CONFIG_64BIT */
|
|
|
|
static inline u32 get_cycles_hi(void)
|
2017-07-11 08:05:09 +07:00
|
|
|
{
|
2019-10-28 19:10:37 +07:00
|
|
|
if (IS_ENABLED(CONFIG_RISCV_SBI))
|
|
|
|
return csr_read(CSR_TIMEH);
|
|
|
|
return mmio_get_cycles_hi();
|
2017-07-11 08:05:09 +07:00
|
|
|
}
|
2019-08-21 21:58:36 +07:00
|
|
|
|
|
|
|
static inline u64 get_cycles64(void)
|
2017-07-11 08:05:09 +07:00
|
|
|
{
|
2019-08-21 21:58:36 +07:00
|
|
|
u32 hi, lo;
|
|
|
|
|
|
|
|
do {
|
|
|
|
hi = get_cycles_hi();
|
|
|
|
lo = get_cycles();
|
|
|
|
} while (hi != get_cycles_hi());
|
|
|
|
|
2017-07-11 08:05:09 +07:00
|
|
|
return ((u64)hi << 32) | lo;
|
|
|
|
}
|
2019-08-21 21:58:36 +07:00
|
|
|
#endif /* CONFIG_64BIT */
|
2017-07-11 08:05:09 +07:00
|
|
|
|
|
|
|
#define ARCH_HAS_READ_CURRENT_TIMER
|
|
|
|
static inline int read_current_timer(unsigned long *timer_val)
|
|
|
|
{
|
|
|
|
*timer_val = get_cycles();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _ASM_RISCV_TIMEX_H */
|