xref: /freebsd/sys/arm64/include/bus_dma.h (revision 7937bfbc0ca53fe7cdd0d54414f9296e273a518e)
1 
2 #ifndef _MACHINE_BUS_DMA_H_
3 #define	_MACHINE_BUS_DMA_H_
4 
5 #define WANT_INLINE_DMAMAP
6 #include <sys/bus_dma.h>
7 
8 #include <machine/bus_dma_impl.h>
9 
10 /*
11  * Is DMA address 1:1 mapping of physical address
12  */
13 static inline bool
14 bus_dma_id_mapped(bus_dma_tag_t dmat, vm_paddr_t buf, bus_size_t buflen)
15 {
16 	struct bus_dma_tag_common *tc;
17 
18 	tc = (struct bus_dma_tag_common *)dmat;
19 	return (tc->impl->id_mapped(dmat, buf, buflen));
20 }
21 
22 /*
23  * Allocate a handle for mapping from kva/uva/physical
24  * address space into bus device space.
25  */
26 static inline int
27 bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
28 {
29 	struct bus_dma_tag_common *tc;
30 
31 	tc = (struct bus_dma_tag_common *)dmat;
32 	return (tc->impl->map_create(dmat, flags, mapp));
33 }
34 
35 /*
36  * Destroy a handle for mapping from kva/uva/physical
37  * address space into bus device space.
38  */
39 static inline int
40 bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
41 {
42 	struct bus_dma_tag_common *tc;
43 
44 	tc = (struct bus_dma_tag_common *)dmat;
45 	return (tc->impl->map_destroy(dmat, map));
46 }
47 
48 /*
49  * Allocate a piece of memory that can be efficiently mapped into
50  * bus device space based on the constraints listed in the dma tag.
51  * A dmamap to for use with dmamap_load is also allocated.
52  */
53 static inline int
54 bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
55     bus_dmamap_t *mapp)
56 {
57 	struct bus_dma_tag_common *tc;
58 
59 	tc = (struct bus_dma_tag_common *)dmat;
60 	return (tc->impl->mem_alloc(dmat, vaddr, flags, mapp));
61 }
62 
63 /*
64  * Free a piece of memory and it's allociated dmamap, that was allocated
65  * via bus_dmamem_alloc.
66  */
67 static inline void
68 bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
69 {
70 	struct bus_dma_tag_common *tc;
71 
72 	tc = (struct bus_dma_tag_common *)dmat;
73 	tc->impl->mem_free(dmat, vaddr, map);
74 }
75 
76 /*
77  * Release the mapping held by map.
78  */
79 static inline void
80 bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
81 {
82 	struct bus_dma_tag_common *tc;
83 
84 	tc = (struct bus_dma_tag_common *)dmat;
85 	tc->impl->map_unload(dmat, map);
86 }
87 
88 static inline void
89 bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
90 {
91 	struct bus_dma_tag_common *tc;
92 
93 	tc = (struct bus_dma_tag_common *)dmat;
94 	tc->impl->map_sync(dmat, map, op);
95 }
96 
97 static inline int
98 _bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf,
99     bus_size_t buflen, int flags, bus_dma_segment_t *segs, int *segp)
100 {
101 	struct bus_dma_tag_common *tc;
102 
103 	tc = (struct bus_dma_tag_common *)dmat;
104 	return (tc->impl->load_phys(dmat, map, buf, buflen, flags, segs,
105 	    segp));
106 }
107 
108 static inline int
109 _bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map, struct vm_page **ma,
110     bus_size_t tlen, int ma_offs, int flags, bus_dma_segment_t *segs,
111     int *segp)
112 {
113 	struct bus_dma_tag_common *tc;
114 
115 	tc = (struct bus_dma_tag_common *)dmat;
116 	return (tc->impl->load_ma(dmat, map, ma, tlen, ma_offs, flags,
117 	    segs, segp));
118 }
119 
120 static inline int
121 _bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
122     bus_size_t buflen, struct pmap *pmap, int flags, bus_dma_segment_t *segs,
123     int *segp)
124 {
125 	struct bus_dma_tag_common *tc;
126 
127 	tc = (struct bus_dma_tag_common *)dmat;
128 	return (tc->impl->load_buffer(dmat, map, buf, buflen, pmap, flags, segs,
129 	    segp));
130 }
131 
132 static inline void
133 _bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
134     struct memdesc *mem, bus_dmamap_callback_t *callback, void *callback_arg)
135 {
136 	struct bus_dma_tag_common *tc;
137 
138 	tc = (struct bus_dma_tag_common *)dmat;
139 	tc->impl->map_waitok(dmat, map, mem, callback, callback_arg);
140 }
141 
142 static inline bus_dma_segment_t *
143 _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
144     bus_dma_segment_t *segs, int nsegs, int error)
145 {
146 	struct bus_dma_tag_common *tc;
147 
148 	tc = (struct bus_dma_tag_common *)dmat;
149 	return (tc->impl->map_complete(dmat, map, segs, nsegs, error));
150 }
151 
152 #ifdef KMSAN
153 static inline void
154 _bus_dmamap_load_kmsan(bus_dma_tag_t dmat, bus_dmamap_t map,
155     struct memdesc *mem)
156 {
157 	struct bus_dma_tag_common *tc;
158 
159 	tc = (struct bus_dma_tag_common *)dmat;
160 	return (tc->impl->load_kmsan(map, mem));
161 }
162 #endif
163 
164 #endif /* !_MACHINE_BUS_DMA_H_ */
165