1 /* $NetBSD: bus.h,v 1.30 2011/02/20 07:50:25 matt 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 * 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 #ifndef _PMAX_BUS_H_ 34 #define _PMAX_BUS_H_ 35 36 #include <mips/locore.h> 37 38 /* 39 * Utility macros; do not use outside this file. 40 */ 41 #define __PB_TYPENAME_PREFIX(BITS) ___CONCAT(u_int,BITS) 42 #define __PB_TYPENAME(BITS) ___CONCAT(__PB_TYPENAME_PREFIX(BITS),_t) 43 44 /* 45 * Bus address and size types 46 */ 47 typedef u_long bus_addr_t; 48 typedef u_long bus_size_t; 49 50 /* 51 * Access methods for bus resources and address space. 52 */ 53 typedef int bus_space_tag_t; 54 typedef u_long bus_space_handle_t; 55 56 /* 57 * int bus_space_map(bus_space_tag_t t, bus_addr_t addr, 58 * bus_size_t size, int flags, bus_space_handle_t *bshp); 59 * 60 * Map a region of bus space. 61 */ 62 63 #define BUS_SPACE_MAP_CACHEABLE 0x01 64 #define BUS_SPACE_MAP_LINEAR 0x02 65 #define BUS_SPACE_MAP_PREFETCHABLE 0x04 66 67 int bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, 68 int, bus_space_handle_t *); 69 70 /* 71 * void bus_space_unmap(bus_space_tag_t t, 72 * bus_space_handle_t bsh, bus_size_t size); 73 * 74 * Unmap a region of bus space. 75 */ 76 77 void bus_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); 78 79 /* 80 * int bus_space_subregion(bus_space_tag_t t, 81 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, 82 * bus_space_handle_t *nbshp); 83 * 84 * Get a new handle for a subregion of an already-mapped area of bus space. 85 */ 86 87 int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh, 88 bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp); 89 90 /* 91 * int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart, 92 * bus_addr_t rend, bus_size_t size, bus_size_t align, 93 * bus_size_t boundary, int flags, bus_addr_t *addrp, 94 * bus_space_handle_t *bshp); 95 * 96 * Allocate a region of bus space. 97 */ 98 99 int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart, 100 bus_addr_t rend, bus_size_t size, bus_size_t align, 101 bus_size_t boundary, int cacheable, bus_addr_t *addrp, 102 bus_space_handle_t *bshp); 103 104 /* 105 * int bus_space_free(bus_space_tag_t t, 106 * bus_space_handle_t bsh, bus_size_t size); 107 * 108 * Free a region of bus space. 109 */ 110 111 void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, 112 bus_size_t size); 113 114 /* 115 * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t); 116 * 117 * Get the kernel virtual address for the mapped bus space. 118 * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR. 119 * (XXX not enforced) 120 */ 121 #define bus_space_vaddr(t, h) \ 122 ((void *)(h)) 123 124 /* 125 * u_intN_t bus_space_read_N(bus_space_tag_t tag, 126 * bus_space_handle_t bsh, bus_size_t offset); 127 * 128 * Read a 1, 2, 4, or 8 byte quantity from bus space 129 * described by tag/handle/offset. 130 */ 131 132 #define bus_space_read_1(t, h, o) \ 133 ((void) t, (*(volatile u_int8_t *)((h) + (o)))) 134 135 #define bus_space_read_2(t, h, o) \ 136 ((void) t, (*(volatile u_int16_t *)((h) + (o)))) 137 138 #define bus_space_read_4(t, h, o) \ 139 ((void) t, (*(volatile uint32_t *)((h) + (o)))) 140 141 #if 0 /* Cause a link error for bus_space_read_8 */ 142 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!! 143 #endif 144 145 /* 146 * void bus_space_read_multi_N(bus_space_tag_t tag, 147 * bus_space_handle_t bsh, bus_size_t offset, 148 * u_intN_t *addr, size_t count); 149 * 150 * Read `count' 1, 2, 4, or 8 byte quantities from bus space 151 * described by tag/handle/offset and copy into buffer provided. 152 */ 153 154 #define __PMAX_bus_space_read_multi(BYTES,BITS) \ 155 static __inline void __CONCAT(bus_space_read_multi_,BYTES) \ 156 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \ 157 __PB_TYPENAME(BITS) *, size_t); \ 158 \ 159 static __inline void \ 160 __CONCAT(bus_space_read_multi_,BYTES)( \ 161 bus_space_tag_t t, \ 162 bus_space_handle_t h, \ 163 bus_size_t o, \ 164 __PB_TYPENAME(BITS) *a, \ 165 size_t c) \ 166 { \ 167 \ 168 while (c--) \ 169 *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o); \ 170 } 171 172 __PMAX_bus_space_read_multi(1,8) 173 __PMAX_bus_space_read_multi(2,16) 174 __PMAX_bus_space_read_multi(4,32) 175 176 #if 0 /* Cause a link error for bus_space_read_multi_8 */ 177 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!! 178 #endif 179 180 #undef __PMAX_bus_space_read_multi 181 182 /* 183 * void bus_space_read_region_N(bus_space_tag_t tag, 184 * bus_space_handle_t bsh, bus_size_t offset, 185 * u_intN_t *addr, size_t count); 186 * 187 * Read `count' 1, 2, 4, or 8 byte quantities from bus space 188 * described by tag/handle and starting at `offset' and copy into 189 * buffer provided. 190 */ 191 192 #define __PMAX_bus_space_read_region(BYTES,BITS) \ 193 static __inline void __CONCAT(bus_space_read_region_,BYTES) \ 194 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \ 195 __PB_TYPENAME(BITS) *, size_t); \ 196 \ 197 static __inline void \ 198 __CONCAT(bus_space_read_region_,BYTES)( \ 199 bus_space_tag_t t, \ 200 bus_space_handle_t h, \ 201 bus_size_t o, \ 202 __PB_TYPENAME(BITS) *a, \ 203 size_t c) \ 204 { \ 205 \ 206 while (c--) { \ 207 *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o); \ 208 o += BYTES; \ 209 } \ 210 } 211 212 __PMAX_bus_space_read_region(1,8) 213 __PMAX_bus_space_read_region(2,16) 214 __PMAX_bus_space_read_region(4,32) 215 216 #if 0 /* Cause a link error for bus_space_read_region_8 */ 217 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!! 218 #endif 219 220 #undef __PMAX_bus_space_read_region 221 222 /* 223 * void bus_space_write_N(bus_space_tag_t tag, 224 * bus_space_handle_t bsh, bus_size_t offset, 225 * u_intN_t value); 226 * 227 * Write the 1, 2, 4, or 8 byte value `value' to bus space 228 * described by tag/handle/offset. 229 */ 230 231 #define bus_space_write_1(t, h, o, v) \ 232 do { \ 233 (void) t; \ 234 *(volatile uint8_t *)((h) + (o)) = (v); \ 235 wbflush(); /* XXX */ \ 236 } while (0) 237 238 #define bus_space_write_2(t, h, o, v) \ 239 do { \ 240 (void) t; \ 241 *(volatile uint16_t *)((h) + (o)) = (v); \ 242 wbflush(); /* XXX */ \ 243 } while (0) 244 245 #define bus_space_write_4(t, h, o, v) \ 246 do { \ 247 (void) t; \ 248 *(volatile uint32_t *)((h) + (o)) = (v); \ 249 wbflush(); /* XXX */ \ 250 } while (0) 251 252 #if 0 /* Cause a link error for bus_space_write_8 */ 253 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!! 254 #endif 255 256 /* 257 * void bus_space_write_multi_N(bus_space_tag_t tag, 258 * bus_space_handle_t bsh, bus_size_t offset, 259 * const u_intN_t *addr, size_t count); 260 * 261 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer 262 * provided to bus space described by tag/handle/offset. 263 */ 264 265 #define __PMAX_bus_space_write_multi(BYTES,BITS) \ 266 static __inline void __CONCAT(bus_space_write_multi_,BYTES) \ 267 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \ 268 __PB_TYPENAME(BITS) *, size_t); \ 269 \ 270 static __inline void \ 271 __CONCAT(bus_space_write_multi_,BYTES)( \ 272 bus_space_tag_t t, \ 273 bus_space_handle_t h, \ 274 bus_size_t o, \ 275 __PB_TYPENAME(BITS) *a, \ 276 size_t c) \ 277 { \ 278 \ 279 while (c--) \ 280 __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++); \ 281 } 282 283 __PMAX_bus_space_write_multi(1,8) 284 __PMAX_bus_space_write_multi(2,16) 285 __PMAX_bus_space_write_multi(4,32) 286 287 #if 0 /* Cause a link error for bus_space_write_8 */ 288 #define bus_space_write_multi_8(t, h, o, a, c) \ 289 !!! bus_space_write_multi_8 unimplimented !!! 290 #endif 291 292 #undef __PMAX_bus_space_write_multi 293 294 /* 295 * void bus_space_write_region_N(bus_space_tag_t tag, 296 * bus_space_handle_t bsh, bus_size_t offset, 297 * const u_intN_t *addr, size_t count); 298 * 299 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided 300 * to bus space described by tag/handle starting at `offset'. 301 */ 302 303 #define __PMAX_bus_space_write_region(BYTES,BITS) \ 304 static __inline void __CONCAT(bus_space_write_region_,BYTES) \ 305 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \ 306 __PB_TYPENAME(BITS) *, size_t); \ 307 \ 308 static __inline void \ 309 __CONCAT(bus_space_write_region_,BYTES)( \ 310 bus_space_tag_t t, \ 311 bus_space_handle_t h, \ 312 bus_size_t o, \ 313 __PB_TYPENAME(BITS) *a, \ 314 size_t c) \ 315 { \ 316 \ 317 while (c--) { \ 318 __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++); \ 319 o += BYTES; \ 320 } \ 321 } 322 323 __PMAX_bus_space_write_region(1,8) 324 __PMAX_bus_space_write_region(2,16) 325 __PMAX_bus_space_write_region(4,32) 326 327 #if 0 /* Cause a link error for bus_space_write_region_8 */ 328 #define bus_space_write_region_8 \ 329 !!! bus_space_write_region_8 unimplemented !!! 330 #endif 331 332 #undef __PMAX_bus_space_write_region 333 334 /* 335 * void bus_space_set_multi_N(bus_space_tag_t tag, 336 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val, 337 * size_t count); 338 * 339 * Write the 1, 2, 4, or 8 byte value `val' to bus space described 340 * by tag/handle/offset `count' times. 341 */ 342 343 #define __PMAX_bus_space_set_multi(BYTES,BITS) \ 344 static __inline void __CONCAT(bus_space_set_multi_,BYTES) \ 345 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \ 346 __PB_TYPENAME(BITS), size_t); \ 347 \ 348 static __inline void \ 349 __CONCAT(bus_space_set_multi_,BYTES)( \ 350 bus_space_tag_t t, \ 351 bus_space_handle_t h, \ 352 bus_size_t o, \ 353 __PB_TYPENAME(BITS) v, \ 354 size_t c) \ 355 { \ 356 \ 357 while (c--) \ 358 __CONCAT(bus_space_write_,BYTES)(t, h, o, v); \ 359 } 360 361 __PMAX_bus_space_set_multi(1,8) 362 __PMAX_bus_space_set_multi(2,16) 363 __PMAX_bus_space_set_multi(4,32) 364 365 #if 0 /* Cause a link error for bus_space_set_multi_8 */ 366 #define bus_space_set_multi_8 \ 367 !!! bus_space_set_multi_8 unimplemented !!! 368 #endif 369 370 #undef __PMAX_bus_space_set_multi 371 372 /* 373 * void bus_space_set_region_N(bus_space_tag_t tag, 374 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val, 375 * size_t count); 376 * 377 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described 378 * by tag/handle starting at `offset'. 379 */ 380 381 #define __PMAX_bus_space_set_region(BYTES,BITS) \ 382 static __inline void __CONCAT(bus_space_set_region_,BYTES) \ 383 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \ 384 __PB_TYPENAME(BITS), size_t); \ 385 \ 386 static __inline void \ 387 __CONCAT(bus_space_set_region_,BYTES)( \ 388 bus_space_tag_t t, \ 389 bus_space_handle_t h, \ 390 bus_size_t o, \ 391 __PB_TYPENAME(BITS) v, \ 392 size_t c) \ 393 { \ 394 \ 395 while (c--) { \ 396 __CONCAT(bus_space_write_,BYTES)(t, h, o, v); \ 397 o += BYTES; \ 398 } \ 399 } 400 401 __PMAX_bus_space_set_region(1,8) 402 __PMAX_bus_space_set_region(2,16) 403 __PMAX_bus_space_set_region(4,32) 404 405 #if 0 /* Cause a link error for bus_space_set_region_8 */ 406 #define bus_space_set_region_8 \ 407 !!! bus_space_set_region_8 unimplemented !!! 408 #endif 409 410 #undef __PMAX_bus_space_set_region 411 412 /* 413 * void bus_space_copy_region_N(bus_space_tag_t tag, 414 * bus_space_handle_t bsh1, bus_size_t off1, 415 * bus_space_handle_t bsh2, bus_size_t off2, 416 * bus_size_t count); 417 * 418 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting 419 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2. 420 */ 421 422 #define __PMAX_copy_region(BYTES) \ 423 static __inline void __CONCAT(bus_space_copy_region_,BYTES) \ 424 (bus_space_tag_t, \ 425 bus_space_handle_t bsh1, bus_size_t off1, \ 426 bus_space_handle_t bsh2, bus_size_t off2, \ 427 bus_size_t count); \ 428 \ 429 static __inline void \ 430 __CONCAT(bus_space_copy_region_,BYTES)( \ 431 bus_space_tag_t t, \ 432 bus_space_handle_t h1, bus_size_t o1, \ 433 bus_space_handle_t h2, bus_size_t o2, \ 434 bus_size_t c) \ 435 { \ 436 bus_size_t o; \ 437 \ 438 if ((h1 + o1) >= (h2 + o2)) { \ 439 /* src after dest: copy forward */ \ 440 for (o = 0; c != 0; c--, o += BYTES) \ 441 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \ 442 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \ 443 } else { \ 444 /* dest after src: copy backwards */ \ 445 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \ 446 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \ 447 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \ 448 } \ 449 } 450 451 __PMAX_copy_region(1) 452 __PMAX_copy_region(2) 453 __PMAX_copy_region(4) 454 455 #if 0 /* Cause a link error for bus_space_copy_region_8 */ 456 #define bus_space_copy_region_8 \ 457 !!! bus_space_copy_region_8 unimplemented !!! 458 #endif 459 460 #undef __PMAX_copy_region 461 462 /* 463 * Bus read/write barrier methods. 464 * 465 * void bus_space_barrier(bus_space_tag_t tag, 466 * bus_space_handle_t bsh, bus_size_t offset, 467 * bus_size_t len, int flags); 468 * 469 * On the MIPS, we just flush the write buffer. 470 */ 471 #define bus_space_barrier(t, h, o, l, f) \ 472 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f), \ 473 wbflush())) 474 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ 475 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ 476 477 #undef __PB_TYPENAME_PREFIX 478 #undef __PB_TYPENAME 479 480 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t) 481 482 /* 483 * Flags used in various bus DMA methods. 484 */ 485 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */ 486 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */ 487 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */ 488 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */ 489 #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */ 490 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */ 491 #define BUS_DMA_BUS2 0x020 492 #define BUS_DMA_BUS3 0x040 493 #define BUS_DMA_BUS4 0x080 494 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */ 495 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */ 496 #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */ 497 498 #define PMAX_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */ 499 500 /* Forwards needed by prototypes below. */ 501 struct mbuf; 502 struct uio; 503 504 /* 505 * Operations performed by bus_dmamap_sync(). 506 */ 507 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */ 508 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */ 509 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */ 510 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */ 511 512 typedef struct pmax_bus_dma_tag *bus_dma_tag_t; 513 typedef struct pmax_bus_dmamap *bus_dmamap_t; 514 515 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0) 516 517 /* 518 * bus_dma_segment_t 519 * 520 * Describes a single contiguous DMA transaction. Values 521 * are suitable for programming into DMA registers. 522 */ 523 struct pmax_bus_dma_segment { 524 bus_addr_t ds_addr; /* DMA address */ 525 bus_size_t ds_len; /* length of transfer */ 526 bus_addr_t _ds_vaddr; /* virtual address, 0 if invalid */ 527 }; 528 typedef struct pmax_bus_dma_segment bus_dma_segment_t; 529 530 /* 531 * bus_dma_tag_t 532 * 533 * A machine-dependent opaque type describing the implementation of 534 * DMA for a given bus. 535 */ 536 537 struct pmax_bus_dma_tag { 538 /* 539 * DMA mapping methods. 540 */ 541 int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int, 542 bus_size_t, bus_size_t, int, bus_dmamap_t *); 543 void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t); 544 int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *, 545 bus_size_t, struct proc *, int); 546 int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t, 547 struct mbuf *, int); 548 int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t, 549 struct uio *, int); 550 int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t, 551 bus_dma_segment_t *, int, bus_size_t, int); 552 void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t); 553 void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t, 554 bus_addr_t, bus_size_t, int); 555 556 /* 557 * DMA memory utility functions. 558 */ 559 int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t, 560 bus_size_t, bus_dma_segment_t *, int, int *, int); 561 void (*_dmamem_free)(bus_dma_tag_t, 562 bus_dma_segment_t *, int); 563 int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *, 564 int, size_t, void **, int); 565 void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t); 566 paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *, 567 int, off_t, int, int); 568 }; 569 570 #define bus_dmamap_create(t, s, n, m, b, f, p) \ 571 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p)) 572 #define bus_dmamap_destroy(t, p) \ 573 (*(t)->_dmamap_destroy)((t), (p)) 574 #define bus_dmamap_load(t, m, b, s, p, f) \ 575 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f)) 576 #define bus_dmamap_load_mbuf(t, m, b, f) \ 577 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f)) 578 #define bus_dmamap_load_uio(t, m, u, f) \ 579 (*(t)->_dmamap_load_uio)((t), (m), (u), (f)) 580 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \ 581 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f)) 582 #define bus_dmamap_unload(t, p) \ 583 (*(t)->_dmamap_unload)((t), (p)) 584 #define bus_dmamap_sync(t, p, o, l, ops) \ 585 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) 586 587 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \ 588 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f)) 589 #define bus_dmamem_free(t, sg, n) \ 590 (*(t)->_dmamem_free)((t), (sg), (n)) 591 #define bus_dmamem_map(t, sg, n, s, k, f) \ 592 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f)) 593 #define bus_dmamem_unmap(t, k, s) \ 594 (*(t)->_dmamem_unmap)((t), (k), (s)) 595 #define bus_dmamem_mmap(t, sg, n, o, p, f) \ 596 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f)) 597 598 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP 599 #define bus_dmatag_destroy(t) 600 601 /* 602 * bus_dmamap_t 603 * 604 * Describes a DMA mapping. 605 */ 606 struct pmax_bus_dmamap { 607 /* 608 * PRIVATE MEMBERS: not for use my machine-independent code. 609 */ 610 bus_size_t _dm_size; /* largest DMA transfer mappable */ 611 int _dm_segcnt; /* number of segs this map can map */ 612 bus_size_t _dm_maxmaxsegsz; /* fixed largest possible segment */ 613 bus_size_t _dm_boundary; /* don't cross this */ 614 int _dm_flags; /* misc. flags */ 615 struct vmspace *_dm_vmspace; /* vmspace that owns the mapping */ 616 617 /* 618 * PUBLIC MEMBERS: these are used by machine-independent code. 619 */ 620 bus_size_t dm_maxsegsz; /* largest possible segment */ 621 bus_size_t dm_mapsize; /* size of the mapping */ 622 int dm_nsegs; /* # valid segments in mapping */ 623 bus_dma_segment_t dm_segs[1]; /* segments; variable length */ 624 }; 625 626 #ifdef _PMAX_BUS_DMA_PRIVATE 627 void pmax_bus_dma_init(void); 628 629 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, 630 bus_size_t, int, bus_dmamap_t *); 631 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); 632 int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, 633 bus_size_t, struct proc *, int); 634 int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, 635 struct mbuf *, int); 636 int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, 637 struct uio *, int); 638 int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, 639 bus_dma_segment_t *, int, bus_size_t, int); 640 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); 641 void _bus_dmamap_sync_r3k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, 642 bus_size_t, int); 643 void _bus_dmamap_sync_r4k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, 644 bus_size_t, int); 645 646 int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size, 647 bus_size_t alignment, bus_size_t boundary, 648 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags); 649 void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, 650 int nsegs); 651 int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, 652 int nsegs, size_t size, void **kvap, int flags); 653 void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva, 654 size_t size); 655 paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs, 656 int nsegs, off_t off, int prot, int flags); 657 658 int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size, 659 bus_size_t alignment, bus_size_t boundary, 660 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags, 661 vaddr_t low, vaddr_t high); 662 663 extern struct pmax_bus_dma_tag pmax_default_bus_dma_tag; 664 #endif /* _PMAX_BUS_DMA_PRIVATE */ 665 666 #endif /* !_PMAX_BUS_H_ */ 667