From e6170c21b5ddba3e5f32cf8afe22cba6148bfee4 Mon Sep 17 00:00:00 2001 From: Han Gao Date: Fri, 20 Sep 2024 16:53:46 +0800 Subject: [PATCH] sync sdk v2.0.2 code Signed-off-by: Han Gao --- firmware/fw_base.S | 2 ++ lib/sbi/sbi_trap.c | 9 +++++++++ lib/utils/Kconfig | 2 ++ lib/utils/mbox/fdt_mbox_thead.c | 2 +- platform/generic/thead/thead-generic.c | 28 +++++++++++++++++--------- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index f7763f4d9..83cb4d9a4 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -738,6 +738,8 @@ memcmp: .globl _trap_handler .globl _trap_exit _trap_handler: + sfence.vma zero, t0 + TRAP_SAVE_AND_SETUP_SP_T0 TRAP_SAVE_MEPC_MSTATUS 0 diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index dbf307c68..795f83db1 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -201,6 +201,15 @@ int sbi_trap_redirect(struct sbi_trap_regs *regs, static int sbi_trap_nonaia_irq(struct sbi_trap_regs *regs, ulong mcause) { mcause &= ~(1UL << (__riscv_xlen - 1)); + + /* + * DCACHE.CALL: + * | 31 - 25 | 24 - 20 | 19 - 15 | 14 - 12 | 11 - 7 | 6 - 0 | + * 0000000 00001 00000 000 00000 0001011 + */ + if ((regs->mepc & 0x7f) == 4) + asm volatile(".long 0x0010000b\n"); + switch (mcause) { case IRQ_M_TIMER: sbi_timer_process(); diff --git a/lib/utils/Kconfig b/lib/utils/Kconfig index de8b4eb91..4d1f4f9a1 100644 --- a/lib/utils/Kconfig +++ b/lib/utils/Kconfig @@ -24,4 +24,6 @@ source "$(OPENSBI_SRC_DIR)/lib/utils/sys/Kconfig" source "$(OPENSBI_SRC_DIR)/lib/utils/timer/Kconfig" +source "$(OPENSBI_SRC_DIR)/lib/utils/mbox/Kconfig" + endmenu diff --git a/lib/utils/mbox/fdt_mbox_thead.c b/lib/utils/mbox/fdt_mbox_thead.c index e4bb5094d..7c6d5048f 100644 --- a/lib/utils/mbox/fdt_mbox_thead.c +++ b/lib/utils/mbox/fdt_mbox_thead.c @@ -201,7 +201,7 @@ static int thead_mbox_init(void *fdt, int nodeoff, { int rc = 0, bitmap = 0, len = 0; struct thead_mbox_adapter *adapter; - uint8_t data = 0x0; + uint32_t data = 0x0; adapter = sbi_zalloc(sizeof(*adapter)); if (!adapter) diff --git a/platform/generic/thead/thead-generic.c b/platform/generic/thead/thead-generic.c index 832c5d7a0..235aaeb0a 100644 --- a/platform/generic/thead/thead-generic.c +++ b/platform/generic/thead/thead-generic.c @@ -264,6 +264,9 @@ static void sbi_thead_reserved_pmp_set(void) unsigned int num, reg_val; for (num = 0; num < 4; num++) { + if (__sbi_hsm_hart_get_state(num) == SBI_HSM_STATE_STOPPED) + continue; + /* pmp entry 28 for reserved memory */ writel(RESERVED_START_ADDR >> 12, (void *)(PMP_ENTRY_START_ADDR(28) + num*PMP_SIZE_PER_CORE)); writel(RESERVED_END_ADDR >> 12, (void *)(PMP_ENTRY_END_ADDR(28) + num*PMP_SIZE_PER_CORE)); @@ -286,12 +289,18 @@ static void sbi_thead_tcm0_pmp_set(unsigned long auth) if (reg_val != TCM0_START_ADDR >> 12) for(num = 0; num < 4; num++) { + if (__sbi_hsm_hart_get_state(num) == SBI_HSM_STATE_STOPPED) + continue; + /* pmp entry 26 for dsp tcm0 */ writel(TCM0_START_ADDR >> 12, (void *)(PMP_ENTRY_START_ADDR(26) + num*PMP_SIZE_PER_CORE)); writel(TCM0_END_ADDR >> 12, (void *)(PMP_ENTRY_END_ADDR(26) + num*PMP_SIZE_PER_CORE)); } for(num = 0; num < 4; num++) { + if (__sbi_hsm_hart_get_state(num) == SBI_HSM_STATE_STOPPED) + continue; + /* pmp entry 26 config */ reg_val = readl((void *)(PMP_ENTRY_CFG_ADDR(26) + num*PMP_SIZE_PER_CORE)); reg_val = (reg_val & 0xff00ffff) | (auth << 16); @@ -309,12 +318,18 @@ static void sbi_thead_tcm1_pmp_set(unsigned long auth) reg_val = readl((void *)PMP_ENTRY_START_ADDR(27)); if (reg_val != TCM1_START_ADDR >> 12) for (num = 0; num < 4; num++) { + if (__sbi_hsm_hart_get_state(num) == SBI_HSM_STATE_STOPPED) + continue; + /* pmp entry 27 for dsp tcm1 */ writel(TCM1_START_ADDR >> 12, (void *)(PMP_ENTRY_START_ADDR(27) + num*PMP_SIZE_PER_CORE)); writel(TCM1_END_ADDR >> 12, (void *)(PMP_ENTRY_END_ADDR(27) + num*PMP_SIZE_PER_CORE)); } for (num = 0; num < 4; num++) { + if (__sbi_hsm_hart_get_state(num) == SBI_HSM_STATE_STOPPED) + continue; + /* pmp entry 27 config */ reg_val = readl((void *)(PMP_ENTRY_CFG_ADDR(27) + num*PMP_SIZE_PER_CORE)); reg_val = (reg_val & 0x00ffffff) | (auth << 24); @@ -406,18 +421,13 @@ static int thead_generic_final_init(bool cold_boot, return 0; } -/* static struct thead_generic_quirks thead_th1520_quirks = { - .errata = THEAD_QUIRK_ERRATA_TLB_FLUSH, -}; */ - -static struct thead_generic_quirks thead_light_quirks = { - .errata = THEAD_QUIRK_ERRATA_TLB_FLUSH | THEAD_QUIRK_ERRATA_LOGHT_PPU, +static struct thead_generic_quirks thead_th1520_quirks = { + .errata = THEAD_QUIRK_ERRATA_LOGHT_PPU, }; static const struct fdt_match thead_generic_match[] = { -/* { .compatible = "thead,th1520", .data = &thead_th1520_quirks }, */ - { .compatible = "thead,th1520", .data = &thead_light_quirks }, - { .compatible = "thead,light", .data = &thead_light_quirks }, + { .compatible = "thead,th1520", .data = &thead_th1520_quirks }, + { .compatible = "thead,light", .data = &thead_th1520_quirks }, { }, };