1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 21648993fSJoerg Roedel #ifndef __LINUX_SWIOTLB_H 31648993fSJoerg Roedel #define __LINUX_SWIOTLB_H 41648993fSJoerg Roedel 538674442SThierry Reding #include <linux/dma-direction.h> 638674442SThierry Reding #include <linux/init.h> 71648993fSJoerg Roedel #include <linux/types.h> 81648993fSJoerg Roedel 91648993fSJoerg Roedel struct device; 1038674442SThierry Reding struct page; 111648993fSJoerg Roedel struct scatterlist; 121648993fSJoerg Roedel 13ae7871beSGeert Uytterhoeven enum swiotlb_force { 14ae7871beSGeert Uytterhoeven SWIOTLB_NORMAL, /* Default - depending on HW DMA mask etc. */ 15ae7871beSGeert Uytterhoeven SWIOTLB_FORCE, /* swiotlb=force */ 16fff5d992SGeert Uytterhoeven SWIOTLB_NO_FORCE, /* swiotlb=noforce */ 17ae7871beSGeert Uytterhoeven }; 18ae7871beSGeert Uytterhoeven 190016fdeeSIan Campbell /* 200016fdeeSIan Campbell * Maximum allowable number of contiguous slabs to map, 210016fdeeSIan Campbell * must be a power of 2. What is the appropriate value ? 220016fdeeSIan Campbell * The complexity of {map,unmap}_single is linearly dependent on this value. 230016fdeeSIan Campbell */ 240016fdeeSIan Campbell #define IO_TLB_SEGSIZE 128 250016fdeeSIan Campbell 260016fdeeSIan Campbell /* 270016fdeeSIan Campbell * log of the size of each IO TLB slab. The number of slabs is command line 280016fdeeSIan Campbell * controllable. 290016fdeeSIan Campbell */ 300016fdeeSIan Campbell #define IO_TLB_SHIFT 11 310016fdeeSIan Campbell 32ad32e8cbSFUJITA Tomonori extern void swiotlb_init(int verbose); 33ac2cbab2SYinghai Lu int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose); 34f21ffe9fSKonrad Rzeszutek Wilk extern unsigned long swiotlb_nr_tbl(void); 35c729de8fSYinghai Lu unsigned long swiotlb_size_or_default(void); 3674838b75SKonrad Rzeszutek Wilk extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs); 37c7753208STom Lendacky extern void __init swiotlb_update_mem_attributes(void); 381648993fSJoerg Roedel 39d7ef1533SKonrad Rzeszutek Wilk /* 40d7ef1533SKonrad Rzeszutek Wilk * Enumeration for sync targets 41d7ef1533SKonrad Rzeszutek Wilk */ 42d7ef1533SKonrad Rzeszutek Wilk enum dma_sync_target { 43d7ef1533SKonrad Rzeszutek Wilk SYNC_FOR_CPU = 0, 44d7ef1533SKonrad Rzeszutek Wilk SYNC_FOR_DEVICE = 1, 45d7ef1533SKonrad Rzeszutek Wilk }; 46e05ed4d1SAlexander Duyck 47e05ed4d1SAlexander Duyck extern phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, 48e05ed4d1SAlexander Duyck dma_addr_t tbl_dma_addr, 49d7ef1533SKonrad Rzeszutek Wilk phys_addr_t phys, size_t size, 500443fa00SAlexander Duyck enum dma_data_direction dir, 510443fa00SAlexander Duyck unsigned long attrs); 52d7ef1533SKonrad Rzeszutek Wilk 5361ca08c3SAlexander Duyck extern void swiotlb_tbl_unmap_single(struct device *hwdev, 5461ca08c3SAlexander Duyck phys_addr_t tlb_addr, 550443fa00SAlexander Duyck size_t size, enum dma_data_direction dir, 560443fa00SAlexander Duyck unsigned long attrs); 57d7ef1533SKonrad Rzeszutek Wilk 58fbfda893SAlexander Duyck extern void swiotlb_tbl_sync_single(struct device *hwdev, 59fbfda893SAlexander Duyck phys_addr_t tlb_addr, 60d7ef1533SKonrad Rzeszutek Wilk size_t size, enum dma_data_direction dir, 61d7ef1533SKonrad Rzeszutek Wilk enum dma_sync_target target); 62d7ef1533SKonrad Rzeszutek Wilk 631648993fSJoerg Roedel extern int 641648993fSJoerg Roedel swiotlb_dma_supported(struct device *hwdev, u64 mask); 651648993fSJoerg Roedel 665740afdbSFUJITA Tomonori #ifdef CONFIG_SWIOTLB 6755897af6SChristoph Hellwig extern enum swiotlb_force swiotlb_force; 6855897af6SChristoph Hellwig extern phys_addr_t io_tlb_start, io_tlb_end; 6955897af6SChristoph Hellwig 7055897af6SChristoph Hellwig static inline bool is_swiotlb_buffer(phys_addr_t paddr) 7155897af6SChristoph Hellwig { 7255897af6SChristoph Hellwig return paddr >= io_tlb_start && paddr < io_tlb_end; 7355897af6SChristoph Hellwig } 7455897af6SChristoph Hellwig 7555897af6SChristoph Hellwig bool swiotlb_map(struct device *dev, phys_addr_t *phys, dma_addr_t *dma_addr, 7655897af6SChristoph Hellwig size_t size, enum dma_data_direction dir, unsigned long attrs); 7755897af6SChristoph Hellwig void __init swiotlb_exit(void); 787453c549SKonrad Rzeszutek Wilk unsigned int swiotlb_max_segment(void); 79*abe420bfSJoerg Roedel size_t swiotlb_max_mapping_size(struct device *dev); 805740afdbSFUJITA Tomonori #else 8155897af6SChristoph Hellwig #define swiotlb_force SWIOTLB_NO_FORCE 8255897af6SChristoph Hellwig static inline bool is_swiotlb_buffer(phys_addr_t paddr) 8355897af6SChristoph Hellwig { 8455897af6SChristoph Hellwig return false; 8555897af6SChristoph Hellwig } 8655897af6SChristoph Hellwig static inline bool swiotlb_map(struct device *dev, phys_addr_t *phys, 8755897af6SChristoph Hellwig dma_addr_t *dma_addr, size_t size, enum dma_data_direction dir, 8855897af6SChristoph Hellwig unsigned long attrs) 8955897af6SChristoph Hellwig { 9055897af6SChristoph Hellwig return false; 9155897af6SChristoph Hellwig } 9255897af6SChristoph Hellwig static inline void swiotlb_exit(void) 9355897af6SChristoph Hellwig { 9455897af6SChristoph Hellwig } 9555897af6SChristoph Hellwig static inline unsigned int swiotlb_max_segment(void) 9655897af6SChristoph Hellwig { 9755897af6SChristoph Hellwig return 0; 9855897af6SChristoph Hellwig } 99*abe420bfSJoerg Roedel static inline size_t swiotlb_max_mapping_size(struct device *dev) 100*abe420bfSJoerg Roedel { 101*abe420bfSJoerg Roedel return SIZE_MAX; 102*abe420bfSJoerg Roedel } 10355897af6SChristoph Hellwig #endif /* CONFIG_SWIOTLB */ 1045740afdbSFUJITA Tomonori 105ad32e8cbSFUJITA Tomonori extern void swiotlb_print_info(void); 1067453c549SKonrad Rzeszutek Wilk extern void swiotlb_set_max_segment(unsigned int); 1079c5a3621SAkinobu Mita 1081648993fSJoerg Roedel #endif /* __LINUX_SWIOTLB_H */ 109