forked from Mirrors/opensbi

The TLB entries remain functional all the time once added in T-HEAD th1520 and Sophgo sg2042 (even if the MMU is then disabled afterwards). If there are some stale TLB entries that contains the address of SBI, it will cause unexpected memory access and issue a illegal instruction error. To avoid this, a TLB flush is needed to drop these TLB entries before any memory access in the trap handler. To handle this workaroud, add a custom trap handler with executing TLB flush first in the T-HEAD platform to fix affected socs. Signed-off-by: Inochi Amaoto <inochiama@outlook.com> Reviewed-by: Anup Patel <anup@brainfault.org>
51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
/*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*
|
|
* Authors:
|
|
* Inochi Amaoto <inochiama@outlook.com>
|
|
*
|
|
*/
|
|
|
|
#include <platform_override.h>
|
|
#include <sbi/riscv_barrier.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);
|
|
}
|
|
|
|
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,
|
|
};
|