static int __valloc_init(spdid_t spdid) { int ret = -1; struct spd_vas_tracker *trac; struct spd_vas_occupied *occ; struct cos_component_information *ci; unsigned long page_off; void *hp; if (cos_vect_lookup(&spd_vect, spdid)) goto success; trac = malloc(sizeof(struct spd_vas_tracker)); if (!trac) goto done; occ = alloc_page(); if (!occ) goto err_free1; ci = cos_get_vas_page(); if (cinfo_map(cos_spd_id(), (vaddr_t)ci, spdid)) goto err_free2; hp = (void*)ci->cos_heap_ptr; // printc("valloc init heap_ptr: %x\n", (unsigned int) hp); trac->spdid = spdid; trac->ci = ci; trac->map = occ; trac->extents[0].start = (void*)round_to_pgd_page(hp); trac->extents[0].end = (void*)round_up_to_pgd_page(hp); page_off = ((unsigned long)hp - (unsigned long)round_to_pgd_page(hp))/PAGE_SIZE; bitmap_set_contig(&occ->pgd_occupied[0], page_off, (PGD_SIZE/PAGE_SIZE)-page_off, 1); cos_vect_add_id(&spd_vect, trac, spdid); assert(cos_vect_lookup(&spd_vect, spdid)); success: // printc("valloc init success\n"); ret = 0; done: return ret; err_free2: cos_release_vas_page(ci); free_page(occ); err_free1: free(trac); goto done; }
static int __valloc_init(spdid_t spdid) { int ret = -1; struct spd_vas_tracker *trac; struct spd_vas_occupied *occ; unsigned long page_off; void *hp; if (cos_vect_lookup(&spd_vect, spdid)) goto success; trac = malloc(sizeof(struct spd_vas_tracker)); if (!trac) goto done; occ = alloc_page(); if (!occ) goto err_free1; hp = cinfo_get_heap_pointer(cos_spd_id(), spdid); if (!hp) goto err_free2; trac->spdid = spdid; trac->map = occ; trac->extents[0].start = (void*)round_to_pgd_page(hp); trac->extents[0].end = (void*)round_up_to_pgd_page(hp); trac->extents[0].map = occ; page_off = ((unsigned long)hp - (unsigned long)round_to_pgd_page(hp))/PAGE_SIZE; bitmap_set_contig(&occ->pgd_occupied[0], page_off, (PGD_SIZE/PAGE_SIZE)-page_off, 1); bitmap_set_contig(&occ->pgd_occupied[0], 0, page_off, 0); cos_vect_add_id(&spd_vect, trac, spdid); assert(cos_vect_lookup(&spd_vect, spdid)); success: ret = 0; done: return ret; err_free2: free_page(occ); err_free1: free(trac); goto done; }
int kern_setup_image(void) { unsigned long i, j; paddr_t kern_pa_start, kern_pa_end; printk("\tSetting up initial page directory.\n"); kern_pa_start = round_to_pgd_page(chal_va2pa(mem_kern_start())); /* likely 0 */ kern_pa_end = chal_va2pa(mem_kmem_end()); /* ASSUMPTION: The static layout of boot_comp_pgd is identical to a pgd post-pgtbl_alloc */ /* FIXME: should use pgtbl_extend instead of directly accessing the pgd array... */ for (i = kern_pa_start, j = COS_MEM_KERN_START_VA/PGD_RANGE ; i < (unsigned long)round_up_to_pgd_page(kern_pa_end) ; i += PGD_RANGE, j++) { assert(j != KERN_INIT_PGD_IDX || ((boot_comp_pgd[j] | PGTBL_GLOBAL) & ~(PGTBL_MODIFIED | PGTBL_ACCESSED)) == (i | PGTBL_PRESENT | PGTBL_WRITABLE | PGTBL_SUPER | PGTBL_GLOBAL)); boot_comp_pgd[j] = i | PGTBL_PRESENT | PGTBL_WRITABLE | PGTBL_SUPER | PGTBL_GLOBAL; boot_comp_pgd[i/PGD_RANGE] = 0; /* unmap lower addresses */ } /* FIXME: Ugly hack to get the physical page with the ACPI RSDT mapped */ printk("ACPI initialization\n"); void *rsdt = acpi_find_rsdt(); if (rsdt) { u32_t page = round_up_to_pgd_page(rsdt) - (1 << 22); boot_comp_pgd[j] = page | PGTBL_PRESENT | PGTBL_WRITABLE | PGTBL_SUPER | PGTBL_GLOBAL; acpi_set_rsdt_page(j); j++; u64_t hpet = timer_find_hpet(acpi_find_timer()); if (hpet) { page = round_up_to_pgd_page(hpet & 0xffffffff) - (1 << 22); boot_comp_pgd[j] = page | PGTBL_PRESENT | PGTBL_WRITABLE | PGTBL_SUPER | PGTBL_GLOBAL; timer_set_hpet_page(j); j++; } } for ( ; j < PAGE_SIZE/sizeof(unsigned int) ; i += PGD_RANGE, j++) { boot_comp_pgd[j] = boot_comp_pgd[i/PGD_RANGE] = 0; } chal_cpu_init(); chal_cpu_pgtbl_activate((pgtbl_t)chal_va2pa(boot_comp_pgd)); kern_retype_initial(); return 0; }
void *valloc_alloc(spdid_t spdid, spdid_t dest, unsigned long npages) { /* JWW print out a few things : spdid, heap ptr, make sure the heap ptr is sane */ void *ret = NULL; struct spd_vas_tracker *trac; struct spd_vas_occupied *occ; long off; /*JWW REMOVE THIS */ struct cos_component_information *ci; unsigned long page_off; void *hp; /* /JWW */ LOCK(); /*JWW REMOVE THIS */ ci = cos_get_vas_page(); if (cinfo_map(cos_spd_id(), (vaddr_t)ci, spdid)) { // error cos_release_vas_page(ci); printc("CINFO_MAP ERROR\n"); } hp = (void*)ci->cos_heap_ptr; // now print some things out. // printc("valloc alloc heap_ptr: %x, ucap_tbl: %x, npages: %ul \n", (unsigned int) hp, (unsigned int) ci->cos_user_caps, npages); /* /JWW */ page_off = ((unsigned long)hp - (unsigned long)round_to_pgd_page(hp))/PAGE_SIZE; trac = cos_vect_lookup(&spd_vect, dest); if (!trac) { printc("valloc init being called\n"); if (__valloc_init(dest) || !(trac = cos_vect_lookup(&spd_vect, dest))) goto done; } // printc("valloc alloc past init\n"); occ = trac->map; assert(occ); // off = bitmap_extent_find_set(&occ->pgd_occupied[0], page_off, npages, MAP_MAX); off = bitmap_extent_find_set(&occ->pgd_occupied[0], 0, npages, MAP_MAX); if (off < 0) goto done; ret = ((char *)trac->extents[0].start) + (off * PAGE_SIZE); done: // printc("valloc alloc returning %x\n", (unsigned int) ret); UNLOCK(); return ret; }