io-pgtable.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef __IO_PGTABLE_H
  2. #define __IO_PGTABLE_H
  3. /*
  4. * Public API for use by IOMMU drivers
  5. */
  6. enum io_pgtable_fmt {
  7. ARM_32_LPAE_S1,
  8. ARM_32_LPAE_S2,
  9. ARM_64_LPAE_S1,
  10. ARM_64_LPAE_S2,
  11. IO_PGTABLE_NUM_FMTS,
  12. };
  13. /**
  14. * struct iommu_gather_ops - IOMMU callbacks for TLB and page table management.
  15. *
  16. * @tlb_flush_all: Synchronously invalidate the entire TLB context.
  17. * @tlb_add_flush: Queue up a TLB invalidation for a virtual address range.
  18. * @tlb_sync: Ensure any queue TLB invalidation has taken effect.
  19. * @flush_pgtable: Ensure page table updates are visible to the IOMMU.
  20. *
  21. * Note that these can all be called in atomic context and must therefore
  22. * not block.
  23. */
  24. struct iommu_gather_ops {
  25. void (*tlb_flush_all)(void *cookie);
  26. void (*tlb_add_flush)(unsigned long iova, size_t size, bool leaf,
  27. void *cookie);
  28. void (*tlb_sync)(void *cookie);
  29. void (*flush_pgtable)(void *ptr, size_t size, void *cookie);
  30. };
  31. /**
  32. * struct io_pgtable_cfg - Configuration data for a set of page tables.
  33. *
  34. * @quirks: A bitmap of hardware quirks that require some special
  35. * action by the low-level page table allocator.
  36. * @pgsize_bitmap: A bitmap of page sizes supported by this set of page
  37. * tables.
  38. * @ias: Input address (iova) size, in bits.
  39. * @oas: Output address (paddr) size, in bits.
  40. * @tlb: TLB management callbacks for this set of tables.
  41. */
  42. struct io_pgtable_cfg {
  43. #define IO_PGTABLE_QUIRK_ARM_NS (1 << 0) /* Set NS bit in PTEs */
  44. int quirks;
  45. unsigned long pgsize_bitmap;
  46. unsigned int ias;
  47. unsigned int oas;
  48. const struct iommu_gather_ops *tlb;
  49. /* Low-level data specific to the table format */
  50. union {
  51. struct {
  52. u64 ttbr[2];
  53. u64 tcr;
  54. u64 mair[2];
  55. } arm_lpae_s1_cfg;
  56. struct {
  57. u64 vttbr;
  58. u64 vtcr;
  59. } arm_lpae_s2_cfg;
  60. };
  61. };
  62. /**
  63. * struct io_pgtable_ops - Page table manipulation API for IOMMU drivers.
  64. *
  65. * @map: Map a physically contiguous memory region.
  66. * @unmap: Unmap a physically contiguous memory region.
  67. * @iova_to_phys: Translate iova to physical address.
  68. *
  69. * These functions map directly onto the iommu_ops member functions with
  70. * the same names.
  71. */
  72. struct io_pgtable_ops {
  73. int (*map)(struct io_pgtable_ops *ops, unsigned long iova,
  74. phys_addr_t paddr, size_t size, int prot);
  75. int (*unmap)(struct io_pgtable_ops *ops, unsigned long iova,
  76. size_t size);
  77. phys_addr_t (*iova_to_phys)(struct io_pgtable_ops *ops,
  78. unsigned long iova);
  79. };
  80. /**
  81. * alloc_io_pgtable_ops() - Allocate a page table allocator for use by an IOMMU.
  82. *
  83. * @fmt: The page table format.
  84. * @cfg: The page table configuration. This will be modified to represent
  85. * the configuration actually provided by the allocator (e.g. the
  86. * pgsize_bitmap may be restricted).
  87. * @cookie: An opaque token provided by the IOMMU driver and passed back to
  88. * the callback routines in cfg->tlb.
  89. */
  90. struct io_pgtable_ops *alloc_io_pgtable_ops(enum io_pgtable_fmt fmt,
  91. struct io_pgtable_cfg *cfg,
  92. void *cookie);
  93. /**
  94. * free_io_pgtable_ops() - Free an io_pgtable_ops structure. The caller
  95. * *must* ensure that the page table is no longer
  96. * live, but the TLB can be dirty.
  97. *
  98. * @ops: The ops returned from alloc_io_pgtable_ops.
  99. */
  100. void free_io_pgtable_ops(struct io_pgtable_ops *ops);
  101. /*
  102. * Internal structures for page table allocator implementations.
  103. */
  104. /**
  105. * struct io_pgtable - Internal structure describing a set of page tables.
  106. *
  107. * @fmt: The page table format.
  108. * @cookie: An opaque token provided by the IOMMU driver and passed back to
  109. * any callback routines.
  110. * @cfg: A copy of the page table configuration.
  111. * @ops: The page table operations in use for this set of page tables.
  112. */
  113. struct io_pgtable {
  114. enum io_pgtable_fmt fmt;
  115. void *cookie;
  116. struct io_pgtable_cfg cfg;
  117. struct io_pgtable_ops ops;
  118. };
  119. /**
  120. * struct io_pgtable_init_fns - Alloc/free a set of page tables for a
  121. * particular format.
  122. *
  123. * @alloc: Allocate a set of page tables described by cfg.
  124. * @free: Free the page tables associated with iop.
  125. */
  126. struct io_pgtable_init_fns {
  127. struct io_pgtable *(*alloc)(struct io_pgtable_cfg *cfg, void *cookie);
  128. void (*free)(struct io_pgtable *iop);
  129. };
  130. #endif /* __IO_PGTABLE_H */