nfs: nfs4xdr: encode_compound_hdr does not have to round up reserved bytes
[safe/jmp/linux-2.6] / arch / x86 / kernel / pci-calgary_64.c
index 363a74e..971a3be 100644 (file)
@@ -186,47 +186,6 @@ static struct cal_chipset_ops calioc2_chip_ops = {
 
 static struct calgary_bus_info bus_info[MAX_PHB_BUS_NUM] = { { NULL, 0, 0 }, };
 
-/* enable this to stress test the chip's TCE cache */
-#ifdef CONFIG_IOMMU_DEBUG
-static int debugging = 1;
-
-static inline unsigned long verify_bit_range(unsigned long* bitmap,
-       int expected, unsigned long start, unsigned long end)
-{
-       unsigned long idx = start;
-
-       BUG_ON(start >= end);
-
-       while (idx < end) {
-               if (!!test_bit(idx, bitmap) != expected)
-                       return idx;
-               ++idx;
-       }
-
-       /* all bits have the expected value */
-       return ~0UL;
-}
-#else /* debugging is disabled */
-static int debugging;
-
-static inline unsigned long verify_bit_range(unsigned long* bitmap,
-       int expected, unsigned long start, unsigned long end)
-{
-       return ~0UL;
-}
-
-#endif /* CONFIG_IOMMU_DEBUG */
-
-static inline unsigned int num_dma_pages(unsigned long dma, unsigned int dmalen)
-{
-       unsigned int npages;
-
-       npages = PAGE_ALIGN(dma + dmalen) - (dma & PAGE_MASK);
-       npages >>= PAGE_SHIFT;
-
-       return npages;
-}
-
 static inline int translation_enabled(struct iommu_table *tbl)
 {
        /* only PHBs with translation enabled have an IOMMU table */
@@ -238,7 +197,6 @@ static void iommu_range_reserve(struct iommu_table *tbl,
 {
        unsigned long index;
        unsigned long end;
-       unsigned long badbit;
        unsigned long flags;
 
        index = start_addr >> PAGE_SHIFT;
@@ -253,15 +211,7 @@ static void iommu_range_reserve(struct iommu_table *tbl,
 
        spin_lock_irqsave(&tbl->it_lock, flags);
 
-       badbit = verify_bit_range(tbl->it_map, 0, index, end);
-       if (badbit != ~0UL) {
-               if (printk_ratelimit())
-                       printk(KERN_ERR "Calgary: entry already allocated at "
-                              "0x%lx tbl %p dma 0x%lx npages %u\n",
-                              badbit, tbl, start_addr, npages);
-       }
-
-       set_bit_string(tbl->it_map, index, npages);
+       iommu_area_reserve(tbl->it_map, index, npages);
 
        spin_unlock_irqrestore(&tbl->it_lock, flags);
 }
@@ -336,16 +286,14 @@ static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
        unsigned int npages)
 {
        unsigned long entry;
-       unsigned long badbit;
        unsigned long badend;
        unsigned long flags;
 
        /* were we called with bad_dma_address? */
        badend = bad_dma_address + (EMERGENCY_PAGES * PAGE_SIZE);
        if (unlikely((dma_addr >= bad_dma_address) && (dma_addr < badend))) {
-               printk(KERN_ERR "Calgary: driver tried unmapping bad DMA "
+               WARN(1, KERN_ERR "Calgary: driver tried unmapping bad DMA "
                       "address 0x%Lx\n", dma_addr);
-               WARN_ON(1);
                return;
        }
 
@@ -357,14 +305,6 @@ static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
 
        spin_lock_irqsave(&tbl->it_lock, flags);
 
-       badbit = verify_bit_range(tbl->it_map, 1, entry, entry + npages);
-       if (badbit != ~0UL) {
-               if (printk_ratelimit())
-                       printk(KERN_ERR "Calgary: bit is off at 0x%lx "
-                              "tbl %p dma 0x%Lx entry 0x%lx npages %u\n",
-                              badbit, tbl, dma_addr, entry, npages);
-       }
-
        iommu_area_free(tbl->it_map, entry, npages);
 
        spin_unlock_irqrestore(&tbl->it_lock, flags);
@@ -391,8 +331,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;
@@ -409,13 +350,14 @@ static void calgary_unmap_sg(struct device *dev,
                if (dmalen == 0)
                        break;
 
-               npages = num_dma_pages(dma, dmalen);
+               npages = iommu_num_pages(dma, dmalen, PAGE_SIZE);
                iommu_free(tbl, dma, npages);
        }
 }
 
 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;
@@ -428,7 +370,7 @@ static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
                BUG_ON(!sg_page(s));
 
                vaddr = (unsigned long) sg_virt(s);
-               npages = num_dma_pages(vaddr, s->length);
+               npages = iommu_num_pages(vaddr, s->length, PAGE_SIZE);
 
                entry = iommu_range_alloc(dev, tbl, npages);
                if (entry == bad_dma_address) {
@@ -440,15 +382,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;
@@ -456,28 +397,31 @@ 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);
 
        uaddr = (unsigned long)vaddr;
-       npages = num_dma_pages(uaddr, size);
+       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 = num_dma_pages(dma_handle, 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,
@@ -492,6 +436,8 @@ static void* calgary_alloc_coherent(struct device *dev, size_t size,
        npages = size >> PAGE_SHIFT;
        order = get_order(size);
 
+       flag &= ~(__GFP_DMA | __GFP_HIGHMEM | __GFP_DMA32);
+
        /* alloc enough pages (and possibly more) */
        ret = (void *)__get_free_pages(flag, order);
        if (!ret)
@@ -511,12 +457,26 @@ error:
        return ret;
 }
 
-static struct dma_mapping_ops calgary_dma_ops = {
+static void calgary_free_coherent(struct device *dev, size_t size,
+                                 void *vaddr, dma_addr_t dma_handle)
+{
+       unsigned int npages;
+       struct iommu_table *tbl = find_iommu_table(dev);
+
+       size = PAGE_ALIGN(size);
+       npages = size >> PAGE_SHIFT;
+
+       iommu_free(tbl, dma_handle, npages);
+       free_pages((unsigned long)vaddr, get_order(size));
+}
+
+static struct dma_map_ops calgary_dma_ops = {
        .alloc_coherent = calgary_alloc_coherent,
-       .map_single = calgary_map_single,
-       .unmap_single = calgary_unmap_single,
+       .free_coherent = calgary_free_coherent,
        .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)
@@ -1479,9 +1439,8 @@ void __init detect_calgary(void)
                iommu_detected = 1;
                calgary_detected = 1;
                printk(KERN_INFO "PCI-DMA: Calgary IOMMU detected.\n");
-               printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d, "
-                      "CONFIG_IOMMU_DEBUG is %s.\n", specified_table_size,
-                      debugging ? "enabled" : "disabled");
+               printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d\n",
+                      specified_table_size);
 
                /* swiotlb for devices that aren't behind the Calgary. */
                if (max_pfn > MAX_DMA32_PFN)
@@ -1562,7 +1521,7 @@ static int __init calgary_parse_options(char *p)
                                ++p;
                        if (*p == '\0')
                                break;
-                       bridge = simple_strtol(p, &endp, 0);
+                       bridge = simple_strtoul(p, &endp, 0);
                        if (p == endp)
                                break;