From patchwork Thu Mar 28 14:51:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10875079 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A27D914DE for ; Thu, 28 Mar 2019 14:53:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D2C628B8E for ; Thu, 28 Mar 2019 14:53:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8179128D0C; Thu, 28 Mar 2019 14:53:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5399528BA7 for ; Thu, 28 Mar 2019 14:53:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h9WNX-00009t-DO; Thu, 28 Mar 2019 14:51:39 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h9WNW-00009i-I6 for xen-devel@lists.xenproject.org; Thu, 28 Mar 2019 14:51:38 +0000 X-Inumbo-ID: fc625f23-5168-11e9-bc90-bc764e045a96 Received: from prv1-mh.provo.novell.com (unknown [137.65.248.33]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id fc625f23-5168-11e9-bc90-bc764e045a96; Thu, 28 Mar 2019 14:51:36 +0000 (UTC) Received: from INET-PRV1-MTA by prv1-mh.provo.novell.com with Novell_GroupWise; Thu, 28 Mar 2019 08:51:36 -0600 Message-Id: <5C9CDF770200007800222847@prv1-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 18.1.0 Date: Thu, 28 Mar 2019 08:51:35 -0600 From: "Jan Beulich" To: "xen-devel" References: <5C9CDDAF020000780022282A@prv1-mh.provo.novell.com> In-Reply-To: <5C9CDDAF020000780022282A@prv1-mh.provo.novell.com> Mime-Version: 1.0 Content-Disposition: inline Subject: [Xen-devel] [PATCH 4/7] x86/IOMMU: introduce init-ops structure X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian , Wei Liu , Andrew Cooper , Suravee Suthikulpanit , Brian Woods , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Do away with the CPU vendor dependency, and set the init ops pointer based on what ACPI tables have been found. Also take the opportunity and add __read_mostly to iommu_ops. Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper Reviewed-by: Kevin Tian Acked-by: Brian Woods --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -30,6 +30,7 @@ static bool_t __read_mostly init_done; +static const struct iommu_init_ops _iommu_init_ops; static const struct iommu_ops amd_iommu_ops; struct amd_iommu *find_iommu_for_device(int seg, int bdf) @@ -185,10 +186,12 @@ int __init acpi_ivrs_init(void) return -ENODEV; } + iommu_init_ops = &_iommu_init_ops; + return 0; } -int __init amd_iov_detect(void) +static int __init iov_detect(void) { if ( !iommu_enable && !iommu_intremap ) return 0; @@ -604,3 +607,7 @@ static const struct iommu_ops __initcons .crash_shutdown = amd_iommu_crash_shutdown, .dump_p2m_table = amd_dump_p2m_table, }; + +static const struct iommu_init_ops __initconstrel _iommu_init_ops = { + .setup = iov_detect, +}; --- a/xen/drivers/passthrough/vtd/dmar.c +++ b/xen/drivers/passthrough/vtd/dmar.c @@ -993,7 +993,11 @@ int __init acpi_dmar_init(void) ret = parse_dmar_table(acpi_parse_dmar); if ( !ret ) + { + iommu_init_ops = &intel_iommu_init_ops; + return add_user_rmrr(); + } return ret; } --- a/xen/drivers/passthrough/vtd/extern.h +++ b/xen/drivers/passthrough/vtd/extern.h @@ -27,6 +27,7 @@ struct pci_ats_dev; extern bool_t rwbf_quirk; +extern const struct iommu_init_ops intel_iommu_init_ops; extern const struct iommu_ops intel_iommu_ops; void print_iommu_regs(struct acpi_drhd_unit *drhd); --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2280,7 +2280,7 @@ static void __hwdom_init setup_hwdom_rmr pcidevs_unlock(); } -int __init intel_vtd_setup(void) +static int __init vtd_setup(void) { struct acpi_drhd_unit *drhd; struct iommu *iommu; @@ -2735,6 +2735,10 @@ const struct iommu_ops __initconstrel in .dump_p2m_table = vtd_dump_p2m_table, }; +const struct iommu_init_ops __initconstrel intel_iommu_init_ops = { + .setup = vtd_setup, +}; + /* * Local variables: * mode: C --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -23,7 +23,8 @@ #include #include -struct iommu_ops iommu_ops; +const struct iommu_init_ops *__initdata iommu_init_ops; +struct iommu_ops __read_mostly iommu_ops; void iommu_update_ire_from_apic( unsigned int apic, unsigned int reg, unsigned int value) --- a/xen/include/asm-x86/iommu.h +++ b/xen/include/asm-x86/iommu.h @@ -56,9 +56,6 @@ struct arch_iommu struct guest_iommu *g_iommu; }; -int intel_vtd_setup(void); -int amd_iov_detect(void); - extern struct iommu_ops iommu_ops; static inline const struct iommu_ops *iommu_get_ops(void) @@ -67,17 +64,15 @@ static inline const struct iommu_ops *io return &iommu_ops; } +struct iommu_init_ops { + int (*setup)(void); +}; + +extern const struct iommu_init_ops *iommu_init_ops; + static inline int iommu_hardware_setup(void) { - switch ( boot_cpu_data.x86_vendor ) - { - case X86_VENDOR_INTEL: - return intel_vtd_setup(); - case X86_VENDOR_AMD: - return amd_iov_detect(); - } - - return -ENODEV; + return iommu_init_ops ? iommu_init_ops->setup() : -ENODEV; } /* Are we using the domain P2M table as its IOMMU pagetable? */