From: Rahul Singh <rahul.singh@arm.com>
To: xen-devel@lists.xenproject.org
Cc: bertrand.marquis@arm.com, rahul.singh@arm.com,
Andre.Przywara@arm.com,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Julien Grall" <julien@xen.org>,
"Volodymyr Babchuk" <Volodymyr_Babchuk@epam.com>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"George Dunlap" <george.dunlap@citrix.com>,
"Ian Jackson" <iwj@xenproject.org>,
"Jan Beulich" <jbeulich@suse.com>, "Wei Liu" <wl@xen.org>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM
Date: Wed, 6 Oct 2021 18:40:28 +0100 [thread overview]
Message-ID: <0dc4423b2e20c1eb40c961b211b18ed041f707b7.1633540842.git.rahul.singh@arm.com> (raw)
In-Reply-To: <cover.1633540842.git.rahul.singh@arm.com>
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 <rahul.singh@arm.com>
---
Change in v5:
- Move the pci_physdev_op() stub to xen/arch/arm/physdev.c.
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 | 6 ++-
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 | 4 ++
7 files changed, 96 insertions(+), 53 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..f9aa274dda 100644
--- a/xen/arch/arm/physdev.c
+++ b/xen/arch/arm/physdev.c
@@ -8,13 +8,17 @@
#include <xen/lib.h>
#include <xen/errno.h>
#include <xen/sched.h>
-#include <asm/hypercall.h>
+#include <xen/hypercall.h>
int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
{
+#ifdef CONFIG_HAS_PCI
+ return pci_physdev_op(cmd, arg);
+#else
gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=%d: not implemented\n", cmd);
return -ENOSYS;
+#endif
}
/*
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 <asm/io_apic.h>
#include <asm/msi.h>
#include <asm/hvm/irq.h>
-#include <asm/hypercall.h>
+#include <xen/hypercall.h>
#include <public/xen.h>
#include <public/physdev.h>
#include <xsm/xsm.h>
@@ -480,54 +480,6 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
break;
}
- case PHYSDEVOP_pci_device_add: {
- struct physdev_pci_device_add add;
- struct pci_dev_info pdev_info;
- nodeid_t node;
-
- ret = -EFAULT;
- if ( copy_from_guest(&add, arg, 1) != 0 )
- break;
-
- pdev_info.is_extfn = !!(add.flags & XEN_PCI_DEV_EXTFN);
- if ( add.flags & XEN_PCI_DEV_VIRTFN )
- {
- pdev_info.is_virtfn = 1;
- pdev_info.physfn.bus = add.physfn.bus;
- pdev_info.physfn.devfn = add.physfn.devfn;
- }
- else
- pdev_info.is_virtfn = 0;
-
- if ( add.flags & XEN_PCI_DEV_PXM )
- {
- uint32_t pxm;
- size_t optarr_off = offsetof(struct physdev_pci_device_add, optarr) /
- sizeof(add.optarr[0]);
-
- if ( copy_from_guest_offset(&pxm, arg, optarr_off, 1) )
- break;
-
- node = pxm_to_node(pxm);
- }
- else
- node = NUMA_NO_NODE;
-
- ret = pci_add_device(add.seg, add.bus, add.devfn, &pdev_info, node);
- break;
- }
-
- case PHYSDEVOP_pci_device_remove: {
- struct physdev_pci_device dev;
-
- ret = -EFAULT;
- if ( copy_from_guest(&dev, arg, 1) != 0 )
- break;
-
- ret = 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(void) arg)
}
default:
- ret = -ENOSYS;
+ ret = pci_physdev_op(cmd, arg);
break;
}
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 <compat/xen.h>
#include <compat/event_channel.h>
#include <compat/physdev.h>
-#include <asm/hypercall.h>
+#include <xen/hypercall.h>
#define do_physdev_op compat_physdev_op
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 += pci.o
+obj-y += 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 <xen/guest_access.h>
+#include <xen/hypercall.h>
+#include <xen/init.h>
+
+#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 = NUMA_NO_NODE;
+
+ ret = -EFAULT;
+ if ( copy_from_guest(&add, arg, 1) != 0 )
+ break;
+
+ pdev_info.is_extfn = (add.flags & XEN_PCI_DEV_EXTFN);
+ if ( add.flags & XEN_PCI_DEV_VIRTFN )
+ {
+ pdev_info.is_virtfn = true;
+ pdev_info.physfn.bus = add.physfn.bus;
+ pdev_info.physfn.devfn = add.physfn.devfn;
+ }
+ else
+ pdev_info.is_virtfn = false;
+
+#ifdef CONFIG_NUMA
+ if ( add.flags & XEN_PCI_DEV_PXM )
+ {
+ uint32_t pxm;
+ size_t optarr_off = offsetof(struct physdev_pci_device_add, optarr) /
+ sizeof(add.optarr[0]);
+
+ if ( copy_from_guest_offset(&pxm, arg, optarr_off, 1) )
+ break;
+
+ node = pxm_to_node(pxm);
+ }
+#endif
+
+ ret = pci_add_device(add.seg, add.bus, add.devfn, &pdev_info, node);
+ break;
+ }
+
+ case PHYSDEVOP_pci_device_remove: {
+ struct physdev_pci_device dev;
+
+ ret = -EFAULT;
+ if ( copy_from_guest(&dev, arg, 1) != 0 )
+ break;
+
+ ret = pci_remove_device(dev.seg, dev.bus, dev.devfn);
+ break;
+ }
+
+ default:
+ ret = -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..07b10ec230 100644
--- a/xen/include/xen/hypercall.h
+++ b/xen/include/xen/hypercall.h
@@ -45,6 +45,10 @@ extern long
do_platform_op(
XEN_GUEST_HANDLE_PARAM(xen_platform_op_t) u_xenpf_op);
+extern long
+pci_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
--
2.25.1
next prev parent reply other threads:[~2021-10-06 17:41 UTC|newest]
Thread overview: 190+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-06 17:40 [PATCH v5 00/11] PCI devices passthrough on Arm Rahul Singh
2021-10-06 17:40 ` [PATCH v5 01/11] xen/arm: xc_domain_ioport_permission(..) not supported on ARM Rahul Singh
2021-10-11 11:47 ` Roger Pau Monné
2021-10-11 12:11 ` Bertrand Marquis
2021-10-11 13:20 ` Roger Pau Monné
2021-10-11 13:40 ` Bertrand Marquis
2021-10-11 13:57 ` Roger Pau Monné
2021-10-11 14:16 ` Bertrand Marquis
2021-10-11 16:32 ` Roger Pau Monné
2021-10-11 17:11 ` Bertrand Marquis
2021-10-12 8:29 ` Jan Beulich
2021-10-12 8:41 ` Bertrand Marquis
2021-10-12 9:32 ` Jan Beulich
2021-10-12 9:38 ` Oleksandr Andrushchenko
2021-10-12 10:01 ` Jan Beulich
2021-10-12 10:06 ` Oleksandr Andrushchenko
2021-10-12 10:20 ` Jan Beulich
2021-10-12 10:41 ` Bertrand Marquis
2021-10-12 10:44 ` Jan Beulich
2021-10-12 14:53 ` Ian Jackson
2021-10-12 16:15 ` Bertrand Marquis
2021-10-12 16:29 ` Ian Jackson
2021-10-12 20:42 ` Stefano Stabellini
2021-10-13 8:07 ` Roger Pau Monné
2021-10-13 11:52 ` Ian Jackson
2021-10-13 8:02 ` Roger Pau Monné
2021-10-13 12:02 ` Ian Jackson
2021-10-12 9:40 ` Bertrand Marquis
2021-10-12 10:03 ` Jan Beulich
2021-10-11 14:16 ` Oleksandr Andrushchenko
2021-10-06 17:40 ` Rahul Singh [this message]
2021-10-07 0:05 ` [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM Stefano Stabellini
2021-10-07 12:58 ` Jan Beulich
2021-10-21 9:28 ` xen/arm: Missing appropriate locking for the IOMMU (WAS Re: [PATCH v5 02/11] xen/arm: Add PHYSDEVOP_pci_device_(*add/remove) support for ARM) Julien Grall
2021-10-21 13:15 ` Bertrand Marquis
2021-10-21 13:47 ` Julien Grall
2021-10-21 13:52 ` Bertrand Marquis
2021-10-06 17:40 ` [PATCH v5 03/11] xen/arm: Add cmdline boot option "pci-passthrough = <boolean>" Rahul Singh
2021-10-07 8:27 ` Jan Beulich
2021-10-07 8:32 ` Rahul Singh
2021-10-07 12:59 ` Jan Beulich
2021-10-06 17:40 ` [PATCH v5 04/11] xen/arm: PCI host bridge discovery within XEN on ARM Rahul Singh
2021-10-06 17:40 ` [PATCH v5 05/11] xen/arm: Add support for Xilinx ZynqMP PCI host controller Rahul Singh
2021-10-06 17:40 ` [PATCH v5 06/11] xen/arm: Implement pci access functions Rahul Singh
2021-10-06 17:40 ` [PATCH v5 07/11] xen/domctl: Introduce XEN_DOMCTL_CDF_vpci flag Rahul Singh
2021-10-07 13:08 ` Jan Beulich
2021-10-08 18:06 ` Andrew Cooper
2021-10-08 21:12 ` Julien Grall
2021-10-08 21:46 ` Stefano Stabellini
2021-10-11 9:24 ` Julien Grall
2021-10-11 11:29 ` Michal Orzel
2021-10-11 11:35 ` Jan Beulich
2021-10-11 13:17 ` Roger Pau Monné
2021-10-11 9:48 ` Ian Jackson
2021-10-11 9:27 ` Roger Pau Monné
2021-10-11 12:06 ` Michal Orzel
2021-10-12 10:38 ` Michal Orzel
2021-10-13 8:30 ` Roger Pau Monné
2021-10-13 9:36 ` Bertrand Marquis
2021-10-13 10:56 ` Roger Pau Monné
2021-10-13 12:11 ` Bertrand Marquis
2021-10-13 12:57 ` Jan Beulich
2021-10-13 20:41 ` Stefano Stabellini
2021-10-14 6:23 ` Jan Beulich
2021-10-14 7:53 ` Bertrand Marquis
2021-10-13 14:28 ` Roger Pau Monné
2021-10-13 20:53 ` Stefano Stabellini
2021-10-13 23:21 ` Stefano Stabellini
2021-10-12 21:48 ` Stefano Stabellini
2021-10-13 6:18 ` Jan Beulich
2021-10-13 7:11 ` Michal Orzel
2021-10-06 17:40 ` [PATCH v5 08/11] xen/arm: Enable the existing x86 virtual PCI support for ARM Rahul Singh
2021-10-07 13:43 ` Jan Beulich
2021-10-11 12:41 ` Bertrand Marquis
2021-10-11 13:09 ` Jan Beulich
2021-10-11 13:34 ` Bertrand Marquis
2021-10-11 14:10 ` Jan Beulich
2021-10-11 14:52 ` Bertrand Marquis
2021-10-11 18:18 ` Stefano Stabellini
2021-10-12 8:04 ` Jan Beulich
2021-10-12 21:37 ` Stefano Stabellini
2021-10-13 6:10 ` Jan Beulich
2021-10-13 10:02 ` Bertrand Marquis
2021-10-13 12:21 ` Jan Beulich
2021-10-12 15:04 ` Julien Grall
2021-10-12 16:12 ` Bertrand Marquis
2021-10-12 16:20 ` Julien Grall
2021-10-12 17:50 ` Bertrand Marquis
2021-10-11 10:51 ` Roger Pau Monné
2021-10-11 16:12 ` Bertrand Marquis
2021-10-11 16:20 ` Oleksandr Andrushchenko
2021-10-11 16:43 ` Roger Pau Monné
2021-10-11 17:15 ` Bertrand Marquis
2021-10-11 18:30 ` Oleksandr Andrushchenko
2021-10-11 19:27 ` Stefano Stabellini
2021-10-12 5:34 ` Oleksandr Andrushchenko
2021-10-12 7:44 ` Bertrand Marquis
2021-10-12 14:32 ` Julien Grall
2021-10-12 14:34 ` Bertrand Marquis
2021-10-13 8:45 ` Roger Pau Monné
2021-10-13 9:48 ` Bertrand Marquis
2021-10-13 10:33 ` Roger Pau Monné
2021-10-13 13:00 ` Jan Beulich
2021-10-13 14:51 ` Oleksandr Andrushchenko
2021-10-13 15:15 ` Jan Beulich
2021-10-13 19:27 ` Stefano Stabellini
2021-10-14 6:33 ` Jan Beulich
2021-10-14 7:53 ` Bertrand Marquis
2021-10-14 9:03 ` Bertrand Marquis
2021-10-14 9:24 ` Jan Beulich
2021-10-06 17:40 ` [PATCH v5 09/11] xen/arm: Transitional change to build HAS_VPCI on ARM Rahul Singh
2021-10-11 11:43 ` Roger Pau Monné
2021-10-11 12:15 ` Bertrand Marquis
2021-10-12 1:32 ` Stefano Stabellini
2021-10-06 17:40 ` [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl Rahul Singh
2021-10-06 18:01 ` Julien Grall
2021-10-07 0:26 ` Stefano Stabellini
2021-10-07 15:31 ` Rahul Singh
2021-10-07 10:53 ` Ian Jackson
2021-10-07 15:29 ` Rahul Singh
2021-10-07 16:11 ` Ian Jackson
2021-10-11 13:46 ` Roger Pau Monné
2021-10-14 17:16 ` Bertrand Marquis
2021-10-14 14:49 ` [PATCH v6 0/3] PCI devices passthrough on Arm Bertrand Marquis
2021-10-14 14:49 ` [PATCH v6 1/3] xen/vpci: Move ecam access functions to common code Bertrand Marquis
2021-10-14 16:06 ` Jan Beulich
2021-10-14 17:09 ` Bertrand Marquis
2021-10-15 6:29 ` Jan Beulich
2021-10-15 7:37 ` Bertrand Marquis
2021-10-15 8:13 ` Jan Beulich
2021-10-15 8:20 ` Bertrand Marquis
2021-10-15 8:24 ` Jan Beulich
2021-10-15 9:49 ` Roger Pau Monné
2021-10-14 23:47 ` Stefano Stabellini
2021-10-15 7:44 ` Roger Pau Monné
2021-10-15 7:53 ` Bertrand Marquis
2021-10-15 9:53 ` Roger Pau Monné
2021-10-15 10:12 ` Bertrand Marquis
2021-10-15 10:14 ` Jan Beulich
2021-10-14 14:49 ` [PATCH v6 2/3] xen/arm: Enable the existing x86 virtual PCI support for ARM Bertrand Marquis
2021-10-14 23:49 ` Stefano Stabellini
2021-10-15 6:40 ` Jan Beulich
2021-10-15 9:59 ` Ian Jackson
2021-10-15 10:10 ` Bertrand Marquis
2021-10-15 8:00 ` Jan Beulich
2021-10-15 10:09 ` Bertrand Marquis
2021-10-15 10:14 ` Ian Jackson
2021-10-15 10:18 ` Jan Beulich
2021-10-15 11:35 ` Roger Pau Monné
2021-10-15 12:13 ` Bertrand Marquis
2021-10-15 12:18 ` Jan Beulich
2021-10-15 12:28 ` Bertrand Marquis
2021-10-15 13:00 ` Jan Beulich
2021-10-15 13:10 ` Bertrand Marquis
2021-10-15 10:38 ` Jan Beulich
2021-10-15 8:32 ` Roger Pau Monné
2021-10-15 8:42 ` Michal Orzel
2021-10-15 9:52 ` Bertrand Marquis
2021-10-15 10:13 ` Luca Fancellu
2021-10-15 10:17 ` Bertrand Marquis
2021-10-15 10:19 ` Roger Pau Monné
2021-10-15 10:31 ` Bertrand Marquis
2021-10-15 10:24 ` Jan Beulich
2021-10-15 10:33 ` Bertrand Marquis
2021-10-15 10:41 ` Jan Beulich
2021-10-15 10:48 ` Bertrand Marquis
2021-10-15 10:51 ` Jan Beulich
2021-10-15 11:08 ` Bertrand Marquis
2021-10-15 13:47 ` Roger Pau Monné
2021-10-15 14:00 ` Luca Fancellu
2021-10-15 14:32 ` Roger Pau Monné
2021-10-14 14:49 ` [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl Bertrand Marquis
2021-10-14 17:54 ` [PATCH v6 3/3] arm/libxl: Emulated PCI device tree node in libxl [and 1 more messages] Ian Jackson
2021-10-14 23:50 ` Stefano Stabellini
2021-10-15 7:28 ` Julien Grall
2021-10-15 7:41 ` Michal Orzel
2021-10-15 9:01 ` Julien Grall
2021-10-15 10:02 ` Ian Jackson
2021-10-15 10:58 ` Michal Orzel
2021-10-15 11:04 ` Michal Orzel
2021-10-15 11:46 ` Ian Jackson
2021-10-15 11:53 ` Michal Orzel
2021-10-15 12:10 ` Julien Grall
2021-10-15 12:14 ` Ian Jackson
2021-10-15 12:13 ` Ian Jackson
2021-10-12 15:03 ` [PATCH v5 10/11] arm/libxl: Emulated PCI device tree node in libxl Ian Jackson
2021-10-06 17:40 ` [PATCH v5 11/11] xen/arm: Add linux,pci-domain property for hwdom if not available Rahul Singh
2021-10-13 20:54 ` Stefano Stabellini
2021-10-07 19:54 ` [PATCH v5 00/11] PCI devices passthrough on Arm Stefano Stabellini
2021-10-07 21:29 ` Rahul Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0dc4423b2e20c1eb40c961b211b18ed041f707b7.1633540842.git.rahul.singh@arm.com \
--to=rahul.singh@arm.com \
--cc=Andre.Przywara@arm.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=bertrand.marquis@arm.com \
--cc=george.dunlap@citrix.com \
--cc=iwj@xenproject.org \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).