xref: /netbsd-src/sys/arch/atari/include/bus_funcs.h (revision d16b7486a53dcb8072b60ec6fcb4373a2d0c27b7)
1 /*	$NetBSD: bus_funcs.h,v 1.2 2022/07/03 16:03:08 tsutsui 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 /* machine dependent utility functions */
64 void bootm_init(vaddr_t, void *, vsize_t);
65 void atari_bus_space_extent_init(paddr_t, paddr_t);
66 int atari_bus_space_alloc_physmem(paddr_t, paddr_t);
67 void atari_bus_space_malloc_set_safe(void);
68 int atari_bus_space_extent_malloc_flag(void);
69 
70 /* functions for machine independent bus_space(9) API */
71 int	bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t, bus_size_t,
72 	    bus_size_t, bus_size_t, int, bus_addr_t *, bus_space_handle_t *);
73 int	bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int,
74 	    bus_space_handle_t *);
75 void	bus_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t);
76 int	bus_space_subregion(bus_space_tag_t, bus_space_handle_t, bus_size_t,
77 	    bus_size_t, bus_space_handle_t *);
78 
79 /*
80  * Tag allocation
81  */
82 bus_space_tag_t		beb_alloc_bus_space_tag(bus_space_tag_t);
83 bus_space_tag_t		leb_alloc_bus_space_tag(bus_space_tag_t);
84 
85 /*
86  * XXX
87  */
88 bus_space_tag_t	mb_alloc_bus_space_tag(void);
89 void		mb_free_bus_space_tag(bus_space_tag_t);
90 
91 /*
92  * Utility macros; INTERNAL USE ONLY.
93  */
94 #define	__abs_c(a,b)		__CONCAT(a,b)
95 #define	__abs_opname(op,size)	__abs_c(__abs_c(__abs_c(abs_,op),_),size)
96 
97 #define	__abs_p(sz, t, h, o)						\
98 	(*(t)->__abs_opname(p,sz))(t, h, o)
99 #define	__abs_rs(sz, t, h, o)						\
100 	(*(t)->__abs_opname(r,sz))(t, h, o)
101 #define	__abs_rss(sz, t, h, o)						\
102 	(*(t)->__abs_opname(rs,sz))(t, h, o)
103 #define	__abs_ws(sz, t, h, o, v)					\
104 	(*(t)->__abs_opname(w,sz))(t, h, o, v)
105 #define	__abs_wss(sz, t, h, o, v)					\
106 	(*(t)->__abs_opname(ws,sz))(t, h, o, v)
107 #define	__abs_nonsingle(type, sz, t, h, o, a, c)			\
108 	(*(t)->__abs_opname(type,sz))(t, h, o, a, c)
109 #define	__abs_set(type, sz, t, h, o, v, c)				\
110 	(*(t)->__abs_opname(type,sz))(t, h, o, v, c)
111 
112     /*
113      * No swaps needed and no other trickery, so it should be possible
114      * to shortcut these to memcpy() directly [ leo 19990107 ]
115      */
116 #if 0
117     #define	__abs_copy(sz, t, h1, o1, h2, o2, cnt)			\
118 	(*(t)->__abs_opname(c,sz))(t, h1, o1, h2, o2, cnt)
119 #else
120     #define	__abs_copy(sz, t, h1, o1, h2, o2, cnt) do {		\
121 		    memcpy((void*)(h2 + o2), (void *)(h1 + o1), sz * cnt);  \
122 		    (void)t;						    \
123 		} while (0)
124 #endif
125 
126 
127 /*
128  * Check accesibility of the location for various sized bus accesses
129  */
130 #define bus_space_peek_1(t, h, o)	__abs_p(1,(t),(h),(o))
131 #define bus_space_peek_2(t, h, o)	__abs_p(2,(t),(h),(o))
132 #define bus_space_peek_4(t, h, o)	__abs_p(4,(t),(h),(o))
133 #define bus_space_peek_8(t, h, o)	__abs_p(8,(t),(h),(o))
134 
135 /*
136  * Bus read (single) operations.
137  */
138 #define	bus_space_read_1(t, h, o)	__abs_rs(1,(t),(h),(o))
139 #define	bus_space_read_2(t, h, o)	__abs_rs(2,(t),(h),(o))
140 #define	bus_space_read_4(t, h, o)	__abs_rs(4,(t),(h),(o))
141 #define	bus_space_read_8(t, h, o)	__abs_rs(8,(t),(h),(o))
142 
143 /*
144  * Bus read (single) stream operations.
145  */
146 #define	bus_space_read_stream_1(t, h, o)	__abs_rss(1,(t),(h),(o))
147 #define	bus_space_read_stream_2(t, h, o)	__abs_rss(2,(t),(h),(o))
148 #define	bus_space_read_stream_4(t, h, o)	__abs_rss(4,(t),(h),(o))
149 #define	bus_space_read_stream_8(t, h, o)	__abs_rss(8,(t),(h),(o))
150 
151 /*
152  * Bus read multiple operations.
153  */
154 #define	bus_space_read_multi_1(t, h, o, a, c)				\
155 	__abs_nonsingle(rm,1,(t),(h),(o),(a),(c))
156 #define	bus_space_read_multi_2(t, h, o, a, c)				\
157 	__abs_nonsingle(rm,2,(t),(h),(o),(a),(c))
158 #define	bus_space_read_multi_4(t, h, o, a, c)				\
159 	__abs_nonsingle(rm,4,(t),(h),(o),(a),(c))
160 #define	bus_space_read_multi_8(t, h, o, a, c)				\
161 	__abs_nonsingle(rm,8,(t),(h),(o),(a),(c))
162 
163 /*
164  * Bus read multiple stream operations.
165  */
166 #define	bus_space_read_multi_stream_1(t, h, o, a, c)			\
167 	__abs_nonsingle(rms,1,(t),(h),(o),(a),(c))
168 #define	bus_space_read_multi_stream_2(t, h, o, a, c)			\
169 	__abs_nonsingle(rms,2,(t),(h),(o),(a),(c))
170 #define	bus_space_read_multi_stream_4(t, h, o, a, c)			\
171 	__abs_nonsingle(rms,4,(t),(h),(o),(a),(c))
172 #define	bus_space_read_multi_stream_8(t, h, o, a, c)			\
173 	__abs_nonsingle(rms,8,(t),(h),(o),(a),(c))
174 
175 
176 /*
177  * Bus read region operations.
178  */
179 #define	bus_space_read_region_1(t, h, o, a, c)				\
180 	__abs_nonsingle(rr,1,(t),(h),(o),(a),(c))
181 #define	bus_space_read_region_2(t, h, o, a, c)				\
182 	__abs_nonsingle(rr,2,(t),(h),(o),(a),(c))
183 #define	bus_space_read_region_4(t, h, o, a, c)				\
184 	__abs_nonsingle(rr,4,(t),(h),(o),(a),(c))
185 #define	bus_space_read_region_8(t, h, o, a, c)				\
186 	__abs_nonsingle(rr,8,(t),(h),(o),(a),(c))
187 
188 /*
189  * Bus read region stream operations.
190  */
191 #define	bus_space_read_region_stream_1(t, h, o, a, c)			\
192 	__abs_nonsingle(rrs,1,(t),(h),(o),(a),(c))
193 #define	bus_space_read_region_stream_2(t, h, o, a, c)			\
194 	__abs_nonsingle(rrs,2,(t),(h),(o),(a),(c))
195 #define	bus_space_read_region_stream_4(t, h, o, a, c)			\
196 	__abs_nonsingle(rrs,4,(t),(h),(o),(a),(c))
197 #define	bus_space_read_region_stream_8(t, h, o, a, c)			\
198 	__abs_nonsingle(rrs,8,(t),(h),(o),(a),(c))
199 
200 /*
201  * Bus write (single) operations.
202  */
203 #define	bus_space_write_1(t, h, o, v)	__abs_ws(1,(t),(h),(o),(v))
204 #define	bus_space_write_2(t, h, o, v)	__abs_ws(2,(t),(h),(o),(v))
205 #define	bus_space_write_4(t, h, o, v)	__abs_ws(4,(t),(h),(o),(v))
206 #define	bus_space_write_8(t, h, o, v)	__abs_ws(8,(t),(h),(o),(v))
207 
208 /*
209  * Bus write (single) stream operations.
210  */
211 #define	bus_space_write_stream_1(t, h, o, v)	__abs_wss(1,(t),(h),(o),(v))
212 #define	bus_space_write_stream_2(t, h, o, v)	__abs_wss(2,(t),(h),(o),(v))
213 #define	bus_space_write_stream_4(t, h, o, v)	__abs_wss(4,(t),(h),(o),(v))
214 #define	bus_space_write_stream_8(t, h, o, v)	__abs_wss(8,(t),(h),(o),(v))
215 
216 
217 /*
218  * Bus write multiple operations.
219  */
220 #define	bus_space_write_multi_1(t, h, o, a, c)				\
221 	__abs_nonsingle(wm,1,(t),(h),(o),(a),(c))
222 #define	bus_space_write_multi_2(t, h, o, a, c)				\
223 	__abs_nonsingle(wm,2,(t),(h),(o),(a),(c))
224 #define	bus_space_write_multi_4(t, h, o, a, c)				\
225 	__abs_nonsingle(wm,4,(t),(h),(o),(a),(c))
226 #define	bus_space_write_multi_8(t, h, o, a, c)				\
227 	__abs_nonsingle(wm,8,(t),(h),(o),(a),(c))
228 
229 /*
230  * Bus write multiple stream operations.
231  */
232 #define	bus_space_write_multi_stream_1(t, h, o, a, c)			\
233 	__abs_nonsingle(wms,1,(t),(h),(o),(a),(c))
234 #define	bus_space_write_multi_stream_2(t, h, o, a, c)			\
235 	__abs_nonsingle(wms,2,(t),(h),(o),(a),(c))
236 #define	bus_space_write_multi_stream_4(t, h, o, a, c)			\
237 	__abs_nonsingle(wms,4,(t),(h),(o),(a),(c))
238 #define	bus_space_write_multi_stream_8(t, h, o, a, c)			\
239 	__abs_nonsingle(wms,8,(t),(h),(o),(a),(c))
240 
241 
242 /*
243  * Bus write region operations.
244  */
245 #define	bus_space_write_region_1(t, h, o, a, c)				\
246 	__abs_nonsingle(wr,1,(t),(h),(o),(a),(c))
247 #define	bus_space_write_region_2(t, h, o, a, c)				\
248 	__abs_nonsingle(wr,2,(t),(h),(o),(a),(c))
249 #define	bus_space_write_region_4(t, h, o, a, c)				\
250 	__abs_nonsingle(wr,4,(t),(h),(o),(a),(c))
251 #define	bus_space_write_region_8(t, h, o, a, c)				\
252 	__abs_nonsingle(wr,8,(t),(h),(o),(a),(c))
253 
254 /*
255  * Bus write region stream operations.
256  */
257 #define	bus_space_write_region_stream_1(t, h, o, a, c)			\
258 	__abs_nonsingle(wrs,1,(t),(h),(o),(a),(c))
259 #define	bus_space_write_region_stream_2(t, h, o, a, c)			\
260 	__abs_nonsingle(wrs,2,(t),(h),(o),(a),(c))
261 #define	bus_space_write_region_stream_4(t, h, o, a, c)			\
262 	__abs_nonsingle(wrs,4,(t),(h),(o),(a),(c))
263 #define	bus_space_write_region_stream_8(t, h, o, a, c)			\
264 	__abs_nonsingle(wrs,8,(t),(h),(o),(a),(c))
265 
266 
267 /*
268  * Set multiple operations.
269  */
270 #define	bus_space_set_multi_1(t, h, o, v, c)				\
271 	__abs_set(sm,1,(t),(h),(o),(v),(c))
272 #define	bus_space_set_multi_2(t, h, o, v, c)				\
273 	__abs_set(sm,2,(t),(h),(o),(v),(c))
274 #define	bus_space_set_multi_4(t, h, o, v, c)				\
275 	__abs_set(sm,4,(t),(h),(o),(v),(c))
276 #define	bus_space_set_multi_8(t, h, o, v, c)				\
277 	__abs_set(sm,8,(t),(h),(o),(v),(c))
278 
279 
280 /*
281  * Set region operations.
282  */
283 #define	bus_space_set_region_1(t, h, o, v, c)				\
284 	__abs_set(sr,1,(t),(h),(o),(v),(c))
285 #define	bus_space_set_region_2(t, h, o, v, c)				\
286 	__abs_set(sr,2,(t),(h),(o),(v),(c))
287 #define	bus_space_set_region_4(t, h, o, v, c)				\
288 	__abs_set(sr,4,(t),(h),(o),(v),(c))
289 #define	bus_space_set_region_8(t, h, o, v, c)				\
290 	__abs_set(sr,8,(t),(h),(o),(v),(c))
291 
292 
293 /*
294  * Copy region operations.
295  */
296 #define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)			\
297 	__abs_copy(1, (t), (h1), (o1), (h2), (o2), (c))
298 #define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)			\
299 	__abs_copy(2, (t), (h1), (o1), (h2), (o2), (c))
300 #define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)			\
301 	__abs_copy(4, (t), (h1), (o1), (h2), (o2), (c))
302 #define	bus_space_copy_region_8(t, h1, o1, h2, o2, c)			\
303 	__abs_copy(8, (t), (h1), (o1), (h2), (o2), (c))
304 
305 /*
306  *	void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
307  *
308  * Get the kernel virtual address for the mapped bus space.
309  * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
310  *  (XXX not enforced)
311  */
312 #define bus_space_vaddr(t, h)	((void)(t), (void *)(h))
313 
314 /*
315  *	paddr_t bus_space_mmap(bus_space_tag_t t, bus_addr_t base,
316  *	    off_t offset, int prot, int flags);
317  *
318  * Mmap an area of bus space.
319  */
320 
321 paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t,
322 	    int, int);
323 
324 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
325 
326 /*
327  * Bus read/write barrier methods.
328  *
329  *	void bus_space_barrier(bus_space_tag_t tag,
330  *	    bus_space_handle_t bsh, bus_size_t offset,
331  *	    bus_size_t len, int flags);
332  *
333  * Note: the Atari does not currently require barriers, but we must
334  * provide the flags to MI code.
335  */
336 #define	bus_space_barrier(t, h, o, l, f)	\
337 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
338 
339 /* Forwards needed by prototypes below. */
340 struct mbuf;
341 struct uio;
342 
343 #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
344 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
345 #define	bus_dmamap_destroy(t, p)				\
346 	(*(t)->_dmamap_destroy)((t), (p))
347 #define	bus_dmamap_load(t, m, b, s, p, f)			\
348 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
349 #define	bus_dmamap_load_mbuf(t, m, b, f)			\
350 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
351 #define	bus_dmamap_load_uio(t, m, u, f)				\
352 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
353 #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
354 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
355 #define	bus_dmamap_unload(t, p)					\
356 	(*(t)->_dmamap_unload)((t), (p))
357 #define	bus_dmamap_sync(t, p, o, l, ops)			\
358 	(void)((t)->_dmamap_sync ?				\
359 	    (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) : (void)0)
360 
361 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
362 #define bus_dmatag_destroy(t)
363 
364 #ifdef _ATARI_BUS_DMA_PRIVATE
365 int	_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
366 	    bus_size_t, int, bus_dmamap_t *);
367 void	_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
368 int	_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
369 	    bus_size_t, struct proc *, int);
370 int	_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int);
371 int	_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int);
372 int	_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
373 	    bus_dma_segment_t *, int, bus_size_t, int);
374 void	_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
375 void	_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
376 	    bus_size_t, int);
377 #endif /* _ATARI_BUS_DMA_PRIVATE */
378 
379 int	bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
380 	    bus_size_t alignment, bus_size_t boundary,
381 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
382 int	bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
383 	    bus_size_t alignment, bus_size_t boundary,
384 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
385 	    paddr_t low, paddr_t high);
386 void	bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs);
387 int	bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
388 	    int nsegs, size_t size, void **kvap, int flags);
389 void	bus_dmamem_unmap(bus_dma_tag_t tag, void *kva, size_t size);
390 paddr_t	bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
391 	    int nsegs, off_t off, int prot, int flags);
392 
393 #endif /* _ATARI_BUS_FUNCS_H_ */
394