1 /*        $NetBSD: bus_funcs.h,v 1.13 2023/04/18 11:06:57 skrll Exp $ */
2 
3 /*-
4  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*
34  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
35  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  * 1. Redistributions of source code must retain the above copyright
41  *    notice, this list of conditions and the following disclaimer.
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  * 3. All advertising materials mentioning features or use of this software
46  *    must display the following acknowledgement:
47  *      This product includes software developed by Christopher G. Demetriou
48  *        for the NetBSD Project.
49  * 4. The name of the author may not be used to endorse or promote products
50  *    derived from this software without specific prior written permission
51  *
52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  */
63 
64 #ifndef _ARM_BUS_FUNCS_H_
65 #define _ARM_BUS_FUNCS_H_
66 
67 #ifdef _KERNEL_OPT
68 #include "opt_cputypes.h"
69 #endif
70 
71 /*
72  * Utility macros; INTERNAL USE ONLY.
73  */
74 #define   __bs_c(a,b)                   __CONCAT(a,b)
75 #define   __bs_opname(op,size)          __bs_c(__bs_c(__bs_c(bs_,op),_),size)
76 
77 #define   __bs_rs(sz, t, h, o)                                                            \
78           (*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o)
79 #define   __bs_ws(sz, t, h, o, v)                                                         \
80           (*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v)
81 #define   __bs_nonsingle(type, sz, t, h, o, a, c)                               \
82           (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c)
83 #define   __bs_set(type, sz, t, h, o, v, c)                                     \
84           (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c)
85 #define   __bs_copy(sz, t, h1, o1, h2, o2, cnt)                                 \
86           (*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt)
87 
88 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
89 #define   __bs_opname_s(op,size)        __bs_c(__bs_c(__bs_c(__bs_c(bs_,op),_),size),_s)
90 #define   __bs_rs_s(sz, t, h, o)                                                          \
91           (*(t)->__bs_opname_s(r,sz))((t)->bs_cookie, h, o)
92 #define   __bs_ws_s(sz, t, h, o, v)                                             \
93           (*(t)->__bs_opname_s(w,sz))((t)->bs_cookie, h, o, v)
94 #define   __bs_nonsingle_s(type, sz, t, h, o, a, c)                             \
95           (*(t)->__bs_opname_s(type,sz))((t)->bs_cookie, h, o, a, c)
96 #define   __bs_set_s(type, sz, t, h, o, v, c)                                   \
97           (*(t)->__bs_opname_s(type,sz))((t)->bs_cookie, h, o, v, c)
98 #define   __bs_copy_s(sz, t, h1, o1, h2, o2, cnt)                               \
99           (*(t)->__bs_opname_s(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt)
100 #endif
101 
102 #ifdef __BUS_SPACE_HAS_PROBING_METHODS
103 #define   __bs_pe(sz, t, h, o, v)                                                         \
104           (*(t)->__bs_opname(pe,sz))((t)->bs_cookie, h, o, v)
105 #define   __bs_po(sz, t, h, o, v)                                                         \
106           (*(t)->__bs_opname(po,sz))((t)->bs_cookie, h, o, v)
107 #endif
108 
109 /*
110  * Mapping and unmapping operations.
111  */
112 #define   bus_space_map(t, a, s, c, hp)                                         \
113           (*(t)->bs_map)((t)->bs_cookie, (a), (s), (c), (hp))
114 #define   bus_space_unmap(t, h, s)                                              \
115           (*(t)->bs_unmap)((t)->bs_cookie, (h), (s))
116 #define   bus_space_subregion(t, h, o, s, hp)                                   \
117           (*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp))
118 
119 
120 /*
121  * Allocation and deallocation operations.
122  */
123 #define   bus_space_alloc(t, rs, re, s, a, b, c, ap, hp)                        \
124           (*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b), \
125               (c), (ap), (hp))
126 #define   bus_space_free(t, h, s)                                                         \
127           (*(t)->bs_free)((t)->bs_cookie, (h), (s))
128 
129 /*
130  * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
131  */
132 #define   bus_space_vaddr(t, h)                                                           \
133           (*(t)->bs_vaddr)((t)->bs_cookie, (h))
134 
135 /*
136  * MMap bus space for a user application.
137  */
138 #define bus_space_mmap(t, a, o, p, f)                                           \
139           (*(t)->bs_mmap)((t)->bs_cookie, (a), (o), (p), (f))
140 
141 /*
142  * Bus barrier operations.
143  */
144 #define   bus_space_barrier(t, h, o, l, f)                                      \
145           (*(t)->bs_barrier)((t)->bs_cookie, (h), (o), (l), (f))
146 
147 /*
148  * Bus read (single) operations.
149  */
150 #define   bus_space_read_1(t, h, o)     __bs_rs(1,(t),(h),(o))
151 #define   bus_space_read_2(t, h, o)     __bs_rs(2,(t),(h),(o))
152 #define   bus_space_read_4(t, h, o)     __bs_rs(4,(t),(h),(o))
153 #ifdef __HAVE_BUS_SPACE_8
154 #define   bus_space_read_8(t, h, o)     __bs_rs(8,(t),(h),(o))
155 #endif
156 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
157 #define   bus_space_read_stream_1(t, h, o)        __bs_rs_s(1,(t),(h),(o))
158 #define   bus_space_read_stream_2(t, h, o)        __bs_rs_s(2,(t),(h),(o))
159 #define   bus_space_read_stream_4(t, h, o)        __bs_rs_s(4,(t),(h),(o))
160 #ifdef __HAVE_BUS_SPACE_8
161 #define   bus_space_read_stream_8(t, h, o)        __bs_rs_s(8,(t),(h),(o))
162 #endif
163 #endif
164 
165 
166 /*
167  * Bus read multiple operations.
168  */
169 #define   bus_space_read_multi_1(t, h, o, a, c)                                 \
170           __bs_nonsingle(rm,1,(t),(h),(o),(a),(c))
171 #define   bus_space_read_multi_2(t, h, o, a, c)                                 \
172           __bs_nonsingle(rm,2,(t),(h),(o),(a),(c))
173 #define   bus_space_read_multi_4(t, h, o, a, c)                                 \
174           __bs_nonsingle(rm,4,(t),(h),(o),(a),(c))
175 #ifdef __HAVE_BUS_SPACE_8
176 #define   bus_space_read_multi_8(t, h, o, a, c)                                 \
177           __bs_nonsingle(rm,8,(t),(h),(o),(a),(c))
178 #endif
179 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
180 #define   bus_space_read_multi_stream_1(t, h, o, a, c)                          \
181           __bs_nonsingle_s(rm,1,(t),(h),(o),(a),(c))
182 #define   bus_space_read_multi_stream_2(t, h, o, a, c)                          \
183           __bs_nonsingle_s(rm,2,(t),(h),(o),(a),(c))
184 #define   bus_space_read_multi_stream_4(t, h, o, a, c)                          \
185           __bs_nonsingle_s(rm,4,(t),(h),(o),(a),(c))
186 #ifdef __HAVE_BUS_SPACE_8
187 #define   bus_space_read_multi_stream_8(t, h, o, a, c)                          \
188           __bs_nonsingle_s(rm,8,(t),(h),(o),(a),(c))
189 #endif
190 #endif
191 
192 
193 /*
194  * Bus read region operations.
195  */
196 #define   bus_space_read_region_1(t, h, o, a, c)                                \
197           __bs_nonsingle(rr,1,(t),(h),(o),(a),(c))
198 #define   bus_space_read_region_2(t, h, o, a, c)                                \
199           __bs_nonsingle(rr,2,(t),(h),(o),(a),(c))
200 #define   bus_space_read_region_4(t, h, o, a, c)                                \
201           __bs_nonsingle(rr,4,(t),(h),(o),(a),(c))
202 #ifdef __HAVE_BUS_SPACE_8
203 #define   bus_space_read_region_8(t, h, o, a, c)                                \
204           __bs_nonsingle(rr,8,(t),(h),(o),(a),(c))
205 #endif
206 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
207 #define   bus_space_read_region_stream_1(t, h, o, a, c)                         \
208           __bs_nonsingle_s(rr,1,(t),(h),(o),(a),(c))
209 #define   bus_space_read_region_stream_2(t, h, o, a, c)                         \
210           __bs_nonsingle_s(rr,2,(t),(h),(o),(a),(c))
211 #define   bus_space_read_region_stream_4(t, h, o, a, c)                         \
212           __bs_nonsingle_s(rr,4,(t),(h),(o),(a),(c))
213 #ifdef __HAVE_BUS_SPACE_8
214 #define   bus_space_read_region_stream_8(t, h, o, a, c)                         \
215           __bs_nonsingle_s(rr,8,(t),(h),(o),(a),(c))
216 #endif
217 #endif
218 
219 
220 /*
221  * Bus write (single) operations.
222  */
223 #define   bus_space_write_1(t, h, o, v) __bs_ws(1,(t),(h),(o),(v))
224 #define   bus_space_write_2(t, h, o, v) __bs_ws(2,(t),(h),(o),(v))
225 #define   bus_space_write_4(t, h, o, v) __bs_ws(4,(t),(h),(o),(v))
226 #ifdef __HAVE_BUS_SPACE_8
227 #define   bus_space_write_8(t, h, o, v) __bs_ws(8,(t),(h),(o),(v))
228 #endif
229 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
230 #define   bus_space_write_stream_1(t, h, o, v)    __bs_ws_s(1,(t),(h),(o),(v))
231 #define   bus_space_write_stream_2(t, h, o, v)    __bs_ws_s(2,(t),(h),(o),(v))
232 #define   bus_space_write_stream_4(t, h, o, v)    __bs_ws_s(4,(t),(h),(o),(v))
233 #ifdef __HAVE_BUS_SPACE_8
234 #define   bus_space_write_stream_8(t, h, o, v)    __bs_ws_s(8,(t),(h),(o),(v))
235 #endif
236 #endif
237 
238 
239 /*
240  * Bus write multiple operations.
241  */
242 #define   bus_space_write_multi_1(t, h, o, a, c)                                \
243           __bs_nonsingle(wm,1,(t),(h),(o),(a),(c))
244 #define   bus_space_write_multi_2(t, h, o, a, c)                                \
245           __bs_nonsingle(wm,2,(t),(h),(o),(a),(c))
246 #define   bus_space_write_multi_4(t, h, o, a, c)                                \
247           __bs_nonsingle(wm,4,(t),(h),(o),(a),(c))
248 #ifdef __HAVE_BUS_SPACE_8
249 #define   bus_space_write_multi_8(t, h, o, a, c)                                \
250           __bs_nonsingle(wm,8,(t),(h),(o),(a),(c))
251 #endif
252 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
253 #define   bus_space_write_multi_stream_1(t, h, o, a, c)                         \
254           __bs_nonsingle_s(wm,1,(t),(h),(o),(a),(c))
255 #define   bus_space_write_multi_stream_2(t, h, o, a, c)                         \
256           __bs_nonsingle_s(wm,2,(t),(h),(o),(a),(c))
257 #define   bus_space_write_multi_stream_4(t, h, o, a, c)                         \
258           __bs_nonsingle_s(wm,4,(t),(h),(o),(a),(c))
259 #ifdef __HAVE_BUS_SPACE_8
260 #define   bus_space_write_multi_stream_8(t, h, o, a, c)                         \
261           __bs_nonsingle_s(wm,8,(t),(h),(o),(a),(c))
262 #endif
263 #endif
264 
265 
266 /*
267  * Bus write region operations.
268  */
269 #define   bus_space_write_region_1(t, h, o, a, c)                               \
270           __bs_nonsingle(wr,1,(t),(h),(o),(a),(c))
271 #define   bus_space_write_region_2(t, h, o, a, c)                               \
272           __bs_nonsingle(wr,2,(t),(h),(o),(a),(c))
273 #define   bus_space_write_region_4(t, h, o, a, c)                               \
274           __bs_nonsingle(wr,4,(t),(h),(o),(a),(c))
275 #ifdef __HAVE_BUS_SPACE_8
276 #define   bus_space_write_region_8(t, h, o, a, c)                               \
277           __bs_nonsingle(wr,8,(t),(h),(o),(a),(c))
278 #endif
279 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
280 #define   bus_space_write_region_stream_1(t, h, o, a, c)                        \
281           __bs_nonsingle_s(wr,1,(t),(h),(o),(a),(c))
282 #define   bus_space_write_region_stream_2(t, h, o, a, c)                        \
283           __bs_nonsingle_s(wr,2,(t),(h),(o),(a),(c))
284 #define   bus_space_write_region_stream_4(t, h, o, a, c)                        \
285           __bs_nonsingle_s(wr,4,(t),(h),(o),(a),(c))
286 #ifdef __HAVE_BUS_SPACE_8
287 #define   bus_space_write_region_stream_8(t, h, o, a, c)                        \
288           __bs_nonsingle_s(wr,8,(t),(h),(o),(a),(c))
289 #endif
290 #endif
291 
292 
293 /*
294  * Set multiple operations.
295  */
296 #define   bus_space_set_multi_1(t, h, o, v, c)                                  \
297           __bs_set(sm,1,(t),(h),(o),(v),(c))
298 #define   bus_space_set_multi_2(t, h, o, v, c)                                  \
299           __bs_set(sm,2,(t),(h),(o),(v),(c))
300 #define   bus_space_set_multi_4(t, h, o, v, c)                                  \
301           __bs_set(sm,4,(t),(h),(o),(v),(c))
302 #ifdef __HAVE_BUS_SPACE_8
303 #define   bus_space_set_multi_8(t, h, o, v, c)                                  \
304           __bs_set(sm,8,(t),(h),(o),(v),(c))
305 #endif
306 
307 /*
308  * Set region operations.
309  */
310 #define   bus_space_set_region_1(t, h, o, v, c)                                 \
311           __bs_set(sr,1,(t),(h),(o),(v),(c))
312 #define   bus_space_set_region_2(t, h, o, v, c)                                 \
313           __bs_set(sr,2,(t),(h),(o),(v),(c))
314 #define   bus_space_set_region_4(t, h, o, v, c)                                 \
315           __bs_set(sr,4,(t),(h),(o),(v),(c))
316 #ifdef __HAVE_BUS_SPACE_8
317 #define   bus_space_set_region_8(t, h, o, v, c)                                 \
318           __bs_set(sr,8,(t),(h),(o),(v),(c))
319 #endif
320 
321 /*
322  * Copy operations.
323  */
324 #define   bus_space_copy_region_1(t, h1, o1, h2, o2, c)                                   \
325           __bs_copy(1, t, h1, o1, h2, o2, c)
326 #define   bus_space_copy_region_2(t, h1, o1, h2, o2, c)                                   \
327           __bs_copy(2, t, h1, o1, h2, o2, c)
328 #define   bus_space_copy_region_4(t, h1, o1, h2, o2, c)                                   \
329           __bs_copy(4, t, h1, o1, h2, o2, c)
330 #ifdef __HAVE_BUS_SPACE_8
331 #define   bus_space_copy_region_8(t, h1, o1, h2, o2, c)                                   \
332           __bs_copy(8, t, h1, o1, h2, o2, c)
333 #endif
334 
335 /*
336  * Probing operations.
337  */
338 #ifdef __BUS_SPACE_HAS_PROBING_METHODS
339 #define   bus_space_peek_1(t, h, o, p)  __bs_pe(1,(t),(h),(o),(p))
340 #define   bus_space_peek_2(t, h, o, p)  __bs_pe(2,(t),(h),(o),(p))
341 #define   bus_space_peek_4(t, h, o, p)  __bs_pe(4,(t),(h),(o),(p))
342 #ifdef __HAVE_BUS_SPACE_8
343 #define   bus_space_peek_8(t, h, o, p)  __bs_pe(8,(t),(h),(o),(p))
344 #endif
345 
346 #define   bus_space_poke_1(t, h, o, v)  __bs_po(1,(t),(h),(o),(v))
347 #define   bus_space_poke_2(t, h, o, v)  __bs_po(2,(t),(h),(o),(v))
348 #define   bus_space_poke_4(t, h, o, v)  __bs_po(4,(t),(h),(o),(v))
349 #ifdef __HAVE_BUS_SPACE_8
350 #define   bus_space_poke_8(t, h, o, v)  __bs_po(8,(t),(h),(o),(v))
351 #endif
352 #endif
353 
354 /*
355  * Macros to provide prototypes for all the functions used in the
356  * bus_space structure
357  */
358 
359 #define bs_map_proto(f)                                                                   \
360 int       __bs_c(f,_bs_map)(void *t, bus_addr_t addr,                 \
361               bus_size_t size, int cacheable, bus_space_handle_t *bshp);
362 
363 #define bs_unmap_proto(f)                                                       \
364 void      __bs_c(f,_bs_unmap)(void *t, bus_space_handle_t bsh,        \
365               bus_size_t size);
366 
367 #define bs_subregion_proto(f)                                                   \
368 int       __bs_c(f,_bs_subregion)(void *t, bus_space_handle_t bsh,    \
369               bus_size_t offset, bus_size_t size,                               \
370               bus_space_handle_t *nbshp);
371 
372 #define bs_alloc_proto(f)                                                       \
373 int       __bs_c(f,_bs_alloc)(void *t, bus_addr_t rstart,             \
374               bus_addr_t rend, bus_size_t size, bus_size_t align,               \
375               bus_size_t boundary, int cacheable, bus_addr_t *addrp,  \
376               bus_space_handle_t *bshp);
377 
378 #define bs_free_proto(f)                                                        \
379 void      __bs_c(f,_bs_free)(void *t, bus_space_handle_t bsh,         \
380               bus_size_t size);
381 
382 #define bs_vaddr_proto(f)                                                       \
383 void *    __bs_c(f,_bs_vaddr)(void *t, bus_space_handle_t bsh);
384 
385 #define bs_mmap_proto(f)                                                        \
386 paddr_t   __bs_c(f,_bs_mmap)(void *, bus_addr_t, off_t, int, int);
387 
388 #define bs_barrier_proto(f)                                                     \
389 void      __bs_c(f,_bs_barrier)(void *t, bus_space_handle_t bsh,      \
390               bus_size_t offset, bus_size_t len, int flags);
391 
392 #define   bs_r_1_proto(f)                                                                 \
393 uint8_t   __bs_c(f,_bs_r_1)(void *t, bus_space_handle_t bsh,          \
394                         bus_size_t offset);
395 
396 #define   bs_r_2_proto(f)                                                                 \
397 uint16_t  __bs_c(f,_bs_r_2)(void *t, bus_space_handle_t bsh,          \
398                         bus_size_t offset);                                               \
399 uint16_t  __bs_c(f,_bs_r_2_swap)(void *t, bus_space_handle_t bsh,     \
400                         bus_size_t offset);
401 
402 #define   bs_r_4_proto(f)                                                                 \
403 uint32_t  __bs_c(f,_bs_r_4)(void *t, bus_space_handle_t bsh,          \
404                         bus_size_t offset);                                               \
405 uint32_t  __bs_c(f,_bs_r_4_swap)(void *t, bus_space_handle_t bsh,     \
406                         bus_size_t offset);
407 
408 #define   bs_r_8_proto(f)                                                                 \
409 uint64_t  __bs_c(f,_bs_r_8)(void *t, bus_space_handle_t bsh,          \
410                         bus_size_t offset);                                               \
411 uint64_t  __bs_c(f,_bs_r_8_swap)(void *t, bus_space_handle_t bsh,     \
412                         bus_size_t offset);
413 
414 #define   bs_w_1_proto(f)                                                                 \
415 void      __bs_c(f,_bs_w_1)(void *t, bus_space_handle_t bsh,                    \
416               bus_size_t offset, uint8_t value);
417 
418 #define   bs_w_2_proto(f)                                                                 \
419 void      __bs_c(f,_bs_w_2)(void *t, bus_space_handle_t bsh,                    \
420               bus_size_t offset, uint16_t value);                               \
421 void      __bs_c(f,_bs_w_2_swap)(void *t, bus_space_handle_t bsh,               \
422               bus_size_t offset, uint16_t value);
423 
424 #define   bs_w_4_proto(f)                                                                 \
425 void      __bs_c(f,_bs_w_4)(void *t, bus_space_handle_t bsh,                    \
426               bus_size_t offset, uint32_t value);                               \
427 void      __bs_c(f,_bs_w_4_swap)(void *t, bus_space_handle_t bsh,               \
428               bus_size_t offset, uint32_t value);
429 
430 #define   bs_w_8_proto(f)                                                                 \
431 void      __bs_c(f,_bs_w_8)(void *t, bus_space_handle_t bsh,                    \
432               bus_size_t offset, uint64_t value);                               \
433 void      __bs_c(f,_bs_w_8_swap)(void *t, bus_space_handle_t bsh,               \
434               bus_size_t offset, uint64_t value);
435 
436 #define   bs_rm_1_proto(f)                                                      \
437 void      __bs_c(f,_bs_rm_1)(void *t, bus_space_handle_t bsh,                   \
438               bus_size_t offset, uint8_t *addr, bus_size_t count);
439 
440 #define   bs_rm_2_proto(f)                                                      \
441 void      __bs_c(f,_bs_rm_2)(void *t, bus_space_handle_t bsh,                   \
442               bus_size_t offset, uint16_t *addr, bus_size_t count);   \
443 void      __bs_c(f,_bs_rm_2_swap)(void *t, bus_space_handle_t bsh,    \
444               bus_size_t offset, uint16_t *addr, bus_size_t count);
445 
446 #define   bs_rm_4_proto(f)                                                      \
447 void      __bs_c(f,_bs_rm_4)(void *t, bus_space_handle_t bsh,                   \
448               bus_size_t offset, uint32_t *addr, bus_size_t count);   \
449 void      __bs_c(f,_bs_rm_4_swap)(void *t, bus_space_handle_t bsh,    \
450               bus_size_t offset, uint32_t *addr, bus_size_t count);
451 
452 #define   bs_rm_8_proto(f)                                                      \
453 void      __bs_c(f,_bs_rm_8)(void *t, bus_space_handle_t bsh,                   \
454               bus_size_t offset, uint64_t *addr, bus_size_t count);   \
455 void      __bs_c(f,_bs_rm_8_swap)(void *t, bus_space_handle_t bsh,    \
456               bus_size_t offset, uint64_t *addr, bus_size_t count);
457 
458 #define   bs_wm_1_proto(f)                                                      \
459 void      __bs_c(f,_bs_wm_1)(void *t, bus_space_handle_t bsh,                   \
460               bus_size_t offset, const uint8_t *addr, bus_size_t count);        \
461 
462 #define   bs_wm_2_proto(f)                                                      \
463 void      __bs_c(f,_bs_wm_2)(void *t, bus_space_handle_t bsh,                   \
464               bus_size_t offset, const uint16_t *addr, bus_size_t count);       \
465 void      __bs_c(f,_bs_wm_2_swap)(void *t, bus_space_handle_t bsh,    \
466               bus_size_t offset, const uint16_t *addr, bus_size_t count);
467 
468 #define   bs_wm_4_proto(f)                                                      \
469 void      __bs_c(f,_bs_wm_4)(void *t, bus_space_handle_t bsh,                   \
470               bus_size_t offset, const uint32_t *addr, bus_size_t count);       \
471 void      __bs_c(f,_bs_wm_4_swap)(void *t, bus_space_handle_t bsh,    \
472               bus_size_t offset, const uint32_t *addr, bus_size_t count);
473 
474 #define   bs_wm_8_proto(f)                                                      \
475 void      __bs_c(f,_bs_wm_8)(void *t, bus_space_handle_t bsh,                   \
476               bus_size_t offset, const uint64_t *addr, bus_size_t count);       \
477 void      __bs_c(f,_bs_wm_8_swap)(void *t, bus_space_handle_t bsh,    \
478               bus_size_t offset, const uint64_t *addr, bus_size_t count);
479 
480 #define   bs_rr_1_proto(f)                                                      \
481 void      __bs_c(f, _bs_rr_1)(void *t, bus_space_handle_t bsh,                  \
482               bus_size_t offset, uint8_t *addr, bus_size_t count);
483 
484 #define   bs_rr_2_proto(f)                                                      \
485 void      __bs_c(f, _bs_rr_2)(void *t, bus_space_handle_t bsh,                  \
486               bus_size_t offset, uint16_t *addr, bus_size_t count);   \
487 void      __bs_c(f, _bs_rr_2_swap)(void *t, bus_space_handle_t bsh,   \
488               bus_size_t offset, uint16_t *addr, bus_size_t count);
489 
490 #define   bs_rr_4_proto(f)                                                      \
491 void      __bs_c(f, _bs_rr_4)(void *t, bus_space_handle_t bsh,                  \
492               bus_size_t offset, uint32_t *addr, bus_size_t count);   \
493 void      __bs_c(f, _bs_rr_4_swap)(void *t, bus_space_handle_t bsh,   \
494               bus_size_t offset, uint32_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, uint64_t *addr, bus_size_t count);   \
499 void      __bs_c(f, _bs_rr_8_swap)(void *t, bus_space_handle_t bsh,   \
500               bus_size_t offset, uint64_t *addr, bus_size_t count);
501 
502 #define   bs_wr_1_proto(f)                                                      \
503 void      __bs_c(f, _bs_wr_1)(void *t, bus_space_handle_t bsh,                  \
504               bus_size_t offset, const uint8_t *addr, bus_size_t count);
505 
506 #define   bs_wr_2_proto(f)                                                      \
507 void      __bs_c(f, _bs_wr_2)(void *t, bus_space_handle_t bsh,                  \
508               bus_size_t offset, const uint16_t *addr, bus_size_t count);       \
509 void      __bs_c(f, _bs_wr_2_swap)(void *t, bus_space_handle_t bsh,   \
510               bus_size_t offset, const uint16_t *addr, bus_size_t count);
511 
512 #define   bs_wr_4_proto(f)                                                      \
513 void      __bs_c(f, _bs_wr_4)(void *t, bus_space_handle_t bsh,                  \
514               bus_size_t offset, const uint32_t *addr, bus_size_t count);       \
515 void      __bs_c(f, _bs_wr_4_swap)(void *t, bus_space_handle_t bsh,   \
516               bus_size_t offset, const uint32_t *addr, bus_size_t count);
517 
518 #define   bs_wr_8_proto(f)                                                      \
519 void      __bs_c(f, _bs_wr_8)(void *t, bus_space_handle_t bsh,                  \
520               bus_size_t offset, const uint64_t *addr, bus_size_t count);       \
521 void      __bs_c(f, _bs_wr_8_swap)(void *t, bus_space_handle_t bsh,   \
522               bus_size_t offset, const uint64_t *addr, bus_size_t count);
523 
524 #define   bs_sm_1_proto(f)                                                      \
525 void      __bs_c(f,_bs_sm_1)(void *t, bus_space_handle_t bsh,                   \
526               bus_size_t offset, uint8_t value, bus_size_t count);
527 
528 #define   bs_sm_2_proto(f)                                                      \
529 void      __bs_c(f,_bs_sm_2)(void *t, bus_space_handle_t bsh,                   \
530               bus_size_t offset, uint16_t value, bus_size_t count);   \
531 void      __bs_c(f,_bs_sm_2_swap)(void *t, bus_space_handle_t bsh,              \
532               bus_size_t offset, uint16_t value, bus_size_t count);
533 
534 #define   bs_sm_4_proto(f)                                                      \
535 void      __bs_c(f,_bs_sm_4)(void *t, bus_space_handle_t bsh,                   \
536               bus_size_t offset, uint32_t value, bus_size_t count);   \
537 void      __bs_c(f,_bs_sm_4_swap)(void *t, bus_space_handle_t bsh,    \
538               bus_size_t offset, uint32_t value, bus_size_t count);
539 
540 #define   bs_sm_8_proto(f)                                                      \
541 void      __bs_c(f,_bs_sm_8)(void *t, bus_space_handle_t bsh,                   \
542               bus_size_t offset, uint64_t value, bus_size_t count);   \
543 void      __bs_c(f,_bs_sm_8_swap)(void *t, bus_space_handle_t bsh,    \
544               bus_size_t offset, uint64_t value, bus_size_t count);
545 
546 #define   bs_sr_1_proto(f)                                                      \
547 void      __bs_c(f,_bs_sr_1)(void *t, bus_space_handle_t bsh,                   \
548               bus_size_t offset, uint8_t value, bus_size_t count);
549 
550 #define   bs_sr_2_proto(f)                                                      \
551 void      __bs_c(f,_bs_sr_2)(void *t, bus_space_handle_t bsh,                   \
552               bus_size_t offset, uint16_t value, bus_size_t count);   \
553 void      __bs_c(f,_bs_sr_2_swap)(void *t, bus_space_handle_t bsh,    \
554               bus_size_t offset, uint16_t value, bus_size_t count);
555 
556 #define   bs_sr_4_proto(f)                                                      \
557 void      __bs_c(f,_bs_sr_4)(void *t, bus_space_handle_t bsh,                   \
558               bus_size_t offset, uint32_t value, bus_size_t count);   \
559 void      __bs_c(f,_bs_sr_4_swap)(void *t, bus_space_handle_t bsh,    \
560               bus_size_t offset, uint32_t value, bus_size_t count);
561 
562 #define   bs_sr_8_proto(f)                                                      \
563 void      __bs_c(f,_bs_sr_8)(void *t, bus_space_handle_t bsh,                   \
564               bus_size_t offset, uint64_t value, bus_size_t count);   \
565 void      __bs_c(f,_bs_sr_8_swap)(void *t, bus_space_handle_t bsh,    \
566               bus_size_t offset, uint64_t value, bus_size_t count);
567 
568 #define   bs_c_1_proto(f)                                                                 \
569 void      __bs_c(f,_bs_c_1)(void *t, bus_space_handle_t bsh1,                   \
570               bus_size_t offset1, bus_space_handle_t bsh2,            \
571               bus_size_t offset2, bus_size_t count);
572 
573 #define   bs_c_2_proto(f)                                                                 \
574 void      __bs_c(f,_bs_c_2)(void *t, bus_space_handle_t bsh1,                   \
575               bus_size_t offset1, bus_space_handle_t bsh2,            \
576               bus_size_t offset2, bus_size_t count);
577 
578 #define   bs_c_4_proto(f)                                                                 \
579 void      __bs_c(f,_bs_c_4)(void *t, bus_space_handle_t bsh1,                   \
580               bus_size_t offset1, bus_space_handle_t bsh2,            \
581               bus_size_t offset2, bus_size_t count);
582 
583 #define   bs_c_8_proto(f)                                                                 \
584 void      __bs_c(f,_bs_c_8)(void *t, bus_space_handle_t bsh1,                   \
585               bus_size_t offset1, bus_space_handle_t bsh2,            \
586               bus_size_t offset2, bus_size_t count);
587 
588 #define   bs_pe_1_proto(f)                                                      \
589 int       __bs_c(f,_bs_pe_1)(void *t, bus_space_handle_t bsh,                   \
590               bus_size_t offset, uint8_t *datap);
591 
592 #define   bs_pe_2_proto(f)                                                      \
593 int       __bs_c(f,_bs_pe_2)(void *t, bus_space_handle_t bsh,                   \
594               bus_size_t offset, uint16_t *datap);                              \
595 
596 #define   bs_pe_4_proto(f)                                                      \
597 int       __bs_c(f,_bs_pe_4)(void *t, bus_space_handle_t bsh,                   \
598               bus_size_t offset, uint32_t *datap);                              \
599 
600 #define   bs_pe_8_proto(f)                                                      \
601 int       __bs_c(f,_bs_pe_8)(void *t, bus_space_handle_t bsh,                   \
602               bus_size_t offset, uint64_t *datap);                              \
603 
604 #define   bs_po_1_proto(f)                                                      \
605 int       __bs_c(f,_bs_po_1)(void *t, bus_space_handle_t bsh,                   \
606               bus_size_t offset, uint8_t value);
607 
608 #define   bs_po_2_proto(f)                                                      \
609 int       __bs_c(f,_bs_po_2)(void *t, bus_space_handle_t bsh,                   \
610               bus_size_t offset, uint16_t value);                               \
611 
612 #define   bs_po_4_proto(f)                                                      \
613 int       __bs_c(f,_bs_po_4)(void *t, bus_space_handle_t bsh,                   \
614               bus_size_t offset, uint32_t value);                               \
615 
616 #define   bs_po_8_proto(f)                                                      \
617 int       __bs_c(f,_bs_po_8)(void *t, bus_space_handle_t bsh,                   \
618               bus_size_t offset, uint64_t value);                               \
619 
620 
621 #define bs_protos(f)                    \
622 bs_map_proto(f);              \
623 bs_unmap_proto(f);            \
624 bs_subregion_proto(f);                  \
625 bs_alloc_proto(f);            \
626 bs_free_proto(f);             \
627 bs_vaddr_proto(f);            \
628 bs_mmap_proto(f);             \
629 bs_barrier_proto(f);                    \
630 bs_r_1_proto(f);              \
631 bs_r_2_proto(f);              \
632 bs_r_4_proto(f);              \
633 bs_r_8_proto(f);              \
634 bs_w_1_proto(f);              \
635 bs_w_2_proto(f);              \
636 bs_w_4_proto(f);              \
637 bs_w_8_proto(f);              \
638 bs_rm_1_proto(f);             \
639 bs_rm_2_proto(f);             \
640 bs_rm_4_proto(f);             \
641 bs_rm_8_proto(f);             \
642 bs_wm_1_proto(f);             \
643 bs_wm_2_proto(f);             \
644 bs_wm_4_proto(f);             \
645 bs_wm_8_proto(f);             \
646 bs_rr_1_proto(f);             \
647 bs_rr_2_proto(f);             \
648 bs_rr_4_proto(f);             \
649 bs_rr_8_proto(f);             \
650 bs_wr_1_proto(f);             \
651 bs_wr_2_proto(f);             \
652 bs_wr_4_proto(f);             \
653 bs_wr_8_proto(f);             \
654 bs_sm_1_proto(f);             \
655 bs_sm_2_proto(f);             \
656 bs_sm_4_proto(f);             \
657 bs_sm_8_proto(f);             \
658 bs_sr_1_proto(f);             \
659 bs_sr_2_proto(f);             \
660 bs_sr_4_proto(f);             \
661 bs_sr_8_proto(f);             \
662 bs_c_1_proto(f);              \
663 bs_c_2_proto(f);              \
664 bs_c_4_proto(f);              \
665 bs_c_8_proto(f);              \
666 bs_pe_1_proto(f);             \
667 bs_pe_2_proto(f);             \
668 bs_pe_4_proto(f);             \
669 bs_pe_8_proto(f);             \
670 bs_po_1_proto(f);             \
671 bs_po_2_proto(f);             \
672 bs_po_4_proto(f);             \
673 bs_po_8_proto(f);
674 
675 /* Bus Space DMA macros */
676 
677 /* Forwards needed by prototypes below. */
678 struct mbuf;
679 struct uio;
680 
681 int bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, bus_size_t,
682     int, bus_dmamap_t *);
683 void bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
684 int bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
685     struct proc *, int);
686 int bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int);
687 int bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int);
688 int bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
689     int, bus_size_t, int);
690 void bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
691 void bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, bus_size_t, int);
692 
693 #define   bus_dmamem_alloc(t, s, a, b, sg, n, r, f)                   \
694           (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
695 #define   bus_dmamem_free(t, sg, n)                                   \
696           (*(t)->_dmamem_free)((t), (sg), (n))
697 #define   bus_dmamem_map(t, sg, n, s, k, f)                           \
698           (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
699 #define   bus_dmamem_unmap(t, k, s)                                   \
700           (*(t)->_dmamem_unmap)((t), (k), (s))
701 #define   bus_dmamem_mmap(t, sg, n, o, p, f)                          \
702           (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
703 
704 #define   bus_dmatag_subregion(t, mna, mxa, nt, f)                    \
705           (*(t)->_dmatag_subregion)((t), (mna), (mxa), (nt), (f))
706 #define   bus_dmatag_destroy(t)                                                 \
707           (*(t)->_dmatag_destroy)(t)
708 
709 #ifdef _ARM32_BUS_DMA_PRIVATE
710 
711 int       arm32_dma_range_intersect(struct arm32_dma_range *, int,
712               paddr_t pa, psize_t size, paddr_t *pap, psize_t *sizep);
713 
714 int       _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
715               bus_size_t, int, bus_dmamap_t *);
716 void      _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
717 int       _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
718               bus_size_t, struct proc *, int);
719 int       _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
720               struct mbuf *, int);
721 int       _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
722               struct uio *, int);
723 int       _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
724               bus_dma_segment_t *, int, bus_size_t, int);
725 void      _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
726 void      _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
727               bus_size_t, int);
728 
729 #if defined(_ARM32_NEED_BUS_DMA_BOUNCE) || defined(CPU_CORTEX)
730 #define   _BUS_DMAMAP_SYNC_FUNCS \
731           ._dmamap_sync_pre = _bus_dmamap_sync,   \
732           ._dmamap_sync_post = _bus_dmamap_sync
733 #else
734 #define   _BUS_DMAMAP_SYNC_FUNCS \
735           ._dmamap_sync_pre = _bus_dmamap_sync
736 #endif
737 
738 #define   _BUS_DMAMAP_FUNCS \
739           ._dmamap_create = _bus_dmamap_create,             \
740           ._dmamap_destroy = _bus_dmamap_destroy,           \
741           ._dmamap_load = _bus_dmamap_load,                 \
742           ._dmamap_load_mbuf = _bus_dmamap_load_mbuf,       \
743           ._dmamap_load_raw = _bus_dmamap_load_raw,         \
744           ._dmamap_load_uio = _bus_dmamap_load_uio,         \
745           ._dmamap_unload = _bus_dmamap_unload,             \
746           _BUS_DMAMAP_SYNC_FUNCS
747 
748 int       _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
749               bus_size_t alignment, bus_size_t boundary,
750               bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
751 void      _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
752               int nsegs);
753 int       _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
754               int nsegs, size_t size, void **kvap, int flags);
755 void      _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
756               size_t size);
757 paddr_t   _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
758               int nsegs, off_t off, int prot, int flags);
759 
760 #define   _BUS_DMAMEM_FUNCS \
761           ._dmamem_alloc = _bus_dmamem_alloc,     \
762           ._dmamem_free = _bus_dmamem_free,       \
763           ._dmamem_map = _bus_dmamem_map,                   \
764           ._dmamem_unmap = _bus_dmamem_unmap,     \
765           ._dmamem_mmap = _bus_dmamem_mmap
766 
767 int       _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
768               bus_size_t alignment, bus_size_t boundary,
769               bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
770               paddr_t low, paddr_t high);
771 
772 int       _bus_dmatag_subregion(bus_dma_tag_t, bus_addr_t, bus_addr_t,
773               bus_dma_tag_t *, int);
774 void      _bus_dmatag_destroy(bus_dma_tag_t);
775 
776 #define   _BUS_DMATAG_FUNCS \
777           ._dmatag_subregion = _bus_dmatag_subregion,       \
778           ._dmatag_destroy = _bus_dmatag_destroy
779 
780 #endif /* _ARM32_BUS_DMA_PRIVATE */
781 
782 #endif /* _ARM_BUS_FUNCS_H_ */
783