1 /* $NetBSD: empb_bsm.c,v 1.5 2012/06/27 18:53:03 rkujawa Exp $ */ 2 3 /*- 4 * Copyright (c) 2012 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Radoslaw Kujawa. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * Special bus space methods handling PCI memory window. Used only by empb. 34 * 35 * XXX: Handle ops on window boundary! Currently these are broken! 36 */ 37 38 #include <sys/bus.h> 39 #include <sys/null.h> 40 #include <sys/param.h> 41 #include <sys/device.h> 42 #include <sys/systm.h> 43 #include <sys/types.h> 44 45 #include <amiga/pci/empbreg.h> 46 #include <amiga/pci/empbvar.h> 47 #include <amiga/pci/emmemvar.h> 48 49 static bool empb_bsm_init(void); 50 51 /* 52 * The bus_space functions are prototyped below. Due to macro-ridden 53 * maddness of amiga port bus_space implementation, these prototypes look 54 * somewhat different than what you can read in bus_space(9) man page. 55 */ 56 57 static int empb_bsm(bus_space_tag_t space, bus_addr_t address, 58 bus_size_t size, int flags, bus_space_handle_t *handlep); 59 static int empb_bsms(bus_space_handle_t handle, bus_size_t offset, 60 bus_size_t size, bus_space_handle_t *nhandlep); 61 static void empb_bsu(bus_space_handle_t handle, 62 bus_size_t size); 63 64 static bsr(empb_bsr1, u_int8_t); 65 static bsw(empb_bsw1, u_int8_t); 66 static bsrm(empb_bsrm1, u_int8_t); 67 static bswm(empb_bswm1, u_int8_t); 68 static bsrm(empb_bsrr1, u_int8_t); 69 static bswm(empb_bswr1, u_int8_t); 70 static bssr(empb_bssr1, u_int8_t); 71 static bscr(empb_bscr1, u_int8_t); 72 73 static bsr(empb_bsr2_swap, u_int16_t); 74 static bsw(empb_bsw2_swap, u_int16_t); 75 static bsr(empb_bsr2, u_int16_t); 76 static bsw(empb_bsw2, u_int16_t); 77 static bsrm(empb_bsrm2_swap, u_int16_t); 78 static bswm(empb_bswm2_swap, u_int16_t); 79 static bsrm(empb_bsrm2, u_int16_t); 80 static bswm(empb_bswm2, u_int16_t); 81 static bsrm(empb_bsrr2_swap, u_int16_t); 82 static bswm(empb_bswr2_swap, u_int16_t); 83 static bsrm(empb_bsrr2, u_int16_t); 84 static bswm(empb_bswr2, u_int16_t); 85 static bssr(empb_bssr2_swap, u_int16_t); 86 static bscr(empb_bscr2, u_int16_t); 87 88 static bsr(empb_bsr4_swap, u_int32_t); 89 static bsw(empb_bsw4_swap, u_int32_t); 90 static bsr(empb_bsr4, u_int32_t); 91 static bsw(empb_bsw4, u_int32_t); 92 static bsrm(empb_bsrm4_swap, u_int32_t); 93 static bswm(empb_bswm4_swap, u_int32_t); 94 static bsrm(empb_bsrm4, u_int32_t); 95 static bswm(empb_bswm4, u_int32_t); 96 static bsrm(empb_bsrr4_swap, u_int32_t); 97 static bswm(empb_bswr4_swap, u_int32_t); 98 static bsrm(empb_bsrr4, u_int32_t); 99 static bswm(empb_bswr4, u_int32_t); 100 static bssr(empb_bssr4_swap, u_int32_t); 101 static bscr(empb_bscr4, u_int32_t); 102 /* 103 * Hold pointer to bridge driver here. We need to access it to switch 104 * window position. Perhaps it should be stored in bus_space_tag instead... 105 */ 106 static struct empb_softc *empb_sc = NULL; 107 108 static bool 109 empb_bsm_init(void) 110 { 111 device_t dev; 112 113 /* We can't have more than one Mediator anyway. */ 114 if (!(dev = device_find_by_xname("empb0"))) { 115 aprint_error("empb: can't find bridge device\n"); 116 return false; 117 } 118 119 if (!(empb_sc = device_private(dev))) { 120 aprint_error_dev(dev, "can't obtain bridge softc\n"); 121 return false; 122 } 123 124 if (empb_sc->pci_mem_win_size == 0) { 125 aprint_error_dev(dev, "no PCI memory window found\n"); 126 return false; 127 } 128 129 return true; 130 } 131 132 /* === common bus space methods === */ 133 134 static int 135 empb_bsm(bus_space_tag_t space, bus_addr_t address, bus_size_t size, 136 int flags, bus_space_handle_t *handlep) 137 { 138 139 /* Check for bridge driver softc. */ 140 if (empb_sc==NULL) 141 if(empb_bsm_init() == false) 142 return -1; 143 144 /* Fail miserably if the driver wants linear space. */ 145 if ( (flags & BUS_SPACE_MAP_LINEAR) && (size > 8*1024*1024)) 146 aprint_error("empb: linear space mapping might not work\n"); 147 148 /* 149 * Just store the desired PCI bus address as handlep. Don't make things 150 * more complicated than they need to be. 151 */ 152 *handlep = address; 153 154 return 0; 155 } 156 157 static int 158 empb_bsms(bus_space_handle_t handle, 159 bus_size_t offset, bus_size_t size, bus_space_handle_t *nhandlep) 160 { 161 *nhandlep = handle + offset; 162 return 0; 163 } 164 165 static void 166 empb_bsu(bus_space_handle_t handle, bus_size_t size) 167 { 168 return; 169 } 170 171 /* === 8-bit methods === */ 172 173 static uint8_t 174 empb_bsr1(bus_space_handle_t handle, bus_size_t offset) 175 { 176 uint8_t *p; 177 uint8_t x; 178 bus_addr_t wp; /* window position */ 179 180 wp = empb_switch_window(empb_sc, handle); 181 182 /* window address + (PCI mem address - window position) */ 183 p = (uint8_t*)((empb_sc->pci_mem_win_t->base) + (handle - wp) + offset); 184 x = *p; 185 186 return x; 187 } 188 189 static void 190 empb_bsw1(bus_space_handle_t handle, bus_size_t offset, unsigned value) 191 { 192 uint8_t *p; 193 bus_addr_t wp; 194 195 wp = empb_switch_window(empb_sc, handle); 196 p = (uint8_t*)((empb_sc->pci_mem_win_t->base) + (handle - wp) + offset); 197 *p = value; 198 } 199 200 static void 201 empb_bsrm1(bus_space_handle_t handle, bus_size_t offset, u_int8_t *pointer, 202 bus_size_t count) 203 { 204 volatile uint8_t *p; 205 bus_addr_t wp; 206 207 wp = empb_switch_window(empb_sc, handle); 208 p = (volatile u_int8_t *) ((empb_sc->pci_mem_win_t->base) + 209 (handle - wp) + offset); 210 211 while (count > 0) { 212 *pointer++ = *p; 213 amiga_bus_reorder_protect(); 214 --count; 215 } 216 } 217 218 static void 219 empb_bswm1(bus_space_handle_t handle, bus_size_t offset, 220 const u_int8_t *pointer, bus_size_t count) 221 { 222 volatile uint8_t *p; 223 bus_addr_t wp; 224 225 wp = empb_switch_window(empb_sc, handle); 226 p = (volatile u_int8_t *) ((empb_sc->pci_mem_win_t->base) + 227 (handle - wp) + offset); 228 229 while (count > 0) { 230 *p = *pointer++; 231 amiga_bus_reorder_protect(); 232 --count; 233 } 234 } 235 236 static void 237 empb_bsrr1(bus_space_handle_t handle, bus_size_t offset, u_int8_t *pointer, 238 bus_size_t count) 239 { 240 volatile uint8_t *p; 241 bus_addr_t wp; 242 243 wp = empb_switch_window(empb_sc, handle); 244 p = (volatile u_int8_t *) ((empb_sc->pci_mem_win_t->base) + 245 (handle - wp) + offset); 246 247 while (count > 0) { 248 *pointer++ = *p; 249 amiga_bus_reorder_protect(); 250 p++; 251 --count; 252 } 253 } 254 255 static void 256 empb_bswr1(bus_space_handle_t handle, bus_size_t offset, 257 const u_int8_t *pointer, bus_size_t count) 258 { 259 volatile uint8_t *p; 260 bus_addr_t wp; 261 262 wp = empb_switch_window(empb_sc, handle); 263 p = (volatile u_int8_t *) ((empb_sc->pci_mem_win_t->base) + 264 (handle - wp) + offset); 265 266 while (count > 0) { 267 *p = *pointer++; 268 amiga_bus_reorder_protect(); 269 p++; 270 --count; 271 } 272 } 273 274 static void 275 empb_bssr1(bus_space_handle_t handle, bus_size_t offset, unsigned value, 276 bus_size_t count) 277 { 278 volatile uint8_t *p; 279 bus_addr_t wp; 280 281 wp = empb_switch_window(empb_sc, handle); 282 p = (volatile u_int8_t *) ((empb_sc->pci_mem_win_t->base) + 283 (handle - wp) + offset); 284 285 while (count > 0) { 286 *p = value; 287 amiga_bus_reorder_protect(); 288 p++; 289 --count; 290 } 291 } 292 293 /* XXX: this is broken, rewrite */ 294 static void 295 empb_bscr1(bus_space_handle_t handlefrom, bus_size_t from, 296 bus_space_handle_t handleto, bus_size_t to, bus_size_t count) 297 { 298 volatile uint8_t *p, *q; 299 bus_addr_t wp; 300 301 wp = empb_switch_window(empb_sc, handlefrom); 302 303 p = (volatile u_int8_t *) 304 ( ((empb_sc->pci_mem_win_t->base)+(handlefrom - wp)) + from ); 305 q = (volatile u_int8_t *) 306 ( ((empb_sc->pci_mem_win_t->base)+(handleto - wp)) + to ); 307 308 while (count > 0) { 309 *q = *p; 310 amiga_bus_reorder_protect(); 311 p ++; q++; 312 --count; 313 } 314 } 315 316 /* === 16-bit methods === */ 317 318 static uint16_t 319 empb_bsr2(bus_space_handle_t handle, bus_size_t offset) 320 { 321 uint16_t *p; 322 uint16_t x; 323 bus_addr_t wp; 324 325 wp = empb_switch_window(empb_sc, handle); 326 327 p = (uint16_t*) ((empb_sc->pci_mem_win_t->base) + (handle - wp) 328 + offset); 329 x = *p; 330 331 return x; 332 } 333 334 static uint16_t 335 empb_bsr2_swap(bus_space_handle_t handle, bus_size_t offset) 336 { 337 uint16_t *p; 338 uint16_t x; 339 bus_addr_t wp; 340 341 wp = empb_switch_window(empb_sc, handle); 342 343 p = (uint16_t*) ((empb_sc->pci_mem_win_t->base) + (handle - wp) 344 + offset); 345 x = *p; 346 347 return bswap16(x); 348 } 349 350 351 static void 352 empb_bsw2(bus_space_handle_t handle, bus_size_t offset, unsigned value) 353 { 354 uint16_t *p; 355 bus_addr_t wp; 356 357 wp = empb_switch_window(empb_sc, handle); 358 p = (uint16_t*)((empb_sc->pci_mem_win_t->base) + (handle - wp) 359 + offset); 360 *p = value; 361 } 362 363 static void 364 empb_bsw2_swap(bus_space_handle_t handle, bus_size_t offset, unsigned value) 365 { 366 uint16_t *p; 367 bus_addr_t wp; 368 369 wp = empb_switch_window(empb_sc, handle); 370 p = (uint16_t*)((empb_sc->pci_mem_win_t->base) + (handle - wp) 371 + offset); 372 *p = bswap16(value); 373 } 374 375 static void 376 empb_bsrm2(bus_space_handle_t handle, bus_size_t offset, u_int16_t *pointer, 377 bus_size_t count) 378 { 379 volatile uint16_t *p; 380 bus_addr_t wp; 381 382 wp = empb_switch_window(empb_sc, handle); 383 p = (volatile uint16_t *) ((empb_sc->pci_mem_win_t->base) + 384 (handle - wp) + offset); 385 386 while (count > 0) { 387 *pointer++ = *p; 388 amiga_bus_reorder_protect(); 389 --count; 390 } 391 } 392 393 static void 394 empb_bsrm2_swap(bus_space_handle_t handle, bus_size_t offset, 395 u_int16_t *pointer, bus_size_t count) 396 { 397 volatile uint16_t *p; 398 bus_addr_t wp; 399 400 wp = empb_switch_window(empb_sc, handle); 401 p = (volatile uint16_t *) ((empb_sc->pci_mem_win_t->base) + 402 (handle - wp) + offset); 403 404 while (count > 0) { 405 *pointer++ = bswap16(*p); 406 amiga_bus_reorder_protect(); 407 --count; 408 } 409 } 410 411 static void 412 empb_bswm2(bus_space_handle_t handle, bus_size_t offset, 413 const u_int16_t *pointer, bus_size_t count) 414 { 415 volatile uint16_t *p; 416 bus_addr_t wp; 417 418 wp = empb_switch_window(empb_sc, handle); 419 p = (volatile uint16_t *) ((empb_sc->pci_mem_win_t->base) + 420 (handle - wp) + offset); 421 422 while (count > 0) { 423 *p = *pointer++; 424 amiga_bus_reorder_protect(); 425 --count; 426 } 427 } 428 429 static void 430 empb_bswm2_swap(bus_space_handle_t handle, bus_size_t offset, 431 const u_int16_t *pointer, bus_size_t count) 432 { 433 volatile uint16_t *p; 434 bus_addr_t wp; 435 436 wp = empb_switch_window(empb_sc, handle); 437 p = (volatile uint16_t *) ((empb_sc->pci_mem_win_t->base) + 438 (handle - wp) + offset); 439 440 while (count > 0) { 441 *p = bswap16(*pointer++); 442 amiga_bus_reorder_protect(); 443 --count; 444 } 445 } 446 447 static void 448 empb_bsrr2(bus_space_handle_t handle, bus_size_t offset, u_int16_t *pointer, 449 bus_size_t count) 450 { 451 volatile uint16_t *p; 452 bus_addr_t wp; 453 454 wp = empb_switch_window(empb_sc, handle); 455 p = (volatile uint16_t *) ((empb_sc->pci_mem_win_t->base) + 456 (handle - wp) + offset); 457 458 while (count > 0) { 459 *pointer++ = *p; 460 amiga_bus_reorder_protect(); 461 p++; 462 --count; 463 } 464 } 465 466 static void 467 empb_bsrr2_swap(bus_space_handle_t handle, bus_size_t offset, 468 u_int16_t *pointer, bus_size_t count) 469 { 470 volatile uint16_t *p; 471 bus_addr_t wp; 472 473 wp = empb_switch_window(empb_sc, handle); 474 p = (volatile uint16_t *) ((empb_sc->pci_mem_win_t->base) + 475 (handle - wp) + offset); 476 477 while (count > 0) { 478 *pointer++ = bswap16(*p); 479 amiga_bus_reorder_protect(); 480 p++; 481 --count; 482 } 483 } 484 485 static void 486 empb_bssr2_swap(bus_space_handle_t handle, bus_size_t offset, unsigned value, 487 bus_size_t count) 488 { 489 volatile uint16_t *p; 490 bus_addr_t wp; 491 492 wp = empb_switch_window(empb_sc, handle); 493 p = (volatile uint16_t *) ((empb_sc->pci_mem_win_t->base) + 494 (handle - wp) + offset); 495 496 while (count > 0) { 497 *p = bswap16(value); 498 amiga_bus_reorder_protect(); 499 p++; 500 --count; 501 } 502 } 503 504 static void 505 empb_bswr2(bus_space_handle_t handle, bus_size_t offset, 506 const u_int16_t *pointer, bus_size_t count) 507 { 508 volatile uint16_t *p; 509 bus_addr_t wp; 510 511 wp = empb_switch_window(empb_sc, handle); 512 p = (volatile u_int16_t *) ((empb_sc->pci_mem_win_t->base) + 513 (handle - wp) + offset); 514 515 while (count > 0) { 516 *p = *pointer++; 517 amiga_bus_reorder_protect(); 518 p++; 519 --count; 520 } 521 } 522 523 static void 524 empb_bswr2_swap(bus_space_handle_t handle, bus_size_t offset, 525 const u_int16_t *pointer, bus_size_t count) 526 { 527 volatile uint16_t *p; 528 bus_addr_t wp; 529 530 wp = empb_switch_window(empb_sc, handle); 531 p = (volatile u_int16_t *) ((empb_sc->pci_mem_win_t->base) 532 + (handle - wp) + offset); 533 534 while (count > 0) { 535 *p = bswap16(*pointer++); 536 amiga_bus_reorder_protect(); 537 p++; 538 --count; 539 } 540 } 541 542 /* XXX: this is broken, rewrite, XXX 2: should we swap here? */ 543 static void 544 empb_bscr2(bus_space_handle_t handlefrom, bus_size_t from, 545 bus_space_handle_t handleto, bus_size_t to, bus_size_t count) 546 { 547 volatile uint16_t *p, *q; 548 bus_addr_t wp; 549 550 wp = empb_switch_window(empb_sc, handlefrom); 551 552 p = (volatile uint16_t *) 553 ( ((empb_sc->pci_mem_win_t->base)+(handlefrom - wp)) + from ); 554 q = (volatile uint16_t *) 555 ( ((empb_sc->pci_mem_win_t->base)+(handleto - wp)) + to ); 556 557 while (count > 0) { 558 *q = *p; 559 amiga_bus_reorder_protect(); 560 p++; q++; 561 --count; 562 } 563 } 564 565 /* === 32-bit methods === */ 566 567 static uint32_t 568 empb_bsr4(bus_space_handle_t handle, bus_size_t offset) 569 { 570 uint32_t *p; 571 uint32_t x; 572 bus_addr_t wp; 573 574 wp = empb_switch_window(empb_sc, handle); 575 576 p = (uint32_t*) ((empb_sc->pci_mem_win_t->base) 577 + (handle - wp) + offset); 578 x = *p; 579 580 return x; 581 } 582 583 static uint32_t 584 empb_bsr4_swap(bus_space_handle_t handle, bus_size_t offset) 585 { 586 uint32_t *p; 587 uint32_t x; 588 bus_addr_t wp; 589 590 wp = empb_switch_window(empb_sc, handle); 591 592 p = (uint32_t*) ((empb_sc->pci_mem_win_t->base) + (handle - wp) 593 + offset); 594 x = *p; 595 596 return bswap32(x); 597 } 598 599 600 static void 601 empb_bsw4(bus_space_handle_t handle, bus_size_t offset, unsigned value) 602 { 603 uint32_t *p; 604 bus_addr_t wp; 605 606 wp = empb_switch_window(empb_sc, handle); 607 p = (uint32_t*)((empb_sc->pci_mem_win_t->base) + (handle - wp) 608 + offset); 609 *p = value; 610 } 611 612 static void 613 empb_bsw4_swap(bus_space_handle_t handle, bus_size_t offset, unsigned value) 614 { 615 uint32_t *p; 616 bus_addr_t wp; 617 618 wp = empb_switch_window(empb_sc, handle); 619 p = (uint32_t*)((empb_sc->pci_mem_win_t->base) + (handle - wp) 620 + offset); 621 *p = bswap32(value); 622 } 623 624 static void 625 empb_bsrm4(bus_space_handle_t handle, bus_size_t offset, u_int32_t *pointer, 626 bus_size_t count) 627 { 628 volatile uint32_t *p; 629 bus_addr_t wp; 630 631 wp = empb_switch_window(empb_sc, handle); 632 p = (volatile uint32_t *) ((empb_sc->pci_mem_win_t->base) + 633 (handle - wp) + offset); 634 635 while (count > 0) { 636 *pointer++ = *p; 637 amiga_bus_reorder_protect(); 638 --count; 639 } 640 } 641 642 static void 643 empb_bsrm4_swap(bus_space_handle_t handle, bus_size_t offset, 644 u_int32_t *pointer, bus_size_t count) 645 { 646 volatile uint32_t *p; 647 bus_addr_t wp; 648 649 wp = empb_switch_window(empb_sc, handle); 650 p = (volatile uint32_t *) ((empb_sc->pci_mem_win_t->base) + 651 (handle - wp) + offset); 652 653 while (count > 0) { 654 *pointer++ = bswap32(*p); 655 amiga_bus_reorder_protect(); 656 --count; 657 } 658 } 659 660 static void 661 empb_bswm4(bus_space_handle_t handle, bus_size_t offset, 662 const u_int32_t *pointer, bus_size_t count) 663 { 664 volatile uint32_t *p; 665 bus_addr_t wp; 666 667 wp = empb_switch_window(empb_sc, handle); 668 p = (volatile uint32_t *) ((empb_sc->pci_mem_win_t->base) + 669 (handle - wp) + offset); 670 671 while (count > 0) { 672 *p = *pointer++; 673 amiga_bus_reorder_protect(); 674 --count; 675 } 676 } 677 678 static void 679 empb_bswm4_swap(bus_space_handle_t handle, bus_size_t offset, 680 const u_int32_t *pointer, bus_size_t count) 681 { 682 volatile uint32_t *p; 683 bus_addr_t wp; 684 685 wp = empb_switch_window(empb_sc, handle); 686 p = (volatile uint32_t *) ((empb_sc->pci_mem_win_t->base) + 687 (handle - wp) + offset); 688 689 while (count > 0) { 690 *p = bswap32(*pointer++); 691 amiga_bus_reorder_protect(); 692 --count; 693 } 694 } 695 696 static void 697 empb_bsrr4(bus_space_handle_t handle, bus_size_t offset, u_int32_t *pointer, 698 bus_size_t count) 699 { 700 volatile uint32_t *p; 701 bus_addr_t wp; 702 703 wp = empb_switch_window(empb_sc, handle); 704 p = (volatile uint32_t *) ((empb_sc->pci_mem_win_t->base) + 705 (handle - wp) + offset); 706 707 while (count > 0) { 708 *pointer++ = *p; 709 amiga_bus_reorder_protect(); 710 p++; 711 --count; 712 } 713 } 714 715 static void 716 empb_bsrr4_swap(bus_space_handle_t handle, bus_size_t offset, 717 u_int32_t *pointer, bus_size_t count) 718 { 719 volatile uint32_t *p; 720 bus_addr_t wp; 721 722 wp = empb_switch_window(empb_sc, handle); 723 p = (volatile uint32_t *) ((empb_sc->pci_mem_win_t->base) 724 + (handle - wp) + offset); 725 726 while (count > 0) { 727 *pointer++ = bswap32(*p); 728 amiga_bus_reorder_protect(); 729 p++; 730 --count; 731 } 732 } 733 734 static void 735 empb_bssr4_swap(bus_space_handle_t handle, bus_size_t offset, unsigned value, 736 bus_size_t count) 737 { 738 volatile uint32_t *p; 739 bus_addr_t wp; 740 741 wp = empb_switch_window(empb_sc, handle); 742 p = (volatile uint32_t *) ((empb_sc->pci_mem_win_t->base) + 743 (handle - wp) + offset); 744 745 while (count > 0) { 746 *p = bswap32(value); 747 amiga_bus_reorder_protect(); 748 p++; 749 --count; 750 } 751 } 752 753 static void 754 empb_bswr4(bus_space_handle_t handle, bus_size_t offset, 755 const u_int32_t *pointer, bus_size_t count) 756 { 757 volatile uint32_t *p; 758 bus_addr_t wp; 759 760 wp = empb_switch_window(empb_sc, handle); 761 p = (volatile uint32_t *) ((empb_sc->pci_mem_win_t->base) 762 + (handle - wp) + offset); 763 764 while (count > 0) { 765 *p = *pointer++; 766 amiga_bus_reorder_protect(); 767 p++; 768 --count; 769 } 770 } 771 772 static void 773 empb_bswr4_swap(bus_space_handle_t handle, bus_size_t offset, 774 const u_int32_t *pointer, bus_size_t count) 775 { 776 volatile uint32_t *p; 777 bus_addr_t wp; 778 779 wp = empb_switch_window(empb_sc, handle); 780 p = (volatile uint32_t *) ((empb_sc->pci_mem_win_t->base) 781 + (handle - wp) + offset); 782 783 while (count > 0) { 784 *p = bswap32(*pointer++); 785 amiga_bus_reorder_protect(); 786 p++; 787 --count; 788 } 789 } 790 791 /* XXX: this is broken, rewrite, XXX 2: should we swap here? */ 792 void 793 empb_bscr4(bus_space_handle_t handlefrom, bus_size_t from, 794 bus_space_handle_t handleto, bus_size_t to, bus_size_t count) 795 { 796 volatile uint32_t *p, *q; 797 bus_addr_t wp; 798 799 wp = empb_switch_window(empb_sc, handlefrom); 800 801 p = (volatile uint32_t *) 802 ( ((empb_sc->pci_mem_win_t->base)+(handlefrom - wp)) + from ); 803 q = (volatile uint32_t *) 804 ( ((empb_sc->pci_mem_win_t->base)+(handleto - wp)) + to ); 805 806 while (count > 0) { 807 *q = *p; 808 amiga_bus_reorder_protect(); 809 p++; q++; 810 --count; 811 } 812 } 813 /* === end of implementation === */ 814 815 const struct amiga_bus_space_methods empb_bus_swap = { 816 817 .bsm = empb_bsm, 818 .bsms = empb_bsms, 819 .bsu = empb_bsu, 820 .bsa = NULL, 821 .bsf = NULL, 822 823 /* 8-bit methods */ 824 .bsr1 = empb_bsr1, 825 .bsw1 = empb_bsw1, 826 .bsrm1 = empb_bsrm1, 827 .bswm1 = empb_bswm1, 828 .bsrr1 = empb_bsrr1, 829 .bswr1 = empb_bswr1, 830 .bssr1 = empb_bssr1, 831 .bscr1 = empb_bscr1, 832 833 /* 16-bit methods */ 834 .bsr2 = empb_bsr2_swap, 835 .bsw2 = empb_bsw2_swap, 836 .bsrs2 = empb_bsr2, 837 .bsws2 = empb_bsw2, 838 .bsrm2 = empb_bsrm2_swap, 839 .bswm2 = empb_bswm2_swap, 840 .bsrms2 = empb_bsrm2, 841 .bswms2 = empb_bswm2, 842 .bsrr2 = empb_bsrr2_swap, 843 .bswr2 = empb_bswr2_swap, 844 .bsrrs2 = empb_bsrr2, 845 .bswrs2 = empb_bswr2, 846 .bssr2 = empb_bssr2_swap, 847 .bscr2 = empb_bscr2, /* swap? */ 848 849 /* 32-bit methods */ 850 .bsr4 = empb_bsr4_swap, 851 .bsw4 = empb_bsw4_swap, 852 .bsrs4 = empb_bsr4, 853 .bsws4 = empb_bsw4, 854 .bsrm4 = empb_bsrm4_swap, 855 .bswm4 = empb_bswm4_swap, 856 .bsrms4 = empb_bsrm4, 857 .bswms4 = empb_bswm4, 858 .bsrr4 = empb_bsrr4_swap, 859 .bswr4 = empb_bswr4_swap, 860 .bsrrs4 = empb_bsrr4, 861 .bswrs4 = empb_bswr4, 862 .bssr4 = empb_bssr4_swap, 863 .bscr4 = empb_bscr4 /* swap? */ 864 865 }; 866 867 868