All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: xen-devel <xen-devel@lists.xenproject.org>
Cc: Kevin Tian <kevin.tian@intel.com>, Wei Liu <wei.liu2@citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
	Brian Woods <brian.woods@amd.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH 4/7] x86/IOMMU: introduce init-ops structure
Date: Thu, 28 Mar 2019 08:51:35 -0600	[thread overview]
Message-ID: <5C9CDF770200007800222847@prv1-mh.provo.novell.com> (raw)
In-Reply-To: <5C9CDDAF020000780022282A@prv1-mh.provo.novell.com>

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 <jbeulich@suse.com>

--- 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 <asm/hvm/io.h>
 #include <asm/setup.h>
 
-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? */





_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-03-28 14:51 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-28 14:43 [PATCH 0/7] x86: eliminate Intel-isms from x2APIC setup Jan Beulich
2019-03-28 14:48 ` [PATCH 1/7] x86/entry: drop unused header inclusions Jan Beulich
2019-03-28 16:11   ` Andrew Cooper
2019-04-02  2:57   ` Tian, Kevin
2019-04-05 14:24   ` Boris Ostrovsky
2019-04-05 14:24     ` [Xen-devel] " Boris Ostrovsky
2019-03-28 14:49 ` [PATCH 2/7] x86/APIC: suppress redundant "Switched to ..." messages Jan Beulich
2019-03-28 16:33   ` Andrew Cooper
2019-03-28 14:49 ` [PATCH 3/7] x86/ACPI: also parse AMD IOMMU tables early Jan Beulich
2019-03-28 16:43   ` Andrew Cooper
2019-03-29  9:00     ` Jan Beulich
2019-04-05 14:28   ` Woods, Brian
2019-04-05 14:28     ` [Xen-devel] " Woods, Brian
2019-03-28 14:51 ` Jan Beulich [this message]
2019-03-28 17:01   ` [PATCH 4/7] x86/IOMMU: introduce init-ops structure Andrew Cooper
2019-04-02  3:00   ` Tian, Kevin
2019-04-05 14:29   ` Woods, Brian
2019-04-05 14:29     ` [Xen-devel] " Woods, Brian
2019-03-28 14:52 ` [PATCH 5/7] x86/IOMMU: abstract Intel-specific iommu_supports_eim() Jan Beulich
2019-03-28 17:03   ` Andrew Cooper
2019-04-02  3:02   ` Tian, Kevin
2019-03-28 14:53 ` [PATCH 6/7] x86/IOMMU: abstract Intel-specific iommu_{en, dis}able_x2apic_IR() Jan Beulich
2019-03-28 17:37   ` Andrew Cooper
2019-03-29  9:13     ` Jan Beulich
2019-04-02  3:24       ` Tian, Kevin
2019-04-02 10:18         ` Andrew Cooper
2019-04-02 13:17         ` Jan Beulich
2019-04-03  0:58           ` Tian, Kevin
2019-03-28 14:54 ` [PATCH 7/7] x86/IOMMU: initialize iommu_ops in vendor-independent code Jan Beulich
2019-03-28 17:50   ` Andrew Cooper
2019-03-29  9:15     ` Jan Beulich
2019-04-02 10:16       ` Andrew Cooper
2019-04-02  3:26   ` Tian, Kevin
2019-04-05 14:30   ` Woods, Brian
2019-04-05 14:30     ` [Xen-devel] " Woods, Brian
2019-04-05  8:05 ` Ping: [PATCH 0/7] x86: eliminate Intel-isms from x2APIC setup Jan Beulich
2019-04-05  8:05   ` [Xen-devel] " Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5C9CDF770200007800222847@prv1-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=brian.woods@amd.com \
    --cc=kevin.tian@intel.com \
    --cc=roger.pau@citrix.com \
    --cc=suravee.suthikulpanit@amd.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.