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