Skip to content

Commit 274f9a3

Browse files
committed
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
pc,pci,virtio: features, fixes A huge acpi refactoring. Fixes, cleanups all over the place. Signed-off-by: Michael S. Tsirkin <[email protected]> # gpg: Signature made Tue 05 Oct 2021 02:31:11 PM PDT # gpg: using RSA key 5D09FD0871C8F85B94CA8A0D281F0DB8D28D5469 # gpg: issuer "[email protected]" # gpg: Good signature from "Michael S. Tsirkin <[email protected]>" [full] # gpg: aka "Michael S. Tsirkin <[email protected]>" [full] * remotes/mst/tags/for_upstream: (47 commits) hw/i386/amd_iommu: Add description/category to TYPE_AMD_IOMMU_PCI hw/i386/amd_iommu: Rename SysBus specific functions as amdvi_sysbus_X() hw/i386/amd_iommu: Rename amdviPCI TypeInfo nvdimm: release the correct device list virtio-balloon: Fix page-poison subsection name bios-tables-test: Update ACPI DSDT table golden blobs for q35 hw/i386/acpi: fix conflicting IO address range for acpi pci hotplug in q35 bios-tables-test: allow changes in DSDT ACPI tables for q35 acpi: AcpiGenericAddress no longer used to map/access fields of MMIO, drop packed attribute acpi: remove no longer used build_header() acpi: build_facs: use build_append_int_noprefix() API to compose table acpi: arm/virt: build_gtdt: use acpi_table_begin()/acpi_table_end() instead of build_header() acpi: arm/virt: build_spcr: use acpi_table_begin()/acpi_table_end() instead of build_header() acpi: arm/virt: build_spcr: fix invalid cast acpi: arm/virt: convert build_iort() to endian agnostic build_append_FOO() API acpi: arm: virt: build_iort: use acpi_table_begin()/acpi_table_end() instead of build_header() acpi: arm: virt: build_dsdt: use acpi_table_begin()/acpi_table_end() instead of build_header() acpi: build_dsdt_microvm: use acpi_table_begin()/acpi_table_end() instead of build_header() acpi: arm/virt: madt: use build_append_int_noprefix() API to compose MADT table acpi: x86: madt: use build_append_int_noprefix() API to compose MADT table ... Signed-off-by: Richard Henderson <[email protected]>
2 parents 08a9b68 + 64bc656 commit 274f9a3

37 files changed

+892
-1212
lines changed

hw/acpi/acpi-x86-stub.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include "hw/i386/acpi-build.h"
44

55
void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid,
6-
const CPUArchIdList *apic_ids, GArray *entry)
6+
const CPUArchIdList *apic_ids, GArray *entry,
7+
bool force_enabled)
78
{
89
}
910

hw/acpi/aml-build.c

Lines changed: 123 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,19 @@ static void build_append_byte(GArray *array, uint8_t val)
5252
g_array_append_val(array, val);
5353
}
5454

55+
static void build_append_padded_str(GArray *array, const char *str,
56+
size_t maxlen, char pad)
57+
{
58+
size_t i;
59+
size_t len = strlen(str);
60+
61+
g_assert(len <= maxlen);
62+
g_array_append_vals(array, str, len);
63+
for (i = maxlen - len; i > 0; i--) {
64+
g_array_append_val(array, pad);
65+
}
66+
}
67+
5568
static void build_append_array(GArray *array, GArray *val)
5669
{
5770
g_array_append_vals(array, val->data, val->len);
@@ -1692,27 +1705,53 @@ Aml *aml_object_type(Aml *object)
16921705
return var;
16931706
}
16941707

1695-
void
1696-
build_header(BIOSLinker *linker, GArray *table_data,
1697-
AcpiTableHeader *h, const char *sig, int len, uint8_t rev,
1698-
const char *oem_id, const char *oem_table_id)
1699-
{
1700-
unsigned tbl_offset = (char *)h - table_data->data;
1701-
unsigned checksum_offset = (char *)&h->checksum - table_data->data;
1702-
memcpy(&h->signature, sig, 4);
1703-
h->length = cpu_to_le32(len);
1704-
h->revision = rev;
1705-
1706-
strpadcpy((char *)h->oem_id, sizeof h->oem_id, oem_id, ' ');
1707-
strpadcpy((char *)h->oem_table_id, sizeof h->oem_table_id,
1708-
oem_table_id, ' ');
1709-
1710-
h->oem_revision = cpu_to_le32(1);
1711-
memcpy(h->asl_compiler_id, ACPI_BUILD_APPNAME8, 4);
1712-
h->asl_compiler_revision = cpu_to_le32(1);
1713-
/* Checksum to be filled in by Guest linker */
1708+
void acpi_table_begin(AcpiTable *desc, GArray *array)
1709+
{
1710+
1711+
desc->array = array;
1712+
desc->table_offset = array->len;
1713+
1714+
/*
1715+
* ACPI spec 1.0b
1716+
* 5.2.3 System Description Table Header
1717+
*/
1718+
g_assert(strlen(desc->sig) == 4);
1719+
g_array_append_vals(array, desc->sig, 4); /* Signature */
1720+
/*
1721+
* reserve space for Length field, which will be patched by
1722+
* acpi_table_end() when the table creation is finished.
1723+
*/
1724+
build_append_int_noprefix(array, 0, 4); /* Length */
1725+
build_append_int_noprefix(array, desc->rev, 1); /* Revision */
1726+
build_append_int_noprefix(array, 0, 1); /* Checksum */
1727+
build_append_padded_str(array, desc->oem_id, 6, ' '); /* OEMID */
1728+
/* OEM Table ID */
1729+
build_append_padded_str(array, desc->oem_table_id, 8, ' ');
1730+
build_append_int_noprefix(array, 1, 4); /* OEM Revision */
1731+
g_array_append_vals(array, ACPI_BUILD_APPNAME8, 4); /* Creator ID */
1732+
build_append_int_noprefix(array, 1, 4); /* Creator Revision */
1733+
}
1734+
1735+
void acpi_table_end(BIOSLinker *linker, AcpiTable *desc)
1736+
{
1737+
/*
1738+
* ACPI spec 1.0b
1739+
* 5.2.3 System Description Table Header
1740+
* Table 5-2 DESCRIPTION_HEADER Fields
1741+
*/
1742+
const unsigned checksum_offset = 9;
1743+
uint32_t table_len = desc->array->len - desc->table_offset;
1744+
uint32_t table_len_le = cpu_to_le32(table_len);
1745+
gchar *len_ptr = &desc->array->data[desc->table_offset + 4];
1746+
1747+
/* patch "Length" field that has been reserved by acpi_table_begin()
1748+
* to the actual length, i.e. accumulated table length from
1749+
* acpi_table_begin() till acpi_table_end()
1750+
*/
1751+
memcpy(len_ptr, &table_len_le, sizeof table_len_le);
1752+
17141753
bios_linker_loader_add_checksum(linker, ACPI_BUILD_TABLE_FILE,
1715-
tbl_offset, len, checksum_offset);
1754+
desc->table_offset, table_len, desc->table_offset + checksum_offset);
17161755
}
17171756

17181757
void *acpi_data_push(GArray *table_data, unsigned size)
@@ -1822,73 +1861,81 @@ build_rsdp(GArray *tbl, BIOSLinker *linker, AcpiRsdpData *rsdp_data)
18221861
32);
18231862
}
18241863

1825-
/* Build rsdt table */
1864+
/*
1865+
* ACPI 1.0 Root System Description Table (RSDT)
1866+
*/
18261867
void
18271868
build_rsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
18281869
const char *oem_id, const char *oem_table_id)
18291870
{
18301871
int i;
1831-
unsigned rsdt_entries_offset;
1832-
AcpiRsdtDescriptorRev1 *rsdt;
1833-
int rsdt_start = table_data->len;
1834-
const unsigned table_data_len = (sizeof(uint32_t) * table_offsets->len);
1835-
const unsigned rsdt_entry_size = sizeof(rsdt->table_offset_entry[0]);
1836-
const size_t rsdt_len = sizeof(*rsdt) + table_data_len;
1837-
1838-
rsdt = acpi_data_push(table_data, rsdt_len);
1839-
rsdt_entries_offset = (char *)rsdt->table_offset_entry - table_data->data;
1872+
AcpiTable table = { .sig = "RSDT", .rev = 1,
1873+
.oem_id = oem_id, .oem_table_id = oem_table_id };
1874+
1875+
acpi_table_begin(&table, table_data);
18401876
for (i = 0; i < table_offsets->len; ++i) {
18411877
uint32_t ref_tbl_offset = g_array_index(table_offsets, uint32_t, i);
1842-
uint32_t rsdt_entry_offset = rsdt_entries_offset + rsdt_entry_size * i;
1878+
uint32_t rsdt_entry_offset = table.array->len;
18431879

1844-
/* rsdt->table_offset_entry to be filled by Guest linker */
1880+
/* reserve space for entry */
1881+
build_append_int_noprefix(table.array, 0, 4);
1882+
1883+
/* mark position of RSDT entry to be filled by Guest linker */
18451884
bios_linker_loader_add_pointer(linker,
1846-
ACPI_BUILD_TABLE_FILE, rsdt_entry_offset, rsdt_entry_size,
1885+
ACPI_BUILD_TABLE_FILE, rsdt_entry_offset, 4,
18471886
ACPI_BUILD_TABLE_FILE, ref_tbl_offset);
1887+
18481888
}
1849-
build_header(linker, table_data,
1850-
(void *)(table_data->data + rsdt_start),
1851-
"RSDT", rsdt_len, 1, oem_id, oem_table_id);
1889+
acpi_table_end(linker, &table);
18521890
}
18531891

1854-
/* Build xsdt table */
1892+
/*
1893+
* ACPI 2.0 eXtended System Description Table (XSDT)
1894+
*/
18551895
void
18561896
build_xsdt(GArray *table_data, BIOSLinker *linker, GArray *table_offsets,
18571897
const char *oem_id, const char *oem_table_id)
18581898
{
18591899
int i;
1860-
unsigned xsdt_entries_offset;
1861-
AcpiXsdtDescriptorRev2 *xsdt;
1862-
int xsdt_start = table_data->len;
1863-
const unsigned table_data_len = (sizeof(uint64_t) * table_offsets->len);
1864-
const unsigned xsdt_entry_size = sizeof(xsdt->table_offset_entry[0]);
1865-
const size_t xsdt_len = sizeof(*xsdt) + table_data_len;
1866-
1867-
xsdt = acpi_data_push(table_data, xsdt_len);
1868-
xsdt_entries_offset = (char *)xsdt->table_offset_entry - table_data->data;
1900+
AcpiTable table = { .sig = "XSDT", .rev = 1,
1901+
.oem_id = oem_id, .oem_table_id = oem_table_id };
1902+
1903+
acpi_table_begin(&table, table_data);
1904+
18691905
for (i = 0; i < table_offsets->len; ++i) {
18701906
uint64_t ref_tbl_offset = g_array_index(table_offsets, uint32_t, i);
1871-
uint64_t xsdt_entry_offset = xsdt_entries_offset + xsdt_entry_size * i;
1907+
uint64_t xsdt_entry_offset = table.array->len;
18721908

1873-
/* xsdt->table_offset_entry to be filled by Guest linker */
1909+
/* reserve space for entry */
1910+
build_append_int_noprefix(table.array, 0, 8);
1911+
1912+
/* mark position of RSDT entry to be filled by Guest linker */
18741913
bios_linker_loader_add_pointer(linker,
1875-
ACPI_BUILD_TABLE_FILE, xsdt_entry_offset, xsdt_entry_size,
1914+
ACPI_BUILD_TABLE_FILE, xsdt_entry_offset, 8,
18761915
ACPI_BUILD_TABLE_FILE, ref_tbl_offset);
18771916
}
1878-
build_header(linker, table_data,
1879-
(void *)(table_data->data + xsdt_start),
1880-
"XSDT", xsdt_len, 1, oem_id, oem_table_id);
1917+
acpi_table_end(linker, &table);
18811918
}
18821919

1883-
void build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base,
1920+
/*
1921+
* ACPI spec, Revision 4.0
1922+
* 5.2.16.2 Memory Affinity Structure
1923+
*/
1924+
void build_srat_memory(GArray *table_data, uint64_t base,
18841925
uint64_t len, int node, MemoryAffinityFlags flags)
18851926
{
1886-
numamem->type = ACPI_SRAT_MEMORY;
1887-
numamem->length = sizeof(*numamem);
1888-
numamem->proximity = cpu_to_le32(node);
1889-
numamem->flags = cpu_to_le32(flags);
1890-
numamem->base_addr = cpu_to_le64(base);
1891-
numamem->range_length = cpu_to_le64(len);
1927+
build_append_int_noprefix(table_data, 1, 1); /* Type */
1928+
build_append_int_noprefix(table_data, 40, 1); /* Length */
1929+
build_append_int_noprefix(table_data, node, 4); /* Proximity Domain */
1930+
build_append_int_noprefix(table_data, 0, 2); /* Reserved */
1931+
build_append_int_noprefix(table_data, base, 4); /* Base Address Low */
1932+
/* Base Address High */
1933+
build_append_int_noprefix(table_data, base >> 32, 4);
1934+
build_append_int_noprefix(table_data, len, 4); /* Length Low */
1935+
build_append_int_noprefix(table_data, len >> 32, 4); /* Length High */
1936+
build_append_int_noprefix(table_data, 0, 4); /* Reserved */
1937+
build_append_int_noprefix(table_data, flags, 4); /* Flags */
1938+
build_append_int_noprefix(table_data, 0, 8); /* Reserved */
18921939
}
18931940

18941941
/*
@@ -1898,11 +1945,12 @@ void build_srat_memory(AcpiSratMemoryAffinity *numamem, uint64_t base,
18981945
void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms,
18991946
const char *oem_id, const char *oem_table_id)
19001947
{
1901-
int slit_start, i, j;
1902-
slit_start = table_data->len;
1948+
int i, j;
19031949
int nb_numa_nodes = ms->numa_state->num_nodes;
1950+
AcpiTable table = { .sig = "SLIT", .rev = 1,
1951+
.oem_id = oem_id, .oem_table_id = oem_table_id };
19041952

1905-
acpi_data_push(table_data, sizeof(AcpiTableHeader));
1953+
acpi_table_begin(&table, table_data);
19061954

19071955
build_append_int_noprefix(table_data, nb_numa_nodes, 8);
19081956
for (i = 0; i < nb_numa_nodes; i++) {
@@ -1913,21 +1961,18 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms,
19131961
1);
19141962
}
19151963
}
1916-
1917-
build_header(linker, table_data,
1918-
(void *)(table_data->data + slit_start),
1919-
"SLIT",
1920-
table_data->len - slit_start, 1, oem_id, oem_table_id);
1964+
acpi_table_end(linker, &table);
19211965
}
19221966

19231967
/* build rev1/rev3/rev5.1 FADT */
19241968
void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
19251969
const char *oem_id, const char *oem_table_id)
19261970
{
19271971
int off;
1928-
int fadt_start = tbl->len;
1972+
AcpiTable table = { .sig = "FACP", .rev = f->rev,
1973+
.oem_id = oem_id, .oem_table_id = oem_table_id };
19291974

1930-
acpi_data_push(tbl, sizeof(AcpiTableHeader));
1975+
acpi_table_begin(&table, tbl);
19311976

19321977
/* FACS address to be filled by Guest linker at runtime */
19331978
off = tbl->len;
@@ -1991,7 +2036,7 @@ void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
19912036
build_append_int_noprefix(tbl, f->flags, 4); /* Flags */
19922037

19932038
if (f->rev == 1) {
1994-
goto build_hdr;
2039+
goto done;
19952040
}
19962041

19972042
build_append_gas_from_struct(tbl, &f->reset_reg); /* RESET_REG */
@@ -2028,7 +2073,7 @@ void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
20282073
build_append_gas(tbl, AML_AS_SYSTEM_MEMORY, 0 , 0, 0, 0); /* X_GPE1_BLK */
20292074

20302075
if (f->rev <= 4) {
2031-
goto build_hdr;
2076+
goto done;
20322077
}
20332078

20342079
/* SLEEP_CONTROL_REG */
@@ -2039,9 +2084,8 @@ void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
20392084
/* TODO: extra fields need to be added to support revisions above rev5 */
20402085
assert(f->rev == 5);
20412086

2042-
build_hdr:
2043-
build_header(linker, tbl, (void *)(tbl->data + fadt_start),
2044-
"FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
2087+
done:
2088+
acpi_table_end(linker, &table);
20452089
}
20462090

20472091
#ifdef CONFIG_TPM
@@ -2054,13 +2098,14 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog,
20542098
const char *oem_id, const char *oem_table_id)
20552099
{
20562100
uint8_t start_method_params[12] = {};
2057-
unsigned log_addr_offset, tpm2_start;
2101+
unsigned log_addr_offset;
20582102
uint64_t control_area_start_address;
20592103
TPMIf *tpmif = tpm_find();
20602104
uint32_t start_method;
2105+
AcpiTable table = { .sig = "TPM2", .rev = 4,
2106+
.oem_id = oem_id, .oem_table_id = oem_table_id };
20612107

2062-
tpm2_start = table_data->len;
2063-
acpi_data_push(table_data, sizeof(AcpiTableHeader));
2108+
acpi_table_begin(&table, table_data);
20642109

20652110
/* Platform Class */
20662111
build_append_int_noprefix(table_data, TPM2_ACPI_CLASS_CLIENT, 2);
@@ -2098,9 +2143,7 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog,
20982143
bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
20992144
log_addr_offset, 8,
21002145
ACPI_BUILD_TPMLOG_FILE, 0);
2101-
build_header(linker, table_data,
2102-
(void *)(table_data->data + tpm2_start),
2103-
"TPM2", table_data->len - tpm2_start, 4, oem_id, oem_table_id);
2146+
acpi_table_end(linker, &table);
21042147
}
21052148
#endif
21062149

hw/acpi/cpu.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -669,21 +669,8 @@ void build_cpus_aml(Aml *table, MachineState *machine, CPUHotplugFeatures opts,
669669

670670
/* build _MAT object */
671671
assert(adevc && adevc->madt_cpu);
672-
adevc->madt_cpu(adev, i, arch_ids, madt_buf);
673-
switch (madt_buf->data[0]) {
674-
case ACPI_APIC_PROCESSOR: {
675-
AcpiMadtProcessorApic *apic = (void *)madt_buf->data;
676-
apic->flags = cpu_to_le32(1);
677-
break;
678-
}
679-
case ACPI_APIC_LOCAL_X2APIC: {
680-
AcpiMadtProcessorX2Apic *apic = (void *)madt_buf->data;
681-
apic->flags = cpu_to_le32(1);
682-
break;
683-
}
684-
default:
685-
assert(0);
686-
}
672+
adevc->madt_cpu(adev, i, arch_ids, madt_buf,
673+
true); /* set enabled flag */
687674
aml_append(dev, aml_name_decl("_MAT",
688675
aml_buffer(madt_buf->len, (uint8_t *)madt_buf->data)));
689676
g_array_free(madt_buf, true);

hw/acpi/ghes.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,16 @@ static void build_ghes_v2(GArray *table_data, int source_id, BIOSLinker *linker)
362362
void acpi_build_hest(GArray *table_data, BIOSLinker *linker,
363363
const char *oem_id, const char *oem_table_id)
364364
{
365-
uint64_t hest_start = table_data->len;
365+
AcpiTable table = { .sig = "HEST", .rev = 1,
366+
.oem_id = oem_id, .oem_table_id = oem_table_id };
366367

367-
/* Hardware Error Source Table header*/
368-
acpi_data_push(table_data, sizeof(AcpiTableHeader));
368+
acpi_table_begin(&table, table_data);
369369

370370
/* Error Source Count */
371371
build_append_int_noprefix(table_data, ACPI_GHES_ERROR_SOURCE_COUNT, 4);
372-
373372
build_ghes_v2(table_data, ACPI_HEST_SRC_ID_SEA, linker);
374373

375-
build_header(linker, table_data, (void *)(table_data->data + hest_start),
376-
"HEST", table_data->len - hest_start, 1, oem_id, oem_table_id);
374+
acpi_table_end(linker, &table);
377375
}
378376

379377
void acpi_ghes_add_fw_cfg(AcpiGhesState *ags, FWCfgState *s,

0 commit comments

Comments
 (0)