risc-v: Fix kernel MMU mapping for L3 table

The L3 table address was calculated incorrectly. For every 2MiB of
mapped memory, an offset of 4KiB is needed from the base of the L3
table. The old calculation failed if paddr was not aligned to a 2MiB
boundary.
This commit is contained in:
Ville Juven 2022-08-09 13:15:02 +03:00 committed by Xiang Xiao
parent 2e7b594bf4
commit 31bb362aab
2 changed files with 14 additions and 4 deletions

View File

@ -80,12 +80,17 @@ uintptr_t g_kernel_pgt_pbase = PGT_L1_PBASE;
static void map_region(uintptr_t paddr, uintptr_t vaddr, size_t size,
uint32_t mmuflags)
{
uintptr_t offset;
uintptr_t l3base;
uintptr_t end_vaddr;
/* Start index for the L3 table, kernel flash is always first */
/* Start offset for the L3 table, kernel flash is always first */
l3base = PGT_L3_PBASE + ((paddr - KFLASH_START) / RV_MMU_PAGE_ENTRIES);
offset = ((paddr - KFLASH_START) / RV_MMU_L2_PAGE_SIZE) * RV_MMU_PAGE_SIZE;
/* L3 base address per 2MiB boundary */
l3base = PGT_L3_PBASE + offset;
/* Map the region to the L3 table as a whole */

View File

@ -80,12 +80,17 @@ uintptr_t g_kernel_pgt_pbase = PGT_L1_PBASE;
static void map_region(uintptr_t paddr, uintptr_t vaddr, size_t size,
uint32_t mmuflags)
{
uintptr_t offset;
uintptr_t l3base;
uintptr_t end_vaddr;
/* Start index for the L3 table, kernel flash is always first */
/* Start offset for the L3 table, kernel flash is always first */
l3base = PGT_L3_PBASE + ((paddr - KFLASH_START) / RV_MMU_PAGE_ENTRIES);
offset = ((paddr - KFLASH_START) / RV_MMU_L2_PAGE_SIZE) * RV_MMU_PAGE_SIZE;
/* L3 base address per 2MiB boundary */
l3base = PGT_L3_PBASE + offset;
/* Map the region to the L3 table as a whole */