platform: generic: thead: separate implement of T-HEAD c9xx errata
authorInochi Amaoto <inochiama@outlook.com>
Sat, 7 Oct 2023 03:06:30 +0000 (11:06 +0800)
committerAnup Patel <anup@brainfault.org>
Tue, 14 Nov 2023 16:23:50 +0000 (21:53 +0530)
Separate the implement of T-HEAD c9xx errata to allow any platform
with bug related to c9xx cores can use it.

Signed-off-by: Inochi Amaoto <inochiama@outlook.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
platform/generic/Kconfig
platform/generic/include/thead/c9xx_errata.h [new file with mode: 0644]
platform/generic/thead/Kconfig
platform/generic/thead/objects.mk
platform/generic/thead/thead-generic.c
platform/generic/thead/thead-trap-handler.S [deleted file]
platform/generic/thead/thead_c9xx_errata_tlb_flush.c [new file with mode: 0644]
platform/generic/thead/thead_c9xx_tlb_trap_handler.S [new file with mode: 0644]

index ea3b5cf43ec4a57af3b01d351b4357a78722e824..3be75cf3d2304e071c614982a04e08f01a17fb76 100644 (file)
@@ -55,6 +55,7 @@ config PLATFORM_STARFIVE_JH7110
 
 config PLATFORM_THEAD
        bool "THEAD C9xx support"
+       select THEAD_C9XX_ERRATA
        default n
 
 source "$(OPENSBI_SRC_DIR)/platform/generic/andes/Kconfig"
diff --git a/platform/generic/include/thead/c9xx_errata.h b/platform/generic/include/thead/c9xx_errata.h
new file mode 100644 (file)
index 0000000..bf97938
--- /dev/null
@@ -0,0 +1,13 @@
+
+#ifndef __RISCV_THEAD_C9XX_ERRATA_H____
+#define __RISCV_THEAD_C9XX_ERRATA_H____
+
+/**
+ * T-HEAD board with this quirk need to execute sfence.vma to flush
+ * stale entrie avoid incorrect memory access.
+ */
+#define THEAD_QUIRK_ERRATA_TLB_FLUSH           BIT(0)
+
+void thead_register_tlb_flush_trap_handler(void);
+
+#endif // __RISCV_THEAD_C9XX_ERRATA_H____
index e54e621029d76cfaf1fe8cdb13944742148455a9..c50d38ee6e4e1a76a7b349bb6a1dbc88dda0b4ad 100644 (file)
@@ -3,3 +3,7 @@
 config THEAD_C9XX_PMU
        bool "T-HEAD c9xx M-mode PMU support"
        default n
+
+config THEAD_C9XX_ERRATA
+       bool "T-HEAD c9xx errata support"
+       default n
index df2c61ba866a31f6ecf4306ae5c26d80ac6d66d4..84f9fafbc7afed4340010fa686ab7acf4b36437b 100644 (file)
@@ -7,6 +7,8 @@
 
 platform-objs-$(CONFIG_THEAD_C9XX_PMU) += thead/thead_c9xx_pmu.o
 
+platform-objs-$(CONFIG_THEAD_C9XX_ERRATA) += thead/thead_c9xx_tlb_trap_handler.o
+platform-objs-$(CONFIG_THEAD_C9XX_ERRATA) += thead/thead_c9xx_errata_tlb_flush.o
+
 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
index 8120f6fcd15dd8a82560fe25c3c10a4357ef8174..c77140c33af20dc7c852e349c4f7adbe8f25ad54 100644 (file)
@@ -7,40 +7,34 @@
  */
 
 #include <platform_override.h>
-#include <sbi/riscv_barrier.h>
+#include <thead/c9xx_errata.h>
 #include <sbi/sbi_const.h>
 #include <sbi/sbi_platform.h>
 #include <sbi/sbi_scratch.h>
 #include <sbi/sbi_string.h>
 #include <sbi_utils/fdt/fdt_helper.h>
 
-/**
- * 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);
-}
+struct thead_generic_quirks {
+       u64     errata;
+};
 
 static int thead_generic_early_init(bool cold_boot,
                                    const struct fdt_match *match)
 {
-       unsigned long quirks = (unsigned long)match->data;
+       struct thead_generic_quirks *quirks = (void *)match->data;
 
-       if (quirks & THEAD_QUIRK_TLB_FLUSH_FIXUP)
+       if (quirks->errata & THEAD_QUIRK_ERRATA_TLB_FLUSH)
                thead_register_tlb_flush_trap_handler();
 
        return 0;
 }
 
+static struct thead_generic_quirks thead_th1520_quirks = {
+       .errata = THEAD_QUIRK_ERRATA_TLB_FLUSH,
+};
+
 static const struct fdt_match thead_generic_match[] = {
-       { .compatible = "thead,th1520",
-         .data = (void*)THEAD_QUIRK_TLB_FLUSH_FIXUP },
+       { .compatible = "thead,th1520", .data = &thead_th1520_quirks },
        { },
 };
 
diff --git a/platform/generic/thead/thead-trap-handler.S b/platform/generic/thead/thead-trap-handler.S
deleted file mode 100644 (file)
index 861c029..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Authors:
- *   Inochi Amaoto <inochiama@outlook.com>
- *
- */
-       .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
diff --git a/platform/generic/thead/thead_c9xx_errata_tlb_flush.c b/platform/generic/thead/thead_c9xx_errata_tlb_flush.c
new file mode 100644 (file)
index 0000000..755899a
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Authors:
+ *   Inochi Amaoto <inochiama@outlook.com>
+ *
+ */
+
+#include <sbi/riscv_encoding.h>
+#include <sbi/riscv_asm.h>
+
+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);
+}
diff --git a/platform/generic/thead/thead_c9xx_tlb_trap_handler.S b/platform/generic/thead/thead_c9xx_tlb_trap_handler.S
new file mode 100644 (file)
index 0000000..861c029
--- /dev/null
@@ -0,0 +1,13 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Authors:
+ *   Inochi Amaoto <inochiama@outlook.com>
+ *
+ */
+       .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