bus_funcs.h revision 1.2.2.1 1 /* $NetBSD: bus_funcs.h,v 1.2.2.1 2012/11/20 03:01:05 tls 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 _ARM32_BUS_FUNCS_H_
65 #define _ARM32_BUS_FUNCS_H_
66
67 /*
68 * Utility macros; INTERNAL USE ONLY.
69 */
70 #define __bs_c(a,b) __CONCAT(a,b)
71 #define __bs_opname(op,size) __bs_c(__bs_c(__bs_c(bs_,op),_),size)
72
73 #define __bs_rs(sz, t, h, o) \
74 (*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o)
75 #define __bs_ws(sz, t, h, o, v) \
76 (*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v)
77 #define __bs_nonsingle(type, sz, t, h, o, a, c) \
78 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c)
79 #define __bs_set(type, sz, t, h, o, v, c) \
80 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c)
81 #define __bs_copy(sz, t, h1, o1, h2, o2, cnt) \
82 (*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt)
83
84 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
85 #define __bs_opname_s(op,size) __bs_c(__bs_c(__bs_c(__bs_c(bs_,op),_),size),_s)
86 #define __bs_rs_s(sz, t, h, o) \
87 (*(t)->__bs_opname_s(r,sz))((t)->bs_cookie, h, o)
88 #define __bs_ws_s(sz, t, h, o, v) \
89 (*(t)->__bs_opname_s(w,sz))((t)->bs_cookie, h, o, v)
90 #define __bs_nonsingle_s(type, sz, t, h, o, a, c) \
91 (*(t)->__bs_opname_s(type,sz))((t)->bs_cookie, h, o, a, c)
92 #define __bs_set_s(type, sz, t, h, o, v, c) \
93 (*(t)->__bs_opname_s(type,sz))((t)->bs_cookie, h, o, v, c)
94 #define __bs_copy_s(sz, t, h1, o1, h2, o2, cnt) \
95 (*(t)->__bs_opname_s(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt)
96 #endif
97
98 /*
99 * Mapping and unmapping operations.
100 */
101 #define bus_space_map(t, a, s, c, hp) \
102 (*(t)->bs_map)((t)->bs_cookie, (a), (s), (c), (hp))
103 #define bus_space_unmap(t, h, s) \
104 (*(t)->bs_unmap)((t)->bs_cookie, (h), (s))
105 #define bus_space_subregion(t, h, o, s, hp) \
106 (*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp))
107
108
109 /*
110 * Allocation and deallocation operations.
111 */
112 #define bus_space_alloc(t, rs, re, s, a, b, c, ap, hp) \
113 (*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b), \
114 (c), (ap), (hp))
115 #define bus_space_free(t, h, s) \
116 (*(t)->bs_free)((t)->bs_cookie, (h), (s))
117
118 /*
119 * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
120 */
121 #define bus_space_vaddr(t, h) \
122 (*(t)->bs_vaddr)((t)->bs_cookie, (h))
123
124 /*
125 * MMap bus space for a user application.
126 */
127 #define bus_space_mmap(t, a, o, p, f) \
128 (*(t)->bs_mmap)((t)->bs_cookie, (a), (o), (p), (f))
129
130 /*
131 * Bus barrier operations.
132 */
133 #define bus_space_barrier(t, h, o, l, f) \
134 (*(t)->bs_barrier)((t)->bs_cookie, (h), (o), (l), (f))
135
136 /*
137 * Bus read (single) operations.
138 */
139 #define bus_space_read_1(t, h, o) __bs_rs(1,(t),(h),(o))
140 #define bus_space_read_2(t, h, o) __bs_rs(2,(t),(h),(o))
141 #define bus_space_read_4(t, h, o) __bs_rs(4,(t),(h),(o))
142 #define bus_space_read_8(t, h, o) __bs_rs(8,(t),(h),(o))
143 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
144 #define bus_space_read_stream_1(t, h, o) __bs_rs_s(1,(t),(h),(o))
145 #define bus_space_read_stream_2(t, h, o) __bs_rs_s(2,(t),(h),(o))
146 #define bus_space_read_stream_4(t, h, o) __bs_rs_s(4,(t),(h),(o))
147 #define bus_space_read_stream_8(t, h, o) __bs_rs_s(8,(t),(h),(o))
148 #endif
149
150
151 /*
152 * Bus read multiple operations.
153 */
154 #define bus_space_read_multi_1(t, h, o, a, c) \
155 __bs_nonsingle(rm,1,(t),(h),(o),(a),(c))
156 #define bus_space_read_multi_2(t, h, o, a, c) \
157 __bs_nonsingle(rm,2,(t),(h),(o),(a),(c))
158 #define bus_space_read_multi_4(t, h, o, a, c) \
159 __bs_nonsingle(rm,4,(t),(h),(o),(a),(c))
160 #define bus_space_read_multi_8(t, h, o, a, c) \
161 __bs_nonsingle(rm,8,(t),(h),(o),(a),(c))
162 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
163 #define bus_space_read_multi_stream_1(t, h, o, a, c) \
164 __bs_nonsingle_s(rm,1,(t),(h),(o),(a),(c))
165 #define bus_space_read_multi_stream_2(t, h, o, a, c) \
166 __bs_nonsingle_s(rm,2,(t),(h),(o),(a),(c))
167 #define bus_space_read_multi_stream_4(t, h, o, a, c) \
168 __bs_nonsingle_s(rm,4,(t),(h),(o),(a),(c))
169 #define bus_space_read_multi_stream_8(t, h, o, a, c) \
170 __bs_nonsingle_s(rm,8,(t),(h),(o),(a),(c))
171 #endif
172
173
174 /*
175 * Bus read region operations.
176 */
177 #define bus_space_read_region_1(t, h, o, a, c) \
178 __bs_nonsingle(rr,1,(t),(h),(o),(a),(c))
179 #define bus_space_read_region_2(t, h, o, a, c) \
180 __bs_nonsingle(rr,2,(t),(h),(o),(a),(c))
181 #define bus_space_read_region_4(t, h, o, a, c) \
182 __bs_nonsingle(rr,4,(t),(h),(o),(a),(c))
183 #define bus_space_read_region_8(t, h, o, a, c) \
184 __bs_nonsingle(rr,8,(t),(h),(o),(a),(c))
185 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
186 #define bus_space_read_region_stream_1(t, h, o, a, c) \
187 __bs_nonsingle_s(rr,1,(t),(h),(o),(a),(c))
188 #define bus_space_read_region_stream_2(t, h, o, a, c) \
189 __bs_nonsingle_s(rr,2,(t),(h),(o),(a),(c))
190 #define bus_space_read_region_stream_4(t, h, o, a, c) \
191 __bs_nonsingle_s(rr,4,(t),(h),(o),(a),(c))
192 #define bus_space_read_region_stream_8(t, h, o, a, c) \
193 __bs_nonsingle_s(rr,8,(t),(h),(o),(a),(c))
194 #endif
195
196
197 /*
198 * Bus write (single) operations.
199 */
200 #define bus_space_write_1(t, h, o, v) __bs_ws(1,(t),(h),(o),(v))
201 #define bus_space_write_2(t, h, o, v) __bs_ws(2,(t),(h),(o),(v))
202 #define bus_space_write_4(t, h, o, v) __bs_ws(4,(t),(h),(o),(v))
203 #define bus_space_write_8(t, h, o, v) __bs_ws(8,(t),(h),(o),(v))
204 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
205 #define bus_space_write_stream_1(t, h, o, v) __bs_ws_s(1,(t),(h),(o),(v))
206 #define bus_space_write_stream_2(t, h, o, v) __bs_ws_s(2,(t),(h),(o),(v))
207 #define bus_space_write_stream_4(t, h, o, v) __bs_ws_s(4,(t),(h),(o),(v))
208 #define bus_space_write_stream_8(t, h, o, v) __bs_ws_s(8,(t),(h),(o),(v))
209 #endif
210
211
212 /*
213 * Bus write multiple operations.
214 */
215 #define bus_space_write_multi_1(t, h, o, a, c) \
216 __bs_nonsingle(wm,1,(t),(h),(o),(a),(c))
217 #define bus_space_write_multi_2(t, h, o, a, c) \
218 __bs_nonsingle(wm,2,(t),(h),(o),(a),(c))
219 #define bus_space_write_multi_4(t, h, o, a, c) \
220 __bs_nonsingle(wm,4,(t),(h),(o),(a),(c))
221 #define bus_space_write_multi_8(t, h, o, a, c) \
222 __bs_nonsingle(wm,8,(t),(h),(o),(a),(c))
223 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
224 #define bus_space_write_multi_stream_1(t, h, o, a, c) \
225 __bs_nonsingle_s(wm,1,(t),(h),(o),(a),(c))
226 #define bus_space_write_multi_stream_2(t, h, o, a, c) \
227 __bs_nonsingle_s(wm,2,(t),(h),(o),(a),(c))
228 #define bus_space_write_multi_stream_4(t, h, o, a, c) \
229 __bs_nonsingle_s(wm,4,(t),(h),(o),(a),(c))
230 #define bus_space_write_multi_stream_8(t, h, o, a, c) \
231 __bs_nonsingle_s(wm,8,(t),(h),(o),(a),(c))
232 #endif
233
234
235 /*
236 * Bus write region operations.
237 */
238 #define bus_space_write_region_1(t, h, o, a, c) \
239 __bs_nonsingle(wr,1,(t),(h),(o),(a),(c))
240 #define bus_space_write_region_2(t, h, o, a, c) \
241 __bs_nonsingle(wr,2,(t),(h),(o),(a),(c))
242 #define bus_space_write_region_4(t, h, o, a, c) \
243 __bs_nonsingle(wr,4,(t),(h),(o),(a),(c))
244 #define bus_space_write_region_8(t, h, o, a, c) \
245 __bs_nonsingle(wr,8,(t),(h),(o),(a),(c))
246 #ifdef __BUS_SPACE_HAS_STREAM_METHODS
247 #define bus_space_write_region_stream_1(t, h, o, a, c) \
248 __bs_nonsingle_s(wr,1,(t),(h),(o),(a),(c))
249 #define bus_space_write_region_stream_2(t, h, o, a, c) \
250 __bs_nonsingle_s(wr,2,(t),(h),(o),(a),(c))
251 #define bus_space_write_region_stream_4(t, h, o, a, c) \
252 __bs_nonsingle_s(wr,4,(t),(h),(o),(a),(c))
253 #define bus_space_write_region_stream_8(t, h, o, a, c) \
254 __bs_nonsingle_s(wr,8,(t),(h),(o),(a),(c))
255 #endif
256
257
258 /*
259 * Set multiple operations.
260 */
261 #define bus_space_set_multi_1(t, h, o, v, c) \
262 __bs_set(sm,1,(t),(h),(o),(v),(c))
263 #define bus_space_set_multi_2(t, h, o, v, c) \
264 __bs_set(sm,2,(t),(h),(o),(v),(c))
265 #define bus_space_set_multi_4(t, h, o, v, c) \
266 __bs_set(sm,4,(t),(h),(o),(v),(c))
267 #define bus_space_set_multi_8(t, h, o, v, c) \
268 __bs_set(sm,8,(t),(h),(o),(v),(c))
269
270 /*
271 * Set region operations.
272 */
273 #define bus_space_set_region_1(t, h, o, v, c) \
274 __bs_set(sr,1,(t),(h),(o),(v),(c))
275 #define bus_space_set_region_2(t, h, o, v, c) \
276 __bs_set(sr,2,(t),(h),(o),(v),(c))
277 #define bus_space_set_region_4(t, h, o, v, c) \
278 __bs_set(sr,4,(t),(h),(o),(v),(c))
279 #define bus_space_set_region_8(t, h, o, v, c) \
280 __bs_set(sr,8,(t),(h),(o),(v),(c))
281
282 /*
283 * Copy operations.
284 */
285 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \
286 __bs_copy(1, t, h1, o1, h2, o2, c)
287 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \
288 __bs_copy(2, t, h1, o1, h2, o2, c)
289 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \
290 __bs_copy(4, t, h1, o1, h2, o2, c)
291 #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \
292 __bs_copy(8, t, h1, o1, h2, o2, c)
293
294 /*
295 * Macros to provide prototypes for all the functions used in the
296 * bus_space structure
297 */
298
299 #define bs_map_proto(f) \
300 int __bs_c(f,_bs_map)(void *t, bus_addr_t addr, \
301 bus_size_t size, int cacheable, bus_space_handle_t *bshp);
302
303 #define bs_unmap_proto(f) \
304 void __bs_c(f,_bs_unmap)(void *t, bus_space_handle_t bsh, \
305 bus_size_t size);
306
307 #define bs_subregion_proto(f) \
308 int __bs_c(f,_bs_subregion)(void *t, bus_space_handle_t bsh, \
309 bus_size_t offset, bus_size_t size, \
310 bus_space_handle_t *nbshp);
311
312 #define bs_alloc_proto(f) \
313 int __bs_c(f,_bs_alloc)(void *t, bus_addr_t rstart, \
314 bus_addr_t rend, bus_size_t size, bus_size_t align, \
315 bus_size_t boundary, int cacheable, bus_addr_t *addrp, \
316 bus_space_handle_t *bshp);
317
318 #define bs_free_proto(f) \
319 void __bs_c(f,_bs_free)(void *t, bus_space_handle_t bsh, \
320 bus_size_t size);
321
322 #define bs_vaddr_proto(f) \
323 void * __bs_c(f,_bs_vaddr)(void *t, bus_space_handle_t bsh);
324
325 #define bs_mmap_proto(f) \
326 paddr_t __bs_c(f,_bs_mmap)(void *, bus_addr_t, off_t, int, int);
327
328 #define bs_barrier_proto(f) \
329 void __bs_c(f,_bs_barrier)(void *t, bus_space_handle_t bsh, \
330 bus_size_t offset, bus_size_t len, int flags);
331
332 #define bs_r_1_proto(f) \
333 uint8_t __bs_c(f,_bs_r_1)(void *t, bus_space_handle_t bsh, \
334 bus_size_t offset);
335
336 #define bs_r_2_proto(f) \
337 uint16_t __bs_c(f,_bs_r_2)(void *t, bus_space_handle_t bsh, \
338 bus_size_t offset); \
339 uint16_t __bs_c(f,_bs_r_2_swap)(void *t, bus_space_handle_t bsh, \
340 bus_size_t offset);
341
342 #define bs_r_4_proto(f) \
343 uint32_t __bs_c(f,_bs_r_4)(void *t, bus_space_handle_t bsh, \
344 bus_size_t offset); \
345 uint32_t __bs_c(f,_bs_r_4_swap)(void *t, bus_space_handle_t bsh, \
346 bus_size_t offset);
347
348 #define bs_r_8_proto(f) \
349 uint64_t __bs_c(f,_bs_r_8)(void *t, bus_space_handle_t bsh, \
350 bus_size_t offset); \
351 uint64_t __bs_c(f,_bs_r_8_swap)(void *t, bus_space_handle_t bsh, \
352 bus_size_t offset);
353
354 #define bs_w_1_proto(f) \
355 void __bs_c(f,_bs_w_1)(void *t, bus_space_handle_t bsh, \
356 bus_size_t offset, uint8_t value);
357
358 #define bs_w_2_proto(f) \
359 void __bs_c(f,_bs_w_2)(void *t, bus_space_handle_t bsh, \
360 bus_size_t offset, uint16_t value); \
361 void __bs_c(f,_bs_w_2_swap)(void *t, bus_space_handle_t bsh, \
362 bus_size_t offset, uint16_t value);
363
364 #define bs_w_4_proto(f) \
365 void __bs_c(f,_bs_w_4)(void *t, bus_space_handle_t bsh, \
366 bus_size_t offset, uint32_t value); \
367 void __bs_c(f,_bs_w_4_swap)(void *t, bus_space_handle_t bsh, \
368 bus_size_t offset, uint32_t value);
369
370 #define bs_w_8_proto(f) \
371 void __bs_c(f,_bs_w_8)(void *t, bus_space_handle_t bsh, \
372 bus_size_t offset, uint64_t value); \
373 void __bs_c(f,_bs_w_8_swap)(void *t, bus_space_handle_t bsh, \
374 bus_size_t offset, uint64_t value);
375
376 #define bs_rm_1_proto(f) \
377 void __bs_c(f,_bs_rm_1)(void *t, bus_space_handle_t bsh, \
378 bus_size_t offset, uint8_t *addr, bus_size_t count);
379
380 #define bs_rm_2_proto(f) \
381 void __bs_c(f,_bs_rm_2)(void *t, bus_space_handle_t bsh, \
382 bus_size_t offset, uint16_t *addr, bus_size_t count); \
383 void __bs_c(f,_bs_rm_2_swap)(void *t, bus_space_handle_t bsh, \
384 bus_size_t offset, uint16_t *addr, bus_size_t count);
385
386 #define bs_rm_4_proto(f) \
387 void __bs_c(f,_bs_rm_4)(void *t, bus_space_handle_t bsh, \
388 bus_size_t offset, uint32_t *addr, bus_size_t count); \
389 void __bs_c(f,_bs_rm_4_swap)(void *t, bus_space_handle_t bsh, \
390 bus_size_t offset, uint32_t *addr, bus_size_t count);
391
392 #define bs_rm_8_proto(f) \
393 void __bs_c(f,_bs_rm_8)(void *t, bus_space_handle_t bsh, \
394 bus_size_t offset, uint64_t *addr, bus_size_t count); \
395 void __bs_c(f,_bs_rm_8_swap)(void *t, bus_space_handle_t bsh, \
396 bus_size_t offset, uint64_t *addr, bus_size_t count);
397
398 #define bs_wm_1_proto(f) \
399 void __bs_c(f,_bs_wm_1)(void *t, bus_space_handle_t bsh, \
400 bus_size_t offset, const uint8_t *addr, bus_size_t count); \
401
402 #define bs_wm_2_proto(f) \
403 void __bs_c(f,_bs_wm_2)(void *t, bus_space_handle_t bsh, \
404 bus_size_t offset, const uint16_t *addr, bus_size_t count); \
405 void __bs_c(f,_bs_wm_2_swap)(void *t, bus_space_handle_t bsh, \
406 bus_size_t offset, const uint16_t *addr, bus_size_t count);
407
408 #define bs_wm_4_proto(f) \
409 void __bs_c(f,_bs_wm_4)(void *t, bus_space_handle_t bsh, \
410 bus_size_t offset, const uint32_t *addr, bus_size_t count); \
411 void __bs_c(f,_bs_wm_4_swap)(void *t, bus_space_handle_t bsh, \
412 bus_size_t offset, const uint32_t *addr, bus_size_t count);
413
414 #define bs_wm_8_proto(f) \
415 void __bs_c(f,_bs_wm_8)(void *t, bus_space_handle_t bsh, \
416 bus_size_t offset, const uint64_t *addr, bus_size_t count); \
417 void __bs_c(f,_bs_wm_8_swap)(void *t, bus_space_handle_t bsh, \
418 bus_size_t offset, const uint64_t *addr, bus_size_t count);
419
420 #define bs_rr_1_proto(f) \
421 void __bs_c(f, _bs_rr_1)(void *t, bus_space_handle_t bsh, \
422 bus_size_t offset, uint8_t *addr, bus_size_t count);
423
424 #define bs_rr_2_proto(f) \
425 void __bs_c(f, _bs_rr_2)(void *t, bus_space_handle_t bsh, \
426 bus_size_t offset, uint16_t *addr, bus_size_t count); \
427 void __bs_c(f, _bs_rr_2_swap)(void *t, bus_space_handle_t bsh, \
428 bus_size_t offset, uint16_t *addr, bus_size_t count);
429
430 #define bs_rr_4_proto(f) \
431 void __bs_c(f, _bs_rr_4)(void *t, bus_space_handle_t bsh, \
432 bus_size_t offset, uint32_t *addr, bus_size_t count); \
433 void __bs_c(f, _bs_rr_4_swap)(void *t, bus_space_handle_t bsh, \
434 bus_size_t offset, uint32_t *addr, bus_size_t count);
435
436 #define bs_rr_8_proto(f) \
437 void __bs_c(f, _bs_rr_8)(void *t, bus_space_handle_t bsh, \
438 bus_size_t offset, uint64_t *addr, bus_size_t count); \
439 void __bs_c(f, _bs_rr_8_swap)(void *t, bus_space_handle_t bsh, \
440 bus_size_t offset, uint64_t *addr, bus_size_t count);
441
442 #define bs_wr_1_proto(f) \
443 void __bs_c(f, _bs_wr_1)(void *t, bus_space_handle_t bsh, \
444 bus_size_t offset, const uint8_t *addr, bus_size_t count);
445
446 #define bs_wr_2_proto(f) \
447 void __bs_c(f, _bs_wr_2)(void *t, bus_space_handle_t bsh, \
448 bus_size_t offset, const uint16_t *addr, bus_size_t count); \
449 void __bs_c(f, _bs_wr_2_swap)(void *t, bus_space_handle_t bsh, \
450 bus_size_t offset, const uint16_t *addr, bus_size_t count);
451
452 #define bs_wr_4_proto(f) \
453 void __bs_c(f, _bs_wr_4)(void *t, bus_space_handle_t bsh, \
454 bus_size_t offset, const uint32_t *addr, bus_size_t count); \
455 void __bs_c(f, _bs_wr_4_swap)(void *t, bus_space_handle_t bsh, \
456 bus_size_t offset, const uint32_t *addr, bus_size_t count);
457
458 #define bs_wr_8_proto(f) \
459 void __bs_c(f, _bs_wr_8)(void *t, bus_space_handle_t bsh, \
460 bus_size_t offset, const uint64_t *addr, bus_size_t count); \
461 void __bs_c(f, _bs_wr_8_swap)(void *t, bus_space_handle_t bsh, \
462 bus_size_t offset, const uint64_t *addr, bus_size_t count);
463
464 #define bs_sm_1_proto(f) \
465 void __bs_c(f,_bs_sm_1)(void *t, bus_space_handle_t bsh, \
466 bus_size_t offset, uint8_t value, bus_size_t count);
467
468 #define bs_sm_2_proto(f) \
469 void __bs_c(f,_bs_sm_2)(void *t, bus_space_handle_t bsh, \
470 bus_size_t offset, uint16_t value, bus_size_t count);
471
472 #define bs_sm_4_proto(f) \
473 void __bs_c(f,_bs_sm_4)(void *t, bus_space_handle_t bsh, \
474 bus_size_t offset, uint32_t value, bus_size_t count);
475
476 #define bs_sm_8_proto(f) \
477 void __bs_c(f,_bs_sm_8)(void *t, bus_space_handle_t bsh, \
478 bus_size_t offset, uint64_t value, bus_size_t count);
479
480 #define bs_sr_1_proto(f) \
481 void __bs_c(f,_bs_sr_1)(void *t, bus_space_handle_t bsh, \
482 bus_size_t offset, uint8_t value, bus_size_t count);
483
484 #define bs_sr_2_proto(f) \
485 void __bs_c(f,_bs_sr_2)(void *t, bus_space_handle_t bsh, \
486 bus_size_t offset, uint16_t value, bus_size_t count); \
487 void __bs_c(f,_bs_sr_2_swap)(void *t, bus_space_handle_t bsh, \
488 bus_size_t offset, uint16_t value, bus_size_t count);
489
490 #define bs_sr_4_proto(f) \
491 void __bs_c(f,_bs_sr_4)(void *t, bus_space_handle_t bsh, \
492 bus_size_t offset, uint32_t value, bus_size_t count); \
493 void __bs_c(f,_bs_sr_4_swap)(void *t, bus_space_handle_t bsh, \
494 bus_size_t offset, uint32_t value, bus_size_t count);
495
496 #define bs_sr_8_proto(f) \
497 void __bs_c(f,_bs_sr_8)(void *t, bus_space_handle_t bsh, \
498 bus_size_t offset, uint64_t value, bus_size_t count); \
499 void __bs_c(f,_bs_sr_8_swap)(void *t, bus_space_handle_t bsh, \
500 bus_size_t offset, uint64_t value, bus_size_t count);
501
502 #define bs_c_1_proto(f) \
503 void __bs_c(f,_bs_c_1)(void *t, bus_space_handle_t bsh1, \
504 bus_size_t offset1, bus_space_handle_t bsh2, \
505 bus_size_t offset2, bus_size_t count);
506
507 #define bs_c_2_proto(f) \
508 void __bs_c(f,_bs_c_2)(void *t, bus_space_handle_t bsh1, \
509 bus_size_t offset1, bus_space_handle_t bsh2, \
510 bus_size_t offset2, bus_size_t count);
511
512 #define bs_c_4_proto(f) \
513 void __bs_c(f,_bs_c_4)(void *t, bus_space_handle_t bsh1, \
514 bus_size_t offset1, bus_space_handle_t bsh2, \
515 bus_size_t offset2, bus_size_t count);
516
517 #define bs_c_8_proto(f) \
518 void __bs_c(f,_bs_c_8)(void *t, bus_space_handle_t bsh1, \
519 bus_size_t offset1, bus_space_handle_t bsh2, \
520 bus_size_t offset2, bus_size_t count);
521
522 #define bs_protos(f) \
523 bs_map_proto(f); \
524 bs_unmap_proto(f); \
525 bs_subregion_proto(f); \
526 bs_alloc_proto(f); \
527 bs_free_proto(f); \
528 bs_vaddr_proto(f); \
529 bs_mmap_proto(f); \
530 bs_barrier_proto(f); \
531 bs_r_1_proto(f); \
532 bs_r_2_proto(f); \
533 bs_r_4_proto(f); \
534 bs_r_8_proto(f); \
535 bs_w_1_proto(f); \
536 bs_w_2_proto(f); \
537 bs_w_4_proto(f); \
538 bs_w_8_proto(f); \
539 bs_rm_1_proto(f); \
540 bs_rm_2_proto(f); \
541 bs_rm_4_proto(f); \
542 bs_rm_8_proto(f); \
543 bs_wm_1_proto(f); \
544 bs_wm_2_proto(f); \
545 bs_wm_4_proto(f); \
546 bs_wm_8_proto(f); \
547 bs_rr_1_proto(f); \
548 bs_rr_2_proto(f); \
549 bs_rr_4_proto(f); \
550 bs_rr_8_proto(f); \
551 bs_wr_1_proto(f); \
552 bs_wr_2_proto(f); \
553 bs_wr_4_proto(f); \
554 bs_wr_8_proto(f); \
555 bs_sm_1_proto(f); \
556 bs_sm_2_proto(f); \
557 bs_sm_4_proto(f); \
558 bs_sm_8_proto(f); \
559 bs_sr_1_proto(f); \
560 bs_sr_2_proto(f); \
561 bs_sr_4_proto(f); \
562 bs_sr_8_proto(f); \
563 bs_c_1_proto(f); \
564 bs_c_2_proto(f); \
565 bs_c_4_proto(f); \
566 bs_c_8_proto(f);
567
568 /* Bus Space DMA macros */
569
570 /* Forwards needed by prototypes below. */
571 struct mbuf;
572 struct uio;
573
574 #define bus_dmamap_create(t, s, n, m, b, f, p) \
575 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
576 #define bus_dmamap_destroy(t, p) \
577 (*(t)->_dmamap_destroy)((t), (p))
578 #define bus_dmamap_load(t, m, b, s, p, f) \
579 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
580 #define bus_dmamap_load_mbuf(t, m, b, f) \
581 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
582 #define bus_dmamap_load_uio(t, m, u, f) \
583 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
584 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
585 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
586 #define bus_dmamap_unload(t, p) \
587 (*(t)->_dmamap_unload)((t), (p))
588 #define bus_dmamap_sync(t, p, o, l, ops) \
589 do { \
590 if (((p)->_dm_flags & (_BUS_DMAMAP_COHERENT|_BUS_DMAMAP_IS_BOUNCING)) == _BUS_DMAMAP_COHERENT) \
591 break; \
592 if (((ops) & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) != 0 \
593 && (t)->_dmamap_sync_pre != NULL) \
594 (*(t)->_dmamap_sync_pre)((t), (p), (o), (l), (ops)); \
595 else if (((ops) & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) != 0 \
596 && (t)->_dmamap_sync_post != NULL) \
597 (*(t)->_dmamap_sync_post)((t), (p), (o), (l), (ops)); \
598 } while (/*CONSTCOND*/0)
599
600 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
601 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
602 #define bus_dmamem_free(t, sg, n) \
603 (*(t)->_dmamem_free)((t), (sg), (n))
604 #define bus_dmamem_map(t, sg, n, s, k, f) \
605 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
606 #define bus_dmamem_unmap(t, k, s) \
607 (*(t)->_dmamem_unmap)((t), (k), (s))
608 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
609 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
610
611 #define bus_dmatag_subregion(t, mna, mxa, nt, f) \
612 (*(t)->_dmatag_subregion)((t), (mna), (mxa), (nt), (f))
613 #define bus_dmatag_destroy(t) \
614 (*(t)->_dmatag_destroy)(t)
615
616 #ifdef _ARM32_BUS_DMA_PRIVATE
617
618 extern paddr_t physical_start, physical_end;
619
620 int arm32_dma_range_intersect(struct arm32_dma_range *, int,
621 paddr_t pa, psize_t size, paddr_t *pap, psize_t *sizep);
622
623 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
624 bus_size_t, int, bus_dmamap_t *);
625 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
626 int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
627 bus_size_t, struct proc *, int);
628 int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
629 struct mbuf *, int);
630 int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
631 struct uio *, int);
632 int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
633 bus_dma_segment_t *, int, bus_size_t, int);
634 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
635 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
636 bus_size_t, int);
637
638 #ifdef _ARM32_NEED_BUS_DMA_BOUNCE
639 #define _BUS_DMAMAP_SYNC_FUNCS \
640 ._dmamap_sync_pre = _bus_dmamap_sync, \
641 ._dmamap_sync_post = _bus_dmamap_sync
642 #else
643 #define _BUS_DMAMAP_SYNC_FUNCS \
644 ._dmamap_sync_pre = _bus_dmamap_sync
645 #endif
646
647 #define _BUS_DMAMAP_FUNCS \
648 ._dmamap_create = _bus_dmamap_create, \
649 ._dmamap_destroy = _bus_dmamap_destroy, \
650 ._dmamap_load = _bus_dmamap_load, \
651 ._dmamap_load_mbuf = _bus_dmamap_load_mbuf, \
652 ._dmamap_load_raw = _bus_dmamap_load_raw, \
653 ._dmamap_load_uio = _bus_dmamap_load_uio, \
654 ._dmamap_unload = _bus_dmamap_unload, \
655 _BUS_DMAMAP_SYNC_FUNCS
656
657 int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
658 bus_size_t alignment, bus_size_t boundary,
659 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
660 void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
661 int nsegs);
662 int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
663 int nsegs, size_t size, void **kvap, int flags);
664 void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
665 size_t size);
666 paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
667 int nsegs, off_t off, int prot, int flags);
668
669 #define _BUS_DMAMEM_FUNCS \
670 ._dmamem_alloc = _bus_dmamem_alloc, \
671 ._dmamem_free = _bus_dmamem_free, \
672 ._dmamem_map = _bus_dmamem_map, \
673 ._dmamem_unmap = _bus_dmamem_unmap, \
674 ._dmamem_mmap = _bus_dmamem_mmap
675
676 int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
677 bus_size_t alignment, bus_size_t boundary,
678 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
679 vaddr_t low, vaddr_t high);
680
681 int _bus_dmatag_subregion(bus_dma_tag_t, bus_addr_t, bus_addr_t,
682 bus_dma_tag_t *, int);
683 void _bus_dmatag_destroy(bus_dma_tag_t);
684
685 #define _BUS_DMATAG_FUNCS \
686 ._dmatag_subregion = _bus_dmatag_subregion, \
687 ._dmatag_destroy = _bus_dmatag_destroy
688
689 #endif /* _ARM32_BUS_DMA_PRIVATE */
690
691 #endif /* _ARM32_BUS_FUNCS_H_ */
692