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