PatchworkOS
Loading...
Searching...
No Matches
PMM Bitmap

A generic bitmap page allocator. More...

Data Structures

struct  pmm_bitmap_t
 Represents a bitmap allocator's state. More...
 

Functions

void pmm_bitmap_init (pmm_bitmap_t *bitmap, void *buffer, uint64_t size, uintptr_t maxAddr)
 Initializes a PMM bitmap.
 
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_free (pmm_bitmap_t *bitmap, void *address, uint64_t count)
 Frees a region of pages, returning them to the bitmap.
 

Detailed Description

A generic bitmap page allocator.

The PMM bitmap provides a flexible allocator for more specific allocations, for example it can handle contiguous pages, specific alignments and allocating below some specified address. This flexibility comes at the cost of performance, so the bitmap should only be used when necessary.

Function Documentation

◆ pmm_bitmap_alloc()

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.

Parameters
bitmapThe bitmap to allocate from.
countThe number of pages to allocate.
maxAddrThe maximum address for the allocation.
alignmentThe required alignment for the allocation.
Returns
On success, a pointer to the allocated region. On failure NULL and errno is set.

Definition at line 16 of file pmm_bitmap.c.

References pmm_bitmap_t::bitmap, bitmap, bitmap_find_clear_region_and_set(), count, pmm_bitmap_t::free, bitmap_t::length, MAX, pmm_bitmap_t::maxAddr, MIN, NULL, PAGE_SIZE, PML_HIGHER_HALF_START, and ROUND_UP.

Referenced by pmm_alloc_bitmap().

◆ pmm_bitmap_free()

void pmm_bitmap_free ( pmm_bitmap_t bitmap,
void *  address,
uint64_t  count 
)

Frees a region of pages, returning them to the bitmap.

Parameters
bitmapThe bitmap to free to.
addressThe address of the region to free.
countThe number of pages to free.

Definition at line 32 of file pmm_bitmap.c.

References address, assert, pmm_bitmap_t::bitmap, bitmap, bitmap_clear_range(), count, pmm_bitmap_t::free, PAGE_SIZE, PML_HIGHER_TO_LOWER, and ROUND_DOWN.

Referenced by pmm_free_pages_unlocked(), and pmm_free_unlocked().

◆ pmm_bitmap_init()

void pmm_bitmap_init ( pmm_bitmap_t bitmap,
void *  buffer,
uint64_t  size,
uintptr_t  maxAddr 
)

Initializes a PMM bitmap.

Parameters
bitmapThe bitmap to initialize.
bufferThe buffer to use for the bitmap data.
sizeThe number of pages to manage.
maxAddrThe maximum address to manage.

Definition at line 7 of file pmm_bitmap.c.

References assert, pmm_bitmap_t::bitmap, bitmap, bitmap_init(), buffer, pmm_bitmap_t::free, pmm_bitmap_t::maxAddr, PAGE_SIZE, and pmm_bitmap_t::total.

Referenced by pmm_init().