From patchwork Thu Jun 13 14:29:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 251082 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A71C82C008A for ; Fri, 14 Jun 2013 00:29:55 +1000 (EST) Received: from localhost ([::1]:56895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Un8XB-0003GR-AN for incoming@patchwork.ozlabs.org; Thu, 13 Jun 2013 10:29:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Un8WY-0003Ay-P9 for qemu-devel@nongnu.org; Thu, 13 Jun 2013 10:29:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Un8WV-0002Ai-Gk for qemu-devel@nongnu.org; Thu, 13 Jun 2013 10:29:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12861) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Un8WV-0002Aa-8H for qemu-devel@nongnu.org; Thu, 13 Jun 2013 10:29:11 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5DETAAq024552 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Jun 2013 10:29:10 -0400 Received: from redhat.com (vpn-203-103.tlv.redhat.com [10.35.203.103]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id r5DET8gq020607; Thu, 13 Jun 2013 10:29:09 -0400 Date: Thu, 13 Jun 2013 17:29:52 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1371133655-10186-3-git-send-email-mst@redhat.com> References: <1371133655-10186-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1371133655-10186-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori Subject: [Qemu-devel] [PATCH RFC 2/3] acpi: add tables as ROM so they are migrated X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org As we are going to very likely change ACPI tables across QEMU versions, cross-verion migration will be a pain. Register the tables as a ROM: this way they are migrated, same as BIOS code. Since size is going to likely change, too, round it up to a multiple of 1MByte to avoid too much churn there. Signed-off-by: Michael S. Tsirkin --- hw/i386/acpi-build.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index 43e4988..911c913 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -35,6 +35,7 @@ #include "hw/nvram/fw_cfg.h" #include "hw/i386/bios-linker-loader.h" #include "hw/pci/pci_bus.h" +#include "hw/loader.h" #define ACPI_BUILD_APPNAME "Bochs" #define ACPI_BUILD_APPNAME6 "BOCHS " @@ -933,6 +934,28 @@ build_rsdp(GArray *linker, unsigned rsdt) return rsdp_table; } +static void acpi_add_rom_blob(PcGuestInfo *guest_info, GArray *blob, + const char *name, unsigned align) +{ + MemoryRegion *mr = g_malloc(sizeof(*mr)); + + /* Align size to multiple of given size. This reduces the chance + * we need to change size in the future (breaking cross version migration). + */ + g_array_set_size(blob, (ROUND_UP(acpi_data_len(blob), align) + + g_array_get_element_size(blob) - 1) / + g_array_get_element_size(blob)); + memory_region_init_ram_ptr(mr, "etc/blob-script", + acpi_data_len(blob), blob->data); + memory_region_set_readonly(mr, true); + vmstate_register_ram_global(mr); + rom_add_blob(ACPI_BUILD_TABLE_FILE, blob->data, acpi_data_len(blob), + -1, mr); + + fw_cfg_add_file(guest_info->fw_cfg, name, + blob->data, acpi_data_len(blob)); +} + #define ACPI_MAX_ACPI_TABLES 20 void acpi_setup(PcGuestInfo *guest_info) { @@ -993,12 +1016,18 @@ void acpi_setup(PcGuestInfo *guest_info) rsdp = build_rsdp(linker, rsdt); /* Now expose it all to Guest */ - fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_TABLE_FILE, - table_data->data, table_data->len); + acpi_add_rom_blob(guest_info, table_data, + ACPI_BUILD_TABLE_FILE, 1 << 20); + + acpi_add_rom_blob(guest_info, linker, + "etc/linker-script", TARGET_PAGE_SIZE); + + /* + * RSDP is small so it's easy to keep it immutable, no need to + * bother with ROM blobs. + */ fw_cfg_add_file(guest_info->fw_cfg, ACPI_BUILD_RSDP_FILE, rsdp->data, acpi_data_len(rsdp)); - fw_cfg_add_file(guest_info->fw_cfg, "etc/linker-script", - linker->data, acpi_data_len(linker)); /* Cleanup GArray wrappers and memory if no longer used. */ bios_linker_cleanup(linker);