xref: /kvm-unit-tests/lib/riscv/asm/mmu.h (revision 386ed5c2f9e98a2605817748c44c0cefa60dc88e)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef _ASMRISCV_MMU_H_
3 #define _ASMRISCV_MMU_H_
4 #include <libcflat.h>
5 #include <asm/csr.h>
6 #include <asm/page.h>
7 #include <asm/pgtable.h>
8 
9 static inline pgd_t *current_pgtable(void)
10 {
11 	return (pgd_t *)((csr_read(CSR_SATP) & SATP_PPN) << PAGE_SHIFT);
12 }
13 
14 void mmu_set_range_ptes(pgd_t *pgtable, uintptr_t virt_offset,
15 			phys_addr_t phys_start, phys_addr_t phys_end,
16 			pgprot_t prot, bool flush);
17 void __mmu_enable(unsigned long satp);
18 void mmu_enable(unsigned long mode, pgd_t *pgtable);
19 void mmu_disable(void);
20 
21 static inline void local_flush_tlb_page(unsigned long addr)
22 {
23 	asm volatile("sfence.vma %0" : : "r" (addr) : "memory");
24 }
25 
26 /*
27  * Get the pte pointer for a virtual address, even if it's not mapped.
28  * Constructs upper levels of the table as necessary.
29  */
30 pte_t *get_pte(pgd_t *pgtable, uintptr_t vaddr);
31 
32 #endif /* _ASMRISCV_MMU_H_ */
33