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