Skip to content

Commit 88b79c9

Browse files
zhenggenjren1
authored andcommitted
UEFI: create new func named construct_mbi
Cleanup the mass code for constructing multiboot info Signed-off-by: Zheng, Gen <gen.zheng@intel.com>
1 parent 2bec3b3 commit 88b79c9

File tree

1 file changed

+54
-45
lines changed

1 file changed

+54
-45
lines changed

hypervisor/bsp/uefi/efi/boot.c

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,19 @@ static inline void hv_jump(EFI_PHYSICAL_ADDRESS hv_start,
6363
hf(MULTIBOOT_INFO_MAGIC, mbi);
6464
}
6565

66-
static EFI_STATUS
67-
switch_to_guest_mode(EFI_HANDLE image)
66+
EFI_STATUS
67+
construct_mbi(struct multiboot_info **mbi_ret, struct efi_ctx *efi_ctx)
6868
{
6969
UINTN map_size, _map_size, map_key;
7070
UINT32 desc_version;
7171
UINTN desc_size;
7272
EFI_MEMORY_DESCRIPTOR *map_buf;
7373
EFI_PHYSICAL_ADDRESS addr;
74-
EFI_STATUS err;
75-
struct multiboot_mmap *mmap;
74+
EFI_STATUS err = EFI_SUCCESS;
7675
struct multiboot_info *mbi;
77-
struct efi_ctx *efi_ctx;
78-
79-
struct acpi_table_rsdp *rsdp = NULL;
76+
struct multiboot_mmap *mmap;
8077
int i, j;
8178

82-
err = emalloc(sizeof(struct efi_ctx), 8, &addr);
83-
if (err != EFI_SUCCESS)
84-
goto out;
85-
86-
efi_ctx = (struct efi_ctx *)(UINTN)addr;
87-
8879
/* multiboot info */
8980
err = emalloc(16384, 8, &addr);
9081
if (err != EFI_SUCCESS)
@@ -100,28 +91,6 @@ switch_to_guest_mode(EFI_HANDLE image)
10091
mmap = (struct multiboot_mmap *)(UINTN)addr;
10192
memset((void *)mmap, 0x0, sizeof(*mmap)*128);
10293

103-
104-
EFI_CONFIGURATION_TABLE *config_table = sys_table->ConfigurationTable;
105-
for (i = 0; i < sys_table->NumberOfTableEntries;i++) {
106-
EFI_GUID acpi_20_table_guid = ACPI_20_TABLE_GUID;
107-
EFI_GUID acpi_table_guid = ACPI_TABLE_GUID;
108-
if (CompareGuid(&acpi_20_table_guid, &config_table->VendorGuid) == 0) {
109-
rsdp = config_table->VendorTable;
110-
break;
111-
}
112-
113-
if (CompareGuid(&acpi_table_guid, &config_table->VendorGuid) == 0)
114-
rsdp = config_table->VendorTable;
115-
116-
config_table++;
117-
}
118-
119-
if (!rsdp) {
120-
Print(L"unable to find RSDP\n");
121-
goto out;
122-
}
123-
124-
12594
/* We're just interested in the map's size for now */
12695
map_size = 0;
12796
err = get_memory_map(&map_size, NULL, NULL, NULL, NULL);
@@ -199,15 +168,6 @@ switch_to_guest_mode(EFI_HANDLE image)
199168
default:
200169
continue;
201170
}
202-
if (e820_type == E820_RAM) {
203-
UINT64 start = d->PhysicalStart;
204-
UINT64 end = d->PhysicalStart
205-
+ (d->NumberOfPages<<EFI_PAGE_SHIFT);
206-
if (start <= CONFIG_RAM_START && end >
207-
(CONFIG_RAM_START + CONFIG_RAM_SIZE))
208-
Print(L"e820[%d] start=%lx len=%lx\n", i,
209-
d->PhysicalStart, d->NumberOfPages << EFI_PAGE_SHIFT);
210-
}
211171

212172
if (j && mmap[j-1].mm_type == e820_type &&
213173
(mmap[j-1].mm_base_addr + mmap[j-1].mm_length)
@@ -246,9 +206,58 @@ switch_to_guest_mode(EFI_HANDLE image)
246206
mbi->mi_flags |= MULTIBOOT_INFO_HAS_DRIVES;
247207
mbi->mi_drives_addr = (UINT32)(UINTN)efi_ctx;
248208

209+
*mbi_ret = mbi;
210+
out:
211+
return err;
212+
}
213+
214+
static EFI_STATUS
215+
switch_to_guest_mode(EFI_HANDLE image)
216+
{
217+
EFI_PHYSICAL_ADDRESS addr;
218+
EFI_STATUS err;
219+
struct multiboot_info *mbi = NULL;
220+
struct efi_ctx *efi_ctx;
221+
struct acpi_table_rsdp *rsdp = NULL;
222+
int i;
223+
EFI_CONFIGURATION_TABLE *config_table;
224+
225+
err = emalloc(sizeof(struct efi_ctx), 8, &addr);
226+
if (err != EFI_SUCCESS)
227+
goto out;
228+
229+
efi_ctx = (struct efi_ctx *)(UINTN)addr;
230+
231+
config_table = sys_table->ConfigurationTable;
232+
233+
for (i = 0; i < sys_table->NumberOfTableEntries; i++) {
234+
EFI_GUID acpi_20_table_guid = ACPI_20_TABLE_GUID;
235+
EFI_GUID acpi_table_guid = ACPI_TABLE_GUID;
236+
237+
if (CompareGuid(&acpi_20_table_guid,
238+
&config_table->VendorGuid) == 0) {
239+
rsdp = config_table->VendorTable;
240+
break;
241+
}
242+
243+
if (CompareGuid(&acpi_table_guid,
244+
&config_table->VendorGuid) == 0)
245+
rsdp = config_table->VendorTable;
246+
247+
config_table++;
248+
}
249+
250+
if (!rsdp) {
251+
Print(L"unable to find RSDP\n");
252+
goto out;
253+
}
254+
249255
efi_ctx->rsdp = rsdp;
250256

251-
//Print(L"start 9!\n");
257+
/* construct multiboot info and deliver it to hypervisor */
258+
err = construct_mbi(&mbi, efi_ctx);
259+
if (err != EFI_SUCCESS)
260+
goto out;
252261

253262
asm volatile ("mov %%cr0, %0" : "=r"(efi_ctx->cr0));
254263
asm volatile ("mov %%cr3, %0" : "=r"(efi_ctx->cr3));

0 commit comments

Comments
 (0)