summaryrefslogtreecommitdiffstats
path: root/hw/i386/acpi-build.c
diff options
context:
space:
mode:
Diffstat (limited to 'hw/i386/acpi-build.c')
-rw-r--r--hw/i386/acpi-build.c70
1 files changed, 44 insertions, 26 deletions
diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 7ecfd7004b..c98df88cd2 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -52,7 +52,7 @@
#include "qom/qom-qobject.h"
typedef struct AcpiCpuInfo {
- DECLARE_BITMAP(found_cpus, MAX_CPUMASK_BITS + 1);
+ DECLARE_BITMAP(found_cpus, ACPI_CPU_HOTPLUG_ID_LIMIT);
} AcpiCpuInfo;
typedef struct AcpiMcfgInfo {
@@ -117,7 +117,7 @@ int acpi_add_cpu_info(Object *o, void *opaque)
if (object_dynamic_cast(o, TYPE_CPU)) {
apic_id = object_property_get_int(o, "apic-id", NULL);
- assert(apic_id <= MAX_CPUMASK_BITS);
+ assert(apic_id < ACPI_CPU_HOTPLUG_ID_LIMIT);
set_bit(apic_id, cpu->found_cpus);
}
@@ -226,14 +226,14 @@ static void acpi_get_pci_info(PcPciInfo *info)
static void
build_header(GArray *linker, GArray *table_data,
- AcpiTableHeader *h, uint32_t sig, int len, uint8_t rev)
+ AcpiTableHeader *h, const char *sig, int len, uint8_t rev)
{
- h->signature = cpu_to_le32(sig);
+ memcpy(&h->signature, sig, 4);
h->length = cpu_to_le32(len);
h->revision = rev;
memcpy(h->oem_id, ACPI_BUILD_APPNAME6, 6);
memcpy(h->oem_table_id, ACPI_BUILD_APPNAME4, 4);
- memcpy(h->oem_table_id + 4, (void *)&sig, 4);
+ memcpy(h->oem_table_id + 4, sig, 4);
h->oem_revision = cpu_to_le32(1);
memcpy(h->asl_compiler_id, ACPI_BUILD_APPNAME4, 4);
h->asl_compiler_revision = cpu_to_le32(1);
@@ -391,7 +391,7 @@ static void build_append_int(GArray *table, uint32_t value)
build_append_byte(table, 0x01); /* OneOp */
} else if (value <= 0xFF) {
build_append_value(table, value, 1);
- } else if (value <= 0xFFFFF) {
+ } else if (value <= 0xFFFF) {
build_append_value(table, value, 2);
} else {
build_append_value(table, value, 4);
@@ -495,7 +495,7 @@ static void
build_facs(GArray *table_data, GArray *linker, PcGuestInfo *guest_info)
{
AcpiFacsDescriptorRev1 *facs = acpi_data_push(table_data, sizeof *facs);
- facs->signature = cpu_to_le32(ACPI_FACS_SIGNATURE);
+ memcpy(&facs->signature, "FACS", 4);
facs->length = cpu_to_le32(sizeof(*facs));
}
@@ -552,7 +552,7 @@ build_fadt(GArray *table_data, GArray *linker, AcpiPmInfo *pm,
fadt_setup(fadt, pm);
build_header(linker, table_data,
- (void *)fadt, ACPI_FACP_SIGNATURE, sizeof(*fadt), 1);
+ (void *)fadt, "FACP", sizeof(*fadt), 1);
}
static void
@@ -621,7 +621,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
local_nmi->lint = 1; /* ACPI_LINT1 */
build_header(linker, table_data,
- (void *)(table_data->data + madt_start), ACPI_APIC_SIGNATURE,
+ (void *)(table_data->data + madt_start), "APIC",
table_data->len - madt_start, 1);
}
@@ -841,7 +841,7 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
pc = PCI_DEVICE_GET_CLASS(pdev);
dc = DEVICE_GET_CLASS(pdev);
- if (pc->class_id == PCI_CLASS_BRIDGE_ISA) {
+ if (pc->class_id == PCI_CLASS_BRIDGE_ISA || pc->is_bridge) {
set_bit(slot, slot_device_system);
}
@@ -882,7 +882,7 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
memcpy(pcihp, ACPI_PCIVGA_AML, ACPI_PCIVGA_SIZEOF);
patch_pcivga(i, pcihp);
} else if (system) {
- /* Nothing to do: system devices are in DSDT. */
+ /* Nothing to do: system devices are in DSDT or in SSDT above. */
} else if (present) {
void *pcihp = acpi_data_push(bus_table,
ACPI_PCINOHP_SIZEOF);
@@ -907,7 +907,7 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
build_append_byte(notify, 0x7B); /* AndOp */
build_append_byte(notify, 0x68); /* Arg0Op */
- build_append_int(notify, 0x1 << i);
+ build_append_int(notify, 0x1U << i);
build_append_byte(notify, 0x00); /* NullName */
build_append_byte(notify, 0x86); /* NotifyOp */
build_append_nameseg(notify, "S%.02X_", PCI_DEVFN(i, 0));
@@ -999,11 +999,16 @@ build_ssdt(GArray *table_data, GArray *linker,
AcpiCpuInfo *cpu, AcpiPmInfo *pm, AcpiMiscInfo *misc,
PcPciInfo *pci, PcGuestInfo *guest_info)
{
- int acpi_cpus = MIN(0xff, guest_info->apic_id_limit);
+ unsigned acpi_cpus = guest_info->apic_id_limit;
int ssdt_start = table_data->len;
uint8_t *ssdt_ptr;
int i;
+ /* The current AML generator can cover the APIC ID range [0..255],
+ * inclusive, for VCPU hotplug. */
+ QEMU_BUILD_BUG_ON(ACPI_CPU_HOTPLUG_ID_LIMIT > 256);
+ g_assert(acpi_cpus <= ACPI_CPU_HOTPLUG_ID_LIMIT);
+
/* Copy header and patch values in the S3_ / S4_ / S5_ packages */
ssdt_ptr = acpi_data_push(table_data, sizeof(ssdp_misc_aml));
memcpy(ssdt_ptr, ssdp_misc_aml, sizeof(ssdp_misc_aml));
@@ -1019,8 +1024,8 @@ build_ssdt(GArray *table_data, GArray *linker,
patch_pci_windows(pci, ssdt_ptr, sizeof(ssdp_misc_aml));
- *(uint16_t *)(ssdt_ptr + *ssdt_isa_pest) =
- cpu_to_le16(misc->pvpanic_port);
+ ACPI_BUILD_SET_LE(ssdt_ptr, sizeof(ssdp_misc_aml),
+ ssdt_isa_pest[0], 16, misc->pvpanic_port);
{
GArray *sb_scope = build_alloc_array();
@@ -1050,9 +1055,21 @@ build_ssdt(GArray *table_data, GArray *linker,
{
GArray *package = build_alloc_array();
- uint8_t op = 0x12; /* PackageOp */
+ uint8_t op;
+
+ /*
+ * Note: The ability to create variable-sized packages was first introduced in ACPI 2.0. ACPI 1.0 only
+ * allowed fixed-size packages with up to 255 elements.
+ * Windows guests up to win2k8 fail when VarPackageOp is used.
+ */
+ if (acpi_cpus <= 255) {
+ op = 0x12; /* PackageOp */
+ build_append_byte(package, acpi_cpus); /* NumElements */
+ } else {
+ op = 0x13; /* VarPackageOp */
+ build_append_int(package, acpi_cpus); /* VarNumElements */
+ }
- build_append_byte(package, acpi_cpus); /* NumElements */
for (i = 0; i < acpi_cpus; i++) {
uint8_t b = test_bit(i, cpu->found_cpus) ? 0x01 : 0x00;
build_append_byte(package, b);
@@ -1093,7 +1110,7 @@ build_ssdt(GArray *table_data, GArray *linker,
build_header(linker, table_data,
(void *)(table_data->data + ssdt_start),
- ACPI_SSDT_SIGNATURE, table_data->len - ssdt_start, 1);
+ "SSDT", table_data->len - ssdt_start, 1);
}
static void
@@ -1108,7 +1125,7 @@ build_hpet(GArray *table_data, GArray *linker)
hpet->timer_block_id = cpu_to_le32(0x8086a201);
hpet->addr.address = cpu_to_le64(HPET_BASE);
build_header(linker, table_data,
- (void *)hpet, ACPI_HPET_SIGNATURE, sizeof(*hpet), 1);
+ (void *)hpet, "HPET", sizeof(*hpet), 1);
}
static void
@@ -1200,7 +1217,7 @@ build_srat(GArray *table_data, GArray *linker,
build_header(linker, table_data,
(void *)(table_data->data + srat_start),
- ACPI_SRAT_SIGNATURE,
+ "SRAT",
table_data->len - srat_start, 1);
}
@@ -1208,7 +1225,7 @@ static void
build_mcfg_q35(GArray *table_data, GArray *linker, AcpiMcfgInfo *info)
{
AcpiTableMcfg *mcfg;
- uint32_t sig;
+ const char *sig;
int len = sizeof(*mcfg) + 1 * sizeof(mcfg->allocation[0]);
mcfg = acpi_data_push(table_data, len);
@@ -1225,9 +1242,10 @@ build_mcfg_q35(GArray *table_data, GArray *linker, AcpiMcfgInfo *info)
* ACPI spec requires OSPMs to ignore such tables.
*/
if (info->mcfg_base == PCIE_BASE_ADDR_UNMAPPED) {
- sig = ACPI_RSRV_SIGNATURE;
+ /* Reserved signature: ignored by OSPM */
+ sig = "QEMU";
} else {
- sig = ACPI_MCFG_SIGNATURE;
+ sig = "MCFG";
}
build_header(linker, table_data, (void *)mcfg, sig, len, 1);
}
@@ -1243,7 +1261,7 @@ build_dsdt(GArray *table_data, GArray *linker, AcpiMiscInfo *misc)
memcpy(dsdt, misc->dsdt_code, misc->dsdt_size);
memset(dsdt, 0, sizeof *dsdt);
- build_header(linker, table_data, dsdt, ACPI_DSDT_SIGNATURE,
+ build_header(linker, table_data, dsdt, "DSDT",
misc->dsdt_size, 1);
}
@@ -1268,7 +1286,7 @@ build_rsdt(GArray *table_data, GArray *linker, GArray *table_offsets)
sizeof(uint32_t));
}
build_header(linker, table_data,
- (void *)rsdt, ACPI_RSDT_SIGNATURE, rsdt_len, 1);
+ (void *)rsdt, "RSDT", rsdt_len, 1);
}
static GArray *
@@ -1279,7 +1297,7 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt)
bios_linker_loader_alloc(linker, ACPI_BUILD_RSDP_FILE, 1,
true /* fseg memory */);
- rsdp->signature = cpu_to_le64(ACPI_RSDP_SIGNATURE);
+ memcpy(&rsdp->signature, "RSD PTR ", 8);
memcpy(rsdp->oem_id, ACPI_BUILD_APPNAME6, 6);
rsdp->rsdt_physical_address = cpu_to_le32(rsdt);
/* Address to be filled by Guest linker */