From nobody Tue Dec 16 02:24:45 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525193085644140.1478545022984; Tue, 1 May 2018 09:44:45 -0700 (PDT) Received: from localhost ([::1]:45252 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDYOS-0004iX-F8 for importer@patchew.org; Tue, 01 May 2018 12:44:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55339) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDYN5-0003xB-2r for qemu-devel@nongnu.org; Tue, 01 May 2018 12:43:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDYN1-0007EY-4U for qemu-devel@nongnu.org; Tue, 01 May 2018 12:43:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45162) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fDYN0-0007DH-QX for qemu-devel@nongnu.org; Tue, 01 May 2018 12:43:15 -0400 Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA68C3003A24; Tue, 1 May 2018 16:43:13 +0000 (UTC) Received: from gimli.home (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2C254D327; Tue, 1 May 2018 16:43:06 +0000 (UTC) From: Alex Williamson To: qemu-devel@nongnu.org Date: Tue, 01 May 2018 10:43:05 -0600 Message-ID: <20180501164305.28940.50928.stgit@gimli.home> In-Reply-To: <20180501162901.28940.1075.stgit@gimli.home> References: <20180501162901.28940.1075.stgit@gimli.home> User-Agent: StGit/0.18-102-gdf9f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Tue, 01 May 2018 16:43:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/4] vfio/quirks: Add common quirk alloc helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: eric.auger@redhat.com, peterx@redhat.com, kvm@vger.kernel.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This will later be used to include list initialization. Reviewed-by: Eric Auger Reviewed-by: Peter Xu Signed-off-by: Alex Williamson --- hw/vfio/pci-quirks.c | 48 +++++++++++++++++++++-------------------------= -- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.c index e5779a7ad35b..cc3a74ed992a 100644 --- a/hw/vfio/pci-quirks.c +++ b/hw/vfio/pci-quirks.c @@ -275,6 +275,15 @@ static const MemoryRegionOps vfio_ati_3c3_quirk =3D { .endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 +static VFIOQuirk *vfio_quirk_alloc(int nr_mem) +{ + VFIOQuirk *quirk =3D g_new0(VFIOQuirk, 1); + quirk->mem =3D g_new0(MemoryRegion, nr_mem); + quirk->nr_mem =3D nr_mem; + + return quirk; +} + static void vfio_vga_probe_ati_3c3_quirk(VFIOPCIDevice *vdev) { VFIOQuirk *quirk; @@ -288,9 +297,7 @@ static void vfio_vga_probe_ati_3c3_quirk(VFIOPCIDevice = *vdev) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); - quirk->mem =3D g_new0(MemoryRegion, 1); - quirk->nr_mem =3D 1; + quirk =3D vfio_quirk_alloc(1); =20 memory_region_init_io(quirk->mem, OBJECT(vdev), &vfio_ati_3c3_quirk, v= dev, "vfio-ati-3c3-quirk", 1); @@ -323,9 +330,7 @@ static void vfio_probe_ati_bar4_quirk(VFIOPCIDevice *vd= ev, int nr) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); - quirk->mem =3D g_new0(MemoryRegion, 2); - quirk->nr_mem =3D 2; + quirk =3D vfio_quirk_alloc(2); window =3D quirk->data =3D g_malloc0(sizeof(*window) + sizeof(VFIOConfigWindowMatch)); window->vdev =3D vdev; @@ -371,10 +376,9 @@ static void vfio_probe_ati_bar2_quirk(VFIOPCIDevice *v= dev, int nr) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D vfio_quirk_alloc(1); mirror =3D quirk->data =3D g_malloc0(sizeof(*mirror)); - mirror->mem =3D quirk->mem =3D g_new0(MemoryRegion, 1); - quirk->nr_mem =3D 1; + mirror->mem =3D quirk->mem; mirror->vdev =3D vdev; mirror->offset =3D 0x4000; mirror->bar =3D nr; @@ -548,10 +552,8 @@ static void vfio_vga_probe_nvidia_3d0_quirk(VFIOPCIDev= ice *vdev) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D vfio_quirk_alloc(2); quirk->data =3D data =3D g_malloc0(sizeof(*data)); - quirk->mem =3D g_new0(MemoryRegion, 2); - quirk->nr_mem =3D 2; data->vdev =3D vdev; =20 memory_region_init_io(&quirk->mem[0], OBJECT(vdev), &vfio_nvidia_3d4_q= uirk, @@ -667,9 +669,7 @@ static void vfio_probe_nvidia_bar5_quirk(VFIOPCIDevice = *vdev, int nr) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); - quirk->mem =3D g_new0(MemoryRegion, 4); - quirk->nr_mem =3D 4; + quirk =3D vfio_quirk_alloc(4); bar5 =3D quirk->data =3D g_malloc0(sizeof(*bar5) + (sizeof(VFIOConfigWindowMatch) * 2)); window =3D &bar5->window; @@ -762,10 +762,9 @@ static void vfio_probe_nvidia_bar0_quirk(VFIOPCIDevice= *vdev, int nr) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D vfio_quirk_alloc(1); mirror =3D quirk->data =3D g_malloc0(sizeof(*mirror)); - mirror->mem =3D quirk->mem =3D g_new0(MemoryRegion, 1); - quirk->nr_mem =3D 1; + mirror->mem =3D quirk->mem; mirror->vdev =3D vdev; mirror->offset =3D 0x88000; mirror->bar =3D nr; @@ -781,10 +780,9 @@ static void vfio_probe_nvidia_bar0_quirk(VFIOPCIDevice= *vdev, int nr) =20 /* The 0x1800 offset mirror only seems to get used by legacy VGA */ if (vdev->vga) { - quirk =3D g_malloc0(sizeof(*quirk)); + quirk =3D vfio_quirk_alloc(1); mirror =3D quirk->data =3D g_malloc0(sizeof(*mirror)); - mirror->mem =3D quirk->mem =3D g_new0(MemoryRegion, 1); - quirk->nr_mem =3D 1; + mirror->mem =3D quirk->mem; mirror->vdev =3D vdev; mirror->offset =3D 0x1800; mirror->bar =3D nr; @@ -945,9 +943,7 @@ static void vfio_probe_rtl8168_bar2_quirk(VFIOPCIDevice= *vdev, int nr) return; } =20 - quirk =3D g_malloc0(sizeof(*quirk)); - quirk->mem =3D g_new0(MemoryRegion, 2); - quirk->nr_mem =3D 2; + quirk =3D vfio_quirk_alloc(2); quirk->data =3D rtl =3D g_malloc0(sizeof(*rtl)); rtl->vdev =3D vdev; =20 @@ -1507,9 +1503,7 @@ static void vfio_probe_igd_bar4_quirk(VFIOPCIDevice *= vdev, int nr) } =20 /* Setup our quirk to munge GTT addresses to the VM allocated buffer */ - quirk =3D g_malloc0(sizeof(*quirk)); - quirk->mem =3D g_new0(MemoryRegion, 2); - quirk->nr_mem =3D 2; + quirk =3D vfio_quirk_alloc(2); igd =3D quirk->data =3D g_malloc0(sizeof(*igd)); igd->vdev =3D vdev; igd->index =3D ~0;