forked from Mirrors/opensbi
		
	lib: sbi: Add functions to manipulate PMP entries
- Add a function to disable a given PMP entry. - Add a function to check if a given entry is disabled. 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
						
							c3b98c610b
						
					
				
				
					commit
					1c099c4f36
				
			@@ -246,6 +246,48 @@ static unsigned long ctz(unsigned long x)
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int pmp_disable(unsigned int n)
 | 
			
		||||
{
 | 
			
		||||
	int pmpcfg_csr, pmpcfg_shift;
 | 
			
		||||
	unsigned long cfgmask, pmpcfg;
 | 
			
		||||
 | 
			
		||||
	if (n >= PMP_COUNT)
 | 
			
		||||
		return SBI_EINVAL;
 | 
			
		||||
 | 
			
		||||
#if __riscv_xlen == 32
 | 
			
		||||
	pmpcfg_csr   = CSR_PMPCFG0 + (n >> 2);
 | 
			
		||||
	pmpcfg_shift = (n & 3) << 3;
 | 
			
		||||
#elif __riscv_xlen == 64
 | 
			
		||||
	pmpcfg_csr   = (CSR_PMPCFG0 + (n >> 2)) & ~1;
 | 
			
		||||
	pmpcfg_shift = (n & 7) << 3;
 | 
			
		||||
#else
 | 
			
		||||
# error "Unexpected __riscv_xlen"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	/* Clear the address matching bits to disable the pmp entry */
 | 
			
		||||
	cfgmask = ~(0xffUL << pmpcfg_shift);
 | 
			
		||||
	pmpcfg	= (csr_read_num(pmpcfg_csr) & cfgmask);
 | 
			
		||||
 | 
			
		||||
	csr_write_num(pmpcfg_csr, pmpcfg);
 | 
			
		||||
 | 
			
		||||
	return SBI_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int is_pmp_entry_mapped(unsigned long entry)
 | 
			
		||||
{
 | 
			
		||||
	unsigned long prot;
 | 
			
		||||
	unsigned long addr;
 | 
			
		||||
	unsigned long log2len;
 | 
			
		||||
 | 
			
		||||
	pmp_get(entry, &prot, &addr, &log2len);
 | 
			
		||||
 | 
			
		||||
	/* If address matching bits are non-zero, the entry is enable */
 | 
			
		||||
	if (prot & PMP_A)
 | 
			
		||||
		return true;
 | 
			
		||||
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int pmp_set(unsigned int n, unsigned long prot, unsigned long addr,
 | 
			
		||||
	    unsigned long log2len)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user