[SPARC64]: iommu_common.h tidy ups...
[cascardo/linux.git] / arch / sparc64 / kernel / iommu_common.h
1 /* iommu_common.h: UltraSparc SBUS/PCI common iommu declarations.
2  *
3  * Copyright (C) 1999, 2008 David S. Miller (davem@davemloft.net)
4  */
5
6 #ifndef _IOMMU_COMMON_H
7 #define _IOMMU_COMMON_H
8
9 #include <linux/kernel.h>
10 #include <linux/types.h>
11 #include <linux/sched.h>
12 #include <linux/mm.h>
13 #include <linux/scatterlist.h>
14 #include <linux/device.h>
15
16 #include <asm/iommu.h>
17 #include <asm/scatterlist.h>
18
19 /*
20  * These give mapping size of each iommu pte/tlb.
21  */
22 #define IO_PAGE_SHIFT                   13
23 #define IO_PAGE_SIZE                    (1UL << IO_PAGE_SHIFT)
24 #define IO_PAGE_MASK                    (~(IO_PAGE_SIZE-1))
25 #define IO_PAGE_ALIGN(addr)             (((addr)+IO_PAGE_SIZE-1)&IO_PAGE_MASK)
26
27 #define IO_TSB_ENTRIES                  (128*1024)
28 #define IO_TSB_SIZE                     (IO_TSB_ENTRIES * 8)
29
30 /*
31  * This is the hardwired shift in the iotlb tag/data parts.
32  */
33 #define IOMMU_PAGE_SHIFT                13
34
35 #define SG_ENT_PHYS_ADDRESS(SG) (__pa(sg_virt((SG))))
36
37 static inline unsigned long iommu_num_pages(unsigned long vaddr,
38                                             unsigned long slen)
39 {
40         unsigned long npages;
41
42         npages = IO_PAGE_ALIGN(vaddr + slen) - (vaddr & IO_PAGE_MASK);
43         npages >>= IO_PAGE_SHIFT;
44
45         return npages;
46 }
47
48 static inline unsigned long calc_npages(struct scatterlist *sglist, int nelems)
49 {
50         unsigned long i, npages = 0;
51         struct scatterlist *sg;
52
53         for_each_sg(sglist, sg, nelems, i) {
54                 unsigned long paddr = SG_ENT_PHYS_ADDRESS(sg);
55                 npages += iommu_num_pages(paddr, sg->length);
56         }
57
58         return npages;
59 }
60
61 #endif /* _IOMMU_COMMON_H */