7f1c5b
From a2ddd68c8365ec602db6b2a9cf83bb441ca701cc Mon Sep 17 00:00:00 2001
7f1c5b
From: Gavin Shan <gshan@redhat.com>
7f1c5b
Date: Wed, 21 Dec 2022 08:48:45 +0800
7f1c5b
Subject: [PATCH 4/8] hw/arm/virt: Introduce virt_get_high_memmap_enabled()
7f1c5b
 helper
7f1c5b
7f1c5b
RH-Author: Gavin Shan <gshan@redhat.com>
7f1c5b
RH-MergeRequest: 126: hw/arm/virt: Optimize high memory region address assignment
7f1c5b
RH-Bugzilla: 2113840
7f1c5b
RH-Acked-by: Eric Auger <eric.auger@redhat.com>
7f1c5b
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
7f1c5b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7f1c5b
RH-Commit: [4/8] 65524de2fc106600bbaff641caa8c4f2f8027114
7f1c5b
7f1c5b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2113840
7f1c5b
7f1c5b
This introduces virt_get_high_memmap_enabled() helper, which returns
7f1c5b
the pointer to vms->highmem_{redists, ecam, mmio}. The pointer will
7f1c5b
be used in the subsequent patches.
7f1c5b
7f1c5b
No functional change intended.
7f1c5b
7f1c5b
Signed-off-by: Gavin Shan <gshan@redhat.com>
7f1c5b
Reviewed-by: Eric Auger <eric.auger@redhat.com>
7f1c5b
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
7f1c5b
Reviewed-by: Marc Zyngier <maz@kernel.org>
7f1c5b
Tested-by: Zhenyu Zhang <zhenyzha@redhat.com>
7f1c5b
Message-id: 20221029224307.138822-5-gshan@redhat.com
7f1c5b
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
7f1c5b
(cherry picked from commit a5cb1350b19a5c2a58ab4edddf609ed429c13085)
7f1c5b
Signed-off-by: Gavin Shan <gshan@redhat.com>
7f1c5b
---
7f1c5b
 hw/arm/virt.c | 32 +++++++++++++++++++-------------
7f1c5b
 1 file changed, 19 insertions(+), 13 deletions(-)
7f1c5b
7f1c5b
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
7f1c5b
index ddcf7ee2f8..6e3b9fc060 100644
7f1c5b
--- a/hw/arm/virt.c
7f1c5b
+++ b/hw/arm/virt.c
7f1c5b
@@ -1736,14 +1736,31 @@ static uint64_t virt_cpu_mp_affinity(VirtMachineState *vms, int idx)
7f1c5b
     return arm_cpu_mp_affinity(idx, clustersz);
7f1c5b
 }
7f1c5b
 
7f1c5b
+static inline bool *virt_get_high_memmap_enabled(VirtMachineState *vms,
7f1c5b
+                                                 int index)
7f1c5b
+{
7f1c5b
+    bool *enabled_array[] = {
7f1c5b
+        &vms->highmem_redists,
7f1c5b
+        &vms->highmem_ecam,
7f1c5b
+        &vms->highmem_mmio,
7f1c5b
+    };
7f1c5b
+
7f1c5b
+    assert(ARRAY_SIZE(extended_memmap) - VIRT_LOWMEMMAP_LAST ==
7f1c5b
+           ARRAY_SIZE(enabled_array));
7f1c5b
+    assert(index - VIRT_LOWMEMMAP_LAST < ARRAY_SIZE(enabled_array));
7f1c5b
+
7f1c5b
+    return enabled_array[index - VIRT_LOWMEMMAP_LAST];
7f1c5b
+}
7f1c5b
+
7f1c5b
 static void virt_set_high_memmap(VirtMachineState *vms,
7f1c5b
                                  hwaddr base, int pa_bits)
7f1c5b
 {
7f1c5b
     hwaddr region_base, region_size;
7f1c5b
-    bool fits;
7f1c5b
+    bool *region_enabled, fits;
7f1c5b
     int i;
7f1c5b
 
7f1c5b
     for (i = VIRT_LOWMEMMAP_LAST; i < ARRAY_SIZE(extended_memmap); i++) {
7f1c5b
+        region_enabled = virt_get_high_memmap_enabled(vms, i);
7f1c5b
         region_base = ROUND_UP(base, extended_memmap[i].size);
7f1c5b
         region_size = extended_memmap[i].size;
7f1c5b
 
7f1c5b
@@ -1761,18 +1778,7 @@ static void virt_set_high_memmap(VirtMachineState *vms,
7f1c5b
             vms->highest_gpa = region_base + region_size - 1;
7f1c5b
         }
7f1c5b
 
7f1c5b
-        switch (i) {
7f1c5b
-        case VIRT_HIGH_GIC_REDIST2:
7f1c5b
-            vms->highmem_redists &= fits;
7f1c5b
-            break;
7f1c5b
-        case VIRT_HIGH_PCIE_ECAM:
7f1c5b
-            vms->highmem_ecam &= fits;
7f1c5b
-            break;
7f1c5b
-        case VIRT_HIGH_PCIE_MMIO:
7f1c5b
-            vms->highmem_mmio &= fits;
7f1c5b
-            break;
7f1c5b
-        }
7f1c5b
-
7f1c5b
+        *region_enabled &= fits;
7f1c5b
         base = region_base + region_size;
7f1c5b
     }
7f1c5b
 }
7f1c5b
-- 
7f1c5b
2.31.1
7f1c5b