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