diff options
Diffstat (limited to 'mem/zone.h')
-rw-r--r-- | mem/zone.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/mem/zone.h b/mem/zone.h new file mode 100644 index 0000000..7e863bf --- /dev/null +++ b/mem/zone.h @@ -0,0 +1,52 @@ +#ifndef JOVE_MEM_ZONE_H +#define JOVE_MEM_ZONE_H 1 + +#include <stdint.h> +#include "lib/buddymap.h" + +enum { + MEM_ZONE_STANDARD = 0, /* First GiB of physical memory. */ + MEM_ZONE_HIGHER, + MEM_ZONE_COUNT +}; + +#define MEM_ZONE_STANDARD_BASE 0 +#define MEM_ZONE_STANDARD_LIMIT (1 * GiB) +#define MEM_ZONE_HIGHER_BASE MEM_ZONE_STANDARD_LIMIT + +#define MEM_BUDDY_ORDERS 12 +struct PhysicalMemoryZone +{ + const char *name; + + uintptr_t base; + uintptr_t limit; + + size_t npages_total; + size_t npages_free; + + struct BuddyMap freemap; +}; + +/** Using a given zone, reserve a range of physical addresses + * @param zone identifier of zone to modify + * @param base starting address to reserve + * @param limit ending address to reserve*/ +void mem_zone_resv(size_t zone, uintptr_t base, uintptr_t limit); + +/** Using a given zone, free a range of physical addresses + * @param zone identifier of zone to modify + * @param base starting address to free + * @param limit ending address to free*/ +void mem_zone_free(size_t zone, uintptr_t base, uintptr_t limit); + +/** Allocate a number of pages from the given zone + * @param zone identifier of the zone to modify + * @param pages number of pages to allocate + * @return physical memory address of allocation + * zero if allocation failed*/ +uintptr_t mem_zone_alloc(size_t zone, size_t pages); + +void mem_zone_setup_standard(void); + +#endif |