Merge branches 'iommu/fixes', 'x86/amd', 'groups', 'arm/tegra' and 'api/domain-attr...
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / iommu / amd_iommu.c
index 4917239..6d1cbdf 100644 (file)
@@ -83,6 +83,8 @@ static struct iommu_ops amd_iommu_ops;
 static ATOMIC_NOTIFIER_HEAD(ppr_notifier);
 int amd_iommu_max_glx_val = -1;
 
+static struct dma_map_ops amd_iommu_dma_ops;
+
 /*
  * general struct to manage commands send to an IOMMU
  */
@@ -429,7 +431,6 @@ DECLARE_STATS_COUNTER(invalidate_iotlb);
 DECLARE_STATS_COUNTER(invalidate_iotlb_all);
 DECLARE_STATS_COUNTER(pri_requests);
 
-
 static struct dentry *stats_dir;
 static struct dentry *de_fflush;
 
@@ -449,7 +450,7 @@ static void amd_iommu_stats_init(void)
                return;
 
        de_fflush  = debugfs_create_bool("fullflush", 0444, stats_dir,
-                                        (u32 *)&amd_iommu_unmap_flush);
+                                        &amd_iommu_unmap_flush);
 
        amd_iommu_stats_add(&compl_wait);
        amd_iommu_stats_add(&cnt_map_single);
@@ -2118,7 +2119,7 @@ out_err:
 /* FIXME: Move this to PCI code */
 #define PCI_PRI_TLP_OFF                (1 << 15)
 
-bool pci_pri_tlp_required(struct pci_dev *pdev)
+static bool pci_pri_tlp_required(struct pci_dev *pdev)
 {
        u16 status;
        int pos;
@@ -2299,6 +2300,18 @@ static int device_change_notifier(struct notifier_block *nb,
 
                iommu_init_device(dev);
 
+               /*
+                * dev_data is still NULL and
+                * got initialized in iommu_init_device
+                */
+               dev_data = get_dev_data(dev);
+
+               if (iommu_pass_through || dev_data->iommu_v2) {
+                       dev_data->passthrough = true;
+                       attach_device(dev, pt_domain);
+                       break;
+               }
+
                domain = domain_for_device(dev);
 
                /* allocate a protection domain if a device is added */
@@ -2314,6 +2327,10 @@ static int device_change_notifier(struct notifier_block *nb,
                list_add_tail(&dma_domain->list, &iommu_pd_list);
                spin_unlock_irqrestore(&iommu_pd_list_lock, flags);
 
+               dev_data = get_dev_data(dev);
+
+               dev->archdata.dma_ops = &amd_iommu_dma_ops;
+
                break;
        case BUS_NOTIFY_DEL_DEVICE:
 
@@ -3010,6 +3027,11 @@ int __init amd_iommu_init_dma_ops(void)
 
        amd_iommu_stats_init();
 
+       if (amd_iommu_unmap_flush)
+               pr_info("AMD-Vi: IO/TLB flush on unmap enabled\n");
+       else
+               pr_info("AMD-Vi: Lazy IO/TLB flushing enabled\n");
+
        return 0;
 
 free_domains:
@@ -3116,6 +3138,10 @@ static int amd_iommu_domain_init(struct iommu_domain *dom)
 
        dom->priv = domain;
 
+       dom->geometry.aperture_start = 0;
+       dom->geometry.aperture_end   = ~0ULL;
+       dom->geometry.force_aperture = true;
+
        return 0;
 
 out_free: