22 "runtime services code",
23 "runtime services data",
34#define PMM_BITMAP_SIZE (CONFIG_PMM_BITMAP_MAX_ADDR / PAGE_SIZE)
55 case EfiConventionalMemory:
58 case EfiBootServicesCode:
59 case EfiBootServicesData:
115 LOG_INFO(
"UEFI-provided memory map\n");
142 LOG_INFO(
"reserve [0x%016lx-0x%016lx] pages=%d type=%s\n", desc->VirtualStart,
143 (
uint64_t)desc->VirtualStart + desc->NumberOfPages *
PAGE_SIZE, desc->NumberOfPages,
168 LOG_WARN(
"failed to allocate single page, there are %llu pages left\n",
stack.
free);
static bool boot_is_mem_ram(EFI_MEMORY_TYPE type)
#define BOOT_MEMORY_MAP_GET_DESCRIPTOR(map, index)
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
#define LOG_WARN(format,...)
#define LOG_INFO(format,...)
#define PML_HIGHER_TO_LOWER(addr)
Converts an address from the higher half to the lower half.
#define PML_LOWER_TO_HIGHER(addr)
Converts an address from the lower half to the higher half.
void * pmm_bitmap_alloc(pmm_bitmap_t *bitmap, uint64_t count, uintptr_t maxAddr, uint64_t alignment)
Allocates a contiguous region of pages from the bitmap.
void pmm_bitmap_init(pmm_bitmap_t *bitmap, void *buffer, uint64_t size, uintptr_t maxAddr)
Initializes a PMM bitmap.
void pmm_bitmap_free(pmm_bitmap_t *bitmap, void *address, uint64_t count)
Frees a region of pages, returning them to the bitmap.
void * pmm_stack_alloc(pmm_stack_t *stack)
Allocates a single page from the stack.
void pmm_stack_init(pmm_stack_t *stack)
Initializes a PMM stack.
void pmm_stack_free(pmm_stack_t *stack, void *address)
Frees a single page, returning it to the stack.
void pmm_init(const boot_memory_map_t *map)
Initializes the Physical Memory Manager.
uint64_t pmm_alloc_pages(void **addresses, uint64_t count)
Allocates multiple physical pages.
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_free_amount(void)
Retrieves the amount of free physical memory.
uint64_t pmm_reserved_amount(void)
Retrieves the amount of reserved physical memory.
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_alloc(void)
Allocates a single physical page.
uint64_t pmm_total_amount(void)
Retrieves the total amount of physical memory managed by the PMM.
#define LOCK_CREATE
Create a lock initializer. @macro LOCK_CREATE.
#define LOCK_SCOPE(lock)
Acquires a lock for the reminder of the current scope.
#define CONFIG_PMM_BITMAP_MAX_ADDR
Maximum bitmap allocator address.
#define ENOMEM
Out of memory.
#define errno
Error number variable.
#define BITMAP_BITS_TO_QWORDS(bits)
Convert number of bits to number of qwords.
#define ROUND_DOWN(number, multiple)
#define PAGE_SIZE
Memory page size.
#define NULL
Pointer error value.
#define ERR
Integer error value.
static void pmm_free_unlocked(void *address)
static uint64_t pageAmount
static pmm_bitmap_t bitmap
static void pmm_load_memory(const boot_memory_map_t *map)
static uint64_t mapBuffer[BITMAP_BITS_TO_QWORDS(PMM_BITMAP_SIZE)]
static void pmm_free_pages_unlocked(void *address, uint64_t count)
static bool pmm_is_efi_mem_available(EFI_MEMORY_TYPE type)
static const char * efiMemTypeToString[]
static void pmm_detect_memory(const boot_memory_map_t *map)
__UINTPTR_TYPE__ uintptr_t
A simple ticket lock implementation.
Represents a bitmap allocator's state.
uint64_t free
The number of free pages in the bitmap.
PMM stack structure for managing higher physical memory.
uint64_t free
The number of free pages in the stack.