Skip to content

Commit

Permalink
sparc64: use iommu_num_pages function in IOMMU code
Browse files Browse the repository at this point in the history
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Acked-by: David S. Miller <davem@davemloft.net>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Muli Ben-Yehuda <muli@il.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Joerg Roedel authored and Linus Torvalds committed Oct 16, 2008
1 parent eb117d3 commit 0fcff28
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
7 changes: 4 additions & 3 deletions arch/sparc64/kernel/iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
}
/* Allocate iommu entries for that segment */
paddr = (unsigned long) SG_ENT_PHYS_ADDRESS(s);
npages = iommu_nr_pages(paddr, slen);
npages = iommu_num_pages(paddr, slen, IO_PAGE_SIZE);
entry = iommu_range_alloc(dev, iommu, npages, &handle);

/* Handle failure */
Expand Down Expand Up @@ -647,7 +647,8 @@ static int dma_4u_map_sg(struct device *dev, struct scatterlist *sglist,
iopte_t *base;

vaddr = s->dma_address & IO_PAGE_MASK;
npages = iommu_nr_pages(s->dma_address, s->dma_length);
npages = iommu_num_pages(s->dma_address, s->dma_length,
IO_PAGE_SIZE);
iommu_range_free(iommu, vaddr, npages);

entry = (vaddr - iommu->page_table_map_base)
Expand Down Expand Up @@ -715,7 +716,7 @@ static void dma_4u_unmap_sg(struct device *dev, struct scatterlist *sglist,

if (!len)
break;
npages = iommu_nr_pages(dma_handle, len);
npages = iommu_num_pages(dma_handle, len, IO_PAGE_SIZE);
iommu_range_free(iommu, dma_handle, npages);

entry = ((dma_handle - iommu->page_table_map_base)
Expand Down
14 changes: 2 additions & 12 deletions arch/sparc64/kernel/iommu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,15 @@

#define SG_ENT_PHYS_ADDRESS(SG) (__pa(sg_virt((SG))))

static inline unsigned long iommu_nr_pages(unsigned long vaddr,
unsigned long slen)
{
unsigned long npages;

npages = IO_PAGE_ALIGN(vaddr + slen) - (vaddr & IO_PAGE_MASK);
npages >>= IO_PAGE_SHIFT;

return npages;
}

static inline int is_span_boundary(unsigned long entry,
unsigned long shift,
unsigned long boundary_size,
struct scatterlist *outs,
struct scatterlist *sg)
{
unsigned long paddr = SG_ENT_PHYS_ADDRESS(outs);
int nr = iommu_nr_pages(paddr, outs->dma_length + sg->length);
int nr = iommu_num_pages(paddr, outs->dma_length + sg->length,
IO_PAGE_SIZE);

return iommu_is_span_boundary(entry, nr, shift, boundary_size);
}
Expand Down
7 changes: 4 additions & 3 deletions arch/sparc64/kernel/pci_sun4v.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
}
/* Allocate iommu entries for that segment */
paddr = (unsigned long) SG_ENT_PHYS_ADDRESS(s);
npages = iommu_nr_pages(paddr, slen);
npages = iommu_num_pages(paddr, slen, IO_PAGE_SIZE);
entry = iommu_range_alloc(dev, iommu, npages, &handle);

/* Handle failure */
Expand Down Expand Up @@ -461,7 +461,8 @@ static int dma_4v_map_sg(struct device *dev, struct scatterlist *sglist,
unsigned long vaddr, npages;

vaddr = s->dma_address & IO_PAGE_MASK;
npages = iommu_nr_pages(s->dma_address, s->dma_length);
npages = iommu_num_pages(s->dma_address, s->dma_length,
IO_PAGE_SIZE);
iommu_range_free(iommu, vaddr, npages);
/* XXX demap? XXX */
s->dma_address = DMA_ERROR_CODE;
Expand Down Expand Up @@ -500,7 +501,7 @@ static void dma_4v_unmap_sg(struct device *dev, struct scatterlist *sglist,

if (!len)
break;
npages = iommu_nr_pages(dma_handle, len);
npages = iommu_num_pages(dma_handle, len, IO_PAGE_SIZE);
iommu_range_free(iommu, dma_handle, npages);

entry = ((dma_handle - iommu->page_table_map_base) >> IO_PAGE_SHIFT);
Expand Down

0 comments on commit 0fcff28

Please sign in to comment.