PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
pmm.c File Reference
#include <kernel/mem/paging_types.h>
#include <kernel/mem/pmm.h>
#include <kernel/config.h>
#include <kernel/init/boot_info.h>
#include <kernel/log/log.h>
#include <kernel/log/panic.h>
#include <kernel/sync/lock.h>
#include <boot/boot_info.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/bitmap.h>
#include <errno.h>
#include <string.h>
#include <sys/math.h>
#include <sys/proc.h>
Include dependency graph for pmm.c:

Go to the source code of this file.

Functions

 BITMAP_CREATE_ONE (bitmap, CONFIG_PMM_BITMAP_MAX_ADDR/PAGE_SIZE)
 
static bool pmm_is_mem_avail (EFI_MEMORY_TYPE type)
 
static void pmm_stack_push (pfn_t pfn)
 
static pfn_t pmm_stack_pop (void)
 
static pfn_t pmm_bitmap_set (size_t count, pfn_t maxPfn, pfn_t alignPfn)
 
static void pmm_bitmap_clear (pfn_t pfn, size_t pageAmount)
 
static void pmm_free_unlocked (pfn_t pfn)
 
static void pmm_free_region_unlocked (pfn_t pfn, size_t count)
 
static void pmm_detect_memory (const boot_memory_map_t *map)
 
static void pmm_init_refs (const boot_memory_map_t *map)
 
static void pmm_load_memory (const boot_memory_map_t *map)
 
void pmm_init (void)
 Read the boot info memory map and initialize the PMM.
 
pfn_t pmm_alloc (void)
 Allocate a single page of physical memory.
 
uint64_t pmm_alloc_pages (pfn_t *pfns, size_t count)
 Allocate multiple pages of physical memory.
 
pfn_t pmm_alloc_bitmap (size_t count, pfn_t maxPfn, pfn_t alignPfn)
 Allocate a contiguous region of physical memory using the bitmap.
 
void pmm_free (pfn_t pfn)
 Free a single page of physical memory.
 
void pmm_free_pages (pfn_t *pfns, size_t count)
 Free multiple pages of physical memory.
 
void pmm_free_region (pfn_t pfn, size_t count)
 Free a contiguous region of physical memory.
 
uint64_t pmm_ref_inc (pfn_t pfn, size_t count)
 Increment the reference count of a physical region.
 
size_t pmm_total_pages (void)
 Get the total number of physical pages.
 
size_t pmm_avail_pages (void)
 Get the number of available physical pages.
 
size_t pmm_used_pages (void)
 Get the number of used physical pages.
 

Variables

static const char * efiMemTypeToString []
 
static page_tpages = NULL
 
static page_stack_tstack = NULL
 
static size_t location = FREE_PAGE_MAX
 
static pfn_t highest = 0
 
static size_t total = 0
 
static size_t avail = 0
 
static lock_t lock = LOCK_CREATE()
 

Function Documentation

◆ BITMAP_CREATE_ONE()

BITMAP_CREATE_ONE ( bitmap  ,
CONFIG_PMM_BITMAP_MAX_ADDR PAGE_SIZE 
)

◆ pmm_is_mem_avail()

static bool pmm_is_mem_avail ( EFI_MEMORY_TYPE  type)
static

Definition at line 51 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_stack_push()

static void pmm_stack_push ( pfn_t  pfn)
inlinestatic

Definition at line 71 of file pmm.c.

Here is the caller graph for this function:

◆ pmm_stack_pop()

static pfn_t pmm_stack_pop ( void  )
inlinestatic

Definition at line 86 of file pmm.c.

Here is the caller graph for this function:

◆ pmm_bitmap_set()

static pfn_t pmm_bitmap_set ( size_t  count,
pfn_t  maxPfn,
pfn_t  alignPfn 
)
inlinestatic

Definition at line 104 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_bitmap_clear()

static void pmm_bitmap_clear ( pfn_t  pfn,
size_t  pageAmount 
)
inlinestatic

Definition at line 118 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_free_unlocked()

static void pmm_free_unlocked ( pfn_t  pfn)
static

Definition at line 123 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_free_region_unlocked()

static void pmm_free_region_unlocked ( pfn_t  pfn,
size_t  count 
)
static

Definition at line 144 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_detect_memory()

static void pmm_detect_memory ( const boot_memory_map_t map)
static

Definition at line 152 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_init_refs()

static void pmm_init_refs ( const boot_memory_map_t map)
static

Definition at line 172 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pmm_load_memory()

static void pmm_load_memory ( const boot_memory_map_t map)
static

Definition at line 189 of file pmm.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ efiMemTypeToString

const char* efiMemTypeToString[]
static
Initial value:
= {
"reserved",
"loader code",
"loader data",
"boot services code",
"boot services data",
"runtime services code",
"runtime services data",
"conventional",
"unusable",
"acpi reclaim",
"acpi memory nvs",
"io",
"io port space",
"pal code",
"persistent",
}

Definition at line 20 of file pmm.c.

◆ pages

page_t* pages = NULL
static

Definition at line 38 of file pmm.c.

◆ stack

page_stack_t* stack = NULL
static

Definition at line 40 of file pmm.c.

◆ location

size_t location = FREE_PAGE_MAX
static

Definition at line 41 of file pmm.c.

◆ highest

pfn_t highest = 0
static

Definition at line 45 of file pmm.c.

◆ total

size_t total = 0
static

Definition at line 46 of file pmm.c.

◆ avail

size_t avail = 0
static

Definition at line 47 of file pmm.c.

◆ lock

lock_t lock = LOCK_CREATE()
static

Definition at line 49 of file pmm.c.