iommu_common.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include <linux/kernel.h>
  7. #include <linux/types.h>
  8. #include <linux/sched.h>
  9. #include <linux/mm.h>
  10. #include <linux/scatterlist.h>
  11. #include <linux/device.h>
  12. #include <asm/iommu.h>
  13. #include <asm/scatterlist.h>
  14. /*
  15. * These give mapping size of each iommu pte/tlb.
  16. */
  17. #define IO_PAGE_SHIFT 13
  18. #define IO_PAGE_SIZE (1UL << IO_PAGE_SHIFT)
  19. #define IO_PAGE_MASK (~(IO_PAGE_SIZE-1))
  20. #define IO_PAGE_ALIGN(addr) (((addr)+IO_PAGE_SIZE-1)&IO_PAGE_MASK)
  21. #define IO_TSB_ENTRIES (128*1024)
  22. #define IO_TSB_SIZE (IO_TSB_ENTRIES * 8)
  23. /*
  24. * This is the hardwired shift in the iotlb tag/data parts.
  25. */
  26. #define IOMMU_PAGE_SHIFT 13
  27. #define SG_ENT_PHYS_ADDRESS(SG) (__pa(sg_virt((SG))))
  28. static inline unsigned long iommu_num_pages(unsigned long vaddr,
  29. unsigned long slen)
  30. {
  31. unsigned long npages;
  32. npages = IO_PAGE_ALIGN(vaddr + slen) - (vaddr & IO_PAGE_MASK);
  33. npages >>= IO_PAGE_SHIFT;
  34. return npages;
  35. }
  36. static inline unsigned long calc_npages(struct scatterlist *sglist, int nelems)
  37. {
  38. unsigned long i, npages = 0;
  39. struct scatterlist *sg;
  40. for_each_sg(sglist, sg, nelems, i) {
  41. unsigned long paddr = SG_ENT_PHYS_ADDRESS(sg);
  42. npages += iommu_num_pages(paddr, sg->length);
  43. }
  44. return npages;
  45. }
  46. /* You are _strongly_ advised to enable the following debugging code
  47. * any time you make changes to the sg code below, run it for a while
  48. * with filesystems mounted read-only before buying the farm... -DaveM
  49. */
  50. #undef VERIFY_SG
  51. #ifdef VERIFY_SG
  52. extern void verify_sglist(struct scatterlist *sg, int nents, iopte_t *iopte, int npages);
  53. #endif
  54. /* Two addresses are "virtually contiguous" if and only if:
  55. * 1) They are equal, or...
  56. * 2) They are both on a page boundary
  57. */
  58. #define VCONTIG(__X, __Y) (((__X) == (__Y)) || \
  59. (((__X) | (__Y)) << (64UL - PAGE_SHIFT)) == 0UL)
  60. extern unsigned long prepare_sg(struct device *dev, struct scatterlist *sg, int nents);