iommu-helper: use bitmap library
[safe/jmp/linux-2.6] / arch / sparc / kernel / iommu.c
index d8900e1..5fad949 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/errno.h>
 #include <linux/iommu-helper.h>
+#include <linux/bitmap.h>
 
 #ifdef CONFIG_PCI
 #include <linux/pci.h>
@@ -169,7 +170,7 @@ void iommu_range_free(struct iommu *iommu, dma_addr_t dma_addr, unsigned long np
 
        entry = (dma_addr - iommu->page_table_map_base) >> IO_PAGE_SHIFT;
 
-       iommu_area_free(arena->map, entry, npages);
+       bitmap_clear(arena->map, entry, npages);
 }
 
 int iommu_table_init(struct iommu *iommu, int tsbsize,
@@ -351,8 +352,10 @@ static void dma_4u_free_coherent(struct device *dev, size_t size,
                free_pages((unsigned long)cpu, order);
 }
 
-static dma_addr_t dma_4u_map_single(struct device *dev, void *ptr, size_t sz,
-                                   enum dma_data_direction direction)
+static dma_addr_t dma_4u_map_page(struct device *dev, struct page *page,
+                                 unsigned long offset, size_t sz,
+                                 enum dma_data_direction direction,
+                                 struct dma_attrs *attrs)
 {
        struct iommu *iommu;
        struct strbuf *strbuf;
@@ -368,7 +371,7 @@ static dma_addr_t dma_4u_map_single(struct device *dev, void *ptr, size_t sz,
        if (unlikely(direction == DMA_NONE))
                goto bad_no_ctx;
 
-       oaddr = (unsigned long)ptr;
+       oaddr = (unsigned long)(page_address(page) + offset);
        npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK);
        npages >>= IO_PAGE_SHIFT;
 
@@ -472,8 +475,9 @@ do_flush_sync:
                       vaddr, ctx, npages);
 }
 
-static void dma_4u_unmap_single(struct device *dev, dma_addr_t bus_addr,
-                               size_t sz, enum dma_data_direction direction)
+static void dma_4u_unmap_page(struct device *dev, dma_addr_t bus_addr,
+                             size_t sz, enum dma_data_direction direction,
+                             struct dma_attrs *attrs)
 {
        struct iommu *iommu;
        struct strbuf *strbuf;
@@ -519,7 +523,8 @@ static void dma_4u_unmap_single(struct device *dev, dma_addr_t bus_addr,
 }
 
 static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
-                        int nelems, enum dma_data_direction direction)
+                        int nelems, enum dma_data_direction direction,
+                        struct dma_attrs *attrs)
 {
        struct scatterlist *s, *outs, *segstart;
        unsigned long flags, handle, prot, ctx;
@@ -690,7 +695,8 @@ static unsigned long fetch_sg_ctx(struct iommu *iommu, struct scatterlist *sg)
 }
 
 static void dma_4u_unmap_sg(struct device *dev, struct scatterlist *sglist,
-                           int nelems, enum dma_data_direction direction)
+                           int nelems, enum dma_data_direction direction,
+                           struct dma_attrs *attrs)
 {
        unsigned long flags, ctx;
        struct scatterlist *sg;
@@ -821,20 +827,22 @@ static void dma_4u_sync_sg_for_cpu(struct device *dev,
        spin_unlock_irqrestore(&iommu->lock, flags);
 }
 
-static const struct dma_ops sun4u_dma_ops = {
+static struct dma_map_ops sun4u_dma_ops = {
        .alloc_coherent         = dma_4u_alloc_coherent,
        .free_coherent          = dma_4u_free_coherent,
-       .map_single             = dma_4u_map_single,
-       .unmap_single           = dma_4u_unmap_single,
+       .map_page               = dma_4u_map_page,
+       .unmap_page             = dma_4u_unmap_page,
        .map_sg                 = dma_4u_map_sg,
        .unmap_sg               = dma_4u_unmap_sg,
        .sync_single_for_cpu    = dma_4u_sync_single_for_cpu,
        .sync_sg_for_cpu        = dma_4u_sync_sg_for_cpu,
 };
 
-const struct dma_ops *dma_ops = &sun4u_dma_ops;
+struct dma_map_ops *dma_ops = &sun4u_dma_ops;
 EXPORT_SYMBOL(dma_ops);
 
+extern int pci64_dma_supported(struct pci_dev *pdev, u64 device_mask);
+
 int dma_supported(struct device *dev, u64 device_mask)
 {
        struct iommu *iommu = dev->archdata.iommu;
@@ -848,7 +856,7 @@ int dma_supported(struct device *dev, u64 device_mask)
 
 #ifdef CONFIG_PCI
        if (dev->bus == &pci_bus_type)
-               return pci_dma_supported(to_pci_dev(dev), device_mask);
+               return pci64_dma_supported(to_pci_dev(dev), device_mask);
 #endif
 
        return 0;