1 /* $NetBSD: bus.h,v 1.11 2003/07/28 17:35:54 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1996, 1997, 1998, 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 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40 /* 41 * Copyright (c) 1996 Charles M. Hannum. All rights reserved. 42 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 43 * 44 * Redistribution and use in source and binary forms, with or without 45 * modification, are permitted provided that the following conditions 46 * are met: 47 * 1. Redistributions of source code must retain the above copyright 48 * notice, this list of conditions and the following disclaimer. 49 * 2. Redistributions in binary form must reproduce the above copyright 50 * notice, this list of conditions and the following disclaimer in the 51 * documentation and/or other materials provided with the distribution. 52 * 3. All advertising materials mentioning features or use of this software 53 * must display the following acknowledgement: 54 * This product includes software developed by Christopher G. Demetriou 55 * for the NetBSD Project. 56 * 4. The name of the author may not be used to endorse or promote products 57 * derived from this software without specific prior written permission 58 * 59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 60 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 61 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 62 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 63 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 64 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 65 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 67 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 68 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 69 * 70 * $FreeBSD$ 71 */ 72 73 #ifndef _MACHINE_BUS_H_ 74 #define _MACHINE_BUS_H_ 75 76 /* 77 * Addresses (in bus space). 78 */ 79 typedef u_long bus_addr_t; 80 typedef u_long bus_size_t; 81 82 /* 83 * Access methods for bus space. 84 */ 85 typedef struct bus_space *bus_space_tag_t; 86 typedef u_long bus_space_handle_t; 87 88 /* 89 * int bus_space_map (bus_space_tag_t t, bus_addr_t addr, 90 * bus_size_t size, int flags, bus_space_handle_t *bshp); 91 * 92 * Map a region of bus space. 93 */ 94 95 #define BUS_SPACE_MAP_CACHEABLE 0x01 96 #define BUS_SPACE_MAP_LINEAR 0x02 97 #define BUS_SPACE_MAP_PREFETCHABLE 0x04 98 99 struct bus_space { 100 /* cookie */ 101 void *bs_cookie; 102 103 /* mapping/unmapping */ 104 int (*bs_map) (void *, bus_addr_t, bus_size_t, 105 int, bus_space_handle_t *); 106 void (*bs_unmap) (void *, bus_size_t); 107 int (*bs_subregion) (void *, bus_space_handle_t, 108 bus_size_t, bus_size_t, bus_space_handle_t *); 109 110 /* allocation/deallocation */ 111 int (*bs_alloc) (void *, bus_addr_t, bus_addr_t, 112 bus_size_t, bus_size_t, bus_size_t, int, 113 bus_addr_t *, bus_space_handle_t *); 114 void (*bs_free) (void *, bus_space_handle_t, 115 bus_size_t); 116 117 /* get kernel virtual address */ 118 void * (*bs_vaddr) (void *, bus_space_handle_t); 119 120 /* barrier */ 121 void (*bs_barrier) (void *, bus_space_handle_t, 122 bus_size_t, bus_size_t, int); 123 124 /* read (single) */ 125 u_int8_t (*bs_r_1) (void *, bus_space_handle_t, bus_size_t); 126 u_int16_t (*bs_r_2) (void *, bus_space_handle_t, bus_size_t); 127 u_int32_t (*bs_r_4) (void *, bus_space_handle_t, bus_size_t); 128 u_int64_t (*bs_r_8) (void *, bus_space_handle_t, bus_size_t); 129 130 /* read multiple */ 131 void (*bs_rm_1) (void *, bus_space_handle_t, bus_size_t, 132 u_int8_t *, bus_size_t); 133 void (*bs_rm_2) (void *, bus_space_handle_t, bus_size_t, 134 u_int16_t *, bus_size_t); 135 void (*bs_rm_4) (void *, bus_space_handle_t, 136 bus_size_t, u_int32_t *, bus_size_t); 137 void (*bs_rm_8) (void *, bus_space_handle_t, 138 bus_size_t, u_int64_t *, bus_size_t); 139 140 /* read region */ 141 void (*bs_rr_1) (void *, bus_space_handle_t, 142 bus_size_t, u_int8_t *, bus_size_t); 143 void (*bs_rr_2) (void *, bus_space_handle_t, 144 bus_size_t, u_int16_t *, bus_size_t); 145 void (*bs_rr_4) (void *, bus_space_handle_t, 146 bus_size_t, u_int32_t *, bus_size_t); 147 void (*bs_rr_8) (void *, bus_space_handle_t, 148 bus_size_t, u_int64_t *, bus_size_t); 149 150 /* write (single) */ 151 void (*bs_w_1) (void *, bus_space_handle_t, 152 bus_size_t, u_int8_t); 153 void (*bs_w_2) (void *, bus_space_handle_t, 154 bus_size_t, u_int16_t); 155 void (*bs_w_4) (void *, bus_space_handle_t, 156 bus_size_t, u_int32_t); 157 void (*bs_w_8) (void *, bus_space_handle_t, 158 bus_size_t, u_int64_t); 159 160 /* write multiple */ 161 void (*bs_wm_1) (void *, bus_space_handle_t, 162 bus_size_t, const u_int8_t *, bus_size_t); 163 void (*bs_wm_2) (void *, bus_space_handle_t, 164 bus_size_t, const u_int16_t *, bus_size_t); 165 void (*bs_wm_4) (void *, bus_space_handle_t, 166 bus_size_t, const u_int32_t *, bus_size_t); 167 void (*bs_wm_8) (void *, bus_space_handle_t, 168 bus_size_t, const u_int64_t *, bus_size_t); 169 170 /* write region */ 171 void (*bs_wr_1) (void *, bus_space_handle_t, 172 bus_size_t, const u_int8_t *, bus_size_t); 173 void (*bs_wr_2) (void *, bus_space_handle_t, 174 bus_size_t, const u_int16_t *, bus_size_t); 175 void (*bs_wr_4) (void *, bus_space_handle_t, 176 bus_size_t, const u_int32_t *, bus_size_t); 177 void (*bs_wr_8) (void *, bus_space_handle_t, 178 bus_size_t, const u_int64_t *, bus_size_t); 179 180 /* set multiple */ 181 void (*bs_sm_1) (void *, bus_space_handle_t, 182 bus_size_t, u_int8_t, bus_size_t); 183 void (*bs_sm_2) (void *, bus_space_handle_t, 184 bus_size_t, u_int16_t, bus_size_t); 185 void (*bs_sm_4) (void *, bus_space_handle_t, 186 bus_size_t, u_int32_t, bus_size_t); 187 void (*bs_sm_8) (void *, bus_space_handle_t, 188 bus_size_t, u_int64_t, bus_size_t); 189 190 /* set region */ 191 void (*bs_sr_1) (void *, bus_space_handle_t, 192 bus_size_t, u_int8_t, bus_size_t); 193 void (*bs_sr_2) (void *, bus_space_handle_t, 194 bus_size_t, u_int16_t, bus_size_t); 195 void (*bs_sr_4) (void *, bus_space_handle_t, 196 bus_size_t, u_int32_t, bus_size_t); 197 void (*bs_sr_8) (void *, bus_space_handle_t, 198 bus_size_t, u_int64_t, bus_size_t); 199 200 /* copy */ 201 void (*bs_c_1) (void *, bus_space_handle_t, bus_size_t, 202 bus_space_handle_t, bus_size_t, bus_size_t); 203 void (*bs_c_2) (void *, bus_space_handle_t, bus_size_t, 204 bus_space_handle_t, bus_size_t, bus_size_t); 205 void (*bs_c_4) (void *, bus_space_handle_t, bus_size_t, 206 bus_space_handle_t, bus_size_t, bus_size_t); 207 void (*bs_c_8) (void *, bus_space_handle_t, bus_size_t, 208 bus_space_handle_t, bus_size_t, bus_size_t); 209 210 }; 211 212 213 /* 214 * Utility macros; INTERNAL USE ONLY. 215 */ 216 #define __bs_c(a,b) __CONCAT(a,b) 217 #define __bs_opname(op,size) __bs_c(__bs_c(__bs_c(bs_,op),_),size) 218 219 #define __bs_rs(sz, t, h, o) \ 220 (*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o) 221 #define __bs_ws(sz, t, h, o, v) \ 222 (*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v) 223 #define __bs_nonsingle(type, sz, t, h, o, a, c) \ 224 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c) 225 #define __bs_set(type, sz, t, h, o, v, c) \ 226 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c) 227 #define __bs_copy(sz, t, h1, o1, h2, o2, cnt) \ 228 (*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt) 229 230 231 /* 232 * Mapping and unmapping operations. 233 */ 234 #define bus_space_map(t, a, s, c, hp) \ 235 (*(t)->bs_map)((t)->bs_cookie, (a), (s), (c), (hp)) 236 #define bus_space_unmap(t, h, s) \ 237 (*(t)->bs_unmap)((t)->bs_cookie, (h), (s)) 238 #define bus_space_subregion(t, h, o, s, hp) \ 239 (*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp)) 240 241 242 /* 243 * Allocation and deallocation operations. 244 */ 245 #define bus_space_alloc(t, rs, re, s, a, b, c, ap, hp) \ 246 (*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b), \ 247 (c), (ap), (hp)) 248 #define bus_space_free(t, h, s) \ 249 (*(t)->bs_free)((t)->bs_cookie, (h), (s)) 250 251 /* 252 * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR. 253 */ 254 #define bus_space_vaddr(t, h) \ 255 (*(t)->bs_vaddr)((t)->bs_cookie, (h)) 256 257 /* 258 * Bus barrier operations. 259 */ 260 #define bus_space_barrier(t, h, o, l, f) \ 261 (*(t)->bs_barrier)((t)->bs_cookie, (h), (o), (l), (f)) 262 263 #define BUS_SPACE_BARRIER_READ 0x01 264 #define BUS_SPACE_BARRIER_WRITE 0x02 265 266 /* 267 * Bus read (single) operations. 268 */ 269 #define bus_space_read_1(t, h, o) __bs_rs(1,(t),(h),(o)) 270 #define bus_space_read_2(t, h, o) __bs_rs(2,(t),(h),(o)) 271 #define bus_space_read_4(t, h, o) __bs_rs(4,(t),(h),(o)) 272 #define bus_space_read_8(t, h, o) __bs_rs(8,(t),(h),(o)) 273 274 275 /* 276 * Bus read multiple operations. 277 */ 278 #define bus_space_read_multi_1(t, h, o, a, c) \ 279 __bs_nonsingle(rm,1,(t),(h),(o),(a),(c)) 280 #define bus_space_read_multi_2(t, h, o, a, c) \ 281 __bs_nonsingle(rm,2,(t),(h),(o),(a),(c)) 282 #define bus_space_read_multi_4(t, h, o, a, c) \ 283 __bs_nonsingle(rm,4,(t),(h),(o),(a),(c)) 284 #define bus_space_read_multi_8(t, h, o, a, c) \ 285 __bs_nonsingle(rm,8,(t),(h),(o),(a),(c)) 286 287 288 /* 289 * Bus read region operations. 290 */ 291 #define bus_space_read_region_1(t, h, o, a, c) \ 292 __bs_nonsingle(rr,1,(t),(h),(o),(a),(c)) 293 #define bus_space_read_region_2(t, h, o, a, c) \ 294 __bs_nonsingle(rr,2,(t),(h),(o),(a),(c)) 295 #define bus_space_read_region_4(t, h, o, a, c) \ 296 __bs_nonsingle(rr,4,(t),(h),(o),(a),(c)) 297 #define bus_space_read_region_8(t, h, o, a, c) \ 298 __bs_nonsingle(rr,8,(t),(h),(o),(a),(c)) 299 300 301 /* 302 * Bus write (single) operations. 303 */ 304 #define bus_space_write_1(t, h, o, v) __bs_ws(1,(t),(h),(o),(v)) 305 #define bus_space_write_2(t, h, o, v) __bs_ws(2,(t),(h),(o),(v)) 306 #define bus_space_write_4(t, h, o, v) __bs_ws(4,(t),(h),(o),(v)) 307 #define bus_space_write_8(t, h, o, v) __bs_ws(8,(t),(h),(o),(v)) 308 309 310 /* 311 * Bus write multiple operations. 312 */ 313 #define bus_space_write_multi_1(t, h, o, a, c) \ 314 __bs_nonsingle(wm,1,(t),(h),(o),(a),(c)) 315 #define bus_space_write_multi_2(t, h, o, a, c) \ 316 __bs_nonsingle(wm,2,(t),(h),(o),(a),(c)) 317 #define bus_space_write_multi_4(t, h, o, a, c) \ 318 __bs_nonsingle(wm,4,(t),(h),(o),(a),(c)) 319 #define bus_space_write_multi_8(t, h, o, a, c) \ 320 __bs_nonsingle(wm,8,(t),(h),(o),(a),(c)) 321 322 323 /* 324 * Bus write region operations. 325 */ 326 #define bus_space_write_region_1(t, h, o, a, c) \ 327 __bs_nonsingle(wr,1,(t),(h),(o),(a),(c)) 328 #define bus_space_write_region_2(t, h, o, a, c) \ 329 __bs_nonsingle(wr,2,(t),(h),(o),(a),(c)) 330 #define bus_space_write_region_4(t, h, o, a, c) \ 331 __bs_nonsingle(wr,4,(t),(h),(o),(a),(c)) 332 #define bus_space_write_region_8(t, h, o, a, c) \ 333 __bs_nonsingle(wr,8,(t),(h),(o),(a),(c)) 334 335 336 /* 337 * Set multiple operations. 338 */ 339 #define bus_space_set_multi_1(t, h, o, v, c) \ 340 __bs_set(sm,1,(t),(h),(o),(v),(c)) 341 #define bus_space_set_multi_2(t, h, o, v, c) \ 342 __bs_set(sm,2,(t),(h),(o),(v),(c)) 343 #define bus_space_set_multi_4(t, h, o, v, c) \ 344 __bs_set(sm,4,(t),(h),(o),(v),(c)) 345 #define bus_space_set_multi_8(t, h, o, v, c) \ 346 __bs_set(sm,8,(t),(h),(o),(v),(c)) 347 348 349 /* 350 * Set region operations. 351 */ 352 #define bus_space_set_region_1(t, h, o, v, c) \ 353 __bs_set(sr,1,(t),(h),(o),(v),(c)) 354 #define bus_space_set_region_2(t, h, o, v, c) \ 355 __bs_set(sr,2,(t),(h),(o),(v),(c)) 356 #define bus_space_set_region_4(t, h, o, v, c) \ 357 __bs_set(sr,4,(t),(h),(o),(v),(c)) 358 #define bus_space_set_region_8(t, h, o, v, c) \ 359 __bs_set(sr,8,(t),(h),(o),(v),(c)) 360 361 362 /* 363 * Copy operations. 364 */ 365 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \ 366 __bs_copy(1, t, h1, o1, h2, o2, c) 367 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \ 368 __bs_copy(2, t, h1, o1, h2, o2, c) 369 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \ 370 __bs_copy(4, t, h1, o1, h2, o2, c) 371 #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \ 372 __bs_copy(8, t, h1, o1, h2, o2, c) 373 374 /* 375 * Macros to provide prototypes for all the functions used in the 376 * bus_space structure 377 */ 378 379 #define bs_map_proto(f) \ 380 int __bs_c(f,_bs_map) (void *t, bus_addr_t addr, \ 381 bus_size_t size, int cacheable, bus_space_handle_t *bshp); 382 383 #define bs_unmap_proto(f) \ 384 void __bs_c(f,_bs_unmap) (void *t, bus_size_t size); 385 386 #define bs_subregion_proto(f) \ 387 int __bs_c(f,_bs_subregion) (void *t, bus_space_handle_t bsh, \ 388 bus_size_t offset, bus_size_t size, \ 389 bus_space_handle_t *nbshp); 390 391 #define bs_alloc_proto(f) \ 392 int __bs_c(f,_bs_alloc) (void *t, bus_addr_t rstart, \ 393 bus_addr_t rend, bus_size_t size, bus_size_t align, \ 394 bus_size_t boundary, int cacheable, bus_addr_t *addrp, \ 395 bus_space_handle_t *bshp); 396 397 #define bs_free_proto(f) \ 398 void __bs_c(f,_bs_free) (void *t, bus_space_handle_t bsh, \ 399 bus_size_t size); 400 401 #define bs_vaddr_proto(f) \ 402 void * __bs_c(f,_bs_vaddr) (void *t, bus_space_handle_t bsh); 403 404 #define bs_mmap_proto(f) \ 405 int __bs_c(f,_bs_mmap) (struct cdev *, vm_offset_t, vm_paddr_t *, int); 406 407 #define bs_barrier_proto(f) \ 408 void __bs_c(f,_bs_barrier) (void *t, bus_space_handle_t bsh, \ 409 bus_size_t offset, bus_size_t len, int flags); 410 411 #define bs_r_1_proto(f) \ 412 u_int8_t __bs_c(f,_bs_r_1) (void *t, bus_space_handle_t bsh, \ 413 bus_size_t offset); 414 415 #define bs_r_2_proto(f) \ 416 u_int16_t __bs_c(f,_bs_r_2) (void *t, bus_space_handle_t bsh, \ 417 bus_size_t offset); 418 419 #define bs_r_4_proto(f) \ 420 u_int32_t __bs_c(f,_bs_r_4) (void *t, bus_space_handle_t bsh, \ 421 bus_size_t offset); 422 423 #define bs_r_8_proto(f) \ 424 u_int64_t __bs_c(f,_bs_r_8) (void *t, bus_space_handle_t bsh, \ 425 bus_size_t offset); 426 427 #define bs_w_1_proto(f) \ 428 void __bs_c(f,_bs_w_1) (void *t, bus_space_handle_t bsh, \ 429 bus_size_t offset, u_int8_t value); 430 431 #define bs_w_2_proto(f) \ 432 void __bs_c(f,_bs_w_2) (void *t, bus_space_handle_t bsh, \ 433 bus_size_t offset, u_int16_t value); 434 435 #define bs_w_4_proto(f) \ 436 void __bs_c(f,_bs_w_4) (void *t, bus_space_handle_t bsh, \ 437 bus_size_t offset, u_int32_t value); 438 439 #define bs_w_8_proto(f) \ 440 void __bs_c(f,_bs_w_8) (void *t, bus_space_handle_t bsh, \ 441 bus_size_t offset, u_int64_t value); 442 443 #define bs_rm_1_proto(f) \ 444 void __bs_c(f,_bs_rm_1) (void *t, bus_space_handle_t bsh, \ 445 bus_size_t offset, u_int8_t *addr, bus_size_t count); 446 447 #define bs_rm_2_proto(f) \ 448 void __bs_c(f,_bs_rm_2) (void *t, bus_space_handle_t bsh, \ 449 bus_size_t offset, u_int16_t *addr, bus_size_t count); 450 451 #define bs_rm_4_proto(f) \ 452 void __bs_c(f,_bs_rm_4) (void *t, bus_space_handle_t bsh, \ 453 bus_size_t offset, u_int32_t *addr, bus_size_t count); 454 455 #define bs_rm_8_proto(f) \ 456 void __bs_c(f,_bs_rm_8) (void *t, bus_space_handle_t bsh, \ 457 bus_size_t offset, u_int64_t *addr, bus_size_t count); 458 459 #define bs_wm_1_proto(f) \ 460 void __bs_c(f,_bs_wm_1) (void *t, bus_space_handle_t bsh, \ 461 bus_size_t offset, const u_int8_t *addr, bus_size_t count); 462 463 #define bs_wm_2_proto(f) \ 464 void __bs_c(f,_bs_wm_2) (void *t, bus_space_handle_t bsh, \ 465 bus_size_t offset, const u_int16_t *addr, bus_size_t count); 466 467 #define bs_wm_4_proto(f) \ 468 void __bs_c(f,_bs_wm_4) (void *t, bus_space_handle_t bsh, \ 469 bus_size_t offset, const u_int32_t *addr, bus_size_t count); 470 471 #define bs_wm_8_proto(f) \ 472 void __bs_c(f,_bs_wm_8) (void *t, bus_space_handle_t bsh, \ 473 bus_size_t offset, const u_int64_t *addr, bus_size_t count); 474 475 #define bs_rr_1_proto(f) \ 476 void __bs_c(f, _bs_rr_1) (void *t, bus_space_handle_t bsh, \ 477 bus_size_t offset, u_int8_t *addr, bus_size_t count); 478 479 #define bs_rr_2_proto(f) \ 480 void __bs_c(f, _bs_rr_2) (void *t, bus_space_handle_t bsh, \ 481 bus_size_t offset, u_int16_t *addr, bus_size_t count); 482 483 #define bs_rr_4_proto(f) \ 484 void __bs_c(f, _bs_rr_4) (void *t, bus_space_handle_t bsh, \ 485 bus_size_t offset, u_int32_t *addr, bus_size_t count); 486 487 #define bs_rr_8_proto(f) \ 488 void __bs_c(f, _bs_rr_8) (void *t, bus_space_handle_t bsh, \ 489 bus_size_t offset, u_int64_t *addr, bus_size_t count); 490 491 #define bs_wr_1_proto(f) \ 492 void __bs_c(f, _bs_wr_1) (void *t, bus_space_handle_t bsh, \ 493 bus_size_t offset, const u_int8_t *addr, bus_size_t count); 494 495 #define bs_wr_2_proto(f) \ 496 void __bs_c(f, _bs_wr_2) (void *t, bus_space_handle_t bsh, \ 497 bus_size_t offset, const u_int16_t *addr, bus_size_t count); 498 499 #define bs_wr_4_proto(f) \ 500 void __bs_c(f, _bs_wr_4) (void *t, bus_space_handle_t bsh, \ 501 bus_size_t offset, const u_int32_t *addr, bus_size_t count); 502 503 #define bs_wr_8_proto(f) \ 504 void __bs_c(f, _bs_wr_8) (void *t, bus_space_handle_t bsh, \ 505 bus_size_t offset, const u_int64_t *addr, bus_size_t count); 506 507 #define bs_sm_1_proto(f) \ 508 void __bs_c(f,_bs_sm_1) (void *t, bus_space_handle_t bsh, \ 509 bus_size_t offset, u_int8_t value, bus_size_t count); 510 511 #define bs_sm_2_proto(f) \ 512 void __bs_c(f,_bs_sm_2) (void *t, bus_space_handle_t bsh, \ 513 bus_size_t offset, u_int16_t value, bus_size_t count); 514 515 #define bs_sm_4_proto(f) \ 516 void __bs_c(f,_bs_sm_4) (void *t, bus_space_handle_t bsh, \ 517 bus_size_t offset, u_int32_t value, bus_size_t count); 518 519 #define bs_sm_8_proto(f) \ 520 void __bs_c(f,_bs_sm_8) (void *t, bus_space_handle_t bsh, \ 521 bus_size_t offset, u_int64_t value, bus_size_t count); 522 523 #define bs_sr_1_proto(f) \ 524 void __bs_c(f,_bs_sr_1) (void *t, bus_space_handle_t bsh, \ 525 bus_size_t offset, u_int8_t value, bus_size_t count); 526 527 #define bs_sr_2_proto(f) \ 528 void __bs_c(f,_bs_sr_2) (void *t, bus_space_handle_t bsh, \ 529 bus_size_t offset, u_int16_t value, bus_size_t count); 530 531 #define bs_sr_4_proto(f) \ 532 void __bs_c(f,_bs_sr_4) (void *t, bus_space_handle_t bsh, \ 533 bus_size_t offset, u_int32_t value, bus_size_t count); 534 535 #define bs_sr_8_proto(f) \ 536 void __bs_c(f,_bs_sr_8) (void *t, bus_space_handle_t bsh, \ 537 bus_size_t offset, u_int64_t value, bus_size_t count); 538 539 #define bs_c_1_proto(f) \ 540 void __bs_c(f,_bs_c_1) (void *t, bus_space_handle_t bsh1, \ 541 bus_size_t offset1, bus_space_handle_t bsh2, \ 542 bus_size_t offset2, bus_size_t count); 543 544 #define bs_c_2_proto(f) \ 545 void __bs_c(f,_bs_c_2) (void *t, bus_space_handle_t bsh1, \ 546 bus_size_t offset1, bus_space_handle_t bsh2, \ 547 bus_size_t offset2, bus_size_t count); 548 549 #define bs_c_4_proto(f) \ 550 void __bs_c(f,_bs_c_4) (void *t, bus_space_handle_t bsh1, \ 551 bus_size_t offset1, bus_space_handle_t bsh2, \ 552 bus_size_t offset2, bus_size_t count); 553 554 #define bs_c_8_proto(f) \ 555 void __bs_c(f,_bs_c_8) (void *t, bus_space_handle_t bsh1, \ 556 bus_size_t offset1, bus_space_handle_t bsh2, \ 557 bus_size_t offset2, bus_size_t count); 558 559 #define bs_protos(f) \ 560 bs_map_proto(f); \ 561 bs_unmap_proto(f); \ 562 bs_subregion_proto(f); \ 563 bs_alloc_proto(f); \ 564 bs_free_proto(f); \ 565 bs_vaddr_proto(f); \ 566 bs_mmap_proto(f); \ 567 bs_barrier_proto(f); \ 568 bs_r_1_proto(f); \ 569 bs_r_2_proto(f); \ 570 bs_r_4_proto(f); \ 571 bs_r_8_proto(f); \ 572 bs_w_1_proto(f); \ 573 bs_w_2_proto(f); \ 574 bs_w_4_proto(f); \ 575 bs_w_8_proto(f); \ 576 bs_rm_1_proto(f); \ 577 bs_rm_2_proto(f); \ 578 bs_rm_4_proto(f); \ 579 bs_rm_8_proto(f); \ 580 bs_wm_1_proto(f); \ 581 bs_wm_2_proto(f); \ 582 bs_wm_4_proto(f); \ 583 bs_wm_8_proto(f); \ 584 bs_rr_1_proto(f); \ 585 bs_rr_2_proto(f); \ 586 bs_rr_4_proto(f); \ 587 bs_rr_8_proto(f); \ 588 bs_wr_1_proto(f); \ 589 bs_wr_2_proto(f); \ 590 bs_wr_4_proto(f); \ 591 bs_wr_8_proto(f); \ 592 bs_sm_1_proto(f); \ 593 bs_sm_2_proto(f); \ 594 bs_sm_4_proto(f); \ 595 bs_sm_8_proto(f); \ 596 bs_sr_1_proto(f); \ 597 bs_sr_2_proto(f); \ 598 bs_sr_4_proto(f); \ 599 bs_sr_8_proto(f); \ 600 bs_c_1_proto(f); \ 601 bs_c_2_proto(f); \ 602 bs_c_4_proto(f); \ 603 bs_c_8_proto(f); 604 605 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t) 606 607 /* Bus Space DMA macros */ 608 609 /* 610 * Flags used in various bus DMA methods. 611 */ 612 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */ 613 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */ 614 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */ 615 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */ 616 #define BUS_DMA_ZERO 0x008 /* hint: sequential, unidirectional */ 617 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */ 618 #define BUS_DMA_BUS2 0x020 619 #define BUS_DMA_BUS3 0x040 620 #define BUS_DMA_BUS4 0x080 621 622 /* 623 * Private flags stored in the DMA map. 624 */ 625 #define ARM32_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */ 626 627 /* Forwards needed by prototypes below. */ 628 struct mbuf; 629 struct uio; 630 631 /* 632 * Operations performed by bus_dmamap_sync(). 633 */ 634 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */ 635 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */ 636 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */ 637 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */ 638 639 typedef struct bus_dma_tag *bus_dma_tag_t; 640 typedef struct bus_dmamap *bus_dmamap_t; 641 642 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0) 643 644 /* 645 * bus_dma_segment_t 646 * 647 * Describes a single contiguous DMA transaction. Values 648 * are suitable for programming into DMA registers. 649 */ 650 struct bus_dma_segment { 651 /* 652 * PUBLIC MEMBERS: these are used by machine-independent code. 653 */ 654 bus_addr_t ds_addr; /* DMA address */ 655 bus_size_t ds_len; /* length of transfer */ 656 }; 657 typedef struct bus_dma_segment bus_dma_segment_t; 658 659 /* 660 * arm32_dma_range 661 * 662 * This structure describes a valid DMA range. 663 */ 664 struct arm32_dma_range { 665 bus_addr_t dr_sysbase; /* system base address */ 666 bus_addr_t dr_busbase; /* appears here on bus */ 667 bus_size_t dr_len; /* length of range */ 668 }; 669 670 /* 671 * bus_dma_tag_t 672 * 673 * A machine-dependent opaque type describing the implementation of 674 * DMA for a given bus. 675 */ 676 677 typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int); 678 typedef int bus_dmasync_op_t; 679 typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int); 680 681 682 #ifdef _ARM32_BUS_DMA_PRIVATE 683 684 /* _dm_buftype */ 685 #define ARM32_BUFTYPE_INVALID 0 686 #define ARM32_BUFTYPE_LINEAR 1 687 #define ARM32_BUFTYPE_MBUF 2 688 #define ARM32_BUFTYPE_UIO 3 689 #define ARM32_BUFTYPE_RAW 4 690 691 struct arm32_dma_range *bus_dma_get_range(void); 692 #endif /* _ARM32_BUS_DMA_PRIVATE */ 693 694 /* 695 * A function that returns 1 if the address cannot be accessed by 696 * a device and 0 if it can be. 697 */ 698 typedef int bus_dma_filter_t(void *, bus_addr_t); 699 700 /* 701 * A function that performs driver-specific syncronization on behalf of 702 * busdma. 703 */ 704 typedef enum { 705 BUS_DMA_LOCK = 0x01, 706 BUS_DMA_UNLOCK = 0x02, 707 } bus_dma_lock_op_t; 708 709 typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t); 710 711 /* 712 * Allocate a device specific dma_tag encapsulating the constraints of 713 * the parent tag in addition to other restrictions specified: 714 * 715 * alignment: alignment for segments. 716 * boundary: Boundary that segments cannot cross. 717 * lowaddr: Low restricted address that cannot appear in a mapping. 718 * highaddr: High restricted address that cannot appear in a mapping. 719 * filtfunc: An optional function to further test if an address 720 * within the range of lowaddr and highaddr cannot appear 721 * in a mapping. 722 * filtfuncarg: An argument that will be passed to filtfunc in addition 723 * to the address to test. 724 * maxsize: Maximum mapping size supported by this tag. 725 * nsegments: Number of discontinuities allowed in maps. 726 * maxsegsz: Maximum size of a segment in the map. 727 * flags: Bus DMA flags. 728 * dmat: A pointer to set to a valid dma tag should the return 729 * value of this function indicate success. 730 */ 731 int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment, 732 bus_size_t boundary, bus_addr_t lowaddr, 733 bus_addr_t highaddr, bus_dma_filter_t *filtfunc, 734 void *filtfuncarg, bus_size_t maxsize, int nsegments, 735 bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc, 736 void *lockfuncarg, bus_dma_tag_t *dmat); 737 738 int bus_dma_tag_destroy(bus_dma_tag_t dmat); 739 740 int bus_dmamap_create (bus_dma_tag_t, int, bus_dmamap_t *); 741 int bus_dmamap_destroy (bus_dma_tag_t, bus_dmamap_t); 742 int bus_dmamap_load (bus_dma_tag_t, bus_dmamap_t, void *, 743 bus_size_t, bus_dmamap_callback_t *, void *, int); 744 int bus_dmamap_load_mbuf (bus_dma_tag_t, bus_dmamap_t, 745 struct mbuf *, bus_dmamap_callback2_t *, void *, int); 746 int bus_dmamap_load_uio (bus_dma_tag_t, bus_dmamap_t, 747 struct uio *, bus_dmamap_callback2_t *, void *, int); 748 void bus_dmamap_unload (bus_dma_tag_t, bus_dmamap_t); 749 void bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t); 750 751 int bus_dmamem_alloc (bus_dma_tag_t tag, void **vaddr, int flag, 752 bus_dmamap_t *mapp); 753 void bus_dmamem_free (bus_dma_tag_t tag, void *vaddr, bus_dmamap_t map); 754 755 /* 756 * Generic helper function for manipulating mutexes. 757 */ 758 void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op); 759 760 #endif /* _MACHINE_BUS_H_ */ 761