bus.h revision 1.4 1 /* $NetBSD: bus.h,v 1.4 1998/10/08 21:46:39 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 * Memory addresses (in bus space)
39 */
40 typedef u_int32_t bus_addr_t;
41 typedef u_int32_t bus_size_t;
42
43 /*
44 * Access methods for bus resources and address space.
45 */
46 typedef struct bus_space_tag *bus_space_tag_t;
47 typedef u_long bus_space_handle_t;
48
49 #define bsr(what, typ) \
50 typ (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t)
51
52 #define bsw(what, typ) \
53 void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, typ)
54
55 #define bsrm(what, typ) \
56 void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
57 typ *, bus_size_t)
58
59 #define bswm(what, typ) \
60 void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
61 typ *, bus_size_t)
62
63 struct amiga_bus_space_methods {
64 /* 16bit methods */
65 bsr(*bsr2, u_int16_t);
66 bsw(*bsw2, u_int16_t);
67 bsrm(*bsrm2, u_int16_t);
68 bswm(*bswm2, u_int16_t);
69 bsrm(*bsrr2, u_int16_t);
70 bswm(*bswr2, u_int16_t);
71 bsrm(*bsrs2, u_int16_t);
72 bswm(*bsws2, u_int16_t);
73 };
74
75 struct bus_space_tag {
76 bus_addr_t base;
77 u_int8_t stride;
78 u_int8_t dum[3];
79 struct amiga_bus_space_methods *absm;
80 };
81
82 #define bus_space_read_2(t, h, o) ((t)->bsr2)((t), (h), (o))
83 #define bus_space_write_2(t, h, o, v) ((t)->bsw2)((t), (h), (o), (v))
84
85 #define bus_space_read_multi_2(t, h, o, p, c) \
86 ((t)->absm->bsrm2)((t), (h), (o), (p), (c))
87
88 #define bus_space_write_multi_2(t, h, o, p, c) \
89 ((t)->absm->bswm2)((t), (h), (o), (p), (c))
90
91 #define bus_space_read_region_2(t, h, o, p, c) \
92 ((t)->absm->bsrr2)((t), (h), (o), (p), (c))
93
94 #define bus_space_write_region_2(t, h, o, p, c) \
95 ((t)->absm->bswr2)((t), (h), (o), (p), (c))
96
97 #define bus_space_read_stream_2(t, h, o, p, c) \
98 ((t)->absm->bsrs2)((t), (h), (o), (p), (c))
99
100 #define bus_space_write_stream_2(t, h, o, p, c) \
101 ((t)->absm->bsws2)((t), (h), (o), (p), (c))
102
103
104 void bus_space_read_multi_1 __P((bus_space_tag_t, bus_space_handle_t,
105 bus_size_t, u_int8_t *, bus_size_t));
106 void bus_space_write_multi_1 __P((bus_space_tag_t, bus_space_handle_t,
107 bus_size_t, u_int8_t *, bus_size_t));
108
109 void bus_space_read_region_1 __P((bus_space_tag_t, bus_space_handle_t,
110 bus_size_t, u_int8_t *, bus_size_t));
111 void bus_space_write_region_1 __P((bus_space_tag_t, bus_space_handle_t,
112 bus_size_t, u_int8_t *, bus_size_t));
113
114 void bus_space_read_stream_1 __P((bus_space_tag_t, bus_space_handle_t,
115 bus_size_t, u_int8_t *, bus_size_t));
116 void bus_space_write_stream_1 __P((bus_space_tag_t, bus_space_handle_t,
117 bus_size_t, u_int8_t *, bus_size_t));
118
119 #define bus_space_map(tag,off,size,cache,handle) \
120 (*(handle) = (tag)->base + ((off)<<(tag)->stride), 0)
121
122 #define bus_space_subregion(tag, handle, offset, size, nhandlep) \
123 (*(nhandlep) = (handle) + ((offset)<<(tag)->stride), 0)
124
125 #define bus_space_unmap(tag,handle,size) (void)0
126
127 #define bus_space_read_1(t, h, o) \
128 ((void) t, (*(volatile u_int8_t *)((h) + ((o)<<(t)->stride))))
129
130 #define bus_space_write_1(t, h, o, v) \
131 ((void) t, ((void)(*(volatile u_int8_t *)((h) + ((o)<<(t)->stride)) = (v))))
132
133 extern __inline__ void
134 bus_space_read_multi_1(t, h, o, a, c)
135 bus_space_tag_t t;
136 bus_space_handle_t h;
137 bus_size_t o, c;
138 u_int8_t *a;
139 {
140 for (; c; a++, c--)
141 *a = bus_space_read_1(t, h, o);
142 }
143
144 extern __inline__ void
145 bus_space_write_multi_1(t, h, o, a, c)
146 bus_space_tag_t t;
147 bus_space_handle_t h;
148 bus_size_t o, c;
149 u_int8_t *a;
150 {
151 for (; c; a++, c--)
152 bus_space_write_1(t, h, o, *a);
153 }
154
155 extern __inline__ void
156 bus_space_read_region_1(t, h, o, a, c)
157 bus_space_tag_t t;
158 bus_space_handle_t h;
159 bus_size_t o, c;
160 u_int8_t *a;
161 {
162 for (; c; a++, c--)
163 *a = bus_space_read_1(t, h, o++);
164 }
165
166 extern __inline__ void
167 bus_space_write_region_1(t, h, o, a, c)
168 bus_space_tag_t t;
169 bus_space_handle_t h;
170 bus_size_t o, c;
171 u_int8_t *a;
172 {
173 for (; c; a++, c--)
174 bus_space_write_1(t, h, o++, *a);
175 }
176
177 extern __inline__ void
178 bus_space_read_stream_1(t, h, o, a, c)
179 bus_space_tag_t t;
180 bus_space_handle_t h;
181 bus_size_t o, c;
182 u_int8_t *a;
183 {
184 for (; c; a++, c--)
185 *a = bus_space_read_1(t, h, o++);
186 }
187
188 extern __inline__ void
189 bus_space_write_stream_1(t, h, o, a, c)
190 bus_space_tag_t t;
191 bus_space_handle_t h;
192 bus_size_t o, c;
193 u_int8_t *a;
194 {
195 for (; c; a++, c--)
196 bus_space_write_1(t, h, o++, *a);
197 }
198 #endif /* _AMIGA_BUS_H_ */
199