1*59adf08eSdyoung /* $NetBSD: bus_funcs.h,v 1.1 2011/07/01 17:10:01 dyoung Exp $ */ 2*59adf08eSdyoung 3*59adf08eSdyoung /*- 4*59adf08eSdyoung * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc. 5*59adf08eSdyoung * All rights reserved. 6*59adf08eSdyoung * 7*59adf08eSdyoung * This code is derived from software contributed to The NetBSD Foundation 8*59adf08eSdyoung * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9*59adf08eSdyoung * NASA Ames Research Center. 10*59adf08eSdyoung * 11*59adf08eSdyoung * Redistribution and use in source and binary forms, with or without 12*59adf08eSdyoung * modification, are permitted provided that the following conditions 13*59adf08eSdyoung * are met: 14*59adf08eSdyoung * 1. Redistributions of source code must retain the above copyright 15*59adf08eSdyoung * notice, this list of conditions and the following disclaimer. 16*59adf08eSdyoung * 2. Redistributions in binary form must reproduce the above copyright 17*59adf08eSdyoung * notice, this list of conditions and the following disclaimer in the 18*59adf08eSdyoung * documentation and/or other materials provided with the distribution. 19*59adf08eSdyoung * 20*59adf08eSdyoung * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21*59adf08eSdyoung * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22*59adf08eSdyoung * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23*59adf08eSdyoung * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24*59adf08eSdyoung * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25*59adf08eSdyoung * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26*59adf08eSdyoung * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27*59adf08eSdyoung * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28*59adf08eSdyoung * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29*59adf08eSdyoung * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30*59adf08eSdyoung * POSSIBILITY OF SUCH DAMAGE. 31*59adf08eSdyoung */ 32*59adf08eSdyoung 33*59adf08eSdyoung /* 34*59adf08eSdyoung * Copyright (c) 1996 Charles M. Hannum. All rights reserved. 35*59adf08eSdyoung * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 36*59adf08eSdyoung * 37*59adf08eSdyoung * Redistribution and use in source and binary forms, with or without 38*59adf08eSdyoung * modification, are permitted provided that the following conditions 39*59adf08eSdyoung * are met: 40*59adf08eSdyoung * 1. Redistributions of source code must retain the above copyright 41*59adf08eSdyoung * notice, this list of conditions and the following disclaimer. 42*59adf08eSdyoung * 2. Redistributions in binary form must reproduce the above copyright 43*59adf08eSdyoung * notice, this list of conditions and the following disclaimer in the 44*59adf08eSdyoung * documentation and/or other materials provided with the distribution. 45*59adf08eSdyoung * 3. All advertising materials mentioning features or use of this software 46*59adf08eSdyoung * must display the following acknowledgement: 47*59adf08eSdyoung * This product includes software developed by Christopher G. Demetriou 48*59adf08eSdyoung * for the NetBSD Project. 49*59adf08eSdyoung * 4. The name of the author may not be used to endorse or promote products 50*59adf08eSdyoung * derived from this software without specific prior written permission 51*59adf08eSdyoung * 52*59adf08eSdyoung * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 53*59adf08eSdyoung * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 54*59adf08eSdyoung * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 55*59adf08eSdyoung * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 56*59adf08eSdyoung * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 57*59adf08eSdyoung * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 58*59adf08eSdyoung * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 59*59adf08eSdyoung * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 60*59adf08eSdyoung * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 61*59adf08eSdyoung * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62*59adf08eSdyoung */ 63*59adf08eSdyoung 64*59adf08eSdyoung #ifndef _SPARC_BUS_FUNCS_H_ 65*59adf08eSdyoung #define _SPARC_BUS_FUNCS_H_ 66*59adf08eSdyoung 67*59adf08eSdyoung bus_space_tag_t bus_space_tag_alloc(bus_space_tag_t, void *); 68*59adf08eSdyoung int bus_space_translate_address_generic(struct openprom_range *, 69*59adf08eSdyoung int, bus_addr_t *); 70*59adf08eSdyoung 71*59adf08eSdyoung /* 72*59adf08eSdyoung * Bus space function prototypes. 73*59adf08eSdyoung * In bus_space_map2(), supply a special virtual address only if you 74*59adf08eSdyoung * get it from ../sparc/vaddrs.h. 75*59adf08eSdyoung */ 76*59adf08eSdyoung int bus_space_map2( 77*59adf08eSdyoung bus_space_tag_t, 78*59adf08eSdyoung bus_addr_t, 79*59adf08eSdyoung bus_size_t, 80*59adf08eSdyoung int, /*flags*/ 81*59adf08eSdyoung vaddr_t, /*preferred vaddr*/ 82*59adf08eSdyoung bus_space_handle_t *); 83*59adf08eSdyoung void *bus_intr_establish( 84*59adf08eSdyoung bus_space_tag_t, 85*59adf08eSdyoung int, /*bus-specific intr*/ 86*59adf08eSdyoung int, /*device class level, 87*59adf08eSdyoung see machine/intr.h*/ 88*59adf08eSdyoung int (*)(void *), /*handler*/ 89*59adf08eSdyoung void *); /*handler arg*/ 90*59adf08eSdyoung void *bus_intr_establish2( 91*59adf08eSdyoung bus_space_tag_t, 92*59adf08eSdyoung int, /*bus-specific intr*/ 93*59adf08eSdyoung int, /*device class level, 94*59adf08eSdyoung see machine/intr.h*/ 95*59adf08eSdyoung int (*)(void *), /*handler*/ 96*59adf08eSdyoung void *, /*handler arg*/ 97*59adf08eSdyoung void (*)(void)); /*optional fast vector*/ 98*59adf08eSdyoung 99*59adf08eSdyoung #define bus_space_vaddr(t, h) ((void)(t), (void *)(h)) 100*59adf08eSdyoung 101*59adf08eSdyoung /* 102*59adf08eSdyoung * Device space probe assistant. 103*59adf08eSdyoung * The optional callback function's arguments are: 104*59adf08eSdyoung * the temporary virtual address 105*59adf08eSdyoung * the passed `arg' argument 106*59adf08eSdyoung */ 107*59adf08eSdyoung int bus_space_probe( 108*59adf08eSdyoung bus_space_tag_t, 109*59adf08eSdyoung bus_addr_t, 110*59adf08eSdyoung bus_size_t, /* probe size */ 111*59adf08eSdyoung size_t, /* offset */ 112*59adf08eSdyoung int, /* flags */ 113*59adf08eSdyoung int (*)(void *, void *), /* callback function */ 114*59adf08eSdyoung void *); /* callback arg */ 115*59adf08eSdyoung 116*59adf08eSdyoung /* 117*59adf08eSdyoung * u_intN_t bus_space_read_N(bus_space_tag_t tag, 118*59adf08eSdyoung * bus_space_handle_t bsh, bus_size_t offset); 119*59adf08eSdyoung * 120*59adf08eSdyoung * Read a 1, 2, 4, or 8 byte quantity from bus space 121*59adf08eSdyoung * described by tag/handle/offset. 122*59adf08eSdyoung */ 123*59adf08eSdyoung 124*59adf08eSdyoung #define bus_space_read_1_real(t, h, o) \ 125*59adf08eSdyoung ((void)(t), *(volatile uint8_t *)((h) + (o))) 126*59adf08eSdyoung 127*59adf08eSdyoung #define bus_space_read_2_real(t, h, o) \ 128*59adf08eSdyoung ((void)(t), *(volatile uint16_t *)((h) + (o))) 129*59adf08eSdyoung 130*59adf08eSdyoung #define bus_space_read_4_real(t, h, o) \ 131*59adf08eSdyoung ((void)(t), *(volatile uint32_t *)((h) + (o))) 132*59adf08eSdyoung 133*59adf08eSdyoung #define bus_space_read_8_real(t, h, o) \ 134*59adf08eSdyoung ((void)(t), *(volatile uint64_t *)((h) + (o))) 135*59adf08eSdyoung 136*59adf08eSdyoung #define bus_space_read_stream_1 bus_space_read_1_real 137*59adf08eSdyoung #define bus_space_read_stream_2 bus_space_read_2_real 138*59adf08eSdyoung #define bus_space_read_stream_4 bus_space_read_4_real 139*59adf08eSdyoung #define bus_space_read_stream_8 bus_space_read_8_real 140*59adf08eSdyoung 141*59adf08eSdyoung 142*59adf08eSdyoung /* 143*59adf08eSdyoung * void bus_space_write_N(bus_space_tag_t tag, 144*59adf08eSdyoung * bus_space_handle_t bsh, bus_size_t offset, 145*59adf08eSdyoung * u_intN_t value); 146*59adf08eSdyoung * 147*59adf08eSdyoung * Write the 1, 2, 4, or 8 byte value `value' to bus space 148*59adf08eSdyoung * described by tag/handle/offset. 149*59adf08eSdyoung */ 150*59adf08eSdyoung 151*59adf08eSdyoung #define bus_space_write_1_real(t, h, o, v) do { \ 152*59adf08eSdyoung ((void)(t), (void)(*(volatile uint8_t *)((h) + (o)) = (v))); \ 153*59adf08eSdyoung } while (/* CONSTCOND */ 0) 154*59adf08eSdyoung 155*59adf08eSdyoung #define bus_space_write_2_real(t, h, o, v) do { \ 156*59adf08eSdyoung ((void)(t), (void)(*(volatile uint16_t *)((h) + (o)) = (v))); \ 157*59adf08eSdyoung } while (/* CONSTCOND */ 0) 158*59adf08eSdyoung 159*59adf08eSdyoung #define bus_space_write_4_real(t, h, o, v) do { \ 160*59adf08eSdyoung ((void)(t), (void)(*(volatile uint32_t *)((h) + (o)) = (v))); \ 161*59adf08eSdyoung } while (/* CONSTCOND */ 0) 162*59adf08eSdyoung 163*59adf08eSdyoung #define bus_space_write_8_real(t, h, o, v) do { \ 164*59adf08eSdyoung ((void)(t), (void)(*(volatile uint64_t *)((h) + (o)) = (v))); \ 165*59adf08eSdyoung } while (/* CONSTCOND */ 0) 166*59adf08eSdyoung 167*59adf08eSdyoung #define bus_space_write_stream_1 bus_space_write_1_real 168*59adf08eSdyoung #define bus_space_write_stream_2 bus_space_write_2_real 169*59adf08eSdyoung #define bus_space_write_stream_4 bus_space_write_4_real 170*59adf08eSdyoung #define bus_space_write_stream_8 bus_space_write_8_real 171*59adf08eSdyoung 172*59adf08eSdyoung #define bus_space_read_multi_stream_1 bus_space_read_multi_1 173*59adf08eSdyoung #define bus_space_write_multi_stream_1 bus_space_write_multi_1 174*59adf08eSdyoung 175*59adf08eSdyoung /* Forwards needed by prototypes below. */ 176*59adf08eSdyoung struct mbuf; 177*59adf08eSdyoung struct uio; 178*59adf08eSdyoung 179*59adf08eSdyoung #define bus_dmamap_create(t, s, n, m, b, f, p) \ 180*59adf08eSdyoung (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) 181*59adf08eSdyoung #define bus_dmamap_destroy(t, p) \ 182*59adf08eSdyoung (*(t)->_dmamap_destroy)((t), (p)) 183*59adf08eSdyoung #define bus_dmamap_load(t, m, b, s, p, f) \ 184*59adf08eSdyoung (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) 185*59adf08eSdyoung #define bus_dmamap_load_mbuf(t, m, b, f) \ 186*59adf08eSdyoung (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) 187*59adf08eSdyoung #define bus_dmamap_load_uio(t, m, u, f) \ 188*59adf08eSdyoung (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) 189*59adf08eSdyoung #define bus_dmamap_load_raw(t, m, sg, n, s, f) \ 190*59adf08eSdyoung (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) 191*59adf08eSdyoung #define bus_dmamap_unload(t, p) \ 192*59adf08eSdyoung (*(t)->_dmamap_unload)((t), (p)) 193*59adf08eSdyoung #define bus_dmamap_sync(t, p, o, l, ops) \ 194*59adf08eSdyoung (void)((t)->_dmamap_sync ? \ 195*59adf08eSdyoung (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) : (void)0) 196*59adf08eSdyoung 197*59adf08eSdyoung #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ 198*59adf08eSdyoung (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) 199*59adf08eSdyoung #define bus_dmamem_free(t, sg, n) \ 200*59adf08eSdyoung (*(t)->_dmamem_free)((t), (sg), (n)) 201*59adf08eSdyoung #define bus_dmamem_map(t, sg, n, s, k, f) \ 202*59adf08eSdyoung (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) 203*59adf08eSdyoung #define bus_dmamem_unmap(t, k, s) \ 204*59adf08eSdyoung (*(t)->_dmamem_unmap)((t), (k), (s)) 205*59adf08eSdyoung #define bus_dmamem_mmap(t, sg, n, o, p, f) \ 206*59adf08eSdyoung (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) 207*59adf08eSdyoung 208*59adf08eSdyoung #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP 209*59adf08eSdyoung #define bus_dmatag_destroy(t) 210*59adf08eSdyoung 211*59adf08eSdyoung #ifdef _SPARC_BUS_DMA_PRIVATE 212*59adf08eSdyoung int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, 213*59adf08eSdyoung bus_size_t, int, bus_dmamap_t *); 214*59adf08eSdyoung void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); 215*59adf08eSdyoung int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, 216*59adf08eSdyoung struct mbuf *, int); 217*59adf08eSdyoung int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, 218*59adf08eSdyoung struct uio *, int); 219*59adf08eSdyoung int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, 220*59adf08eSdyoung bus_dma_segment_t *, int, bus_size_t, int); 221*59adf08eSdyoung void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); 222*59adf08eSdyoung void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, 223*59adf08eSdyoung bus_size_t, int); 224*59adf08eSdyoung 225*59adf08eSdyoung int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size, 226*59adf08eSdyoung bus_size_t alignment, bus_size_t boundary, 227*59adf08eSdyoung bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags); 228*59adf08eSdyoung void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, 229*59adf08eSdyoung int nsegs); 230*59adf08eSdyoung void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva, 231*59adf08eSdyoung size_t size); 232*59adf08eSdyoung paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, 233*59adf08eSdyoung int nsegs, off_t off, int prot, int flags); 234*59adf08eSdyoung 235*59adf08eSdyoung int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size, 236*59adf08eSdyoung bus_size_t alignment, bus_size_t boundary, 237*59adf08eSdyoung bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags, 238*59adf08eSdyoung vaddr_t low, vaddr_t high); 239*59adf08eSdyoung 240*59adf08eSdyoung vaddr_t _bus_dma_valloc_skewed(size_t, u_long, u_long, u_long); 241*59adf08eSdyoung #endif /* _SPARC_BUS_DMA_PRIVATE */ 242*59adf08eSdyoung 243*59adf08eSdyoung #endif /* _SPARC_BUS_FUNCS_H_ */ 244