1 /* $NetBSD: bus.h,v 1.26 2008/04/28 20:23:27 martin Exp $ */ 2 3 /*- 4 * Copyright (c) 1996, 1997, 1998 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 /* 34 * Copyright (C) 1997 Scott Reynolds. All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in the 43 * documentation and/or other materials provided with the distribution. 44 * 3. The name of the author may not be used to endorse or promote products 45 * derived from this software without specific prior written permission 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 57 */ 58 59 #ifndef _MAC68K_BUS_H_ 60 #define _MAC68K_BUS_H_ 61 62 /* 63 * Value for the mac68k bus space tag, not to be used directly by MI code. 64 */ 65 #define MAC68K_BUS_SPACE_MEM 0 /* space is mem space */ 66 67 #define __BUS_SPACE_HAS_STREAM_METHODS 1 68 69 /* 70 * Bus address and size types 71 */ 72 typedef u_long bus_addr_t; 73 typedef u_long bus_size_t; 74 75 /* 76 * Access methods for bus resources and address space. 77 */ 78 #define BSH_T struct bus_space_handle_s 79 typedef int bus_space_tag_t; 80 typedef struct bus_space_handle_s { 81 u_long base; 82 int swapped; 83 int stride; 84 85 u_int8_t (*bsr1)(bus_space_tag_t, BSH_T *, bus_size_t); 86 u_int16_t (*bsr2)(bus_space_tag_t, BSH_T *, bus_size_t); 87 u_int32_t (*bsr4)(bus_space_tag_t, BSH_T *, bus_size_t); 88 u_int8_t (*bsrs1)(bus_space_tag_t, BSH_T *, bus_size_t); 89 u_int16_t (*bsrs2)(bus_space_tag_t, BSH_T *, bus_size_t); 90 u_int32_t (*bsrs4)(bus_space_tag_t, BSH_T *, bus_size_t); 91 void (*bsrm1)(bus_space_tag_t, BSH_T *, bus_size_t, 92 u_int8_t *, size_t); 93 void (*bsrm2)(bus_space_tag_t, BSH_T *, bus_size_t, 94 u_int16_t *, size_t); 95 void (*bsrm4)(bus_space_tag_t, BSH_T *, bus_size_t, 96 u_int32_t *, size_t); 97 void (*bsrms1)(bus_space_tag_t, BSH_T *, bus_size_t, 98 u_int8_t *, size_t); 99 void (*bsrms2)(bus_space_tag_t, BSH_T *, bus_size_t, 100 u_int16_t *, size_t); 101 void (*bsrms4)(bus_space_tag_t, BSH_T *, bus_size_t, 102 u_int32_t *, size_t); 103 void (*bsrr1)(bus_space_tag_t, BSH_T *, bus_size_t, 104 u_int8_t *, size_t); 105 void (*bsrr2)(bus_space_tag_t, BSH_T *, bus_size_t, 106 u_int16_t *, size_t); 107 void (*bsrr4)(bus_space_tag_t, BSH_T *, bus_size_t, 108 u_int32_t *, size_t); 109 void (*bsrrs1)(bus_space_tag_t, BSH_T *, bus_size_t, 110 u_int8_t *, size_t); 111 void (*bsrrs2)(bus_space_tag_t, BSH_T *, bus_size_t, 112 u_int16_t *, size_t); 113 void (*bsrrs4)(bus_space_tag_t, BSH_T *, bus_size_t, 114 u_int32_t *, size_t); 115 void (*bsw1)(bus_space_tag_t, BSH_T *, bus_size_t, u_int8_t); 116 void (*bsw2)(bus_space_tag_t, BSH_T *, bus_size_t, 117 u_int16_t); 118 void (*bsw4)(bus_space_tag_t, BSH_T *, bus_size_t, 119 u_int32_t); 120 void (*bsws1)(bus_space_tag_t, BSH_T *, bus_size_t, 121 u_int8_t); 122 void (*bsws2)(bus_space_tag_t, BSH_T *, bus_size_t, 123 u_int16_t); 124 void (*bsws4)(bus_space_tag_t, BSH_T *, bus_size_t, 125 u_int32_t); 126 void (*bswm1)(bus_space_tag_t, BSH_T *, bus_size_t, 127 const u_int8_t *, size_t); 128 void (*bswm2)(bus_space_tag_t, BSH_T *, bus_size_t, 129 const u_int16_t *, size_t); 130 void (*bswm4)(bus_space_tag_t, BSH_T *, bus_size_t, 131 const u_int32_t *, size_t); 132 void (*bswms1)(bus_space_tag_t, BSH_T *, bus_size_t, 133 const u_int8_t *, size_t); 134 void (*bswms2)(bus_space_tag_t, BSH_T *, bus_size_t, 135 const u_int16_t *, size_t); 136 void (*bswms4)(bus_space_tag_t, BSH_T *, bus_size_t, 137 const u_int32_t *, size_t); 138 void (*bswr1)(bus_space_tag_t, BSH_T *, bus_size_t, 139 const u_int8_t *, size_t); 140 void (*bswr2)(bus_space_tag_t, BSH_T *, bus_size_t, 141 const u_int16_t *, size_t); 142 void (*bswr4)(bus_space_tag_t, BSH_T *, bus_size_t, 143 const u_int32_t *, size_t); 144 void (*bswrs1)(bus_space_tag_t, BSH_T *, bus_size_t, 145 const u_int8_t *, size_t); 146 void (*bswrs2)(bus_space_tag_t, BSH_T *, bus_size_t, 147 const u_int16_t *, size_t); 148 void (*bswrs4)(bus_space_tag_t, BSH_T *, bus_size_t, 149 const u_int32_t *, size_t); 150 void (*bssm1)(bus_space_tag_t, BSH_T *, bus_size_t, 151 u_int8_t v, size_t); 152 void (*bssm2)(bus_space_tag_t, BSH_T *, bus_size_t, 153 u_int16_t v, size_t); 154 void (*bssm4)(bus_space_tag_t, BSH_T *, bus_size_t, 155 u_int32_t v, size_t); 156 void (*bssr1)(bus_space_tag_t, BSH_T *, bus_size_t, 157 u_int8_t v, size_t); 158 void (*bssr2)(bus_space_tag_t, BSH_T *, bus_size_t, 159 u_int16_t v, size_t); 160 void (*bssr4)(bus_space_tag_t, BSH_T *, bus_size_t, 161 u_int32_t v, size_t); 162 } bus_space_handle_t; 163 #undef BSH_T 164 165 void mac68k_bus_space_handle_swapped(bus_space_tag_t, 166 bus_space_handle_t *); 167 void mac68k_bus_space_handle_set_stride(bus_space_tag_t, 168 bus_space_handle_t *, int); 169 170 /* 171 * int bus_space_map(bus_space_tag_t t, bus_addr_t addr, 172 * bus_size_t size, int flags, bus_space_handle_t *bshp); 173 * 174 * Map a region of bus space. 175 */ 176 177 #define BUS_SPACE_MAP_CACHEABLE 0x01 178 #define BUS_SPACE_MAP_LINEAR 0x02 179 #define BUS_SPACE_MAP_PREFETCHABLE 0x04 180 181 int bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, 182 int, bus_space_handle_t *); 183 184 /* 185 * void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh, 186 * bus_size_t size); 187 * 188 * Unmap a region of bus space. 189 */ 190 191 void bus_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t); 192 193 /* 194 * int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh, 195 * bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp); 196 * 197 * Get a new handle for a subregion of an already-mapped area of bus space. 198 */ 199 200 int bus_space_subregion(bus_space_tag_t, bus_space_handle_t, 201 bus_size_t, bus_size_t size, bus_space_handle_t *); 202 203 /* 204 * int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart, 205 * bus_addr_t rend, bus_size_t size, bus_size_t align, 206 * bus_size_t boundary, int flags, bus_addr_t *addrp, 207 * bus_space_handle_t *bshp); 208 * 209 * Allocate a region of bus space. 210 */ 211 212 int bus_space_alloc(bus_space_tag_t, bus_addr_t rstart, 213 bus_addr_t rend, bus_size_t size, bus_size_t align, 214 bus_size_t boundary, int cacheable, bus_addr_t *addrp, 215 bus_space_handle_t *bshp); 216 217 /* 218 * int bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh, 219 * bus_size_t size); 220 * 221 * Free a region of bus space. 222 */ 223 224 void bus_space_free(bus_space_tag_t, bus_space_handle_t bsh, 225 bus_size_t size); 226 227 /* 228 * int mac68k_bus_space_probe(bus_space_tag_t t, bus_space_handle_t bsh, 229 * bus_size_t offset, int sz); 230 * 231 * Probe the bus at t/bsh/offset, using sz as the size of the load. 232 * 233 * This is a machine-dependent extension, and is not to be used by 234 * machine-independent code. 235 */ 236 237 int mac68k_bus_space_probe(bus_space_tag_t, 238 bus_space_handle_t bsh, bus_size_t, int sz); 239 240 /* 241 * u_intN_t bus_space_read_N(bus_space_tag_t tag, 242 * bus_space_handle_t bsh, bus_size_t offset); 243 * 244 * Read a 1, 2, 4, or 8 byte quantity from bus space 245 * described by tag/handle/offset. 246 */ 247 248 u_int8_t mac68k_bsr1(bus_space_tag_t, bus_space_handle_t *, bus_size_t); 249 u_int8_t mac68k_bsr1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t); 250 u_int16_t mac68k_bsr2(bus_space_tag_t, bus_space_handle_t *, bus_size_t); 251 u_int16_t mac68k_bsr2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t); 252 u_int16_t mac68k_bsr2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t); 253 u_int16_t mac68k_bsrs2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t); 254 u_int32_t mac68k_bsr4(bus_space_tag_t, bus_space_handle_t *, bus_size_t); 255 u_int32_t mac68k_bsr4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t); 256 u_int32_t mac68k_bsr4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t); 257 u_int32_t mac68k_bsrs4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t); 258 259 #define bus_space_read_1(t,h,o) (h).bsr1((t), &(h), (o)) 260 #define bus_space_read_2(t,h,o) (h).bsr2((t), &(h), (o)) 261 #define bus_space_read_4(t,h,o) (h).bsr4((t), &(h), (o)) 262 #define bus_space_read_stream_1(t,h,o) (h).bsrs1((t), &(h), (o)) 263 #define bus_space_read_stream_2(t,h,o) (h).bsrs2((t), &(h), (o)) 264 #define bus_space_read_stream_4(t,h,o) (h).bsrs4((t), &(h), (o)) 265 266 #if 0 /* Cause a link error for bus_space_read_8 */ 267 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!! 268 #define bus_space_read_stream_8(t, h, o) \ 269 !!! bus_space_read_stream_8 unimplemented !!! 270 #endif 271 272 /* 273 * void bus_space_read_multi_N(bus_space_tag_t tag, 274 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t *addr, 275 * size_t count); 276 * 277 * Read `count' 1, 2, 4, or 8 byte quantities from bus space 278 * described by tag/handle/offset and copy into buffer provided. 279 */ 280 281 void mac68k_bsrm1(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 282 u_int8_t *, size_t); 283 void mac68k_bsrm1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 284 u_int8_t *, size_t); 285 void mac68k_bsrm2(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 286 u_int16_t *, size_t); 287 void mac68k_bsrm2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 288 u_int16_t *, size_t); 289 void mac68k_bsrm2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 290 u_int16_t *, size_t); 291 void mac68k_bsrms2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 292 u_int16_t *, size_t); 293 void mac68k_bsrm4(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 294 u_int32_t *, size_t); 295 void mac68k_bsrms4(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 296 u_int32_t *, size_t); 297 void mac68k_bsrm4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 298 u_int32_t *, size_t); 299 void mac68k_bsrm4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 300 u_int32_t *, size_t); 301 void mac68k_bsrms4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 302 u_int32_t *, size_t); 303 304 #if defined(DIAGNOSTIC) 305 #define bus_space_read_multi_1(t, h, o, a, c) do { \ 306 if ((c) == 0) \ 307 panic("bus_space_read_multi_1 called with zero count."); \ 308 (h).bsrm1(t,&(h),o,a,c); } while (0) 309 #define bus_space_read_multi_2(t, h, o, a, c) do { \ 310 if ((c) == 0) \ 311 panic("bus_space_read_multi_2 called with zero count."); \ 312 (h).bsrm2(t,&(h),o,a,c); } while (0) 313 #define bus_space_read_multi_4(t, h, o, a, c) do { \ 314 if ((c) == 0) \ 315 panic("bus_space_read_multi_4 called with zero count."); \ 316 (h).bsrm4(t,&(h),o,a,c); } while (0) 317 #define bus_space_read_multi_stream_1(t, h, o, a, c) do { \ 318 if ((c) == 0) \ 319 panic("bus_space_read_multi_stream_1 called with count=0."); \ 320 (h).bsrms1(t,&(h),o,a,c); } while (0) 321 #define bus_space_read_multi_stream_2(t, h, o, a, c) do { \ 322 if ((c) == 0) \ 323 panic("bus_space_read_multi_stream_2 called with count=0."); \ 324 (h).bsrms2(t,&(h),o,a,c); } while (0) 325 #define bus_space_read_multi_stream_4(t, h, o, a, c) do { \ 326 if ((c) == 0) \ 327 panic("bus_space_read_multi_stream_4 called with count=0."); \ 328 (h).bsrms4(t,&(h),o,a,c); } while (0) 329 #else 330 #define bus_space_read_multi_1(t, h, o, a, c) \ 331 do { if (c) (h).bsrm1(t, &(h), o, a, c); } while (0) 332 #define bus_space_read_multi_2(t, h, o, a, c) \ 333 do { if (c) (h).bsrm2(t, &(h), o, a, c); } while (0) 334 #define bus_space_read_multi_4(t, h, o, a, c) \ 335 do { if (c) (h).bsrm4(t, &(h), o, a, c); } while (0) 336 #define bus_space_read_multi_stream_1(t, h, o, a, c) \ 337 do { if (c) (h).bsrms1(t, &(h), o, a, c); } while (0) 338 #define bus_space_read_multi_stream_2(t, h, o, a, c) \ 339 do { if (c) (h).bsrms2(t, &(h), o, a, c); } while (0) 340 #define bus_space_read_multi_stream_4(t, h, o, a, c) \ 341 do { if (c) (h).bsrms4(t, &(h), o, a, c); } while (0) 342 #endif 343 344 #if 0 /* Cause a link error for bus_space_read_multi_8 */ 345 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!! 346 #define bus_space_read_multi_stream_8 \ 347 !!! bus_space_read_multi_stream_8 unimplemented !!! 348 #endif 349 350 /* 351 * void bus_space_read_region_N(bus_space_tag_t tag, 352 * bus_space_handle_t bsh, bus_size_t offset, 353 * u_intN_t *addr, size_t count); 354 * 355 * Read `count' 1, 2, 4, or 8 byte quantities from bus space 356 * described by tag/handle and starting at `offset' and copy into 357 * buffer provided. 358 */ 359 360 void mac68k_bsrr1(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 361 u_int8_t *, size_t); 362 void mac68k_bsrr1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 363 u_int8_t *, size_t); 364 void mac68k_bsrr2(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 365 u_int16_t *, size_t); 366 void mac68k_bsrr2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 367 u_int16_t *, size_t); 368 void mac68k_bsrr2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 369 u_int16_t *, size_t); 370 void mac68k_bsrrs2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 371 u_int16_t *, size_t); 372 void mac68k_bsrr4(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 373 u_int32_t *, size_t); 374 void mac68k_bsrr4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 375 u_int32_t *, size_t); 376 void mac68k_bsrr4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 377 u_int32_t *, size_t); 378 void mac68k_bsrrs4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 379 u_int32_t *, size_t); 380 381 #if defined(DIAGNOSTIC) 382 #define bus_space_read_region_1(t, h, o, a, c) do { \ 383 if ((c) == 0) \ 384 panic("bus_space_read_region_1 called with zero count."); \ 385 (h).bsrr1(t,&(h),o,a,c); } while (0) 386 #define bus_space_read_region_2(t, h, o, a, c) do { \ 387 if ((c) == 0) \ 388 panic("bus_space_read_region_2 called with zero count."); \ 389 (h).bsrr2(t,&(h),o,a,c); } while (0) 390 #define bus_space_read_region_4(t, h, o, a, c) do { \ 391 if ((c) == 0) \ 392 panic("bus_space_read_region_4 called with zero count."); \ 393 (h).bsrr4(t,&(h),o,a,c); } while (0) 394 #define bus_space_read_region_stream_1(t, h, o, a, c) do { \ 395 if ((c) == 0) \ 396 panic("bus_space_read_region_stream_1 called with count=0."); \ 397 (h).bsrrs1(t,&(h),o,a,c); } while (0) 398 #define bus_space_read_region_stream_2(t, h, o, a, c) do { \ 399 if ((c) == 0) \ 400 panic("bus_space_read_region_stream_2 called with count=0."); \ 401 (h).bsrrs2(t,&(h),o,a,c); } while (0) 402 #define bus_space_read_region_stream_4(t, h, o, a, c) do { \ 403 if ((c) == 0) \ 404 panic("bus_space_read_region_stream_4 called with count=0."); \ 405 (h).bsrrs4(t,&(h),o,a,c); } while (0) 406 #else 407 #define bus_space_read_region_1(t, h, o, a, c) \ 408 do { if (c) (h).bsrr1(t,&(h),o,a,c); } while (0) 409 #define bus_space_read_region_2(t, h, o, a, c) \ 410 do { if (c) (h).bsrr2(t,&(h),o,a,c); } while (0) 411 #define bus_space_read_region_4(t, h, o, a, c) \ 412 do { if (c) (h).bsrr4(t,&(h),o,a,c); } while (0) 413 #define bus_space_read_region_stream_1(t, h, o, a, c) \ 414 do { if (c) (h).bsrrs1(t,&(h),o,a,c); } while (0) 415 #define bus_space_read_region_stream_2(t, h, o, a, c) \ 416 do { if (c) (h).bsrrs2(t,&(h),o,a,c); } while (0) 417 #define bus_space_read_region_stream_4(t, h, o, a, c) \ 418 do { if (c) (h).bsrrs4(t,&(h),o,a,c); } while (0) 419 #endif 420 421 #if 0 /* Cause a link error for bus_space_read_region_8 */ 422 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!! 423 #define bus_space_read_region_stream_8 \ 424 !!! bus_space_read_region_stream_8 unimplemented !!! 425 #endif 426 427 /* 428 * void bus_space_write_N(bus_space_tag_t tag, 429 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t value); 430 * 431 * Write the 1, 2, 4, or 8 byte value `value' to bus space 432 * described by tag/handle/offset. 433 */ 434 435 void mac68k_bsw1(bus_space_tag_t, bus_space_handle_t *, bus_size_t, u_int8_t); 436 void mac68k_bsw1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 437 u_int8_t); 438 void mac68k_bsw2(bus_space_tag_t, bus_space_handle_t *, bus_size_t, u_int16_t); 439 void mac68k_bsw2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 440 u_int16_t); 441 void mac68k_bsw2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 442 u_int16_t); 443 void mac68k_bsws2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 444 u_int16_t); 445 void mac68k_bsw4(bus_space_tag_t, bus_space_handle_t *, bus_size_t, u_int32_t); 446 void mac68k_bsw4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 447 u_int32_t); 448 void mac68k_bsw4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 449 u_int32_t); 450 void mac68k_bsws4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 451 u_int32_t); 452 453 #define bus_space_write_1(t, h, o, v) (h).bsw1(t, &(h), o, v) 454 #define bus_space_write_2(t, h, o, v) (h).bsw2(t, &(h), o, v) 455 #define bus_space_write_4(t, h, o, v) (h).bsw4(t, &(h), o, v) 456 #define bus_space_write_stream_1(t, h, o, v) (h).bsws1(t, &(h), o, v) 457 #define bus_space_write_stream_2(t, h, o, v) (h).bsws2(t, &(h), o, v) 458 #define bus_space_write_stream_4(t, h, o, v) (h).bsws4(t, &(h), o, v) 459 460 #if 0 /* Cause a link error for bus_space_write_8 */ 461 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!! 462 #define bus_space_write_stream_8 \ 463 !!! bus_space_write_stream_8 not implemented !!! 464 #endif 465 466 /* 467 * void bus_space_write_multi_N(bus_space_tag_t tag, 468 * bus_space_handle_t bsh, bus_size_t offset, const u_intN_t *addr, 469 * size_t count); 470 * 471 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer 472 * provided to bus space described by tag/handle/offset. 473 */ 474 475 void mac68k_bswm1(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 476 const u_int8_t *, size_t); 477 void mac68k_bswm1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 478 const u_int8_t *, size_t); 479 void mac68k_bswm2(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 480 const u_int16_t *, size_t); 481 void mac68k_bswm2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 482 const u_int16_t *, size_t); 483 void mac68k_bswm2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 484 const u_int16_t *, size_t); 485 void mac68k_bswms2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 486 const u_int16_t *, size_t); 487 void mac68k_bswm4(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 488 const u_int32_t *, size_t); 489 void mac68k_bswm4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 490 const u_int32_t *, size_t); 491 void mac68k_bswm4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 492 const u_int32_t *, size_t); 493 void mac68k_bswms4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 494 const u_int32_t *, size_t); 495 496 #if defined(DIAGNOSTIC) 497 #define bus_space_write_multi_1(t, h, o, a, c) do { \ 498 if ((c) == 0) \ 499 panic("bus_space_write_multi_1 called with zero count."); \ 500 (h).bswm1(t,&(h),o,a,c); } while (0) 501 #define bus_space_write_multi_2(t, h, o, a, c) do { \ 502 if ((c) == 0) \ 503 panic("bus_space_write_multi_2 called with zero count."); \ 504 (h).bswm2(t,&(h),o,a,c); } while (0) 505 #define bus_space_write_multi_4(t, h, o, a, c) do { \ 506 if ((c) == 0) \ 507 panic("bus_space_write_multi_4 called with zero count."); \ 508 (h).bswm4(t,&(h),o,a,c); } while (0) 509 #define bus_space_write_multi_stream_1(t, h, o, a, c) do { \ 510 if ((c) == 0) \ 511 panic("bus_space_write_multi_stream_1 called with count=0."); \ 512 (h).bswms1(t,&(h),o,a,c); } while (0) 513 #define bus_space_write_multi_stream_2(t, h, o, a, c) do { \ 514 if ((c) == 0) \ 515 panic("bus_space_write_multi_stream_2 called with count=0."); \ 516 (h).bswms2(t,&(h),o,a,c); } while (0) 517 #define bus_space_write_multi_stream_4(t, h, o, a, c) do { \ 518 if ((c) == 0) \ 519 panic("bus_space_write_multi_stream_4 called with count=0."); \ 520 (h).bswms4(t,&(h),o,a,c); } while (0) 521 #else 522 #define bus_space_write_multi_1(t, h, o, a, c) \ 523 do { if (c) (h).bswm1(t, &(h), o, a, c); } while (0) 524 #define bus_space_write_multi_2(t, h, o, a, c) \ 525 do { if (c) (h).bswm2(t, &(h), o, a, c); } while (0) 526 #define bus_space_write_multi_4(t, h, o, a, c) \ 527 do { if (c) (h).bswm4(t, &(h), o, a, c); } while (0) 528 #define bus_space_write_multi_stream_1(t, h, o, a, c) \ 529 do { if (c) (h).bswms1(t, &(h), o, a, c); } while (0) 530 #define bus_space_write_multi_stream_2(t, h, o, a, c) \ 531 do { if (c) (h).bswms2(t, &(h), o, a, c); } while (0) 532 #define bus_space_write_multi_stream_4(t, h, o, a, c) \ 533 do { if (c) (h).bswms4(t, &(h), o, a, c); } while (0) 534 #endif 535 536 #if 0 /* Cause a link error for bus_space_write_8 */ 537 #define bus_space_write_multi_8(t, h, o, a, c) \ 538 !!! bus_space_write_multi_8 unimplimented !!! 539 #define bus_space_write_multi_stream_8(t, h, o, a, c) \ 540 !!! bus_space_write_multi_stream_8 unimplimented !!! 541 #endif 542 543 /* 544 * void bus_space_write_region_N(bus_space_tag_t tag, 545 * bus_space_handle_t bsh, bus_size_t offset, const u_intN_t *addr, 546 * size_t count); 547 * 548 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided 549 * to bus space described by tag/handle starting at `offset'. 550 */ 551 552 void mac68k_bswr1(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 553 const u_int8_t *, size_t); 554 void mac68k_bswr1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 555 const u_int8_t *, size_t); 556 void mac68k_bswr2(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 557 const u_int16_t *, size_t); 558 void mac68k_bswr2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 559 const u_int16_t *, size_t); 560 void mac68k_bswr2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 561 const u_int16_t *, size_t); 562 void mac68k_bswrs2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 563 const u_int16_t *, size_t); 564 void mac68k_bswr4(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 565 const u_int32_t *, size_t); 566 void mac68k_bswr4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 567 const u_int32_t *, size_t); 568 void mac68k_bswr4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 569 const u_int32_t *, size_t); 570 void mac68k_bswrs4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 571 const u_int32_t *, size_t); 572 573 #if defined(DIAGNOSTIC) 574 #define bus_space_write_region_1(t, h, o, a, c) do { \ 575 if ((c) == 0) \ 576 panic("bus_space_write_region_1 called with zero count."); \ 577 (h).bswr1(t,&(h),o,a,c); } while (0) 578 #define bus_space_write_region_2(t, h, o, a, c) do { \ 579 if ((c) == 0) \ 580 panic("bus_space_write_region_2 called with zero count."); \ 581 (h).bswr2(t,&(h),o,a,c); } while (0) 582 #define bus_space_write_region_4(t, h, o, a, c) do { \ 583 if ((c) == 0) \ 584 panic("bus_space_write_region_4 called with zero count."); \ 585 (h).bswr4(t,&(h),o,a,c); } while (0) 586 #define bus_space_write_region_stream_1(t, h, o, a, c) do { \ 587 if ((c) == 0) \ 588 panic("bus_space_write_region_stream_1 called with count=0."); \ 589 (h).bswrs1(t,&(h),o,a,c); } while (0) 590 #define bus_space_write_region_stream_2(t, h, o, a, c) do { \ 591 if ((c) == 0) \ 592 panic("bus_space_write_region_stream_2 called with count=0."); \ 593 (h).bswrs2(t,&(h),o,a,c); } while (0) 594 #define bus_space_write_region_stream_4(t, h, o, a, c) do { \ 595 if ((c) == 0) \ 596 panic("bus_space_write_region_stream_4 called with count=0."); \ 597 (h).bswrs4(t,&(h),o,a,c); } while (0) 598 #else 599 #define bus_space_write_region_1(t, h, o, a, c) \ 600 do { if (c) (h).bswr1(t,&(h),o,a,c); } while (0) 601 #define bus_space_write_region_2(t, h, o, a, c) \ 602 do { if (c) (h).bswr2(t,&(h),o,a,c); } while (0) 603 #define bus_space_write_region_4(t, h, o, a, c) \ 604 do { if (c) (h).bswr4(t,&(h),o,a,c); } while (0) 605 #define bus_space_write_region_stream_1(t, h, o, a, c) \ 606 do { if (c) (h).bswrs1(t,&(h),o,a,c); } while (0) 607 #define bus_space_write_region_stream_2(t, h, o, a, c) \ 608 do { if (c) (h).bswrs2(t,&(h),o,a,c); } while (0) 609 #define bus_space_write_region_stream_4(t, h, o, a, c) \ 610 do { if (c) (h).bswrs4(t,&(h),o,a,c); } while (0) 611 #endif 612 613 #if 0 /* Cause a link error for bus_space_write_region_8 */ 614 #define bus_space_write_region_8 \ 615 !!! bus_space_write_region_8 unimplemented !!! 616 #define bus_space_write_region_stream_8 \ 617 !!! bus_space_write_region_stream_8 unimplemented !!! 618 #endif 619 620 /* 621 * void bus_space_set_multi_N(bus_space_tag_t tag, 622 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val, 623 * size_t count); 624 * 625 * Write the 1, 2, 4, or 8 byte value `val' to bus space described 626 * by tag/handle/offset `count' times. 627 */ 628 629 void mac68k_bssm1(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 630 u_int8_t, size_t); 631 void mac68k_bssm1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 632 u_int8_t, size_t); 633 void mac68k_bssm2(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 634 u_int16_t, size_t); 635 void mac68k_bssm2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 636 u_int16_t, size_t); 637 void mac68k_bssm2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 638 u_int16_t, size_t); 639 void mac68k_bssm4(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 640 u_int32_t, size_t); 641 void mac68k_bssm4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 642 u_int32_t, size_t); 643 void mac68k_bssm4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 644 u_int32_t, size_t); 645 646 #if defined(DIAGNOSTIC) 647 #define bus_space_set_multi_1(t, h, o, val, c) do { \ 648 if ((c) == 0) \ 649 panic("bus_space_set_multi_1 called with zero count."); \ 650 (h).bssm1(t,&(h),o,val,c); } while (0) 651 #define bus_space_set_multi_2(t, h, o, val, c) do { \ 652 if ((c) == 0) \ 653 panic("bus_space_set_multi_2 called with zero count."); \ 654 (h).bssm2(t,&(h),o,val,c); } while (0) 655 #define bus_space_set_multi_4(t, h, o, val, c) do { \ 656 if ((c) == 0) \ 657 panic("bus_space_set_multi_4 called with zero count."); \ 658 (h).bssm4(t,&(h),o,val,c); } while (0) 659 #else 660 #define bus_space_set_multi_1(t, h, o, val, c) \ 661 do { if (c) (h).bssm1(t,&(h),o,val,c); } while (0) 662 #define bus_space_set_multi_2(t, h, o, val, c) \ 663 do { if (c) (h).bssm2(t,&(h),o,val,c); } while (0) 664 #define bus_space_set_multi_4(t, h, o, val, c) \ 665 do { if (c) (h).bssm4(t,&(h),o,val,c); } while (0) 666 #endif 667 668 #if 0 /* Cause a link error for bus_space_set_multi_8 */ 669 #define bus_space_set_multi_8 \ 670 !!! bus_space_set_multi_8 unimplemented !!! 671 #endif 672 673 /* 674 * void bus_space_set_region_N(bus_space_tag_t tag, 675 * bus_space_handle_t bsh, bus_size_t, u_intN_t val, 676 * size_t count); 677 * 678 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described 679 * by tag/handle starting at `offset'. 680 */ 681 682 void mac68k_bssr1(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 683 u_int8_t, size_t); 684 void mac68k_bssr1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 685 u_int8_t, size_t); 686 void mac68k_bssr2(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 687 u_int16_t, size_t); 688 void mac68k_bssr2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 689 u_int16_t, size_t); 690 void mac68k_bssr2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 691 u_int16_t, size_t); 692 void mac68k_bssr4(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 693 u_int32_t, size_t); 694 void mac68k_bssr4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 695 u_int32_t, size_t); 696 void mac68k_bssr4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t, 697 u_int32_t, size_t); 698 699 #if defined(DIAGNOSTIC) 700 #define bus_space_set_region_1(t, h, o, val, c) do { \ 701 if ((c) == 0) \ 702 panic("bus_space_set_region_1 called with zero count."); \ 703 (h).bssr1(t,&(h),o,val,c); } while (0) 704 #define bus_space_set_region_2(t, h, o, val, c) do { \ 705 if ((c) == 0) \ 706 panic("bus_space_set_region_2 called with zero count."); \ 707 (h).bssr2(t,&(h),o,val,c); } while (0) 708 #define bus_space_set_region_4(t, h, o, val, c) do { \ 709 if ((c) == 0) \ 710 panic("bus_space_set_region_4 called with zero count."); \ 711 (h).bssr4(t,&(h),o,val,c); } while (0) 712 #else 713 #define bus_space_set_region_1(t, h, o, val, c) \ 714 do { if (c) (h).bssr1(t,&(h),o,val,c); } while (0) 715 #define bus_space_set_region_2(t, h, o, val, c) \ 716 do { if (c) (h).bssr2(t,&(h),o,val,c); } while (0) 717 #define bus_space_set_region_4(t, h, o, val, c) \ 718 do { if (c) (h).bssr4(t,&(h),o,val,c); } while (0) 719 #endif 720 721 #if 0 /* Cause a link error for bus_space_set_region_8 */ 722 #define bus_space_set_region_8 \ 723 !!! bus_space_set_region_8 unimplemented !!! 724 #endif 725 726 /* 727 * void bus_space_copy_N(bus_space_tag_t tag, 728 * bus_space_handle_t bsh1, bus_size_t off1, 729 * bus_space_handle_t bsh2, bus_size_t off2, size_t count); 730 * 731 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting 732 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2. 733 */ 734 735 #define __MAC68K_copy_region_N(BYTES) \ 736 static __inline void __CONCAT(bus_space_copy_region_,BYTES) \ 737 (bus_space_tag_t, \ 738 bus_space_handle_t, bus_size_t, \ 739 bus_space_handle_t, bus_size_t, \ 740 bus_size_t); \ 741 \ 742 static __inline void \ 743 __CONCAT(bus_space_copy_region_,BYTES)( \ 744 bus_space_tag_t t, \ 745 bus_space_handle_t h1, \ 746 bus_size_t o1, \ 747 bus_space_handle_t h2, \ 748 bus_size_t o2, \ 749 bus_size_t c) \ 750 { \ 751 bus_size_t o; \ 752 \ 753 if ((h1.base + o1) >= (h2.base + o2)) { \ 754 /* src after dest: copy forward */ \ 755 for (o = 0; c != 0; c--, o += BYTES) \ 756 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \ 757 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \ 758 } else { \ 759 /* dest after src: copy backwards */ \ 760 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \ 761 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \ 762 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \ 763 } \ 764 } 765 __MAC68K_copy_region_N(1) 766 __MAC68K_copy_region_N(2) 767 __MAC68K_copy_region_N(4) 768 #if 0 /* Cause a link error for bus_space_copy_8 */ 769 #define bus_space_copy_8 \ 770 !!! bus_space_copy_8 unimplemented !!! 771 #endif 772 773 #undef __MAC68K_copy_region_N 774 775 /* 776 * Bus read/write barrier methods. 777 * 778 * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh, 779 * bus_size_t offset, bus_size_t len, int flags); 780 * 781 * Note: the 680x0 does not currently require barriers, but we must 782 * provide the flags to MI code. 783 */ 784 #define bus_space_barrier(t, h, o, l, f) \ 785 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f))) 786 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ 787 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ 788 789 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t) 790 791 #include <m68k/bus_dma.h> 792 793 #endif /* _MAC68K_BUS_H_ */ 794