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