forked from Mirrors/opensbi
		
	lib: sbi: Add functions to map/unmap shared memory
When Smepmp is enabled, M-mode will need to map/unmap the shared memory before it can read/write to it. This patch adds functions to create dynamic short-lived mappings. Signed-off-by: Himanshu Chauhan <hchauhan@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
		
				
					committed by
					
						
						Anup Patel
					
				
			
			
				
	
			
			
			
						parent
						
							5dd8db5b10
						
					
				
				
					commit
					6e44ef686a
				
			@@ -347,6 +347,48 @@ unsigned int sbi_hart_get_smepmp_flags(struct sbi_scratch *scratch,
 | 
			
		||||
	return pmp_flags;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sbi_hart_map_saddr(unsigned long addr, unsigned long size)
 | 
			
		||||
{
 | 
			
		||||
	/* shared R/W access for M and S/U mode */
 | 
			
		||||
	unsigned int pmp_flags = (PMP_W | PMP_X);
 | 
			
		||||
	unsigned long order, base = 0;
 | 
			
		||||
	struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
 | 
			
		||||
 | 
			
		||||
	/* If Smepmp is not supported no special mapping is required */
 | 
			
		||||
	if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP))
 | 
			
		||||
		return SBI_OK;
 | 
			
		||||
 | 
			
		||||
	if (is_pmp_entry_mapped(SBI_SMEPMP_RESV_ENTRY))
 | 
			
		||||
		return SBI_ENOSPC;
 | 
			
		||||
 | 
			
		||||
	for (order = log2roundup(size) ; order <= __riscv_xlen; order++) {
 | 
			
		||||
		if (order < __riscv_xlen) {
 | 
			
		||||
			base = addr & ~((1UL << order) - 1UL);
 | 
			
		||||
			if ((base <= addr) &&
 | 
			
		||||
			    (addr < (base + (1UL << order))) &&
 | 
			
		||||
			    (base <= (addr + size - 1UL)) &&
 | 
			
		||||
			    ((addr + size - 1UL) < (base + (1UL << order))))
 | 
			
		||||
				break;
 | 
			
		||||
		} else {
 | 
			
		||||
			return SBI_EFAIL;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	pmp_set(SBI_SMEPMP_RESV_ENTRY, pmp_flags, base, order);
 | 
			
		||||
 | 
			
		||||
	return SBI_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sbi_hart_unmap_saddr(void)
 | 
			
		||||
{
 | 
			
		||||
	struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
 | 
			
		||||
 | 
			
		||||
	if (!sbi_hart_has_extension(scratch, SBI_HART_EXT_SMEPMP))
 | 
			
		||||
		return SBI_OK;
 | 
			
		||||
 | 
			
		||||
	return pmp_disable(SBI_SMEPMP_RESV_ENTRY);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sbi_hart_pmp_configure(struct sbi_scratch *scratch)
 | 
			
		||||
{
 | 
			
		||||
	struct sbi_domain_memregion *reg;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user