From patchwork Sun May 15 19:23:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 9096791 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E72A5BF29F for ; Sun, 15 May 2016 19:24:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 209FA201F5 for ; Sun, 15 May 2016 19:24:03 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5CDC720172 for ; Sun, 15 May 2016 19:24:02 +0000 (UTC) Received: from localhost ([::1]:41184 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b21dx-0005Dc-JA for patchwork-qemu-devel@patchwork.kernel.org; Sun, 15 May 2016 15:24:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b21di-00054L-FF for qemu-devel@nongnu.org; Sun, 15 May 2016 15:23:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b21dc-0003cc-70 for qemu-devel@nongnu.org; Sun, 15 May 2016 15:23:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49420) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b21dc-0003cW-1L for qemu-devel@nongnu.org; Sun, 15 May 2016 15:23:40 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87B082027D for ; Sun, 15 May 2016 19:23:39 +0000 (UTC) Received: from work.redhat.com (vpn-203-81.tlv.redhat.com [10.35.203.81]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4FJNYMS019754; Sun, 15 May 2016 15:23:37 -0400 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Sun, 15 May 2016 22:23:31 +0300 Message-Id: <1463340214-8721-2-git-send-email-marcel@redhat.com> In-Reply-To: <1463340214-8721-1-git-send-email-marcel@redhat.com> References: <1463340214-8721-1-git-send-email-marcel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sun, 15 May 2016 19:23:39 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH V2 1/4] hw/pc: extract reserved memory end computation to a standalone function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcel@redhat.com, imammedo@redhat.com, lersek@redhat.com, ehabkost@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This code will be reused when calculating 64-bit MMIO hotplug ranges. Signed-off-by: Marcel Apfelbaum Reviewed-by: Igor Mammedov --- hw/i386/pc.c | 29 +++++++++++++++++++++-------- include/hw/i386/pc.h | 1 + 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 99437e0..a7791e3 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1280,6 +1280,7 @@ void pc_memory_init(PCMachineState *pcms, FWCfgState *fw_cfg; MachineState *machine = MACHINE(pcms); PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms); + uint64_t res_mem_end; assert(machine->ram_size == pcms->below_4g_mem_size + pcms->above_4g_mem_size); @@ -1375,15 +1376,10 @@ void pc_memory_init(PCMachineState *pcms, rom_set_fw(fw_cfg); - if (pcmc->has_reserved_memory && pcms->hotplug_memory.base) { + res_mem_end = pc_machine_get_reserved_memory_end(pcms); + if (res_mem_end) { uint64_t *val = g_malloc(sizeof(*val)); - PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms); - uint64_t res_mem_end = pcms->hotplug_memory.base; - - if (!pcmc->broken_reserved_end) { - res_mem_end += memory_region_size(&pcms->hotplug_memory.mr); - } - *val = cpu_to_le64(ROUND_UP(res_mem_end, 0x1ULL << 30)); + *val = cpu_to_le64(res_mem_end); fw_cfg_add_file(fw_cfg, "etc/reserved-memory-end", val, sizeof(*val)); } @@ -1853,6 +1849,23 @@ bool pc_machine_is_smm_enabled(PCMachineState *pcms) return false; } +uint64_t pc_machine_get_reserved_memory_end(PCMachineState *pcms) +{ + PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms); + uint64_t res_mem_end = 0; + + if (pcmc->has_reserved_memory && pcms->hotplug_memory.base) { + res_mem_end = pcms->hotplug_memory.base; + + if (!pcmc->broken_reserved_end) { + res_mem_end += memory_region_size(&pcms->hotplug_memory.mr); + } + res_mem_end = ROUND_UP(res_mem_end, 0x1ULL << 30); + } + + return res_mem_end; +} + static void pc_machine_get_smm(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 96f0b66..7c25814 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -223,6 +223,7 @@ void i8042_setup_a20_line(ISADevice *dev, qemu_irq *a20_out); extern int fd_bootchk; bool pc_machine_is_smm_enabled(PCMachineState *pcms); +uint64_t pc_machine_get_reserved_memory_end(PCMachineState *pcms); void pc_register_ferr_irq(qemu_irq irq); void pc_acpi_smi_interrupt(void *opaque, int irq, int level);