From nobody Fri Nov 29 18:50:02 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 1632853243484512.9033869432889; Tue, 28 Sep 2021 11:20:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198223.351608 (Exim 4.92) (envelope-from ) id 1mVHiR-0000Dr-I2; Tue, 28 Sep 2021 18:20:31 +0000 Received: by outflank-mailman (output) from mailman id 198223.351608; Tue, 28 Sep 2021 18:20:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHiR-0000Di-ET; Tue, 28 Sep 2021 18:20:31 +0000 Received: by outflank-mailman (input) for mailman id 198223; Tue, 28 Sep 2021 18:20:30 +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 1mVHiQ-0006l6-Hr for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:20:30 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id c076fd34-2088-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:20:25 +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 8CAAF6D; Tue, 28 Sep 2021 11:20:25 -0700 (PDT) Received: from e109506.cambridge.arm.com (e109506.cambridge.arm.com [10.1.199.1]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E05A63F793; Tue, 28 Sep 2021 11:20:23 -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: c076fd34-2088-11ec-bcc4-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 v3 05/17] xen/arm: Add PHYSDEVOP_pci_device_* support for ARM Date: Tue, 28 Sep 2021 19:18:14 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853243907100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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. Signed-off-by: Rahul Singh Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- 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 | 50 +------------------- xen/arch/x86/x86_64/physdev.c | 4 +- xen/common/Makefile | 1 + xen/common/physdev.c | 81 +++++++++++++++++++++++++++++++++ xen/include/asm-arm/hypercall.h | 2 - xen/include/asm-arm/numa.h | 5 ++ xen/include/asm-x86/hypercall.h | 9 ++-- xen/include/xen/hypercall.h | 8 ++++ 9 files changed, 106 insertions(+), 59 deletions(-) create mode 100644 xen/common/physdev.c diff --git a/xen/arch/arm/physdev.c b/xen/arch/arm/physdev.c index e91355fe22..4e00b03aab 100644 --- a/xen/arch/arm/physdev.c +++ b/xen/arch/arm/physdev.c @@ -8,10 +8,9 @@ #include #include #include -#include +#include =20 - -int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) +long arch_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=3D%d: not implemented\n", cmd); return -ENOSYS; diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index 23465bcd00..c00cc99404 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -174,7 +174,7 @@ int physdev_unmap_pirq(domid_t domid, int pirq) } #endif /* COMPAT */ =20 -ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) +ret_t arch_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { int irq; ret_t ret; @@ -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; diff --git a/xen/arch/x86/x86_64/physdev.c b/xen/arch/x86/x86_64/physdev.c index 0a50cbd4d8..5f72652ff7 100644 --- a/xen/arch/x86/x86_64/physdev.c +++ b/xen/arch/x86/x86_64/physdev.c @@ -9,9 +9,10 @@ EMIT_FILE; #include #include #include -#include +#include =20 #define do_physdev_op compat_physdev_op +#define arch_physdev_op arch_compat_physdev_op =20 #define physdev_apic compat_physdev_apic #define physdev_apic_t physdev_apic_compat_t @@ -82,6 +83,7 @@ CHECK_physdev_pci_device typedef int ret_t; =20 #include "../physdev.c" +#include "../../../common/physdev.c" =20 /* * Local variables: diff --git a/xen/common/Makefile b/xen/common/Makefile index 54de70d422..bcb1c8fb03 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -29,6 +29,7 @@ obj-y +=3D notifier.o obj-y +=3D page_alloc.o obj-$(CONFIG_HAS_PDX) +=3D pdx.o obj-$(CONFIG_PERF_COUNTERS) +=3D perfc.o +obj-y +=3D physdev.o obj-y +=3D preempt.o obj-y +=3D random.o obj-y +=3D rangeset.o diff --git a/xen/common/physdev.c b/xen/common/physdev.c new file mode 100644 index 0000000000..20a5530269 --- /dev/null +++ b/xen/common/physdev.c @@ -0,0 +1,81 @@ + +#include +#include +#include + +#ifndef COMPAT +typedef long ret_t; +#endif + +ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) +{ + ret_t ret; + + switch ( cmd ) + { +#ifdef CONFIG_HAS_PCI + 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; + } +#endif + default: + ret =3D arch_physdev_op(cmd, arg); + 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/asm-arm/hypercall.h b/xen/include/asm-arm/hypercal= l.h index a0c5a31a2f..c6e4a04fd6 100644 --- a/xen/include/asm-arm/hypercall.h +++ b/xen/include/asm-arm/hypercall.h @@ -2,8 +2,6 @@ #define __ASM_ARM_HYPERCALL_H__ =20 #include /* for arch_do_domctl */ -int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg); - long do_arm_vcpu_op(int cmd, unsigned int vcpuid, XEN_GUEST_HANDLE_PARAM(v= oid) arg); =20 long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d, diff --git a/xen/include/asm-arm/numa.h b/xen/include/asm-arm/numa.h index 31a6de4e23..dbd1c2467f 100644 --- a/xen/include/asm-arm/numa.h +++ b/xen/include/asm-arm/numa.h @@ -25,6 +25,11 @@ extern mfn_t first_valid_mfn; #define node_start_pfn(nid) (mfn_x(first_valid_mfn)) #define __node_distance(a, b) (20) =20 +static inline nodeid_t pxm_to_node(unsigned pxm) +{ + return 0xff; +} + #endif /* __ARCH_ARM_NUMA_H */ /* * Local variables: diff --git a/xen/include/asm-x86/hypercall.h b/xen/include/asm-x86/hypercal= l.h index 0ae3b8b043..7afba98186 100644 --- a/xen/include/asm-x86/hypercall.h +++ b/xen/include/asm-x86/hypercall.h @@ -105,10 +105,6 @@ do_update_va_mapping( u64 val64, unsigned long flags); =20 -extern long -do_physdev_op( - int cmd, XEN_GUEST_HANDLE_PARAM(void) arg); - extern long do_update_va_mapping_otherdomain( unsigned long va, @@ -151,6 +147,11 @@ compat_physdev_op( int cmd, XEN_GUEST_HANDLE_PARAM(void) arg); =20 +extern int +arch_compat_physdev_op( + int cmd, + XEN_GUEST_HANDLE_PARAM(void) arg); + extern int arch_compat_vcpu_op( int cmd, struct vcpu *v, XEN_GUEST_HANDLE_PARAM(void) arg); diff --git a/xen/include/xen/hypercall.h b/xen/include/xen/hypercall.h index 3771487a30..5cc74f40b7 100644 --- a/xen/include/xen/hypercall.h +++ b/xen/include/xen/hypercall.h @@ -45,6 +45,14 @@ extern long do_platform_op( XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op); =20 +extern long +do_physdev_op( + int cmd, XEN_GUEST_HANDLE_PARAM(void) arg); + +extern long +arch_physdev_op( + int cmd, XEN_GUEST_HANDLE_PARAM(void) arg); + /* * 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.17.1