From nobody Fri Nov 29 16:38:33 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 1632853183914744.5630823479803; Tue, 28 Sep 2021 11:19:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198197.351563 (Exim 4.92) (envelope-from ) id 1mVHhR-0005qX-9r; Tue, 28 Sep 2021 18:19:29 +0000 Received: by outflank-mailman (output) from mailman id 198197.351563; Tue, 28 Sep 2021 18:19:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHhR-0005qQ-71; Tue, 28 Sep 2021 18:19:29 +0000 Received: by outflank-mailman (input) for mailman id 198197; Tue, 28 Sep 2021 18:19:28 +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 1mVHhQ-0005qD-DE for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:19:28 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 9cc18f95-2088-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:19:26 +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 B05B36D; Tue, 28 Sep 2021 11:19: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 B4F903F793; Tue, 28 Sep 2021 11:19: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: 9cc18f95-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, Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Paul Durrant , Daniel De Graaf , "Daniel P. Smith" Subject: [PATCH v3 01/17] xen/pci: Refactor MSI code that implements MSI functionality within XEN Date: Tue, 28 Sep 2021 19:18:10 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853184757100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" On Arm, the initial plan is to only support GICv3 ITS which doesn't require us to manage the MSIs because the HW will protect against spoofing. Move the code under CONFIG_HAS_PCI_MSI flag to gate the code for ARM. No functional change intended. Signed-off-by: Rahul Singh Reviewed-by: Daniel P. Smith Acked-by: Jan Beulich Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Change in v3: none=20 Change in v2: Fixed minor comments --- xen/arch/x86/Kconfig | 1 + xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/msi.c | 83 ++++++++++++++++++++++++++++++++ xen/drivers/passthrough/pci.c | 54 +++++---------------- xen/drivers/pci/Kconfig | 4 ++ xen/include/xen/msi.h | 43 +++++++++++++++++ xen/xsm/flask/hooks.c | 8 +-- 7 files changed, 149 insertions(+), 45 deletions(-) create mode 100644 xen/drivers/passthrough/msi.c create mode 100644 xen/include/xen/msi.h diff --git a/xen/arch/x86/Kconfig b/xen/arch/x86/Kconfig index 1f83518ee0..b4abfca46f 100644 --- a/xen/arch/x86/Kconfig +++ b/xen/arch/x86/Kconfig @@ -20,6 +20,7 @@ config X86 select HAS_NS16550 select HAS_PASSTHROUGH select HAS_PCI + select HAS_PCI_MSI select HAS_PDX select HAS_SCHED_GRANULARITY select HAS_UBSAN diff --git a/xen/drivers/passthrough/Makefile b/xen/drivers/passthrough/Mak= efile index 445690e3e5..a5efa22714 100644 --- a/xen/drivers/passthrough/Makefile +++ b/xen/drivers/passthrough/Makefile @@ -7,3 +7,4 @@ obj-y +=3D iommu.o obj-$(CONFIG_HAS_PCI) +=3D pci.o obj-$(CONFIG_HAS_DEVICE_TREE) +=3D device_tree.o obj-$(CONFIG_HAS_PCI) +=3D ats.o +obj-$(CONFIG_HAS_PCI_MSI) +=3D msi.o diff --git a/xen/drivers/passthrough/msi.c b/xen/drivers/passthrough/msi.c new file mode 100644 index 0000000000..ce1a450f6f --- /dev/null +++ b/xen/drivers/passthrough/msi.c @@ -0,0 +1,83 @@ +#include +#include +#include +#include + +int pdev_msix_assign(struct domain *d, struct pci_dev *pdev) +{ + int rc; + + if ( pdev->msix ) + { + rc =3D pci_reset_msix_state(pdev); + if ( rc ) + return rc; + msixtbl_init(d); + } + + return 0; +} + +int pdev_msi_init(struct pci_dev *pdev) +{ + unsigned int pos; + + INIT_LIST_HEAD(&pdev->msi_list); + + pos =3D pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn= ), + PCI_FUNC(pdev->devfn), PCI_CAP_ID_MSI); + if ( pos ) + { + uint16_t ctrl =3D pci_conf_read16(pdev->sbdf, msi_control_reg(pos)= ); + + pdev->msi_maxvec =3D multi_msi_capable(ctrl); + } + + pos =3D pci_find_cap_offset(pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn= ), + PCI_FUNC(pdev->devfn), PCI_CAP_ID_MSIX); + if ( pos ) + { + struct arch_msix *msix =3D xzalloc(struct arch_msix); + uint16_t ctrl; + + if ( !msix ) + return -ENOMEM; + + spin_lock_init(&msix->table_lock); + + ctrl =3D pci_conf_read16(pdev->sbdf, msix_control_reg(pos)); + msix->nr_entries =3D msix_table_size(ctrl); + + pdev->msix =3D msix; + } + + return 0; +} + +void pdev_msi_deinit(struct pci_dev *pdev) +{ + XFREE(pdev->msix); +} + +void pdev_dump_msi(const struct pci_dev *pdev) +{ + const struct msi_desc *msi; + + if ( list_empty(&pdev->msi_list) ) + return; + + printk(" - MSIs < "); + list_for_each_entry ( msi, &pdev->msi_list, list ) + printk("%d ", msi->irq); + printk(">"); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index fc4fa2e5c3..8996403161 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -32,8 +32,8 @@ #include #include #include +#include #include -#include #include "ats.h" =20 struct pci_seg { @@ -314,6 +314,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg,= u8 bus, u8 devfn) { struct pci_dev *pdev; unsigned int pos; + int rc; =20 list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) if ( pdev->bus =3D=3D bus && pdev->devfn =3D=3D devfn ) @@ -327,35 +328,12 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pse= g, u8 bus, u8 devfn) *((u8*) &pdev->bus) =3D bus; *((u8*) &pdev->devfn) =3D devfn; pdev->domain =3D NULL; - INIT_LIST_HEAD(&pdev->msi_list); - - pos =3D pci_find_cap_offset(pseg->nr, bus, PCI_SLOT(devfn), PCI_FUNC(d= evfn), - PCI_CAP_ID_MSI); - if ( pos ) - { - uint16_t ctrl =3D pci_conf_read16(pdev->sbdf, msi_control_reg(pos)= ); - - pdev->msi_maxvec =3D multi_msi_capable(ctrl); - } =20 - pos =3D pci_find_cap_offset(pseg->nr, bus, PCI_SLOT(devfn), PCI_FUNC(d= evfn), - PCI_CAP_ID_MSIX); - if ( pos ) + rc =3D pdev_msi_init(pdev); + if ( rc ) { - struct arch_msix *msix =3D xzalloc(struct arch_msix); - uint16_t ctrl; - - if ( !msix ) - { - xfree(pdev); - return NULL; - } - spin_lock_init(&msix->table_lock); - - ctrl =3D pci_conf_read16(pdev->sbdf, msix_control_reg(pos)); - msix->nr_entries =3D msix_table_size(ctrl); - - pdev->msix =3D msix; + xfree(pdev); + return NULL; } =20 list_add(&pdev->alldevs_list, &pseg->alldevs_list); @@ -449,7 +427,7 @@ static void free_pdev(struct pci_seg *pseg, struct pci_= dev *pdev) } =20 list_del(&pdev->alldevs_list); - xfree(pdev->msix); + pdev_msi_deinit(pdev); xfree(pdev); } =20 @@ -1271,18 +1249,16 @@ bool_t pcie_aer_get_firmware_first(const struct pci= _dev *pdev) static int _dump_pci_devices(struct pci_seg *pseg, void *arg) { struct pci_dev *pdev; - struct msi_desc *msi; =20 printk("=3D=3D=3D=3D segment %04x =3D=3D=3D=3D\n", pseg->nr); =20 list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) { - printk("%pp - %pd - node %-3d - MSIs < ", + printk("%pp - %pd - node %-3d", &pdev->sbdf, pdev->domain, (pdev->node !=3D NUMA_NO_NODE) ? pdev->node : -1); - list_for_each_entry ( msi, &pdev->msi_list, list ) - printk("%d ", msi->irq); - printk(">\n"); + pdev_dump_msi(pdev); + printk("\n"); } =20 return 0; @@ -1422,13 +1398,9 @@ static int assign_device(struct domain *d, u16 seg, = u8 bus, u8 devfn, u32 flag) ASSERT(pdev && (pdev->domain =3D=3D hardware_domain || pdev->domain =3D=3D dom_io)); =20 - if ( pdev->msix ) - { - rc =3D pci_reset_msix_state(pdev); - if ( rc ) - goto done; - msixtbl_init(d); - } + rc =3D pdev_msix_assign(d, pdev); + if ( rc ) + goto done; =20 pdev->fault.count =3D 0; =20 diff --git a/xen/drivers/pci/Kconfig b/xen/drivers/pci/Kconfig index 7da03fa13b..c6a7bc8007 100644 --- a/xen/drivers/pci/Kconfig +++ b/xen/drivers/pci/Kconfig @@ -1,3 +1,7 @@ =20 config HAS_PCI bool + +config HAS_PCI_MSI + bool + depends on HAS_PCI diff --git a/xen/include/xen/msi.h b/xen/include/xen/msi.h new file mode 100644 index 0000000000..c903d0050c --- /dev/null +++ b/xen/include/xen/msi.h @@ -0,0 +1,43 @@ +#ifndef __XEN_MSI_H_ +#define __XEN_MSI_H_ + +#include + +#ifdef CONFIG_HAS_PCI_MSI + +#include + +int pdev_msix_assign(struct domain *d, struct pci_dev *pdev); +int pdev_msi_init(struct pci_dev *pdev); +void pdev_msi_deinit(struct pci_dev *pdev); +void pdev_dump_msi(const struct pci_dev *pdev); + +#else /* !CONFIG_HAS_PCI_MSI */ + +static inline int pdev_msix_assign(struct domain *d, struct pci_dev *pdev) +{ + return 0; +} + +static inline int pdev_msi_init(struct pci_dev *pdev) +{ + return 0; +} + +static inline void pdev_msi_deinit(struct pci_dev *pdev) {} +static inline void pci_cleanup_msi(struct pci_dev *pdev) {} +static inline void pdev_dump_msi(const struct pci_dev *pdev) {} + +#endif /* CONFIG_HAS_PCI_MSI */ + +#endif /* __XEN_MSI_H */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/xsm/flask/hooks.c b/xen/xsm/flask/hooks.c index 25e87180b4..ea9a12bd71 100644 --- a/xen/xsm/flask/hooks.c +++ b/xen/xsm/flask/hooks.c @@ -21,7 +21,7 @@ #include #include #include -#ifdef CONFIG_HAS_PCI +#ifdef CONFIG_HAS_PCI_MSI #include #endif #include @@ -114,7 +114,7 @@ static int get_irq_sid(int irq, u32 *sid, struct avc_au= dit_data *ad) } return security_irq_sid(irq, sid); } -#ifdef CONFIG_HAS_PCI +#ifdef CONFIG_HAS_PCI_MSI { struct irq_desc *desc =3D irq_to_desc(irq); if ( desc->msi_desc && desc->msi_desc->dev ) { @@ -874,7 +874,7 @@ static int flask_map_domain_pirq (struct domain *d) static int flask_map_domain_msi (struct domain *d, int irq, const void *da= ta, u32 *sid, struct avc_audit_data *ad) { -#ifdef CONFIG_HAS_PCI +#ifdef CONFIG_HAS_PCI_MSI const struct msi_info *msi =3D data; u32 machine_bdf =3D (msi->seg << 16) | (msi->bus << 8) | msi->devfn; =20 @@ -940,7 +940,7 @@ static int flask_unmap_domain_pirq (struct domain *d) static int flask_unmap_domain_msi (struct domain *d, int irq, const void *= data, u32 *sid, struct avc_audit_data *ad) { -#ifdef CONFIG_HAS_PCI +#ifdef CONFIG_HAS_PCI_MSI const struct pci_dev *pdev =3D data; u32 machine_bdf =3D (pdev->seg << 16) | (pdev->bus << 8) | pdev->devfn; =20 --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853202102905.7130537993473; Tue, 28 Sep 2021 11:20:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198203.351575 (Exim 4.92) (envelope-from ) id 1mVHhj-0006N6-JV; Tue, 28 Sep 2021 18:19:47 +0000 Received: by outflank-mailman (output) from mailman id 198203.351575; Tue, 28 Sep 2021 18:19:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHhj-0006Mz-G1; Tue, 28 Sep 2021 18:19:47 +0000 Received: by outflank-mailman (input) for mailman id 198203; Tue, 28 Sep 2021 18:19:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHhh-0006Ma-SN for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:19:45 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id c278eeda-7b05-41fe-ba82-559089251627; Tue, 28 Sep 2021 18:19:44 +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 11D9E6D; Tue, 28 Sep 2021 11:19:44 -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 118903F793; Tue, 28 Sep 2021 11:19:42 -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: c278eeda-7b05-41fe-ba82-559089251627 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 Subject: [PATCH v3 02/17] xen/arm: pci: Add stubs to allow selecting HAS_PCI Date: Tue, 28 Sep 2021 19:18:11 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853203120100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" In a follow-up we will enable PCI support in Xen on Arm (i.e select HAS_PCI). The generic code expects the arch to implement a few functions: arch_iommu_use_permitted() arch_pci_clean_pirqs() Note that this is not yet sufficient to enable HAS_PCI and will be addressed in follow-ups. Signed-off-by: Rahul Singh Reviewed-by: Stefano Stabellini Reviewed-by: Bertrand Marquis --- Change in v3: - Modify commit message. - Added Reviewed-by: Stefano Stabellini Change in v2: - Remove pci_conf_read*(..) dummy implementation - Add in code comment for arch_pci_clean_pirqs() and arch_iommu_use_permitt= ed() - Fixed minor comments. --- xen/arch/arm/Makefile | 1 + xen/arch/arm/pci/Makefile | 1 + xen/arch/arm/pci/pci.c | 33 +++++++++++++++++++++++++++++ xen/drivers/passthrough/arm/iommu.c | 9 ++++++++ xen/include/asm-arm/pci.h | 31 ++++++++++++++++++++++++--- 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 xen/arch/arm/pci/Makefile create mode 100644 xen/arch/arm/pci/pci.c diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 3d3b97b5b4..44d7cc81fa 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -2,6 +2,7 @@ obj-$(CONFIG_ARM_32) +=3D arm32/ obj-$(CONFIG_ARM_64) +=3D arm64/ obj-$(CONFIG_ARM_64) +=3D efi/ obj-$(CONFIG_ACPI) +=3D acpi/ +obj-$(CONFIG_HAS_PCI) +=3D pci/ ifneq ($(CONFIG_NO_PLAT),y) obj-y +=3D platforms/ endif diff --git a/xen/arch/arm/pci/Makefile b/xen/arch/arm/pci/Makefile new file mode 100644 index 0000000000..a98035df4c --- /dev/null +++ b/xen/arch/arm/pci/Makefile @@ -0,0 +1 @@ +obj-y +=3D pci.o diff --git a/xen/arch/arm/pci/pci.c b/xen/arch/arm/pci/pci.c new file mode 100644 index 0000000000..a7a7bc3213 --- /dev/null +++ b/xen/arch/arm/pci/pci.c @@ -0,0 +1,33 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +/* + * PIRQ event channels are not supported on Arm, so nothing to do. + */ +int arch_pci_clean_pirqs(struct domain *d) +{ + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/= arm/iommu.c index db3b07a571..ee653a9c48 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -135,3 +135,12 @@ void arch_iommu_domain_destroy(struct domain *d) void __hwdom_init arch_iommu_hwdom_init(struct domain *d) { } + +/* + * Unlike x86, Arm doesn't support mem-sharing, mem-paging and log-dirty (= yet). + * So there is no restriction to use the IOMMU. + */ +bool arch_iommu_use_permitted(const struct domain *d) +{ + return true; +} diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index de13359f65..7dd9eb3dba 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -1,7 +1,32 @@ -#ifndef __X86_PCI_H__ -#define __X86_PCI_H__ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ =20 +#ifndef __ARM_PCI_H__ +#define __ARM_PCI_H__ + +#ifdef CONFIG_HAS_PCI + +#define pci_to_dev(pcidev) (&(pcidev)->arch.dev) + +/* Arch pci dev struct */ struct arch_pci_dev { + struct device dev; }; =20 -#endif /* __X86_PCI_H__ */ +#else /*!CONFIG_HAS_PCI*/ + +struct arch_pci_dev { }; + +#endif /*!CONFIG_HAS_PCI*/ +#endif /* __ARM_PCI_H__ */ --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853219624161.80286881075597; Tue, 28 Sep 2021 11:20:19 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198210.351586 (Exim 4.92) (envelope-from ) id 1mVHi2-0007Zu-UC; Tue, 28 Sep 2021 18:20:06 +0000 Received: by outflank-mailman (output) from mailman id 198210.351586; Tue, 28 Sep 2021 18:20:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHi2-0007Zl-Ol; Tue, 28 Sep 2021 18:20:06 +0000 Received: by outflank-mailman (input) for mailman id 198210; Tue, 28 Sep 2021 18:20:05 +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 1mVHi1-0006l6-HU for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:20:05 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id ae47c80b-2088-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:19:56 +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 734E46D; Tue, 28 Sep 2021 11:19:56 -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 8E1703F793; Tue, 28 Sep 2021 11:19:55 -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: ae47c80b-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, Jan Beulich , Paul Durrant Subject: [PATCH v3 03/17] xen/arm: solve compilation error on ARM with ACPI && HAS_PCI Date: Tue, 28 Sep 2021 19:18:12 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1632853220947100001 prelink.o: In function `pcie_aer_get_firmware_first=E2=80=99: drivers/passthrough/pci.c:1251: undefined reference to `apei_hest_parse' Compilation error is observed when ACPI and HAS_PCI is enabled for ARM architecture. APEI not supported on ARM yet move the code under CONFIG_X86 flag to gate the code for ARM. Signed-off-by: Rahul Singh Acked-by: Stefano Stabellini Acked-by: Jan Beulich Reviewed-by: Bertrand Marquis --- Change in v3: Added Acked-by: Stefano Stabellini Change in v2: Add in code comment "APEI not supported on ARM yet" --- xen/drivers/passthrough/pci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 8996403161..d774a6154e 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -1150,7 +1150,8 @@ void __hwdom_init setup_hwdom_pci_devices( pcidevs_unlock(); } =20 -#ifdef CONFIG_ACPI +/* APEI not supported on ARM yet. */ +#if defined(CONFIG_ACPI) && defined(CONFIG_X86) #include #include =20 --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853237536919.2682779436209; Tue, 28 Sep 2021 11:20:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198217.351597 (Exim 4.92) (envelope-from ) id 1mVHiI-0008Be-AW; Tue, 28 Sep 2021 18:20:22 +0000 Received: by outflank-mailman (output) from mailman id 198217.351597; Tue, 28 Sep 2021 18:20:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHiI-0008BX-6j; Tue, 28 Sep 2021 18:20:22 +0000 Received: by outflank-mailman (input) for mailman id 198217; Tue, 28 Sep 2021 18:20:20 +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 1mVHiG-0006l6-HX for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:20:20 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id b8248dc2-2088-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:20:11 +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 9833E6D; Tue, 28 Sep 2021 11:20:11 -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 89C913F793; Tue, 28 Sep 2021 11:20:10 -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: b8248dc2-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, Ian Jackson , Wei Liu , Juergen Gross Subject: [PATCH v3 04/17] xen/arm: xc_domain_ioport_permission(..) not supported on ARM. Date: Tue, 28 Sep 2021 19:18:13 +0100 Message-Id: <9d796d7c5c6d6c2d206809f99ed0be7ec9ebe056.1632847120.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853239217100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" ARM architecture does not implement I/O ports. Ignore this call on ARM to avoid the overhead of making a hypercall just for Xen to return -ENOSYS. Signed-off-by: Rahul Singh Reviewed-by: Stefano Stabellini Reviewed-by: Bertrand Marquis --- Change in v3: Added Reviewed-by: Stefano Stabellini Change in v2: - Instead of returning success in XEN, ignored the call in xl. --- tools/libs/ctrl/xc_domain.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index 23322b70b5..25c95f6596 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -1348,6 +1348,14 @@ int xc_domain_ioport_permission(xc_interface *xch, uint32_t nr_ports, uint32_t allow_access) { +#if defined(__arm__) || defined(__aarch64__) + /* + * The ARM architecture does not implement I/O ports. + * Avoid the overhead of making a hypercall just for Xen to return -EN= OSYS. + * It is safe to ignore this call on ARM so we just return 0. + */ + return 0; +#else DECLARE_DOMCTL; =20 domctl.cmd =3D XEN_DOMCTL_ioport_permission; @@ -1357,6 +1365,7 @@ int xc_domain_ioport_permission(xc_interface *xch, domctl.u.ioport_permission.allow_access =3D allow_access; =20 return do_domctl(xch, &domctl); +#endif } =20 int xc_availheap(xc_interface *xch, --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 From nobody Fri Nov 29 16:38:33 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 1632853267003475.66757870370316; Tue, 28 Sep 2021 11:21:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198235.351618 (Exim 4.92) (envelope-from ) id 1mVHin-00014o-R2; Tue, 28 Sep 2021 18:20:53 +0000 Received: by outflank-mailman (output) from mailman id 198235.351618; Tue, 28 Sep 2021 18:20:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHin-00014d-O1; Tue, 28 Sep 2021 18:20:53 +0000 Received: by outflank-mailman (input) for mailman id 198235; Tue, 28 Sep 2021 18:20:52 +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 1mVHim-00012z-4e for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:20:52 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id cf4a5dd8-2088-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:20:50 +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 844996D; Tue, 28 Sep 2021 11:20:50 -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 9F3F73F793; Tue, 28 Sep 2021 11:20:49 -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: cf4a5dd8-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 Subject: [PATCH v3 06/17] xen/device-tree: Add dt_property_read_variable_u32_array helper Date: Tue, 28 Sep 2021 19:18:15 +0100 Message-Id: <9dba5f3457d9ead9084ac73297bf5a65e665a8d9.1632847120.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853268662100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Based Linux commit a67e9472da423ec47a3586920b526ebaedf25fc3 Import the Linux helper of_property_read_variable_u32_array. This function find and read an array of 32 bit integers from a property, with bounds on the minimum and maximum array size. Signed-off-by: Rahul Singh Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Change in v3: - Modify commit message to include upstream Linux commit-id not stable=20 Linux commit-id Change in v2: Patch introduced in v2 --- xen/common/device_tree.c | 61 +++++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 26 +++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 03d25a81ce..53160d61f8 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -208,6 +208,67 @@ int dt_property_read_string(const struct dt_device_nod= e *np, return 0; } =20 +/** + * dt_find_property_value_of_size + * + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @min: minimum allowed length of property value + * @max: maximum allowed length of property value (0 means unlimited) + * @len: if !=3DNULL, actual length is written to here + * + * Search for a property in a device node and valid the requested size. + * + * Return: The property value on success, -EINVAL if the property does not + * exist, -ENODATA if property does not have a value, and -EOVERFLOW if the + * property data is too small or too large. + */ +static void *dt_find_property_value_of_size(const struct dt_device_node *n= p, + const char *propname, u32 min, + u32 max, size_t *len) +{ + const struct dt_property *prop =3D dt_find_property(np, propname, NULL= ); + + if ( !prop ) + return ERR_PTR(-EINVAL); + if ( !prop->value ) + return ERR_PTR(-ENODATA); + if ( prop->length < min ) + return ERR_PTR(-EOVERFLOW); + if ( max && prop->length > max ) + return ERR_PTR(-EOVERFLOW); + + if ( len ) + *len =3D prop->length; + + return prop->value; +} + +int dt_property_read_variable_u32_array(const struct dt_device_node *np, + const char *propname, u32 *out_val= ues, + size_t sz_min, size_t sz_max) +{ + size_t sz, count; + const __be32 *val =3D dt_find_property_value_of_size(np, propname, + (sz_min * sizeof(*out_values)), + (sz_max * sizeof(*out_values)), + &sz); + + if ( IS_ERR(val) ) + return PTR_ERR(val); + + if ( !sz_max ) + sz =3D sz_min; + else + sz /=3D sizeof(*out_values); + + count =3D sz; + while ( count-- ) + *out_values++ =3D be32_to_cpup(val++); + + return sz; +} + int dt_property_match_string(const struct dt_device_node *np, const char *propname, const char *string) { diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index b02696be94..1693fb8e8c 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -366,6 +366,32 @@ bool_t dt_property_read_u32(const struct dt_device_nod= e *np, bool_t dt_property_read_u64(const struct dt_device_node *np, const char *name, u64 *out_value); =20 + +/** + * dt_property_read_variable_u32_array - Find and read an array of 32 bit + * integers from a property, with bounds on the minimum and maximum array = size. + * + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @out_values: pointer to return found values. + * @sz_min: minimum number of array elements to read + * @sz_max: maximum number of array elements to read, if zero there is no + * upper limit on the number of elements in the dts entry but only + * sz_min will be read. + * + * Search for a property in a device node and read 32-bit value(s) from + * it. + * + * Return: The number of elements read on success, -EINVAL if the property + * does not exist, -ENODATA if property does not have a value, and -EOVERF= LOW + * if the property data is smaller than sz_min or longer than sz_max. + * + * The out_values is modified only if a valid u32 value can be decoded. + */ +int dt_property_read_variable_u32_array(const struct dt_device_node *np, + const char *propname, u32 *out_val= ues, + size_t sz_min, size_t sz_max); + /** * dt_property_read_bool - Check if a property exists * @np: node to get the value --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853298467541.0619382276437; Tue, 28 Sep 2021 11:21:38 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198245.351630 (Exim 4.92) (envelope-from ) id 1mVHjK-0001kk-4z; Tue, 28 Sep 2021 18:21:26 +0000 Received: by outflank-mailman (output) from mailman id 198245.351630; Tue, 28 Sep 2021 18:21:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHjK-0001kZ-0p; Tue, 28 Sep 2021 18:21:26 +0000 Received: by outflank-mailman (input) for mailman id 198245; Tue, 28 Sep 2021 18:21:25 +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 1mVHjJ-0001kM-3o for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:21:25 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id e351fd90-2088-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:21:24 +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 249EB6D; Tue, 28 Sep 2021 11:21:24 -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 3F6233F793; Tue, 28 Sep 2021 11:21: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: e351fd90-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 Subject: [PATCH v3 07/17] xen/device-tree: Add dt_property_read_u32_array helper Date: Tue, 28 Sep 2021 19:18:16 +0100 Message-Id: <89788e202bc91e2bc7f9c3c33eb91ab7478381ee.1632847120.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853300184100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Based Linux commit a67e9472da423ec47a3586920b526ebaedf25fc3 Import the Linux helper of_property_read_u32_array. This function find and read an array of 32 bit integers from a property. Signed-off-by: Rahul Singh Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Change in v3: - Modify commit message to include upstream Linux commit-id not stable Linux commit-id Change in v2: Patch introduced in v2 --- xen/include/xen/device_tree.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 1693fb8e8c..3ffe3eb3d2 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -392,6 +392,36 @@ int dt_property_read_variable_u32_array(const struct d= t_device_node *np, const char *propname, u32 *out_val= ues, size_t sz_min, size_t sz_max); =20 +/** + * dt_property_read_u32_array - Find and read an array of 32 bit integers + * from a property. + * + * @np: device node from which the property value is to be read. + * @propname: name of the property to be searched. + * @out_values: pointer to return value, modified only if return value is = 0. + * @sz: number of array elements to read + * + * Search for a property in a device node and read 32-bit value(s) from + * it. + * + * Return: 0 on success, -EINVAL if the property does not exist, + * -ENODATA if property does not have a value, and -EOVERFLOW if the + * property data isn't large enough. + * + * The out_values is modified only if a valid u32 value can be decoded. + */ +static inline int dt_property_read_u32_array(const struct dt_device_node *= np, + const char *propname, + u32 *out_values, size_t sz) +{ + int ret =3D dt_property_read_variable_u32_array(np, propname, out_valu= es, + sz, 0); + if ( ret >=3D 0 ) + return 0; + else + return ret; +} + /** * dt_property_read_bool - Check if a property exists * @np: node to get the value --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853318831588.3355575576051; Tue, 28 Sep 2021 11:21:58 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198249.351640 (Exim 4.92) (envelope-from ) id 1mVHje-0002JJ-Cl; Tue, 28 Sep 2021 18:21:46 +0000 Received: by outflank-mailman (output) from mailman id 198249.351640; Tue, 28 Sep 2021 18:21:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHje-0002JC-9q; Tue, 28 Sep 2021 18:21:46 +0000 Received: by outflank-mailman (input) for mailman id 198249; Tue, 28 Sep 2021 18:21:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHjd-0002Ii-4Q for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:21:45 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 6ae4ebc5-0c61-4d20-af29-907f25ad8507; Tue, 28 Sep 2021 18:21:44 +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 DAB296D; Tue, 28 Sep 2021 11:21:43 -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 014CB3F793; Tue, 28 Sep 2021 11:21:42 -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: 6ae4ebc5-0c61-4d20-af29-907f25ad8507 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 Subject: [PATCH v3 08/17] xen/device-tree: Add dt_get_pci_domain_nr helper Date: Tue, 28 Sep 2021 19:18:17 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853320537100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Based Linux commit 41e5c0f81d3e676d671d96a0a1fafb27abfbd9d7 Import the Linux helper of_get_pci_domain_nr. This function will try to obtain the host bridge domain number by finding a property called "linux,pci-domain" of the given device node. Signed-off-by: Rahul Singh Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Change in v3: - Modify commit message to include upstream Linux commit-id not stable Linux commit-id - Remove return value as those are not valid for XEN Change in v2: Patch introduced in v2 --- xen/common/device_tree.c | 12 ++++++++++++ xen/include/xen/device_tree.h | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/xen/common/device_tree.c b/xen/common/device_tree.c index 53160d61f8..ea93da1725 100644 --- a/xen/common/device_tree.c +++ b/xen/common/device_tree.c @@ -2183,6 +2183,18 @@ void __init dt_unflatten_host_device_tree(void) dt_alias_scan(); } =20 +int dt_get_pci_domain_nr(struct dt_device_node *node) +{ + u32 domain; + int error; + + error =3D dt_property_read_u32(node, "linux,pci-domain", &domain); + if ( !error ) + return -EINVAL; + + return (u16)domain; +} + /* * Local variables: * mode: C diff --git a/xen/include/xen/device_tree.h b/xen/include/xen/device_tree.h index 3ffe3eb3d2..2297c59ce6 100644 --- a/xen/include/xen/device_tree.h +++ b/xen/include/xen/device_tree.h @@ -832,6 +832,23 @@ int dt_count_phandle_with_args(const struct dt_device_= node *np, const char *list_name, const char *cells_name); =20 +/** + * dt_get_pci_domain_nr - Find the host bridge domain number + * of the given device node. + * @node: Device tree node with the domain information. + * + * This function will try to obtain the host bridge domain number by findi= ng + * a property called "linux,pci-domain" of the given device node. + * + * Return: + * * > 0 - On success, an associated domain number. + * * -EINVAL - The property "linux,pci-domain" does not exist. + * + * Returns the associated domain number from DT in the range [0-0xffff], or + * a negative value if the required property is not found. + */ +int dt_get_pci_domain_nr(struct dt_device_node *node); + #ifdef CONFIG_DEVICE_TREE_DEBUG #define dt_dprintk(fmt, args...) \ printk(XENLOG_DEBUG fmt, ## args) --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853329976820.807413116976; Tue, 28 Sep 2021 11:22:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198253.351651 (Exim 4.92) (envelope-from ) id 1mVHjp-0002my-P3; Tue, 28 Sep 2021 18:21:57 +0000 Received: by outflank-mailman (output) from mailman id 198253.351651; Tue, 28 Sep 2021 18:21:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHjp-0002mr-M6; Tue, 28 Sep 2021 18:21:57 +0000 Received: by outflank-mailman (input) for mailman id 198253; Tue, 28 Sep 2021 18:21:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHjo-0002iO-W4 for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:21:57 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 30f8032f-a30a-47aa-b339-519f9609134c; Tue, 28 Sep 2021 18:21:56 +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 CEE896D; Tue, 28 Sep 2021 11:21:55 -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 CF1FF3F793; Tue, 28 Sep 2021 11:21:54 -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: 30f8032f-a30a-47aa-b339-519f9609134c 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 Subject: [PATCH v3 09/17] xen/arm: Add support for PCI init to initialize the PCI driver. Date: Tue, 28 Sep 2021 19:18:18 +0100 Message-Id: <31f2e3baf45f059a8ddac22fefc7cdfe1bc63ef5.1632847120.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853331491100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" pci_init(..) will be called during xen startup to initialize and probe the PCI host-bridge driver. Signed-off-by: Rahul Singh Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Change in v3: - Some nit for device_init(..) return logic - Remove inline from acpi_pci_init(..) - Modify return value for apci_pci_init(..) to return -EOPNOTSUPP Change in v2: - ACPI init function to return int - pci_segments_init() called before dt/acpi init --- xen/arch/arm/pci/pci.c | 51 ++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/device.h | 1 + 2 files changed, 52 insertions(+) diff --git a/xen/arch/arm/pci/pci.c b/xen/arch/arm/pci/pci.c index a7a7bc3213..e359bab9ea 100644 --- a/xen/arch/arm/pci/pci.c +++ b/xen/arch/arm/pci/pci.c @@ -12,6 +12,10 @@ * along with this program. If not, see . */ =20 +#include +#include +#include +#include #include =20 /* @@ -22,6 +26,53 @@ int arch_pci_clean_pirqs(struct domain *d) return 0; } =20 +static int __init dt_pci_init(void) +{ + struct dt_device_node *np; + int rc; + + dt_for_each_device_node(dt_host, np) + { + rc =3D device_init(np, DEVICE_PCI, NULL); + /* + * Ignore the following error codes: + * - EBADF: Indicate the current device is not a pci device. + * - ENODEV: The pci device is not present or cannot be used by + * Xen. + */ + if( !rc || rc =3D=3D -EBADF || rc =3D=3D -ENODEV ) + continue; + + return rc; + } + + return 0; +} + +#ifdef CONFIG_ACPI +static int __init acpi_pci_init(void) +{ + printk(XENLOG_ERR "ACPI pci init not supported \n"); + return -EOPNOTSUPP; +} +#else +static int __init acpi_pci_init(void) +{ + return -EINVAL; +} +#endif + +static int __init pci_init(void) +{ + pci_segments_init(); + + if ( acpi_disabled ) + return dt_pci_init(); + else + return acpi_pci_init(); +} +__initcall(pci_init); + /* * Local variables: * mode: C diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index ee7cff2d44..5ecd5e7bd1 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -34,6 +34,7 @@ enum device_class DEVICE_SERIAL, DEVICE_IOMMU, DEVICE_GIC, + DEVICE_PCI, /* Use for error */ DEVICE_UNKNOWN, }; --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853346852303.78865176509817; Tue, 28 Sep 2021 11:22:26 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198261.351663 (Exim 4.92) (envelope-from ) id 1mVHk6-0003Rm-47; Tue, 28 Sep 2021 18:22:14 +0000 Received: by outflank-mailman (output) from mailman id 198261.351663; Tue, 28 Sep 2021 18:22:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHk6-0003Rf-0q; Tue, 28 Sep 2021 18:22:14 +0000 Received: by outflank-mailman (input) for mailman id 198261; Tue, 28 Sep 2021 18:22:13 +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 1mVHk4-0003C1-W1 for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:22:13 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id fc9694f0-2088-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:22:06 +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 8A2D26D; Tue, 28 Sep 2021 11:22:06 -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 DB6093F793; Tue, 28 Sep 2021 11:22:04 -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: fc9694f0-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, Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v3 10/17] xen/arm: Add cmdline boot option "pci-passthrough = " Date: Tue, 28 Sep 2021 19:18:19 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853347678100003 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add cmdline boot option "pci-passthrough =3D =3D " to enable or disable the PCI passthrough support on ARM. Signed-off-by: Rahul Singh Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Change in v3: - Remove "define pci_passthrough_enabled (false)" - Fixed coding style and minor comment Change in v2: - Add option in xen-command-line.pandoc - Change pci option to pci-passthrough - modify option from custom_param to boolean param --- docs/misc/xen-command-line.pandoc | 7 +++++++ xen/arch/arm/pci/pci.c | 14 ++++++++++++++ xen/common/physdev.c | 6 ++++++ xen/include/asm-arm/pci.h | 11 +++++++++++ xen/include/asm-x86/pci.h | 8 ++++++++ 5 files changed, 46 insertions(+) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 177e656f12..c8bf96ccf8 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1808,6 +1808,13 @@ All numbers specified must be hexadecimal ones. =20 This option can be specified more than once (up to 8 times at present). =20 +### pci-passthrough (arm) +> `=3D ` + +> Default: `false` + +Flag to enable or disable support for PCI passthrough + ### pcid (x86) > `=3D | xpti=3D` =20 diff --git a/xen/arch/arm/pci/pci.c b/xen/arch/arm/pci/pci.c index e359bab9ea..84d8f0d634 100644 --- a/xen/arch/arm/pci/pci.c +++ b/xen/arch/arm/pci/pci.c @@ -16,6 +16,7 @@ #include #include #include +#include #include =20 /* @@ -62,8 +63,21 @@ static int __init acpi_pci_init(void) } #endif =20 +/* + * By default pci passthrough is disabled + */ +bool __read_mostly pci_passthrough_enabled =3D false; +boolean_param("pci-passthrough", pci_passthrough_enabled); + static int __init pci_init(void) { + /* + * Enable PCI passthrough when has been enabled explicitly + * (pci-passthrough=3Don) + */ + if ( !pci_passthrough_enabled ) + return 0; + pci_segments_init(); =20 if ( acpi_disabled ) diff --git a/xen/common/physdev.c b/xen/common/physdev.c index 20a5530269..2d5fc886fc 100644 --- a/xen/common/physdev.c +++ b/xen/common/physdev.c @@ -19,6 +19,9 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void)= arg) struct pci_dev_info pdev_info; nodeid_t node; =20 + if ( !is_pci_passthrough_enabled() ) + return -ENOSYS; + ret =3D -EFAULT; if ( copy_from_guest(&add, arg, 1) !=3D 0 ) break; @@ -54,6 +57,9 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void)= arg) case PHYSDEVOP_pci_device_remove: { struct physdev_pci_device dev; =20 + if ( !is_pci_passthrough_enabled() ) + return -ENOSYS; + ret =3D -EFAULT; if ( copy_from_guest(&dev, arg, 1) !=3D 0 ) break; diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index 7dd9eb3dba..0cf849e26f 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -19,14 +19,25 @@ =20 #define pci_to_dev(pcidev) (&(pcidev)->arch.dev) =20 +extern bool_t pci_passthrough_enabled; + /* Arch pci dev struct */ struct arch_pci_dev { struct device dev; }; =20 +static always_inline bool is_pci_passthrough_enabled(void) +{ + return pci_passthrough_enabled; +} #else /*!CONFIG_HAS_PCI*/ =20 struct arch_pci_dev { }; =20 +static always_inline bool is_pci_passthrough_enabled(void) +{ + return false; +} + #endif /*!CONFIG_HAS_PCI*/ #endif /* __ARM_PCI_H__ */ diff --git a/xen/include/asm-x86/pci.h b/xen/include/asm-x86/pci.h index cc05045e9c..3f806ce7a8 100644 --- a/xen/include/asm-x86/pci.h +++ b/xen/include/asm-x86/pci.h @@ -32,4 +32,12 @@ bool_t pci_ro_mmcfg_decode(unsigned long mfn, unsigned i= nt *seg, extern int pci_mmcfg_config_num; extern struct acpi_mcfg_allocation *pci_mmcfg_config; =20 +/* + * Unlike ARM, PCI passthrough is always enabled for x86. + */ +static always_inline bool is_pci_passthrough_enabled(void) +{ + return true; +} + #endif /* __X86_PCI_H__ */ --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853372193209.75288876863237; Tue, 28 Sep 2021 11:22:52 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198272.351674 (Exim 4.92) (envelope-from ) id 1mVHkT-0004BI-Ca; Tue, 28 Sep 2021 18:22:37 +0000 Received: by outflank-mailman (output) from mailman id 198272.351674; Tue, 28 Sep 2021 18:22:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHkT-0004B7-9Q; Tue, 28 Sep 2021 18:22:37 +0000 Received: by outflank-mailman (input) for mailman id 198272; Tue, 28 Sep 2021 18:22:35 +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 1mVHkR-00049L-Gr for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:22:35 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 0c953712-2089-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:22:33 +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 6A9946D; Tue, 28 Sep 2021 11:22:33 -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 BDD7C3F793; Tue, 28 Sep 2021 11:22:31 -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: 0c953712-2089-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 Subject: [PATCH v3 11/17] xen/arm: PCI host bridge discovery within XEN on ARM Date: Tue, 28 Sep 2021 19:18:20 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1632853373618100001 XEN during boot will read the PCI device tree node =E2=80=9Creg=E2=80=9D pr= operty and will map the PCI config space to the XEN memory. As of now only "pci-host-ecam-generic" compatible board is supported. "linux,pci-domain" device tree property assigns a fixed PCI domain number to a host bridge, otherwise an unstable (across boots) unique number will be assigned by Linux. XEN access the PCI devices based on Segment:Bus:Device:Function. A Segment number in the XEN is same as a domain number in Linux. Segment number and domain number has to be in sync to access the correct PCI devices. XEN will read the =E2=80=9Clinux,pci-domain=E2=80=9D property from the devi= ce tree node and configure the host bridge segment number accordingly. If this property is not available XEN will allocate the unique segment number to the host bridge. Signed-off-by: Rahul Singh Acked-by: Jan Beulich --- Change in v3: - Modify commit msg based on received comments. - Remove added struct match_table{} struct in struct device{} - Replace uint32_t sbdf to pci_sbdf_t sbdf to avoid typecast - Remove bus_start,bus_end and void *sysdata from struct pci_host_bridge{} - Move "#include " in "xen/pci.h" after pci_sbdf_t sbdf declarat= ion - Add pci_host_generic_probe() function=20 Change in v2: - Add more info in commit msg - Add callback to parse register index. - Merge patch pci_ecam_operation into this patch to avoid confusion - Add new struct in struct device for match table --- xen/arch/arm/pci/Makefile | 4 + xen/arch/arm/pci/ecam.c | 61 +++++++ xen/arch/arm/pci/pci-access.c | 83 ++++++++++ xen/arch/arm/pci/pci-host-common.c | 247 ++++++++++++++++++++++++++++ xen/arch/arm/pci/pci-host-generic.c | 46 ++++++ xen/include/asm-arm/pci.h | 56 +++++++ xen/include/xen/pci.h | 3 +- 7 files changed, 499 insertions(+), 1 deletion(-) create mode 100644 xen/arch/arm/pci/ecam.c create mode 100644 xen/arch/arm/pci/pci-access.c create mode 100644 xen/arch/arm/pci/pci-host-common.c create mode 100644 xen/arch/arm/pci/pci-host-generic.c diff --git a/xen/arch/arm/pci/Makefile b/xen/arch/arm/pci/Makefile index a98035df4c..6f32fbbe67 100644 --- a/xen/arch/arm/pci/Makefile +++ b/xen/arch/arm/pci/Makefile @@ -1 +1,5 @@ obj-y +=3D pci.o +obj-y +=3D pci-access.o +obj-y +=3D pci-host-generic.o +obj-y +=3D pci-host-common.o +obj-y +=3D ecam.o diff --git a/xen/arch/arm/pci/ecam.c b/xen/arch/arm/pci/ecam.c new file mode 100644 index 0000000000..602d00799c --- /dev/null +++ b/xen/arch/arm/pci/ecam.c @@ -0,0 +1,61 @@ +/* + * Based on Linux drivers/pci/ecam.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +/* + * Function to implement the pci_ops->map_bus method. + */ +void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge, + pci_sbdf_t sbdf, uint32_t where) +{ + const struct pci_config_window *cfg =3D bridge->cfg; + struct pci_ecam_ops *ops =3D + container_of(bridge->ops, struct pci_ecam_ops, pci_ops); + unsigned int devfn_shift =3D ops->bus_shift - 8; + void __iomem *base; + + unsigned int busn =3D PCI_BUS(sbdf.bdf); + + if ( busn < cfg->busn_start || busn > cfg->busn_end ) + return NULL; + + busn -=3D cfg->busn_start; + base =3D cfg->win + (busn << ops->bus_shift); + + return base + (PCI_DEVFN2(sbdf.bdf) << devfn_shift) + where; +} + +/* ECAM ops */ +const struct pci_ecam_ops pci_generic_ecam_ops =3D { + .bus_shift =3D 20, + .pci_ops =3D { + .map_bus =3D pci_ecam_map_bus, + .read =3D pci_generic_config_read, + .write =3D pci_generic_config_write, + } +}; + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/pci/pci-access.c b/xen/arch/arm/pci/pci-access.c new file mode 100644 index 0000000000..3cd14a4b87 --- /dev/null +++ b/xen/arch/arm/pci/pci-access.c @@ -0,0 +1,83 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include + +#define INVALID_VALUE (~0U) + +int pci_generic_config_read(struct pci_host_bridge *bridge, pci_sbdf_t sbd= f, + uint32_t reg, uint32_t len, uint32_t *value) +{ + void __iomem *addr =3D bridge->ops->map_bus(bridge, sbdf, reg); + + if ( !addr ) + { + *value =3D INVALID_VALUE; + return -ENODEV; + } + + switch ( len ) + { + case 1: + *value =3D readb(addr); + break; + case 2: + *value =3D readw(addr); + break; + case 4: + *value =3D readl(addr); + break; + default: + ASSERT_UNREACHABLE(); + } + + return 0; +} + +int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sb= df, + uint32_t reg, uint32_t len, uint32_t value) +{ + void __iomem *addr =3D bridge->ops->map_bus(bridge, sbdf, reg); + + if ( !addr ) + return -ENODEV; + + switch ( len ) + { + case 1: + writeb(value, addr); + break; + case 2: + writew(value, addr); + break; + case 4: + writel(value, addr); + break; + default: + ASSERT_UNREACHABLE(); + } + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host= -common.c new file mode 100644 index 0000000000..a08e06cea1 --- /dev/null +++ b/xen/arch/arm/pci/pci-host-common.c @@ -0,0 +1,247 @@ +/* + * Based on Linux drivers/pci/ecam.c + * Based on Linux drivers/pci/controller/pci-host-common.c + * Based on Linux drivers/pci/controller/pci-host-generic.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include + +/* + * List for all the pci host bridges. + */ + +static LIST_HEAD(pci_host_bridges); + +static atomic_t domain_nr =3D ATOMIC_INIT(-1); + +static inline void __iomem *pci_remap_cfgspace(paddr_t start, size_t len) +{ + return ioremap_nocache(start, len); +} + +static void pci_ecam_free(struct pci_config_window *cfg) +{ + if ( cfg->win ) + iounmap(cfg->win); + + xfree(cfg); +} + +static struct pci_config_window * __init +gen_pci_init(struct dt_device_node *dev, const struct pci_ecam_ops *ops) +{ + int err, cfg_reg_idx; + u32 bus_range[2]; + paddr_t addr, size; + struct pci_config_window *cfg; + + cfg =3D xzalloc(struct pci_config_window); + if ( !cfg ) + return NULL; + + err =3D dt_property_read_u32_array(dev, "bus-range", bus_range, + ARRAY_SIZE(bus_range)); + if ( err ) { + cfg->busn_start =3D 0; + cfg->busn_end =3D 0xff; + printk(XENLOG_INFO "%s: No bus range found for pci controller\n", + dt_node_full_name(dev)); + } else { + cfg->busn_start =3D bus_range[0]; + cfg->busn_end =3D bus_range[1]; + if ( cfg->busn_end > cfg->busn_start + 0xff ) + cfg->busn_end =3D cfg->busn_start + 0xff; + } + + if ( ops->cfg_reg_index ) + { + cfg_reg_idx =3D ops->cfg_reg_index(dev); + if ( cfg_reg_idx < 0 ) + goto err_exit; + } + else + cfg_reg_idx =3D 0; + + /* Parse our PCI ecam register address */ + err =3D dt_device_get_address(dev, cfg_reg_idx, &addr, &size); + if ( err ) + goto err_exit; + + cfg->phys_addr =3D addr; + cfg->size =3D size; + + /* + * On 64-bit systems, we do a single ioremap for the whole config space + * since we have enough virtual address range available. On 32-bit, we + * ioremap the config space for each bus individually. + * As of now only 64-bit is supported 32-bit is not supported. + * + * TODO: For 32-bit implement the ioremap/iounmap of config space + * dynamically for each read/write call. + */ + cfg->win =3D pci_remap_cfgspace(cfg->phys_addr, cfg->size); + if ( !cfg->win ) + { + printk(XENLOG_ERR "ECAM ioremap failed\n"); + goto err_exit; + } + printk("ECAM at [mem 0x%"PRIpaddr"-0x%"PRIpaddr"] for [bus %x-%x] \n", + cfg->phys_addr, cfg->phys_addr + cfg->size - 1, + cfg->busn_start, cfg->busn_end); + + if ( ops->init ) + { + err =3D ops->init(cfg); + if ( err ) + goto err_exit; + } + + return cfg; + +err_exit: + pci_ecam_free(cfg); + + return NULL; +} + +struct pci_host_bridge *pci_alloc_host_bridge(void) +{ + struct pci_host_bridge *bridge =3D xzalloc(struct pci_host_bridge); + + if ( !bridge ) + return NULL; + + INIT_LIST_HEAD(&bridge->node); + + return bridge; +} + +void pci_add_host_bridge(struct pci_host_bridge *bridge) +{ + list_add_tail(&bridge->node, &pci_host_bridges); +} + +static int pci_get_new_domain_nr(void) +{ + return atomic_inc_return(&domain_nr); +} + +static int pci_bus_find_domain_nr(struct dt_device_node *dev) +{ + static int use_dt_domains =3D -1; + int domain; + + domain =3D dt_get_pci_domain_nr(dev); + + /* + * Check DT domain and use_dt_domains values. + * + * If DT domain property is valid (domain >=3D 0) and + * use_dt_domains !=3D 0, the DT assignment is valid since this means + * we have not previously allocated a domain number by using + * pci_get_new_domain_nr(); we should also update use_dt_domains to + * 1, to indicate that we have just assigned a domain number from + * DT. + * + * If DT domain property value is not valid (ie domain < 0), and we + * have not previously assigned a domain number from DT + * (use_dt_domains !=3D 1) we should assign a domain number by + * using the: + * + * pci_get_new_domain_nr() + * + * API and update the use_dt_domains value to keep track of method we + * are using to assign domain numbers (use_dt_domains =3D 0). + * + * All other combinations imply we have a platform that is trying + * to mix domain numbers obtained from DT and pci_get_new_domain_nr(), + * which is a recipe for domain mishandling and it is prevented by + * invalidating the domain value (domain =3D -1) and printing a + * corresponding error. + */ + if ( domain >=3D 0 && use_dt_domains ) + { + use_dt_domains =3D 1; + } + else if ( domain < 0 && use_dt_domains !=3D 1 ) + { + use_dt_domains =3D 0; + domain =3D pci_get_new_domain_nr(); + } + else + { + domain =3D -1; + } + + return domain; +} + +int pci_host_common_probe(struct dt_device_node *dev, const void *data) +{ + struct pci_host_bridge *bridge; + struct pci_config_window *cfg; + struct pci_ecam_ops *ops; + int err; + + if ( dt_device_for_passthrough(dev) ) + return 0; + + ops =3D (struct pci_ecam_ops *) data; + + bridge =3D pci_alloc_host_bridge(); + if ( !bridge ) + return -ENOMEM; + + /* Parse and map our Configuration Space windows */ + cfg =3D gen_pci_init(dev, ops); + if ( !cfg ) + { + err =3D -ENOMEM; + goto err_exit; + } + + bridge->dt_node =3D dev; + bridge->cfg =3D cfg; + bridge->ops =3D &ops->pci_ops; + + bridge->segment =3D pci_bus_find_domain_nr(dev); + if ( bridge->segment < 0 ) + { + printk(XENLOG_ERR "Inconsistent \"linux,pci-domain\" property in D= T\n"); + BUG(); + } + pci_add_host_bridge(bridge); + + return 0; + +err_exit: + xfree(bridge); + + return err; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/arm/pci/pci-host-generic.c b/xen/arch/arm/pci/pci-hos= t-generic.c new file mode 100644 index 0000000000..5e4f8f28a0 --- /dev/null +++ b/xen/arch/arm/pci/pci-host-generic.c @@ -0,0 +1,46 @@ +/* + * Based on Linux drivers/pci/controller/pci-host-common.c + * Based on Linux drivers/pci/controller/pci-host-generic.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +static const struct dt_device_match gen_pci_dt_match[] =3D { + { .compatible =3D "pci-host-ecam-generic" }, + { }, +}; + +static int pci_host_generic_probe(struct dt_device_node *dev, + const void *data) +{ + return pci_host_common_probe(dev, &pci_generic_ecam_ops); +} + +DT_DEVICE_START(pci_gen, "PCI HOST GENERIC", DEVICE_PCI) +.dt_match =3D gen_pci_dt_match, +.init =3D pci_host_generic_probe, +DT_DEVICE_END + +/* + * 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/pci.h b/xen/include/asm-arm/pci.h index 0cf849e26f..bb7eda6705 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -26,6 +26,62 @@ struct arch_pci_dev { struct device dev; }; =20 +/* + * struct to hold the mappings of a config space window. This + * is expected to be used as sysdata for PCI controllers that + * use ECAM. + */ +struct pci_config_window { + paddr_t phys_addr; + paddr_t size; + uint8_t busn_start; + uint8_t busn_end; + void __iomem *win; +}; + +/* + * struct to hold pci host bridge information + * for a PCI controller. + */ +struct pci_host_bridge { + struct dt_device_node *dt_node; /* Pointer to the associated DT node = */ + struct list_head node; /* Node in list of host bridges */ + uint16_t segment; /* Segment number */ + struct pci_config_window* cfg; /* Pointer to the bridge config windo= w */ + struct pci_ops *ops; +}; + +struct pci_ops { + void __iomem *(*map_bus)(struct pci_host_bridge *bridge, pci_sbdf_t sb= df, + uint32_t offset); + int (*read)(struct pci_host_bridge *bridge, pci_sbdf_t sbdf, + uint32_t reg, uint32_t len, uint32_t *value); + int (*write)(struct pci_host_bridge *bridge, pci_sbdf_t sbdf, + uint32_t reg, uint32_t len, uint32_t value); +}; + +/* + * struct to hold pci ops and bus shift of the config window + * for a PCI controller. + */ +struct pci_ecam_ops { + unsigned int bus_shift; + struct pci_ops pci_ops; + int (*cfg_reg_index)(struct dt_device_node *dev); + int (*init)(struct pci_config_window *); +}; + +/* Default ECAM ops */ +extern const struct pci_ecam_ops pci_generic_ecam_ops; + +int pci_host_common_probe(struct dt_device_node *dev, const void *data); +int pci_generic_config_read(struct pci_host_bridge *bridge, pci_sbdf_t sbd= f, + uint32_t reg, uint32_t len, uint32_t *value); +int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sb= df, + uint32_t reg, uint32_t len, uint32_t value); +void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge, + pci_sbdf_t sbdf, uint32_t where); + static always_inline bool is_pci_passthrough_enabled(void) { return pci_passthrough_enabled; diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 8e3d4d9454..70ac25345c 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -15,7 +15,6 @@ #include #include #include -#include =20 /* * The PCI interface treats multi-function devices as independent @@ -62,6 +61,8 @@ typedef union { }; } pci_sbdf_t; =20 +#include + struct pci_dev_info { /* * VF's 'is_extfn' field is used to indicate whether its PF is an exte= nded --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853388206331.25090962869047; Tue, 28 Sep 2021 11:23:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198278.351685 (Exim 4.92) (envelope-from ) id 1mVHkk-0004j9-Qo; Tue, 28 Sep 2021 18:22:54 +0000 Received: by outflank-mailman (output) from mailman id 198278.351685; Tue, 28 Sep 2021 18:22:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHkk-0004j2-NC; Tue, 28 Sep 2021 18:22:54 +0000 Received: by outflank-mailman (input) for mailman id 198278; Tue, 28 Sep 2021 18:22:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHkj-0004g0-Eq for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:22:53 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 8c62079f-236d-49c5-9a98-bd6b520a552e; Tue, 28 Sep 2021 18:22:52 +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 0810B6D; Tue, 28 Sep 2021 11:22:52 -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 E1B873F793; Tue, 28 Sep 2021 11:22:50 -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: 8c62079f-236d-49c5-9a98-bd6b520a552e From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Andre.Przywara@arm.com, Oleksandr Andrushchenko , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH v3 12/17] xen/arm: Add support for Xilinx ZynqMP PCI host controller Date: Tue, 28 Sep 2021 19:18:21 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853389264100005 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Oleksandr Andrushchenko Add support for Xilinx ZynqMP PCI host controller to map the PCI config space to the XEN memory. Patch helps to understand how the generic infrastructure for PCI host-bridge discovery will be used for future references. Signed-off-by: Oleksandr Andrushchenko Reviewed-by: Bertrand Marquis --- Change in v3: - nwl_cfg_reg_index(..) as static function - Add support for pci_host_generic_probe()=20 Change in v2: - Add more info in commit msg --- xen/arch/arm/pci/Makefile | 1 + xen/arch/arm/pci/pci-host-zynqmp.c | 63 ++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 xen/arch/arm/pci/pci-host-zynqmp.c diff --git a/xen/arch/arm/pci/Makefile b/xen/arch/arm/pci/Makefile index 6f32fbbe67..1d045ade01 100644 --- a/xen/arch/arm/pci/Makefile +++ b/xen/arch/arm/pci/Makefile @@ -3,3 +3,4 @@ obj-y +=3D pci-access.o obj-y +=3D pci-host-generic.o obj-y +=3D pci-host-common.o obj-y +=3D ecam.o +obj-y +=3D pci-host-zynqmp.o diff --git a/xen/arch/arm/pci/pci-host-zynqmp.c b/xen/arch/arm/pci/pci-host= -zynqmp.c new file mode 100644 index 0000000000..6ccbfd15c9 --- /dev/null +++ b/xen/arch/arm/pci/pci-host-zynqmp.c @@ -0,0 +1,63 @@ +/* + * Based on Linux drivers/pci/controller/pci-host-common.c + * Based on Linux drivers/pci/controller/pci-host-generic.c + * Based on xen/arch/arm/pci/pci-host-generic.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +static int nwl_cfg_reg_index(struct dt_device_node *np) +{ + return dt_property_match_string(np, "reg-names", "cfg"); +} + +/* ECAM ops */ +const struct pci_ecam_ops nwl_pcie_ops =3D { + .bus_shift =3D 20, + .cfg_reg_index =3D nwl_cfg_reg_index, + .pci_ops =3D { + .map_bus =3D pci_ecam_map_bus, + .read =3D pci_generic_config_read, + .write =3D pci_generic_config_write, + } +}; + +static const struct dt_device_match nwl_pcie_dt_match[] =3D { + { .compatible =3D "xlnx,nwl-pcie-2.11" }, + { }, +}; + +static int pci_host_generic_probe(struct dt_device_node *dev, + const void *data) +{ + return pci_host_common_probe(dev, &nwl_pcie_ops); +} + +DT_DEVICE_START(pci_gen, "PCI HOST ZYNQMP", DEVICE_PCI) +.dt_match =3D nwl_pcie_dt_match, +.init =3D pci_host_generic_probe, +DT_DEVICE_END + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853389430736.4509395831831; Tue, 28 Sep 2021 11:23:09 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198280.351696 (Exim 4.92) (envelope-from ) id 1mVHko-00054c-3F; Tue, 28 Sep 2021 18:22:58 +0000 Received: by outflank-mailman (output) from mailman id 198280.351696; Tue, 28 Sep 2021 18:22:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHkn-00054R-VN; Tue, 28 Sep 2021 18:22:57 +0000 Received: by outflank-mailman (input) for mailman id 198280; Tue, 28 Sep 2021 18:22:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHkn-0004g0-Bj for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:22:57 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id a725ef51-be9c-48fa-a825-9e0c02c51380; Tue, 28 Sep 2021 18:22:55 +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 220626D; Tue, 28 Sep 2021 11:22:55 -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 214DB3F793; Tue, 28 Sep 2021 11:22:54 -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: a725ef51-be9c-48fa-a825-9e0c02c51380 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 Subject: [PATCH v3 13/17] xen/arm: Implement pci access functions Date: Tue, 28 Sep 2021 19:18:22 +0100 Message-Id: <33cc6b7a133787700ea8ba4e54a03141d3aca1ea.1632847120.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853391424100009 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Implement generic pci access functions to read/write the configuration space. Signed-off-by: Rahul Singh Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Change in v3: - Remove PRI_pci as not used. - Replace uint32_t sbdf to pci_sbdf_t sbdf to avoid typecast Change in v2: Fixed comments --- xen/arch/arm/pci/pci-access.c | 57 ++++++++++++++++++++++++++++++ xen/arch/arm/pci/pci-host-common.c | 19 ++++++++++ xen/include/asm-arm/pci.h | 1 + 3 files changed, 77 insertions(+) diff --git a/xen/arch/arm/pci/pci-access.c b/xen/arch/arm/pci/pci-access.c index 3cd14a4b87..9f9aac43d7 100644 --- a/xen/arch/arm/pci/pci-access.c +++ b/xen/arch/arm/pci/pci-access.c @@ -16,6 +16,7 @@ #include =20 #define INVALID_VALUE (~0U) +#define PCI_ERR_VALUE(len) GENMASK(0, len * 8) =20 int pci_generic_config_read(struct pci_host_bridge *bridge, pci_sbdf_t sbd= f, uint32_t reg, uint32_t len, uint32_t *value) @@ -72,6 +73,62 @@ int pci_generic_config_write(struct pci_host_bridge *bri= dge, pci_sbdf_t sbdf, return 0; } =20 +static uint32_t pci_config_read(pci_sbdf_t sbdf, unsigned int reg, + unsigned int len) +{ + uint32_t val =3D PCI_ERR_VALUE(len); + struct pci_host_bridge *bridge =3D pci_find_host_bridge(sbdf.seg, sbdf= .bus); + + if ( unlikely(!bridge) ) + return val; + + if ( unlikely(!bridge->ops->read) ) + return val; + + bridge->ops->read(bridge, sbdf, reg, len, &val); + + return val; +} + +static void pci_config_write(pci_sbdf_t sbdf, unsigned int reg, + unsigned int len, uint32_t val) +{ + struct pci_host_bridge *bridge =3D pci_find_host_bridge(sbdf.seg, sbdf= .bus); + + if ( unlikely(!bridge) ) + return; + + if ( unlikely(!bridge->ops->write) ) + return; + + bridge->ops->write(bridge, sbdf, reg, len, val); +} + +/* + * Wrappers for all PCI configuration access functions. + */ + +#define PCI_OP_WRITE(size, type) \ + void pci_conf_write##size(pci_sbdf_t sbdf, \ + unsigned int reg, type val) \ +{ \ + pci_config_write(sbdf, reg, size / 8, val); \ +} + +#define PCI_OP_READ(size, type) \ + type pci_conf_read##size(pci_sbdf_t sbdf, \ + unsigned int reg) \ +{ \ + return pci_config_read(sbdf, reg, size / 8); \ +} + +PCI_OP_READ(8, uint8_t) +PCI_OP_READ(16, uint16_t) +PCI_OP_READ(32, uint32_t) +PCI_OP_WRITE(8, uint8_t) +PCI_OP_WRITE(16, uint16_t) +PCI_OP_WRITE(32, uint32_t) + /* * Local variables: * mode: C diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host= -common.c index a08e06cea1..c5941b10e9 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -236,6 +236,25 @@ err_exit: return err; } =20 +/* + * This function will lookup an hostbridge based on the segment and bus + * number. + */ +struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus) +{ + struct pci_host_bridge *bridge; + + list_for_each_entry( bridge, &pci_host_bridges, node ) + { + if ( bridge->segment !=3D segment ) + continue; + if ( (bus < bridge->cfg->busn_start) || (bus > bridge->cfg->busn_e= nd) ) + continue; + return bridge; + } + + return NULL; +} /* * Local variables: * mode: C diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index bb7eda6705..49c9622902 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -81,6 +81,7 @@ int pci_generic_config_write(struct pci_host_bridge *brid= ge, pci_sbdf_t sbdf, uint32_t reg, uint32_t len, uint32_t value); void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge, pci_sbdf_t sbdf, uint32_t where); +struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus= ); =20 static always_inline bool is_pci_passthrough_enabled(void) { --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853439016887.6060671648078; Tue, 28 Sep 2021 11:23:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198302.351729 (Exim 4.92) (envelope-from ) id 1mVHlW-0006yv-TL; Tue, 28 Sep 2021 18:23:42 +0000 Received: by outflank-mailman (output) from mailman id 198302.351729; Tue, 28 Sep 2021 18:23:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHlW-0006yl-Q3; Tue, 28 Sep 2021 18:23:42 +0000 Received: by outflank-mailman (input) for mailman id 198302; Tue, 28 Sep 2021 18:23:40 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHlU-0005t2-KV for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:23:40 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 113a5697-4cfd-44ca-9739-44131b0b555f; Tue, 28 Sep 2021 18:23:36 +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 629266D; Tue, 28 Sep 2021 11:23:36 -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 9B1DA3F793; Tue, 28 Sep 2021 11:23:34 -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: 113a5697-4cfd-44ca-9739-44131b0b555f 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?= , Paul Durrant Subject: [PATCH v3 14/17] xen/arm: Enable the existing x86 virtual PCI support for ARM. Date: Tue, 28 Sep 2021 19:18:23 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1632853440371100001 The existing VPCI support available for X86 is adapted for Arm. When the device is added to XEN via the hyper call =E2=80=9CPHYSDEVOP_pci_device_add=E2=80=9D, VPCI handler for the config spa= ce access is added to the Xen to emulate the PCI devices config space. A MMIO trap handler for the PCI ECAM space is registered in XEN so that when guest is trying to access the PCI config space,XEN will trap the access and emulate read/write using the VPCI and not the real PCI hardware. For Dom0less systems scan_pci_devices() would be used to discover the PCI device in XEN and VPCI handler will be added during XEN boots. Signed-off-by: Rahul Singh Reviewed-by: Stefano Stabellini --- Change in v3: - Use is_pci_passthrough_enabled() in place of pci_passthrough_enabled vari= able - Reject XEN_DOMCTL_CDF_vpci for x86 in arch_sanitise_domain_config() - Remove IS_ENABLED(CONFIG_HAS_VPCI) from has_vpci() Change in v2: - Add new XEN_DOMCTL_CDF_vpci flag - modify has_vpci() to include XEN_DOMCTL_CDF_vpci - enable vpci support when pci-passthough option is enabled. --- xen/arch/arm/Makefile | 1 + xen/arch/arm/domain.c | 8 ++- xen/arch/arm/domain_build.c | 3 + xen/arch/arm/vpci.c | 102 ++++++++++++++++++++++++++++++++++ xen/arch/arm/vpci.h | 36 ++++++++++++ xen/arch/x86/domain.c | 6 ++ xen/common/domain.c | 2 +- xen/drivers/passthrough/pci.c | 12 ++++ xen/include/asm-arm/domain.h | 8 ++- xen/include/asm-x86/pci.h | 2 - xen/include/public/arch-arm.h | 7 +++ xen/include/public/domctl.h | 4 +- xen/include/xen/pci.h | 2 + 13 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 xen/arch/arm/vpci.c create mode 100644 xen/arch/arm/vpci.h diff --git a/xen/arch/arm/Makefile b/xen/arch/arm/Makefile index 44d7cc81fa..fb9c976ea2 100644 --- a/xen/arch/arm/Makefile +++ b/xen/arch/arm/Makefile @@ -7,6 +7,7 @@ ifneq ($(CONFIG_NO_PLAT),y) obj-y +=3D platforms/ endif obj-$(CONFIG_TEE) +=3D tee/ +obj-$(CONFIG_HAS_VPCI) +=3D vpci.o =20 obj-$(CONFIG_HAS_ALTERNATIVE) +=3D alternative.o obj-y +=3D bootfdt.init.o diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 19c756ac3d..fbb52f78f1 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -39,6 +39,7 @@ #include #include =20 +#include "vpci.h" #include "vuart.h" =20 DEFINE_PER_CPU(struct vcpu *, curr_vcpu); @@ -622,8 +623,8 @@ int arch_sanitise_domain_config(struct xen_domctl_creat= edomain *config) { unsigned int max_vcpus; =20 - /* HVM and HAP must be set. IOMMU may or may not be */ - if ( (config->flags & ~XEN_DOMCTL_CDF_iommu) !=3D + /* HVM and HAP must be set. IOMMU and VPCI may or may not be */ + if ( (config->flags & ~XEN_DOMCTL_CDF_iommu & ~XEN_DOMCTL_CDF_vpci) != =3D (XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap) ) { dprintk(XENLOG_INFO, "Unsupported configuration %#x\n", @@ -767,6 +768,9 @@ int arch_domain_create(struct domain *d, if ( is_hardware_domain(d) && (rc =3D domain_vuart_init(d)) ) goto fail; =20 + if ( (rc =3D domain_vpci_init(d)) !=3D 0 ) + goto fail; + return 0; =20 fail: diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d233d634c1..1731ae2028 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2773,6 +2773,9 @@ void __init create_dom0(void) if ( iommu_enabled ) dom0_cfg.flags |=3D XEN_DOMCTL_CDF_iommu; =20 + if ( is_pci_passthrough_enabled() ) + dom0_cfg.flags |=3D XEN_DOMCTL_CDF_vpci; + dom0 =3D domain_create(0, &dom0_cfg, true); if ( IS_ERR(dom0) || (alloc_dom0_vcpu0(dom0) =3D=3D NULL) ) panic("Error creating domain 0\n"); diff --git a/xen/arch/arm/vpci.c b/xen/arch/arm/vpci.c new file mode 100644 index 0000000000..76c12b9281 --- /dev/null +++ b/xen/arch/arm/vpci.c @@ -0,0 +1,102 @@ +/* + * xen/arch/arm/vpci.c + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ +#include + +#include + +#define REGISTER_OFFSET(addr) ( (addr) & 0x00000fff) + +/* Do some sanity checks. */ +static bool vpci_mmio_access_allowed(unsigned int reg, unsigned int len) +{ + /* Check access size. */ + if ( len > 8 ) + return false; + + /* Check that access is size aligned. */ + if ( (reg & (len - 1)) ) + return false; + + return true; +} + +static int vpci_mmio_read(struct vcpu *v, mmio_info_t *info, + register_t *r, void *p) +{ + unsigned int reg; + pci_sbdf_t sbdf; + unsigned long data =3D ~0UL; + unsigned int size =3D 1U << info->dabt.size; + + sbdf.sbdf =3D MMCFG_BDF(info->gpa); + reg =3D REGISTER_OFFSET(info->gpa); + + if ( !vpci_mmio_access_allowed(reg, size) ) + return 0; + + data =3D vpci_read(sbdf, reg, min(4u, size)); + if ( size =3D=3D 8 ) + data |=3D (uint64_t)vpci_read(sbdf, reg + 4, 4) << 32; + + *r =3D data; + + return 1; +} + +static int vpci_mmio_write(struct vcpu *v, mmio_info_t *info, + register_t r, void *p) +{ + unsigned int reg; + pci_sbdf_t sbdf; + unsigned long data =3D r; + unsigned int size =3D 1U << info->dabt.size; + + sbdf.sbdf =3D MMCFG_BDF(info->gpa); + reg =3D REGISTER_OFFSET(info->gpa); + + if ( !vpci_mmio_access_allowed(reg, size) ) + return 0; + + vpci_write(sbdf, reg, min(4u, size), data); + if ( size =3D=3D 8 ) + vpci_write(sbdf, reg + 4, 4, data >> 32); + + return 1; +} + +static const struct mmio_handler_ops vpci_mmio_handler =3D { + .read =3D vpci_mmio_read, + .write =3D vpci_mmio_write, +}; + +int domain_vpci_init(struct domain *d) +{ + if ( !has_vpci(d) ) + return 0; + + register_mmio_handler(d, &vpci_mmio_handler, + GUEST_VPCI_ECAM_BASE, GUEST_VPCI_ECAM_SIZE, NULL= ); + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ + diff --git a/xen/arch/arm/vpci.h b/xen/arch/arm/vpci.h new file mode 100644 index 0000000000..d8a7b0e3e8 --- /dev/null +++ b/xen/arch/arm/vpci.h @@ -0,0 +1,36 @@ +/* + * xen/arch/arm/vpci.h + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef __ARCH_ARM_VPCI_H__ +#define __ARCH_ARM_VPCI_H__ + +#ifdef CONFIG_HAS_VPCI +int domain_vpci_init(struct domain *d); +#else +static inline int domain_vpci_init(struct domain *d) +{ + return 0; +} +#endif + +#endif /* __ARCH_ARM_VPCI_H__ */ + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index ef1812dc14..d7a48781c5 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -662,6 +662,12 @@ int arch_sanitise_domain_config(struct xen_domctl_crea= tedomain *config) return -EINVAL; } =20 + if ( config->flags & XEN_DOMCTL_CDF_vpci ) + { + dprintk(XENLOG_INFO, "VPCI not supported\n"); + return -EINVAL; + } + if ( config->vmtrace_size ) { unsigned int size =3D config->vmtrace_size; diff --git a/xen/common/domain.c b/xen/common/domain.c index 6ee5d033b0..40d67ec342 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -483,7 +483,7 @@ static int sanitise_domain_config(struct xen_domctl_cre= atedomain *config) ~(XEN_DOMCTL_CDF_hvm | XEN_DOMCTL_CDF_hap | XEN_DOMCTL_CDF_s3_integrity | XEN_DOMCTL_CDF_oos_off | XEN_DOMCTL_CDF_xs_domain | XEN_DOMCTL_CDF_iommu | - XEN_DOMCTL_CDF_nested_virt) ) + XEN_DOMCTL_CDF_nested_virt | XEN_DOMCTL_CDF_vpci) ) { dprintk(XENLOG_INFO, "Unknown CDF flags %#x\n", config->flags); return -EINVAL; diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index d774a6154e..633e89ac13 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -767,6 +767,18 @@ int pci_add_device(u16 seg, u8 bus, u8 devfn, else iommu_enable_device(pdev); =20 +#ifdef CONFIG_ARM + /* + * On ARM PCI devices discovery will be done by Dom0. Add vpci handler= when + * Dom0 inform XEN to add the PCI devices in XEN. + */ + ret =3D vpci_add_handlers(pdev); + if ( ret ) { + printk(XENLOG_ERR "setup of vPCI for failed: %d\n",ret); + goto out; + } +#endif + pci_enable_acs(pdev); =20 out: diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index c9277b5c6d..5d9dd6b0d0 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -2,6 +2,7 @@ #define __ASM_DOMAIN_H__ =20 #include +#include #include #include #include @@ -262,7 +263,12 @@ static inline void arch_vcpu_block(struct vcpu *v) {} =20 #define arch_vm_assist_valid_mask(d) (1UL << VMASST_TYPE_runstate_update_f= lag) =20 -#define has_vpci(d) ({ (void)(d); false; }) +/* + * For X86 VPCI is enabled and tested for PVH DOM0 only but + * for ARM we enable support VPCI for guest domain also. + */ +#define has_vpci(d) ((void)(d), \ + evaluate_nospec(d->options & XEN_DOMCTL_CDF_vpci)) =20 #endif /* __ASM_DOMAIN_H__ */ =20 diff --git a/xen/include/asm-x86/pci.h b/xen/include/asm-x86/pci.h index 3f806ce7a8..61b940c91d 100644 --- a/xen/include/asm-x86/pci.h +++ b/xen/include/asm-x86/pci.h @@ -6,8 +6,6 @@ #define CF8_ADDR_HI(cf8) ( ((cf8) & 0x0f000000) >> 16) #define CF8_ENABLED(cf8) (!!((cf8) & 0x80000000)) =20 -#define MMCFG_BDF(addr) ( ((addr) & 0x0ffff000) >> 12) - #define IS_SNB_GFX(id) (id =3D=3D 0x01068086 || id =3D=3D 0x01168086 \ || id =3D=3D 0x01268086 || id =3D=3D 0x01028086 \ || id =3D=3D 0x01128086 || id =3D=3D 0x01228086 \ diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 6b5a5f818a..727541a321 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -416,6 +416,13 @@ typedef uint64_t xen_callback_t; #define GUEST_GICV3_GICR0_BASE xen_mk_ullong(0x03020000) /* vCPU0..127= */ #define GUEST_GICV3_GICR0_SIZE xen_mk_ullong(0x01000000) =20 +/* + * 256 MB is reserved for VPCI configuration space based on calculation + * 256 buses =C3=97 32 devices =C3=97 8 functions =C3=97 4 KB =3D 256 MB + */ +#define GUEST_VPCI_ECAM_BASE xen_mk_ullong(0x10000000) +#define GUEST_VPCI_ECAM_SIZE xen_mk_ullong(0x10000000) + /* ACPI tables physical address */ #define GUEST_ACPI_BASE xen_mk_ullong(0x20000000) #define GUEST_ACPI_SIZE xen_mk_ullong(0x02000000) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 96696e3842..4245da3f45 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -70,9 +70,11 @@ struct xen_domctl_createdomain { #define XEN_DOMCTL_CDF_iommu (1U<<_XEN_DOMCTL_CDF_iommu) #define _XEN_DOMCTL_CDF_nested_virt 6 #define XEN_DOMCTL_CDF_nested_virt (1U << _XEN_DOMCTL_CDF_nested_virt) +#define _XEN_DOMCTL_CDF_vpci 7 +#define XEN_DOMCTL_CDF_vpci (1U << _XEN_DOMCTL_CDF_vpci) =20 /* Max XEN_DOMCTL_CDF_* constant. Used for ABI checking. */ -#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_nested_virt +#define XEN_DOMCTL_CDF_MAX XEN_DOMCTL_CDF_vpci =20 uint32_t flags; =20 diff --git a/xen/include/xen/pci.h b/xen/include/xen/pci.h index 70ac25345c..43b8a08170 100644 --- a/xen/include/xen/pci.h +++ b/xen/include/xen/pci.h @@ -40,6 +40,8 @@ #define PCI_SBDF3(s,b,df) \ ((pci_sbdf_t){ .sbdf =3D (((s) & 0xffff) << 16) | PCI_BDF2(b, df) }) =20 +#define MMCFG_BDF(addr) (((addr) & 0x0ffff000) >> 12) + typedef union { uint32_t sbdf; struct { --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853454672857.2434516042765; Tue, 28 Sep 2021 11:24:14 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198312.351762 (Exim 4.92) (envelope-from ) id 1mVHlp-0008Nu-Uy; Tue, 28 Sep 2021 18:24:01 +0000 Received: by outflank-mailman (output) from mailman id 198312.351762; Tue, 28 Sep 2021 18:24:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHlp-0008Nm-Qo; Tue, 28 Sep 2021 18:24:01 +0000 Received: by outflank-mailman (input) for mailman id 198312; Tue, 28 Sep 2021 18:24:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHlo-0007ni-KZ for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:24:00 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-rack-iad1.inumbo.com (Halon) with ESMTP id 60b7dc57-d8fb-42d8-aaa2-b15f0d1259c7; Tue, 28 Sep 2021 18:23:56 +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 725F86D; Tue, 28 Sep 2021 11:23:56 -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 57A203F793; Tue, 28 Sep 2021 11:23:55 -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: 60b7dc57-d8fb-42d8-aaa2-b15f0d1259c7 From: Rahul Singh To: xen-devel@lists.xenproject.org Cc: bertrand.marquis@arm.com, rahul.singh@arm.com, Andre.Przywara@arm.com, =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH v3 15/17] xen/arm: Transitional change to build HAS_VPCI on ARM. Date: Tue, 28 Sep 2021 19:18:24 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853456082100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch will be reverted once we add support for VPCI MSI/MSIX support on ARM. Signed-off-by: Rahul Singh Acked-by: Stefano Stabellini Reviewed-by: Bertrand Marquis --- Change in v3: none Change in v2: Patch introduced in v2 --- xen/drivers/vpci/Makefile | 3 ++- xen/drivers/vpci/header.c | 2 ++ xen/include/asm-arm/pci.h | 8 ++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/xen/drivers/vpci/Makefile b/xen/drivers/vpci/Makefile index 55d1bdfda0..1a1413b93e 100644 --- a/xen/drivers/vpci/Makefile +++ b/xen/drivers/vpci/Makefile @@ -1 +1,2 @@ -obj-y +=3D vpci.o header.o msi.o msix.o +obj-y +=3D vpci.o header.o +obj-$(CONFIG_HAS_PCI_MSI) +=3D msi.o msix.o diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c index ba9a036202..f8cd55e7c0 100644 --- a/xen/drivers/vpci/header.c +++ b/xen/drivers/vpci/header.c @@ -96,8 +96,10 @@ static void modify_decoding(const struct pci_dev *pdev, = uint16_t cmd, * FIXME: punching holes after the p2m has been set up might be racy f= or * DomU usage, needs to be revisited. */ +#ifdef CONFIG_HAS_PCI_MSI if ( map && !rom_only && vpci_make_msix_hole(pdev) ) return; +#endif =20 for ( i =3D 0; i < ARRAY_SIZE(header->bars); i++ ) { diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index 49c9622902..5532ce3977 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -26,6 +26,14 @@ struct arch_pci_dev { struct device dev; }; =20 +/* Arch-specific MSI data for vPCI. */ +struct vpci_arch_msi { +}; + +/* Arch-specific MSI-X entry data for vPCI. */ +struct vpci_arch_msix_entry { +}; + /* * struct to hold the mappings of a config space window. This * is expected to be used as sysdata for PCI controllers that --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853476624522.205191752024; Tue, 28 Sep 2021 11:24:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198325.351773 (Exim 4.92) (envelope-from ) id 1mVHm8-00012y-Ae; Tue, 28 Sep 2021 18:24:20 +0000 Received: by outflank-mailman (output) from mailman id 198325.351773; Tue, 28 Sep 2021 18:24:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHm8-00012r-6l; Tue, 28 Sep 2021 18:24:20 +0000 Received: by outflank-mailman (input) for mailman id 198325; Tue, 28 Sep 2021 18:24:19 +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 1mVHm6-0000b7-Vy for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:24:19 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 497e2fd0-2089-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:24:15 +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 89F666D; Tue, 28 Sep 2021 11:24:15 -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 1F8893F793; Tue, 28 Sep 2021 11:24:14 -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: 497e2fd0-2089-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, Ian Jackson , Wei Liu , Anthony PERARD , Juergen Gross , Stefano Stabellini , Julien Grall , Volodymyr Babchuk Subject: [PATCH v3 16/17] arm/libxl: Emulated PCI device tree node in libxl Date: Tue, 28 Sep 2021 19:18:25 +0100 Message-Id: <7f19d0802a9ac7544ddefe96f282ba7f97caefe9.1632847120.git.rahul.singh@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853478028100003 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" libxl will create an emulated PCI device tree node in the device tree to enable the guest OS to discover the virtual PCI during guest boot. Emulated PCI device tree node will only be created when there is any device assigned to guest. A new area has been reserved in the arm guest physical map at which the VPCI bus is declared in the device tree (reg and ranges parameters of the node). Signed-off-by: Rahul Singh Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Change in v3: - Make GUEST_VPCI_MEM_ADDR address 2MB aligned Change in v2: - enable doamin_vpci_init() when XEN_DOMCTL_CDF_vpci is set for domain. --- tools/include/libxl.h | 6 ++ tools/libs/light/libxl_arm.c | 105 +++++++++++++++++++++++++++++++ tools/libs/light/libxl_create.c | 3 + tools/libs/light/libxl_types.idl | 1 + tools/xl/xl_parse.c | 2 + xen/include/public/arch-arm.h | 10 +++ 6 files changed, 127 insertions(+) diff --git a/tools/include/libxl.h b/tools/include/libxl.h index b9ba16d698..3362073b21 100644 --- a/tools/include/libxl.h +++ b/tools/include/libxl.h @@ -358,6 +358,12 @@ */ #define LIBXL_HAVE_BUILDINFO_ARM_VUART 1 =20 +/* + * LIBXL_HAVE_BUILDINFO_ARM_VPCI indicates that the toolstack supports vir= tual + * PCI for ARM. + */ +#define LIBXL_HAVE_BUILDINFO_ARM_VPCI 1 + /* * LIBXL_HAVE_BUILDINFO_GRANT_LIMITS indicates that libxl_domain_build_info * has the max_grant_frames and max_maptrack_frames fields. diff --git a/tools/libs/light/libxl_arm.c b/tools/libs/light/libxl_arm.c index e3140a6e00..52f1ddce48 100644 --- a/tools/libs/light/libxl_arm.c +++ b/tools/libs/light/libxl_arm.c @@ -269,6 +269,58 @@ static int fdt_property_regs(libxl__gc *gc, void *fdt, return fdt_property(fdt, "reg", regs, sizeof(regs)); } =20 +static int fdt_property_values(libxl__gc *gc, void *fdt, + const char *name, unsigned num_cells, ...) +{ + uint32_t prop[num_cells]; + be32 *cells =3D &prop[0]; + int i; + va_list ap; + uint32_t arg; + + va_start(ap, num_cells); + for (i =3D 0 ; i < num_cells; i++) { + arg =3D va_arg(ap, uint32_t); + set_cell(&cells, 1, arg); + } + va_end(ap); + + return fdt_property(fdt, name, prop, sizeof(prop)); +} + +static int fdt_property_vpci_ranges(libxl__gc *gc, void *fdt, + unsigned addr_cells, + unsigned size_cells, + unsigned num_regs, ...) +{ + uint32_t regs[num_regs*((addr_cells*2)+size_cells+1)]; + be32 *cells =3D ®s[0]; + int i; + va_list ap; + uint64_t arg; + + va_start(ap, num_regs); + for (i =3D 0 ; i < num_regs; i++) { + /* Set the memory bit field */ + arg =3D va_arg(ap, uint32_t); + set_cell(&cells, 1, arg); + + /* Set the vpci bus address */ + arg =3D addr_cells ? va_arg(ap, uint64_t) : 0; + set_cell(&cells, addr_cells , arg); + + /* Set the cpu bus address where vpci address is mapped */ + set_cell(&cells, addr_cells, arg); + + /* Set the vpci size requested */ + arg =3D size_cells ? va_arg(ap, uint64_t) : 0; + set_cell(&cells, size_cells, arg); + } + va_end(ap); + + return fdt_property(fdt, "ranges", regs, sizeof(regs)); +} + static int make_root_properties(libxl__gc *gc, const libxl_version_info *vers, void *fdt) @@ -668,6 +720,53 @@ static int make_vpl011_uart_node(libxl__gc *gc, void *= fdt, return 0; } =20 +static int make_vpci_node(libxl__gc *gc, void *fdt, + const struct arch_info *ainfo, + struct xc_dom_image *dom) +{ + int res; + const uint64_t vpci_ecam_base =3D GUEST_VPCI_ECAM_BASE; + const uint64_t vpci_ecam_size =3D GUEST_VPCI_ECAM_SIZE; + const char *name =3D GCSPRINTF("pcie@%"PRIx64, vpci_ecam_base); + + res =3D fdt_begin_node(fdt, name); + if (res) return res; + + res =3D fdt_property_compat(gc, fdt, 1, "pci-host-ecam-generic"); + if (res) return res; + + res =3D fdt_property_string(fdt, "device_type", "pci"); + if (res) return res; + + res =3D fdt_property_regs(gc, fdt, GUEST_ROOT_ADDRESS_CELLS, + GUEST_ROOT_SIZE_CELLS, 1, vpci_ecam_base, vpci_ecam_size); + if (res) return res; + + res =3D fdt_property_values(gc, fdt, "bus-range", 2, 0, 255); + if (res) return res; + + res =3D fdt_property_cell(fdt, "#address-cells", 3); + if (res) return res; + + res =3D fdt_property_cell(fdt, "#size-cells", 2); + if (res) return res; + + res =3D fdt_property_string(fdt, "status", "okay"); + if (res) return res; + + res =3D fdt_property_vpci_ranges(gc, fdt, GUEST_ROOT_ADDRESS_CELLS, + GUEST_ROOT_SIZE_CELLS, 2, + GUEST_VPCI_ADDR_TYPE_MEM, GUEST_VPCI_MEM_ADDR, GUEST_VPCI_MEM_SIZE, + GUEST_VPCI_ADDR_TYPE_PREFETCH_MEM, GUEST_VPCI_PREFETCH_MEM_ADDR, + GUEST_VPCI_PREFETCH_MEM_SIZE); + if (res) return res; + + res =3D fdt_end_node(fdt); + if (res) return res; + + return 0; +} + static const struct arch_info *get_arch_info(libxl__gc *gc, const struct xc_dom_image *do= m) { @@ -971,6 +1070,9 @@ next_resize: if (info->tee =3D=3D LIBXL_TEE_TYPE_OPTEE) FDT( make_optee_node(gc, fdt) ); =20 + if (libxl_defbool_val(info->arch_arm.vpci)) + FDT( make_vpci_node(gc, fdt, ainfo, dom) ); + if (pfdt) FDT( copy_partial_fdt(gc, fdt, pfdt) ); =20 @@ -1189,6 +1291,9 @@ void libxl__arch_domain_build_info_setdefault(libxl__= gc *gc, /* ACPI is disabled by default */ libxl_defbool_setdefault(&b_info->acpi, false); =20 + /* VPCI is disabled by default */ + libxl_defbool_setdefault(&b_info->arch_arm.vpci, false); + if (b_info->type !=3D LIBXL_DOMAIN_TYPE_PV) return; =20 diff --git a/tools/libs/light/libxl_create.c b/tools/libs/light/libxl_creat= e.c index e356b2106d..529e475489 100644 --- a/tools/libs/light/libxl_create.c +++ b/tools/libs/light/libxl_create.c @@ -632,6 +632,9 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_conf= ig *d_config, if (info->passthrough =3D=3D LIBXL_PASSTHROUGH_SYNC_PT) create.iommu_opts |=3D XEN_DOMCTL_IOMMU_no_sharept; =20 + if ( libxl_defbool_val(b_info->arch_arm.vpci) ) + create.flags |=3D XEN_DOMCTL_CDF_vpci; + /* Ultimately, handle is an array of 16 uint8_t, same as uuid */ libxl_uuid_copy(ctx, (libxl_uuid *)&create.handle, &info->uuid); =20 diff --git a/tools/libs/light/libxl_types.idl b/tools/libs/light/libxl_type= s.idl index 3f9fff653a..78b1ddf0b8 100644 --- a/tools/libs/light/libxl_types.idl +++ b/tools/libs/light/libxl_types.idl @@ -644,6 +644,7 @@ libxl_domain_build_info =3D Struct("domain_build_info",[ =20 ("arch_arm", Struct(None, [("gic_version", libxl_gic_version), ("vuart", libxl_vuart_type), + ("vpci", libxl_defbool), ])), ("arch_x86", Struct(None, [("msr_relaxed", libxl_defbool), ])), diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 17dddb4cd5..ffafbeffb4 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1497,6 +1497,8 @@ void parse_config_data(const char *config_source, } if (d_config->num_pcidevs && c_info->type =3D=3D LIBXL_DOMAIN_TYPE= _PV) libxl_defbool_set(&b_info->u.pv.e820_host, true); + if (d_config->num_pcidevs) + libxl_defbool_set(&b_info->arch_arm.vpci, true); } =20 if (!xlu_cfg_get_list (config, "dtdev", &dtdevs, 0, 0)) { diff --git a/xen/include/public/arch-arm.h b/xen/include/public/arch-arm.h index 727541a321..acd97eb327 100644 --- a/xen/include/public/arch-arm.h +++ b/xen/include/public/arch-arm.h @@ -431,6 +431,11 @@ typedef uint64_t xen_callback_t; #define GUEST_PL011_BASE xen_mk_ullong(0x22000000) #define GUEST_PL011_SIZE xen_mk_ullong(0x00001000) =20 +/* Guest PCI-PCIe memory space where config space and BAR will be availabl= e.*/ +#define GUEST_VPCI_ADDR_TYPE_MEM xen_mk_ullong(0x02000000) +#define GUEST_VPCI_MEM_ADDR xen_mk_ullong(0x23000000) +#define GUEST_VPCI_MEM_SIZE xen_mk_ullong(0x10000000) + /* * 16MB =3D=3D 4096 pages reserved for guest to use as a region to map its * grant table in. @@ -446,6 +451,11 @@ typedef uint64_t xen_callback_t; #define GUEST_RAM0_BASE xen_mk_ullong(0x40000000) /* 3GB of low RAM @ 1G= B */ #define GUEST_RAM0_SIZE xen_mk_ullong(0xc0000000) =20 +/* 4GB @ 4GB Prefetch Memory for VPCI */ +#define GUEST_VPCI_ADDR_TYPE_PREFETCH_MEM xen_mk_ullong(0x42000000) +#define GUEST_VPCI_PREFETCH_MEM_ADDR xen_mk_ullong(0x100000000) +#define GUEST_VPCI_PREFETCH_MEM_SIZE xen_mk_ullong(0x100000000) + #define GUEST_RAM1_BASE xen_mk_ullong(0x0200000000) /* 1016GB of RAM @ 8= GB */ #define GUEST_RAM1_SIZE xen_mk_ullong(0xfe00000000) =20 --=20 2.17.1 From nobody Fri Nov 29 16:38:33 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 1632853502254679.8022605918901; Tue, 28 Sep 2021 11:25:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.198336.351784 (Exim 4.92) (envelope-from ) id 1mVHma-0001qS-KO; Tue, 28 Sep 2021 18:24:48 +0000 Received: by outflank-mailman (output) from mailman id 198336.351784; Tue, 28 Sep 2021 18:24:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVHma-0001qL-Gf; Tue, 28 Sep 2021 18:24:48 +0000 Received: by outflank-mailman (input) for mailman id 198336; Tue, 28 Sep 2021 18:24:47 +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 1mVHmZ-0001pr-Fg for xen-devel@lists.xenproject.org; Tue, 28 Sep 2021 18:24:47 +0000 Received: from foss.arm.com (unknown [217.140.110.172]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 5bd91d34-2089-11ec-bcc4-12813bfff9fa; Tue, 28 Sep 2021 18:24:46 +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 5DC786D; Tue, 28 Sep 2021 11:24:46 -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 5DFCC3F793; Tue, 28 Sep 2021 11:24:45 -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: 5bd91d34-2089-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 Subject: [PATCH v3 17/17] xen/arm: Add linux,pci-domain property for hwdom if not available. Date: Tue, 28 Sep 2021 19:18:26 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-ZM-MESSAGEID: 1632853503984100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" If the property is not present in the device tree node for host bridge, XEN while creating the dtb for hwdom will create this property and assigns the already allocated segment to the host bridge so that XEN and linux will have the same segment for the host bridges. Signed-off-by: Rahul Singh Reviewed-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- Change in v3: - Use is_pci_passthrough_enabled() Change in v2: - Add linux,pci-domain only when pci-passthrough command line option is ena= beld --- xen/arch/arm/domain_build.c | 16 ++++++++++++++++ xen/arch/arm/pci/pci-host-common.c | 21 +++++++++++++++++++++ xen/include/asm-arm/pci.h | 9 +++++++++ 3 files changed, 46 insertions(+) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 1731ae2028..026c9e5c6c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -743,6 +743,22 @@ static int __init write_properties(struct domain *d, s= truct kernel_info *kinfo, return res; } =20 + if ( is_pci_passthrough_enabled() && dt_device_type_is_equal(node, "pc= i") ) + { + if ( !dt_find_property(node, "linux,pci-domain", NULL) ) + { + uint16_t segment; + + res =3D pci_get_host_bridge_segment(node, &segment); + if ( res < 0 ) + return res; + + res =3D fdt_property_cell(kinfo->fdt, "linux,pci-domain", segm= ent); + if ( res ) + return res; + } + } + /* * Override the property "status" to disable the device when it's * marked for passthrough. diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host= -common.c index c5941b10e9..593beeb48c 100644 --- a/xen/arch/arm/pci/pci-host-common.c +++ b/xen/arch/arm/pci/pci-host-common.c @@ -255,6 +255,27 @@ struct pci_host_bridge *pci_find_host_bridge(uint16_t = segment, uint8_t bus) =20 return NULL; } + +/* + * This function will lookup an hostbridge based on config space address. + */ +int pci_get_host_bridge_segment(const struct dt_device_node *node, + uint16_t *segment) +{ + struct pci_host_bridge *bridge; + + list_for_each_entry( bridge, &pci_host_bridges, node ) + { + if ( bridge->dt_node !=3D node ) + continue; + + *segment =3D bridge->segment; + return 0; + } + + return -EINVAL; +} + /* * Local variables: * mode: C diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h index 5532ce3977..7cb2e2f1ed 100644 --- a/xen/include/asm-arm/pci.h +++ b/xen/include/asm-arm/pci.h @@ -90,6 +90,8 @@ int pci_generic_config_write(struct pci_host_bridge *brid= ge, pci_sbdf_t sbdf, void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge, pci_sbdf_t sbdf, uint32_t where); struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus= ); +int pci_get_host_bridge_segment(const struct dt_device_node *node, + uint16_t *segment); =20 static always_inline bool is_pci_passthrough_enabled(void) { @@ -104,5 +106,12 @@ static always_inline bool is_pci_passthrough_enabled(v= oid) return false; } =20 +static inline int pci_get_host_bridge_segment(const struct dt_device_node = *node, + uint16_t *segment) +{ + ASSERT_UNREACHABLE(); + return -EINVAL; +} + #endif /*!CONFIG_HAS_PCI*/ #endif /* __ARM_PCI_H__ */ --=20 2.17.1