PatchworkOS  c9fea19
A non-POSIX operating system.
Loading...
Searching...
No Matches
pmm.c File Reference
#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/mem/pmm_bitmap.h>
#include <kernel/mem/pmm_stack.h>
#include <kernel/sync/lock.h>
#include <boot/boot_info.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.

Macros

#define PMM_BITMAP_SIZE   (CONFIG_PMM_BITMAP_MAX_ADDR / PAGE_SIZE)
 

Functions

static bool pmm_is_efi_mem_available (EFI_MEMORY_TYPE type)
 
static void pmm_free_unlocked (void *address)
 
static void pmm_free_pages_unlocked (void *address, uint64_t count)
 
static void pmm_detect_memory (const boot_memory_map_t *map)
 
static void pmm_load_memory (const boot_memory_map_t *map)
 
void pmm_init (void)
 Initializes the Physical Memory Manager.
 
void * pmm_alloc (void)
 Allocates a single physical page.
 
uint64_t pmm_alloc_pages (void **addresses, uint64_t count)
 Allocates multiple physical pages.
 
void * pmm_alloc_bitmap (uint64_t count, uintptr_t maxAddr, uint64_t alignment)
 Allocates a contiguous region of physical pages managed by the bitmap.
 
void pmm_free (void *address)
 Frees a single physical page.
 
void pmm_free_pages (void **addresses, uint64_t count)
 Frees multiple physical pages.
 
void pmm_free_region (void *address, uint64_t count)
 Frees a contiguous region of physical pages.
 
uint64_t pmm_total_amount (void)
 Retrieves the total amount of physical memory managed by the PMM.
 
uint64_t pmm_free_amount (void)
 Retrieves the amount of free physical memory.
 
uint64_t pmm_used_amount (void)
 Retrieves the amount of reserved physical memory.
 

Variables

static const char * efiMemTypeToString []
 
static pmm_stack_t stack
 
static pmm_bitmap_t bitmap
 
static uint64_t bitmapBuffer [BITMAP_BITS_TO_QWORDS(PMM_BITMAP_SIZE)]
 
static uint64_t pageAmount = 0
 
static lock_t lock = LOCK_CREATE()
 

Macro Definition Documentation

◆ PMM_BITMAP_SIZE

#define PMM_BITMAP_SIZE   (CONFIG_PMM_BITMAP_MAX_ADDR / PAGE_SIZE)

Definition at line 36 of file pmm.c.

Function Documentation

◆ pmm_is_efi_mem_available()

static bool pmm_is_efi_mem_available ( EFI_MEMORY_TYPE  type)
static

Definition at line 48 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 ( void *  address)
static

Definition at line 68 of file pmm.c.

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

◆ pmm_free_pages_unlocked()

static void pmm_free_pages_unlocked ( void *  address,
uint64_t  count 
)
static

Definition at line 84 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 115 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 132 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 18 of file pmm.c.

◆ stack

pmm_stack_t stack
static

Definition at line 38 of file pmm.c.

◆ bitmap

pmm_bitmap_t bitmap
static

Definition at line 39 of file pmm.c.

◆ bitmapBuffer

Definition at line 42 of file pmm.c.

◆ pageAmount

uint64_t pageAmount = 0
static

Definition at line 44 of file pmm.c.

◆ lock

lock_t lock = LOCK_CREATE()
static

Definition at line 46 of file pmm.c.