#include <linux/gfp.h>
 #include <linux/acpi.h>
+#include <linux/bootmem.h>
 #include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/genalloc.h>
 
 #include <asm/cacheflush.h>
 
+static int swiotlb __read_mostly;
+
 static pgprot_t __get_dma_pgprot(struct dma_attrs *attrs, pgprot_t prot,
                                 bool coherent)
 {
        return ret;
 }
 
+static int __swiotlb_dma_supported(struct device *hwdev, u64 mask)
+{
+       if (swiotlb)
+               return swiotlb_dma_supported(hwdev, mask);
+       return 1;
+}
+
 static struct dma_map_ops swiotlb_dma_ops = {
        .alloc = __dma_alloc,
        .free = __dma_free,
        .sync_single_for_device = __swiotlb_sync_single_for_device,
        .sync_sg_for_cpu = __swiotlb_sync_sg_for_cpu,
        .sync_sg_for_device = __swiotlb_sync_sg_for_device,
-       .dma_supported = swiotlb_dma_supported,
+       .dma_supported = __swiotlb_dma_supported,
        .mapping_error = swiotlb_dma_mapping_error,
 };
 
 
 static int __init arm64_dma_init(void)
 {
+       if (swiotlb_force || max_pfn > (arm64_dma_phys_limit >> PAGE_SHIFT))
+               swiotlb = 1;
+
        return atomic_pool_init();
 }
 arch_initcall(arm64_dma_init);