Implemented memblock_alloc()

This commit is contained in:
2022-12-29 20:53:39 +00:00
parent d9daeae384
commit 02211e6eba
3 changed files with 85 additions and 32 deletions

View File

@@ -9,8 +9,8 @@
#define MEMBLOCK_INIT_RESERVED_REGION_COUNT 128
#define __for_each_mem_range(i, type_a, type_b, p_start, p_end) \
for ((i)->idx = 0, __next_memory_region(i, type_a, type_b, p_start, p_end); \
(i)->idx != ULLONG_MAX; \
for ((i)->__idx = 0, __next_memory_region(i, type_a, type_b, p_start, p_end); \
(i)->__idx != ULLONG_MAX; \
__next_memory_region(i, type_a, type_b, p_start, p_end))
#define for_each_mem_range(i, p_start, p_end) \
@@ -57,9 +57,10 @@ typedef struct memblock {
} memblock_t;
typedef struct memblock_iter {
memblock_index_t idx;
phys_addr_t base;
phys_addr_t limit;
memblock_index_t __idx;
phys_addr_t it_base;
phys_addr_t it_limit;
memblock_region_status_t it_status;
} memblock_iter_t;
extern memblock_t memblock;
@@ -70,6 +71,7 @@ extern int memblock_add(phys_addr_t base, size_t size);
extern int memblock_reserve(phys_addr_t base, size_t size);
extern phys_addr_t memblock_alloc(size_t size);
extern int memblock_free(phys_addr_t addr, size_t size);
extern void __next_memory_region(memblock_iter_t *it, \
memblock_type_t *type_a, memblock_type_t *type_b,