#ifndef JOVE_MEM_ZONE_H #define JOVE_MEM_ZONE_H 1 #include #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; struct BuddyMap freemap; }; /**Return the zone index for the given address * @param addr address to look up * @return zone index*/ int mem_zone_for(uintptr_t addr); /**Return the lower bound for the given zone index. * @param zone index into zones. * @return lower bound.*/ uintptr_t mem_zone_bound_lower(size_t zone); /**Return the upper bound for the given zone index. * @param zone index into zones. * @return upper bound.*/ uintptr_t mem_zone_bound_upper(size_t zone); /**Return the number of pages free in the given zone. * @param zone index into zones. * @return number of free pages.*/ size_t mem_zone_pages_free(size_t zone); /** 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 * @return error code or 0 if success */ int 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 * @return error code or 0 if success*/ int 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