diff --git a/src/display.c b/src/display.c index fd7bc0dd..70864a3f 100644 --- a/src/display.c +++ b/src/display.c @@ -370,12 +370,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); diff --git a/src/utils.c b/src/utils.c index 23434762..ff8dd84b 100644 --- a/src/utils.c +++ b/src/utils.c @@ -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; +} diff --git a/src/utils.h b/src/utils.h index f60ac773..dc4bb8d6 100644 --- a/src/utils.h +++ b/src/utils.h @@ -434,5 +434,6 @@ void cpu_sleep(bool deep) __attribute__((noreturn)); void deep_wfi(void); bool is_heap(void *addr); +u64 top_of_memory_alloc(size_t size); #endif