thebeanogamer / rpms / qemu-kvm

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