bus.h revision 1.7 1 1.7 is /* $NetBSD: bus.h,v 1.7 1998/11/07 22:44:36 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.5 is 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.4 is
121 1.5 is /*
122 1.5 is * Macro definition of map, unmap, etc.
123 1.5 is */
124 1.1 is
125 1.1 is #define bus_space_map(tag,off,size,cache,handle) \
126 1.1 is (*(handle) = (tag)->base + ((off)<<(tag)->stride), 0)
127 1.2 is
128 1.2 is #define bus_space_subregion(tag, handle, offset, size, nhandlep) \
129 1.2 is (*(nhandlep) = (handle) + ((offset)<<(tag)->stride), 0)
130 1.1 is
131 1.1 is #define bus_space_unmap(tag,handle,size) (void)0
132 1.1 is
133 1.5 is /*
134 1.5 is * Macro definition of some _1 functions:
135 1.5 is */
136 1.5 is
137 1.1 is #define bus_space_read_1(t, h, o) \
138 1.1 is ((void) t, (*(volatile u_int8_t *)((h) + ((o)<<(t)->stride))))
139 1.1 is
140 1.1 is #define bus_space_write_1(t, h, o, v) \
141 1.1 is ((void) t, ((void)(*(volatile u_int8_t *)((h) + ((o)<<(t)->stride)) = (v))))
142 1.1 is
143 1.5 is /*
144 1.5 is * Inline definition of other _1 functions:
145 1.5 is */
146 1.5 is
147 1.1 is extern __inline__ void
148 1.1 is bus_space_read_multi_1(t, h, o, a, c)
149 1.1 is bus_space_tag_t t;
150 1.1 is bus_space_handle_t h;
151 1.4 is bus_size_t o, c;
152 1.4 is u_int8_t *a;
153 1.1 is {
154 1.1 is for (; c; a++, c--)
155 1.4 is *a = bus_space_read_1(t, h, o);
156 1.1 is }
157 1.1 is
158 1.1 is extern __inline__ void
159 1.1 is bus_space_write_multi_1(t, h, o, a, c)
160 1.1 is bus_space_tag_t t;
161 1.1 is bus_space_handle_t h;
162 1.4 is bus_size_t o, c;
163 1.6 is const u_int8_t *a;
164 1.1 is {
165 1.1 is for (; c; a++, c--)
166 1.4 is bus_space_write_1(t, h, o, *a);
167 1.1 is }
168 1.1 is
169 1.1 is extern __inline__ void
170 1.4 is bus_space_read_region_1(t, h, o, a, c)
171 1.1 is bus_space_tag_t t;
172 1.1 is bus_space_handle_t h;
173 1.4 is bus_size_t o, c;
174 1.4 is u_int8_t *a;
175 1.1 is {
176 1.4 is for (; c; a++, c--)
177 1.4 is *a = bus_space_read_1(t, h, o++);
178 1.1 is }
179 1.1 is
180 1.1 is extern __inline__ void
181 1.4 is bus_space_write_region_1(t, h, o, a, c)
182 1.1 is bus_space_tag_t t;
183 1.1 is bus_space_handle_t h;
184 1.4 is bus_size_t o, c;
185 1.6 is const u_int8_t *a;
186 1.1 is {
187 1.4 is for (; c; a++, c--)
188 1.4 is bus_space_write_1(t, h, o++, *a);
189 1.1 is }
190 1.1 is
191 1.3 is extern __inline__ void
192 1.5 is bus_space_set_region_1(t, h, o, v, c)
193 1.5 is bus_space_tag_t t;
194 1.5 is bus_space_handle_t h;
195 1.5 is bus_size_t o, c;
196 1.5 is u_int8_t v;
197 1.5 is {
198 1.5 is while (c--)
199 1.5 is bus_space_write_1(t, h, o++, v);
200 1.5 is }
201 1.5 is
202 1.5 is extern __inline__ void
203 1.5 is bus_space_copy_region_1(t, srch, srco, dsth, dsto, c)
204 1.5 is bus_space_tag_t t;
205 1.5 is bus_space_handle_t srch, dsth;
206 1.5 is bus_size_t srco, dsto, c;
207 1.5 is {
208 1.5 is u_int8_t v;
209 1.5 is
210 1.5 is while (c--) {
211 1.5 is v = bus_space_read_1(t, srch, srco++);
212 1.5 is bus_space_write_1(t, dsth, dsto++, v);
213 1.5 is }
214 1.5 is }
215 1.5 is
216 1.5 is extern __inline__ void
217 1.7 is bus_space_read_region_stream_1(t, h, o, a, c)
218 1.3 is bus_space_tag_t t;
219 1.3 is bus_space_handle_t h;
220 1.4 is bus_size_t o, c;
221 1.4 is u_int8_t *a;
222 1.3 is {
223 1.3 is for (; c; a++, c--)
224 1.4 is *a = bus_space_read_1(t, h, o++);
225 1.3 is }
226 1.3 is
227 1.3 is extern __inline__ void
228 1.7 is bus_space_write_region_stream_1(t, h, o, a, c)
229 1.3 is bus_space_tag_t t;
230 1.3 is bus_space_handle_t h;
231 1.4 is bus_size_t o, c;
232 1.6 is const u_int8_t *a;
233 1.3 is {
234 1.3 is for (; c; a++, c--)
235 1.4 is bus_space_write_1(t, h, o++, *a);
236 1.3 is }
237 1.5 is
238 1.5 is /*
239 1.5 is * Macro definition of _2 functions as indirect method array calls
240 1.5 is */
241 1.5 is
242 1.5 is #define bus_space_read_2(t, h, o) ((t)->bsr2)((t), (h), (o))
243 1.5 is #define bus_space_write_2(t, h, o, v) ((t)->bsw2)((t), (h), (o), (v))
244 1.5 is
245 1.5 is #define bus_space_read_multi_2(t, h, o, p, c) \
246 1.5 is ((t)->absm->bsrm2)((t), (h), (o), (p), (c))
247 1.5 is
248 1.5 is #define bus_space_write_multi_2(t, h, o, p, c) \
249 1.5 is ((t)->absm->bswm2)((t), (h), (o), (p), (c))
250 1.5 is
251 1.5 is #define bus_space_read_region_2(t, h, o, p, c) \
252 1.5 is ((t)->absm->bsrr2)((t), (h), (o), (p), (c))
253 1.5 is
254 1.5 is #define bus_space_write_region_2(t, h, o, p, c) \
255 1.5 is ((t)->absm->bswr2)((t), (h), (o), (p), (c))
256 1.5 is
257 1.7 is #define bus_space_read_region_stream_2(t, h, o, p, c) \
258 1.7 is ((t)->absm->bsrrs2)((t), (h), (o), (p), (c))
259 1.5 is
260 1.7 is #define bus_space_write_region_stream_2(t, h, o, p, c) \
261 1.7 is ((t)->absm->bswrs2)((t), (h), (o), (p), (c))
262 1.5 is
263 1.5 is #define bus_space_set_region_2(t, h, o, v, c) \
264 1.5 is ((t)->absm->bssr2)((t), (h), (o), (v), (c))
265 1.5 is
266 1.5 is #define bus_space_copy_region_2(t, srch, srco, dsth, dsto, c) \
267 1.5 is ((t)->absm->bscr2)((t), (srch), (srco), (dsth), (dsto), (c))
268 1.5 is
269 1.1 is #endif /* _AMIGA_BUS_H_ */
270