Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
| 3 | * |
| 4 | * Copyright (C) 1999 David S. Miller (davem@redhat.com) |
| 5 | */ |
| 6 | |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/types.h> |
| 9 | #include <linux/sched.h> |
| 10 | #include <linux/mm.h> |
FUJITA Tomonori | 24c31ee | 2007-10-17 09:22:14 +0200 | [diff] [blame] | 11 | #include <linux/scatterlist.h> |
FUJITA Tomonori | fde6a3c | 2008-02-04 22:28:02 -0800 | [diff] [blame] | 12 | #include <linux/device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include <asm/iommu.h> |
| 15 | #include <asm/scatterlist.h> |
| 16 | |
| 17 | /* |
| 18 | * These give mapping size of each iommu pte/tlb. |
| 19 | */ |
| 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) |
| 24 | |
| 25 | #define IO_TSB_ENTRIES (128*1024) |
| 26 | #define IO_TSB_SIZE (IO_TSB_ENTRIES * 8) |
| 27 | |
| 28 | /* |
| 29 | * This is the hardwired shift in the iotlb tag/data parts. |
| 30 | */ |
| 31 | #define IOMMU_PAGE_SHIFT 13 |
| 32 | |
David S. Miller | 38192d5 | 2008-02-06 03:50:26 -0800 | [diff] [blame^] | 33 | #define SG_ENT_PHYS_ADDRESS(SG) (__pa(sg_virt((SG)))) |
| 34 | |
| 35 | static inline unsigned long iommu_num_pages(unsigned long vaddr, |
| 36 | unsigned long slen) |
| 37 | { |
| 38 | unsigned long npages; |
| 39 | |
| 40 | npages = IO_PAGE_ALIGN(vaddr + slen) - (vaddr & IO_PAGE_MASK); |
| 41 | npages >>= IO_PAGE_SHIFT; |
| 42 | |
| 43 | return npages; |
| 44 | } |
| 45 | |
| 46 | static inline unsigned long calc_npages(struct scatterlist *sglist, int nelems) |
| 47 | { |
| 48 | unsigned long i, npages = 0; |
| 49 | struct scatterlist *sg; |
| 50 | |
| 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); |
| 54 | } |
| 55 | |
| 56 | return npages; |
| 57 | } |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | /* You are _strongly_ advised to enable the following debugging code |
| 60 | * any time you make changes to the sg code below, run it for a while |
| 61 | * with filesystems mounted read-only before buying the farm... -DaveM |
| 62 | */ |
| 63 | #undef VERIFY_SG |
| 64 | |
| 65 | #ifdef VERIFY_SG |
| 66 | extern void verify_sglist(struct scatterlist *sg, int nents, iopte_t *iopte, int npages); |
| 67 | #endif |
| 68 | |
| 69 | /* Two addresses are "virtually contiguous" if and only if: |
| 70 | * 1) They are equal, or... |
| 71 | * 2) They are both on a page boundary |
| 72 | */ |
| 73 | #define VCONTIG(__X, __Y) (((__X) == (__Y)) || \ |
| 74 | (((__X) | (__Y)) << (64UL - PAGE_SHIFT)) == 0UL) |
| 75 | |
FUJITA Tomonori | fde6a3c | 2008-02-04 22:28:02 -0800 | [diff] [blame] | 76 | extern unsigned long prepare_sg(struct device *dev, struct scatterlist *sg, int nents); |