From d82549e1e9fd40e3fd104986180a25a5001313f6 Mon Sep 17 00:00:00 2001 From: sinceforYy <1017657683@qq.com> Date: Tue, 18 Feb 2025 10:43:46 +0800 Subject: [PATCH] feat(dts): add some empty devices node * Like PLIC, add some empty devices for UT testing. * Imsic_m, device address 0x3a800000, is an interrupt controller, address range size 0x10000. The device occupies the address space from 0x3a800000 to 0x3a80ffff. * Imsic_s, device address 0x3b000000, is an interrupt controller, address range size 0x80000. The device occupies the address space from 0x3b000000 to 0x3b07ffff. * Aplic_m, device address 0x31100000, is an advanced platform interrupt controller, address range size 0x8000. The device occupies the address space from 0x31100000 to 0x31107fff. * Aplic_s, device address 0x31120000, is an advanced platform interrupt controller, address range size 0x8000. The device occupies the address space from 0x31120000 to 0x31127fff. --- Makefile | 4 ++++ configs/riscv64-xs_defconfig | 11 ++++++++- src/device/Kconfig | 44 ++++++++++++++++++++++++++++++++++++ src/device/aplic_m.c | 15 ++++++++++++ src/device/aplic_s.c | 15 ++++++++++++ src/device/device.c | 8 +++++++ src/device/imsic_m.c | 15 ++++++++++++ src/device/imsic_s.c | 15 ++++++++++++ 8 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/device/aplic_m.c create mode 100644 src/device/aplic_s.c create mode 100644 src/device/imsic_m.c create mode 100644 src/device/imsic_s.c diff --git a/Makefile b/Makefile index 84e99b593..778ead102 100644 --- a/Makefile +++ b/Makefile @@ -65,6 +65,10 @@ SRCS-$(CONFIG_HAS_AUDIO) += src/device/audio.c SRCS-$(CONFIG_HAS_DISK) += src/device/disk.c SRCS-$(CONFIG_HAS_SDCARD) += src/device/sdcard.c SRCS-$(CONFIG_HAS_FLASH) += src/device/flash.c +SRCS-$(CONFIG_HAS_IMSIC_M) += src/device/imsic_m.c +SRCS-$(CONFIG_HAS_IMSIC_S) += src/device/imsic_s.c +SRCS-$(CONFIG_HAS_APLIC_M) += src/device/aplic_m.c +SRCS-$(CONFIG_HAS_APLIC_S) += src/device/aplic_s.c DIRS-y += src/profiling diff --git a/configs/riscv64-xs_defconfig b/configs/riscv64-xs_defconfig index 3eb6419d8..aabcd7dab 100644 --- a/configs/riscv64-xs_defconfig +++ b/configs/riscv64-xs_defconfig @@ -37,7 +37,8 @@ CONFIG_TDATA1_MCONTROL6=y # CONFIG_TDATA1_ETRIGGER is not set CONFIG_TRIGGER_NUM=4 # CONFIG_SDTRIG_EXTRA is not set -# CONFIG_RV_AIA is not set +CONFIG_RV_AIA=y +CONFIG_RV_IMSIC=y CONFIG_RV_SSTC=y CONFIG_RV_SMRNMI=y CONFIG_RV_SMDBLTRP=y @@ -155,6 +156,14 @@ CONFIG_UARTLITE_ASSERT_FOUR=y # CONFIG_HAS_UART_SNPS is not set CONFIG_HAS_PLIC=y CONFIG_PLIC_ADDRESS=0x3c000000 +CONFIG_HAS_IMSIC_M=y +CONFIG_IMSIC_M_ADDRESS=0x3a800000 +CONFIG_HAS_IMSIC_S=y +CONFIG_IMSIC_S_ADDRESS=0x3b000000 +CONFIG_HAS_APLIC_M=y +CONFIG_APLIC_M_ADDRESS=0x31100000 +CONFIG_HAS_APLIC_S=y +CONFIG_APLIC_S_ADDRESS=0x31120000 # CONFIG_HAS_TIMER is not set CONFIG_RTC_PORT=0x48 CONFIG_RTC_MMIO=0xa1000048 diff --git a/src/device/Kconfig b/src/device/Kconfig index cab0cc105..f31c20554 100644 --- a/src/device/Kconfig +++ b/src/device/Kconfig @@ -84,6 +84,50 @@ config PLIC_ADDRESS default 0x3c000000 endif +menuconfig HAS_IMSIC_M + depends on !SHARE + bool "Enable IMSIC_M" + default n + +if HAS_IMSIC_M +config IMSIC_M_ADDRESS + hex "base address of IMSIC_M" + default 0x3a800000 +endif + +menuconfig HAS_IMSIC_S + depends on !SHARE + bool "Enable IMSIC_S" + default n + +if HAS_IMSIC_S +config IMSIC_S_ADDRESS + hex "base address of IMSIC_S" + default 0x3b000000 +endif + +menuconfig HAS_APLIC_M + depends on !SHARE + bool "Enable APLIC_M" + default n + +if HAS_APLIC_M +config APLIC_M_ADDRESS + hex "base address of APLIC_M" + default 0x31100000 +endif + +menuconfig HAS_APLIC_S + depends on !SHARE + bool "Enable APLIC_S" + default n + +if HAS_APLIC_S +config APLIC_S_ADDRESS + hex "base address of APLIC_S" + default 0x31120000 +endif + menuconfig HAS_TIMER depends on !SHARE bool "Enable timer" diff --git a/src/device/aplic_m.c b/src/device/aplic_m.c new file mode 100644 index 000000000..2ecabff02 --- /dev/null +++ b/src/device/aplic_m.c @@ -0,0 +1,15 @@ +#include +#include + +uint8_t *aplic_m_base = NULL; +#define APLIC_M_SIZE (0x8000) + +static void aplic_m_io_handler(uint32_t offset, int len, bool is_write) { + // Fake aplic_m handler, empty now + return; +} + +void init_aplic_m(const char *flash_img) { + aplic_m_base = new_space(APLIC_M_SIZE); + add_mmio_map("aplic_m", CONFIG_APLIC_M_ADDRESS, aplic_m_base, APLIC_M_SIZE, aplic_m_io_handler); +} diff --git a/src/device/aplic_s.c b/src/device/aplic_s.c new file mode 100644 index 000000000..abdaca912 --- /dev/null +++ b/src/device/aplic_s.c @@ -0,0 +1,15 @@ +#include +#include + +uint8_t *aplic_s_base = NULL; +#define APLIC_S_SIZE (0x8000) + +static void aplic_s_io_handler(uint32_t offset, int len, bool is_write) { + // Fake aplic_s handler, empty now + return; +} + +void init_aplic_s(const char *flash_img) { + aplic_s_base = new_space(APLIC_S_SIZE); + add_mmio_map("aplic_s", CONFIG_APLIC_S_ADDRESS, aplic_s_base, APLIC_S_SIZE, aplic_s_io_handler); +} diff --git a/src/device/device.c b/src/device/device.c index 2b194edfe..d33c3bfcf 100644 --- a/src/device/device.c +++ b/src/device/device.c @@ -36,6 +36,10 @@ void init_disk(); void init_sdcard(); void init_flash(); void load_flash_contents(const char *); +void init_imsic_m(); +void init_imsic_s(); +void init_aplic_m(); +void init_aplic_s(); void send_key(uint8_t, bool); void vga_update_screen(); @@ -99,6 +103,10 @@ void init_device() { IFDEF(CONFIG_HAS_DISK, init_disk()); IFDEF(CONFIG_HAS_SDCARD, init_sdcard()); IFDEF(CONFIG_HAS_FLASH, init_flash()); + IFDEF(CONFIG_HAS_IMSIC_M, init_imsic_m()); + IFDEF(CONFIG_HAS_IMSIC_S, init_imsic_s()); + IFDEF(CONFIG_HAS_APLIC_M, init_aplic_m()); + IFDEF(CONFIG_HAS_APLIC_S, init_aplic_s()); // host alarm for device and timer update. add_alarm_handle(set_device_update_flag); diff --git a/src/device/imsic_m.c b/src/device/imsic_m.c new file mode 100644 index 000000000..ad9210998 --- /dev/null +++ b/src/device/imsic_m.c @@ -0,0 +1,15 @@ +#include +#include + +uint8_t *imsic_m_base = NULL; +#define IMSIC_M_SIZE (0x10000) + +static void imsic_m_io_handler(uint32_t offset, int len, bool is_write) { + // Fake imsic_m handler, empty now + return; +} + +void init_imsic_m(const char *flash_img) { + imsic_m_base = new_space(IMSIC_M_SIZE); + add_mmio_map("imsic_m", CONFIG_IMSIC_M_ADDRESS, imsic_m_base, IMSIC_M_SIZE, imsic_m_io_handler); +} diff --git a/src/device/imsic_s.c b/src/device/imsic_s.c new file mode 100644 index 000000000..0efbaf550 --- /dev/null +++ b/src/device/imsic_s.c @@ -0,0 +1,15 @@ +#include +#include + +uint8_t *imsic_s_base = NULL; +#define IMSIC_S_SIZE (0x80000) + +static void imsic_s_io_handler(uint32_t offset, int len, bool is_write) { + // Fake imsic_s handler, empty now + return; +} + +void init_imsic_s(const char *flash_img) { + imsic_s_base = new_space(IMSIC_S_SIZE); + add_mmio_map("imsic_s", CONFIG_IMSIC_S_ADDRESS, imsic_s_base, IMSIC_S_SIZE, imsic_s_io_handler); +}