1
0

Consolidate physical page frame declaration from all archs

This commit is contained in:
2013-01-01 23:54:19 -05:00
parent 1c75a68815
commit b51f8f8422
3 changed files with 76 additions and 125 deletions

View File

@ -23,6 +23,8 @@
#include <print.h>
#include <types.h>
#include <arch/properties.h>
struct dlist_node free_frames_list;
void frames_init() {
@ -143,3 +145,52 @@ int put_free_frames(struct frame *f) {
}
return 1;
}
static inline int mmu_region_contains(void *lower_a, void *upper_a, void *lower_b, void *upper_b) {
return lower_b >= lower_a && upper_b <= upper_a;
}
static inline int mmu_region_contains_single(void *lower_a, void *upper_a, void *ptr) {
return lower_a <= ptr && ptr <= upper_a;
}
#define page_round_down(ptr) (((uint32)ptr) & ~(CONFIG_INIT_PAGE_SIZE-1))
#define page_round_up(ptr) (((((uint32)ptr) & ~1) + (CONFIG_INIT_PAGE_SIZE-1) ) & ~(CONFIG_INIT_PAGE_SIZE-1))
/* Called once per physical memory region by bootup code. This function is
* responsible for only adding (via add_physical_memory()) those parts of the
* memory region which are still available (i.e. aren't in the kernel and
* haven't been remapped anywhere else. */
void declare_memory_region(void *lower, void *upper) {
void *k_section_start_phys = (void *)page_round_down(kernel_start_physical());
void *k_section_end_phys = (void *)(page_round_up(kernel_end_physical()) - 1);
void *k_section_start_virt = (void *)page_round_down(kernel_start_virtual());
void *k_section_end_virt = (void *)(page_round_up(kernel_end_virtual()) - 1);
if (upper - lower < 1) {
print("Warning: declare_memory_region() called with lower=%x, upper=%x. Ignoring.\n", lower, upper);
return;
}
if (mmu_region_contains(lower, upper, k_section_start_phys, k_section_end_phys)) {
//Don't map any of the physical kernel's memory
declare_memory_region(lower, (void *) ((char *)k_section_start_phys - 1));
declare_memory_region((void *) ((char *)k_section_end_phys + 1), upper);
add_physical_memory(kernel_end_virtual(), k_section_end_virt);
} else if (mmu_region_contains(lower, upper, k_section_start_virt, k_section_end_virt)) {
declare_memory_region(lower, (void *) ((char *)k_section_start_virt - 1));
declare_memory_region((void *) ((char *)k_section_end_virt + 1), upper);
} else if (mmu_region_contains_single(lower, upper, k_section_start_phys)) {
if ((void*)((char*)lower + 1) < k_section_start_phys)
declare_memory_region(lower, (void *) ((char *)k_section_start_phys - 1));
} else if (mmu_region_contains_single(lower, upper, k_section_end_phys)) {
if (k_section_end_phys < (void*)((char*)upper - 1))
declare_memory_region((void *) ((char *)k_section_end_phys + 1), upper);
} else if (mmu_region_contains_single(lower, upper, k_section_start_virt)) {
if ((void*)((char*)lower + 1) < k_section_start_virt)
declare_memory_region(lower, (void *) ((char *)k_section_start_virt - 1));
} else if (mmu_region_contains_single(lower, upper, k_section_end_virt)) {
if (k_section_end_virt < (void*)((char*)upper - 1))
declare_memory_region((void *) ((char *)k_section_end_virt + 1), upper);
} else {
add_physical_memory(lower, upper);
}
}