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