arm64: mte: add in-kernel tag fault handler
[linux-2.6-microblaze.git] / include / linux / swiotlb.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __LINUX_SWIOTLB_H
3 #define __LINUX_SWIOTLB_H
4
5 #include <linux/dma-direction.h>
6 #include <linux/init.h>
7 #include <linux/types.h>
8 #include <linux/limits.h>
9
10 struct device;
11 struct page;
12 struct scatterlist;
13
14 enum swiotlb_force {
15         SWIOTLB_NORMAL,         /* Default - depending on HW DMA mask etc. */
16         SWIOTLB_FORCE,          /* swiotlb=force */
17         SWIOTLB_NO_FORCE,       /* swiotlb=noforce */
18 };
19
20 /*
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.
24  */
25 #define IO_TLB_SEGSIZE  128
26
27 /*
28  * log of the size of each IO TLB slab.  The number of slabs is command line
29  * controllable.
30  */
31 #define IO_TLB_SHIFT 11
32
33 /* default to 64MB */
34 #define IO_TLB_DEFAULT_SIZE (64UL<<20)
35
36 extern void swiotlb_init(int verbose);
37 int swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
38 extern unsigned long swiotlb_nr_tbl(void);
39 unsigned long swiotlb_size_or_default(void);
40 extern int swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs);
41 extern int swiotlb_late_init_with_default_size(size_t default_size);
42 extern void __init swiotlb_update_mem_attributes(void);
43
44 /*
45  * Enumeration for sync targets
46  */
47 enum dma_sync_target {
48         SYNC_FOR_CPU = 0,
49         SYNC_FOR_DEVICE = 1,
50 };
51
52 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys,
53                 size_t mapping_size, size_t alloc_size,
54                 enum dma_data_direction dir, unsigned long attrs);
55
56 extern void swiotlb_tbl_unmap_single(struct device *hwdev,
57                                      phys_addr_t tlb_addr,
58                                      size_t mapping_size,
59                                      size_t alloc_size,
60                                      enum dma_data_direction dir,
61                                      unsigned long attrs);
62
63 extern void swiotlb_tbl_sync_single(struct device *hwdev,
64                                     phys_addr_t tlb_addr,
65                                     size_t size, enum dma_data_direction dir,
66                                     enum dma_sync_target target);
67
68 dma_addr_t swiotlb_map(struct device *dev, phys_addr_t phys,
69                 size_t size, enum dma_data_direction dir, unsigned long attrs);
70
71 #ifdef CONFIG_SWIOTLB
72 extern enum swiotlb_force swiotlb_force;
73 extern phys_addr_t io_tlb_start, io_tlb_end;
74
75 static inline bool is_swiotlb_buffer(phys_addr_t paddr)
76 {
77         return paddr >= io_tlb_start && paddr < io_tlb_end;
78 }
79
80 void __init swiotlb_exit(void);
81 unsigned int swiotlb_max_segment(void);
82 size_t swiotlb_max_mapping_size(struct device *dev);
83 bool is_swiotlb_active(void);
84 void __init swiotlb_adjust_size(unsigned long new_size);
85 #else
86 #define swiotlb_force SWIOTLB_NO_FORCE
87 static inline bool is_swiotlb_buffer(phys_addr_t paddr)
88 {
89         return false;
90 }
91 static inline void swiotlb_exit(void)
92 {
93 }
94 static inline unsigned int swiotlb_max_segment(void)
95 {
96         return 0;
97 }
98 static inline size_t swiotlb_max_mapping_size(struct device *dev)
99 {
100         return SIZE_MAX;
101 }
102
103 static inline bool is_swiotlb_active(void)
104 {
105         return false;
106 }
107
108 static inline void swiotlb_adjust_size(unsigned long new_size)
109 {
110 }
111 #endif /* CONFIG_SWIOTLB */
112
113 extern void swiotlb_print_info(void);
114 extern void swiotlb_set_max_segment(unsigned int);
115
116 #endif /* __LINUX_SWIOTLB_H */