UEFI: create new func named construct_mbi
Cleanup the mass code for constructing multiboot info Signed-off-by: Zheng, Gen <gen.zheng@intel.com>
This commit is contained in:
parent
2bec3b3c73
commit
88b79c901b
|
@ -63,28 +63,19 @@ static inline void hv_jump(EFI_PHYSICAL_ADDRESS hv_start,
|
||||||
hf(MULTIBOOT_INFO_MAGIC, mbi);
|
hf(MULTIBOOT_INFO_MAGIC, mbi);
|
||||||
}
|
}
|
||||||
|
|
||||||
static EFI_STATUS
|
EFI_STATUS
|
||||||
switch_to_guest_mode(EFI_HANDLE image)
|
construct_mbi(struct multiboot_info **mbi_ret, struct efi_ctx *efi_ctx)
|
||||||
{
|
{
|
||||||
UINTN map_size, _map_size, map_key;
|
UINTN map_size, _map_size, map_key;
|
||||||
UINT32 desc_version;
|
UINT32 desc_version;
|
||||||
UINTN desc_size;
|
UINTN desc_size;
|
||||||
EFI_MEMORY_DESCRIPTOR *map_buf;
|
EFI_MEMORY_DESCRIPTOR *map_buf;
|
||||||
EFI_PHYSICAL_ADDRESS addr;
|
EFI_PHYSICAL_ADDRESS addr;
|
||||||
EFI_STATUS err;
|
EFI_STATUS err = EFI_SUCCESS;
|
||||||
struct multiboot_mmap *mmap;
|
|
||||||
struct multiboot_info *mbi;
|
struct multiboot_info *mbi;
|
||||||
struct efi_ctx *efi_ctx;
|
struct multiboot_mmap *mmap;
|
||||||
|
|
||||||
struct acpi_table_rsdp *rsdp = NULL;
|
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
err = emalloc(sizeof(struct efi_ctx), 8, &addr);
|
|
||||||
if (err != EFI_SUCCESS)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
efi_ctx = (struct efi_ctx *)(UINTN)addr;
|
|
||||||
|
|
||||||
/* multiboot info */
|
/* multiboot info */
|
||||||
err = emalloc(16384, 8, &addr);
|
err = emalloc(16384, 8, &addr);
|
||||||
if (err != EFI_SUCCESS)
|
if (err != EFI_SUCCESS)
|
||||||
|
@ -100,28 +91,6 @@ switch_to_guest_mode(EFI_HANDLE image)
|
||||||
mmap = (struct multiboot_mmap *)(UINTN)addr;
|
mmap = (struct multiboot_mmap *)(UINTN)addr;
|
||||||
memset((void *)mmap, 0x0, sizeof(*mmap)*128);
|
memset((void *)mmap, 0x0, sizeof(*mmap)*128);
|
||||||
|
|
||||||
|
|
||||||
EFI_CONFIGURATION_TABLE *config_table = sys_table->ConfigurationTable;
|
|
||||||
for (i = 0; i < sys_table->NumberOfTableEntries;i++) {
|
|
||||||
EFI_GUID acpi_20_table_guid = ACPI_20_TABLE_GUID;
|
|
||||||
EFI_GUID acpi_table_guid = ACPI_TABLE_GUID;
|
|
||||||
if (CompareGuid(&acpi_20_table_guid, &config_table->VendorGuid) == 0) {
|
|
||||||
rsdp = config_table->VendorTable;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (CompareGuid(&acpi_table_guid, &config_table->VendorGuid) == 0)
|
|
||||||
rsdp = config_table->VendorTable;
|
|
||||||
|
|
||||||
config_table++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!rsdp) {
|
|
||||||
Print(L"unable to find RSDP\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* We're just interested in the map's size for now */
|
/* We're just interested in the map's size for now */
|
||||||
map_size = 0;
|
map_size = 0;
|
||||||
err = get_memory_map(&map_size, NULL, NULL, NULL, NULL);
|
err = get_memory_map(&map_size, NULL, NULL, NULL, NULL);
|
||||||
|
@ -199,15 +168,6 @@ again:
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (e820_type == E820_RAM) {
|
|
||||||
UINT64 start = d->PhysicalStart;
|
|
||||||
UINT64 end = d->PhysicalStart
|
|
||||||
+ (d->NumberOfPages<<EFI_PAGE_SHIFT);
|
|
||||||
if (start <= CONFIG_RAM_START && end >
|
|
||||||
(CONFIG_RAM_START + CONFIG_RAM_SIZE))
|
|
||||||
Print(L"e820[%d] start=%lx len=%lx\n", i,
|
|
||||||
d->PhysicalStart, d->NumberOfPages << EFI_PAGE_SHIFT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (j && mmap[j-1].mm_type == e820_type &&
|
if (j && mmap[j-1].mm_type == e820_type &&
|
||||||
(mmap[j-1].mm_base_addr + mmap[j-1].mm_length)
|
(mmap[j-1].mm_base_addr + mmap[j-1].mm_length)
|
||||||
|
@ -246,9 +206,58 @@ again:
|
||||||
mbi->mi_flags |= MULTIBOOT_INFO_HAS_DRIVES;
|
mbi->mi_flags |= MULTIBOOT_INFO_HAS_DRIVES;
|
||||||
mbi->mi_drives_addr = (UINT32)(UINTN)efi_ctx;
|
mbi->mi_drives_addr = (UINT32)(UINTN)efi_ctx;
|
||||||
|
|
||||||
|
*mbi_ret = mbi;
|
||||||
|
out:
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
static EFI_STATUS
|
||||||
|
switch_to_guest_mode(EFI_HANDLE image)
|
||||||
|
{
|
||||||
|
EFI_PHYSICAL_ADDRESS addr;
|
||||||
|
EFI_STATUS err;
|
||||||
|
struct multiboot_info *mbi = NULL;
|
||||||
|
struct efi_ctx *efi_ctx;
|
||||||
|
struct acpi_table_rsdp *rsdp = NULL;
|
||||||
|
int i;
|
||||||
|
EFI_CONFIGURATION_TABLE *config_table;
|
||||||
|
|
||||||
|
err = emalloc(sizeof(struct efi_ctx), 8, &addr);
|
||||||
|
if (err != EFI_SUCCESS)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
efi_ctx = (struct efi_ctx *)(UINTN)addr;
|
||||||
|
|
||||||
|
config_table = sys_table->ConfigurationTable;
|
||||||
|
|
||||||
|
for (i = 0; i < sys_table->NumberOfTableEntries; i++) {
|
||||||
|
EFI_GUID acpi_20_table_guid = ACPI_20_TABLE_GUID;
|
||||||
|
EFI_GUID acpi_table_guid = ACPI_TABLE_GUID;
|
||||||
|
|
||||||
|
if (CompareGuid(&acpi_20_table_guid,
|
||||||
|
&config_table->VendorGuid) == 0) {
|
||||||
|
rsdp = config_table->VendorTable;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CompareGuid(&acpi_table_guid,
|
||||||
|
&config_table->VendorGuid) == 0)
|
||||||
|
rsdp = config_table->VendorTable;
|
||||||
|
|
||||||
|
config_table++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rsdp) {
|
||||||
|
Print(L"unable to find RSDP\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
efi_ctx->rsdp = rsdp;
|
efi_ctx->rsdp = rsdp;
|
||||||
|
|
||||||
//Print(L"start 9!\n");
|
/* construct multiboot info and deliver it to hypervisor */
|
||||||
|
err = construct_mbi(&mbi, efi_ctx);
|
||||||
|
if (err != EFI_SUCCESS)
|
||||||
|
goto out;
|
||||||
|
|
||||||
asm volatile ("mov %%cr0, %0" : "=r"(efi_ctx->cr0));
|
asm volatile ("mov %%cr0, %0" : "=r"(efi_ctx->cr0));
|
||||||
asm volatile ("mov %%cr3, %0" : "=r"(efi_ctx->cr3));
|
asm volatile ("mov %%cr3, %0" : "=r"(efi_ctx->cr3));
|
||||||
|
|
Loading…
Reference in New Issue