From 1dccc374ab8f9129d1db2a9b8c228e49bf9ee4c7 Mon Sep 17 00:00:00 2001 From: Petro Karashchenko Date: Thu, 20 Jan 2022 15:41:27 +0200 Subject: [PATCH] risc-v/mpfs: switch to NuttX types for opensbi Signed-off-by: Petro Karashchenko --- arch/risc-v/src/Makefile | 5 +- arch/risc-v/src/mpfs/mpfs_opensbi.c | 23 ++----- arch/risc-v/src/opensbi/Kconfig | 2 +- arch/risc-v/src/opensbi/Make.defs | 2 + arch/risc-v/src/opensbi/nuttx_sbi_types.h | 80 +++++++++++++++++++++++ 5 files changed, 90 insertions(+), 22 deletions(-) create mode 100644 arch/risc-v/src/opensbi/nuttx_sbi_types.h diff --git a/arch/risc-v/src/Makefile b/arch/risc-v/src/Makefile index a6add5f590..e7008106f4 100644 --- a/arch/risc-v/src/Makefile +++ b/arch/risc-v/src/Makefile @@ -38,9 +38,10 @@ INCLUDES += ${shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)chip} INCLUDES += ${shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)common} INCLUDES += ${shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)$(ARCH_SUBDIR)} INCLUDES += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)sched} -#ifeq ($(CONFIG_OPENSBI),y) +ifeq ($(CONFIG_OPENSBI),y) +INCLUDES += $(shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)opensbi) INCLUDES += $(shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)opensbi$(DELIM)opensbi-3rdparty$(DELIM)include) -#endif +endif CPPFLAGS += $(INCLUDES) CFLAGS += $(INCLUDES) diff --git a/arch/risc-v/src/mpfs/mpfs_opensbi.c b/arch/risc-v/src/mpfs/mpfs_opensbi.c index f45ff51261..442e820a36 100644 --- a/arch/risc-v/src/mpfs/mpfs_opensbi.c +++ b/arch/risc-v/src/mpfs/mpfs_opensbi.c @@ -23,24 +23,19 @@ ****************************************************************************/ #include + #include #include #include -#include + +#include "riscv_internal.h" +#include "riscv_arch.h" #include #include #include #include -/* OpenSBI will also define NULL. Undefine NULL in order to avoid warning: - * 'warning: "NULL" redefined' - */ - -#ifdef NULL - #undef NULL -#endif - #include #include #include @@ -117,16 +112,6 @@ static int mpfs_irqchip_init(bool cold_boot); static int mpfs_ipi_init(bool cold_boot); static int mpfs_timer_init(bool cold_boot); -/**************************************************************************** - * Extern Function Declarations - ****************************************************************************/ - -/* riscv_internal.h cannot be included due to a number of redefinition - * conflicts. Thus, define the riscv_lowputc() with the extern definition. - */ - -extern void riscv_lowputc(char ch); - /**************************************************************************** * Private Data ****************************************************************************/ diff --git a/arch/risc-v/src/opensbi/Kconfig b/arch/risc-v/src/opensbi/Kconfig index f24337e0b2..1c538be6b6 100644 --- a/arch/risc-v/src/opensbi/Kconfig +++ b/arch/risc-v/src/opensbi/Kconfig @@ -9,4 +9,4 @@ config OPENSBI default n ---help--- Enable or disable Open Source Supervisor Binary Interface (OpenSBI) features - for RISC-V. + for RISC-V. diff --git a/arch/risc-v/src/opensbi/Make.defs b/arch/risc-v/src/opensbi/Make.defs index 0e1d83fd0f..e9ca5d0a4a 100644 --- a/arch/risc-v/src/opensbi/Make.defs +++ b/arch/risc-v/src/opensbi/Make.defs @@ -37,6 +37,8 @@ OPENSBI_URL = https://github.com/riscv-software-src/opensbi/tarball OPENSBI_TARBALL = opensbi.tar.gz OPENSBI_DIR = riscv-software-src-opensbi-48f91ee +CFLAGS += -DOPENSBI_EXTERNAL_SBI_TYPES=nuttx_sbi_types.h + $(OPENSBI_TARBALL): $(Q) echo "Downloading: OpenSBI" $(Q) curl -L $(OPENSBI_URL)/$(OPENSBI_COMMIT) -o opensbi/$(OPENSBI_TARBALL) diff --git a/arch/risc-v/src/opensbi/nuttx_sbi_types.h b/arch/risc-v/src/opensbi/nuttx_sbi_types.h new file mode 100644 index 0000000000..e9636ed51e --- /dev/null +++ b/arch/risc-v/src/opensbi/nuttx_sbi_types.h @@ -0,0 +1,80 @@ +/**************************************************************************** + * arch/risc-v/src/opensbi/nuttx_sbi_types.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_RISCV_SRC_OPENSBI_NUTTX_SBI_TYPES_H +#define __ARCH_RISCV_SRC_OPENSBI_NUTTX_SBI_TYPES_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +#include +#include + +#include "riscv_internal.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define PRILX PRIxREG + +#define __packed end_packed_struct +#define __noreturn noreturn_function +#define __aligned(x) aligned_data(x) + +#define likely(x) __builtin_expect((x), 1) +#define unlikely(x) __builtin_expect((x), 0) + +#define array_size(x) (sizeof(x) / sizeof((x)[0])) + +#define MAX(a, b) ((a) > (b) ? (a) : (b)) +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi) + +#define ROUNDUP(a, b) ((((a) - 1) / (b) + 1) * (b)) +#define ROUNDDOWN(a, b) ((a) / (b) * (b)) + +/**************************************************************************** + * Type Definitions + ****************************************************************************/ + +typedef int8_t s8; +typedef uint8_t u8; + +typedef int16_t s16; +typedef uint16_t u16; + +typedef int32_t s32; +typedef uint32_t u32; + +typedef int64_t s64; +typedef uint64_t u64; + +typedef uintptr_t virtual_addr_t; +typedef uintptr_t virtual_size_t; +typedef uintptr_t physical_addr_t; +typedef uintptr_t physical_size_t; + +#endif /* __ARCH_RISCV_SRC_OPENSBI_NUTTX_SBI_TYPES_H */