13bcb7c2aSAdrian Chadd /*- 23bcb7c2aSAdrian Chadd * Copyright (c) 2013 The FreeBSD Foundation 33bcb7c2aSAdrian Chadd * 43bcb7c2aSAdrian Chadd * This software was developed by Konstantin Belousov <kib@FreeBSD.org> 53bcb7c2aSAdrian Chadd * under sponsorship from the FreeBSD Foundation. 63bcb7c2aSAdrian Chadd * 73bcb7c2aSAdrian Chadd * Redistribution and use in source and binary forms, with or without 83bcb7c2aSAdrian Chadd * modification, are permitted provided that the following conditions 93bcb7c2aSAdrian Chadd * are met: 103bcb7c2aSAdrian Chadd * 1. Redistributions of source code must retain the above copyright 113bcb7c2aSAdrian Chadd * notice, this list of conditions and the following disclaimer. 123bcb7c2aSAdrian Chadd * 2. Redistributions in binary form must reproduce the above copyright 133bcb7c2aSAdrian Chadd * notice, this list of conditions and the following disclaimer in the 143bcb7c2aSAdrian Chadd * documentation and/or other materials provided with the distribution. 153bcb7c2aSAdrian Chadd * 163bcb7c2aSAdrian Chadd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 173bcb7c2aSAdrian Chadd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 183bcb7c2aSAdrian Chadd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 193bcb7c2aSAdrian Chadd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 203bcb7c2aSAdrian Chadd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 213bcb7c2aSAdrian Chadd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 223bcb7c2aSAdrian Chadd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 233bcb7c2aSAdrian Chadd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 243bcb7c2aSAdrian Chadd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 253bcb7c2aSAdrian Chadd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 263bcb7c2aSAdrian Chadd * SUCH DAMAGE. 273bcb7c2aSAdrian Chadd */ 283bcb7c2aSAdrian Chadd 293bcb7c2aSAdrian Chadd #ifndef _MACHINE_BUS_DMA_IMPL_H_ 303bcb7c2aSAdrian Chadd #define _MACHINE_BUS_DMA_IMPL_H_ 313bcb7c2aSAdrian Chadd 323bcb7c2aSAdrian Chadd /* Note: must be first entry in bus_dma_tag */ 333bcb7c2aSAdrian Chadd struct bus_dma_tag_common { 343bcb7c2aSAdrian Chadd struct bus_dma_impl *impl; 353bcb7c2aSAdrian Chadd bus_size_t alignment; 363bcb7c2aSAdrian Chadd bus_addr_t boundary; 373bcb7c2aSAdrian Chadd bus_addr_t lowaddr; 383bcb7c2aSAdrian Chadd bus_addr_t highaddr; 393bcb7c2aSAdrian Chadd bus_size_t maxsize; 403bcb7c2aSAdrian Chadd u_int nsegments; 413bcb7c2aSAdrian Chadd bus_size_t maxsegsz; 423bcb7c2aSAdrian Chadd int flags; 433bcb7c2aSAdrian Chadd bus_dma_lock_t *lockfunc; 443bcb7c2aSAdrian Chadd void *lockfuncarg; 45df3bd720SAdrian Chadd int domain; 463bcb7c2aSAdrian Chadd }; 473bcb7c2aSAdrian Chadd 483bcb7c2aSAdrian Chadd struct bus_dma_impl { 493bcb7c2aSAdrian Chadd int (*tag_create)(bus_dma_tag_t parent, 503bcb7c2aSAdrian Chadd bus_size_t alignment, bus_addr_t boundary, bus_addr_t lowaddr, 513bcb7c2aSAdrian Chadd bus_addr_t highaddr, bus_size_t maxsize, int nsegments, 523bcb7c2aSAdrian Chadd bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, 533bcb7c2aSAdrian Chadd void *lockfuncarg, bus_dma_tag_t *dmat); 543bcb7c2aSAdrian Chadd int (*tag_destroy)(bus_dma_tag_t dmat); 553bcb7c2aSAdrian Chadd int (*tag_set_domain)(bus_dma_tag_t, int domain); 563bcb7c2aSAdrian Chadd int (*map_create)(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp); 573bcb7c2aSAdrian Chadd int (*map_destroy)(bus_dma_tag_t dmat, bus_dmamap_t map); 583bcb7c2aSAdrian Chadd int (*mem_alloc)(bus_dma_tag_t dmat, void** vaddr, int flags, 593bcb7c2aSAdrian Chadd bus_dmamap_t *mapp); 603bcb7c2aSAdrian Chadd void (*mem_free)(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map); 613bcb7c2aSAdrian Chadd int (*load_ma)(bus_dma_tag_t dmat, bus_dmamap_t map, 623bcb7c2aSAdrian Chadd struct vm_page **ma, bus_size_t tlen, int ma_offs, int flags, 633bcb7c2aSAdrian Chadd bus_dma_segment_t *segs, int *segp); 643bcb7c2aSAdrian Chadd int (*load_phys)(bus_dma_tag_t dmat, bus_dmamap_t map, 653bcb7c2aSAdrian Chadd vm_paddr_t buf, bus_size_t buflen, int flags, 663bcb7c2aSAdrian Chadd bus_dma_segment_t *segs, int *segp); 673bcb7c2aSAdrian Chadd int (*load_buffer)(bus_dma_tag_t dmat, bus_dmamap_t map, 683bcb7c2aSAdrian Chadd void *buf, bus_size_t buflen, struct pmap *pmap, int flags, 693bcb7c2aSAdrian Chadd bus_dma_segment_t *segs, int *segp); 703bcb7c2aSAdrian Chadd void (*map_waitok)(bus_dma_tag_t dmat, bus_dmamap_t map, 713bcb7c2aSAdrian Chadd struct memdesc *mem, bus_dmamap_callback_t *callback, 723bcb7c2aSAdrian Chadd void *callback_arg); 733bcb7c2aSAdrian Chadd bus_dma_segment_t *(*map_complete)(bus_dma_tag_t dmat, bus_dmamap_t map, 743bcb7c2aSAdrian Chadd bus_dma_segment_t *segs, int nsegs, int error); 753bcb7c2aSAdrian Chadd void (*map_unload)(bus_dma_tag_t dmat, bus_dmamap_t map); 763bcb7c2aSAdrian Chadd void (*map_sync)(bus_dma_tag_t dmat, bus_dmamap_t map, 773bcb7c2aSAdrian Chadd bus_dmasync_op_t op); 783bcb7c2aSAdrian Chadd int (*set_iommu)(bus_dma_tag_t dmat, device_t iommu, void *cookie); 793bcb7c2aSAdrian Chadd }; 803bcb7c2aSAdrian Chadd 813bcb7c2aSAdrian Chadd extern struct bus_dma_impl bus_dma_bounce_impl; 823bcb7c2aSAdrian Chadd 83*00ec88d2SAdrian Chadd extern int common_bus_dma_tag_create(struct bus_dma_tag_common *parent, 84*00ec88d2SAdrian Chadd bus_size_t alignment, bus_addr_t boundary, bus_addr_t lowaddr, 85*00ec88d2SAdrian Chadd bus_addr_t highaddr, bus_size_t maxsize, int nsegments, 86*00ec88d2SAdrian Chadd bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, 87*00ec88d2SAdrian Chadd void *lockfuncarg, size_t sz, void **dmat); 88*00ec88d2SAdrian Chadd 893bcb7c2aSAdrian Chadd #endif 90