diff --git a/platform/generic/Kconfig b/platform/generic/Kconfig index 72768ede..e7bd94eb 100644 --- a/platform/generic/Kconfig +++ b/platform/generic/Kconfig @@ -52,6 +52,10 @@ config PLATFORM_STARFIVE_JH7110 bool "StarFive JH7110 support" default n +config PLATFORM_THEAD + bool "THEAD C9xx support" + default n + source "$(OPENSBI_SRC_DIR)/platform/generic/andes/Kconfig" endif diff --git a/platform/generic/configs/defconfig b/platform/generic/configs/defconfig index 634d4108..c432bc2f 100644 --- a/platform/generic/configs/defconfig +++ b/platform/generic/configs/defconfig @@ -4,6 +4,7 @@ CONFIG_PLATFORM_RENESAS_RZFIVE=y CONFIG_PLATFORM_SIFIVE_FU540=y CONFIG_PLATFORM_SIFIVE_FU740=y CONFIG_PLATFORM_STARFIVE_JH7110=y +CONFIG_PLATFORM_THEAD=y CONFIG_FDT_GPIO=y CONFIG_FDT_GPIO_DESIGNWARE=y CONFIG_FDT_GPIO_SIFIVE=y diff --git a/platform/generic/thead/objects.mk b/platform/generic/thead/objects.mk new file mode 100644 index 00000000..854bfbde --- /dev/null +++ b/platform/generic/thead/objects.mk @@ -0,0 +1,10 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (C) 2023 Inochi Amaoto +# Copyright (C) 2023 Alibaba Group Holding Limited. +# + +carray-platform_override_modules-$(CONFIG_PLATFORM_THEAD) += thead_generic +platform-objs-$(CONFIG_PLATFORM_THEAD) += thead/thead-generic.o +platform-objs-$(CONFIG_PLATFORM_THEAD) += thead/thead-trap-handler.o diff --git a/platform/generic/thead/thead-generic.c b/platform/generic/thead/thead-generic.c new file mode 100644 index 00000000..8120f6fc --- /dev/null +++ b/platform/generic/thead/thead-generic.c @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Authors: + * Inochi Amaoto + * + */ + +#include +#include +#include +#include +#include +#include +#include + +/** + * T-HEAD board with this quirk need to execute sfence.vma to flush + * stale entrie avoid incorrect memory access. + */ +#define THEAD_QUIRK_TLB_FLUSH_FIXUP BIT(0) + +void _thead_tlb_flush_fixup_trap_handler(void); + +void thead_register_tlb_flush_trap_handler(void) +{ + csr_write(CSR_MTVEC, &_thead_tlb_flush_fixup_trap_handler); +} + +static int thead_generic_early_init(bool cold_boot, + const struct fdt_match *match) +{ + unsigned long quirks = (unsigned long)match->data; + + if (quirks & THEAD_QUIRK_TLB_FLUSH_FIXUP) + thead_register_tlb_flush_trap_handler(); + + return 0; +} + +static const struct fdt_match thead_generic_match[] = { + { .compatible = "thead,th1520", + .data = (void*)THEAD_QUIRK_TLB_FLUSH_FIXUP }, + { }, +}; + +const struct platform_override thead_generic = { + .match_table = thead_generic_match, + .early_init = thead_generic_early_init, +}; diff --git a/platform/generic/thead/thead-trap-handler.S b/platform/generic/thead/thead-trap-handler.S new file mode 100644 index 00000000..861c0292 --- /dev/null +++ b/platform/generic/thead/thead-trap-handler.S @@ -0,0 +1,13 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Authors: + * Inochi Amaoto + * + */ + .section .entry, "ax", %progbits + .align 3 + .globl _thead_tlb_flush_fixup_trap_handler +_thead_tlb_flush_fixup_trap_handler: + sfence.vma t0, zero + j _trap_handler