swiotlb.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. extern void swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
  21. extern unsigned long swiotlb_nr_tbl(void);
  22. extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
  23. /*
  24. * Enumeration for sync targets
  25. */
  26. enum dma_sync_target {
  27. SYNC_FOR_CPU = 0,
  28. SYNC_FOR_DEVICE = 1,
  29. };
  30. extern void *swiotlb_tbl_map_single(struct device *hwdev, dma_addr_t tbl_dma_addr,
  31. phys_addr_t phys, size_t size,
  32. enum dma_data_direction dir);
  33. extern void swiotlb_tbl_unmap_single(struct device *hwdev, char *dma_addr,
  34. size_t size, enum dma_data_direction dir);
  35. extern void swiotlb_tbl_sync_single(struct device *hwdev, char *dma_addr,
  36. size_t size, enum dma_data_direction dir,
  37. enum dma_sync_target target);
  38. /* Accessory functions. */
  39. extern void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size,
  40. enum dma_data_direction dir);
  41. extern void
  42. *swiotlb_alloc_coherent(struct device *hwdev, size_t size,
  43. dma_addr_t *dma_handle, gfp_t flags);
  44. extern void
  45. swiotlb_free_coherent(struct device *hwdev, size_t size,
  46. void *vaddr, dma_addr_t dma_handle);
  47. extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
  48. unsigned long offset, size_t size,
  49. enum dma_data_direction dir,
  50. struct dma_attrs *attrs);
  51. extern void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,
  52. size_t size, enum dma_data_direction dir,
  53. struct dma_attrs *attrs);
  54. extern int
  55. swiotlb_map_sg(struct device *hwdev, struct scatterlist *sg, int nents,
  56. enum dma_data_direction dir);
  57. extern void
  58. swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
  59. enum dma_data_direction dir);
  60. extern int
  61. swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,
  62. enum dma_data_direction dir, struct dma_attrs *attrs);
  63. extern void
  64. swiotlb_unmap_sg_attrs(struct device *hwdev, struct scatterlist *sgl,
  65. int nelems, enum dma_data_direction dir,
  66. struct dma_attrs *attrs);
  67. extern void
  68. swiotlb_sync_single_for_cpu(struct device *hwdev, dma_addr_t dev_addr,
  69. size_t size, enum dma_data_direction dir);
  70. extern void
  71. swiotlb_sync_sg_for_cpu(struct device *hwdev, struct scatterlist *sg,
  72. int nelems, enum dma_data_direction dir);
  73. extern void
  74. swiotlb_sync_single_for_device(struct device *hwdev, dma_addr_t dev_addr,
  75. size_t size, enum dma_data_direction dir);
  76. extern void
  77. swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
  78. int nelems, enum dma_data_direction dir);
  79. extern int
  80. swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr);
  81. extern int
  82. swiotlb_dma_supported(struct device *hwdev, u64 mask);
  83. #ifdef CONFIG_SWIOTLB
  84. extern void __init swiotlb_free(void);
  85. #else
  86. static inline void swiotlb_free(void) { }
  87. #endif
  88. extern void swiotlb_print_info(void);
  89. #endif /* __LINUX_SWIOTLB_H */