lib: sbi: Add hart_ prefix to PMP functions

PMP functions that deal with hart PMP CSRs are given a sbi_hart_ prefix,
to distinguish from RISC-V PMP encoding functions.

The is_pmp_entry_mapped() function is changed a little more, to align
with other PMP conventions, and made to return a bool to make it more
obvious that it returns a bool and not an SBI_ return code.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20260430045528.420437-8-npiggin@gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Nicholas Piggin
2026-04-30 14:55:24 +10:00
committed by Anup Patel
parent f7738cc1e5
commit 63350c6ea6
4 changed files with 42 additions and 40 deletions
+8 -6
View File
@@ -81,6 +81,8 @@
#ifndef __ASSEMBLER__ #ifndef __ASSEMBLER__
#include <sbi/sbi_types.h>
#define csr_swap(csr, val) \ #define csr_swap(csr, val) \
({ \ ({ \
register unsigned long __v = (unsigned long)(val); \ register unsigned long __v = (unsigned long)(val); \
@@ -210,16 +212,16 @@ int misa_xlen(void);
void misa_string(int xlen, char *out, unsigned int out_sz); void misa_string(int xlen, char *out, unsigned int out_sz);
/* Disable pmp entry at a given index */ /* Disable pmp entry at a given index */
int pmp_disable(unsigned int n); int sbi_hart_pmp_disable(unsigned int n);
/* Check if the matching field is set */ /* Check if the matching field is set */
int is_pmp_entry_mapped(unsigned long entry); bool sbi_hart_is_pmp_enabled(unsigned int n);
int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, int sbi_hart_pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
unsigned long log2len); unsigned long log2len);
int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out, int sbi_hart_pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
unsigned long *log2len); unsigned long *log2len);
#endif /* !__ASSEMBLER__ */ #endif /* !__ASSEMBLER__ */
+7 -7
View File
@@ -332,7 +332,7 @@ static int hart_pmp_write(pmp_t *pmp, unsigned int n)
return SBI_OK; return SBI_OK;
} }
int pmp_disable(unsigned int n) int sbi_hart_pmp_disable(unsigned int n)
{ {
pmp_t pmp; pmp_t pmp;
int rc; int rc;
@@ -346,18 +346,18 @@ int pmp_disable(unsigned int n)
return hart_pmp_write(&pmp, n); return hart_pmp_write(&pmp, n);
} }
int is_pmp_entry_mapped(unsigned long entry) bool sbi_hart_is_pmp_enabled(unsigned int n)
{ {
pmp_t pmp; pmp_t pmp;
if (hart_pmp_read(&pmp, entry) != SBI_OK) if (hart_pmp_read(&pmp, n) != SBI_OK)
return false; return false;
return sbi_pmp_is_enabled(&pmp); return sbi_pmp_is_enabled(&pmp);
} }
int pmp_set(unsigned int n, unsigned long prot, unsigned long addr, int sbi_hart_pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
unsigned long log2len) unsigned long log2len)
{ {
pmp_t pmp; pmp_t pmp;
int rc; int rc;
@@ -369,8 +369,8 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
return hart_pmp_write(&pmp, n); return hart_pmp_write(&pmp, n);
} }
int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out, int sbi_hart_pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
unsigned long *log2len) unsigned long *log2len)
{ {
pmp_t pmp; pmp_t pmp;
int rc; int rc;
+9 -9
View File
@@ -100,7 +100,7 @@ static void sbi_hart_smepmp_set(struct sbi_scratch *scratch,
sbi_platform_pmp_set(sbi_platform_ptr(scratch), sbi_platform_pmp_set(sbi_platform_ptr(scratch),
pmp_idx, reg->flags, pmp_flags, pmp_idx, reg->flags, pmp_flags,
reg->base, reg->order); reg->base, reg->order);
pmp_set(pmp_idx, pmp_flags, reg->base, reg->order); sbi_hart_pmp_set(pmp_idx, pmp_flags, reg->base, reg->order);
} else { } else {
sbi_printf("Can not configure pmp for domain %s because" sbi_printf("Can not configure pmp for domain %s because"
" memory region address 0x%lx or size 0x%lx " " memory region address 0x%lx or size 0x%lx "
@@ -139,7 +139,7 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch)
csr_set(CSR_MSECCFG, MSECCFG_RLB); csr_set(CSR_MSECCFG, MSECCFG_RLB);
/* Disable the reserved entry */ /* Disable the reserved entry */
pmp_disable(SBI_SMEPMP_RESV_ENTRY); sbi_hart_pmp_disable(SBI_SMEPMP_RESV_ENTRY);
/* Program M-only regions when MML is not set. */ /* Program M-only regions when MML is not set. */
pmp_idx = 0; pmp_idx = 0;
@@ -206,7 +206,7 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch)
} }
/* Disable remaining PMP entries */ /* Disable remaining PMP entries */
for(; pmp_idx < pmp_count; pmp_idx++) for(; pmp_idx < pmp_count; pmp_idx++)
pmp_disable(pmp_idx); sbi_hart_pmp_disable(pmp_idx);
/* /*
* All entries are programmed. * All entries are programmed.
@@ -224,7 +224,7 @@ static int sbi_hart_smepmp_map_range(struct sbi_scratch *scratch,
unsigned int pmp_flags = (PMP_W | PMP_X); unsigned int pmp_flags = (PMP_W | PMP_X);
unsigned long order, base = 0; unsigned long order, base = 0;
if (is_pmp_entry_mapped(SBI_SMEPMP_RESV_ENTRY)) if (sbi_hart_is_pmp_enabled(SBI_SMEPMP_RESV_ENTRY))
return SBI_ENOSPC; return SBI_ENOSPC;
for (order = MAX(sbi_hart_pmp_log2gran(scratch), log2roundup(size)); for (order = MAX(sbi_hart_pmp_log2gran(scratch), log2roundup(size));
@@ -244,7 +244,7 @@ static int sbi_hart_smepmp_map_range(struct sbi_scratch *scratch,
sbi_platform_pmp_set(sbi_platform_ptr(scratch), SBI_SMEPMP_RESV_ENTRY, sbi_platform_pmp_set(sbi_platform_ptr(scratch), SBI_SMEPMP_RESV_ENTRY,
SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW, SBI_DOMAIN_MEMREGION_SHARED_SURW_MRW,
pmp_flags, base, order); pmp_flags, base, order);
pmp_set(SBI_SMEPMP_RESV_ENTRY, pmp_flags, base, order); sbi_hart_pmp_set(SBI_SMEPMP_RESV_ENTRY, pmp_flags, base, order);
return SBI_OK; return SBI_OK;
} }
@@ -253,7 +253,7 @@ static int sbi_hart_smepmp_unmap_range(struct sbi_scratch *scratch,
unsigned long addr, unsigned long size) unsigned long addr, unsigned long size)
{ {
sbi_platform_pmp_disable(sbi_platform_ptr(scratch), SBI_SMEPMP_RESV_ENTRY); sbi_platform_pmp_disable(sbi_platform_ptr(scratch), SBI_SMEPMP_RESV_ENTRY);
return pmp_disable(SBI_SMEPMP_RESV_ENTRY); return sbi_hart_pmp_disable(SBI_SMEPMP_RESV_ENTRY);
} }
static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch) static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch)
@@ -281,7 +281,7 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch)
sbi_platform_pmp_set(sbi_platform_ptr(scratch), sbi_platform_pmp_set(sbi_platform_ptr(scratch),
pmp_idx, reg->flags, pmp_flags, pmp_idx, reg->flags, pmp_flags,
reg->base, reg->order); reg->base, reg->order);
pmp_set(pmp_idx++, pmp_flags, reg->base, reg->order); sbi_hart_pmp_set(pmp_idx++, pmp_flags, reg->base, reg->order);
} else { } else {
sbi_printf("Can not configure pmp for domain %s because" sbi_printf("Can not configure pmp for domain %s because"
" memory region address 0x%lx or size 0x%lx " " memory region address 0x%lx or size 0x%lx "
@@ -291,7 +291,7 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch)
} }
/* Disable remaining PMP entries */ /* Disable remaining PMP entries */
for(; pmp_idx < pmp_count; pmp_idx++) for(; pmp_idx < pmp_count; pmp_idx++)
pmp_disable(pmp_idx); sbi_hart_pmp_disable(pmp_idx);
sbi_hart_pmp_fence(); sbi_hart_pmp_fence();
return 0; return 0;
@@ -307,7 +307,7 @@ static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch)
continue; continue;
sbi_platform_pmp_disable(sbi_platform_ptr(scratch), i); sbi_platform_pmp_disable(sbi_platform_ptr(scratch), i);
pmp_disable(i); sbi_hart_pmp_disable(i);
} }
} }
+18 -18
View File
@@ -254,21 +254,21 @@ static int eswin_eic7700_final_init(bool cold_boot)
__func__); __func__);
return SBI_EFAIL; return SBI_EFAIL;
} }
pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg), sbi_hart_pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
reg->base, reg->order); reg->base, reg->order);
} }
pmp_set(PMP_RESERVED_A, PMP_L, EIC770X_L3_ZERO_REMOTE, sbi_hart_pmp_set(PMP_RESERVED_A, PMP_L, EIC770X_L3_ZERO_REMOTE,
log2roundup(EIC770X_L3_ZERO_SIZE)); log2roundup(EIC770X_L3_ZERO_SIZE));
/** /**
* Enable P550 internal + System Port, so OpenSBI can access * Enable P550 internal + System Port, so OpenSBI can access
* CLINT/PLIC/UART. Might be overwritten in pmp_configure. * CLINT/PLIC/UART. Might be overwritten in pmp_configure.
*/ */
pmp_set(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1, 0, 0, sbi_hart_pmp_set(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1, 0, 0,
log2roundup(EIC770X_MEMPORT_BASE)); log2roundup(EIC770X_MEMPORT_BASE));
pmp_set(PMP_RESERVED_B, PMP_L, 0, sbi_hart_pmp_set(PMP_RESERVED_B, PMP_L, 0,
log2roundup(EIC770X_MEMPORT_LIMIT)); log2roundup(EIC770X_MEMPORT_LIMIT));
/** /**
* These must come after the setup of PMP, as we are about to * These must come after the setup of PMP, as we are about to
* enable speculation and HW prefetcher bits * enable speculation and HW prefetcher bits
@@ -321,13 +321,13 @@ static int eswin_eic7700_pmp_configure(struct sbi_scratch *scratch)
if (pmp_idx >= pmp_max) if (pmp_idx >= pmp_max)
goto no_more_pmp; goto no_more_pmp;
pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg), sbi_hart_pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
reg->base, reg->order); reg->base, reg->order);
prev = reg; prev = reg;
} }
/* Disable the rest */ /* Disable the rest */
while (pmp_idx < pmp_max) while (pmp_idx < pmp_max)
pmp_disable(pmp_idx++); sbi_hart_pmp_disable(pmp_idx++);
/* Process the second free range B [7-7] */ /* Process the second free range B [7-7] */
pmp_idx = PMP_FREE_B_START, pmp_idx = PMP_FREE_B_START,
@@ -340,12 +340,12 @@ static int eswin_eic7700_pmp_configure(struct sbi_scratch *scratch)
if (pmp_idx >= pmp_max) if (pmp_idx >= pmp_max)
goto no_more_pmp; goto no_more_pmp;
pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg), sbi_hart_pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
reg->base, reg->order); reg->base, reg->order);
} }
/* Disable the rest */ /* Disable the rest */
while (pmp_idx < pmp_max) while (pmp_idx < pmp_max)
pmp_disable(pmp_idx++); sbi_hart_pmp_disable(pmp_idx++);
sbi_hart_pmp_fence(); sbi_hart_pmp_fence();
return 0; return 0;
@@ -357,14 +357,14 @@ no_more_pmp:
static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch) static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch)
{ {
/* Enable P550 internal + System Port */ /* Enable P550 internal + System Port */
pmp_set(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1, 0, 0, sbi_hart_pmp_set(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1, 0, 0,
log2roundup(EIC770X_MEMPORT_BASE)); log2roundup(EIC770X_MEMPORT_BASE));
for (unsigned int i = 0; i < PMP_FREE_A_COUNT - 1; i++) for (unsigned int i = 0; i < PMP_FREE_A_COUNT - 1; i++)
pmp_disable(i + PMP_FREE_A_START); sbi_hart_pmp_disable(i + PMP_FREE_A_START);
for (unsigned int i = 0; i < PMP_FREE_B_COUNT; i++) for (unsigned int i = 0; i < PMP_FREE_B_COUNT; i++)
pmp_disable(i + PMP_FREE_B_START); sbi_hart_pmp_disable(i + PMP_FREE_B_START);
} }
static struct sbi_hart_protection eswin_eic7700_pmp_protection = { static struct sbi_hart_protection eswin_eic7700_pmp_protection = {