xref: /netbsd-src/sys/arch/atari/include/bus_funcs.h (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1 /*	$NetBSD: bus_funcs.h,v 1.1 2011/07/01 17:09:58 dyoung Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * Copyright (c) 1996 Carnegie-Mellon University.
35  * All rights reserved.
36  *
37  * Author: Chris G. Demetriou
38  *
39  * Permission to use, copy, modify and distribute this software and
40  * its documentation is hereby granted, provided that both the copyright
41  * notice and this permission notice appear in all copies of the
42  * software, derivative works or modified versions, and any portions
43  * thereof, and that both notices appear in supporting documentation.
44  *
45  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48  *
49  * Carnegie Mellon requests users of this software to return to
50  *
51  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
52  *  School of Computer Science
53  *  Carnegie Mellon University
54  *  Pittsburgh PA 15213-3890
55  *
56  * any improvements or extensions that they make and grant Carnegie the
57  * rights to redistribute these changes.
58  */
59 
60 #ifndef _ATARI_BUS_FUNCS_H_
61 #define _ATARI_BUS_FUNCS_H_
62 
63 int	bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t, bus_size_t,
64 	    bus_size_t, bus_size_t, int, bus_addr_t *, bus_space_handle_t *);
65 int	bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int,
66 	    bus_space_handle_t *);
67 void	bus_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t);
68 int	bus_space_subregion(bus_space_tag_t, bus_space_handle_t, bus_size_t,
69 	    bus_size_t, bus_space_handle_t *);
70 
71 /*
72  * Tag allocation
73  */
74 bus_space_tag_t		beb_alloc_bus_space_tag(bus_space_tag_t);
75 bus_space_tag_t		leb_alloc_bus_space_tag(bus_space_tag_t);
76 
77 /*
78  * XXX
79  */
80 bus_space_tag_t	mb_alloc_bus_space_tag(void);
81 void		mb_free_bus_space_tag(bus_space_tag_t);
82 
83 /*
84  * Utility macros; INTERNAL USE ONLY.
85  */
86 #define	__abs_c(a,b)		__CONCAT(a,b)
87 #define	__abs_opname(op,size)	__abs_c(__abs_c(__abs_c(abs_,op),_),size)
88 
89 #define	__abs_p(sz, t, h, o)						\
90 	(*(t)->__abs_opname(p,sz))(t, h, o)
91 #define	__abs_rs(sz, t, h, o)						\
92 	(*(t)->__abs_opname(r,sz))(t, h, o)
93 #define	__abs_rss(sz, t, h, o)						\
94 	(*(t)->__abs_opname(rs,sz))(t, h, o)
95 #define	__abs_ws(sz, t, h, o, v)					\
96 	(*(t)->__abs_opname(w,sz))(t, h, o, v)
97 #define	__abs_wss(sz, t, h, o, v)					\
98 	(*(t)->__abs_opname(ws,sz))(t, h, o, v)
99 #define	__abs_nonsingle(type, sz, t, h, o, a, c)			\
100 	(*(t)->__abs_opname(type,sz))(t, h, o, a, c)
101 #define	__abs_set(type, sz, t, h, o, v, c)				\
102 	(*(t)->__abs_opname(type,sz))(t, h, o, v, c)
103 
104     /*
105      * No swaps needed and no other trickery, so it should be possible
106      * to shortcut these to memcpy() directly [ leo 19990107 ]
107      */
108 #if 0
109     #define	__abs_copy(sz, t, h1, o1, h2, o2, cnt)			\
110 	(*(t)->__abs_opname(c,sz))(t, h1, o1, h2, o2, cnt)
111 #else
112     #define	__abs_copy(sz, t, h1, o1, h2, o2, cnt) do {		\
113 		    memcpy((void*)(h2 + o2), (void *)(h1 + o1), sz * cnt);  \
114 		    (void)t;						    \
115 		} while (0)
116 #endif
117 
118 
119 /*
120  * Check accesibility of the location for various sized bus accesses
121  */
122 #define bus_space_peek_1(t, h, o)	__abs_p(1,(t),(h),(o))
123 #define bus_space_peek_2(t, h, o)	__abs_p(2,(t),(h),(o))
124 #define bus_space_peek_4(t, h, o)	__abs_p(4,(t),(h),(o))
125 #define bus_space_peek_8(t, h, o)	__abs_p(8,(t),(h),(o))
126 
127 /*
128  * Bus read (single) operations.
129  */
130 #define	bus_space_read_1(t, h, o)	__abs_rs(1,(t),(h),(o))
131 #define	bus_space_read_2(t, h, o)	__abs_rs(2,(t),(h),(o))
132 #define	bus_space_read_4(t, h, o)	__abs_rs(4,(t),(h),(o))
133 #define	bus_space_read_8(t, h, o)	__abs_rs(8,(t),(h),(o))
134 
135 /*
136  * Bus read (single) stream operations.
137  */
138 #define	bus_space_read_stream_1(t, h, o)	__abs_rss(1,(t),(h),(o))
139 #define	bus_space_read_stream_2(t, h, o)	__abs_rss(2,(t),(h),(o))
140 #define	bus_space_read_stream_4(t, h, o)	__abs_rss(4,(t),(h),(o))
141 #define	bus_space_read_stream_8(t, h, o)	__abs_rss(8,(t),(h),(o))
142 
143 /*
144  * Bus read multiple operations.
145  */
146 #define	bus_space_read_multi_1(t, h, o, a, c)				\
147 	__abs_nonsingle(rm,1,(t),(h),(o),(a),(c))
148 #define	bus_space_read_multi_2(t, h, o, a, c)				\
149 	__abs_nonsingle(rm,2,(t),(h),(o),(a),(c))
150 #define	bus_space_read_multi_4(t, h, o, a, c)				\
151 	__abs_nonsingle(rm,4,(t),(h),(o),(a),(c))
152 #define	bus_space_read_multi_8(t, h, o, a, c)				\
153 	__abs_nonsingle(rm,8,(t),(h),(o),(a),(c))
154 
155 /*
156  * Bus read multiple stream operations.
157  */
158 #define	bus_space_read_multi_stream_1(t, h, o, a, c)			\
159 	__abs_nonsingle(rms,1,(t),(h),(o),(a),(c))
160 #define	bus_space_read_multi_stream_2(t, h, o, a, c)			\
161 	__abs_nonsingle(rms,2,(t),(h),(o),(a),(c))
162 #define	bus_space_read_multi_stream_4(t, h, o, a, c)			\
163 	__abs_nonsingle(rms,4,(t),(h),(o),(a),(c))
164 #define	bus_space_read_multi_stream_8(t, h, o, a, c)			\
165 	__abs_nonsingle(rms,8,(t),(h),(o),(a),(c))
166 
167 
168 /*
169  * Bus read region operations.
170  */
171 #define	bus_space_read_region_1(t, h, o, a, c)				\
172 	__abs_nonsingle(rr,1,(t),(h),(o),(a),(c))
173 #define	bus_space_read_region_2(t, h, o, a, c)				\
174 	__abs_nonsingle(rr,2,(t),(h),(o),(a),(c))
175 #define	bus_space_read_region_4(t, h, o, a, c)				\
176 	__abs_nonsingle(rr,4,(t),(h),(o),(a),(c))
177 #define	bus_space_read_region_8(t, h, o, a, c)				\
178 	__abs_nonsingle(rr,8,(t),(h),(o),(a),(c))
179 
180 /*
181  * Bus read region stream operations.
182  */
183 #define	bus_space_read_region_stream_1(t, h, o, a, c)			\
184 	__abs_nonsingle(rrs,1,(t),(h),(o),(a),(c))
185 #define	bus_space_read_region_stream_2(t, h, o, a, c)			\
186 	__abs_nonsingle(rrs,2,(t),(h),(o),(a),(c))
187 #define	bus_space_read_region_stream_4(t, h, o, a, c)			\
188 	__abs_nonsingle(rrs,4,(t),(h),(o),(a),(c))
189 #define	bus_space_read_region_stream_8(t, h, o, a, c)			\
190 	__abs_nonsingle(rrs,8,(t),(h),(o),(a),(c))
191 
192 /*
193  * Bus write (single) operations.
194  */
195 #define	bus_space_write_1(t, h, o, v)	__abs_ws(1,(t),(h),(o),(v))
196 #define	bus_space_write_2(t, h, o, v)	__abs_ws(2,(t),(h),(o),(v))
197 #define	bus_space_write_4(t, h, o, v)	__abs_ws(4,(t),(h),(o),(v))
198 #define	bus_space_write_8(t, h, o, v)	__abs_ws(8,(t),(h),(o),(v))
199 
200 /*
201  * Bus write (single) stream operations.
202  */
203 #define	bus_space_write_stream_1(t, h, o, v)	__abs_wss(1,(t),(h),(o),(v))
204 #define	bus_space_write_stream_2(t, h, o, v)	__abs_wss(2,(t),(h),(o),(v))
205 #define	bus_space_write_stream_4(t, h, o, v)	__abs_wss(4,(t),(h),(o),(v))
206 #define	bus_space_write_stream_8(t, h, o, v)	__abs_wss(8,(t),(h),(o),(v))
207 
208 
209 /*
210  * Bus write multiple operations.
211  */
212 #define	bus_space_write_multi_1(t, h, o, a, c)				\
213 	__abs_nonsingle(wm,1,(t),(h),(o),(a),(c))
214 #define	bus_space_write_multi_2(t, h, o, a, c)				\
215 	__abs_nonsingle(wm,2,(t),(h),(o),(a),(c))
216 #define	bus_space_write_multi_4(t, h, o, a, c)				\
217 	__abs_nonsingle(wm,4,(t),(h),(o),(a),(c))
218 #define	bus_space_write_multi_8(t, h, o, a, c)				\
219 	__abs_nonsingle(wm,8,(t),(h),(o),(a),(c))
220 
221 /*
222  * Bus write multiple stream operations.
223  */
224 #define	bus_space_write_multi_stream_1(t, h, o, a, c)			\
225 	__abs_nonsingle(wms,1,(t),(h),(o),(a),(c))
226 #define	bus_space_write_multi_stream_2(t, h, o, a, c)			\
227 	__abs_nonsingle(wms,2,(t),(h),(o),(a),(c))
228 #define	bus_space_write_multi_stream_4(t, h, o, a, c)			\
229 	__abs_nonsingle(wms,4,(t),(h),(o),(a),(c))
230 #define	bus_space_write_multi_stream_8(t, h, o, a, c)			\
231 	__abs_nonsingle(wms,8,(t),(h),(o),(a),(c))
232 
233 
234 /*
235  * Bus write region operations.
236  */
237 #define	bus_space_write_region_1(t, h, o, a, c)				\
238 	__abs_nonsingle(wr,1,(t),(h),(o),(a),(c))
239 #define	bus_space_write_region_2(t, h, o, a, c)				\
240 	__abs_nonsingle(wr,2,(t),(h),(o),(a),(c))
241 #define	bus_space_write_region_4(t, h, o, a, c)				\
242 	__abs_nonsingle(wr,4,(t),(h),(o),(a),(c))
243 #define	bus_space_write_region_8(t, h, o, a, c)				\
244 	__abs_nonsingle(wr,8,(t),(h),(o),(a),(c))
245 
246 /*
247  * Bus write region stream operations.
248  */
249 #define	bus_space_write_region_stream_1(t, h, o, a, c)			\
250 	__abs_nonsingle(wrs,1,(t),(h),(o),(a),(c))
251 #define	bus_space_write_region_stream_2(t, h, o, a, c)			\
252 	__abs_nonsingle(wrs,2,(t),(h),(o),(a),(c))
253 #define	bus_space_write_region_stream_4(t, h, o, a, c)			\
254 	__abs_nonsingle(wrs,4,(t),(h),(o),(a),(c))
255 #define	bus_space_write_region_stream_8(t, h, o, a, c)			\
256 	__abs_nonsingle(wrs,8,(t),(h),(o),(a),(c))
257 
258 
259 /*
260  * Set multiple operations.
261  */
262 #define	bus_space_set_multi_1(t, h, o, v, c)				\
263 	__abs_set(sm,1,(t),(h),(o),(v),(c))
264 #define	bus_space_set_multi_2(t, h, o, v, c)				\
265 	__abs_set(sm,2,(t),(h),(o),(v),(c))
266 #define	bus_space_set_multi_4(t, h, o, v, c)				\
267 	__abs_set(sm,4,(t),(h),(o),(v),(c))
268 #define	bus_space_set_multi_8(t, h, o, v, c)				\
269 	__abs_set(sm,8,(t),(h),(o),(v),(c))
270 
271 
272 /*
273  * Set region operations.
274  */
275 #define	bus_space_set_region_1(t, h, o, v, c)				\
276 	__abs_set(sr,1,(t),(h),(o),(v),(c))
277 #define	bus_space_set_region_2(t, h, o, v, c)				\
278 	__abs_set(sr,2,(t),(h),(o),(v),(c))
279 #define	bus_space_set_region_4(t, h, o, v, c)				\
280 	__abs_set(sr,4,(t),(h),(o),(v),(c))
281 #define	bus_space_set_region_8(t, h, o, v, c)				\
282 	__abs_set(sr,8,(t),(h),(o),(v),(c))
283 
284 
285 /*
286  * Copy region operations.
287  */
288 #define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)			\
289 	__abs_copy(1, (t), (h1), (o1), (h2), (o2), (c))
290 #define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)			\
291 	__abs_copy(2, (t), (h1), (o1), (h2), (o2), (c))
292 #define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)			\
293 	__abs_copy(4, (t), (h1), (o1), (h2), (o2), (c))
294 #define	bus_space_copy_region_8(t, h1, o1, h2, o2, c)			\
295 	__abs_copy(8, (t), (h1), (o1), (h2), (o2), (c))
296 
297 /*
298  *	void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
299  *
300  * Get the kernel virtual address for the mapped bus space.
301  * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
302  *  (XXX not enforced)
303  */
304 #define bus_space_vaddr(t, h)	((void)(t), (void *)(h))
305 
306 /*
307  *	paddr_t bus_space_mmap(bus_space_tag_t t, bus_addr_t base,
308  *	    off_t offset, int prot, int flags);
309  *
310  * Mmap an area of bus space.
311  */
312 
313 paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t,
314 	    int, int);
315 
316 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
317 
318 /*
319  * Bus read/write barrier methods.
320  *
321  *	void bus_space_barrier(bus_space_tag_t tag,
322  *	    bus_space_handle_t bsh, bus_size_t offset,
323  *	    bus_size_t len, int flags);
324  *
325  * Note: the Atari does not currently require barriers, but we must
326  * provide the flags to MI code.
327  */
328 #define	bus_space_barrier(t, h, o, l, f)	\
329 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
330 
331 /* Forwards needed by prototypes below. */
332 struct mbuf;
333 struct uio;
334 
335 #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
336 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
337 #define	bus_dmamap_destroy(t, p)				\
338 	(*(t)->_dmamap_destroy)((t), (p))
339 #define	bus_dmamap_load(t, m, b, s, p, f)			\
340 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
341 #define	bus_dmamap_load_mbuf(t, m, b, f)			\
342 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
343 #define	bus_dmamap_load_uio(t, m, u, f)				\
344 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
345 #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
346 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
347 #define	bus_dmamap_unload(t, p)					\
348 	(*(t)->_dmamap_unload)((t), (p))
349 #define	bus_dmamap_sync(t, p, o, l, ops)			\
350 	(void)((t)->_dmamap_sync ?				\
351 	    (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) : (void)0)
352 
353 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
354 #define bus_dmatag_destroy(t)
355 
356 #ifdef _ATARI_BUS_DMA_PRIVATE
357 int	_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
358 	    bus_size_t, int, bus_dmamap_t *);
359 void	_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
360 int	_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
361 	    bus_size_t, struct proc *, int);
362 int	_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int);
363 int	_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int);
364 int	_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
365 	    bus_dma_segment_t *, int, bus_size_t, int);
366 void	_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
367 void	_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
368 	    bus_size_t, int);
369 #endif /* _ATARI_BUS_DMA_PRIVATE */
370 
371 int	bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
372 	    bus_size_t alignment, bus_size_t boundary,
373 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
374 int	bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
375 	    bus_size_t alignment, bus_size_t boundary,
376 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
377 	    paddr_t low, paddr_t high);
378 void	bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs);
379 int	bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
380 	    int nsegs, size_t size, void **kvap, int flags);
381 void	bus_dmamem_unmap(bus_dma_tag_t tag, void *kva, size_t size);
382 paddr_t	bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
383 	    int nsegs, off_t off, int prot, int flags);
384 
385 #endif /* _ATARI_BUS_FUNCS_H_ */
386