From nobody Wed Nov 5 05:22:25 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1532529509046281.3942087341252; Wed, 25 Jul 2018 07:38:29 -0700 (PDT) Received: from localhost ([::1]:51608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiKvr-0004Q3-0M for importer@patchew.org; Wed, 25 Jul 2018 10:38:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48519) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiKrx-00016S-4g for qemu-devel@nongnu.org; Wed, 25 Jul 2018 10:34:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fiKru-00066r-4Z for qemu-devel@nongnu.org; Wed, 25 Jul 2018 10:34:25 -0400 Received: from andre.telenet-ops.be ([2a02:1800:120:4::f00:15]:47406) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fiKrt-00065c-QV for qemu-devel@nongnu.org; Wed, 25 Jul 2018 10:34:22 -0400 Received: from ramsan.of.borg ([84.194.111.163]) by andre.telenet-ops.be with bizsmtp id F2aJ1y0033XaVaC012aJrn; Wed, 25 Jul 2018 16:34:19 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1fiKrq-00051v-5b; Wed, 25 Jul 2018 16:34:18 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1fiKrq-0002Xm-3v; Wed, 25 Jul 2018 16:34:18 +0200 From: Geert Uytterhoeven To: Peter Maydell , Alex Williamson Date: Wed, 25 Jul 2018 16:34:10 +0200 Message-Id: <20180725143413.9728-2-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180725143413.9728-1-geert+renesas@glider.be> References: <20180725143413.9728-1-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2a02:1800:120:4::f00:15 Subject: [Qemu-devel] [PATCH v3 1/4] vfio/platform: Make the vfio-platform device non-abstract 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: Laurent Pinchart , Geert Uytterhoeven , Wolfram Sang , Kieran Bingham , Magnus Damm , qemu-devel@nongnu.org, linux-renesas-soc@vger.kernel.org, Auger Eric , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Auger Eric Up to now the vfio-platform device has been abstract and could not be instantiated. The integration of a new vfio platform device required creating a dummy derived device which only set the compatible string. Following the few vfio-platform device integrations we have seen the actual requested adaptation happens on device tree node creation (sysbus-fdt). Hence remove the abstract setting, and read the list of compatible values from sysfs if not set by a derived device. Update the amd-xgbe and calxeda-xgmac drivers to fill in the number of compatible values, as there can now be more than one. Note that sysbus-fdt does not support the instantiation of the vfio-platform device yet. Signed-off-by: Eric Auger [geert: Rebase, set user_creatable=3Dtrue, use compatible values in sysfs instead of user-supplied manufacturer/model options, reword] Signed-off-by: Geert Uytterhoeven --- v3: - Read all compatible values from sysfs instead of using user-supplied manufacturer and model options, - Reword patch description, - Drop RFC state, v2: - No changes, v1: - Rebase, Set user_creatable=3Dtrue, v0: - Original version from Eric. --- hw/vfio/amd-xgbe.c | 1 + hw/vfio/calxeda-xgmac.c | 1 + hw/vfio/platform.c | 22 +++++++++++++++++++++- include/hw/vfio/vfio-platform.h | 3 ++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/hw/vfio/amd-xgbe.c b/hw/vfio/amd-xgbe.c index 0c4ec4ba25170366..ee64a3b4a2e45bf5 100644 --- a/hw/vfio/amd-xgbe.c +++ b/hw/vfio/amd-xgbe.c @@ -20,6 +20,7 @@ static void amd_xgbe_realize(DeviceState *dev, Error **er= rp) VFIOAmdXgbeDeviceClass *k =3D VFIO_AMD_XGBE_DEVICE_GET_CLASS(dev); =20 vdev->compat =3D g_strdup("amd,xgbe-seattle-v1a"); + vdev->num_compat =3D 1; =20 k->parent_realize(dev, errp); } diff --git a/hw/vfio/calxeda-xgmac.c b/hw/vfio/calxeda-xgmac.c index 24cee6d06512c1b6..e7767c4b021be566 100644 --- a/hw/vfio/calxeda-xgmac.c +++ b/hw/vfio/calxeda-xgmac.c @@ -20,6 +20,7 @@ static void calxeda_xgmac_realize(DeviceState *dev, Error= **errp) VFIOCalxedaXgmacDeviceClass *k =3D VFIO_CALXEDA_XGMAC_DEVICE_GET_CLASS= (dev); =20 vdev->compat =3D g_strdup("calxeda,hb-xgmac"); + vdev->num_compat =3D 1; =20 k->parent_realize(dev, errp); } diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 57c4a0ee2b58da70..e264555cd5dafb16 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -655,6 +655,25 @@ static void vfio_platform_realize(DeviceState *dev, Er= ror **errp) goto out; } =20 + if (!vdev->compat) { + gchar *contents; + gsize length; + char *tmp; + + tmp =3D g_strdup_printf("%s/of_node/compatible", vbasedev->sysfsde= v); + if (!g_file_get_contents(tmp, &contents, &length, NULL)) { + error_report("failed to load \"%s\"", tmp); + exit(1); + } + g_free(tmp); + vdev->compat =3D contents; + for (vdev->num_compat =3D 0; length; vdev->num_compat++) { + size_t skip =3D strlen(contents) + 1; + contents +=3D skip; + length -=3D skip; + } + } + for (i =3D 0; i < vbasedev->num_regions; i++) { if (vfio_region_mmap(vdev->regions[i])) { error_report("%s mmap unsupported. Performance may be slow", @@ -700,6 +719,8 @@ static void vfio_platform_class_init(ObjectClass *klass= , void *data) dc->desc =3D "VFIO-based platform device assignment"; sbc->connect_irq_notifier =3D vfio_start_irqfd_injection; set_bit(DEVICE_CATEGORY_MISC, dc->categories); + /* Supported by TYPE_VIRT_MACHINE */ + dc->user_creatable =3D true; } =20 static const TypeInfo vfio_platform_dev_info =3D { @@ -708,7 +729,6 @@ static const TypeInfo vfio_platform_dev_info =3D { .instance_size =3D sizeof(VFIOPlatformDevice), .class_init =3D vfio_platform_class_init, .class_size =3D sizeof(VFIOPlatformDeviceClass), - .abstract =3D true, }; =20 static void register_vfio_platform_dev_type(void) diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platfor= m.h index 9baaa2db09b84f3e..0ee10b1d71ed2503 100644 --- a/include/hw/vfio/vfio-platform.h +++ b/include/hw/vfio/vfio-platform.h @@ -54,7 +54,8 @@ typedef struct VFIOPlatformDevice { QLIST_HEAD(, VFIOINTp) intp_list; /* list of IRQs */ /* queue of pending IRQs */ QSIMPLEQ_HEAD(pending_intp_queue, VFIOINTp) pending_intp_queue; - char *compat; /* compatibility string */ + char *compat; /* DT compatible values, separated by NUL */ + unsigned int num_compat; /* number of compatible values */ uint32_t mmap_timeout; /* delay to re-enable mmaps after interrupt */ QEMUTimer *mmap_timer; /* allows fast-path resume after IRQ hit */ QemuMutex intp_mutex; /* protect the intp_list IRQ state */ --=20 2.17.1