|
1 | 1 | #ifndef UKO_OS_KERNEL__MM_VIRTUAL_ALLOC_H |
2 | 2 | #define UKO_OS_KERNEL__MM_VIRTUAL_ALLOC_H 1 |
3 | 3 |
|
4 | | -#include <types.h> |
| 4 | +#include <list.h> |
5 | 5 |
|
6 | 6 | /** |
7 | | - * Flags about a link of the free list. |
| 7 | + * A virtual memory area. This struct represents a region of either free or |
| 8 | + * allocated memory, with page granularity or greater. |
8 | 9 | */ |
9 | | -enum virtual_buddy_free_list_flags : u16 { |
10 | | - /** |
11 | | - * This link was allocated in static memory as part of bootstrapping the |
12 | | - * allocator, and should not be freed. |
13 | | - */ |
14 | | - VIRTUAL_BUDDY_FREE_LIST_BOOTSTRAP = 1 << 0, |
15 | | -}; |
| 10 | +struct vma; |
16 | 11 |
|
17 | 12 | /** |
18 | | - * A link in the free list for the buddy allocator for virtual address space. |
19 | | - * These are heap-allocated. |
| 13 | + * An instance of the virtual memory allocator. |
20 | 14 | */ |
21 | | -struct virtual_buddy_free_list { |
22 | | - /** |
23 | | - * The next link in the list. |
24 | | - */ |
25 | | - struct virtual_buddy_free_list *next; |
26 | | - |
27 | | - /** |
28 | | - * Flags about this link. |
29 | | - */ |
30 | | - enum virtual_buddy_free_list_flags flags : 12; |
31 | | - |
32 | | - /** |
33 | | - * The high bits of the address of the allocatable block of memory. |
34 | | - */ |
35 | | - uptr addr_hi_bits : (sizeof(uptr) * 8) - 12; |
36 | | -}; |
37 | | - |
38 | | -static_assert(sizeof(struct virtual_buddy_free_list) == 2 * sizeof(uptr)); |
39 | | -static_assert(alignof(struct virtual_buddy_free_list) == alignof(uptr)); |
40 | | - |
41 | | -/** |
42 | | - * A buddy allocator for a 26-bit space. If pages are the leaves, this covers |
43 | | - * 256GiB, i.e. either the lower or upper half of Sv39 (and still a convenient |
44 | | - * size on x86_64, or on ARMv8-A with a 4KiB granule). |
45 | | - */ |
46 | | -struct virtual_buddy { |
47 | | - /** |
48 | | - * The range of virtual addresses this allocator covers. |
49 | | - */ |
50 | | - uaddr start, end; |
51 | | - |
52 | | - /** |
53 | | - * The free lists. |
54 | | - */ |
55 | | - struct virtual_buddy_free_list *free_lists[27]; |
56 | | - |
57 | | - /** |
58 | | - * The bitmap. |
59 | | - */ |
60 | | - u8 bitmap[1 << 25]; |
61 | | -}; |
| 15 | +struct vma_alloc; |
62 | 16 |
|
63 | 17 | /** |
64 | | - * The kernel's virtual memory allocator. |
| 18 | + * Creates a new instance of the virtual memory allocator, set to cover the |
| 19 | + * given address range. |
65 | 20 | */ |
66 | | -extern struct virtual_buddy *const mm_kernel_virtual_buddy; |
| 21 | +struct vma_alloc *vma_alloc_new(uaddr lo, uaddr hi); |
67 | 22 |
|
68 | 23 | /** |
69 | | - * Sets up `mm_kernel_virtual_buddy`. |
| 24 | + * Prints the VMA allocator's state, for debugging purposes. |
70 | 25 | */ |
71 | | -void mm_init_virtual(uptr free_va_start, uptr free_va_end); |
| 26 | +void vma_alloc_print(struct vma_alloc *vma_alloc); |
72 | 27 |
|
73 | 28 | /** |
74 | 29 | * Allocates a range of virtual address space from the given allocator. |
|
0 commit comments