iommu_table.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _ASM_X86_IOMMU_TABLE_H
  2. #define _ASM_X86_IOMMU_TABLE_H
  3. #include <asm/swiotlb.h>
  4. /*
  5. * History lesson:
  6. * The execution chain of IOMMUs in 2.6.36 looks as so:
  7. *
  8. * [xen-swiotlb]
  9. * |
  10. * +----[swiotlb *]--+
  11. * / | \
  12. * / | \
  13. * [GART] [Calgary] [Intel VT-d]
  14. * /
  15. * /
  16. * [AMD-Vi]
  17. *
  18. * *: if SWIOTLB detected 'iommu=soft'/'swiotlb=force' it would skip
  19. * over the rest of IOMMUs and unconditionally initialize the SWIOTLB.
  20. * Also it would surreptitiously initialize set the swiotlb=1 if there were
  21. * more than 4GB and if the user did not pass in 'iommu=off'. The swiotlb
  22. * flag would be turned off by all IOMMUs except the Calgary one.
  23. *
  24. * The IOMMU_INIT* macros allow a similar tree (or more complex if desired)
  25. * to be built by defining who we depend on.
  26. *
  27. * And all that needs to be done is to use one of the macros in the IOMMU
  28. * and the pci-dma.c will take care of the rest.
  29. */
  30. struct iommu_table_entry {
  31. initcall_t detect;
  32. initcall_t depend;
  33. void (*early_init)(void); /* No memory allocate available. */
  34. void (*late_init)(void); /* Yes, can allocate memory. */
  35. #define IOMMU_FINISH_IF_DETECTED (1<<0)
  36. #define IOMMU_DETECTED (1<<1)
  37. int flags;
  38. };
  39. /*
  40. * Macro fills out an entry in the .iommu_table that is equivalent
  41. * to the fields that 'struct iommu_table_entry' has. The entries
  42. * that are put in the .iommu_table section are not put in any order
  43. * hence during boot-time we will have to resort them based on
  44. * dependency. */
  45. #define __IOMMU_INIT(_detect, _depend, _early_init, _late_init, _finish)\
  46. static const struct iommu_table_entry const \
  47. __iommu_entry_##_detect __used \
  48. __attribute__ ((unused, __section__(".iommu_table"), \
  49. aligned((sizeof(void *))))) \
  50. = {_detect, _depend, _early_init, _late_init, \
  51. _finish ? IOMMU_FINISH_IF_DETECTED : 0}
  52. /*
  53. * The simplest IOMMU definition. Provide the detection routine
  54. * and it will be run after the SWIOTLB and the other IOMMUs
  55. * that utilize this macro. If the IOMMU is detected (ie, the
  56. * detect routine returns a positive value), the other IOMMUs
  57. * are also checked. You can use IOMMU_INIT_POST_FINISH if you prefer
  58. * to stop detecting the other IOMMUs after yours has been detected.
  59. */
  60. #define IOMMU_INIT_POST(_detect) \
  61. __IOMMU_INIT(_detect, pci_swiotlb_detect_4gb, 0, 0, 0)
  62. #define IOMMU_INIT_POST_FINISH(detect) \
  63. __IOMMU_INIT(_detect, pci_swiotlb_detect_4gb, 0, 0, 1)
  64. /*
  65. * A more sophisticated version of IOMMU_INIT. This variant requires:
  66. * a). A detection routine function.
  67. * b). The name of the detection routine we depend on to get called
  68. * before us.
  69. * c). The init routine which gets called if the detection routine
  70. * returns a positive value from the pci_iommu_alloc. This means
  71. * no presence of a memory allocator.
  72. * d). Similar to the 'init', except that this gets called from pci_iommu_init
  73. * where we do have a memory allocator.
  74. *
  75. * The standard IOMMU_INIT differs from the IOMMU_INIT_FINISH variant
  76. * in that the former will continue detecting other IOMMUs in the call
  77. * list after the detection routine returns a positive number, while the
  78. * latter will stop the execution chain upon first successful detection.
  79. * Both variants will still call the 'init' and 'late_init' functions if
  80. * they are set.
  81. */
  82. #define IOMMU_INIT_FINISH(_detect, _depend, _init, _late_init) \
  83. __IOMMU_INIT(_detect, _depend, _init, _late_init, 1)
  84. #define IOMMU_INIT(_detect, _depend, _init, _late_init) \
  85. __IOMMU_INIT(_detect, _depend, _init, _late_init, 0)
  86. void sort_iommu_table(struct iommu_table_entry *start,
  87. struct iommu_table_entry *finish);
  88. void check_iommu_entries(struct iommu_table_entry *start,
  89. struct iommu_table_entry *finish);
  90. #endif /* _ASM_X86_IOMMU_TABLE_H */