| 1 | /* @title: Page Allocation */ |
| 2 | #pragma once |
| 3 | #include <compiler.h> |
| 4 | #include <mem/alloc.h> |
| 5 | #include <stddef.h> |
| 6 | #include <stdint.h> |
| 7 | |
| 8 | #define page_alloc_1(n_pages) \ |
| 9 | page_alloc_internal((n_pages), ALLOC_FLAGS_NONE, ALLOC_BEHAVIOR_NORMAL) |
| 10 | #define page_alloc_2(n_pages, flags) \ |
| 11 | page_alloc_internal((n_pages), (flags), ALLOC_BEHAVIOR_NORMAL) |
| 12 | #define page_alloc_3(n_pages, flags, bh) \ |
| 13 | page_alloc_internal((n_pages), (flags), (bh)) |
| 14 | #define page_alloc(...) _DISPATCH(page_alloc, PP_NARG(__VA_ARGS__))(__VA_ARGS__) |
| 15 | |
| 16 | #define page_alloc_demand_1(n_pages) \ |
| 17 | page_alloc_demand_internal((n_pages), ALLOC_FLAGS_NONE, \ |
| 18 | ALLOC_BEHAVIOR_NORMAL) |
| 19 | #define page_alloc_demand_2(n_pages, flags) \ |
| 20 | page_alloc_demand_internal((n_pages), (flags), ALLOC_BEHAVIOR_NORMAL) |
| 21 | #define page_alloc_demand_3(n_pages, flags, bh) \ |
| 22 | page_alloc_demand_internal((n_pages), (flags), (bh)) |
| 23 | #define page_alloc_demand(...) \ |
| 24 | _DISPATCH(page_alloc_demand, PP_NARG(__VA_ARGS__))(__VA_ARGS__) |
| 25 | |
| 26 | #define page_free_2(ptr, n_pages) \ |
| 27 | page_free_internal((ptr), (n_pages), ALLOC_BEHAVIOR_NORMAL) |
| 28 | #define page_free_3(ptr, n_pages, bh) page_free_internal((ptr), (n_pages), (bh)) |
| 29 | |
| 30 | #define page_free(...) _DISPATCH(page_free, PP_NARG(__VA_ARGS__))(__VA_ARGS__) |
| 31 | |
| 32 | void *page_alloc_internal(size_t n_pages, enum alloc_flags flags, |
| 33 | enum alloc_behavior bh); |
| 34 | void *page_alloc_demand_internal(size_t n_pages, enum alloc_flags flags, |
| 35 | enum alloc_behavior bh); |
| 36 | void page_free_internal(void *ptr, size_t n_pages, |
| 37 | enum alloc_behavior behavior); |
| 38 | bool page_alloc_vaddr_in_vas(vaddr_t vaddr); |
| 39 | void page_alloc_init(); |
| 40 | |