175cf8837SRuslan Bukin /*- 275cf8837SRuslan Bukin * Copyright (c) 2013 The FreeBSD Foundation 375cf8837SRuslan Bukin * 475cf8837SRuslan Bukin * This software was developed by Konstantin Belousov <kib@FreeBSD.org> 575cf8837SRuslan Bukin * under sponsorship from the FreeBSD Foundation. 675cf8837SRuslan Bukin * 775cf8837SRuslan Bukin * Redistribution and use in source and binary forms, with or without 875cf8837SRuslan Bukin * modification, are permitted provided that the following conditions 975cf8837SRuslan Bukin * are met: 1075cf8837SRuslan Bukin * 1. Redistributions of source code must retain the above copyright 1175cf8837SRuslan Bukin * notice, this list of conditions and the following disclaimer. 1275cf8837SRuslan Bukin * 2. Redistributions in binary form must reproduce the above copyright 1375cf8837SRuslan Bukin * notice, this list of conditions and the following disclaimer in the 1475cf8837SRuslan Bukin * documentation and/or other materials provided with the distribution. 1575cf8837SRuslan Bukin * 1675cf8837SRuslan Bukin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1775cf8837SRuslan Bukin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1875cf8837SRuslan Bukin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1975cf8837SRuslan Bukin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2075cf8837SRuslan Bukin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2175cf8837SRuslan Bukin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2275cf8837SRuslan Bukin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2375cf8837SRuslan Bukin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2475cf8837SRuslan Bukin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2575cf8837SRuslan Bukin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2675cf8837SRuslan Bukin * SUCH DAMAGE. 2775cf8837SRuslan Bukin */ 2875cf8837SRuslan Bukin 2975cf8837SRuslan Bukin #ifndef _MACHINE_BUS_DMA_IMPL_H_ 3075cf8837SRuslan Bukin #define _MACHINE_BUS_DMA_IMPL_H_ 3175cf8837SRuslan Bukin 3275cf8837SRuslan Bukin struct bus_dma_tag_common { 3375cf8837SRuslan Bukin struct bus_dma_impl *impl; 3475cf8837SRuslan Bukin bus_size_t alignment; 3575cf8837SRuslan Bukin bus_addr_t boundary; 3675cf8837SRuslan Bukin bus_addr_t lowaddr; 3775cf8837SRuslan Bukin bus_addr_t highaddr; 3875cf8837SRuslan Bukin bus_size_t maxsize; 3975cf8837SRuslan Bukin u_int nsegments; 4075cf8837SRuslan Bukin bus_size_t maxsegsz; 4175cf8837SRuslan Bukin int flags; 4275cf8837SRuslan Bukin bus_dma_lock_t *lockfunc; 4375cf8837SRuslan Bukin void *lockfuncarg; 4475cf8837SRuslan Bukin }; 4575cf8837SRuslan Bukin 4675cf8837SRuslan Bukin struct bus_dma_impl { 4775cf8837SRuslan Bukin int (*tag_create)(bus_dma_tag_t parent, 4875cf8837SRuslan Bukin bus_size_t alignment, bus_addr_t boundary, bus_addr_t lowaddr, 49*900907f4SMitchell Horne bus_addr_t highaddr, bus_size_t maxsize, int nsegments, 5075cf8837SRuslan Bukin bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, 5175cf8837SRuslan Bukin void *lockfuncarg, bus_dma_tag_t *dmat); 5275cf8837SRuslan Bukin int (*tag_destroy)(bus_dma_tag_t dmat); 5375cf8837SRuslan Bukin int (*map_create)(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp); 5475cf8837SRuslan Bukin int (*map_destroy)(bus_dma_tag_t dmat, bus_dmamap_t map); 5575cf8837SRuslan Bukin int (*mem_alloc)(bus_dma_tag_t dmat, void** vaddr, int flags, 5675cf8837SRuslan Bukin bus_dmamap_t *mapp); 5775cf8837SRuslan Bukin void (*mem_free)(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); 5875cf8837SRuslan Bukin int (*load_ma)(bus_dma_tag_t dmat, bus_dmamap_t map, 5975cf8837SRuslan Bukin struct vm_page **ma, bus_size_t tlen, int ma_offs, int flags, 6075cf8837SRuslan Bukin bus_dma_segment_t *segs, int *segp); 6175cf8837SRuslan Bukin int (*load_phys)(bus_dma_tag_t dmat, bus_dmamap_t map, 6275cf8837SRuslan Bukin vm_paddr_t buf, bus_size_t buflen, int flags, 6375cf8837SRuslan Bukin bus_dma_segment_t *segs, int *segp); 6475cf8837SRuslan Bukin int (*load_buffer)(bus_dma_tag_t dmat, bus_dmamap_t map, 6575cf8837SRuslan Bukin void *buf, bus_size_t buflen, struct pmap *pmap, int flags, 6675cf8837SRuslan Bukin bus_dma_segment_t *segs, int *segp); 6775cf8837SRuslan Bukin void (*map_waitok)(bus_dma_tag_t dmat, bus_dmamap_t map, 6875cf8837SRuslan Bukin struct memdesc *mem, bus_dmamap_callback_t *callback, 6975cf8837SRuslan Bukin void *callback_arg); 7075cf8837SRuslan Bukin bus_dma_segment_t *(*map_complete)(bus_dma_tag_t dmat, bus_dmamap_t map, 7175cf8837SRuslan Bukin bus_dma_segment_t *segs, int nsegs, int error); 7275cf8837SRuslan Bukin void (*map_unload)(bus_dma_tag_t dmat, bus_dmamap_t map); 7375cf8837SRuslan Bukin void (*map_sync)(bus_dma_tag_t dmat, bus_dmamap_t map, 7475cf8837SRuslan Bukin bus_dmasync_op_t op); 7575cf8837SRuslan Bukin }; 7675cf8837SRuslan Bukin 7775cf8837SRuslan Bukin int common_bus_dma_tag_create(struct bus_dma_tag_common *parent, 7875cf8837SRuslan Bukin bus_size_t alignment, 7975cf8837SRuslan Bukin bus_addr_t boundary, bus_addr_t lowaddr, bus_addr_t highaddr, 80*900907f4SMitchell Horne bus_size_t maxsize, int nsegments, bus_size_t maxsegsz, int flags, 81*900907f4SMitchell Horne bus_dma_lock_t *lockfunc, void *lockfuncarg, size_t sz, void **dmat); 8275cf8837SRuslan Bukin 8375cf8837SRuslan Bukin extern struct bus_dma_impl bus_dma_bounce_impl; 8475cf8837SRuslan Bukin 8575cf8837SRuslan Bukin #endif 86