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