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