From 4a72abb5f490c01a5a4dd24930ccae9c42d15c74 Mon Sep 17 00:00:00 2001 From: Ben Zong-You Xie Date: Tue, 23 Jul 2024 15:57:26 +0800 Subject: [PATCH] platform: generic: andes: add Andes SBI call to probe Andes PMA feature Add a new Andes SBI call to check whether PPMA is supported by hardware or not. Signed-off-by: Ben Zong-You Xie Reviewed-by: Anup Patel --- platform/generic/andes/ae350.c | 2 ++ platform/generic/andes/andes_pma.c | 8 ++++++-- platform/generic/andes/andes_sbi.c | 5 +++++ platform/generic/include/andes/andes_pma.h | 12 ++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/platform/generic/andes/ae350.c b/platform/generic/andes/ae350.c index 63c10bc4..a1ab6b93 100644 --- a/platform/generic/andes/ae350.c +++ b/platform/generic/andes/ae350.c @@ -19,6 +19,7 @@ #include #include #include +#include static struct smu_data smu = { 0 }; extern void __ae350_enable_coherency_warmboot(void); @@ -120,4 +121,5 @@ const struct platform_override andes_ae350 = { .final_init = ae350_final_init, .extensions_init = andes_pmu_extensions_init, .pmu_init = andes_pmu_init, + .vendor_ext_provider = andes_sbi_vendor_ext_provider, }; diff --git a/platform/generic/andes/andes_pma.c b/platform/generic/andes/andes_pma.c index 9c37720b..a884bf75 100644 --- a/platform/generic/andes/andes_pma.c +++ b/platform/generic/andes/andes_pma.c @@ -241,7 +241,6 @@ static int andes_fdt_reserved_memory_fixup(void *fdt, int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, unsigned int pma_regions_count) { - unsigned long mmsc = csr_read(CSR_MMSC_CFG); unsigned int dt_populate_cnt; unsigned int i, j; unsigned long pa; @@ -254,7 +253,7 @@ int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, if (pma_regions_count > ANDES_MAX_PMA_REGIONS) return SBI_EINVAL; - if ((mmsc & MMSC_CFG_PPMA_MASK) == 0) + if (!andes_sbi_probe_pma()) return SBI_ENOTSUPP; /* Configure the PMA regions */ @@ -290,3 +289,8 @@ int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, return 0; } + +bool andes_sbi_probe_pma(void) +{ + return (csr_read(CSR_MMSC_CFG) & MMSC_CFG_PPMA_MASK) ? true : false; +} diff --git a/platform/generic/andes/andes_sbi.c b/platform/generic/andes/andes_sbi.c index 43bafdc7..a7ca4a59 100644 --- a/platform/generic/andes/andes_sbi.c +++ b/platform/generic/andes/andes_sbi.c @@ -5,12 +5,14 @@ */ #include #include +#include #include #include enum sbi_ext_andes_fid { SBI_EXT_ANDES_FID0 = 0, /* Reserved for future use */ SBI_EXT_ANDES_IOCP_SW_WORKAROUND, + SBI_EXT_ANDES_PMA_PROBE, }; static bool andes_cache_controllable(void) @@ -41,6 +43,9 @@ int andes_sbi_vendor_ext_provider(long funcid, case SBI_EXT_ANDES_IOCP_SW_WORKAROUND: out->value = andes_apply_iocp_sw_workaround(); break; + case SBI_EXT_ANDES_PMA_PROBE: + out->value = andes_sbi_probe_pma(); + break; default: return SBI_EINVAL; diff --git a/platform/generic/include/andes/andes_pma.h b/platform/generic/include/andes/andes_pma.h index 5ea12475..147dca1e 100644 --- a/platform/generic/include/andes/andes_pma.h +++ b/platform/generic/include/andes/andes_pma.h @@ -47,4 +47,16 @@ struct andes_pma_region { int andes_pma_setup_regions(const struct andes_pma_region *pma_regions, unsigned int pma_regions_count); +/** + * Programmable PMA(PPMA) is a feature for Andes. PPMA allows dynamic adjustment + * of memory attributes in the runtime. It contains a configurable amount of PMA + * entries implemented as CSRs to control the attributes of memory locations. + * + * Check if hardware supports PPMA + * + * @return true if PPMA is supported + * @return false if PPMA is not supported + */ +bool andes_sbi_probe_pma(void); + #endif /* _ANDES_PMA_H_ */