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