]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Merge branch 'linus' into core/iommu
authorIngo Molnar <mingo@elte.hu>
Sat, 10 Jan 2009 23:51:06 +0000 (00:51 +0100)
committerIngo Molnar <mingo@elte.hu>
Sat, 10 Jan 2009 23:51:06 +0000 (00:51 +0100)
30 files changed:
arch/ia64/dig/Makefile
arch/ia64/dig/dig_vtd_iommu.c [deleted file]
arch/ia64/hp/common/hwsw_iommu.c
arch/ia64/hp/common/sba_iommu.c
arch/ia64/include/asm/dma-mapping.h
arch/ia64/include/asm/machvec.h
arch/ia64/include/asm/machvec_dig_vtd.h
arch/ia64/include/asm/machvec_hpzx1.h
arch/ia64/include/asm/machvec_hpzx1_swiotlb.h
arch/ia64/include/asm/machvec_sn2.h
arch/ia64/kernel/Makefile
arch/ia64/kernel/dma-mapping.c [new file with mode: 0644]
arch/ia64/kernel/machvec.c
arch/ia64/kernel/pci-dma.c
arch/ia64/kernel/pci-swiotlb.c
arch/ia64/sn/pci/pci_dma.c
arch/x86/include/asm/device.h
arch/x86/include/asm/dma-mapping.h
arch/x86/include/asm/iommu.h
arch/x86/kernel/amd_iommu.c
arch/x86/kernel/pci-calgary_64.c
arch/x86/kernel/pci-dma.c
arch/x86/kernel/pci-gart_64.c
arch/x86/kernel/pci-nommu.c
arch/x86/kernel/pci-swiotlb_64.c
drivers/pci/intel-iommu.c
include/linux/dma-mapping.h
include/linux/intel-iommu.h
include/linux/swiotlb.h
lib/swiotlb.c

index 5c0283830bd611d951c28f3b64ed49b41f961c73..2f7caddf093e8bce77d4d92f2933ee2500f8ab60 100644 (file)
@@ -7,8 +7,8 @@
 
 obj-y := setup.o
 ifeq ($(CONFIG_DMAR), y)
-obj-$(CONFIG_IA64_GENERIC) += machvec.o machvec_vtd.o dig_vtd_iommu.o
+obj-$(CONFIG_IA64_GENERIC) += machvec.o machvec_vtd.o
 else
 obj-$(CONFIG_IA64_GENERIC) += machvec.o
 endif
-obj-$(CONFIG_IA64_DIG_VTD) += dig_vtd_iommu.o
+
diff --git a/arch/ia64/dig/dig_vtd_iommu.c b/arch/ia64/dig/dig_vtd_iommu.c
deleted file mode 100644 (file)
index 1c8a079..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/intel-iommu.h>
-
-void *
-vtd_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
-                gfp_t flags)
-{
-       return intel_alloc_coherent(dev, size, dma_handle, flags);
-}
-EXPORT_SYMBOL_GPL(vtd_alloc_coherent);
-
-void
-vtd_free_coherent(struct device *dev, size_t size, void *vaddr,
-                dma_addr_t dma_handle)
-{
-       intel_free_coherent(dev, size, vaddr, dma_handle);
-}
-EXPORT_SYMBOL_GPL(vtd_free_coherent);
-
-dma_addr_t
-vtd_map_single_attrs(struct device *dev, void *addr, size_t size,
-                    int dir, struct dma_attrs *attrs)
-{
-       return intel_map_single(dev, (phys_addr_t)addr, size, dir);
-}
-EXPORT_SYMBOL_GPL(vtd_map_single_attrs);
-
-void
-vtd_unmap_single_attrs(struct device *dev, dma_addr_t iova, size_t size,
-                      int dir, struct dma_attrs *attrs)
-{
-       intel_unmap_single(dev, iova, size, dir);
-}
-EXPORT_SYMBOL_GPL(vtd_unmap_single_attrs);
-
-int
-vtd_map_sg_attrs(struct device *dev, struct scatterlist *sglist, int nents,
-                int dir, struct dma_attrs *attrs)
-{
-       return intel_map_sg(dev, sglist, nents, dir);
-}
-EXPORT_SYMBOL_GPL(vtd_map_sg_attrs);
-
-void
-vtd_unmap_sg_attrs(struct device *dev, struct scatterlist *sglist,
-                  int nents, int dir, struct dma_attrs *attrs)
-{
-       intel_unmap_sg(dev, sglist, nents, dir);
-}
-EXPORT_SYMBOL_GPL(vtd_unmap_sg_attrs);
-
-int
-vtd_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       return 0;
-}
-EXPORT_SYMBOL_GPL(vtd_dma_mapping_error);
index 2769dbfd03bf8146852e7340ef5aee44746c0d30..e4a80d82e3d8b570d2ce2950319094f5d286b9c7 100644 (file)
  */
 
 #include <linux/device.h>
+#include <linux/dma-mapping.h>
 #include <linux/swiotlb.h>
-
 #include <asm/machvec.h>
 
+extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
+
 /* swiotlb declarations & definitions: */
 extern int swiotlb_late_init_with_default_size (size_t size);
 
-/* hwiommu declarations & definitions: */
-
-extern ia64_mv_dma_alloc_coherent      sba_alloc_coherent;
-extern ia64_mv_dma_free_coherent       sba_free_coherent;
-extern ia64_mv_dma_map_single_attrs    sba_map_single_attrs;
-extern ia64_mv_dma_unmap_single_attrs  sba_unmap_single_attrs;
-extern ia64_mv_dma_map_sg_attrs                sba_map_sg_attrs;
-extern ia64_mv_dma_unmap_sg_attrs      sba_unmap_sg_attrs;
-extern ia64_mv_dma_supported           sba_dma_supported;
-extern ia64_mv_dma_mapping_error       sba_dma_mapping_error;
-
-#define hwiommu_alloc_coherent         sba_alloc_coherent
-#define hwiommu_free_coherent          sba_free_coherent
-#define hwiommu_map_single_attrs       sba_map_single_attrs
-#define hwiommu_unmap_single_attrs     sba_unmap_single_attrs
-#define hwiommu_map_sg_attrs           sba_map_sg_attrs
-#define hwiommu_unmap_sg_attrs         sba_unmap_sg_attrs
-#define hwiommu_dma_supported          sba_dma_supported
-#define hwiommu_dma_mapping_error      sba_dma_mapping_error
-#define hwiommu_sync_single_for_cpu    machvec_dma_sync_single
-#define hwiommu_sync_sg_for_cpu                machvec_dma_sync_sg
-#define hwiommu_sync_single_for_device machvec_dma_sync_single
-#define hwiommu_sync_sg_for_device     machvec_dma_sync_sg
-
-
 /*
  * Note: we need to make the determination of whether or not to use
  * the sw I/O TLB based purely on the device structure.  Anything else
  * would be unreliable or would be too intrusive.
  */
-static inline int
-use_swiotlb (struct device *dev)
+static inline int use_swiotlb(struct device *dev)
 {
-       return dev && dev->dma_mask && !hwiommu_dma_supported(dev, *dev->dma_mask);
+       return dev && dev->dma_mask &&
+               !sba_dma_ops.dma_supported(dev, *dev->dma_mask);
 }
 
+struct dma_map_ops *hwsw_dma_get_ops(struct device *dev)
+{
+       if (use_swiotlb(dev))
+               return &swiotlb_dma_ops;
+       return &sba_dma_ops;
+}
+EXPORT_SYMBOL(hwsw_dma_get_ops);
+
 void __init
 hwsw_init (void)
 {
@@ -71,125 +56,3 @@ hwsw_init (void)
 #endif
        }
 }
-
-void *
-hwsw_alloc_coherent (struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flags)
-{
-       if (use_swiotlb(dev))
-               return swiotlb_alloc_coherent(dev, size, dma_handle, flags);
-       else
-               return hwiommu_alloc_coherent(dev, size, dma_handle, flags);
-}
-
-void
-hwsw_free_coherent (struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle)
-{
-       if (use_swiotlb(dev))
-               swiotlb_free_coherent(dev, size, vaddr, dma_handle);
-       else
-               hwiommu_free_coherent(dev, size, vaddr, dma_handle);
-}
-
-dma_addr_t
-hwsw_map_single_attrs(struct device *dev, void *addr, size_t size, int dir,
-                      struct dma_attrs *attrs)
-{
-       if (use_swiotlb(dev))
-               return swiotlb_map_single_attrs(dev, addr, size, dir, attrs);
-       else
-               return hwiommu_map_single_attrs(dev, addr, size, dir, attrs);
-}
-EXPORT_SYMBOL(hwsw_map_single_attrs);
-
-void
-hwsw_unmap_single_attrs(struct device *dev, dma_addr_t iova, size_t size,
-                        int dir, struct dma_attrs *attrs)
-{
-       if (use_swiotlb(dev))
-               return swiotlb_unmap_single_attrs(dev, iova, size, dir, attrs);
-       else
-               return hwiommu_unmap_single_attrs(dev, iova, size, dir, attrs);
-}
-EXPORT_SYMBOL(hwsw_unmap_single_attrs);
-
-int
-hwsw_map_sg_attrs(struct device *dev, struct scatterlist *sglist, int nents,
-                  int dir, struct dma_attrs *attrs)
-{
-       if (use_swiotlb(dev))
-               return swiotlb_map_sg_attrs(dev, sglist, nents, dir, attrs);
-       else
-               return hwiommu_map_sg_attrs(dev, sglist, nents, dir, attrs);
-}
-EXPORT_SYMBOL(hwsw_map_sg_attrs);
-
-void
-hwsw_unmap_sg_attrs(struct device *dev, struct scatterlist *sglist, int nents,
-                    int dir, struct dma_attrs *attrs)
-{
-       if (use_swiotlb(dev))
-               return swiotlb_unmap_sg_attrs(dev, sglist, nents, dir, attrs);
-       else
-               return hwiommu_unmap_sg_attrs(dev, sglist, nents, dir, attrs);
-}
-EXPORT_SYMBOL(hwsw_unmap_sg_attrs);
-
-void
-hwsw_sync_single_for_cpu (struct device *dev, dma_addr_t addr, size_t size, int dir)
-{
-       if (use_swiotlb(dev))
-               swiotlb_sync_single_for_cpu(dev, addr, size, dir);
-       else
-               hwiommu_sync_single_for_cpu(dev, addr, size, dir);
-}
-
-void
-hwsw_sync_sg_for_cpu (struct device *dev, struct scatterlist *sg, int nelems, int dir)
-{
-       if (use_swiotlb(dev))
-               swiotlb_sync_sg_for_cpu(dev, sg, nelems, dir);
-       else
-               hwiommu_sync_sg_for_cpu(dev, sg, nelems, dir);
-}
-
-void
-hwsw_sync_single_for_device (struct device *dev, dma_addr_t addr, size_t size, int dir)
-{
-       if (use_swiotlb(dev))
-               swiotlb_sync_single_for_device(dev, addr, size, dir);
-       else
-               hwiommu_sync_single_for_device(dev, addr, size, dir);
-}
-
-void
-hwsw_sync_sg_for_device (struct device *dev, struct scatterlist *sg, int nelems, int dir)
-{
-       if (use_swiotlb(dev))
-               swiotlb_sync_sg_for_device(dev, sg, nelems, dir);
-       else
-               hwiommu_sync_sg_for_device(dev, sg, nelems, dir);
-}
-
-int
-hwsw_dma_supported (struct device *dev, u64 mask)
-{
-       if (hwiommu_dma_supported(dev, mask))
-               return 1;
-       return swiotlb_dma_supported(dev, mask);
-}
-
-int
-hwsw_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-       return hwiommu_dma_mapping_error(dev, dma_addr) ||
-               swiotlb_dma_mapping_error(dev, dma_addr);
-}
-
-EXPORT_SYMBOL(hwsw_dma_mapping_error);
-EXPORT_SYMBOL(hwsw_dma_supported);
-EXPORT_SYMBOL(hwsw_alloc_coherent);
-EXPORT_SYMBOL(hwsw_free_coherent);
-EXPORT_SYMBOL(hwsw_sync_single_for_cpu);
-EXPORT_SYMBOL(hwsw_sync_single_for_device);
-EXPORT_SYMBOL(hwsw_sync_sg_for_cpu);
-EXPORT_SYMBOL(hwsw_sync_sg_for_device);
index d98f0f4ff83f22c01df79ffc063d5aaafd8be4a7..129b62eb39e5813457c464bb22b70c69740e63e4 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/bitops.h>         /* hweight64() */
 #include <linux/crash_dump.h>
 #include <linux/iommu-helper.h>
+#include <linux/dma-mapping.h>
 
 #include <asm/delay.h>         /* ia64_get_itc() */
 #include <asm/io.h>
@@ -908,11 +909,13 @@ sba_mark_invalid(struct ioc *ioc, dma_addr_t iova, size_t byte_cnt)
  *
  * See Documentation/DMA-mapping.txt
  */
-dma_addr_t
-sba_map_single_attrs(struct device *dev, void *addr, size_t size, int dir,
-                    struct dma_attrs *attrs)
+static dma_addr_t sba_map_page(struct device *dev, struct page *page,
+                              unsigned long poff, size_t size,
+                              enum dma_data_direction dir,
+                              struct dma_attrs *attrs)
 {
        struct ioc *ioc;
+       void *addr = page_address(page) + poff;
        dma_addr_t iovp;
        dma_addr_t offset;
        u64 *pdir_start;
@@ -990,7 +993,14 @@ sba_map_single_attrs(struct device *dev, void *addr, size_t size, int dir,
 #endif
        return SBA_IOVA(ioc, iovp, offset);
 }
-EXPORT_SYMBOL(sba_map_single_attrs);
+
+static dma_addr_t sba_map_single_attrs(struct device *dev, void *addr,
+                                      size_t size, enum dma_data_direction dir,
+                                      struct dma_attrs *attrs)
+{
+       return sba_map_page(dev, virt_to_page(addr),
+                           (unsigned long)addr & ~PAGE_MASK, size, dir, attrs);
+}
 
 #ifdef ENABLE_MARK_CLEAN
 static SBA_INLINE void
@@ -1026,8 +1036,8 @@ sba_mark_clean(struct ioc *ioc, dma_addr_t iova, size_t size)
  *
  * See Documentation/DMA-mapping.txt
  */
-void sba_unmap_single_attrs(struct device *dev, dma_addr_t iova, size_t size,
-                           int dir, struct dma_attrs *attrs)
+static void sba_unmap_page(struct device *dev, dma_addr_t iova, size_t size,
+                          enum dma_data_direction dir, struct dma_attrs *attrs)
 {
        struct ioc *ioc;
 #if DELAYED_RESOURCE_CNT > 0
@@ -1094,7 +1104,12 @@ void sba_unmap_single_attrs(struct device *dev, dma_addr_t iova, size_t size,
        spin_unlock_irqrestore(&ioc->res_lock, flags);
 #endif /* DELAYED_RESOURCE_CNT == 0 */
 }
-EXPORT_SYMBOL(sba_unmap_single_attrs);
+
+void sba_unmap_single_attrs(struct device *dev, dma_addr_t iova, size_t size,
+                           enum dma_data_direction dir, struct dma_attrs *attrs)
+{
+       sba_unmap_page(dev, iova, size, dir, attrs);
+}
 
 /**
  * sba_alloc_coherent - allocate/map shared mem for DMA
@@ -1104,7 +1119,7 @@ EXPORT_SYMBOL(sba_unmap_single_attrs);
  *
  * See Documentation/DMA-mapping.txt
  */
-void *
+static void *
 sba_alloc_coherent (struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flags)
 {
        struct ioc *ioc;
@@ -1167,7 +1182,8 @@ sba_alloc_coherent (struct device *dev, size_t size, dma_addr_t *dma_handle, gfp
  *
  * See Documentation/DMA-mapping.txt
  */
-void sba_free_coherent (struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle)
+static void sba_free_coherent (struct device *dev, size_t size, void *vaddr,
+                              dma_addr_t dma_handle)
 {
        sba_unmap_single_attrs(dev, dma_handle, size, 0, NULL);
        free_pages((unsigned long) vaddr, get_order(size));
@@ -1422,8 +1438,9 @@ sba_coalesce_chunks(struct ioc *ioc, struct device *dev,
  *
  * See Documentation/DMA-mapping.txt
  */
-int sba_map_sg_attrs(struct device *dev, struct scatterlist *sglist, int nents,
-                    int dir, struct dma_attrs *attrs)
+static int sba_map_sg_attrs(struct device *dev, struct scatterlist *sglist,
+                           int nents, enum dma_data_direction dir,
+                           struct dma_attrs *attrs)
 {
        struct ioc *ioc;
        int coalesced, filled = 0;
@@ -1502,7 +1519,6 @@ int sba_map_sg_attrs(struct device *dev, struct scatterlist *sglist, int nents,
 
        return filled;
 }
-EXPORT_SYMBOL(sba_map_sg_attrs);
 
 /**
  * sba_unmap_sg_attrs - unmap Scatter/Gather list
@@ -1514,8 +1530,9 @@ EXPORT_SYMBOL(sba_map_sg_attrs);
  *
  * See Documentation/DMA-mapping.txt
  */
-void sba_unmap_sg_attrs(struct device *dev, struct scatterlist *sglist,
-                       int nents, int dir, struct dma_attrs *attrs)
+static void sba_unmap_sg_attrs(struct device *dev, struct scatterlist *sglist,
+                              int nents, enum dma_data_direction dir,
+                              struct dma_attrs *attrs)
 {
 #ifdef ASSERT_PDIR_SANITY
        struct ioc *ioc;
@@ -1551,7 +1568,6 @@ void sba_unmap_sg_attrs(struct device *dev, struct scatterlist *sglist,
 #endif
 
 }
-EXPORT_SYMBOL(sba_unmap_sg_attrs);
 
 /**************************************************************
 *
@@ -2064,6 +2080,8 @@ static struct acpi_driver acpi_sba_ioc_driver = {
        },
 };
 
+extern struct dma_map_ops swiotlb_dma_ops;
+
 static int __init
 sba_init(void)
 {
@@ -2077,6 +2095,7 @@ sba_init(void)
         * a successful kdump kernel boot is to use the swiotlb.
         */
        if (is_kdump_kernel()) {
+               dma_ops = &swiotlb_dma_ops;
                if (swiotlb_late_init_with_default_size(64 * (1<<20)) != 0)
                        panic("Unable to initialize software I/O TLB:"
                                  " Try machvec=dig boot option");
@@ -2092,6 +2111,7 @@ sba_init(void)
                 * If we didn't find something sba_iommu can claim, we
                 * need to setup the swiotlb and switch to the dig machvec.
                 */
+               dma_ops = &swiotlb_dma_ops;
                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");
@@ -2138,15 +2158,13 @@ nosbagart(char *str)
        return 1;
 }
 
-int
-sba_dma_supported (struct device *dev, u64 mask)
+static int sba_dma_supported (struct device *dev, u64 mask)
 {
        /* make sure it's at least 32bit capable */
        return ((mask & 0xFFFFFFFFUL) == 0xFFFFFFFFUL);
 }
 
-int
-sba_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+static int sba_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
 {
        return 0;
 }
@@ -2176,7 +2194,22 @@ sba_page_override(char *str)
 
 __setup("sbapagesize=",sba_page_override);
 
-EXPORT_SYMBOL(sba_dma_mapping_error);
-EXPORT_SYMBOL(sba_dma_supported);
-EXPORT_SYMBOL(sba_alloc_coherent);
-EXPORT_SYMBOL(sba_free_coherent);
+struct dma_map_ops sba_dma_ops = {
+       .alloc_coherent         = sba_alloc_coherent,
+       .free_coherent          = 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,
+       .sync_single_for_cpu    = machvec_dma_sync_single,
+       .sync_sg_for_cpu        = machvec_dma_sync_sg,
+       .sync_single_for_device = machvec_dma_sync_single,
+       .sync_sg_for_device     = machvec_dma_sync_sg,
+       .dma_supported          = sba_dma_supported,
+       .mapping_error          = sba_dma_mapping_error,
+};
+
+void sba_dma_init(void)
+{
+       dma_ops = &sba_dma_ops;
+}
index bbab7e2b0fc92f3f546a48fea7095d040975422b..f4d4b1850a7ec0f9ae0ba0257b2d019665412092 100644 (file)
 #include <linux/scatterlist.h>
 #include <asm/swiotlb.h>
 
-struct dma_mapping_ops {
-       int             (*mapping_error)(struct device *dev,
-                                        dma_addr_t dma_addr);
-       void*           (*alloc_coherent)(struct device *dev, size_t size,
-                               dma_addr_t *dma_handle, gfp_t gfp);
-       void            (*free_coherent)(struct device *dev, size_t size,
-                               void *vaddr, dma_addr_t dma_handle);
-       dma_addr_t      (*map_single)(struct device *hwdev, unsigned long ptr,
-                               size_t size, int direction);
-       void            (*unmap_single)(struct device *dev, dma_addr_t addr,
-                               size_t size, int direction);
-       void            (*sync_single_for_cpu)(struct device *hwdev,
-                               dma_addr_t dma_handle, size_t size,
-                               int direction);
-       void            (*sync_single_for_device)(struct device *hwdev,
-                               dma_addr_t dma_handle, size_t size,
-                               int direction);
-       void            (*sync_single_range_for_cpu)(struct device *hwdev,
-                               dma_addr_t dma_handle, unsigned long offset,
-                               size_t size, int direction);
-       void            (*sync_single_range_for_device)(struct device *hwdev,
-                               dma_addr_t dma_handle, unsigned long offset,
-                               size_t size, int direction);
-       void            (*sync_sg_for_cpu)(struct device *hwdev,
-                               struct scatterlist *sg, int nelems,
-                               int direction);
-       void            (*sync_sg_for_device)(struct device *hwdev,
-                               struct scatterlist *sg, int nelems,
-                               int direction);
-       int             (*map_sg)(struct device *hwdev, struct scatterlist *sg,
-                               int nents, int direction);
-       void            (*unmap_sg)(struct device *hwdev,
-                               struct scatterlist *sg, int nents,
-                               int direction);
-       int             (*dma_supported_op)(struct device *hwdev, u64 mask);
-       int             is_phys;
-};
-
-extern struct dma_mapping_ops *dma_ops;
+extern struct dma_map_ops *dma_ops;
 extern struct ia64_machine_vector ia64_mv;
 extern void set_iommu_machvec(void);
 
-#define dma_alloc_coherent(dev, size, handle, gfp)     \
-       platform_dma_alloc_coherent(dev, size, handle, (gfp) | GFP_DMA)
+extern void machvec_dma_sync_single(struct device *, dma_addr_t, size_t,
+                                   enum dma_data_direction);
+extern void machvec_dma_sync_sg(struct device *, struct scatterlist *, int,
+                               enum dma_data_direction);
 
-/* coherent mem. is cheap */
-static inline void *
-dma_alloc_noncoherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
-                     gfp_t flag)
+static inline void *dma_alloc_coherent(struct device *dev, size_t size,
+                                      dma_addr_t *daddr, gfp_t gfp)
 {
-       return dma_alloc_coherent(dev, size, dma_handle, flag);
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       return ops->alloc_coherent(dev, size, daddr, gfp | GFP_DMA);
 }
-#define dma_free_coherent      platform_dma_free_coherent
-static inline void
-dma_free_noncoherent(struct device *dev, size_t size, void *cpu_addr,
-                    dma_addr_t dma_handle)
+
+static inline void dma_free_coherent(struct device *dev, size_t size,
+                                    void *caddr, dma_addr_t daddr)
+{
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       ops->free_coherent(dev, size, caddr, daddr);
+}
+
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+
+static inline dma_addr_t dma_map_single_attrs(struct device *dev,
+                                             void *caddr, size_t size,
+                                             enum dma_data_direction dir,
+                                             struct dma_attrs *attrs)
+{
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       return ops->map_page(dev, virt_to_page(caddr),
+                            (unsigned long)caddr & ~PAGE_MASK, size,
+                            dir, attrs);
+}
+
+static inline void dma_unmap_single_attrs(struct device *dev, dma_addr_t daddr,
+                                         size_t size,
+                                         enum dma_data_direction dir,
+                                         struct dma_attrs *attrs)
+{
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       ops->unmap_page(dev, daddr, size, dir, attrs);
+}
+
+#define dma_map_single(d, a, s, r) dma_map_single_attrs(d, a, s, r, NULL)
+#define dma_unmap_single(d, a, s, r) dma_unmap_single_attrs(d, a, s, r, NULL)
+
+static inline int dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
+                                  int nents, enum dma_data_direction dir,
+                                  struct dma_attrs *attrs)
+{
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       return ops->map_sg(dev, sgl, nents, dir, attrs);
+}
+
+static inline void dma_unmap_sg_attrs(struct device *dev,
+                                     struct scatterlist *sgl, int nents,
+                                     enum dma_data_direction dir,
+                                     struct dma_attrs *attrs)
+{
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       ops->unmap_sg(dev, sgl, nents, dir, attrs);
+}
+
+#define dma_map_sg(d, s, n, r) dma_map_sg_attrs(d, s, n, r, NULL)
+#define dma_unmap_sg(d, s, n, r) dma_unmap_sg_attrs(d, s, n, r, NULL)
+
+static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t daddr,
+                                          size_t size,
+                                          enum dma_data_direction dir)
 {
-       dma_free_coherent(dev, size, cpu_addr, dma_handle);
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       ops->sync_single_for_cpu(dev, daddr, size, dir);
 }
-#define dma_map_single_attrs   platform_dma_map_single_attrs
-static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
-                                       size_t size, int dir)
+
+static inline void dma_sync_sg_for_cpu(struct device *dev,
+                                      struct scatterlist *sgl,
+                                      int nents, enum dma_data_direction dir)
 {
-       return dma_map_single_attrs(dev, cpu_addr, size, dir, NULL);
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       ops->sync_sg_for_cpu(dev, sgl, nents, dir);
 }
-#define dma_map_sg_attrs       platform_dma_map_sg_attrs
-static inline int dma_map_sg(struct device *dev, struct scatterlist *sgl,
-                            int nents, int dir)
+
+static inline void dma_sync_single_for_device(struct device *dev,
+                                             dma_addr_t daddr,
+                                             size_t size,
+                                             enum dma_data_direction dir)
 {
-       return dma_map_sg_attrs(dev, sgl, nents, dir, NULL);
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       ops->sync_single_for_device(dev, daddr, size, dir);
 }
-#define dma_unmap_single_attrs platform_dma_unmap_single_attrs
-static inline void dma_unmap_single(struct device *dev, dma_addr_t cpu_addr,
-                                   size_t size, int dir)
+
+static inline void dma_sync_sg_for_device(struct device *dev,
+                                         struct scatterlist *sgl,
+                                         int nents,
+                                         enum dma_data_direction dir)
 {
-       return dma_unmap_single_attrs(dev, cpu_addr, size, dir, NULL);
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       ops->sync_sg_for_device(dev, sgl, nents, dir);
 }
-#define dma_unmap_sg_attrs     platform_dma_unmap_sg_attrs
-static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sgl,
-                               int nents, int dir)
+
+static inline int dma_mapping_error(struct device *dev, dma_addr_t daddr)
+{
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       return ops->mapping_error(dev, daddr);
+}
+
+static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
+                                     size_t offset, size_t size,
+                                     enum dma_data_direction dir)
 {
-       return dma_unmap_sg_attrs(dev, sgl, nents, dir, NULL);
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       return ops->map_page(dev, page, offset, size, dir, NULL);
 }
-#define dma_sync_single_for_cpu        platform_dma_sync_single_for_cpu
-#define dma_sync_sg_for_cpu    platform_dma_sync_sg_for_cpu
-#define dma_sync_single_for_device platform_dma_sync_single_for_device
-#define dma_sync_sg_for_device platform_dma_sync_sg_for_device
-#define dma_mapping_error      platform_dma_mapping_error
 
-#define dma_map_page(dev, pg, off, size, dir)                          \
-       dma_map_single(dev, page_address(pg) + (off), (size), (dir))
-#define dma_unmap_page(dev, dma_addr, size, dir)                       \
-       dma_unmap_single(dev, dma_addr, size, dir)
+static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
+                                 size_t size, enum dma_data_direction dir)
+{
+       dma_unmap_single(dev, addr, size, dir);
+}
 
 /*
  * Rest of this file is part of the "Advanced DMA API".  Use at your own risk.
@@ -113,7 +142,11 @@ static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sgl,
 #define dma_sync_single_range_for_device(dev, dma_handle, offset, size, dir)   \
        dma_sync_single_for_device(dev, dma_handle, size, dir)
 
-#define dma_supported          platform_dma_supported
+static inline int dma_supported(struct device *dev, u64 mask)
+{
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
+       return ops->dma_supported(dev, mask);
+}
 
 static inline int
 dma_set_mask (struct device *dev, u64 mask)
@@ -139,11 +172,4 @@ dma_cache_sync (struct device *dev, void *vaddr, size_t size,
 
 #define dma_is_consistent(d, h)        (1)     /* all we do is coherent memory... */
 
-static inline struct dma_mapping_ops *get_dma_ops(struct device *dev)
-{
-       return dma_ops;
-}
-
-
-
 #endif /* _ASM_IA64_DMA_MAPPING_H */
index 59c17e446683c5c12decbd3cad96f7b4a3373e7c..22a75fb55adb42b14e6f7c5ffdd2434ee883c84a 100644 (file)
@@ -11,7 +11,6 @@
 #define _ASM_IA64_MACHVEC_H
 
 #include <linux/types.h>
-#include <linux/swiotlb.h>
 
 /* forward declarations: */
 struct device;
@@ -45,23 +44,7 @@ typedef void ia64_mv_kernel_launch_event_t(void);
 
 /* DMA-mapping interface: */
 typedef void ia64_mv_dma_init (void);
-typedef void *ia64_mv_dma_alloc_coherent (struct device *, size_t, dma_addr_t *, gfp_t);
-typedef void ia64_mv_dma_free_coherent (struct device *, size_t, void *, dma_addr_t);
-typedef dma_addr_t ia64_mv_dma_map_single (struct device *, void *, size_t, int);
-typedef void ia64_mv_dma_unmap_single (struct device *, dma_addr_t, size_t, int);
-typedef int ia64_mv_dma_map_sg (struct device *, struct scatterlist *, int, int);
-typedef void ia64_mv_dma_unmap_sg (struct device *, struct scatterlist *, int, int);
-typedef void ia64_mv_dma_sync_single_for_cpu (struct device *, dma_addr_t, size_t, int);
-typedef void ia64_mv_dma_sync_sg_for_cpu (struct device *, struct scatterlist *, int, int);
-typedef void ia64_mv_dma_sync_single_for_device (struct device *, dma_addr_t, size_t, int);
-typedef void ia64_mv_dma_sync_sg_for_device (struct device *, struct scatterlist *, int, int);
-typedef int ia64_mv_dma_mapping_error(struct device *, dma_addr_t dma_addr);
-typedef int ia64_mv_dma_supported (struct device *, u64);
-
-typedef dma_addr_t ia64_mv_dma_map_single_attrs (struct device *, void *, size_t, int, struct dma_attrs *);
-typedef void ia64_mv_dma_unmap_single_attrs (struct device *, dma_addr_t, size_t, int, struct dma_attrs *);
-typedef int ia64_mv_dma_map_sg_attrs (struct device *, struct scatterlist *, int, int, struct dma_attrs *);
-typedef void ia64_mv_dma_unmap_sg_attrs (struct device *, struct scatterlist *, int, int, struct dma_attrs *);
+typedef struct dma_map_ops *ia64_mv_dma_get_ops(struct device *);
 
 /*
  * WARNING: The legacy I/O space is _architected_.  Platforms are
@@ -113,8 +96,6 @@ machvec_noop_bus (struct pci_bus *bus)
 
 extern void machvec_setup (char **);
 extern void machvec_timer_interrupt (int, void *);
-extern void machvec_dma_sync_single (struct device *, dma_addr_t, size_t, int);
-extern void machvec_dma_sync_sg (struct device *, struct scatterlist *, int, int);
 extern void machvec_tlb_migrate_finish (struct mm_struct *);
 
 # if defined (CONFIG_IA64_HP_SIM)
@@ -147,18 +128,7 @@ extern void machvec_tlb_migrate_finish (struct mm_struct *);
 #  define platform_global_tlb_purge    ia64_mv.global_tlb_purge
 #  define platform_tlb_migrate_finish  ia64_mv.tlb_migrate_finish
 #  define platform_dma_init            ia64_mv.dma_init
-#  define platform_dma_alloc_coherent  ia64_mv.dma_alloc_coherent
-#  define platform_dma_free_coherent   ia64_mv.dma_free_coherent
-#  define platform_dma_map_single_attrs        ia64_mv.dma_map_single_attrs
-#  define platform_dma_unmap_single_attrs      ia64_mv.dma_unmap_single_attrs
-#  define platform_dma_map_sg_attrs    ia64_mv.dma_map_sg_attrs
-#  define platform_dma_unmap_sg_attrs  ia64_mv.dma_unmap_sg_attrs
-#  define platform_dma_sync_single_for_cpu ia64_mv.dma_sync_single_for_cpu
-#  define platform_dma_sync_sg_for_cpu ia64_mv.dma_sync_sg_for_cpu
-#  define platform_dma_sync_single_for_device ia64_mv.dma_sync_single_for_device
-#  define platform_dma_sync_sg_for_device ia64_mv.dma_sync_sg_for_device
-#  define platform_dma_mapping_error           ia64_mv.dma_mapping_error
-#  define platform_dma_supported       ia64_mv.dma_supported
+#  define platform_dma_get_ops         ia64_mv.dma_get_ops
 #  define platform_irq_to_vector       ia64_mv.irq_to_vector
 #  define platform_local_vector_to_irq ia64_mv.local_vector_to_irq
 #  define platform_pci_get_legacy_mem  ia64_mv.pci_get_legacy_mem
@@ -201,18 +171,7 @@ struct ia64_machine_vector {
        ia64_mv_global_tlb_purge_t *global_tlb_purge;
        ia64_mv_tlb_migrate_finish_t *tlb_migrate_finish;
        ia64_mv_dma_init *dma_init;
-       ia64_mv_dma_alloc_coherent *dma_alloc_coherent;
-       ia64_mv_dma_free_coherent *dma_free_coherent;
-       ia64_mv_dma_map_single_attrs *dma_map_single_attrs;
-       ia64_mv_dma_unmap_single_attrs *dma_unmap_single_attrs;
-       ia64_mv_dma_map_sg_attrs *dma_map_sg_attrs;
-       ia64_mv_dma_unmap_sg_attrs *dma_unmap_sg_attrs;
-       ia64_mv_dma_sync_single_for_cpu *dma_sync_single_for_cpu;
-       ia64_mv_dma_sync_sg_for_cpu *dma_sync_sg_for_cpu;
-       ia64_mv_dma_sync_single_for_device *dma_sync_single_for_device;
-       ia64_mv_dma_sync_sg_for_device *dma_sync_sg_for_device;
-       ia64_mv_dma_mapping_error *dma_mapping_error;
-       ia64_mv_dma_supported *dma_supported;
+       ia64_mv_dma_get_ops *dma_get_ops;
        ia64_mv_irq_to_vector *irq_to_vector;
        ia64_mv_local_vector_to_irq *local_vector_to_irq;
        ia64_mv_pci_get_legacy_mem_t *pci_get_legacy_mem;
@@ -251,18 +210,7 @@ struct ia64_machine_vector {
        platform_global_tlb_purge,              \
        platform_tlb_migrate_finish,            \
        platform_dma_init,                      \
-       platform_dma_alloc_coherent,            \
-       platform_dma_free_coherent,             \
-       platform_dma_map_single_attrs,          \
-       platform_dma_unmap_single_attrs,        \
-       platform_dma_map_sg_attrs,              \
-       platform_dma_unmap_sg_attrs,            \
-       platform_dma_sync_single_for_cpu,       \
-       platform_dma_sync_sg_for_cpu,           \
-       platform_dma_sync_single_for_device,    \
-       platform_dma_sync_sg_for_device,        \
-       platform_dma_mapping_error,                     \
-       platform_dma_supported,                 \
+       platform_dma_get_ops,                   \
        platform_irq_to_vector,                 \
        platform_local_vector_to_irq,           \
        platform_pci_get_legacy_mem,            \
@@ -298,6 +246,9 @@ extern void machvec_init_from_cmdline(const char *cmdline);
 #  error Unknown configuration.  Update arch/ia64/include/asm/machvec.h.
 # endif /* CONFIG_IA64_GENERIC */
 
+extern void swiotlb_dma_init(void);
+extern struct dma_map_ops *dma_get_ops(struct device *);
+
 /*
  * Define default versions so we can extend machvec for new platforms without having
  * to update the machvec files for all existing platforms.
@@ -328,43 +279,10 @@ extern void machvec_init_from_cmdline(const char *cmdline);
 # define platform_kernel_launch_event  machvec_noop
 #endif
 #ifndef platform_dma_init
-# define platform_dma_init             swiotlb_init
-#endif
-#ifndef platform_dma_alloc_coherent
-# define platform_dma_alloc_coherent   swiotlb_alloc_coherent
-#endif
-#ifndef platform_dma_free_coherent
-# define platform_dma_free_coherent    swiotlb_free_coherent
-#endif
-#ifndef platform_dma_map_single_attrs
-# define platform_dma_map_single_attrs swiotlb_map_single_attrs
-#endif
-#ifndef platform_dma_unmap_single_attrs
-# define platform_dma_unmap_single_attrs       swiotlb_unmap_single_attrs
-#endif
-#ifndef platform_dma_map_sg_attrs
-# define platform_dma_map_sg_attrs     swiotlb_map_sg_attrs
-#endif
-#ifndef platform_dma_unmap_sg_attrs
-# define platform_dma_unmap_sg_attrs   swiotlb_unmap_sg_attrs
-#endif
-#ifndef platform_dma_sync_single_for_cpu
-# define platform_dma_sync_single_for_cpu      swiotlb_sync_single_for_cpu
-#endif
-#ifndef platform_dma_sync_sg_for_cpu
-# define platform_dma_sync_sg_for_cpu          swiotlb_sync_sg_for_cpu
-#endif
-#ifndef platform_dma_sync_single_for_device
-# define platform_dma_sync_single_for_device   swiotlb_sync_single_for_device
-#endif
-#ifndef platform_dma_sync_sg_for_device
-# define platform_dma_sync_sg_for_device       swiotlb_sync_sg_for_device
-#endif
-#ifndef platform_dma_mapping_error
-# define platform_dma_mapping_error            swiotlb_dma_mapping_error
+# define platform_dma_init             swiotlb_dma_init
 #endif
-#ifndef platform_dma_supported
-# define  platform_dma_supported       swiotlb_dma_supported
+#ifndef platform_dma_get_ops
+# define platform_dma_get_ops          dma_get_ops
 #endif
 #ifndef platform_irq_to_vector
 # define platform_irq_to_vector                __ia64_irq_to_vector
index 3400b561e711b63820429702b8710025c98b35cc..6ab1de5c45efe74b9e86e542f6b066578e2aa751 100644 (file)
@@ -2,14 +2,6 @@
 #define _ASM_IA64_MACHVEC_DIG_VTD_h
 
 extern ia64_mv_setup_t                 dig_setup;
-extern ia64_mv_dma_alloc_coherent      vtd_alloc_coherent;
-extern ia64_mv_dma_free_coherent       vtd_free_coherent;
-extern ia64_mv_dma_map_single_attrs    vtd_map_single_attrs;
-extern ia64_mv_dma_unmap_single_attrs  vtd_unmap_single_attrs;
-extern ia64_mv_dma_map_sg_attrs                vtd_map_sg_attrs;
-extern ia64_mv_dma_unmap_sg_attrs      vtd_unmap_sg_attrs;
-extern ia64_mv_dma_supported           iommu_dma_supported;
-extern ia64_mv_dma_mapping_error       vtd_dma_mapping_error;
 extern ia64_mv_dma_init                        pci_iommu_alloc;
 
 /*
@@ -22,17 +14,5 @@ extern ia64_mv_dma_init                      pci_iommu_alloc;
 #define platform_name                          "dig_vtd"
 #define platform_setup                         dig_setup
 #define platform_dma_init                      pci_iommu_alloc
-#define platform_dma_alloc_coherent            vtd_alloc_coherent
-#define platform_dma_free_coherent             vtd_free_coherent
-#define platform_dma_map_single_attrs          vtd_map_single_attrs
-#define platform_dma_unmap_single_attrs                vtd_unmap_single_attrs
-#define platform_dma_map_sg_attrs              vtd_map_sg_attrs
-#define platform_dma_unmap_sg_attrs            vtd_unmap_sg_attrs
-#define platform_dma_sync_single_for_cpu       machvec_dma_sync_single
-#define platform_dma_sync_sg_for_cpu           machvec_dma_sync_sg
-#define platform_dma_sync_single_for_device    machvec_dma_sync_single
-#define platform_dma_sync_sg_for_device                machvec_dma_sync_sg
-#define platform_dma_supported                 iommu_dma_supported
-#define platform_dma_mapping_error             vtd_dma_mapping_error
 
 #endif /* _ASM_IA64_MACHVEC_DIG_VTD_h */
index 2f57f5144b9fbc55363734d0dbf0920bac497fa6..3bd83d78a412047099be119a2fa1b3094d767f47 100644 (file)
@@ -2,14 +2,7 @@
 #define _ASM_IA64_MACHVEC_HPZX1_h
 
 extern ia64_mv_setup_t                 dig_setup;
-extern ia64_mv_dma_alloc_coherent      sba_alloc_coherent;
-extern ia64_mv_dma_free_coherent       sba_free_coherent;
-extern ia64_mv_dma_map_single_attrs    sba_map_single_attrs;
-extern ia64_mv_dma_unmap_single_attrs  sba_unmap_single_attrs;
-extern ia64_mv_dma_map_sg_attrs                sba_map_sg_attrs;
-extern ia64_mv_dma_unmap_sg_attrs      sba_unmap_sg_attrs;
-extern ia64_mv_dma_supported           sba_dma_supported;
-extern ia64_mv_dma_mapping_error       sba_dma_mapping_error;
+extern ia64_mv_dma_init                        sba_dma_init;
 
 /*
  * This stuff has dual use!
@@ -20,18 +13,6 @@ extern ia64_mv_dma_mapping_error     sba_dma_mapping_error;
  */
 #define platform_name                          "hpzx1"
 #define platform_setup                         dig_setup
-#define platform_dma_init                      machvec_noop
-#define platform_dma_alloc_coherent            sba_alloc_coherent
-#define platform_dma_free_coherent             sba_free_coherent
-#define platform_dma_map_single_attrs          sba_map_single_attrs
-#define platform_dma_unmap_single_attrs                sba_unmap_single_attrs
-#define platform_dma_map_sg_attrs              sba_map_sg_attrs
-#define platform_dma_unmap_sg_attrs            sba_unmap_sg_attrs
-#define platform_dma_sync_single_for_cpu       machvec_dma_sync_single
-#define platform_dma_sync_sg_for_cpu           machvec_dma_sync_sg
-#define platform_dma_sync_single_for_device    machvec_dma_sync_single
-#define platform_dma_sync_sg_for_device                machvec_dma_sync_sg
-#define platform_dma_supported                 sba_dma_supported
-#define platform_dma_mapping_error             sba_dma_mapping_error
+#define platform_dma_init                      sba_dma_init
 
 #endif /* _ASM_IA64_MACHVEC_HPZX1_h */
index a842cdda827bd8203f95d4e367e1a8eed47d8764..1091ac39740c6c407c35bb43e8d511eea2aafb02 100644 (file)
@@ -2,18 +2,7 @@
 #define _ASM_IA64_MACHVEC_HPZX1_SWIOTLB_h
 
 extern ia64_mv_setup_t                         dig_setup;
-extern ia64_mv_dma_alloc_coherent              hwsw_alloc_coherent;
-extern ia64_mv_dma_free_coherent               hwsw_free_coherent;
-extern ia64_mv_dma_map_single_attrs            hwsw_map_single_attrs;
-extern ia64_mv_dma_unmap_single_attrs          hwsw_unmap_single_attrs;
-extern ia64_mv_dma_map_sg_attrs                        hwsw_map_sg_attrs;
-extern ia64_mv_dma_unmap_sg_attrs              hwsw_unmap_sg_attrs;
-extern ia64_mv_dma_supported                   hwsw_dma_supported;
-extern ia64_mv_dma_mapping_error               hwsw_dma_mapping_error;
-extern ia64_mv_dma_sync_single_for_cpu         hwsw_sync_single_for_cpu;
-extern ia64_mv_dma_sync_sg_for_cpu             hwsw_sync_sg_for_cpu;
-extern ia64_mv_dma_sync_single_for_device      hwsw_sync_single_for_device;
-extern ia64_mv_dma_sync_sg_for_device          hwsw_sync_sg_for_device;
+extern ia64_mv_dma_get_ops                     hwsw_dma_get_ops;
 
 /*
  * This stuff has dual use!
@@ -23,20 +12,8 @@ extern ia64_mv_dma_sync_sg_for_device                hwsw_sync_sg_for_device;
  * the macros are used directly.
  */
 #define platform_name                          "hpzx1_swiotlb"
-
 #define platform_setup                         dig_setup
 #define platform_dma_init                      machvec_noop
-#define platform_dma_alloc_coherent            hwsw_alloc_coherent
-#define platform_dma_free_coherent             hwsw_free_coherent
-#define platform_dma_map_single_attrs          hwsw_map_single_attrs
-#define platform_dma_unmap_single_attrs                hwsw_unmap_single_attrs
-#define platform_dma_map_sg_attrs              hwsw_map_sg_attrs
-#define platform_dma_unmap_sg_attrs            hwsw_unmap_sg_attrs
-#define platform_dma_supported                 hwsw_dma_supported
-#define platform_dma_mapping_error             hwsw_dma_mapping_error
-#define platform_dma_sync_single_for_cpu       hwsw_sync_single_for_cpu
-#define platform_dma_sync_sg_for_cpu           hwsw_sync_sg_for_cpu
-#define platform_dma_sync_single_for_device    hwsw_sync_single_for_device
-#define platform_dma_sync_sg_for_device                hwsw_sync_sg_for_device
+#define platform_dma_get_ops                   hwsw_dma_get_ops
 
 #endif /* _ASM_IA64_MACHVEC_HPZX1_SWIOTLB_h */
index 781308ea7b88baad9f1c6f58eeb039c4fc60f048..afd029b4797ec84587595f902defe076df45cc6e 100644 (file)
@@ -55,18 +55,7 @@ extern ia64_mv_readb_t __sn_readb_relaxed;
 extern ia64_mv_readw_t __sn_readw_relaxed;
 extern ia64_mv_readl_t __sn_readl_relaxed;
 extern ia64_mv_readq_t __sn_readq_relaxed;
-extern ia64_mv_dma_alloc_coherent      sn_dma_alloc_coherent;
-extern ia64_mv_dma_free_coherent       sn_dma_free_coherent;
-extern ia64_mv_dma_map_single_attrs    sn_dma_map_single_attrs;
-extern ia64_mv_dma_unmap_single_attrs  sn_dma_unmap_single_attrs;
-extern ia64_mv_dma_map_sg_attrs                sn_dma_map_sg_attrs;
-extern ia64_mv_dma_unmap_sg_attrs      sn_dma_unmap_sg_attrs;
-extern ia64_mv_dma_sync_single_for_cpu sn_dma_sync_single_for_cpu;
-extern ia64_mv_dma_sync_sg_for_cpu     sn_dma_sync_sg_for_cpu;
-extern ia64_mv_dma_sync_single_for_device sn_dma_sync_single_for_device;
-extern ia64_mv_dma_sync_sg_for_device  sn_dma_sync_sg_for_device;
-extern ia64_mv_dma_mapping_error       sn_dma_mapping_error;
-extern ia64_mv_dma_supported           sn_dma_supported;
+extern ia64_mv_dma_init                        sn_dma_init;
 extern ia64_mv_migrate_t               sn_migrate;
 extern ia64_mv_kernel_launch_event_t   sn_kernel_launch_event;
 extern ia64_mv_setup_msi_irq_t         sn_setup_msi_irq;
@@ -110,19 +99,7 @@ extern ia64_mv_pci_fixup_bus_t              sn_pci_fixup_bus;
 #define platform_pci_get_legacy_mem    sn_pci_get_legacy_mem
 #define platform_pci_legacy_read       sn_pci_legacy_read
 #define platform_pci_legacy_write      sn_pci_legacy_write
-#define platform_dma_init              machvec_noop
-#define platform_dma_alloc_coherent    sn_dma_alloc_coherent
-#define platform_dma_free_coherent     sn_dma_free_coherent
-#define platform_dma_map_single_attrs  sn_dma_map_single_attrs
-#define platform_dma_unmap_single_attrs        sn_dma_unmap_single_attrs
-#define platform_dma_map_sg_attrs      sn_dma_map_sg_attrs
-#define platform_dma_unmap_sg_attrs    sn_dma_unmap_sg_attrs
-#define platform_dma_sync_single_for_cpu sn_dma_sync_single_for_cpu
-#define platform_dma_sync_sg_for_cpu   sn_dma_sync_sg_for_cpu
-#define platform_dma_sync_single_for_device sn_dma_sync_single_for_device
-#define platform_dma_sync_sg_for_device        sn_dma_sync_sg_for_device
-#define platform_dma_mapping_error             sn_dma_mapping_error
-#define platform_dma_supported         sn_dma_supported
+#define platform_dma_init              sn_dma_init
 #define platform_migrate               sn_migrate
 #define platform_kernel_launch_event    sn_kernel_launch_event
 #ifdef CONFIG_PCI_MSI
index c381ea9548924149835ba223f758729dea3ebc03..f2778f2c4fd9307f75c989fc8553364efe1b9253 100644 (file)
@@ -7,7 +7,7 @@ extra-y := head.o init_task.o vmlinux.lds
 obj-y := acpi.o entry.o efi.o efi_stub.o gate-data.o fsys.o ia64_ksyms.o irq.o irq_ia64.o      \
         irq_lsapic.o ivt.o machvec.o pal.o patch.o process.o perfmon.o ptrace.o sal.o          \
         salinfo.o setup.o signal.o sys_ia64.o time.o traps.o unaligned.o \
-        unwind.o mca.o mca_asm.o topology.o
+        unwind.o mca.o mca_asm.o topology.o dma-mapping.o
 
 obj-$(CONFIG_IA64_BRL_EMU)     += brl_emu.o
 obj-$(CONFIG_IA64_GENERIC)     += acpi-ext.o
@@ -43,9 +43,7 @@ ifneq ($(CONFIG_IA64_ESI),)
 obj-y                          += esi_stub.o   # must be in kernel proper
 endif
 obj-$(CONFIG_DMAR)             += pci-dma.o
-ifeq ($(CONFIG_DMAR), y)
 obj-$(CONFIG_SWIOTLB)          += pci-swiotlb.o
-endif
 
 # The gate DSO image is built using a special linker script.
 targets += gate.so gate-syms.o
diff --git a/arch/ia64/kernel/dma-mapping.c b/arch/ia64/kernel/dma-mapping.c
new file mode 100644 (file)
index 0000000..7060e13
--- /dev/null
@@ -0,0 +1,10 @@
+#include <linux/dma-mapping.h>
+
+struct dma_map_ops *dma_ops;
+EXPORT_SYMBOL(dma_ops);
+
+struct dma_map_ops *dma_get_ops(struct device *dev)
+{
+       return dma_ops;
+}
+EXPORT_SYMBOL(dma_get_ops);
index 7ccb228ceedc337e90ae956ad3d1934e66c25bda..d41a40ef80c074575a5f5706011b22a563b4e99d 100644 (file)
@@ -1,5 +1,5 @@
 #include <linux/module.h>
-
+#include <linux/dma-mapping.h>
 #include <asm/machvec.h>
 #include <asm/system.h>
 
@@ -75,14 +75,16 @@ machvec_timer_interrupt (int irq, void *dev_id)
 EXPORT_SYMBOL(machvec_timer_interrupt);
 
 void
-machvec_dma_sync_single (struct device *hwdev, dma_addr_t dma_handle, size_t size, int dir)
+machvec_dma_sync_single(struct device *hwdev, dma_addr_t dma_handle, size_t size,
+                       enum dma_data_direction dir)
 {
        mb();
 }
 EXPORT_SYMBOL(machvec_dma_sync_single);
 
 void
-machvec_dma_sync_sg (struct device *hwdev, struct scatterlist *sg, int n, int dir)
+machvec_dma_sync_sg(struct device *hwdev, struct scatterlist *sg, int n,
+                   enum dma_data_direction dir)
 {
        mb();
 }
index d0ada067a4af52bd83fdac763b862d3b62e2ed13..a647f116a1551d434d300f93bd662cdae51b0cb7 100644 (file)
@@ -32,9 +32,6 @@ int force_iommu __read_mostly = 1;
 int force_iommu __read_mostly;
 #endif
 
-/* Set this to 1 if there is a HW IOMMU in the system */
-int iommu_detected __read_mostly;
-
 /* Dummy device used for NULL arguments (normally ISA). Better would
    be probably a smaller DMA mask, but this is bug-to-bug compatible
    to i386. */
@@ -44,18 +41,7 @@ struct device fallback_dev = {
        .dma_mask = &fallback_dev.coherent_dma_mask,
 };
 
-void __init pci_iommu_alloc(void)
-{
-       /*
-        * The order of these functions is important for
-        * fall-back/fail-over reasons
-        */
-       detect_intel_iommu();
-
-#ifdef CONFIG_SWIOTLB
-       pci_swiotlb_init();
-#endif
-}
+extern struct dma_map_ops intel_dma_ops;
 
 static int __init pci_iommu_init(void)
 {
@@ -79,15 +65,12 @@ iommu_dma_init(void)
        return;
 }
 
-struct dma_mapping_ops *dma_ops;
-EXPORT_SYMBOL(dma_ops);
-
 int iommu_dma_supported(struct device *dev, u64 mask)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(dev);
+       struct dma_map_ops *ops = platform_dma_get_ops(dev);
 
-       if (ops->dma_supported_op)
-               return ops->dma_supported_op(dev, mask);
+       if (ops->dma_supported)
+               return ops->dma_supported(dev, mask);
 
        /* Copied from i386. Doesn't make much sense, because it will
           only work for pci_alloc_coherent.
@@ -116,4 +99,31 @@ int iommu_dma_supported(struct device *dev, u64 mask)
 }
 EXPORT_SYMBOL(iommu_dma_supported);
 
+static int vtd_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+       return 0;
+}
+
+void __init pci_iommu_alloc(void)
+{
+       dma_ops = &intel_dma_ops;
+
+       dma_ops->sync_single_for_cpu = machvec_dma_sync_single;
+       dma_ops->sync_sg_for_cpu = machvec_dma_sync_sg;
+       dma_ops->sync_single_for_device = machvec_dma_sync_single;
+       dma_ops->sync_sg_for_device = machvec_dma_sync_sg;
+       dma_ops->dma_supported = iommu_dma_supported;
+       dma_ops->mapping_error = vtd_dma_mapping_error;
+
+       /*
+        * The order of these functions is important for
+        * fall-back/fail-over reasons
+        */
+       detect_intel_iommu();
+
+#ifdef CONFIG_SWIOTLB
+       pci_swiotlb_init();
+#endif
+}
+
 #endif
index 16c50516dbc11ffb9e0a3042eabef9d4fbd81127..d21dea44e76fa45407526dbb374ef7207fd8ef49 100644 (file)
 int swiotlb __read_mostly;
 EXPORT_SYMBOL(swiotlb);
 
-struct dma_mapping_ops swiotlb_dma_ops = {
-       .mapping_error = swiotlb_dma_mapping_error,
+/* Set this to 1 if there is a HW IOMMU in the system */
+int iommu_detected __read_mostly;
+
+struct dma_map_ops swiotlb_dma_ops = {
        .alloc_coherent = swiotlb_alloc_coherent,
        .free_coherent = swiotlb_free_coherent,
-       .map_single = swiotlb_map_single,
-       .unmap_single = swiotlb_unmap_single,
+       .map_page = swiotlb_map_page,
+       .unmap_page = swiotlb_unmap_page,
+       .map_sg = swiotlb_map_sg_attrs,
+       .unmap_sg = swiotlb_unmap_sg_attrs,
        .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
        .sync_single_for_device = swiotlb_sync_single_for_device,
        .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
        .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
        .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
        .sync_sg_for_device = swiotlb_sync_sg_for_device,
-       .map_sg = swiotlb_map_sg,
-       .unmap_sg = swiotlb_unmap_sg,
-       .dma_supported_op = swiotlb_dma_supported,
+       .dma_supported = swiotlb_dma_supported,
+       .mapping_error = swiotlb_dma_mapping_error,
 };
 
+void __init swiotlb_dma_init(void)
+{
+       dma_ops = &swiotlb_dma_ops;
+       swiotlb_init();
+}
+
 void __init pci_swiotlb_init(void)
 {
        if (!iommu_detected) {
index 53ebb6484495545550e3f07e149bea575db07981..9c788f9cedfd334dad67d0b3c085e116addcabd3 100644 (file)
@@ -10,7 +10,7 @@
  */
 
 #include <linux/module.h>
-#include <linux/dma-attrs.h>
+#include <linux/dma-mapping.h>
 #include <asm/dma.h>
 #include <asm/sn/intr.h>
 #include <asm/sn/pcibus_provider_defs.h>
@@ -31,7 +31,7 @@
  * this function.  Of course, SN only supports devices that have 32 or more
  * address bits when using the PMU.
  */
-int sn_dma_supported(struct device *dev, u64 mask)
+static int sn_dma_supported(struct device *dev, u64 mask)
 {
        BUG_ON(dev->bus != &pci_bus_type);
 
@@ -39,7 +39,6 @@ int sn_dma_supported(struct device *dev, u64 mask)
                return 0;
        return 1;
 }
-EXPORT_SYMBOL(sn_dma_supported);
 
 /**
  * sn_dma_set_mask - set the DMA mask
@@ -75,8 +74,8 @@ EXPORT_SYMBOL(sn_dma_set_mask);
  * queue for a SCSI controller).  See Documentation/DMA-API.txt for
  * more information.
  */
-void *sn_dma_alloc_coherent(struct device *dev, size_t size,
-                           dma_addr_t * dma_handle, gfp_t flags)
+static void *sn_dma_alloc_coherent(struct device *dev, size_t size,
+                                  dma_addr_t * dma_handle, gfp_t flags)
 {
        void *cpuaddr;
        unsigned long phys_addr;
@@ -124,7 +123,6 @@ void *sn_dma_alloc_coherent(struct device *dev, size_t size,
 
        return cpuaddr;
 }
-EXPORT_SYMBOL(sn_dma_alloc_coherent);
 
 /**
  * sn_pci_free_coherent - free memory associated with coherent DMAable region
@@ -136,8 +134,8 @@ EXPORT_SYMBOL(sn_dma_alloc_coherent);
  * Frees the memory allocated by dma_alloc_coherent(), potentially unmapping
  * any associated IOMMU mappings.
  */
-void sn_dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
-                         dma_addr_t dma_handle)
+static void sn_dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
+                                dma_addr_t dma_handle)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
        struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
@@ -147,7 +145,6 @@ void sn_dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
        provider->dma_unmap(pdev, dma_handle, 0);
        free_pages((unsigned long)cpu_addr, get_order(size));
 }
-EXPORT_SYMBOL(sn_dma_free_coherent);
 
 /**
  * sn_dma_map_single_attrs - map a single page for DMA
@@ -173,10 +170,12 @@ EXPORT_SYMBOL(sn_dma_free_coherent);
  * TODO: simplify our interface;
  *       figure out how to save dmamap handle so can use two step.
  */
-dma_addr_t sn_dma_map_single_attrs(struct device *dev, void *cpu_addr,
-                                  size_t size, int direction,
-                                  struct dma_attrs *attrs)
+static dma_addr_t sn_dma_map_page(struct device *dev, struct page *page,
+                                 unsigned long offset, size_t size,
+                                 enum dma_data_direction dir,
+                                 struct dma_attrs *attrs)
 {
+       void *cpu_addr = page_address(page) + offset;
        dma_addr_t dma_addr;
        unsigned long phys_addr;
        struct pci_dev *pdev = to_pci_dev(dev);
@@ -201,7 +200,6 @@ dma_addr_t sn_dma_map_single_attrs(struct device *dev, void *cpu_addr,
        }
        return dma_addr;
 }
-EXPORT_SYMBOL(sn_dma_map_single_attrs);
 
 /**
  * sn_dma_unmap_single_attrs - unamp a DMA mapped page
@@ -215,21 +213,20 @@ EXPORT_SYMBOL(sn_dma_map_single_attrs);
  * by @dma_handle into the coherence domain.  On SN, we're always cache
  * coherent, so we just need to free any ATEs associated with this mapping.
  */
-void sn_dma_unmap_single_attrs(struct device *dev, dma_addr_t dma_addr,
-                              size_t size, int direction,
-                              struct dma_attrs *attrs)
+static void sn_dma_unmap_page(struct device *dev, dma_addr_t dma_addr,
+                             size_t size, enum dma_data_direction dir,
+                             struct dma_attrs *attrs)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
        struct sn_pcibus_provider *provider = SN_PCIDEV_BUSPROVIDER(pdev);
 
        BUG_ON(dev->bus != &pci_bus_type);
 
-       provider->dma_unmap(pdev, dma_addr, direction);
+       provider->dma_unmap(pdev, dma_addr, dir);
 }
-EXPORT_SYMBOL(sn_dma_unmap_single_attrs);
 
 /**
- * sn_dma_unmap_sg_attrs - unmap a DMA scatterlist
+ * sn_dma_unmap_sg - unmap a DMA scatterlist
  * @dev: device to unmap
  * @sg: scatterlist to unmap
  * @nhwentries: number of scatterlist entries
@@ -238,9 +235,9 @@ EXPORT_SYMBOL(sn_dma_unmap_single_attrs);
  *
  * Unmap a set of streaming mode DMA translations.
  */
-void sn_dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sgl,
-                          int nhwentries, int direction,
-                          struct dma_attrs *attrs)
+static void sn_dma_unmap_sg(struct device *dev, struct scatterlist *sgl,
+                           int nhwentries, enum dma_data_direction dir,
+                           struct dma_attrs *attrs)
 {
        int i;
        struct pci_dev *pdev = to_pci_dev(dev);
@@ -250,15 +247,14 @@ void sn_dma_unmap_sg_attrs(struct device *dev, struct scatterlist *sgl,
        BUG_ON(dev->bus != &pci_bus_type);
 
        for_each_sg(sgl, sg, nhwentries, i) {
-               provider->dma_unmap(pdev, sg->dma_address, direction);
+               provider->dma_unmap(pdev, sg->dma_address, dir);
                sg->dma_address = (dma_addr_t) NULL;
                sg->dma_length = 0;
        }
 }
-EXPORT_SYMBOL(sn_dma_unmap_sg_attrs);
 
 /**
- * sn_dma_map_sg_attrs - map a scatterlist for DMA
+ * sn_dma_map_sg - map a scatterlist for DMA
  * @dev: device to map for
  * @sg: scatterlist to map
  * @nhwentries: number of entries
@@ -272,8 +268,9 @@ EXPORT_SYMBOL(sn_dma_unmap_sg_attrs);
  *
  * Maps each entry of @sg for DMA.
  */
-int sn_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
-                       int nhwentries, int direction, struct dma_attrs *attrs)
+static int sn_dma_map_sg(struct device *dev, struct scatterlist *sgl,
+                        int nhwentries, enum dma_data_direction dir,
+                        struct dma_attrs *attrs)
 {
        unsigned long phys_addr;
        struct scatterlist *saved_sg = sgl, *sg;
@@ -310,8 +307,7 @@ int sn_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
                         * Free any successfully allocated entries.
                         */
                        if (i > 0)
-                               sn_dma_unmap_sg_attrs(dev, saved_sg, i,
-                                                     direction, attrs);
+                               sn_dma_unmap_sg(dev, saved_sg, i, dir, attrs);
                        return 0;
                }
 
@@ -320,41 +316,36 @@ int sn_dma_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
 
        return nhwentries;
 }
-EXPORT_SYMBOL(sn_dma_map_sg_attrs);
 
-void sn_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
-                               size_t size, int direction)
+static void sn_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
+                                      size_t size, enum dma_data_direction dir)
 {
        BUG_ON(dev->bus != &pci_bus_type);
 }
-EXPORT_SYMBOL(sn_dma_sync_single_for_cpu);
 
-void sn_dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
-                                  size_t size, int direction)
+static void sn_dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
+                                         size_t size,
+                                         enum dma_data_direction dir)
 {
        BUG_ON(dev->bus != &pci_bus_type);
 }
-EXPORT_SYMBOL(sn_dma_sync_single_for_device);
 
-void sn_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
-                           int nelems, int direction)
+static void sn_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
+                                  int nelems, enum dma_data_direction dir)
 {
        BUG_ON(dev->bus != &pci_bus_type);
 }
-EXPORT_SYMBOL(sn_dma_sync_sg_for_cpu);
 
-void sn_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
-                              int nelems, int direction)
+static void sn_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
+                                     int nelems, enum dma_data_direction dir)
 {
        BUG_ON(dev->bus != &pci_bus_type);
 }
-EXPORT_SYMBOL(sn_dma_sync_sg_for_device);
 
-int sn_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+static int sn_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
 {
        return 0;
 }
-EXPORT_SYMBOL(sn_dma_mapping_error);
 
 char *sn_pci_get_legacy_mem(struct pci_bus *bus)
 {
@@ -465,3 +456,23 @@ int sn_pci_legacy_write(struct pci_bus *bus, u16 port, u32 val, u8 size)
  out:
        return ret;
 }
+
+static struct dma_map_ops sn_dma_ops = {
+       .alloc_coherent         = sn_dma_alloc_coherent,
+       .free_coherent          = sn_dma_free_coherent,
+       .map_page               = sn_dma_map_page,
+       .unmap_page             = sn_dma_unmap_page,
+       .map_sg                 = sn_dma_map_sg,
+       .unmap_sg               = sn_dma_unmap_sg,
+       .sync_single_for_cpu    = sn_dma_sync_single_for_cpu,
+       .sync_sg_for_cpu        = sn_dma_sync_sg_for_cpu,
+       .sync_single_for_device = sn_dma_sync_single_for_device,
+       .sync_sg_for_device     = sn_dma_sync_sg_for_device,
+       .mapping_error          = sn_dma_mapping_error,
+       .dma_supported          = sn_dma_supported,
+};
+
+void sn_dma_init(void)
+{
+       dma_ops = &sn_dma_ops;
+}
index 3c034f48fdb0a12f5a3fefe1499d014b68e6f4a2..4994a20acbcbf66aee788ebcb275eac4a2edd442 100644 (file)
@@ -6,7 +6,7 @@ struct dev_archdata {
        void    *acpi_handle;
 #endif
 #ifdef CONFIG_X86_64
-struct dma_mapping_ops *dma_ops;
+struct dma_map_ops *dma_ops;
 #endif
 #ifdef CONFIG_DMAR
        void *iommu; /* hook for IOMMU specific extension */
index 4035357f5b9d6b830a16b09f39d30e90810aae9e..5a347805a6c7ced5bb6c09e86d79d7663419d48c 100644 (file)
@@ -7,6 +7,7 @@
  */
 
 #include <linux/scatterlist.h>
+#include <linux/dma-attrs.h>
 #include <asm/io.h>
 #include <asm/swiotlb.h>
 #include <asm-generic/dma-coherent.h>
@@ -16,47 +17,9 @@ extern int iommu_merge;
 extern struct device x86_dma_fallback_dev;
 extern int panic_on_overflow;
 
-struct dma_mapping_ops {
-       int             (*mapping_error)(struct device *dev,
-                                        dma_addr_t dma_addr);
-       void*           (*alloc_coherent)(struct device *dev, size_t size,
-                               dma_addr_t *dma_handle, gfp_t gfp);
-       void            (*free_coherent)(struct device *dev, size_t size,
-                               void *vaddr, dma_addr_t dma_handle);
-       dma_addr_t      (*map_single)(struct device *hwdev, phys_addr_t ptr,
-                               size_t size, int direction);
-       void            (*unmap_single)(struct device *dev, dma_addr_t addr,
-                               size_t size, int direction);
-       void            (*sync_single_for_cpu)(struct device *hwdev,
-                               dma_addr_t dma_handle, size_t size,
-                               int direction);
-       void            (*sync_single_for_device)(struct device *hwdev,
-                               dma_addr_t dma_handle, size_t size,
-                               int direction);
-       void            (*sync_single_range_for_cpu)(struct device *hwdev,
-                               dma_addr_t dma_handle, unsigned long offset,
-                               size_t size, int direction);
-       void            (*sync_single_range_for_device)(struct device *hwdev,
-                               dma_addr_t dma_handle, unsigned long offset,
-                               size_t size, int direction);
-       void            (*sync_sg_for_cpu)(struct device *hwdev,
-                               struct scatterlist *sg, int nelems,
-                               int direction);
-       void            (*sync_sg_for_device)(struct device *hwdev,
-                               struct scatterlist *sg, int nelems,
-                               int direction);
-       int             (*map_sg)(struct device *hwdev, struct scatterlist *sg,
-                               int nents, int direction);
-       void            (*unmap_sg)(struct device *hwdev,
-                               struct scatterlist *sg, int nents,
-                               int direction);
-       int             (*dma_supported)(struct device *hwdev, u64 mask);
-       int             is_phys;
-};
-
-extern struct dma_mapping_ops *dma_ops;
-
-static inline struct dma_mapping_ops *get_dma_ops(struct device *dev)
+extern struct dma_map_ops *dma_ops;
+
+static inline struct dma_map_ops *get_dma_ops(struct device *dev)
 {
 #ifdef CONFIG_X86_32
        return dma_ops;
@@ -71,7 +34,7 @@ static inline struct dma_mapping_ops *get_dma_ops(struct device *dev)
 /* Make sure we keep the same behaviour */
 static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(dev);
+       struct dma_map_ops *ops = get_dma_ops(dev);
        if (ops->mapping_error)
                return ops->mapping_error(dev, dma_addr);
 
@@ -90,137 +53,139 @@ extern void *dma_generic_alloc_coherent(struct device *dev, size_t size,
 
 static inline dma_addr_t
 dma_map_single(struct device *hwdev, void *ptr, size_t size,
-              int direction)
+              enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(hwdev);
+       struct dma_map_ops *ops = get_dma_ops(hwdev);
 
-       BUG_ON(!valid_dma_direction(direction));
-       return ops->map_single(hwdev, virt_to_phys(ptr), size, direction);
+       BUG_ON(!valid_dma_direction(dir));
+       return ops->map_page(hwdev, virt_to_page(ptr),
+                            (unsigned long)ptr & ~PAGE_MASK, size,
+                            dir, NULL);
 }
 
 static inline void
 dma_unmap_single(struct device *dev, dma_addr_t addr, size_t size,
-                int direction)
+                enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(dev);
+       struct dma_map_ops *ops = get_dma_ops(dev);
 
-       BUG_ON(!valid_dma_direction(direction));
-       if (ops->unmap_single)
-               ops->unmap_single(dev, addr, size, direction);
+       BUG_ON(!valid_dma_direction(dir));
+       if (ops->unmap_page)
+               ops->unmap_page(dev, addr, size, dir, NULL);
 }
 
 static inline int
 dma_map_sg(struct device *hwdev, struct scatterlist *sg,
-          int nents, int direction)
+          int nents, enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(hwdev);
+       struct dma_map_ops *ops = get_dma_ops(hwdev);
 
-       BUG_ON(!valid_dma_direction(direction));
-       return ops->map_sg(hwdev, sg, nents, direction);
+       BUG_ON(!valid_dma_direction(dir));
+       return ops->map_sg(hwdev, sg, nents, dir, NULL);
 }
 
 static inline void
 dma_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
-            int direction)
+            enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(hwdev);
+       struct dma_map_ops *ops = get_dma_ops(hwdev);
 
-       BUG_ON(!valid_dma_direction(direction));
+       BUG_ON(!valid_dma_direction(dir));
        if (ops->unmap_sg)
-               ops->unmap_sg(hwdev, sg, nents, direction);
+               ops->unmap_sg(hwdev, sg, nents, dir, NULL);
 }
 
 static inline void
 dma_sync_single_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
-                       size_t size, int direction)
+                       size_t size, enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(hwdev);
+       struct dma_map_ops *ops = get_dma_ops(hwdev);
 
-       BUG_ON(!valid_dma_direction(direction));
+       BUG_ON(!valid_dma_direction(dir));
        if (ops->sync_single_for_cpu)
-               ops->sync_single_for_cpu(hwdev, dma_handle, size, direction);
+               ops->sync_single_for_cpu(hwdev, dma_handle, size, dir);
        flush_write_buffers();
 }
 
 static inline void
 dma_sync_single_for_device(struct device *hwdev, dma_addr_t dma_handle,
-                          size_t size, int direction)
+                          size_t size, enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(hwdev);
+       struct dma_map_ops *ops = get_dma_ops(hwdev);
 
-       BUG_ON(!valid_dma_direction(direction));
+       BUG_ON(!valid_dma_direction(dir));
        if (ops->sync_single_for_device)
-               ops->sync_single_for_device(hwdev, dma_handle, size, direction);
+               ops->sync_single_for_device(hwdev, dma_handle, size, dir);
        flush_write_buffers();
 }
 
 static inline void
 dma_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dma_handle,
-                             unsigned long offset, size_t size, int direction)
+                             unsigned long offset, size_t size,
+                             enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(hwdev);
+       struct dma_map_ops *ops = get_dma_ops(hwdev);
 
-       BUG_ON(!valid_dma_direction(direction));
+       BUG_ON(!valid_dma_direction(dir));
        if (ops->sync_single_range_for_cpu)
                ops->sync_single_range_for_cpu(hwdev, dma_handle, offset,
-                                              size, direction);
+                                              size, dir);
        flush_write_buffers();
 }
 
 static inline void
 dma_sync_single_range_for_device(struct device *hwdev, dma_addr_t dma_handle,
                                 unsigned long offset, size_t size,
-                                int direction)
+                                enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(hwdev);
+       struct dma_map_ops *ops = get_dma_ops(hwdev);
 
-       BUG_ON(!valid_dma_direction(direction));
+       BUG_ON(!valid_dma_direction(dir));
        if (ops->sync_single_range_for_device)
                ops->sync_single_range_for_device(hwdev, dma_handle,
-                                                 offset, size, direction);
+                                                 offset, size, dir);
        flush_write_buffers();
 }
 
 static inline void
 dma_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
-                   int nelems, int direction)
+                   int nelems, enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(hwdev);
+       struct dma_map_ops *ops = get_dma_ops(hwdev);
 
-       BUG_ON(!valid_dma_direction(direction));
+       BUG_ON(!valid_dma_direction(dir));
        if (ops->sync_sg_for_cpu)
-               ops->sync_sg_for_cpu(hwdev, sg, nelems, direction);
+               ops->sync_sg_for_cpu(hwdev, sg, nelems, dir);
        flush_write_buffers();
 }
 
 static inline void
 dma_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
-                      int nelems, int direction)
+                      int nelems, enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(hwdev);
+       struct dma_map_ops *ops = get_dma_ops(hwdev);
 
-       BUG_ON(!valid_dma_direction(direction));
+       BUG_ON(!valid_dma_direction(dir));
        if (ops->sync_sg_for_device)
-               ops->sync_sg_for_device(hwdev, sg, nelems, direction);
+               ops->sync_sg_for_device(hwdev, sg, nelems, dir);
 
        flush_write_buffers();
 }
 
 static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
                                      size_t offset, size_t size,
-                                     int direction)
+                                     enum dma_data_direction dir)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(dev);
+       struct dma_map_ops *ops = get_dma_ops(dev);
 
-       BUG_ON(!valid_dma_direction(direction));
-       return ops->map_single(dev, page_to_phys(page) + offset,
-                              size, direction);
+       BUG_ON(!valid_dma_direction(dir));
+       return ops->map_page(dev, page, offset, size, dir, NULL);
 }
 
 static inline void dma_unmap_page(struct device *dev, dma_addr_t addr,
-                                 size_t size, int direction)
+                                 size_t size, enum dma_data_direction dir)
 {
-       dma_unmap_single(dev, addr, size, direction);
+       dma_unmap_single(dev, addr, size, dir);
 }
 
 static inline void
@@ -266,7 +231,7 @@ static inline void *
 dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
                gfp_t gfp)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(dev);
+       struct dma_map_ops *ops = get_dma_ops(dev);
        void *memory;
 
        gfp &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
@@ -292,7 +257,7 @@ dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle,
 static inline void dma_free_coherent(struct device *dev, size_t size,
                                     void *vaddr, dma_addr_t bus)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(dev);
+       struct dma_map_ops *ops = get_dma_ops(dev);
 
        WARN_ON(irqs_disabled());       /* for portability */
 
index a6ee9e6f530f89cc2e86a5607ceff6597c9d1757..af326a2975b5c71d6df7e27954310368a1e36813 100644 (file)
@@ -3,7 +3,7 @@
 
 extern void pci_iommu_shutdown(void);
 extern void no_iommu_init(void);
-extern struct dma_mapping_ops nommu_dma_ops;
+extern struct dma_map_ops nommu_dma_ops;
 extern int force_iommu, no_iommu;
 extern int iommu_detected;
 
index 5113c080f0c442093db228b759946766f59afb06..008e522b9536aab02b1a8f5bbd59c73f86e93287 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/bitops.h>
 #include <linux/debugfs.h>
 #include <linux/scatterlist.h>
+#include <linux/dma-mapping.h>
 #include <linux/iommu-helper.h>
 #ifdef CONFIG_IOMMU_API
 #include <linux/iommu.h>
@@ -1297,8 +1298,10 @@ static void __unmap_single(struct amd_iommu *iommu,
 /*
  * The exported map_single function for dma_ops.
  */
-static dma_addr_t map_single(struct device *dev, phys_addr_t paddr,
-                            size_t size, int dir)
+static dma_addr_t map_page(struct device *dev, struct page *page,
+                          unsigned long offset, size_t size,
+                          enum dma_data_direction dir,
+                          struct dma_attrs *attrs)
 {
        unsigned long flags;
        struct amd_iommu *iommu;
@@ -1306,6 +1309,7 @@ static dma_addr_t map_single(struct device *dev, phys_addr_t paddr,
        u16 devid;
        dma_addr_t addr;
        u64 dma_mask;
+       phys_addr_t paddr = page_to_phys(page) + offset;
 
        INC_STATS_COUNTER(cnt_map_single);
 
@@ -1340,8 +1344,8 @@ out:
 /*
  * The exported unmap_single function for dma_ops.
  */
-static void unmap_single(struct device *dev, dma_addr_t dma_addr,
-                        size_t size, int dir)
+static void unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,
+                      enum dma_data_direction dir, struct dma_attrs *attrs)
 {
        unsigned long flags;
        struct amd_iommu *iommu;
@@ -1390,7 +1394,8 @@ static int map_sg_no_iommu(struct device *dev, struct scatterlist *sglist,
  * lists).
  */
 static int map_sg(struct device *dev, struct scatterlist *sglist,
-                 int nelems, int dir)
+                 int nelems, enum dma_data_direction dir,
+                 struct dma_attrs *attrs)
 {
        unsigned long flags;
        struct amd_iommu *iommu;
@@ -1457,7 +1462,8 @@ unmap:
  * lists).
  */
 static void unmap_sg(struct device *dev, struct scatterlist *sglist,
-                    int nelems, int dir)
+                    int nelems, enum dma_data_direction dir,
+                    struct dma_attrs *attrs)
 {
        unsigned long flags;
        struct amd_iommu *iommu;
@@ -1644,11 +1650,11 @@ static void prealloc_protection_domains(void)
        }
 }
 
-static struct dma_mapping_ops amd_iommu_dma_ops = {
+static struct dma_map_ops amd_iommu_dma_ops = {
        .alloc_coherent = alloc_coherent,
        .free_coherent = free_coherent,
-       .map_single = map_single,
-       .unmap_single = unmap_single,
+       .map_page = map_page,
+       .unmap_page = unmap_page,
        .map_sg = map_sg,
        .unmap_sg = unmap_sg,
        .dma_supported = amd_iommu_dma_supported,
index d28bbdc35e4e5dec064bd1f9e5e7fbc548deaf4e..755c21e906f3f04821755c703bb99e26b118e0f7 100644 (file)
@@ -380,8 +380,9 @@ static inline struct iommu_table *find_iommu_table(struct device *dev)
        return tbl;
 }
 
-static void calgary_unmap_sg(struct device *dev,
-       struct scatterlist *sglist, int nelems, int direction)
+static void calgary_unmap_sg(struct device *dev, struct scatterlist *sglist,
+                            int nelems,enum dma_data_direction dir,
+                            struct dma_attrs *attrs)
 {
        struct iommu_table *tbl = find_iommu_table(dev);
        struct scatterlist *s;
@@ -404,7 +405,8 @@ static void calgary_unmap_sg(struct device *dev,
 }
 
 static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
-       int nelems, int direction)
+                         int nelems, enum dma_data_direction dir,
+                         struct dma_attrs *attrs)
 {
        struct iommu_table *tbl = find_iommu_table(dev);
        struct scatterlist *s;
@@ -429,15 +431,14 @@ static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
                s->dma_address = (entry << PAGE_SHIFT) | s->offset;
 
                /* insert into HW table */
-               tce_build(tbl, entry, npages, vaddr & PAGE_MASK,
-                         direction);
+               tce_build(tbl, entry, npages, vaddr & PAGE_MASK, dir);
 
                s->dma_length = s->length;
        }
 
        return nelems;
 error:
-       calgary_unmap_sg(dev, sg, nelems, direction);
+       calgary_unmap_sg(dev, sg, nelems, dir, NULL);
        for_each_sg(sg, s, nelems, i) {
                sg->dma_address = bad_dma_address;
                sg->dma_length = 0;
@@ -445,10 +446,12 @@ error:
        return 0;
 }
 
-static dma_addr_t calgary_map_single(struct device *dev, phys_addr_t paddr,
-       size_t size, int direction)
+static dma_addr_t calgary_map_page(struct device *dev, struct page *page,
+                                  unsigned long offset, size_t size,
+                                  enum dma_data_direction dir,
+                                  struct dma_attrs *attrs)
 {
-       void *vaddr = phys_to_virt(paddr);
+       void *vaddr = page_address(page) + offset;
        unsigned long uaddr;
        unsigned int npages;
        struct iommu_table *tbl = find_iommu_table(dev);
@@ -456,17 +459,18 @@ static dma_addr_t calgary_map_single(struct device *dev, phys_addr_t paddr,
        uaddr = (unsigned long)vaddr;
        npages = iommu_num_pages(uaddr, size, PAGE_SIZE);
 
-       return iommu_alloc(dev, tbl, vaddr, npages, direction);
+       return iommu_alloc(dev, tbl, vaddr, npages, dir);
 }
 
-static void calgary_unmap_single(struct device *dev, dma_addr_t dma_handle,
-       size_t size, int direction)
+static void calgary_unmap_page(struct device *dev, dma_addr_t dma_addr,
+                              size_t size, enum dma_data_direction dir,
+                              struct dma_attrs *attrs)
 {
        struct iommu_table *tbl = find_iommu_table(dev);
        unsigned int npages;
 
-       npages = iommu_num_pages(dma_handle, size, PAGE_SIZE);
-       iommu_free(tbl, dma_handle, npages);
+       npages = iommu_num_pages(dma_addr, size, PAGE_SIZE);
+       iommu_free(tbl, dma_addr, npages);
 }
 
 static void* calgary_alloc_coherent(struct device *dev, size_t size,
@@ -515,13 +519,13 @@ static void calgary_free_coherent(struct device *dev, size_t size,
        free_pages((unsigned long)vaddr, get_order(size));
 }
 
-static struct dma_mapping_ops calgary_dma_ops = {
+static struct dma_map_ops calgary_dma_ops = {
        .alloc_coherent = calgary_alloc_coherent,
        .free_coherent = calgary_free_coherent,
-       .map_single = calgary_map_single,
-       .unmap_single = calgary_unmap_single,
        .map_sg = calgary_map_sg,
        .unmap_sg = calgary_unmap_sg,
+       .map_page = calgary_map_page,
+       .unmap_page = calgary_unmap_page,
 };
 
 static inline void __iomem * busno_to_bbar(unsigned char num)
index b25428533141a5a73fb8787268864b774c5e9752..f293a8df68282b1de49eda6241ef96fc905d559e 100644 (file)
@@ -12,7 +12,7 @@
 
 static int forbid_dac __read_mostly;
 
-struct dma_mapping_ops *dma_ops;
+struct dma_map_ops *dma_ops;
 EXPORT_SYMBOL(dma_ops);
 
 static int iommu_sac_force __read_mostly;
@@ -224,7 +224,7 @@ early_param("iommu", iommu_setup);
 
 int dma_supported(struct device *dev, u64 mask)
 {
-       struct dma_mapping_ops *ops = get_dma_ops(dev);
+       struct dma_map_ops *ops = get_dma_ops(dev);
 
 #ifdef CONFIG_PCI
        if (mask > 0xffffffff && forbid_dac > 0) {
index 00c2bcd41463e325976a74cbee0fa06f4b6fe85c..8cb3e45439cf25b0738e09445386238073d8f7e6 100644 (file)
@@ -255,10 +255,13 @@ static dma_addr_t dma_map_area(struct device *dev, dma_addr_t phys_mem,
 }
 
 /* Map a single area into the IOMMU */
-static dma_addr_t
-gart_map_single(struct device *dev, phys_addr_t paddr, size_t size, int dir)
+static dma_addr_t gart_map_page(struct device *dev, struct page *page,
+                               unsigned long offset, size_t size,
+                               enum dma_data_direction dir,
+                               struct dma_attrs *attrs)
 {
        unsigned long bus;
+       phys_addr_t paddr = page_to_phys(page) + offset;
 
        if (!dev)
                dev = &x86_dma_fallback_dev;
@@ -275,8 +278,9 @@ gart_map_single(struct device *dev, phys_addr_t paddr, size_t size, int dir)
 /*
  * Free a DMA mapping.
  */
-static void gart_unmap_single(struct device *dev, dma_addr_t dma_addr,
-                             size_t size, int direction)
+static void gart_unmap_page(struct device *dev, dma_addr_t dma_addr,
+                           size_t size, enum dma_data_direction dir,
+                           struct dma_attrs *attrs)
 {
        unsigned long iommu_page;
        int npages;
@@ -298,8 +302,8 @@ static void gart_unmap_single(struct device *dev, dma_addr_t dma_addr,
 /*
  * Wrapper for pci_unmap_single working with scatterlists.
  */
-static void
-gart_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
+static void gart_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
+                         enum dma_data_direction dir, struct dma_attrs *attrs)
 {
        struct scatterlist *s;
        int i;
@@ -307,7 +311,7 @@ gart_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
        for_each_sg(sg, s, nents, i) {
                if (!s->dma_length || !s->length)
                        break;
-               gart_unmap_single(dev, s->dma_address, s->dma_length, dir);
+               gart_unmap_page(dev, s->dma_address, s->dma_length, dir, NULL);
        }
 }
 
@@ -329,7 +333,7 @@ static int dma_map_sg_nonforce(struct device *dev, struct scatterlist *sg,
                        addr = dma_map_area(dev, addr, s->length, dir, 0);
                        if (addr == bad_dma_address) {
                                if (i > 0)
-                                       gart_unmap_sg(dev, sg, i, dir);
+                                       gart_unmap_sg(dev, sg, i, dir, NULL);
                                nents = 0;
                                sg[0].dma_length = 0;
                                break;
@@ -400,8 +404,8 @@ dma_map_cont(struct device *dev, struct scatterlist *start, int nelems,
  * DMA map all entries in a scatterlist.
  * Merge chunks that have page aligned sizes into a continuous mapping.
  */
-static int
-gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
+static int gart_map_sg(struct device *dev, struct scatterlist *sg, int nents,
+                      enum dma_data_direction dir, struct dma_attrs *attrs)
 {
        struct scatterlist *s, *ps, *start_sg, *sgmap;
        int need = 0, nextneed, i, out, start;
@@ -468,7 +472,7 @@ gart_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir)
 
 error:
        flush_gart();
-       gart_unmap_sg(dev, sg, out, dir);
+       gart_unmap_sg(dev, sg, out, dir, NULL);
 
        /* When it was forced or merged try again in a dumb way */
        if (force_iommu || iommu_merge) {
@@ -521,7 +525,7 @@ static void
 gart_free_coherent(struct device *dev, size_t size, void *vaddr,
                   dma_addr_t dma_addr)
 {
-       gart_unmap_single(dev, dma_addr, size, DMA_BIDIRECTIONAL);
+       gart_unmap_page(dev, dma_addr, size, DMA_BIDIRECTIONAL, NULL);
        free_pages((unsigned long)vaddr, get_order(size));
 }
 
@@ -707,11 +711,11 @@ static __init int init_k8_gatt(struct agp_kern_info *info)
        return -1;
 }
 
-static struct dma_mapping_ops gart_dma_ops = {
-       .map_single                     = gart_map_single,
-       .unmap_single                   = gart_unmap_single,
+static struct dma_map_ops gart_dma_ops = {
        .map_sg                         = gart_map_sg,
        .unmap_sg                       = gart_unmap_sg,
+       .map_page                       = gart_map_page,
+       .unmap_page                     = gart_unmap_page,
        .alloc_coherent                 = gart_alloc_coherent,
        .free_coherent                  = gart_free_coherent,
 };
index c70ab5a5d4c886a0856de8e0f313a97048d2c328..fe50214db8765d6e064e70cff38def77b9793508 100644 (file)
@@ -25,19 +25,19 @@ check_addr(char *name, struct device *hwdev, dma_addr_t bus, size_t size)
        return 1;
 }
 
-static dma_addr_t
-nommu_map_single(struct device *hwdev, phys_addr_t paddr, size_t size,
-              int direction)
+static dma_addr_t nommu_map_page(struct device *dev, struct page *page,
+                                unsigned long offset, size_t size,
+                                enum dma_data_direction dir,
+                                struct dma_attrs *attrs)
 {
-       dma_addr_t bus = paddr;
+       dma_addr_t bus = page_to_phys(page) + offset;
        WARN_ON(size == 0);
-       if (!check_addr("map_single", hwdev, bus, size))
-                               return bad_dma_address;
+       if (!check_addr("map_single", dev, bus, size))
+               return bad_dma_address;
        flush_write_buffers();
        return bus;
 }
 
-
 /* Map a set of buffers described by scatterlist in streaming
  * mode for DMA.  This is the scatter-gather version of the
  * above pci_map_single interface.  Here the scatter gather list
@@ -54,7 +54,8 @@ nommu_map_single(struct device *hwdev, phys_addr_t paddr, size_t size,
  * the same here.
  */
 static int nommu_map_sg(struct device *hwdev, struct scatterlist *sg,
-              int nents, int direction)
+                       int nents, enum dma_data_direction dir,
+                       struct dma_attrs *attrs)
 {
        struct scatterlist *s;
        int i;
@@ -78,11 +79,11 @@ static void nommu_free_coherent(struct device *dev, size_t size, void *vaddr,
        free_pages((unsigned long)vaddr, get_order(size));
 }
 
-struct dma_mapping_ops nommu_dma_ops = {
+struct dma_map_ops nommu_dma_ops = {
        .alloc_coherent = dma_generic_alloc_coherent,
        .free_coherent = nommu_free_coherent,
-       .map_single = nommu_map_single,
        .map_sg = nommu_map_sg,
+       .map_page = nommu_map_page,
        .is_phys = 1,
 };
 
index d59c9174766586c01f3377a13a7763cb716eceeb..5e32c4f6a7ba8f1e7febf5db1b1a65cafd79467a 100644 (file)
@@ -38,13 +38,6 @@ int __weak swiotlb_arch_range_needs_mapping(void *ptr, size_t size)
        return 0;
 }
 
-static dma_addr_t
-swiotlb_map_single_phys(struct device *hwdev, phys_addr_t paddr, size_t size,
-                       int direction)
-{
-       return swiotlb_map_single(hwdev, phys_to_virt(paddr), size, direction);
-}
-
 static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
                                        dma_addr_t *dma_handle, gfp_t flags)
 {
@@ -57,20 +50,20 @@ static void *x86_swiotlb_alloc_coherent(struct device *hwdev, size_t size,
        return swiotlb_alloc_coherent(hwdev, size, dma_handle, flags);
 }
 
-struct dma_mapping_ops swiotlb_dma_ops = {
+struct dma_map_ops swiotlb_dma_ops = {
        .mapping_error = swiotlb_dma_mapping_error,
        .alloc_coherent = x86_swiotlb_alloc_coherent,
        .free_coherent = swiotlb_free_coherent,
-       .map_single = swiotlb_map_single_phys,
-       .unmap_single = swiotlb_unmap_single,
        .sync_single_for_cpu = swiotlb_sync_single_for_cpu,
        .sync_single_for_device = swiotlb_sync_single_for_device,
        .sync_single_range_for_cpu = swiotlb_sync_single_range_for_cpu,
        .sync_single_range_for_device = swiotlb_sync_single_range_for_device,
        .sync_sg_for_cpu = swiotlb_sync_sg_for_cpu,
        .sync_sg_for_device = swiotlb_sync_sg_for_device,
-       .map_sg = swiotlb_map_sg,
-       .unmap_sg = swiotlb_unmap_sg,
+       .map_sg = swiotlb_map_sg_attrs,
+       .unmap_sg = swiotlb_unmap_sg_attrs,
+       .map_page = swiotlb_map_page,
+       .unmap_page = swiotlb_unmap_page,
        .dma_supported = NULL,
 };
 
index 235fb7a5a8a50455fcbf27a64ff8b84f6e418882..b9a5629339039a7e54bbfbe7f1ad6f5e6c173f95 100644 (file)
@@ -2273,6 +2273,15 @@ error:
        return 0;
 }
 
+static dma_addr_t intel_map_page(struct device *dev, struct page *page,
+                                unsigned long offset, size_t size,
+                                enum dma_data_direction dir,
+                                struct dma_attrs *attrs)
+{
+       return __intel_map_single(dev, page_to_phys(page) + offset, size,
+                                 dir, to_pci_dev(dev)->dma_mask);
+}
+
 dma_addr_t intel_map_single(struct device *hwdev, phys_addr_t paddr,
                            size_t size, int dir)
 {
@@ -2341,8 +2350,9 @@ static void add_unmap(struct dmar_domain *dom, struct iova *iova)
        spin_unlock_irqrestore(&async_umap_flush_lock, flags);
 }
 
-void intel_unmap_single(struct device *dev, dma_addr_t dev_addr, size_t size,
-                       int dir)
+static void intel_unmap_page(struct device *dev, dma_addr_t dev_addr,
+                            size_t size, enum dma_data_direction dir,
+                            struct dma_attrs *attrs)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
        struct dmar_domain *domain;
@@ -2386,6 +2396,12 @@ void intel_unmap_single(struct device *dev, dma_addr_t dev_addr, size_t size,
        }
 }
 
+void intel_unmap_single(struct device *dev, dma_addr_t dev_addr, size_t size,
+                       int dir)
+{
+       intel_unmap_page(dev, dev_addr, size, dir, NULL);
+}
+
 void *intel_alloc_coherent(struct device *hwdev, size_t size,
                           dma_addr_t *dma_handle, gfp_t flags)
 {
@@ -2425,7 +2441,8 @@ void intel_free_coherent(struct device *hwdev, size_t size, void *vaddr,
 #define SG_ENT_VIRT_ADDRESS(sg)        (sg_virt((sg)))
 
 void intel_unmap_sg(struct device *hwdev, struct scatterlist *sglist,
-                   int nelems, int dir)
+                   int nelems, enum dma_data_direction dir,
+                   struct dma_attrs *attrs)
 {
        int i;
        struct pci_dev *pdev = to_pci_dev(hwdev);
@@ -2483,7 +2500,7 @@ static int intel_nontranslate_map_sg(struct device *hddev,
 }
 
 int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
-                int dir)
+                enum dma_data_direction dir, struct dma_attrs *attrs)
 {
        void *addr;
        int i;
@@ -2563,13 +2580,13 @@ int intel_map_sg(struct device *hwdev, struct scatterlist *sglist, int nelems,
        return nelems;
 }
 
-static struct dma_mapping_ops intel_dma_ops = {
+struct dma_map_ops intel_dma_ops = {
        .alloc_coherent = intel_alloc_coherent,
        .free_coherent = intel_free_coherent,
-       .map_single = intel_map_single,
-       .unmap_single = intel_unmap_single,
        .map_sg = intel_map_sg,
        .unmap_sg = intel_unmap_sg,
+       .map_page = intel_map_page,
+       .unmap_page = intel_unmap_page,
 };
 
 static inline int iommu_domain_cache_init(void)
index ba9114ec5d3aa953a13f057e157b6b866de76f53..d7d090d210317b258f400239fdf42d76bd8db7f6 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <linux/device.h>
 #include <linux/err.h>
+#include <linux/dma-attrs.h>
+#include <linux/scatterlist.h>
 
 /* These definitions mirror those in pci.h, so they can be used
  * interchangeably with their PCI_ counterparts */
@@ -13,6 +15,52 @@ enum dma_data_direction {
        DMA_NONE = 3,
 };
 
+struct dma_map_ops {
+       void* (*alloc_coherent)(struct device *dev, size_t size,
+                               dma_addr_t *dma_handle, gfp_t gfp);
+       void (*free_coherent)(struct device *dev, size_t size,
+                             void *vaddr, dma_addr_t dma_handle);
+       dma_addr_t (*map_page)(struct device *dev, struct page *page,
+                              unsigned long offset, size_t size,
+                              enum dma_data_direction dir,
+                              struct dma_attrs *attrs);
+       void (*unmap_page)(struct device *dev, dma_addr_t dma_handle,
+                          size_t size, enum dma_data_direction dir,
+                          struct dma_attrs *attrs);
+       int (*map_sg)(struct device *dev, struct scatterlist *sg,
+                     int nents, enum dma_data_direction dir,
+                     struct dma_attrs *attrs);
+       void (*unmap_sg)(struct device *dev,
+                        struct scatterlist *sg, int nents,
+                        enum dma_data_direction dir,
+                        struct dma_attrs *attrs);
+       void (*sync_single_for_cpu)(struct device *dev,
+                                   dma_addr_t dma_handle, size_t size,
+                                   enum dma_data_direction dir);
+       void (*sync_single_for_device)(struct device *dev,
+                                      dma_addr_t dma_handle, size_t size,
+                                      enum dma_data_direction dir);
+       void (*sync_single_range_for_cpu)(struct device *dev,
+                                         dma_addr_t dma_handle,
+                                         unsigned long offset,
+                                         size_t size,
+                                         enum dma_data_direction dir);
+       void (*sync_single_range_for_device)(struct device *dev,
+                                            dma_addr_t dma_handle,
+                                            unsigned long offset,
+                                            size_t size,
+                                            enum dma_data_direction dir);
+       void (*sync_sg_for_cpu)(struct device *dev,
+                               struct scatterlist *sg, int nents,
+                               enum dma_data_direction dir);
+       void (*sync_sg_for_device)(struct device *dev,
+                                  struct scatterlist *sg, int nents,
+                                  enum dma_data_direction dir);
+       int (*mapping_error)(struct device *dev, dma_addr_t dma_addr);
+       int (*dma_supported)(struct device *dev, u64 mask);
+       int is_phys;
+};
+
 #define DMA_BIT_MASK(n)        (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
 
 /*
index c4f6c101dbcddd91e0b7d045a345a4d6fba28777..a254db1decd018f125d279acb6d2d0dcfc02ec34 100644 (file)
@@ -334,7 +334,9 @@ extern void *intel_alloc_coherent(struct device *, size_t, dma_addr_t *, gfp_t);
 extern void intel_free_coherent(struct device *, size_t, void *, dma_addr_t);
 extern dma_addr_t intel_map_single(struct device *, phys_addr_t, size_t, int);
 extern void intel_unmap_single(struct device *, dma_addr_t, size_t, int);
-extern int intel_map_sg(struct device *, struct scatterlist *, int, int);
-extern void intel_unmap_sg(struct device *, struct scatterlist *, int, int);
+extern int intel_map_sg(struct device *, struct scatterlist *, int,
+                       enum dma_data_direction, struct dma_attrs *);
+extern void intel_unmap_sg(struct device *, struct scatterlist *, int,
+                          enum dma_data_direction, struct dma_attrs *);
 
 #endif
index dedd3c0cfe300c8fbaf841cd525d8991cd404c19..493dc17e7c87b123622c870c72f3ef7604c2569e 100644 (file)
@@ -41,20 +41,13 @@ extern void
 swiotlb_free_coherent(struct device *hwdev, size_t size,
                      void *vaddr, dma_addr_t dma_handle);
 
-extern dma_addr_t
-swiotlb_map_single(struct device *hwdev, void *ptr, size_t size, int dir);
-
-extern void
-swiotlb_unmap_single(struct device *hwdev, dma_addr_t dev_addr,
-                    size_t size, int dir);
-
-extern dma_addr_t
-swiotlb_map_single_attrs(struct device *hwdev, void *ptr, size_t size,
-                        int dir, struct dma_attrs *attrs);
-
-extern void
-swiotlb_unmap_single_attrs(struct device *hwdev, dma_addr_t dev_addr,
-                          size_t size, int dir, struct dma_attrs *attrs);
+extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
+                                  unsigned long offset, size_t size,
+                                  enum dma_data_direction dir,
+                                  struct dma_attrs *attrs);
+extern void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,
+                              size_t size, enum dma_data_direction dir,
+                              struct dma_attrs *attrs);
 
 extern int
 swiotlb_map_sg(struct device *hwdev, struct scatterlist *sg, int nents,
@@ -66,36 +59,38 @@ swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
 
 extern int
 swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,
-                    int dir, struct dma_attrs *attrs);
+                    enum dma_data_direction dir, struct dma_attrs *attrs);
 
 extern void
 swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
-                      int nelems, int dir, struct dma_attrs *attrs);
+                      int nelems, enum dma_data_direction dir,
+                      struct dma_attrs *attrs);
 
 extern void
 swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
-                           size_t size, int dir);
+                           size_t size, enum dma_data_direction dir);
 
 extern void
 swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
-                       int nelems, int dir);
+                       int nelems, enum dma_data_direction dir);
 
 extern void
 swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
-                              size_t size, int dir);
+                              size_t size, enum dma_data_direction dir);
 
 extern void
 swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
-                          int nelems, int dir);
+                          int nelems, enum dma_data_direction dir);
 
 extern void
 swiotlb_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
-                                 unsigned long offset, size_t size, int dir);
+                                 unsigned long offset, size_t size,
+                                 enum dma_data_direction dir);
 
 extern void
 swiotlb_sync_single_range_for_device(struct device *hwdev, dma_addr_t dev_addr,
                                     unsigned long offset, size_t size,
-                                    int dir);
+                                    enum dma_data_direction dir);
 
 extern int
 swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr);
index 1f991acc2a057acf65728448a5c3488d8e963351..30fe65ede2bbf9a4f6b3f8a7c44be967a5c727f0 100644 (file)
@@ -636,11 +636,14 @@ swiotlb_full(struct device *dev, size_t size, int dir, int do_panic)
  * Once the device is given the dma address, the device owns this memory until
  * either swiotlb_unmap_single or swiotlb_dma_sync_single is performed.
  */
-dma_addr_t
-swiotlb_map_single_attrs(struct device *hwdev, void *ptr, size_t size,
-                        int dir, struct dma_attrs *attrs)
-{
-       dma_addr_t dev_addr = swiotlb_virt_to_bus(hwdev, ptr);
+dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
+                           unsigned long offset, size_t size,
+                           enum dma_data_direction dir,
+                           struct dma_attrs *attrs)
+{
+       phys_addr_t phys = page_to_phys(page) + offset;
+       void *ptr = page_address(page) + offset;
+       dma_addr_t dev_addr = swiotlb_phys_to_bus(dev, phys);
        void *map;
 
        BUG_ON(dir == DMA_NONE);
@@ -649,37 +652,30 @@ swiotlb_map_single_attrs(struct device *hwdev, void *ptr, size_t size,
         * we can safely return the device addr and not worry about bounce
         * buffering it.
         */
-       if (!address_needs_mapping(hwdev, dev_addr, size) &&
+       if (!address_needs_mapping(dev, dev_addr, size) &&
            !range_needs_mapping(ptr, size))
                return dev_addr;
 
        /*
         * Oh well, have to allocate and map a bounce buffer.
         */
-       map = map_single(hwdev, virt_to_phys(ptr), size, dir);
+       map = map_single(dev, phys, size, dir);
        if (!map) {
-               swiotlb_full(hwdev, size, dir, 1);
+               swiotlb_full(dev, size, dir, 1);
                map = io_tlb_overflow_buffer;
        }
 
-       dev_addr = swiotlb_virt_to_bus(hwdev, map);
+       dev_addr = swiotlb_virt_to_bus(dev, map);
 
        /*
         * Ensure that the address returned is DMA'ble
         */
-       if (address_needs_mapping(hwdev, dev_addr, size))
+       if (address_needs_mapping(dev, dev_addr, size))
                panic("map_single: bounce buffer is not DMA'ble");
 
        return dev_addr;
 }
-EXPORT_SYMBOL(swiotlb_map_single_attrs);
-
-dma_addr_t
-swiotlb_map_single(struct device *hwdev, void *ptr, size_t size, int dir)
-{
-       return swiotlb_map_single_attrs(hwdev, ptr, size, dir, NULL);
-}
-EXPORT_SYMBOL(swiotlb_map_single);
+EXPORT_SYMBOL_GPL(swiotlb_map_page);
 
 /*
  * Unmap a single streaming mode DMA translation.  The dma_addr and size must
@@ -689,9 +685,9 @@ EXPORT_SYMBOL(swiotlb_map_single);
  * After this call, reads by the cpu to the buffer are guaranteed to see
  * whatever the device wrote there.
  */
-void
-swiotlb_unmap_single_attrs(struct device *hwdev, dma_addr_t dev_addr,
-                          size_t size, int dir, struct dma_attrs *attrs)
+void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,
+                       size_t size, enum dma_data_direction dir,
+                       struct dma_attrs *attrs)
 {
        char *dma_addr = swiotlb_bus_to_virt(dev_addr);
 
@@ -701,15 +697,7 @@ swiotlb_unmap_single_attrs(struct device *hwdev, dma_addr_t dev_addr,
        else if (dir == DMA_FROM_DEVICE)
                dma_mark_clean(dma_addr, size);
 }
-EXPORT_SYMBOL(swiotlb_unmap_single_attrs);
-
-void
-swiotlb_unmap_single(struct device *hwdev, dma_addr_t dev_addr, size_t size,
-                    int dir)
-{
-       return swiotlb_unmap_single_attrs(hwdev, dev_addr, size, dir, NULL);
-}
-EXPORT_SYMBOL(swiotlb_unmap_single);
+EXPORT_SYMBOL_GPL(swiotlb_unmap_page);
 
 /*
  * Make physical memory consistent for a single streaming mode DMA translation
@@ -736,7 +724,7 @@ swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr,
 
 void
 swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
-                           size_t size, int dir)
+                           size_t size, enum dma_data_direction dir)
 {
        swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_CPU);
 }
@@ -744,7 +732,7 @@ EXPORT_SYMBOL(swiotlb_sync_single_for_cpu);
 
 void
 swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
-                              size_t size, int dir)
+                              size_t size, enum dma_data_direction dir)
 {
        swiotlb_sync_single(hwdev, dev_addr, size, dir, SYNC_FOR_DEVICE);
 }
@@ -769,7 +757,8 @@ swiotlb_sync_single_range(struct device *hwdev, dma_addr_t dev_addr,
 
 void
 swiotlb_sync_single_range_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
-                                 unsigned long offset, size_t size, int dir)
+                                 unsigned long offset, size_t size,
+                                 enum dma_data_direction dir)
 {
        swiotlb_sync_single_range(hwdev, dev_addr, offset, size, dir,
                                  SYNC_FOR_CPU);
@@ -778,7 +767,8 @@ EXPORT_SYMBOL_GPL(swiotlb_sync_single_range_for_cpu);
 
 void
 swiotlb_sync_single_range_for_device(struct device *hwdev, dma_addr_t dev_addr,
-                                    unsigned long offset, size_t size, int dir)
+                                    unsigned long offset, size_t size,
+                                    enum dma_data_direction dir)
 {
        swiotlb_sync_single_range(hwdev, dev_addr, offset, size, dir,
                                  SYNC_FOR_DEVICE);
@@ -803,7 +793,7 @@ EXPORT_SYMBOL_GPL(swiotlb_sync_single_range_for_device);
  */
 int
 swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,
-                    int dir, struct dma_attrs *attrs)
+                    enum dma_data_direction dir, struct dma_attrs *attrs)
 {
        struct scatterlist *sg;
        int i;
@@ -850,7 +840,7 @@ EXPORT_SYMBOL(swiotlb_map_sg);
  */
 void
 swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
-                      int nelems, int dir, struct dma_attrs *attrs)
+                      int nelems, enum dma_data_direction dir, struct dma_attrs *attrs)
 {
        struct scatterlist *sg;
        int i;
@@ -902,7 +892,7 @@ swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl,
 
 void
 swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
-                       int nelems, int dir)
+                       int nelems, enum dma_data_direction dir)
 {
        swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_CPU);
 }
@@ -910,7 +900,7 @@ EXPORT_SYMBOL(swiotlb_sync_sg_for_cpu);
 
 void
 swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
-                          int nelems, int dir)
+                          int nelems, enum dma_data_direction dir)
 {
        swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE);
 }