From: Nicholas Piggin <npiggin@gmail.com>
To: opensbi@lists.infradead.org
Cc: Nicholas Piggin <npiggin@gmail.com>
Subject: [PATCH 3/4] lib: sbi: Add hart_ prefix to PMP functions
Date: Tue, 10 Mar 2026 10:49:56 +1000 [thread overview]
Message-ID: <20260310005000.3837512-3-npiggin@gmail.com> (raw)
In-Reply-To: <20260310005000.3837512-1-npiggin@gmail.com>
Give PMP functions that deal with HART CSRs a hart_ prefix, to help
distinguish from general PMP encoding functions that will be shared by
the Tenstorrent IOMMU.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
include/sbi/riscv_asm.h | 8 +++----
lib/sbi/riscv_asm.c | 10 ++++-----
lib/sbi/sbi_hart_pmp.c | 14 ++++++-------
platform/generic/eswin/eic770x.c | 36 ++++++++++++++++----------------
4 files changed, 34 insertions(+), 34 deletions(-)
diff --git a/include/sbi/riscv_asm.h b/include/sbi/riscv_asm.h
index b97e1880..14bc35e5 100644
--- a/include/sbi/riscv_asm.h
+++ b/include/sbi/riscv_asm.h
@@ -210,15 +210,15 @@ int misa_xlen(void);
void misa_string(int xlen, char *out, unsigned int out_sz);
/* Disable pmp entry at a given index */
-int pmp_disable(unsigned int n);
+int hart_pmp_disable(unsigned int n);
/* Check if the matching field is set */
-int is_pmp_entry_mapped(unsigned int entry);
+int hart_is_pmp_enabled(unsigned int n);
-int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
+int hart_pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
unsigned long log2len);
-int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
+int hart_pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
unsigned long *log2len);
#endif /* !__ASSEMBLER__ */
diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c
index c11abb1a..03c8e4d7 100644
--- a/lib/sbi/riscv_asm.c
+++ b/lib/sbi/riscv_asm.c
@@ -329,23 +329,23 @@ int hart_pmp_write(unsigned int n, pmp_t *pmp)
return SBI_OK;
}
-int pmp_disable(unsigned int n)
+int hart_pmp_disable(unsigned int n)
{
struct pmp pmp = { .cfg = 0, .addr = 0 };
return hart_pmp_write(n, &pmp);
}
-int is_pmp_entry_mapped(unsigned int entry)
+int hart_is_pmp_enabled(unsigned int n)
{
pmp_t pmp;
- if (hart_pmp_read(entry, &pmp))
+ if (hart_pmp_read(n, &pmp))
return pmp_enabled(&pmp);
return false;
}
-int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
+int hart_pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
unsigned long log2len)
{
pmp_t pmp;
@@ -358,7 +358,7 @@ int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
return hart_pmp_write(n, &pmp);
}
-int pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
+int hart_pmp_get(unsigned int n, unsigned long *prot_out, unsigned long *addr_out,
unsigned long *log2len)
{
pmp_t pmp;
diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
index 02a3b3c4..0aa4752f 100644
--- a/lib/sbi/sbi_hart_pmp.c
+++ b/lib/sbi/sbi_hart_pmp.c
@@ -100,7 +100,7 @@ static void sbi_hart_smepmp_set(struct sbi_scratch *scratch,
sbi_platform_pmp_set(sbi_platform_ptr(scratch),
pmp_idx, reg->flags, pmp_flags,
reg->base, reg->order);
- pmp_set(pmp_idx, pmp_flags, reg->base, reg->order);
+ hart_pmp_set(pmp_idx, pmp_flags, reg->base, reg->order);
} else {
sbi_printf("Can not configure pmp for domain %s because"
" 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);
/* Disable the reserved entry */
- pmp_disable(SBI_SMEPMP_RESV_ENTRY);
+ hart_pmp_disable(SBI_SMEPMP_RESV_ENTRY);
/* Program M-only regions when MML is not set. */
pmp_idx = 0;
@@ -224,7 +224,7 @@ static int sbi_hart_smepmp_map_range(struct sbi_scratch *scratch,
unsigned int pmp_flags = (PMP_W | PMP_X);
unsigned long order, base = 0;
- if (is_pmp_entry_mapped(SBI_SMEPMP_RESV_ENTRY))
+ if (hart_is_pmp_enabled(SBI_SMEPMP_RESV_ENTRY))
return SBI_ENOSPC;
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_DOMAIN_MEMREGION_SHARED_SURW_MRW,
pmp_flags, base, order);
- pmp_set(SBI_SMEPMP_RESV_ENTRY, pmp_flags, base, order);
+ hart_pmp_set(SBI_SMEPMP_RESV_ENTRY, pmp_flags, base, order);
return SBI_OK;
}
@@ -253,7 +253,7 @@ static int sbi_hart_smepmp_unmap_range(struct sbi_scratch *scratch,
unsigned long addr, unsigned long size)
{
sbi_platform_pmp_disable(sbi_platform_ptr(scratch), SBI_SMEPMP_RESV_ENTRY);
- return pmp_disable(SBI_SMEPMP_RESV_ENTRY);
+ return hart_pmp_disable(SBI_SMEPMP_RESV_ENTRY);
}
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),
pmp_idx, reg->flags, pmp_flags,
reg->base, reg->order);
- pmp_set(pmp_idx++, pmp_flags, reg->base, reg->order);
+ hart_pmp_set(pmp_idx++, pmp_flags, reg->base, reg->order);
} else {
sbi_printf("Can not configure pmp for domain %s because"
" memory region address 0x%lx or size 0x%lx "
@@ -307,7 +307,7 @@ static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch)
continue;
sbi_platform_pmp_disable(sbi_platform_ptr(scratch), i);
- pmp_disable(i);
+ hart_pmp_disable(i);
}
}
diff --git a/platform/generic/eswin/eic770x.c b/platform/generic/eswin/eic770x.c
index 7330df9f..dfca0c41 100644
--- a/platform/generic/eswin/eic770x.c
+++ b/platform/generic/eswin/eic770x.c
@@ -254,21 +254,21 @@ static int eswin_eic7700_final_init(bool cold_boot)
__func__);
return SBI_EFAIL;
}
- pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
- reg->base, reg->order);
+ hart_pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
+ reg->base, reg->order);
}
- pmp_set(PMP_RESERVED_A, PMP_L, EIC770X_L3_ZERO_REMOTE,
- log2roundup(EIC770X_L3_ZERO_SIZE));
+ hart_pmp_set(PMP_RESERVED_A, PMP_L, EIC770X_L3_ZERO_REMOTE,
+ log2roundup(EIC770X_L3_ZERO_SIZE));
/**
* Enable P550 internal + System Port, so OpenSBI can access
* CLINT/PLIC/UART. Might be overwritten in pmp_configure.
*/
- pmp_set(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1, 0, 0,
- log2roundup(EIC770X_MEMPORT_BASE));
+ hart_pmp_set(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1, 0, 0,
+ log2roundup(EIC770X_MEMPORT_BASE));
- pmp_set(PMP_RESERVED_B, PMP_L, 0,
- log2roundup(EIC770X_MEMPORT_LIMIT));
+ hart_pmp_set(PMP_RESERVED_B, PMP_L, 0,
+ log2roundup(EIC770X_MEMPORT_LIMIT));
/**
* These must come after the setup of PMP, as we are about to
* 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)
goto no_more_pmp;
- pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
- reg->base, reg->order);
+ hart_pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
+ reg->base, reg->order);
prev = reg;
}
/* Disable the rest */
while (pmp_idx < pmp_max)
- pmp_disable(pmp_idx++);
+ hart_pmp_disable(pmp_idx++);
/* Process the second free range B [7-7] */
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)
goto no_more_pmp;
- pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
- reg->base, reg->order);
+ hart_pmp_set(pmp_idx++, sbi_domain_get_oldpmp_flags(reg),
+ reg->base, reg->order);
}
/* Disable the rest */
while (pmp_idx < pmp_max)
- pmp_disable(pmp_idx++);
+ hart_pmp_disable(pmp_idx++);
sbi_hart_pmp_fence();
return 0;
@@ -357,14 +357,14 @@ no_more_pmp:
static void eswin_eic7700_pmp_unconfigure(struct sbi_scratch *scratch)
{
/* Enable P550 internal + System Port */
- pmp_set(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1, 0, 0,
- log2roundup(EIC770X_MEMPORT_BASE));
+ hart_pmp_set(PMP_FREE_A_START + PMP_FREE_A_COUNT - 1, 0, 0,
+ log2roundup(EIC770X_MEMPORT_BASE));
for (unsigned int i = 0; i < PMP_FREE_A_COUNT - 1; i++)
- pmp_disable(i + PMP_FREE_A_START);
+ hart_pmp_disable(i + PMP_FREE_A_START);
for (unsigned int i = 0; i < PMP_FREE_B_COUNT; i++)
- pmp_disable(i + PMP_FREE_B_START);
+ hart_pmp_disable(i + PMP_FREE_B_START);
}
static struct sbi_hart_protection eswin_eic7700_pmp_protection = {
--
2.51.0
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2026-03-10 0:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 0:49 [PATCH 1/4] platform: generic: Tenstorrent Atlantis support Nicholas Piggin
2026-03-10 0:49 ` [PATCH 2/4] lib: sbi: Move PMP encoding into a new file Nicholas Piggin
2026-04-01 12:50 ` Joel Stanley
2026-03-10 0:49 ` Nicholas Piggin [this message]
2026-04-01 12:50 ` [PATCH 3/4] lib: sbi: Add hart_ prefix to PMP functions Joel Stanley
2026-03-10 0:49 ` [PATCH 4/4] platform: generic: tenstorrent: Add RISC-V IOMMU support Nicholas Piggin
2026-04-01 12:51 ` Joel Stanley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260310005000.3837512-3-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=opensbi@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox