@@ -42,24 +42,6 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
4242 int (* remap )(void * tlb , unsigned long nslabs ));
4343extern void __init swiotlb_update_mem_attributes (void );
4444
45- phys_addr_t swiotlb_tbl_map_single (struct device * hwdev , phys_addr_t phys ,
46- size_t mapping_size ,
47- unsigned int alloc_aligned_mask , enum dma_data_direction dir ,
48- unsigned long attrs );
49-
50- extern void swiotlb_tbl_unmap_single (struct device * hwdev ,
51- phys_addr_t tlb_addr ,
52- size_t mapping_size ,
53- enum dma_data_direction dir ,
54- unsigned long attrs );
55-
56- void swiotlb_sync_single_for_device (struct device * dev , phys_addr_t tlb_addr ,
57- size_t size , enum dma_data_direction dir );
58- void swiotlb_sync_single_for_cpu (struct device * dev , phys_addr_t tlb_addr ,
59- size_t size , enum dma_data_direction dir );
60- dma_addr_t swiotlb_map (struct device * dev , phys_addr_t phys ,
61- size_t size , enum dma_data_direction dir , unsigned long attrs );
62-
6345#ifdef CONFIG_SWIOTLB
6446
6547/**
@@ -143,37 +125,27 @@ struct io_tlb_mem {
143125#endif
144126};
145127
146- #ifdef CONFIG_SWIOTLB_DYNAMIC
147-
148- struct io_tlb_pool * swiotlb_find_pool (struct device * dev , phys_addr_t paddr );
149-
150- #else
151-
152- static inline struct io_tlb_pool * swiotlb_find_pool (struct device * dev ,
153- phys_addr_t paddr )
154- {
155- return & dev -> dma_io_tlb_mem -> defpool ;
156- }
157-
158- #endif
128+ struct io_tlb_pool * __swiotlb_find_pool (struct device * dev , phys_addr_t paddr );
159129
160130/**
161- * is_swiotlb_buffer () - check if a physical address belongs to a swiotlb
131+ * swiotlb_find_pool () - find swiotlb pool to which a physical address belongs
162132 * @dev: Device which has mapped the buffer.
163133 * @paddr: Physical address within the DMA buffer.
164134 *
165- * Check if @paddr points into a bounce buffer .
135+ * Find the swiotlb pool that @paddr points into.
166136 *
167137 * Return:
168- * * %true if @paddr points into a bounce buffer
169- * * %false otherwise
138+ * * pool address if @paddr points into a bounce buffer
139+ * * NULL if @paddr does not point into a bounce buffer. As such, this function
140+ * can be used to determine if @paddr denotes a swiotlb bounce buffer.
170141 */
171- static inline bool is_swiotlb_buffer (struct device * dev , phys_addr_t paddr )
142+ static inline struct io_tlb_pool * swiotlb_find_pool (struct device * dev ,
143+ phys_addr_t paddr )
172144{
173145 struct io_tlb_mem * mem = dev -> dma_io_tlb_mem ;
174146
175147 if (!mem )
176- return false ;
148+ return NULL ;
177149
178150#ifdef CONFIG_SWIOTLB_DYNAMIC
179151 /*
@@ -182,16 +154,19 @@ static inline bool is_swiotlb_buffer(struct device *dev, phys_addr_t paddr)
182154 * If a SWIOTLB address is checked on another CPU, then it was
183155 * presumably loaded by the device driver from an unspecified private
184156 * data structure. Make sure that this load is ordered before reading
185- * dev->dma_uses_io_tlb here and mem->pools in swiotlb_find_pool ().
157+ * dev->dma_uses_io_tlb here and mem->pools in __swiotlb_find_pool ().
186158 *
187159 * This barrier pairs with smp_mb() in swiotlb_find_slots().
188160 */
189161 smp_rmb ();
190- return READ_ONCE (dev -> dma_uses_io_tlb ) &&
191- swiotlb_find_pool (dev , paddr );
162+ if ( READ_ONCE (dev -> dma_uses_io_tlb ))
163+ return __swiotlb_find_pool (dev , paddr );
192164#else
193- return paddr >= mem -> defpool .start && paddr < mem -> defpool .end ;
165+ if (paddr >= mem -> defpool .start && paddr < mem -> defpool .end )
166+ return & mem -> defpool ;
194167#endif
168+
169+ return NULL ;
195170}
196171
197172static inline bool is_swiotlb_force_bounce (struct device * dev )
@@ -219,9 +194,10 @@ static inline void swiotlb_dev_init(struct device *dev)
219194{
220195}
221196
222- static inline bool is_swiotlb_buffer (struct device * dev , phys_addr_t paddr )
197+ static inline struct io_tlb_pool * swiotlb_find_pool (struct device * dev ,
198+ phys_addr_t paddr )
223199{
224- return false ;
200+ return NULL ;
225201}
226202static inline bool is_swiotlb_force_bounce (struct device * dev )
227203{
@@ -260,6 +236,49 @@ static inline phys_addr_t default_swiotlb_limit(void)
260236}
261237#endif /* CONFIG_SWIOTLB */
262238
239+ phys_addr_t swiotlb_tbl_map_single (struct device * hwdev , phys_addr_t phys ,
240+ size_t mapping_size , unsigned int alloc_aligned_mask ,
241+ enum dma_data_direction dir , unsigned long attrs );
242+ dma_addr_t swiotlb_map (struct device * dev , phys_addr_t phys ,
243+ size_t size , enum dma_data_direction dir , unsigned long attrs );
244+
245+ void __swiotlb_tbl_unmap_single (struct device * hwdev , phys_addr_t tlb_addr ,
246+ size_t mapping_size , enum dma_data_direction dir ,
247+ unsigned long attrs , struct io_tlb_pool * pool );
248+ static inline void swiotlb_tbl_unmap_single (struct device * dev ,
249+ phys_addr_t addr , size_t size , enum dma_data_direction dir ,
250+ unsigned long attrs )
251+ {
252+ struct io_tlb_pool * pool = swiotlb_find_pool (dev , addr );
253+
254+ if (unlikely (pool ))
255+ __swiotlb_tbl_unmap_single (dev , addr , size , dir , attrs , pool );
256+ }
257+
258+ void __swiotlb_sync_single_for_device (struct device * dev , phys_addr_t tlb_addr ,
259+ size_t size , enum dma_data_direction dir ,
260+ struct io_tlb_pool * pool );
261+ static inline void swiotlb_sync_single_for_device (struct device * dev ,
262+ phys_addr_t addr , size_t size , enum dma_data_direction dir )
263+ {
264+ struct io_tlb_pool * pool = swiotlb_find_pool (dev , addr );
265+
266+ if (unlikely (pool ))
267+ __swiotlb_sync_single_for_device (dev , addr , size , dir , pool );
268+ }
269+
270+ void __swiotlb_sync_single_for_cpu (struct device * dev , phys_addr_t tlb_addr ,
271+ size_t size , enum dma_data_direction dir ,
272+ struct io_tlb_pool * pool );
273+ static inline void swiotlb_sync_single_for_cpu (struct device * dev ,
274+ phys_addr_t addr , size_t size , enum dma_data_direction dir )
275+ {
276+ struct io_tlb_pool * pool = swiotlb_find_pool (dev , addr );
277+
278+ if (unlikely (pool ))
279+ __swiotlb_sync_single_for_cpu (dev , addr , size , dir , pool );
280+ }
281+
263282extern void swiotlb_print_info (void );
264283
265284#ifdef CONFIG_DMA_RESTRICTED_POOL
0 commit comments