Merge branch 'linux-2.6'
[powerpc.git] / arch / sparc64 / kernel / iommu.c
index 5d4e96d..070a484 100644 (file)
@@ -472,15 +472,13 @@ static void dma_4u_unmap_single(struct device *dev, dma_addr_t bus_addr,
        spin_unlock_irqrestore(&iommu->lock, flags);
 }
 
-#define SG_ENT_PHYS_ADDRESS(SG)        \
-       (__pa(page_address((SG)->page)) + (SG)->offset)
+#define SG_ENT_PHYS_ADDRESS(SG)        (__pa(sg_virt((SG))))
 
-static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
-                          int nused, int nelems,
-                          unsigned long iopte_protection)
+static void fill_sg(iopte_t *iopte, struct scatterlist *sg,
+                   int nused, int nelems,
+                   unsigned long iopte_protection)
 {
        struct scatterlist *dma_sg = sg;
-       struct scatterlist *sg_end = sg_last(sg, nelems);
        int i;
 
        for (i = 0; i < nused; i++) {
@@ -516,6 +514,7 @@ static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
                                        break;
                                }
                                sg = sg_next(sg);
+                               nelems--;
                        }
 
                        pteval = iopte_protection | (pteval & IOPTE_PAGE);
@@ -529,18 +528,20 @@ static inline void fill_sg(iopte_t *iopte, struct scatterlist *sg,
 
                        pteval = (pteval & IOPTE_PAGE) + len;
                        sg = sg_next(sg);
+                       nelems--;
 
                        /* Skip over any tail mappings we've fully mapped,
                         * adjusting pteval along the way.  Stop when we
                         * detect a page crossing event.
                         */
-                       while (sg != sg_end &&
+                       while (nelems &&
                               (pteval << (64 - IO_PAGE_SHIFT)) != 0UL &&
                               (pteval == SG_ENT_PHYS_ADDRESS(sg)) &&
                               ((pteval ^
                                 (SG_ENT_PHYS_ADDRESS(sg) + sg->length - 1UL)) >> IO_PAGE_SHIFT) == 0UL) {
                                pteval += sg->length;
                                sg = sg_next(sg);
+                               nelems--;
                        }
                        if ((pteval << (64 - IO_PAGE_SHIFT)) == 0UL)
                                pteval = ~0UL;
@@ -563,9 +564,7 @@ static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
        /* Fast path single entry scatterlists. */
        if (nelems == 1) {
                sglist->dma_address =
-                       dma_4u_map_single(dev,
-                                         (page_address(sglist->page) +
-                                          sglist->offset),
+                       dma_4u_map_single(dev, sg_virt(sglist),
                                          sglist->length, direction);
                if (unlikely(sglist->dma_address == DMA_ERROR_CODE))
                        return 0;