Skip to content

Commit

Permalink
core: riscv: Translate to PA when allocating PGT with MMU enabled
Browse files Browse the repository at this point in the history
If MMU is enabled, core_mmu_pgt_alloc() returns virtual address of PGT
instead of physical address. Thus, it leads to some errors when we
invoke pa_to_ppn() with returned PGT which is actually the virtual
address of that PGT.

Fix it by checking whether MMU is enabled or not. If MMU is enabled, we
translate the returned PGT to its physical address.

Signed-off-by: Alvin Chang <alvinga@andestech.com>
Reviewed-by: Yu Chien Peter Lin <peterlin@andestech.com>
  • Loading branch information
gagachang committed Jul 23, 2024
1 parent 39f965c commit 670d50b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/arch/riscv/mm/core_mmu_arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ bool core_mmu_entry_to_finer_grained(struct core_mmu_table_info *tbl_info,
struct mmu_pte *pte = NULL;
struct mmu_partition *prtn = core_mmu_get_prtn();
unsigned long ptp = 0;
paddr_t pgt_pa = 0;

if (!core_mmu_level_in_range(tbl_info->level))
return false;
Expand All @@ -538,7 +539,12 @@ bool core_mmu_entry_to_finer_grained(struct core_mmu_table_info *tbl_info,
if (!pgt)
return false;

ptp = core_mmu_ptp_create(pa_to_ppn((paddr_t)pgt));
if (cpu_mmu_enabled())
pgt_pa = virt_to_phys(pgt);
else
pgt_pa = (paddr_t)pgt;

ptp = core_mmu_ptp_create(pa_to_ppn(pgt_pa));
core_mmu_entry_set(pte, ptp);
}

Expand Down

0 comments on commit 670d50b

Please sign in to comment.