1 /*- 2 * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to The NetBSD Foundation 6 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 7 * NASA Ames Research Center. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the NetBSD 20 * Foundation, Inc. and its contributors. 21 * 4. Neither the name of The NetBSD Foundation nor the names of its 22 * contributors may be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 /*- 39 * Copyright (c) 1996 Charles M. Hannum. All rights reserved. 40 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved. 41 * 42 * Redistribution and use in source and binary forms, with or without 43 * modification, are permitted provided that the following conditions 44 * are met: 45 * 1. Redistributions of source code must retain the above copyright 46 * notice, this list of conditions and the following disclaimer. 47 * 2. Redistributions in binary form must reproduce the above copyright 48 * notice, this list of conditions and the following disclaimer in the 49 * documentation and/or other materials provided with the distribution. 50 * 3. All advertising materials mentioning features or use of this software 51 * must display the following acknowledgement: 52 * This product includes software developed by Christopher G. Demetriou 53 * for the NetBSD Project. 54 * 4. The name of the author may not be used to endorse or promote products 55 * derived from this software without specific prior written permission 56 * 57 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 58 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 59 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 60 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 61 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 62 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 63 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 64 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 65 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 66 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 67 * 68 * $NetBSD: bus.h,v 1.9.4.1 2000/06/30 16:27:30 simonb Exp $ 69 * $FreeBSD$ 70 */ 71 72 #ifndef _MACPPC_BUS_H_ 73 #define _MACPPC_BUS_H_ 74 75 #include <machine/_bus.h> 76 #include <machine/pio.h> 77 78 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF 79 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF 80 #define BUS_SPACE_MAXSIZE 0xFFFFFFFF 81 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF 82 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF 83 #define BUS_SPACE_MAXADDR 0xFFFFFFFF 84 85 #define BUS_SPACE_UNRESTRICTED (~0) 86 87 /* 88 * Values for the macppc bus space tag, not to be used directly by MI code. 89 */ 90 91 #define __BUS_SPACE_HAS_STREAM_METHODS 1 92 93 /* 94 * Define the PPC tag values 95 */ 96 #define PPC_BUS_SPACE_MEM 1 /* space is mem space */ 97 #define PPC_BUS_SPACE_IO 2 /* space is io space */ 98 99 static __inline void * 100 __ppc_ba(bus_space_tag_t tag __unused, bus_space_handle_t handle, 101 bus_size_t offset) 102 { 103 return ((void *)(handle + offset)); 104 } 105 106 /* 107 * int bus_space_map(bus_space_tag_t t, bus_addr_t addr, 108 * bus_size_t size, int flags, bus_space_handle_t *bshp)); 109 * 110 * Map a region of bus space. 111 */ 112 #if 0 113 bus_space_map(t, addr, size, flags, bshp) ! not implemented ! 114 #endif 115 116 /* 117 * int bus_space_unmap(bus_space_tag_t t, 118 * bus_space_handle_t bsh, bus_size_t size)); 119 * 120 * Unmap a region of bus space. 121 */ 122 123 static __inline void 124 bus_space_unmap(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused, 125 bus_size_t size __unused) 126 { 127 } 128 129 /* 130 * int bus_space_subregion(bus_space_tag_t t, 131 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, 132 * bus_space_handle_t *nbshp)); 133 * 134 * Get a new handle for a subregion of an already-mapped area of bus space. 135 */ 136 137 static __inline int 138 bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t bsh, 139 bus_size_t offset, bus_size_t size __unused, bus_space_handle_t *nbshp) 140 { 141 *nbshp = bsh + offset; 142 return (0); 143 } 144 145 /* 146 * int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart, 147 * bus_addr_t rend, bus_size_t size, bus_size_t align, 148 * bus_size_t boundary, int flags, bus_addr_t *addrp, 149 * bus_space_handle_t *bshp)); 150 * 151 * Allocate a region of bus space. 152 */ 153 154 #if 0 155 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) !!! unimplemented !!! 156 #endif 157 158 /* 159 * int bus_space_free(bus_space_tag_t t, 160 * bus_space_handle_t bsh, bus_size_t size)); 161 * 162 * Free a region of bus space. 163 */ 164 #if 0 165 #define bus_space_free(t, h, s) !!! unimplemented !!! 166 #endif 167 168 /* 169 * u_intN_t bus_space_read_N(bus_space_tag_t tag, 170 * bus_space_handle_t bsh, bus_size_t offset)); 171 * 172 * Read a 1, 2, 4, or 8 byte quantity from bus space 173 * described by tag/handle/offset. 174 */ 175 176 static __inline u_int8_t 177 bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) 178 { 179 return (in8(__ppc_ba(t, h, o))); 180 } 181 182 static __inline u_int16_t 183 bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) 184 { 185 return (in16rb(__ppc_ba(t, h, o))); 186 } 187 188 static __inline u_int32_t 189 bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) 190 { 191 return (in32rb(__ppc_ba(t, h, o))); 192 } 193 194 #if 0 /* Cause a link error for bus_space_read_8 */ 195 #define bus_space_read_8(t, h, o) !!! unimplemented !!! 196 #endif 197 198 static __inline u_int8_t 199 bus_space_read_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) 200 { 201 return (in8(__ppc_ba(t, h, o))); 202 } 203 204 static __inline u_int16_t 205 bus_space_read_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) 206 { 207 return (in16(__ppc_ba(t, h, o))); 208 } 209 210 static __inline u_int32_t 211 bus_space_read_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) 212 { 213 return (in32(__ppc_ba(t, h, o))); 214 } 215 216 #if 0 /* Cause a link error for bus_space_read_stream_8 */ 217 #define bus_space_read_stream_8(t, h, o) !!! unimplemented !!! 218 #endif 219 220 /* 221 * void bus_space_read_multi_N(bus_space_tag_t tag, 222 * bus_space_handle_t bsh, bus_size_t offset, 223 * u_intN_t *addr, size_t count)); 224 * 225 * Read `count' 1, 2, 4, or 8 byte quantities from bus space 226 * described by tag/handle/offset and copy into buffer provided. 227 */ 228 229 static __inline void 230 bus_space_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 231 u_int8_t *a, size_t c) 232 { 233 ins8(__ppc_ba(t, h, o), a, c); 234 } 235 236 static __inline void 237 bus_space_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 238 u_int16_t *a, size_t c) 239 { 240 ins16rb(__ppc_ba(t, h, o), a, c); 241 } 242 243 static __inline void 244 bus_space_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 245 u_int32_t *a, size_t c) 246 { 247 ins32rb(__ppc_ba(t, h, o), a, c); 248 } 249 250 #if 0 /* Cause a link error for bus_space_read_multi_8 */ 251 #define bus_space_read_multi_8 !!! unimplemented !!! 252 #endif 253 254 static __inline void 255 bus_space_read_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h, 256 bus_size_t o, u_int8_t *a, size_t c) 257 { 258 ins8(__ppc_ba(t, h, o), a, c); 259 } 260 261 static __inline void 262 bus_space_read_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h, 263 bus_size_t o, u_int16_t *a, size_t c) 264 { 265 ins16(__ppc_ba(t, h, o), a, c); 266 } 267 268 static __inline void 269 bus_space_read_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h, 270 bus_size_t o, u_int32_t *a, size_t c) 271 { 272 ins32(__ppc_ba(t, h, o), a, c); 273 } 274 275 #if 0 /* Cause a link error for bus_space_read_multi_stream_8 */ 276 #define bus_space_read_multi_stream_8 !!! unimplemented !!! 277 #endif 278 279 /* 280 * void bus_space_read_region_N(bus_space_tag_t tag, 281 * bus_space_handle_t bsh, bus_size_t offset, 282 * u_intN_t *addr, size_t count)); 283 * 284 * Read `count' 1, 2, 4, or 8 byte quantities from bus space 285 * described by tag/handle and starting at `offset' and copy into 286 * buffer provided. 287 */ 288 289 static __inline void 290 bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, 291 bus_size_t offset, u_int8_t *addr, size_t count) 292 { 293 volatile u_int8_t *s = __ppc_ba(tag, bsh, offset); 294 295 while (count--) 296 *addr++ = *s++; 297 __asm __volatile("eieio; sync"); 298 } 299 300 static __inline void 301 bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, 302 bus_size_t offset, u_int16_t *addr, size_t count) 303 { 304 volatile u_int16_t *s = __ppc_ba(tag, bsh, offset); 305 306 while (count--) 307 __asm __volatile("lhbrx %0, 0, %1" : 308 "=r"(*addr++) : "r"(s++)); 309 __asm __volatile("eieio; sync"); 310 } 311 312 static __inline void 313 bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, 314 bus_size_t offset, u_int32_t *addr, size_t count) 315 { 316 volatile u_int32_t *s = __ppc_ba(tag, bsh, offset); 317 318 while (count--) 319 __asm __volatile("lwbrx %0, 0, %1" : 320 "=r"(*addr++) : "r"(s++)); 321 __asm __volatile("eieio; sync"); 322 } 323 324 #if 0 /* Cause a link error for bus_space_read_region_8 */ 325 #define bus_space_read_region_8 !!! unimplemented !!! 326 #endif 327 328 static __inline void 329 bus_space_read_region_stream_2(bus_space_tag_t tag, bus_space_handle_t bsh, 330 bus_size_t offset, u_int16_t *addr, size_t count) 331 { 332 volatile u_int16_t *s = __ppc_ba(tag, bsh, offset); 333 334 while (count--) 335 *addr++ = *s++; 336 __asm __volatile("eieio; sync"); 337 } 338 339 static __inline void 340 bus_space_read_region_stream_4(bus_space_tag_t tag, bus_space_handle_t bsh, 341 bus_size_t offset, u_int32_t *addr, size_t count) 342 { 343 volatile u_int32_t *s = __ppc_ba(tag, bsh, offset); 344 345 while (count--) 346 *addr++ = *s++; 347 __asm __volatile("eieio; sync"); 348 } 349 350 #if 0 /* Cause a link error */ 351 #define bus_space_read_region_stream_8 !!! unimplemented !!! 352 #endif 353 354 /* 355 * void bus_space_write_N(bus_space_tag_t tag, 356 * bus_space_handle_t bsh, bus_size_t offset, 357 * u_intN_t value)); 358 * 359 * Write the 1, 2, 4, or 8 byte value `value' to bus space 360 * described by tag/handle/offset. 361 */ 362 363 static __inline void 364 bus_space_write_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 365 uint8_t v) 366 { 367 out8(__ppc_ba(t, h, o), v); 368 } 369 370 static __inline void 371 bus_space_write_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 372 uint16_t v) 373 { 374 out16rb(__ppc_ba(t, h, o), v); 375 } 376 377 static __inline void 378 bus_space_write_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 379 uint32_t v) 380 { 381 out32rb(__ppc_ba(t, h, o), v); 382 } 383 384 #if 0 /* Cause a link error for bus_space_write_8 */ 385 #define bus_space_write_8 !!! unimplemented !!! 386 #endif 387 388 static __inline void 389 bus_space_write_stream_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 390 uint8_t v) 391 { 392 out8(__ppc_ba(t, h, o), v); 393 } 394 395 static __inline void 396 bus_space_write_stream_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 397 uint16_t v) 398 { 399 out16(__ppc_ba(t, h, o), v); 400 } 401 402 static __inline void 403 bus_space_write_stream_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 404 uint32_t v) 405 { 406 out32(__ppc_ba(t, h, o), v); 407 } 408 409 #if 0 /* Cause a link error for bus_space_write_stream_8 */ 410 #define bus_space_write_stream_8 !!! unimplemented !!! 411 #endif 412 413 414 /* 415 * void bus_space_write_multi_N(bus_space_tag_t tag, 416 * bus_space_handle_t bsh, bus_size_t offset, 417 * const u_intN_t *addr, size_t count)); 418 * 419 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer 420 * provided to bus space described by tag/handle/offset. 421 */ 422 423 static __inline void 424 bus_space_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 425 uint8_t *a, size_t c) 426 { 427 outsb(__ppc_ba(t, h, o), a, c); 428 } 429 430 static __inline void 431 bus_space_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 432 uint16_t *a, size_t c) 433 { 434 outsw(__ppc_ba(t, h, o), a, c); 435 } 436 437 static __inline void 438 bus_space_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, 439 uint32_t *a, size_t c) 440 { 441 outsl(__ppc_ba(t, h, o), a, c); 442 } 443 444 #if 0 445 #define bus_space_write_multi_8 !!! unimplemented !!! 446 #endif 447 448 static __inline void 449 bus_space_write_multi_stream_1(bus_space_tag_t t, bus_space_handle_t h, 450 bus_size_t o, const u_int8_t *a, size_t c) 451 { 452 outsb(__ppc_ba(t, h, o), a, c); 453 } 454 455 static __inline void 456 bus_space_write_multi_stream_2(bus_space_tag_t t, bus_space_handle_t h, 457 bus_size_t o, const u_int16_t *a, size_t c) 458 { 459 outsw(__ppc_ba(t, h, o), a, c); 460 } 461 462 static __inline void 463 bus_space_write_multi_stream_4(bus_space_tag_t t, bus_space_handle_t h, 464 bus_size_t o, const u_int32_t *a, size_t c) 465 { 466 outsl(__ppc_ba(t, h, o), a, c); 467 } 468 469 #if 0 470 #define bus_space_write_multi_stream_8 !!! unimplemented !!! 471 #endif 472 473 /* 474 * void bus_space_write_region_N(bus_space_tag_t tag, 475 * bus_space_handle_t bsh, bus_size_t offset, 476 * const u_intN_t *addr, size_t count)); 477 * 478 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided 479 * to bus space described by tag/handle starting at `offset'. 480 */ 481 482 static __inline void 483 bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, 484 bus_size_t offset, const u_int8_t *addr, size_t count) 485 { 486 volatile u_int8_t *d = __ppc_ba(tag, bsh, offset); 487 488 while (count--) 489 *d++ = *addr++; 490 __asm __volatile("eieio; sync"); 491 } 492 493 static __inline void 494 bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, 495 bus_size_t offset, const u_int16_t *addr, size_t count) 496 { 497 volatile u_int16_t *d = __ppc_ba(tag, bsh, offset); 498 499 while (count--) 500 __asm __volatile("sthbrx %0, 0, %1" :: 501 "r"(*addr++), "r"(d++)); 502 __asm __volatile("eieio; sync"); 503 } 504 505 static __inline void 506 bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, 507 bus_size_t offset, const u_int32_t *addr, size_t count) 508 { 509 volatile u_int32_t *d = __ppc_ba(tag, bsh, offset); 510 511 while (count--) 512 __asm __volatile("stwbrx %0, 0, %1" :: 513 "r"(*addr++), "r"(d++)); 514 __asm __volatile("eieio; sync"); 515 } 516 517 #if 0 518 #define bus_space_write_region_8 !!! bus_space_write_region_8 unimplemented !!! 519 #endif 520 521 static __inline void 522 bus_space_write_region_stream_2(bus_space_tag_t tag, bus_space_handle_t bsh, 523 bus_size_t offset, const u_int16_t *addr, size_t count) 524 { 525 volatile u_int16_t *d = __ppc_ba(tag, bsh, offset); 526 527 while (count--) 528 *d++ = *addr++; 529 __asm __volatile("eieio; sync"); 530 } 531 532 static __inline void 533 bus_space_write_region_stream_4(bus_space_tag_t tag, bus_space_handle_t bsh, 534 bus_size_t offset, const u_int32_t *addr, size_t count) 535 { 536 volatile u_int32_t *d = __ppc_ba(tag, bsh, offset); 537 538 while (count--) 539 *d++ = *addr++; 540 __asm __volatile("eieio; sync"); 541 } 542 543 #if 0 544 #define bus_space_write_region_stream_8 !!! unimplemented !!! 545 #endif 546 547 /* 548 * void bus_space_set_multi_N(bus_space_tag_t tag, 549 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val, 550 * size_t count)); 551 * 552 * Write the 1, 2, 4, or 8 byte value `val' to bus space described 553 * by tag/handle/offset `count' times. 554 */ 555 556 static __inline void 557 bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh, 558 bus_size_t offset, u_int8_t val, size_t count) 559 { 560 volatile u_int8_t *d = __ppc_ba(tag, bsh, offset); 561 562 while (count--) 563 *d = val; 564 __asm __volatile("eieio; sync"); 565 } 566 567 static __inline void 568 bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh, 569 bus_size_t offset, u_int16_t val, size_t count) 570 { 571 volatile u_int16_t *d = __ppc_ba(tag, bsh, offset); 572 573 while (count--) 574 __asm __volatile("sthbrx %0, 0, %1" :: 575 "r"(val), "r"(d)); 576 __asm __volatile("eieio; sync"); 577 } 578 579 static __inline void 580 bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh, 581 bus_size_t offset, u_int32_t val, size_t count) 582 { 583 volatile u_int32_t *d = __ppc_ba(tag, bsh, offset); 584 585 while (count--) 586 __asm __volatile("stwbrx %0, 0, %1" :: 587 "r"(val), "r"(d)); 588 __asm __volatile("eieio; sync"); 589 } 590 591 #if 0 592 #define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!! 593 #endif 594 595 static __inline void 596 bus_space_set_multi_stream_2(bus_space_tag_t tag, bus_space_handle_t bsh, 597 bus_size_t offset, u_int16_t val, size_t count) 598 { 599 volatile u_int16_t *d = __ppc_ba(tag, bsh, offset); 600 601 while (count--) 602 *d = val; 603 __asm __volatile("eieio; sync"); 604 } 605 606 static __inline void 607 bus_space_set_multi_stream_4(bus_space_tag_t tag, bus_space_handle_t bsh, 608 bus_size_t offset, u_int32_t val, size_t count) 609 { 610 volatile u_int32_t *d = __ppc_ba(tag, bsh, offset); 611 612 while (count--) 613 *d = val; 614 __asm __volatile("eieio; sync"); 615 } 616 617 #if 0 618 #define bus_space_set_multi_stream_8 !!! unimplemented !!! 619 #endif 620 621 /* 622 * void bus_space_set_region_N(bus_space_tag_t tag, 623 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val, 624 * size_t count)); 625 * 626 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described 627 * by tag/handle starting at `offset'. 628 */ 629 630 static __inline void 631 bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh, 632 bus_size_t offset, u_int8_t val, size_t count) 633 { 634 volatile u_int8_t *d = __ppc_ba(tag, bsh, offset); 635 636 while (count--) 637 *d++ = val; 638 __asm __volatile("eieio; sync"); 639 } 640 641 static __inline void 642 bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh, 643 bus_size_t offset, u_int16_t val, size_t count) 644 { 645 volatile u_int16_t *d = __ppc_ba(tag, bsh, offset); 646 647 while (count--) 648 __asm __volatile("sthbrx %0, 0, %1" :: 649 "r"(val), "r"(d++)); 650 __asm __volatile("eieio; sync"); 651 } 652 653 static __inline void 654 bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh, 655 bus_size_t offset, u_int32_t val, size_t count) 656 { 657 volatile u_int32_t *d = __ppc_ba(tag, bsh, offset); 658 659 while (count--) 660 __asm __volatile("stwbrx %0, 0, %1" :: 661 "r"(val), "r"(d++)); 662 __asm __volatile("eieio; sync"); 663 } 664 665 #if 0 666 #define bus_space_set_region_8 !!! bus_space_set_region_8 unimplemented !!! 667 #endif 668 669 static __inline void 670 bus_space_set_region_stream_2(bus_space_tag_t tag, bus_space_handle_t bsh, 671 bus_size_t offset, u_int16_t val, size_t count) 672 { 673 volatile u_int16_t *d = __ppc_ba(tag, bsh, offset); 674 675 while (count--) 676 *d++ = val; 677 __asm __volatile("eieio; sync"); 678 } 679 680 static __inline void 681 bus_space_set_region_stream_4(bus_space_tag_t tag, bus_space_handle_t bsh, 682 bus_size_t offset, u_int32_t val, size_t count) 683 { 684 volatile u_int32_t *d = __ppc_ba(tag, bsh, offset); 685 686 while (count--) 687 *d++ = val; 688 __asm __volatile("eieio; sync"); 689 } 690 691 #if 0 692 #define bus_space_set_region_stream_8 !!! unimplemented !!! 693 #endif 694 695 /* 696 * void bus_space_copy_region_N(bus_space_tag_t tag, 697 * bus_space_handle_t bsh1, bus_size_t off1, 698 * bus_space_handle_t bsh2, bus_size_t off2, 699 * size_t count)); 700 * 701 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting 702 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2. 703 */ 704 705 /* XXX IMPLEMENT bus_space_copy_N() XXX */ 706 707 /* 708 * Bus read/write barrier methods. 709 * 710 * void bus_space_barrier(bus_space_tag_t tag, 711 * bus_space_handle_t bsh, bus_size_t offset, 712 * bus_size_t len, int flags)); 713 * 714 * Note: the macppc does not currently require barriers, but we must 715 * provide the flags to MI code. 716 */ 717 718 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ 719 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ 720 721 static __inline void 722 bus_space_barrier(bus_space_tag_t tag __unused, 723 bus_space_handle_t bsh __unused, bus_size_t offset __unused, 724 bus_size_t len __unused, int flags __unused) 725 { 726 __asm __volatile("" : : : "memory"); 727 } 728 729 730 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t) 731 732 #include <machine/bus_dma.h> 733 734 #endif /* _MACPPC_BUS_H_ */ 735