io-pgtable-fast.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2018-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __LINUX_IO_PGTABLE_FAST_H
  6. #define __LINUX_IO_PGTABLE_FAST_H
  7. #include <linux/notifier.h>
  8. #include <linux/io-pgtable.h>
  9. /*
  10. * This ought to be private to io-pgtable-fast, but dma-mapping-fast
  11. * currently requires it for a debug usecase.
  12. */
  13. typedef u64 av8l_fast_iopte;
  14. struct io_pgtable_ops;
  15. struct scatterlist;
  16. struct av8l_fast_io_pgtable {
  17. struct io_pgtable iop;
  18. av8l_fast_iopte *pgd;
  19. av8l_fast_iopte *puds[4];
  20. av8l_fast_iopte *pmds;
  21. struct page **pages; /* page table memory */
  22. int nr_pages;
  23. dma_addr_t base;
  24. dma_addr_t end;
  25. };
  26. /* Struct accessors */
  27. #define iof_pgtable_to_data(x) \
  28. container_of((x), struct av8l_fast_io_pgtable, iop)
  29. #define iof_pgtable_ops_to_pgtable(x) \
  30. container_of((x), struct io_pgtable, ops)
  31. #define iof_pgtable_ops_to_data(x) \
  32. iof_pgtable_to_data(iof_pgtable_ops_to_pgtable(x))
  33. #ifdef CONFIG_IOMMU_IO_PGTABLE_FAST
  34. int av8l_fast_map_public(struct io_pgtable_ops *ops, unsigned long iova,
  35. phys_addr_t paddr, size_t size, int prot);
  36. void av8l_fast_unmap_public(struct io_pgtable_ops *ops, unsigned long iova,
  37. size_t size);
  38. int av8l_fast_map_sg_public(struct io_pgtable_ops *ops,
  39. unsigned long iova, struct scatterlist *sgl,
  40. unsigned int nents, int prot, size_t *size);
  41. bool av8l_fast_iova_coherent_public(struct io_pgtable_ops *ops,
  42. unsigned long iova);
  43. phys_addr_t av8l_fast_iova_to_phys_public(struct io_pgtable_ops *ops,
  44. unsigned long iova);
  45. #else
  46. static inline int
  47. av8l_fast_map_public(struct io_pgtable_ops *ops, unsigned long iova,
  48. phys_addr_t paddr, size_t size, int prot)
  49. {
  50. return -EINVAL;
  51. }
  52. static inline void av8l_fast_unmap_public(struct io_pgtable_ops *ops,
  53. unsigned long iova, size_t size)
  54. {
  55. }
  56. static inline int av8l_fast_map_sg_public(struct io_pgtable_ops *ops,
  57. unsigned long iova, struct scatterlist *sgl,
  58. unsigned int nents, int prot, size_t *size)
  59. {
  60. return 0;
  61. }
  62. static inline bool av8l_fast_iova_coherent_public(struct io_pgtable_ops *ops,
  63. unsigned long iova)
  64. {
  65. return false;
  66. }
  67. static inline phys_addr_t
  68. av8l_fast_iova_to_phys_public(struct io_pgtable_ops *ops,
  69. unsigned long iova)
  70. {
  71. return 0;
  72. }
  73. #endif /* CONFIG_IOMMU_IO_PGTABLE_FAST */
  74. /* events for notifiers passed to av8l_register_notify */
  75. #define MAPPED_OVER_STALE_TLB 1
  76. #ifdef CONFIG_IOMMU_IO_PGTABLE_FAST_PROVE_TLB
  77. /*
  78. * Doesn't matter what we use as long as bit 0 is unset. The reason why we
  79. * need a different value at all is that there are certain hardware
  80. * platforms with erratum that require that a PTE actually be zero'd out
  81. * and not just have its valid bit unset.
  82. */
  83. #define AV8L_FAST_PTE_UNMAPPED_NEED_TLBI 0xa
  84. void av8l_fast_clear_stale_ptes(struct io_pgtable_ops *ops, u64 base, u64 end,
  85. bool skip_sync);
  86. void av8l_register_notify(struct notifier_block *nb);
  87. #else /* !CONFIG_IOMMU_IO_PGTABLE_FAST_PROVE_TLB */
  88. #define AV8L_FAST_PTE_UNMAPPED_NEED_TLBI 0
  89. static inline void av8l_fast_clear_stale_ptes(struct io_pgtable_ops *ops,
  90. u64 base,
  91. u64 end,
  92. bool skip_sync)
  93. {
  94. }
  95. static inline void av8l_register_notify(struct notifier_block *nb)
  96. {
  97. }
  98. #endif /* CONFIG_IOMMU_IO_PGTABLE_FAST_PROVE_TLB */
  99. #endif /* __LINUX_IO_PGTABLE_FAST_H */