[RFC PATCH 17/23] platform: generic: eswin: verify PMP configure/unconfigure
Yu-Chien Peter Lin
peter.lin at sifive.com
Mon Nov 30 02:11:41 PST 2026
Use verified PMP set and disable operations in the Eswin domain
protection callbacks to detect hardware programming failures.
Return the first error from eswin_eic7700_pmp_configure(). The void
eswin_eic7700_pmp_unconfigure() callback logs failures and continues
with the remaining updates; it does not return errors to its caller.
Signed-off-by: Yu-Chien Peter Lin <peter.lin at sifive.com>
---
platform/generic/eswin/eic770x.c | 53 +++++++++++++++++++++++---------
1 file changed, 39 insertions(+), 14 deletions(-)
diff --git a/platform/generic/eswin/eic770x.c b/platform/generic/eswin/eic770x.c
index e69ead38..11bbbcae 100644
--- a/platform/generic/eswin/eic770x.c
+++ b/platform/generic/eswin/eic770x.c
@@ -397,6 +397,7 @@ static int eswin_eic7700_pmp_configure(struct sbi_scratch *scratch,
struct sbi_domain_memregion *reg, *prev = NULL;
unsigned int pmp_idx, pmp_max;
unsigned int i, j;
+ int rc;
/* Process the first free range A [3-5] */
pmp_idx = PMP_FREE_A_START,
@@ -431,13 +432,19 @@ static int eswin_eic7700_pmp_configure(struct sbi_scratch *scratch,
if (pmp_idx >= pmp_max)
goto no_more_pmp;
- sbi_hart_pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
- reg->base, reg->order);
+ rc = sbi_hart_pmp_set_verified(pmp_idx++,
+ sbi_domain_get_oldpmp_flags(reg),
+ reg->base, reg->order);
+ if (rc)
+ return rc;
prev = reg;
}
/* Disable the rest */
- while (pmp_idx < pmp_max)
- sbi_hart_pmp_disable(pmp_idx++);
+ while (pmp_idx < pmp_max) {
+ rc = sbi_hart_pmp_disable_verified(pmp_idx++);
+ if (rc)
+ return rc;
+ }
/* Process the second free range B [7-7] */
pmp_idx = PMP_FREE_B_START,
@@ -450,12 +457,18 @@ static int eswin_eic7700_pmp_configure(struct sbi_scratch *scratch,
if (pmp_idx >= pmp_max)
goto no_more_pmp;
- sbi_hart_pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
- reg->base, reg->order);
+ rc = sbi_hart_pmp_set_verified(pmp_idx++,
+ sbi_domain_get_oldpmp_flags(reg),
+ reg->base, reg->order);
+ if (rc)
+ return rc;
}
/* Disable the rest */
- while (pmp_idx < pmp_max)
- sbi_hart_pmp_disable(pmp_idx++);
+ while (pmp_idx < pmp_max) {
+ rc = sbi_hart_pmp_disable_verified(pmp_idx++);
+ if (rc)
+ return rc;
+ }
sbi_hart_pmp_fence();
return 0;
@@ -467,15 +480,27 @@ no_more_pmp:
static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch,
struct sbi_domain *dom)
{
+ int rc;
+
/* Enable P550 internal + System Port */
- sbi_hart_pmp_set(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1, 0, 0,
- log2roundup(EIC770X_MEMPORT_BASE));
+ rc = sbi_hart_pmp_set_verified(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1,
+ 0, 0, log2roundup(EIC770X_MEMPORT_BASE));
+ if (rc)
+ sbi_printf("%s: failed to set PMP entry: %d\n", __func__, rc);
- for (unsigned int i = 0; i < PMP_FREE_A_COUNT - 1; i++)
- sbi_hart_pmp_disable(i + PMP_FREE_A_START);
+ for (unsigned int i = 0; i < PMP_FREE_A_COUNT - 1; i++) {
+ rc = sbi_hart_pmp_disable_verified(i + PMP_FREE_A_START);
+ if (rc)
+ sbi_printf("%s: failed to disable PMP entry: %d\n",
+ __func__, rc);
+ }
- for (unsigned int i = 0; i < PMP_FREE_B_COUNT; i++)
- sbi_hart_pmp_disable(i + PMP_FREE_B_START);
+ for (unsigned int i = 0; i < PMP_FREE_B_COUNT; i++) {
+ rc = sbi_hart_pmp_disable_verified(i + PMP_FREE_B_START);
+ if (rc)
+ sbi_printf("%s: failed to disable PMP entry: %d\n",
+ __func__, rc);
+ }
}
static struct sbi_hart_protection eswin_eic7700_pmp_protection = {
--
2.43.7
More information about the opensbi
mailing list