Merge tag 'dma-mapping-5.4' of git://git.infradead.org/users/hch/dma-mapping
[linux-2.6-block.git] / arch / ia64 / hp / common / sba_iommu.c
index 4c0ea6c2833d4f568b08d0a45b3ce52943a1246f..a806227c1fad8fd3747f53bf6bfe19b252ff1582 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/iommu-helper.h>
 #include <linux/dma-mapping.h>
 #include <linux/prefetch.h>
+#include <linux/swiotlb.h>
 
 #include <asm/delay.h>         /* ia64_get_itc() */
 #include <asm/io.h>
@@ -43,8 +44,6 @@
 
 #include <asm/acpi-ext.h>
 
-extern int swiotlb_late_init_with_default_size (size_t size);
-
 #define PFX "IOC: "
 
 /*
@@ -251,12 +250,8 @@ static SBA_INLINE void sba_free_range(struct ioc *, dma_addr_t, size_t);
 static u64 prefetch_spill_page;
 #endif
 
-#ifdef CONFIG_PCI
-# define GET_IOC(dev)  ((dev_is_pci(dev))                                              \
+#define GET_IOC(dev)   ((dev_is_pci(dev))                                              \
                         ? ((struct ioc *) PCI_CONTROLLER(to_pci_dev(dev))->iommu) : NULL)
-#else
-# define GET_IOC(dev)  NULL
-#endif
 
 /*
 ** DMA_CHUNK_SIZE is used by the SCSI mid-layer to break up
@@ -1741,9 +1736,7 @@ ioc_sac_init(struct ioc *ioc)
        controller->iommu = ioc;
        sac->sysdata = controller;
        sac->dma_mask = 0xFFFFFFFFUL;
-#ifdef CONFIG_PCI
        sac->dev.bus = &pci_bus_type;
-#endif
        ioc->sac_only_dev = sac;
 }
 
@@ -2062,27 +2055,35 @@ static int __init acpi_sba_ioc_init_acpi(void)
 /* This has to run before acpi_scan_init(). */
 arch_initcall(acpi_sba_ioc_init_acpi);
 
+static int sba_dma_supported (struct device *dev, u64 mask)
+{
+       /* make sure it's at least 32bit capable */
+       return ((mask & 0xFFFFFFFFUL) == 0xFFFFFFFFUL);
+}
+
+static const struct dma_map_ops sba_dma_ops = {
+       .alloc                  = sba_alloc_coherent,
+       .free                   = sba_free_coherent,
+       .map_page               = sba_map_page,
+       .unmap_page             = sba_unmap_page,
+       .map_sg                 = sba_map_sg_attrs,
+       .unmap_sg               = sba_unmap_sg_attrs,
+       .dma_supported          = sba_dma_supported,
+       .mmap                   = dma_common_mmap,
+       .get_sgtable            = dma_common_get_sgtable,
+};
+
 static int __init
 sba_init(void)
 {
-       if (!ia64_platform_is("hpzx1") && !ia64_platform_is("hpzx1_swiotlb"))
-               return 0;
-
-#if defined(CONFIG_IA64_GENERIC)
-       /* If we are booting a kdump kernel, the sba_iommu will
-        * cause devices that were not shutdown properly to MCA
-        * as soon as they are turned back on.  Our only option for
-        * a successful kdump kernel boot is to use the swiotlb.
+       /*
+        * If we are booting a kdump kernel, the sba_iommu will cause devices
+        * that were not shutdown properly to MCA as soon as they are turned
+        * back on.  Our only option for a successful kdump kernel boot is to
+        * use swiotlb.
         */
-       if (is_kdump_kernel()) {
-               dma_ops = NULL;
-               if (swiotlb_late_init_with_default_size(64 * (1<<20)) != 0)
-                       panic("Unable to initialize software I/O TLB:"
-                                 " Try machvec=dig boot option");
-               machvec_init("dig");
+       if (is_kdump_kernel())
                return 0;
-       }
-#endif
 
        /*
         * ioc_found should be populated by the acpi_sba_ioc_handler's .attach()
@@ -2091,43 +2092,18 @@ sba_init(void)
        while (ioc_found)
                acpi_sba_ioc_add(ioc_found);
 
-       if (!ioc_list) {
-#ifdef CONFIG_IA64_GENERIC
-               /*
-                * If we didn't find something sba_iommu can claim, we
-                * need to setup the swiotlb and switch to the dig machvec.
-                */
-               dma_ops = NULL;
-               if (swiotlb_late_init_with_default_size(64 * (1<<20)) != 0)
-                       panic("Unable to find SBA IOMMU or initialize "
-                             "software I/O TLB: Try machvec=dig boot option");
-               machvec_init("dig");
-#else
-               panic("Unable to find SBA IOMMU: Try a generic or DIG kernel");
-#endif
+       if (!ioc_list)
                return 0;
-       }
 
-#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_HP_ZX1_SWIOTLB)
-       /*
-        * hpzx1_swiotlb needs to have a fairly small swiotlb bounce
-        * buffer setup to support devices with smaller DMA masks than
-        * sba_iommu can handle.
-        */
-       if (ia64_platform_is("hpzx1_swiotlb")) {
-               extern void hwsw_init(void);
-
-               hwsw_init();
-       }
-#endif
-
-#ifdef CONFIG_PCI
        {
                struct pci_bus *b = NULL;
                while ((b = pci_find_next_bus(b)) != NULL)
                        sba_connect_bus(b);
        }
-#endif
+
+       /* no need for swiotlb with the iommu */
+       swiotlb_exit();
+       dma_ops = &sba_dma_ops;
 
 #ifdef CONFIG_PROC_FS
        ioc_proc_init();
@@ -2144,12 +2120,6 @@ nosbagart(char *str)
        return 1;
 }
 
-static int sba_dma_supported (struct device *dev, u64 mask)
-{
-       /* make sure it's at least 32bit capable */
-       return ((mask & 0xFFFFFFFFUL) == 0xFFFFFFFFUL);
-}
-
 __setup("nosbagart", nosbagart);
 
 static int __init
@@ -2174,20 +2144,3 @@ sba_page_override(char *str)
 }
 
 __setup("sbapagesize=",sba_page_override);
-
-const struct dma_map_ops sba_dma_ops = {
-       .alloc                  = sba_alloc_coherent,
-       .free                   = sba_free_coherent,
-       .map_page               = sba_map_page,
-       .unmap_page             = sba_unmap_page,
-       .map_sg                 = sba_map_sg_attrs,
-       .unmap_sg               = sba_unmap_sg_attrs,
-       .dma_supported          = sba_dma_supported,
-       .mmap                   = dma_common_mmap,
-       .get_sgtable            = dma_common_get_sgtable,
-};
-
-void sba_dma_init(void)
-{
-       dma_ops = &sba_dma_ops;
-}