xref: /netbsd/sys/arch/amiga/include/bus.h (revision 8a06b90d)
1 /*	$NetBSD: bus.h,v 1.30 2019/09/23 16:17:54 skrll 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 #define PRIxBUSADDR	"x"
42 #define PRIxBUSSIZE	"x"
43 #define PRIuBUSSIZE	"u"
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 #define PRIxBSH		"lx"
52 
53 /* unpublic, but needed by method implementors */
54 
55 /*
56  * Lazyness macros for function declarations.
57  */
58 
59 #define bsr(what, typ) \
60 	typ (what)(bus_space_handle_t, bus_addr_t)
61 
62 #define bsw(what, typ) \
63 	void (what)(bus_space_handle_t, bus_addr_t, unsigned)
64 
65 #define bsrm(what, typ) \
66 	void (what)(bus_space_handle_t, bus_size_t, typ *, bus_size_t)
67 
68 #define bswm(what, typ) \
69 	void (what)(bus_space_handle_t, bus_size_t, const typ *, bus_size_t)
70 
71 #define bssr(what, typ) \
72 	void (what)(bus_space_handle_t, bus_size_t, unsigned, bus_size_t)
73 
74 #define bscr(what, typ) \
75 	void (what)(bus_space_handle_t, bus_size_t, \
76 		    bus_space_handle_t, bus_size_t, bus_size_t)
77 
78 /*
79  * Implementation specific structures.
80  * XXX Don't use outside of bus_space definitions!
81  * XXX maybe this should be encapsuled in a non-global .h file?
82  */
83 
84 struct bus_space_tag {
85 	bus_addr_t	base;
86 	const struct amiga_bus_space_methods *absm;
87 };
88 
89 struct amiga_bus_space_methods {
90 
91 	/* map, unmap, etc */
92 
93 	int (*bsm)(bus_space_tag_t,
94 		bus_addr_t, bus_size_t, int, bus_space_handle_t *);
95 
96 	int (*bsms)(bus_space_handle_t,
97 		bus_size_t, bus_size_t, bus_space_handle_t *);
98 
99 	void (*bsu)(bus_space_handle_t, bus_size_t);
100 
101 	/* placeholders for currently not implemented alloc and free */
102 
103 	void *bsa;
104 	void *bsf;
105 
106 	/* 8 bit methods */
107 
108 	bsr(*bsr1, u_int8_t);
109 	bsw(*bsw1, u_int8_t);
110 	bsrm(*bsrm1, u_int8_t);
111 	bswm(*bswm1, u_int8_t);
112 	bsrm(*bsrr1, u_int8_t);
113 	bswm(*bswr1, u_int8_t);
114 	bssr(*bssr1, u_int8_t);
115 	bscr(*bscr1, u_int8_t);
116 
117 	/* 16bit methods */
118 
119 	bsr(*bsr2, u_int16_t);
120 	bsw(*bsw2, u_int16_t);
121 	bsr(*bsrs2, u_int16_t);
122 	bsw(*bsws2, u_int16_t);
123 	bsrm(*bsrm2, u_int16_t);
124 	bswm(*bswm2, u_int16_t);
125 	bsrm(*bsrms2, u_int16_t);
126 	bswm(*bswms2, u_int16_t);
127 	bsrm(*bsrr2, u_int16_t);
128 	bswm(*bswr2, u_int16_t);
129 	bsrm(*bsrrs2, u_int16_t);
130 	bswm(*bswrs2, u_int16_t);
131 	bssr(*bssr2, u_int16_t);
132 	bscr(*bscr2, u_int16_t);
133 
134 	/* 32bit methods */
135 
136 	bsr(*bsr4, u_int32_t);
137 	bsw(*bsw4, u_int32_t);
138 	bsr(*bsrs4, u_int32_t);
139 	bsw(*bsws4, u_int32_t);
140 	bsrm(*bsrm4, u_int32_t);
141 	bswm(*bswm4, u_int32_t);
142 	bsrm(*bsrms4, u_int32_t);
143 	bswm(*bswms4, u_int32_t);
144 	bsrm(*bsrr4, u_int32_t);
145 	bswm(*bswr4, u_int32_t);
146 	bsrm(*bsrrs4, u_int32_t);
147 	bswm(*bswrs4, u_int32_t);
148 	bssr(*bssr4, u_int32_t);
149 	bscr(*bscr4, u_int32_t);
150 
151 };
152 
153 /*
154  * Macro definition of map, unmap, etc.
155  */
156 
157 #define bus_space_map(t, o, s, f, hp) \
158 	((t)->absm->bsm)((t), (o), (s), (f), (hp))
159 
160 #define bus_space_subregion(t, h, o, s, hp) \
161 	((t)->absm->bsms)((h), (o), (s), (hp))
162 
163 #define bus_space_unmap(t, h, s) \
164 	((t)->absm->bsu)((h), (s))
165 
166 /*
167  * Macro definition of _2 functions as indirect method array calls
168  */
169 
170 /* 0: Helper macros */
171 
172 #define dbsdr(n, t, h, o)	((t)->absm->n)((h), (o))
173 #define dbsdw(n, t, h, o, v)	((t)->absm->n)((h), (o), (v))
174 #define dbsm(n, t, h, o, p, c)	((t)->absm->n)((h), (o), (p), (c))
175 #define dbss(n, t, h, o, v, c)	((t)->absm->n)((h), (o), (v), (c))
176 #define dbsc(n, t, h, o, v, c)	((t)->absm->n)((h), (o), (v), (c))
177 
178 /* 1: byte-wide "functions" */
179 
180 #define bus_space_read_1(t, h, o)		  dbsdr(bsr1, t, h, o)
181 #define bus_space_write_1(t, h, o, v)		  dbsdw(bsw1, t, h, o, v)
182 
183 #define bus_space_read_multi_1(t, h, o, p, c)	  dbsm(bsrm1, t, h, o, p, c)
184 #define bus_space_write_multi_1(t, h, o, p, c)	  dbsm(bswm1, t, h, o, p, c)
185 
186 #define bus_space_read_region_1(t, h, o, p, c)	  dbsm(bsrr1, t, h, o, p, c)
187 #define bus_space_write_region_1(t, h, o, p, c)	  dbsm(bswr1, t, h, o, p, c)
188 
189 #define bus_space_set_region_1(t, h, o, v, c)	  dbss(bssr1, t, h, o, v, c)
190 #define bus_space_copy_region_1(t, h, o, g, q, c) dbss(bscr1, t, h, o, g, q, c)
191 
192 
193 /* 2: word-wide "functions" */
194 
195 #define bus_space_read_2(t, h, o)		  dbsdr(bsr2, t, h, o)
196 #define bus_space_write_2(t, h, o, v)		  dbsdw(bsw2, t, h, o, v)
197 #define bus_space_read_stream_2(t, h, o)	  dbsdr(bsrs2, t, h, o)
198 #define bus_space_write_stream_2(t, h, o, v)	  dbsdw(bsws2, t, h, o, v)
199 
200 #define bus_space_read_multi_2(t, h, o, p, c)	  dbsm(bsrm2, t, h, o, p, c)
201 #define bus_space_write_multi_2(t, h, o, p, c)	  dbsm(bswm2, t, h, o, p, c)
202 
203 #define bus_space_read_multi_stream_2(t, h, o, p, c) \
204 						  dbsm(bsrms2, t, h, o, p, c)
205 
206 #define bus_space_write_multi_stream_2(t, h, o, p, c) \
207 						  dbsm(bswms2, t, h, o, p, c)
208 
209 #define bus_space_read_region_2(t, h, o, p, c)	  dbsm(bsrr2, t, h, o, p, c)
210 #define bus_space_write_region_2(t, h, o, p, c)	  dbsm(bswr2, t, h, o, p, c)
211 
212 #define bus_space_read_region_stream_2(t, h, o, p, c) \
213 						  dbsm(bsrrs2, t, h, o, p, c)
214 
215 #define bus_space_write_region_stream_2(t, h, o, p, c) \
216 						  dbsm(bswrs2, t, h, o, p, c)
217 
218 #define bus_space_set_region_2(t, h, o, v, c)	  dbss(bssr2, t, h, o, v, c)
219 #define bus_space_copy_region_2(t, h, o, g, q, c) dbss(bscr2, t, h, o, g, q, c)
220 
221 /* 4: long-wide "functions" */
222 
223 #define bus_space_read_4(t, h, o)                 dbsdr(bsr4, t, h, o)
224 #define bus_space_write_4(t, h, o, v)             dbsdw(bsw4, t, h, o, v)
225 #define bus_space_read_stream_4(t, h, o)          dbsdr(bsrs4, t, h, o)
226 #define bus_space_write_stream_4(t, h, o, v)      dbsdw(bsws4, t, h, o, v)
227 
228 #define bus_space_read_multi_4(t, h, o, p, c)     dbsm(bsrm4, t, h, o, p, c)
229 #define bus_space_write_multi_4(t, h, o, p, c)    dbsm(bswm4, t, h, o, p, c)
230 
231 #define bus_space_read_multi_stream_4(t, h, o, p, c) \
232                                                   dbsm(bsrms4, t, h, o, p, c)
233 
234 #define bus_space_write_multi_stream_4(t, h, o, p, c) \
235                                                   dbsm(bswms4, t, h, o, p, c)
236 
237 #define bus_space_read_region_4(t, h, o, p, c)    dbsm(bsrr4, t, h, o, p, c)
238 #define bus_space_write_region_4(t, h, o, p, c)   dbsm(bswr4, t, h, o, p, c)
239 
240 #define bus_space_read_region_stream_4(t, h, o, p, c) \
241                                                   dbsm(bsrrs4, t, h, o, p, c)
242 
243 #define bus_space_write_region_stream_4(t, h, o, p, c) \
244                                                   dbsm(bswrs4, t, h, o, p, c)
245 
246 #define bus_space_set_region_4(t, h, o, v, c)     dbss(bssr4, t, h, o, v, c)
247 #define bus_space_copy_region_4(t, h, o, g, q, c) dbss(bscr4, t, h, o, g, q, c)
248 
249 /*
250  * Bus read/write barrier methods.
251  *
252  *      void bus_space_barrier(bus_space_tag_t tag,
253  *          bus_space_handle_t bsh, bus_size_t offset,
254  *          bus_size_t len, int flags);
255  *
256  * Note: the 680x0 does not currently require barriers, but we must
257  * provide the flags to MI code.
258  */
259 void bus_space_barrier(bus_space_tag_t space, bus_space_handle_t handle,
260 			bus_size_t offset, bus_size_t length, int flags);
261 
262 #define BUS_SPACE_BARRIER_READ  0x01            /* force read barrier */
263 #define BUS_SPACE_BARRIER_WRITE 0x02            /* force write barrier */
264 
265 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
266 
267 #define __BUS_SPACE_HAS_STREAM_METHODS
268 
269 paddr_t bus_space_mmap(bus_space_tag_t t, bus_addr_t addr, off_t off, int prot,
270 			int flags);
271 
272 #define BUS_SPACE_MAP_CACHEABLE		0x01
273 #define BUS_SPACE_MAP_LINEAR		0x02
274 #define BUS_SPACE_MAP_PREFETCHABLE	0x04
275 
276 /* Instruction for enforcing reorder protection. Nothing for 68k. */
277 #define amiga_bus_reorder_protect()
278 
279 void * bus_space_vaddr(bus_space_tag_t space, bus_space_handle_t handle);
280 
281 extern const struct amiga_bus_space_methods amiga_bus_stride_1;
282 extern const struct amiga_bus_space_methods amiga_bus_stride_1swap;
283 extern const struct amiga_bus_space_methods amiga_bus_stride_1swap_abs;
284 extern const struct amiga_bus_space_methods amiga_bus_stride_2;
285 extern const struct amiga_bus_space_methods amiga_bus_stride_4;
286 extern const struct amiga_bus_space_methods amiga_bus_stride_4swap;
287 extern const struct amiga_bus_space_methods amiga_bus_stride_16;
288 extern const struct amiga_bus_space_methods amiga_bus_stride_0x1000;
289 extern const struct amiga_bus_space_methods amiga_bus_stride_0x4000;
290 extern const struct amiga_bus_space_methods empb_bus_swap;
291 
292 /*
293  * XXX
294  * amiga doesn't have actual bus_dma(9) implementation for PCI devices yet.
295  */
296 #include <m68k/bus_dma.h>
297 
298 #endif /* _AMIGA_BUS_H_ */
299 
300