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