From patchwork Tue Mar 5 16:50:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 159693 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp5202213jad; Tue, 5 Mar 2019 09:08:43 -0800 (PST) X-Google-Smtp-Source: APXvYqw3Ly9DKc2xtH+v/eSndVSaZB+pruyIoxgWrvvh38OBCPz7dG0wRKu3TX+l5qUMY/b0kD2y X-Received: by 2002:a5b:704:: with SMTP id g4mr3007059ybq.272.1551805723689; Tue, 05 Mar 2019 09:08:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551805723; cv=none; d=google.com; s=arc-20160816; b=TPi5mCGyWKcqBJGJW5bebRGRTZeRPv6/ksb64pTnjBI+VNfHSkvUewhpo8xPINJFnF 3h/j3Z/8AS1meFM2sIRNP0mxR+Ai2nOzsvimS04+xBoOTQPfesArIPDSws8Ssj/Jn0N2 70d8cvqf6C6aIMwMMmk7U4aCFNc5Ea8Klhw1ZycatKbFUckmSoq8yDUPalLHGe44SrNV 1scHeWSW3EnkPVhZ7HIfi3i2X5aa9O4wE4+W/iy/OLaGDMZ3bMKz313D9IkkAz0lvtHv AtZ9YpkUGkJcL+5/BzVVF3c/yz3Fc/mQuU0fuQJrwqnpLMcGodBlLW7IsUuOc4vpncQ+ YECQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=Ltk70KUUJO5NHKp1nZhYlY5OByUUnYGe7vFLDaegESg=; b=LX7S7B4OUB41OSqwQpxxDruxtVyRdmqVlz7oCoo9r59oT2lQQs+O42YzRirMgWM54R /5mML7x6fhVoTz36zRVmOU9wynYqPlbekAENsgX75/oXw1skdleQtgYLCF8C1yU6gT4a IwbilFMwMCAbjvUYdiC5UOJ93gJfMyibqdrttCtVRAd4UaCQQNbJdxkjKCBYWHtWA4AQ YFEFDBEIxSr0vIFGUpVoTGuneIOCBNKvhIMMWZVn3eptLxmdoiSq8kN31LdLJak+5euo DuzKQY8k5LAVOPu/wucLj5n4rbgmBxgK/XBDNVvjFr4KveCZ+H4ei6OWvq7yF0rZotJV cAZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MewqAdI6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d186si5783456ywb.18.2019.03.05.09.08.43 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 05 Mar 2019 09:08:43 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MewqAdI6; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:45991 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1DYZ-0006tI-3z for patch@linaro.org; Tue, 05 Mar 2019 12:08:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1DHc-0001eO-VB for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:51:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1DHb-0000xN-RE for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:51:12 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:38667) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1DHb-0000wj-JT for qemu-devel@nongnu.org; Tue, 05 Mar 2019 11:51:11 -0500 Received: by mail-wr1-x432.google.com with SMTP id g12so10246954wrm.5 for ; Tue, 05 Mar 2019 08:51:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Ltk70KUUJO5NHKp1nZhYlY5OByUUnYGe7vFLDaegESg=; b=MewqAdI6sjhGbc+Blk56uaM0YNIRVyTtboHTemRG8hCq+V0YwhlaoxUiviAscm0uDL Lu80J1lccbspLllevY7UP6pkHVjatcLbO2QeL3odZrWnqq6gU3DOwPjxPD52DGoPFuzx BbFgTBDRh+fevvax3xqAebCfEaCnM+/yr0BujaQGiddzAEV9vKofWp6c7ESFuPIXYVHw nRQQw1emjO0mZCYXPY7QfWYem/HUsy6qt8b0p4fYdBrpHoddTNjngNlDrIfjc9vIaFlO CejsFBW24hFKoQy9GnJt57l51YxlRtZ4KJ+Oe+wx2JScJAcbs2v5yBe1bGRYx85NOSxI o/yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ltk70KUUJO5NHKp1nZhYlY5OByUUnYGe7vFLDaegESg=; b=LwplTUPhrR9fIeOXxZdPIB0eTKp7BGlMzWYyIQLVDgna5HmLYxC9UzXVPnh/pCU5iW wY8nw8eKyW9IB2JjTguuXes0F009maPk2P1oguKlWlGS6YyVcyxUta8YvJvljG3NlaEz 1fFXCu5Q/wuRGzpxnO6fIBMTj7d/2WznWsovXmlaL4iQ+awMpErE5yggJ/NEF7Cra/qO U7iNzSv6AifJFjYoOS8zHwhjLQoHqWN5DSwG8MRb5QRv4gvBFPhOriM9nfKaWqYeDvwL KaFgpzurjF8K094fNobbjLn+XOEuvHibIXjAtG28flrXigaENJVW41ltAh52nkxepXTp p+rw== X-Gm-Message-State: APjAAAXUji5ASqKPu/90pA1cPjLamQRX6yIbr8YFdsGhQpO2nADreMUf TqtMcgcmxHbQPbZMAWvro+h7Oy8/VQY= X-Received: by 2002:a5d:5042:: with SMTP id h2mr17004445wrt.12.1551804670254; Tue, 05 Mar 2019 08:51:10 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id 2sm10071495wrg.89.2019.03.05.08.51.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Mar 2019 08:51:09 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Tue, 5 Mar 2019 16:50:43 +0000 Message-Id: <20190305165051.26860-15-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190305165051.26860-1-peter.maydell@linaro.org> References: <20190305165051.26860-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::432 Subject: [Qemu-devel] [PULL 14/22] hw/arm/virt: Split the memory map description 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Eric Auger In the prospect to introduce an extended memory map supporting more RAM, let's split the memory map array into two parts: - the former a15memmap, renamed base_memmap, contains regions below and including the RAM. MemMapEntries initialized in this array have a static size and base address. - extended_memmap, only initialized with entries located after the RAM. MemMapEntries initialized in this array only get their size initialized. Their base address is dynamically computed depending on the the top of the RAM, with same alignment as their size. Eventually base_memmap entries are copied into the extended_memmap array. Using two separate arrays however clarifies which entries are statically allocated and those which are dynamically allocated. This new split will allow to grow the RAM size without changing the description of the high IO entries. We introduce a new virt_set_memmap() helper function which "freezes" the memory map. We call it in machvirt_init as memory attributes of the machine are not yet set when virt_instance_init() gets called. The memory map is unchanged (the top of the initial RAM still is 256GiB). Then come the high IO regions with same layout as before. Signed-off-by: Eric Auger Reviewed-by: Igor Mammedov Message-id: 20190304101339.25970-4-eric.auger@redhat.com Signed-off-by: Peter Maydell --- include/hw/arm/virt.h | 13 +++++++---- hw/arm/virt.c | 50 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 10 deletions(-) -- 2.20.1 diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h index a27086d524c..f3f7fae4acd 100644 --- a/include/hw/arm/virt.h +++ b/include/hw/arm/virt.h @@ -64,7 +64,6 @@ enum { VIRT_GIC_VCPU, VIRT_GIC_ITS, VIRT_GIC_REDIST, - VIRT_HIGH_GIC_REDIST2, VIRT_SMMU, VIRT_UART, VIRT_MMIO, @@ -74,12 +73,18 @@ enum { VIRT_PCIE_MMIO, VIRT_PCIE_PIO, VIRT_PCIE_ECAM, - VIRT_HIGH_PCIE_ECAM, VIRT_PLATFORM_BUS, - VIRT_HIGH_PCIE_MMIO, VIRT_GPIO, VIRT_SECURE_UART, VIRT_SECURE_MEM, + VIRT_LOWMEMMAP_LAST, +}; + +/* indices of IO regions located after the RAM */ +enum { + VIRT_HIGH_GIC_REDIST2 = VIRT_LOWMEMMAP_LAST, + VIRT_HIGH_PCIE_ECAM, + VIRT_HIGH_PCIE_MMIO, }; typedef enum VirtIOMMUType { @@ -116,7 +121,7 @@ typedef struct { int32_t gic_version; VirtIOMMUType iommu; struct arm_boot_info bootinfo; - const MemMapEntry *memmap; + MemMapEntry *memmap; const int *irqmap; int smp_cpus; void *fdt; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 892bae4f3a7..9596c7c7f13 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -29,6 +29,7 @@ */ #include "qemu/osdep.h" +#include "qemu/units.h" #include "qapi/error.h" #include "hw/sysbus.h" #include "hw/arm/arm.h" @@ -121,7 +122,7 @@ * Note that devices should generally be placed at multiples of 0x10000, * to accommodate guests using 64K pages. */ -static const MemMapEntry a15memmap[] = { +static const MemMapEntry base_memmap[] = { /* Space up to 0x8000000 is reserved for a boot ROM */ [VIRT_FLASH] = { 0, 0x08000000 }, [VIRT_CPUPERIPHS] = { 0x08000000, 0x00020000 }, @@ -149,11 +150,24 @@ static const MemMapEntry a15memmap[] = { [VIRT_PCIE_PIO] = { 0x3eff0000, 0x00010000 }, [VIRT_PCIE_ECAM] = { 0x3f000000, 0x01000000 }, [VIRT_MEM] = { 0x40000000, RAMLIMIT_BYTES }, +}; + +/* + * Highmem IO Regions: This memory map is floating, located after the RAM. + * Each MemMapEntry base (GPA) will be dynamically computed, depending on the + * top of the RAM, so that its base get the same alignment as the size, + * ie. a 512GiB entry will be aligned on a 512GiB boundary. If there is + * less than 256GiB of RAM, the floating area starts at the 256GiB mark. + * Note the extended_memmap is sized so that it eventually also includes the + * base_memmap entries (VIRT_HIGH_GIC_REDIST2 index is greater than the last + * index of base_memmap). + */ +static MemMapEntry extended_memmap[] = { /* Additional 64 MB redist region (can contain up to 512 redistributors) */ - [VIRT_HIGH_GIC_REDIST2] = { 0x4000000000ULL, 0x4000000 }, - [VIRT_HIGH_PCIE_ECAM] = { 0x4010000000ULL, 0x10000000 }, - /* Second PCIe window, 512GB wide at the 512GB boundary */ - [VIRT_HIGH_PCIE_MMIO] = { 0x8000000000ULL, 0x8000000000ULL }, + [VIRT_HIGH_GIC_REDIST2] = { 0x0, 64 * MiB }, + [VIRT_HIGH_PCIE_ECAM] = { 0x0, 256 * MiB }, + /* Second PCIe window */ + [VIRT_HIGH_PCIE_MMIO] = { 0x0, 512 * GiB }, }; static const int a15irqmap[] = { @@ -1354,6 +1368,29 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx) return arm_cpu_mp_affinity(idx, clustersz); } +static void virt_set_memmap(VirtMachineState *vms) +{ + hwaddr base; + int i; + + vms->memmap = extended_memmap; + + for (i = 0; i < ARRAY_SIZE(base_memmap); i++) { + vms->memmap[i] = base_memmap[i]; + } + + base = 256 * GiB; /* Top of the legacy initial RAM region */ + + for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) { + hwaddr size = extended_memmap[i].size; + + base = ROUND_UP(base, size); + vms->memmap[i].base = base; + vms->memmap[i].size = size; + base += size; + } +} + static void machvirt_init(MachineState *machine) { VirtMachineState *vms = VIRT_MACHINE(machine); @@ -1368,6 +1405,8 @@ static void machvirt_init(MachineState *machine) bool firmware_loaded = bios_name || drive_get(IF_PFLASH, 0, 0); bool aarch64 = true; + virt_set_memmap(vms); + /* We can probe only here because during property set * KVM is not available yet */ @@ -1845,7 +1884,6 @@ static void virt_instance_init(Object *obj) "Valid values are none and smmuv3", NULL); - vms->memmap = a15memmap; vms->irqmap = a15irqmap; }