1 /* $Id: iommu_common.h,v 1.5 2001/12/11 09:41:01 davem Exp $
2 * iommu_common.h: UltraSparc SBUS/PCI common iommu declarations.
4 * Copyright (C) 1999 David S. Miller (davem@redhat.com)
7 #include <linux/kernel.h>
8 #include <linux/types.h>
9 #include <linux/sched.h>
11 #include <linux/scatterlist.h>
12 #include <linux/device.h>
14 #include <asm/iommu.h>
15 #include <asm/scatterlist.h>
18 * These give mapping size of each iommu pte/tlb.
20 #define IO_PAGE_SHIFT 13
21 #define IO_PAGE_SIZE (1UL << IO_PAGE_SHIFT)
22 #define IO_PAGE_MASK (~(IO_PAGE_SIZE-1))
23 #define IO_PAGE_ALIGN(addr) (((addr)+IO_PAGE_SIZE-1)&IO_PAGE_MASK)
25 #define IO_TSB_ENTRIES (128*1024)
26 #define IO_TSB_SIZE (IO_TSB_ENTRIES * 8)
29 * This is the hardwired shift in the iotlb tag/data parts.
31 #define IOMMU_PAGE_SHIFT 13
33 #define SG_ENT_PHYS_ADDRESS(SG) (__pa(sg_virt((SG))))
35 static inline unsigned long iommu_num_pages(unsigned long vaddr,
40 npages = IO_PAGE_ALIGN(vaddr + slen) - (vaddr & IO_PAGE_MASK);
41 npages >>= IO_PAGE_SHIFT;
46 static inline unsigned long calc_npages(struct scatterlist *sglist, int nelems)
48 unsigned long i, npages = 0;
49 struct scatterlist *sg;
51 for_each_sg(sglist, sg, nelems, i) {
52 unsigned long paddr = SG_ENT_PHYS_ADDRESS(sg);
53 npages += iommu_num_pages(paddr, sg->length);