mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-12-17 04:21:39 +00:00
lib: sbi: Introduce sbi_hart_pmp_unconfigure() function
Currently, the unconfiguring PMP is implemented directly inside switch_to_next_domain_context() whereas rest of the PMP programming is done via functions implemented in sbi_hart.c. Introduce a separate sbi_hart_pmp_unconfigure() function so that all PMP programming is in one place. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Link: https://lore.kernel.org/r/20251209135235.423391-2-apatel@ventanamicro.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
@@ -150,6 +150,7 @@ unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch);
|
|||||||
unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch);
|
unsigned int sbi_hart_mhpm_bits(struct sbi_scratch *scratch);
|
||||||
bool sbi_hart_smepmp_is_fw_region(unsigned int pmp_idx);
|
bool sbi_hart_smepmp_is_fw_region(unsigned int pmp_idx);
|
||||||
int sbi_hart_pmp_configure(struct sbi_scratch *scratch);
|
int sbi_hart_pmp_configure(struct sbi_scratch *scratch);
|
||||||
|
void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch);
|
||||||
int sbi_hart_map_saddr(unsigned long base, unsigned long size);
|
int sbi_hart_map_saddr(unsigned long base, unsigned long size);
|
||||||
int sbi_hart_unmap_saddr(void);
|
int sbi_hart_unmap_saddr(void);
|
||||||
int sbi_hart_priv_version(struct sbi_scratch *scratch);
|
int sbi_hart_priv_version(struct sbi_scratch *scratch);
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
|
|||||||
struct sbi_trap_context *trap_ctx;
|
struct sbi_trap_context *trap_ctx;
|
||||||
struct sbi_domain *current_dom, *target_dom;
|
struct sbi_domain *current_dom, *target_dom;
|
||||||
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
|
||||||
unsigned int pmp_count = sbi_hart_pmp_count(scratch);
|
|
||||||
|
|
||||||
if (!ctx || !dom_ctx || ctx == dom_ctx)
|
if (!ctx || !dom_ctx || ctx == dom_ctx)
|
||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
@@ -123,14 +122,7 @@ static int switch_to_next_domain_context(struct hart_context *ctx,
|
|||||||
spin_unlock(&target_dom->assigned_harts_lock);
|
spin_unlock(&target_dom->assigned_harts_lock);
|
||||||
|
|
||||||
/* Reconfigure PMP settings for the new domain */
|
/* Reconfigure PMP settings for the new domain */
|
||||||
for (int i = 0; i < pmp_count; i++) {
|
sbi_hart_pmp_unconfigure(scratch);
|
||||||
/* Don't revoke firmware access permissions */
|
|
||||||
if (sbi_hart_smepmp_is_fw_region(i))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
sbi_platform_pmp_disable(sbi_platform_thishart_ptr(), i);
|
|
||||||
pmp_disable(i);
|
|
||||||
}
|
|
||||||
sbi_hart_pmp_configure(scratch);
|
sbi_hart_pmp_configure(scratch);
|
||||||
|
|
||||||
/* Save current CSR context and restore target domain's CSR context */
|
/* Save current CSR context and restore target domain's CSR context */
|
||||||
|
|||||||
@@ -578,6 +578,20 @@ int sbi_hart_pmp_configure(struct sbi_scratch *scratch)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch)
|
||||||
|
{
|
||||||
|
int i, pmp_count = sbi_hart_pmp_count(scratch);
|
||||||
|
|
||||||
|
for (i = 0; i < pmp_count; i++) {
|
||||||
|
/* Don't revoke firmware access permissions */
|
||||||
|
if (sbi_hart_smepmp_is_fw_region(i))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sbi_platform_pmp_disable(sbi_platform_ptr(scratch), i);
|
||||||
|
pmp_disable(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int sbi_hart_priv_version(struct sbi_scratch *scratch)
|
int sbi_hart_priv_version(struct sbi_scratch *scratch)
|
||||||
{
|
{
|
||||||
struct sbi_hart_features *hfeatures =
|
struct sbi_hart_features *hfeatures =
|
||||||
|
|||||||
Reference in New Issue
Block a user