iommu_common.h 1.4 KB

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