From nobody Fri May 3 21:55:05 2024 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 1518198067974308.4663789368832; Fri, 9 Feb 2018 09:41:07 -0800 (PST) Received: from localhost ([::1]:49375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekCfb-0003ZK-31 for importer@patchew.org; Fri, 09 Feb 2018 12:41:07 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekBDa-0007MB-MR for qemu-devel@nongnu.org; Fri, 09 Feb 2018 11:08:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekBDY-0001Ft-DJ for qemu-devel@nongnu.org; Fri, 09 Feb 2018 11:08:06 -0500 Received: from leibniz.telenet-ops.be ([2a02:1800:110:4::f00:d]:34040) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekBDX-0001Es-VG for qemu-devel@nongnu.org; Fri, 09 Feb 2018 11:08:04 -0500 Received: from andre.telenet-ops.be (andre.telenet-ops.be [IPv6:2a02:1800:120:4::f00:15]) by leibniz.telenet-ops.be (Postfix) with ESMTPS id 3zdJwl3ZK2zMqgCS for ; Fri, 9 Feb 2018 16:32:55 +0100 (CET) Received: from ayla.of.borg ([84.194.111.163]) by andre.telenet-ops.be with bizsmtp id 8fHm1x02J3XaVaC01fHmfz; Fri, 09 Feb 2018 16:17:50 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1ekAQs-0003Rv-Mv; Fri, 09 Feb 2018 16:17:46 +0100 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1ekAQs-0000lF-M2; Fri, 09 Feb 2018 16:17:46 +0100 From: Geert Uytterhoeven To: Peter Maydell , Alex Williamson Date: Fri, 9 Feb 2018 16:17:32 +0100 Message-Id: <1518189456-2873-2-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> References: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:1800:110:4::f00:d X-Mailman-Approved-At: Fri, 09 Feb 2018 12:38:16 -0500 Subject: [Qemu-devel] [PATCH/RFC 1/5] 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: Geert Uytterhoeven , Arnd Bergmann , Wolfram Sang , Magnus Damm , Alexander Graf , qemu-devel@nongnu.org, linux-renesas-soc@vger.kernel.org, Auger Eric , qemu-arm@nongnu.org, Laurent Pinchart , Xiao Feng Ren 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 to create a dummy derived device which only set the compatibility string. Following the few vfio-platform device integration we have seen the actual requested adaptation happens on device tree node creation (sysbus-fdt). So this patch removes the abstract setting and defines 2 new options, manufacturer and model that are used to build a compatibility string. This latter will be used to match the device tree node creation function sysbus-fdt does not support the instantiation of the vfio-platform device yet. Signed-off-by: Eric Auger [geert: Rebase, Set user_creatable=3Dtrue] Signed-off-by: Geert Uytterhoeven --- hw/vfio/platform.c | 20 ++++++++++++++++++-- include/hw/vfio/vfio-platform.h | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index 0d4bc0aae8891435..32bed1974e23c569 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -637,7 +637,20 @@ static void vfio_platform_realize(DeviceState *dev, Er= ror **errp) VFIOPlatformDevice *vdev =3D VFIO_PLATFORM_DEVICE(dev); SysBusDevice *sbdev =3D SYS_BUS_DEVICE(dev); VFIODevice *vbasedev =3D &vdev->vbasedev; - int i, ret; + int i, ret =3D -EINVAL; + + if (!vdev->compat) { + if (!vdev->model) { + error_setg(errp, "no usable compatible string"); + goto out; + } + if (!vdev->manufacturer) { + vdev->compat =3D g_strdup(vdev->model); + } else { + vdev->compat =3D g_strjoin(",", vdev->manufacturer, + vdev->model, NULL); + } + } =20 vbasedev->type =3D VFIO_DEVICE_TYPE_PLATFORM; vbasedev->dev =3D dev; @@ -681,6 +694,8 @@ static const VMStateDescription vfio_platform_vmstate = =3D { static Property vfio_platform_dev_properties[] =3D { DEFINE_PROP_STRING("host", VFIOPlatformDevice, vbasedev.name), DEFINE_PROP_STRING("sysfsdev", VFIOPlatformDevice, vbasedev.sysfsdev), + DEFINE_PROP_STRING("manufacturer", VFIOPlatformDevice, manufacturer), + DEFINE_PROP_STRING("model", VFIOPlatformDevice, model), DEFINE_PROP_BOOL("x-no-mmap", VFIOPlatformDevice, vbasedev.no_mmap, fa= lse), DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice, mmap_timeout, 1100), @@ -699,6 +714,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 { @@ -707,7 +724,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..31b9a9800f7d9d00 100644 --- a/include/hw/vfio/vfio-platform.h +++ b/include/hw/vfio/vfio-platform.h @@ -55,6 +55,8 @@ typedef struct VFIOPlatformDevice { /* queue of pending IRQs */ QSIMPLEQ_HEAD(pending_intp_queue, VFIOINTp) pending_intp_queue; char *compat; /* compatibility string */ + char *manufacturer; /* manufacturer (1st part of the compatible proper= ty) */ + char *model; /* model (2d part of the compatible property) */ 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.7.4 From nobody Fri May 3 21:55:05 2024 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 1518198672133172.25040793913843; Fri, 9 Feb 2018 09:51:12 -0800 (PST) Received: from localhost ([::1]:49873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekCpG-0003nQ-TM for importer@patchew.org; Fri, 09 Feb 2018 12:51:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekAyP-0001XS-8Z for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekAyM-0007he-5X for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:25 -0500 Received: from newton.telenet-ops.be ([195.130.132.45]:48752) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekAyL-0007gw-U1 for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:22 -0500 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by newton.telenet-ops.be (Postfix) with ESMTPS id 3zdJwl22mVzMqw1W for ; Fri, 9 Feb 2018 16:32:55 +0100 (CET) Received: from ayla.of.borg ([84.194.111.163]) by laurent.telenet-ops.be with bizsmtp id 8fHm1x02Y3XaVaC01fHmCl; Fri, 09 Feb 2018 16:17:50 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1ekAQs-0003Rz-OW; Fri, 09 Feb 2018 16:17:46 +0100 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1ekAQs-0000lK-Mj; Fri, 09 Feb 2018 16:17:46 +0100 From: Geert Uytterhoeven To: Peter Maydell , Alex Williamson Date: Fri, 9 Feb 2018 16:17:33 +0100 Message-Id: <1518189456-2873-3-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> References: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.130.132.45 X-Mailman-Approved-At: Fri, 09 Feb 2018 12:38:16 -0500 Subject: [Qemu-devel] [PATCH/RFC 2/5] hw/arm/sysbus-fdt: Allow device matching with compat string 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: Geert Uytterhoeven , Arnd Bergmann , Wolfram Sang , Magnus Damm , Alexander Graf , qemu-devel@nongnu.org, linux-renesas-soc@vger.kernel.org, Auger Eric , qemu-arm@nongnu.org, Laurent Pinchart , Xiao Feng Ren 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 we have relied on the device type to identify a device tree node creation function. Since we would like the VFIO-PLATFORM device to be instantiable with different compatibility strings we introduce the capability to specialize the node creation depending on a manufacturer/model combo. NodeCreationPair is renamed into BindingEntry. The struct is enhanced with manufacturer, model and match_fn() fields. We introduce a new matching function adapted to vfio-platform generic device. From now on, the AMD XGBE can be instantiated with either manner, ie: -device vfio-amd-xgbe,host=3De0900000.xgmac or new option line: -device vfio-platform,host=3De0900000.xgmac,manufacturer=3Damd,model=3Dxgbe= -seattle-v1a Signed-off-by: Eric Auger Signed-off-by: Geert Uytterhoeven --- hw/arm/sysbus-fdt.c | 61 +++++++++++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index d68e3dcdbd260895..c5d4fd5604c28118 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -58,11 +58,14 @@ typedef struct PlatformBusFDTNotifierParams { ARMPlatformBusFDTParams *fdt_params; } PlatformBusFDTNotifierParams; =20 -/* struct that associates a device type name and a node creation function = */ -typedef struct NodeCreationPair { +/* struct that allows to match a device and create its FDT node */ +typedef struct BindingEntry { const char *typename; - int (*add_fdt_node_fn)(SysBusDevice *sbdev, void *opaque); -} NodeCreationPair; + const char *manufacturer; + const char *model; + int (*add_fn)(SysBusDevice *sbdev, void *opaque); + bool (*match_fn)(SysBusDevice *sbdev, const struct BindingEntry *combo= ); +} BindingEntry; =20 /* helpers */ =20 @@ -413,15 +416,46 @@ static int add_amd_xgbe_fdt_node(SysBusDevice *sbdev,= void *opaque) return 0; } =20 +/* manufacturer/model matching */ +static bool vfio_platform_match(SysBusDevice *sbdev, + const BindingEntry *entry) +{ + VFIOPlatformDevice *vdev =3D VFIO_PLATFORM_DEVICE(sbdev); + + if (strcmp(entry->model, vdev->model)) { + return false; + } + + if (entry->manufacturer) { + if (!vdev->manufacturer) { + return false; + } + return !strcmp(entry->manufacturer, vdev->manufacturer); + } + return true; +} + +#define VFIO_PLATFORM_BINDING(manuf, model, add_fn) \ + {TYPE_VFIO_PLATFORM, (manuf), (model), (add_fn), vfio_platform_match} + #endif /* CONFIG_LINUX */ =20 -/* list of supported dynamic sysbus devices */ -static const NodeCreationPair add_fdt_node_functions[] =3D { +/* Device type based matching */ +static bool type_match(SysBusDevice *sbdev, const BindingEntry *entry) +{ + return !strcmp(object_get_typename(OBJECT(sbdev)), entry->typename); +} + +#define TYPE_BINDING(type, add_fn) {(type), NULL, NULL, (add_fn), type_mat= ch} + +/* list of supported dynamic sysbus bindings */ +static const BindingEntry bindings[] =3D { #ifdef CONFIG_LINUX - {TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node}, - {TYPE_VFIO_AMD_XGBE, add_amd_xgbe_fdt_node}, + TYPE_BINDING(TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_nod= e), + TYPE_BINDING(TYPE_VFIO_AMD_XGBE, add_amd_xgbe_fdt_node), + VFIO_PLATFORM_BINDING("amd", "xgbe-seattle-v1a", add_amd_xgbe_fdt_node= ), #endif - {"", NULL}, /* last element */ + TYPE_BINDING("", NULL), /* last element */ }; =20 /* Generic Code */ @@ -440,10 +474,11 @@ static void add_fdt_node(SysBusDevice *sbdev, void *o= paque) { int i, ret; =20 - for (i =3D 0; i < ARRAY_SIZE(add_fdt_node_functions); i++) { - if (!strcmp(object_get_typename(OBJECT(sbdev)), - add_fdt_node_functions[i].typename)) { - ret =3D add_fdt_node_functions[i].add_fdt_node_fn(sbdev, opaqu= e); + for (i =3D 0; i < ARRAY_SIZE(bindings); i++) { + const BindingEntry *iter =3D &bindings[i]; + + if (iter->match_fn(sbdev, iter)) { + ret =3D iter->add_fn(sbdev, opaque); assert(!ret); return; } --=20 2.7.4 From nobody Fri May 3 21:55:05 2024 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 1518198450321475.43977399277037; Fri, 9 Feb 2018 09:47:30 -0800 (PST) Received: from localhost ([::1]:49601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekClh-0000W9-2B for importer@patchew.org; Fri, 09 Feb 2018 12:47:25 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekAyP-0001XR-8S for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekAyM-0007iL-Tw for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:25 -0500 Received: from newton.telenet-ops.be ([2a02:1800:120:4::f00:d]:37530) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekAyM-0007hH-MH for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:22 -0500 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by newton.telenet-ops.be (Postfix) with ESMTPS id 3zdJwj1mlhzMqgcr for ; Fri, 9 Feb 2018 16:32:53 +0100 (CET) Received: from ayla.of.borg ([84.194.111.163]) by xavier.telenet-ops.be with bizsmtp id 8fHm1x0393XaVaC01fHmhK; Fri, 09 Feb 2018 16:17:50 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1ekAQs-0003S2-Ou; Fri, 09 Feb 2018 16:17:46 +0100 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1ekAQs-0000lO-Nn; Fri, 09 Feb 2018 16:17:46 +0100 From: Geert Uytterhoeven To: Peter Maydell , Alex Williamson Date: Fri, 9 Feb 2018 16:17:34 +0100 Message-Id: <1518189456-2873-4-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> References: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a02:1800:120:4::f00:d X-Mailman-Approved-At: Fri, 09 Feb 2018 12:38:16 -0500 Subject: [Qemu-devel] [PATCH/RFC 3/5] hw/arm/virt: Allow dynamic sysbus devices again 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: Geert Uytterhoeven , Arnd Bergmann , Wolfram Sang , Magnus Damm , Alexander Graf , qemu-devel@nongnu.org, linux-renesas-soc@vger.kernel.org, Auger Eric , qemu-arm@nongnu.org, Laurent Pinchart , Xiao Feng Ren 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" Allow the instantation of generic dynamic sysbus devices again, without the need to create a new device-specific vfio type. This is a partial revert of commit 6f2062b9758ebc64 ("hw/arm/virt: Allow only supported dynamic sysbus devices"). Not-Yet-Signed-off-by: Geert Uytterhoeven --- hw/arm/virt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index b334c82edae9fb1f..fa83784fc08ed076 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -1596,6 +1596,7 @@ static void virt_machine_class_init(ObjectClass *oc, = void *data) mc->max_cpus =3D 255; machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_CALXEDA_XGMAC); machine_class_allow_dynamic_sysbus_dev(mc, TYPE_VFIO_AMD_XGBE); + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_SYS_BUS_DEVICE); mc->block_default_type =3D IF_VIRTIO; mc->no_cdrom =3D 1; mc->pci_allow_0_address =3D true; --=20 2.7.4 From nobody Fri May 3 21:55:05 2024 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 1518198878591645.8310064844492; Fri, 9 Feb 2018 09:54:38 -0800 (PST) Received: from localhost ([::1]:49953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekCsf-00073F-Mv for importer@patchew.org; Fri, 09 Feb 2018 12:54:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48368) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekAyP-0001XP-7t for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekAyM-0007hp-9J for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:25 -0500 Received: from newton.telenet-ops.be ([195.130.132.45]:48754) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekAyL-0007gu-Tt for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:22 -0500 Received: from laurent.telenet-ops.be (laurent.telenet-ops.be [IPv6:2a02:1800:110:4::f00:19]) by newton.telenet-ops.be (Postfix) with ESMTPS id 3zdJwl25VZzMqw9F for ; Fri, 9 Feb 2018 16:32:55 +0100 (CET) Received: from ayla.of.borg ([84.194.111.163]) by laurent.telenet-ops.be with bizsmtp id 8fHm1x02c3XaVaC01fHmCm; Fri, 09 Feb 2018 16:17:50 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1ekAQs-0003S6-Pf; Fri, 09 Feb 2018 16:17:46 +0100 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1ekAQs-0000lS-OZ; Fri, 09 Feb 2018 16:17:46 +0100 From: Geert Uytterhoeven To: Peter Maydell , Alex Williamson Date: Fri, 9 Feb 2018 16:17:35 +0100 Message-Id: <1518189456-2873-5-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> References: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.130.132.45 X-Mailman-Approved-At: Fri, 09 Feb 2018 12:38:16 -0500 Subject: [Qemu-devel] [PATCH/RFC 4/5] vfio: No-IOMMU mode support 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: Geert Uytterhoeven , Arnd Bergmann , Wolfram Sang , Magnus Damm , Alexander Graf , qemu-devel@nongnu.org, linux-renesas-soc@vger.kernel.org, Auger Eric , qemu-arm@nongnu.org, Laurent Pinchart , Xiao Feng Ren 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: Xiao Feng Ren Add qemu support for the newly introduced VFIO No-IOMMU driver. We need to add special handling for: - Group character device is /dev/vfio/noiommu-$GROUP. - No-IOMMU does not rely on a memory listener. - No IOMMU will be set for its group, so no need to call vfio_kvm_device_add_group. Signed-off-by: Xiao Feng Ren [geert: Rebase] Signed-off-by: Geert Uytterhoeven --- hw/vfio/common.c | 61 ++++++++++++++++++++++++++++++++++-----= ---- include/hw/vfio/vfio-common.h | 2 ++ 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index f895e3c3359af779..2ee94a3304202a74 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -1019,6 +1019,33 @@ static int vfio_connect_container(VFIOGroup *group, = AddressSpace *as, container->fd =3D fd; QLIST_INIT(&container->giommu_list); QLIST_INIT(&container->hostwin_list); + container->noiommu =3D group->noiommu; + + if (container->noiommu) { + ret =3D ioctl(group->fd, VFIO_GROUP_SET_CONTAINER, &fd); + if (ret) { + error_report("vfio: failed to set group container: %m"); + ret =3D -errno; + goto free_container_exit; + } + + ret =3D ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_NOIOMMU_IOMMU); + if (!ret) { + error_report("vfio: No available IOMMU models"); + ret =3D -EINVAL; + goto free_container_exit; + } + + ret =3D ioctl(fd, VFIO_SET_IOMMU, VFIO_NOIOMMU_IOMMU); + if (ret) { + error_report("vfio: failed to set iommu for container: %m"); + ret =3D -errno; + goto free_container_exit; + } + + goto listener_register; + } + if (ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1_IOMMU) || ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU)) { bool v2 =3D !!ioctl(fd, VFIO_CHECK_EXTENSION, VFIO_TYPE1v2_IOMMU); @@ -1151,15 +1178,16 @@ static int vfio_connect_container(VFIOGroup *group,= AddressSpace *as, group->container =3D container; QLIST_INSERT_HEAD(&container->group_list, group, container_next); =20 - container->listener =3D vfio_memory_listener; - - memory_listener_register(&container->listener, container->space->as); - - if (container->error) { - ret =3D container->error; - error_setg_errno(errp, -ret, - "memory listener initialization failed for contai= ner"); - goto listener_release_exit; +listener_register: + if (!container->noiommu) { + container->listener =3D vfio_memory_listener; + memory_listener_register(&container->listener, container->space->a= s); + if (container->error) { + ret =3D container->error; + error_setg_errno(errp, -ret, + "memory listener initialization failed for container"); + goto listener_release_exit; + } } =20 container->initialized =3D true; @@ -1169,7 +1197,9 @@ listener_release_exit: QLIST_REMOVE(group, container_next); QLIST_REMOVE(container, next); vfio_kvm_device_del_group(group); - vfio_listener_release(container); + if (!container->noiommu) { + vfio_listener_release(container); + } =20 free_container_exit: g_free(container); @@ -1195,7 +1225,7 @@ static void vfio_disconnect_container(VFIOGroup *grou= p) * since unset may destroy the backend container if it's the last * group. */ - if (QLIST_EMPTY(&container->group_list)) { + if (QLIST_EMPTY(&container->group_list) && !container->noiommu) { vfio_listener_release(container); } =20 @@ -1249,8 +1279,13 @@ VFIOGroup *vfio_get_group(int groupid, AddressSpace = *as, Error **errp) snprintf(path, sizeof(path), "/dev/vfio/%d", groupid); group->fd =3D qemu_open(path, O_RDWR); if (group->fd < 0) { - error_setg_errno(errp, errno, "failed to open %s", path); - goto free_group_exit; + snprintf(path, sizeof(path), "/dev/vfio/noiommu-%d", groupid); + group->fd =3D qemu_open(path, O_RDWR); + if (group->fd < 0) { + error_setg_errno(errp, errno, "failed to open %s", path); + goto free_group_exit; + } + group->noiommu =3D 1; } =20 if (ioctl(group->fd, VFIO_GROUP_GET_STATUS, &status)) { diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index f3a2ac9fee02066f..aca2e33efb9b118c 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -77,6 +77,7 @@ struct VFIOGroup; typedef struct VFIOContainer { VFIOAddressSpace *space; int fd; /* /dev/vfio/vfio, empowered by the attached groups */ + bool noiommu; MemoryListener listener; MemoryListener prereg_listener; unsigned iommu_type; @@ -136,6 +137,7 @@ struct VFIODeviceOps { typedef struct VFIOGroup { int fd; int groupid; + bool noiommu; VFIOContainer *container; QLIST_HEAD(, VFIODevice) device_list; QLIST_ENTRY(VFIOGroup) next; --=20 2.7.4 From nobody Fri May 3 21:55:05 2024 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 1518198376600573.7293714155957; Fri, 9 Feb 2018 09:46:16 -0800 (PST) Received: from localhost ([::1]:49600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekCkW-000850-CI for importer@patchew.org; Fri, 09 Feb 2018 12:46:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekAyP-0001XO-7m for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekAyM-0007hj-6B for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:25 -0500 Received: from newton.telenet-ops.be ([195.130.132.45]:48758) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekAyL-0007gv-Tl for qemu-devel@nongnu.org; Fri, 09 Feb 2018 10:52:22 -0500 Received: from xavier.telenet-ops.be (xavier.telenet-ops.be [IPv6:2a02:1800:120:4::f00:14]) by newton.telenet-ops.be (Postfix) with ESMTPS id 3zdJwg1xhkzMqtr2 for ; Fri, 9 Feb 2018 16:32:51 +0100 (CET) Received: from ayla.of.borg ([84.194.111.163]) by xavier.telenet-ops.be with bizsmtp id 8fHm1x03N3XaVaC01fHmhP; Fri, 09 Feb 2018 16:17:50 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1ekAQs-0003SB-Qm; Fri, 09 Feb 2018 16:17:46 +0100 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1ekAQs-0000lY-PH; Fri, 09 Feb 2018 16:17:46 +0100 From: Geert Uytterhoeven To: Peter Maydell , Alex Williamson Date: Fri, 9 Feb 2018 16:17:36 +0100 Message-Id: <1518189456-2873-6-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> References: <1518189456-2873-1-git-send-email-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.130.132.45 X-Mailman-Approved-At: Fri, 09 Feb 2018 12:38:16 -0500 Subject: [Qemu-devel] [PATCH/RFC 5/5] hw/arm/sysbus-fdt: Enable rcar-gen3-gpio dynamic instantiation 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: Geert Uytterhoeven , Arnd Bergmann , Wolfram Sang , Magnus Damm , Alexander Graf , qemu-devel@nongnu.org, linux-renesas-soc@vger.kernel.org, Auger Eric , qemu-arm@nongnu.org, Laurent Pinchart , Xiao Feng Ren 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" Allow the instantiation of a Renesas R-Car Gen3 GPIO controller device from the QEMU command line: -device vfio-platform,host=3D,manufacturer=3Drenesas,model=3Drcar-g= en3-gpio -device vfio-platform,sysfsdev=3D,manufacturer=3Drenesas,model=3Drcar= -gen3-gpio A specialized device tree node is created for the guest, containing compatible, reg, gpio-controller, and #gpio-cells properties. Not-Yet-Signed-off-by: Geert Uytterhoeven --- Question: - Why do we need the manufacturer=3Dfoo,model=3Dbar syntax? Can't this just be extracted from the host DT? TODO: - Copy properties from the host DT, as add_amd_xgbe_fdt_node() does, - Make this more generic? --- hw/arm/sysbus-fdt.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c index c5d4fd5604c28118..428175f343d9f3b9 100644 --- a/hw/arm/sysbus-fdt.c +++ b/hw/arm/sysbus-fdt.c @@ -416,6 +416,52 @@ static int add_amd_xgbe_fdt_node(SysBusDevice *sbdev, = void *opaque) return 0; } =20 +/** + * add_rcar_gpio_fdt_node + * + * Generates a simple node with following properties: + * compatible string, regs, #gpio-cells, gpio-controller + */ +static int add_rcar_gpio_fdt_node(SysBusDevice *sbdev, void *opaque) +{ + PlatformBusFDTData *data =3D opaque; + PlatformBusDevice *pbus =3D data->pbus; + void *fdt =3D data->fdt; + const char *parent_node =3D data->pbus_node_name; + int compat_str_len, i; + char *nodename; + uint32_t *reg_attr; + uint64_t mmio_base; + VFIOPlatformDevice *vdev =3D VFIO_PLATFORM_DEVICE(sbdev); + VFIODevice *vbasedev =3D &vdev->vbasedev; + + mmio_base =3D platform_bus_get_mmio_addr(pbus, sbdev, 0); + nodename =3D g_strdup_printf("%s/%s@%" PRIx64, parent_node, + vbasedev->name, mmio_base); + qemu_fdt_add_subnode(fdt, nodename); + + compat_str_len =3D strlen(vdev->compat) + 1; + qemu_fdt_setprop(fdt, nodename, "compatible", + vdev->compat, compat_str_len); + + qemu_fdt_setprop(fdt, nodename, "gpio-controller", NULL, 0); + qemu_fdt_setprop_cells(fdt, nodename, "#gpio-cells", 2); + + reg_attr =3D g_new(uint32_t, vbasedev->num_regions * 2); + for (i =3D 0; i < vbasedev->num_regions; i++) { + mmio_base =3D platform_bus_get_mmio_addr(pbus, sbdev, i); + reg_attr[2 * i] =3D cpu_to_be32(mmio_base); + reg_attr[2 * i + 1] =3D cpu_to_be32( + memory_region_size(vdev->regions[i]->mem)); + } + qemu_fdt_setprop(fdt, nodename, "reg", reg_attr, + vbasedev->num_regions * 2 * sizeof(uint32_t)); + + g_free(reg_attr); + g_free(nodename); + return 0; +} + /* manufacturer/model matching */ static bool vfio_platform_match(SysBusDevice *sbdev, const BindingEntry *entry) @@ -454,6 +500,7 @@ static const BindingEntry bindings[] =3D { TYPE_BINDING(TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_nod= e), TYPE_BINDING(TYPE_VFIO_AMD_XGBE, add_amd_xgbe_fdt_node), VFIO_PLATFORM_BINDING("amd", "xgbe-seattle-v1a", add_amd_xgbe_fdt_node= ), + VFIO_PLATFORM_BINDING("renesas", "rcar-gen3-gpio", add_rcar_gpio_fdt_n= ode), #endif TYPE_BINDING("", NULL), /* last element */ }; --=20 2.7.4