PatchworkOS
Loading...
Searching...
No Matches
pmm.c File Reference
#include <kernel/mem/pmm.h>
#include <kernel/config.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 <sys/math.h>
#include <sys/proc.h>

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 (const boot_memory_map_t *map)
 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_reserved_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 mapBuffer [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 34 of file pmm.c.

Function Documentation

◆ pmm_detect_memory()

static void pmm_detect_memory ( const boot_memory_map_t map)
static

Definition at line 113 of file pmm.c.

References boot_is_mem_ram(), BOOT_MEMORY_MAP_GET_DESCRIPTOR, boot_memory_map_t::length, LOG_INFO, map, and pageAmount.

Referenced by pmm_init().

◆ pmm_free_pages_unlocked()

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

◆ pmm_free_unlocked()

static void pmm_free_unlocked ( void *  address)
static

◆ pmm_is_efi_mem_available()

static bool pmm_is_efi_mem_available ( EFI_MEMORY_TYPE  type)
static

Definition at line 46 of file pmm.c.

References boot_is_mem_ram().

Referenced by pmm_load_memory().

◆ pmm_load_memory()

Variable Documentation

◆ bitmap

◆ 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 16 of file pmm.c.

Referenced by pmm_load_memory().

◆ lock

◆ mapBuffer

Definition at line 40 of file pmm.c.

Referenced by pmm_init().

◆ pageAmount

◆ stack