]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - arch/x86/kernel/pci-gart_64.c
x86: move GART TLB flushing options to generic code
[karo-tx-linux.git] / arch / x86 / kernel / pci-gart_64.c
index 338c4f2415598b6fdf253e5d52408567f885394c..508ef470b27f09649e298f25ce0320c57939f156 100644 (file)
@@ -45,15 +45,6 @@ static unsigned long iommu_pages;    /* .. and in pages */
 
 static u32 *iommu_gatt_base;           /* Remapping table */
 
-/*
- * If this is disabled the IOMMU will use an optimized flushing strategy
- * of only flushing when an mapping is reused. With it true the GART is
- * flushed for every mapping. Problem is that doing the lazy flush seems
- * to trigger bugs with some popular PCI cards, in particular 3ware (but
- * has been also also seen with Qlogic at least).
- */
-int iommu_fullflush = 1;
-
 /* Allocation bitmap for the remapping area: */
 static DEFINE_SPINLOCK(iommu_bitmap_lock);
 /* Guarded by iommu_bitmap_lock: */
@@ -83,23 +74,34 @@ static unsigned long next_bit;  /* protected by iommu_bitmap_lock */
 static int need_flush;         /* global flush state. set for each gart wrap */
 
 static unsigned long alloc_iommu(struct device *dev, int size,
-                                unsigned long align_mask)
+                                unsigned long align_mask, u64 dma_mask)
 {
        unsigned long offset, flags;
        unsigned long boundary_size;
        unsigned long base_index;
+       unsigned long limit;
 
        base_index = ALIGN(iommu_bus_base & dma_get_seg_boundary(dev),
                           PAGE_SIZE) >> PAGE_SHIFT;
        boundary_size = ALIGN((unsigned long long)dma_get_seg_boundary(dev) + 1,
                              PAGE_SIZE) >> PAGE_SHIFT;
 
+       limit = iommu_device_max_index(iommu_pages,
+                                      DIV_ROUND_UP(iommu_bus_base, PAGE_SIZE),
+                                      dma_mask >> PAGE_SHIFT);
+
        spin_lock_irqsave(&iommu_bitmap_lock, flags);
-       offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, next_bit,
+
+       if (limit <= next_bit) {
+               need_flush = 1;
+               next_bit = 0;
+       }
+
+       offset = iommu_area_alloc(iommu_gart_bitmap, limit, next_bit,
                                  size, base_index, boundary_size, align_mask);
-       if (offset == -1) {
+       if (offset == -1 && next_bit) {
                need_flush = 1;
-               offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, 0,
+               offset = iommu_area_alloc(iommu_gart_bitmap, limit, 0,
                                          size, base_index, boundary_size,
                                          align_mask);
        }
@@ -214,36 +216,28 @@ static void iommu_full(struct device *dev, size_t size, int dir)
 static inline int
 need_iommu(struct device *dev, unsigned long addr, size_t size)
 {
-       u64 mask = *dev->dma_mask;
-       int high = addr + size > mask;
-       int mmu = high;
-
-       if (force_iommu)
-               mmu = 1;
-
-       return mmu;
+       return force_iommu ||
+               !is_buffer_dma_capable(*dev->dma_mask, addr, size);
 }
 
 static inline int
 nonforced_iommu(struct device *dev, unsigned long addr, size_t size)
 {
-       u64 mask = *dev->dma_mask;
-       int high = addr + size > mask;
-       int mmu = high;
-
-       return mmu;
+       return !is_buffer_dma_capable(*dev->dma_mask, addr, size);
 }
 
 /* Map a single continuous physical area into the IOMMU.
  * Caller needs to check if the iommu is needed and flush.
  */
 static dma_addr_t dma_map_area(struct device *dev, dma_addr_t phys_mem,
-                               size_t size, int dir, unsigned long align_mask)
+                              size_t size, int dir, unsigned long align_mask,
+                              u64 dma_mask)
 {
        unsigned long npages = iommu_num_pages(phys_mem, size);
-       unsigned long iommu_page = alloc_iommu(dev, npages, align_mask);
+       unsigned long iommu_page;
        int i;
 
+       iommu_page = alloc_iommu(dev, npages, align_mask, dma_mask);
        if (iommu_page == -1) {
                if (!nonforced_iommu(dev, phys_mem, size))
                        return phys_mem;
@@ -261,20 +255,6 @@ static dma_addr_t dma_map_area(struct device *dev, dma_addr_t phys_mem,
        return iommu_bus_base + iommu_page*PAGE_SIZE + (phys_mem & ~PAGE_MASK);
 }
 
-static dma_addr_t
-gart_map_simple(struct device *dev, phys_addr_t paddr, size_t size, int dir)
-{
-       dma_addr_t map;
-       unsigned long align_mask;
-
-       align_mask = (1UL << get_order(size)) - 1;
-       map = dma_map_area(dev, paddr, size, dir, align_mask);
-
-       flush_gart();
-
-       return map;
-}
-
 /* 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)
@@ -287,7 +267,7 @@ gart_map_single(struct device *dev, phys_addr_t paddr, size_t size, int dir)
        if (!need_iommu(dev, paddr, size))
                return paddr;
 
-       bus = dma_map_area(dev, paddr, size, dir, 0);
+       bus = dma_map_area(dev, paddr, size, dir, 0, dma_get_mask(dev));
        flush_gart();
 
        return bus;
@@ -338,6 +318,7 @@ static int dma_map_sg_nonforce(struct device *dev, struct scatterlist *sg,
 {
        struct scatterlist *s;
        int i;
+       u64 dma_mask = dma_get_mask(dev);
 
 #ifdef CONFIG_IOMMU_DEBUG
        printk(KERN_DEBUG "dma_map_sg overflow\n");
@@ -347,7 +328,8 @@ static int dma_map_sg_nonforce(struct device *dev, struct scatterlist *sg,
                unsigned long addr = sg_phys(s);
 
                if (nonforced_iommu(dev, addr, s->length)) {
-                       addr = dma_map_area(dev, addr, s->length, dir, 0);
+                       addr = dma_map_area(dev, addr, s->length, dir, 0,
+                                           dma_mask);
                        if (addr == bad_dma_address) {
                                if (i > 0)
                                        gart_unmap_sg(dev, sg, i, dir);
@@ -369,14 +351,16 @@ static int __dma_map_cont(struct device *dev, struct scatterlist *start,
                          int nelems, struct scatterlist *sout,
                          unsigned long pages)
 {
-       unsigned long iommu_start = alloc_iommu(dev, pages, 0);
-       unsigned long iommu_page = iommu_start;
+       unsigned long iommu_start;
+       unsigned long iommu_page;
        struct scatterlist *s;
        int i;
 
+       iommu_start = alloc_iommu(dev, pages, 0, dma_get_mask(dev));
        if (iommu_start == -1)
                return -1;
 
+       iommu_page = iommu_start;
        for_each_sg(start, s, nelems, i) {
                unsigned long pages, addr;
                unsigned long phys_addr = s->dma_address;
@@ -512,12 +496,26 @@ gart_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_addr,
                    gfp_t flag)
 {
        void *vaddr;
+       dma_addr_t paddr;
+       unsigned long align_mask;
+       u64 dma_mask = dma_alloc_coherent_mask(dev, flag);
 
        vaddr = (void *)__get_free_pages(flag | __GFP_ZERO, get_order(size));
        if (!vaddr)
                return NULL;
 
-       *dma_addr = gart_map_single(dev, __pa(vaddr), size, DMA_BIDIRECTIONAL);
+       paddr = virt_to_phys(vaddr);
+       if (is_buffer_dma_capable(dma_mask, paddr, size)) {
+               *dma_addr = paddr;
+               return vaddr;
+       }
+
+       align_mask = (1UL << get_order(size)) - 1;
+
+       *dma_addr = dma_map_area(dev, paddr, size, DMA_BIDIRECTIONAL,
+                                align_mask, dma_mask);
+       flush_gart();
+
        if (*dma_addr != bad_dma_address)
                return vaddr;
 
@@ -894,10 +892,6 @@ void __init gart_parse_options(char *p)
 #endif
        if (isdigit(*p) && get_option(&p, &arg))
                iommu_size = arg;
-       if (!strncmp(p, "fullflush", 8))
-               iommu_fullflush = 1;
-       if (!strncmp(p, "nofullflush", 11))
-               iommu_fullflush = 0;
        if (!strncmp(p, "noagp", 5))
                no_agp = 1;
        if (!strncmp(p, "noaperture", 10))