qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

hw/acpi: extract acpi_add_rom_blob()

arm and i386 has almost the same function acpi_add_rom_blob(), except
giving different FWCfgCallback function.

This patch moves acpi_add_rom_blob() to utils.c by passing
FWCfgCallback to it.

Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>

v7:
* rebase on top of current master because of conflict
v6:
* change author from Igor to Michael
v5:
* remove unnecessary header glib/gprintf.h
* rearrange include header to make it more suitable
v4:
* extract -> moves
* adjust comment in source to make checkpatch happy
v3:
* put acpi_add_rom_blob() to hw/acpi/utils.c
v2:
* remove unused header in original source file
Message-Id: <20190610011830.28398-1-richardw.yang@linux.intel.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Wei Yang and committed by
Michael S. Tsirkin
82f76c67 240e647a

+65 -33
+1 -1
hw/acpi/Makefile.objs
··· 10 10 11 11 common-obj-y += acpi_interface.o 12 12 common-obj-y += bios-linker-loader.o 13 - common-obj-y += aml-build.o 13 + common-obj-y += aml-build.o utils.o 14 14 common-obj-$(CONFIG_ACPI_PCI) += pci.o 15 15 common-obj-$(CONFIG_TPM) += tpm.o 16 16
+35
hw/acpi/utils.c
··· 1 + /* 2 + * Utilities for generating ACPI tables and passing them to Guests 3 + * 4 + * Copyright (C) 2019 Intel Corporation 5 + * Copyright (C) 2019 Red Hat Inc 6 + * 7 + * Author: Wei Yang <richardw.yang@linux.intel.com> 8 + * Author: Michael S. Tsirkin <mst@redhat.com> 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License as published by 12 + * the Free Software Foundation; either version 2 of the License, or 13 + * (at your option) any later version. 14 + 15 + * This program is distributed in the hope that it will be useful, 16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 + * GNU General Public License for more details. 19 + 20 + * You should have received a copy of the GNU General Public License along 21 + * with this program; if not, see <http://www.gnu.org/licenses/>. 22 + */ 23 + 24 + #include "qemu/osdep.h" 25 + #include "hw/acpi/aml-build.h" 26 + #include "hw/acpi/utils.h" 27 + #include "hw/loader.h" 28 + 29 + MemoryRegion *acpi_add_rom_blob(FWCfgCallback update, void *opaque, 30 + GArray *blob, const char *name, 31 + uint64_t max_size) 32 + { 33 + return rom_add_blob(name, blob->data, acpi_data_len(blob), max_size, -1, 34 + name, update, opaque, NULL, true); 35 + }
+10 -16
hw/arm/virt-acpi-build.c
··· 36 36 #include "hw/acpi/acpi.h" 37 37 #include "hw/nvram/fw_cfg.h" 38 38 #include "hw/acpi/bios-linker-loader.h" 39 - #include "hw/loader.h" 40 39 #include "hw/hw.h" 41 40 #include "hw/acpi/aml-build.h" 41 + #include "hw/acpi/utils.h" 42 42 #include "hw/acpi/pci.h" 43 43 #include "hw/pci/pcie_host.h" 44 44 #include "hw/pci/pci.h" ··· 865 865 build_state->patched = false; 866 866 } 867 867 868 - static MemoryRegion *acpi_add_rom_blob(AcpiBuildState *build_state, 869 - GArray *blob, const char *name, 870 - uint64_t max_size) 871 - { 872 - return rom_add_blob(name, blob->data, acpi_data_len(blob), max_size, -1, 873 - name, virt_acpi_build_update, build_state, NULL, true); 874 - } 875 - 876 868 static const VMStateDescription vmstate_virt_acpi_build = { 877 869 .name = "virt_acpi_build", 878 870 .version_id = 1, ··· 904 896 virt_acpi_build(vms, &tables); 905 897 906 898 /* Now expose it all to Guest */ 907 - build_state->table_mr = acpi_add_rom_blob(build_state, tables.table_data, 908 - ACPI_BUILD_TABLE_FILE, 909 - ACPI_BUILD_TABLE_MAX_SIZE); 899 + build_state->table_mr = acpi_add_rom_blob(virt_acpi_build_update, 900 + build_state, tables.table_data, 901 + ACPI_BUILD_TABLE_FILE, 902 + ACPI_BUILD_TABLE_MAX_SIZE); 910 903 assert(build_state->table_mr != NULL); 911 904 912 905 build_state->linker_mr = 913 - acpi_add_rom_blob(build_state, tables.linker->cmd_blob, 914 - "etc/table-loader", 0); 906 + acpi_add_rom_blob(virt_acpi_build_update, build_state, 907 + tables.linker->cmd_blob, "etc/table-loader", 0); 915 908 916 909 fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, 917 910 acpi_data_len(tables.tcpalog)); 918 911 919 - build_state->rsdp_mr = acpi_add_rom_blob(build_state, tables.rsdp, 920 - ACPI_BUILD_RSDP_FILE, 0); 912 + build_state->rsdp_mr = acpi_add_rom_blob(virt_acpi_build_update, 913 + build_state, tables.rsdp, 914 + ACPI_BUILD_RSDP_FILE, 0); 921 915 922 916 qemu_register_reset(virt_acpi_build_reset, build_state); 923 917 virt_acpi_build_reset(build_state);
+10 -16
hw/i386/acpi-build.c
··· 37 37 #include "hw/acpi/piix4.h" 38 38 #include "hw/nvram/fw_cfg.h" 39 39 #include "hw/acpi/bios-linker-loader.h" 40 - #include "hw/loader.h" 41 40 #include "hw/isa/isa.h" 42 41 #include "hw/block/fdc.h" 43 42 #include "hw/acpi/memory_hotplug.h" ··· 58 57 #include "hw/i386/x86-iommu.h" 59 58 60 59 #include "hw/acpi/aml-build.h" 60 + #include "hw/acpi/utils.h" 61 61 #include "hw/acpi/pci.h" 62 62 63 63 #include "qom/qom-qobject.h" ··· 2823 2823 build_state->patched = 0; 2824 2824 } 2825 2825 2826 - static MemoryRegion *acpi_add_rom_blob(AcpiBuildState *build_state, 2827 - GArray *blob, const char *name, 2828 - uint64_t max_size) 2829 - { 2830 - return rom_add_blob(name, blob->data, acpi_data_len(blob), max_size, -1, 2831 - name, acpi_build_update, build_state, NULL, true); 2832 - } 2833 - 2834 2826 static const VMStateDescription vmstate_acpi_build = { 2835 2827 .name = "acpi_build", 2836 2828 .version_id = 1, ··· 2872 2864 acpi_build(&tables, MACHINE(pcms)); 2873 2865 2874 2866 /* Now expose it all to Guest */ 2875 - build_state->table_mr = acpi_add_rom_blob(build_state, tables.table_data, 2876 - ACPI_BUILD_TABLE_FILE, 2877 - ACPI_BUILD_TABLE_MAX_SIZE); 2867 + build_state->table_mr = acpi_add_rom_blob(acpi_build_update, 2868 + build_state, tables.table_data, 2869 + ACPI_BUILD_TABLE_FILE, 2870 + ACPI_BUILD_TABLE_MAX_SIZE); 2878 2871 assert(build_state->table_mr != NULL); 2879 2872 2880 2873 build_state->linker_mr = 2881 - acpi_add_rom_blob(build_state, tables.linker->cmd_blob, 2882 - "etc/table-loader", 0); 2874 + acpi_add_rom_blob(acpi_build_update, build_state, 2875 + tables.linker->cmd_blob, "etc/table-loader", 0); 2883 2876 2884 2877 fw_cfg_add_file(pcms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, 2885 2878 tables.tcpalog->data, acpi_data_len(tables.tcpalog)); ··· 2916 2909 build_state->rsdp_mr = NULL; 2917 2910 } else { 2918 2911 build_state->rsdp = NULL; 2919 - build_state->rsdp_mr = acpi_add_rom_blob(build_state, tables.rsdp, 2920 - ACPI_BUILD_RSDP_FILE, 0); 2912 + build_state->rsdp_mr = acpi_add_rom_blob(acpi_build_update, 2913 + build_state, tables.rsdp, 2914 + ACPI_BUILD_RSDP_FILE, 0); 2921 2915 } 2922 2916 2923 2917 qemu_register_reset(acpi_build_reset, build_state);
+9
include/hw/acpi/utils.h
··· 1 + #ifndef HW_ACPI_UTILS_H 2 + #define HW_ACPI_UTILS_H 3 + 4 + #include "hw/nvram/fw_cfg.h" 5 + 6 + MemoryRegion *acpi_add_rom_blob(FWCfgCallback update, void *opaque, 7 + GArray *blob, const char *name, 8 + uint64_t max_size); 9 + #endif