1 /* $NetBSD: bus_funcs.h,v 1.1 2011/07/19 15:52:31 dyoung Exp $ */ 2 3 /*- 4 * Copyright (c) 1997, 1998, 2000, 2001 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 Carnegie-Mellon University. 35 * All rights reserved. 36 * 37 * Author: Chris G. Demetriou 38 * 39 * Permission to use, copy, modify and distribute this software and 40 * its documentation is hereby granted, provided that both the copyright 41 * notice and this permission notice appear in all copies of the 42 * software, derivative works or modified versions, and any portions 43 * thereof, and that both notices appear in supporting documentation. 44 * 45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 48 * 49 * Carnegie Mellon requests users of this software to return to 50 * 51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 52 * School of Computer Science 53 * Carnegie Mellon University 54 * Pittsburgh PA 15213-3890 55 * 56 * any improvements or extensions that they make and grant Carnegie the 57 * rights to redistribute these changes. 58 */ 59 60 #ifndef _DREAMCAST_BUS_FUNCS_H_ 61 #define _DREAMCAST_BUS_FUNCS_H_ 62 63 #ifdef _KERNEL 64 /* 65 * Utility macros; INTERNAL USE ONLY. 66 */ 67 #define __dbs_c(a,b) __CONCAT(a,b) 68 #define __dbs_opname(op,size) __dbs_c(__dbs_c(__dbs_c(dbs_,op),_),size) 69 70 #define __dbs_rs(sz, tn, t, h, o) \ 71 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \ 72 (*(t)->__dbs_opname(r,sz))((t)->dbs_cookie, h, o)) 73 74 #define __dbs_ws(sz, tn, t, h, o, v) \ 75 do { \ 76 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 77 (*(t)->__dbs_opname(w,sz))((t)->dbs_cookie, h, o, v); \ 78 } while (0) 79 80 #define __dbs_nonsingle(type, sz, tn, t, h, o, a, c) \ 81 do { \ 82 __BUS_SPACE_ADDRESS_SANITY((a), tn, "buffer"); \ 83 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 84 (*(t)->__dbs_opname(type,sz))((t)->dbs_cookie, h, o, a, c); \ 85 } while (0) 86 87 #define __dbs_set(type, sz, tn, t, h, o, v, c) \ 88 do { \ 89 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \ 90 (*(t)->__dbs_opname(type,sz))((t)->dbs_cookie, h, o, v, c); \ 91 } while (0) 92 93 #define __dbs_copy(sz, tn, t, h1, o1, h2, o2, cnt) \ 94 do { \ 95 __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), tn, "bus addr 1"); \ 96 __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), tn, "bus addr 2"); \ 97 (*(t)->__dbs_opname(c,sz))((t)->dbs_cookie, h1, o1, h2, o2, cnt); \ 98 } while (0) 99 100 101 /* 102 * Mapping and unmapping operations. 103 */ 104 #define bus_space_map(t, a, s, f, hp) \ 105 (*(t)->dbs_map)((t)->dbs_cookie, (a), (s), (f), (hp)) 106 #define bus_space_unmap(t, h, s) \ 107 (*(t)->dbs_unmap)((t)->dbs_cookie, (h), (s)) 108 #define bus_space_subregion(t, h, o, s, hp) \ 109 (*(t)->dbs_subregion)((t)->dbs_cookie, (h), (o), (s), (hp)) 110 #define bus_space_mmap(t, a, o, p, f) \ 111 (*(t)->dbs_mmap)((t)->dbs_cookie, (a), (o), (p), (f)) 112 113 #endif /* _KERNEL */ 114 115 #ifdef _KERNEL 116 /* 117 * Allocation and deallocation operations. 118 */ 119 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \ 120 (*(t)->dbs_alloc)((t)->dbs_cookie, (rs), (re), (s), (a), (b), \ 121 (f), (ap), (hp)) 122 #define bus_space_free(t, h, s) \ 123 (*(t)->dbs_free)((t)->dbs_cookie, (h), (s)) 124 125 /* 126 * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR. 127 */ 128 #define bus_space_vaddr(t, h) \ 129 (*(t)->dbs_vaddr)((t)->dbs_cookie, (h)) 130 131 /* 132 * Bus barrier operations. The Dreamcast does not currently require 133 * barriers, but we must provide the flags to MI code. 134 */ 135 #define bus_space_barrier(t, h, o, l, f) \ 136 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f))) 137 138 /* 139 * Bus read (single) operations. 140 */ 141 #define bus_space_read_1(t, h, o) __dbs_rs(1,uint8_t,(t),(h),(o)) 142 #define bus_space_read_2(t, h, o) __dbs_rs(2,uint16_t,(t),(h),(o)) 143 #define bus_space_read_4(t, h, o) __dbs_rs(4,uint32_t,(t),(h),(o)) 144 #define bus_space_read_8(t, h, o) __dbs_rs(8,uint64_t,(t),(h),(o)) 145 146 147 /* 148 * Bus read multiple operations. 149 */ 150 #define bus_space_read_multi_1(t, h, o, a, c) \ 151 __dbs_nonsingle(rm,1,uint8_t,(t),(h),(o),(a),(c)) 152 #define bus_space_read_multi_2(t, h, o, a, c) \ 153 __dbs_nonsingle(rm,2,uint16_t,(t),(h),(o),(a),(c)) 154 #define bus_space_read_multi_4(t, h, o, a, c) \ 155 __dbs_nonsingle(rm,4,uint32_t,(t),(h),(o),(a),(c)) 156 #define bus_space_read_multi_8(t, h, o, a, c) \ 157 __dbs_nonsingle(rm,8,uint64_t,(t),(h),(o),(a),(c)) 158 159 160 /* 161 * Bus read region operations. 162 */ 163 #define bus_space_read_region_1(t, h, o, a, c) \ 164 __dbs_nonsingle(rr,1,uint8_t,(t),(h),(o),(a),(c)) 165 #define bus_space_read_region_2(t, h, o, a, c) \ 166 __dbs_nonsingle(rr,2,uint16_t,(t),(h),(o),(a),(c)) 167 #define bus_space_read_region_4(t, h, o, a, c) \ 168 __dbs_nonsingle(rr,4,uint32_t,(t),(h),(o),(a),(c)) 169 #define bus_space_read_region_8(t, h, o, a, c) \ 170 __dbs_nonsingle(rr,8,uint64_t,(t),(h),(o),(a),(c)) 171 172 173 /* 174 * Bus write (single) operations. 175 */ 176 #define bus_space_write_1(t, h, o, v) __dbs_ws(1,uint8_t,(t),(h),(o),(v)) 177 #define bus_space_write_2(t, h, o, v) __dbs_ws(2,uint16_t,(t),(h),(o),(v)) 178 #define bus_space_write_4(t, h, o, v) __dbs_ws(4,uint32_t,(t),(h),(o),(v)) 179 #define bus_space_write_8(t, h, o, v) __dbs_ws(8,uint64_t,(t),(h),(o),(v)) 180 181 182 /* 183 * Bus write multiple operations. 184 */ 185 #define bus_space_write_multi_1(t, h, o, a, c) \ 186 __dbs_nonsingle(wm,1,uint8_t,(t),(h),(o),(a),(c)) 187 #define bus_space_write_multi_2(t, h, o, a, c) \ 188 __dbs_nonsingle(wm,2,uint16_t,(t),(h),(o),(a),(c)) 189 #define bus_space_write_multi_4(t, h, o, a, c) \ 190 __dbs_nonsingle(wm,4,uint32_t,(t),(h),(o),(a),(c)) 191 #define bus_space_write_multi_8(t, h, o, a, c) \ 192 __dbs_nonsingle(wm,8,uint64_t,(t),(h),(o),(a),(c)) 193 194 195 /* 196 * Bus write region operations. 197 */ 198 #define bus_space_write_region_1(t, h, o, a, c) \ 199 __dbs_nonsingle(wr,1,uint8_t,(t),(h),(o),(a),(c)) 200 #define bus_space_write_region_2(t, h, o, a, c) \ 201 __dbs_nonsingle(wr,2,uint16_t,(t),(h),(o),(a),(c)) 202 #define bus_space_write_region_4(t, h, o, a, c) \ 203 __dbs_nonsingle(wr,4,uint32_t,(t),(h),(o),(a),(c)) 204 #define bus_space_write_region_8(t, h, o, a, c) \ 205 __dbs_nonsingle(wr,8,uint64_t,(t),(h),(o),(a),(c)) 206 207 208 /* 209 * Set multiple operations. 210 */ 211 #define bus_space_set_multi_1(t, h, o, v, c) \ 212 __dbs_set(sm,1,uint8_t,(t),(h),(o),(v),(c)) 213 #define bus_space_set_multi_2(t, h, o, v, c) \ 214 __dbs_set(sm,2,uint16_t,(t),(h),(o),(v),(c)) 215 #define bus_space_set_multi_4(t, h, o, v, c) \ 216 __dbs_set(sm,4,uint32_t,(t),(h),(o),(v),(c)) 217 #define bus_space_set_multi_8(t, h, o, v, c) \ 218 __dbs_set(sm,8,uint64_t,(t),(h),(o),(v),(c)) 219 220 221 /* 222 * Set region operations. 223 */ 224 #define bus_space_set_region_1(t, h, o, v, c) \ 225 __dbs_set(sr,1,uint8_t,(t),(h),(o),(v),(c)) 226 #define bus_space_set_region_2(t, h, o, v, c) \ 227 __dbs_set(sr,2,uint16_t,(t),(h),(o),(v),(c)) 228 #define bus_space_set_region_4(t, h, o, v, c) \ 229 __dbs_set(sr,4,uint32_t,(t),(h),(o),(v),(c)) 230 #define bus_space_set_region_8(t, h, o, v, c) \ 231 __dbs_set(sr,8,uint64_t,(t),(h),(o),(v),(c)) 232 233 234 /* 235 * Copy region operations. 236 */ 237 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \ 238 __dbs_copy(1, uint8_t, (t), (h1), (o1), (h2), (o2), (c)) 239 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \ 240 __dbs_copy(2, uint16_t, (t), (h1), (o1), (h2), (o2), (c)) 241 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \ 242 __dbs_copy(4, uint32_t, (t), (h1), (o1), (h2), (o2), (c)) 243 #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \ 244 __dbs_copy(8, uint64_t, (t), (h1), (o1), (h2), (o2), (c)) 245 246 /* 247 * Bus stream operations--defined in terms of non-stream counterparts 248 */ 249 #define __BUS_SPACE_HAS_STREAM_METHODS 1 250 #define bus_space_read_stream_1 bus_space_read_1 251 #define bus_space_read_stream_2 bus_space_read_2 252 #define bus_space_read_stream_4 bus_space_read_4 253 #define bus_space_read_stream_8 bus_space_read_8 254 #define bus_space_read_multi_stream_1 bus_space_read_multi_1 255 #define bus_space_read_multi_stream_2 bus_space_read_multi_2 256 #define bus_space_read_multi_stream_4 bus_space_read_multi_4 257 #define bus_space_read_multi_stream_8 bus_space_read_multi_8 258 #define bus_space_read_region_stream_1 bus_space_read_region_1 259 #define bus_space_read_region_stream_2 bus_space_read_region_2 260 #define bus_space_read_region_stream_4 bus_space_read_region_4 261 #define bus_space_read_region_stream_8 bus_space_read_region_8 262 #define bus_space_write_stream_1 bus_space_write_1 263 #define bus_space_write_stream_2 bus_space_write_2 264 #define bus_space_write_stream_4 bus_space_write_4 265 #define bus_space_write_stream_8 bus_space_write_8 266 #define bus_space_write_multi_stream_1 bus_space_write_multi_1 267 #define bus_space_write_multi_stream_2 bus_space_write_multi_2 268 #define bus_space_write_multi_stream_4 bus_space_write_multi_4 269 #define bus_space_write_multi_stream_8 bus_space_write_multi_8 270 #define bus_space_write_region_stream_1 bus_space_write_region_1 271 #define bus_space_write_region_stream_2 bus_space_write_region_2 272 #define bus_space_write_region_stream_4 bus_space_write_region_4 273 #define bus_space_write_region_stream_8 bus_space_write_region_8 274 275 #endif /* _KERNEL */ 276 277 #define bus_dmamap_create(t, s, n, m, b, f, p) \ 278 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) 279 #define bus_dmamap_destroy(t, p) \ 280 (*(t)->_dmamap_destroy)((t), (p)) 281 #define bus_dmamap_load(t, m, b, s, p, f) \ 282 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) 283 #define bus_dmamap_load_mbuf(t, m, b, f) \ 284 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) 285 #define bus_dmamap_load_uio(t, m, u, f) \ 286 (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) 287 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \ 288 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) 289 #define bus_dmamap_unload(t, p) \ 290 (*(t)->_dmamap_unload)((t), (p)) 291 #define bus_dmamap_sync(t, m, o, l, op) \ 292 (void)((t)->_dmamap_sync ? \ 293 (*(t)->_dmamap_sync)((t), (m), (o), (l), (op)) : (void)0) 294 295 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ 296 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) 297 #define bus_dmamem_free(t, sg, n) \ 298 (*(t)->_dmamem_free)((t), (sg), (n)) 299 #define bus_dmamem_map(t, sg, n, s, k, f) \ 300 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) 301 #define bus_dmamem_unmap(t, k, s) \ 302 (*(t)->_dmamem_unmap)((t), (k), (s)) 303 #define bus_dmamem_mmap(t, sg, n, o, p, f) \ 304 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) 305 306 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP 307 #define bus_dmatag_destroy(t) 308 309 #endif /* _DREAMCAST_BUS_FUNCS_H_ */ 310