]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/x86/kernel/pci-calgary_64.c
x86: make only GART code include gart.h
[linux-2.6-omap-h63xx.git] / arch / x86 / kernel / pci-calgary_64.c
index 1fe7f043ebdee5d4d94c0b5e8bf0a54cdf87f2e8..151f2d171f7c7386b7a14f574d4c7f34edfab0f3 100644 (file)
 #include <linux/pci.h>
 #include <linux/delay.h>
 #include <linux/scatterlist.h>
-#include <asm/gart.h>
+#include <linux/iommu-helper.h>
+#include <asm/iommu.h>
 #include <asm/calgary.h>
 #include <asm/tce.h>
 #include <asm/pci-direct.h>
 #include <asm/system.h>
 #include <asm/dma.h>
 #include <asm/rio.h>
+#include <asm/bios_ebda.h>
 
 #ifdef CONFIG_CALGARY_IOMMU_ENABLED_BY_DEFAULT
 int use_calgary __read_mostly = 1;
@@ -260,22 +262,28 @@ static void iommu_range_reserve(struct iommu_table *tbl,
        spin_unlock_irqrestore(&tbl->it_lock, flags);
 }
 
-static unsigned long iommu_range_alloc(struct iommu_table *tbl,
-       unsigned int npages)
+static unsigned long iommu_range_alloc(struct device *dev,
+                                      struct iommu_table *tbl,
+                                      unsigned int npages)
 {
        unsigned long flags;
        unsigned long offset;
+       unsigned long boundary_size;
+
+       boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
+                             PAGE_SIZE) >> PAGE_SHIFT;
 
        BUG_ON(npages == 0);
 
        spin_lock_irqsave(&tbl->it_lock, flags);
 
-       offset = find_next_zero_string(tbl->it_map, tbl->it_hint,
-                                      tbl->it_size, npages);
+       offset = iommu_area_alloc(tbl->it_map, tbl->it_size, tbl->it_hint,
+                                 npages, 0, boundary_size, 0);
        if (offset == ~0UL) {
                tbl->chip_ops->tce_cache_blast(tbl);
-               offset = find_next_zero_string(tbl->it_map, 0,
-                                              tbl->it_size, npages);
+
+               offset = iommu_area_alloc(tbl->it_map, tbl->it_size, 0,
+                                         npages, 0, boundary_size, 0);
                if (offset == ~0UL) {
                        printk(KERN_WARNING "Calgary: IOMMU full.\n");
                        spin_unlock_irqrestore(&tbl->it_lock, flags);
@@ -286,7 +294,6 @@ static unsigned long iommu_range_alloc(struct iommu_table *tbl,
                }
        }
 
-       set_bit_string(tbl->it_map, offset, npages);
        tbl->it_hint = offset + npages;
        BUG_ON(tbl->it_hint > tbl->it_size);
 
@@ -295,13 +302,13 @@ static unsigned long iommu_range_alloc(struct iommu_table *tbl,
        return offset;
 }
 
-static dma_addr_t iommu_alloc(struct iommu_table *tbl, void *vaddr,
-       unsigned int npages, int direction)
+static dma_addr_t iommu_alloc(struct device *dev, struct iommu_table *tbl,
+                             void *vaddr, unsigned int npages, int direction)
 {
        unsigned long entry;
        dma_addr_t ret = bad_dma_address;
 
-       entry = iommu_range_alloc(tbl, npages);
+       entry = iommu_range_alloc(dev, tbl, npages);
 
        if (unlikely(entry == bad_dma_address))
                goto error;
@@ -354,7 +361,7 @@ static void iommu_free(struct iommu_table *tbl, dma_addr_t dma_addr,
                               badbit, tbl, dma_addr, entry, npages);
        }
 
-       __clear_bit_string(tbl->it_map, entry, npages);
+       iommu_area_free(tbl->it_map, entry, npages);
 
        spin_unlock_irqrestore(&tbl->it_lock, flags);
 }
@@ -438,7 +445,7 @@ static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
                vaddr = (unsigned long) sg_virt(s);
                npages = num_dma_pages(vaddr, s->length);
 
-               entry = iommu_range_alloc(tbl, npages);
+               entry = iommu_range_alloc(dev, tbl, npages);
                if (entry == bad_dma_address) {
                        /* makes sure unmap knows to stop */
                        s->dma_length = 0;
@@ -464,10 +471,11 @@ error:
        return 0;
 }
 
-static dma_addr_t calgary_map_single(struct device *dev, void *vaddr,
+static dma_addr_t calgary_map_single(struct device *dev, phys_addr_t paddr,
        size_t size, int direction)
 {
        dma_addr_t dma_handle = bad_dma_address;
+       void *vaddr = phys_to_virt(paddr);
        unsigned long uaddr;
        unsigned int npages;
        struct iommu_table *tbl = find_iommu_table(dev);
@@ -476,7 +484,7 @@ static dma_addr_t calgary_map_single(struct device *dev, void *vaddr,
        npages = num_dma_pages(uaddr, size);
 
        if (translation_enabled(tbl))
-               dma_handle = iommu_alloc(tbl, vaddr, npages, direction);
+               dma_handle = iommu_alloc(dev, tbl, vaddr, npages, direction);
        else
                dma_handle = virt_to_bus(vaddr);
 
@@ -516,7 +524,7 @@ static void* calgary_alloc_coherent(struct device *dev, size_t size,
 
        if (translation_enabled(tbl)) {
                /* set up tces to cover the allocated range */
-               mapping = iommu_alloc(tbl, ret, npages, DMA_BIDIRECTIONAL);
+               mapping = iommu_alloc(dev, tbl, ret, npages, DMA_BIDIRECTIONAL);
                if (mapping == bad_dma_address)
                        goto free;
 
@@ -1226,8 +1234,7 @@ static int __init calgary_init(void)
 
 error:
        do {
-               dev = pci_get_device_reverse(PCI_VENDOR_ID_IBM,
-                                            PCI_ANY_ID, dev);
+               dev = pci_get_device(PCI_VENDOR_ID_IBM, PCI_ANY_ID, dev);
                if (!dev)
                        break;
                if (!is_cal_pci_dev(dev->device))
@@ -1387,7 +1394,7 @@ void __init detect_calgary(void)
                return;
        }
 
-       specified_table_size = determine_tce_table_size(end_pfn * PAGE_SIZE);
+       specified_table_size = determine_tce_table_size(max_pfn * PAGE_SIZE);
 
        for (bus = 0; bus < MAX_PHB_BUS_NUM; bus++) {
                struct calgary_bus_info *info = &bus_info[bus];
@@ -1452,7 +1459,7 @@ int __init calgary_iommu_init(void)
        if (ret) {
                printk(KERN_ERR "PCI-DMA: Calgary init failed %d, "
                       "falling back to no_iommu\n", ret);
-               if (end_pfn > MAX_DMA32_PFN)
+               if (max_pfn > MAX_DMA32_PFN)
                        printk(KERN_ERR "WARNING more than 4GB of memory, "
                                        "32bit PCI may malfunction.\n");
                return ret;