1 /* $NetBSD: bus_stubs.c,v 1.3 2021/09/18 09:49:57 jmcneill Exp $ */ 2 3 /* 4 * Copyright (c) 2020 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Maxime Villard. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: bus_stubs.c,v 1.3 2021/09/18 09:49:57 jmcneill Exp $"); 34 35 #include <sys/systm.h> 36 #include <sys/asan.h> 37 #include <sys/bus.h> 38 #include <sys/bus_proto.h> 39 40 bool 41 bus_space_is_equal(bus_space_tag_t t1, bus_space_tag_t t2) 42 { 43 if (t1 == t2) { 44 return true; 45 } 46 47 return t1 != NULL && t2 != NULL && t1->bs_cookie == t2->bs_cookie; 48 } 49 50 int 51 bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments, 52 bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp) 53 { 54 return (*t->_dmamap_create)(t, size, nsegments, maxsegsz, boundary, 55 flags, dmamp); 56 } 57 58 void 59 bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t dmam) 60 { 61 (*t->_dmamap_destroy)(t, dmam); 62 } 63 64 int 65 bus_dmamap_load(bus_dma_tag_t t, bus_dmamap_t dmam, void *buf, 66 bus_size_t buflen, struct proc *p, int flags) 67 { 68 kasan_dma_load(dmam, buf, buflen, KASAN_DMA_LINEAR); 69 return (*t->_dmamap_load)(t, dmam, buf, buflen, p, flags); 70 } 71 72 int 73 bus_dmamap_load_mbuf(bus_dma_tag_t t, bus_dmamap_t dmam, struct mbuf *chain, 74 int flags) 75 { 76 kasan_dma_load(dmam, chain, 0, KASAN_DMA_MBUF); 77 return (*t->_dmamap_load_mbuf)(t, dmam, chain, flags); 78 } 79 80 int 81 bus_dmamap_load_uio(bus_dma_tag_t t, bus_dmamap_t dmam, struct uio *uio, 82 int flags) 83 { 84 kasan_dma_load(dmam, uio, 0, KASAN_DMA_UIO); 85 return (*t->_dmamap_load_uio)(t, dmam, uio, flags); 86 } 87 88 int 89 bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t dmam, bus_dma_segment_t *segs, 90 int nsegs, bus_size_t size, int flags) 91 { 92 return (*t->_dmamap_load_raw)(t, dmam, segs, nsegs, size, flags); 93 } 94 95 void 96 bus_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t dmam) 97 { 98 (*t->_dmamap_unload)(t, dmam); 99 } 100 101 void 102 bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t p, bus_addr_t o, bus_size_t l, 103 int ops) 104 { 105 kasan_dma_sync(p, o, l, ops); 106 107 if ((ops & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) != 0 && 108 t->_dmamap_sync_pre != NULL) 109 (*t->_dmamap_sync_pre)(t, p, o, l, ops); 110 else if ((ops & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) != 0 && 111 t->_dmamap_sync_post != NULL) 112 (*t->_dmamap_sync_post)(t, p, o, l, ops); 113 } 114