bus.h revision 1.6 1 /* $NetBSD: bus.h,v 1.6 1998/10/12 22:02:43 is 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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Leo Weppelman for the
17 * NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef _AMIGA_BUS_H_
34 #define _AMIGA_BUS_H_
35
36 #include <sys/types.h>
37
38 /*
39 * Memory addresses (in bus space)
40 */
41
42 typedef u_int32_t bus_addr_t;
43 typedef u_int32_t bus_size_t;
44
45 /*
46 * Access methods for bus resources and address space.
47 */
48 typedef struct bus_space_tag *bus_space_tag_t;
49 typedef u_long bus_space_handle_t;
50
51 /*
52 * Lazyness macros for function declarations.
53 */
54
55 #define bsr(what, typ) \
56 typ (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t)
57
58 #define bsw(what, typ) \
59 void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, typ)
60
61 #define bsrm(what, typ) \
62 void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
63 typ *, bus_size_t)
64
65 #define bswm(what, typ) \
66 void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
67 const typ *, bus_size_t)
68
69 #define bssr(what, typ) \
70 void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
71 typ, bus_size_t)
72
73 #define bscr(what, typ) \
74 void (what)(bus_space_tag_t, \
75 bus_space_handle_t, bus_size_t, \
76 bus_space_handle_t, bus_size_t, \
77 bus_size_t)
78
79 /* declarations for _1 functions */
80
81 bsrm(bus_space_read_multi_1, u_int8_t);
82 bswm(bus_space_write_multi_1, u_int8_t);
83 bsrm(bus_space_read_region_1, u_int8_t);
84 bswm(bus_space_write_region_1, u_int8_t);
85 bsrm(bus_space_read_stream_1, u_int8_t);
86 bswm(bus_space_write_stream_1, u_int8_t);
87 bssr(bus_space_set_region_1, u_int8_t);
88 bscr(bus_space_copy_region_1, u_int8_t);
89
90 /*
91 * Implementation specific structures.
92 * XXX Don't use outside of bus_space definitions!
93 * XXX maybe this should be encapsuled in a non-global .h file?
94 */
95
96 struct bus_space_tag {
97 bus_addr_t base;
98 u_int8_t stride;
99 u_int8_t dum[3];
100 struct amiga_bus_space_methods *absm;
101 };
102
103 struct amiga_bus_space_methods {
104
105 /* 16bit methods */
106
107 bsr(*bsr2, u_int16_t);
108 bsw(*bsw2, u_int16_t);
109 bsrm(*bsrm2, u_int16_t);
110 bswm(*bswm2, u_int16_t);
111 bsrm(*bsrr2, u_int16_t);
112 bswm(*bswr2, u_int16_t);
113 bsrm(*bsrs2, u_int16_t);
114 bswm(*bsws2, u_int16_t);
115 bssr(*bssr2, u_int16_t);
116 bscr(*bscr2, u_int16_t);
117
118 /* add 32bit methods here */
119 };
120
121 /*
122 * Macro definition of map, unmap, etc.
123 */
124
125 #define bus_space_map(tag,off,size,cache,handle) \
126 (*(handle) = (tag)->base + ((off)<<(tag)->stride), 0)
127
128 #define bus_space_subregion(tag, handle, offset, size, nhandlep) \
129 (*(nhandlep) = (handle) + ((offset)<<(tag)->stride), 0)
130
131 #define bus_space_unmap(tag,handle,size) (void)0
132
133 /*
134 * Macro definition of some _1 functions:
135 */
136
137 #define bus_space_read_1(t, h, o) \
138 ((void) t, (*(volatile u_int8_t *)((h) + ((o)<<(t)->stride))))
139
140 #define bus_space_write_1(t, h, o, v) \
141 ((void) t, ((void)(*(volatile u_int8_t *)((h) + ((o)<<(t)->stride)) = (v))))
142
143 /*
144 * Inline definition of other _1 functions:
145 */
146
147 extern __inline__ void
148 bus_space_read_multi_1(t, h, o, a, c)
149 bus_space_tag_t t;
150 bus_space_handle_t h;
151 bus_size_t o, c;
152 u_int8_t *a;
153 {
154 for (; c; a++, c--)
155 *a = bus_space_read_1(t, h, o);
156 }
157
158 extern __inline__ void
159 bus_space_write_multi_1(t, h, o, a, c)
160 bus_space_tag_t t;
161 bus_space_handle_t h;
162 bus_size_t o, c;
163 const u_int8_t *a;
164 {
165 for (; c; a++, c--)
166 bus_space_write_1(t, h, o, *a);
167 }
168
169 extern __inline__ void
170 bus_space_read_region_1(t, h, o, a, c)
171 bus_space_tag_t t;
172 bus_space_handle_t h;
173 bus_size_t o, c;
174 u_int8_t *a;
175 {
176 for (; c; a++, c--)
177 *a = bus_space_read_1(t, h, o++);
178 }
179
180 extern __inline__ void
181 bus_space_write_region_1(t, h, o, a, c)
182 bus_space_tag_t t;
183 bus_space_handle_t h;
184 bus_size_t o, c;
185 const u_int8_t *a;
186 {
187 for (; c; a++, c--)
188 bus_space_write_1(t, h, o++, *a);
189 }
190
191 extern __inline__ void
192 bus_space_set_region_1(t, h, o, v, c)
193 bus_space_tag_t t;
194 bus_space_handle_t h;
195 bus_size_t o, c;
196 u_int8_t v;
197 {
198 while (c--)
199 bus_space_write_1(t, h, o++, v);
200 }
201
202 extern __inline__ void
203 bus_space_copy_region_1(t, srch, srco, dsth, dsto, c)
204 bus_space_tag_t t;
205 bus_space_handle_t srch, dsth;
206 bus_size_t srco, dsto, c;
207 {
208 u_int8_t v;
209
210 while (c--) {
211 v = bus_space_read_1(t, srch, srco++);
212 bus_space_write_1(t, dsth, dsto++, v);
213 }
214 }
215
216 extern __inline__ void
217 bus_space_read_stream_1(t, h, o, a, c)
218 bus_space_tag_t t;
219 bus_space_handle_t h;
220 bus_size_t o, c;
221 u_int8_t *a;
222 {
223 for (; c; a++, c--)
224 *a = bus_space_read_1(t, h, o++);
225 }
226
227 extern __inline__ void
228 bus_space_write_stream_1(t, h, o, a, c)
229 bus_space_tag_t t;
230 bus_space_handle_t h;
231 bus_size_t o, c;
232 const u_int8_t *a;
233 {
234 for (; c; a++, c--)
235 bus_space_write_1(t, h, o++, *a);
236 }
237
238 /*
239 * Macro definition of _2 functions as indirect method array calls
240 */
241
242 #define bus_space_read_2(t, h, o) ((t)->bsr2)((t), (h), (o))
243 #define bus_space_write_2(t, h, o, v) ((t)->bsw2)((t), (h), (o), (v))
244
245 #define bus_space_read_multi_2(t, h, o, p, c) \
246 ((t)->absm->bsrm2)((t), (h), (o), (p), (c))
247
248 #define bus_space_write_multi_2(t, h, o, p, c) \
249 ((t)->absm->bswm2)((t), (h), (o), (p), (c))
250
251 #define bus_space_read_region_2(t, h, o, p, c) \
252 ((t)->absm->bsrr2)((t), (h), (o), (p), (c))
253
254 #define bus_space_write_region_2(t, h, o, p, c) \
255 ((t)->absm->bswr2)((t), (h), (o), (p), (c))
256
257 #define bus_space_read_stream_2(t, h, o, p, c) \
258 ((t)->absm->bsrs2)((t), (h), (o), (p), (c))
259
260 #define bus_space_write_stream_2(t, h, o, p, c) \
261 ((t)->absm->bsws2)((t), (h), (o), (p), (c))
262
263 #define bus_space_set_region_2(t, h, o, v, c) \
264 ((t)->absm->bssr2)((t), (h), (o), (v), (c))
265
266 #define bus_space_copy_region_2(t, srch, srco, dsth, dsto, c) \
267 ((t)->absm->bscr2)((t), (srch), (srco), (dsth), (dsto), (c))
268
269 #endif /* _AMIGA_BUS_H_ */
270