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