diff --git a/arch/risc-v/src/common/riscv_internal.h b/arch/risc-v/src/common/riscv_internal.h index 627d834d86..a56be9416d 100644 --- a/arch/risc-v/src/common/riscv_internal.h +++ b/arch/risc-v/src/common/riscv_internal.h @@ -250,6 +250,13 @@ int riscv_check_pmp_access(uintptr_t attr, uintptr_t base, uintptr_t size); int riscv_configured_pmp_regions(void); int riscv_next_free_pmp_region(void); +/* RISC-V SBI wrappers ******************************************************/ + +#ifdef CONFIG_ARCH_USE_S_MODE +void riscv_sbi_set_timer(uint64_t stime_value); +uint64_t riscv_sbi_get_time(void); +#endif + /* Power management *********************************************************/ #ifdef CONFIG_PM diff --git a/arch/risc-v/src/common/supervisor/Make.defs b/arch/risc-v/src/common/supervisor/Make.defs index e3125b0cef..62625c2368 100644 --- a/arch/risc-v/src/common/supervisor/Make.defs +++ b/arch/risc-v/src/common/supervisor/Make.defs @@ -22,7 +22,7 @@ CMN_ASRCS += riscv_dispatch_syscall.S CMN_CSRCS += riscv_perform_syscall.c -CMN_CSRCS += riscv_percpu.c +CMN_CSRCS += riscv_percpu.c riscv_sbi.c INCLUDES += ${shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)common$(DELIM)supervisor} VPATH += common$(DELIM)supervisor diff --git a/arch/risc-v/src/common/supervisor/riscv_sbi.c b/arch/risc-v/src/common/supervisor/riscv_sbi.c new file mode 100644 index 0000000000..9694f69f64 --- /dev/null +++ b/arch/risc-v/src/common/supervisor/riscv_sbi.c @@ -0,0 +1,89 @@ +/**************************************************************************** + * arch/risc-v/src/common/supervisor/riscv_sbi.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include + +#include "riscv_internal.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_ARCH_RV64 +static inline uint64_t rdtime(void) +{ + uint32_t hi; + uint32_t lo; + + do + { + hi = READ_CSR(timeh); + lo = READ_CSR(time); + } + while (hi != READ_CSR(timeh)); + + return (((uint64_t) hi) << 32) | lo; +} +#else +#define rdtime() READ_CSR(time) +#endif /* CONFIG_ARCH_RV64 */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: riscv_sbi_set_timer + * + * Description: + * Set new compare match value for timer + * + * Input Parameters: + * stime_value - Value to set + * + ****************************************************************************/ + +void riscv_sbi_set_timer(uint64_t stime_value) +{ +#error "Missing functionality..." +} + +/**************************************************************************** + * Name: riscv_sbi_get_time + * + * Description: + * Get value of mtime + * + * Return: + * Value of mtime + * + ****************************************************************************/ + +uint64_t riscv_sbi_get_time(void) +{ + return rdtime(); +}