]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/iommu/arm-smmu.c
Merge branches 'iommu/fixes', 'arm/exynos', 'arm/renesas', 'arm/smmu', 'arm/mediatek...
[mirror_ubuntu-bionic-kernel.git] / drivers / iommu / arm-smmu.c
index c841eb7a1a7417af301e6c51a9ba464d05b1472a..abf6496843a617070289377ffad3fd1e119b0aa6 100644 (file)
  *     - v7/v8 long-descriptor format
  *     - Non-secure access to the SMMU
  *     - Context fault reporting
+ *     - Extended Stream ID (16 bit)
  */
 
 #define pr_fmt(fmt) "arm-smmu: " fmt
 
+#include <linux/acpi.h>
+#include <linux/acpi_iort.h>
 #include <linux/atomic.h>
 #include <linux/delay.h>
 #include <linux/dma-iommu.h>
@@ -85,6 +88,7 @@
 #define sCR0_CLIENTPD                  (1 << 0)
 #define sCR0_GFRE                      (1 << 1)
 #define sCR0_GFIE                      (1 << 2)
+#define sCR0_EXIDENABLE                        (1 << 3)
 #define sCR0_GCFGFRE                   (1 << 4)
 #define sCR0_GCFGFIE                   (1 << 5)
 #define sCR0_USFCFG                    (1 << 10)
 #define ID0_NUMIRPT_MASK               0xff
 #define ID0_NUMSIDB_SHIFT              9
 #define ID0_NUMSIDB_MASK               0xf
+#define ID0_EXIDS                      (1 << 8)
 #define ID0_NUMSMRG_SHIFT              0
 #define ID0_NUMSMRG_MASK               0xff
 
 #define ARM_SMMU_GR0_S2CR(n)           (0xc00 + ((n) << 2))
 #define S2CR_CBNDX_SHIFT               0
 #define S2CR_CBNDX_MASK                        0xff
+#define S2CR_EXIDVALID                 (1 << 10)
 #define S2CR_TYPE_SHIFT                        16
 #define S2CR_TYPE_MASK                 0x3
 enum arm_smmu_s2cr_type {
@@ -247,6 +253,7 @@ enum arm_smmu_s2cr_privcfg {
 #define ARM_MMU500_ACTLR_CPRE          (1 << 1)
 
 #define ARM_MMU500_ACR_CACHE_LOCK      (1 << 26)
+#define ARM_MMU500_ACR_SMTNMB_TLBEN    (1 << 8)
 
 #define CB_PAR_F                       (1 << 0)
 
@@ -257,6 +264,7 @@ enum arm_smmu_s2cr_privcfg {
 
 #define TTBCR2_SEP_SHIFT               15
 #define TTBCR2_SEP_UPSTREAM            (0x7 << TTBCR2_SEP_SHIFT)
+#define TTBCR2_AS                      (1 << 4)
 
 #define TTBRn_ASID_SHIFT               48
 
@@ -278,6 +286,9 @@ enum arm_smmu_s2cr_privcfg {
 
 #define FSYNR0_WNR                     (1 << 4)
 
+#define MSI_IOVA_BASE                  0x8000000
+#define MSI_IOVA_LENGTH                        0x100000
+
 static int force_stage;
 module_param(force_stage, int, S_IRUGO);
 MODULE_PARM_DESC(force_stage,
@@ -324,8 +335,10 @@ struct arm_smmu_master_cfg {
 #define INVALID_SMENDX                 -1
 #define __fwspec_cfg(fw) ((struct arm_smmu_master_cfg *)fw->iommu_priv)
 #define fwspec_smmu(fw)  (__fwspec_cfg(fw)->smmu)
+#define fwspec_smendx(fw, i) \
+       (i >= fw->num_ids ? INVALID_SMENDX : __fwspec_cfg(fw)->smendx[i])
 #define for_each_cfg_sme(fw, i, idx) \
-       for (i = 0; idx = __fwspec_cfg(fw)->smendx[i], i < fw->num_ids; ++i)
+       for (i = 0; idx = fwspec_smendx(fw, i), i < fw->num_ids; ++i)
 
 struct arm_smmu_device {
        struct device                   *dev;
@@ -346,6 +359,7 @@ struct arm_smmu_device {
 #define ARM_SMMU_FEAT_FMT_AARCH64_64K  (1 << 9)
 #define ARM_SMMU_FEAT_FMT_AARCH32_L    (1 << 10)
 #define ARM_SMMU_FEAT_FMT_AARCH32_S    (1 << 11)
+#define ARM_SMMU_FEAT_EXIDS            (1 << 12)
        u32                             features;
 
 #define ARM_SMMU_OPT_SECURE_CFG_ACCESS (1 << 0)
@@ -375,6 +389,9 @@ struct arm_smmu_device {
        unsigned int                    *irqs;
 
        u32                             cavium_id_base; /* Specific to Cavium */
+
+       /* IOMMU core code handle */
+       struct iommu_device             iommu;
 };
 
 enum arm_smmu_context_fmt {
@@ -640,7 +657,7 @@ static void arm_smmu_tlb_inv_range_nosync(unsigned long iova, size_t size,
        }
 }
 
-static struct iommu_gather_ops arm_smmu_gather_ops = {
+static const struct iommu_gather_ops arm_smmu_gather_ops = {
        .tlb_flush_all  = arm_smmu_tlb_inv_context,
        .tlb_add_flush  = arm_smmu_tlb_inv_range_nosync,
        .tlb_sync       = arm_smmu_tlb_sync,
@@ -773,6 +790,8 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain,
                        reg = pgtbl_cfg->arm_lpae_s1_cfg.tcr;
                        reg2 = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32;
                        reg2 |= TTBCR2_SEP_UPSTREAM;
+                       if (cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64)
+                               reg2 |= TTBCR2_AS;
                }
                if (smmu->version > ARM_SMMU_V1)
                        writel_relaxed(reg2, cb_base + ARM_SMMU_CB_TTBCR2);
@@ -1043,7 +1062,7 @@ static void arm_smmu_write_smr(struct arm_smmu_device *smmu, int idx)
        struct arm_smmu_smr *smr = smmu->smrs + idx;
        u32 reg = smr->id << SMR_ID_SHIFT | smr->mask << SMR_MASK_SHIFT;
 
-       if (smr->valid)
+       if (!(smmu->features & ARM_SMMU_FEAT_EXIDS) && smr->valid)
                reg |= SMR_VALID;
        writel_relaxed(reg, ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_SMR(idx));
 }
@@ -1055,6 +1074,9 @@ static void arm_smmu_write_s2cr(struct arm_smmu_device *smmu, int idx)
                  (s2cr->cbndx & S2CR_CBNDX_MASK) << S2CR_CBNDX_SHIFT |
                  (s2cr->privcfg & S2CR_PRIVCFG_MASK) << S2CR_PRIVCFG_SHIFT;
 
+       if (smmu->features & ARM_SMMU_FEAT_EXIDS && smmu->smrs &&
+           smmu->smrs[idx].valid)
+               reg |= S2CR_EXIDVALID;
        writel_relaxed(reg, ARM_SMMU_GR0(smmu) + ARM_SMMU_GR0_S2CR(idx));
 }
 
@@ -1065,6 +1087,34 @@ static void arm_smmu_write_sme(struct arm_smmu_device *smmu, int idx)
                arm_smmu_write_smr(smmu, idx);
 }
 
+/*
+ * The width of SMR's mask field depends on sCR0_EXIDENABLE, so this function
+ * should be called after sCR0 is written.
+ */
+static void arm_smmu_test_smr_masks(struct arm_smmu_device *smmu)
+{
+       void __iomem *gr0_base = ARM_SMMU_GR0(smmu);
+       u32 smr;
+
+       if (!smmu->smrs)
+               return;
+
+       /*
+        * SMR.ID bits may not be preserved if the corresponding MASK
+        * bits are set, so check each one separately. We can reject
+        * masters later if they try to claim IDs outside these masks.
+        */
+       smr = smmu->streamid_mask << SMR_ID_SHIFT;
+       writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(0));
+       smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(0));
+       smmu->streamid_mask = smr >> SMR_ID_SHIFT;
+
+       smr = smmu->streamid_mask << SMR_MASK_SHIFT;
+       writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(0));
+       smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(0));
+       smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
+}
+
 static int arm_smmu_find_sme(struct arm_smmu_device *smmu, u16 id, u16 mask)
 {
        struct arm_smmu_smr *smrs = smmu->smrs;
@@ -1209,7 +1259,7 @@ static int arm_smmu_domain_add_master(struct arm_smmu_domain *smmu_domain,
                        continue;
 
                s2cr[idx].type = type;
-               s2cr[idx].privcfg = S2CR_PRIVCFG_UNPRIV;
+               s2cr[idx].privcfg = S2CR_PRIVCFG_DEFAULT;
                s2cr[idx].cbndx = cbndx;
                arm_smmu_write_s2cr(smmu, idx);
        }
@@ -1228,6 +1278,16 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
                return -ENXIO;
        }
 
+       /*
+        * FIXME: The arch/arm DMA API code tries to attach devices to its own
+        * domains between of_xlate() and add_device() - we have no way to cope
+        * with that, so until ARM gets converted to rely on groups and default
+        * domains, just say no (but more politely than by dereferencing NULL).
+        * This should be at least a WARN_ON once that's sorted.
+        */
+       if (!fwspec->iommu_priv)
+               return -ENODEV;
+
        smmu = fwspec_smmu(fwspec);
        /* Ensure that the domain is finalised */
        ret = arm_smmu_init_domain_context(domain, smmu);
@@ -1356,8 +1416,6 @@ static bool arm_smmu_capable(enum iommu_cap cap)
                 * requests.
                 */
                return true;
-       case IOMMU_CAP_INTR_REMAP:
-               return true; /* MSIs are just memory writes */
        case IOMMU_CAP_NOEXEC:
                return true;
        default:
@@ -1367,13 +1425,14 @@ static bool arm_smmu_capable(enum iommu_cap cap)
 
 static int arm_smmu_match_node(struct device *dev, void *data)
 {
-       return dev->of_node == data;
+       return dev->fwnode == data;
 }
 
-static struct arm_smmu_device *arm_smmu_get_by_node(struct device_node *np)
+static
+struct arm_smmu_device *arm_smmu_get_by_fwnode(struct fwnode_handle *fwnode)
 {
        struct device *dev = driver_find_device(&arm_smmu_driver.driver, NULL,
-                                               np, arm_smmu_match_node);
+                                               fwnode, arm_smmu_match_node);
        put_device(dev);
        return dev ? dev_get_drvdata(dev) : NULL;
 }
@@ -1390,8 +1449,8 @@ static int arm_smmu_add_device(struct device *dev)
                fwspec = dev->iommu_fwspec;
                if (ret)
                        goto out_free;
-       } else if (fwspec) {
-               smmu = arm_smmu_get_by_node(to_of_node(fwspec->iommu_fwnode));
+       } else if (fwspec && fwspec->ops == &arm_smmu_ops) {
+               smmu = arm_smmu_get_by_fwnode(fwspec->iommu_fwnode);
        } else {
                return -ENODEV;
        }
@@ -1428,6 +1487,8 @@ static int arm_smmu_add_device(struct device *dev)
        if (ret)
                goto out_free;
 
+       iommu_device_link(&smmu->iommu, dev);
+
        return 0;
 
 out_free:
@@ -1440,10 +1501,17 @@ out_free:
 static void arm_smmu_remove_device(struct device *dev)
 {
        struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+       struct arm_smmu_master_cfg *cfg;
+       struct arm_smmu_device *smmu;
+
 
        if (!fwspec || fwspec->ops != &arm_smmu_ops)
                return;
 
+       cfg  = fwspec->iommu_priv;
+       smmu = cfg->smmu;
+
+       iommu_device_unlink(&smmu->iommu, dev);
        arm_smmu_master_free_smes(fwspec);
        iommu_group_remove_device(dev);
        kfree(fwspec->iommu_priv);
@@ -1466,7 +1534,7 @@ static struct iommu_group *arm_smmu_device_group(struct device *dev)
        }
 
        if (group)
-               return group;
+               return iommu_group_ref_get(group);
 
        if (dev_is_pci(dev))
                group = pci_device_group(dev);
@@ -1533,6 +1601,29 @@ static int arm_smmu_of_xlate(struct device *dev, struct of_phandle_args *args)
        return iommu_fwspec_add_ids(dev, &fwid, 1);
 }
 
+static void arm_smmu_get_resv_regions(struct device *dev,
+                                     struct list_head *head)
+{
+       struct iommu_resv_region *region;
+       int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
+
+       region = iommu_alloc_resv_region(MSI_IOVA_BASE, MSI_IOVA_LENGTH,
+                                        prot, IOMMU_RESV_MSI);
+       if (!region)
+               return;
+
+       list_add_tail(&region->list, head);
+}
+
+static void arm_smmu_put_resv_regions(struct device *dev,
+                                     struct list_head *head)
+{
+       struct iommu_resv_region *entry, *next;
+
+       list_for_each_entry_safe(entry, next, head, list)
+               kfree(entry);
+}
+
 static struct iommu_ops arm_smmu_ops = {
        .capable                = arm_smmu_capable,
        .domain_alloc           = arm_smmu_domain_alloc,
@@ -1548,6 +1639,8 @@ static struct iommu_ops arm_smmu_ops = {
        .domain_get_attr        = arm_smmu_domain_get_attr,
        .domain_set_attr        = arm_smmu_domain_set_attr,
        .of_xlate               = arm_smmu_of_xlate,
+       .get_resv_regions       = arm_smmu_get_resv_regions,
+       .put_resv_regions       = arm_smmu_put_resv_regions,
        .pgsize_bitmap          = -1UL, /* Restricted during device attach */
 };
 
@@ -1569,16 +1662,22 @@ static void arm_smmu_device_reset(struct arm_smmu_device *smmu)
        for (i = 0; i < smmu->num_mapping_groups; ++i)
                arm_smmu_write_sme(smmu, i);
 
-       /*
-        * Before clearing ARM_MMU500_ACTLR_CPRE, need to
-        * clear CACHE_LOCK bit of ACR first. And, CACHE_LOCK
-        * bit is only present in MMU-500r2 onwards.
-        */
-       reg = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID7);
-       major = (reg >> ID7_MAJOR_SHIFT) & ID7_MAJOR_MASK;
-       if ((smmu->model == ARM_MMU500) && (major >= 2)) {
+       if (smmu->model == ARM_MMU500) {
+               /*
+                * Before clearing ARM_MMU500_ACTLR_CPRE, need to
+                * clear CACHE_LOCK bit of ACR first. And, CACHE_LOCK
+                * bit is only present in MMU-500r2 onwards.
+                */
+               reg = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID7);
+               major = (reg >> ID7_MAJOR_SHIFT) & ID7_MAJOR_MASK;
                reg = readl_relaxed(gr0_base + ARM_SMMU_GR0_sACR);
-               reg &= ~ARM_MMU500_ACR_CACHE_LOCK;
+               if (major >= 2)
+                       reg &= ~ARM_MMU500_ACR_CACHE_LOCK;
+               /*
+                * Allow unmatched Stream IDs to allocate bypass
+                * TLB entries for reduced latency.
+                */
+               reg |= ARM_MMU500_ACR_SMTNMB_TLBEN;
                writel_relaxed(reg, gr0_base + ARM_SMMU_GR0_sACR);
        }
 
@@ -1626,6 +1725,9 @@ static void arm_smmu_device_reset(struct arm_smmu_device *smmu)
        if (smmu->features & ARM_SMMU_FEAT_VMID16)
                reg |= sCR0_VMID16EN;
 
+       if (smmu->features & ARM_SMMU_FEAT_EXIDS)
+               reg |= sCR0_EXIDENABLE;
+
        /* Push the button */
        __arm_smmu_tlb_sync(smmu);
        writel(reg, ARM_SMMU_GR0_NS(smmu) + ARM_SMMU_GR0_sCR0);
@@ -1655,7 +1757,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
        unsigned long size;
        void __iomem *gr0_base = ARM_SMMU_GR0(smmu);
        u32 id;
-       bool cttw_dt, cttw_reg;
+       bool cttw_reg, cttw_fw = smmu->features & ARM_SMMU_FEAT_COHERENT_WALK;
        int i;
 
        dev_notice(smmu->dev, "probing hardware configuration...\n");
@@ -1700,27 +1802,27 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
 
        /*
         * In order for DMA API calls to work properly, we must defer to what
-        * the DT says about coherency, regardless of what the hardware claims.
+        * the FW says about coherency, regardless of what the hardware claims.
         * Fortunately, this also opens up a workaround for systems where the
         * ID register value has ended up configured incorrectly.
         */
-       cttw_dt = of_dma_is_coherent(smmu->dev->of_node);
        cttw_reg = !!(id & ID0_CTTW);
-       if (cttw_dt)
-               smmu->features |= ARM_SMMU_FEAT_COHERENT_WALK;
-       if (cttw_dt || cttw_reg)
+       if (cttw_fw || cttw_reg)
                dev_notice(smmu->dev, "\t%scoherent table walk\n",
-                          cttw_dt ? "" : "non-");
-       if (cttw_dt != cttw_reg)
+                          cttw_fw ? "" : "non-");
+       if (cttw_fw != cttw_reg)
                dev_notice(smmu->dev,
-                          "\t(IDR0.CTTW overridden by dma-coherent property)\n");
+                          "\t(IDR0.CTTW overridden by FW configuration)\n");
 
        /* Max. number of entries we have for stream matching/indexing */
-       size = 1 << ((id >> ID0_NUMSIDB_SHIFT) & ID0_NUMSIDB_MASK);
+       if (smmu->version == ARM_SMMU_V2 && id & ID0_EXIDS) {
+               smmu->features |= ARM_SMMU_FEAT_EXIDS;
+               size = 1 << 16;
+       } else {
+               size = 1 << ((id >> ID0_NUMSIDB_SHIFT) & ID0_NUMSIDB_MASK);
+       }
        smmu->streamid_mask = size - 1;
        if (id & ID0_SMS) {
-               u32 smr;
-
                smmu->features |= ARM_SMMU_FEAT_STREAM_MATCH;
                size = (id >> ID0_NUMSMRG_SHIFT) & ID0_NUMSMRG_MASK;
                if (size == 0) {
@@ -1729,21 +1831,6 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
                        return -ENODEV;
                }
 
-               /*
-                * SMR.ID bits may not be preserved if the corresponding MASK
-                * bits are set, so check each one separately. We can reject
-                * masters later if they try to claim IDs outside these masks.
-                */
-               smr = smmu->streamid_mask << SMR_ID_SHIFT;
-               writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(0));
-               smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(0));
-               smmu->streamid_mask = smr >> SMR_ID_SHIFT;
-
-               smr = smmu->streamid_mask << SMR_MASK_SHIFT;
-               writel_relaxed(smr, gr0_base + ARM_SMMU_GR0_SMR(0));
-               smr = readl_relaxed(gr0_base + ARM_SMMU_GR0_SMR(0));
-               smmu->smr_mask_mask = smr >> SMR_MASK_SHIFT;
-
                /* Zero-initialised to mark as invalid */
                smmu->smrs = devm_kcalloc(smmu->dev, size, sizeof(*smmu->smrs),
                                          GFP_KERNEL);
@@ -1751,8 +1838,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
                        return -ENOMEM;
 
                dev_notice(smmu->dev,
-                          "\tstream matching with %lu register groups, mask 0x%x",
-                          size, smmu->smr_mask_mask);
+                          "\tstream matching with %lu register groups", size);
        }
        /* s2cr->type == 0 means translation, so initialise explicitly */
        smmu->s2crs = devm_kmalloc_array(smmu->dev, size, sizeof(*smmu->s2crs),
@@ -1894,15 +1980,83 @@ static const struct of_device_id arm_smmu_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, arm_smmu_of_match);
 
-static int arm_smmu_device_dt_probe(struct platform_device *pdev)
+#ifdef CONFIG_ACPI
+static int acpi_smmu_get_data(u32 model, struct arm_smmu_device *smmu)
+{
+       int ret = 0;
+
+       switch (model) {
+       case ACPI_IORT_SMMU_V1:
+       case ACPI_IORT_SMMU_CORELINK_MMU400:
+               smmu->version = ARM_SMMU_V1;
+               smmu->model = GENERIC_SMMU;
+               break;
+       case ACPI_IORT_SMMU_V2:
+               smmu->version = ARM_SMMU_V2;
+               smmu->model = GENERIC_SMMU;
+               break;
+       case ACPI_IORT_SMMU_CORELINK_MMU500:
+               smmu->version = ARM_SMMU_V2;
+               smmu->model = ARM_MMU500;
+               break;
+       default:
+               ret = -ENODEV;
+       }
+
+       return ret;
+}
+
+static int arm_smmu_device_acpi_probe(struct platform_device *pdev,
+                                     struct arm_smmu_device *smmu)
+{
+       struct device *dev = smmu->dev;
+       struct acpi_iort_node *node =
+               *(struct acpi_iort_node **)dev_get_platdata(dev);
+       struct acpi_iort_smmu *iort_smmu;
+       int ret;
+
+       /* Retrieve SMMU1/2 specific data */
+       iort_smmu = (struct acpi_iort_smmu *)node->node_data;
+
+       ret = acpi_smmu_get_data(iort_smmu->model, smmu);
+       if (ret < 0)
+               return ret;
+
+       /* Ignore the configuration access interrupt */
+       smmu->num_global_irqs = 1;
+
+       if (iort_smmu->flags & ACPI_IORT_SMMU_COHERENT_WALK)
+               smmu->features |= ARM_SMMU_FEAT_COHERENT_WALK;
+
+       return 0;
+}
+#else
+static inline int arm_smmu_device_acpi_probe(struct platform_device *pdev,
+                                            struct arm_smmu_device *smmu)
+{
+       return -ENODEV;
+}
+#endif
+
+static int arm_smmu_device_dt_probe(struct platform_device *pdev,
+                                   struct arm_smmu_device *smmu)
 {
        const struct arm_smmu_match_data *data;
-       struct resource *res;
-       struct arm_smmu_device *smmu;
        struct device *dev = &pdev->dev;
-       int num_irqs, i, err;
        bool legacy_binding;
 
+       if (of_property_read_u32(dev->of_node, "#global-interrupts",
+                                &smmu->num_global_irqs)) {
+               dev_err(dev, "missing #global-interrupts property\n");
+               return -ENODEV;
+       }
+
+       data = of_device_get_match_data(dev);
+       smmu->version = data->version;
+       smmu->model = data->model;
+
+       parse_driver_options(smmu);
+
        legacy_binding = of_find_property(dev->of_node, "mmu-masters", NULL);
        if (legacy_binding && !using_generic_binding) {
                if (!using_legacy_binding)
@@ -1915,6 +2069,20 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
                return -ENODEV;
        }
 
+       if (of_dma_is_coherent(dev->of_node))
+               smmu->features |= ARM_SMMU_FEAT_COHERENT_WALK;
+
+       return 0;
+}
+
+static int arm_smmu_device_probe(struct platform_device *pdev)
+{
+       struct resource *res;
+       resource_size_t ioaddr;
+       struct arm_smmu_device *smmu;
+       struct device *dev = &pdev->dev;
+       int num_irqs, i, err;
+
        smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL);
        if (!smmu) {
                dev_err(dev, "failed to allocate arm_smmu_device\n");
@@ -1922,22 +2090,21 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
        }
        smmu->dev = dev;
 
-       data = of_device_get_match_data(dev);
-       smmu->version = data->version;
-       smmu->model = data->model;
+       if (dev->of_node)
+               err = arm_smmu_device_dt_probe(pdev, smmu);
+       else
+               err = arm_smmu_device_acpi_probe(pdev, smmu);
+
+       if (err)
+               return err;
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       ioaddr = res->start;
        smmu->base = devm_ioremap_resource(dev, res);
        if (IS_ERR(smmu->base))
                return PTR_ERR(smmu->base);
        smmu->size = resource_size(res);
 
-       if (of_property_read_u32(dev->of_node, "#global-interrupts",
-                                &smmu->num_global_irqs)) {
-               dev_err(dev, "missing #global-interrupts property\n");
-               return -ENODEV;
-       }
-
        num_irqs = 0;
        while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, num_irqs))) {
                num_irqs++;
@@ -1972,8 +2139,6 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
        if (err)
                return err;
 
-       parse_driver_options(smmu);
-
        if (smmu->version == ARM_SMMU_V2 &&
            smmu->num_context_banks != smmu->num_context_irqs) {
                dev_err(dev,
@@ -1995,9 +2160,25 @@ static int arm_smmu_device_dt_probe(struct platform_device *pdev)
                }
        }
 
-       of_iommu_set_ops(dev->of_node, &arm_smmu_ops);
+       err = iommu_device_sysfs_add(&smmu->iommu, smmu->dev, NULL,
+                                    "smmu.%pa", &ioaddr);
+       if (err) {
+               dev_err(dev, "Failed to register iommu in sysfs\n");
+               return err;
+       }
+
+       iommu_device_set_ops(&smmu->iommu, &arm_smmu_ops);
+       iommu_device_set_fwnode(&smmu->iommu, dev->fwnode);
+
+       err = iommu_device_register(&smmu->iommu);
+       if (err) {
+               dev_err(dev, "Failed to register iommu\n");
+               return err;
+       }
+
        platform_set_drvdata(pdev, smmu);
        arm_smmu_device_reset(smmu);
+       arm_smmu_test_smr_masks(smmu);
 
        /* Oh, for a proper bus abstraction */
        if (!iommu_present(&platform_bus_type))
@@ -2035,7 +2216,7 @@ static struct platform_driver arm_smmu_driver = {
                .name           = "arm-smmu",
                .of_match_table = of_match_ptr(arm_smmu_of_match),
        },
-       .probe  = arm_smmu_device_dt_probe,
+       .probe  = arm_smmu_device_probe,
        .remove = arm_smmu_device_remove,
 };
 
@@ -2078,6 +2259,17 @@ IOMMU_OF_DECLARE(arm_mmu401, "arm,mmu-401", arm_smmu_of_init);
 IOMMU_OF_DECLARE(arm_mmu500, "arm,mmu-500", arm_smmu_of_init);
 IOMMU_OF_DECLARE(cavium_smmuv2, "cavium,smmu-v2", arm_smmu_of_init);
 
+#ifdef CONFIG_ACPI
+static int __init arm_smmu_acpi_init(struct acpi_table_header *table)
+{
+       if (iort_node_match(ACPI_IORT_NODE_SMMU))
+               return arm_smmu_init();
+
+       return 0;
+}
+IORT_ACPI_DECLARE(arm_smmu, ACPI_SIG_IORT, arm_smmu_acpi_init);
+#endif
+
 MODULE_DESCRIPTION("IOMMU API for ARM architected SMMU implementations");
 MODULE_AUTHOR("Will Deacon <will.deacon@arm.com>");
 MODULE_LICENSE("GPL v2");