swiotlb.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_SWIOTLB_H
  3. #define __LINUX_SWIOTLB_H
  4. #include <linux/dma-direction.h>
  5. #include <linux/init.h>
  6. #include <linux/types.h>
  7. #include <linux/limits.h>
  8. struct device;
  9. struct page;
  10. struct scatterlist;
  11. enum swiotlb_force {
  12. SWIOTLB_NORMAL, /* Default - depending on HW DMA mask etc. */
  13. SWIOTLB_FORCE, /* swiotlb=force */
  14. SWIOTLB_NO_FORCE, /* swiotlb=noforce */
  15. };
  16. /*
  17. * Maximum allowable number of contiguous slabs to map,
  18. * must be a power of 2. What is the appropriate value ?
  19. * The complexity of {map,unmap}_single is linearly dependent on this value.
  20. */
  21. #define IO_TLB_SEGSIZE 128
  22. /*
  23. * log of the size of each IO TLB slab. The number of slabs is command line
  24. * controllable.
  25. */
  26. #define IO_TLB_SHIFT 11
  27. #define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
  28. extern void swiotlb_init(int verbose);
  29. int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
  30. extern unsigned long swiotlb_nr_tbl(void);
  31. unsigned long swiotlb_size_or_default(void);
  32. extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
  33. extern int swiotlb_late_init_with_default_size(size_t default_size);
  34. extern void __init swiotlb_update_mem_attributes(void);
  35. /*
  36. * Enumeration for sync targets
  37. */
  38. enum dma_sync_target {
  39. SYNC_FOR_CPU = 0,
  40. SYNC_FOR_DEVICE = 1,
  41. };
  42. phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
  43. size_t mapping_size, size_t alloc_size,
  44. enum dma_data_direction dir, unsigned long attrs);
  45. extern void swiotlb_tbl_unmap_single(struct device *hwdev,
  46. phys_addr_t tlb_addr,
  47. size_t mapping_size,
  48. size_t alloc_size,
  49. enum dma_data_direction dir,
  50. unsigned long attrs);
  51. extern void swiotlb_tbl_sync_single(struct device *hwdev,
  52. phys_addr_t tlb_addr,
  53. size_t size, enum dma_data_direction dir,
  54. enum dma_sync_target target);
  55. dma_addr_t swiotlb_map(struct device *dev, phys_addr_t phys,
  56. size_t size, enum dma_data_direction dir, unsigned long attrs);
  57. #ifdef CONFIG_SWIOTLB
  58. extern enum swiotlb_force swiotlb_force;
  59. extern phys_addr_t io_tlb_start, io_tlb_end;
  60. static inline bool is_swiotlb_buffer(phys_addr_t paddr)
  61. {
  62. return paddr >= io_tlb_start && paddr < io_tlb_end;
  63. }
  64. void __init swiotlb_exit(void);
  65. unsigned int swiotlb_max_segment(void);
  66. size_t swiotlb_max_mapping_size(struct device *dev);
  67. bool is_swiotlb_active(void);
  68. #else
  69. #define swiotlb_force SWIOTLB_NO_FORCE
  70. static inline bool is_swiotlb_buffer(phys_addr_t paddr)
  71. {
  72. return false;
  73. }
  74. static inline void swiotlb_exit(void)
  75. {
  76. }
  77. static inline unsigned int swiotlb_max_segment(void)
  78. {
  79. return 0;
  80. }
  81. static inline size_t swiotlb_max_mapping_size(struct device *dev)
  82. {
  83. return SIZE_MAX;
  84. }
  85. static inline bool is_swiotlb_active(void)
  86. {
  87. return false;
  88. }
  89. #endif /* CONFIG_SWIOTLB */
  90. extern void swiotlb_print_info(void);
  91. extern void swiotlb_set_max_segment(unsigned int);
  92. #endif /* __LINUX_SWIOTLB_H */