Home | History | Annotate | Line # | Download | only in include
      1  1.13  tsutsui /*	$NetBSD: bus.h,v 1.13 2023/01/27 19:50:02 tsutsui 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.10    skrll #define PRIxBUSADDR	"lx"
     77  1.10    skrll #define PRIxBUSSIZE	"lx"
     78  1.10    skrll #define PRIuBUSSIZE	"lu"
     79  1.10    skrll 
     80   1.1  tsutsui /*
     81   1.1  tsutsui  * Access methods for bus resources and address space.
     82   1.1  tsutsui  */
     83   1.1  tsutsui typedef int	bus_space_tag_t;
     84   1.1  tsutsui typedef u_long	bus_space_handle_t;
     85   1.1  tsutsui 
     86  1.10    skrll #define PRIxBSH		"lx"
     87  1.10    skrll 
     88   1.1  tsutsui /*
     89   1.2  tsutsui  *	int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
     90   1.2  tsutsui  *	    bus_size_t size, int flags, bus_space_handle_t *bshp);
     91   1.1  tsutsui  *
     92   1.1  tsutsui  * Map a region of bus space.
     93   1.1  tsutsui  */
     94   1.1  tsutsui 
     95   1.1  tsutsui #define	BUS_SPACE_MAP_CACHEABLE		0x01
     96   1.1  tsutsui #define	BUS_SPACE_MAP_LINEAR		0x02
     97   1.1  tsutsui #define	BUS_SPACE_MAP_PREFETCHABLE	0x04
     98   1.1  tsutsui 
     99   1.2  tsutsui int	bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
    100   1.2  tsutsui 	    int, bus_space_handle_t *);
    101   1.1  tsutsui 
    102   1.1  tsutsui /*
    103   1.2  tsutsui  *	void bus_space_unmap(bus_space_tag_t t,
    104   1.2  tsutsui  *	    bus_space_handle_t bsh, bus_size_t size);
    105   1.1  tsutsui  *
    106   1.1  tsutsui  * Unmap a region of bus space.
    107   1.1  tsutsui  */
    108   1.1  tsutsui 
    109   1.2  tsutsui void	bus_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t);
    110   1.1  tsutsui 
    111   1.1  tsutsui /*
    112   1.2  tsutsui  *	int bus_space_subregion(bus_space_tag_t t,
    113   1.1  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
    114   1.2  tsutsui  *	    bus_space_handle_t *nbshp);
    115   1.1  tsutsui  *
    116   1.1  tsutsui  * Get a new handle for a subregion of an already-mapped area of bus space.
    117   1.1  tsutsui  */
    118   1.1  tsutsui 
    119   1.2  tsutsui int	bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
    120   1.2  tsutsui 	    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
    121   1.1  tsutsui 
    122   1.1  tsutsui /*
    123   1.2  tsutsui  *	int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
    124   1.1  tsutsui  *	    bus_addr_t rend, bus_size_t size, bus_size_t align,
    125   1.1  tsutsui  *	    bus_size_t boundary, int flags, bus_addr_t *addrp,
    126   1.2  tsutsui  *	    bus_space_handle_t *bshp);
    127   1.1  tsutsui  *
    128   1.1  tsutsui  * Allocate a region of bus space.
    129   1.1  tsutsui  */
    130   1.1  tsutsui 
    131   1.2  tsutsui int	bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
    132   1.1  tsutsui 	    bus_addr_t rend, bus_size_t size, bus_size_t align,
    133   1.1  tsutsui 	    bus_size_t boundary, int cacheable, bus_addr_t *addrp,
    134   1.2  tsutsui 	    bus_space_handle_t *bshp);
    135   1.1  tsutsui 
    136   1.1  tsutsui /*
    137   1.2  tsutsui  *	int bus_space_free(bus_space_tag_t t,
    138   1.2  tsutsui  *	    bus_space_handle_t bsh, bus_size_t size);
    139   1.1  tsutsui  *
    140   1.1  tsutsui  * Free a region of bus space.
    141   1.1  tsutsui  */
    142   1.1  tsutsui 
    143   1.2  tsutsui void	bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
    144   1.2  tsutsui 	    bus_size_t size);
    145   1.1  tsutsui 
    146   1.1  tsutsui /*
    147   1.2  tsutsui  *	int news68k_bus_space_probe(bus_space_tag_t t,
    148   1.2  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset, int sz);
    149   1.1  tsutsui  *
    150   1.1  tsutsui  * Probe the bus at t/bsh/offset, using sz as the size of the load.
    151   1.1  tsutsui  *
    152   1.1  tsutsui  * This is a machine-dependent extension, and is not to be used by
    153   1.1  tsutsui  * machine-independent code.
    154   1.1  tsutsui  */
    155   1.1  tsutsui 
    156   1.2  tsutsui int	news68k_bus_space_probe(bus_space_tag_t t,
    157   1.2  tsutsui 	    bus_space_handle_t bsh, bus_size_t offset, int sz);
    158   1.1  tsutsui 
    159   1.1  tsutsui /*
    160   1.4  tsutsui  *	uintN_t bus_space_read_N(bus_space_tag_t tag,
    161   1.2  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset);
    162   1.1  tsutsui  *
    163   1.1  tsutsui  * Read a 1, 2, 4, or 8 byte quantity from bus space
    164   1.1  tsutsui  * described by tag/handle/offset.
    165   1.1  tsutsui  */
    166   1.1  tsutsui 
    167   1.1  tsutsui #define	bus_space_read_1(t, h, o)					\
    168   1.4  tsutsui     ((void) t, (*(volatile uint8_t *)((h) + (o))))
    169   1.1  tsutsui 
    170   1.1  tsutsui #define	bus_space_read_2(t, h, o)					\
    171   1.4  tsutsui     ((void) t, (*(volatile uint16_t *)((h) + (o))))
    172   1.1  tsutsui 
    173   1.1  tsutsui #define	bus_space_read_4(t, h, o)					\
    174   1.4  tsutsui     ((void) t, (*(volatile uint32_t *)((h) + (o))))
    175   1.1  tsutsui 
    176   1.1  tsutsui /*
    177   1.2  tsutsui  *	void bus_space_read_multi_N(bus_space_tag_t tag,
    178   1.1  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset,
    179   1.4  tsutsui  *	    uintN_t *addr, size_t count);
    180   1.1  tsutsui  *
    181   1.1  tsutsui  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    182   1.1  tsutsui  * described by tag/handle/offset and copy into buffer provided.
    183   1.1  tsutsui  */
    184   1.1  tsutsui 
    185   1.1  tsutsui #define	bus_space_read_multi_1(t, h, o, a, c) do {			\
    186   1.1  tsutsui 	(void) t;							\
    187   1.6    perry 	__asm volatile ("						\
    188   1.1  tsutsui 		movl	%0,%%a0					;	\
    189   1.1  tsutsui 		movl	%1,%%a1					;	\
    190   1.1  tsutsui 		movl	%2,%%d0					;	\
    191   1.1  tsutsui 	1:	movb	%%a0@,%%a1@+				;	\
    192   1.1  tsutsui 		subql	#1,%%d0					;	\
    193   1.1  tsutsui 		jne	1b"					:	\
    194   1.1  tsutsui 								:	\
    195   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    196  1.13  tsutsui 		    "a0","a1","d0","memory");				\
    197   1.1  tsutsui } while (0)
    198   1.1  tsutsui 
    199   1.1  tsutsui #define	bus_space_read_multi_2(t, h, o, a, c) do {			\
    200   1.1  tsutsui 	(void) t;							\
    201   1.6    perry 	__asm volatile ("						\
    202   1.1  tsutsui 		movl	%0,%%a0					;	\
    203   1.1  tsutsui 		movl	%1,%%a1					;	\
    204   1.1  tsutsui 		movl	%2,%%d0					;	\
    205   1.1  tsutsui 	1:	movw	%%a0@,%%a1@+				;	\
    206   1.1  tsutsui 		subql	#1,%%d0					;	\
    207   1.1  tsutsui 		jne	1b"					:	\
    208   1.1  tsutsui 								:	\
    209   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    210  1.13  tsutsui 		    "a0","a1","d0","memory");				\
    211   1.1  tsutsui } while (0)
    212   1.1  tsutsui 
    213   1.1  tsutsui #define	bus_space_read_multi_4(t, h, o, a, c) do {			\
    214   1.1  tsutsui 	(void) t;							\
    215   1.6    perry 	__asm volatile ("						\
    216   1.1  tsutsui 		movl	%0,%%a0					;	\
    217   1.1  tsutsui 		movl	%1,%%a1					;	\
    218   1.1  tsutsui 		movl	%2,%%d0					;	\
    219   1.1  tsutsui 	1:	movl	%%a0@,%%a1@+				;	\
    220   1.1  tsutsui 		subql	#1,%%d0					;	\
    221   1.1  tsutsui 		jne	1b"					:	\
    222   1.1  tsutsui 								:	\
    223   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    224  1.13  tsutsui 		    "a0","a1","d0","memory");				\
    225   1.1  tsutsui } while (0)
    226   1.1  tsutsui 
    227   1.1  tsutsui /*
    228   1.2  tsutsui  *	void bus_space_read_region_N(bus_space_tag_t tag,
    229   1.1  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset,
    230   1.4  tsutsui  *	    uintN_t *addr, size_t count);
    231   1.1  tsutsui  *
    232   1.1  tsutsui  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    233   1.1  tsutsui  * described by tag/handle and starting at `offset' and copy into
    234   1.1  tsutsui  * buffer provided.
    235   1.1  tsutsui  */
    236   1.1  tsutsui 
    237   1.1  tsutsui #define	bus_space_read_region_1(t, h, o, a, c) do {			\
    238   1.1  tsutsui 	(void) t;							\
    239   1.6    perry 	__asm volatile ("						\
    240   1.1  tsutsui 		movl	%0,%%a0					;	\
    241   1.1  tsutsui 		movl	%1,%%a1					;	\
    242   1.1  tsutsui 		movl	%2,%%d0					;	\
    243   1.1  tsutsui 	1:	movb	%%a0@+,%%a1@+				;	\
    244   1.1  tsutsui 		subql	#1,%%d0					;	\
    245   1.1  tsutsui 		jne	1b"					:	\
    246   1.1  tsutsui 								:	\
    247   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    248  1.13  tsutsui 		    "a0","a1","d0","memory");				\
    249   1.1  tsutsui } while (0)
    250   1.1  tsutsui 
    251   1.1  tsutsui #define	bus_space_read_region_2(t, h, o, a, c) do {			\
    252   1.1  tsutsui 	(void) t;							\
    253   1.6    perry 	__asm volatile ("						\
    254   1.1  tsutsui 		movl	%0,%%a0					;	\
    255   1.1  tsutsui 		movl	%1,%%a1					;	\
    256   1.1  tsutsui 		movl	%2,%%d0					;	\
    257   1.1  tsutsui 	1:	movw	%%a0@+,%%a1@+				;	\
    258   1.1  tsutsui 		subql	#1,%%d0					;	\
    259   1.1  tsutsui 		jne	1b"					:	\
    260   1.1  tsutsui 								:	\
    261   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    262  1.13  tsutsui 		    "a0","a1","d0","memory");				\
    263   1.1  tsutsui } while (0)
    264   1.1  tsutsui 
    265   1.1  tsutsui #define	bus_space_read_region_4(t, h, o, a, c) do {			\
    266   1.1  tsutsui 	(void) t;							\
    267   1.6    perry 	__asm volatile ("						\
    268   1.1  tsutsui 		movl	%0,%%a0					;	\
    269   1.1  tsutsui 		movl	%1,%%a1					;	\
    270   1.1  tsutsui 		movl	%2,%%d0					;	\
    271   1.1  tsutsui 	1:	movl	%%a0@+,%%a1@+				;	\
    272   1.1  tsutsui 		subql	#1,%%d0					;	\
    273   1.1  tsutsui 		jne	1b"					:	\
    274   1.1  tsutsui 								:	\
    275   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    276  1.13  tsutsui 		    "a0","a1","d0","memory");				\
    277   1.1  tsutsui } while (0)
    278   1.1  tsutsui 
    279   1.1  tsutsui /*
    280   1.2  tsutsui  *	void bus_space_write_N(bus_space_tag_t tag,
    281   1.1  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset,
    282   1.4  tsutsui  *	    uintN_t value);
    283   1.1  tsutsui  *
    284   1.1  tsutsui  * Write the 1, 2, 4, or 8 byte value `value' to bus space
    285   1.1  tsutsui  * described by tag/handle/offset.
    286   1.1  tsutsui  */
    287   1.1  tsutsui 
    288   1.1  tsutsui #define	bus_space_write_1(t, h, o, v)					\
    289   1.4  tsutsui     ((void) t, ((void)(*(volatile uint8_t *)((h) + (o)) = (v))))
    290   1.1  tsutsui 
    291   1.1  tsutsui #define	bus_space_write_2(t, h, o, v)					\
    292   1.4  tsutsui     ((void) t, ((void)(*(volatile uint16_t *)((h) + (o)) = (v))))
    293   1.1  tsutsui 
    294   1.1  tsutsui #define	bus_space_write_4(t, h, o, v)					\
    295   1.4  tsutsui     ((void) t, ((void)(*(volatile uint32_t *)((h) + (o)) = (v))))
    296   1.1  tsutsui 
    297   1.1  tsutsui /*
    298   1.2  tsutsui  *	void bus_space_write_multi_N(bus_space_tag_t tag,
    299   1.1  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset,
    300   1.4  tsutsui  *	    const uintN_t *addr, size_t count);
    301   1.1  tsutsui  *
    302   1.1  tsutsui  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
    303   1.1  tsutsui  * provided to bus space described by tag/handle/offset.
    304   1.1  tsutsui  */
    305   1.1  tsutsui 
    306   1.1  tsutsui #define	bus_space_write_multi_1(t, h, o, a, c) do {			\
    307   1.1  tsutsui 	(void) t;							\
    308   1.6    perry 	__asm volatile ("						\
    309   1.1  tsutsui 		movl	%0,%%a0					;	\
    310   1.1  tsutsui 		movl	%1,%%a1					;	\
    311   1.1  tsutsui 		movl	%2,%%d0					;	\
    312   1.1  tsutsui 	1:	movb	%%a1@+,%%a0@				;	\
    313   1.1  tsutsui 		subql	#1,%%d0					;	\
    314   1.1  tsutsui 		jne	1b"					:	\
    315   1.1  tsutsui 								:	\
    316   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    317  1.13  tsutsui 		    "a0","a1","d0");					\
    318   1.1  tsutsui } while (0)
    319   1.1  tsutsui 
    320   1.1  tsutsui #define	bus_space_write_multi_2(t, h, o, a, c) do {			\
    321   1.1  tsutsui 	(void) t;							\
    322   1.6    perry 	__asm volatile ("						\
    323   1.1  tsutsui 		movl	%0,%%a0					;	\
    324   1.1  tsutsui 		movl	%1,%%a1					;	\
    325   1.1  tsutsui 		movl	%2,%%d0					;	\
    326   1.1  tsutsui 	1:	movw	%%a1@+,%%a0@				;	\
    327   1.1  tsutsui 		subql	#1,%%d0					;	\
    328   1.1  tsutsui 		jne	1b"					:	\
    329   1.1  tsutsui 								:	\
    330   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    331  1.13  tsutsui 		    "a0","a1","d0");					\
    332   1.1  tsutsui } while (0)
    333   1.1  tsutsui 
    334   1.1  tsutsui #define	bus_space_write_multi_4(t, h, o, a, c) do {			\
    335   1.1  tsutsui 	(void) t;							\
    336   1.6    perry 	__asm volatile ("						\
    337   1.1  tsutsui 		movl	%0,%%a0					;	\
    338   1.1  tsutsui 		movl	%1,%%a1					;	\
    339   1.1  tsutsui 		movl	%2,%%d0					;	\
    340   1.1  tsutsui 	1:	movl	%%a1@+,%%a0@				;	\
    341   1.1  tsutsui 		subql	#1,%%d0					;	\
    342   1.1  tsutsui 		jne	1b"					:	\
    343   1.1  tsutsui 								:	\
    344   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    345  1.13  tsutsui 		    "a0","a1","d0");					\
    346   1.1  tsutsui } while (0)
    347   1.1  tsutsui 
    348   1.1  tsutsui /*
    349   1.2  tsutsui  *	void bus_space_write_region_N(bus_space_tag_t tag,
    350   1.1  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset,
    351   1.4  tsutsui  *	    const uintN_t *addr, size_t count);
    352   1.1  tsutsui  *
    353   1.1  tsutsui  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
    354   1.1  tsutsui  * to bus space described by tag/handle starting at `offset'.
    355   1.1  tsutsui  */
    356   1.1  tsutsui 
    357   1.1  tsutsui #define	bus_space_write_region_1(t, h, o, a, c) do {			\
    358   1.1  tsutsui 	(void) t;							\
    359   1.6    perry 	__asm volatile ("						\
    360   1.1  tsutsui 		movl	%0,%%a0					;	\
    361   1.1  tsutsui 		movl	%1,%%a1					;	\
    362   1.1  tsutsui 		movl	%2,%%d0					;	\
    363   1.1  tsutsui 	1:	movb	%%a1@+,%%a0@+				;	\
    364   1.1  tsutsui 		subql	#1,%%d0					;	\
    365   1.1  tsutsui 		jne	1b"					:	\
    366   1.1  tsutsui 								:	\
    367   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    368  1.13  tsutsui 		    "a0","a1","d0");					\
    369   1.1  tsutsui } while (0)
    370   1.1  tsutsui 
    371   1.1  tsutsui #define	bus_space_write_region_2(t, h, o, a, c) do {			\
    372   1.1  tsutsui 	(void) t;							\
    373   1.6    perry 	__asm volatile ("						\
    374   1.1  tsutsui 		movl	%0,%%a0					;	\
    375   1.1  tsutsui 		movl	%1,%%a1					;	\
    376   1.1  tsutsui 		movl	%2,%%d0					;	\
    377   1.1  tsutsui 	1:	movw	%%a1@+,%%a0@+				;	\
    378   1.1  tsutsui 		subql	#1,%%d0					;	\
    379   1.1  tsutsui 		jne	1b"					:	\
    380   1.1  tsutsui 								:	\
    381   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    382  1.13  tsutsui 		    "a0","a1","d0");					\
    383   1.1  tsutsui } while (0)
    384   1.1  tsutsui 
    385   1.1  tsutsui #define	bus_space_write_region_4(t, h, o, a, c) do {			\
    386   1.1  tsutsui 	(void) t;							\
    387   1.6    perry 	__asm volatile ("						\
    388   1.1  tsutsui 		movl	%0,%%a0					;	\
    389   1.1  tsutsui 		movl	%1,%%a1					;	\
    390   1.1  tsutsui 		movl	%2,%%d0					;	\
    391   1.1  tsutsui 	1:	movl	%%a1@+,%%a0@+				;	\
    392   1.1  tsutsui 		subql	#1,%%d0					;	\
    393   1.1  tsutsui 		jne	1b"					:	\
    394   1.1  tsutsui 								:	\
    395   1.1  tsutsui 		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
    396  1.13  tsutsui 		    "a0","a1","d0");					\
    397   1.1  tsutsui } while (0)
    398   1.1  tsutsui 
    399   1.1  tsutsui /*
    400   1.2  tsutsui  *	void bus_space_set_multi_N(bus_space_tag_t tag,
    401   1.4  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
    402   1.2  tsutsui  *	    size_t count);
    403   1.1  tsutsui  *
    404   1.1  tsutsui  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
    405   1.1  tsutsui  * by tag/handle/offset `count' times.
    406   1.1  tsutsui  */
    407   1.1  tsutsui 
    408   1.1  tsutsui #define	bus_space_set_multi_1(t, h, o, val, c) do {			\
    409   1.1  tsutsui 	(void) t;							\
    410   1.6    perry 	__asm volatile ("						\
    411   1.1  tsutsui 		movl	%0,%%a0					;	\
    412   1.1  tsutsui 		movl	%1,%%d1					;	\
    413   1.1  tsutsui 		movl	%2,%%d0					;	\
    414   1.1  tsutsui 	1:	movb	%%d1,%%a0@				;	\
    415   1.1  tsutsui 		subql	#1,%%d0					;	\
    416   1.1  tsutsui 		jne	1b"					:	\
    417   1.1  tsutsui 								:	\
    418   1.1  tsutsui 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    419  1.13  tsutsui 		    "a0","d0","d1");					\
    420   1.1  tsutsui } while (0)
    421   1.1  tsutsui 
    422   1.1  tsutsui #define	bus_space_set_multi_2(t, h, o, val, c) do {			\
    423   1.1  tsutsui 	(void) t;							\
    424   1.6    perry 	__asm volatile ("						\
    425   1.1  tsutsui 		movl	%0,%%a0					;	\
    426   1.1  tsutsui 		movl	%1,%%d1					;	\
    427   1.1  tsutsui 		movl	%2,%%d0					;	\
    428   1.1  tsutsui 	1:	movw	%%d1,%%a0@				;	\
    429   1.1  tsutsui 		subql	#1,%%d0					;	\
    430   1.1  tsutsui 		jne	1b"					:	\
    431   1.1  tsutsui 								:	\
    432   1.1  tsutsui 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    433  1.13  tsutsui 		    "a0","d0","d1");					\
    434   1.1  tsutsui } while (0)
    435   1.1  tsutsui 
    436   1.1  tsutsui #define	bus_space_set_multi_4(t, h, o, val, c) do {			\
    437   1.1  tsutsui 	(void) t;							\
    438   1.6    perry 	__asm volatile ("						\
    439   1.1  tsutsui 		movl	%0,%%a0					;	\
    440   1.1  tsutsui 		movl	%1,%%d1					;	\
    441   1.1  tsutsui 		movl	%2,%%d0					;	\
    442   1.1  tsutsui 	1:	movl	%%d1,%%a0@				;	\
    443   1.1  tsutsui 		subql	#1,%%d0					;	\
    444   1.1  tsutsui 		jne	1b"					:	\
    445   1.1  tsutsui 								:	\
    446   1.1  tsutsui 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    447  1.13  tsutsui 		    "a0","d0","d1");					\
    448   1.1  tsutsui } while (0)
    449   1.1  tsutsui 
    450   1.1  tsutsui /*
    451   1.2  tsutsui  *	void bus_space_set_region_N(bus_space_tag_t tag,
    452   1.4  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
    453   1.2  tsutsui  *	    size_t count);
    454   1.1  tsutsui  *
    455   1.1  tsutsui  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
    456   1.1  tsutsui  * by tag/handle starting at `offset'.
    457   1.1  tsutsui  */
    458   1.1  tsutsui 
    459   1.1  tsutsui #define	bus_space_set_region_1(t, h, o, val, c) do {			\
    460   1.1  tsutsui 	(void) t;							\
    461   1.6    perry 	__asm volatile ("						\
    462   1.1  tsutsui 		movl	%0,%%a0					;	\
    463   1.1  tsutsui 		movl	%1,%%d1					;	\
    464   1.1  tsutsui 		movl	%2,%%d0					;	\
    465   1.1  tsutsui 	1:	movb	%%d1,%%a0@+				;	\
    466   1.1  tsutsui 		subql	#1,%%d0					;	\
    467   1.1  tsutsui 		jne	1b"					:	\
    468   1.1  tsutsui 								:	\
    469   1.1  tsutsui 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    470  1.13  tsutsui 		    "a0","d0","d1");					\
    471   1.1  tsutsui } while (0)
    472   1.1  tsutsui 
    473   1.1  tsutsui #define	bus_space_set_region_2(t, h, o, val, c) do {			\
    474   1.1  tsutsui 	(void) t;							\
    475   1.6    perry 	__asm volatile ("						\
    476   1.1  tsutsui 		movl	%0,%%a0					;	\
    477   1.1  tsutsui 		movl	%1,%%d1					;	\
    478   1.1  tsutsui 		movl	%2,%%d0					;	\
    479   1.1  tsutsui 	1:	movw	%%d1,%%a0@+				;	\
    480   1.1  tsutsui 		subql	#1,%%d0					;	\
    481   1.1  tsutsui 		jne	1b"					:	\
    482   1.1  tsutsui 								:	\
    483   1.1  tsutsui 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    484  1.13  tsutsui 		    "a0","d0","d1");					\
    485   1.1  tsutsui } while (0)
    486   1.1  tsutsui 
    487   1.1  tsutsui #define	bus_space_set_region_4(t, h, o, val, c) do {			\
    488   1.1  tsutsui 	(void) t;							\
    489   1.6    perry 	__asm volatile ("						\
    490   1.1  tsutsui 		movl	%0,%%a0					;	\
    491   1.1  tsutsui 		movl	%1,%%d1					;	\
    492   1.1  tsutsui 		movl	%2,%%d0					;	\
    493   1.1  tsutsui 	1:	movl	%%d1,%%a0@+				;	\
    494   1.1  tsutsui 		subql	#1,%%d0					;	\
    495   1.1  tsutsui 		jne	1b"					:	\
    496   1.1  tsutsui 								:	\
    497   1.1  tsutsui 		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
    498  1.13  tsutsui 		    "a0","d0","d1");					\
    499   1.1  tsutsui } while (0)
    500   1.1  tsutsui 
    501   1.1  tsutsui /*
    502   1.2  tsutsui  *	void bus_space_copy_region_N(bus_space_tag_t tag,
    503   1.1  tsutsui  *	    bus_space_handle_t bsh1, bus_size_t off1,
    504   1.1  tsutsui  *	    bus_space_handle_t bsh2, bus_size_t off2,
    505   1.2  tsutsui  *	    bus_size_t count);
    506   1.1  tsutsui  *
    507   1.1  tsutsui  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
    508   1.1  tsutsui  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
    509   1.1  tsutsui  */
    510   1.1  tsutsui 
    511   1.1  tsutsui #define	__NEWS68K_copy_region_N(BYTES)					\
    512   1.7    perry static __inline void __CONCAT(bus_space_copy_region_,BYTES)		\
    513   1.2  tsutsui 	(bus_space_tag_t,						\
    514   1.2  tsutsui 	 bus_space_handle_t bsh1, bus_size_t off1,			\
    515   1.2  tsutsui 	 bus_space_handle_t bsh2, bus_size_t off2,			\
    516   1.2  tsutsui 	 bus_size_t count);						\
    517   1.1  tsutsui 									\
    518   1.7    perry static __inline void							\
    519   1.3  tsutsui __CONCAT(bus_space_copy_region_,BYTES)(bus_space_tag_t t,		\
    520   1.3  tsutsui     bus_space_handle_t h1, bus_space_handle_t h2,			\
    521   1.3  tsutsui     bus_size_t o1, bus_size_t o2, bus_size_t c)				\
    522   1.1  tsutsui {									\
    523   1.1  tsutsui 	bus_size_t o;							\
    524   1.1  tsutsui 									\
    525   1.1  tsutsui 	if ((h1 + o1) >= (h2 + o2)) {					\
    526   1.1  tsutsui 		/* src after dest: copy forward */			\
    527   1.1  tsutsui 		for (o = 0; c != 0; c--, o += BYTES)			\
    528   1.1  tsutsui 			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
    529   1.1  tsutsui 			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
    530   1.1  tsutsui 	} else {							\
    531   1.1  tsutsui 		/* dest after src: copy backwards */			\
    532   1.1  tsutsui 		for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)	\
    533   1.1  tsutsui 			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
    534   1.1  tsutsui 			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
    535   1.1  tsutsui 	}								\
    536   1.1  tsutsui }
    537   1.1  tsutsui __NEWS68K_copy_region_N(1)
    538   1.1  tsutsui __NEWS68K_copy_region_N(2)
    539   1.1  tsutsui __NEWS68K_copy_region_N(4)
    540   1.1  tsutsui 
    541   1.1  tsutsui #undef __NEWS68K_copy_region_N
    542   1.1  tsutsui 
    543   1.1  tsutsui /*
    544   1.1  tsutsui  * Bus read/write barrier methods.
    545   1.1  tsutsui  *
    546   1.2  tsutsui  *	void bus_space_barrier(bus_space_tag_t tag,
    547   1.1  tsutsui  *	    bus_space_handle_t bsh, bus_size_t offset,
    548   1.2  tsutsui  *	    bus_size_t len, int flags);
    549   1.1  tsutsui  *
    550   1.1  tsutsui  * Note: the 680x0 does not currently require barriers, but we must
    551   1.1  tsutsui  * provide the flags to MI code.
    552   1.1  tsutsui  */
    553   1.1  tsutsui #define	bus_space_barrier(t, h, o, l, f)	\
    554   1.1  tsutsui 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
    555   1.1  tsutsui #define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
    556   1.1  tsutsui #define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
    557   1.1  tsutsui 
    558   1.1  tsutsui #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
    559   1.1  tsutsui 
    560   1.9  tsutsui /*
    561   1.9  tsutsui  * There is no bus_dma(9)'fied bus drivers on this port.
    562   1.9  tsutsui  */
    563   1.9  tsutsui #define __HAVE_NO_BUS_DMA
    564   1.9  tsutsui 
    565   1.1  tsutsui #endif /* _NEWS68K_BUS_H_ */
    566