xref: /freebsd/sys/riscv/include/bus_dma.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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  * Allocate a handle for mapping from kva/uva/physical
12  * address space into bus device space.
13  */
14 static inline int
15 bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp)
16 {
17 	struct bus_dma_tag_common *tc;
18 
19 	tc = (struct bus_dma_tag_common *)dmat;
20 	return (tc->impl->map_create(dmat, flags, mapp));
21 }
22 
23 /*
24  * Destroy a handle for mapping from kva/uva/physical
25  * address space into bus device space.
26  */
27 static inline int
28 bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map)
29 {
30 	struct bus_dma_tag_common *tc;
31 
32 	tc = (struct bus_dma_tag_common *)dmat;
33 	return (tc->impl->map_destroy(dmat, map));
34 }
35 
36 /*
37  * Allocate a piece of memory that can be efficiently mapped into
38  * bus device space based on the constraints listed in the dma tag.
39  * A dmamap to for use with dmamap_load is also allocated.
40  */
41 static inline int
42 bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
43     bus_dmamap_t *mapp)
44 {
45 	struct bus_dma_tag_common *tc;
46 
47 	tc = (struct bus_dma_tag_common *)dmat;
48 	return (tc->impl->mem_alloc(dmat, vaddr, flags, mapp));
49 }
50 
51 /*
52  * Free a piece of memory and it's allociated dmamap, that was allocated
53  * via bus_dmamem_alloc.  Make the same choice for free/contigfree.
54  */
55 static inline void
56 bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map)
57 {
58 	struct bus_dma_tag_common *tc;
59 
60 	tc = (struct bus_dma_tag_common *)dmat;
61 	tc->impl->mem_free(dmat, vaddr, map);
62 }
63 
64 /*
65  * Release the mapping held by map.
66  */
67 static inline void
68 bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map)
69 {
70 	struct bus_dma_tag_common *tc;
71 
72 	tc = (struct bus_dma_tag_common *)dmat;
73 	tc->impl->map_unload(dmat, map);
74 }
75 
76 static inline void
77 bus_dmamap_sync(bus_dma_tag_t dmat, bus_dmamap_t map, bus_dmasync_op_t op)
78 {
79 	struct bus_dma_tag_common *tc;
80 
81 	tc = (struct bus_dma_tag_common *)dmat;
82 	tc->impl->map_sync(dmat, map, op);
83 }
84 
85 static inline int
86 _bus_dmamap_load_phys(bus_dma_tag_t dmat, bus_dmamap_t map, vm_paddr_t buf,
87     bus_size_t buflen, int flags, bus_dma_segment_t *segs, int *segp)
88 {
89 	struct bus_dma_tag_common *tc;
90 
91 	tc = (struct bus_dma_tag_common *)dmat;
92 	return (tc->impl->load_phys(dmat, map, buf, buflen, flags, segs,
93 	    segp));
94 }
95 
96 static inline int
97 _bus_dmamap_load_ma(bus_dma_tag_t dmat, bus_dmamap_t map, struct vm_page **ma,
98     bus_size_t tlen, int ma_offs, int flags, bus_dma_segment_t *segs,
99     int *segp)
100 {
101 	struct bus_dma_tag_common *tc;
102 
103 	tc = (struct bus_dma_tag_common *)dmat;
104 	return (tc->impl->load_ma(dmat, map, ma, tlen, ma_offs, flags,
105 	    segs, segp));
106 }
107 
108 static inline int
109 _bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
110     bus_size_t buflen, struct pmap *pmap, 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_buffer(dmat, map, buf, buflen, pmap, flags, segs,
117 	    segp));
118 }
119 
120 static inline void
121 _bus_dmamap_waitok(bus_dma_tag_t dmat, bus_dmamap_t map,
122     struct memdesc *mem, bus_dmamap_callback_t *callback, void *callback_arg)
123 {
124 	struct bus_dma_tag_common *tc;
125 
126 	tc = (struct bus_dma_tag_common *)dmat;
127 	tc->impl->map_waitok(dmat, map, mem, callback, callback_arg);
128 }
129 
130 static inline bus_dma_segment_t *
131 _bus_dmamap_complete(bus_dma_tag_t dmat, bus_dmamap_t map,
132     bus_dma_segment_t *segs, int nsegs, int error)
133 {
134 	struct bus_dma_tag_common *tc;
135 
136 	tc = (struct bus_dma_tag_common *)dmat;
137 	return (tc->impl->map_complete(dmat, map, segs, nsegs, error));
138 }
139 
140 #endif /* !_MACHINE_BUS_DMA_H_ */
141