From nobody Fri Oct 24 12:48:02 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 1519850864732144.3676804572076; Wed, 28 Feb 2018 12:47:44 -0800 (PST) Received: from localhost ([::1]:46809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1er8db-0004iz-6R for importer@patchew.org; Wed, 28 Feb 2018 15:47:43 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35262) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1er8bY-0003Y6-Bg for qemu-devel@nongnu.org; Wed, 28 Feb 2018 15:45:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1er8bV-0002oT-7A for qemu-devel@nongnu.org; Wed, 28 Feb 2018 15:45:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54120) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1er8bU-0002o3-Tt for qemu-devel@nongnu.org; Wed, 28 Feb 2018 15:45:33 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B631C04BE04; Wed, 28 Feb 2018 20:45:32 +0000 (UTC) Received: from gimli.home (ovpn-117-203.phx2.redhat.com [10.3.117.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 358105F701; Wed, 28 Feb 2018 20:45:23 +0000 (UTC) From: Alex Williamson To: qemu-devel@nongnu.org Date: Wed, 28 Feb 2018 13:45:23 -0700 Message-ID: <20180228204523.26629.68401.stgit@gimli.home> In-Reply-To: <20180228201837.26629.3346.stgit@gimli.home> References: <20180228201837.26629.3346.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.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 28 Feb 2018 20:45:32 +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 1/5] 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, alex.williamson@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 Signed-off-by: Alex Williamson Reviewed-by: Peter Xu --- 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;