1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_SWIOTLB_H
3 #define __LINUX_SWIOTLB_H
5 #include <linux/dma-direction.h>
6 #include <linux/init.h>
7 #include <linux/types.h>
8 #include <linux/limits.h>
15 SWIOTLB_NORMAL, /* Default - depending on HW DMA mask etc. */
16 SWIOTLB_FORCE, /* swiotlb=force */
17 SWIOTLB_NO_FORCE, /* swiotlb=noforce */
21 * Maximum allowable number of contiguous slabs to map,
22 * must be a power of 2. What is the appropriate value ?
23 * The complexity of {map,unmap}_single is linearly dependent on this value.
25 #define IO_TLB_SEGSIZE 128
28 * log of the size of each IO TLB slab. The number of slabs is command line
31 #define IO_TLB_SHIFT 11
32 #define IO_TLB_SIZE (1 << IO_TLB_SHIFT)
35 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
37 extern void swiotlb_init(int verbose);
38 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
39 extern unsigned long swiotlb_nr_tbl(void);
40 unsigned long swiotlb_size_or_default(void);
41 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
42 extern int swiotlb_late_init_with_default_size(size_t default_size);
43 extern void __init swiotlb_update_mem_attributes(void);
46 * Enumeration for sync targets
48 enum dma_sync_target {
53 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
54 size_t mapping_size, size_t alloc_size,
55 enum dma_data_direction dir, unsigned long attrs);
57 extern void swiotlb_tbl_unmap_single(struct device *hwdev,
61 enum dma_data_direction dir,
64 extern void swiotlb_tbl_sync_single(struct device *hwdev,
66 size_t size, enum dma_data_direction dir,
67 enum dma_sync_target target);
69 dma_addr_t swiotlb_map(struct device *dev, phys_addr_t phys,
70 size_t size, enum dma_data_direction dir, unsigned long attrs);
73 extern enum swiotlb_force swiotlb_force;
74 extern phys_addr_t io_tlb_start, io_tlb_end;
76 static inline bool is_swiotlb_buffer(phys_addr_t paddr)
78 return paddr >= io_tlb_start && paddr < io_tlb_end;
81 void __init swiotlb_exit(void);
82 unsigned int swiotlb_max_segment(void);
83 size_t swiotlb_max_mapping_size(struct device *dev);
84 bool is_swiotlb_active(void);
85 void __init swiotlb_adjust_size(unsigned long new_size);
87 #define swiotlb_force SWIOTLB_NO_FORCE
88 static inline bool is_swiotlb_buffer(phys_addr_t paddr)
92 static inline void swiotlb_exit(void)
95 static inline unsigned int swiotlb_max_segment(void)
99 static inline size_t swiotlb_max_mapping_size(struct device *dev)
104 static inline bool is_swiotlb_active(void)
109 static inline void swiotlb_adjust_size(unsigned long new_size)
112 #endif /* CONFIG_SWIOTLB */
114 extern void swiotlb_print_info(void);
115 extern void swiotlb_set_max_segment(unsigned int);
117 #endif /* __LINUX_SWIOTLB_H */