]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blobdiff - arch/arm/mm/dma-mapping.c
ARM: dma-mapping: Add arm_iommu_detach_device()
[mirror_ubuntu-hirsute-kernel.git] / arch / arm / mm / dma-mapping.c
index 076c26d43864f8a5b3da49ac7231a62e8edde0c2..6563e38726599275798872cb3f3fdc6cf44336ab 100644 (file)
@@ -640,7 +640,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 
        if (is_coherent || nommu())
                addr = __alloc_simple_buffer(dev, size, gfp, &page);
-       else if (gfp & GFP_ATOMIC)
+       else if (!(gfp & __GFP_WAIT))
                addr = __alloc_from_pool(size, &page);
        else if (!IS_ENABLED(CONFIG_CMA))
                addr = __alloc_remap_buffer(dev, size, gfp, prot, &page, caller);
@@ -1732,6 +1732,8 @@ struct dma_map_ops iommu_ops = {
        .unmap_sg               = arm_iommu_unmap_sg,
        .sync_sg_for_cpu        = arm_iommu_sync_sg_for_cpu,
        .sync_sg_for_device     = arm_iommu_sync_sg_for_device,
+
+       .set_dma_mask           = arm_dma_set_mask,
 };
 
 struct dma_map_ops iommu_coherent_ops = {
@@ -1745,6 +1747,8 @@ struct dma_map_ops iommu_coherent_ops = {
 
        .map_sg         = arm_coherent_iommu_map_sg,
        .unmap_sg       = arm_coherent_iommu_unmap_sg,
+
+       .set_dma_mask   = arm_dma_set_mask,
 };
 
 /**
@@ -1844,4 +1848,29 @@ int arm_iommu_attach_device(struct device *dev,
        return 0;
 }
 
+/**
+ * arm_iommu_detach_device
+ * @dev: valid struct device pointer
+ *
+ * Detaches the provided device from a previously attached map.
+ * This voids the dma operations (dma_map_ops pointer)
+ */
+void arm_iommu_detach_device(struct device *dev)
+{
+       struct dma_iommu_mapping *mapping;
+
+       mapping = to_dma_iommu_mapping(dev);
+       if (!mapping) {
+               dev_warn(dev, "Not attached\n");
+               return;
+       }
+
+       iommu_detach_device(mapping->domain, dev);
+       kref_put(&mapping->kref, release_iommu_mapping);
+       mapping = NULL;
+       set_dma_ops(dev, NULL);
+
+       pr_debug("Detached IOMMU controller from %s device.\n", dev_name(dev));
+}
+
 #endif