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