Skip to content

Commit 1f3acb3

Browse files
zhenggenjren1
authored andcommitted
UEFI: bug fix on delivering RSDP
With current code, memcpy rsdp to 0x500 maybe overwrite uefi code/data region. So remove the legacy BIOS deliver method of RSDP, which need copy the RSDP to EBDA space which is addressed by the 16bit pointer at 0x40E or upper memory BIOS space 0xe0000-0xfffff. And just deliver the pointer of RSDP, which is already saved in UEFI system table, to hypervisor. Create a function named efi_init() to separate efi initialize code. Signed-off-by: Zheng, Gen <gen.zheng@intel.com>
1 parent 8d67f29 commit 1f3acb3

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

hypervisor/boot/acpi.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#include <hv_arch.h>
3636
#include <hv_debug.h>
3737
#include "acpi.h"
38+
#ifdef CONFIG_EFI_STUB
39+
#include <acrn_efi.h>
40+
#endif
3841

3942
#define ACPI_SIG_RSDP "RSD PTR " /* Root System Description Ptr */
4043
#define ACPI_OEM_ID_SIZE 6
@@ -140,6 +143,12 @@ static void *get_rsdp(void)
140143
struct acpi_table_rsdp *rsdp = NULL;
141144
uint16_t *addr;
142145

146+
#ifdef CONFIG_EFI_STUB
147+
rsdp = get_rsdp_from_uefi();
148+
if (rsdp)
149+
return rsdp;
150+
#endif
151+
143152
/* EBDA is addressed by the 16 bit pointer at 0x40E */
144153
addr = (uint16_t *)0x40E;
145154

hypervisor/bsp/uefi/efi/boot.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@
4141
#define ERROR_STRING_LENGTH 32
4242
#define EFI_LOADER_SIGNATURE "EL64"
4343

44-
#define LEAGCY_BIOS
45-
4644
#define ACPI_XSDT_ENTRY_SIZE (sizeof (UINT64))
4745
#define ACPI_NAME_SIZE 4
4846
#define ACPI_OEM_ID_SIZE 6
@@ -448,11 +446,8 @@ load_sos_image(EFI_HANDLE image, CHAR16 *name, CHAR16 *cmdline)
448446
mbi->mi_cmdline = (UINTN)"uart=disabled";
449447
mbi->mi_mmap_addr = (UINTN)mmap;
450448

451-
#ifdef LEAGCY_BIOS
452-
/* copy rsdt in low memory space(0~0x1000) for hypervisor parsing */
453-
memcpy((void *)0x500, (void*)rsdp, sizeof(struct acpi_table_rsdp));
454-
*(UINT16*)(0x40E) = 0x50;
455-
#endif
449+
pe->rsdp = rsdp;
450+
456451
//Print(L"start 9!\n");
457452

458453
asm volatile ("mov %%cr0, %0":"=r"(pe->cr0));

hypervisor/bsp/uefi/efi/boot.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ struct e820_entry {
7676
struct efi_ctx {
7777
EFI_IMAGE_ENTRY_POINT entry;
7878
EFI_HANDLE handle;
79-
EFI_SYSTEM_TABLE* table;
79+
EFI_SYSTEM_TABLE *table;
80+
VOID *rsdp;
8081
dt_addr_t gdt;
8182
dt_addr_t idt;
8283
uint16_t tr_sel;

hypervisor/bsp/uefi/uefi.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,15 @@
5353
#define UEFI_PCI_IRQ_ASSIGNMENT_NUM 28
5454

5555
#ifdef CONFIG_EFI_STUB
56+
static void efi_init(void);
57+
5658
uint32_t efi_physical_available_ap_bitmap = 0;
5759
uint32_t efi_wake_up_ap_bitmap = 0;
5860
struct efi_ctx* efi_ctx = NULL;
5961
struct lapic_regs uefi_lapic_regs;
6062
extern uint32_t up_count;
6163
extern unsigned long pcpu_sync;
64+
static int efi_initialized;
6265

6366
void efi_spurious_handler(int vector)
6467
{
@@ -144,20 +147,36 @@ int uefi_sw_loader(struct vm *vm, struct vcpu *vcpu)
144147

145148
return ret;
146149
}
147-
#endif
148150

149-
void init_bsp(void)
151+
void *get_rsdp_from_uefi(void)
150152
{
151-
parse_hv_cmdline();
153+
if (!efi_initialized)
154+
efi_init();
152155

153-
#ifdef CONFIG_EFI_STUB
154-
efi_ctx = (struct efi_ctx*)(uint64_t)boot_regs[2];
156+
return efi_ctx->rsdp;
157+
}
158+
159+
static void efi_init(void)
160+
{
161+
efi_ctx = (struct efi_ctx *)(uint64_t)(uint32_t)boot_regs[2];
155162
ASSERT(efi_ctx != NULL, "");
156163

157164
vm_sw_loader = uefi_sw_loader;
158165

159166
spurious_handler = efi_spurious_handler;
160167

161168
save_lapic(&uefi_lapic_regs);
169+
170+
efi_initialized = 1;
171+
}
172+
#endif
173+
174+
void init_bsp(void)
175+
{
176+
parse_hv_cmdline();
177+
178+
#ifdef CONFIG_EFI_STUB
179+
if (!efi_initialized)
180+
efi_init();
162181
#endif
163182
}

hypervisor/include/common/acrn_efi.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ typedef struct {
3737
} __attribute__((packed)) dt_addr_t;
3838

3939
struct efi_ctx {
40-
void* entry;
41-
void* handle;
42-
void* table;
40+
void *entry;
41+
void *handle;
42+
void *table;
43+
void *rsdp;
4344
dt_addr_t gdt;
4445
dt_addr_t idt;
4546
uint16_t tr_sel;
@@ -59,4 +60,6 @@ struct efi_ctx {
5960
uint64_t efer;
6061
}__attribute__((packed));
6162

63+
void *get_rsdp_from_uefi(void);
64+
6265
#endif /* UEFI_H*/

0 commit comments

Comments
 (0)