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