Home | History | Annotate | Line # | Download | only in include
      1 /*	$NetBSD: bus.h,v 1.30 2021/01/23 19:38:08 christos Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996, 1997, 1998 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) 1997 Scott Reynolds.  All rights reserved.
     35  *
     36  * Redistribution and use in source and binary forms, with or without
     37  * modification, are permitted provided that the following conditions
     38  * are met:
     39  * 1. Redistributions of source code must retain the above copyright
     40  *    notice, this list of conditions and the following disclaimer.
     41  * 2. Redistributions in binary form must reproduce the above copyright
     42  *    notice, this list of conditions and the following disclaimer in the
     43  *    documentation and/or other materials provided with the distribution.
     44  * 3. The name of the author may not be used to endorse or promote products
     45  *    derived from this software without specific prior written permission
     46  *
     47  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     48  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     49  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     50  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     51  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     52  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     53  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     54  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     55  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     56  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     57  */
     58 
     59 #ifndef _MAC68K_BUS_H_
     60 #define _MAC68K_BUS_H_
     61 
     62 /*
     63  * Value for the mac68k bus space tag, not to be used directly by MI code.
     64  */
     65 #define MAC68K_BUS_SPACE_MEM	0	/* space is mem space */
     66 
     67 #define __BUS_SPACE_HAS_STREAM_METHODS 1
     68 
     69 /*
     70  * Bus address and size types
     71  */
     72 typedef u_long bus_addr_t;
     73 typedef u_long bus_size_t;
     74 
     75 #define PRIxBUSADDR	"lx"
     76 #define PRIxBUSSIZE	"lx"
     77 #define PRIuBUSSIZE	"lu"
     78 /*
     79  * Access methods for bus resources and address space.
     80  */
     81 #define BSH_T	struct bus_space_handle_s
     82 typedef int	bus_space_tag_t;
     83 typedef struct bus_space_handle_s {
     84 	u_long	base;
     85 	int	swapped;
     86 	int	stride;
     87 
     88 	u_int8_t	(*bsr1)(bus_space_tag_t, BSH_T *, bus_size_t);
     89 	u_int16_t	(*bsr2)(bus_space_tag_t, BSH_T *, bus_size_t);
     90 	u_int32_t	(*bsr4)(bus_space_tag_t, BSH_T *, bus_size_t);
     91 	u_int8_t	(*bsrs1)(bus_space_tag_t, BSH_T *, bus_size_t);
     92 	u_int16_t	(*bsrs2)(bus_space_tag_t, BSH_T *, bus_size_t);
     93 	u_int32_t	(*bsrs4)(bus_space_tag_t, BSH_T *, bus_size_t);
     94 	void		(*bsrm1)(bus_space_tag_t, BSH_T *, bus_size_t,
     95 				 u_int8_t *, size_t);
     96 	void		(*bsrm2)(bus_space_tag_t, BSH_T *, bus_size_t,
     97 				 u_int16_t *, size_t);
     98 	void		(*bsrm4)(bus_space_tag_t, BSH_T *, bus_size_t,
     99 				 u_int32_t *, size_t);
    100 	void		(*bsrms1)(bus_space_tag_t, BSH_T *, bus_size_t,
    101 				  u_int8_t *, size_t);
    102 	void		(*bsrms2)(bus_space_tag_t, BSH_T *, bus_size_t,
    103 				  u_int16_t *, size_t);
    104 	void		(*bsrms4)(bus_space_tag_t, BSH_T *, bus_size_t,
    105 				  u_int32_t *, size_t);
    106 	void		(*bsrr1)(bus_space_tag_t, BSH_T *, bus_size_t,
    107 				 u_int8_t *, size_t);
    108 	void		(*bsrr2)(bus_space_tag_t, BSH_T *, bus_size_t,
    109 				 u_int16_t *, size_t);
    110 	void		(*bsrr4)(bus_space_tag_t, BSH_T *, bus_size_t,
    111 				 u_int32_t *, size_t);
    112 	void		(*bsrrs1)(bus_space_tag_t, BSH_T *, bus_size_t,
    113 				  u_int8_t *, size_t);
    114 	void		(*bsrrs2)(bus_space_tag_t, BSH_T *, bus_size_t,
    115 				  u_int16_t *, size_t);
    116 	void		(*bsrrs4)(bus_space_tag_t, BSH_T *, bus_size_t,
    117 				  u_int32_t *, size_t);
    118 	void		(*bsw1)(bus_space_tag_t, BSH_T *, bus_size_t, u_int8_t);
    119 	void		(*bsw2)(bus_space_tag_t, BSH_T *, bus_size_t,
    120 				u_int16_t);
    121 	void		(*bsw4)(bus_space_tag_t, BSH_T *, bus_size_t,
    122 				u_int32_t);
    123 	void		(*bsws1)(bus_space_tag_t, BSH_T *, bus_size_t,
    124 				 u_int8_t);
    125 	void		(*bsws2)(bus_space_tag_t, BSH_T *, bus_size_t,
    126 				 u_int16_t);
    127 	void		(*bsws4)(bus_space_tag_t, BSH_T *, bus_size_t,
    128 				 u_int32_t);
    129 	void		(*bswm1)(bus_space_tag_t, BSH_T *, bus_size_t,
    130 				 const u_int8_t *, size_t);
    131 	void		(*bswm2)(bus_space_tag_t, BSH_T *, bus_size_t,
    132 				 const u_int16_t *, size_t);
    133 	void		(*bswm4)(bus_space_tag_t, BSH_T *, bus_size_t,
    134 				 const u_int32_t *, size_t);
    135 	void		(*bswms1)(bus_space_tag_t, BSH_T *, bus_size_t,
    136 				  const u_int8_t *, size_t);
    137 	void		(*bswms2)(bus_space_tag_t, BSH_T *, bus_size_t,
    138 				  const u_int16_t *, size_t);
    139 	void		(*bswms4)(bus_space_tag_t, BSH_T *, bus_size_t,
    140 				  const u_int32_t *, size_t);
    141 	void		(*bswr1)(bus_space_tag_t, BSH_T *, bus_size_t,
    142 				 const u_int8_t *, size_t);
    143 	void		(*bswr2)(bus_space_tag_t, BSH_T *, bus_size_t,
    144 				 const u_int16_t *, size_t);
    145 	void		(*bswr4)(bus_space_tag_t, BSH_T *, bus_size_t,
    146 				 const u_int32_t *, size_t);
    147 	void		(*bswrs1)(bus_space_tag_t, BSH_T *, bus_size_t,
    148 				  const u_int8_t *, size_t);
    149 	void		(*bswrs2)(bus_space_tag_t, BSH_T *, bus_size_t,
    150 				  const u_int16_t *, size_t);
    151 	void		(*bswrs4)(bus_space_tag_t, BSH_T *, bus_size_t,
    152 				  const u_int32_t *, size_t);
    153 	void		(*bssm1)(bus_space_tag_t, BSH_T *, bus_size_t,
    154 				 u_int8_t v, size_t);
    155 	void		(*bssm2)(bus_space_tag_t, BSH_T *, bus_size_t,
    156 				 u_int16_t v, size_t);
    157 	void		(*bssm4)(bus_space_tag_t, BSH_T *, bus_size_t,
    158 				 u_int32_t v, size_t);
    159 	void		(*bssr1)(bus_space_tag_t, BSH_T *, bus_size_t,
    160 				 u_int8_t v, size_t);
    161 	void		(*bssr2)(bus_space_tag_t, BSH_T *, bus_size_t,
    162 				 u_int16_t v, size_t);
    163 	void		(*bssr4)(bus_space_tag_t, BSH_T *, bus_size_t,
    164 				 u_int32_t v, size_t);
    165 } bus_space_handle_t;
    166 #undef BSH_T
    167 
    168 void	mac68k_bus_space_handle_swapped(bus_space_tag_t,
    169 		bus_space_handle_t *);
    170 void	mac68k_bus_space_handle_set_stride(bus_space_tag_t,
    171 		bus_space_handle_t *, int);
    172 
    173 /*
    174  *	int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
    175  *	    bus_size_t size, int flags, bus_space_handle_t *bshp);
    176  *
    177  * Map a region of bus space.
    178  */
    179 
    180 #define	BUS_SPACE_MAP_CACHEABLE		0x01
    181 #define	BUS_SPACE_MAP_LINEAR		0x02
    182 #define	BUS_SPACE_MAP_PREFETCHABLE	0x04
    183 
    184 int	bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
    185 	    int, bus_space_handle_t *);
    186 
    187 /*
    188  *	void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
    189  *	    bus_size_t size);
    190  *
    191  * Unmap a region of bus space.
    192  */
    193 
    194 void	bus_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t);
    195 
    196 /*
    197  *	int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
    198  *	    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
    199  *
    200  * Get a new handle for a subregion of an already-mapped area of bus space.
    201  */
    202 
    203 int	bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
    204 	    bus_size_t, bus_size_t size, bus_space_handle_t *);
    205 
    206 /*
    207  *	int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
    208  *	    bus_addr_t rend, bus_size_t size, bus_size_t align,
    209  *	    bus_size_t boundary, int flags, bus_addr_t *addrp,
    210  *	    bus_space_handle_t *bshp);
    211  *
    212  * Allocate a region of bus space.
    213  */
    214 
    215 int	bus_space_alloc(bus_space_tag_t, bus_addr_t rstart,
    216 	    bus_addr_t rend, bus_size_t size, bus_size_t align,
    217 	    bus_size_t boundary, int cacheable, bus_addr_t *addrp,
    218 	    bus_space_handle_t *bshp);
    219 
    220 /*
    221  *	int bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
    222  *	    bus_size_t size);
    223  *
    224  * Free a region of bus space.
    225  */
    226 
    227 void	bus_space_free(bus_space_tag_t, bus_space_handle_t bsh,
    228 	    bus_size_t size);
    229 
    230 /*
    231  *	int mac68k_bus_space_probe(bus_space_tag_t t, bus_space_handle_t bsh,
    232  *	    bus_size_t offset, int sz);
    233  *
    234  * Probe the bus at t/bsh/offset, using sz as the size of the load.
    235  *
    236  * This is a machine-dependent extension, and is not to be used by
    237  * machine-independent code.
    238  */
    239 
    240 int	mac68k_bus_space_probe(bus_space_tag_t,
    241 	    bus_space_handle_t bsh, bus_size_t, int sz);
    242 
    243 /*
    244  *	u_intN_t bus_space_read_N(bus_space_tag_t tag,
    245  *	    bus_space_handle_t bsh, bus_size_t offset);
    246  *
    247  * Read a 1, 2, 4, or 8 byte quantity from bus space
    248  * described by tag/handle/offset.
    249  */
    250 
    251 u_int8_t mac68k_bsr1(bus_space_tag_t, bus_space_handle_t *, bus_size_t);
    252 u_int8_t mac68k_bsr1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t);
    253 u_int16_t mac68k_bsr2(bus_space_tag_t, bus_space_handle_t *, bus_size_t);
    254 u_int16_t mac68k_bsr2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t);
    255 u_int16_t mac68k_bsr2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t);
    256 u_int16_t mac68k_bsrs2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t);
    257 u_int32_t mac68k_bsr4(bus_space_tag_t, bus_space_handle_t *, bus_size_t);
    258 u_int32_t mac68k_bsr4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t);
    259 u_int32_t mac68k_bsr4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t);
    260 u_int32_t mac68k_bsrs4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t);
    261 
    262 #define	bus_space_read_1(t,h,o)	(h).bsr1((t), &(h), (o))
    263 #define	bus_space_read_2(t,h,o)	(h).bsr2((t), &(h), (o))
    264 #define	bus_space_read_4(t,h,o)	(h).bsr4((t), &(h), (o))
    265 #define	bus_space_read_stream_1(t,h,o)	(h).bsrs1((t), &(h), (o))
    266 #define	bus_space_read_stream_2(t,h,o)	(h).bsrs2((t), &(h), (o))
    267 #define	bus_space_read_stream_4(t,h,o)	(h).bsrs4((t), &(h), (o))
    268 
    269 /*
    270  *	void bus_space_read_multi_N(bus_space_tag_t tag,
    271  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t *addr,
    272  *	    size_t count);
    273  *
    274  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    275  * described by tag/handle/offset and copy into buffer provided.
    276  */
    277 
    278 void mac68k_bsrm1(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    279 	u_int8_t *, size_t);
    280 void mac68k_bsrm1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    281 	u_int8_t *, size_t);
    282 void mac68k_bsrm2(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    283 	u_int16_t *, size_t);
    284 void mac68k_bsrm2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    285 	u_int16_t *, size_t);
    286 void mac68k_bsrm2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    287 	u_int16_t *, size_t);
    288 void mac68k_bsrms2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    289 	u_int16_t *, size_t);
    290 void mac68k_bsrm4(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    291 	u_int32_t *, size_t);
    292 void mac68k_bsrms4(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    293 	u_int32_t *, size_t);
    294 void mac68k_bsrm4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    295 	u_int32_t *, size_t);
    296 void mac68k_bsrm4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    297 	u_int32_t *, size_t);
    298 void mac68k_bsrms4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    299 	u_int32_t *, size_t);
    300 
    301 #if defined(DIAGNOSTIC)
    302 #define	bus_space_read_multi_1(t, h, o, a, c) do {			 \
    303 	if ((c) == 0)							 \
    304 		panic("bus_space_read_multi_1 called with zero count."); \
    305 	(h).bsrm1(t,&(h),o,a,c); } while (0)
    306 #define	bus_space_read_multi_2(t, h, o, a, c) do {			 \
    307 	if ((c) == 0)							 \
    308 		panic("bus_space_read_multi_2 called with zero count."); \
    309 	(h).bsrm2(t,&(h),o,a,c); } while (0)
    310 #define	bus_space_read_multi_4(t, h, o, a, c) do {			 \
    311 	if ((c) == 0)							 \
    312 		panic("bus_space_read_multi_4 called with zero count."); \
    313 	(h).bsrm4(t,&(h),o,a,c); } while (0)
    314 #define	bus_space_read_multi_stream_1(t, h, o, a, c) do {		 \
    315 	if ((c) == 0)							 \
    316 		panic("bus_space_read_multi_stream_1 called with count=0."); \
    317 	(h).bsrms1(t,&(h),o,a,c); } while (0)
    318 #define	bus_space_read_multi_stream_2(t, h, o, a, c) do {		 \
    319 	if ((c) == 0)							 \
    320 		panic("bus_space_read_multi_stream_2 called with count=0."); \
    321 	(h).bsrms2(t,&(h),o,a,c); } while (0)
    322 #define	bus_space_read_multi_stream_4(t, h, o, a, c) do {		 \
    323 	if ((c) == 0)							 \
    324 		panic("bus_space_read_multi_stream_4 called with count=0."); \
    325 	(h).bsrms4(t,&(h),o,a,c); } while (0)
    326 #else
    327 #define	bus_space_read_multi_1(t, h, o, a, c) \
    328 	do { if (c) (h).bsrm1(t, &(h), o, a, c); } while (0)
    329 #define	bus_space_read_multi_2(t, h, o, a, c) \
    330 	do { if (c) (h).bsrm2(t, &(h), o, a, c); } while (0)
    331 #define	bus_space_read_multi_4(t, h, o, a, c) \
    332 	do { if (c) (h).bsrm4(t, &(h), o, a, c); } while (0)
    333 #define	bus_space_read_multi_stream_1(t, h, o, a, c) \
    334 	do { if (c) (h).bsrms1(t, &(h), o, a, c); } while (0)
    335 #define	bus_space_read_multi_stream_2(t, h, o, a, c) \
    336 	do { if (c) (h).bsrms2(t, &(h), o, a, c); } while (0)
    337 #define	bus_space_read_multi_stream_4(t, h, o, a, c) \
    338 	do { if (c) (h).bsrms4(t, &(h), o, a, c); } while (0)
    339 #endif
    340 
    341 /*
    342  *	void bus_space_read_region_N(bus_space_tag_t tag,
    343  *	    bus_space_handle_t bsh, bus_size_t offset,
    344  *	    u_intN_t *addr, size_t count);
    345  *
    346  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    347  * described by tag/handle and starting at `offset' and copy into
    348  * buffer provided.
    349  */
    350 
    351 void mac68k_bsrr1(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    352 	u_int8_t *, size_t);
    353 void mac68k_bsrr1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    354 	u_int8_t *, size_t);
    355 void mac68k_bsrr2(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    356 	u_int16_t *, size_t);
    357 void mac68k_bsrr2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    358 	u_int16_t *, size_t);
    359 void mac68k_bsrr2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    360 	u_int16_t *, size_t);
    361 void mac68k_bsrrs2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    362 	u_int16_t *, size_t);
    363 void mac68k_bsrr4(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    364 	u_int32_t *, size_t);
    365 void mac68k_bsrr4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    366 	u_int32_t *, size_t);
    367 void mac68k_bsrr4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    368 	u_int32_t *, size_t);
    369 void mac68k_bsrrs4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    370 	u_int32_t *, size_t);
    371 
    372 #if defined(DIAGNOSTIC)
    373 #define	bus_space_read_region_1(t, h, o, a, c) do {			  \
    374 	if ((c) == 0)							  \
    375 		panic("bus_space_read_region_1 called with zero count."); \
    376 	(h).bsrr1(t,&(h),o,a,c); } while (0)
    377 #define	bus_space_read_region_2(t, h, o, a, c) do {			  \
    378 	if ((c) == 0)							  \
    379 		panic("bus_space_read_region_2 called with zero count."); \
    380 	(h).bsrr2(t,&(h),o,a,c); } while (0)
    381 #define	bus_space_read_region_4(t, h, o, a, c) do {			  \
    382 	if ((c) == 0)							  \
    383 		panic("bus_space_read_region_4 called with zero count."); \
    384 	(h).bsrr4(t,&(h),o,a,c); } while (0)
    385 #define	bus_space_read_region_stream_1(t, h, o, a, c) do {		  \
    386 	if ((c) == 0)							  \
    387 		panic("bus_space_read_region_stream_1 called with count=0."); \
    388 	(h).bsrrs1(t,&(h),o,a,c); } while (0)
    389 #define	bus_space_read_region_stream_2(t, h, o, a, c) do {		  \
    390 	if ((c) == 0)							  \
    391 		 panic("bus_space_read_region_stream_2 called with count=0."); \
    392 	(h).bsrrs2(t,&(h),o,a,c); } while (0)
    393 #define	bus_space_read_region_stream_4(t, h, o, a, c) do {		  \
    394 	if ((c) == 0)							  \
    395 		panic("bus_space_read_region_stream_4 called with count=0."); \
    396 	(h).bsrrs4(t,&(h),o,a,c); } while (0)
    397 #else
    398 #define	bus_space_read_region_1(t, h, o, a, c) \
    399 	do { if (c) (h).bsrr1(t,&(h),o,a,c); } while (0)
    400 #define	bus_space_read_region_2(t, h, o, a, c) \
    401 	do { if (c) (h).bsrr2(t,&(h),o,a,c); } while (0)
    402 #define	bus_space_read_region_4(t, h, o, a, c) \
    403 	do { if (c) (h).bsrr4(t,&(h),o,a,c); } while (0)
    404 #define	bus_space_read_region_stream_1(t, h, o, a, c) \
    405 	do { if (c) (h).bsrrs1(t,&(h),o,a,c); } while (0)
    406 #define	bus_space_read_region_stream_2(t, h, o, a, c) \
    407 	do { if (c) (h).bsrrs2(t,&(h),o,a,c); } while (0)
    408 #define	bus_space_read_region_stream_4(t, h, o, a, c) \
    409 	do { if (c) (h).bsrrs4(t,&(h),o,a,c); } while (0)
    410 #endif
    411 
    412 /*
    413  *	void bus_space_write_N(bus_space_tag_t tag,
    414  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t value);
    415  *
    416  * Write the 1, 2, 4, or 8 byte value `value' to bus space
    417  * described by tag/handle/offset.
    418  */
    419 
    420 void mac68k_bsw1(bus_space_tag_t, bus_space_handle_t *, bus_size_t, u_int8_t);
    421 void mac68k_bsw1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    422 	u_int8_t);
    423 void mac68k_bsw2(bus_space_tag_t, bus_space_handle_t *, bus_size_t, u_int16_t);
    424 void mac68k_bsw2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    425 	u_int16_t);
    426 void mac68k_bsw2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    427 	u_int16_t);
    428 void mac68k_bsws2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    429 	u_int16_t);
    430 void mac68k_bsw4(bus_space_tag_t, bus_space_handle_t *, bus_size_t, u_int32_t);
    431 void mac68k_bsw4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    432 	u_int32_t);
    433 void mac68k_bsw4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    434 	u_int32_t);
    435 void mac68k_bsws4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    436 	u_int32_t);
    437 
    438 #define	bus_space_write_1(t, h, o, v) (h).bsw1(t, &(h), o, v)
    439 #define	bus_space_write_2(t, h, o, v) (h).bsw2(t, &(h), o, v)
    440 #define	bus_space_write_4(t, h, o, v) (h).bsw4(t, &(h), o, v)
    441 #define	bus_space_write_stream_1(t, h, o, v) (h).bsws1(t, &(h), o, v)
    442 #define	bus_space_write_stream_2(t, h, o, v) (h).bsws2(t, &(h), o, v)
    443 #define	bus_space_write_stream_4(t, h, o, v) (h).bsws4(t, &(h), o, v)
    444 
    445 /*
    446  *	void bus_space_write_multi_N(bus_space_tag_t tag,
    447  *	    bus_space_handle_t bsh, bus_size_t offset, const u_intN_t *addr,
    448  *	    size_t count);
    449  *
    450  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
    451  * provided to bus space described by tag/handle/offset.
    452  */
    453 
    454 void mac68k_bswm1(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    455 	const u_int8_t *, size_t);
    456 void mac68k_bswm1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    457 	const u_int8_t *, size_t);
    458 void mac68k_bswm2(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    459 	const u_int16_t *, size_t);
    460 void mac68k_bswm2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    461 	const u_int16_t *, size_t);
    462 void mac68k_bswm2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    463 	const u_int16_t *, size_t);
    464 void mac68k_bswms2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    465 	const u_int16_t *, size_t);
    466 void mac68k_bswm4(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    467 	const u_int32_t *, size_t);
    468 void mac68k_bswm4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    469 	const u_int32_t *, size_t);
    470 void mac68k_bswm4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    471 	const u_int32_t *, size_t);
    472 void mac68k_bswms4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    473 	const u_int32_t *, size_t);
    474 
    475 #if defined(DIAGNOSTIC)
    476 #define	bus_space_write_multi_1(t, h, o, a, c) do {			  \
    477 	if ((c) == 0)							  \
    478 		panic("bus_space_write_multi_1 called with zero count."); \
    479 	(h).bswm1(t,&(h),o,a,c); } while (0)
    480 #define	bus_space_write_multi_2(t, h, o, a, c) do {			  \
    481 	if ((c) == 0)							  \
    482 		panic("bus_space_write_multi_2 called with zero count."); \
    483 	(h).bswm2(t,&(h),o,a,c); } while (0)
    484 #define	bus_space_write_multi_4(t, h, o, a, c) do {			  \
    485 	if ((c) == 0)							  \
    486 		panic("bus_space_write_multi_4 called with zero count."); \
    487 	(h).bswm4(t,&(h),o,a,c); } while (0)
    488 #define	bus_space_write_multi_stream_1(t, h, o, a, c) do {		  \
    489 	if ((c) == 0)							  \
    490 		panic("bus_space_write_multi_stream_1 called with count=0."); \
    491 	(h).bswms1(t,&(h),o,a,c); } while (0)
    492 #define	bus_space_write_multi_stream_2(t, h, o, a, c) do {		  \
    493 	if ((c) == 0)							  \
    494 		panic("bus_space_write_multi_stream_2 called with count=0."); \
    495 	(h).bswms2(t,&(h),o,a,c); } while (0)
    496 #define	bus_space_write_multi_stream_4(t, h, o, a, c) do {		  \
    497 	if ((c) == 0)							  \
    498 		panic("bus_space_write_multi_stream_4 called with count=0."); \
    499 	(h).bswms4(t,&(h),o,a,c); } while (0)
    500 #else
    501 #define	bus_space_write_multi_1(t, h, o, a, c) \
    502 	do { if (c) (h).bswm1(t, &(h), o, a, c); } while (0)
    503 #define	bus_space_write_multi_2(t, h, o, a, c) \
    504 	do { if (c) (h).bswm2(t, &(h), o, a, c); } while (0)
    505 #define	bus_space_write_multi_4(t, h, o, a, c) \
    506 	do { if (c) (h).bswm4(t, &(h), o, a, c); } while (0)
    507 #define	bus_space_write_multi_stream_1(t, h, o, a, c) \
    508 	do { if (c) (h).bswms1(t, &(h), o, a, c); } while (0)
    509 #define	bus_space_write_multi_stream_2(t, h, o, a, c) \
    510 	do { if (c) (h).bswms2(t, &(h), o, a, c); } while (0)
    511 #define	bus_space_write_multi_stream_4(t, h, o, a, c) \
    512 	do { if (c) (h).bswms4(t, &(h), o, a, c); } while (0)
    513 #endif
    514 
    515 /*
    516  *	void bus_space_write_region_N(bus_space_tag_t tag,
    517  *	    bus_space_handle_t bsh, bus_size_t offset, const u_intN_t *addr,
    518  *	    size_t count);
    519  *
    520  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
    521  * to bus space described by tag/handle starting at `offset'.
    522  */
    523 
    524 void mac68k_bswr1(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    525 	const u_int8_t *, size_t);
    526 void mac68k_bswr1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    527 	const u_int8_t *, size_t);
    528 void mac68k_bswr2(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    529 	const u_int16_t *, size_t);
    530 void mac68k_bswr2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    531 	const u_int16_t *, size_t);
    532 void mac68k_bswr2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    533 	const u_int16_t *, size_t);
    534 void mac68k_bswrs2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    535 	const u_int16_t *, size_t);
    536 void mac68k_bswr4(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    537 	const u_int32_t *, size_t);
    538 void mac68k_bswr4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    539 	const u_int32_t *, size_t);
    540 void mac68k_bswr4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    541 	const u_int32_t *, size_t);
    542 void mac68k_bswrs4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    543 	const u_int32_t *, size_t);
    544 
    545 #if defined(DIAGNOSTIC)
    546 #define	bus_space_write_region_1(t, h, o, a, c) do {			   \
    547 	if ((c) == 0)							   \
    548 		panic("bus_space_write_region_1 called with zero count."); \
    549 	(h).bswr1(t,&(h),o,a,c); } while (0)
    550 #define	bus_space_write_region_2(t, h, o, a, c) do {			   \
    551 	if ((c) == 0)							   \
    552 		panic("bus_space_write_region_2 called with zero count."); \
    553 	(h).bswr2(t,&(h),o,a,c); } while (0)
    554 #define	bus_space_write_region_4(t, h, o, a, c) do {			   \
    555 	if ((c) == 0)							   \
    556 		panic("bus_space_write_region_4 called with zero count."); \
    557 	(h).bswr4(t,&(h),o,a,c); } while (0)
    558 #define	bus_space_write_region_stream_1(t, h, o, a, c) do {		   \
    559 	if ((c) == 0)							   \
    560 		panic("bus_space_write_region_stream_1 called with count=0."); \
    561 	(h).bswrs1(t,&(h),o,a,c); } while (0)
    562 #define	bus_space_write_region_stream_2(t, h, o, a, c) do {		   \
    563 	if ((c) == 0)							   \
    564 		panic("bus_space_write_region_stream_2 called with count=0."); \
    565 	(h).bswrs2(t,&(h),o,a,c); } while (0)
    566 #define	bus_space_write_region_stream_4(t, h, o, a, c) do {		   \
    567 	if ((c) == 0)							   \
    568 		panic("bus_space_write_region_stream_4 called with count=0."); \
    569 	(h).bswrs4(t,&(h),o,a,c); } while (0)
    570 #else
    571 #define	bus_space_write_region_1(t, h, o, a, c) \
    572 	do { if (c) (h).bswr1(t,&(h),o,a,c); } while (0)
    573 #define	bus_space_write_region_2(t, h, o, a, c) \
    574 	do { if (c) (h).bswr2(t,&(h),o,a,c); } while (0)
    575 #define	bus_space_write_region_4(t, h, o, a, c) \
    576 	do { if (c) (h).bswr4(t,&(h),o,a,c); } while (0)
    577 #define	bus_space_write_region_stream_1(t, h, o, a, c) \
    578 	do { if (c) (h).bswrs1(t,&(h),o,a,c); } while (0)
    579 #define	bus_space_write_region_stream_2(t, h, o, a, c) \
    580 	do { if (c) (h).bswrs2(t,&(h),o,a,c); } while (0)
    581 #define	bus_space_write_region_stream_4(t, h, o, a, c) \
    582 	do { if (c) (h).bswrs4(t,&(h),o,a,c); } while (0)
    583 #endif
    584 
    585 /*
    586  *	void bus_space_set_multi_N(bus_space_tag_t tag,
    587  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    588  *	    size_t count);
    589  *
    590  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
    591  * by tag/handle/offset `count' times.
    592  */
    593 
    594 void mac68k_bssm1(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    595 	u_int8_t, size_t);
    596 void mac68k_bssm1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    597 	u_int8_t, size_t);
    598 void mac68k_bssm2(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    599 	u_int16_t, size_t);
    600 void mac68k_bssm2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    601 	u_int16_t, size_t);
    602 void mac68k_bssm2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    603 	u_int16_t, size_t);
    604 void mac68k_bssm4(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    605 	u_int32_t, size_t);
    606 void mac68k_bssm4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    607 	u_int32_t, size_t);
    608 void mac68k_bssm4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    609 	u_int32_t, size_t);
    610 
    611 #if defined(DIAGNOSTIC)
    612 #define	bus_space_set_multi_1(t, h, o, val, c) do {			\
    613 	if ((c) == 0)							\
    614 		 panic("bus_space_set_multi_1 called with zero count."); \
    615 	(h).bssm1(t,&(h),o,val,c); } while (0)
    616 #define	bus_space_set_multi_2(t, h, o, val, c) do {			\
    617 	if ((c) == 0)							\
    618 		panic("bus_space_set_multi_2 called with zero count."); \
    619 	(h).bssm2(t,&(h),o,val,c); } while (0)
    620 #define	bus_space_set_multi_4(t, h, o, val, c) do {			\
    621 	if ((c) == 0)							\
    622 		panic("bus_space_set_multi_4 called with zero count."); \
    623 	(h).bssm4(t,&(h),o,val,c); } while (0)
    624 #else
    625 #define	bus_space_set_multi_1(t, h, o, val, c) \
    626 	do { if (c) (h).bssm1(t,&(h),o,val,c); } while (0)
    627 #define	bus_space_set_multi_2(t, h, o, val, c) \
    628 	do { if (c) (h).bssm2(t,&(h),o,val,c); } while (0)
    629 #define	bus_space_set_multi_4(t, h, o, val, c) \
    630 	do { if (c) (h).bssm4(t,&(h),o,val,c); } while (0)
    631 #endif
    632 
    633 /*
    634  *	void bus_space_set_region_N(bus_space_tag_t tag,
    635  *	    bus_space_handle_t bsh, bus_size_t, u_intN_t val,
    636  *	    size_t count);
    637  *
    638  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
    639  * by tag/handle starting at `offset'.
    640  */
    641 
    642 void mac68k_bssr1(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    643 	u_int8_t, size_t);
    644 void mac68k_bssr1_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    645 	u_int8_t, size_t);
    646 void mac68k_bssr2(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    647 	u_int16_t, size_t);
    648 void mac68k_bssr2_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    649 	u_int16_t, size_t);
    650 void mac68k_bssr2_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    651 	u_int16_t, size_t);
    652 void mac68k_bssr4(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    653 	u_int32_t, size_t);
    654 void mac68k_bssr4_swap(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    655 	u_int32_t, size_t);
    656 void mac68k_bssr4_gen(bus_space_tag_t, bus_space_handle_t *, bus_size_t,
    657 	u_int32_t, size_t);
    658 
    659 #if defined(DIAGNOSTIC)
    660 #define	bus_space_set_region_1(t, h, o, val, c) do {			 \
    661 	if ((c) == 0)							 \
    662 		panic("bus_space_set_region_1 called with zero count."); \
    663 	(h).bssr1(t,&(h),o,val,c); } while (0)
    664 #define	bus_space_set_region_2(t, h, o, val, c) do {			 \
    665 	if ((c) == 0)							 \
    666 		panic("bus_space_set_region_2 called with zero count."); \
    667 	(h).bssr2(t,&(h),o,val,c); } while (0)
    668 #define	bus_space_set_region_4(t, h, o, val, c) do {			 \
    669 	if ((c) == 0)							 \
    670 		panic("bus_space_set_region_4 called with zero count."); \
    671 	(h).bssr4(t,&(h),o,val,c); } while (0)
    672 #else
    673 #define	bus_space_set_region_1(t, h, o, val, c) \
    674 	do { if (c) (h).bssr1(t,&(h),o,val,c); } while (0)
    675 #define	bus_space_set_region_2(t, h, o, val, c) \
    676 	do { if (c) (h).bssr2(t,&(h),o,val,c); } while (0)
    677 #define	bus_space_set_region_4(t, h, o, val, c) \
    678 	do { if (c) (h).bssr4(t,&(h),o,val,c); } while (0)
    679 #endif
    680 
    681 /*
    682  *	void bus_space_copy_N(bus_space_tag_t tag,
    683  *	    bus_space_handle_t bsh1, bus_size_t off1,
    684  *	    bus_space_handle_t bsh2, bus_size_t off2, size_t count);
    685  *
    686  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
    687  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
    688  */
    689 
    690 #define	__MAC68K_copy_region_N(BYTES)					\
    691 static __inline void __CONCAT(bus_space_copy_region_,BYTES)		\
    692 	(bus_space_tag_t,						\
    693 	    bus_space_handle_t, bus_size_t,				\
    694 	    bus_space_handle_t, bus_size_t,				\
    695 	    bus_size_t);						\
    696 									\
    697 static __inline void							\
    698 __CONCAT(bus_space_copy_region_,BYTES)(					\
    699 	bus_space_tag_t t,						\
    700 	bus_space_handle_t h1,						\
    701 	bus_size_t o1,							\
    702 	bus_space_handle_t h2,						\
    703 	bus_size_t o2,							\
    704 	bus_size_t c)							\
    705 {									\
    706 	bus_size_t o;							\
    707 									\
    708 	if ((h1.base + o1) >= (h2.base + o2)) {				\
    709 		/* src after dest: copy forward */			\
    710 		for (o = 0; c != 0; c--, o += BYTES)			\
    711 			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
    712 			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
    713 	} else {							\
    714 		/* dest after src: copy backwards */			\
    715 		for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)	\
    716 			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
    717 			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
    718 	}								\
    719 }
    720 __MAC68K_copy_region_N(1)
    721 __MAC68K_copy_region_N(2)
    722 __MAC68K_copy_region_N(4)
    723 
    724 #undef __MAC68K_copy_region_N
    725 
    726 /*
    727  * Bus read/write barrier methods.
    728  *
    729  *	void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
    730  *	    bus_size_t offset, bus_size_t len, int flags);
    731  *
    732  * Note: the 680x0 does not currently require barriers, but we must
    733  * provide the flags to MI code.
    734  */
    735 #define	bus_space_barrier(t, h, o, l, f)	\
    736 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
    737 #define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
    738 #define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
    739 
    740 /*
    741  *	void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
    742  *
    743  * Get the kernel virtual address for the mapped bus space.
    744  */
    745 #define	bus_space_vaddr(t, h)	((void)(t), (void *)(h.base))
    746 
    747 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
    748 
    749 #include <m68k/bus_dma.h>
    750 
    751 #endif /* _MAC68K_BUS_H_ */
    752