thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ae23c9
From e8b5f27c84d9a7e1b1b18b2a472a1500711da828 Mon Sep 17 00:00:00 2001
ae23c9
From: David Gibson <dgibson@redhat.com>
ae23c9
Date: Thu, 30 May 2019 04:37:26 +0100
ae23c9
Subject: [PATCH 5/8] vfio/quirks: Add common quirk alloc helper
ae23c9
MIME-Version: 1.0
ae23c9
Content-Type: text/plain; charset=UTF-8
ae23c9
Content-Transfer-Encoding: 8bit
ae23c9
ae23c9
RH-Author: David Gibson <dgibson@redhat.com>
ae23c9
Message-id: <20190530043728.32575-5-dgibson@redhat.com>
ae23c9
Patchwork-id: 88422
ae23c9
O-Subject: [RHEL-8.1 qemu-kvm PATCH 4/6] vfio/quirks: Add common quirk alloc helper
ae23c9
Bugzilla: 1710662
ae23c9
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
ae23c9
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ae23c9
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
ae23c9
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
ae23c9
ae23c9
From: Alex Williamson <alex.williamson@redhat.com>
ae23c9
ae23c9
This will later be used to include list initialization.
ae23c9
ae23c9
Reviewed-by: Eric Auger <eric.auger@redhat.com>
ae23c9
Reviewed-by: Peter Xu <peterx@redhat.com>
ae23c9
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
ae23c9
(cherry picked from commit bcf3c3d029e73d54455e1d7a51177c37d668378c)
ae23c9
ae23c9
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1710662
ae23c9
ae23c9
Signed-off-by: David Gibson <dgibson@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 hw/vfio/pci-quirks.c | 48 +++++++++++++++++++++---------------------------
ae23c9
 1 file changed, 21 insertions(+), 27 deletions(-)
ae23c9
ae23c9
diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c
ae23c9
index 90859d1..92457ed 100644
ae23c9
--- a/hw/vfio/pci-quirks.c
ae23c9
+++ b/hw/vfio/pci-quirks.c
ae23c9
@@ -275,6 +275,15 @@ static const MemoryRegionOps vfio_ati_3c3_quirk = {
ae23c9
     .endianness = DEVICE_LITTLE_ENDIAN,
ae23c9
 };
ae23c9
 
ae23c9
+static VFIOQuirk *vfio_quirk_alloc(int nr_mem)
ae23c9
+{
ae23c9
+    VFIOQuirk *quirk = g_new0(VFIOQuirk, 1);
ae23c9
+    quirk->mem = g_new0(MemoryRegion, nr_mem);
ae23c9
+    quirk->nr_mem = nr_mem;
ae23c9
+
ae23c9
+    return quirk;
ae23c9
+}
ae23c9
+
ae23c9
 static void vfio_vga_probe_ati_3c3_quirk(VFIOPCIDevice *vdev)
ae23c9
 {
ae23c9
     VFIOQuirk *quirk;
ae23c9
@@ -288,9 +297,7 @@ static void vfio_vga_probe_ati_3c3_quirk(VFIOPCIDevice *vdev)
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    quirk = g_malloc0(sizeof(*quirk));
ae23c9
-    quirk->mem = g_new0(MemoryRegion, 1);
ae23c9
-    quirk->nr_mem = 1;
ae23c9
+    quirk = vfio_quirk_alloc(1);
ae23c9
 
ae23c9
     memory_region_init_io(quirk->mem, OBJECT(vdev), &vfio_ati_3c3_quirk, vdev,
ae23c9
                           "vfio-ati-3c3-quirk", 1);
ae23c9
@@ -323,9 +330,7 @@ static void vfio_probe_ati_bar4_quirk(VFIOPCIDevice *vdev, int nr)
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    quirk = g_malloc0(sizeof(*quirk));
ae23c9
-    quirk->mem = g_new0(MemoryRegion, 2);
ae23c9
-    quirk->nr_mem = 2;
ae23c9
+    quirk = vfio_quirk_alloc(2);
ae23c9
     window = quirk->data = g_malloc0(sizeof(*window) +
ae23c9
                                      sizeof(VFIOConfigWindowMatch));
ae23c9
     window->vdev = vdev;
ae23c9
@@ -371,10 +376,9 @@ static void vfio_probe_ati_bar2_quirk(VFIOPCIDevice *vdev, int nr)
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    quirk = g_malloc0(sizeof(*quirk));
ae23c9
+    quirk = vfio_quirk_alloc(1);
ae23c9
     mirror = quirk->data = g_malloc0(sizeof(*mirror));
ae23c9
-    mirror->mem = quirk->mem = g_new0(MemoryRegion, 1);
ae23c9
-    quirk->nr_mem = 1;
ae23c9
+    mirror->mem = quirk->mem;
ae23c9
     mirror->vdev = vdev;
ae23c9
     mirror->offset = 0x4000;
ae23c9
     mirror->bar = nr;
ae23c9
@@ -546,10 +550,8 @@ static void vfio_vga_probe_nvidia_3d0_quirk(VFIOPCIDevice *vdev)
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    quirk = g_malloc0(sizeof(*quirk));
ae23c9
+    quirk = vfio_quirk_alloc(2);
ae23c9
     quirk->data = data = g_malloc0(sizeof(*data));
ae23c9
-    quirk->mem = g_new0(MemoryRegion, 2);
ae23c9
-    quirk->nr_mem = 2;
ae23c9
     data->vdev = vdev;
ae23c9
 
ae23c9
     memory_region_init_io(&quirk->mem[0], OBJECT(vdev), &vfio_nvidia_3d4_quirk,
ae23c9
@@ -665,9 +667,7 @@ static void vfio_probe_nvidia_bar5_quirk(VFIOPCIDevice *vdev, int nr)
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    quirk = g_malloc0(sizeof(*quirk));
ae23c9
-    quirk->mem = g_new0(MemoryRegion, 4);
ae23c9
-    quirk->nr_mem = 4;
ae23c9
+    quirk = vfio_quirk_alloc(4);
ae23c9
     bar5 = quirk->data = g_malloc0(sizeof(*bar5) +
ae23c9
                                    (sizeof(VFIOConfigWindowMatch) * 2));
ae23c9
     window = &bar5->window;
ae23c9
@@ -760,10 +760,9 @@ static void vfio_probe_nvidia_bar0_quirk(VFIOPCIDevice *vdev, int nr)
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    quirk = g_malloc0(sizeof(*quirk));
ae23c9
+    quirk = vfio_quirk_alloc(1);
ae23c9
     mirror = quirk->data = g_malloc0(sizeof(*mirror));
ae23c9
-    mirror->mem = quirk->mem = g_new0(MemoryRegion, 1);
ae23c9
-    quirk->nr_mem = 1;
ae23c9
+    mirror->mem = quirk->mem;
ae23c9
     mirror->vdev = vdev;
ae23c9
     mirror->offset = 0x88000;
ae23c9
     mirror->bar = nr;
ae23c9
@@ -779,10 +778,9 @@ static void vfio_probe_nvidia_bar0_quirk(VFIOPCIDevice *vdev, int nr)
ae23c9
 
ae23c9
     /* The 0x1800 offset mirror only seems to get used by legacy VGA */
ae23c9
     if (vdev->vga) {
ae23c9
-        quirk = g_malloc0(sizeof(*quirk));
ae23c9
+        quirk = vfio_quirk_alloc(1);
ae23c9
         mirror = quirk->data = g_malloc0(sizeof(*mirror));
ae23c9
-        mirror->mem = quirk->mem = g_new0(MemoryRegion, 1);
ae23c9
-        quirk->nr_mem = 1;
ae23c9
+        mirror->mem = quirk->mem;
ae23c9
         mirror->vdev = vdev;
ae23c9
         mirror->offset = 0x1800;
ae23c9
         mirror->bar = nr;
ae23c9
@@ -943,9 +941,7 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDevice *vdev, int nr)
ae23c9
         return;
ae23c9
     }
ae23c9
 
ae23c9
-    quirk = g_malloc0(sizeof(*quirk));
ae23c9
-    quirk->mem = g_new0(MemoryRegion, 2);
ae23c9
-    quirk->nr_mem = 2;
ae23c9
+    quirk = vfio_quirk_alloc(2);
ae23c9
     quirk->data = rtl = g_malloc0(sizeof(*rtl));
ae23c9
     rtl->vdev = vdev;
ae23c9
 
ae23c9
@@ -1510,9 +1506,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *vdev, int nr)
ae23c9
     }
ae23c9
 
ae23c9
     /* Setup our quirk to munge GTT addresses to the VM allocated buffer */
ae23c9
-    quirk = g_malloc0(sizeof(*quirk));
ae23c9
-    quirk->mem = g_new0(MemoryRegion, 2);
ae23c9
-    quirk->nr_mem = 2;
ae23c9
+    quirk = vfio_quirk_alloc(2);
ae23c9
     igd = quirk->data = g_malloc0(sizeof(*igd));
ae23c9
     igd->vdev = vdev;
ae23c9
     igd->index = ~0;
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9