page_pool: remove PP_FLAG_PAGE_FRAG
[platform/kernel/linux-rpi.git] / drivers / iommu / of_iommu.c
index 157b286..42cffb0 100644 (file)
@@ -112,16 +112,20 @@ const struct iommu_ops *of_iommu_configure(struct device *dev,
                                           const u32 *id)
 {
        const struct iommu_ops *ops = NULL;
-       struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
+       struct iommu_fwspec *fwspec;
        int err = NO_IOMMU;
 
        if (!master_np)
                return NULL;
 
+       /* Serialise to make dev->iommu stable under our potential fwspec */
+       mutex_lock(&iommu_probe_device_lock);
+       fwspec = dev_iommu_fwspec_get(dev);
        if (fwspec) {
-               if (fwspec->ops)
+               if (fwspec->ops) {
+                       mutex_unlock(&iommu_probe_device_lock);
                        return fwspec->ops;
-
+               }
                /* In the deferred case, start again from scratch */
                iommu_fwspec_free(dev);
        }
@@ -155,6 +159,8 @@ const struct iommu_ops *of_iommu_configure(struct device *dev,
                fwspec = dev_iommu_fwspec_get(dev);
                ops    = fwspec->ops;
        }
+       mutex_unlock(&iommu_probe_device_lock);
+
        /*
         * If we have reason to believe the IOMMU driver missed the initial
         * probe for dev, replay it to get things in order.
@@ -191,7 +197,7 @@ iommu_resv_region_get_type(struct device *dev,
        if (start == phys->start && end == phys->end)
                return IOMMU_RESV_DIRECT;
 
-       dev_warn(dev, "treating non-direct mapping [%pr] -> [%pap-%pap] as reservation\n", &phys,
+       dev_warn(dev, "treating non-direct mapping [%pr] -> [%pap-%pap] as reservation\n", phys,
                 &start, &end);
        return IOMMU_RESV_RESERVED;
 }
@@ -254,7 +260,14 @@ void of_iommu_get_resv_regions(struct device *dev, struct list_head *list)
                                phys_addr_t iova;
                                size_t length;
 
+                               if (of_dma_is_coherent(dev->of_node))
+                                       prot |= IOMMU_CACHE;
+
                                maps = of_translate_dma_region(np, maps, &iova, &length);
+                               if (length == 0) {
+                                       dev_warn(dev, "Cannot reserve IOVA region of 0 size\n");
+                                       continue;
+                               }
                                type = iommu_resv_region_get_type(dev, &phys, iova, length);
 
                                region = iommu_alloc_resv_region(iova, length, prot, type,