xref: /freebsd/sys/arm/include/bus.h (revision 1f4bcc459a76b7aa664f3fd557684cd0ba6da352)
1 /*	$NetBSD: bus.h,v 1.11 2003/07/28 17:35:54 thorpej 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  * $FreeBSD$
64  */
65 
66 #ifndef _MACHINE_BUS_H_
67 #define _MACHINE_BUS_H_
68 
69 #include <machine/_bus.h>
70 #include <machine/acle-compat.h>
71 
72 /*
73  *	int bus_space_map  (bus_space_tag_t t, bus_addr_t addr,
74  *	    bus_size_t size, int flags, bus_space_handle_t *bshp);
75  *
76  * Map a region of bus space.
77  */
78 
79 #define	BUS_SPACE_MAP_CACHEABLE		0x01
80 #define	BUS_SPACE_MAP_LINEAR		0x02
81 #define	BUS_SPACE_MAP_PREFETCHABLE     	0x04
82 
83 /*
84  * Bus space for ARM.
85  *
86  * The functions used most often are grouped together at the beginning to ensure
87  * that all the data fits into a single cache line.  The inline implementations
88  * of single read/write access these values a lot.
89  */
90 struct bus_space {
91 	/* Read/write single and barrier: the most commonly used functions. */
92 	uint8_t	 (*bs_r_1)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
93 	uint32_t (*bs_r_4)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
94 	void	 (*bs_w_1)(bus_space_tag_t, bus_space_handle_t,
95 			   bus_size_t, uint8_t);
96 	void	 (*bs_w_4)(bus_space_tag_t, bus_space_handle_t,
97 			   bus_size_t, uint32_t);
98 	void	 (*bs_barrier)(bus_space_tag_t, bus_space_handle_t,
99 			       bus_size_t, bus_size_t, int);
100 
101 	/* Backlink to parent (if copied), and implementation private data. */
102 	struct bus_space *bs_parent;
103 	void		 *bs_privdata;
104 
105 	/* mapping/unmapping */
106 	int		(*bs_map) (bus_space_tag_t, bus_addr_t, bus_size_t,
107 			    int, bus_space_handle_t *);
108 	void		(*bs_unmap) (bus_space_tag_t, bus_space_handle_t, bus_size_t);
109 	int		(*bs_subregion) (bus_space_tag_t, bus_space_handle_t,
110 			    bus_size_t, bus_size_t, bus_space_handle_t *);
111 
112 	/* allocation/deallocation */
113 	int		(*bs_alloc) (bus_space_tag_t, bus_addr_t, bus_addr_t,
114 			    bus_size_t, bus_size_t, bus_size_t, int,
115 			    bus_addr_t *, bus_space_handle_t *);
116 	void		(*bs_free) (bus_space_tag_t, bus_space_handle_t,
117 			    bus_size_t);
118 
119 	/* Read single, the less commonly used functions. */
120 	uint16_t	(*bs_r_2) (bus_space_tag_t, bus_space_handle_t, bus_size_t);
121 	uint64_t	(*bs_r_8) (bus_space_tag_t, bus_space_handle_t, bus_size_t);
122 
123 	/* read multiple */
124 	void		(*bs_rm_1) (bus_space_tag_t, bus_space_handle_t, bus_size_t,
125 	    uint8_t *, bus_size_t);
126 	void		(*bs_rm_2) (bus_space_tag_t, bus_space_handle_t, bus_size_t,
127 	    uint16_t *, bus_size_t);
128 	void		(*bs_rm_4) (bus_space_tag_t, bus_space_handle_t,
129 			    bus_size_t, uint32_t *, bus_size_t);
130 	void		(*bs_rm_8) (bus_space_tag_t, bus_space_handle_t,
131 			    bus_size_t, uint64_t *, bus_size_t);
132 
133 	/* read region */
134 	void		(*bs_rr_1) (bus_space_tag_t, bus_space_handle_t,
135 			    bus_size_t, uint8_t *, bus_size_t);
136 	void		(*bs_rr_2) (bus_space_tag_t, bus_space_handle_t,
137 			    bus_size_t, uint16_t *, bus_size_t);
138 	void		(*bs_rr_4) (bus_space_tag_t, bus_space_handle_t,
139 			    bus_size_t, uint32_t *, bus_size_t);
140 	void		(*bs_rr_8) (bus_space_tag_t, bus_space_handle_t,
141 			    bus_size_t, uint64_t *, bus_size_t);
142 
143 	/* Write single, the less commonly used functions. */
144 	void		(*bs_w_2) (bus_space_tag_t, bus_space_handle_t,
145 			    bus_size_t, uint16_t);
146 	void		(*bs_w_8) (bus_space_tag_t, bus_space_handle_t,
147 			    bus_size_t, uint64_t);
148 
149 	/* write multiple */
150 	void		(*bs_wm_1) (bus_space_tag_t, bus_space_handle_t,
151 			    bus_size_t, const uint8_t *, bus_size_t);
152 	void		(*bs_wm_2) (bus_space_tag_t, bus_space_handle_t,
153 			    bus_size_t, const uint16_t *, bus_size_t);
154 	void		(*bs_wm_4) (bus_space_tag_t, bus_space_handle_t,
155 			    bus_size_t, const uint32_t *, bus_size_t);
156 	void		(*bs_wm_8) (bus_space_tag_t, bus_space_handle_t,
157 			    bus_size_t, const uint64_t *, bus_size_t);
158 
159 	/* write region */
160 	void		(*bs_wr_1) (bus_space_tag_t, bus_space_handle_t,
161 			    bus_size_t, const uint8_t *, bus_size_t);
162 	void		(*bs_wr_2) (bus_space_tag_t, bus_space_handle_t,
163 			    bus_size_t, const uint16_t *, bus_size_t);
164 	void		(*bs_wr_4) (bus_space_tag_t, bus_space_handle_t,
165 			    bus_size_t, const uint32_t *, bus_size_t);
166 	void		(*bs_wr_8) (bus_space_tag_t, bus_space_handle_t,
167 			    bus_size_t, const uint64_t *, bus_size_t);
168 
169 	/* set multiple */
170 	void		(*bs_sm_1) (bus_space_tag_t, bus_space_handle_t,
171 			    bus_size_t, uint8_t, bus_size_t);
172 	void		(*bs_sm_2) (bus_space_tag_t, bus_space_handle_t,
173 			    bus_size_t, uint16_t, bus_size_t);
174 	void		(*bs_sm_4) (bus_space_tag_t, bus_space_handle_t,
175 			    bus_size_t, uint32_t, bus_size_t);
176 	void		(*bs_sm_8) (bus_space_tag_t, bus_space_handle_t,
177 			    bus_size_t, uint64_t, bus_size_t);
178 
179 	/* set region */
180 	void		(*bs_sr_1) (bus_space_tag_t, bus_space_handle_t,
181 			    bus_size_t, uint8_t, bus_size_t);
182 	void		(*bs_sr_2) (bus_space_tag_t, bus_space_handle_t,
183 			    bus_size_t, uint16_t, bus_size_t);
184 	void		(*bs_sr_4) (bus_space_tag_t, bus_space_handle_t,
185 			    bus_size_t, uint32_t, bus_size_t);
186 	void		(*bs_sr_8) (bus_space_tag_t, bus_space_handle_t,
187 			    bus_size_t, uint64_t, bus_size_t);
188 
189 	/* copy */
190 	void		(*bs_c_1) (bus_space_tag_t, bus_space_handle_t, bus_size_t,
191 			    bus_space_handle_t, bus_size_t, bus_size_t);
192 	void		(*bs_c_2) (bus_space_tag_t, bus_space_handle_t, bus_size_t,
193 			    bus_space_handle_t, bus_size_t, bus_size_t);
194 	void		(*bs_c_4) (bus_space_tag_t, bus_space_handle_t, bus_size_t,
195 			    bus_space_handle_t, bus_size_t, bus_size_t);
196 	void		(*bs_c_8) (bus_space_tag_t, bus_space_handle_t, bus_size_t,
197 			    bus_space_handle_t, bus_size_t, bus_size_t);
198 
199 	/* read stream (single) */
200 	uint8_t	(*bs_r_1_s) (bus_space_tag_t, bus_space_handle_t, bus_size_t);
201 	uint16_t	(*bs_r_2_s) (bus_space_tag_t, bus_space_handle_t, bus_size_t);
202 	uint32_t	(*bs_r_4_s) (bus_space_tag_t, bus_space_handle_t, bus_size_t);
203 	uint64_t	(*bs_r_8_s) (bus_space_tag_t, bus_space_handle_t, bus_size_t);
204 
205 	/* read multiple stream */
206 	void		(*bs_rm_1_s) (bus_space_tag_t, bus_space_handle_t, bus_size_t,
207 	    uint8_t *, bus_size_t);
208 	void		(*bs_rm_2_s) (bus_space_tag_t, bus_space_handle_t, bus_size_t,
209 	    uint16_t *, bus_size_t);
210 	void		(*bs_rm_4_s) (bus_space_tag_t, bus_space_handle_t,
211 			    bus_size_t, uint32_t *, bus_size_t);
212 	void		(*bs_rm_8_s) (bus_space_tag_t, bus_space_handle_t,
213 			    bus_size_t, uint64_t *, bus_size_t);
214 
215 	/* read region stream */
216 	void		(*bs_rr_1_s) (bus_space_tag_t, bus_space_handle_t,
217 			    bus_size_t, uint8_t *, bus_size_t);
218 	void		(*bs_rr_2_s) (bus_space_tag_t, bus_space_handle_t,
219 			    bus_size_t, uint16_t *, bus_size_t);
220 	void		(*bs_rr_4_s) (bus_space_tag_t, bus_space_handle_t,
221 			    bus_size_t, uint32_t *, bus_size_t);
222 	void		(*bs_rr_8_s) (bus_space_tag_t, bus_space_handle_t,
223 			    bus_size_t, uint64_t *, bus_size_t);
224 
225 	/* write stream (single) */
226 	void		(*bs_w_1_s) (bus_space_tag_t, bus_space_handle_t,
227 			    bus_size_t, uint8_t);
228 	void		(*bs_w_2_s) (bus_space_tag_t, bus_space_handle_t,
229 			    bus_size_t, uint16_t);
230 	void		(*bs_w_4_s) (bus_space_tag_t, bus_space_handle_t,
231 			    bus_size_t, uint32_t);
232 	void		(*bs_w_8_s) (bus_space_tag_t, bus_space_handle_t,
233 			    bus_size_t, uint64_t);
234 
235 	/* write multiple stream */
236 	void		(*bs_wm_1_s) (bus_space_tag_t, bus_space_handle_t,
237 			    bus_size_t, const uint8_t *, bus_size_t);
238 	void		(*bs_wm_2_s) (bus_space_tag_t, bus_space_handle_t,
239 			    bus_size_t, const uint16_t *, bus_size_t);
240 	void		(*bs_wm_4_s) (bus_space_tag_t, bus_space_handle_t,
241 			    bus_size_t, const uint32_t *, bus_size_t);
242 	void		(*bs_wm_8_s) (bus_space_tag_t, bus_space_handle_t,
243 			    bus_size_t, const uint64_t *, bus_size_t);
244 
245 	/* write region stream */
246 	void		(*bs_wr_1_s) (bus_space_tag_t, bus_space_handle_t,
247 			    bus_size_t, const uint8_t *, bus_size_t);
248 	void		(*bs_wr_2_s) (bus_space_tag_t, bus_space_handle_t,
249 			    bus_size_t, const uint16_t *, bus_size_t);
250 	void		(*bs_wr_4_s) (bus_space_tag_t, bus_space_handle_t,
251 			    bus_size_t, const uint32_t *, bus_size_t);
252 	void		(*bs_wr_8_s) (bus_space_tag_t, bus_space_handle_t,
253 			    bus_size_t, const uint64_t *, bus_size_t);
254 };
255 
256 #if __ARM_ARCH < 6
257 extern bus_space_tag_t arm_base_bs_tag;
258 #endif
259 
260 /*
261  * Utility macros; INTERNAL USE ONLY.
262  */
263 #define	__bs_c(a,b)		__CONCAT(a,b)
264 #define	__bs_opname(op,size)	__bs_c(__bs_c(__bs_c(bs_,op),_),size)
265 
266 #define	__bs_nonsingle(type, sz, t, h, o, a, c)				\
267 	(*(t)->__bs_opname(type,sz))((t), h, o, a, c)
268 #define	__bs_set(type, sz, t, h, o, v, c)				\
269 	(*(t)->__bs_opname(type,sz))((t), h, o, v, c)
270 #define	__bs_copy(sz, t, h1, o1, h2, o2, cnt)				\
271 	(*(t)->__bs_opname(c,sz))((t), h1, o1, h2, o2, cnt)
272 
273 #define	__bs_opname_s(op,size)	__bs_c(__bs_c(__bs_c(__bs_c(bs_,op),_),size),_s)
274 #define	__bs_rs_s(sz, t, h, o)						\
275 	(*(t)->__bs_opname_s(r,sz))((t), h, o)
276 #define	__bs_ws_s(sz, t, h, o, v)					\
277 	(*(t)->__bs_opname_s(w,sz))((t), h, o, v)
278 #define	__bs_nonsingle_s(type, sz, t, h, o, a, c)			\
279 	(*(t)->__bs_opname_s(type,sz))((t), h, o, a, c)
280 
281 
282 #define __generate_inline_bs_rs(IFN, MBR, TYP)					\
283 	static inline TYP						\
284 	IFN(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)	\
285 	{								\
286 									\
287 		if (__predict_true(t->MBR == NULL))			\
288 			return (*(volatile TYP *)(h + o));		\
289 		else							\
290 			return (t->MBR(t, h, o));		\
291 	}
292 
293 #define __generate_inline_bs_ws(IFN, MBR, TYP)					\
294 	static inline void						\
295 	IFN(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, TYP v)\
296 	{								\
297 									\
298 		if (__predict_true(t->MBR == NULL))			\
299 			*(volatile TYP *)(h + o) = v;			\
300 		else							\
301 			t->MBR(t, h, o, v);			\
302 	}
303 
304 /*
305  * Mapping and unmapping operations.
306  */
307 #define	bus_space_map(t, a, s, c, hp)					\
308 	(*(t)->bs_map)((t), (a), (s), (c), (hp))
309 #define	bus_space_unmap(t, h, s)					\
310 	(*(t)->bs_unmap)((t), (h), (s))
311 #define	bus_space_subregion(t, h, o, s, hp)				\
312 	(*(t)->bs_subregion)((t), (h), (o), (s), (hp))
313 
314 
315 /*
316  * Allocation and deallocation operations.
317  */
318 #define	bus_space_alloc(t, rs, re, s, a, b, c, ap, hp)			\
319 	(*(t)->bs_alloc)((t), (rs), (re), (s), (a), (b),	\
320 	    (c), (ap), (hp))
321 #define	bus_space_free(t, h, s)						\
322 	(*(t)->bs_free)((t), (h), (s))
323 
324 /*
325  * Bus barrier operations.
326  */
327 #define	bus_space_barrier(t, h, o, l, f)				\
328 	(*(t)->bs_barrier)((t), (h), (o), (l), (f))
329 
330 #define	BUS_SPACE_BARRIER_READ	0x01
331 #define	BUS_SPACE_BARRIER_WRITE	0x02
332 
333 /*
334  * Bus read (single) operations.
335  */
336 __generate_inline_bs_rs(bus_space_read_1, bs_r_1, uint8_t);
337 __generate_inline_bs_rs(bus_space_read_2, bs_r_2, uint16_t);
338 __generate_inline_bs_rs(bus_space_read_4, bs_r_4, uint32_t);
339 __generate_inline_bs_rs(bus_space_read_8, bs_r_8, uint64_t);
340 
341 __generate_inline_bs_rs(bus_space_read_stream_1, bs_r_1_s, uint8_t);
342 __generate_inline_bs_rs(bus_space_read_stream_2, bs_r_2_s, uint16_t);
343 __generate_inline_bs_rs(bus_space_read_stream_4, bs_r_4_s, uint32_t);
344 __generate_inline_bs_rs(bus_space_read_stream_8, bs_r_8_s, uint64_t);
345 
346 /*
347  * Bus read multiple operations.
348  */
349 #define	bus_space_read_multi_1(t, h, o, a, c)				\
350 	__bs_nonsingle(rm,1,(t),(h),(o),(a),(c))
351 #define	bus_space_read_multi_2(t, h, o, a, c)				\
352 	__bs_nonsingle(rm,2,(t),(h),(o),(a),(c))
353 #define	bus_space_read_multi_4(t, h, o, a, c)				\
354 	__bs_nonsingle(rm,4,(t),(h),(o),(a),(c))
355 #define	bus_space_read_multi_8(t, h, o, a, c)				\
356 	__bs_nonsingle(rm,8,(t),(h),(o),(a),(c))
357 
358 #define	bus_space_read_multi_stream_1(t, h, o, a, c)			\
359 	__bs_nonsingle_s(rm,1,(t),(h),(o),(a),(c))
360 #define	bus_space_read_multi_stream_2(t, h, o, a, c)			\
361 	__bs_nonsingle_s(rm,2,(t),(h),(o),(a),(c))
362 #define	bus_space_read_multi_stream_4(t, h, o, a, c)			\
363 	__bs_nonsingle_s(rm,4,(t),(h),(o),(a),(c))
364 #define	bus_space_read_multi_stream_8(t, h, o, a, c)			\
365 	__bs_nonsingle_s(rm,8,(t),(h),(o),(a),(c))
366 
367 
368 /*
369  * Bus read region operations.
370  */
371 #define	bus_space_read_region_1(t, h, o, a, c)				\
372 	__bs_nonsingle(rr,1,(t),(h),(o),(a),(c))
373 #define	bus_space_read_region_2(t, h, o, a, c)				\
374 	__bs_nonsingle(rr,2,(t),(h),(o),(a),(c))
375 #define	bus_space_read_region_4(t, h, o, a, c)				\
376 	__bs_nonsingle(rr,4,(t),(h),(o),(a),(c))
377 #define	bus_space_read_region_8(t, h, o, a, c)				\
378 	__bs_nonsingle(rr,8,(t),(h),(o),(a),(c))
379 
380 #define	bus_space_read_region_stream_1(t, h, o, a, c)			\
381 	__bs_nonsingle_s(rr,1,(t),(h),(o),(a),(c))
382 #define	bus_space_read_region_stream_2(t, h, o, a, c)			\
383 	__bs_nonsingle_s(rr,2,(t),(h),(o),(a),(c))
384 #define	bus_space_read_region_stream_4(t, h, o, a, c)			\
385 	__bs_nonsingle_s(rr,4,(t),(h),(o),(a),(c))
386 #define	bus_space_read_region_stream_8(t, h, o, a, c)			\
387 	__bs_nonsingle_s(rr,8,(t),(h),(o),(a),(c))
388 
389 
390 /*
391  * Bus write (single) operations.
392  */
393 __generate_inline_bs_ws(bus_space_write_1, bs_w_1, uint8_t);
394 __generate_inline_bs_ws(bus_space_write_2, bs_w_2, uint16_t);
395 __generate_inline_bs_ws(bus_space_write_4, bs_w_4, uint32_t);
396 __generate_inline_bs_ws(bus_space_write_8, bs_w_8, uint64_t);
397 
398 __generate_inline_bs_ws(bus_space_write_stream_1, bs_w_1_s, uint8_t);
399 __generate_inline_bs_ws(bus_space_write_stream_2, bs_w_2_s, uint16_t);
400 __generate_inline_bs_ws(bus_space_write_stream_4, bs_w_4_s, uint32_t);
401 __generate_inline_bs_ws(bus_space_write_stream_8, bs_w_8_s, uint64_t);
402 
403 
404 /*
405  * Bus write multiple operations.
406  */
407 #define	bus_space_write_multi_1(t, h, o, a, c)				\
408 	__bs_nonsingle(wm,1,(t),(h),(o),(a),(c))
409 #define	bus_space_write_multi_2(t, h, o, a, c)				\
410 	__bs_nonsingle(wm,2,(t),(h),(o),(a),(c))
411 #define	bus_space_write_multi_4(t, h, o, a, c)				\
412 	__bs_nonsingle(wm,4,(t),(h),(o),(a),(c))
413 #define	bus_space_write_multi_8(t, h, o, a, c)				\
414 	__bs_nonsingle(wm,8,(t),(h),(o),(a),(c))
415 
416 #define	bus_space_write_multi_stream_1(t, h, o, a, c)			\
417 	__bs_nonsingle_s(wm,1,(t),(h),(o),(a),(c))
418 #define	bus_space_write_multi_stream_2(t, h, o, a, c)			\
419 	__bs_nonsingle_s(wm,2,(t),(h),(o),(a),(c))
420 #define	bus_space_write_multi_stream_4(t, h, o, a, c)			\
421 	__bs_nonsingle_s(wm,4,(t),(h),(o),(a),(c))
422 #define	bus_space_write_multi_stream_8(t, h, o, a, c)			\
423 	__bs_nonsingle_s(wm,8,(t),(h),(o),(a),(c))
424 
425 
426 /*
427  * Bus write region operations.
428  */
429 #define	bus_space_write_region_1(t, h, o, a, c)				\
430 	__bs_nonsingle(wr,1,(t),(h),(o),(a),(c))
431 #define	bus_space_write_region_2(t, h, o, a, c)				\
432 	__bs_nonsingle(wr,2,(t),(h),(o),(a),(c))
433 #define	bus_space_write_region_4(t, h, o, a, c)				\
434 	__bs_nonsingle(wr,4,(t),(h),(o),(a),(c))
435 #define	bus_space_write_region_8(t, h, o, a, c)				\
436 	__bs_nonsingle(wr,8,(t),(h),(o),(a),(c))
437 
438 #define	bus_space_write_region_stream_1(t, h, o, a, c)			\
439 	__bs_nonsingle_s(wr,1,(t),(h),(o),(a),(c))
440 #define	bus_space_write_region_stream_2(t, h, o, a, c)			\
441 	__bs_nonsingle_s(wr,2,(t),(h),(o),(a),(c))
442 #define	bus_space_write_region_stream_4(t, h, o, a, c)			\
443 	__bs_nonsingle_s(wr,4,(t),(h),(o),(a),(c))
444 #define	bus_space_write_region_stream_8(t, h, o, a, c)			\
445 	__bs_nonsingle_s(wr,8,(t),(h),(o),(a),(c))
446 
447 
448 /*
449  * Set multiple operations.
450  */
451 #define	bus_space_set_multi_1(t, h, o, v, c)				\
452 	__bs_set(sm,1,(t),(h),(o),(v),(c))
453 #define	bus_space_set_multi_2(t, h, o, v, c)				\
454 	__bs_set(sm,2,(t),(h),(o),(v),(c))
455 #define	bus_space_set_multi_4(t, h, o, v, c)				\
456 	__bs_set(sm,4,(t),(h),(o),(v),(c))
457 #define	bus_space_set_multi_8(t, h, o, v, c)				\
458 	__bs_set(sm,8,(t),(h),(o),(v),(c))
459 
460 
461 /*
462  * Set region operations.
463  */
464 #define	bus_space_set_region_1(t, h, o, v, c)				\
465 	__bs_set(sr,1,(t),(h),(o),(v),(c))
466 #define	bus_space_set_region_2(t, h, o, v, c)				\
467 	__bs_set(sr,2,(t),(h),(o),(v),(c))
468 #define	bus_space_set_region_4(t, h, o, v, c)				\
469 	__bs_set(sr,4,(t),(h),(o),(v),(c))
470 #define	bus_space_set_region_8(t, h, o, v, c)				\
471 	__bs_set(sr,8,(t),(h),(o),(v),(c))
472 
473 
474 /*
475  * Copy operations.
476  */
477 #define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)				\
478 	__bs_copy(1, t, h1, o1, h2, o2, c)
479 #define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)				\
480 	__bs_copy(2, t, h1, o1, h2, o2, c)
481 #define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)				\
482 	__bs_copy(4, t, h1, o1, h2, o2, c)
483 #define	bus_space_copy_region_8(t, h1, o1, h2, o2, c)				\
484 	__bs_copy(8, t, h1, o1, h2, o2, c)
485 
486 /*
487  * Macros to provide prototypes for all the functions used in the
488  * bus_space structure
489  */
490 
491 #define bs_map_proto(f)							\
492 int	__bs_c(f,_bs_map) (bus_space_tag_t t, bus_addr_t addr,		\
493 	    bus_size_t size, int cacheable, bus_space_handle_t *bshp);
494 
495 #define bs_unmap_proto(f)						\
496 void	__bs_c(f,_bs_unmap) (bus_space_tag_t t, bus_space_handle_t bsh,		\
497 	    bus_size_t size);
498 
499 #define bs_subregion_proto(f)						\
500 int	__bs_c(f,_bs_subregion) (bus_space_tag_t t, bus_space_handle_t bsh,	\
501 	    bus_size_t offset, bus_size_t size, 			\
502 	    bus_space_handle_t *nbshp);
503 
504 #define bs_alloc_proto(f)						\
505 int	__bs_c(f,_bs_alloc) (bus_space_tag_t t, bus_addr_t rstart,		\
506 	    bus_addr_t rend, bus_size_t size, bus_size_t align,		\
507 	    bus_size_t boundary, int cacheable, bus_addr_t *addrp,	\
508 	    bus_space_handle_t *bshp);
509 
510 #define bs_free_proto(f)						\
511 void	__bs_c(f,_bs_free) (bus_space_tag_t t, bus_space_handle_t bsh,	\
512 	    bus_size_t size);
513 
514 #define bs_mmap_proto(f)						\
515 int	__bs_c(f,_bs_mmap) (struct cdev *, vm_offset_t, vm_paddr_t *, int);
516 
517 #define bs_barrier_proto(f)						\
518 void	__bs_c(f,_bs_barrier) (bus_space_tag_t t, bus_space_handle_t bsh,	\
519 	    bus_size_t offset, bus_size_t len, int flags);
520 
521 #define	bs_r_1_proto(f)							\
522 uint8_t	__bs_c(f,_bs_r_1) (bus_space_tag_t t, bus_space_handle_t bsh,	\
523 		    bus_size_t offset);
524 
525 #define	bs_r_2_proto(f)							\
526 uint16_t	__bs_c(f,_bs_r_2) (bus_space_tag_t t, bus_space_handle_t bsh,	\
527 		    bus_size_t offset);
528 
529 #define	bs_r_4_proto(f)							\
530 uint32_t	__bs_c(f,_bs_r_4) (bus_space_tag_t t, bus_space_handle_t bsh,	\
531 		    bus_size_t offset);
532 
533 #define	bs_r_8_proto(f)							\
534 uint64_t	__bs_c(f,_bs_r_8) (bus_space_tag_t t, bus_space_handle_t bsh,	\
535 		    bus_size_t offset);
536 
537 #define	bs_r_1_s_proto(f)						\
538 uint8_t	__bs_c(f,_bs_r_1_s) (bus_space_tag_t t, bus_space_handle_t bsh,	\
539 		    bus_size_t offset);
540 
541 #define	bs_r_2_s_proto(f)						\
542 uint16_t	__bs_c(f,_bs_r_2_s) (bus_space_tag_t t, bus_space_handle_t bsh,	\
543 		    bus_size_t offset);
544 
545 #define	bs_r_4_s_proto(f)						\
546 uint32_t	__bs_c(f,_bs_r_4_s) (bus_space_tag_t t, bus_space_handle_t bsh,	\
547 		    bus_size_t offset);
548 
549 #define	bs_w_1_proto(f)							\
550 void	__bs_c(f,_bs_w_1) (bus_space_tag_t t, bus_space_handle_t bsh,		\
551 	    bus_size_t offset, uint8_t value);
552 
553 #define	bs_w_2_proto(f)							\
554 void	__bs_c(f,_bs_w_2) (bus_space_tag_t t, bus_space_handle_t bsh,		\
555 	    bus_size_t offset, uint16_t value);
556 
557 #define	bs_w_4_proto(f)							\
558 void	__bs_c(f,_bs_w_4) (bus_space_tag_t t, bus_space_handle_t bsh,		\
559 	    bus_size_t offset, uint32_t value);
560 
561 #define	bs_w_8_proto(f)							\
562 void	__bs_c(f,_bs_w_8) (bus_space_tag_t t, bus_space_handle_t bsh,		\
563 	    bus_size_t offset, uint64_t value);
564 
565 #define	bs_w_1_s_proto(f)						\
566 void	__bs_c(f,_bs_w_1_s) (bus_space_tag_t t, bus_space_handle_t bsh,		\
567 	    bus_size_t offset, uint8_t value);
568 
569 #define	bs_w_2_s_proto(f)						\
570 void	__bs_c(f,_bs_w_2_s) (bus_space_tag_t t, bus_space_handle_t bsh,		\
571 	    bus_size_t offset, uint16_t value);
572 
573 #define	bs_w_4_s_proto(f)						\
574 void	__bs_c(f,_bs_w_4_s) (bus_space_tag_t t, bus_space_handle_t bsh,		\
575 	    bus_size_t offset, uint32_t value);
576 
577 #define	bs_rm_1_proto(f)						\
578 void	__bs_c(f,_bs_rm_1) (bus_space_tag_t t, bus_space_handle_t bsh,	\
579 	    bus_size_t offset, uint8_t *addr, bus_size_t count);
580 
581 #define	bs_rm_2_proto(f)						\
582 void	__bs_c(f,_bs_rm_2) (bus_space_tag_t t, bus_space_handle_t bsh,	\
583 	    bus_size_t offset, uint16_t *addr, bus_size_t count);
584 
585 #define	bs_rm_4_proto(f)						\
586 void	__bs_c(f,_bs_rm_4) (bus_space_tag_t t, bus_space_handle_t bsh,	\
587 	    bus_size_t offset, uint32_t *addr, bus_size_t count);
588 
589 #define	bs_rm_8_proto(f)						\
590 void	__bs_c(f,_bs_rm_8) (bus_space_tag_t t, bus_space_handle_t bsh,	\
591 	    bus_size_t offset, uint64_t *addr, bus_size_t count);
592 
593 #define	bs_wm_1_proto(f)						\
594 void	__bs_c(f,_bs_wm_1) (bus_space_tag_t t, bus_space_handle_t bsh,	\
595 	    bus_size_t offset, const uint8_t *addr, bus_size_t count);
596 
597 #define	bs_wm_2_proto(f)						\
598 void	__bs_c(f,_bs_wm_2) (bus_space_tag_t t, bus_space_handle_t bsh,	\
599 	    bus_size_t offset, const uint16_t *addr, bus_size_t count);
600 
601 #define	bs_wm_4_proto(f)						\
602 void	__bs_c(f,_bs_wm_4) (bus_space_tag_t t, bus_space_handle_t bsh,	\
603 	    bus_size_t offset, const uint32_t *addr, bus_size_t count);
604 
605 #define	bs_wm_8_proto(f)						\
606 void	__bs_c(f,_bs_wm_8) (bus_space_tag_t t, bus_space_handle_t bsh,	\
607 	    bus_size_t offset, const uint64_t *addr, bus_size_t count);
608 
609 #define	bs_rr_1_proto(f)						\
610 void	__bs_c(f, _bs_rr_1) (bus_space_tag_t t, bus_space_handle_t bsh,	\
611 	    bus_size_t offset, uint8_t *addr, bus_size_t count);
612 
613 #define	bs_rr_2_proto(f)						\
614 void	__bs_c(f, _bs_rr_2) (bus_space_tag_t t, bus_space_handle_t bsh,	\
615 	    bus_size_t offset, uint16_t *addr, bus_size_t count);
616 
617 #define	bs_rr_4_proto(f)						\
618 void	__bs_c(f, _bs_rr_4) (bus_space_tag_t t, bus_space_handle_t bsh,	\
619 	    bus_size_t offset, uint32_t *addr, bus_size_t count);
620 
621 #define	bs_rr_8_proto(f)						\
622 void	__bs_c(f, _bs_rr_8) (bus_space_tag_t t, bus_space_handle_t bsh,	\
623 	    bus_size_t offset, uint64_t *addr, bus_size_t count);
624 
625 #define	bs_wr_1_proto(f)						\
626 void	__bs_c(f, _bs_wr_1) (bus_space_tag_t t, bus_space_handle_t bsh,	\
627 	    bus_size_t offset, const uint8_t *addr, bus_size_t count);
628 
629 #define	bs_wr_2_proto(f)						\
630 void	__bs_c(f, _bs_wr_2) (bus_space_tag_t t, bus_space_handle_t bsh,	\
631 	    bus_size_t offset, const uint16_t *addr, bus_size_t count);
632 
633 #define	bs_wr_4_proto(f)						\
634 void	__bs_c(f, _bs_wr_4) (bus_space_tag_t t, bus_space_handle_t bsh,	\
635 	    bus_size_t offset, const uint32_t *addr, bus_size_t count);
636 
637 #define	bs_wr_8_proto(f)						\
638 void	__bs_c(f, _bs_wr_8) (bus_space_tag_t t, bus_space_handle_t bsh,	\
639 	    bus_size_t offset, const uint64_t *addr, bus_size_t count);
640 
641 #define	bs_sm_1_proto(f)						\
642 void	__bs_c(f,_bs_sm_1) (bus_space_tag_t t, bus_space_handle_t bsh,	\
643 	    bus_size_t offset, uint8_t value, bus_size_t count);
644 
645 #define	bs_sm_2_proto(f)						\
646 void	__bs_c(f,_bs_sm_2) (bus_space_tag_t t, bus_space_handle_t bsh,	\
647 	    bus_size_t offset, uint16_t value, bus_size_t count);
648 
649 #define	bs_sm_4_proto(f)						\
650 void	__bs_c(f,_bs_sm_4) (bus_space_tag_t t, bus_space_handle_t bsh,	\
651 	    bus_size_t offset, uint32_t value, bus_size_t count);
652 
653 #define	bs_sm_8_proto(f)						\
654 void	__bs_c(f,_bs_sm_8) (bus_space_tag_t t, bus_space_handle_t bsh,	\
655 	    bus_size_t offset, uint64_t value, bus_size_t count);
656 
657 #define	bs_sr_1_proto(f)						\
658 void	__bs_c(f,_bs_sr_1) (bus_space_tag_t t, bus_space_handle_t bsh,	\
659 	    bus_size_t offset, uint8_t value, bus_size_t count);
660 
661 #define	bs_sr_2_proto(f)						\
662 void	__bs_c(f,_bs_sr_2) (bus_space_tag_t t, bus_space_handle_t bsh,	\
663 	    bus_size_t offset, uint16_t value, bus_size_t count);
664 
665 #define	bs_sr_4_proto(f)						\
666 void	__bs_c(f,_bs_sr_4) (bus_space_tag_t t, bus_space_handle_t bsh,	\
667 	    bus_size_t offset, uint32_t value, bus_size_t count);
668 
669 #define	bs_sr_8_proto(f)						\
670 void	__bs_c(f,_bs_sr_8) (bus_space_tag_t t, bus_space_handle_t bsh,	\
671 	    bus_size_t offset, uint64_t value, bus_size_t count);
672 
673 #define	bs_c_1_proto(f)							\
674 void	__bs_c(f,_bs_c_1) (bus_space_tag_t t, bus_space_handle_t bsh1,	\
675 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
676 	    bus_size_t offset2, bus_size_t count);
677 
678 #define	bs_c_2_proto(f)							\
679 void	__bs_c(f,_bs_c_2) (bus_space_tag_t t, bus_space_handle_t bsh1,	\
680 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
681 	    bus_size_t offset2, bus_size_t count);
682 
683 #define	bs_c_4_proto(f)							\
684 void	__bs_c(f,_bs_c_4) (bus_space_tag_t t, bus_space_handle_t bsh1,	\
685 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
686 	    bus_size_t offset2, bus_size_t count);
687 
688 #define	bs_c_8_proto(f)							\
689 void	__bs_c(f,_bs_c_8) (bus_space_tag_t t, bus_space_handle_t bsh1,	\
690 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
691 	    bus_size_t offset2, bus_size_t count);
692 
693 #define bs_protos(f)		\
694 bs_map_proto(f);		\
695 bs_unmap_proto(f);		\
696 bs_subregion_proto(f);		\
697 bs_alloc_proto(f);		\
698 bs_free_proto(f);		\
699 bs_mmap_proto(f);		\
700 bs_barrier_proto(f);		\
701 bs_r_1_proto(f);		\
702 bs_r_2_proto(f);		\
703 bs_r_4_proto(f);		\
704 bs_r_8_proto(f);		\
705 bs_r_1_s_proto(f);		\
706 bs_r_2_s_proto(f);		\
707 bs_r_4_s_proto(f);		\
708 bs_w_1_proto(f);		\
709 bs_w_2_proto(f);		\
710 bs_w_4_proto(f);		\
711 bs_w_8_proto(f);		\
712 bs_w_1_s_proto(f);		\
713 bs_w_2_s_proto(f);		\
714 bs_w_4_s_proto(f);		\
715 bs_rm_1_proto(f);		\
716 bs_rm_2_proto(f);		\
717 bs_rm_4_proto(f);		\
718 bs_rm_8_proto(f);		\
719 bs_wm_1_proto(f);		\
720 bs_wm_2_proto(f);		\
721 bs_wm_4_proto(f);		\
722 bs_wm_8_proto(f);		\
723 bs_rr_1_proto(f);		\
724 bs_rr_2_proto(f);		\
725 bs_rr_4_proto(f);		\
726 bs_rr_8_proto(f);		\
727 bs_wr_1_proto(f);		\
728 bs_wr_2_proto(f);		\
729 bs_wr_4_proto(f);		\
730 bs_wr_8_proto(f);		\
731 bs_sm_1_proto(f);		\
732 bs_sm_2_proto(f);		\
733 bs_sm_4_proto(f);		\
734 bs_sm_8_proto(f);		\
735 bs_sr_1_proto(f);		\
736 bs_sr_2_proto(f);		\
737 bs_sr_4_proto(f);		\
738 bs_sr_8_proto(f);		\
739 bs_c_1_proto(f);		\
740 bs_c_2_proto(f);		\
741 bs_c_4_proto(f);		\
742 bs_c_8_proto(f);
743 
744 void generic_bs_unimplemented(void);
745 #define	BS_UNIMPLEMENTED	(void *)generic_bs_unimplemented
746 
747 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
748 
749 #define BUS_SPACE_MAXADDR_24BIT	0xFFFFFF
750 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
751 #define BUS_SPACE_MAXADDR 	0xFFFFFFFF
752 #define BUS_SPACE_MAXSIZE_24BIT	0xFFFFFF
753 #define BUS_SPACE_MAXSIZE_32BIT	0xFFFFFFFF
754 #define BUS_SPACE_MAXSIZE 	0xFFFFFFFF
755 
756 #define BUS_SPACE_UNRESTRICTED	(~0)
757 
758 #include <machine/bus_dma.h>
759 
760 /*
761  * Get the physical address of a bus space memory-mapped resource.
762  * Doing this as a macro is a temporary solution until a more robust fix is
763  * designed.  It also serves to mark the locations needing that fix.
764  */
765 #define BUS_SPACE_PHYSADDR(res, offs) \
766 	((u_int)(rman_get_start(res)+(offs)))
767 
768 #endif /* _MACHINE_BUS_H_ */
769