xref: /netbsd-src/sys/arch/amiga/include/bus.h (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /*	$NetBSD: bus.h,v 1.29 2014/01/03 00:33:06 rkujawa 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 	/* 32bit methods */
129 
130 	bsr(*bsr4, u_int32_t);
131 	bsw(*bsw4, u_int32_t);
132 	bsr(*bsrs4, u_int32_t);
133 	bsw(*bsws4, u_int32_t);
134 	bsrm(*bsrm4, u_int32_t);
135 	bswm(*bswm4, u_int32_t);
136 	bsrm(*bsrms4, u_int32_t);
137 	bswm(*bswms4, u_int32_t);
138 	bsrm(*bsrr4, u_int32_t);
139 	bswm(*bswr4, u_int32_t);
140 	bsrm(*bsrrs4, u_int32_t);
141 	bswm(*bswrs4, u_int32_t);
142 	bssr(*bssr4, u_int32_t);
143 	bscr(*bscr4, u_int32_t);
144 
145 };
146 
147 /*
148  * Macro definition of map, unmap, etc.
149  */
150 
151 #define bus_space_map(t, o, s, f, hp) \
152 	((t)->absm->bsm)((t), (o), (s), (f), (hp))
153 
154 #define bus_space_subregion(t, h, o, s, hp) \
155 	((t)->absm->bsms)((h), (o), (s), (hp))
156 
157 #define bus_space_unmap(t, h, s) \
158 	((t)->absm->bsu)((h), (s))
159 
160 /*
161  * Macro definition of _2 functions as indirect method array calls
162  */
163 
164 /* 0: Helper macros */
165 
166 #define dbsdr(n, t, h, o)	((t)->absm->n)((h), (o))
167 #define dbsdw(n, t, h, o, v)	((t)->absm->n)((h), (o), (v))
168 #define dbsm(n, t, h, o, p, c)	((t)->absm->n)((h), (o), (p), (c))
169 #define dbss(n, t, h, o, v, c)	((t)->absm->n)((h), (o), (v), (c))
170 #define dbsc(n, t, h, o, v, c)	((t)->absm->n)((h), (o), (v), (c))
171 
172 /* 1: byte-wide "functions" */
173 
174 #define bus_space_read_1(t, h, o)		  dbsdr(bsr1, t, h, o)
175 #define bus_space_write_1(t, h, o, v)		  dbsdw(bsw1, t, h, o, v)
176 
177 #define bus_space_read_multi_1(t, h, o, p, c)	  dbsm(bsrm1, t, h, o, p, c)
178 #define bus_space_write_multi_1(t, h, o, p, c)	  dbsm(bswm1, t, h, o, p, c)
179 
180 #define bus_space_read_region_1(t, h, o, p, c)	  dbsm(bsrr1, t, h, o, p, c)
181 #define bus_space_write_region_1(t, h, o, p, c)	  dbsm(bswr1, t, h, o, p, c)
182 
183 #define bus_space_set_region_1(t, h, o, v, c)	  dbss(bssr1, t, h, o, v, c)
184 #define bus_space_copy_region_1(t, h, o, g, q, c) dbss(bscr1, t, h, o, g, q, c)
185 
186 
187 /* 2: word-wide "functions" */
188 
189 #define bus_space_read_2(t, h, o)		  dbsdr(bsr2, t, h, o)
190 #define bus_space_write_2(t, h, o, v)		  dbsdw(bsw2, t, h, o, v)
191 #define bus_space_read_stream_2(t, h, o)	  dbsdr(bsrs2, t, h, o)
192 #define bus_space_write_stream_2(t, h, o, v)	  dbsdw(bsws2, t, h, o, v)
193 
194 #define bus_space_read_multi_2(t, h, o, p, c)	  dbsm(bsrm2, t, h, o, p, c)
195 #define bus_space_write_multi_2(t, h, o, p, c)	  dbsm(bswm2, t, h, o, p, c)
196 
197 #define bus_space_read_multi_stream_2(t, h, o, p, c) \
198 						  dbsm(bsrms2, t, h, o, p, c)
199 
200 #define bus_space_write_multi_stream_2(t, h, o, p, c) \
201 						  dbsm(bswms2, t, h, o, p, c)
202 
203 #define bus_space_read_region_2(t, h, o, p, c)	  dbsm(bsrr2, t, h, o, p, c)
204 #define bus_space_write_region_2(t, h, o, p, c)	  dbsm(bswr2, t, h, o, p, c)
205 
206 #define bus_space_read_region_stream_2(t, h, o, p, c) \
207 						  dbsm(bsrrs2, t, h, o, p, c)
208 
209 #define bus_space_write_region_stream_2(t, h, o, p, c) \
210 						  dbsm(bswrs2, t, h, o, p, c)
211 
212 #define bus_space_set_region_2(t, h, o, v, c)	  dbss(bssr2, t, h, o, v, c)
213 #define bus_space_copy_region_2(t, h, o, g, q, c) dbss(bscr2, t, h, o, g, q, c)
214 
215 /* 4: long-wide "functions" */
216 
217 #define bus_space_read_4(t, h, o)                 dbsdr(bsr4, t, h, o)
218 #define bus_space_write_4(t, h, o, v)             dbsdw(bsw4, t, h, o, v)
219 #define bus_space_read_stream_4(t, h, o)          dbsdr(bsrs4, t, h, o)
220 #define bus_space_write_stream_4(t, h, o, v)      dbsdw(bsws4, t, h, o, v)
221 
222 #define bus_space_read_multi_4(t, h, o, p, c)     dbsm(bsrm4, t, h, o, p, c)
223 #define bus_space_write_multi_4(t, h, o, p, c)    dbsm(bswm4, t, h, o, p, c)
224 
225 #define bus_space_read_multi_stream_4(t, h, o, p, c) \
226                                                   dbsm(bsrms4, t, h, o, p, c)
227 
228 #define bus_space_write_multi_stream_4(t, h, o, p, c) \
229                                                   dbsm(bswms4, t, h, o, p, c)
230 
231 #define bus_space_read_region_4(t, h, o, p, c)    dbsm(bsrr4, t, h, o, p, c)
232 #define bus_space_write_region_4(t, h, o, p, c)   dbsm(bswr4, t, h, o, p, c)
233 
234 #define bus_space_read_region_stream_4(t, h, o, p, c) \
235                                                   dbsm(bsrrs4, t, h, o, p, c)
236 
237 #define bus_space_write_region_stream_4(t, h, o, p, c) \
238                                                   dbsm(bswrs4, t, h, o, p, c)
239 
240 #define bus_space_set_region_4(t, h, o, v, c)     dbss(bssr4, t, h, o, v, c)
241 #define bus_space_copy_region_4(t, h, o, g, q, c) dbss(bscr4, t, h, o, g, q, c)
242 
243 /*
244  * Bus read/write barrier methods.
245  *
246  *      void bus_space_barrier(bus_space_tag_t tag,
247  *          bus_space_handle_t bsh, bus_size_t offset,
248  *          bus_size_t len, int flags);
249  *
250  * Note: the 680x0 does not currently require barriers, but we must
251  * provide the flags to MI code.
252  */
253 void bus_space_barrier(bus_space_tag_t space, bus_space_handle_t handle,
254 			bus_size_t offset, bus_size_t length, int flags);
255 
256 #define BUS_SPACE_BARRIER_READ  0x01            /* force read barrier */
257 #define BUS_SPACE_BARRIER_WRITE 0x02            /* force write barrier */
258 
259 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
260 
261 #define __BUS_SPACE_HAS_STREAM_METHODS
262 
263 paddr_t bus_space_mmap(bus_space_tag_t t, bus_addr_t addr, off_t off, int prot,
264 			int flags);
265 
266 #define BUS_SPACE_MAP_CACHEABLE		0x01
267 #define BUS_SPACE_MAP_LINEAR		0x02
268 #define BUS_SPACE_MAP_PREFETCHABLE	0x04
269 
270 /* Instruction for enforcing reorder protection. Nothing for 68k. */
271 #define amiga_bus_reorder_protect()
272 
273 void * bus_space_vaddr(bus_space_tag_t space, bus_space_handle_t handle);
274 
275 extern const struct amiga_bus_space_methods amiga_bus_stride_1;
276 extern const struct amiga_bus_space_methods amiga_bus_stride_1swap;
277 extern const struct amiga_bus_space_methods amiga_bus_stride_1swap_abs;
278 extern const struct amiga_bus_space_methods amiga_bus_stride_2;
279 extern const struct amiga_bus_space_methods amiga_bus_stride_4;
280 extern const struct amiga_bus_space_methods amiga_bus_stride_4swap;
281 extern const struct amiga_bus_space_methods amiga_bus_stride_16;
282 extern const struct amiga_bus_space_methods amiga_bus_stride_0x1000;
283 extern const struct amiga_bus_space_methods amiga_bus_stride_0x4000;
284 extern const struct amiga_bus_space_methods empb_bus_swap;
285 
286 /*
287  * XXX
288  * amiga doesn't have actual bus_dma(9) implementation for PCI devices yet.
289  */
290 #include <m68k/bus_dma.h>
291 
292 #endif /* _AMIGA_BUS_H_ */
293 
294