Merge tag 'iommu-updates-v4.21' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / drivers / iommu / amd_iommu.c
index 49a669b1ce116082213805d9791957c180097812..87ba23a75b381ff245690a1106ddf190b0b327f7 100644 (file)
@@ -57,8 +57,6 @@
 #include "amd_iommu_types.h"
 #include "irq_remapping.h"
 
-#define AMD_IOMMU_MAPPING_ERROR        0
-
 #define CMD_SET_TYPE(cmd, t) ((cmd)->data[1] |= ((t) << 28))
 
 #define LOOP_TIMEOUT   100000
@@ -2257,7 +2255,7 @@ static int amd_iommu_add_device(struct device *dev)
                                dev_name(dev));
 
                iommu_ignore_device(dev);
-               dev->dma_ops = &dma_direct_ops;
+               dev->dma_ops = NULL;
                goto out;
        }
        init_iommu_group(dev);
@@ -2410,7 +2408,7 @@ static dma_addr_t __map_single(struct device *dev,
        paddr &= PAGE_MASK;
 
        address = dma_ops_alloc_iova(dev, dma_dom, pages, dma_mask);
-       if (address == AMD_IOMMU_MAPPING_ERROR)
+       if (!address)
                goto out;
 
        prot = dir2prot(direction);
@@ -2447,7 +2445,7 @@ out_unmap:
 
        dma_ops_free_iova(dma_dom, address, pages);
 
-       return AMD_IOMMU_MAPPING_ERROR;
+       return DMA_MAPPING_ERROR;
 }
 
 /*
@@ -2498,7 +2496,7 @@ static dma_addr_t map_page(struct device *dev, struct page *page,
        if (PTR_ERR(domain) == -EINVAL)
                return (dma_addr_t)paddr;
        else if (IS_ERR(domain))
-               return AMD_IOMMU_MAPPING_ERROR;
+               return DMA_MAPPING_ERROR;
 
        dma_mask = *dev->dma_mask;
        dma_dom = to_dma_ops_domain(domain);
@@ -2575,7 +2573,7 @@ static int map_sg(struct device *dev, struct scatterlist *sglist,
        npages = sg_num_pages(dev, sglist, nelems);
 
        address = dma_ops_alloc_iova(dev, dma_dom, npages, dma_mask);
-       if (address == AMD_IOMMU_MAPPING_ERROR)
+       if (address == DMA_MAPPING_ERROR)
                goto out_err;
 
        prot = dir2prot(direction);
@@ -2698,7 +2696,7 @@ static void *alloc_coherent(struct device *dev, size_t size,
        *dma_addr = __map_single(dev, dma_dom, page_to_phys(page),
                                 size, DMA_BIDIRECTIONAL, dma_mask);
 
-       if (*dma_addr == AMD_IOMMU_MAPPING_ERROR)
+       if (*dma_addr == DMA_MAPPING_ERROR)
                goto out_free;
 
        return page_address(page);
@@ -2749,11 +2747,6 @@ static int amd_iommu_dma_supported(struct device *dev, u64 mask)
        return check_device(dev);
 }
 
-static int amd_iommu_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       return dma_addr == AMD_IOMMU_MAPPING_ERROR;
-}
-
 static const struct dma_map_ops amd_iommu_dma_ops = {
        .alloc          = alloc_coherent,
        .free           = free_coherent,
@@ -2762,7 +2755,6 @@ static const struct dma_map_ops amd_iommu_dma_ops = {
        .map_sg         = map_sg,
        .unmap_sg       = unmap_sg,
        .dma_supported  = amd_iommu_dma_supported,
-       .mapping_error  = amd_iommu_mapping_error,
 };
 
 static int init_reserved_iova_ranges(void)
@@ -2849,17 +2841,6 @@ int __init amd_iommu_init_dma_ops(void)
        swiotlb        = (iommu_pass_through || sme_me_mask) ? 1 : 0;
        iommu_detected = 1;
 
-       /*
-        * In case we don't initialize SWIOTLB (actually the common case
-        * when AMD IOMMU is enabled and SME is not active), make sure there
-        * are global dma_ops set as a fall-back for devices not handled by
-        * this driver (for example non-PCI devices). When SME is active,
-        * make sure that swiotlb variable remains set so the global dma_ops
-        * continue to be SWIOTLB.
-        */
-       if (!swiotlb)
-               dma_ops = &dma_direct_ops;
-
        if (amd_iommu_unmap_flush)
                pr_info("IO/TLB flush on unmap enabled\n");
        else