1/*	$NetBSD: bus_funcs.h,v 1.2 2022/03/10 00:14:16 riastradh Exp $	*/
2/*	$OpenBSD: bus.h,v 1.1 1997/10/13 10:53:42 pefo Exp $	*/
3
4/*-
5 * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
36 * Copyright (c) 1996 Jason R. Thorpe.  All rights reserved.
37 * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 *    notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 *    notice, this list of conditions and the following disclaimer in the
46 *    documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 *    must display the following acknowledgement:
49 *      This product includes software developed by Christopher G. Demetriou
50 *	for the NetBSD Project.
51 * 4. The name of the author may not be used to endorse or promote products
52 *    derived from this software without specific prior written permission
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
59 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
63 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 */
65
66/*
67 * Copyright (c) 1997 Per Fogelstrom.  All rights reserved.
68 * Copyright (c) 1996 Niklas Hallqvist.  All rights reserved.
69 *
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
72 * are met:
73 * 1. Redistributions of source code must retain the above copyright
74 *    notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 *    notice, this list of conditions and the following disclaimer in the
77 *    documentation and/or other materials provided with the distribution.
78 * 3. All advertising materials mentioning features or use of this software
79 *    must display the following acknowledgement:
80 *      This product includes software developed by Christopher G. Demetriou
81 *	for the NetBSD Project.
82 * 4. The name of the author may not be used to endorse or promote products
83 *    derived from this software without specific prior written permission
84 *
85 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
86 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
87 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
88 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
89 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
90 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
91 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
92 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
93 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
94 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
95 */
96
97#ifndef _POWERPC_BUS_FUNCS_H_
98#define _POWERPC_BUS_FUNCS_H_
99
100#ifndef __HAVE_LOCAL_BUS_SPACE
101
102#ifdef __STDC__
103#define CAT(a,b)	a##b
104#define CAT3(a,b,c)	a##b##c
105#else
106#define CAT(a,b)	a/**/b
107#define CAT3(a,b,c)	a/**/b/**/c
108#endif
109
110int bus_space_init(struct powerpc_bus_space *, const char *, void *, size_t);
111void bus_space_mallocok(void);
112
113/*
114 * Access methods for bus resources
115 */
116
117/*
118 *	void *bus_space_vaddr (bus_space_tag_t, bus_space_handle_t);
119 *
120 * Get the kernel virtual address for the mapped bus space.
121 * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
122 *  (XXX not enforced)
123 */
124#define bus_space_vaddr(t, h) ((void *)(h))
125
126/*
127 *	paddr_t bus_space_mmap  (bus_space_tag_t t, bus_addr_t addr,
128 *	    off_t offset, int prot, int flags);
129 *
130 * Mmap a region of bus space.
131 */
132
133#define bus_space_mmap(t, b, o, p, f)					\
134    ((*(t)->pbs_mmap)((t), (b), (o), (p), (f)))
135
136/*
137 *	int bus_space_map  (bus_space_tag_t t, bus_addr_t addr,
138 *	    bus_size_t size, int flags, bus_space_handle_t *bshp);
139 *
140 * Map a region of bus space.
141 */
142
143#define bus_space_map(t, a, s, f, hp)					\
144    ((*(t)->pbs_map)((t), (a), (s), (f), (hp)))
145
146/*
147 *	int bus_space_unmap (bus_space_tag_t t,
148 *	    bus_space_handle_t bsh, bus_size_t size);
149 *
150 * Unmap a region of bus space.
151 */
152
153#define bus_space_unmap(t, h, s)					\
154    ((void)(*(t)->pbs_unmap)((t), (h), (s)))
155
156/*
157 *	int bus_space_subregion (bus_space_tag_t t,
158 *	    bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
159 *	    bus_space_handle_t *nbshp);
160 *
161 * Get a new handle for a subregion of an already-mapped area of bus space.
162 */
163
164#define bus_space_subregion(t, h, o, s, hp)				\
165    ((*(t)->pbs_subregion)((t), (h), (o), (s), (hp)))
166
167/*
168 *	int bus_space_alloc (bus_space_tag_t t, bus_addr_t rstart,
169 *	    bus_addr_t rend, bus_size_t size, bus_size_t align,
170 *	    bus_size_t boundary, int flags, bus_addr_t *bpap,
171 *	    bus_space_handle_t *bshp);
172 *
173 * Allocate a region of bus space.
174 */
175
176#define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp)			\
177    ((*(t)->pbs_alloc)((t), (rs), (re), (s), (a), (b), (f), (ap), (hp)))
178
179/*
180 *	int bus_space_free (bus_space_tag_t t,
181 *	    bus_space_handle_t bsh, bus_size_t size);
182 *
183 * Free a region of bus space.
184 */
185
186#define	bus_space_free(t, h, s)						\
187    ((void)(*(t)->pbs_free)((t), (h), (s)))
188
189/*
190 *	uintN_t bus_space_read_N (bus_space_tag_t tag,
191 *	    bus_space_handle_t bsh, bus_size_t offset);
192 *
193 * Read a 1, 2, 4, or 8 byte quantity from bus space
194 * described by tag/handle/offset.
195 */
196
197#define bus_space_read_1(t, h, o)					\
198	((*(t)->pbs_scalar.pbss_read_1)((t), (h), (o)))
199#define bus_space_read_2(t, h, o)					\
200	((*(t)->pbs_scalar.pbss_read_2)((t), (h), (o)))
201#define bus_space_read_4(t, h, o)					\
202	((*(t)->pbs_scalar.pbss_read_4)((t), (h), (o)))
203#define bus_space_read_8(t, h, o)					\
204	((*(t)->pbs_scalar.pbss_read_8)((t), (h), (o)))
205
206/*
207 *	uintN_t bus_space_read_stream_N (bus_space_tag_t tag,
208 *	    bus_space_handle_t bsh, bus_size_t offset);
209 *
210 * Read a 2, 4, or 8 byte quantity from bus space
211 * described by tag/handle/offset ignoring endianness.
212 */
213
214#define bus_space_read_stream_2(t, h, o)				\
215	((*(t)->pbs_scalar_stream.pbss_read_2)((t), (h), (o)))
216#define bus_space_read_stream_4(t, h, o)				\
217	((*(t)->pbs_scalar_stream.pbss_read_4)((t), (h), (o)))
218#define bus_space_read_stream_8(t, h, o)				\
219	((*(t)->pbs_scalar_stream.pbss_read_8)((t), (h), (o)))
220
221/*
222 *	void bus_space_read_multi_N _P((bus_space_tag_t tag,
223 *	    bus_space_handle_t bsh, bus_size_t offset,
224 *	    uintN_t *addr, size_t count);
225 *
226 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
227 * described by tag/handle/offset and copy into buffer provided.
228 */
229
230#define bus_space_read_multi_1(t, h, o, a, c)				\
231	((*(t)->pbs_multi->pbsg_read_1)((t), (h), (o), (a), (c)))
232#define bus_space_read_multi_2(t, h, o, a, c)				\
233	((*(t)->pbs_multi->pbsg_read_2)((t), (h), (o), (a), (c)))
234#define bus_space_read_multi_4(t, h, o, a, c)				\
235	((*(t)->pbs_multi->pbsg_read_4)((t), (h), (o), (a), (c)))
236#define bus_space_read_multi_8(t, h, o, a, c)				\
237	((*(t)->pbs_multi->pbsg_read_8)((t), (h), (o), (a), (c)))
238
239/*
240 *	void bus_space_read_multi_stream_N (bus_space_tag_t tag,
241 *	    bus_space_handle_t bsh, bus_size_t offset,
242 *	    uintN_t *addr, size_t count);
243 *
244 * Read `count' 2, 4, or 8 byte stream quantities from bus space
245 * described by tag/handle/offset and copy into buffer provided.
246 */
247
248#define bus_space_read_multi_stream_2(t, h, o, a, c)			\
249	((*(t)->pbs_multi_stream->pbsg_read_2)((t), (h), (o), (a), (c)))
250#define bus_space_read_multi_stream_4(t, h, o, a, c)			\
251	((*(t)->pbs_multi_stream->pbsg_read_4)((t), (h), (o), (a), (c)))
252#define bus_space_read_multi_stream_8(t, h, o, a, c)			\
253	((*(t)->pbs_multi_stream->pbsg_read_8)((t), (h), (o), (a), (c)))
254
255/*
256 *	void bus_space_write_N (bus_space_tag_t tag,
257 *	    bus_space_handle_t bsh, bus_size_t offset,
258 *	    uintN_t value);
259 *
260 * Write the 1, 2, 4, or 8 byte value `value' to bus space
261 * described by tag/handle/offset.
262 */
263
264#define bus_space_write_1(t, h, o, v)					\
265	((*(t)->pbs_scalar.pbss_write_1)((t), (h), (o), (v)))
266#define bus_space_write_2(t, h, o, v)					\
267	((*(t)->pbs_scalar.pbss_write_2)((t), (h), (o), (v)))
268#define bus_space_write_4(t, h, o, v)					\
269	((*(t)->pbs_scalar.pbss_write_4)((t), (h), (o), (v)))
270#define bus_space_write_8(t, h, o, v)					\
271	((*(t)->pbs_scalar.pbss_write_8)((t), (h), (o), (v)))
272
273/*
274 *	void bus_space_write_stream_N (bus_space_tag_t tag,
275 *	    bus_space_handle_t bsh, bus_size_t offset,
276 *	    uintN_t value);
277 *
278 * Write the 2, 4, or 8 byte stream value `value' to bus space
279 * described by tag/handle/offset.
280 */
281
282#define bus_space_write_stream_1(t, h, o, v)				\
283	((*(t)->pbs_scalar_stream.pbss_write_1)((t), (h), (o), (v)))
284#define bus_space_write_stream_2(t, h, o, v)				\
285	((*(t)->pbs_scalar_stream.pbss_write_2)((t), (h), (o), (v)))
286#define bus_space_write_stream_4(t, h, o, v)				\
287	((*(t)->pbs_scalar_stream.pbss_write_4)((t), (h), (o), (v)))
288#define bus_space_write_stream_8(t, h, o, v)				\
289	((*(t)->pbs_scalar_stream.pbss_write_8)((t), (h), (o), (v)))
290
291/*
292 *	void bus_space_write_multi_N (bus_space_tag_t tag,
293 *	    bus_space_handle_t bsh, bus_size_t offset,
294 *	    const uintN_t *addr, size_t count);
295 *
296 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
297 * provided to bus space described by tag/handle/offset.
298 */
299
300#define bus_space_write_multi_1(t, h, o, a, c)				\
301	((*(t)->pbs_multi->pbsg_write_1)((t), (h), (o), (a), (c)))
302#define bus_space_write_multi_2(t, h, o, a, c)				\
303	((*(t)->pbs_multi->pbsg_write_2)((t), (h), (o), (a), (c)))
304#define bus_space_write_multi_4(t, h, o, a, c)				\
305	((*(t)->pbs_multi->pbsg_write_4)((t), (h), (o), (a), (c)))
306#define bus_space_write_multi_8(t, h, o, a, c)				\
307	((*(t)->pbs_multi->pbsg_write_8)((t), (h), (o), (a), (c)))
308
309/*
310 *	void bus_space_write_multi_stream_N (bus_space_tag_t tag,
311 *	    bus_space_handle_t bsh, bus_size_t offset,
312 *	    const uintN_t *addr, size_t count);
313 *
314 * Write `count' 2, 4, or 8 byte stream quantities from the buffer
315 * provided to bus space described by tag/handle/offset.
316 */
317
318#define bus_space_write_multi_stream_1(t, h, o, a, c)			\
319	((*(t)->pbs_multi_stream->pbsg_write_1)((t), (h), (o), (a), (c)))
320#define bus_space_write_multi_stream_2(t, h, o, a, c)			\
321	((*(t)->pbs_multi_stream->pbsg_write_2)((t), (h), (o), (a), (c)))
322#define bus_space_write_multi_stream_4(t, h, o, a, c)			\
323	((*(t)->pbs_multi_stream->pbsg_write_4)((t), (h), (o), (a), (c)))
324#define bus_space_write_multi_stream_8(t, h, o, a, c)			\
325	((*(t)->pbs_multi_stream->pbsg_write_8)((t), (h), (o), (a), (c)))
326
327/*
328 *	void bus_space_read_region_N (bus_space_tag_t tag,
329 *	    bus_space_handle_t bsh, bus_size_t offset,
330 *	    uintN_t *addr, size_t count);
331 *
332 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
333 * described by tag/handle and starting at `offset' and copy into
334 * buffer provided.
335 */
336#define bus_space_read_region_1(t, h, o, a, c)				\
337	((*(t)->pbs_region->pbsg_read_1)((t), (h), (o), (a), (c)))
338#define bus_space_read_region_2(t, h, o, a, c)				\
339	((*(t)->pbs_region->pbsg_read_2)((t), (h), (o), (a), (c)))
340#define bus_space_read_region_4(t, h, o, a, c)				\
341	((*(t)->pbs_region->pbsg_read_4)((t), (h), (o), (a), (c)))
342#define bus_space_read_region_8(t, h, o, a, c)				\
343	((*(t)->pbs_region->pbsg_read_8)((t), (h), (o), (a), (c)))
344
345/*
346 *	void bus_space_read_region_stream_N (bus_space_tag_t tag,
347 *	    bus_space_handle_t bsh, bus_size_t offset,
348 *	    uintN_t *addr, size_t count);
349 *
350 * Read `count' 2, 4, or 8 byte stream quantities from bus space
351 * described by tag/handle and starting at `offset' and copy into
352 * buffer provided.
353 */
354#define bus_space_read_region_stream_2(t, h, o, a, c)			\
355	((*(t)->pbs_region_stream->pbsg_read_2)((t), (h), (o), (a), (c)))
356#define bus_space_read_region_stream_4(t, h, o, a, c)			\
357	((*(t)->pbs_region_stream->pbsg_read_4)((t), (h), (o), (a), (c)))
358#define bus_space_read_region_stream_8(t, h, o, a, c)			\
359	((*(t)->pbs_region_stream->pbsg_read_8)((t), (h), (o), (a), (c)))
360
361/*
362 *	void bus_space_write_region_N (bus_space_tag_t tag,
363 *	    bus_space_handle_t bsh, bus_size_t offset,
364 *	    const uintN_t *addr, size_t count);
365 *
366 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
367 * to bus space described by tag/handle starting at `offset'.
368 */
369#define bus_space_write_region_1(t, h, o, a, c)				\
370	((*(t)->pbs_region->pbsg_write_1)((t), (h), (o), (a), (c)))
371#define bus_space_write_region_2(t, h, o, a, c)				\
372	((*(t)->pbs_region->pbsg_write_2)((t), (h), (o), (a), (c)))
373#define bus_space_write_region_4(t, h, o, a, c)				\
374	((*(t)->pbs_region->pbsg_write_4)((t), (h), (o), (a), (c)))
375#define bus_space_write_region_8(t, h, o, a, c)				\
376	((*(t)->pbs_region->pbsg_write_8)((t), (h), (o), (a), (c)))
377
378/*
379 *	void bus_space_write_region_stream_N (bus_space_tag_t tag,
380 *	    bus_space_handle_t bsh, bus_size_t offset,
381 *	    const uintN_t *addr, size_t count);
382 *
383 * Write `count' 2, 4, or 8 byte stream quantities from the buffer provided
384 * to bus space described by tag/handle starting at `offset'.
385 */
386#define bus_space_write_region_stream_2(t, h, o, a, c)			\
387	((*(t)->pbs_region_stream->pbsg_write_2)((t), (h), (o), (a), (c)))
388#define bus_space_write_region_stream_4(t, h, o, a, c)			\
389	((*(t)->pbs_region_stream->pbsg_write_4)((t), (h), (o), (a), (c)))
390#define bus_space_write_region_stream_8(t, h, o, a, c)			\
391	((*(t)->pbs_region_stream->pbsg_write_8)((t), (h), (o), (a), (c)))
392
393#if 0
394/*
395 *	void bus_space_set_multi_N (bus_space_tag_t tag,
396 *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
397 *	    size_t count);
398 *
399 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
400 * by tag/handle/offset `count' times.
401 */
402#define	bus_space_set_multi_1(t, h, o, v, c)
403	((*(t)->pbs_set_multi_1)((t), (h), (o), (v), (c)))
404#define	bus_space_set_multi_2(t, h, o, v, c)
405	((*(t)->pbs_set_multi_2)((t), (h), (o), (v), (c)))
406#define	bus_space_set_multi_4(t, h, o, v, c)
407	((*(t)->pbs_set_multi_4)((t), (h), (o), (v), (c)))
408#define	bus_space_set_multi_8(t, h, o, v, c)
409	((*(t)->pbs_set_multi_8)((t), (h), (o), (v), (c)))
410
411/*
412 *	void bus_space_set_multi_stream_N (bus_space_tag_t tag,
413 *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
414 *	    size_t count);
415 *
416 * Write the 2, 4, or 8 byte stream value `val' to bus space described
417 * by tag/handle/offset `count' times.
418 */
419#define	bus_space_set_multi_stream_2(t, h, o, v, c)
420	((*(t)->pbs_set_multi_stream_2)((t), (h), (o), (v), (c)))
421#define	bus_space_set_multi_stream_4(t, h, o, v, c)
422	((*(t)->pbs_set_multi_stream_4)((t), (h), (o), (v), (c)))
423#define	bus_space_set_multi_stream_8(t, h, o, v, c)
424	((*(t)->pbs_set_multi_stream_8)((t), (h), (o), (v), (c)))
425
426#endif
427
428/*
429 *	void bus_space_set_region_N (bus_space_tag_t tag,
430 *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
431 *	    size_t count);
432 *
433 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
434 * by tag/handle starting at `offset'.
435 */
436#define bus_space_set_region_1(t, h, o, v, c)				\
437	((*(t)->pbs_set->pbss_set_1)((t), (h), (o), (v), (c)))
438#define bus_space_set_region_2(t, h, o, v, c)				\
439	((*(t)->pbs_set->pbss_set_2)((t), (h), (o), (v), (c)))
440#define bus_space_set_region_4(t, h, o, v, c)				\
441	((*(t)->pbs_set->pbss_set_4)((t), (h), (o), (v), (c)))
442#define bus_space_set_region_8(t, h, o, v, c)				\
443	((*(t)->pbs_set->pbss_set_8)((t), (h), (o), (v), (c)))
444
445/*
446 *	void bus_space_set_region_stream_N (bus_space_tag_t tag,
447 *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
448 *	    size_t count);
449 *
450 * Write `count' 2, 4, or 8 byte stream value `val' to bus space described
451 * by tag/handle starting at `offset'.
452 */
453#define bus_space_set_region_stream_2(t, h, o, v, c)			\
454	((*(t)->pbs_set_stream->pbss_set_2)((t), (h), (o), (v), (c)))
455#define bus_space_set_region_stream_4(t, h, o, v, c)			\
456	((*(t)->pbs_set_stream->pbss_set_4)((t), (h), (o), (v), (c)))
457#define bus_space_set_region_stream_8(t, h, o, v, c)			\
458	((*(t)->pbs_set_stream->pbss_set_8)((t), (h), (o), (v), (c)))
459
460
461/*
462 *	void bus_space_copy_region_N (bus_space_tag_t tag,
463 *	    bus_space_handle_t bsh1, bus_size_t off1,
464 *	    bus_space_handle_t bsh2, bus_size_t off2,
465 *	    size_t count);
466 *
467 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
468 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
469 */
470#define bus_space_copy_region_1(t, h1, o1, h2, o2, c)			\
471	((*(t)->pbs_copy->pbsc_copy_1)((t), (h1), (o1), (h2), (o2), (c)))
472#define bus_space_copy_region_2(t, h1, o1, h2, o2, c)			\
473	((*(t)->pbs_copy->pbsc_copy_2)((t), (h1), (o1), (h2), (o2), (c)))
474#define bus_space_copy_region_4(t, h1, o1, h2, o2, c)			\
475	((*(t)->pbs_copy->pbsc_copy_4)((t), (h1), (o1), (h2), (o2), (c)))
476#define bus_space_copy_region_8(t, h1, o1, h2, o2, c)			\
477	((*(t)->pbs_copy->pbsc_copy_8)((t), (h1), (o1), (h2), (o2), (c)))
478
479/*
480 * Bus read/write barrier methods.
481 *
482 *	void bus_space_barrier (bus_space_tag_t tag,
483 *	    bus_space_handle_t bsh, bus_size_t offset,
484 *	    bus_size_t len, int flags);
485 *
486 */
487#define	bus_space_barrier(t, h, o, l, f)	\
488	((*(t)->pbs_barrier)((t), (h), (o), (l), (f)))
489
490#endif	/* !__HAVE_LOCAL_BUS_SPACE */
491
492/*
493 * Bus DMA methods.
494 */
495
496/* Forwards needed by prototypes below. */
497struct proc;
498struct mbuf;
499struct uio;
500
501#define	bus_dmamap_create(t, s, n, m, b, f, p)			\
502	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
503#define	bus_dmamap_destroy(t, p)				\
504	(*(t)->_dmamap_destroy)((t), (p))
505#define	bus_dmamap_load(t, m, b, s, p, f)			\
506	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
507#define	bus_dmamap_load_mbuf(t, m, b, f)			\
508	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
509#define	bus_dmamap_load_uio(t, m, u, f)				\
510	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
511#define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
512	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
513#define	bus_dmamap_unload(t, p)					\
514	(*(t)->_dmamap_unload)((t), (p))
515#define	bus_dmamap_sync(t, p, o, l, ops)			\
516	(void)((t)->_dmamap_sync ?				\
517	    (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) : (void)0)
518
519#define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
520	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
521#define	bus_dmamem_free(t, sg, n)				\
522	(*(t)->_dmamem_free)((t), (sg), (n))
523#define	bus_dmamem_map(t, sg, n, s, k, f)			\
524	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
525#define	bus_dmamem_unmap(t, k, s)				\
526	(*(t)->_dmamem_unmap)((t), (k), (s))
527#define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
528	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
529
530#define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
531#define bus_dmatag_destroy(t)
532
533#ifdef _POWERPC_BUS_DMA_PRIVATE
534int	_bus_dmamap_create (bus_dma_tag_t, bus_size_t, int, bus_size_t,
535	    bus_size_t, int, bus_dmamap_t *);
536void	_bus_dmamap_destroy (bus_dma_tag_t, bus_dmamap_t);
537int	_bus_dmamap_load (bus_dma_tag_t, bus_dmamap_t, void *,
538	    bus_size_t, struct proc *, int);
539int	_bus_dmamap_load_mbuf (bus_dma_tag_t, bus_dmamap_t,
540	    struct mbuf *, int);
541int	_bus_dmamap_load_uio (bus_dma_tag_t, bus_dmamap_t,
542	    struct uio *, int);
543int	_bus_dmamap_load_raw (bus_dma_tag_t, bus_dmamap_t,
544	    bus_dma_segment_t *, int, bus_size_t, int);
545void	_bus_dmamap_unload (bus_dma_tag_t, bus_dmamap_t);
546void	_bus_dmamap_sync (bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
547	    bus_size_t, int);
548
549int	_bus_dmamem_alloc (bus_dma_tag_t tag, bus_size_t size,
550	    bus_size_t alignment, bus_size_t boundary,
551	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
552void	_bus_dmamem_free (bus_dma_tag_t tag, bus_dma_segment_t *segs,
553	    int nsegs);
554int	_bus_dmamem_map (bus_dma_tag_t tag, bus_dma_segment_t *segs,
555	    int nsegs, size_t size, void **kvap, int flags);
556void	_bus_dmamem_unmap (bus_dma_tag_t tag, void *kva,
557	    size_t size);
558paddr_t	_bus_dmamem_mmap (bus_dma_tag_t tag, bus_dma_segment_t *segs,
559	    int nsegs, off_t off, int prot, int flags);
560
561int	_bus_dmamem_alloc_range (bus_dma_tag_t tag, bus_size_t size,
562	    bus_size_t alignment, bus_size_t boundary,
563	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
564	    paddr_t low, paddr_t high);
565bus_addr_t _bus_dma_phys_to_bus_mem_generic(bus_dma_tag_t, bus_addr_t);
566bus_addr_t _bus_dma_bus_mem_to_phys_generic(bus_dma_tag_t, bus_addr_t);
567#endif /* _POWERPC_BUS_DMA_PRIVATE */
568#endif /* _POWERPC_BUS_FUNCS_H_ */
569