Skip to content

Commit

Permalink
arm/src/armv7-a: correct condition to allocate sections in mmu
Browse files Browse the repository at this point in the history
Previous code was checking only if size is multiple of section
size for allocating section. Modified the code to allocate section
if size >= section size. This also makes sure that during binary
loading, each binary atmost will need 4 l2 pages, 2 for rw data
atmost and 2 for rox data atmost.

Before changes :

mmu_allocate_app_l2_pgtbl: app_id : 0, l2idx : 0
mmu_allocate_app_l2_pgtbl: app_id : 0, l2idx : 1
mmu_allocate_app_l2_pgtbl: app_id : 0, l2idx : 2
mmu_allocate_app_l2_pgtbl: app_id : 0, l2idx : 3
mmu_allocate_app_l2_pgtbl: app_id : 0, l2idx : 4
mmu_allocate_app_l2_pgtbl: app_id : 0, l2idx : 5
mmu_allocate_app_l2_pgtbl: app_id : 0, l2idx : 6

mmu_allocate_app_l2_pgtbl: app_id : 1, l2idx : 0
mmu_allocate_app_l2_pgtbl: app_id : 1, l2idx : 1
mmu_allocate_app_l2_pgtbl: app_id : 1, l2idx : 2
mmu_allocate_app_l2_pgtbl: app_id : 1, l2idx : 3
mmu_allocate_app_l2_pgtbl: app_id : 1, l2idx : 4
mmu_allocate_app_l2_pgtbl: app_id : 1, l2idx : 5

After changes :

mmu_allocate_app_l2_pgtbl: app_id : 0, l2idx : 0
mmu_allocate_app_l2_pgtbl: app_id : 0, l2idx : 1
mmu_allocate_app_l2_pgtbl: app_id : 0, l2idx : 2

mmu_allocate_app_l2_pgtbl: app_id : 1, l2idx : 0
mmu_allocate_app_l2_pgtbl: app_id : 1, l2idx : 1

Signed-off-by: Abhishek Akkabathula <[email protected]>
  • Loading branch information
abhishek-samsung authored and kishore-sn committed Sep 9, 2024
1 parent 12be199 commit 8cac5b7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions os/arch/arm/src/armv7-a/arm_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,10 @@ void mmu_map_app_region(int app_id, uint32_t *l1_pgtbl, uint32_t start, uint32_t

// Run a loop until the entire region is mapped.
while (start < end) {
// Check if this address can be mapped to a section.
if (!(start & SECTION_MASK) && !(size & SECTION_MASK)) {
// Check if this address can be mapped to a section. Below are the conditions,
// 1. start should be aligned to section size
// 2. remaining size should be greater than or equal to section size
if (!(start & SECTION_MASK) && size >= SECTION_SIZE) {
// Yes. Update the section entry in the the L1 page table.
idx = start >> 20;
val = start & PMD_PTE_PADDR_MASK;
Expand All @@ -453,6 +455,7 @@ void mmu_map_app_region(int app_id, uint32_t *l1_pgtbl, uint32_t start, uint32_t

// Advance the memory region address.
start += SECTION_SIZE;
size -= SECTION_SIZE;
} else { // Check if this address can be mapped to a small page.

// Check if L2 page table is not created.
Expand Down Expand Up @@ -483,6 +486,7 @@ void mmu_map_app_region(int app_id, uint32_t *l1_pgtbl, uint32_t start, uint32_t

// Advance the memory region address.
start += SMALL_PAGE_SIZE;
size -= SMALL_PAGE_SIZE;
}
}
cp15_invalidate_tlbs();
Expand Down

0 comments on commit 8cac5b7

Please sign in to comment.