Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(extra mem): Fix additonal memory allocation for MPU-based systems #196

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/core/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <fences.h>
#include <config.h>

extern uint8_t _image_start, _image_load_end, _image_end, _vm_image_start, _vm_image_end;
extern uint8_t _image_start, _image_load_end, _image_end, _vm_image_start, _vm_image_end, _image_noload_start, _dmem_phys_beg;

struct list page_pool_list;

Expand Down Expand Up @@ -138,16 +138,14 @@ void* mem_alloc_page(size_t num_pages, enum AS_SEC sec, bool phys_aligned)

static bool root_pool_set_up_bitmap(paddr_t load_addr, struct page_pool* root_pool)
{
size_t image_size = (size_t)(&_image_end - &_image_start);
size_t vm_image_size = (size_t)(&_vm_image_end - &_vm_image_start);
size_t cpu_size = platform.cpu_num * mem_cpu_boot_alloc_size();
paddr_t bitmap_base = load_addr + (paddr_t)(&_dmem_phys_beg - &_image_start) + cpu_size;

size_t bitmap_num_pages =
root_pool->size / (8 * PAGE_SIZE) + ((root_pool->size % (8 * PAGE_SIZE) != 0) ? 1 : 0);
if (root_pool->size <= bitmap_num_pages) {
return false;
}
size_t bitmap_base = load_addr + image_size + vm_image_size + cpu_size;

struct ppages bitmap_pp = mem_ppages_get(bitmap_base, bitmap_num_pages);
bitmap_t* root_bitmap = (bitmap_t*)mem_alloc_map(&cpu()->as, SEC_HYP_GLOBAL, &bitmap_pp,
Expand All @@ -160,11 +158,10 @@ static bool root_pool_set_up_bitmap(paddr_t load_addr, struct page_pool* root_po

static bool pp_root_reserve_hyp_mem(paddr_t load_addr, struct page_pool* root_pool)
{
size_t image_load_size = (size_t)(&_image_load_end - &_image_start);
size_t image_noload_size = (size_t)(&_image_end - &_image_load_end);
size_t vm_image_size = (size_t)(&_vm_image_end - &_vm_image_start);
size_t image_load_size = (size_t)(&_image_load_end - &_image_start);
size_t image_noload_size = (size_t)(&_image_end - &_image_noload_start);
size_t cpu_size = platform.cpu_num * mem_cpu_boot_alloc_size();
paddr_t image_noload_addr = load_addr + image_load_size + vm_image_size;
paddr_t image_noload_addr = load_addr + (paddr_t)(&_image_noload_start- &_image_start);
paddr_t cpu_base_addr = image_noload_addr + image_noload_size;

struct ppages images_load_ppages = mem_ppages_get(load_addr, NUM_PAGES(image_load_size));
Expand Down
9 changes: 7 additions & 2 deletions src/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ SECTIONS
KEEP(*(.vm_image*))
}
. = ALIGN(PAGE_SIZE);
_vm_image_end = .;
_image_noload_start = .;
_vm_image_end = .;
extra_allocated_phys_mem = _image_noload_start - _image_load_end;

#ifdef MEM_PROT_MMU
Expand All @@ -73,6 +72,7 @@ SECTIONS
#endif

/* Only no load regions below */
_image_noload_start = .;

.bss (NOLOAD) : {
_bss_start = .;
Expand All @@ -89,7 +89,12 @@ SECTIONS

. = ALIGN(PAGE_SIZE);
_image_end = ABSOLUTE(.);

#ifdef MEM_PROT_MMU
_dmem_phys_beg = ABSOLUTE(.) + extra_allocated_phys_mem;
#else
_dmem_phys_beg = ABSOLUTE(.);
#endif

. = ALIGN(PAGE_SIZE);
_dmem_beg = ABSOLUTE(.);
Expand Down
Loading