|
| 1 | +/* |
| 2 | + * Copyright (C) 2019 Intel Corporation. All rights reserved. |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: BSD-3-Clause |
| 5 | + */ |
| 6 | + |
| 7 | +#include <vm.h> |
| 8 | +#include <per_cpu.h> |
| 9 | +#include <vacpi.h> |
| 10 | +#include <pgtable.h> |
| 11 | + |
| 12 | +/* ACPI tables for pre-launched VM and SOS */ |
| 13 | +static struct acpi_table_info acpi_table_template[CONFIG_MAX_VM_NUM] = { |
| 14 | + [0U ... (CONFIG_MAX_VM_NUM - 1U)] = { |
| 15 | + .rsdp = { |
| 16 | + .signature = ACPI_SIG_RSDP, |
| 17 | + .oem_id = ACPI_OEM_ID, |
| 18 | + .revision = 0x2U, |
| 19 | + .length = ACPI_RSDP_XCHECKSUM_LENGTH, |
| 20 | + .xsdt_physical_address = ACPI_XSDT_ADDR, |
| 21 | + }, |
| 22 | + .xsdt = { |
| 23 | + /* Currently XSDT table only pointers to 1 ACPI table entry (MADT) */ |
| 24 | + .header.length = sizeof(struct acpi_table_header) + sizeof(uint64_t), |
| 25 | + |
| 26 | + .header.revision = 0x1U, |
| 27 | + .header.oem_revision = 0x1U, |
| 28 | + .header.asl_compiler_revision = ACPI_ASL_COMPILER_VERSION, |
| 29 | + .header.signature = ACPI_SIG_XSDT, |
| 30 | + .header.oem_id = ACPI_OEM_ID, |
| 31 | + .header.oem_table_id = "ACRNXSDT", |
| 32 | + .header.asl_compiler_id = ACPI_ASL_COMPILER_ID, |
| 33 | + |
| 34 | + .table_offset_entry[0] = ACPI_MADT_ADDR, |
| 35 | + }, |
| 36 | + .madt = { |
| 37 | + .header.revision = 0x3U, |
| 38 | + .header.oem_revision = 0x1U, |
| 39 | + .header.asl_compiler_revision = ACPI_ASL_COMPILER_VERSION, |
| 40 | + .header.signature = ACPI_SIG_MADT, |
| 41 | + .header.oem_id = ACPI_OEM_ID, |
| 42 | + .header.oem_table_id = "ACRNMADT", |
| 43 | + .header.asl_compiler_id = ACPI_ASL_COMPILER_ID, |
| 44 | + |
| 45 | + .address = 0xFEE00000U, /* Local APIC Address */ |
| 46 | + .flags = 0x1U, /* PC-AT Compatibility=1 */ |
| 47 | + }, |
| 48 | + .lapic_nmi = { |
| 49 | + .header.type = ACPI_MADT_TYPE_LOCAL_APIC_NMI, |
| 50 | + .header.length = sizeof(struct acpi_madt_local_apic_nmi), |
| 51 | + .processor_id = 0xFFU, |
| 52 | + .flags = 0x5U, |
| 53 | + .lint = 0x1U, |
| 54 | + }, |
| 55 | + .lapic_array = { |
| 56 | + [0U ... (CONFIG_MAX_PCPU_NUM - 1U)] = { |
| 57 | + .header.type = ACPI_MADT_TYPE_LOCAL_APIC, |
| 58 | + .header.length = sizeof(struct acpi_madt_local_apic), |
| 59 | + .lapic_flags = 0x1U, /* Processor Enabled=1, Runtime Online Capable=0 */ |
| 60 | + } |
| 61 | + }, |
| 62 | + } |
| 63 | +}; |
| 64 | + |
| 65 | +/** |
| 66 | + * @pre vm != NULL |
| 67 | + * @pre vm->vm_id < CONFIG_MAX_VM_NUM |
| 68 | + */ |
| 69 | +void build_vacpi(struct acrn_vm *vm) |
| 70 | +{ |
| 71 | + struct acpi_table_rsdp *rsdp; |
| 72 | + struct acpi_table_xsdt *xsdt; |
| 73 | + struct acpi_table_madt *madt; |
| 74 | + struct acpi_madt_local_apic *lapic; |
| 75 | + uint16_t i; |
| 76 | + |
| 77 | + rsdp = &acpi_table_template[vm->vm_id].rsdp; |
| 78 | + rsdp->checksum = calculate_checksum8(rsdp, ACPI_RSDP_CHECKSUM_LENGTH); |
| 79 | + rsdp->extended_checksum = calculate_checksum8(rsdp, ACPI_RSDP_XCHECKSUM_LENGTH); |
| 80 | + /* Copy RSDP table to guest physical memory */ |
| 81 | + (void)copy_to_gpa(vm, rsdp, ACPI_RSDP_ADDR, ACPI_RSDP_XCHECKSUM_LENGTH); |
| 82 | + |
| 83 | + xsdt = &acpi_table_template[vm->vm_id].xsdt; |
| 84 | + xsdt->header.checksum = calculate_checksum8(xsdt, xsdt->header.length); |
| 85 | + /* Copy XSDT table to guest physical memory */ |
| 86 | + (void)copy_to_gpa(vm, xsdt, ACPI_XSDT_ADDR, xsdt->header.length); |
| 87 | + |
| 88 | + /* Fix up MADT LAPIC subtables */ |
| 89 | + for (i = 0U; i < vm->hw.created_vcpus; i++) { |
| 90 | + lapic = &acpi_table_template[vm->vm_id].lapic_array[i]; |
| 91 | + lapic->processor_id = (uint8_t)i; |
| 92 | + lapic->id = (uint8_t)i; |
| 93 | + } |
| 94 | + |
| 95 | + madt = &acpi_table_template[vm->vm_id].madt; |
| 96 | + madt->header.length = sizeof(struct acpi_table_madt) |
| 97 | + + sizeof(struct acpi_madt_local_apic_nmi) |
| 98 | + + (sizeof(struct acpi_madt_local_apic) * (size_t)vm->hw.created_vcpus); |
| 99 | + madt->header.checksum = calculate_checksum8(madt, madt->header.length); |
| 100 | + |
| 101 | + /* Copy MADT table and its subtables to guest physical memory */ |
| 102 | + (void)copy_to_gpa(vm, madt, ACPI_MADT_ADDR, madt->header.length); |
| 103 | +} |
0 commit comments