/* mark the physical pages backing a range of virtual as in use. * allocate the physical pages and throw them away */ static void mark_pages_in_use(vaddr_t va, size_t len) { LTRACEF("va 0x%lx, len 0x%zx\n", va, len); struct list_node list; list_initialize(&list); /* make sure we are inclusive of all of the pages in the address range */ len = PAGE_ALIGN(len + (va & (PAGE_SIZE - 1))); va = ROUNDDOWN(va, PAGE_SIZE); LTRACEF("aligned va 0x%lx, len 0x%zx\n", va, len); for (size_t offset = 0; offset < len; offset += PAGE_SIZE) { uint flags; paddr_t pa; status_t err = arch_mmu_query(va + offset, &pa, &flags); if (err >= 0) { //LTRACEF("va 0x%x, pa 0x%x, flags 0x%x, err %d\n", va + offset, pa, flags, err); /* alloate the range, throw the results away */ pmm_alloc_range(pa, 1, &list); } else { panic("Could not find pa for va 0x%lx\n", va); } } }
void platform_early_init(void) { /* initialize the interrupt controller */ arm_gic_init(); arm_generic_timer_init(ARM_GENERIC_TIMER_PHYSICAL_INT, 0); uart_init_early(); /* look for a flattened device tree just before the kernel */ const void *fdt = (void *)KERNEL_BASE; int err = fdt_check_header(fdt); if (err >= 0) { /* walk the nodes, looking for 'memory' */ int depth = 0; int offset = 0; for (;;) { offset = fdt_next_node(fdt, offset, &depth); if (offset < 0) break; /* get the name */ const char *name = fdt_get_name(fdt, offset, NULL); if (!name) continue; /* look for the 'memory' property */ if (strcmp(name, "memory") == 0) { int lenp; const void *prop_ptr = fdt_getprop(fdt, offset, "reg", &lenp); if (prop_ptr && lenp == 0x10) { /* we're looking at a memory descriptor */ //uint64_t base = fdt64_to_cpu(*(uint64_t *)prop_ptr); uint64_t len = fdt64_to_cpu(*((const uint64_t *)prop_ptr + 1)); /* trim size on certain platforms */ #if ARCH_ARM if (len > 1024*1024*1024U) { len = 1024*1024*1024; /* only use the first 1GB on ARM32 */ printf("trimming memory to 1GB\n"); } #endif /* set the size in the pmm arena */ arena.size = len; } } } } /* add the main memory arena */ pmm_add_arena(&arena); /* reserve the first 64k of ram, which should be holding the fdt */ struct list_node list = LIST_INITIAL_VALUE(list); pmm_alloc_range(MEMBASE, 0x10000 / PAGE_SIZE, &list); }