xref: /netbsd/sys/arch/hpcmips/include/bus.h (revision e0efbec3)
1 /*	$NetBSD: bus.h,v 1.24 2021/12/12 08:49:57 andvar Exp $	*/
2 
3 /*-
4  * Copyright (c) 1996, 1997, 1998, 2001 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 Charles M. Hannum.  All rights reserved.
35  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  * 3. All advertising materials mentioning features or use of this software
46  *    must display the following acknowledgement:
47  *      This product includes software developed by Christopher G. Demetriou
48  *	for the NetBSD Project.
49  * 4. The name of the author may not be used to endorse or promote products
50  *    derived from this software without specific prior written permission
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  */
63 
64 /*
65  * derived from arch/arm/include/bus.h Rev. 1.3
66  */
67 
68 #ifndef _HPCMIPS_BUS_H_
69 #define _HPCMIPS_BUS_H_
70 
71 #include <machine/bus_types.h>
72 
73 #ifndef BUS_SPACE_MD_CALLS
74 
75 #define	BUS_SPACE_MAP_CACHEABLE		0x01
76 #define	BUS_SPACE_MAP_LINEAR		0x02
77 #define	BUS_SPACE_MAP_PREFETCHABLE     	0x04
78 
79 #define	BUS_SPACE_BARRIER_READ	0x01
80 #define	BUS_SPACE_BARRIER_WRITE	0x02
81 
82 #ifndef BUS_SPACE_MD_TYPES
83 typedef struct bus_space_tag *bus_space_tag_t;
84 #endif
85 
86 /*
87  * bus space operation table
88  */
89 struct bus_space_ops {
90 	/* mapping/unmapping */
91 	int	  (*bs_map)(bus_space_tag_t, bus_addr_t, bus_size_t,
92 		      int, bus_space_handle_t *);
93 	void	  (*bs_unmap)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
94 	int	  (*bs_subregion)(bus_space_tag_t, bus_space_handle_t,
95 		      bus_size_t, bus_size_t, bus_space_handle_t *);
96 
97 	/* allocation/deallocation */
98 	int	  (*bs_alloc)(bus_space_tag_t, bus_addr_t,
99 		      bus_addr_t, bus_size_t, bus_size_t, bus_size_t,
100 		      int, bus_addr_t *, bus_space_handle_t *);
101 	void	  (*bs_free)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
102 
103 	/* get kernel virtual address */
104 	void *	  (*bs_vaddr)(bus_space_tag_t, bus_space_handle_t);
105 
106 	/* mmap bus space for user */
107 	paddr_t	  (*bs_mmap)(bus_space_tag_t, bus_addr_t, off_t, int, int);
108 
109 	/* barrier */
110 	void	  (*bs_barrier)(bus_space_tag_t, bus_space_handle_t,
111 		      bus_size_t, bus_size_t, int);
112 
113 	/* probe */
114 	int	  (*bs_peek)(bus_space_tag_t, bus_space_handle_t,
115 		      bus_size_t, size_t, void *);
116 	int	  (*bs_poke)(bus_space_tag_t, bus_space_handle_t,
117 		      bus_size_t, size_t, u_int32_t);
118 
119 	/* read (single) */
120 	u_int8_t  (*bs_r_1)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
121 	u_int16_t (*bs_r_2)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
122 	u_int32_t (*bs_r_4)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
123 	u_int64_t (*bs_r_8)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
124 
125 	/* read multiple */
126 	void	  (*bs_rm_1)(bus_space_tag_t, bus_space_handle_t,
127 		      bus_size_t, u_int8_t *, bus_size_t);
128 	void	  (*bs_rm_2)(bus_space_tag_t, bus_space_handle_t,
129 		      bus_size_t, u_int16_t *, bus_size_t);
130 	void	  (*bs_rm_4)(bus_space_tag_t, bus_space_handle_t,
131 		      bus_size_t, u_int32_t *, bus_size_t);
132 	void	  (*bs_rm_8)(bus_space_tag_t, bus_space_handle_t,
133 		      bus_size_t, u_int64_t *, bus_size_t);
134 
135 	/* read region */
136 	void	  (*bs_rr_1)(bus_space_tag_t, bus_space_handle_t,
137 		      bus_size_t, u_int8_t *, bus_size_t);
138 	void	  (*bs_rr_2)(bus_space_tag_t, bus_space_handle_t,
139 		      bus_size_t, u_int16_t *, bus_size_t);
140 	void	  (*bs_rr_4)(bus_space_tag_t, bus_space_handle_t,
141 		      bus_size_t, u_int32_t *, bus_size_t);
142 	void	  (*bs_rr_8)(bus_space_tag_t, bus_space_handle_t,
143 		      bus_size_t, u_int64_t *, bus_size_t);
144 
145 	/* write (single) */
146 	void	  (*bs_w_1)(bus_space_tag_t, bus_space_handle_t,
147 		      bus_size_t, u_int8_t);
148 	void	  (*bs_w_2)(bus_space_tag_t, bus_space_handle_t,
149 		      bus_size_t, u_int16_t);
150 	void	  (*bs_w_4)(bus_space_tag_t, bus_space_handle_t,
151 		      bus_size_t, u_int32_t);
152 	void	  (*bs_w_8)(bus_space_tag_t, bus_space_handle_t,
153 		      bus_size_t, u_int64_t);
154 
155 	/* write multiple */
156 	void	  (*bs_wm_1)(bus_space_tag_t, bus_space_handle_t,
157 		      bus_size_t, const u_int8_t *, bus_size_t);
158 	void	  (*bs_wm_2)(bus_space_tag_t, bus_space_handle_t,
159 		      bus_size_t, const u_int16_t *, bus_size_t);
160 	void	  (*bs_wm_4)(bus_space_tag_t, bus_space_handle_t,
161 		      bus_size_t, const u_int32_t *, bus_size_t);
162 	void	  (*bs_wm_8)(bus_space_tag_t, bus_space_handle_t,
163 		      bus_size_t, const u_int64_t *, bus_size_t);
164 
165 	/* write region */
166 	void	  (*bs_wr_1)(bus_space_tag_t, bus_space_handle_t,
167 		      bus_size_t, const u_int8_t *, bus_size_t);
168 	void	  (*bs_wr_2)(bus_space_tag_t, bus_space_handle_t,
169 		      bus_size_t, const u_int16_t *, bus_size_t);
170 	void	  (*bs_wr_4)(bus_space_tag_t, bus_space_handle_t,
171 		      bus_size_t, const u_int32_t *, bus_size_t);
172 	void	  (*bs_wr_8)(bus_space_tag_t, bus_space_handle_t,
173 		      bus_size_t, const u_int64_t *, bus_size_t);
174 
175 #ifdef BUS_SPACE_HAS_REAL_STREAM_METHODS
176 	/* read (single) stream */
177 	u_int8_t  (*bs_rs_1)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
178 	u_int16_t (*bs_rs_2)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
179 	u_int32_t (*bs_rs_4)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
180 	u_int64_t (*bs_rs_8)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
181 
182 	/* read multiple stream */
183 	void	  (*bs_rms_1)(bus_space_tag_t, bus_space_handle_t,
184 		      bus_size_t, u_int8_t *, bus_size_t);
185 	void	  (*bs_rms_2)(bus_space_tag_t, bus_space_handle_t,
186 		      bus_size_t, u_int16_t *, bus_size_t);
187 	void	  (*bs_rms_4)(bus_space_tag_t, bus_space_handle_t,
188 		      bus_size_t, u_int32_t *, bus_size_t);
189 	void	  (*bs_rms_8)(bus_space_tag_t, bus_space_handle_t,
190 		      bus_size_t, u_int64_t *, bus_size_t);
191 
192 	/* read region stream */
193 	void	  (*bs_rrs_1)(bus_space_tag_t, bus_space_handle_t,
194 		      bus_size_t, u_int8_t *, bus_size_t);
195 	void	  (*bs_rrs_2)(bus_space_tag_t, bus_space_handle_t,
196 		      bus_size_t, u_int16_t *, bus_size_t);
197 	void	  (*bs_rrs_4)(bus_space_tag_t, bus_space_handle_t,
198 		      bus_size_t, u_int32_t *, bus_size_t);
199 	void	  (*bs_rrs_8)(bus_space_tag_t, bus_space_handle_t,
200 		      bus_size_t, u_int64_t *, bus_size_t);
201 
202 	/* write (single) stream */
203 	void	  (*bs_ws_1)(bus_space_tag_t, bus_space_handle_t,
204 		      bus_size_t, u_int8_t);
205 	void	  (*bs_ws_2)(bus_space_tag_t, bus_space_handle_t,
206 		      bus_size_t, u_int16_t);
207 	void	  (*bs_ws_4)(bus_space_tag_t, bus_space_handle_t,
208 		      bus_size_t, u_int32_t);
209 	void	  (*bs_ws_8)(bus_space_tag_t, bus_space_handle_t,
210 		      bus_size_t, u_int64_t);
211 
212 	/* write multiple stream */
213 	void	  (*bs_wms_1)(bus_space_tag_t, bus_space_handle_t,
214 		      bus_size_t, const u_int8_t *, bus_size_t);
215 	void	  (*bs_wms_2)(bus_space_tag_t, bus_space_handle_t,
216 		      bus_size_t, const u_int16_t *, bus_size_t);
217 	void	  (*bs_wms_4)(bus_space_tag_t, bus_space_handle_t,
218 		      bus_size_t, const u_int32_t *, bus_size_t);
219 	void	  (*bs_wms_8)(bus_space_tag_t, bus_space_handle_t,
220 		      bus_size_t, const u_int64_t *, bus_size_t);
221 
222 	/* write region stream */
223 	void	  (*bs_wrs_1)(bus_space_tag_t, bus_space_handle_t,
224 		      bus_size_t, const u_int8_t *, bus_size_t);
225 	void	  (*bs_wrs_2)(bus_space_tag_t, bus_space_handle_t,
226 		      bus_size_t, const u_int16_t *, bus_size_t);
227 	void	  (*bs_wrs_4)(bus_space_tag_t, bus_space_handle_t,
228 		      bus_size_t, const u_int32_t *, bus_size_t);
229 	void	  (*bs_wrs_8)(bus_space_tag_t, bus_space_handle_t,
230 		      bus_size_t, const u_int64_t *, bus_size_t);
231 #endif /* BUS_SPACE_HAS_REAL_STREAM_METHODS */
232 
233 	/* set multiple */
234 	void	  (*bs_sm_1)(bus_space_tag_t, bus_space_handle_t,
235 		      bus_size_t, u_int8_t, bus_size_t);
236 	void	  (*bs_sm_2)(bus_space_tag_t, bus_space_handle_t,
237 		      bus_size_t, u_int16_t, bus_size_t);
238 	void	  (*bs_sm_4)(bus_space_tag_t, bus_space_handle_t,
239 		      bus_size_t, u_int32_t, bus_size_t);
240 	void	  (*bs_sm_8)(bus_space_tag_t, bus_space_handle_t,
241 		      bus_size_t, u_int64_t, bus_size_t);
242 
243 	/* set region */
244 	void	  (*bs_sr_1)(bus_space_tag_t, bus_space_handle_t,
245 		      bus_size_t, u_int8_t, bus_size_t);
246 	void	  (*bs_sr_2)(bus_space_tag_t, bus_space_handle_t,
247 		      bus_size_t, u_int16_t, bus_size_t);
248 	void	  (*bs_sr_4)(bus_space_tag_t, bus_space_handle_t,
249 		      bus_size_t, u_int32_t, bus_size_t);
250 	void	  (*bs_sr_8)(bus_space_tag_t, bus_space_handle_t,
251 		      bus_size_t, u_int64_t, bus_size_t);
252 
253 	/* copy */
254 	void	  (*bs_c_1)(bus_space_tag_t, bus_space_handle_t, bus_size_t,
255 		      bus_space_handle_t, bus_size_t, bus_size_t);
256 	void	  (*bs_c_2)(bus_space_tag_t, bus_space_handle_t, bus_size_t,
257 		      bus_space_handle_t, bus_size_t, bus_size_t);
258 	void	  (*bs_c_4)(bus_space_tag_t, bus_space_handle_t, bus_size_t,
259 		      bus_space_handle_t, bus_size_t, bus_size_t);
260 	void	  (*bs_c_8)(bus_space_tag_t, bus_space_handle_t, bus_size_t,
261 		      bus_space_handle_t, bus_size_t, bus_size_t);
262 };
263 
264 
265 /*
266  * Utility macros; INTERNAL USE ONLY.
267  */
268 #define	__bs_c(a,b)		__CONCAT(a,b)
269 #define	__bs_opname(op,s)	__bs_c(__bs_c(__bs_c(bs_,op),_),s)
270 #define	__bs_popname(pfx,op,s)	__bs_c(pfx,__bs_c(_,__bs_opname(op,s)))
271 #define	__bs_ops(t)		(((bus_space_tag_t)(t))->bs_ops)
272 
273 #define	__bs_rs(sz, t, h, o)						\
274 	(*__bs_ops(t).__bs_opname(r,sz))(t, h, o)
275 #define	__bs_ws(sz, t, h, o, v)						\
276 	(*__bs_ops(t).__bs_opname(w,sz))(t, h, o, v)
277 #ifdef BUS_SPACE_HAS_REAL_STREAM_METHODS
278 #define	__bs_rss(sz, t, h, o)						\
279 	(*__bs_ops(t).__bs_opname(rs,sz))(t, h, o)
280 #define	__bs_wss(sz, t, h, o, v)					\
281 	(*__bs_ops(t).__bs_opname(ws,sz))(t, h, o, v)
282 #endif /* BUS_SPACE_HAS_REAL_STREAM_METHODS */
283 #define	__bs_nonsingle(type, sz, t, h, o, a, c)				\
284 	(*__bs_ops(t).__bs_opname(type,sz))(t, h, o, a, c)
285 #define	__bs_set(type, sz, t, h, o, v, c)				\
286 	(*__bs_ops(t).__bs_opname(type,sz))(t, h, o, v, c)
287 #define	__bs_copy(sz, t, h1, o1, h2, o2, cnt)				\
288 	(*__bs_ops(t).__bs_opname(c,sz))(t, h1, o1, h2, o2, cnt)
289 
290 
291 /*
292  * Mapping and unmapping operations.
293  */
294 #define	bus_space_map(t, a, s, c, hp)					\
295 	(*__bs_ops(t).bs_map)(t, (a), (s), (c), (hp))
296 #define	bus_space_unmap(t, h, s)					\
297 	(*__bs_ops(t).bs_unmap)(t, (h), (s))
298 #define	bus_space_subregion(t, h, o, s, hp)				\
299 	(*__bs_ops(t).bs_subregion)(t, (h), (o), (s), (hp))
300 
301 
302 /*
303  * Allocation and deallocation operations.
304  */
305 #define	bus_space_alloc(t, rs, re, s, a, b, c, ap, hp)			\
306 	(*__bs_ops(t).bs_alloc)(t, (rs), (re), (s), (a), (b), (c), (ap), (hp))
307 #define	bus_space_free(t, h, s)						\
308 	(*__bs_ops(t).bs_free)(t, (h), (s))
309 
310 
311 /*
312  * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
313  */
314 #define	bus_space_vaddr(t, h)						\
315 	(*__bs_ops(t).bs_vaddr)(t, (h))
316 
317 
318 /*
319  * MMap bus space for a user application.
320  */
321 #define bus_space_mmap(t, a, o, p, f)					\
322 	(*__bs_ops(t).bs_mmap)(t, (a), (o), (p), (f))
323 
324 
325 /*
326  * Bus barrier operations.
327  */
328 #define	bus_space_barrier(t, h, o, l, f)				\
329 	(*__bs_ops(t).bs_barrier)(t, (h), (o), (l), (f))
330 
331 
332 /*
333  * Bus probe operations.
334  */
335 #define	bus_space_peek(t, h, o, s, p)					\
336 	(*__bs_ops(t).bs_peek)(t, (h), (o), (s), (p))
337 #define	bus_space_poke(t, h, o, s, v)					\
338 	(*__bs_ops(t).bs_poke)(t, (h), (o), (s), (v))
339 
340 
341 /*
342  * Bus read (single) operations.
343  */
344 #define	bus_space_read_1(t, h, o)	__bs_rs(1,(t),(h),(o))
345 #define	bus_space_read_2(t, h, o)	__bs_rs(2,(t),(h),(o))
346 #define	bus_space_read_4(t, h, o)	__bs_rs(4,(t),(h),(o))
347 #define	bus_space_read_8(t, h, o)	__bs_rs(8,(t),(h),(o))
348 
349 
350 /*
351  * Bus read multiple operations.
352  */
353 #define	bus_space_read_multi_1(t, h, o, a, c)				\
354 	__bs_nonsingle(rm,1,(t),(h),(o),(a),(c))
355 #define	bus_space_read_multi_2(t, h, o, a, c)				\
356 	__bs_nonsingle(rm,2,(t),(h),(o),(a),(c))
357 #define	bus_space_read_multi_4(t, h, o, a, c)				\
358 	__bs_nonsingle(rm,4,(t),(h),(o),(a),(c))
359 #define	bus_space_read_multi_8(t, h, o, a, c)				\
360 	__bs_nonsingle(rm,8,(t),(h),(o),(a),(c))
361 
362 
363 /*
364  * Bus read region operations.
365  */
366 #define	bus_space_read_region_1(t, h, o, a, c)				\
367 	__bs_nonsingle(rr,1,(t),(h),(o),(a),(c))
368 #define	bus_space_read_region_2(t, h, o, a, c)				\
369 	__bs_nonsingle(rr,2,(t),(h),(o),(a),(c))
370 #define	bus_space_read_region_4(t, h, o, a, c)				\
371 	__bs_nonsingle(rr,4,(t),(h),(o),(a),(c))
372 #define	bus_space_read_region_8(t, h, o, a, c)				\
373 	__bs_nonsingle(rr,8,(t),(h),(o),(a),(c))
374 
375 
376 /*
377  * Bus write (single) operations.
378  */
379 #define	bus_space_write_1(t, h, o, v)	__bs_ws(1,(t),(h),(o),(v))
380 #define	bus_space_write_2(t, h, o, v)	__bs_ws(2,(t),(h),(o),(v))
381 #define	bus_space_write_4(t, h, o, v)	__bs_ws(4,(t),(h),(o),(v))
382 #define	bus_space_write_8(t, h, o, v)	__bs_ws(8,(t),(h),(o),(v))
383 
384 
385 /*
386  * Bus write multiple operations.
387  */
388 #define	bus_space_write_multi_1(t, h, o, a, c)				\
389 	__bs_nonsingle(wm,1,(t),(h),(o),(a),(c))
390 #define	bus_space_write_multi_2(t, h, o, a, c)				\
391 	__bs_nonsingle(wm,2,(t),(h),(o),(a),(c))
392 #define	bus_space_write_multi_4(t, h, o, a, c)				\
393 	__bs_nonsingle(wm,4,(t),(h),(o),(a),(c))
394 #define	bus_space_write_multi_8(t, h, o, a, c)				\
395 	__bs_nonsingle(wm,8,(t),(h),(o),(a),(c))
396 
397 
398 /*
399  * Bus write region operations.
400  */
401 #define	bus_space_write_region_1(t, h, o, a, c)				\
402 	__bs_nonsingle(wr,1,(t),(h),(o),(a),(c))
403 #define	bus_space_write_region_2(t, h, o, a, c)				\
404 	__bs_nonsingle(wr,2,(t),(h),(o),(a),(c))
405 #define	bus_space_write_region_4(t, h, o, a, c)				\
406 	__bs_nonsingle(wr,4,(t),(h),(o),(a),(c))
407 #define	bus_space_write_region_8(t, h, o, a, c)				\
408 	__bs_nonsingle(wr,8,(t),(h),(o),(a),(c))
409 
410 
411 #ifdef BUS_SPACE_HAS_REAL_STREAM_METHODS
412 /*
413  * Bus read (single) stream operations.
414  */
415 #define	bus_space_read_stream_1(t, h, o)	__bs_rss(1,(t),(h),(o))
416 #define	bus_space_read_stream_2(t, h, o)	__bs_rss(2,(t),(h),(o))
417 #define	bus_space_read_stream_4(t, h, o)	__bs_rss(4,(t),(h),(o))
418 #define	bus_space_read_stream_8(t, h, o)	__bs_rss(8,(t),(h),(o))
419 
420 
421 /*
422  * Bus read multiple operations.
423  */
424 #define	bus_space_read_multi_stream_1(t, h, o, a, c)			\
425 	__bs_nonsingle(rms,1,(t),(h),(o),(a),(c))
426 #define	bus_space_read_multi_stream_2(t, h, o, a, c)			\
427 	__bs_nonsingle(rms,2,(t),(h),(o),(a),(c))
428 #define	bus_space_read_multi_stream_4(t, h, o, a, c)			\
429 	__bs_nonsingle(rms,4,(t),(h),(o),(a),(c))
430 #define	bus_space_read_multi_stream_8(t, h, o, a, c)			\
431 	__bs_nonsingle(rms,8,(t),(h),(o),(a),(c))
432 
433 
434 /*
435  * Bus read region operations.
436  */
437 #define	bus_space_read_region_stream_1(t, h, o, a, c)			\
438 	__bs_nonsingle(rrs,1,(t),(h),(o),(a),(c))
439 #define	bus_space_read_region_stream_2(t, h, o, a, c)			\
440 	__bs_nonsingle(rrs,2,(t),(h),(o),(a),(c))
441 #define	bus_space_read_region_stream_4(t, h, o, a, c)			\
442 	__bs_nonsingle(rrs,4,(t),(h),(o),(a),(c))
443 #define	bus_space_read_region_stream_8(t, h, o, a, c)			\
444 	__bs_nonsingle(rrs,8,(t),(h),(o),(a),(c))
445 
446 
447 /*
448  * Bus write (single) operations.
449  */
450 #define	bus_space_write_stream_1(t, h, o, v)	__bs_wss(1,(t),(h),(o),(v))
451 #define	bus_space_write_stream_2(t, h, o, v)	__bs_wss(2,(t),(h),(o),(v))
452 #define	bus_space_write_stream_4(t, h, o, v)	__bs_wss(4,(t),(h),(o),(v))
453 #define	bus_space_write_stream_8(t, h, o, v)	__bs_wss(8,(t),(h),(o),(v))
454 
455 
456 /*
457  * Bus write multiple operations.
458  */
459 #define	bus_space_write_multi_stream_1(t, h, o, a, c)			\
460 	__bs_nonsingle(wms,1,(t),(h),(o),(a),(c))
461 #define	bus_space_write_multi_stream_2(t, h, o, a, c)			\
462 	__bs_nonsingle(wms,2,(t),(h),(o),(a),(c))
463 #define	bus_space_write_multi_stream_4(t, h, o, a, c)			\
464 	__bs_nonsingle(wms,4,(t),(h),(o),(a),(c))
465 #define	bus_space_write_multi_stream_8(t, h, o, a, c)			\
466 	__bs_nonsingle(wms,8,(t),(h),(o),(a),(c))
467 
468 
469 /*
470  * Bus write region operations.
471  */
472 #define	bus_space_write_region_stream_1(t, h, o, a, c)			\
473 	__bs_nonsingle(wrs,1,(t),(h),(o),(a),(c))
474 #define	bus_space_write_region_stream_2(t, h, o, a, c)			\
475 	__bs_nonsingle(wrs,2,(t),(h),(o),(a),(c))
476 #define	bus_space_write_region_stream_4(t, h, o, a, c)			\
477 	__bs_nonsingle(wrs,4,(t),(h),(o),(a),(c))
478 #define	bus_space_write_region_stream_8(t, h, o, a, c)			\
479 	__bs_nonsingle(wrs,8,(t),(h),(o),(a),(c))
480 #else
481 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
482 #define bus_space_read_stream_1 bus_space_read_1
483 #define bus_space_read_stream_2 bus_space_read_2
484 #define bus_space_read_stream_4 bus_space_read_4
485 #define	bus_space_read_stream_8 bus_space_read_8
486 #define bus_space_read_multi_stream_1 bus_space_read_multi_1
487 #define bus_space_read_multi_stream_2 bus_space_read_multi_2
488 #define bus_space_read_multi_stream_4 bus_space_read_multi_4
489 #define	bus_space_read_multi_stream_8 bus_space_read_multi_8
490 #define bus_space_read_region_stream_1 bus_space_read_region_1
491 #define bus_space_read_region_stream_2 bus_space_read_region_2
492 #define bus_space_read_region_stream_4 bus_space_read_region_4
493 #define	bus_space_read_region_stream_8 bus_space_read_region_8
494 #define bus_space_write_stream_1 bus_space_write_1
495 #define bus_space_write_stream_2 bus_space_write_2
496 #define bus_space_write_stream_4 bus_space_write_4
497 #define	bus_space_write_stream_8 bus_space_write_8
498 #define bus_space_write_multi_stream_1 bus_space_write_multi_1
499 #define bus_space_write_multi_stream_2 bus_space_write_multi_2
500 #define bus_space_write_multi_stream_4 bus_space_write_multi_4
501 #define	bus_space_write_multi_stream_8 bus_space_write_multi_8
502 #define bus_space_write_region_stream_1 bus_space_write_region_1
503 #define bus_space_write_region_stream_2 bus_space_write_region_2
504 #define bus_space_write_region_stream_4 bus_space_write_region_4
505 #define	bus_space_write_region_stream_8	bus_space_write_region_8
506 #endif /* __BUS_SPACE_HAS_STREAM_METHODS */
507 #endif /* BUS_SPACE_HAS_REAL_STREAM_METHODS */
508 
509 
510 /*
511  * Set multiple operations.
512  */
513 #define	bus_space_set_multi_1(t, h, o, v, c)				\
514 	__bs_set(sm,1,(t),(h),(o),(v),(c))
515 #define	bus_space_set_multi_2(t, h, o, v, c)				\
516 	__bs_set(sm,2,(t),(h),(o),(v),(c))
517 #define	bus_space_set_multi_4(t, h, o, v, c)				\
518 	__bs_set(sm,4,(t),(h),(o),(v),(c))
519 #define	bus_space_set_multi_8(t, h, o, v, c)				\
520 	__bs_set(sm,8,(t),(h),(o),(v),(c))
521 
522 
523 /*
524  * Set region operations.
525  */
526 #define	bus_space_set_region_1(t, h, o, v, c)				\
527 	__bs_set(sr,1,(t),(h),(o),(v),(c))
528 #define	bus_space_set_region_2(t, h, o, v, c)				\
529 	__bs_set(sr,2,(t),(h),(o),(v),(c))
530 #define	bus_space_set_region_4(t, h, o, v, c)				\
531 	__bs_set(sr,4,(t),(h),(o),(v),(c))
532 #define	bus_space_set_region_8(t, h, o, v, c)				\
533 	__bs_set(sr,8,(t),(h),(o),(v),(c))
534 
535 
536 /*
537  * Copy operations.
538  */
539 #define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)			\
540 	__bs_copy(1, t, h1, o1, h2, o2, c)
541 #define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)			\
542 	__bs_copy(2, t, h1, o1, h2, o2, c)
543 #define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)			\
544 	__bs_copy(4, t, h1, o1, h2, o2, c)
545 #define	bus_space_copy_region_8(t, h1, o1, h2, o2, c)			\
546 	__bs_copy(8, t, h1, o1, h2, o2, c)
547 
548 
549 /*
550  * Macros to provide prototypes for all the functions used in the
551  * bus_space structure
552  */
553 #define bs_map_proto(f)							\
554 int	__bs_c(f,_bs_map)(bus_space_tag_t t, bus_addr_t addr,		\
555 	    bus_size_t size, int cacheable, bus_space_handle_t *bshp)
556 
557 #define bs_unmap_proto(f)						\
558 void	__bs_c(f,_bs_unmap)(bus_space_tag_t t, bus_space_handle_t bsh,	\
559 	    bus_size_t size)
560 
561 #define bs_subregion_proto(f)						\
562 int	__bs_c(f,_bs_subregion)(bus_space_tag_t t,			\
563 	    bus_space_handle_t bsh, bus_size_t offset,			\
564 	    bus_size_t size, bus_space_handle_t *nbshp)
565 
566 #define bs_alloc_proto(f)						\
567 int	__bs_c(f,_bs_alloc)(bus_space_tag_t t, bus_addr_t rstart,	\
568 	    bus_addr_t rend, bus_size_t size, bus_size_t align,		\
569 	    bus_size_t boundary, int cacheable, bus_addr_t *addrp,	\
570 	    bus_space_handle_t *bshp)
571 
572 #define bs_free_proto(f)						\
573 void	__bs_c(f,_bs_free)(bus_space_tag_t t, bus_space_handle_t bsh,	\
574 	    bus_size_t size)
575 
576 #define bs_vaddr_proto(f)						\
577 void *	__bs_c(f,_bs_vaddr)(bus_space_tag_t t, bus_space_handle_t bsh)
578 
579 #define bs_mmap_proto(f)						\
580 paddr_t	__bs_c(f,_bs_mmap)(bus_space_tag_t t, bus_addr_t addr,		\
581 	    off_t offset, int prot, int flags)
582 
583 #define bs_barrier_proto(f)						\
584 void	__bs_c(f,_bs_barrier)(bus_space_tag_t t, bus_space_handle_t bsh,\
585 	    bus_size_t offset, bus_size_t len, int flags)
586 
587 #define bs_peek_proto(f)						\
588 int	__bs_c(f,_bs_peek)(bus_space_tag_t t, bus_space_handle_t bsh,	\
589 	    bus_size_t offset, size_t len, void *ptr)
590 #define bs_poke_proto(f)						\
591 int	__bs_c(f,_bs_poke)(bus_space_tag_t t, bus_space_handle_t bsh,	\
592 	    bus_size_t offset, size_t len, u_int32_t val)
593 
594 #define	bs_r_1_proto(f)							\
595 u_int8_t	__bs_c(f,_bs_r_1)(bus_space_tag_t t,			\
596 		    bus_space_handle_t bsh, bus_size_t offset)
597 #define	bs_r_2_proto(f)							\
598 u_int16_t	__bs_c(f,_bs_r_2)(bus_space_tag_t t,			\
599 		    bus_space_handle_t bsh, bus_size_t offset)
600 #define	bs_r_4_proto(f)							\
601 u_int32_t	__bs_c(f,_bs_r_4)(bus_space_tag_t t,			\
602 		    bus_space_handle_t bsh, bus_size_t offset)
603 #define	bs_r_8_proto(f)							\
604 u_int64_t	__bs_c(f,_bs_r_8)(bus_space_tag_t t,			\
605 		    bus_space_handle_t bsh, bus_size_t offset)
606 
607 #define	bs_rm_1_proto(f)						\
608 void	__bs_c(f,_bs_rm_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
609 	    bus_size_t offset, u_int8_t *addr,	bus_size_t count)
610 #define	bs_rm_2_proto(f)						\
611 void	__bs_c(f,_bs_rm_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
612 	    bus_size_t offset, u_int16_t *addr,	bus_size_t count)
613 #define	bs_rm_4_proto(f)						\
614 void	__bs_c(f,_bs_rm_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
615 	    bus_size_t offset, u_int32_t *addr,	bus_size_t count)
616 #define	bs_rm_8_proto(f)						\
617 void	__bs_c(f,_bs_rm_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
618 	    bus_size_t offset, u_int64_t *addr,	bus_size_t count)
619 
620 #define	bs_rr_1_proto(f)						\
621 void	__bs_c(f,_bs_rr_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
622 	   bus_size_t offset, u_int8_t *addr, bus_size_t count)
623 #define	bs_rr_2_proto(f)						\
624 void	__bs_c(f,_bs_rr_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
625 	   bus_size_t offset, u_int16_t *addr, bus_size_t count)
626 #define	bs_rr_4_proto(f)						\
627 void	__bs_c(f,_bs_rr_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
628 	   bus_size_t offset, u_int32_t *addr, bus_size_t count)
629 #define	bs_rr_8_proto(f)						\
630 void	__bs_c(f,_bs_rr_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
631 	   bus_size_t offset, u_int64_t *addr, bus_size_t count)
632 
633 #define	bs_w_1_proto(f)							\
634 void	__bs_c(f,_bs_w_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
635 	    bus_size_t offset, u_int8_t value)
636 #define	bs_w_2_proto(f)							\
637 void	__bs_c(f,_bs_w_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
638 	    bus_size_t offset, u_int16_t value)
639 #define	bs_w_4_proto(f)							\
640 void	__bs_c(f,_bs_w_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
641 	    bus_size_t offset, u_int32_t value)
642 #define	bs_w_8_proto(f)							\
643 void	__bs_c(f,_bs_w_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
644 	    bus_size_t offset, u_int64_t value)
645 
646 #define	bs_wm_1_proto(f)						\
647 void	__bs_c(f,_bs_wm_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
648 	   bus_size_t offset, const u_int8_t *addr, bus_size_t count)
649 #define	bs_wm_2_proto(f)						\
650 void	__bs_c(f,_bs_wm_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
651 	   bus_size_t offset, const u_int16_t *addr, bus_size_t count)
652 #define	bs_wm_4_proto(f)						\
653 void	__bs_c(f,_bs_wm_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
654 	   bus_size_t offset, const u_int32_t *addr, bus_size_t count)
655 #define	bs_wm_8_proto(f)						\
656 void	__bs_c(f,_bs_wm_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
657 	   bus_size_t offset, const u_int64_t *addr, bus_size_t count)
658 
659 #define	bs_wr_1_proto(f)						\
660 void	__bs_c(f,_bs_wr_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
661 	    bus_size_t offset, const u_int8_t *addr, bus_size_t count)
662 #define	bs_wr_2_proto(f)						\
663 void	__bs_c(f,_bs_wr_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
664 	    bus_size_t offset, const u_int16_t *addr, bus_size_t count)
665 #define	bs_wr_4_proto(f)						\
666 void	__bs_c(f,_bs_wr_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
667 	    bus_size_t offset, const u_int32_t *addr, bus_size_t count)
668 #define	bs_wr_8_proto(f)						\
669 void	__bs_c(f,_bs_wr_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
670 	    bus_size_t offset, const u_int64_t *addr, bus_size_t count)
671 
672 #ifdef BUS_SPACE_HAS_REAL_STREAM_METHODS
673 #define	bs_rs_1_proto(f)						\
674 u_int8_t	__bs_c(f,_bs_rs_1)(bus_space_tag_t t,			\
675 		    bus_space_handle_t bsh, bus_size_t offset)
676 #define	bs_rs_2_proto(f)						\
677 u_int16_t	__bs_c(f,_bs_rs_2)(bus_space_tag_t t,			\
678 		    bus_space_handle_t bsh, bus_size_t offset)
679 #define	bs_rs_4_proto(f)						\
680 u_int32_t	__bs_c(f,_bs_rs_4)(bus_space_tag_t t,			\
681 		    bus_space_handle_t bsh, bus_size_t offset)
682 #define	bs_rs_8_proto(f)						\
683 u_int64_t	__bs_c(f,_bs_rs_8)(bus_space_tag_t t,			\
684 		    bus_space_handle_t bsh, bus_size_t offset)
685 
686 #define	bs_rms_1_proto(f)						\
687 void	__bs_c(f,_bs_rms_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
688 	    bus_size_t offset, u_int8_t *addr,	bus_size_t count)
689 #define	bs_rms_2_proto(f)						\
690 void	__bs_c(f,_bs_rms_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
691 	    bus_size_t offset, u_int16_t *addr,	bus_size_t count)
692 #define	bs_rms_4_proto(f)						\
693 void	__bs_c(f,_bs_rms_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
694 	    bus_size_t offset, u_int32_t *addr,	bus_size_t count)
695 #define	bs_rms_8_proto(f)						\
696 void	__bs_c(f,_bs_rms_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
697 	    bus_size_t offset, u_int64_t *addr,	bus_size_t count)
698 
699 #define	bs_rrs_1_proto(f)						\
700 void	__bs_c(f,_bs_rrs_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
701 	   bus_size_t offset, u_int8_t *addr, bus_size_t count)
702 #define	bs_rrs_2_proto(f)						\
703 void	__bs_c(f,_bs_rrs_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
704 	   bus_size_t offset, u_int16_t *addr, bus_size_t count)
705 #define	bs_rrs_4_proto(f)						\
706 void	__bs_c(f,_bs_rrs_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
707 	   bus_size_t offset, u_int32_t *addr, bus_size_t count)
708 #define	bs_rrs_8_proto(f)						\
709 void	__bs_c(f,_bs_rrs_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
710 	   bus_size_t offset, u_int64_t *addr, bus_size_t count)
711 
712 #define	bs_ws_1_proto(f)						\
713 void	__bs_c(f,_bs_ws_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
714 	    bus_size_t offset, u_int8_t value)
715 #define	bs_ws_2_proto(f)						\
716 void	__bs_c(f,_bs_ws_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
717 	    bus_size_t offset, u_int16_t value)
718 #define	bs_ws_4_proto(f)						\
719 void	__bs_c(f,_bs_ws_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
720 	    bus_size_t offset, u_int32_t value)
721 #define	bs_ws_8_proto(f)						\
722 void	__bs_c(f,_bs_ws_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
723 	    bus_size_t offset, u_int64_t value)
724 
725 #define	bs_wms_1_proto(f)						\
726 void	__bs_c(f,_bs_wms_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
727 	   bus_size_t offset, const u_int8_t *addr, bus_size_t count)
728 #define	bs_wms_2_proto(f)						\
729 void	__bs_c(f,_bs_wms_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
730 	   bus_size_t offset, const u_int16_t *addr, bus_size_t count)
731 #define	bs_wms_4_proto(f)						\
732 void	__bs_c(f,_bs_wms_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
733 	   bus_size_t offset, const u_int32_t *addr, bus_size_t count)
734 #define	bs_wms_8_proto(f)						\
735 void	__bs_c(f,_bs_wms_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
736 	   bus_size_t offset, const u_int64_t *addr, bus_size_t count)
737 
738 #define	bs_wrs_1_proto(f)						\
739 void	__bs_c(f,_bs_wrs_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
740 	    bus_size_t offset, const u_int8_t *addr, bus_size_t count)
741 #define	bs_wrs_2_proto(f)						\
742 void	__bs_c(f,_bs_wrs_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
743 	    bus_size_t offset, const u_int16_t *addr, bus_size_t count)
744 #define	bs_wrs_4_proto(f)						\
745 void	__bs_c(f,_bs_wrs_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
746 	    bus_size_t offset, const u_int32_t *addr, bus_size_t count)
747 #define	bs_wrs_8_proto(f)						\
748 void	__bs_c(f,_bs_wrs_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
749 	    bus_size_t offset, const u_int64_t *addr, bus_size_t count)
750 #else /* BUS_SPACE_HAS_REAL_STREAM_METHODS */
751 #define	bs_rs_1_proto(f)
752 #define	bs_rs_2_proto(f)
753 #define	bs_rs_4_proto(f)
754 #define	bs_rs_8_proto(f)
755 #define	bs_rms_1_proto(f)
756 #define	bs_rms_2_proto(f)
757 #define	bs_rms_4_proto(f)
758 #define	bs_rms_8_proto(f)
759 #define	bs_rrs_1_proto(f)
760 #define	bs_rrs_2_proto(f)
761 #define	bs_rrs_4_proto(f)
762 #define	bs_rrs_8_proto(f)
763 #define	bs_ws_1_proto(f)
764 #define	bs_ws_2_proto(f)
765 #define	bs_ws_4_proto(f)
766 #define	bs_ws_8_proto(f)
767 #define	bs_wms_1_proto(f)
768 #define	bs_wms_2_proto(f)
769 #define	bs_wms_4_proto(f)
770 #define	bs_wms_8_proto(f)
771 #define	bs_wrs_1_proto(f)
772 #define	bs_wrs_2_proto(f)
773 #define	bs_wrs_4_proto(f)
774 #define	bs_wrs_8_proto(f)
775 #endif /* ! BUS_SPACE_HAS_REAL_STREAM_METHODS */
776 
777 #define	bs_sm_1_proto(f)						\
778 void	__bs_c(f,_bs_sm_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
779 	    bus_size_t offset, u_int8_t value, bus_size_t count)
780 #define	bs_sm_2_proto(f)						\
781 void	__bs_c(f,_bs_sm_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
782 	    bus_size_t offset, u_int16_t value, bus_size_t count)
783 #define	bs_sm_4_proto(f)						\
784 void	__bs_c(f,_bs_sm_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
785 	    bus_size_t offset, u_int32_t value, bus_size_t count)
786 #define	bs_sm_8_proto(f)						\
787 void	__bs_c(f,_bs_sm_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
788 	    bus_size_t offset, u_int64_t value, bus_size_t count)
789 
790 #define	bs_sr_1_proto(f)						\
791 void	__bs_c(f,_bs_sr_1)(bus_space_tag_t t, bus_space_handle_t bsh,	\
792 	    bus_size_t offset, u_int8_t value, bus_size_t count)
793 #define	bs_sr_2_proto(f)						\
794 void	__bs_c(f,_bs_sr_2)(bus_space_tag_t t, bus_space_handle_t bsh,	\
795 	    bus_size_t offset, u_int16_t value, bus_size_t count)
796 #define	bs_sr_4_proto(f)						\
797 void	__bs_c(f,_bs_sr_4)(bus_space_tag_t t, bus_space_handle_t bsh,	\
798 	    bus_size_t offset, u_int32_t value, bus_size_t count)
799 #define	bs_sr_8_proto(f)						\
800 void	__bs_c(f,_bs_sr_8)(bus_space_tag_t t, bus_space_handle_t bsh,	\
801 	    bus_size_t offset, u_int64_t value, bus_size_t count)
802 
803 #define	bs_c_1_proto(f)							\
804 void	__bs_c(f,_bs_c_1)(bus_space_tag_t t, bus_space_handle_t bsh1,	\
805 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
806 	    bus_size_t offset2, bus_size_t count)
807 #define	bs_c_2_proto(f)							\
808 void	__bs_c(f,_bs_c_2)(bus_space_tag_t t, bus_space_handle_t bsh1,	\
809 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
810 	    bus_size_t offset2, bus_size_t count)
811 #define	bs_c_4_proto(f)							\
812 void	__bs_c(f,_bs_c_4)(bus_space_tag_t t, bus_space_handle_t bsh1,	\
813 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
814 	    bus_size_t offset2, bus_size_t count)
815 #define	bs_c_8_proto(f)							\
816 void	__bs_c(f,_bs_c_8)(bus_space_tag_t t, bus_space_handle_t bsh1,	\
817 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
818 	    bus_size_t offset2, bus_size_t count)
819 
820 
821 #define bus_space_protos(f)	\
822 bs_map_proto(f);		\
823 bs_unmap_proto(f);		\
824 bs_subregion_proto(f);		\
825 bs_alloc_proto(f);		\
826 bs_free_proto(f);		\
827 bs_vaddr_proto(f);		\
828 bs_mmap_proto(f);		\
829 bs_barrier_proto(f);		\
830 bs_peek_proto(f);		\
831 bs_poke_proto(f);		\
832 bs_r_1_proto(f);		\
833 bs_r_2_proto(f);		\
834 bs_r_4_proto(f);		\
835 bs_r_8_proto(f);		\
836 bs_rm_1_proto(f);		\
837 bs_rm_2_proto(f);		\
838 bs_rm_4_proto(f);		\
839 bs_rm_8_proto(f);		\
840 bs_rr_1_proto(f);		\
841 bs_rr_2_proto(f);		\
842 bs_rr_4_proto(f);		\
843 bs_rr_8_proto(f);		\
844 bs_w_1_proto(f);		\
845 bs_w_2_proto(f);		\
846 bs_w_4_proto(f);		\
847 bs_w_8_proto(f);		\
848 bs_wm_1_proto(f);		\
849 bs_wm_2_proto(f);		\
850 bs_wm_4_proto(f);		\
851 bs_wm_8_proto(f);		\
852 bs_wr_1_proto(f);		\
853 bs_wr_2_proto(f);		\
854 bs_wr_4_proto(f);		\
855 bs_wr_8_proto(f);		\
856 bs_rs_1_proto(f);		\
857 bs_rs_2_proto(f);		\
858 bs_rs_4_proto(f);		\
859 bs_rs_8_proto(f);		\
860 bs_rms_1_proto(f);		\
861 bs_rms_2_proto(f);		\
862 bs_rms_4_proto(f);		\
863 bs_rms_8_proto(f);		\
864 bs_rrs_1_proto(f);		\
865 bs_rrs_2_proto(f);		\
866 bs_rrs_4_proto(f);		\
867 bs_rrs_8_proto(f);		\
868 bs_ws_1_proto(f);		\
869 bs_ws_2_proto(f);		\
870 bs_ws_4_proto(f);		\
871 bs_ws_8_proto(f);		\
872 bs_wms_1_proto(f);		\
873 bs_wms_2_proto(f);		\
874 bs_wms_4_proto(f);		\
875 bs_wms_8_proto(f);		\
876 bs_wrs_1_proto(f);		\
877 bs_wrs_2_proto(f);		\
878 bs_wrs_4_proto(f);		\
879 bs_wrs_8_proto(f);		\
880 bs_sm_1_proto(f);		\
881 bs_sm_2_proto(f);		\
882 bs_sm_4_proto(f);		\
883 bs_sm_8_proto(f);		\
884 bs_sr_1_proto(f);		\
885 bs_sr_2_proto(f);		\
886 bs_sr_4_proto(f);		\
887 bs_sr_8_proto(f);		\
888 bs_c_1_proto(f);		\
889 bs_c_2_proto(f);		\
890 bs_c_4_proto(f);		\
891 bs_c_8_proto(f);
892 
893 #endif /* ! BUS_SPACE_MD_CALLS */
894 
895 #ifndef BUS_SPACE_MD_TYPES
896 #ifdef BUS_SPACE_MD_CALLS
897 typedef struct bus_space *bus_space_tag_t;
898 #endif /* BUS_SPACE_MD_CALLS */
899 
900 /*
901  *	bus_space_tag_t
902  *
903  *	bus space tag structure
904  */
905 struct bus_space_tag {
906 	bus_space_tag_t bs_base;
907 	struct bus_space_ops bs_ops;
908 };
909 #endif /* ! BUS_SPACE_MD_TYPES */
910 
911 #ifndef BUS_DMA_MD_CALLS
912 
913 /*
914  * Flags used in various bus DMA methods.
915  */
916 #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
917 #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
918 #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
919 #define	BUS_DMA_COHERENT	0x004	/* hint: map memory DMA coherent */
920 #define	BUS_DMA_STREAMING	0x008	/* hint: sequential, unidirectional */
921 #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
922 #define	BUS_DMA_BUS2		0x020
923 #define	BUS_DMA_BUS3		0x040
924 #define	BUS_DMA_BUS4		0x080
925 #define	BUS_DMA_READ		0x100	/* mapping is device -> memory only */
926 #define	BUS_DMA_WRITE		0x200	/* mapping is memory -> device only */
927 #define	BUS_DMA_NOCACHE		0x400	/* hint: map non-cached memory */
928 
929 /*
930  * Operations performed by bus_dmamap_sync().
931  */
932 #define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
933 #define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
934 #define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
935 #define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
936 
937 /* Forwards needed by prototypes below. */
938 struct mbuf;
939 struct uio;
940 
941 #ifndef BUS_DMA_MD_TYPES
942 typedef struct bus_dma_tag	*bus_dma_tag_t;
943 typedef struct bus_dma_segment	bus_dma_segment_t;
944 typedef struct bus_dmamap	*bus_dmamap_t;
945 #endif /* ! BUS_DMA_MD_TYPES */
946 
947 #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
948 
949 /*
950  * bus DMA operation table
951  */
952 struct bus_dma_ops {
953 	/*
954 	 * DMA mapping methods.
955 	 */
956 	int	(*bd_map_create)(bus_dma_tag_t, bus_size_t, int,
957 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
958 	void	(*bd_map_destroy)(bus_dma_tag_t, bus_dmamap_t);
959 	int	(*bd_map_load)(bus_dma_tag_t, bus_dmamap_t, void *,
960 		    bus_size_t, struct proc *, int);
961 	int	(*bd_map_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
962 		    struct mbuf *, int);
963 	int	(*bd_map_load_uio)(bus_dma_tag_t, bus_dmamap_t,
964 		    struct uio *, int);
965 	int	(*bd_map_load_raw)(bus_dma_tag_t, bus_dmamap_t,
966 		    bus_dma_segment_t *, int, bus_size_t, int);
967 	void	(*bd_map_unload)(bus_dma_tag_t, bus_dmamap_t);
968 	void	(*bd_map_sync)(bus_dma_tag_t, bus_dmamap_t,
969 		    bus_addr_t, bus_size_t, int);
970 
971 	/*
972 	 * DMA memory utility functions.
973 	 */
974 	int	(*bd_mem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
975 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
976 	void	(*bd_mem_free)(bus_dma_tag_t,
977 		    bus_dma_segment_t *, int);
978 	int	(*bd_mem_map)(bus_dma_tag_t, bus_dma_segment_t *,
979 		    int, size_t, void **, int);
980 	void	(*bd_mem_unmap)(bus_dma_tag_t, void *, size_t);
981 	paddr_t	(*bd_mem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
982 		    int, off_t, int, int);
983 };
984 
985 
986 /*
987  * bus DMA methods
988  */
989 #define	__bd_ops(t)	(((bus_dma_tag_t)(t))->bd_ops)
990 #define	bus_dmamap_create(t, s, n, m, b, f, p)				\
991 	(*__bd_ops(t).bd_map_create)((t), (s), (n), (m), (b), (f), (p))
992 #define	bus_dmamap_destroy(t, p)					\
993 	(*__bd_ops(t).bd_map_destroy)((t), (p))
994 #define	bus_dmamap_load(t, m, b, s, p, f)				\
995 	(*__bd_ops(t).bd_map_load)((t), (m), (b), (s), (p), (f))
996 #define	bus_dmamap_load_mbuf(t, m, b, f)				\
997 	(*__bd_ops(t).bd_map_load_mbuf)((t), (m), (b), (f))
998 #define	bus_dmamap_load_uio(t, m, u, f)					\
999 	(*__bd_ops(t).bd_map_load_uio)((t), (m), (u), (f))
1000 #define	bus_dmamap_load_raw(t, m, sg, n, s, f)				\
1001 	(*__bd_ops(t).bd_map_load_raw)((t), (m), (sg), (n), (s), (f))
1002 #define	bus_dmamap_unload(t, p)						\
1003 	(*__bd_ops(t).bd_map_unload)((t), (p))
1004 #define	bus_dmamap_sync(t, p, o, l, ops)				\
1005 	(void)(__bd_ops(t).bd_map_sync ?				\
1006 	    (*__bd_ops(t).bd_map_sync)((t), (p), (o), (l), (ops)) : (void)0)
1007 
1008 #define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)			\
1009 	(*__bd_ops(t).bd_mem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
1010 #define	bus_dmamem_free(t, sg, n)					\
1011 	(*__bd_ops(t).bd_mem_free)((t), (sg), (n))
1012 #define	bus_dmamem_map(t, sg, n, s, k, f)				\
1013 	(*__bd_ops(t).bd_mem_map)((t), (sg), (n), (s), (k), (f))
1014 #define	bus_dmamem_unmap(t, k, s)					\
1015 	(*__bd_ops(t).bd_mem_unmap)((t), (k), (s))
1016 #define	bus_dmamem_mmap(t, sg, n, o, p, f)				\
1017 	(*__bd_ops(t).bd_mem_mmap)((t), (sg), (n), (o), (p), (f))
1018 
1019 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
1020 #define bus_dmatag_destroy(t)
1021 
1022 /*
1023  * Macros to provide prototypes for all the functions used in the
1024  * bus_dma structure
1025  */
1026 #define bus_dma_protos(f)						\
1027 int	__bs_c(f,_bd_map_create)(bus_dma_tag_t, bus_size_t, int,	\
1028 	    bus_size_t, bus_size_t, int, bus_dmamap_t *);		\
1029 void	__bs_c(f,_bd_map_destroy)(bus_dma_tag_t, bus_dmamap_t);		\
1030 int	__bs_c(f,_bd_map_load)(bus_dma_tag_t, bus_dmamap_t, void *,	\
1031 	    bus_size_t, struct proc *, int);				\
1032 int	__bs_c(f,_bd_map_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,	\
1033 	    struct mbuf *, int);					\
1034 int	__bs_c(f,_bd_map_load_uio)(bus_dma_tag_t, bus_dmamap_t,		\
1035 	    struct uio *, int);						\
1036 int	__bs_c(f,_bd_map_load_raw)(bus_dma_tag_t, bus_dmamap_t,		\
1037 	    bus_dma_segment_t *, int, bus_size_t, int);			\
1038 void	__bs_c(f,_bd_map_unload)(bus_dma_tag_t, bus_dmamap_t);		\
1039 void	__bs_c(f,_bd_map_sync)(bus_dma_tag_t, bus_dmamap_t,		\
1040 	    bus_addr_t, bus_size_t, int);				\
1041 int	__bs_c(f,_bd_mem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,	\
1042 	    bus_size_t, bus_dma_segment_t *, int, int *, int);		\
1043 void	__bs_c(f,_bd_mem_free)(bus_dma_tag_t, bus_dma_segment_t *, int);\
1044 int	__bs_c(f,_bd_mem_map)(bus_dma_tag_t, bus_dma_segment_t *,	\
1045 	    int, size_t, void **, int);				\
1046 void	__bs_c(f,_bd_mem_unmap)(bus_dma_tag_t, void *, size_t);	\
1047 paddr_t	__bs_c(f,_bd_mem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,	\
1048 	    int, off_t, int, int);
1049 
1050 #endif /* ! BUS_DMA_MD_CALLS */
1051 
1052 #ifndef BUS_DMA_MD_TYPES
1053 #ifdef BUS_DMA_MD_CALLS
1054 typedef struct bus_dma_tag	*bus_dma_tag_t;
1055 typedef struct bus_dma_segment	bus_dma_segment_t;
1056 typedef struct bus_dmamap	*bus_dmamap_t;
1057 #endif /* ! BUS_DMA_MD_CALLS */
1058 
1059 /*
1060  *	bus_dma_tag
1061  *
1062  *	Describes a implementation of DMA for a given bus.
1063  */
1064 struct bus_dma_tag {
1065 	bus_dma_tag_t bd_base;
1066 	struct bus_dma_ops bd_ops;
1067 };
1068 
1069 /*
1070  *	bus_dma_segment
1071  *
1072  *	Describes a single contiguous DMA transaction.
1073  */
1074 struct bus_dma_segment {
1075 	bus_addr_t	ds_addr;	/* DMA address */
1076 	bus_size_t	ds_len;		/* length of transfer */
1077 };
1078 
1079 /*
1080  *	bus_dmamap
1081  *
1082  *	Describes a DMA mapping.
1083  */
1084 struct bus_dmamap {
1085 	bus_size_t	dm_maxsegsz;	/* largest possible segment */
1086 	bus_size_t	dm_mapsize;	/* size of the mapping */
1087 	int		dm_nsegs;	/* # valid segments in mapping */
1088 	bus_dma_segment_t *dm_segs;	/* segments; variable length */
1089 };
1090 
1091 #endif /* ! BUS_DMA_MD_TYPES */
1092 
1093 #include <machine/bus_machdep.h>
1094 
1095 #endif /* _HPCMIPS_BUS_H_ */
1096