Home | History | Annotate | Line # | Download | only in include
bus.h revision 1.1
      1 /*	$NetBSD: bus.h,v 1.1 1997/02/03 17:32:54 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 u_long	bus_space_tag_t;
     52 typedef caddr_t	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 /*
     62  *	u_intN_t bus_space_read_N __P((bus_space_tag_t tag,
     63  *	    bus_space_handle_t bsh, bus_size_t offset));
     64  *
     65  * Read a 1, 2, 4, or 8 byte quantity from bus space
     66  * described by tag/handle/offset.
     67  */
     68 
     69 #define	bus_space_read_1(t, h, o)					\
     70     ((void) t, (*(volatile u_int8_t *)((h) + (o))))
     71 
     72 #define	bus_space_read_2(t, h, o)					\
     73     ((void) t, (*(volatile u_int16_t *)((h) + (o))))
     74 
     75 #define	bus_space_read_4(t, h, o)					\
     76     ((void) t, (*(volatile u_int32_t *)((h) + (o))))
     77 
     78 #if 0	/* Cause a link error for bus_space_read_8 */
     79 #define	bus_space_read_8(t, h, o)	!!! bus_space_read_8 unimplemented !!!
     80 #endif
     81 
     82 /*
     83  *	void bus_space_read_multi_N __P((bus_space_tag_t tag,
     84  *	    bus_space_handle_t bsh, bus_size_t offset,
     85  *	    u_intN_t *addr, size_t count));
     86  *
     87  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
     88  * described by tag/handle/offset and copy into buffer provided.
     89  */
     90 
     91 #define	bus_space_read_multi_1(t, h, o, a, c) do {			\
     92 	__asm __volatile ("						\
     93 		movl	%0,a0					;	\
     94 		movl	%1,a1					;	\
     95 		movl	%2,d0					;	\
     96 	1:	movb	a0@,a1@+				;	\
     97 		subql	#1,d0					;	\
     98 		jne	1b"					:	\
     99 								:	\
    100 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    101 		    "a0","a1","d0");					\
    102 } while (0);
    103 
    104 #define	bus_space_read_multi_2(t, h, o, a, c) do {			\
    105 	__asm __volatile ("						\
    106 		movl	%0,a0					;	\
    107 		movl	%1,a1					;	\
    108 		movl	%2,d0					;	\
    109 	1:	movw	a0@,a1@+				;	\
    110 		subql	#1,d0					;	\
    111 		jne	1b"					:	\
    112 								:	\
    113 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    114 		    "a0","a1","d0");					\
    115 } while (0);
    116 
    117 #define	bus_space_read_multi_4(t, h, o, a, c) do {			\
    118 	__asm __volatile ("						\
    119 		movl	%0,a0					;	\
    120 		movl	%1,a1					;	\
    121 		movl	%2,d0					;	\
    122 	1:	movl	a0@,a1@+				;	\
    123 		subql	#1,d0					;	\
    124 		jne	1b"					:	\
    125 								:	\
    126 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    127 		    "a0","a1","d0");					\
    128 } while (0);
    129 
    130 #if 0	/* Cause a link error for bus_space_read_multi_8 */
    131 #define	bus_space_read_multi_8	!!! bus_space_read_multi_8 unimplemented !!!
    132 #endif
    133 
    134 /*
    135  *	void bus_space_read_region_N __P((bus_space_tag_t tag,
    136  *	    bus_space_handle_t bsh, bus_size_t offset,
    137  *	    u_intN_t *addr, size_t count));
    138  *
    139  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    140  * described by tag/handle and starting at `offset' and copy into
    141  * buffer provided.
    142  */
    143 
    144 #define	bus_space_read_region_1(t, h, o, a, c) do {			\
    145 	__asm __volatile ("						\
    146 		movl	%0,a0					;	\
    147 		movl	%1,a1					;	\
    148 		movl	%2,d0					;	\
    149 	1:	movb	a0@+,a1@+				;	\
    150 		subql	#1,d0					;	\
    151 		jne	1b"					:	\
    152 								:	\
    153 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    154 		    "a0","a1","d0");					\
    155 } while (0);
    156 
    157 #define	bus_space_read_region_2(t, h, o, a, c) do {			\
    158 	__asm __volatile ("						\
    159 		movl	%0,a0					;	\
    160 		movl	%1,a1					;	\
    161 		movl	%2,d0					;	\
    162 	1:	movw	a0@+,a1@+				;	\
    163 		subql	#1,d0					;	\
    164 		jne	1b"					:	\
    165 								:	\
    166 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    167 		    "a0","a1","d0");					\
    168 } while (0);
    169 
    170 #define	bus_space_read_region_4(t, h, o, a, c) do {			\
    171 	__asm __volatile ("						\
    172 		movl	%0,a0					;	\
    173 		movl	%1,a1					;	\
    174 		movl	%2,d0					;	\
    175 	1:	movl	a0@+,a1@+				;	\
    176 		subql	#1,d0					;	\
    177 		jne	1b"					:	\
    178 								:	\
    179 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    180 		    "a0","a1","d0");					\
    181 } while (0);
    182 
    183 #if 0	/* Cause a link error for bus_space_read_region_8 */
    184 #define	bus_space_read_region_8	!!! bus_space_read_region_8 unimplemented !!!
    185 #endif
    186 
    187 /*
    188  *	void bus_space_write_N __P((bus_space_tag_t tag,
    189  *	    bus_space_handle_t bsh, bus_size_t offset,
    190  *	    u_intN_t value));
    191  *
    192  * Write the 1, 2, 4, or 8 byte value `value' to bus space
    193  * described by tag/handle/offset.
    194  */
    195 
    196 #define	bus_space_write_1(t, h, o, v)					\
    197     ((void) t, ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))))
    198 
    199 #define	bus_space_write_2(t, h, o, v)					\
    200     ((void) t, ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))))
    201 
    202 #define	bus_space_write_4(t, h, o, v)					\
    203     ((void) t, ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))))
    204 
    205 #if 0	/* Cause a link error for bus_space_write_8 */
    206 #define	bus_space_write_8	!!! bus_space_write_8 not implemented !!!
    207 #endif
    208 
    209 /*
    210  *	void bus_space_write_multi_N __P((bus_space_tag_t tag,
    211  *	    bus_space_handle_t bsh, bus_size_t offset,
    212  *	    const u_intN_t *addr, size_t count));
    213  *
    214  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
    215  * provided to bus space described by tag/handle/offset.
    216  */
    217 
    218 #define	bus_space_write_multi_1(t, h, o, a, c) do {			\
    219 	__asm __volatile ("						\
    220 		movl	%0,a0					;	\
    221 		movl	%1,a1					;	\
    222 		movl	%2,d0					;	\
    223 	1:	movb	a1@+,a0@				;	\
    224 		subql	#1,d0					;	\
    225 		jne	1b"					:	\
    226 								:	\
    227 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    228 		    "a0","a1","d0");					\
    229 } while (0);
    230 
    231 #define	bus_space_write_multi_2(t, h, o, a, c) do {			\
    232 	__asm __volatile ("						\
    233 		movl	%0,a0					;	\
    234 		movl	%1,a1					;	\
    235 		movl	%2,d0					;	\
    236 	1:	movw	a1@+,a0@				;	\
    237 		subql	#1,d0					;	\
    238 		jne	1b"					:	\
    239 								:	\
    240 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    241 		    "a0","a1","d0");					\
    242 } while (0);
    243 
    244 #define	bus_space_write_multi_4(t, h, o, a, c) do {			\
    245 	__asm __volatile ("						\
    246 		movl	%0,a0					;	\
    247 		movl	%1,a1					;	\
    248 		movl	%2,d0					;	\
    249 	1:	movl	a1@+,a0@				;	\
    250 		subql	#1,d0					;	\
    251 		jne	1b"					:	\
    252 								:	\
    253 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    254 		    "a0","a1","d0");					\
    255 } while (0);
    256 
    257 #if 0	/* Cause a link error for bus_space_write_8 */
    258 #define	bus_space_write_multi_8(t, h, o, a, c)				\
    259 			!!! bus_space_write_multi_8 unimplimented !!!
    260 #endif
    261 
    262 /*
    263  *	void bus_space_write_region_N __P((bus_space_tag_t tag,
    264  *	    bus_space_handle_t bsh, bus_size_t offset,
    265  *	    const u_intN_t *addr, size_t count));
    266  *
    267  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
    268  * to bus space described by tag/handle starting at `offset'.
    269  */
    270 
    271 #define	bus_space_write_region_1(t, h, o, a, c) do {			\
    272 	__asm __volatile ("						\
    273 		movl	%0,a0					;	\
    274 		movl	%1,a1					;	\
    275 		movl	%2,d0					;	\
    276 	1:	movb	a1@+,a0@+				;	\
    277 		subql	#1,d0					;	\
    278 		jne	1b"					:	\
    279 								:	\
    280 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    281 		    "a0","a1","d0");					\
    282 } while (0);
    283 
    284 #define	bus_space_write_region_2(t, h, o, a, c) do {			\
    285 	__asm __volatile ("						\
    286 		movl	%0,a0					;	\
    287 		movl	%1,a1					;	\
    288 		movl	%2,d0					;	\
    289 	1:	movw	a1@+,a0@+				;	\
    290 		subql	#1,d0					;	\
    291 		jne	1b"					:	\
    292 								:	\
    293 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    294 		    "a0","a1","d0");					\
    295 } while (0);
    296 
    297 #define	bus_space_write_region_4(t, h, o, a, c) do {			\
    298 	__asm __volatile ("						\
    299 		movl	%0,a0					;	\
    300 		movl	%1,a1					;	\
    301 		movl	%2,d0					;	\
    302 	1:	movl	a1@+,a0@+				;	\
    303 		subql	#1,d0					;	\
    304 		jne	1b"					:	\
    305 								:	\
    306 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    307 		    "a0","a1","d0");					\
    308 } while (0);
    309 
    310 #if 0	/* Cause a link error for bus_space_write_region_8 */
    311 #define	bus_space_write_region_8					\
    312 			!!! bus_space_write_region_8 unimplemented !!!
    313 #endif
    314 
    315 /*
    316  *	void bus_space_set_multi_N __P((bus_space_tag_t tag,
    317  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    318  *	    size_t count));
    319  *
    320  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
    321  * by tag/handle/offset `count' times.
    322  */
    323 
    324 	/* XXX IMPLEMENT bus_space_set_multi_N() XXX */
    325 
    326 /*
    327  *	void bus_space_set_region_N __P((bus_space_tag_t tag,
    328  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    329  *	    size_t count));
    330  *
    331  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
    332  * by tag/handle starting at `offset'.
    333  */
    334 
    335 	/* XXX IMPLEMENT bus_space_set_region_N() XXX */
    336 
    337 /*
    338  *	void bus_space_copy_N __P((bus_space_tag_t tag,
    339  *	    bus_space_handle_t bsh1, bus_size_t off1,
    340  *	    bus_space_handle_t bsh2, bus_size_t off2,
    341  *	    size_t count));
    342  *
    343  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
    344  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
    345  */
    346 
    347 	/* XXX IMPLEMENT bus_space_copy_N() XXX */
    348 
    349 /*
    350  * Bus read/write barrier methods.
    351  *
    352  *	void bus_space_barrier __P((bus_space_tag_t tag,
    353  *	    bus_space_handle_t bsh, bus_size_t offset,
    354  *	    bus_size_t len, int flags));
    355  *
    356  * Note: the 680x0 does not currently require barriers, but we must
    357  * provide the flags to MI code.
    358  */
    359 #define	bus_space_barrier(t, h, o, l, f)	\
    360 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
    361 #define	BUS_BARRIER_READ	0x01		/* force read barrier */
    362 #define	BUS_BARRIER_WRITE	0x02		/* force write barrier */
    363 
    364 /*
    365  * Machine-dependent extensions.
    366  */
    367 int	bus_probe __P((bus_space_tag_t t, bus_space_handle_t bsh,
    368 	    bus_size_t offset, int sz));
    369 
    370 #endif /* _MAC68K_BUS_H_ */
    371