/* Following functions- ikgt_malloc() and ikgt_free() have been extended to * use mon_page_alloc() and mon_page_free() as a temporary solution for * allocation of more than 2040 bytes using page alignment of buffer for * differentiating between mon_malloc allocation() and mon_page_alloc() */ API uint64_t *ikgt_malloc(IN uint32_t size) { uint64_t *buf = NULL; uint32_t num_pages = 0; if (0 == size) { MON_LOG(mask_plugin, level_trace, "%s: size must be greater than 0.\n", __FUNCTION__); return NULL; } /* Internal function requirement. Max block is 2048 bytes, * including 8 byte mem_allocation_info_t structure. */ if (size <= IKGT_MALLOC_MAX_SIZE) { buf = mon_malloc(size); } else { /* If size is more than 2040 bytes, then find number of pages * needed and use mon_page_alloc */ MON_LOG(mask_plugin, level_info, "%s: Using mon_page_alloc\n", __FUNCTION__); num_pages = PAGE_ROUNDUP(size); buf = mon_page_alloc(num_pages); } return buf; }
boolean_t e820_abstraction_create_new_map(OUT e820_handle_t *handle) { int15_e820_memory_map_t *e820_map = (int15_e820_memory_map_t *)mon_page_alloc(1); if (e820_map == NULL) { return FALSE; } e820_map->memory_map_size = 0; *handle = (e820_handle_t)e820_map; return TRUE; }
int get_e820_table_from_sfi(xmon_desc_t *td, uint64_t *e820_addr) { #define SYST 0x54535953 #define MMAP 0x50414d4d int15_e820_memory_map_t *e820; int15_e820_memory_map_entry_ext_t *blk; uint32_t table; uint32_t size; sfi_mem_dsc_t *dsc; int cnt; int r; int i; r = find_sfi_table(0xe0000, 0xfffff, 16, 0, SYST, &table, &size); if (r != 0) { return -1; } r = find_sfi_table(table, table + size - 1, 8, 1, MMAP, &table, &size); if (r != 0) { return -1; } dsc = (sfi_mem_dsc_t *)table; cnt = size / sizeof(sfi_mem_dsc_t); e820 = (int15_e820_memory_map_t *)mon_page_alloc(1); if (e820 == NULL) { return -1; } blk = e820->memory_map_entry; for (i = 0; i < cnt; i++) { blk[i].basic_entry.base_address = dsc[i].paddr; blk[i].basic_entry.length = dsc[i].pages * 0x1000; blk[i].basic_entry.address_range_type = sfi_e820_type(dsc[i].type); blk[i].extended_attributes.bits.enabled = 1; } e820->memory_map_size = cnt * sizeof(*blk); *e820_addr = (uint64_t)(uint32_t)e820; return 0; }
int copy_e820_table_from_efi(xmon_desc_t *td, uint64_t *e820_addr) { mon_guest_cpu_startup_state_t *s; int15_e820_memory_map_t *e820; void *inf; s = (mon_guest_cpu_startup_state_t *)GUEST1_BASE(td); inf = (void *)((uint32_t)(s->gp.reg[IA32_REG_RBX])); e820 = (int15_e820_memory_map_t *)mon_page_alloc(1); if (e820 == NULL) { return -1; } mon_memcpy(e820, inf, 4096); *e820_addr = (uint64_t)(uint32_t)e820; return 0; }
int get_e820_table_from_multiboot(xmon_desc_t *td, uint64_t *e820_addr) { mon_guest_cpu_startup_state_t *s; int15_e820_memory_map_t *e820; uint32_t start; uint32_t next; uint32_t end; multiboot_info_t *inf; int i; s = (mon_guest_cpu_startup_state_t *)GUEST1_BASE(td); inf = (multiboot_info_t *)((uint32_t)(s->gp.reg[IA32_REG_RBX])); if (((inf->flags & 0x00000003) == 0) || (inf->mmap_length > 4096)) { return -1; } e820 = (int15_e820_memory_map_t *)mon_page_alloc(1); if (e820 == NULL) { return -1; } start = inf->mmap_addr; end = inf->mmap_addr + inf->mmap_length; i = 0; for (next = start; next < end; next += ((multiboot_memory_map_t *)next)->size + 4) { multiboot_memory_map_t *map = (multiboot_memory_map_t *)next; e820->memory_map_entry[i].basic_entry.base_address = map->addr; e820->memory_map_entry[i].basic_entry.length = map->len; e820->memory_map_entry[i].basic_entry.address_range_type = map->type; e820->memory_map_entry[i].extended_attributes.uint32 = 1; i++; } e820->memory_map_size = i * sizeof(int15_e820_memory_map_entry_ext_t); *e820_addr = (uint64_t)(uint32_t)e820; return 0; }