1/* $NetBSD$ */ 2 3/*- 4 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 * NASA Ames Research Center. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33/* 34 * Copyright (c) 1996 Charles M. Hannum. All rights reserved. 35 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 3. All advertising materials mentioning features or use of this software 46 * must display the following acknowledgement: 47 * This product includes software developed by Christopher G. Demetriou 48 * for the NetBSD Project. 49 * 4. The name of the author may not be used to endorse or promote products 50 * derived from this software without specific prior written permission 51 * 52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 53 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 54 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 55 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 56 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 57 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 61 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 */ 63 64#ifndef _LANDISK_BUS_FUNCS_H_ 65#define _LANDISK_BUS_FUNCS_H_ 66 67#ifdef _KERNEL 68/* 69 * Utility macros; INTERNAL USE ONLY. 70 */ 71#define __bs_c(a,b) __CONCAT(a,b) 72#define __bs_opname(op,size) __bs_c(__bs_c(__bs_c(bs_,op),_),size) 73 74#define __bs_rs(sz, tn, t, h, o) \ 75 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \ 76 (*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o)) 77 78#define __bs_ws(sz, tn, t, h, o, v) \ 79do { \ 80 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 81 (*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v); \ 82} while (0) 83 84#define __bs_nonsingle(type, sz, tn, t, h, o, a, c) \ 85do { \ 86 __BUS_SPACE_ADDRESS_SANITY((a), tn, "buffer"); \ 87 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 88 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c); \ 89} while (0) 90 91#define __bs_set(type, sz, tn, t, h, o, v, c) \ 92do { \ 93 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 94 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c); \ 95} while (0) 96 97#define __bs_copy(sz, tn, t, h1, o1, h2, o2, cnt) \ 98do { \ 99 __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), tn, "bus addr 1"); \ 100 __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), tn, "bus addr 2"); \ 101 (*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt); \ 102} while (0) 103 104 105/* 106 * Mapping and unmapping operations. 107 */ 108#define bus_space_map(t, a, s, f, hp) \ 109 (*(t)->bs_map)((t)->bs_cookie, (a), (s), (f), (hp)) 110#define bus_space_unmap(t, h, s) \ 111 (*(t)->bs_unmap)((t)->bs_cookie, (h), (s)) 112#define bus_space_subregion(t, h, o, s, hp) \ 113 (*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp)) 114 115/* 116 * Allocation and deallocation operations. 117 */ 118#define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \ 119 (*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b), \ 120 (f), (ap), (hp)) 121#define bus_space_free(t, h, s) \ 122 (*(t)->bs_free)((t)->bs_cookie, (h), (s)) 123 124/* 125 * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR. 126 */ 127#define bus_space_vaddr(t, h) \ 128 (*(t)->bs_vaddr)((t)->bs_cookie, (h)) 129 130/* 131 * MMap bus space for a user application. 132 */ 133#define bus_space_mmap(t, a, o, p, f) \ 134 (*(t)->bs_mmap)((t)->bs_cookie, (a), (o), (p), (f)) 135 136/* 137 * Bus barrier operations. The SH3 does not currently require 138 * barriers, but we must provide the flags to MI code. 139 */ 140#define bus_space_barrier(t, h, o, l, f) \ 141 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f))) 142 143/* 144 * Bus read (single) operations. 145 */ 146#define bus_space_read_1(t, h, o) __bs_rs(1,uint8_t,(t),(h),(o)) 147#define bus_space_read_2(t, h, o) __bs_rs(2,uint16_t,(t),(h),(o)) 148#define bus_space_read_4(t, h, o) __bs_rs(4,uint32_t,(t),(h),(o)) 149#define bus_space_read_8(t, h, o) __bs_rs(8,uint64_t,(t),(h),(o)) 150 151 152/* 153 * Bus read multiple operations. 154 */ 155#define bus_space_read_multi_1(t, h, o, a, c) \ 156 __bs_nonsingle(rm,1,uint8_t,(t),(h),(o),(a),(c)) 157#define bus_space_read_multi_2(t, h, o, a, c) \ 158 __bs_nonsingle(rm,2,uint16_t,(t),(h),(o),(a),(c)) 159#define bus_space_read_multi_4(t, h, o, a, c) \ 160 __bs_nonsingle(rm,4,uint32_t,(t),(h),(o),(a),(c)) 161#define bus_space_read_multi_8(t, h, o, a, c) \ 162 __bs_nonsingle(rm,8,uint64_t,(t),(h),(o),(a),(c)) 163 164 165/* 166 * Bus read region operations. 167 */ 168#define bus_space_read_region_1(t, h, o, a, c) \ 169 __bs_nonsingle(rr,1,uint8_t,(t),(h),(o),(a),(c)) 170#define bus_space_read_region_2(t, h, o, a, c) \ 171 __bs_nonsingle(rr,2,uint16_t,(t),(h),(o),(a),(c)) 172#define bus_space_read_region_4(t, h, o, a, c) \ 173 __bs_nonsingle(rr,4,uint32_t,(t),(h),(o),(a),(c)) 174#define bus_space_read_region_8(t, h, o, a, c) \ 175 __bs_nonsingle(rr,8,uint64_t,(t),(h),(o),(a),(c)) 176 177 178/* 179 * Bus write (single) operations. 180 */ 181#define bus_space_write_1(t, h, o, v) __bs_ws(1,uint8_t,(t),(h),(o),(v)) 182#define bus_space_write_2(t, h, o, v) __bs_ws(2,uint16_t,(t),(h),(o),(v)) 183#define bus_space_write_4(t, h, o, v) __bs_ws(4,uint32_t,(t),(h),(o),(v)) 184#define bus_space_write_8(t, h, o, v) __bs_ws(8,uint64_t,(t),(h),(o),(v)) 185 186 187/* 188 * Bus write multiple operations. 189 */ 190#define bus_space_write_multi_1(t, h, o, a, c) \ 191 __bs_nonsingle(wm,1,uint8_t,(t),(h),(o),(a),(c)) 192#define bus_space_write_multi_2(t, h, o, a, c) \ 193 __bs_nonsingle(wm,2,uint16_t,(t),(h),(o),(a),(c)) 194#define bus_space_write_multi_4(t, h, o, a, c) \ 195 __bs_nonsingle(wm,4,uint32_t,(t),(h),(o),(a),(c)) 196#define bus_space_write_multi_8(t, h, o, a, c) \ 197 __bs_nonsingle(wm,8,uint64_t,(t),(h),(o),(a),(c)) 198 199 200/* 201 * Bus write region operations. 202 */ 203#define bus_space_write_region_1(t, h, o, a, c) \ 204 __bs_nonsingle(wr,1,uint8_t,(t),(h),(o),(a),(c)) 205#define bus_space_write_region_2(t, h, o, a, c) \ 206 __bs_nonsingle(wr,2,uint16_t,(t),(h),(o),(a),(c)) 207#define bus_space_write_region_4(t, h, o, a, c) \ 208 __bs_nonsingle(wr,4,uint32_t,(t),(h),(o),(a),(c)) 209#define bus_space_write_region_8(t, h, o, a, c) \ 210 __bs_nonsingle(wr,8,uint64_t,(t),(h),(o),(a),(c)) 211 212 213/* 214 * Set multiple operations. 215 */ 216#define bus_space_set_multi_1(t, h, o, v, c) \ 217 __bs_set(sm,1,uint8_t,(t),(h),(o),(v),(c)) 218#define bus_space_set_multi_2(t, h, o, v, c) \ 219 __bs_set(sm,2,uint16_t,(t),(h),(o),(v),(c)) 220#define bus_space_set_multi_4(t, h, o, v, c) \ 221 __bs_set(sm,4,uint32_t,(t),(h),(o),(v),(c)) 222#define bus_space_set_multi_8(t, h, o, v, c) \ 223 __bs_set(sm,8,uint64_t,(t),(h),(o),(v),(c)) 224 225 226/* 227 * Set region operations. 228 */ 229#define bus_space_set_region_1(t, h, o, v, c) \ 230 __bs_set(sr,1,uint8_t,(t),(h),(o),(v),(c)) 231#define bus_space_set_region_2(t, h, o, v, c) \ 232 __bs_set(sr,2,uint16_t,(t),(h),(o),(v),(c)) 233#define bus_space_set_region_4(t, h, o, v, c) \ 234 __bs_set(sr,4,uint32_t,(t),(h),(o),(v),(c)) 235#define bus_space_set_region_8(t, h, o, v, c) \ 236 __bs_set(sr,8,uint64_t,(t),(h),(o),(v),(c)) 237 238 239/* 240 * Copy region operations. 241 */ 242#define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \ 243 __bs_copy(1, uint8_t, (t), (h1), (o1), (h2), (o2), (c)) 244#define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \ 245 __bs_copy(2, uint16_t, (t), (h1), (o1), (h2), (o2), (c)) 246#define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \ 247 __bs_copy(4, uint32_t, (t), (h1), (o1), (h2), (o2), (c)) 248#define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \ 249 __bs_copy(8, uint64_t, (t), (h1), (o1), (h2), (o2), (c)) 250 251/* 252 * Bus stream operations--defined in terms of non-stream counterparts 253 */ 254#define bus_space_read_stream_1 bus_space_read_1 255#define bus_space_read_stream_2 bus_space_read_2 256#define bus_space_read_stream_4 bus_space_read_4 257#define bus_space_read_stream_8 bus_space_read_8 258#define bus_space_read_multi_stream_1 bus_space_read_multi_1 259#define bus_space_read_multi_stream_2 bus_space_read_multi_2 260#define bus_space_read_multi_stream_4 bus_space_read_multi_4 261#define bus_space_read_multi_stream_8 bus_space_read_multi_8 262#define bus_space_read_region_stream_1 bus_space_read_region_1 263#define bus_space_read_region_stream_2 bus_space_read_region_2 264#define bus_space_read_region_stream_4 bus_space_read_region_4 265#define bus_space_read_region_stream_8 bus_space_read_region_8 266#define bus_space_write_stream_1 bus_space_write_1 267#define bus_space_write_stream_2 bus_space_write_2 268#define bus_space_write_stream_4 bus_space_write_4 269#define bus_space_write_stream_8 bus_space_write_8 270#define bus_space_write_multi_stream_1 bus_space_write_multi_1 271#define bus_space_write_multi_stream_2 bus_space_write_multi_2 272#define bus_space_write_multi_stream_4 bus_space_write_multi_4 273#define bus_space_write_multi_stream_8 bus_space_write_multi_8 274#define bus_space_write_region_stream_1 bus_space_write_region_1 275#define bus_space_write_region_stream_2 bus_space_write_region_2 276#define bus_space_write_region_stream_4 bus_space_write_region_4 277#define bus_space_write_region_stream_8 bus_space_write_region_8 278 279#endif /* _KERNEL */ 280 281/* Forwards needed by prototypes below. */ 282struct mbuf; 283struct uio; 284 285#define bus_dmamap_create(t, s, n, m, b, f, p) \ 286 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) 287#define bus_dmamap_destroy(t, p) \ 288 (*(t)->_dmamap_destroy)((t), (p)) 289#define bus_dmamap_load(t, m, b, s, p, f) \ 290 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) 291#define bus_dmamap_load_mbuf(t, m, b, f) \ 292 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) 293#define bus_dmamap_load_uio(t, m, u, f) \ 294 (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) 295#define bus_dmamap_load_raw(t, m, sg, n, s, f) \ 296 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) 297#define bus_dmamap_unload(t, p) \ 298 (*(t)->_dmamap_unload)((t), (p)) 299#define bus_dmamap_sync(t, m, o, l, op) \ 300 (void)((t)->_dmamap_sync ? \ 301 (*(t)->_dmamap_sync)((t), (m), (o), (l), (op)) : (void)0) 302 303#define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ 304 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) 305#define bus_dmamem_free(t, sg, n) \ 306 (*(t)->_dmamem_free)((t), (sg), (n)) 307#define bus_dmamem_map(t, sg, n, s, k, f) \ 308 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) 309#define bus_dmamem_unmap(t, k, s) \ 310 (*(t)->_dmamem_unmap)((t), (k), (s)) 311#define bus_dmamem_mmap(t, sg, n, o, p, f) \ 312 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) 313 314#define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP 315#define bus_dmatag_destroy(t) 316 317#if defined(_LANDISK_BUS_DMA_PRIVATE) 318int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, 319 bus_size_t, int, bus_dmamap_t *); 320void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); 321int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t, 322 struct proc *, int); 323int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *,int); 324int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); 325int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *, 326 int, bus_size_t, int); 327void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); 328void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, 329 bus_size_t, int); 330 331int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size, 332 bus_size_t alignment, bus_size_t boundary, bus_dma_segment_t *segs, 333 int nsegs, int *rsegs, int flags); 334void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, 335 int nsegs); 336int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs, 337 size_t size, void **kvap, int flags); 338void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva, size_t size); 339paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, 340 int nsegs, off_t off, int prot, int flags); 341#endif /* _LANDISK_BUS_DMA_PRIVATE */ 342 343#endif /* _LANDISK_BUS_FUNCS_H_ */ 344