From nobody Fri Nov 29 18:31:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 163334842756225.510202709661485; Mon, 4 Oct 2021 04:53:47 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.201310.355769 (Exim 4.92) (envelope-from ) id 1mXMXG-0001lo-Jy; Mon, 04 Oct 2021 11:53:34 +0000 Received: by outflank-mailman (output) from mailman id 201310.355769; Mon, 04 Oct 2021 11:53:34 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mXMXG-0001lh-Gz; Mon, 04 Oct 2021 11:53:34 +0000 Received: by outflank-mailman (input) for mailman id 201310; Mon, 04 Oct 2021 11:53:32 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mXMXE-0001hd-RK for xen-devel@lists.xenproject.org; Mon, 04 Oct 2021 11:53:32 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id b23755fe-2509-11ec-beab-12813bfff9fa; Mon, 04 Oct 2021 11:53:31 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6D27B1FB; Mon, 4 Oct 2021 04:53:31 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9C8A23F70D; Mon, 4 Oct 2021 04:53:29 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b23755fe-2509-11ec-beab-12813bfff9fa From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Andre.Przywara@arm.com, Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Wei Liu , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v4 03/14] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM Date: Mon, 4 Oct 2021 12:51:58 +0100 Message-Id: <99ee039a6cdd9ac7d54f1f01649d1dd3eeea3763.1633340795.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1633348429452100001 Content-Type: text/plain; charset="utf-8" Hardware domain is in charge of doing the PCI enumeration and will discover the PCI devices and then will communicate to XEN via hyper call PHYSDEVOP_pci_device_add(..) to add the PCI devices in XEN. Also implement PHYSDEVOP_pci_device_remove(..) to remove the PCI device. As most of the code for PHYSDEVOP_pci_device_* is the same between x86 and ARM, move the code to a common file to avoid duplication. There are other PHYSDEVOP_pci_device_* operations to add PCI devices. Currently implemented PHYSDEVOP_pci_device_remove(..) and PHYSDEVOP_pci_device_add(..) only as those are minimum required to support PCI passthrough on ARM. Signed-off-by: Rahul Singh --- Change in v4: - Move file commom/physdev.c to drivers/pci/physdev.c - minor comments. Change in v3: Fixed minor comment. Change in v2: - Add support for PHYSDEVOP_pci_device_remove() - Move code to common code --- --- xen/arch/arm/physdev.c | 5 +-- xen/arch/x86/physdev.c | 52 +---------------------- xen/arch/x86/x86_64/physdev.c | 2 +- xen/drivers/pci/Makefile | 1 + xen/drivers/pci/physdev.c | 80 +++++++++++++++++++++++++++++++++++ xen/include/public/arch-arm.h | 4 +- xen/include/xen/hypercall.h | 11 +++++ 7 files changed, 100 insertions(+), 55 deletions(-) create mode 100644 xen/drivers/pci/physdev.c diff --git a/xen/arch/arm/physdev.c b/xen/arch/arm/physdev.c index e91355fe22..d766978629 100644 --- a/xen/arch/arm/physdev.c +++ b/xen/arch/arm/physdev.c @@ -8,13 +8,12 @@ #include #include #include -#include +#include =20 =20 int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { - gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=3D%d: not implemented\n", cmd); - return -ENOSYS; + return pci_physdev_op(cmd, arg); } =20 /* diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index 23465bcd00..ea38be8b79 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -480,54 +480,6 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(vo= id) arg) break; } =20 - case PHYSDEVOP_pci_device_add: { - struct physdev_pci_device_add add; - struct pci_dev_info pdev_info; - nodeid_t node; - - ret =3D -EFAULT; - if ( copy_from_guest(&add, arg, 1) !=3D 0 ) - break; - - pdev_info.is_extfn =3D !!(add.flags & XEN_PCI_DEV_EXTFN); - if ( add.flags & XEN_PCI_DEV_VIRTFN ) - { - pdev_info.is_virtfn =3D 1; - pdev_info.physfn.bus =3D add.physfn.bus; - pdev_info.physfn.devfn =3D add.physfn.devfn; - } - else - pdev_info.is_virtfn =3D 0; - - if ( add.flags & XEN_PCI_DEV_PXM ) - { - uint32_t pxm; - size_t optarr_off =3D offsetof(struct physdev_pci_device_add, = optarr) / - sizeof(add.optarr[0]); - - if ( copy_from_guest_offset(&pxm, arg, optarr_off, 1) ) - break; - - node =3D pxm_to_node(pxm); - } - else - node =3D NUMA_NO_NODE; - - ret =3D pci_add_device(add.seg, add.bus, add.devfn, &pdev_info, no= de); - break; - } - - case PHYSDEVOP_pci_device_remove: { - struct physdev_pci_device dev; - - ret =3D -EFAULT; - if ( copy_from_guest(&dev, arg, 1) !=3D 0 ) - break; - - ret =3D pci_remove_device(dev.seg, dev.bus, dev.devfn); - break; - } - case PHYSDEVOP_prepare_msix: case PHYSDEVOP_release_msix: { struct physdev_pci_device dev; @@ -663,7 +615,7 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(voi= d) arg) } =20 default: - ret =3D -ENOSYS; + ret =3D pci_physdev_op(cmd, arg); break; } =20 diff --git a/xen/arch/x86/x86_64/physdev.c b/xen/arch/x86/x86_64/physdev.c index 0a50cbd4d8..e3cbd5ebcb 100644 --- a/xen/arch/x86/x86_64/physdev.c +++ b/xen/arch/x86/x86_64/physdev.c @@ -9,7 +9,7 @@ EMIT_FILE; #include #include #include -#include +#include =20 #define do_physdev_op compat_physdev_op =20 diff --git a/xen/drivers/pci/Makefile b/xen/drivers/pci/Makefile index a98035df4c..972c923db0 100644 --- a/xen/drivers/pci/Makefile +++ b/xen/drivers/pci/Makefile @@ -1 +1,2 @@ obj-y +=3D pci.o +obj-y +=3D physdev.o diff --git a/xen/drivers/pci/physdev.c b/xen/drivers/pci/physdev.c new file mode 100644 index 0000000000..4f3e1a96c0 --- /dev/null +++ b/xen/drivers/pci/physdev.c @@ -0,0 +1,80 @@ + +#include +#include +#include + +#ifndef COMPAT +typedef long ret_t; +#endif + +ret_t pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) +{ + ret_t ret; + + switch ( cmd ) + { + case PHYSDEVOP_pci_device_add: { + struct physdev_pci_device_add add; + struct pci_dev_info pdev_info; + nodeid_t node =3D NUMA_NO_NODE; + + ret =3D -EFAULT; + if ( copy_from_guest(&add, arg, 1) !=3D 0 ) + break; + + pdev_info.is_extfn =3D (add.flags & XEN_PCI_DEV_EXTFN); + if ( add.flags & XEN_PCI_DEV_VIRTFN ) + { + pdev_info.is_virtfn =3D true; + pdev_info.physfn.bus =3D add.physfn.bus; + pdev_info.physfn.devfn =3D add.physfn.devfn; + } + else + pdev_info.is_virtfn =3D false; + +#ifdef CONFIG_NUMA + if ( add.flags & XEN_PCI_DEV_PXM ) + { + uint32_t pxm; + size_t optarr_off =3D offsetof(struct physdev_pci_device_add, = optarr) / + sizeof(add.optarr[0]); + + if ( copy_from_guest_offset(&pxm, arg, optarr_off, 1) ) + break; + + node =3D pxm_to_node(pxm); + } +#endif + + ret =3D pci_add_device(add.seg, add.bus, add.devfn, &pdev_info, no= de); + break; + } + + case PHYSDEVOP_pci_device_remove: { + struct physdev_pci_device dev; + + ret =3D -EFAULT; + if ( copy_from_guest(&dev, arg, 1) !=3D 0 ) + break; + + ret =3D pci_remove_device(dev.seg, dev.bus, dev.devfn); + break; + } + + default: + ret =3D -ENOSYS; + break; + } + + return ret; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 6b5a5f818a..d46c61fca9 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -107,7 +107,9 @@ * All generic sub-operations * * HYPERVISOR_physdev_op - * No sub-operations are currenty supported + * Exactly these sub-operations are supported: + * PHYSDEVOP_pci_device_add + * PHYSDEVOP_pci_device_remove * * HYPERVISOR_sysctl * All generic sub-operations, with the exception of: diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h index 3771487a30..7096cc4fe4 100644 --- a/xen/include/xen/hypercall.h +++ b/xen/include/xen/hypercall.h @@ -45,6 +45,17 @@ extern long do_platform_op( XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op); =20 +#ifdef CONFIG_HAS_PCI +extern long +pci_physdev_op( + int cmd, XEN_GUEST_HANDLE_PARAM(void) arg); +#else +static inline long pci_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) ar= g) +{ + gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=3D%d: not implemented\n", cmd); + return -ENOSYS; +} +#endif /* * To allow safe resume of do_memory_op() after preemption, we need to know * at what point in the page list to resume. For this purpose I steal the --=20 2.25.1