Home | History | Annotate | Line # | Download | only in include
bus.h revision 1.4
      1 /*	$NetBSD: bus.h,v 1.4 1997/02/20 05:53:00 scottr Exp $	*/
      2 
      3 /*
      4  * Copyright "g" (c) 1997 Scott Reynolds.  All rights reserved.
      5  * Copyright "g" (c) 1996 Jason R. Thorpe.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *      This product includes software developed by Scott Reynolds for the
     18  *	NetBSD Project.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #ifndef _MAC68K_BUS_H_
     35 #define _MAC68K_BUS_H_
     36 
     37 /*
     38  * Value for the mac68k bus space tag, not to be used directly by MI code.
     39  */
     40 #define MAC68K_BUS_SPACE_MEM	0	/* space is mem space */
     41 
     42 /*
     43  * Bus address and size types
     44  */
     45 typedef u_long bus_addr_t;
     46 typedef u_long bus_size_t;
     47 
     48 /*
     49  * Access methods for bus resources and address space.
     50  */
     51 typedef int	bus_space_tag_t;
     52 typedef u_long	bus_space_handle_t;
     53 
     54 int	bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t,
     55 				int, bus_space_handle_t *));
     56 void	bus_space_unmap __P((bus_space_tag_t, bus_space_handle_t,
     57 				bus_size_t));
     58 int	bus_space_subregion __P((bus_space_tag_t t, bus_space_handle_t bsh,
     59 	    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp));
     60 
     61 int	bus_space_alloc __P((bus_space_tag_t t, bus_addr_t rstart,
     62 	    bus_addr_t rend, bus_size_t size, bus_size_t align,
     63 	    bus_size_t boundary, int cacheable, bus_addr_t *addrp,
     64 	    bus_space_handle_t *bshp));
     65 void	bus_space_free __P((bus_space_tag_t t, bus_space_handle_t bsh,
     66 	    bus_size_t size));
     67 
     68 /*
     69  *	u_intN_t bus_space_read_N __P((bus_space_tag_t tag,
     70  *	    bus_space_handle_t bsh, bus_size_t offset));
     71  *
     72  * Read a 1, 2, 4, or 8 byte quantity from bus space
     73  * described by tag/handle/offset.
     74  */
     75 
     76 #define	bus_space_read_1(t, h, o)					\
     77     ((void) t, (*(volatile u_int8_t *)((h) + (o))))
     78 
     79 #define	bus_space_read_2(t, h, o)					\
     80     ((void) t, (*(volatile u_int16_t *)((h) + (o))))
     81 
     82 #define	bus_space_read_4(t, h, o)					\
     83     ((void) t, (*(volatile u_int32_t *)((h) + (o))))
     84 
     85 #if 0	/* Cause a link error for bus_space_read_8 */
     86 #define	bus_space_read_8(t, h, o)	!!! bus_space_read_8 unimplemented !!!
     87 #endif
     88 
     89 /*
     90  *	void bus_space_read_multi_N __P((bus_space_tag_t tag,
     91  *	    bus_space_handle_t bsh, bus_size_t offset,
     92  *	    u_intN_t *addr, size_t count));
     93  *
     94  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
     95  * described by tag/handle/offset and copy into buffer provided.
     96  */
     97 
     98 #define	bus_space_read_multi_1(t, h, o, a, c) do {			\
     99 	__asm __volatile ("						\
    100 		movl	%0,a0					;	\
    101 		movl	%1,a1					;	\
    102 		movl	%2,d0					;	\
    103 	1:	movb	a0@,a1@+				;	\
    104 		subql	#1,d0					;	\
    105 		jne	1b"					:	\
    106 								:	\
    107 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    108 		    "a0","a1","d0");					\
    109 } while (0);
    110 
    111 #define	bus_space_read_multi_2(t, h, o, a, c) do {			\
    112 	__asm __volatile ("						\
    113 		movl	%0,a0					;	\
    114 		movl	%1,a1					;	\
    115 		movl	%2,d0					;	\
    116 	1:	movw	a0@,a1@+				;	\
    117 		subql	#1,d0					;	\
    118 		jne	1b"					:	\
    119 								:	\
    120 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    121 		    "a0","a1","d0");					\
    122 } while (0);
    123 
    124 #define	bus_space_read_multi_4(t, h, o, a, c) do {			\
    125 	__asm __volatile ("						\
    126 		movl	%0,a0					;	\
    127 		movl	%1,a1					;	\
    128 		movl	%2,d0					;	\
    129 	1:	movl	a0@,a1@+				;	\
    130 		subql	#1,d0					;	\
    131 		jne	1b"					:	\
    132 								:	\
    133 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    134 		    "a0","a1","d0");					\
    135 } while (0);
    136 
    137 #if 0	/* Cause a link error for bus_space_read_multi_8 */
    138 #define	bus_space_read_multi_8	!!! bus_space_read_multi_8 unimplemented !!!
    139 #endif
    140 
    141 /*
    142  *	void bus_space_read_region_N __P((bus_space_tag_t tag,
    143  *	    bus_space_handle_t bsh, bus_size_t offset,
    144  *	    u_intN_t *addr, size_t count));
    145  *
    146  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    147  * described by tag/handle and starting at `offset' and copy into
    148  * buffer provided.
    149  */
    150 
    151 #define	bus_space_read_region_1(t, h, o, a, c) do {			\
    152 	__asm __volatile ("						\
    153 		movl	%0,a0					;	\
    154 		movl	%1,a1					;	\
    155 		movl	%2,d0					;	\
    156 	1:	movb	a0@+,a1@+				;	\
    157 		subql	#1,d0					;	\
    158 		jne	1b"					:	\
    159 								:	\
    160 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    161 		    "a0","a1","d0");					\
    162 } while (0);
    163 
    164 #define	bus_space_read_region_2(t, h, o, a, c) do {			\
    165 	__asm __volatile ("						\
    166 		movl	%0,a0					;	\
    167 		movl	%1,a1					;	\
    168 		movl	%2,d0					;	\
    169 	1:	movw	a0@+,a1@+				;	\
    170 		subql	#1,d0					;	\
    171 		jne	1b"					:	\
    172 								:	\
    173 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    174 		    "a0","a1","d0");					\
    175 } while (0);
    176 
    177 #define	bus_space_read_region_4(t, h, o, a, c) do {			\
    178 	__asm __volatile ("						\
    179 		movl	%0,a0					;	\
    180 		movl	%1,a1					;	\
    181 		movl	%2,d0					;	\
    182 	1:	movl	a0@+,a1@+				;	\
    183 		subql	#1,d0					;	\
    184 		jne	1b"					:	\
    185 								:	\
    186 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    187 		    "a0","a1","d0");					\
    188 } while (0);
    189 
    190 #if 0	/* Cause a link error for bus_space_read_region_8 */
    191 #define	bus_space_read_region_8	!!! bus_space_read_region_8 unimplemented !!!
    192 #endif
    193 
    194 /*
    195  *	void bus_space_write_N __P((bus_space_tag_t tag,
    196  *	    bus_space_handle_t bsh, bus_size_t offset,
    197  *	    u_intN_t value));
    198  *
    199  * Write the 1, 2, 4, or 8 byte value `value' to bus space
    200  * described by tag/handle/offset.
    201  */
    202 
    203 #define	bus_space_write_1(t, h, o, v)					\
    204     ((void) t, ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))))
    205 
    206 #define	bus_space_write_2(t, h, o, v)					\
    207     ((void) t, ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))))
    208 
    209 #define	bus_space_write_4(t, h, o, v)					\
    210     ((void) t, ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))))
    211 
    212 #if 0	/* Cause a link error for bus_space_write_8 */
    213 #define	bus_space_write_8	!!! bus_space_write_8 not implemented !!!
    214 #endif
    215 
    216 /*
    217  *	void bus_space_write_multi_N __P((bus_space_tag_t tag,
    218  *	    bus_space_handle_t bsh, bus_size_t offset,
    219  *	    const u_intN_t *addr, size_t count));
    220  *
    221  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
    222  * provided to bus space described by tag/handle/offset.
    223  */
    224 
    225 #define	bus_space_write_multi_1(t, h, o, a, c) do {			\
    226 	__asm __volatile ("						\
    227 		movl	%0,a0					;	\
    228 		movl	%1,a1					;	\
    229 		movl	%2,d0					;	\
    230 	1:	movb	a1@+,a0@				;	\
    231 		subql	#1,d0					;	\
    232 		jne	1b"					:	\
    233 								:	\
    234 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    235 		    "a0","a1","d0");					\
    236 } while (0);
    237 
    238 #define	bus_space_write_multi_2(t, h, o, a, c) do {			\
    239 	__asm __volatile ("						\
    240 		movl	%0,a0					;	\
    241 		movl	%1,a1					;	\
    242 		movl	%2,d0					;	\
    243 	1:	movw	a1@+,a0@				;	\
    244 		subql	#1,d0					;	\
    245 		jne	1b"					:	\
    246 								:	\
    247 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    248 		    "a0","a1","d0");					\
    249 } while (0);
    250 
    251 #define	bus_space_write_multi_4(t, h, o, a, c) do {			\
    252 	__asm __volatile ("						\
    253 		movl	%0,a0					;	\
    254 		movl	%1,a1					;	\
    255 		movl	%2,d0					;	\
    256 	1:	movl	a1@+,a0@				;	\
    257 		subql	#1,d0					;	\
    258 		jne	1b"					:	\
    259 								:	\
    260 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    261 		    "a0","a1","d0");					\
    262 } while (0);
    263 
    264 #if 0	/* Cause a link error for bus_space_write_8 */
    265 #define	bus_space_write_multi_8(t, h, o, a, c)				\
    266 			!!! bus_space_write_multi_8 unimplimented !!!
    267 #endif
    268 
    269 /*
    270  *	void bus_space_write_region_N __P((bus_space_tag_t tag,
    271  *	    bus_space_handle_t bsh, bus_size_t offset,
    272  *	    const u_intN_t *addr, size_t count));
    273  *
    274  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
    275  * to bus space described by tag/handle starting at `offset'.
    276  */
    277 
    278 #define	bus_space_write_region_1(t, h, o, a, c) do {			\
    279 	__asm __volatile ("						\
    280 		movl	%0,a0					;	\
    281 		movl	%1,a1					;	\
    282 		movl	%2,d0					;	\
    283 	1:	movb	a1@+,a0@+				;	\
    284 		subql	#1,d0					;	\
    285 		jne	1b"					:	\
    286 								:	\
    287 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    288 		    "a0","a1","d0");					\
    289 } while (0);
    290 
    291 #define	bus_space_write_region_2(t, h, o, a, c) do {			\
    292 	__asm __volatile ("						\
    293 		movl	%0,a0					;	\
    294 		movl	%1,a1					;	\
    295 		movl	%2,d0					;	\
    296 	1:	movw	a1@+,a0@+				;	\
    297 		subql	#1,d0					;	\
    298 		jne	1b"					:	\
    299 								:	\
    300 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    301 		    "a0","a1","d0");					\
    302 } while (0);
    303 
    304 #define	bus_space_write_region_4(t, h, o, a, c) do {			\
    305 	__asm __volatile ("						\
    306 		movl	%0,a0					;	\
    307 		movl	%1,a1					;	\
    308 		movl	%2,d0					;	\
    309 	1:	movl	a1@+,a0@+				;	\
    310 		subql	#1,d0					;	\
    311 		jne	1b"					:	\
    312 								:	\
    313 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    314 		    "a0","a1","d0");					\
    315 } while (0);
    316 
    317 #if 0	/* Cause a link error for bus_space_write_region_8 */
    318 #define	bus_space_write_region_8					\
    319 			!!! bus_space_write_region_8 unimplemented !!!
    320 #endif
    321 
    322 /*
    323  *	void bus_space_set_multi_N __P((bus_space_tag_t tag,
    324  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    325  *	    size_t count));
    326  *
    327  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
    328  * by tag/handle/offset `count' times.
    329  */
    330 
    331 #define	bus_space_set_multi_1(t, h, o, val, c) do {			\
    332 	__asm __volatile ("						\
    333 		movl	%0,a0					;	\
    334 		movl	%1,d1					;	\
    335 		movl	%2,d0					;	\
    336 	1:	movb	d1,a0@					;	\
    337 		subql	#1,d0					;	\
    338 		jne	1b"					:	\
    339 								:	\
    340 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    341 		    "a0","d0","d1");					\
    342 } while (0);
    343 
    344 #define	bus_space_set_multi_2(t, h, o, val, c) do {			\
    345 	__asm __volatile ("						\
    346 		movl	%0,a0					;	\
    347 		movl	%1,d1					;	\
    348 		movl	%2,d0					;	\
    349 	1:	movw	d1,a0@					;	\
    350 		subql	#1,d0					;	\
    351 		jne	1b"					:	\
    352 								:	\
    353 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    354 		    "a0","d0","d1");					\
    355 } while (0);
    356 
    357 #define	bus_space_set_multi_4(t, h, o, val, c) do {			\
    358 	__asm __volatile ("						\
    359 		movl	%0,a0					;	\
    360 		movl	%1,d1					;	\
    361 		movl	%2,d0					;	\
    362 	1:	movl	d1,a0@					;	\
    363 		subql	#1,d0					;	\
    364 		jne	1b"					:	\
    365 								:	\
    366 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    367 		    "a0","d0","d1");					\
    368 } while (0);
    369 
    370 #if 0	/* Cause a link error for bus_space_set_multi_8 */
    371 #define	bus_space_set_multi_8						\
    372 			!!! bus_space_set_multi_8 unimplemented !!!
    373 #endif
    374 
    375 /*
    376  *	void bus_space_set_region_N __P((bus_space_tag_t tag,
    377  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    378  *	    size_t count));
    379  *
    380  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
    381  * by tag/handle starting at `offset'.
    382  */
    383 
    384 #define	bus_space_set_region_1(t, h, o, val, c) do {			\
    385 	__asm __volatile ("						\
    386 		movl	%0,a0					;	\
    387 		movl	%1,d1					;	\
    388 		movl	%2,d0					;	\
    389 	1:	movb	d1,a0@+					;	\
    390 		subql	#1,d0					;	\
    391 		jne	1b"					:	\
    392 								:	\
    393 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    394 		    "a0","d0","d1");					\
    395 } while (0);
    396 
    397 #define	bus_space_set_region_2(t, h, o, val, c) do {			\
    398 	__asm __volatile ("						\
    399 		movl	%0,a0					;	\
    400 		movl	%1,d1					;	\
    401 		movl	%2,d0					;	\
    402 	1:	movw	d1,a0@+					;	\
    403 		subql	#1,d0					;	\
    404 		jne	1b"					:	\
    405 								:	\
    406 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    407 		    "a0","d0","d1");					\
    408 } while (0);
    409 
    410 #define	bus_space_set_region_4(t, h, o, val, c) do {			\
    411 	__asm __volatile ("						\
    412 		movl	%0,a0					;	\
    413 		movl	%1,d1					;	\
    414 		movl	%2,d0					;	\
    415 	1:	movl	d1,a0@+					;	\
    416 		subql	#1,d0					;	\
    417 		jne	1b"					:	\
    418 								:	\
    419 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    420 		    "a0","d0","d1");					\
    421 } while (0);
    422 
    423 #if 0	/* Cause a link error for bus_space_set_region_8 */
    424 #define	bus_space_set_region_8						\
    425 			!!! bus_space_set_region_8 unimplemented !!!
    426 #endif
    427 
    428 /*
    429  *	void bus_space_copy_N __P((bus_space_tag_t tag,
    430  *	    bus_space_handle_t bsh1, bus_size_t off1,
    431  *	    bus_space_handle_t bsh2, bus_size_t off2,
    432  *	    size_t count));
    433  *
    434  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
    435  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
    436  */
    437 
    438 #define	bus_space_copy_1(t, h1, o1, h2, o2, c) do {			\
    439 	__asm __volatile ("						\
    440 		movl	%0,a0					;	\
    441 		movl	%1,a1					;	\
    442 		movl	%2,d0					;	\
    443 	1:	movb	a0@+,a1@+				;	\
    444 		subql	#1,d0					;	\
    445 		jne	1b"					:	\
    446 								:	\
    447 		    "r" ((h1) + (o1)), "r" ((h2) + (o2)), "g" (c) :	\
    448 		    "a0","a1","d0");					\
    449 } while (0);
    450 
    451 #define	bus_space_copy_2(t, h1, o1, h2, o2, c) do {			\
    452 	__asm __volatile ("						\
    453 		movl	%0,a0					;	\
    454 		movl	%1,a1					;	\
    455 		movl	%2,d0					;	\
    456 	1:	movw	a0@+,a1@+				;	\
    457 		subql	#1,d0					;	\
    458 		jne	1b"					:	\
    459 								:	\
    460 		    "r" ((h1) + (o1)), "r" ((h2) + (o2)), "g" (c) :	\
    461 		    "a0","a1","d0");					\
    462 } while (0);
    463 
    464 #define	bus_space_copy_4(t, h1, o1, h2, o2, c) do {			\
    465 	__asm __volatile ("						\
    466 		movl	%0,a0					;	\
    467 		movl	%1,a1					;	\
    468 		movl	%2,d0					;	\
    469 	1:	movl	a0@+,a1@+				;	\
    470 		subql	#1,d0					;	\
    471 		jne	1b"					:	\
    472 								:	\
    473 		    "r" ((h1) + (o1)), "r" ((h2) + (o2)), "g" (c) :	\
    474 		    "a0","a1","d0");					\
    475 } while (0);
    476 
    477 #if 0	/* Cause a link error for bus_space_copy_8 */
    478 #define	bus_space_copy_8						\
    479 			!!! bus_space_copy_8 unimplemented !!!
    480 #endif
    481 
    482 /*
    483  * Bus read/write barrier methods.
    484  *
    485  *	void bus_space_barrier __P((bus_space_tag_t tag,
    486  *	    bus_space_handle_t bsh, bus_size_t offset,
    487  *	    bus_size_t len, int flags));
    488  *
    489  * Note: the 680x0 does not currently require barriers, but we must
    490  * provide the flags to MI code.
    491  */
    492 #define	bus_space_barrier(t, h, o, l, f)	\
    493 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
    494 #define	BUS_BARRIER_READ	0x01		/* force read barrier */
    495 #define	BUS_BARRIER_WRITE	0x02		/* force write barrier */
    496 
    497 /*
    498  * Machine-dependent extensions.
    499  */
    500 int	bus_probe __P((bus_space_tag_t t, bus_space_handle_t bsh,
    501 	    bus_size_t offset, int sz));
    502 
    503 #endif /* _MAC68K_BUS_H_ */
    504