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