int get_addr_from_mmap(char *id, U32 *addr) { MMapInfo_s mmapInfo; UBOOT_TRACE("IN\n"); if((id==NULL)||(addr==NULL)) { UBOOT_ERROR("One of the parameters is a null pointer\n"); return -1; } UBOOT_DEBUG("id=%s\n",id); if(get_mmap(id,&mmapInfo)!=0) { UBOOT_ERROR("get mmap fail\n"); return -1; } if(mmapInfo.b_is_miu0==0) { UBOOT_DEBUG("In MIU0\n"); *addr=mmapInfo.u32Addr+miu_interval; } else { UBOOT_DEBUG("In MIU1\n"); *addr=mmapInfo.u32Addr; } UBOOT_DEBUG("addr=0x%x\n",*addr); UBOOT_TRACE("OK\n"); return 0; }
void init_buddy() { get_mmap(); print_mmap(); // request memory for page descriptors // requested pages for all memory until the last available address -- because I can dt_size = (find_max_available_address() / PAGE_SIZE) * sizeof(page_descr); descr_table = (page_descr*) boot_allocate(dt_size); // initialize dt page_descr* prev = heads + 0; for(unsigned int i = 0; i < dt_size; ++i) { set_page_descr(descr_table + i, i, PAGE_DESCRIPTOR_RESERVED, 0, prev, NULL); } //initialize heads for(int i = 0; i < MAX_SIZE; ++i) { set_page_descr(heads + i, 0, PAGE_DESCRIPTOR_FICT, i, NULL, NULL); } //initialize actually available descriptors activate_available_mem(); //print_pages(); }
// Test if the get_mmap() function correctly uses the ioctls to obtain the // memory map and its meta data. void test_get_mmap(void) { uint8_t *mmap = NULL; uint8_t *test_mmap = NULL; unsigned int mmap_size = 0; unsigned int mmap_desc_size = 0; assert(init_test_mmap(&test_mmap, kNumMemorySegments, sizeof(EfiMemoryRange), kNumTestPages) == EXIT_SUCCESS); assert(test_mmap != NULL); assert(get_mmap(&mmap, &mmap_size, &mmap_desc_size, MEM_DEV) == EXIT_SUCCESS); assert(mmap_size == kNumMemorySegments * sizeof(EfiMemoryRange)); assert(mmap_desc_size == sizeof(EfiMemoryRange)); assert(mmap != NULL); assert(memcmp(mmap, test_mmap, mmap_size) == 0); // Don't forget cleaning up free(mmap); free(test_mmap); }
int get_length_from_mmap(char *id, U32 *len) { MMapInfo_s mmapInfo; UBOOT_TRACE("IN\n"); if((id==NULL)||(len==NULL)) { UBOOT_ERROR("One of the parameters is a null pointer\n"); return -1; } UBOOT_DEBUG("id=%s\n",id); if(get_mmap(id,&mmapInfo)!=0) { UBOOT_ERROR("get mmap fail\n"); return -1; } *len=mmapInfo.u32Size; UBOOT_DEBUG("len=0x%x\n",*len); UBOOT_TRACE("OK\n"); return 0; }