1 /* $NetBSD: amiga_bus_simple_4.c,v 1.10 2011/10/30 08:33:43 rkujawa Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Ignatios Souvatzis. 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 #include <sys/cdefs.h> 33 __KERNEL_RCSID(1, "$NetBSD: amiga_bus_simple_4.c,v 1.10 2011/10/30 08:33:43 rkujawa Exp $"); 34 35 #define AMIGA_SIMPLE_BUS_STRIDE 4 /* 1 byte per long */ 36 #define AMIGA_SIMPLE_BUS_WORD_METHODS 37 #define AMIGA_SIMPLE_BUS_LONGWORD_METHODS 38 39 #include "simple_busfuncs.c" 40 41 /* 42 * Little-endian word methods. 43 * Stream access does not swap, used for 16-bit and 32-bit wide transfers 44 * of byte streams. Non-stream access swaps bytes. 45 * XXX Only *_multi_2 and *_multi_4 transfers currently swap bytes XXX 46 */ 47 48 bsrm(oabs(bsrm2_swap_), u_int16_t); 49 bswm(oabs(bswm2_swap_), u_int16_t); 50 bsrm(oabs(bsrm4_swap_), u_int32_t); 51 bswm(oabs(bswm4_swap_), u_int32_t); 52 53 void 54 oabs(bsrm2_swap_)(bus_space_handle_t handle, bus_size_t offset, 55 u_int16_t *pointer, bus_size_t count) 56 { 57 volatile u_int16_t *p; 58 59 p = (volatile u_int16_t *)(handle + offset * AMIGA_SIMPLE_BUS_STRIDE); 60 61 while (count > 0) { 62 *pointer++ = bswap16(*p); 63 amiga_bus_reorder_protect(); 64 --count; 65 } 66 } 67 68 void 69 oabs(bswm2_swap_)(bus_space_handle_t handle, bus_size_t offset, 70 const u_int16_t *pointer, bus_size_t count) 71 { 72 volatile u_int16_t *p; 73 74 p = (volatile u_int16_t *)(handle + offset * AMIGA_SIMPLE_BUS_STRIDE); 75 76 while (count > 0) { 77 *p = bswap16(*pointer); 78 amiga_bus_reorder_protect(); 79 ++pointer; 80 --count; 81 } 82 } 83 84 void 85 oabs(bsrm4_swap_)(bus_space_handle_t handle, bus_size_t offset, 86 u_int32_t *pointer, bus_size_t count) 87 { 88 volatile u_int32_t *p; 89 90 p = (volatile u_int32_t *)(handle + offset * AMIGA_SIMPLE_BUS_STRIDE); 91 92 while (count > 0) { 93 *pointer++ = bswap32(*p); 94 amiga_bus_reorder_protect(); 95 --count; 96 } 97 } 98 99 void 100 oabs(bswm4_swap_)(bus_space_handle_t handle, bus_size_t offset, 101 const u_int32_t *pointer, bus_size_t count) 102 { 103 volatile u_int32_t *p; 104 105 p = (volatile u_int32_t *)(handle + offset * AMIGA_SIMPLE_BUS_STRIDE); 106 107 while (count > 0) { 108 *p = bswap32(*pointer); 109 amiga_bus_reorder_protect(); 110 ++pointer; 111 --count; 112 } 113 } 114 115 const struct amiga_bus_space_methods amiga_bus_stride_4swap = { 116 117 .bsm = oabs(bsm_), 118 .bsms = oabs(bsms_), 119 .bsu = oabs(bsu_), 120 .bsa = NULL, 121 .bsf = NULL, 122 123 .bsr1 = oabs(bsr1_), 124 .bsw1 = oabs(bsw1_), 125 .bsrm1 = oabs(bsrm1_), 126 .bswm1 = oabs(bswm1_), 127 .bsrr1 = oabs(bsrr1_), 128 .bswr1 = oabs(bswr1_), 129 .bssr1 = oabs(bssr1_), 130 .bscr1 = oabs(bscr1_), 131 132 .bsr2 = oabs(bsr2_), /* XXX swap? */ 133 .bsw2 = oabs(bsw2_), /* XXX swap? */ 134 .bsrs2 = oabs(bsr2_), 135 .bsws2 = oabs(bsw2_), 136 .bsrm2 = oabs(bsrm2_swap_), 137 .bswm2 = oabs(bswm2_swap_), 138 .bsrms2 = oabs(bsrm2_), 139 .bswms2 = oabs(bswm2_), 140 .bsrr2 = oabs(bsrr2_), /* XXX swap? */ 141 .bswr2 = oabs(bswr2_), /* XXX swap? */ 142 .bsrrs2 = oabs(bsrr2_), 143 .bswrs2 = oabs(bswr2_), 144 .bssr2 = oabs(bssr2_), /* XXX swap? */ 145 .bscr2 = oabs(bscr2_), /* XXX swap? */ 146 147 .bsr4 = oabs(bsr4_), /* XXX swap? */ 148 .bsw4 = oabs(bsw4_), /* XXX swap? */ 149 .bsrs4 = oabs(bsr4_), 150 .bsws4 = oabs(bsw4_), 151 .bsrm4 = oabs(bsrm4_swap_), 152 .bswm4 = oabs(bswm4_swap_), 153 .bsrms4 = oabs(bsrm4_), 154 .bswms4 = oabs(bswm4_), 155 .bsrr4 = oabs(bsrr4_), /* XXX swap? */ 156 .bswr4 = oabs(bswr4_), /* XXX swap? */ 157 .bsrrs4 = oabs(bsrr4_), 158 .bswrs4 = oabs(bswr4_), 159 .bssr4 = oabs(bssr4_), /* XXX swap? */ 160 .bscr4 = oabs(bscr4_) /* XXX swap? */ 161 }; 162 163