From patchwork Thu Dec 15 12:49:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 634178 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp127225pvb; Thu, 15 Dec 2022 04:50:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf44h/KxVjcp9FJxcJ+TDiQkHGrbGxkxYw0VjMa2jPEHe3s1EInbYIkMsYCrgh2hC1m7w/fZ X-Received: by 2002:ac8:6b96:0:b0:3a7:e1aa:727c with SMTP id z22-20020ac86b96000000b003a7e1aa727cmr16194480qts.17.1671108655920; Thu, 15 Dec 2022 04:50:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671108655; cv=none; d=google.com; s=arc-20160816; b=xq3JAuTX5lOCsdCsCDdXI7vQrSyP50brHJzY/7vmEoEer6PqatACP4khNPykU/3OsK KT63Krveado6s7u/gWHimXVK6jXgskbyAo0UIozHThTvbzu6vpt5AGWY00DsgZTLDfyX Mt4Mww5BWXGaQC4vFUUMZ0mXki0ifkPR1aNJusbqi5fT4YznK/OO+yqUmamWOV2bQBK1 TCsDfn9KMTJPuhsBqQqU5p6TKHEsm/GzP9JxGoAPKB4Bf9LYtVyAkqVDcTAKkmEVVsZl t/E1RpDJzeCtr/vaFc323dv0t6YDHasB4Ez3KYXC4dTxdDQhhdOdPR6mnwBrweaakhE2 DckQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=ju1JwZIZJKkp9vxG0wSz+KQOFubdrSKxVCNw3F2ffWI=; b=vI6rvAoRzFxOWziqj/CONU2rCvCOzGITWdlV2y/M4msVTldz+xO/353SJH0Pd24d9k zUy4JCamo4B2VtUIgH46hOsUTDa49BxHsJFJ8m1EZkS3e57DEbmC29jZsPCNTUg1X45f xNvWl1neUk6k1Oopp9HTZltv1r2gvGz2KXxu4Tc0929bYz+VQHvp1OckeVjx005OoQvY 0xI/lsBlHmRoCi/+8qiSP6FG++TN8CTBEVM8yFwunRFi+VuyGVHKq8ejpmBrE2kOF1KK 16R5poZ9qqcN3/Y7V2g4ES8dw+BN1ZL6ypCrd+6+mvIe3DokdikUrUj//E8+M132hvjO u/wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PhlrbVKP; 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=pass (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 bb26-20020a05622a1b1a00b003a4f242dc2asi3814136qtb.362.2022.12.15.04.50.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 15 Dec 2022 04:50:55 -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=pass header.i=@linaro.org header.s=google header.b=PhlrbVKP; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5ngo-0006cT-Jc; Thu, 15 Dec 2022 07:50:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5ngm-0006bR-I7 for qemu-devel@nongnu.org; Thu, 15 Dec 2022 07:50:16 -0500 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p5ngk-00045d-My for qemu-devel@nongnu.org; Thu, 15 Dec 2022 07:50:16 -0500 Received: by mail-wm1-x32c.google.com with SMTP id ay40so13692699wmb.2 for ; Thu, 15 Dec 2022 04:50:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ju1JwZIZJKkp9vxG0wSz+KQOFubdrSKxVCNw3F2ffWI=; b=PhlrbVKPT/nhEmw0NdU9d6pGH4LXOM+6xrBipphNrZ77/wAOXT1BTNK+qkOTNTa5Lp Y51aq5x4UdQ0UFvMdKp9OWazp7LFPXtId3L+tQSTW5SgwDV+rrWI+tWD98pYshqO+j/B jQBI5MA5LI4E46CUHsYgBRtH9NyU+qIGgJSMGv7YwqZjB8XzaKdOuiMU0QRP3FNt2VLX H/bz22HopGyLcJUoLFoCx8DkjQf3DUhAjuRRRSEuCO7qbl2pNxh8X6BvEt8YmYJkZ4Fc U+bjx46w8q6lIounv3YY8lX4Sci3bEAOS3yYjtA1TyKxs+QNkIEjjktWZPvseRVwVpII pEpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ju1JwZIZJKkp9vxG0wSz+KQOFubdrSKxVCNw3F2ffWI=; b=TCGG4CthtSWORtryFXUlmAwkQ3w1Tz81iGWq/3Wpkh8CXWF8n/50+132z/++HajRMr iPUCl4CcqBcQBnNUy+qNXNuZgsJAs/GBj1cOSAI6IRR3GqpnnloOoweErJ8F1ELdHoay J/p9kWjz6rx9/I4D2/opK/2jRfzopaGxT7NHBzXqZKwD9Zr1LtnyGbaTE1IRHmImomlx SrO1AcYlZ2EMLa9Kco3rZb1Ospq34oAHOFi2raOINTtAReHIlpjpMpNnZYdpMEC2a1xX Qgg1/ETgpPW1F4FMNjgRnmobjF3GkgHmUXvfJ8U1V+995KFZ4anFMFwFqPX7+hBM8y4P GrlA== X-Gm-Message-State: ANoB5pleh9r58ol1Nj+PqISw7i5RyTPp/Y7KRNGli/UDM9LMCffAAqVI QGX77YYA2o7CDBwcF77lka94Cr1WJqfF9HkK X-Received: by 2002:a05:600c:348a:b0:3cf:69f4:bfd4 with SMTP id a10-20020a05600c348a00b003cf69f4bfd4mr22077956wmq.7.1671108613328; Thu, 15 Dec 2022 04:50:13 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id i12-20020a05600c354c00b003cfd64b6be1sm8388787wmq.27.2022.12.15.04.50.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 04:50:12 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 01/29] hw/arm/virt: Introduce virt_set_high_memmap() helper Date: Thu, 15 Dec 2022 12:49:41 +0000 Message-Id: <20221215125009.980128-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221215125009.980128-1-peter.maydell@linaro.org> References: <20221215125009.980128-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32c; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org From: Gavin Shan This introduces virt_set_high_memmap() helper. The logic of high memory region address assignment is moved to the helper. The intention is to make the subsequent optimization for high memory region address assignment easier. No functional change intended. Signed-off-by: Gavin Shan Reviewed-by: Eric Auger Reviewed-by: Cornelia Huck Reviewed-by: Marc Zyngier Tested-by: Zhenyu Zhang Message-id: 20221029224307.138822-2-gshan@redhat.com Signed-off-by: Peter Maydell --- hw/arm/virt.c | 74 ++++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index b8713508561..ca300281939 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1690,6 +1690,46 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx) return arm_cpu_mp_affinity(idx, clustersz); } +static void virt_set_high_memmap(VirtMachineState *vms, + hwaddr base, int pa_bits) +{ + int i; + + for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) { + hwaddr size = extended_memmap[i].size; + bool fits; + + base = ROUND_UP(base, size); + vms->memmap[i].base = base; + vms->memmap[i].size = size; + + /* + * Check each device to see if they fit in the PA space, + * moving highest_gpa as we go. + * + * For each device that doesn't fit, disable it. + */ + fits = (base + size) <= BIT_ULL(pa_bits); + if (fits) { + vms->highest_gpa = base + size - 1; + } + + switch (i) { + case VIRT_HIGH_GIC_REDIST2: + vms->highmem_redists &= fits; + break; + case VIRT_HIGH_PCIE_ECAM: + vms->highmem_ecam &= fits; + break; + case VIRT_HIGH_PCIE_MMIO: + vms->highmem_mmio &= fits; + break; + } + + base += size; + } +} + static void virt_set_memmap(VirtMachineState *vms, int pa_bits) { MachineState *ms = MACHINE(vms); @@ -1745,39 +1785,7 @@ static void virt_set_memmap(VirtMachineState *vms, int pa_bits) /* We know for sure that at least the memory fits in the PA space */ vms->highest_gpa = memtop - 1; - for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) { - hwaddr size = extended_memmap[i].size; - bool fits; - - base = ROUND_UP(base, size); - vms->memmap[i].base = base; - vms->memmap[i].size = size; - - /* - * Check each device to see if they fit in the PA space, - * moving highest_gpa as we go. - * - * For each device that doesn't fit, disable it. - */ - fits = (base + size) <= BIT_ULL(pa_bits); - if (fits) { - vms->highest_gpa = base + size - 1; - } - - switch (i) { - case VIRT_HIGH_GIC_REDIST2: - vms->highmem_redists &= fits; - break; - case VIRT_HIGH_PCIE_ECAM: - vms->highmem_ecam &= fits; - break; - case VIRT_HIGH_PCIE_MMIO: - vms->highmem_mmio &= fits; - break; - } - - base += size; - } + virt_set_high_memmap(vms, base, pa_bits); if (device_memory_size > 0) { ms->device_memory = g_malloc0(sizeof(*ms->device_memory));