From 5eec86eec8ee92f9c7d4211c34fddf794609ed71 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Tue, 9 Dec 2025 19:22:35 +0530 Subject: lib: sbi: Factor-out PMP programming into separate sources The PMP programming is a significant part of sbi_hart.c so factor-out this into separate sources sbi_hart_pmp.c and sbi_hart_pmp.h for better maintainability. Signed-off-by: Anup Patel Link: https://lore.kernel.org/r/20251209135235.423391-6-apatel@ventanamicro.com Signed-off-by: Anup Patel --- include/sbi/sbi_hart.h | 22 +++------------------- include/sbi/sbi_hart_pmp.h | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 include/sbi/sbi_hart_pmp.h (limited to 'include') diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index bbd8026e..a788b34c 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -107,21 +107,6 @@ enum sbi_hart_csrs { SBI_HART_CSR_MAX, }; -/* - * Smepmp enforces access boundaries between M-mode and - * S/U-mode. When it is enabled, the PMPs are programmed - * such that M-mode doesn't have access to S/U-mode memory. - * - * To give M-mode R/W access to the shared memory between M and - * S/U-mode, first entry is reserved. It is disabled at boot. - * When shared memory access is required, the physical address - * should be programmed into the first PMP entry with R/W - * permissions to the M-mode. Once the work is done, it should be - * unmapped. sbi_hart_protection_map_range/sbi_hart_protection_unmap_range - * function pair should be used to map/unmap the shared memory. - */ -#define SBI_SMEPMP_RESV_ENTRY 0 - struct sbi_hart_features { bool detected; int priv_version; @@ -134,6 +119,9 @@ struct sbi_hart_features { unsigned int mhpm_bits; }; +extern unsigned long hart_features_offset; +#define sbi_hart_features_ptr(__s) sbi_scratch_offset_ptr(__s, hart_features_offset) + struct sbi_scratch; int sbi_hart_reinit(struct sbi_scratch *scratch); @@ -144,11 +132,7 @@ extern void (*sbi_hart_expected_trap)(void); unsigned int sbi_hart_mhpm_mask(struct sbi_scratch *scratch); void sbi_hart_delegation_dump(struct sbi_scratch *scratch, const char *prefix, const char *suffix); -unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch); -unsigned int sbi_hart_pmp_log2gran(struct sbi_scratch *scratch); -unsigned int sbi_hart_pmp_addrbits(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); int sbi_hart_priv_version(struct sbi_scratch *scratch); void sbi_hart_get_priv_version_str(struct sbi_scratch *scratch, char *version_str, int nvstr); diff --git a/include/sbi/sbi_hart_pmp.h b/include/sbi/sbi_hart_pmp.h new file mode 100644 index 00000000..f54e8b2a --- /dev/null +++ b/include/sbi/sbi_hart_pmp.h @@ -0,0 +1,20 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2025 Ventana Micro Systems Inc. + */ + +#ifndef __SBI_HART_PMP_H__ +#define __SBI_HART_PMP_H__ + +#include + +struct sbi_scratch; + +unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch); +unsigned int sbi_hart_pmp_log2gran(struct sbi_scratch *scratch); +unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch); +bool sbi_hart_smepmp_is_fw_region(unsigned int pmp_idx); +int sbi_hart_pmp_init(struct sbi_scratch *scratch); + +#endif -- cgit v1.2.3