26 "runtime services code",
27 "runtime services data",
60 case EfiConventionalMemory:
63 case EfiBootServicesCode:
64 case EfiBootServicesData:
106 alignPfn =
MAX(alignPfn, 1);
110 if (index == bitmap.length)
146 for (
size_t i = 0; i <
count; i++)
154 LOG_INFO(
"UEFI-provided memory map\n");
162 total += desc->NumberOfPages;
178 if (desc->Type == EfiConventionalMemory && desc->NumberOfPages >=
BYTES_TO_PAGES(size))
186 panic(
NULL,
"Failed to allocate pmm refs array");
198 size_t amount = desc->NumberOfPages;
214 for (
size_t j = 0; j < amount; j++)
224 for (
size_t j = 0; j < amount; j++)
269 LOG_WARN(
"out of memory in pmm_alloc()\n");
278 for (
size_t i = 0; i <
count; i++)
288 LOG_WARN(
"out of memory in pmm_alloc_pages()\n");
289 for (
size_t j = 0; j < i; j++)
305 for (
size_t i = 0; i <
count; i++)
323 for (
size_t i = 0; i <
count; i++)
335 LOG_WARN(
"out of memory in pmm_alloc_bitmap()\n");
351 for (
size_t i = 0; i <
count; i++)
368 for (
size_t i = 0; i <
count; i++)
373 for (
size_t j = 0; j < i; j++)
#define assert(expression)
static UNUSED_FUNC bool boot_is_mem_ram(EFI_MEMORY_TYPE type)
#define BOOT_MEMORY_MAP_GET_DESCRIPTOR(map, index)
#define CONFIG_PMM_BITMAP_MAX_ADDR
Maximum bitmap allocator address.
boot_info_t * boot_info_get(void)
Gets the boot info structure.
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 VIRT_TO_PFN(_addr)
Convert a identity mapped higher half virtual address to its PFN.
#define PFN_TO_VIRT(_pfn)
Convert a PFN to its identity mapped higher half virtual address.
size_t pfn_t
Page Frame Number type.
void pmm_free_pages(pfn_t *pfns, size_t count)
Free multiple pages of physical memory.
uint64_t pmm_alloc_pages(pfn_t *pfns, size_t count)
Allocate multiple pages of physical memory.
#define FREE_PAGE_MAX
Maximum number of free pages that can be stored in a free page.
size_t pmm_total_pages(void)
Get the total number of physical pages.
void pmm_free(pfn_t pfn)
Free a single page of physical memory.
uint64_t pmm_ref_inc(pfn_t pfn, size_t count)
Increment the reference count of a physical region.
pfn_t pmm_alloc(void)
Allocate a single page of physical memory.
size_t pmm_used_pages(void)
Get the number of used physical pages.
size_t pmm_avail_pages(void)
Get the number of available physical pages.
void pmm_free_region(pfn_t pfn, size_t count)
Free a contiguous region 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_init(void)
Read the boot info memory map and initialize the PMM.
#define LOCK_CREATE()
Create a lock initializer.
static void lock_release(lock_t *lock)
Releases a lock.
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
#define BITMAP_CREATE_ONE(name, bits)
Define and create a one-initialized bitmap and its buffer.
static uint64_t bitmap_find_clear_region_and_set(bitmap_t *map, uint64_t minIdx, uintptr_t maxIdx, uint64_t length, uint64_t alignment)
Find a clear region of specified length and alignment, and set it.
static void bitmap_clear_range(bitmap_t *map, uint64_t low, uint64_t high)
Clear a range of bits in the bitmap.
#define BYTES_TO_PAGES(amount)
Convert a size in bytes to pages.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define PAGE_SIZE
The size of a memory page in bytes.
static bool pmm_is_mem_avail(EFI_MEMORY_TYPE type)
static pfn_t pmm_stack_pop(void)
static page_stack_t * stack
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_init_refs(const boot_memory_map_t *map)
static void pmm_load_memory(const boot_memory_map_t *map)
static void pmm_stack_push(pfn_t pfn)
static pfn_t pmm_bitmap_set(size_t count, pfn_t maxPfn, pfn_t alignPfn)
static const char * efiMemTypeToString[]
static void pmm_detect_memory(const boot_memory_map_t *map)
__UINTPTR_TYPE__ uintptr_t
_PUBLIC void * memset(void *s, int c, size_t n)
A simple ticket lock implementation.
Stored in free pages to form a stack of free pages.
pfn_t pages[FREE_PAGE_MAX]