display: Factor out top of memory allocation

Move it into utils.c before we reuse it for SIO data.

Signed-off-by: Martin Povišer <povik@cutebit.org>
This commit is contained in:
Martin Povišer 2023-02-22 15:24:21 +01:00
parent 9e616021d6
commit b74218f2ae
3 changed files with 22 additions and 6 deletions

View file

@ -369,12 +369,7 @@ int display_configure(const char *config)
return -1;
}
cur_boot_args.mem_size -= size;
fb_pa = cur_boot_args.phys_base + cur_boot_args.mem_size;
/* add guard page between RAM and framebuffer */
// TODO: update mapping?
cur_boot_args.mem_size -= SZ_16K;
fb_pa = top_of_memory_alloc(size);
memset((void *)fb_pa, 0, size);
tmp_dva = iova_alloc(dcp->iovad_dcp, size);

View file

@ -180,3 +180,23 @@ bool is_heap(void *addr)
return p > top_of_kernel_data && p < top_of_ram;
}
// TODO: update mapping?
u64 top_of_memory_alloc(size_t size)
{
static bool guard_page_inserted = false;
cur_boot_args.mem_size -= ALIGN_UP(size, SZ_16K);
u64 ret = cur_boot_args.phys_base + cur_boot_args.mem_size;
if (!guard_page_inserted) {
cur_boot_args.mem_size -= SZ_16K;
guard_page_inserted = true;
} else {
// If the guard page was already there, move it down and allocate
// above it -- this is accomplished by simply shifting the allocated
// region by one page up.
ret += SZ_16K;
}
return ret;
}

View file

@ -440,5 +440,6 @@ extern struct vector_args next_stage;
void deep_wfi(void);
bool is_heap(void *addr);
u64 top_of_memory_alloc(size_t size);
#endif