HV: refine acpi rsdp initialize interface

In previous code, the rsdp initialization is done in get_rsdp() api implicitly.
The function is called multiple times in following acpi table parsing functions
and the condition (rsdp == NULL) need to be added in each parsing function.
This is not needed since the panic would occur if rsdp is NULL when do acpi
initialization.

Tracked-On: #5626

Signed-off-by: Victor Sun <victor.sun@intel.com>
Reviewed-by: Jason Chen CJ <jason.cj.chen@intel.com>
This commit is contained in:
Victor Sun 2021-02-24 11:08:50 +08:00 committed by wenlingz
parent 59de88d6bc
commit ff1f6bc975
3 changed files with 47 additions and 57 deletions

View File

@ -148,6 +148,7 @@ void init_pcpu_pre(bool is_bsp)
early_init_lapic(); early_init_lapic();
init_acpi();
#ifdef CONFIG_ACPI_PARSE_ENABLED #ifdef CONFIG_ACPI_PARSE_ENABLED
ret = acpi_fixup(); ret = acpi_fixup();
if (ret != 0) { if (ret != 0) {

View File

@ -63,53 +63,50 @@ static struct acpi_table_rsdp *found_rsdp(char *base, uint64_t length)
* If it is NULL, the hypervisor can't be booted * If it is NULL, the hypervisor can't be booted
*/ */
static struct acpi_table_rsdp *get_rsdp(void) static struct acpi_table_rsdp *get_rsdp(void)
{
return acpi_rsdp;
}
void init_acpi(void)
{ {
struct acpi_table_rsdp *rsdp = NULL; struct acpi_table_rsdp *rsdp = NULL;
/* If acpi_rsdp is already parsed, it will be returned directly */ rsdp = (struct acpi_table_rsdp *)(get_acrn_multiboot_info()->mi_acpi_rsdp_va);
if (acpi_rsdp != NULL) { if (rsdp == NULL) {
rsdp = acpi_rsdp; uint16_t *addr;
} else {
rsdp = (struct acpi_table_rsdp *)(get_acrn_multiboot_info()->mi_acpi_rsdp_va);
if (rsdp == NULL) {
uint16_t *addr;
/* EBDA is addressed by the 16 bit pointer at 0x40E */ /* EBDA is addressed by the 16 bit pointer at 0x40E */
addr = (uint16_t *)hpa2hva(0x40eUL); addr = (uint16_t *)hpa2hva(0x40eUL);
rsdp = found_rsdp((char *)hpa2hva((uint64_t)(*addr) << 4U), 0x400UL); rsdp = found_rsdp((char *)hpa2hva((uint64_t)(*addr) << 4U), 0x400UL);
} }
if (rsdp == NULL) { if (rsdp == NULL) {
/* Check the upper memory BIOS space, 0xe0000 - 0xfffff. */ /* Check the upper memory BIOS space, 0xe0000 - 0xfffff. */
rsdp = found_rsdp((char *)hpa2hva(0xe0000UL), 0x20000UL); rsdp = found_rsdp((char *)hpa2hva(0xe0000UL), 0x20000UL);
} }
if (rsdp == NULL) { if (rsdp == NULL) {
/* Check ACPI RECLAIM region, there might be multiple ACPI reclaimable regions. */ /* Check ACPI RECLAIM region, there might be multiple ACPI reclaimable regions. */
uint32_t i; uint32_t i;
const struct e820_entry *entry = get_e820_entry(); const struct e820_entry *entry = get_e820_entry();
uint32_t entries_count = get_e820_entries_count(); uint32_t entries_count = get_e820_entries_count();
for (i = 0U; i < entries_count; i++) { for (i = 0U; i < entries_count; i++) {
if (entry[i].type == E820_TYPE_ACPI_RECLAIM) { if (entry[i].type == E820_TYPE_ACPI_RECLAIM) {
rsdp = found_rsdp((char *)hpa2hva(entry[i].baseaddr), entry[i].length); rsdp = found_rsdp((char *)hpa2hva(entry[i].baseaddr), entry[i].length);
if (rsdp != NULL) { if (rsdp != NULL) {
break; break;
}
} }
} }
} }
if (rsdp == NULL) {
panic("No RSDP is found");
}
/* After RSDP is parsed, it will be assigned to acpi_rsdp */
acpi_rsdp = rsdp;
} }
if (rsdp == NULL) {
panic("No RSDP is found");
}
return rsdp; /* After RSDP is parsed, it will be assigned to acpi_rsdp */
acpi_rsdp = rsdp;
} }
static bool probe_table(uint64_t address, const char *signature) static bool probe_table(uint64_t address, const char *signature)
@ -213,15 +210,10 @@ local_parse_madt(struct acpi_table_madt *madt, uint32_t lapic_id_array[MAX_PCPU_
uint16_t parse_madt(uint32_t lapic_id_array[MAX_PCPU_NUM]) uint16_t parse_madt(uint32_t lapic_id_array[MAX_PCPU_NUM])
{ {
uint16_t ret = 0U; uint16_t ret = 0U;
struct acpi_table_rsdp *rsdp = NULL; struct acpi_table_madt *madt = (struct acpi_table_madt *)get_acpi_tbl(ACPI_SIG_MADT);
rsdp = get_rsdp(); if (madt != NULL) {
if (rsdp != NULL) { ret = local_parse_madt(madt, lapic_id_array);
struct acpi_table_madt *madt = (struct acpi_table_madt *)get_acpi_tbl(ACPI_SIG_MADT);
if (madt != NULL) {
ret = local_parse_madt(madt, lapic_id_array);
}
} }
return ret; return ret;
@ -232,25 +224,21 @@ uint8_t parse_madt_ioapic(struct ioapic_info *ioapic_id_array)
uint8_t ioapic_idx = 0U; uint8_t ioapic_idx = 0U;
uint64_t entry, end; uint64_t entry, end;
const struct acpi_madt_ioapic *ioapic; const struct acpi_madt_ioapic *ioapic;
const struct acpi_table_madt *madt; const struct acpi_table_madt *madt = (const struct acpi_table_madt *)get_acpi_tbl(ACPI_SIG_MADT);
if (get_rsdp() != NULL) { if (madt != NULL) {
madt = (const struct acpi_table_madt *)get_acpi_tbl(ACPI_SIG_MADT); end = (uint64_t)madt + madt->header.length;
if (madt != NULL) { for (entry = (uint64_t)(madt + 1); entry < end; entry += ioapic->header.length) {
end = (uint64_t)madt + madt->header.length; ioapic = (const struct acpi_madt_ioapic *)entry;
for (entry = (uint64_t)(madt + 1); entry < end; entry += ioapic->header.length) { if (ioapic->header.type == ACPI_MADT_TYPE_IOAPIC) {
ioapic = (const struct acpi_madt_ioapic *)entry; if (ioapic_idx < CONFIG_MAX_IOAPIC_NUM) {
ioapic_id_array[ioapic_idx].id = ioapic->id;
if (ioapic->header.type == ACPI_MADT_TYPE_IOAPIC) { ioapic_id_array[ioapic_idx].addr = ioapic->addr;
if (ioapic_idx < CONFIG_MAX_IOAPIC_NUM) { ioapic_id_array[ioapic_idx].gsi_base = ioapic->gsi_base;
ioapic_id_array[ioapic_idx].id = ioapic->id;
ioapic_id_array[ioapic_idx].addr = ioapic->addr;
ioapic_id_array[ioapic_idx].gsi_base = ioapic->gsi_base;
}
ioapic_idx++;
} }
ioapic_idx++;
} }
} }
} }

View File

@ -236,6 +236,7 @@ struct acpi_table_tpm2 {
uint32_t start_method; uint32_t start_method;
} __packed; } __packed;
void init_acpi(void);
void *get_acpi_tbl(const char *signature); void *get_acpi_tbl(const char *signature);
struct ioapic_info; struct ioapic_info;