Received: by 2002:a17:906:43c7:b0:78d:9f02:16a1 with SMTP id j7csp2783962ejn; Tue, 11 Oct 2022 16:19:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4OQlu8rvy68pwvQ3JKW5I2MsNyxd4H6VekhU8YYLzZwjqDmeIKJv0s8eQ0J7bOD6WktmXw X-Received: by 2002:a05:622a:550:b0:399:7b3c:1905 with SMTP id m16-20020a05622a055000b003997b3c1905mr11903470qtx.187.1665530362675; Tue, 11 Oct 2022 16:19:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665530362; cv=none; d=google.com; s=arc-20160816; b=0IHfeL6ubdCpNSza2mBsEK3Z6+KKHk6VWKR/9mNIqK2v4T5WiK6WsvtyQQtfniWrvl ttB6nOEOUXLOjYJp0JrgqO6IhgTxwOVwA3KAb/IQmLx0Uh/0tVKGC5L/+z3eJpa6uCbz SLVOIiq1BXjgCzlyFdf3/xZFOmon+lGFXMdlybeswDPfEv+HCiZtgRiSSFTQ5/4uHJnr inz21GmRyqROkfyP5sKAgZjzBrWzMM9BtaVNMEbGFXwFg+PX2pWfhgUkZLjixGGQNuKB z2RchtKcGEz7E+6I4QsX8Cc/HBawhbLktDxDKJ7vrqMFbtM4ogUxTA/xHJ6NdIRoCGG6 XHzw== 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:cc:to :from:dkim-signature; bh=J1StH2dMBzUeyRMEsgfoJeHQ/K4Oy05VZ1BcH9DQeqI=; b=CPG45bKQ+Pfa5YGPtFXx/YQTx9NKlooWNNMBe9lj9rymF5C7MTjpAMkFVSrydmqTFk 8rpzEWvcb0v1n7peFLlQf/b+7xgB+DiHzZtJ5RkNsuH6shQBi2i8Y9Gaz/vWTr0Ij9ng c2qZ9ZejABVwUwVF25lFqfohIddMvUQ7aPJxUitQ17t1sLXFwYlwXWbHuSZEqSOhg1C5 MeL5N3jXuEGUndRn2V64uQZCYhXIUBwXxvMinM7tSfC7hi3hdejMol8KXkYWfRwzN8SS GK6IRTv8b8hCglk+UbiRI6DLyuL5gf/tXsVZIfGbV7kU0TkosFyea46Zy6+BcI5KKxAq YJ1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="SJ7pH/n6"; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 2-20020a0562140d6200b004b3f281a29bsi5092156qvs.470.2022.10.11.16.19.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Oct 2022 16:19:22 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=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=@redhat.com header.s=mimecast20190719 header.b="SJ7pH/n6"; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:53118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oiOWv-0004Q9-Kq for alex.bennee@linaro.org; Tue, 11 Oct 2022 19:19:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiOWg-0004Ms-Ld for qemu-arm@nongnu.org; Tue, 11 Oct 2022 19:19:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:53039) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oiOWf-0006P0-3K for qemu-arm@nongnu.org; Tue, 11 Oct 2022 19:19:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665530344; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J1StH2dMBzUeyRMEsgfoJeHQ/K4Oy05VZ1BcH9DQeqI=; b=SJ7pH/n6vGvkMxwKHhY6LuT+pP+6F9qYinLvjYUsc5yryxnZwVRZh2dqp1KwBmn+OjpR7A aUss8XX3mf2pkQUaPA8mHyW9j9rCErhxY1fCfQ0LJmgy3tUawo1XIxudEFPS57EoJ211Pt PSAfG3QOwCkdrAAY41av4tAG0e9YyyU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-215-XvEBgVLnPh-Z2TbJraqIhw-1; Tue, 11 Oct 2022 19:19:03 -0400 X-MC-Unique: XvEBgVLnPh-Z2TbJraqIhw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C53808027F5; Tue, 11 Oct 2022 23:19:02 +0000 (UTC) Received: from gshan.redhat.com (vpn2-54-52.bne.redhat.com [10.64.54.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF86B2166B30; Tue, 11 Oct 2022 23:18:58 +0000 (UTC) From: Gavin Shan To: qemu-arm@nongnu.org Cc: qemu-devel@nongnu.org, maz@kernel.org, eric.auger@redhat.com, cohuck@redhat.com, zhenyzha@redhat.com, richard.henderson@linaro.org, peter.maydell@linaro.org, shan.gavin@gmail.com Subject: [PATCH v5 1/6] hw/arm/virt: Introduce virt_set_high_memmap() helper Date: Wed, 12 Oct 2022 07:18:27 +0800 Message-Id: <20221011231832.149839-2-gshan@redhat.com> In-Reply-To: <20221011231832.149839-1-gshan@redhat.com> References: <20221011231832.149839-1-gshan@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=gshan@redhat.com; helo=us-smtp-delivery-124.mimecast.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, DKIMWL_WL_HIGH=-0.001, 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-arm@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-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: KizefCOITMsP 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 Tested-by: Zhenyu Zhang --- 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 cda9defe8f..7572c44bda 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1689,6 +1689,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); @@ -1744,39 +1784,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)); -- 2.23.0