Function comments (v1)
This commit is contained in:
@@ -24,13 +24,16 @@ First we'll have to discover the physical memory layout,
|
||||
and for that we can use a Limine request.
|
||||
*/
|
||||
|
||||
/*
|
||||
We will look for the biggest usable physical memory region
|
||||
and use this for the bitmap. The reserved memory will be ignored.
|
||||
*/
|
||||
|
||||
struct limine_memmap_entry* biggest_entry;
|
||||
|
||||
/*
|
||||
* pmm_find_biggest_usable_region - Finding the biggest free memory region
|
||||
* @memmap: Limine memory map
|
||||
* @hhdm: Limine HHDM offset
|
||||
*
|
||||
* This function uses the memory map provided by the bootloader
|
||||
* to find the single biggest free memory region we can use.
|
||||
*/
|
||||
static void pmm_find_biggest_usable_region(struct limine_memmap_response* memmap, struct limine_hhdm_response* hhdm)
|
||||
{
|
||||
// Max length of a usable memory region
|
||||
@@ -62,6 +65,14 @@ uint64_t hhdm_off;
|
||||
|
||||
static uintptr_t g_freelist = 0;
|
||||
|
||||
/*
|
||||
* pmm_alloc - Allocate a physical page
|
||||
*
|
||||
* This function allocates a single physical page (frame)
|
||||
*
|
||||
* Return:
|
||||
* <addr> - Address for the allocated page
|
||||
*/
|
||||
uintptr_t pmm_alloc()
|
||||
{
|
||||
if (!g_freelist) {
|
||||
@@ -72,12 +83,22 @@ uintptr_t pmm_alloc()
|
||||
return addr;
|
||||
}
|
||||
|
||||
/*
|
||||
* pmm_free - Frees a memory page
|
||||
* @addr: Address to the page
|
||||
*/
|
||||
void pmm_free(uintptr_t addr)
|
||||
{
|
||||
*(uintptr_t*) PHYS_TO_VIRT(addr) = g_freelist;
|
||||
g_freelist = addr;
|
||||
}
|
||||
|
||||
/*
|
||||
* pmm_init_freelist - PMM freelist initialization
|
||||
*
|
||||
* This function marks the biggest memory region as
|
||||
* free, so we can use it in pmm_alloc.
|
||||
*/
|
||||
static void pmm_init_freelist()
|
||||
{
|
||||
// We simply call pmm_free() on each page that is marked USABLE
|
||||
@@ -93,6 +114,13 @@ static void pmm_init_freelist()
|
||||
DEBUG("%u frames in freelist, available for use (%u bytes)", page_count, page_count*PAGE_SIZE);
|
||||
}
|
||||
|
||||
/*
|
||||
* pmm_init - Physical memory manager initialization
|
||||
* @boot_ctx: Boot context structure
|
||||
*
|
||||
* This function prepares the PMM for use.
|
||||
* The PMM works with a freelist.
|
||||
*/
|
||||
void pmm_init(struct boot_context boot_ctx)
|
||||
{
|
||||
hhdm_off = boot_ctx.hhdm->offset;
|
||||
|
||||
Reference in New Issue
Block a user