]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/x86/kernel/pci-calgary_64.c
Update arch/ to use sg helpers
[linux-2.6-omap-h63xx.git] / arch / x86 / kernel / pci-calgary_64.c
index 71da01e73f038162fe955181baad38f16de1126e..1a20fe31338b18ea302d5ac035fd521d458bd6e7 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/pci_ids.h>
 #include <linux/pci.h>
 #include <linux/delay.h>
+#include <linux/scatterlist.h>
 #include <asm/iommu.h>
 #include <asm/calgary.h>
 #include <asm/tce.h>
@@ -221,10 +222,10 @@ static inline unsigned int num_dma_pages(unsigned long dma, unsigned int dmalen)
        return npages;
 }
 
-static inline int translate_phb(struct pci_dev* dev)
+static inline int translation_enabled(struct iommu_table *tbl)
 {
-       int disabled = bus_info[dev->bus->number].translation_disabled;
-       return !disabled;
+       /* only PHBs with translation enabled have an IOMMU table */
+       return (tbl != NULL);
 }
 
 static void iommu_range_reserve(struct iommu_table *tbl,
@@ -384,33 +385,36 @@ static void calgary_unmap_sg(struct device *dev,
        struct scatterlist *sglist, int nelems, int direction)
 {
        struct iommu_table *tbl = find_iommu_table(dev);
+       struct scatterlist *s;
+       int i;
 
-       if (!translate_phb(to_pci_dev(dev)))
+       if (!translation_enabled(tbl))
                return;
 
-       while (nelems--) {
+       for_each_sg(sglist, s, nelems, i) {
                unsigned int npages;
-               dma_addr_t dma = sglist->dma_address;
-               unsigned int dmalen = sglist->dma_length;
+               dma_addr_t dma = s->dma_address;
+               unsigned int dmalen = s->dma_length;
 
                if (dmalen == 0)
                        break;
 
                npages = num_dma_pages(dma, dmalen);
                iommu_free(tbl, dma, npages);
-               sglist++;
        }
 }
 
 static int calgary_nontranslate_map_sg(struct device* dev,
        struct scatterlist *sg, int nelems, int direction)
 {
+       struct scatterlist *s;
        int i;
 
-       for (i = 0; i < nelems; i++ ) {
-               struct scatterlist *s = &sg[i];
-               BUG_ON(!s->page);
-               s->dma_address = virt_to_bus(page_address(s->page) +s->offset);
+       for_each_sg(sg, s, nelems, i) {
+               struct page *p = sg_page(s);
+
+               BUG_ON(!p);
+               s->dma_address = virt_to_bus(sg_virt(s));
                s->dma_length = s->length;
        }
        return nelems;
@@ -420,19 +424,19 @@ static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
        int nelems, int direction)
 {
        struct iommu_table *tbl = find_iommu_table(dev);
+       struct scatterlist *s;
        unsigned long vaddr;
        unsigned int npages;
        unsigned long entry;
        int i;
 
-       if (!translate_phb(to_pci_dev(dev)))
+       if (!translation_enabled(tbl))
                return calgary_nontranslate_map_sg(dev, sg, nelems, direction);
 
-       for (i = 0; i < nelems; i++ ) {
-               struct scatterlist *s = &sg[i];
-               BUG_ON(!s->page);
+       for_each_sg(sg, s, nelems, i) {
+               BUG_ON(!sg_page(s));
 
-               vaddr = (unsigned long)page_address(s->page) + s->offset;
+               vaddr = (unsigned long) sg_virt(s);
                npages = num_dma_pages(vaddr, s->length);
 
                entry = iommu_range_alloc(tbl, npages);
@@ -454,9 +458,9 @@ static int calgary_map_sg(struct device *dev, struct scatterlist *sg,
        return nelems;
 error:
        calgary_unmap_sg(dev, sg, nelems, direction);
-       for (i = 0; i < nelems; i++) {
-               sg[i].dma_address = bad_dma_address;
-               sg[i].dma_length = 0;
+       for_each_sg(sg, s, nelems, i) {
+               sg->dma_address = bad_dma_address;
+               sg->dma_length = 0;
        }
        return 0;
 }
@@ -472,7 +476,7 @@ static dma_addr_t calgary_map_single(struct device *dev, void *vaddr,
        uaddr = (unsigned long)vaddr;
        npages = num_dma_pages(uaddr, size);
 
-       if (translate_phb(to_pci_dev(dev)))
+       if (translation_enabled(tbl))
                dma_handle = iommu_alloc(tbl, vaddr, npages, direction);
        else
                dma_handle = virt_to_bus(vaddr);
@@ -486,7 +490,7 @@ static void calgary_unmap_single(struct device *dev, dma_addr_t dma_handle,
        struct iommu_table *tbl = find_iommu_table(dev);
        unsigned int npages;
 
-       if (!translate_phb(to_pci_dev(dev)))
+       if (!translation_enabled(tbl))
                return;
 
        npages = num_dma_pages(dma_handle, size);
@@ -511,7 +515,7 @@ static void* calgary_alloc_coherent(struct device *dev, size_t size,
                goto error;
        memset(ret, 0, size);
 
-       if (translate_phb(to_pci_dev(dev))) {
+       if (translation_enabled(tbl)) {
                /* set up tces to cover the allocated range */
                mapping = iommu_alloc(tbl, ret, npages, DMA_BIDIRECTIONAL);
                if (mapping == bad_dma_address)
@@ -1192,7 +1196,7 @@ static int __init calgary_init(void)
 {
        int ret;
        struct pci_dev *dev = NULL;
-       void *tce_space;
+       struct calgary_bus_info *info;
 
        ret = calgary_locate_bbars();
        if (ret)
@@ -1204,12 +1208,14 @@ static int __init calgary_init(void)
                        break;
                if (!is_cal_pci_dev(dev->device))
                        continue;
-               if (!translate_phb(dev)) {
+
+               info = &bus_info[dev->bus->number];
+               if (info->translation_disabled) {
                        calgary_init_one_nontraslated(dev);
                        continue;
                }
-               tce_space = bus_info[dev->bus->number].tce_space;
-               if (!tce_space && !translate_empty_slots)
+
+               if (!info->tce_space && !translate_empty_slots)
                        continue;
 
                ret = calgary_init_one(dev);
@@ -1227,11 +1233,13 @@ error:
                        break;
                if (!is_cal_pci_dev(dev->device))
                        continue;
-               if (!translate_phb(dev)) {
+
+               info = &bus_info[dev->bus->number];
+               if (info->translation_disabled) {
                        pci_dev_put(dev);
                        continue;
                }
-               if (!bus_info[dev->bus->number].tce_space && !translate_empty_slots)
+               if (!info->tce_space && !translate_empty_slots)
                        continue;
 
                calgary_disable_translation(dev);
@@ -1544,7 +1552,7 @@ static void __init calgary_fixup_one_tce_space(struct pci_dev *dev)
 static int __init calgary_fixup_tce_spaces(void)
 {
        struct pci_dev *dev = NULL;
-       void *tce_space;
+       struct calgary_bus_info *info;
 
        if (no_iommu || swiotlb || !calgary_detected)
                return -ENODEV;
@@ -1557,11 +1565,12 @@ static int __init calgary_fixup_tce_spaces(void)
                        break;
                if (!is_cal_pci_dev(dev->device))
                        continue;
-               if (!translate_phb(dev))
+
+               info = &bus_info[dev->bus->number];
+               if (info->translation_disabled)
                        continue;
 
-               tce_space = bus_info[dev->bus->number].tce_space;
-               if (!tce_space)
+               if (!info->tce_space)
                        continue;
 
                calgary_fixup_one_tce_space(dev);