diff --git a/hypervisor/acpi_parser/acpi_ext.c b/hypervisor/acpi_parser/acpi_ext.c index 764e93bf7..152b8183d 100644 --- a/hypervisor/acpi_parser/acpi_ext.c +++ b/hypervisor/acpi_parser/acpi_ext.c @@ -51,23 +51,6 @@ * When ACRN go FuSa, the platform ACPI data should be fixed and this file is not needed. */ -#define ACPI_SIG_FACS 0x53434146U /* "FACS" */ -#define ACPI_SIG_FADT "FACP" /* Fixed ACPI Description Table */ - -/* FACP field offsets */ -#define OFFSET_FACS_ADDR 36U -#define OFFSET_RESET_REGISTER 116U -#define OFFSET_RESET_VALUE 128U -#define OFFSET_FACS_X_ADDR 132U -#define OFFSET_PM1A_EVT 148U -#define OFFSET_PM1A_CNT 172U - -/* FACS field offsets */ -#define OFFSET_FACS_SIGNATURE 0U -#define OFFSET_FACS_LENGTH 4U -#define OFFSET_WAKE_VECTOR_32 12U -#define OFFSET_WAKE_VECTOR_64 24U - /* get a dword value from given table and its offset */ static inline uint32_t get_acpi_dt_dword(const uint8_t *dt_addr, uint32_t dt_offset) { @@ -80,14 +63,6 @@ static inline uint64_t get_acpi_dt_qword(const uint8_t *dt_addr, uint32_t dt_off return *(uint64_t *)(dt_addr + dt_offset); } -struct packed_gas { - uint8_t space_id; - uint8_t bit_width; - uint8_t bit_offset; - uint8_t access_size; - uint64_t address; -} __attribute__((packed)); - /* get a GAS struct from given table and its offset. * ACPI table stores packed gas, but it is not guaranteed that * struct acpi_generic_address is packed, so do not use memcpy in function. diff --git a/hypervisor/acpi_parser/dmar_parse.c b/hypervisor/acpi_parser/dmar_parse.c index d84e5e249..f3e6150e5 100644 --- a/hypervisor/acpi_parser/dmar_parse.c +++ b/hypervisor/acpi_parser/dmar_parse.c @@ -12,59 +12,12 @@ #include "vtd.h" #include "acpi.h" -#define ACPI_SIG_DMAR "DMAR" - -enum acpi_dmar_type { - ACPI_DMAR_TYPE_HARDWARE_UNIT = 0, - ACPI_DMAR_TYPE_RESERVED_MEMORY = 1, - ACPI_DMAR_TYPE_ROOT_ATS = 2, - ACPI_DMAR_TYPE_HARDWARE_AFFINITY = 3, - ACPI_DMAR_TYPE_NAMESPACE = 4, - ACPI_DMAR_TYPE_RESERVED = 5 -}; - -struct acpi_table_dmar { - /* Common ACPI table header */ - struct acpi_table_header header; - /* Host address Width */ - uint8_t width; - uint8_t flags; - uint8_t reserved[10]; -}; - -/* DMAR subtable header */ -struct acpi_dmar_header { - uint16_t type; - uint16_t length; -}; - -struct acpi_dmar_hardware_unit { - struct acpi_dmar_header header; - uint8_t flags; - uint8_t reserved; - uint16_t segment; - /* register base address */ - uint64_t address; -}; struct find_iter_args { int32_t i; struct acpi_dmar_hardware_unit *res; }; -struct acpi_dmar_pci_path { - uint8_t device; - uint8_t function; -}; - -struct acpi_dmar_device_scope { - uint8_t entry_type; - uint8_t length; - uint16_t reserved; - uint8_t enumeration_id; - uint8_t bus; -}; - typedef int32_t (*dmar_iter_t)(struct acpi_dmar_header*, void*); static int32_t dmar_unit_cnt; diff --git a/hypervisor/boot/acpi_base.c b/hypervisor/boot/acpi_base.c index ca3591b76..54c08ac13 100644 --- a/hypervisor/boot/acpi_base.c +++ b/hypervisor/boot/acpi_base.c @@ -35,85 +35,9 @@ #include #include -#define ACPI_SIG_RSDP "RSD PTR " /* Root System Description Ptr */ -#define ACPI_OEM_ID_SIZE 6 -#define ACPI_SIG_MADT "APIC" /* Multiple APIC Description Table */ -#define RSDP_CHECKSUM_LENGTH 20 -#define ACPI_NAME_SIZE 4U -#define ACPI_MADT_TYPE_LOCAL_APIC 0U -#define ACPI_MADT_TYPE_IOAPIC 1U -#define ACPI_MADT_ENABLED 1U -#define ACPI_OEM_TABLE_ID_SIZE 8 - -struct acpi_table_rsdp { - /* ACPI signature, contains "RSD PTR " */ - char signature[8]; - /* ACPI 1.0 checksum */ - uint8_t checksum; - /* OEM identification */ - char oem_id[ACPI_OEM_ID_SIZE]; - /* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */ - uint8_t revision; - /* 32-bit physical address of the RSDT */ - uint32_t rsdt_physical_address; - /* Table length in bytes, including header (ACPI 2.0+) */ - uint32_t length; - /* 64-bit physical address of the XSDT (ACPI 2.0+) */ - uint64_t xsdt_physical_address; - /* Checksum of entire table (ACPI 2.0+) */ - uint8_t extended_checksum; - /* Reserved, must be zero */ - uint8_t reserved[3]; -}; - -struct acpi_table_rsdt { - /* Common ACPI table header */ - struct acpi_table_header header; - /* Array of pointers to ACPI tables */ - uint32_t table_offset_entry[1]; -} __packed; - -struct acpi_table_xsdt { - /* Common ACPI table header */ - struct acpi_table_header header; - /* Array of pointers to ACPI tables */ - uint64_t table_offset_entry[1]; -} __packed; - -struct acpi_subtable_header { - uint8_t type; - uint8_t length; -}; - -struct acpi_table_madt { - /* Common ACPI table header */ - struct acpi_table_header header; - /* Physical address of local APIC */ - uint32_t address; - uint32_t flags; -}; - -struct acpi_madt_local_apic { - struct acpi_subtable_header header; - /* ACPI processor id */ - uint8_t processor_id; - /* Processor's local APIC id */ - uint8_t id; - uint32_t lapic_flags; -}; - static struct acpi_table_rsdp *acpi_rsdp; -struct acpi_madt_ioapic { - struct acpi_subtable_header header; - /* IOAPIC id */ - uint8_t id; - uint8_t rsvd; - uint32_t addr; - uint32_t gsi_base; -}; -static struct acpi_table_rsdp* -found_rsdp(char *base, int32_t length) +static struct acpi_table_rsdp *found_rsdp(char *base, int32_t length) { struct acpi_table_rsdp *rsdp, *ret = NULL; uint8_t *cp, sum; diff --git a/hypervisor/boot/include/acpi.h b/hypervisor/boot/include/acpi.h index c1786dfb2..584e081fa 100644 --- a/hypervisor/boot/include/acpi.h +++ b/hypervisor/boot/include/acpi.h @@ -9,6 +9,45 @@ #include +#define ACPI_OEM_ID_SIZE 6 + +#define RSDP_CHECKSUM_LENGTH 20 +#define ACPI_NAME_SIZE 4U +#define ACPI_MADT_TYPE_LOCAL_APIC 0U +#define ACPI_MADT_TYPE_IOAPIC 1U +#define ACPI_MADT_ENABLED 1U +#define ACPI_OEM_TABLE_ID_SIZE 8 + + +/* FACP field offsets */ +#define OFFSET_FACS_ADDR 36U +#define OFFSET_RESET_REGISTER 116U +#define OFFSET_RESET_VALUE 128U +#define OFFSET_FACS_X_ADDR 132U +#define OFFSET_PM1A_EVT 148U +#define OFFSET_PM1A_CNT 172U + +/* FACS field offsets */ +#define OFFSET_FACS_SIGNATURE 0U +#define OFFSET_FACS_LENGTH 4U +#define OFFSET_WAKE_VECTOR_32 12U +#define OFFSET_WAKE_VECTOR_64 24U + +#define ACPI_SIG_FADT "FACP" /* Fixed ACPI Description Table */ +#define ACPI_SIG_FACS 0x53434146U /* "FACS" */ +#define ACPI_SIG_RSDP "RSD PTR " /* Root System Description Ptr */ +#define ACPI_SIG_MADT "APIC" /* Multiple APIC Description Table */ +#define ACPI_SIG_DMAR "DMAR" + + +struct packed_gas { + uint8_t space_id; + uint8_t bit_width; + uint8_t bit_offset; + uint8_t access_size; + uint64_t address; +} __attribute__((packed)); + struct acpi_table_header { /* ASCII table signature */ char signature[4]; @@ -30,6 +69,119 @@ struct acpi_table_header { uint32_t asl_compiler_revision; }; +struct acpi_table_rsdp { + /* ACPI signature, contains "RSD PTR " */ + char signature[8]; + /* ACPI 1.0 checksum */ + uint8_t checksum; + /* OEM identification */ + char oem_id[ACPI_OEM_ID_SIZE]; + /* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */ + uint8_t revision; + /* 32-bit physical address of the RSDT */ + uint32_t rsdt_physical_address; + /* Table length in bytes, including header (ACPI 2.0+) */ + uint32_t length; + /* 64-bit physical address of the XSDT (ACPI 2.0+) */ + uint64_t xsdt_physical_address; + /* Checksum of entire table (ACPI 2.0+) */ + uint8_t extended_checksum; + /* Reserved, must be zero */ + uint8_t reserved[3]; +}; + +struct acpi_table_rsdt { + /* Common ACPI table header */ + struct acpi_table_header header; + /* Array of pointers to ACPI tables */ + uint32_t table_offset_entry[1]; +} __packed; + +struct acpi_table_xsdt { + /* Common ACPI table header */ + struct acpi_table_header header; + /* Array of pointers to ACPI tables */ + uint64_t table_offset_entry[1]; +} __packed; + +struct acpi_table_madt { + /* Common ACPI table header */ + struct acpi_table_header header; + /* Physical address of local APIC */ + uint32_t address; + uint32_t flags; +}; + +struct acpi_subtable_header { + uint8_t type; + uint8_t length; +}; + +struct acpi_madt_local_apic { + struct acpi_subtable_header header; + /* ACPI processor id */ + uint8_t processor_id; + /* Processor's local APIC id */ + uint8_t id; + uint32_t lapic_flags; +}; + +struct acpi_madt_ioapic { + struct acpi_subtable_header header; + /* IOAPIC id */ + uint8_t id; + uint8_t rsvd; + uint32_t addr; + uint32_t gsi_base; +}; + +enum acpi_dmar_type { + ACPI_DMAR_TYPE_HARDWARE_UNIT = 0, + ACPI_DMAR_TYPE_RESERVED_MEMORY = 1, + ACPI_DMAR_TYPE_ROOT_ATS = 2, + ACPI_DMAR_TYPE_HARDWARE_AFFINITY = 3, + ACPI_DMAR_TYPE_NAMESPACE = 4, + ACPI_DMAR_TYPE_RESERVED = 5 +}; + +struct acpi_table_dmar { + /* Common ACPI table header */ + struct acpi_table_header header; + /* Host address Width */ + uint8_t width; + uint8_t flags; + uint8_t reserved[10]; +}; + +/* DMAR subtable header */ +struct acpi_dmar_header { + uint16_t type; + uint16_t length; +}; + +struct acpi_dmar_hardware_unit { + struct acpi_dmar_header header; + uint8_t flags; + uint8_t reserved; + uint16_t segment; + /* register base address */ + uint64_t address; +}; + +struct acpi_dmar_pci_path { + uint8_t device; + uint8_t function; +}; + +struct acpi_dmar_device_scope { + uint8_t entry_type; + uint8_t length; + uint16_t reserved; + uint8_t enumeration_id; + uint8_t bus; +}; + + void *get_acpi_tbl(const char *signature); struct ioapic_info;