| 1 | /* @title: Virtual address allocator */ |
| 2 | #pragma once |
| 3 | #include <mem/page.h> |
| 4 | #include <mem/vmm.h> |
| 5 | #include <stdbool.h> |
| 6 | #include <stddef.h> |
| 7 | #include <stdint.h> |
| 8 | #include <types/types.h> |
| 9 | |
| 10 | struct address_range; |
| 11 | struct vas; |
| 12 | struct vas_arena; |
| 13 | |
| 14 | #define VAS_CHUNK_SHIFT 26 |
| 15 | #define VAS_CHUNK_SIZE (1ULL << VAS_CHUNK_SHIFT) |
| 16 | |
| 17 | /* [base, limit) */ |
| 18 | struct vas *vas_bootstrap(vaddr_t base, vaddr_t limit); |
| 19 | struct vas *vas_create(vaddr_t base, vaddr_t limit); |
| 20 | struct vas *vas_from(struct address_range *ar); |
| 21 | struct vas *vas_bootstrap_from(struct address_range *ar); |
| 22 | |
| 23 | /* No touching in interrupts or above DISPATCH */ |
| 24 | vaddr_t vas_alloc(struct vas *vas, size_t size, size_t align); |
| 25 | |
| 26 | /* Giving the wrong size panics. TODO: we only need to pass in addr, |
| 27 | * we can update the APIs for that later on */ |
| 28 | void vas_free(struct vas *vas, vaddr_t addr, size_t size); |
| 29 | |
| 30 | void *vas_map(struct vas *vas, paddr_t paddr, size_t len, uint64_t flags, |
| 31 | enum vmm_flags vflags); |
| 32 | void vas_unmap(struct vas *vas, void *vaddr, size_t len); |
| 33 | |
| 34 | /* Drain cached reservations */ |
| 35 | void vas_reclaim(struct vas *vas); |
| 36 | void vas_reclaim_freelist_pages(struct vas_arena *arena); |
| 37 | |
| 38 | /* TODO: virtual address spaces are NOT refcounted */ |
| 39 | bool vas_destroy(struct vas *vas); |
| 40 | void vas_space_dump(struct vas *vas); |
| 41 | |
| 42 | bool vas_vaddr_in_vas(struct vas *vas, vaddr_t addr); |
| 43 | /* Includes interior byte addresses */ |
| 44 | bool vas_vaddr_is_allocated(struct vas *vas, vaddr_t addr); |
| 45 | |