diff --git a/Makefile b/Makefile index e29a487be..3c2363b86 100644 --- a/Makefile +++ b/Makefile @@ -143,6 +143,8 @@ gens+=$(config_def_generator) $(config_defs) inc_dirs+=$(config_build_dir) platform_def_generator_src:=$(scripts_dir)/platform_defs_gen.c +platform_arch_def_generator_src:=$(wildcard $(scripts_dir)/arch/$(ARCH)/platform_defs_gen.c) +platform_def_generator_src+=$(platform_arch_def_generator_src) platform_def_generator:=$(scripts_build_dir)/platform_defs_gen platform_defs:=$(platform_build_dir)/platform_defs_gen.h platform_description:=$(platform_dir)/$(platform_description) diff --git a/scripts/arch/riscv/platform_defs_gen.c b/scripts/arch/riscv/platform_defs_gen.c new file mode 100644 index 000000000..3ed3daf6e --- /dev/null +++ b/scripts/arch/riscv/platform_defs_gen.c @@ -0,0 +1,15 @@ +/** + * SPDX-License-Identifier: Apache-2.0 + * Copyright (c) Bao Project and Contributors. All rights reserved + */ + +#include +#include + +void arch_platform_defs() { + + if (platform.arch.aclint_sswi.base != 0) { + printf("#define ACLINT_SSWI 1\n"); + } + +} \ No newline at end of file diff --git a/scripts/platform_defs_gen.c b/scripts/platform_defs_gen.c index 7db709cd5..ad132a85b 100644 --- a/scripts/platform_defs_gen.c +++ b/scripts/platform_defs_gen.c @@ -6,7 +6,9 @@ #include #include -extern void arch_platform_defs(); +__attribute__((weak)) void arch_platform_defs(void){ + return; +} int main() { @@ -15,6 +17,7 @@ int main() { if (platform.cpu_master_fixed) { printf("#define CPU_MASTER_FIXED (%ld)\n", platform.cpu_master); } - + // Call arch specific platform defines generator + arch_platform_defs(); return 0; } diff --git a/src/arch/riscv/arch.mk b/src/arch/riscv/arch.mk index 428c7f2bd..456babc30 100644 --- a/src/arch/riscv/arch.mk +++ b/src/arch/riscv/arch.mk @@ -18,9 +18,6 @@ irqc_arch_dir=$(cpu_arch_dir)/irqc/$(IRQC_DIR) src_dirs+=$(irqc_arch_dir) arch-cppflags+=-DIRQC=$(IRQC) -ifeq ($(ACLINT_PRESENT), 1) -arch-cppflags+=-DACLINT_PRESENT -endif arch-cflags = -mcmodel=medany -march=rv64g -mstrict-align arch-asflags = arch-ldflags = diff --git a/src/arch/riscv/inc/arch/interrupts.h b/src/arch/riscv/inc/arch/interrupts.h index aba7d60ed..38d98105a 100644 --- a/src/arch/riscv/inc/arch/interrupts.h +++ b/src/arch/riscv/inc/arch/interrupts.h @@ -12,6 +12,8 @@ #define PLIC (1) #define APLIC (2) +#define ACLINT_PRESENT() DEFINED(ACLINT_SSWI) + /** * In riscv, the ipi (software interrupt) and timer interrupts dont actually have an ID as their * are treated differently from external interrupts routed by the external interrupt controller, diff --git a/src/arch/riscv/interrupts.c b/src/arch/riscv/interrupts.c index 1753bbd7b..0b1a84db9 100644 --- a/src/arch/riscv/interrupts.c +++ b/src/arch/riscv/interrupts.c @@ -20,7 +20,7 @@ void interrupts_arch_init() { if (cpu()->id == CPU_MASTER) { irqc_init(); - if(DEFINED(ACLINT_PRESENT)){ + if(ACLINT_PRESENT()){ aclint_init(); } } @@ -38,7 +38,7 @@ void interrupts_arch_init() void interrupts_arch_ipi_send(cpuid_t target_cpu, irqid_t ipi_id) { - if (DEFINED(ACLINT_PRESENT)) { + if (ACLINT_PRESENT()) { aclint_send_ipi(target_cpu); } else { sbi_send_ipi(1ULL << target_cpu, 0); diff --git a/src/platform/qemu-riscv64-virt/inc/plat/platform.h b/src/platform/qemu-riscv64-virt/inc/plat/platform.h index e62fe25b3..e142f87ba 100644 --- a/src/platform/qemu-riscv64-virt/inc/plat/platform.h +++ b/src/platform/qemu-riscv64-virt/inc/plat/platform.h @@ -10,4 +10,7 @@ #define CPU_EXT_SSTC 1 +#define IPIC_SBI (1) +#define IPIC_ACLINT (2) + #endif diff --git a/src/platform/qemu-riscv64-virt/platform.mk b/src/platform/qemu-riscv64-virt/platform.mk index f5625c6f6..638b96da5 100644 --- a/src/platform/qemu-riscv64-virt/platform.mk +++ b/src/platform/qemu-riscv64-virt/platform.mk @@ -7,12 +7,14 @@ ARCH:=riscv CPU:= # Interrupt controller definition IRQC:=PLIC +# Core IPIs controller +IPIC:=IPIC_ACLINT drivers := sbi_uart platform_description:=virt_desc.c -platform-cppflags = +platform-cppflags =-DIPIC=$(IPIC) platform-cflags = platform-asflags = platform-ldflags = diff --git a/src/platform/qemu-riscv64-virt/virt_desc.c b/src/platform/qemu-riscv64-virt/virt_desc.c index 48a2a0611..73e225055 100644 --- a/src/platform/qemu-riscv64-virt/virt_desc.c +++ b/src/platform/qemu-riscv64-virt/virt_desc.c @@ -26,8 +26,13 @@ struct platform platform = { #else #error "unknown IRQC type " IRQC #endif - // Disable ACLINT by default - .aclint_sswi.base = 0 +#if (IPIC == IPIC_SBI) + .aclint_sswi.base = 0, +#elif (IPIC == IPIC_ACLINT) + .aclint_sswi.base = 0x2f00000, +#else +#error "unknown IPIC type " IPIC +#endif }, };