it allows to hide linker and direct access to table's storage from table building function if it would use acpi_def_block() to declare table and ASL/AML API to compose it. Which following patch will do for build_ssdt() function.
Signed-off-by: Igor Mammedov <imamm...@redhat.com> --- PS: this series does it only for build_ssdt(), but it also could be done for other tables later by using there acpi_def_block() to describe table's header and adding addtional API to compose table's entries. --- hw/i386/acpi-build.c | 85 ++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 3a22bdb..347448b 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -1253,7 +1253,7 @@ build_rsdp(GArray *rsdp_table, GArray *linker, unsigned rsdt) typedef struct AcpiBuildTables { - GArray *table_data; + AcpiAml table_data; GArray *rsdp; GArray *tcpalog; GArray *linker; @@ -1262,9 +1262,10 @@ struct AcpiBuildTables { static inline void acpi_build_tables_init(AcpiBuildTables *tables) { tables->rsdp = g_array_new(false, true /* clear */, 1); - tables->table_data = g_array_new(false, true /* clear */, 1); + tables->table_data.buf = g_array_new(false, true /* clear */, 1); tables->tcpalog = g_array_new(false, true /* clear */, 1); tables->linker = bios_linker_loader_init(); + tables->table_data.linker = tables->linker; } static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) @@ -1272,7 +1273,7 @@ static inline void acpi_build_tables_cleanup(AcpiBuildTables *tables, bool mfre) void *linker_data = bios_linker_loader_cleanup(tables->linker); g_free(linker_data); g_array_free(tables->rsdp, mfre); - g_array_free(tables->table_data, true); + g_array_free(tables->table_data.buf, true); g_array_free(tables->tcpalog, mfre); } @@ -1352,66 +1353,66 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables) * We place it first since it's the only table that has alignment * requirements. */ - facs = tables->table_data->len; - build_facs(tables->table_data, tables->linker, guest_info); + facs = tables->table_data.buf->len; + build_facs(tables->table_data.buf, tables->linker, guest_info); /* DSDT is pointed to by FADT */ - dsdt = tables->table_data->len; - build_dsdt(tables->table_data, tables->linker, &misc); + dsdt = tables->table_data.buf->len; + build_dsdt(tables->table_data.buf, tables->linker, &misc); /* Count the size of the DSDT and SSDT, we will need it for legacy * sizing of ACPI tables. */ - aml_len += tables->table_data->len - dsdt; + aml_len += tables->table_data.buf->len - dsdt; /* ACPI tables pointed to by RSDT */ - acpi_add_table(table_offsets, tables->table_data); - build_fadt(tables->table_data, tables->linker, &pm, facs, dsdt); + acpi_add_table(table_offsets, tables->table_data.buf); + build_fadt(tables->table_data.buf, tables->linker, &pm, facs, dsdt); - ssdt = tables->table_data->len; - acpi_add_table(table_offsets, tables->table_data); - build_ssdt(tables->table_data, tables->linker, &cpu, &pm, &misc, &pci, + ssdt = tables->table_data.buf->len; + acpi_add_table(table_offsets, tables->table_data.buf); + build_ssdt(tables->table_data.buf, tables->linker, &cpu, &pm, &misc, &pci, guest_info); - aml_len += tables->table_data->len - ssdt; + aml_len += tables->table_data.buf->len - ssdt; - acpi_add_table(table_offsets, tables->table_data); - build_madt(tables->table_data, tables->linker, &cpu, guest_info); + acpi_add_table(table_offsets, tables->table_data.buf); + build_madt(tables->table_data.buf, tables->linker, &cpu, guest_info); if (misc.has_hpet) { - acpi_add_table(table_offsets, tables->table_data); - build_hpet(tables->table_data, tables->linker); + acpi_add_table(table_offsets, tables->table_data.buf); + build_hpet(tables->table_data.buf, tables->linker); } if (misc.has_tpm) { - acpi_add_table(table_offsets, tables->table_data); - build_tpm_tcpa(tables->table_data, tables->linker, tables->tcpalog); + acpi_add_table(table_offsets, tables->table_data.buf); + build_tpm_tcpa(tables->table_data.buf, tables->linker, tables->tcpalog); - acpi_add_table(table_offsets, tables->table_data); - build_tpm_ssdt(tables->table_data, tables->linker); + acpi_add_table(table_offsets, tables->table_data.buf); + build_tpm_ssdt(tables->table_data.buf, tables->linker); } if (guest_info->numa_nodes) { - acpi_add_table(table_offsets, tables->table_data); - build_srat(tables->table_data, tables->linker, guest_info); + acpi_add_table(table_offsets, tables->table_data.buf); + build_srat(tables->table_data.buf, tables->linker, guest_info); } if (acpi_get_mcfg(&mcfg)) { - acpi_add_table(table_offsets, tables->table_data); - build_mcfg_q35(tables->table_data, tables->linker, &mcfg); + acpi_add_table(table_offsets, tables->table_data.buf); + build_mcfg_q35(tables->table_data.buf, tables->linker, &mcfg); } if (acpi_has_iommu()) { - acpi_add_table(table_offsets, tables->table_data); - build_dmar_q35(tables->table_data, tables->linker); + acpi_add_table(table_offsets, tables->table_data.buf); + build_dmar_q35(tables->table_data.buf, tables->linker); } /* Add tables supplied by user (if any) */ for (u = acpi_table_first(); u; u = acpi_table_next(u)) { unsigned len = acpi_table_len(u); - acpi_add_table(table_offsets, tables->table_data); - g_array_append_vals(tables->table_data, u, len); + acpi_add_table(table_offsets, tables->table_data.buf); + g_array_append_vals(tables->table_data.buf, u, len); } /* RSDT is pointed to by RSDP */ - rsdt = tables->table_data->len; - build_rsdt(tables->table_data, tables->linker, table_offsets); + rsdt = tables->table_data.buf->len; + build_rsdt(tables->table_data.buf, tables->linker, table_offsets); /* RSDP is in FSEG memory, so allocate it separately */ build_rsdp(tables->rsdp, tables->linker, rsdt); @@ -1443,23 +1444,23 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables) guest_info->legacy_acpi_table_size + ACPI_BUILD_LEGACY_CPU_AML_SIZE * max_cpus; int legacy_table_size = - ROUND_UP(tables->table_data->len - aml_len + legacy_aml_len, + ROUND_UP(tables->table_data.buf->len - aml_len + legacy_aml_len, ACPI_BUILD_ALIGN_SIZE); - if (tables->table_data->len > legacy_table_size) { + if (tables->table_data.buf->len > legacy_table_size) { /* Should happen only with PCI bridges and -M pc-i440fx-2.0. */ error_report("Warning: migration may not work."); } - g_array_set_size(tables->table_data, legacy_table_size); + g_array_set_size(tables->table_data.buf, legacy_table_size); } else { /* Make sure we have a buffer in case we need to resize the tables. */ - if (tables->table_data->len > ACPI_BUILD_TABLE_SIZE / 2) { + if (tables->table_data.buf->len > ACPI_BUILD_TABLE_SIZE / 2) { /* As of QEMU 2.1, this fires with 160 VCPUs and 255 memory slots. */ error_report("Warning: ACPI tables are larger than 64k."); error_report("Warning: migration may not work."); error_report("Warning: please remove CPUs, NUMA nodes, " "memory slots or PCI bridges."); } - acpi_align_size(tables->table_data, ACPI_BUILD_TABLE_SIZE); + acpi_align_size(tables->table_data.buf, ACPI_BUILD_TABLE_SIZE); } acpi_align_size(tables->linker, ACPI_BUILD_ALIGN_SIZE); @@ -1483,8 +1484,8 @@ static void acpi_build_update(void *build_opaque, uint32_t offset) acpi_build(build_state->guest_info, &tables); - assert(acpi_data_len(tables.table_data) == build_state->table_size); - memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data->data, + assert(acpi_data_len(tables.table_data.buf) == build_state->table_size); + memcpy(qemu_get_ram_ptr(build_state->table_ram), tables.table_data.buf->data, build_state->table_size); cpu_physical_memory_set_dirty_range_nocode(build_state->table_ram, @@ -1546,10 +1547,10 @@ void acpi_setup(PcGuestInfo *guest_info) acpi_build(build_state->guest_info, &tables); /* Now expose it all to Guest */ - build_state->table_ram = acpi_add_rom_blob(build_state, tables.table_data, - ACPI_BUILD_TABLE_FILE); + build_state->table_ram = acpi_add_rom_blob(build_state, + tables.table_data.buf, ACPI_BUILD_TABLE_FILE); assert(build_state->table_ram != RAM_ADDR_MAX); - build_state->table_size = acpi_data_len(tables.table_data); + build_state->table_size = acpi_data_len(tables.table_data.buf); acpi_add_rom_blob(NULL, tables.linker, "etc/table-loader"); -- 1.8.3.1