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