--- zzzz-none-000/linux-2.6.19.2/arch/powerpc/kernel/iommu.c 2007-01-10 19:10:37.000000000 +0000 +++ davinci-8020-5504/linux-2.6.19.2/arch/powerpc/kernel/iommu.c 2007-01-11 07:38:19.000000000 +0000 @@ -47,17 +47,6 @@ static int novmerge = 1; #endif -static inline unsigned long iommu_num_pages(unsigned long vaddr, - unsigned long slen) -{ - unsigned long npages; - - npages = IOMMU_PAGE_ALIGN(vaddr + slen) - (vaddr & IOMMU_PAGE_MASK); - npages >>= IOMMU_PAGE_SHIFT; - - return npages; -} - static int __init setup_iommu(char *str) { if (!strcmp(str, "novmerge")) @@ -189,10 +178,10 @@ } entry += tbl->it_offset; /* Offset into real TCE table */ - ret = entry << IOMMU_PAGE_SHIFT; /* Set the return dma address */ + ret = entry << PAGE_SHIFT; /* Set the return dma address */ /* Put the TCEs in the HW table */ - ppc_md.tce_build(tbl, entry, npages, (unsigned long)page & IOMMU_PAGE_MASK, + ppc_md.tce_build(tbl, entry, npages, (unsigned long)page & PAGE_MASK, direction); @@ -214,7 +203,7 @@ unsigned long entry, free_entry; unsigned long i; - entry = dma_addr >> IOMMU_PAGE_SHIFT; + entry = dma_addr >> PAGE_SHIFT; free_entry = entry - tbl->it_offset; if (((free_entry + npages) > tbl->it_size) || @@ -281,7 +270,7 @@ /* Init first segment length for backout at failure */ outs->dma_length = 0; - DBG("sg mapping %d elements:\n", nelems); + DBG("mapping %d elements:\n", nelems); spin_lock_irqsave(&(tbl->it_lock), flags); @@ -296,8 +285,9 @@ } /* Allocate iommu entries for that segment */ vaddr = (unsigned long)page_address(s->page) + s->offset; - npages = iommu_num_pages(vaddr, slen); - entry = iommu_range_alloc(tbl, npages, &handle, mask >> IOMMU_PAGE_SHIFT, 0); + npages = PAGE_ALIGN(vaddr + slen) - (vaddr & PAGE_MASK); + npages >>= PAGE_SHIFT; + entry = iommu_range_alloc(tbl, npages, &handle, mask >> PAGE_SHIFT, 0); DBG(" - vaddr: %lx, size: %lx\n", vaddr, slen); @@ -311,14 +301,14 @@ /* Convert entry to a dma_addr_t */ entry += tbl->it_offset; - dma_addr = entry << IOMMU_PAGE_SHIFT; - dma_addr |= (s->offset & ~IOMMU_PAGE_MASK); + dma_addr = entry << PAGE_SHIFT; + dma_addr |= s->offset; - DBG(" - %lu pages, entry: %lx, dma_addr: %lx\n", + DBG(" - %lx pages, entry: %lx, dma_addr: %lx\n", npages, entry, dma_addr); /* Insert into HW table */ - ppc_md.tce_build(tbl, entry, npages, vaddr & IOMMU_PAGE_MASK, direction); + ppc_md.tce_build(tbl, entry, npages, vaddr & PAGE_MASK, direction); /* If we are in an open segment, try merging */ if (segstart != s) { @@ -333,7 +323,7 @@ DBG(" can't merge, new segment.\n"); } else { outs->dma_length += s->length; - DBG(" merged, new len: %ux\n", outs->dma_length); + DBG(" merged, new len: %lx\n", outs->dma_length); } } @@ -377,8 +367,9 @@ if (s->dma_length != 0) { unsigned long vaddr, npages; - vaddr = s->dma_address & IOMMU_PAGE_MASK; - npages = iommu_num_pages(s->dma_address, s->dma_length); + vaddr = s->dma_address & PAGE_MASK; + npages = (PAGE_ALIGN(s->dma_address + s->dma_length) - vaddr) + >> PAGE_SHIFT; __iommu_free(tbl, vaddr, npages); s->dma_address = DMA_ERROR_CODE; s->dma_length = 0; @@ -407,7 +398,8 @@ if (sglist->dma_length == 0) break; - npages = iommu_num_pages(dma_handle,sglist->dma_length); + npages = (PAGE_ALIGN(dma_handle + sglist->dma_length) + - (dma_handle & PAGE_MASK)) >> PAGE_SHIFT; __iommu_free(tbl, dma_handle, npages); sglist++; } @@ -540,11 +532,12 @@ BUG_ON(direction == DMA_NONE); uaddr = (unsigned long)vaddr; - npages = iommu_num_pages(uaddr, size); + npages = PAGE_ALIGN(uaddr + size) - (uaddr & PAGE_MASK); + npages >>= PAGE_SHIFT; if (tbl) { dma_handle = iommu_alloc(tbl, vaddr, npages, direction, - mask >> IOMMU_PAGE_SHIFT, 0); + mask >> PAGE_SHIFT, 0); if (dma_handle == DMA_ERROR_CODE) { if (printk_ratelimit()) { printk(KERN_INFO "iommu_alloc failed, " @@ -552,7 +545,7 @@ tbl, vaddr, npages); } } else - dma_handle |= (uaddr & ~IOMMU_PAGE_MASK); + dma_handle |= (uaddr & ~PAGE_MASK); } return dma_handle; @@ -561,14 +554,11 @@ void iommu_unmap_single(struct iommu_table *tbl, dma_addr_t dma_handle, size_t size, enum dma_data_direction direction) { - unsigned int npages; - BUG_ON(direction == DMA_NONE); - if (tbl) { - npages = iommu_num_pages(dma_handle, size); - iommu_free(tbl, dma_handle, npages); - } + if (tbl) + iommu_free(tbl, dma_handle, (PAGE_ALIGN(dma_handle + size) - + (dma_handle & PAGE_MASK)) >> PAGE_SHIFT); } /* Allocates a contiguous real buffer and creates mappings over it. @@ -580,11 +570,11 @@ { void *ret = NULL; dma_addr_t mapping; - unsigned int order; - unsigned int nio_pages, io_order; + unsigned int npages, order; struct page *page; size = PAGE_ALIGN(size); + npages = size >> PAGE_SHIFT; order = get_order(size); /* @@ -608,10 +598,8 @@ memset(ret, 0, size); /* Set up tces to cover the allocated range */ - nio_pages = size >> IOMMU_PAGE_SHIFT; - io_order = get_iommu_order(size); - mapping = iommu_alloc(tbl, ret, nio_pages, DMA_BIDIRECTIONAL, - mask >> IOMMU_PAGE_SHIFT, io_order); + mapping = iommu_alloc(tbl, ret, npages, DMA_BIDIRECTIONAL, + mask >> PAGE_SHIFT, order); if (mapping == DMA_ERROR_CODE) { free_pages((unsigned long)ret, order); return NULL; @@ -623,13 +611,12 @@ void iommu_free_coherent(struct iommu_table *tbl, size_t size, void *vaddr, dma_addr_t dma_handle) { - if (tbl) { - unsigned int nio_pages; + unsigned int npages; + if (tbl) { size = PAGE_ALIGN(size); - nio_pages = size >> IOMMU_PAGE_SHIFT; - iommu_free(tbl, dma_handle, nio_pages); - size = PAGE_ALIGN(size); + npages = size >> PAGE_SHIFT; + iommu_free(tbl, dma_handle, npages); free_pages((unsigned long)vaddr, get_order(size)); } }