1 /* $NetBSD: podulebus_io.c,v 1.4 2005/12/11 12:16:05 christos Exp $ */ 2 3 /* 4 * Copyright (c) 1997 Mark Brinicombe. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Mark Brinicombe. 18 * 4. The name of the company nor the name of the author may be used to 19 * endorse or promote products derived from this software without specific 20 * prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 /* 36 * bus_space I/O functions for podulebus 37 */ 38 39 #include <sys/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: podulebus_io.c,v 1.4 2005/12/11 12:16:05 christos Exp $"); 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <machine/bus.h> 45 46 /* Proto types for all the bus_space structure functions */ 47 48 bs_protos(podulebus); 49 bs_protos(bs_notimpl); 50 51 /* Declare the podulebus bus space tag */ 52 53 struct bus_space podulebus_bs_tag = { 54 /* cookie */ 55 (void *) 2, /* Shift to apply to registers */ 56 57 /* mapping/unmapping */ 58 podulebus_bs_map, 59 podulebus_bs_unmap, 60 podulebus_bs_subregion, 61 62 /* allocation/deallocation */ 63 podulebus_bs_alloc, 64 podulebus_bs_free, 65 66 /* get kernel virtual address */ 67 0, /* there is no linear mapping */ 68 69 /* mmap bus space for userland */ 70 bs_notimpl_bs_mmap, /* there is no bus mapping ... well maybe EASI space? */ 71 72 /* barrier */ 73 podulebus_bs_barrier, 74 75 /* read (single) */ 76 podulebus_bs_r_1, 77 podulebus_bs_r_2, 78 podulebus_bs_r_4, 79 bs_notimpl_bs_r_8, 80 81 /* read multiple */ 82 podulebus_bs_rm_1, 83 podulebus_bs_rm_2, 84 bs_notimpl_bs_rm_4, 85 bs_notimpl_bs_rm_8, 86 87 /* read region */ 88 podulebus_bs_rr_1, 89 podulebus_bs_rr_2, 90 bs_notimpl_bs_rr_4, 91 bs_notimpl_bs_rr_8, 92 93 /* write (single) */ 94 podulebus_bs_w_1, 95 podulebus_bs_w_2, 96 podulebus_bs_w_4, 97 bs_notimpl_bs_w_8, 98 99 /* write multiple */ 100 podulebus_bs_wm_1, 101 podulebus_bs_wm_2, 102 bs_notimpl_bs_wm_4, 103 bs_notimpl_bs_wm_8, 104 105 /* write region */ 106 podulebus_bs_wr_1, 107 podulebus_bs_wr_2, 108 bs_notimpl_bs_wr_4, 109 bs_notimpl_bs_wr_8, 110 111 /* set multiple */ 112 bs_notimpl_bs_sm_1, 113 bs_notimpl_bs_sm_2, 114 bs_notimpl_bs_sm_4, 115 bs_notimpl_bs_sm_8, 116 117 /* set region */ 118 podulebus_bs_sr_1, 119 podulebus_bs_sr_2, 120 bs_notimpl_bs_sr_4, 121 bs_notimpl_bs_sr_8, 122 123 /* copy */ 124 bs_notimpl_bs_c_1, 125 bs_notimpl_bs_c_2, 126 bs_notimpl_bs_c_4, 127 bs_notimpl_bs_c_8, 128 }; 129 130 /* bus space functions */ 131 132 int 133 podulebus_bs_map(t, bpa, size, cacheable, bshp) 134 void *t; 135 bus_addr_t bpa; 136 bus_size_t size; 137 int cacheable; 138 bus_space_handle_t *bshp; 139 { 140 /* 141 * Temporary implementation as all I/O is already mapped etc. 142 * 143 * Eventually this function will do the mapping check for multiple maps 144 */ 145 *bshp = bpa; 146 return(0); 147 } 148 149 int 150 podulebus_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable, 151 bpap, bshp) 152 void *t; 153 bus_addr_t rstart, rend; 154 bus_size_t size, alignment, boundary; 155 int cacheable; 156 bus_addr_t *bpap; 157 bus_space_handle_t *bshp; 158 { 159 panic("podulebus_bs_alloc(): Help!"); 160 } 161 162 163 void 164 podulebus_bs_unmap(t, bsh, size) 165 void *t; 166 bus_space_handle_t bsh; 167 bus_size_t size; 168 { 169 /* 170 * Temporary implementation 171 */ 172 } 173 174 void 175 podulebus_bs_free(t, bsh, size) 176 void *t; 177 bus_space_handle_t bsh; 178 bus_size_t size; 179 { 180 181 panic("podulebus_bs_free(): Help!"); 182 /* podulebus_bs_unmap() does all that we need to do. */ 183 /* podulebus_bs_unmap(t, bsh, size);*/ 184 } 185 186 int 187 podulebus_bs_subregion(t, bsh, offset, size, nbshp) 188 void *t; 189 bus_space_handle_t bsh; 190 bus_size_t offset, size; 191 bus_space_handle_t *nbshp; 192 { 193 194 *nbshp = bsh + (offset << ((int)t)); 195 return (0); 196 } 197 198 void 199 podulebus_bs_barrier(t, bsh, offset, len, flags) 200 void *t; 201 bus_space_handle_t bsh; 202 bus_size_t offset, len; 203 int flags; 204 { 205 } 206 207 /* Rough-and-ready implementations from arm26 */ 208 209 void 210 podulebus_bs_rr_1(void *cookie, bus_space_handle_t bsh, 211 bus_size_t offset, u_int8_t *datap, bus_size_t count) 212 { 213 int i; 214 215 for (i = 0; i < count; i++) 216 datap[i] = podulebus_bs_r_1(cookie, bsh, offset + i); 217 } 218 219 void 220 podulebus_bs_rr_2(void *cookie, bus_space_handle_t bsh, 221 bus_size_t offset, u_int16_t *datap, bus_size_t count) 222 { 223 int i; 224 225 for (i = 0; i < count; i++) 226 datap[i] = podulebus_bs_r_2(cookie, bsh, offset + i); 227 } 228 229 void 230 podulebus_bs_wr_1(void *cookie, bus_space_handle_t bsh, 231 bus_size_t offset, u_int8_t const *datap, 232 bus_size_t count) 233 { 234 int i; 235 236 for (i = 0; i < count; i++) 237 podulebus_bs_w_1(cookie, bsh, offset + i, datap[i]); 238 } 239 240 void 241 podulebus_bs_wr_2(void *cookie, bus_space_handle_t bsh, 242 bus_size_t offset, u_int16_t const *datap, 243 bus_size_t count) 244 { 245 int i; 246 247 for (i = 0; i < count; i++) 248 podulebus_bs_w_2(cookie, bsh, offset + i, datap[i]); 249 } 250 251 void 252 podulebus_bs_sr_1(void *cookie, bus_space_handle_t bsh, 253 bus_size_t offset, u_int8_t value, bus_size_t count) 254 { 255 int i; 256 257 for (i = 0; i < count; i++) 258 podulebus_bs_w_1(cookie, bsh, offset + i, value); 259 } 260 261 void 262 podulebus_bs_sr_2(void *cookie, bus_space_handle_t bsh, 263 bus_size_t offset, u_int16_t value, bus_size_t count) 264 { 265 int i; 266 267 for (i = 0; i < count; i++) 268 podulebus_bs_w_2(cookie, bsh, offset + i, value); 269 } 270