1 /* $NetBSD: bus.h,v 1.23 2010/02/03 13:56:53 phx Exp $ */ 2 3 /* 4 * Copyright (c) 1996 Leo Weppelman. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef _AMIGA_BUS_H_ 28 #define _AMIGA_BUS_H_ 29 30 #include <sys/types.h> 31 32 /* for public use: */ 33 34 /* 35 * Memory addresses (in bus space) 36 */ 37 38 typedef u_int32_t bus_addr_t; 39 typedef u_int32_t bus_size_t; 40 41 /* 42 * Access methods for bus resources and address space. 43 */ 44 typedef struct bus_space_tag *bus_space_tag_t; 45 typedef u_long bus_space_handle_t; 46 47 /* unpublic, but needed by method implementors */ 48 49 /* 50 * Lazyness macros for function declarations. 51 */ 52 53 #define bsr(what, typ) \ 54 typ (what)(bus_space_handle_t, bus_addr_t) 55 56 #define bsw(what, typ) \ 57 void (what)(bus_space_handle_t, bus_addr_t, unsigned) 58 59 #define bsrm(what, typ) \ 60 void (what)(bus_space_handle_t, bus_size_t, typ *, bus_size_t) 61 62 #define bswm(what, typ) \ 63 void (what)(bus_space_handle_t, bus_size_t, const typ *, bus_size_t) 64 65 #define bssr(what, typ) \ 66 void (what)(bus_space_handle_t, bus_size_t, unsigned, bus_size_t) 67 68 #define bscr(what, typ) \ 69 void (what)(bus_space_handle_t, bus_size_t, \ 70 bus_space_handle_t, bus_size_t, bus_size_t) 71 72 /* 73 * Implementation specific structures. 74 * XXX Don't use outside of bus_space definitions! 75 * XXX maybe this should be encapsuled in a non-global .h file? 76 */ 77 78 struct bus_space_tag { 79 bus_addr_t base; 80 const struct amiga_bus_space_methods *absm; 81 }; 82 83 struct amiga_bus_space_methods { 84 85 /* map, unmap, etc */ 86 87 int (*bsm)(bus_space_tag_t, 88 bus_addr_t, bus_size_t, int, bus_space_handle_t *); 89 90 int (*bsms)(bus_space_handle_t, 91 bus_size_t, bus_size_t, bus_space_handle_t *); 92 93 void (*bsu)(bus_space_handle_t, bus_size_t); 94 95 /* placeholders for currently not implemented alloc and free */ 96 97 void *bsa; 98 void *bsf; 99 100 /* 8 bit methods */ 101 102 bsr(*bsr1, u_int8_t); 103 bsw(*bsw1, u_int8_t); 104 bsrm(*bsrm1, u_int8_t); 105 bswm(*bswm1, u_int8_t); 106 bsrm(*bsrr1, u_int8_t); 107 bswm(*bswr1, u_int8_t); 108 bssr(*bssr1, u_int8_t); 109 bscr(*bscr1, u_int8_t); 110 111 /* 16bit methods */ 112 113 bsr(*bsr2, u_int16_t); 114 bsw(*bsw2, u_int16_t); 115 bsr(*bsrs2, u_int16_t); 116 bsw(*bsws2, u_int16_t); 117 bsrm(*bsrm2, u_int16_t); 118 bswm(*bswm2, u_int16_t); 119 bsrm(*bsrms2, u_int16_t); 120 bswm(*bswms2, u_int16_t); 121 bsrm(*bsrr2, u_int16_t); 122 bswm(*bswr2, u_int16_t); 123 bsrm(*bsrrs2, u_int16_t); 124 bswm(*bswrs2, u_int16_t); 125 bssr(*bssr2, u_int16_t); 126 bscr(*bscr2, u_int16_t); 127 128 /* add 32bit methods here */ 129 }; 130 131 /* 132 * Macro definition of map, unmap, etc. 133 */ 134 135 #define bus_space_map(t, o, s, f, hp) \ 136 ((t)->absm->bsm)((t), (o), (s), (f), (hp)) 137 138 #define bus_space_subregion(t, h, o, s, hp) \ 139 ((t)->absm->bsms)((h), (o), (s), (hp)) 140 141 #define bus_space_unmap(t, h, s) \ 142 ((t)->absm->bsu)((h), (s)) 143 144 /* 145 * Macro definition of _2 functions as indirect method array calls 146 */ 147 148 /* 0: Helper macros */ 149 150 #define dbsdr(n, t, h, o) ((t)->absm->n)((h), (o)) 151 #define dbsdw(n, t, h, o, v) ((t)->absm->n)((h), (o), (v)) 152 #define dbsm(n, t, h, o, p, c) ((t)->absm->n)((h), (o), (p), (c)) 153 #define dbss(n, t, h, o, v, c) ((t)->absm->n)((h), (o), (v), (c)) 154 #define dbsc(n, t, h, o, v, c) ((t)->absm->n)((h), (o), (v), (c)) 155 156 /* 1: byte-wide "functions" */ 157 158 #define bus_space_read_1(t, h, o) dbsdr(bsr1, t, h, o) 159 #define bus_space_write_1(t, h, o, v) dbsdw(bsw1, t, h, o, v) 160 161 #define bus_space_read_multi_1(t, h, o, p, c) dbsm(bsrm1, t, h, o, p, c) 162 #define bus_space_write_multi_1(t, h, o, p, c) dbsm(bswm1, t, h, o, p, c) 163 164 #define bus_space_read_region_1(t, h, o, p, c) dbsm(bsrr1, t, h, o, p, c) 165 #define bus_space_write_region_1(t, h, o, p, c) dbsm(bswr1, t, h, o, p, c) 166 167 #define bus_space_set_region_1(t, h, o, v, c) dbss(bssr1, t, h, o, v, c) 168 #define bus_space_copy_region_1(t, h, o, g, q, c) dbss(bscr1, t, h, o, g, q, c) 169 170 171 /* 2: word-wide "functions" */ 172 173 #define bus_space_read_2(t, h, o) dbsdr(bsr2, t, h, o) 174 #define bus_space_write_2(t, h, o, v) dbsdw(bsw2, t, h, o, v) 175 #define bus_space_read_stream_2(t, h, o) dbsdr(bsrs2, t, h, o) 176 #define bus_space_write_stream_2(t, h, o, v) dbsdw(bsws2, t, h, o, v) 177 178 #define bus_space_read_multi_2(t, h, o, p, c) dbsm(bsrm2, t, h, o, p, c) 179 #define bus_space_write_multi_2(t, h, o, p, c) dbsm(bswm2, t, h, o, p, c) 180 181 #define bus_space_read_multi_stream_2(t, h, o, p, c) \ 182 dbsm(bsrms2, t, h, o, p, c) 183 184 #define bus_space_write_multi_stream_2(t, h, o, p, c) \ 185 dbsm(bswms2, t, h, o, p, c) 186 187 #define bus_space_read_region_2(t, h, o, p, c) dbsm(bsrr2, t, h, o, p, c) 188 #define bus_space_write_region_2(t, h, o, p, c) dbsm(bswr2, t, h, o, p, c) 189 190 #define bus_space_read_region_stream_2(t, h, o, p, c) \ 191 dbsm(bsrrs2, t, h, o, p, c) 192 193 #define bus_space_write_region_stream_2(t, h, o, p, c) \ 194 dbsm(bswrs2, t, h, o, p, c) 195 196 #define bus_space_set_region_2(t, h, o, v, c) dbss(bssr2, t, h, o, v, c) 197 #define bus_space_copy_region_2(t, h, o, g, q, c) dbss(bscr2, t, h, o, g, q, c) 198 199 /* 4: Fake 32-bit macros */ 200 201 #define bus_space_read_4(t, h, o) \ 202 (panic("bus_space_read_4 not implemented"), 0) 203 204 #define bus_space_write_4(t, h, o, v) \ 205 panic("bus_space_write_4 not implemented") 206 207 #define bus_space_read_stream_4(t, h, o) \ 208 (panic("bus_space_read_stream_4 not implemented"), 0) 209 210 #define bus_space_write_stream_4(t, h, o, v) \ 211 panic("bus_space_read_stream_4 not implemented") 212 213 #define bus_space_read_multi_4(t, h, o, p, c) \ 214 panic("bus_space_read_multi_4 not implemented") 215 216 #define bus_space_write_multi_4(t, h, o, p, c) \ 217 panic("bus_space_write_multi_4 not implemented") 218 219 #define bus_space_read_multi_stream_4(t, h, o, p, c) \ 220 panic("bus_space_read_multi_stream_4 not implemented") 221 222 #define bus_space_write_multi_stream_4(t, h, o, p, c) \ 223 panic("bus_space_write_multi_stream_4 not implemented") 224 225 #define bus_space_read_region_stream_4(t, h, o, p, c) \ 226 panic("bus_space_read_region_stream_4 not implemented") 227 228 #define bus_space_write_region_stream_4(t, h, o, p, c) \ 229 panic("bus_space_write_region_stream_4 not implemented") 230 231 /* 232 * Bus read/write barrier methods. 233 * 234 * void bus_space_barrier(bus_space_tag_t tag, 235 * bus_space_handle_t bsh, bus_size_t offset, 236 * bus_size_t len, int flags); 237 * 238 * Note: the 680x0 does not currently require barriers, but we must 239 * provide the flags to MI code. 240 */ 241 #define bus_space_barrier(t, h, o, l, f) \ 242 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f))) 243 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */ 244 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */ 245 246 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t) 247 248 #define __BUS_SPACE_HAS_STREAM_METHODS 249 250 /* Instruction for enforcing reorder protection. Nothing for 68k. */ 251 #define amiga_bus_reorder_protect() 252 253 extern const struct amiga_bus_space_methods amiga_bus_stride_1; 254 extern const struct amiga_bus_space_methods amiga_bus_stride_2; 255 extern const struct amiga_bus_space_methods amiga_bus_stride_4; 256 extern const struct amiga_bus_space_methods amiga_bus_stride_4swap; 257 extern const struct amiga_bus_space_methods amiga_bus_stride_16; 258 259 #endif /* _AMIGA_BUS_H_ */ 260