From patchwork Mon May 13 20:01:20 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: 243516 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D8A332C009E for ; Tue, 14 May 2013 06:03:45 +1000 (EST) Received: from localhost ([::1]:51869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UbyyG-0008Il-1e for incoming@patchwork.ozlabs.org; Mon, 13 May 2013 16:03:44 -0400 Received: from eggs.gnu.org ([208.118.235.92]:34486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ubyw2-00055P-8C for qemu-devel@nongnu.org; Mon, 13 May 2013 16:01:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ubyvz-0008E5-A9 for qemu-devel@nongnu.org; Mon, 13 May 2013 16:01:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25797) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ubyvz-0008Dv-3R for qemu-devel@nongnu.org; Mon, 13 May 2013 16:01:23 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4DK1LDM011782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 13 May 2013 16:01:21 -0400 Received: from redhat.com (vpn-202-66.tlv.redhat.com [10.35.202.66]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id r4DK1Is8008378; Mon, 13 May 2013 16:01:19 -0400 Date: Mon, 13 May 2013 23:01:20 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org, Anthony Liguori , lersek@redhat.com, seabios@seabios.org Message-ID: <5a4fcc1346b9b0e0b3ea6d10dd3a9d5c4da28282.1368474222.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 13/13] pc: reuse guest info for legacy fw cfg 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 Reduce code duplication by getting legacy fw cfg data from guest info structure. Signed-off-by: Michael S. Tsirkin --- hw/i386/pc.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index af414a4..41bfb5b 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -594,14 +594,13 @@ static unsigned int pc_apic_id_limit(unsigned int max_cpus) return x86_cpu_apic_id_from_index(max_cpus - 1) + 1; } -static FWCfgState *bochs_bios_init(void) +static FWCfgState *bochs_bios_init(PcGuestInfo *guest_info) { FWCfgState *fw_cfg; uint8_t *smbios_table; size_t smbios_len; uint64_t *numa_fw_cfg; - int i, j; - unsigned int apic_id_limit = pc_apic_id_limit(max_cpus); + int i; fw_cfg = fw_cfg_init(BIOS_CFG_IOPORT, BIOS_CFG_IOPORT + 1, 0, 0); /* FW_CFG_MAX_CPUS is a bit confusing/problematic on x86: @@ -618,7 +617,7 @@ static FWCfgState *bochs_bios_init(void) * [1] The only kind of "CPU identifier" used between SeaBIOS and QEMU is * the APIC ID, not the "CPU index" */ - fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)apic_id_limit); + fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, (uint16_t)guest_info->apic_id_limit); fw_cfg_add_i32(fw_cfg, FW_CFG_ID, 1); fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)ram_size); fw_cfg_add_bytes(fw_cfg, FW_CFG_ACPI_TABLES, @@ -637,24 +636,19 @@ static FWCfgState *bochs_bios_init(void) * of nodes, one word for each VCPU->node and one word for each node to * hold the amount of memory. */ - numa_fw_cfg = g_new0(uint64_t, 1 + apic_id_limit + nb_numa_nodes); - numa_fw_cfg[0] = cpu_to_le64(nb_numa_nodes); - for (i = 0; i < max_cpus; i++) { - unsigned int apic_id = x86_cpu_apic_id_from_index(i); - assert(apic_id < apic_id_limit); - for (j = 0; j < nb_numa_nodes; j++) { - if (test_bit(i, node_cpumask[j])) { - numa_fw_cfg[apic_id + 1] = cpu_to_le64(j); - break; - } - } + numa_fw_cfg = g_new0(uint64_t, 1 + guest_info->apic_id_limit + + guest_info->numa_nodes); + numa_fw_cfg[0] = cpu_to_le64(guest_info->numa_nodes); + for (i = 0; i < guest_info->apic_id_limit; i++) { + numa_fw_cfg[i + 1] = cpu_to_le64(guest_info->node_cpu[i]); } - for (i = 0; i < nb_numa_nodes; i++) { - numa_fw_cfg[apic_id_limit + 1 + i] = cpu_to_le64(node_mem[i]); + for (i = 0; i < guest_info->numa_nodes; i++) { + numa_fw_cfg[guest_info->apic_id_limit + 1 + i] = + cpu_to_le64(guest_info->node_mem[i]); } fw_cfg_add_bytes(fw_cfg, FW_CFG_NUMA, numa_fw_cfg, - (1 + apic_id_limit + nb_numa_nodes) * - sizeof(*numa_fw_cfg)); + (1 + guest_info->apic_id_limit + + guest_info->numa_nodes) * sizeof(*numa_fw_cfg)); return fw_cfg; } @@ -1151,7 +1145,7 @@ FWCfgState *pc_memory_init(MemoryRegion *system_memory, option_rom_mr, 1); - fw_cfg = bochs_bios_init(); + fw_cfg = bochs_bios_init(guest_info); rom_set_fw(fw_cfg); if (linux_boot) {