xref: /freebsd/sys/arm/include/bus.h (revision 2357939bc239bd5334a169b62313806178dd8f30)
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  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the NetBSD
22  *	Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 /*
41  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
42  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  * 3. All advertising materials mentioning features or use of this software
53  *    must display the following acknowledgement:
54  *      This product includes software developed by Christopher G. Demetriou
55  *	for the NetBSD Project.
56  * 4. The name of the author may not be used to endorse or promote products
57  *    derived from this software without specific prior written permission
58  *
59  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
60  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
61  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
63  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
64  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
68  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69  *
70  * $FreeBSD$
71  */
72 
73 #ifndef _MACHINE_BUS_H_
74 #define _MACHINE_BUS_H_
75 
76 /*
77  * Addresses (in bus space).
78  */
79 typedef u_long bus_addr_t;
80 typedef u_long bus_size_t;
81 
82 /*
83  * Access methods for bus space.
84  */
85 typedef struct bus_space *bus_space_tag_t;
86 typedef u_long bus_space_handle_t;
87 
88 /*
89  *	int bus_space_map  (bus_space_tag_t t, bus_addr_t addr,
90  *	    bus_size_t size, int flags, bus_space_handle_t *bshp);
91  *
92  * Map a region of bus space.
93  */
94 
95 #define	BUS_SPACE_MAP_CACHEABLE		0x01
96 #define	BUS_SPACE_MAP_LINEAR		0x02
97 #define	BUS_SPACE_MAP_PREFETCHABLE     	0x04
98 
99 struct bus_space {
100 	/* cookie */
101 	void		*bs_cookie;
102 
103 	/* mapping/unmapping */
104 	int		(*bs_map) (void *, bus_addr_t, bus_size_t,
105 			    int, bus_space_handle_t *);
106 	void		(*bs_unmap) (void *, bus_size_t);
107 	int		(*bs_subregion) (void *, bus_space_handle_t,
108 			    bus_size_t, bus_size_t, bus_space_handle_t *);
109 
110 	/* allocation/deallocation */
111 	int		(*bs_alloc) (void *, bus_addr_t, bus_addr_t,
112 			    bus_size_t, bus_size_t, bus_size_t, int,
113 			    bus_addr_t *, bus_space_handle_t *);
114 	void		(*bs_free) (void *, bus_space_handle_t,
115 			    bus_size_t);
116 
117 	/* get kernel virtual address */
118 	void *		(*bs_vaddr) (void *, bus_space_handle_t);
119 
120 	/* mmap bus space for user */
121 	int		(*bs_mmap) (dev_t, vm_offset_t, vm_paddr_t *, int);
122 
123 	/* barrier */
124 	void		(*bs_barrier) (void *, bus_space_handle_t,
125 			    bus_size_t, bus_size_t, int);
126 
127 	/* read (single) */
128 	u_int8_t	(*bs_r_1) (void *, bus_space_handle_t, bus_size_t);
129 	u_int16_t	(*bs_r_2) (void *, bus_space_handle_t, bus_size_t);
130 	u_int32_t	(*bs_r_4) (void *, bus_space_handle_t, bus_size_t);
131 	u_int64_t	(*bs_r_8) (void *, bus_space_handle_t, bus_size_t);
132 
133 	/* read multiple */
134 	void		(*bs_rm_1) (void *, bus_space_handle_t, bus_size_t,
135 	    u_int8_t *, bus_size_t);
136 	void		(*bs_rm_2) (void *, bus_space_handle_t, bus_size_t,
137 	    u_int16_t *, bus_size_t);
138 	void		(*bs_rm_4) (void *, bus_space_handle_t,
139 			    bus_size_t, u_int32_t *, bus_size_t);
140 	void		(*bs_rm_8) (void *, bus_space_handle_t,
141 			    bus_size_t, u_int64_t *, bus_size_t);
142 
143 	/* read region */
144 	void		(*bs_rr_1) (void *, bus_space_handle_t,
145 			    bus_size_t, u_int8_t *, bus_size_t);
146 	void		(*bs_rr_2) (void *, bus_space_handle_t,
147 			    bus_size_t, u_int16_t *, bus_size_t);
148 	void		(*bs_rr_4) (void *, bus_space_handle_t,
149 			    bus_size_t, u_int32_t *, bus_size_t);
150 	void		(*bs_rr_8) (void *, bus_space_handle_t,
151 			    bus_size_t, u_int64_t *, bus_size_t);
152 
153 	/* write (single) */
154 	void		(*bs_w_1) (void *, bus_space_handle_t,
155 			    bus_size_t, u_int8_t);
156 	void		(*bs_w_2) (void *, bus_space_handle_t,
157 			    bus_size_t, u_int16_t);
158 	void		(*bs_w_4) (void *, bus_space_handle_t,
159 			    bus_size_t, u_int32_t);
160 	void		(*bs_w_8) (void *, bus_space_handle_t,
161 			    bus_size_t, u_int64_t);
162 
163 	/* write multiple */
164 	void		(*bs_wm_1) (void *, bus_space_handle_t,
165 			    bus_size_t, const u_int8_t *, bus_size_t);
166 	void		(*bs_wm_2) (void *, bus_space_handle_t,
167 			    bus_size_t, const u_int16_t *, bus_size_t);
168 	void		(*bs_wm_4) (void *, bus_space_handle_t,
169 			    bus_size_t, const u_int32_t *, bus_size_t);
170 	void		(*bs_wm_8) (void *, bus_space_handle_t,
171 			    bus_size_t, const u_int64_t *, bus_size_t);
172 
173 	/* write region */
174 	void		(*bs_wr_1) (void *, bus_space_handle_t,
175 			    bus_size_t, const u_int8_t *, bus_size_t);
176 	void		(*bs_wr_2) (void *, bus_space_handle_t,
177 			    bus_size_t, const u_int16_t *, bus_size_t);
178 	void		(*bs_wr_4) (void *, bus_space_handle_t,
179 			    bus_size_t, const u_int32_t *, bus_size_t);
180 	void		(*bs_wr_8) (void *, bus_space_handle_t,
181 			    bus_size_t, const u_int64_t *, bus_size_t);
182 
183 	/* set multiple */
184 	void		(*bs_sm_1) (void *, bus_space_handle_t,
185 			    bus_size_t, u_int8_t, bus_size_t);
186 	void		(*bs_sm_2) (void *, bus_space_handle_t,
187 			    bus_size_t, u_int16_t, bus_size_t);
188 	void		(*bs_sm_4) (void *, bus_space_handle_t,
189 			    bus_size_t, u_int32_t, bus_size_t);
190 	void		(*bs_sm_8) (void *, bus_space_handle_t,
191 			    bus_size_t, u_int64_t, bus_size_t);
192 
193 	/* set region */
194 	void		(*bs_sr_1) (void *, bus_space_handle_t,
195 			    bus_size_t, u_int8_t, bus_size_t);
196 	void		(*bs_sr_2) (void *, bus_space_handle_t,
197 			    bus_size_t, u_int16_t, bus_size_t);
198 	void		(*bs_sr_4) (void *, bus_space_handle_t,
199 			    bus_size_t, u_int32_t, bus_size_t);
200 	void		(*bs_sr_8) (void *, bus_space_handle_t,
201 			    bus_size_t, u_int64_t, bus_size_t);
202 
203 	/* copy */
204 	void		(*bs_c_1) (void *, bus_space_handle_t, bus_size_t,
205 			    bus_space_handle_t, bus_size_t, bus_size_t);
206 	void		(*bs_c_2) (void *, bus_space_handle_t, bus_size_t,
207 			    bus_space_handle_t, bus_size_t, bus_size_t);
208 	void		(*bs_c_4) (void *, bus_space_handle_t, bus_size_t,
209 			    bus_space_handle_t, bus_size_t, bus_size_t);
210 	void		(*bs_c_8) (void *, bus_space_handle_t, bus_size_t,
211 			    bus_space_handle_t, bus_size_t, bus_size_t);
212 
213 };
214 
215 
216 /*
217  * Utility macros; INTERNAL USE ONLY.
218  */
219 #define	__bs_c(a,b)		__CONCAT(a,b)
220 #define	__bs_opname(op,size)	__bs_c(__bs_c(__bs_c(bs_,op),_),size)
221 
222 #define	__bs_rs(sz, t, h, o)						\
223 	(*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o)
224 #define	__bs_ws(sz, t, h, o, v)						\
225 	(*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v)
226 #define	__bs_nonsingle(type, sz, t, h, o, a, c)				\
227 	(*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c)
228 #define	__bs_set(type, sz, t, h, o, v, c)				\
229 	(*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c)
230 #define	__bs_copy(sz, t, h1, o1, h2, o2, cnt)				\
231 	(*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt)
232 
233 
234 /*
235  * Mapping and unmapping operations.
236  */
237 #define	bus_space_map(t, a, s, c, hp)					\
238 	(*(t)->bs_map)((t)->bs_cookie, (a), (s), (c), (hp))
239 #define	bus_space_unmap(t, h, s)					\
240 	(*(t)->bs_unmap)((t)->bs_cookie, (h), (s))
241 #define	bus_space_subregion(t, h, o, s, hp)				\
242 	(*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp))
243 
244 
245 /*
246  * Allocation and deallocation operations.
247  */
248 #define	bus_space_alloc(t, rs, re, s, a, b, c, ap, hp)			\
249 	(*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b),	\
250 	    (c), (ap), (hp))
251 #define	bus_space_free(t, h, s)						\
252 	(*(t)->bs_free)((t)->bs_cookie, (h), (s))
253 
254 /*
255  * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
256  */
257 #define	bus_space_vaddr(t, h)						\
258 	(*(t)->bs_vaddr)((t)->bs_cookie, (h))
259 
260 /*
261  * MMap bus space for a user application.
262  */
263 #define bus_space_mmap(t, a, o, p, f)					\
264 	(*(t)->bs_mmap)((t)->bs_cookie, (a), (o), (p), (f))
265 
266 /*
267  * Bus barrier operations.
268  */
269 #define	bus_space_barrier(t, h, o, l, f)				\
270 	(*(t)->bs_barrier)((t)->bs_cookie, (h), (o), (l), (f))
271 
272 #define	BUS_SPACE_BARRIER_READ	0x01
273 #define	BUS_SPACE_BARRIER_WRITE	0x02
274 
275 /*
276  * Bus read (single) operations.
277  */
278 #define	bus_space_read_1(t, h, o)	__bs_rs(1,(t),(h),(o))
279 #define	bus_space_read_2(t, h, o)	__bs_rs(2,(t),(h),(o))
280 #define	bus_space_read_4(t, h, o)	__bs_rs(4,(t),(h),(o))
281 #define	bus_space_read_8(t, h, o)	__bs_rs(8,(t),(h),(o))
282 
283 
284 /*
285  * Bus read multiple operations.
286  */
287 #define	bus_space_read_multi_1(t, h, o, a, c)				\
288 	__bs_nonsingle(rm,1,(t),(h),(o),(a),(c))
289 #define	bus_space_read_multi_2(t, h, o, a, c)				\
290 	__bs_nonsingle(rm,2,(t),(h),(o),(a),(c))
291 #define	bus_space_read_multi_4(t, h, o, a, c)				\
292 	__bs_nonsingle(rm,4,(t),(h),(o),(a),(c))
293 #define	bus_space_read_multi_8(t, h, o, a, c)				\
294 	__bs_nonsingle(rm,8,(t),(h),(o),(a),(c))
295 
296 
297 /*
298  * Bus read region operations.
299  */
300 #define	bus_space_read_region_1(t, h, o, a, c)				\
301 	__bs_nonsingle(rr,1,(t),(h),(o),(a),(c))
302 #define	bus_space_read_region_2(t, h, o, a, c)				\
303 	__bs_nonsingle(rr,2,(t),(h),(o),(a),(c))
304 #define	bus_space_read_region_4(t, h, o, a, c)				\
305 	__bs_nonsingle(rr,4,(t),(h),(o),(a),(c))
306 #define	bus_space_read_region_8(t, h, o, a, c)				\
307 	__bs_nonsingle(rr,8,(t),(h),(o),(a),(c))
308 
309 
310 /*
311  * Bus write (single) operations.
312  */
313 #define	bus_space_write_1(t, h, o, v)	__bs_ws(1,(t),(h),(o),(v))
314 #define	bus_space_write_2(t, h, o, v)	__bs_ws(2,(t),(h),(o),(v))
315 #define	bus_space_write_4(t, h, o, v)	__bs_ws(4,(t),(h),(o),(v))
316 #define	bus_space_write_8(t, h, o, v)	__bs_ws(8,(t),(h),(o),(v))
317 
318 
319 /*
320  * Bus write multiple operations.
321  */
322 #define	bus_space_write_multi_1(t, h, o, a, c)				\
323 	__bs_nonsingle(wm,1,(t),(h),(o),(a),(c))
324 #define	bus_space_write_multi_2(t, h, o, a, c)				\
325 	__bs_nonsingle(wm,2,(t),(h),(o),(a),(c))
326 #define	bus_space_write_multi_4(t, h, o, a, c)				\
327 	__bs_nonsingle(wm,4,(t),(h),(o),(a),(c))
328 #define	bus_space_write_multi_8(t, h, o, a, c)				\
329 	__bs_nonsingle(wm,8,(t),(h),(o),(a),(c))
330 
331 
332 /*
333  * Bus write region operations.
334  */
335 #define	bus_space_write_region_1(t, h, o, a, c)				\
336 	__bs_nonsingle(wr,1,(t),(h),(o),(a),(c))
337 #define	bus_space_write_region_2(t, h, o, a, c)				\
338 	__bs_nonsingle(wr,2,(t),(h),(o),(a),(c))
339 #define	bus_space_write_region_4(t, h, o, a, c)				\
340 	__bs_nonsingle(wr,4,(t),(h),(o),(a),(c))
341 #define	bus_space_write_region_8(t, h, o, a, c)				\
342 	__bs_nonsingle(wr,8,(t),(h),(o),(a),(c))
343 
344 
345 /*
346  * Set multiple operations.
347  */
348 #define	bus_space_set_multi_1(t, h, o, v, c)				\
349 	__bs_set(sm,1,(t),(h),(o),(v),(c))
350 #define	bus_space_set_multi_2(t, h, o, v, c)				\
351 	__bs_set(sm,2,(t),(h),(o),(v),(c))
352 #define	bus_space_set_multi_4(t, h, o, v, c)				\
353 	__bs_set(sm,4,(t),(h),(o),(v),(c))
354 #define	bus_space_set_multi_8(t, h, o, v, c)				\
355 	__bs_set(sm,8,(t),(h),(o),(v),(c))
356 
357 
358 /*
359  * Set region operations.
360  */
361 #define	bus_space_set_region_1(t, h, o, v, c)				\
362 	__bs_set(sr,1,(t),(h),(o),(v),(c))
363 #define	bus_space_set_region_2(t, h, o, v, c)				\
364 	__bs_set(sr,2,(t),(h),(o),(v),(c))
365 #define	bus_space_set_region_4(t, h, o, v, c)				\
366 	__bs_set(sr,4,(t),(h),(o),(v),(c))
367 #define	bus_space_set_region_8(t, h, o, v, c)				\
368 	__bs_set(sr,8,(t),(h),(o),(v),(c))
369 
370 
371 /*
372  * Copy operations.
373  */
374 #define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)				\
375 	__bs_copy(1, t, h1, o1, h2, o2, c)
376 #define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)				\
377 	__bs_copy(2, t, h1, o1, h2, o2, c)
378 #define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)				\
379 	__bs_copy(4, t, h1, o1, h2, o2, c)
380 #define	bus_space_copy_region_8(t, h1, o1, h2, o2, c)				\
381 	__bs_copy(8, t, h1, o1, h2, o2, c)
382 
383 /*
384  * Macros to provide prototypes for all the functions used in the
385  * bus_space structure
386  */
387 
388 #define bs_map_proto(f)							\
389 int	__bs_c(f,_bs_map) (void *t, bus_addr_t addr,		\
390 	    bus_size_t size, int cacheable, bus_space_handle_t *bshp);
391 
392 #define bs_unmap_proto(f)						\
393 void	__bs_c(f,_bs_unmap) (void *t, bus_size_t size);
394 
395 #define bs_subregion_proto(f)						\
396 int	__bs_c(f,_bs_subregion) (void *t, bus_space_handle_t bsh,	\
397 	    bus_size_t offset, bus_size_t size, 			\
398 	    bus_space_handle_t *nbshp);
399 
400 #define bs_alloc_proto(f)						\
401 int	__bs_c(f,_bs_alloc) (void *t, bus_addr_t rstart,		\
402 	    bus_addr_t rend, bus_size_t size, bus_size_t align,		\
403 	    bus_size_t boundary, int cacheable, bus_addr_t *addrp,	\
404 	    bus_space_handle_t *bshp);
405 
406 #define bs_free_proto(f)						\
407 void	__bs_c(f,_bs_free) (void *t, bus_space_handle_t bsh,	\
408 	    bus_size_t size);
409 
410 #define bs_vaddr_proto(f)						\
411 void *	__bs_c(f,_bs_vaddr) (void *t, bus_space_handle_t bsh);
412 
413 #define bs_mmap_proto(f)						\
414 int	__bs_c(f,_bs_mmap) (dev_t, vm_offset_t, vm_paddr_t *, int);
415 
416 #define bs_barrier_proto(f)						\
417 void	__bs_c(f,_bs_barrier) (void *t, bus_space_handle_t bsh,	\
418 	    bus_size_t offset, bus_size_t len, int flags);
419 
420 #define	bs_r_1_proto(f)							\
421 u_int8_t	__bs_c(f,_bs_r_1) (void *t, bus_space_handle_t bsh,	\
422 		    bus_size_t offset);
423 
424 #define	bs_r_2_proto(f)							\
425 u_int16_t	__bs_c(f,_bs_r_2) (void *t, bus_space_handle_t bsh,	\
426 		    bus_size_t offset);
427 
428 #define	bs_r_4_proto(f)							\
429 u_int32_t	__bs_c(f,_bs_r_4) (void *t, bus_space_handle_t bsh,	\
430 		    bus_size_t offset);
431 
432 #define	bs_r_8_proto(f)							\
433 u_int64_t	__bs_c(f,_bs_r_8) (void *t, bus_space_handle_t bsh,	\
434 		    bus_size_t offset);
435 
436 #define	bs_w_1_proto(f)							\
437 void	__bs_c(f,_bs_w_1) (void *t, bus_space_handle_t bsh,		\
438 	    bus_size_t offset, u_int8_t value);
439 
440 #define	bs_w_2_proto(f)							\
441 void	__bs_c(f,_bs_w_2) (void *t, bus_space_handle_t bsh,		\
442 	    bus_size_t offset, u_int16_t value);
443 
444 #define	bs_w_4_proto(f)							\
445 void	__bs_c(f,_bs_w_4) (void *t, bus_space_handle_t bsh,		\
446 	    bus_size_t offset, u_int32_t value);
447 
448 #define	bs_w_8_proto(f)							\
449 void	__bs_c(f,_bs_w_8) (void *t, bus_space_handle_t bsh,		\
450 	    bus_size_t offset, u_int64_t value);
451 
452 #define	bs_rm_1_proto(f)						\
453 void	__bs_c(f,_bs_rm_1) (void *t, bus_space_handle_t bsh,	\
454 	    bus_size_t offset, u_int8_t *addr, bus_size_t count);
455 
456 #define	bs_rm_2_proto(f)						\
457 void	__bs_c(f,_bs_rm_2) (void *t, bus_space_handle_t bsh,	\
458 	    bus_size_t offset, u_int16_t *addr, bus_size_t count);
459 
460 #define	bs_rm_4_proto(f)						\
461 void	__bs_c(f,_bs_rm_4) (void *t, bus_space_handle_t bsh,	\
462 	    bus_size_t offset, u_int32_t *addr, bus_size_t count);
463 
464 #define	bs_rm_8_proto(f)						\
465 void	__bs_c(f,_bs_rm_8) (void *t, bus_space_handle_t bsh,	\
466 	    bus_size_t offset, u_int64_t *addr, bus_size_t count);
467 
468 #define	bs_wm_1_proto(f)						\
469 void	__bs_c(f,_bs_wm_1) (void *t, bus_space_handle_t bsh,	\
470 	    bus_size_t offset, const u_int8_t *addr, bus_size_t count);
471 
472 #define	bs_wm_2_proto(f)						\
473 void	__bs_c(f,_bs_wm_2) (void *t, bus_space_handle_t bsh,	\
474 	    bus_size_t offset, const u_int16_t *addr, bus_size_t count);
475 
476 #define	bs_wm_4_proto(f)						\
477 void	__bs_c(f,_bs_wm_4) (void *t, bus_space_handle_t bsh,	\
478 	    bus_size_t offset, const u_int32_t *addr, bus_size_t count);
479 
480 #define	bs_wm_8_proto(f)						\
481 void	__bs_c(f,_bs_wm_8) (void *t, bus_space_handle_t bsh,	\
482 	    bus_size_t offset, const u_int64_t *addr, bus_size_t count);
483 
484 #define	bs_rr_1_proto(f)						\
485 void	__bs_c(f, _bs_rr_1) (void *t, bus_space_handle_t bsh,	\
486 	    bus_size_t offset, u_int8_t *addr, bus_size_t count);
487 
488 #define	bs_rr_2_proto(f)						\
489 void	__bs_c(f, _bs_rr_2) (void *t, bus_space_handle_t bsh,	\
490 	    bus_size_t offset, u_int16_t *addr, bus_size_t count);
491 
492 #define	bs_rr_4_proto(f)						\
493 void	__bs_c(f, _bs_rr_4) (void *t, bus_space_handle_t bsh,	\
494 	    bus_size_t offset, u_int32_t *addr, bus_size_t count);
495 
496 #define	bs_rr_8_proto(f)						\
497 void	__bs_c(f, _bs_rr_8) (void *t, bus_space_handle_t bsh,	\
498 	    bus_size_t offset, u_int64_t *addr, bus_size_t count);
499 
500 #define	bs_wr_1_proto(f)						\
501 void	__bs_c(f, _bs_wr_1) (void *t, bus_space_handle_t bsh,	\
502 	    bus_size_t offset, const u_int8_t *addr, bus_size_t count);
503 
504 #define	bs_wr_2_proto(f)						\
505 void	__bs_c(f, _bs_wr_2) (void *t, bus_space_handle_t bsh,	\
506 	    bus_size_t offset, const u_int16_t *addr, bus_size_t count);
507 
508 #define	bs_wr_4_proto(f)						\
509 void	__bs_c(f, _bs_wr_4) (void *t, bus_space_handle_t bsh,	\
510 	    bus_size_t offset, const u_int32_t *addr, bus_size_t count);
511 
512 #define	bs_wr_8_proto(f)						\
513 void	__bs_c(f, _bs_wr_8) (void *t, bus_space_handle_t bsh,	\
514 	    bus_size_t offset, const u_int64_t *addr, bus_size_t count);
515 
516 #define	bs_sm_1_proto(f)						\
517 void	__bs_c(f,_bs_sm_1) (void *t, bus_space_handle_t bsh,	\
518 	    bus_size_t offset, u_int8_t value, bus_size_t count);
519 
520 #define	bs_sm_2_proto(f)						\
521 void	__bs_c(f,_bs_sm_2) (void *t, bus_space_handle_t bsh,	\
522 	    bus_size_t offset, u_int16_t value, bus_size_t count);
523 
524 #define	bs_sm_4_proto(f)						\
525 void	__bs_c(f,_bs_sm_4) (void *t, bus_space_handle_t bsh,	\
526 	    bus_size_t offset, u_int32_t value, bus_size_t count);
527 
528 #define	bs_sm_8_proto(f)						\
529 void	__bs_c(f,_bs_sm_8) (void *t, bus_space_handle_t bsh,	\
530 	    bus_size_t offset, u_int64_t value, bus_size_t count);
531 
532 #define	bs_sr_1_proto(f)						\
533 void	__bs_c(f,_bs_sr_1) (void *t, bus_space_handle_t bsh,	\
534 	    bus_size_t offset, u_int8_t value, bus_size_t count);
535 
536 #define	bs_sr_2_proto(f)						\
537 void	__bs_c(f,_bs_sr_2) (void *t, bus_space_handle_t bsh,	\
538 	    bus_size_t offset, u_int16_t value, bus_size_t count);
539 
540 #define	bs_sr_4_proto(f)						\
541 void	__bs_c(f,_bs_sr_4) (void *t, bus_space_handle_t bsh,	\
542 	    bus_size_t offset, u_int32_t value, bus_size_t count);
543 
544 #define	bs_sr_8_proto(f)						\
545 void	__bs_c(f,_bs_sr_8) (void *t, bus_space_handle_t bsh,	\
546 	    bus_size_t offset, u_int64_t value, bus_size_t count);
547 
548 #define	bs_c_1_proto(f)							\
549 void	__bs_c(f,_bs_c_1) (void *t, bus_space_handle_t bsh1,	\
550 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
551 	    bus_size_t offset2, bus_size_t count);
552 
553 #define	bs_c_2_proto(f)							\
554 void	__bs_c(f,_bs_c_2) (void *t, bus_space_handle_t bsh1,	\
555 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
556 	    bus_size_t offset2, bus_size_t count);
557 
558 #define	bs_c_4_proto(f)							\
559 void	__bs_c(f,_bs_c_4) (void *t, bus_space_handle_t bsh1,	\
560 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
561 	    bus_size_t offset2, bus_size_t count);
562 
563 #define	bs_c_8_proto(f)							\
564 void	__bs_c(f,_bs_c_8) (void *t, bus_space_handle_t bsh1,	\
565 	    bus_size_t offset1, bus_space_handle_t bsh2,		\
566 	    bus_size_t offset2, bus_size_t count);
567 
568 #define bs_protos(f)		\
569 bs_map_proto(f);		\
570 bs_unmap_proto(f);		\
571 bs_subregion_proto(f);		\
572 bs_alloc_proto(f);		\
573 bs_free_proto(f);		\
574 bs_vaddr_proto(f);		\
575 bs_mmap_proto(f);		\
576 bs_barrier_proto(f);		\
577 bs_r_1_proto(f);		\
578 bs_r_2_proto(f);		\
579 bs_r_4_proto(f);		\
580 bs_r_8_proto(f);		\
581 bs_w_1_proto(f);		\
582 bs_w_2_proto(f);		\
583 bs_w_4_proto(f);		\
584 bs_w_8_proto(f);		\
585 bs_rm_1_proto(f);		\
586 bs_rm_2_proto(f);		\
587 bs_rm_4_proto(f);		\
588 bs_rm_8_proto(f);		\
589 bs_wm_1_proto(f);		\
590 bs_wm_2_proto(f);		\
591 bs_wm_4_proto(f);		\
592 bs_wm_8_proto(f);		\
593 bs_rr_1_proto(f);		\
594 bs_rr_2_proto(f);		\
595 bs_rr_4_proto(f);		\
596 bs_rr_8_proto(f);		\
597 bs_wr_1_proto(f);		\
598 bs_wr_2_proto(f);		\
599 bs_wr_4_proto(f);		\
600 bs_wr_8_proto(f);		\
601 bs_sm_1_proto(f);		\
602 bs_sm_2_proto(f);		\
603 bs_sm_4_proto(f);		\
604 bs_sm_8_proto(f);		\
605 bs_sr_1_proto(f);		\
606 bs_sr_2_proto(f);		\
607 bs_sr_4_proto(f);		\
608 bs_sr_8_proto(f);		\
609 bs_c_1_proto(f);		\
610 bs_c_2_proto(f);		\
611 bs_c_4_proto(f);		\
612 bs_c_8_proto(f);
613 
614 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
615 
616 /* Bus Space DMA macros */
617 
618 /*
619  * Flags used in various bus DMA methods.
620  */
621 #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
622 #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
623 #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
624 #define	BUS_DMA_COHERENT	0x004	/* hint: map memory DMA coherent */
625 #define	BUS_DMA_ZERO		0x008	/* hint: sequential, unidirectional */
626 #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
627 #define	BUS_DMA_BUS2		0x020
628 #define	BUS_DMA_BUS3		0x040
629 #define	BUS_DMA_BUS4		0x080
630 
631 /*
632  * Private flags stored in the DMA map.
633  */
634 #define	ARM32_DMAMAP_COHERENT	0x10000	/* no cache flush necessary on sync */
635 
636 /* Forwards needed by prototypes below. */
637 struct mbuf;
638 struct uio;
639 
640 /*
641  * Operations performed by bus_dmamap_sync().
642  */
643 #define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
644 #define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
645 #define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
646 #define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
647 
648 typedef struct bus_dma_tag	*bus_dma_tag_t;
649 typedef struct bus_dmamap	*bus_dmamap_t;
650 
651 #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
652 
653 /*
654  *	bus_dma_segment_t
655  *
656  *	Describes a single contiguous DMA transaction.  Values
657  *	are suitable for programming into DMA registers.
658  */
659 struct bus_dma_segment {
660 	/*
661 	 * PUBLIC MEMBERS: these are used by machine-independent code.
662 	 */
663 	bus_addr_t	ds_addr;	/* DMA address */
664 	bus_size_t	ds_len;		/* length of transfer */
665 };
666 typedef struct bus_dma_segment	bus_dma_segment_t;
667 
668 /*
669  *	arm32_dma_range
670  *
671  *	This structure describes a valid DMA range.
672  */
673 struct arm32_dma_range {
674 	bus_addr_t	dr_sysbase;	/* system base address */
675 	bus_addr_t	dr_busbase;	/* appears here on bus */
676 	bus_size_t	dr_len;		/* length of range */
677 };
678 
679 /*
680  *	bus_dma_tag_t
681  *
682  *	A machine-dependent opaque type describing the implementation of
683  *	DMA for a given bus.
684  */
685 
686 typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
687 typedef int bus_dmasync_op_t;
688 typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int);
689 
690 
691 #ifdef _ARM32_BUS_DMA_PRIVATE
692 
693 /* _dm_buftype */
694 #define	ARM32_BUFTYPE_INVALID		0
695 #define	ARM32_BUFTYPE_LINEAR		1
696 #define	ARM32_BUFTYPE_MBUF		2
697 #define	ARM32_BUFTYPE_UIO		3
698 #define	ARM32_BUFTYPE_RAW		4
699 
700 struct arm32_dma_range	*bus_dma_get_range(void);
701 #endif /* _ARM32_BUS_DMA_PRIVATE */
702 
703 /*
704  * A function that returns 1 if the address cannot be accessed by
705  * a device and 0 if it can be.
706  */
707 typedef int bus_dma_filter_t(void *, bus_addr_t);
708 
709 /*
710  * A function that performs driver-specific syncronization on behalf of
711  * busdma.
712  */
713 typedef enum {
714 	BUS_DMA_LOCK    = 0x01,
715 	BUS_DMA_UNLOCK  = 0x02,
716 } bus_dma_lock_op_t;
717 
718 typedef void bus_dma_lock_t(void *, bus_dma_lock_op_t);
719 
720 /*
721  * Allocate a device specific dma_tag encapsulating the constraints of
722  * the parent tag in addition to other restrictions specified:
723  *
724  *      alignment:      alignment for segments.
725  *      boundary:       Boundary that segments cannot cross.
726  *      lowaddr:        Low restricted address that cannot appear in a mapping.
727  *      highaddr:       High restricted address that cannot appear in a mapping.
728  *      filtfunc:       An optional function to further test if an address
729  *                      within the range of lowaddr and highaddr cannot appear
730  *                      in a mapping.
731  *      filtfuncarg:    An argument that will be passed to filtfunc in addition
732  *                      to the address to test.
733  *      maxsize:        Maximum mapping size supported by this tag.
734  *      nsegments:      Number of discontinuities allowed in maps.
735  *      maxsegsz:       Maximum size of a segment in the map.
736  *      flags:          Bus DMA flags.
737  *      dmat:           A pointer to set to a valid dma tag should the return
738  *                      value of this function indicate success.
739  */
740 int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
741 		       bus_size_t boundary, bus_addr_t lowaddr,
742 		       bus_addr_t highaddr, bus_dma_filter_t *filtfunc,
743 		       void *filtfuncarg, bus_size_t maxsize, int nsegments,
744 		       bus_size_t maxsegsz, int flags, bus_dma_lock_t *lockfunc,
745 		       void *lockfuncarg, bus_dma_tag_t *dmat);
746 
747 int bus_dma_tag_destroy(bus_dma_tag_t dmat);
748 
749 int	bus_dmamap_create (bus_dma_tag_t, int, bus_dmamap_t *);
750 int	bus_dmamap_destroy (bus_dma_tag_t, bus_dmamap_t);
751 int	bus_dmamap_load (bus_dma_tag_t, bus_dmamap_t, void *,
752 	    bus_size_t, bus_dmamap_callback_t *, void *, int);
753 int	bus_dmamap_load_mbuf (bus_dma_tag_t, bus_dmamap_t,
754 	    struct mbuf *, bus_dmamap_callback2_t *, void *, int);
755 int	bus_dmamap_load_uio (bus_dma_tag_t, bus_dmamap_t,
756 	    struct uio *, bus_dmamap_callback2_t *, void *, int);
757 void	bus_dmamap_unload (bus_dma_tag_t, bus_dmamap_t);
758 void	bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t);
759 
760 int	bus_dmamem_alloc (bus_dma_tag_t tag, void **vaddr, int flag,
761     bus_dmamap_t *mapp);
762 void	bus_dmamem_free (bus_dma_tag_t tag, void *vaddr, bus_dmamap_t map);
763 
764 /*
765  * Generic helper function for manipulating mutexes.
766  */
767 void busdma_lock_mutex(void *arg, bus_dma_lock_op_t op);
768 
769 #endif /* _MACHINE_BUS_H_ */
770