swiotlb.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef __LINUX_SWIOTLB_H
  2. #define __LINUX_SWIOTLB_H
  3. #include <linux/types.h>
  4. struct device;
  5. struct dma_attrs;
  6. struct scatterlist;
  7. extern int swiotlb_force;
  8. /*
  9. * Maximum allowable number of contiguous slabs to map,
  10. * must be a power of 2. What is the appropriate value ?
  11. * The complexity of {map,unmap}_single is linearly dependent on this value.
  12. */
  13. #define IO_TLB_SEGSIZE 128
  14. /*
  15. * log of the size of each IO TLB slab. The number of slabs is command line
  16. * controllable.
  17. */
  18. #define IO_TLB_SHIFT 11
  19. extern void swiotlb_init(int verbose);
  20. int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
  21. extern unsigned long swiotlb_nr_tbl(void);
  22. unsigned long swiotlb_size_or_default(void);
  23. extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
  24. /*
  25. * Enumeration for sync targets
  26. */
  27. enum dma_sync_target {
  28. SYNC_FOR_CPU = 0,
  29. SYNC_FOR_DEVICE = 1,
  30. };
  31. /* define the last possible byte of physical address space as a mapping error */
  32. #define SWIOTLB_MAP_ERROR (~(phys_addr_t)0x0)
  33. extern phys_addr_t swiotlb_tbl_map_single(struct device *hwdev,
  34. dma_addr_t tbl_dma_addr,
  35. phys_addr_t phys, size_t size,
  36. enum dma_data_direction dir);
  37. extern void swiotlb_tbl_unmap_single(struct device *hwdev,
  38. phys_addr_t tlb_addr,
  39. size_t size, enum dma_data_direction dir);
  40. extern void swiotlb_tbl_sync_single(struct device *hwdev,
  41. phys_addr_t tlb_addr,
  42. size_t size, enum dma_data_direction dir,
  43. enum dma_sync_target target);
  44. /* Accessory functions. */
  45. extern void
  46. *swiotlb_alloc_coherent(struct device *hwdev, size_t size,
  47. dma_addr_t *dma_handle, gfp_t flags);
  48. extern void
  49. swiotlb_free_coherent(struct device *hwdev, size_t size,
  50. void *vaddr, dma_addr_t dma_handle);
  51. extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
  52. unsigned long offset, size_t size,
  53. enum dma_data_direction dir,
  54. struct dma_attrs *attrs);
  55. extern void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,
  56. size_t size, enum dma_data_direction dir,
  57. struct dma_attrs *attrs);
  58. extern int
  59. swiotlb_map_sg(struct device *hwdev, struct scatterlist *sg, int nents,
  60. enum dma_data_direction dir);
  61. extern void
  62. swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
  63. enum dma_data_direction dir);
  64. extern int
  65. swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,
  66. enum dma_data_direction dir, struct dma_attrs *attrs);
  67. extern void
  68. swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
  69. int nelems, enum dma_data_direction dir,
  70. struct dma_attrs *attrs);
  71. extern void
  72. swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
  73. size_t size, enum dma_data_direction dir);
  74. extern void
  75. swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
  76. int nelems, enum dma_data_direction dir);
  77. extern void
  78. swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
  79. size_t size, enum dma_data_direction dir);
  80. extern void
  81. swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
  82. int nelems, enum dma_data_direction dir);
  83. extern int
  84. swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr);
  85. extern int
  86. swiotlb_dma_supported(struct device *hwdev, u64 mask);
  87. #ifdef CONFIG_SWIOTLB
  88. extern void __init swiotlb_free(void);
  89. #else
  90. static inline void swiotlb_free(void) { }
  91. #endif
  92. extern void swiotlb_print_info(void);
  93. #endif /* __LINUX_SWIOTLB_H */