mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-09-08 18:21:29 +01:00
lib: sbi: Allow platforms to override local TLB operations
Some T-Head based processors, for example the Sophgo SG2044, have a JTLB errata that requires special handling of certain TLB maintenance instructions (sfence.vma). Introduce a sbi_tlb_local_operations structure so platforms can provide custom local TLB flush implementations. Use it to implement the JTLB workaround on affected SoCs (currently Sophgo SG2044). Signed-off-by: Xiang W <wangxiang@iscas.ac.cn> Signed-off-by: Han Gao <gaohan@iscas.ac.cn> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260617112925.1144190-2-wangxiang@iscas.ac.cn Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
#define THEAD_QUIRK_ERRATA_TLB_FLUSH BIT(0)
|
||||
#define THEAD_QUIRK_ERRATA_THEAD_PMU BIT(1)
|
||||
#define THEAD_QUIRK_ERRATA_JTLB BIT(2)
|
||||
|
||||
void thead_register_tlb_flush_trap_handler(void);
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@
|
||||
#include <thead/c9xx_pmu.h>
|
||||
#include <sbi/sbi_const.h>
|
||||
#include <sbi/sbi_platform.h>
|
||||
#include <sbi/sbi_pmu.h>
|
||||
#include <sbi/sbi_scratch.h>
|
||||
#include <sbi/sbi_string.h>
|
||||
#include <sbi/sbi_tlb.h>
|
||||
#include <sbi_utils/fdt/fdt_helper.h>
|
||||
|
||||
struct thead_generic_quirks {
|
||||
@@ -39,15 +41,38 @@ static int thead_pmu_extensions_init(bool cold_boot)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void thead_jtlb_local_sfence_vma(struct sbi_tlb_info *tinfo)
|
||||
{
|
||||
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_RCVD);
|
||||
__asm__ __volatile__("sfence.vma");
|
||||
}
|
||||
|
||||
static void thead_jtlb_local_sfence_vma_asid(struct sbi_tlb_info *tinfo)
|
||||
{
|
||||
sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_ASID_RCVD);
|
||||
/* Flush entire MM context for a given ASID */
|
||||
__asm__ __volatile__("sfence.vma x0, %0"
|
||||
:
|
||||
: "r"(tinfo->asid)
|
||||
: "memory");
|
||||
}
|
||||
|
||||
static int thead_generic_platform_init(const void *fdt, int nodeoff,
|
||||
const struct fdt_match *match)
|
||||
{
|
||||
const struct thead_generic_quirks *quirks = match->data;
|
||||
static struct sbi_tlb_local_operations tlb_local_ops;
|
||||
|
||||
if (quirks->errata & THEAD_QUIRK_ERRATA_TLB_FLUSH)
|
||||
generic_platform_ops.early_init = thead_tlb_flush_early_init;
|
||||
if (quirks->errata & THEAD_QUIRK_ERRATA_THEAD_PMU)
|
||||
generic_platform_ops.extensions_init = thead_pmu_extensions_init;
|
||||
if (quirks->errata &THEAD_QUIRK_ERRATA_JTLB) {
|
||||
sbi_memcpy(&tlb_local_ops, sbi_tlb_get_local_operations(), sizeof(tlb_local_ops));
|
||||
tlb_local_ops.local_sfence_vma = thead_jtlb_local_sfence_vma;
|
||||
tlb_local_ops.local_sfence_vma_asid = thead_jtlb_local_sfence_vma_asid;
|
||||
sbi_tlb_set_local_operations(&tlb_local_ops);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -60,13 +85,17 @@ static const struct thead_generic_quirks thead_pmu_quirks = {
|
||||
.errata = THEAD_QUIRK_ERRATA_THEAD_PMU,
|
||||
};
|
||||
|
||||
static const struct thead_generic_quirks thead_pmu_jtlb_quirks = {
|
||||
.errata = THEAD_QUIRK_ERRATA_THEAD_PMU | THEAD_QUIRK_ERRATA_JTLB,
|
||||
};
|
||||
|
||||
static const struct fdt_match thead_generic_match[] = {
|
||||
{ .compatible = "canaan,kendryte-k230", .data = &thead_pmu_quirks },
|
||||
{ .compatible = "sophgo,cv1800b", .data = &thead_pmu_quirks },
|
||||
{ .compatible = "sophgo,cv1812h", .data = &thead_pmu_quirks },
|
||||
{ .compatible = "sophgo,sg2000", .data = &thead_pmu_quirks },
|
||||
{ .compatible = "sophgo,sg2002", .data = &thead_pmu_quirks },
|
||||
{ .compatible = "sophgo,sg2044", .data = &thead_pmu_quirks },
|
||||
{ .compatible = "sophgo,sg2044", .data = &thead_pmu_jtlb_quirks },
|
||||
{ .compatible = "thead,th1520", .data = &thead_th1520_quirks },
|
||||
{ },
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user