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 67*55897af6SChristoph Hellwig extern enum swiotlb_force swiotlb_force; 68*55897af6SChristoph Hellwig extern phys_addr_t io_tlb_start, io_tlb_end; 69*55897af6SChristoph Hellwig 70*55897af6SChristoph Hellwig static inline bool is_swiotlb_buffer(phys_addr_t paddr) 71*55897af6SChristoph Hellwig { 72*55897af6SChristoph Hellwig return paddr >= io_tlb_start && paddr < io_tlb_end; 73*55897af6SChristoph Hellwig } 74*55897af6SChristoph Hellwig 75*55897af6SChristoph Hellwig bool swiotlb_map(struct device *dev, phys_addr_t *phys, dma_addr_t *dma_addr, 76*55897af6SChristoph Hellwig size_t size, enum dma_data_direction dir, unsigned long attrs); 77*55897af6SChristoph Hellwig void __init swiotlb_exit(void); 787453c549SKonrad Rzeszutek Wilk unsigned int swiotlb_max_segment(void); 795740afdbSFUJITA Tomonori #else 80*55897af6SChristoph Hellwig #define swiotlb_force SWIOTLB_NO_FORCE 81*55897af6SChristoph Hellwig static inline bool is_swiotlb_buffer(phys_addr_t paddr) 82*55897af6SChristoph Hellwig { 83*55897af6SChristoph Hellwig return false; 84*55897af6SChristoph Hellwig } 85*55897af6SChristoph Hellwig static inline bool swiotlb_map(struct device *dev, phys_addr_t *phys, 86*55897af6SChristoph Hellwig dma_addr_t *dma_addr, size_t size, enum dma_data_direction dir, 87*55897af6SChristoph Hellwig unsigned long attrs) 88*55897af6SChristoph Hellwig { 89*55897af6SChristoph Hellwig return false; 90*55897af6SChristoph Hellwig } 91*55897af6SChristoph Hellwig static inline void swiotlb_exit(void) 92*55897af6SChristoph Hellwig { 93*55897af6SChristoph Hellwig } 94*55897af6SChristoph Hellwig static inline unsigned int swiotlb_max_segment(void) 95*55897af6SChristoph Hellwig { 96*55897af6SChristoph Hellwig return 0; 97*55897af6SChristoph Hellwig } 98*55897af6SChristoph Hellwig #endif /* CONFIG_SWIOTLB */ 995740afdbSFUJITA Tomonori 100ad32e8cbSFUJITA Tomonori extern void swiotlb_print_info(void); 1017453c549SKonrad Rzeszutek Wilk extern void swiotlb_set_max_segment(unsigned int); 1029c5a3621SAkinobu Mita 1031648993fSJoerg Roedel #endif /* __LINUX_SWIOTLB_H */ 104