| 1 | #ifndef MM__PMM_H__ |
| 2 | #define MM__PMM_H__ |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | #include <stddef.h> |
| 6 | #include <stdbool.h> |
| 7 | |
| 8 | struct memmap_entry { |
| 9 | uint64_t base; |
| 10 | uint64_t length; |
| 11 | uint32_t type; |
| 12 | uint32_t unused; |
| 13 | }; |
| 14 | |
| 15 | #define MEMMAP_USABLE 1 |
| 16 | #define MEMMAP_RESERVED 2 |
| 17 | #define MEMMAP_ACPI_RECLAIMABLE 3 |
| 18 | #define MEMMAP_ACPI_NVS 4 |
| 19 | #define MEMMAP_BAD_MEMORY 5 |
| 20 | #define MEMMAP_BOOTLOADER_RECLAIMABLE 0x1000 |
| 21 | #define MEMMAP_KERNEL_AND_MODULES 0x1001 |
| 22 | #define MEMMAP_FRAMEBUFFER 0x1002 |
| 23 | #define MEMMAP_RESERVED_MAPPED 0x1003 |
| 24 | #define MEMMAP_EFI_RECLAIMABLE 0x2000 |
| 25 | |
| 26 | struct meminfo { |
| 27 | size_t uppermem; |
| 28 | size_t lowermem; |
| 29 | }; |
| 30 | |
| 31 | struct meminfo mmap_get_info(size_t mmap_count, struct memmap_entry *mmap); |
| 32 | |
| 33 | #if defined (BIOS) |
| 34 | extern struct memmap_entry memmap[]; |
| 35 | extern size_t memmap_entries; |
| 36 | #endif |
| 37 | |
| 38 | #if defined (UEFI) |
| 39 | extern struct memmap_entry *memmap; |
| 40 | extern size_t memmap_entries; |
| 41 | |
| 42 | extern struct memmap_entry *untouched_memmap; |
| 43 | extern size_t untouched_memmap_entries; |
| 44 | #endif |
| 45 | |
| 46 | extern bool allocations_disallowed; |
| 47 | |
| 48 | void init_memmap(void); |
| 49 | struct memmap_entry *get_memmap(size_t *entries); |
| 50 | struct memmap_entry *get_raw_memmap(size_t *entry_count); |
| 51 | void print_memmap(struct memmap_entry *mm, size_t size); |
| 52 | uint64_t pmm_check_type(uint64_t addr); |
| 53 | bool memmap_alloc_range_in(struct memmap_entry *m, size_t *_count, |
| 54 | uint64_t base, uint64_t length, uint32_t type, uint32_t overlay_type, bool do_panic, bool simulation, bool new_entry); |
| 55 | bool memmap_alloc_range(uint64_t base, uint64_t length, uint32_t type, uint32_t overlay_type, bool panic, bool simulation, bool new_entry); |
| 56 | void pmm_randomise_memory(void); |
| 57 | |
| 58 | void *ext_mem_alloc_size_t(size_t count); |
| 59 | void *ext_mem_alloc(uint64_t count); |
| 60 | void *ext_mem_alloc_counted(uint64_t count, uint64_t elem_size); |
| 61 | void *ext_mem_alloc_type(uint64_t count, uint32_t type); |
| 62 | void *ext_mem_alloc_type_aligned(uint64_t count, uint32_t type, size_t alignment); |
| 63 | void *ext_mem_alloc_type_aligned_mode(uint64_t count, uint32_t type, size_t alignment, bool allow_high_allocs); |
| 64 | |
| 65 | void *conv_mem_alloc(uint64_t count); |
| 66 | |
| 67 | void pmm_free_size_t(void *ptr, size_t length); |
| 68 | void pmm_free(void *ptr, uint64_t length); |
| 69 | void *pmm_realloc(void *old_ptr, uint64_t old_size, uint64_t new_size); |
| 70 | |
| 71 | #if defined (UEFI) |
| 72 | void pmm_release_uefi_mem(void); |
| 73 | #endif |
| 74 | |
| 75 | bool check_usable_memory(uint64_t base, uint64_t top); |
| 76 | void pmm_sanitise_entries(struct memmap_entry *m, size_t *_count, bool align_entries); |
| 77 | |
| 78 | extern bool pmm_sanitiser_keep_first_page; |
| 79 | |
| 80 | #endif |