PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
pmm_bitmap.h
Go to the documentation of this file.
1#pragma once
2
3#include <sys/bitmap.h>
4#include <sys/proc.h>
5
6/**
7 * @brief A generic bitmap page allocator.
8 * @defgroup kernel_mem_pmm_bitmap PMM Bitmap
9 * @ingroup kernel_mem
10 *
11 * The PMM bitmap provides a flexible allocator for more specific allocations, for example it can handle contiguous
12 * pages, specific alignments and allocating below some specified address. This flexibility comes at the cost of
13 * performance, so the bitmap should only be used when necessary.
14 *
15 * @{
16 */
17
18/**
19 * @brief Represents a bitmap allocator's state.
20 */
21typedef struct
22{
23 /**
24 * @brief The underlying bitmap used for tracking page status.
25 */
27 /**
28 * @brief The number of free pages in the bitmap.
29 */
31 /**
32 * @brief The total number of pages managed by the bitmap.
33 */
35 /**
36 * @brief The maximum address managed by the bitmap.
37 */
40
41/**
42 * @brief Initializes a PMM bitmap.
43 *
44 * @param bitmap The bitmap to initialize.
45 * @param buffer The buffer to use for the bitmap data.
46 * @param size The number of pages to manage.
47 * @param maxAddr The maximum address to manage.
48 */
49void pmm_bitmap_init(pmm_bitmap_t* bitmap, void* buffer, uint64_t size, uintptr_t maxAddr);
50
51/**
52 * @brief Allocates a contiguous region of pages from the bitmap.
53 *
54 * @param bitmap The bitmap to allocate from.
55 * @param count The number of pages to allocate.
56 * @param maxAddr The maximum address for the allocation.
57 * @param alignment The required alignment for the allocation.
58 * @return On success, a pointer to the allocated region. On failure `NULL` and errno is set.
59 */
61
62/**
63 * @brief Frees a region of pages, returning them to the bitmap.
64 *
65 * @param bitmap The bitmap to free to.
66 * @param address The address of the region to free.
67 * @param count The number of pages to free.
68 */
70
71/** @} */
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.
Definition pmm_bitmap.c:16
void pmm_bitmap_init(pmm_bitmap_t *bitmap, void *buffer, uint64_t size, uintptr_t maxAddr)
Initializes a PMM bitmap.
Definition pmm_bitmap.c:7
void pmm_bitmap_free(pmm_bitmap_t *bitmap, void *address, uint64_t count)
Frees a region of pages, returning them to the bitmap.
Definition pmm_bitmap.c:32
static uintptr_t address
Mapped virtual address of the HPET registers.
Definition hpet.c:95
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
static pmm_bitmap_t bitmap
Definition pmm.c:39
static atomic_long count
Definition main.c:10
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:43
Bitmap structure.
Definition bitmap.h:22
Represents a bitmap allocator's state.
Definition pmm_bitmap.h:22
uint64_t free
The number of free pages in the bitmap.
Definition pmm_bitmap.h:30
bitmap_t bitmap
The underlying bitmap used for tracking page status.
Definition pmm_bitmap.h:26
uint64_t total
The total number of pages managed by the bitmap.
Definition pmm_bitmap.h:34
uintptr_t maxAddr
The maximum address managed by the bitmap.
Definition pmm_bitmap.h:38