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