1 /* $NetBSD: bus_funcs.h,v 1.1 2011/07/19 15:44:53 dyoung Exp $ */ 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 _EVBSH3_BUS_FUNCS_H_ 65 #define _EVBSH3_BUS_FUNCS_H_ 66 67 #ifdef _KERNEL 68 69 /* 70 * Utility macros; INTERNAL USE ONLY. 71 */ 72 #define __bs_c(a,b) __CONCAT(a,b) 73 #define __bs_opname(op,size) __bs_c(__bs_c(__bs_c(bs_,op),_),size) 74 75 #define __bs_rs(sz, tn, t, h, o) \ 76 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \ 77 (*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o)) 78 #define __bs_rss(sz, tn, t, h, o) \ 79 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \ 80 (*(t)->__bs_opname(rs,sz))((t)->bs_cookie, h, o)) 81 82 #define __bs_ws(sz, tn, t, h, o, v) \ 83 do { \ 84 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 85 (*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v); \ 86 } while (0) 87 #define __bs_wss(sz, tn, t, h, o, v) \ 88 do { \ 89 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 90 (*(t)->__bs_opname(ws,sz))((t)->bs_cookie, h, o, v); \ 91 } while (0) 92 93 #define __bs_nonsingle(type, sz, tn, t, h, o, a, c) \ 94 do { \ 95 __BUS_SPACE_ADDRESS_SANITY((a), tn, "buffer"); \ 96 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 97 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c); \ 98 } while (0) 99 100 #define __bs_set(type, sz, tn, t, h, o, v, c) \ 101 do { \ 102 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 103 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c); \ 104 } while (0) 105 106 #define __bs_copy(sz, tn, t, h1, o1, h2, o2, cnt) \ 107 do { \ 108 __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), tn, "bus addr 1"); \ 109 __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), tn, "bus addr 2"); \ 110 (*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt); \ 111 } while (0) 112 113 114 /* 115 * Mapping and unmapping operations. 116 */ 117 #define bus_space_map(t, a, s, f, hp) \ 118 (*(t)->bs_map)((t)->bs_cookie, (a), (s), (f), (hp)) 119 #define bus_space_unmap(t, h, s) \ 120 (*(t)->bs_unmap)((t)->bs_cookie, (h), (s)) 121 #define bus_space_subregion(t, h, o, s, hp) \ 122 (*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp)) 123 124 #endif /* _KERNEL */ 125 126 #ifdef _KERNEL 127 /* 128 * Allocation and deallocation operations. 129 */ 130 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \ 131 (*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b), \ 132 (f), (ap), (hp)) 133 #define bus_space_free(t, h, s) \ 134 (*(t)->bs_free)((t)->bs_cookie, (h), (s)) 135 136 /* 137 * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR. 138 */ 139 #define bus_space_vaddr(t, h) \ 140 (*(t)->bs_vaddr)((t)->bs_cookie, (h)) 141 142 /* 143 * Bus barrier operations. The SH3 does not currently require 144 * barriers, but we must provide the flags to MI code. 145 */ 146 #define bus_space_barrier(t, h, o, l, f) \ 147 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f))) 148 149 /* 150 * Bus read (single) operations. 151 */ 152 #define bus_space_read_1(t, h, o) __bs_rs(1,uint8_t,(t),(h),(o)) 153 #define bus_space_read_2(t, h, o) __bs_rs(2,uint16_t,(t),(h),(o)) 154 #define bus_space_read_4(t, h, o) __bs_rs(4,uint32_t,(t),(h),(o)) 155 #define bus_space_read_8(t, h, o) __bs_rs(8,uint64_t,(t),(h),(o)) 156 #define bus_space_read_stream_1(t, h, o) __bs_rss(1,uint8_t,(t),(h),(o)) 157 #define bus_space_read_stream_2(t, h, o) __bs_rss(2,uint16_t,(t),(h),(o)) 158 #define bus_space_read_stream_4(t, h, o) __bs_rss(4,uint32_t,(t),(h),(o)) 159 #define bus_space_read_stream_8(t, h, o) __bs_rss(8,uint64_t,(t),(h),(o)) 160 161 162 /* 163 * Bus read multiple operations. 164 */ 165 #define bus_space_read_multi_1(t, h, o, a, c) \ 166 __bs_nonsingle(rm,1,uint8_t,(t),(h),(o),(a),(c)) 167 #define bus_space_read_multi_2(t, h, o, a, c) \ 168 __bs_nonsingle(rm,2,uint16_t,(t),(h),(o),(a),(c)) 169 #define bus_space_read_multi_4(t, h, o, a, c) \ 170 __bs_nonsingle(rm,4,uint32_t,(t),(h),(o),(a),(c)) 171 #define bus_space_read_multi_8(t, h, o, a, c) \ 172 __bs_nonsingle(rm,8,uint64_t,(t),(h),(o),(a),(c)) 173 #define bus_space_read_multi_stream_1(t, h, o, a, c) \ 174 __bs_nonsingle(rms,1,uint8_t,(t),(h),(o),(a),(c)) 175 #define bus_space_read_multi_stream_2(t, h, o, a, c) \ 176 __bs_nonsingle(rms,2,uint16_t,(t),(h),(o),(a),(c)) 177 #define bus_space_read_multi_stream_4(t, h, o, a, c) \ 178 __bs_nonsingle(rms,4,uint32_t,(t),(h),(o),(a),(c)) 179 #define bus_space_read_multi_stream_8(t, h, o, a, c) \ 180 __bs_nonsingle(rms,8,uint64_t,(t),(h),(o),(a),(c)) 181 182 183 /* 184 * Bus read region operations. 185 */ 186 #define bus_space_read_region_1(t, h, o, a, c) \ 187 __bs_nonsingle(rr,1,uint8_t,(t),(h),(o),(a),(c)) 188 #define bus_space_read_region_2(t, h, o, a, c) \ 189 __bs_nonsingle(rr,2,uint16_t,(t),(h),(o),(a),(c)) 190 #define bus_space_read_region_4(t, h, o, a, c) \ 191 __bs_nonsingle(rr,4,uint32_t,(t),(h),(o),(a),(c)) 192 #define bus_space_read_region_8(t, h, o, a, c) \ 193 __bs_nonsingle(rr,8,uint64_t,(t),(h),(o),(a),(c)) 194 #define bus_space_read_region_stream_1(t, h, o, a, c) \ 195 __bs_nonsingle(rrs,1,uint8_t,(t),(h),(o),(a),(c)) 196 #define bus_space_read_region_stream_2(t, h, o, a, c) \ 197 __bs_nonsingle(rrs,2,uint16_t,(t),(h),(o),(a),(c)) 198 #define bus_space_read_region_stream_4(t, h, o, a, c) \ 199 __bs_nonsingle(rrs,4,uint32_t,(t),(h),(o),(a),(c)) 200 #define bus_space_read_region_stream_8(t, h, o, a, c) \ 201 __bs_nonsingle(rrs,8,uint64_t,(t),(h),(o),(a),(c)) 202 203 204 /* 205 * Bus write (single) operations. 206 */ 207 #define bus_space_write_1(t, h, o, v) __bs_ws(1,uint8_t,(t),(h),(o),(v)) 208 #define bus_space_write_2(t, h, o, v) __bs_ws(2,uint16_t,(t),(h),(o),(v)) 209 #define bus_space_write_4(t, h, o, v) __bs_ws(4,uint32_t,(t),(h),(o),(v)) 210 #define bus_space_write_8(t, h, o, v) __bs_ws(8,uint64_t,(t),(h),(o),(v)) 211 #define bus_space_write_stream_1(t, h, o, v) \ 212 __bs_wss(1,uint8_t,(t),(h),(o),(v)) 213 #define bus_space_write_stream_2(t, h, o, v) \ 214 __bs_wss(2,uint16_t,(t),(h),(o),(v)) 215 #define bus_space_write_stream_4(t, h, o, v) \ 216 __bs_wss(4,uint32_t,(t),(h),(o),(v)) 217 #define bus_space_write_stream_8(t, h, o, v) \ 218 __bs_wss(8,uint64_t,(t),(h),(o),(v)) 219 220 221 /* 222 * Bus write multiple operations. 223 */ 224 #define bus_space_write_multi_1(t, h, o, a, c) \ 225 __bs_nonsingle(wm,1,uint8_t,(t),(h),(o),(a),(c)) 226 #define bus_space_write_multi_2(t, h, o, a, c) \ 227 __bs_nonsingle(wm,2,uint16_t,(t),(h),(o),(a),(c)) 228 #define bus_space_write_multi_4(t, h, o, a, c) \ 229 __bs_nonsingle(wm,4,uint32_t,(t),(h),(o),(a),(c)) 230 #define bus_space_write_multi_8(t, h, o, a, c) \ 231 __bs_nonsingle(wm,8,uint64_t,(t),(h),(o),(a),(c)) 232 #define bus_space_write_multi_stream_1(t, h, o, a, c) \ 233 __bs_nonsingle(wms,1,uint8_t,(t),(h),(o),(a),(c)) 234 #define bus_space_write_multi_stream_2(t, h, o, a, c) \ 235 __bs_nonsingle(wms,2,uint16_t,(t),(h),(o),(a),(c)) 236 #define bus_space_write_multi_stream_4(t, h, o, a, c) \ 237 __bs_nonsingle(wms,4,uint32_t,(t),(h),(o),(a),(c)) 238 #define bus_space_write_multi_stream_8(t, h, o, a, c) \ 239 __bs_nonsingle(wms,8,uint64_t,(t),(h),(o),(a),(c)) 240 241 242 /* 243 * Bus write region operations. 244 */ 245 #define bus_space_write_region_1(t, h, o, a, c) \ 246 __bs_nonsingle(wr,1,uint8_t,(t),(h),(o),(a),(c)) 247 #define bus_space_write_region_2(t, h, o, a, c) \ 248 __bs_nonsingle(wr,2,uint16_t,(t),(h),(o),(a),(c)) 249 #define bus_space_write_region_4(t, h, o, a, c) \ 250 __bs_nonsingle(wr,4,uint32_t,(t),(h),(o),(a),(c)) 251 #define bus_space_write_region_8(t, h, o, a, c) \ 252 __bs_nonsingle(wr,8,uint64_t,(t),(h),(o),(a),(c)) 253 #define bus_space_write_region_stream_1(t, h, o, a, c) \ 254 __bs_nonsingle(wrs,1,uint8_t,(t),(h),(o),(a),(c)) 255 #define bus_space_write_region_stream_2(t, h, o, a, c) \ 256 __bs_nonsingle(wrs,2,uint16_t,(t),(h),(o),(a),(c)) 257 #define bus_space_write_region_stream_4(t, h, o, a, c) \ 258 __bs_nonsingle(wrs,4,uint32_t,(t),(h),(o),(a),(c)) 259 #define bus_space_write_region_stream_8(t, h, o, a, c) \ 260 __bs_nonsingle(wrs,8,uint64_t,(t),(h),(o),(a),(c)) 261 262 263 /* 264 * Set multiple operations. 265 */ 266 #define bus_space_set_multi_1(t, h, o, v, c) \ 267 __bs_set(sm,1,uint8_t,(t),(h),(o),(v),(c)) 268 #define bus_space_set_multi_2(t, h, o, v, c) \ 269 __bs_set(sm,2,uint16_t,(t),(h),(o),(v),(c)) 270 #define bus_space_set_multi_4(t, h, o, v, c) \ 271 __bs_set(sm,4,uint32_t,(t),(h),(o),(v),(c)) 272 #define bus_space_set_multi_8(t, h, o, v, c) \ 273 __bs_set(sm,8,uint64_t,(t),(h),(o),(v),(c)) 274 275 276 /* 277 * Set region operations. 278 */ 279 #define bus_space_set_region_1(t, h, o, v, c) \ 280 __bs_set(sr,1,uint8_t,(t),(h),(o),(v),(c)) 281 #define bus_space_set_region_2(t, h, o, v, c) \ 282 __bs_set(sr,2,uint16_t,(t),(h),(o),(v),(c)) 283 #define bus_space_set_region_4(t, h, o, v, c) \ 284 __bs_set(sr,4,uint32_t,(t),(h),(o),(v),(c)) 285 #define bus_space_set_region_8(t, h, o, v, c) \ 286 __bs_set(sr,8,uint64_t,(t),(h),(o),(v),(c)) 287 288 289 /* 290 * Copy region operations. 291 */ 292 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \ 293 __bs_copy(1, uint8_t, (t), (h1), (o1), (h2), (o2), (c)) 294 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \ 295 __bs_copy(2, uint16_t, (t), (h1), (o1), (h2), (o2), (c)) 296 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \ 297 __bs_copy(4, uint32_t, (t), (h1), (o1), (h2), (o2), (c)) 298 #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \ 299 __bs_copy(8, uint64_t, (t), (h1), (o1), (h2), (o2), (c)) 300 301 /* 302 * Bus stream operations--defined in terms of non-stream counterparts 303 */ 304 #define __BUS_SPACE_HAS_STREAM_METHODS 305 306 #endif /* _KERNEL */ 307 308 #define bus_dmamap_create(t, s, n, m, b, f, p) \ 309 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) 310 #define bus_dmamap_destroy(t, p) \ 311 (*(t)->_dmamap_destroy)((t), (p)) 312 #define bus_dmamap_load(t, m, b, s, p, f) \ 313 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) 314 #define bus_dmamap_load_mbuf(t, m, b, f) \ 315 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) 316 #define bus_dmamap_load_uio(t, m, u, f) \ 317 (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) 318 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \ 319 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) 320 #define bus_dmamap_unload(t, p) \ 321 (*(t)->_dmamap_unload)((t), (p)) 322 #define bus_dmamap_sync(t, m, o, l, op) \ 323 (void)((t)->_dmamap_sync ? \ 324 (*(t)->_dmamap_sync)((t), (m), (o), (l), (op)) : (void)0) 325 326 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ 327 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) 328 #define bus_dmamem_free(t, sg, n) \ 329 (*(t)->_dmamem_free)((t), (sg), (n)) 330 #define bus_dmamem_map(t, sg, n, s, k, f) \ 331 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) 332 #define bus_dmamem_unmap(t, k, s) \ 333 (*(t)->_dmamem_unmap)((t), (k), (s)) 334 #define bus_dmamem_mmap(t, sg, n, o, p, f) \ 335 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) 336 337 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP 338 #define bus_dmatag_destroy(t) 339 340 #if defined(_EVBSH3_BUS_DMA_PRIVATE) 341 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, 342 bus_size_t, int, bus_dmamap_t *); 343 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); 344 int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t, 345 struct proc *, int); 346 int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *,int); 347 int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int); 348 int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *, 349 int, bus_size_t, int); 350 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); 351 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, 352 bus_size_t, int); 353 354 int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size, 355 bus_size_t alignment, bus_size_t boundary, bus_dma_segment_t *segs, 356 int nsegs, int *rsegs, int flags); 357 void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, 358 int nsegs); 359 int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs, 360 size_t size, void **kvap, int flags); 361 void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva, size_t size); 362 paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, 363 int nsegs, off_t off, int prot, int flags); 364 #endif /* _EVBSH3_BUS_DMA_PRIVATE */ 365 366 #endif /* _EVBSH3_BUS_FUNCS_H_ */ 367