Home | History | Annotate | Line # | Download | only in include
bus.h revision 1.23.4.4
      1  1.23.4.4      yamt /*	$NetBSD: bus.h,v 1.23.4.4 2008/03/17 09:14:29 yamt Exp $	*/
      2       1.1      matt 
      3       1.1      matt /*-
      4      1.15   thorpej  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
      5       1.1      matt  * All rights reserved.
      6       1.1      matt  *
      7       1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      matt  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9       1.1      matt  * NASA Ames Research Center.
     10       1.1      matt  *
     11       1.1      matt  * Redistribution and use in source and binary forms, with or without
     12       1.1      matt  * modification, are permitted provided that the following conditions
     13       1.1      matt  * are met:
     14       1.1      matt  * 1. Redistributions of source code must retain the above copyright
     15       1.1      matt  *    notice, this list of conditions and the following disclaimer.
     16       1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     18       1.1      matt  *    documentation and/or other materials provided with the distribution.
     19       1.1      matt  * 3. All advertising materials mentioning features or use of this software
     20       1.1      matt  *    must display the following acknowledgement:
     21       1.1      matt  *	This product includes software developed by the NetBSD
     22       1.1      matt  *	Foundation, Inc. and its contributors.
     23       1.1      matt  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24       1.1      matt  *    contributors may be used to endorse or promote products derived
     25       1.1      matt  *    from this software without specific prior written permission.
     26       1.1      matt  *
     27       1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28       1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29       1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30       1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31       1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32       1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33       1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34       1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35       1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36       1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37       1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     38       1.1      matt  */
     39       1.1      matt 
     40       1.1      matt /*
     41       1.1      matt  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
     42       1.1      matt  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
     43       1.1      matt  *
     44       1.1      matt  * Redistribution and use in source and binary forms, with or without
     45       1.1      matt  * modification, are permitted provided that the following conditions
     46       1.1      matt  * are met:
     47       1.1      matt  * 1. Redistributions of source code must retain the above copyright
     48       1.1      matt  *    notice, this list of conditions and the following disclaimer.
     49       1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     50       1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     51       1.1      matt  *    documentation and/or other materials provided with the distribution.
     52       1.1      matt  * 3. All advertising materials mentioning features or use of this software
     53       1.1      matt  *    must display the following acknowledgement:
     54       1.1      matt  *      This product includes software developed by Christopher G. Demetriou
     55       1.1      matt  *	for the NetBSD Project.
     56       1.1      matt  * 4. The name of the author may not be used to endorse or promote products
     57       1.1      matt  *    derived from this software without specific prior written permission
     58       1.1      matt  *
     59       1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     60       1.1      matt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     61       1.1      matt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     62       1.1      matt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     63       1.1      matt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     64       1.1      matt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     65       1.1      matt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     66       1.1      matt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     67       1.1      matt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     68       1.1      matt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     69       1.1      matt  */
     70       1.1      matt 
     71       1.1      matt #ifndef _VAX_BUS_H_
     72       1.1      matt #define _VAX_BUS_H_
     73       1.1      matt 
     74       1.1      matt #ifdef BUS_SPACE_DEBUG
     75      1.11  drochner #include <sys/systm.h> /* for printf() prototype */
     76       1.1      matt /*
     77       1.1      matt  * Macros for sanity-checking the aligned-ness of pointers passed to
     78       1.1      matt  * bus space ops.  These are not strictly necessary on the VAX, but
     79       1.1      matt  * could lead to performance improvements, and help catch problems
     80       1.1      matt  * with drivers that would creep up on other architectures.
     81       1.1      matt  */
     82       1.1      matt #define	__BUS_SPACE_ALIGNED_ADDRESS(p, t)				\
     83       1.1      matt 	((((u_long)(p)) & (sizeof(t)-1)) == 0)
     84       1.1      matt 
     85       1.1      matt #define	__BUS_SPACE_ADDRESS_SANITY(p, t, d)				\
     86       1.1      matt ({									\
     87       1.1      matt 	if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) {			\
     88       1.1      matt 		printf("%s 0x%lx not aligned to %d bytes %s:%d\n",	\
     89       1.1      matt 		    d, (u_long)(p), sizeof(t), __FILE__, __LINE__);	\
     90       1.1      matt 	}								\
     91       1.1      matt 	(void) 0;							\
     92       1.1      matt })
     93       1.4  drochner 
     94       1.4  drochner #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
     95       1.1      matt #else
     96       1.1      matt #define	__BUS_SPACE_ADDRESS_SANITY(p,t,d)	(void) 0
     97       1.4  drochner #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
     98       1.1      matt #endif /* BUS_SPACE_DEBUG */
     99       1.1      matt 
    100       1.1      matt /*
    101       1.1      matt  * Bus address and size types
    102       1.1      matt  */
    103  1.23.4.4      yamt typedef paddr_t bus_addr_t;
    104  1.23.4.4      yamt typedef psize_t bus_size_t;
    105       1.1      matt 
    106       1.1      matt /*
    107       1.1      matt  * Access methods for bus resources and address space.
    108       1.1      matt  */
    109       1.6     ragge typedef	struct vax_bus_space *bus_space_tag_t;
    110  1.23.4.4      yamt typedef	vaddr_t bus_space_handle_t;
    111       1.1      matt 
    112       1.1      matt struct vax_bus_space {
    113       1.1      matt 	/* cookie */
    114       1.1      matt 	void		*vbs_cookie;
    115       1.1      matt 
    116       1.1      matt 	/* mapping/unmapping */
    117  1.23.4.4      yamt 	int		(*vbs_map)(void *, bus_addr_t, bus_size_t, int,
    118  1.23.4.4      yamt 			    bus_space_handle_t *, int);
    119  1.23.4.4      yamt 	void		(*vbs_unmap)(void *, bus_space_handle_t, bus_size_t,
    120  1.23.4.4      yamt 			    int);
    121  1.23.4.4      yamt 	int		(*vbs_subregion)(void *, bus_space_handle_t, bus_size_t,
    122  1.23.4.4      yamt 			    bus_size_t, bus_space_handle_t *);
    123       1.1      matt 
    124       1.1      matt 	/* allocation/deallocation */
    125  1.23.4.4      yamt 	int		(*vbs_alloc)(void *, bus_addr_t, bus_addr_t, bus_size_t,
    126  1.23.4.4      yamt 			    bus_size_t, bus_size_t, int, bus_addr_t *,
    127  1.23.4.4      yamt 			    bus_space_handle_t *);
    128  1.23.4.4      yamt 	void		(*vbs_free)(void *, bus_space_handle_t, bus_size_t);
    129      1.18     ragge 	/* mmap bus space for user */
    130      1.18     ragge 	paddr_t		(*vbs_mmap)(void *, bus_addr_t, off_t, int, int);
    131       1.1      matt };
    132       1.1      matt 
    133       1.1      matt /*
    134  1.23.4.4      yamt  *	int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
    135  1.23.4.4      yamt  *	    bus_size_t size, int flags, bus_space_handle_t *bshp);
    136       1.1      matt  *
    137       1.1      matt  * Map a region of bus space.
    138       1.1      matt  */
    139       1.1      matt 
    140       1.1      matt #define	BUS_SPACE_MAP_CACHEABLE		0x01
    141       1.1      matt #define	BUS_SPACE_MAP_LINEAR		0x02
    142       1.9  drochner #define	BUS_SPACE_MAP_PREFETCHABLE	0x04
    143       1.1      matt 
    144       1.1      matt #define	bus_space_map(t, a, s, f, hp)					\
    145       1.1      matt 	(*(t)->vbs_map)((t)->vbs_cookie, (a), (s), (f), (hp), 1)
    146       1.1      matt #define	vax_bus_space_map_noacct(t, a, s, f, hp)			\
    147       1.1      matt 	(*(t)->vbs_map)((t)->vbs_cookie, (a), (s), (f), (hp), 0)
    148       1.1      matt 
    149       1.1      matt /*
    150  1.23.4.4      yamt  *	int bus_space_unmap(bus_space_tag_t t,
    151  1.23.4.4      yamt  *	    bus_space_handle_t bsh, bus_size_t size);
    152       1.1      matt  *
    153       1.1      matt  * Unmap a region of bus space.
    154       1.1      matt  */
    155       1.1      matt 
    156       1.1      matt #define bus_space_unmap(t, h, s)					\
    157       1.1      matt 	(*(t)->vbs_unmap)((t)->vbs_cookie, (h), (s), 1)
    158       1.1      matt #define vax_bus_space_unmap_noacct(t, h, s)				\
    159       1.1      matt 	(*(t)->vbs_unmap)((t)->vbs_cookie, (h), (s), 0)
    160       1.1      matt 
    161       1.1      matt /*
    162  1.23.4.4      yamt  *	int bus_space_subregion(bus_space_tag_t t,
    163       1.1      matt  *	    bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
    164  1.23.4.4      yamt  *	    bus_space_handle_t *nbshp);
    165       1.1      matt  *
    166       1.1      matt  * Get a new handle for a subregion of an already-mapped area of bus space.
    167       1.1      matt  */
    168       1.1      matt 
    169       1.1      matt #define bus_space_subregion(t, h, o, s, nhp)				\
    170      1.10      matt 	(*(t)->vbs_subregion)((t)->vbs_cookie, (h), (o), (s), (nhp))
    171       1.1      matt 
    172       1.1      matt /*
    173  1.23.4.4      yamt  *	int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
    174       1.1      matt  *	    bus_addr_t rend, bus_size_t size, bus_size_t align,
    175       1.1      matt  *	    bus_size_t boundary, int flags, bus_addr_t *addrp,
    176  1.23.4.4      yamt  *	    bus_space_handle_t *bshp);
    177       1.1      matt  *
    178       1.1      matt  * Allocate a region of bus space.
    179       1.1      matt  */
    180       1.1      matt 
    181       1.1      matt #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp)			\
    182       1.1      matt 	(*(t)->vbs_alloc)((t)->vbs_cookie, (rs), (re), (s), (a), (b),   \
    183       1.1      matt 	    (f), (ap), (hp))
    184       1.1      matt 
    185       1.1      matt /*
    186  1.23.4.4      yamt  *	int bus_space_free(bus_space_tag_t t,
    187  1.23.4.4      yamt  *	    bus_space_handle_t bsh, bus_size_t size);
    188       1.1      matt  *
    189       1.1      matt  * Free a region of bus space.
    190       1.1      matt  */
    191       1.1      matt 
    192       1.1      matt #define bus_space_free(t, h, s)						\
    193       1.1      matt 	(*(t)->vbs_free)((t)->vbs_cookie, (h), (s))
    194      1.18     ragge 
    195      1.18     ragge /*
    196      1.18     ragge  * Mmap bus space for a user application.
    197      1.18     ragge  */
    198      1.18     ragge #define bus_space_mmap(t, a, o, p, f)					\
    199      1.18     ragge 	(*(t)->vbs_mmap)((t)->vbs_cookie, (a), (o), (p), (f))
    200      1.18     ragge 
    201       1.1      matt 
    202       1.1      matt /*
    203  1.23.4.4      yamt  *	u_intN_t bus_space_read_N(bus_space_tag_t tag,
    204  1.23.4.4      yamt  *	    bus_space_handle_t bsh, bus_size_t offset);
    205       1.1      matt  *
    206       1.1      matt  * Read a 1, 2, 4, or 8 byte quantity from bus space
    207       1.1      matt  * described by tag/handle/offset.
    208       1.1      matt  */
    209       1.1      matt 
    210       1.1      matt #define	bus_space_read_1(t, h, o)					\
    211  1.23.4.3      yamt 	    (*(volatile uint8_t *)((h) + (o)))
    212       1.1      matt 
    213       1.1      matt #define	bus_space_read_2(t, h, o)					\
    214  1.23.4.3      yamt 	 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr"),	\
    215  1.23.4.3      yamt 	    (*(volatile uint16_t *)((h) + (o))))
    216       1.1      matt 
    217       1.1      matt #define	bus_space_read_4(t, h, o)					\
    218  1.23.4.3      yamt 	 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr"),	\
    219  1.23.4.3      yamt 	    (*(volatile uint32_t *)((h) + (o))))
    220       1.1      matt 
    221       1.1      matt #if 0	/* Cause a link error for bus_space_read_8 */
    222       1.1      matt #define	bus_space_read_8(t, h, o)	!!! bus_space_read_8 unimplemented !!!
    223       1.1      matt #endif
    224       1.1      matt 
    225       1.1      matt /*
    226  1.23.4.4      yamt  *	void bus_space_read_multi_N(bus_space_tag_t tag,
    227       1.1      matt  *	    bus_space_handle_t bsh, bus_size_t offset,
    228  1.23.4.4      yamt  *	    u_intN_t *addr, size_t count);
    229       1.1      matt  *
    230       1.1      matt  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    231       1.1      matt  * described by tag/handle/offset and copy into buffer provided.
    232       1.1      matt  */
    233  1.23.4.4      yamt static __inline void
    234  1.23.4.4      yamt 	vax_mem_read_multi_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    235  1.23.4.4      yamt 	    uint8_t *, size_t),
    236  1.23.4.4      yamt 	vax_mem_read_multi_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    237  1.23.4.4      yamt 	    uint16_t *, size_t),
    238  1.23.4.4      yamt 	vax_mem_read_multi_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    239  1.23.4.4      yamt 	    uint32_t *, size_t);
    240       1.1      matt 
    241       1.1      matt #define	bus_space_read_multi_1(t, h, o, a, c)				\
    242       1.1      matt 	vax_mem_read_multi_1((t), (h), (o), (a), (c))
    243       1.1      matt 
    244       1.1      matt #define bus_space_read_multi_2(t, h, o, a, c)				\
    245       1.1      matt do {									\
    246  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((a), uint16_t, "buffer");		\
    247  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    248       1.1      matt 	vax_mem_read_multi_2((t), (h), (o), (a), (c));		\
    249       1.1      matt } while (0)
    250       1.1      matt 
    251       1.1      matt #define bus_space_read_multi_4(t, h, o, a, c)				\
    252       1.1      matt do {									\
    253  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((a), uint32_t, "buffer");		\
    254  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    255       1.1      matt 	vax_mem_read_multi_4((t), (h), (o), (a), (c));		\
    256       1.1      matt } while (0)
    257       1.1      matt 
    258       1.1      matt #if 0	/* Cause a link error for bus_space_read_multi_8 */
    259       1.1      matt #define	bus_space_read_multi_8	!!! bus_space_read_multi_8 unimplemented !!!
    260       1.1      matt #endif
    261       1.1      matt 
    262       1.1      matt static __inline void
    263  1.23.4.4      yamt vax_mem_read_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    264  1.23.4.4      yamt 	uint8_t *a, size_t c)
    265       1.1      matt {
    266       1.1      matt 	const bus_addr_t addr = h + o;
    267       1.1      matt 
    268       1.1      matt 	for (; c != 0; c--, a++)
    269  1.23.4.3      yamt 		*a = *(volatile uint8_t *)(addr);
    270       1.1      matt }
    271       1.1      matt 
    272       1.1      matt static __inline void
    273  1.23.4.4      yamt vax_mem_read_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    274  1.23.4.4      yamt 	uint16_t *a, size_t c)
    275       1.1      matt {
    276       1.1      matt 	const bus_addr_t addr = h + o;
    277       1.1      matt 
    278       1.1      matt 	for (; c != 0; c--, a++)
    279  1.23.4.3      yamt 		*a = *(volatile uint16_t *)(addr);
    280       1.1      matt }
    281       1.1      matt 
    282       1.1      matt static __inline void
    283  1.23.4.4      yamt vax_mem_read_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    284  1.23.4.4      yamt 	uint32_t *a, size_t c)
    285       1.1      matt {
    286       1.1      matt 	const bus_addr_t addr = h + o;
    287       1.1      matt 
    288       1.1      matt 	for (; c != 0; c--, a++)
    289  1.23.4.3      yamt 		*a = *(volatile uint32_t *)(addr);
    290       1.1      matt }
    291       1.1      matt 
    292       1.1      matt /*
    293  1.23.4.4      yamt  *	void bus_space_read_region_N(bus_space_tag_t tag,
    294       1.1      matt  *	    bus_space_handle_t bsh, bus_size_t offset,
    295  1.23.4.4      yamt  *	    u_intN_t *addr, size_t count);
    296       1.1      matt  *
    297       1.1      matt  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    298       1.1      matt  * described by tag/handle and starting at `offset' and copy into
    299       1.1      matt  * buffer provided.
    300       1.1      matt  */
    301       1.1      matt 
    302  1.23.4.4      yamt static __inline void vax_mem_read_region_1(bus_space_tag_t,
    303  1.23.4.4      yamt 	bus_space_handle_t, bus_size_t, uint8_t *, size_t);
    304  1.23.4.4      yamt static __inline void vax_mem_read_region_2(bus_space_tag_t,
    305  1.23.4.4      yamt 	bus_space_handle_t, bus_size_t, uint16_t *, size_t);
    306  1.23.4.4      yamt static __inline void vax_mem_read_region_4(bus_space_tag_t,
    307  1.23.4.4      yamt 	bus_space_handle_t, bus_size_t, uint32_t *, size_t);
    308       1.1      matt 
    309       1.1      matt #define	bus_space_read_region_1(t, h, o, a, c)				\
    310       1.1      matt do {									\
    311       1.1      matt 	vax_mem_read_region_1((t), (h), (o), (a), (c));		\
    312       1.1      matt } while (0)
    313       1.1      matt 
    314       1.1      matt #define bus_space_read_region_2(t, h, o, a, c)				\
    315       1.1      matt do {									\
    316  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((a), uint16_t, "buffer");		\
    317  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    318       1.1      matt 	vax_mem_read_region_2((t), (h), (o), (a), (c));		\
    319       1.1      matt } while (0)
    320       1.1      matt 
    321       1.1      matt #define bus_space_read_region_4(t, h, o, a, c)				\
    322       1.1      matt do {									\
    323  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((a), uint32_t, "buffer");		\
    324  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    325       1.1      matt 	vax_mem_read_region_4((t), (h), (o), (a), (c));		\
    326       1.1      matt } while (0)
    327       1.1      matt 
    328       1.1      matt #if 0	/* Cause a link error for bus_space_read_region_8 */
    329       1.1      matt #define	bus_space_read_region_8					\
    330       1.1      matt 			!!! bus_space_read_region_8 unimplemented !!!
    331       1.1      matt #endif
    332       1.1      matt 
    333       1.1      matt static __inline void
    334  1.23.4.4      yamt vax_mem_read_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    335  1.23.4.4      yamt 	uint8_t *a, size_t c)
    336       1.1      matt {
    337       1.1      matt 	bus_addr_t addr = h + o;
    338       1.1      matt 
    339       1.1      matt 	for (; c != 0; c--, addr++, a++)
    340  1.23.4.3      yamt 		*a = *(volatile uint8_t *)(addr);
    341       1.1      matt }
    342       1.1      matt 
    343       1.1      matt static __inline void
    344  1.23.4.4      yamt vax_mem_read_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    345  1.23.4.4      yamt 	uint16_t *a, size_t c)
    346       1.1      matt {
    347       1.1      matt 	bus_addr_t addr = h + o;
    348       1.1      matt 
    349      1.19     ragge 	for (; c != 0; c--, addr += 2, a++)
    350  1.23.4.3      yamt 		*a = *(volatile uint16_t *)(addr);
    351       1.1      matt }
    352       1.1      matt 
    353       1.1      matt static __inline void
    354  1.23.4.4      yamt vax_mem_read_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    355  1.23.4.4      yamt 	uint32_t *a, size_t c)
    356       1.1      matt {
    357       1.1      matt 	bus_addr_t addr = h + o;
    358       1.1      matt 
    359      1.19     ragge 	for (; c != 0; c--, addr += 4, a++)
    360  1.23.4.3      yamt 		*a = *(volatile uint32_t *)(addr);
    361       1.1      matt }
    362       1.1      matt 
    363       1.1      matt /*
    364  1.23.4.4      yamt  *	void bus_space_write_N(bus_space_tag_t tag,
    365       1.1      matt  *	    bus_space_handle_t bsh, bus_size_t offset,
    366  1.23.4.4      yamt  *	    u_intN_t value);
    367       1.1      matt  *
    368       1.1      matt  * Write the 1, 2, 4, or 8 byte value `value' to bus space
    369       1.1      matt  * described by tag/handle/offset.
    370       1.1      matt  */
    371       1.1      matt 
    372       1.1      matt #define	bus_space_write_1(t, h, o, v)					\
    373       1.1      matt do {									\
    374  1.23.4.3      yamt 	((void)(*(volatile uint8_t *)((h) + (o)) = (v)));		\
    375       1.1      matt } while (0)
    376       1.1      matt 
    377       1.1      matt #define	bus_space_write_2(t, h, o, v)					\
    378       1.1      matt do {									\
    379  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    380  1.23.4.3      yamt 	((void)(*(volatile uint16_t *)((h) + (o)) = (v)));		\
    381       1.1      matt } while (0)
    382       1.1      matt 
    383       1.1      matt #define	bus_space_write_4(t, h, o, v)					\
    384       1.1      matt do {									\
    385  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    386  1.23.4.3      yamt 	((void)(*(volatile uint32_t *)((h) + (o)) = (v)));		\
    387       1.1      matt } while (0)
    388       1.1      matt 
    389       1.1      matt #if 0	/* Cause a link error for bus_space_write_8 */
    390       1.1      matt #define	bus_space_write_8	!!! bus_space_write_8 not implemented !!!
    391       1.1      matt #endif
    392       1.1      matt 
    393       1.1      matt /*
    394  1.23.4.4      yamt  *	void bus_space_write_multi_N(bus_space_tag_t tag,
    395       1.1      matt  *	    bus_space_handle_t bsh, bus_size_t offset,
    396  1.23.4.4      yamt  *	    const u_intN_t *addr, size_t count);
    397       1.1      matt  *
    398       1.1      matt  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
    399       1.1      matt  * provided to bus space described by tag/handle/offset.
    400       1.1      matt  */
    401  1.23.4.4      yamt static __inline void
    402  1.23.4.4      yamt 	vax_mem_write_multi_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    403  1.23.4.4      yamt 	    const uint8_t *, size_t),
    404  1.23.4.4      yamt 	vax_mem_write_multi_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    405  1.23.4.4      yamt 	    const uint16_t *, size_t),
    406  1.23.4.4      yamt 	vax_mem_write_multi_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    407  1.23.4.4      yamt 	    const uint32_t *, size_t);
    408       1.1      matt 
    409       1.1      matt #define	bus_space_write_multi_1(t, h, o, a, c)				\
    410       1.1      matt do {									\
    411       1.1      matt 	vax_mem_write_multi_1((t), (h), (o), (a), (c));		\
    412       1.1      matt } while (0)
    413       1.1      matt 
    414       1.1      matt #define bus_space_write_multi_2(t, h, o, a, c)				\
    415       1.1      matt do {									\
    416  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((a), uint16_t, "buffer");		\
    417  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    418       1.1      matt 	vax_mem_write_multi_2((t), (h), (o), (a), (c));		\
    419       1.1      matt } while (0)
    420       1.1      matt 
    421       1.1      matt #define bus_space_write_multi_4(t, h, o, a, c)				\
    422       1.1      matt do {									\
    423  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((a), uint32_t, "buffer");		\
    424  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    425       1.1      matt 	vax_mem_write_multi_4((t), (h), (o), (a), (c));		\
    426       1.1      matt } while (0)
    427       1.1      matt 
    428       1.1      matt #if 0	/* Cause a link error for bus_space_write_multi_8 */
    429       1.1      matt #define	bus_space_write_multi_8(t, h, o, a, c)				\
    430       1.1      matt 			!!! bus_space_write_multi_8 unimplemented !!!
    431       1.1      matt #endif
    432       1.1      matt 
    433       1.1      matt static __inline void
    434  1.23.4.4      yamt vax_mem_write_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    435  1.23.4.4      yamt 	const uint8_t *a, size_t c)
    436       1.1      matt {
    437       1.1      matt 	const bus_addr_t addr = h + o;
    438       1.1      matt 
    439       1.1      matt 	for (; c != 0; c--, a++)
    440  1.23.4.3      yamt 		*(volatile uint8_t *)(addr) = *a;
    441       1.1      matt }
    442       1.1      matt 
    443       1.1      matt static __inline void
    444  1.23.4.4      yamt vax_mem_write_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    445  1.23.4.4      yamt 	const uint16_t *a, size_t c)
    446       1.1      matt {
    447       1.1      matt 	const bus_addr_t addr = h + o;
    448       1.1      matt 
    449       1.3      matt 	for (; c != 0; c--, a++)
    450  1.23.4.3      yamt 		*(volatile uint16_t *)(addr) = *a;
    451       1.1      matt }
    452       1.1      matt 
    453       1.1      matt static __inline void
    454  1.23.4.4      yamt vax_mem_write_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    455  1.23.4.4      yamt 	const uint32_t *a, size_t c)
    456       1.1      matt {
    457       1.1      matt 	const bus_addr_t addr = h + o;
    458       1.1      matt 
    459       1.1      matt 	for (; c != 0; c--, a++)
    460  1.23.4.3      yamt 		*(volatile uint32_t *)(addr) = *a;
    461       1.1      matt }
    462       1.1      matt 
    463       1.1      matt /*
    464  1.23.4.4      yamt  *	void bus_space_write_region_N(bus_space_tag_t tag,
    465       1.1      matt  *	    bus_space_handle_t bsh, bus_size_t offset,
    466  1.23.4.4      yamt  *	    const u_intN_t *addr, size_t count);
    467       1.1      matt  *
    468       1.1      matt  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
    469       1.1      matt  * to bus space described by tag/handle starting at `offset'.
    470       1.1      matt  */
    471  1.23.4.4      yamt static __inline void
    472  1.23.4.4      yamt 	vax_mem_write_region_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    473  1.23.4.4      yamt 	    const uint8_t *, size_t),
    474  1.23.4.4      yamt 	vax_mem_write_region_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    475  1.23.4.4      yamt 	    const uint16_t *, size_t),
    476  1.23.4.4      yamt 	vax_mem_write_region_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    477  1.23.4.4      yamt 	    const uint32_t *, size_t);
    478       1.1      matt 
    479       1.1      matt #define	bus_space_write_region_1(t, h, o, a, c)				\
    480       1.1      matt 	vax_mem_write_region_1((t), (h), (o), (a), (c))
    481       1.1      matt 
    482       1.1      matt #define bus_space_write_region_2(t, h, o, a, c)				\
    483       1.1      matt do {									\
    484  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((a), uint16_t, "buffer");		\
    485  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    486       1.1      matt 	vax_mem_write_region_2((t), (h), (o), (a), (c));		\
    487       1.1      matt } while (0)
    488       1.1      matt 
    489       1.1      matt #define bus_space_write_region_4(t, h, o, a, c)				\
    490       1.1      matt do {									\
    491  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((a), uint32_t, "buffer");		\
    492  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    493       1.1      matt 	vax_mem_write_region_4((t), (h), (o), (a), (c));		\
    494       1.1      matt } while (0)
    495       1.1      matt 
    496       1.1      matt #if 0	/* Cause a link error for bus_space_write_region_8 */
    497       1.1      matt #define	bus_space_write_region_8					\
    498       1.1      matt 			!!! bus_space_write_region_8 unimplemented !!!
    499       1.1      matt #endif
    500       1.1      matt 
    501       1.1      matt static __inline void
    502  1.23.4.4      yamt vax_mem_write_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    503  1.23.4.4      yamt 	const uint8_t *a, size_t c)
    504       1.1      matt {
    505       1.1      matt 	bus_addr_t addr = h + o;
    506       1.1      matt 
    507       1.1      matt 	for (; c != 0; c--, addr++, a++)
    508  1.23.4.3      yamt 		*(volatile uint8_t *)(addr) = *a;
    509       1.1      matt }
    510       1.1      matt 
    511       1.1      matt static __inline void
    512  1.23.4.4      yamt vax_mem_write_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    513  1.23.4.4      yamt 	const uint16_t *a, size_t c)
    514       1.1      matt {
    515       1.1      matt 	bus_addr_t addr = h + o;
    516       1.1      matt 
    517       1.1      matt 	for (; c != 0; c--, addr++, a++)
    518  1.23.4.3      yamt 		*(volatile uint16_t *)(addr) = *a;
    519       1.1      matt }
    520       1.1      matt 
    521       1.1      matt static __inline void
    522  1.23.4.4      yamt vax_mem_write_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    523  1.23.4.4      yamt 	const uint32_t *a, size_t c)
    524       1.1      matt {
    525       1.1      matt 	bus_addr_t addr = h + o;
    526       1.1      matt 
    527       1.1      matt 	for (; c != 0; c--, addr++, a++)
    528  1.23.4.3      yamt 		*(volatile uint32_t *)(addr) = *a;
    529       1.1      matt }
    530       1.1      matt 
    531       1.1      matt /*
    532  1.23.4.4      yamt  *	void bus_space_set_multi_N(bus_space_tag_t tag,
    533       1.1      matt  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    534  1.23.4.4      yamt  *	    size_t count);
    535       1.1      matt  *
    536       1.1      matt  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
    537       1.1      matt  * by tag/handle/offset `count' times.
    538       1.1      matt  */
    539       1.1      matt 
    540  1.23.4.4      yamt static __inline void
    541  1.23.4.4      yamt 	vax_mem_set_multi_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    542  1.23.4.4      yamt 	    uint8_t, size_t),
    543  1.23.4.4      yamt 	vax_mem_set_multi_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    544  1.23.4.4      yamt 	    uint16_t, size_t),
    545  1.23.4.4      yamt 	vax_mem_set_multi_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    546  1.23.4.4      yamt 	    uint32_t, size_t);
    547       1.1      matt 
    548       1.1      matt #define	bus_space_set_multi_1(t, h, o, v, c)				\
    549       1.1      matt 	vax_mem_set_multi_1((t), (h), (o), (v), (c))
    550       1.1      matt 
    551       1.1      matt #define	bus_space_set_multi_2(t, h, o, v, c)				\
    552       1.1      matt do {									\
    553  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    554       1.1      matt 	vax_mem_set_multi_2((t), (h), (o), (v), (c));		\
    555       1.1      matt } while (0)
    556       1.1      matt 
    557       1.1      matt #define	bus_space_set_multi_4(t, h, o, v, c)				\
    558       1.1      matt do {									\
    559  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    560       1.1      matt 	vax_mem_set_multi_4((t), (h), (o), (v), (c));		\
    561       1.1      matt } while (0)
    562       1.1      matt 
    563       1.1      matt static __inline void
    564  1.23.4.4      yamt vax_mem_set_multi_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    565  1.23.4.4      yamt 	uint8_t v, size_t c)
    566       1.1      matt {
    567       1.1      matt 	bus_addr_t addr = h + o;
    568       1.1      matt 
    569       1.1      matt 	while (c--)
    570  1.23.4.3      yamt 		*(volatile uint8_t *)(addr) = v;
    571       1.1      matt }
    572       1.1      matt 
    573       1.1      matt static __inline void
    574  1.23.4.4      yamt vax_mem_set_multi_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    575  1.23.4.4      yamt 	uint16_t v, size_t c)
    576       1.1      matt {
    577       1.1      matt 	bus_addr_t addr = h + o;
    578       1.1      matt 
    579       1.1      matt 	while (c--)
    580  1.23.4.3      yamt 		*(volatile uint16_t *)(addr) = v;
    581       1.1      matt }
    582       1.1      matt 
    583       1.1      matt static __inline void
    584  1.23.4.4      yamt vax_mem_set_multi_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    585  1.23.4.4      yamt 	uint32_t v, size_t c)
    586       1.1      matt {
    587       1.1      matt 	bus_addr_t addr = h + o;
    588       1.1      matt 
    589       1.1      matt 	while (c--)
    590  1.23.4.3      yamt 		*(volatile uint32_t *)(addr) = v;
    591       1.1      matt }
    592       1.1      matt 
    593       1.1      matt #if 0	/* Cause a link error for bus_space_set_multi_8 */
    594       1.1      matt #define	bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!!
    595       1.1      matt #endif
    596       1.1      matt 
    597       1.1      matt /*
    598  1.23.4.4      yamt  *	void bus_space_set_region_N(bus_space_tag_t tag,
    599       1.1      matt  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    600  1.23.4.4      yamt  *	    size_t count);
    601       1.1      matt  *
    602       1.1      matt  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
    603       1.1      matt  * by tag/handle starting at `offset'.
    604       1.1      matt  */
    605       1.1      matt 
    606  1.23.4.4      yamt static __inline void
    607  1.23.4.4      yamt 	vax_mem_set_region_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    608  1.23.4.4      yamt 	    uint8_t, size_t),
    609  1.23.4.4      yamt 	vax_mem_set_region_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    610  1.23.4.4      yamt 	    uint16_t, size_t),
    611  1.23.4.4      yamt 	vax_mem_set_region_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    612  1.23.4.4      yamt 	    uint32_t, size_t);
    613       1.1      matt 
    614       1.1      matt #define	bus_space_set_region_1(t, h, o, v, c)				\
    615       1.1      matt 	vax_mem_set_region_1((t), (h), (o), (v), (c))
    616       1.1      matt 
    617       1.1      matt #define	bus_space_set_region_2(t, h, o, v, c)				\
    618       1.1      matt do {									\
    619  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr");	\
    620       1.1      matt 	vax_mem_set_region_2((t), (h), (o), (v), (c));		\
    621       1.1      matt } while (0)
    622       1.1      matt 
    623       1.1      matt #define	bus_space_set_region_4(t, h, o, v, c)				\
    624       1.1      matt do {									\
    625  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr");	\
    626       1.1      matt 	vax_mem_set_region_4((t), (h), (o), (v), (c));		\
    627       1.1      matt } while (0)
    628       1.1      matt 
    629       1.1      matt static __inline void
    630  1.23.4.4      yamt vax_mem_set_region_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    631  1.23.4.4      yamt 	uint8_t v, size_t c)
    632       1.1      matt {
    633       1.1      matt 	bus_addr_t addr = h + o;
    634       1.1      matt 
    635       1.1      matt 	for (; c != 0; c--, addr++)
    636  1.23.4.3      yamt 		*(volatile uint8_t *)(addr) = v;
    637       1.1      matt }
    638       1.1      matt 
    639       1.1      matt static __inline void
    640  1.23.4.4      yamt vax_mem_set_region_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    641  1.23.4.4      yamt 	uint16_t v, size_t c)
    642       1.1      matt {
    643       1.1      matt 	bus_addr_t addr = h + o;
    644       1.1      matt 
    645       1.1      matt 	for (; c != 0; c--, addr += 2)
    646  1.23.4.3      yamt 		*(volatile uint16_t *)(addr) = v;
    647       1.1      matt }
    648       1.1      matt 
    649       1.1      matt static __inline void
    650  1.23.4.4      yamt vax_mem_set_region_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o,
    651  1.23.4.4      yamt 	uint32_t v, size_t c)
    652       1.1      matt {
    653       1.1      matt 	bus_addr_t addr = h + o;
    654       1.1      matt 
    655       1.1      matt 	for (; c != 0; c--, addr += 4)
    656  1.23.4.3      yamt 		*(volatile uint32_t *)(addr) = v;
    657       1.1      matt }
    658       1.1      matt 
    659       1.1      matt #if 0	/* Cause a link error for bus_space_set_region_8 */
    660       1.1      matt #define	bus_space_set_region_8	!!! bus_space_set_region_8 unimplemented !!!
    661       1.1      matt #endif
    662       1.1      matt 
    663       1.1      matt /*
    664  1.23.4.4      yamt  *	void bus_space_copy_region_N(bus_space_tag_t tag,
    665       1.1      matt  *	    bus_space_handle_t bsh1, bus_size_t off1,
    666       1.1      matt  *	    bus_space_handle_t bsh2, bus_size_t off2,
    667  1.23.4.4      yamt  *	    size_t count);
    668       1.1      matt  *
    669       1.1      matt  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
    670       1.1      matt  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
    671       1.1      matt  */
    672       1.1      matt 
    673  1.23.4.4      yamt static __inline void
    674  1.23.4.4      yamt 	vax_mem_copy_region_1(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    675  1.23.4.4      yamt 	    bus_space_handle_t, bus_size_t, size_t),
    676  1.23.4.4      yamt 	vax_mem_copy_region_2(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    677  1.23.4.4      yamt 	    bus_space_handle_t, bus_size_t, size_t),
    678  1.23.4.4      yamt 	vax_mem_copy_region_4(bus_space_tag_t, bus_space_handle_t, bus_size_t,
    679  1.23.4.4      yamt 	    bus_space_handle_t, bus_size_t, size_t);
    680       1.1      matt 
    681       1.1      matt #define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)			\
    682       1.1      matt 	vax_mem_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
    683       1.1      matt 
    684       1.1      matt #define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)			\
    685       1.1      matt do {									\
    686  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h1) + (o1), uint16_t, "bus addr 1"); \
    687  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h2) + (o2), uint16_t, "bus addr 2"); \
    688       1.1      matt 	vax_mem_copy_region_2((t), (h1), (o1), (h2), (o2), (c));	\
    689       1.1      matt } while (0)
    690       1.1      matt 
    691       1.1      matt #define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)			\
    692       1.1      matt do {									\
    693  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h1) + (o1), uint32_t, "bus addr 1"); \
    694  1.23.4.3      yamt 	__BUS_SPACE_ADDRESS_SANITY((h2) + (o2), uint32_t, "bus addr 2"); \
    695       1.1      matt 	vax_mem_copy_region_4((t), (h1), (o1), (h2), (o2), (c));	\
    696       1.1      matt } while (0)
    697       1.1      matt 
    698       1.1      matt static __inline void
    699  1.23.4.4      yamt vax_mem_copy_region_1(bus_space_tag_t t, bus_space_handle_t h1, bus_size_t o1,
    700  1.23.4.4      yamt 	bus_space_handle_t h2, bus_size_t o2, size_t c)
    701       1.1      matt {
    702       1.1      matt 	bus_addr_t addr1 = h1 + o1;
    703       1.1      matt 	bus_addr_t addr2 = h2 + o2;
    704       1.1      matt 
    705       1.1      matt 	if (addr1 >= addr2) {
    706       1.1      matt 		/* src after dest: copy forward */
    707       1.1      matt 		for (; c != 0; c--, addr1++, addr2++)
    708  1.23.4.3      yamt 			*(volatile uint8_t *)(addr2) =
    709  1.23.4.3      yamt 			    *(volatile uint8_t *)(addr1);
    710       1.1      matt 	} else {
    711       1.1      matt 		/* dest after src: copy backwards */
    712       1.1      matt 		for (addr1 += (c - 1), addr2 += (c - 1);
    713       1.1      matt 		    c != 0; c--, addr1--, addr2--)
    714  1.23.4.3      yamt 			*(volatile uint8_t *)(addr2) =
    715  1.23.4.3      yamt 			    *(volatile uint8_t *)(addr1);
    716       1.1      matt 	}
    717       1.1      matt }
    718       1.1      matt 
    719       1.1      matt static __inline void
    720  1.23.4.4      yamt vax_mem_copy_region_2(bus_space_tag_t t, bus_space_handle_t h1, bus_size_t o1,
    721  1.23.4.4      yamt 	bus_space_handle_t h2, bus_size_t o2, size_t c)
    722       1.1      matt {
    723       1.1      matt 	bus_addr_t addr1 = h1 + o1;
    724       1.1      matt 	bus_addr_t addr2 = h2 + o2;
    725       1.1      matt 
    726       1.1      matt 	if (addr1 >= addr2) {
    727       1.1      matt 		/* src after dest: copy forward */
    728       1.1      matt 		for (; c != 0; c--, addr1 += 2, addr2 += 2)
    729  1.23.4.3      yamt 			*(volatile uint16_t *)(addr2) =
    730  1.23.4.3      yamt 			    *(volatile uint16_t *)(addr1);
    731       1.1      matt 	} else {
    732       1.1      matt 		/* dest after src: copy backwards */
    733       1.1      matt 		for (addr1 += 2 * (c - 1), addr2 += 2 * (c - 1);
    734       1.1      matt 		    c != 0; c--, addr1 -= 2, addr2 -= 2)
    735  1.23.4.3      yamt 			*(volatile uint16_t *)(addr2) =
    736  1.23.4.3      yamt 			    *(volatile uint16_t *)(addr1);
    737       1.1      matt 	}
    738       1.1      matt }
    739       1.1      matt 
    740       1.1      matt static __inline void
    741  1.23.4.4      yamt vax_mem_copy_region_4(bus_space_tag_t t, bus_space_handle_t h1, bus_size_t o1,
    742  1.23.4.4      yamt 	bus_space_handle_t h2, bus_size_t o2, size_t c)
    743       1.1      matt {
    744       1.1      matt 	bus_addr_t addr1 = h1 + o1;
    745       1.1      matt 	bus_addr_t addr2 = h2 + o2;
    746       1.1      matt 
    747       1.1      matt 	if (addr1 >= addr2) {
    748       1.1      matt 		/* src after dest: copy forward */
    749       1.1      matt 		for (; c != 0; c--, addr1 += 4, addr2 += 4)
    750  1.23.4.3      yamt 			*(volatile uint32_t *)(addr2) =
    751  1.23.4.3      yamt 			    *(volatile uint32_t *)(addr1);
    752       1.1      matt 	} else {
    753       1.1      matt 		/* dest after src: copy backwards */
    754       1.1      matt 		for (addr1 += 4 * (c - 1), addr2 += 4 * (c - 1);
    755       1.1      matt 		    c != 0; c--, addr1 -= 4, addr2 -= 4)
    756  1.23.4.3      yamt 			*(volatile uint32_t *)(addr2) =
    757  1.23.4.3      yamt 			    *(volatile uint32_t *)(addr1);
    758       1.1      matt 	}
    759       1.1      matt }
    760       1.1      matt 
    761       1.1      matt #if 0	/* Cause a link error for bus_space_copy_8 */
    762       1.1      matt #define	bus_space_copy_region_8	!!! bus_space_copy_region_8 unimplemented !!!
    763       1.1      matt #endif
    764       1.1      matt 
    765       1.1      matt 
    766       1.1      matt /*
    767       1.1      matt  * Bus read/write barrier methods.
    768       1.1      matt  *
    769  1.23.4.4      yamt  *	void bus_space_barrier(bus_space_tag_t tag,
    770       1.1      matt  *	    bus_space_handle_t bsh, bus_size_t offset,
    771  1.23.4.4      yamt  *	    bus_size_t len, int flags);
    772       1.1      matt  *
    773       1.1      matt  * Note: the vax does not currently require barriers, but we must
    774       1.1      matt  * provide the flags to MI code.
    775       1.1      matt  */
    776       1.1      matt #define	bus_space_barrier(t, h, o, l, f)	\
    777       1.1      matt 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
    778       1.1      matt #define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
    779       1.1      matt #define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
    780       1.1      matt 
    781       1.1      matt 
    782       1.1      matt /*
    783       1.1      matt  * Flags used in various bus DMA methods.
    784       1.1      matt  */
    785      1.17   thorpej #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
    786      1.17   thorpej #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
    787      1.17   thorpej #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
    788      1.17   thorpej #define	BUS_DMA_COHERENT	0x004	/* hint: map memory DMA coherent */
    789      1.17   thorpej #define	BUS_DMA_STREAMING	0x008	/* hint: sequential, unidirectional */
    790      1.17   thorpej #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
    791      1.17   thorpej #define	BUS_DMA_BUS2		0x020
    792      1.17   thorpej #define	BUS_DMA_BUS3		0x040
    793      1.17   thorpej #define	BUS_DMA_BUS4		0x080
    794      1.17   thorpej #define	BUS_DMA_READ		0x100	/* mapping is device -> memory only */
    795      1.17   thorpej #define	BUS_DMA_WRITE		0x200	/* mapping is memory -> device only */
    796      1.21      kent #define	BUS_DMA_NOCACHE		0x400	/* hint: map non-cached memory */
    797       1.7     ragge 
    798      1.12      matt #define	VAX_BUS_DMA_SPILLPAGE	BUS_DMA_BUS1	/* VS4000 kludge */
    799       1.7     ragge /*
    800       1.7     ragge  * Private flags stored in the DMA map.
    801       1.7     ragge  */
    802       1.7     ragge #define DMAMAP_HAS_SGMAP	0x80000000	/* sgva/len are valid */
    803       1.1      matt 
    804       1.1      matt /* Forwards needed by prototypes below. */
    805       1.1      matt struct mbuf;
    806       1.1      matt struct uio;
    807       1.1      matt struct vax_sgmap;
    808       1.1      matt 
    809       1.1      matt /*
    810       1.1      matt  * Operations performed by bus_dmamap_sync().
    811       1.1      matt  */
    812       1.1      matt #define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
    813       1.1      matt #define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
    814       1.1      matt #define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
    815       1.1      matt #define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
    816       1.1      matt 
    817       1.1      matt /*
    818       1.1      matt  *	vax_bus_t
    819       1.1      matt  *
    820       1.1      matt  *	Busses supported by NetBSD/vax, used by internal
    821       1.1      matt  *	utility functions.  NOT TO BE USED BY MACHINE-INDEPENDENT
    822       1.1      matt  *	CODE!
    823       1.1      matt  */
    824       1.1      matt typedef enum {
    825       1.1      matt 	VAX_BUS_MAINBUS,
    826       1.1      matt 	VAX_BUS_SBI,
    827       1.1      matt 	VAX_BUS_MASSBUS,
    828       1.1      matt 	VAX_BUS_UNIBUS,		/* Also handles QBUS */
    829       1.1      matt 	VAX_BUS_BI,
    830       1.1      matt 	VAX_BUS_XMI,
    831       1.1      matt 	VAX_BUS_TURBOCHANNEL
    832       1.1      matt } vax_bus_t;
    833       1.1      matt 
    834       1.1      matt typedef struct vax_bus_dma_tag	*bus_dma_tag_t;
    835       1.1      matt typedef struct vax_bus_dmamap	*bus_dmamap_t;
    836      1.22      fvdl 
    837      1.22      fvdl #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
    838       1.1      matt 
    839       1.1      matt /*
    840       1.1      matt  *	bus_dma_segment_t
    841       1.1      matt  *
    842       1.1      matt  *	Describes a single contiguous DMA transaction.  Values
    843       1.1      matt  *	are suitable for programming into DMA registers.
    844       1.1      matt  */
    845       1.1      matt struct vax_bus_dma_segment {
    846       1.1      matt 	bus_addr_t	ds_addr;	/* DMA address */
    847       1.1      matt 	bus_size_t	ds_len;		/* length of transfer */
    848       1.1      matt };
    849       1.1      matt typedef struct vax_bus_dma_segment	bus_dma_segment_t;
    850      1.13     ragge 
    851      1.13     ragge struct proc;
    852       1.1      matt 
    853       1.1      matt /*
    854       1.1      matt  *	bus_dma_tag_t
    855       1.1      matt  *
    856       1.1      matt  *	A machine-dependent opaque type describing the implementation of
    857       1.1      matt  *	DMA for a given bus.
    858       1.1      matt  */
    859       1.1      matt struct vax_bus_dma_tag {
    860       1.1      matt 	void	*_cookie;		/* cookie used in the guts */
    861       1.1      matt 	bus_addr_t _wbase;		/* DMA window base */
    862       1.1      matt 	bus_size_t _wsize;		/* DMA window size */
    863       1.1      matt 
    864       1.1      matt 	/*
    865       1.1      matt 	 * Some chipsets have a built-in boundary constraint, independent
    866       1.1      matt 	 * of what the device requests.  This allows that boundary to
    867      1.16       wiz 	 * be specified.  If the device has a more restrictive constraint,
    868       1.1      matt 	 * the map will use that, otherwise this boundary will be used.
    869       1.1      matt 	 * This value is ignored if 0.
    870       1.1      matt 	 */
    871       1.1      matt 	bus_size_t _boundary;
    872       1.1      matt 
    873       1.1      matt 	/*
    874       1.1      matt 	 * A bus may have more than one SGMAP window, so SGMAP
    875       1.1      matt 	 * windows also get a pointer to their SGMAP state.
    876       1.1      matt 	 */
    877       1.1      matt 	struct vax_sgmap *_sgmap;
    878       1.1      matt 
    879       1.1      matt 	/*
    880       1.1      matt 	 * Internal-use only utility methods.  NOT TO BE USED BY
    881       1.1      matt 	 * MACHINE-INDEPENDENT CODE!
    882       1.1      matt 	 */
    883  1.23.4.4      yamt 	bus_dma_tag_t (*_get_tag)(bus_dma_tag_t, vax_bus_t);
    884       1.1      matt 
    885       1.1      matt 	/*
    886       1.1      matt 	 * DMA mapping methods.
    887       1.1      matt 	 */
    888  1.23.4.4      yamt 	int	(*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
    889  1.23.4.4      yamt 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
    890  1.23.4.4      yamt 	void	(*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
    891  1.23.4.4      yamt 	int	(*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
    892  1.23.4.4      yamt 		    bus_size_t, struct proc *, int);
    893  1.23.4.4      yamt 	int	(*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
    894  1.23.4.4      yamt 		    struct mbuf *, int);
    895  1.23.4.4      yamt 	int	(*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
    896  1.23.4.4      yamt 		    struct uio *, int);
    897  1.23.4.4      yamt 	int	(*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
    898  1.23.4.4      yamt 		    bus_dma_segment_t *, int, bus_size_t, int);
    899  1.23.4.4      yamt 	void	(*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
    900  1.23.4.4      yamt 	void	(*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
    901  1.23.4.4      yamt 		    bus_addr_t, bus_size_t, int);
    902       1.1      matt 
    903       1.1      matt 	/*
    904       1.1      matt 	 * DMA memory utility functions.
    905       1.1      matt 	 */
    906  1.23.4.4      yamt 	int	(*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
    907  1.23.4.4      yamt 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
    908  1.23.4.4      yamt 	void	(*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int);
    909  1.23.4.4      yamt 	int	(*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
    910  1.23.4.4      yamt 		    int, size_t, void **, int);
    911  1.23.4.4      yamt 	void	(*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
    912  1.23.4.4      yamt 	paddr_t	(*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
    913  1.23.4.4      yamt 		    int, off_t, int, int);
    914       1.1      matt };
    915       1.1      matt 
    916       1.1      matt #define	vaxbus_dma_get_tag(t, b)				\
    917       1.1      matt 	(*(t)->_get_tag)(t, b)
    918       1.1      matt 
    919       1.1      matt #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
    920       1.1      matt 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
    921       1.1      matt #define	bus_dmamap_destroy(t, p)				\
    922       1.1      matt 	(*(t)->_dmamap_destroy)((t), (p))
    923       1.1      matt #define	bus_dmamap_load(t, m, b, s, p, f)			\
    924       1.1      matt 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
    925       1.1      matt #define	bus_dmamap_load_mbuf(t, m, b, f)			\
    926       1.1      matt 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
    927       1.1      matt #define	bus_dmamap_load_uio(t, m, u, f)				\
    928       1.1      matt 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
    929       1.1      matt #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
    930       1.1      matt 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
    931       1.1      matt #define	bus_dmamap_unload(t, p)					\
    932       1.1      matt 	(*(t)->_dmamap_unload)((t), (p))
    933       1.1      matt #define	bus_dmamap_sync(t, p, o, l, ops)			\
    934       1.1      matt 	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
    935       1.1      matt #define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
    936       1.1      matt 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
    937       1.1      matt #define	bus_dmamem_free(t, sg, n)				\
    938       1.1      matt 	(*(t)->_dmamem_free)((t), (sg), (n))
    939       1.1      matt #define	bus_dmamem_map(t, sg, n, s, k, f)			\
    940       1.1      matt 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
    941       1.1      matt #define	bus_dmamem_unmap(t, k, s)				\
    942       1.1      matt 	(*(t)->_dmamem_unmap)((t), (k), (s))
    943       1.1      matt #define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
    944       1.1      matt 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
    945       1.1      matt 
    946  1.23.4.1      yamt #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
    947  1.23.4.1      yamt #define bus_dmatag_destroy(t)
    948  1.23.4.1      yamt 
    949       1.1      matt /*
    950       1.1      matt  *	bus_dmamap_t
    951       1.1      matt  *
    952       1.1      matt  *	Describes a DMA mapping.
    953       1.1      matt  */
    954       1.1      matt struct vax_bus_dmamap {
    955       1.1      matt 	/*
    956       1.1      matt 	 * PRIVATE MEMBERS: not for use my machine-independent code.
    957       1.1      matt 	 */
    958       1.1      matt 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
    959       1.1      matt 	int		_dm_segcnt;	/* number of segs this map can map */
    960      1.23      matt 	bus_size_t	_dm_maxmaxsegsz; /* fixed largest possible segment */
    961       1.1      matt 	bus_size_t	_dm_boundary;	/* don't cross this */
    962       1.1      matt 	int		_dm_flags;	/* misc. flags */
    963       1.1      matt 
    964       1.1      matt 	/*
    965       1.1      matt 	 * This is used only for SGMAP-mapped DMA, but we keep it
    966       1.1      matt 	 * here to avoid pointless indirection.
    967       1.1      matt 	 */
    968       1.1      matt 	int		_dm_pteidx;	/* PTE index */
    969       1.1      matt 	int		_dm_ptecnt;	/* PTE count */
    970       1.1      matt 	u_long		_dm_sgva;	/* allocated sgva */
    971       1.1      matt 	bus_size_t	_dm_sgvalen;	/* svga length */
    972       1.1      matt 
    973       1.1      matt 	/*
    974       1.1      matt 	 * PUBLIC MEMBERS: these are used by machine-independent code.
    975       1.1      matt 	 */
    976      1.23      matt 	bus_size_t	dm_maxsegsz;	/* largest possible segment */
    977       1.1      matt 	bus_size_t	dm_mapsize;	/* size of the mapping */
    978       1.1      matt 	int		dm_nsegs;	/* # valid segments in mapping */
    979       1.1      matt 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
    980       1.1      matt };
    981       1.1      matt 
    982      1.20      matt /*#ifdef _VAX_BUS_DMA_PRIVATE */
    983  1.23.4.4      yamt int	_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
    984  1.23.4.4      yamt 	    bus_size_t, int, bus_dmamap_t *);
    985  1.23.4.4      yamt void	_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
    986  1.23.4.4      yamt 
    987  1.23.4.4      yamt int	_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t,
    988  1.23.4.4      yamt 	    void *, bus_size_t, struct proc *, int);
    989  1.23.4.4      yamt int	_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int);
    990  1.23.4.4      yamt int	_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int);
    991  1.23.4.4      yamt int	_bus_dmamap_load_raw(bus_dma_tag_t,
    992  1.23.4.4      yamt 	    bus_dmamap_t, bus_dma_segment_t *, int, bus_size_t, int);
    993  1.23.4.4      yamt 
    994  1.23.4.4      yamt void	_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
    995  1.23.4.4      yamt void	_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    996  1.23.4.4      yamt 	    bus_size_t, int);
    997       1.1      matt 
    998  1.23.4.4      yamt int	_bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
    999       1.1      matt 	    bus_size_t alignment, bus_size_t boundary,
   1000  1.23.4.4      yamt 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
   1001  1.23.4.4      yamt void	_bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs);
   1002  1.23.4.4      yamt int	_bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
   1003  1.23.4.4      yamt 	    int nsegs, size_t size, void **kvap, int flags);
   1004  1.23.4.4      yamt void	_bus_dmamem_unmap(bus_dma_tag_t tag, void *kva, size_t size);
   1005  1.23.4.4      yamt paddr_t	_bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
   1006  1.23.4.4      yamt 	    int nsegs, off_t off, int prot, int flags);
   1007      1.20      matt /*#endif*/ /* _VAX_BUS_DMA_PRIVATE */
   1008       1.1      matt 
   1009       1.1      matt #endif /* _VAX_BUS_H_ */
   1010