From 1387c352135efdfcd7e3a14298617febdebb7d5c Mon Sep 17 00:00:00 2001 From: Ville Juven Date: Tue, 23 May 2023 16:40:01 +0300 Subject: [PATCH] arch/risc-v: Add method to extract PPN from SATP value This makes it possible to get the physical page number (PPN) from any SATP value, not only the currently active SATP register. --- arch/risc-v/src/common/riscv_mmu.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/arch/risc-v/src/common/riscv_mmu.h b/arch/risc-v/src/common/riscv_mmu.h index 26e398fc1d..fbc5a68828 100644 --- a/arch/risc-v/src/common/riscv_mmu.h +++ b/arch/risc-v/src/common/riscv_mmu.h @@ -307,11 +307,30 @@ static inline uintptr_t mmu_pte_to_paddr(uintptr_t pte) return paddr; } +/**************************************************************************** + * Name: mmu_satp_to_paddr + * + * Description: + * Extract physical address from SATP + * + * Returned Value: + * Physical address from SATP value + * + ****************************************************************************/ + +static inline uintptr_t mmu_satp_to_paddr(uintptr_t satp) +{ + uintptr_t ppn; + ppn = satp; + ppn = ((ppn >> SATP_PPN_SHIFT) & SATP_PPN_MASK); + return SATP_PPN_TO_ADDR(ppn); +} + /**************************************************************************** * Name: mmu_get_satp_pgbase * * Description: - * Utility function to read the base page table physical address + * Utility function to read the current base page table physical address * * Returned Value: * Physical address of the current base page table @@ -320,10 +339,7 @@ static inline uintptr_t mmu_pte_to_paddr(uintptr_t pte) static inline uintptr_t mmu_get_satp_pgbase(void) { - uintptr_t ppn; - ppn = mmu_read_satp(); - ppn = ((ppn >> SATP_PPN_SHIFT) & SATP_PPN_MASK); - return SATP_PPN_TO_ADDR(ppn); + return mmu_satp_to_paddr(mmu_read_satp()); } /****************************************************************************