Home | History | Annotate | Line # | Download | only in include
bus.h revision 1.3
      1  1.3  wdk /*	$NetBSD: bus.h,v 1.3 2000/09/04 22:18:58 wdk Exp $	*/
      2  1.1  wdk /*-
      3  1.1  wdk  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
      4  1.1  wdk  * All rights reserved.
      5  1.1  wdk  *
      6  1.1  wdk  * This code is derived from software contributed to The NetBSD Foundation
      7  1.1  wdk  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      8  1.1  wdk  * NASA Ames Research Center.
      9  1.1  wdk  *
     10  1.1  wdk  * Redistribution and use in source and binary forms, with or without
     11  1.1  wdk  * modification, are permitted provided that the following conditions
     12  1.1  wdk  * are met:
     13  1.1  wdk  * 1. Redistributions of source code must retain the above copyright
     14  1.1  wdk  *    notice, this list of conditions and the following disclaimer.
     15  1.1  wdk  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  wdk  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  wdk  *    documentation and/or other materials provided with the distribution.
     18  1.1  wdk  * 3. All advertising materials mentioning features or use of this software
     19  1.1  wdk  *    must display the following acknowledgement:
     20  1.1  wdk  *	This product includes software developed by the NetBSD
     21  1.1  wdk  *	Foundation, Inc. and its contributors.
     22  1.1  wdk  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  wdk  *    contributors may be used to endorse or promote products derived
     24  1.1  wdk  *    from this software without specific prior written permission.
     25  1.1  wdk  *
     26  1.1  wdk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  wdk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  wdk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  wdk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  wdk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  wdk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  wdk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  wdk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  wdk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  wdk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  wdk  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  wdk  */
     38  1.1  wdk 
     39  1.1  wdk /*
     40  1.1  wdk  * Copyright (c) 1997 Per Fogelstrom.  All rights reserved.
     41  1.1  wdk  * Copyright (c) 1996 Niklas Hallqvist.  All rights reserved.
     42  1.1  wdk  *
     43  1.1  wdk  * Redistribution and use in source and binary forms, with or without
     44  1.1  wdk  * modification, are permitted provided that the following conditions
     45  1.1  wdk  * are met:
     46  1.1  wdk  * 1. Redistributions of source code must retain the above copyright
     47  1.1  wdk  *    notice, this list of conditions and the following disclaimer.
     48  1.1  wdk  * 2. Redistributions in binary form must reproduce the above copyright
     49  1.1  wdk  *    notice, this list of conditions and the following disclaimer in the
     50  1.1  wdk  *    documentation and/or other materials provided with the distribution.
     51  1.1  wdk  * 3. All advertising materials mentioning features or use of this software
     52  1.1  wdk  *    must display the following acknowledgement:
     53  1.1  wdk  *      This product includes software developed by Christopher G. Demetriou
     54  1.1  wdk  *	for the NetBSD Project.
     55  1.1  wdk  * 4. The name of the author may not be used to endorse or promote products
     56  1.1  wdk  *    derived from this software without specific prior written permission
     57  1.1  wdk  *
     58  1.1  wdk  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     59  1.1  wdk  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60  1.1  wdk  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61  1.1  wdk  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     62  1.1  wdk  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     63  1.1  wdk  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     64  1.1  wdk  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     65  1.1  wdk  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     66  1.1  wdk  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     67  1.1  wdk  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68  1.1  wdk  */
     69  1.1  wdk 
     70  1.1  wdk #ifndef _MIPSCO_BUS_H_
     71  1.1  wdk #define _MIPSCO_BUS_H_
     72  1.1  wdk #ifdef _KERNEL
     73  1.1  wdk 
     74  1.1  wdk #include <mips/locore.h>
     75  1.1  wdk 
     76  1.1  wdk #ifdef BUS_SPACE_DEBUG
     77  1.1  wdk #include <sys/systm.h> /* for printf() prototype */
     78  1.1  wdk /*
     79  1.1  wdk  * Macros for checking the aligned-ness of pointers passed to bus
     80  1.1  wdk  * space ops.  Strict alignment is required by the MIPS architecture,
     81  1.1  wdk  * and a trap will occur if unaligned access is performed.  These
     82  1.1  wdk  * may aid in the debugging of a broken device driver by displaying
     83  1.1  wdk  * useful information about the problem.
     84  1.1  wdk  */
     85  1.1  wdk #define __BUS_SPACE_ALIGNED_ADDRESS(p, t)				\
     86  1.1  wdk 	((((u_long)(p)) & (sizeof(t)-1)) == 0)
     87  1.1  wdk 
     88  1.1  wdk #define __BUS_SPACE_ADDRESS_SANITY(p, t, d)				\
     89  1.1  wdk ({									\
     90  1.1  wdk 	if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) {			\
     91  1.1  wdk 		printf("%s 0x%lx not aligned to %d bytes %s:%d\n",	\
     92  1.1  wdk 		    d, (u_long)(p), sizeof(t), __FILE__, __LINE__);	\
     93  1.1  wdk 	}								\
     94  1.1  wdk 	(void) 0;							\
     95  1.1  wdk })
     96  1.1  wdk 
     97  1.1  wdk #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
     98  1.1  wdk #else
     99  1.1  wdk #define __BUS_SPACE_ADDRESS_SANITY(p,t,d)	(void) 0
    100  1.1  wdk #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
    101  1.1  wdk #endif /* BUS_SPACE_DEBUG */
    102  1.1  wdk 
    103  1.1  wdk /*
    104  1.1  wdk  * Utility macro; do not use outside this file.
    105  1.1  wdk  */
    106  1.1  wdk #ifdef __STDC__
    107  1.1  wdk #define __CONCAT3(a,b,c)	a##b##c
    108  1.1  wdk #else
    109  1.1  wdk #define __CONCAT3(a,b,c)	a/**/b/**/c
    110  1.1  wdk #endif
    111  1.1  wdk 
    112  1.1  wdk /*
    113  1.1  wdk  * Bus address and size types
    114  1.1  wdk  */
    115  1.1  wdk typedef u_long bus_addr_t;
    116  1.1  wdk typedef u_long bus_size_t;
    117  1.1  wdk 
    118  1.1  wdk /*
    119  1.1  wdk  * Access methods for bus resources and address space.
    120  1.1  wdk  */
    121  1.1  wdk typedef u_int32_t bus_space_handle_t;
    122  1.1  wdk typedef struct mipsco_bus_space *bus_space_tag_t;
    123  1.1  wdk 
    124  1.1  wdk struct mipsco_bus_space {
    125  1.1  wdk 	const char	*bs_name;
    126  1.1  wdk 	struct extent	*bs_extent;
    127  1.1  wdk 	bus_addr_t	bs_start;
    128  1.1  wdk 	bus_size_t	bs_size;
    129  1.1  wdk 
    130  1.1  wdk 	paddr_t		bs_pbase;
    131  1.1  wdk 	vaddr_t		bs_vbase;
    132  1.1  wdk 
    133  1.1  wdk 	/* sparse addressing shift count */
    134  1.1  wdk 	u_int8_t	bs_stride_1;
    135  1.1  wdk 	u_int8_t	bs_stride_2;
    136  1.1  wdk 	u_int8_t	bs_stride_4;
    137  1.1  wdk 	u_int8_t	bs_stride_8;
    138  1.1  wdk 
    139  1.1  wdk 	/* compose a bus_space handle from tag/handle/addr/size/flags (MD) */
    140  1.1  wdk 	int	(*bs_compose_handle) __P((bus_space_tag_t, bus_addr_t,
    141  1.1  wdk 				bus_size_t, int, bus_space_handle_t *));
    142  1.1  wdk 
    143  1.1  wdk 	/* dispose a bus_space handle (MD) */
    144  1.1  wdk 	int	(*bs_dispose_handle) __P((bus_space_tag_t, bus_space_handle_t,
    145  1.1  wdk 				bus_size_t));
    146  1.1  wdk 
    147  1.1  wdk 	/* convert bus_space tag/handle to physical address (MD) */
    148  1.1  wdk 	int	(*bs_paddr) __P((bus_space_tag_t, bus_space_handle_t,
    149  1.1  wdk 				paddr_t *));
    150  1.1  wdk 
    151  1.1  wdk 	/* mapping/unmapping */
    152  1.1  wdk 	int	(*bs_map) __P((bus_space_tag_t, bus_addr_t, bus_size_t, int,
    153  1.1  wdk 				bus_space_handle_t *));
    154  1.1  wdk 	void	(*bs_unmap) __P((bus_space_tag_t, bus_space_handle_t,
    155  1.1  wdk 				bus_size_t));
    156  1.1  wdk 	int	(*bs_subregion) __P((bus_space_tag_t, bus_space_handle_t,
    157  1.1  wdk 				bus_size_t, bus_size_t,	bus_space_handle_t *));
    158  1.1  wdk 
    159  1.1  wdk 	/* allocation/deallocation */
    160  1.1  wdk 	int	(*bs_alloc) __P((bus_space_tag_t, bus_addr_t, bus_addr_t,
    161  1.1  wdk 				bus_size_t, bus_size_t,	bus_size_t, int,
    162  1.1  wdk 				bus_addr_t *, bus_space_handle_t *));
    163  1.1  wdk 	void	(*bs_free) __P((bus_space_tag_t, bus_space_handle_t,
    164  1.1  wdk 				bus_size_t));
    165  1.1  wdk 
    166  1.2  wdk 	/* interrupt attach */
    167  1.2  wdk 	void	(*bs_intr_establish) __P((
    168  1.2  wdk 				bus_space_tag_t,
    169  1.2  wdk 				int,			/*bus-specific intr*/
    170  1.2  wdk 				int,			/*priority/class*/
    171  1.2  wdk 				int,			/*flags*/
    172  1.2  wdk 				int (*) __P((void *)),	/*handler*/
    173  1.2  wdk 				void *));		/*handler arg*/
    174  1.2  wdk 
    175  1.1  wdk 	void	*bs_aux;
    176  1.1  wdk };
    177  1.1  wdk 
    178  1.1  wdk /* vaddr_t argument of mipsco_bus_space_init() */
    179  1.1  wdk #define MIPSCO_BUS_SPACE_UNMAPPED	((vaddr_t)0)
    180  1.1  wdk 
    181  1.1  wdk /* machine dependent utility function for bus_space users */
    182  1.1  wdk void	mipsco_bus_space_malloc_set_safe __P((void));
    183  1.1  wdk void	mipsco_bus_space_init __P((bus_space_tag_t, const char *,
    184  1.1  wdk 	    paddr_t, vaddr_t, bus_addr_t, bus_size_t));
    185  1.1  wdk void	mipsco_bus_space_init_extent __P((bus_space_tag_t, caddr_t, size_t));
    186  1.1  wdk void	mipsco_bus_space_set_aligned_stride __P((bus_space_tag_t, unsigned int));
    187  1.1  wdk void	mipsco_sparse_bus_space_init __P((bus_space_tag_t, const char *,
    188  1.1  wdk 	    paddr_t, bus_addr_t, bus_size_t));
    189  1.1  wdk void	mipsco_large_bus_space_init __P((bus_space_tag_t, const char *,
    190  1.1  wdk 	    paddr_t, bus_addr_t, bus_size_t));
    191  1.1  wdk 
    192  1.1  wdk /* machine dependent utility function for bus_space implementations */
    193  1.1  wdk int	mipsco_bus_space_extent_malloc_flag __P((void));
    194  1.1  wdk 
    195  1.1  wdk /* these are provided for subclasses which override base bus_space. */
    196  1.1  wdk 
    197  1.1  wdk int	mipsco_bus_space_compose_handle __P((bus_space_tag_t,
    198  1.1  wdk 	    bus_addr_t, bus_size_t, int, bus_space_handle_t *));
    199  1.1  wdk int	mipsco_bus_space_dispose_handle __P((bus_space_tag_t,
    200  1.1  wdk 	    bus_space_handle_t, bus_size_t));
    201  1.1  wdk int	mipsco_bus_space_paddr __P((bus_space_tag_t,
    202  1.1  wdk 	    bus_space_handle_t, paddr_t *));
    203  1.1  wdk 
    204  1.1  wdk int	mipsco_sparse_bus_space_compose_handle __P((bus_space_tag_t,
    205  1.1  wdk 	    bus_addr_t, bus_size_t, int, bus_space_handle_t *));
    206  1.1  wdk int	mipsco_sparse_bus_space_dispose_handle __P((bus_space_tag_t,
    207  1.1  wdk 	    bus_space_handle_t, bus_size_t));
    208  1.1  wdk int	mipsco_sparse_bus_space_paddr __P((bus_space_tag_t,
    209  1.1  wdk 	    bus_space_handle_t, paddr_t *));
    210  1.1  wdk 
    211  1.1  wdk int	mipsco_bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t, int,
    212  1.1  wdk 	    bus_space_handle_t *));
    213  1.1  wdk void	mipsco_bus_space_unmap __P((bus_space_tag_t, bus_space_handle_t,
    214  1.1  wdk 	    bus_size_t));
    215  1.1  wdk int	mipsco_bus_space_subregion __P((bus_space_tag_t, bus_space_handle_t,
    216  1.1  wdk 	    bus_size_t, bus_size_t, bus_space_handle_t *));
    217  1.1  wdk int	mipsco_bus_space_alloc __P((bus_space_tag_t, bus_addr_t, bus_addr_t,
    218  1.1  wdk 	    bus_size_t, bus_size_t, bus_size_t, int, bus_addr_t *,
    219  1.1  wdk 	    bus_space_handle_t *));
    220  1.1  wdk #define mipsco_bus_space_free	mipsco_bus_space_unmap
    221  1.1  wdk 
    222  1.1  wdk /*
    223  1.1  wdk  *	int bus_space_compose_handle __P((bus_space_tag_t t, bus_addr_t addr,
    224  1.1  wdk  *	    bus_size_t size, int flags, bus_space_handle_t *bshp));
    225  1.1  wdk  *
    226  1.1  wdk  * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
    227  1.1  wdk  * Compose a bus_space handle from tag/handle/addr/size/flags.
    228  1.1  wdk  * A helper function for bus_space_map()/bus_space_alloc() implementation.
    229  1.1  wdk  */
    230  1.1  wdk #define bus_space_compose_handle(bst, addr, size, flags, bshp)		\
    231  1.1  wdk 	(*(bst)->bs_compose_handle)(bst, addr, size, flags, bshp)
    232  1.1  wdk 
    233  1.1  wdk /*
    234  1.1  wdk  *	int bus_space_dispose_handle __P((bus_space_tag_t t, bus_addr_t addr,
    235  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t size));
    236  1.1  wdk  *
    237  1.1  wdk  * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
    238  1.1  wdk  * Dispose a bus_space handle.
    239  1.1  wdk  * A helper function for bus_space_unmap()/bus_space_free() implementation.
    240  1.1  wdk  */
    241  1.1  wdk #define bus_space_dispose_handle(bst, bsh, size)			\
    242  1.1  wdk 	(*(bst)->bs_dispose_handle)(bst, bsh, size)
    243  1.1  wdk 
    244  1.1  wdk /*
    245  1.1  wdk  *	int bus_space_paddr __P((bus_space_tag_t tag,
    246  1.1  wdk  *	    bus_space_handle_t bsh, paddr_t *pap));
    247  1.1  wdk  *
    248  1.1  wdk  * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
    249  1.1  wdk  * (cannot be implemented on e.g. I/O space on i386, non-linear space on alpha)
    250  1.1  wdk  * Return physical address of a region.
    251  1.1  wdk  * A helper function for device mmap entry.
    252  1.1  wdk  */
    253  1.1  wdk #define bus_space_paddr(bst, bsh, pap)					\
    254  1.1  wdk 	(*(bst)->bs_paddr)(bst, bsh, pap)
    255  1.1  wdk 
    256  1.1  wdk /*
    257  1.1  wdk  *	void *bus_space_vaddr __P((bus_space_tag_t, bus_space_handle_t));
    258  1.1  wdk  *
    259  1.1  wdk  * Get the kernel virtual address for the mapped bus space.
    260  1.1  wdk  * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
    261  1.1  wdk  *  (XXX not enforced)
    262  1.1  wdk  */
    263  1.1  wdk #define bus_space_vaddr(bst, bsh)					\
    264  1.1  wdk 	((void *)(bsh))
    265  1.1  wdk 
    266  1.1  wdk /*
    267  1.1  wdk  *	int bus_space_map __P((bus_space_tag_t t, bus_addr_t addr,
    268  1.1  wdk  *	    bus_size_t size, int flags, bus_space_handle_t *bshp));
    269  1.1  wdk  *
    270  1.1  wdk  * Map a region of bus space.
    271  1.1  wdk  */
    272  1.1  wdk 
    273  1.1  wdk #define BUS_SPACE_MAP_CACHEABLE		0x01
    274  1.1  wdk #define BUS_SPACE_MAP_LINEAR		0x02
    275  1.1  wdk #define BUS_SPACE_MAP_PREFETCHABLE	0x04
    276  1.1  wdk 
    277  1.1  wdk #define bus_space_map(t, a, s, f, hp)					\
    278  1.1  wdk 	(*(t)->bs_map)((t), (a), (s), (f), (hp))
    279  1.1  wdk 
    280  1.1  wdk /*
    281  1.1  wdk  *	void bus_space_unmap __P((bus_space_tag_t t,
    282  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t size));
    283  1.1  wdk  *
    284  1.1  wdk  * Unmap a region of bus space.
    285  1.1  wdk  */
    286  1.1  wdk 
    287  1.1  wdk #define bus_space_unmap(t, h, s)					\
    288  1.1  wdk 	(*(t)->bs_unmap)((t), (h), (s))
    289  1.1  wdk 
    290  1.1  wdk /*
    291  1.1  wdk  *	int bus_space_subregion __P((bus_space_tag_t t,
    292  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
    293  1.1  wdk  *	    bus_space_handle_t *nbshp));
    294  1.1  wdk  *
    295  1.1  wdk  * Get a new handle for a subregion of an already-mapped area of bus space.
    296  1.1  wdk  */
    297  1.1  wdk 
    298  1.1  wdk #define bus_space_subregion(t, h, o, s, hp)				\
    299  1.1  wdk 	(*(t)->bs_subregion)((t), (h), (o), (s), (hp))
    300  1.1  wdk 
    301  1.1  wdk /*
    302  1.1  wdk  *	int bus_space_alloc __P((bus_space_tag_t t, bus_addr_t, rstart,
    303  1.1  wdk  *	    bus_addr_t rend, bus_size_t size, bus_size_t align,
    304  1.1  wdk  *	    bus_size_t boundary, int flags, bus_addr_t *addrp,
    305  1.1  wdk  *	    bus_space_handle_t *bshp));
    306  1.1  wdk  *
    307  1.1  wdk  * Allocate a region of bus space.
    308  1.1  wdk  */
    309  1.1  wdk 
    310  1.1  wdk #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp)			\
    311  1.1  wdk 	(*(t)->bs_alloc)((t), (rs), (re), (s), (a), (b), (f), (ap), (hp))
    312  1.1  wdk 
    313  1.1  wdk /*
    314  1.1  wdk  *	int bus_space_free __P((bus_space_tag_t t,
    315  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t size));
    316  1.1  wdk  *
    317  1.1  wdk  * Free a region of bus space.
    318  1.1  wdk  */
    319  1.1  wdk 
    320  1.1  wdk #define bus_space_free(t, h, s)						\
    321  1.1  wdk 	(*(t)->bs_free)((t), (h), (s))
    322  1.2  wdk 
    323  1.2  wdk /*
    324  1.2  wdk  *	void bus_intr_establish __P((bus_space_tag_t bst,
    325  1.2  wdk  *	     int level, int pri, int flags, int (*func) __P((void *))
    326  1.2  wdk  *	     void *arg));
    327  1.2  wdk  *
    328  1.2  wdk  *  Attach interrupt handler and softc argument
    329  1.2  wdk  */
    330  1.2  wdk 
    331  1.2  wdk #define bus_intr_establish(t, i, c, f, ihf, iha)			\
    332  1.2  wdk 	(*(t)->bs_intr_establish)((t), (i), (c), (f), (ihf), (iha))
    333  1.1  wdk 
    334  1.1  wdk /*
    335  1.1  wdk  *	u_intN_t bus_space_read_N __P((bus_space_tag_t tag,
    336  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t offset));
    337  1.1  wdk  *
    338  1.1  wdk  * Read a 1, 2, 4, or 8 byte quantity from bus space
    339  1.1  wdk  * described by tag/handle/offset.
    340  1.1  wdk  */
    341  1.1  wdk 
    342  1.1  wdk #define bus_space_read(BYTES,BITS)					\
    343  1.1  wdk static __inline __CONCAT3(u_int,BITS,_t)				\
    344  1.1  wdk __CONCAT(bus_space_read_,BYTES)(bus_space_tag_t bst,			\
    345  1.1  wdk     bus_space_handle_t bsh, bus_size_t offset)				\
    346  1.1  wdk {									\
    347  1.1  wdk 	return (*(volatile __CONCAT3(u_int,BITS,_t) *)			\
    348  1.1  wdk 	    (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))));	\
    349  1.1  wdk }
    350  1.1  wdk 
    351  1.1  wdk bus_space_read(1,8)
    352  1.1  wdk bus_space_read(2,16)
    353  1.1  wdk bus_space_read(4,32)
    354  1.1  wdk bus_space_read(8,64)
    355  1.1  wdk 
    356  1.1  wdk /*
    357  1.1  wdk  *	void bus_space_read_multi_N __P((bus_space_tag_t tag,
    358  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    359  1.1  wdk  *	    u_intN_t *addr, size_t count));
    360  1.1  wdk  *
    361  1.1  wdk  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    362  1.1  wdk  * described by tag/handle/offset and copy into buffer provided.
    363  1.1  wdk  */
    364  1.1  wdk 
    365  1.1  wdk #define bus_space_read_multi(BYTES,BITS)				\
    366  1.1  wdk static __inline void							\
    367  1.1  wdk __CONCAT(bus_space_read_multi_,BYTES)(bus_space_tag_t bst,		\
    368  1.1  wdk     bus_space_handle_t bsh, bus_size_t offset,				\
    369  1.1  wdk     __CONCAT3(u_int,BITS,_t) *datap, bus_size_t count)			\
    370  1.1  wdk {									\
    371  1.1  wdk 	volatile __CONCAT3(u_int,BITS,_t) *p =				\
    372  1.1  wdk 	    (volatile __CONCAT3(u_int,BITS,_t) *)			\
    373  1.1  wdk 	    (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES)));	\
    374  1.1  wdk 									\
    375  1.1  wdk 	for (; count > 0; --count)					\
    376  1.1  wdk 		*datap++ = *p;						\
    377  1.1  wdk }
    378  1.1  wdk 
    379  1.1  wdk bus_space_read_multi(1,8)
    380  1.1  wdk bus_space_read_multi(2,16)
    381  1.1  wdk bus_space_read_multi(4,32)
    382  1.1  wdk bus_space_read_multi(8,64)
    383  1.1  wdk 
    384  1.1  wdk /*
    385  1.1  wdk  *	void bus_space_read_region_N __P((bus_space_tag_t tag,
    386  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    387  1.1  wdk  *	    u_intN_t *addr, size_t count));
    388  1.1  wdk  *
    389  1.1  wdk  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    390  1.1  wdk  * described by tag/handle and starting at `offset' and copy into
    391  1.1  wdk  * buffer provided.
    392  1.1  wdk  */
    393  1.1  wdk 
    394  1.1  wdk #define bus_space_read_region(BYTES,BITS)				\
    395  1.1  wdk static __inline void							\
    396  1.1  wdk __CONCAT(bus_space_read_region_,BYTES)(bus_space_tag_t bst,		\
    397  1.1  wdk     bus_space_handle_t bsh, bus_size_t offset,				\
    398  1.1  wdk     __CONCAT3(u_int,BITS,_t) *datap, bus_size_t count)			\
    399  1.1  wdk {									\
    400  1.1  wdk 	int stride = 1 << __CONCAT(bst->bs_stride_,BYTES);		\
    401  1.1  wdk 	volatile __CONCAT3(u_int,BITS,_t) *p =				\
    402  1.1  wdk 	    (volatile __CONCAT3(u_int,BITS,_t) *)			\
    403  1.1  wdk 	    (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES)));	\
    404  1.1  wdk 									\
    405  1.1  wdk 	for (; count > 0; --count) {					\
    406  1.1  wdk 		*datap++ = *p;						\
    407  1.1  wdk 		p += stride;						\
    408  1.1  wdk 	}								\
    409  1.1  wdk }
    410  1.1  wdk 
    411  1.1  wdk bus_space_read_region(1,8)
    412  1.1  wdk bus_space_read_region(2,16)
    413  1.1  wdk bus_space_read_region(4,32)
    414  1.1  wdk bus_space_read_region(8,64)
    415  1.1  wdk 
    416  1.1  wdk /*
    417  1.1  wdk  *	void bus_space_write_N __P((bus_space_tag_t tag,
    418  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    419  1.1  wdk  *	    u_intN_t value));
    420  1.1  wdk  *
    421  1.1  wdk  * Write the 1, 2, 4, or 8 byte value `value' to bus space
    422  1.1  wdk  * described by tag/handle/offset.
    423  1.1  wdk  */
    424  1.1  wdk 
    425  1.1  wdk #define bus_space_write(BYTES,BITS)					\
    426  1.1  wdk static __inline void							\
    427  1.1  wdk __CONCAT(bus_space_write_,BYTES)(bus_space_tag_t bst,			\
    428  1.1  wdk     bus_space_handle_t bsh,						\
    429  1.1  wdk     bus_size_t offset, __CONCAT3(u_int,BITS,_t) data)			\
    430  1.1  wdk {									\
    431  1.1  wdk 	*(volatile __CONCAT3(u_int,BITS,_t) *)				\
    432  1.1  wdk 	    (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))) = data; \
    433  1.1  wdk 	wbflush();							\
    434  1.1  wdk }
    435  1.1  wdk 
    436  1.1  wdk bus_space_write(1,8)
    437  1.1  wdk bus_space_write(2,16)
    438  1.1  wdk bus_space_write(4,32)
    439  1.1  wdk bus_space_write(8,64)
    440  1.1  wdk 
    441  1.1  wdk /*
    442  1.1  wdk  *	void bus_space_write_multi_N __P((bus_space_tag_t tag,
    443  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    444  1.1  wdk  *	    const u_intN_t *addr, size_t count));
    445  1.1  wdk  *
    446  1.1  wdk  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
    447  1.1  wdk  * provided to bus space described by tag/handle/offset.
    448  1.1  wdk  */
    449  1.1  wdk 
    450  1.1  wdk #define bus_space_write_multi(BYTES,BITS)				\
    451  1.1  wdk static __inline void							\
    452  1.1  wdk __CONCAT(bus_space_write_multi_,BYTES)(bus_space_tag_t bst,		\
    453  1.1  wdk     bus_space_handle_t bsh, bus_size_t offset,				\
    454  1.1  wdk     const __CONCAT3(u_int,BITS,_t) *datap, bus_size_t count)		\
    455  1.1  wdk {									\
    456  1.1  wdk 	volatile __CONCAT3(u_int,BITS,_t) *p =				\
    457  1.1  wdk 	    (volatile __CONCAT3(u_int,BITS,_t) *)			\
    458  1.1  wdk 	    (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES)));	\
    459  1.1  wdk 									\
    460  1.3  wdk 	while (count--) {						\
    461  1.1  wdk 		*p = *datap++;						\
    462  1.3  wdk 		wbflush();						\
    463  1.3  wdk 	}								\
    464  1.1  wdk }
    465  1.1  wdk 
    466  1.1  wdk bus_space_write_multi(1,8)
    467  1.1  wdk bus_space_write_multi(2,16)
    468  1.1  wdk bus_space_write_multi(4,32)
    469  1.1  wdk bus_space_write_multi(8,64)
    470  1.1  wdk 
    471  1.1  wdk /*
    472  1.1  wdk  *	void bus_space_write_region_N __P((bus_space_tag_t tag,
    473  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    474  1.1  wdk  *	    const u_intN_t *addr, size_t count));
    475  1.1  wdk  *
    476  1.1  wdk  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
    477  1.1  wdk  * to bus space described by tag/handle starting at `offset'.
    478  1.1  wdk  */
    479  1.1  wdk 
    480  1.1  wdk #define bus_space_write_region(BYTES,BITS)				\
    481  1.1  wdk static __inline void							\
    482  1.1  wdk __CONCAT(bus_space_write_region_,BYTES)(bus_space_tag_t bst,		\
    483  1.1  wdk     bus_space_handle_t bsh, bus_size_t offset,				\
    484  1.1  wdk     const __CONCAT3(u_int,BITS,_t) *datap, bus_size_t count)		\
    485  1.1  wdk {									\
    486  1.1  wdk 	int stride = 1 << __CONCAT(bst->bs_stride_,BYTES);		\
    487  1.1  wdk 	volatile __CONCAT3(u_int,BITS,_t) *p =				\
    488  1.1  wdk 	    (volatile __CONCAT3(u_int,BITS,_t) *)			\
    489  1.1  wdk 	    (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES)));	\
    490  1.1  wdk 									\
    491  1.3  wdk 	while (count--) {						\
    492  1.1  wdk 		*p = *datap++;						\
    493  1.1  wdk 		p += stride;						\
    494  1.1  wdk 	}								\
    495  1.3  wdk 	wbflush();							\
    496  1.1  wdk }
    497  1.1  wdk 
    498  1.1  wdk bus_space_write_region(1,8)
    499  1.1  wdk bus_space_write_region(2,16)
    500  1.1  wdk bus_space_write_region(4,32)
    501  1.1  wdk bus_space_write_region(8,64)
    502  1.1  wdk 
    503  1.1  wdk /*
    504  1.1  wdk  *	void bus_space_set_multi_N __P((bus_space_tag_t tag,
    505  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    506  1.1  wdk  *	    size_t count));
    507  1.1  wdk  *
    508  1.1  wdk  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
    509  1.1  wdk  * by tag/handle/offset `count' times.
    510  1.1  wdk  */
    511  1.1  wdk 
    512  1.1  wdk #define bus_space_set_multi(BYTES,BITS)					\
    513  1.1  wdk static __inline void							\
    514  1.1  wdk __CONCAT(bus_space_set_multi_,BYTES)(bus_space_tag_t bst,		\
    515  1.1  wdk     bus_space_handle_t bsh, bus_size_t offset,				\
    516  1.1  wdk     const __CONCAT3(u_int,BITS,_t) data, bus_size_t count)		\
    517  1.1  wdk {									\
    518  1.1  wdk 	volatile __CONCAT3(u_int,BITS,_t) *p =				\
    519  1.1  wdk 	    (volatile __CONCAT3(u_int,BITS,_t) *)			\
    520  1.1  wdk 	    (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES)));	\
    521  1.1  wdk 									\
    522  1.3  wdk 	while (count--)							\
    523  1.1  wdk 		*p = data;						\
    524  1.1  wdk }
    525  1.1  wdk 
    526  1.1  wdk bus_space_set_multi(1,8)
    527  1.1  wdk bus_space_set_multi(2,16)
    528  1.1  wdk bus_space_set_multi(4,32)
    529  1.1  wdk bus_space_set_multi(8,64)
    530  1.1  wdk 
    531  1.1  wdk /*
    532  1.1  wdk  *	void bus_space_set_region_N __P((bus_space_tag_t tag,
    533  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    534  1.1  wdk  *	    size_t count));
    535  1.1  wdk  *
    536  1.1  wdk  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
    537  1.1  wdk  * by tag/handle starting at `offset'.
    538  1.1  wdk  */
    539  1.1  wdk 
    540  1.1  wdk #define bus_space_set_region(BYTES,BITS)				\
    541  1.1  wdk static __inline void							\
    542  1.1  wdk __CONCAT(bus_space_set_region_,BYTES)(bus_space_tag_t bst,		\
    543  1.1  wdk     bus_space_handle_t bsh, bus_size_t offset,				\
    544  1.1  wdk     __CONCAT3(u_int,BITS,_t) data, bus_size_t count)			\
    545  1.1  wdk {									\
    546  1.1  wdk 	int stride = 1 << __CONCAT(bst->bs_stride_,BYTES);		\
    547  1.1  wdk 	volatile __CONCAT3(u_int,BITS,_t) *p =				\
    548  1.1  wdk 	    (volatile __CONCAT3(u_int,BITS,_t) *)			\
    549  1.1  wdk 	    (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES)));	\
    550  1.1  wdk 									\
    551  1.3  wdk 	while (count--) {						\
    552  1.1  wdk 		*p = data;						\
    553  1.1  wdk 		p += stride;						\
    554  1.1  wdk 	}								\
    555  1.3  wdk 	wbflush();							\
    556  1.1  wdk }
    557  1.1  wdk 
    558  1.1  wdk bus_space_set_region(1,8)
    559  1.1  wdk bus_space_set_region(2,16)
    560  1.1  wdk bus_space_set_region(4,32)
    561  1.1  wdk bus_space_set_region(8,64)
    562  1.1  wdk 
    563  1.1  wdk /*
    564  1.1  wdk  *	void bus_space_copy_region_N __P((bus_space_tag_t tag,
    565  1.1  wdk  *	    bus_space_handle_t bsh1, bus_size_t off1,
    566  1.1  wdk  *	    bus_space_handle_t bsh2, bus_size_t off2,
    567  1.1  wdk  *	    size_t count));
    568  1.1  wdk  *
    569  1.1  wdk  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
    570  1.1  wdk  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
    571  1.1  wdk  */
    572  1.1  wdk 
    573  1.1  wdk #define bus_space_copy_region(BYTES,BITS)				\
    574  1.1  wdk static __inline void							\
    575  1.1  wdk __CONCAT(bus_space_copy_region_,BYTES)(bus_space_tag_t bst,		\
    576  1.1  wdk     bus_space_handle_t srcbsh, bus_size_t srcoffset,			\
    577  1.1  wdk     bus_space_handle_t dstbsh, bus_size_t dstoffset, bus_size_t count)	\
    578  1.1  wdk {									\
    579  1.1  wdk 	int stride = 1 << __CONCAT(bst->bs_stride_,BYTES);		\
    580  1.1  wdk 	volatile __CONCAT3(u_int,BITS,_t) *srcp =			\
    581  1.1  wdk 	    (volatile __CONCAT3(u_int,BITS,_t) *)			\
    582  1.1  wdk 	    (srcbsh + (srcoffset << __CONCAT(bst->bs_stride_,BYTES)));	\
    583  1.1  wdk 	volatile __CONCAT3(u_int,BITS,_t) *dstp =			\
    584  1.1  wdk 	    (volatile __CONCAT3(u_int,BITS,_t) *)			\
    585  1.1  wdk 	    (dstbsh + (dstoffset << __CONCAT(bst->bs_stride_,BYTES)));	\
    586  1.1  wdk 	bus_size_t offset;						\
    587  1.1  wdk 									\
    588  1.1  wdk 	if (srcp >= dstp) {						\
    589  1.1  wdk 		/* src after dest: copy forward */			\
    590  1.1  wdk 		for (offset = 0; count > 0; --count, offset += stride)	\
    591  1.1  wdk 			dstp[offset] = srcp[offset];			\
    592  1.1  wdk 	} else {							\
    593  1.1  wdk 		/* dest after src: copy backward */			\
    594  1.1  wdk 		offset = (count << __CONCAT(bst->bs_stride_,BYTES))	\
    595  1.1  wdk 		    - stride;						\
    596  1.1  wdk 		for (; count > 0; --count, offset -= stride)		\
    597  1.1  wdk 			dstp[offset] = srcp[offset];			\
    598  1.1  wdk 	}								\
    599  1.3  wdk 	wbflush();							\
    600  1.1  wdk }
    601  1.1  wdk 
    602  1.1  wdk bus_space_copy_region(1,8)
    603  1.1  wdk bus_space_copy_region(2,16)
    604  1.1  wdk bus_space_copy_region(4,32)
    605  1.1  wdk bus_space_copy_region(8,64)
    606  1.1  wdk 
    607  1.1  wdk /*
    608  1.1  wdk  * Operations which handle byte stream data on word access.
    609  1.1  wdk  *
    610  1.1  wdk  * These functions are defined to resolve endian mismatch, by either
    611  1.1  wdk  * - When normal (i.e. stream-less) operations perform byte swap
    612  1.1  wdk  *   to resolve endian mismatch, these functions bypass the byte swap.
    613  1.1  wdk  * or
    614  1.1  wdk  * - When bus bridge performs automatic byte swap, these functions
    615  1.1  wdk  *   perform byte swap once more, to cancel the bridge's behavior.
    616  1.1  wdk  *
    617  1.1  wdk  * Currently these are just same as normal operations, since all
    618  1.1  wdk  * supported buses are same endian with CPU (i.e. little-endian).
    619  1.1  wdk  *
    620  1.1  wdk  */
    621  1.1  wdk #define __BUS_SPACE_HAS_STREAM_METHODS
    622  1.1  wdk #define bus_space_read_stream_2(tag, bsh, offset)			\
    623  1.1  wdk 	bus_space_read_2(tag, bsh, offset)
    624  1.1  wdk #define bus_space_read_stream_4(tag, bsh, offset)			\
    625  1.1  wdk 	bus_space_read_4(tag, bsh, offset)
    626  1.1  wdk #define bus_space_read_stream_8(tag, bsh, offset)			\
    627  1.1  wdk 	bus_space_read_8(tag, bsh, offset)
    628  1.1  wdk #define bus_space_read_multi_stream_2(tag, bsh, offset, datap, count)	\
    629  1.1  wdk 	bus_space_read_multi_2(tag, bsh, offset, datap, count)
    630  1.1  wdk #define bus_space_read_multi_stream_4(tag, bsh, offset, datap, count)	\
    631  1.1  wdk 	bus_space_read_multi_4(tag, bsh, offset, datap, count)
    632  1.1  wdk #define bus_space_read_multi_stream_8(tag, bsh, offset, datap, count)	\
    633  1.1  wdk 	bus_space_read_multi_8(tag, bsh, offset, datap, count)
    634  1.1  wdk #define bus_space_read_region_stream_2(tag, bsh, offset, datap, count)	\
    635  1.1  wdk 	bus_space_read_region_2(tag, bsh, offset, datap, count)
    636  1.1  wdk #define bus_space_read_region_stream_4(tag, bsh, offset, datap, count)	\
    637  1.1  wdk 	bus_space_read_region_4(tag, bsh, offset, datap, count)
    638  1.1  wdk #define bus_space_read_region_stream_8(tag, bsh, offset, datap, count)	\
    639  1.1  wdk 	bus_space_read_region_8(tag, bsh, offset, datap, count)
    640  1.1  wdk #define bus_space_write_stream_2(tag, bsh, offset, data)		\
    641  1.1  wdk 	bus_space_write_2(tag, bsh, offset, data)
    642  1.1  wdk #define bus_space_write_stream_4(tag, bsh, offset, data)		\
    643  1.1  wdk 	bus_space_write_4(tag, bsh, offset, data)
    644  1.1  wdk #define bus_space_write_stream_8(tag, bsh, offset, data)		\
    645  1.1  wdk 	bus_space_write_8(tag, bsh, offset, data)
    646  1.1  wdk #define bus_space_write_multi_stream_2(tag, bsh, offset, datap, count)	\
    647  1.1  wdk 	bus_space_write_multi_2(tag, bsh, offset, datap, count)
    648  1.1  wdk #define bus_space_write_multi_stream_4(tag, bsh, offset, datap, count)	\
    649  1.1  wdk 	bus_space_write_multi_4(tag, bsh, offset, datap, count)
    650  1.1  wdk #define bus_space_write_multi_stream_8(tag, bsh, offset, datap, count)	\
    651  1.1  wdk 	bus_space_write_multi_8(tag, bsh, offset, datap, count)
    652  1.1  wdk #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count)	\
    653  1.1  wdk 	bus_space_write_region_2(tag, bsh, offset, datap, count)
    654  1.1  wdk #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count)	\
    655  1.1  wdk 	bus_space_write_region_4(tag, bsh, offset, datap, count)
    656  1.1  wdk #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count)	\
    657  1.1  wdk 	bus_space_write_region_8(tag, bsh, offset, datap, count)
    658  1.1  wdk #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count)	\
    659  1.1  wdk 	bus_space_write_region_2(tag, bsh, offset, datap, count)
    660  1.1  wdk #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count)	\
    661  1.1  wdk 	bus_space_write_region_4(tag, bsh, offset, datap, count)
    662  1.1  wdk #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count)	\
    663  1.1  wdk 	bus_space_write_region_8(tag, bsh, offset, datap, count)
    664  1.1  wdk #define bus_space_set_multi_stream_2(tag, bsh, offset, data, count)	\
    665  1.1  wdk 	bus_space_set_multi_2(tag, bsh, offset, data, count)
    666  1.1  wdk #define bus_space_set_multi_stream_4(tag, bsh, offset, data, count)	\
    667  1.1  wdk 	bus_space_set_multi_4(tag, bsh, offset, data, count)
    668  1.1  wdk #define bus_space_set_multi_stream_8(tag, bsh, offset, data, count)	\
    669  1.1  wdk 	bus_space_set_multi_8(tag, bsh, offset, data, count)
    670  1.1  wdk #define bus_space_set_region_stream_2(tag, bsh, offset, data, count)	\
    671  1.1  wdk 	bus_space_set_region_2(tag, bsh, offset, data, count)
    672  1.1  wdk #define bus_space_set_region_stream_4(tag, bsh, offset, data, count)	\
    673  1.1  wdk 	bus_space_set_region_4(tag, bsh, offset, data, count)
    674  1.1  wdk #define bus_space_set_region_stream_8(tag, bsh, offset, data, count)	\
    675  1.1  wdk 	bus_space_set_region_8(tag, bsh, offset, data, count)
    676  1.1  wdk 
    677  1.1  wdk /*
    678  1.1  wdk  * Bus read/write barrier methods.
    679  1.1  wdk  *
    680  1.1  wdk  *	void bus_space_barrier __P((bus_space_tag_t tag,
    681  1.1  wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    682  1.1  wdk  *	    bus_size_t len, int flags));
    683  1.1  wdk  *
    684  1.1  wdk  * On the MIPS, we just flush the write buffer.
    685  1.1  wdk  */
    686  1.1  wdk #define bus_space_barrier(t, h, o, l, f)				\
    687  1.1  wdk 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)),	\
    688  1.1  wdk 	 wbflush())
    689  1.1  wdk 
    690  1.1  wdk #define BUS_SPACE_BARRIER_READ	0x01
    691  1.1  wdk #define BUS_SPACE_BARRIER_WRITE	0x02
    692  1.1  wdk 
    693  1.1  wdk /*
    694  1.1  wdk  * Flags used in various bus DMA methods.
    695  1.1  wdk  */
    696  1.1  wdk #define BUS_DMA_WAITOK		0x00	/* safe to sleep (pseudo-flag) */
    697  1.1  wdk #define BUS_DMA_NOWAIT		0x01	/* not safe to sleep */
    698  1.1  wdk #define BUS_DMA_ALLOCNOW	0x02	/* perform resource allocation now */
    699  1.1  wdk #define BUS_DMA_COHERENT	0x04	/* hint: map memory DMA coherent */
    700  1.1  wdk #define BUS_DMA_BUS1		0x10	/* placeholders for bus functions... */
    701  1.1  wdk #define BUS_DMA_BUS2		0x20
    702  1.1  wdk #define BUS_DMA_BUS3		0x40
    703  1.1  wdk #define BUS_DMA_BUS4		0x80
    704  1.1  wdk 
    705  1.1  wdk #define MIPSCO_DMAMAP_COHERENT	0x100	/* no cache flush necessary on sync */
    706  1.1  wdk 
    707  1.1  wdk /* Forwards needed by prototypes below. */
    708  1.1  wdk struct mbuf;
    709  1.1  wdk struct uio;
    710  1.1  wdk 
    711  1.1  wdk /*
    712  1.1  wdk  * Operations performed by bus_dmamap_sync().
    713  1.1  wdk  */
    714  1.1  wdk #define BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
    715  1.1  wdk #define BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
    716  1.1  wdk #define BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
    717  1.1  wdk #define BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
    718  1.1  wdk 
    719  1.1  wdk typedef struct mipsco_bus_dma_tag		*bus_dma_tag_t;
    720  1.1  wdk typedef struct mipsco_bus_dmamap		*bus_dmamap_t;
    721  1.1  wdk 
    722  1.1  wdk /*
    723  1.1  wdk  *	bus_dma_segment_t
    724  1.1  wdk  *
    725  1.1  wdk  *	Describes a single contiguous DMA transaction.  Values
    726  1.1  wdk  *	are suitable for programming into DMA registers.
    727  1.1  wdk  */
    728  1.1  wdk struct mipsco_bus_dma_segment {
    729  1.1  wdk 	/*
    730  1.1  wdk 	 * PUBLIC MEMBERS: these are used by device drivers.
    731  1.1  wdk 	 */
    732  1.1  wdk 	bus_addr_t	ds_addr;	/* DMA address */
    733  1.1  wdk 	bus_size_t	ds_len;		/* length of transfer */
    734  1.1  wdk 	/*
    735  1.1  wdk 	 * PRIVATE MEMBERS for the DMA back-end.: not for use by drivers.
    736  1.1  wdk 	 */
    737  1.1  wdk 	vaddr_t		_ds_paddr;	/* CPU physical address */
    738  1.1  wdk 	vaddr_t		_ds_vaddr;	/* virtual address, 0 if invalid */
    739  1.1  wdk };
    740  1.1  wdk typedef struct mipsco_bus_dma_segment	bus_dma_segment_t;
    741  1.1  wdk 
    742  1.1  wdk /*
    743  1.1  wdk  *	bus_dma_tag_t
    744  1.1  wdk  *
    745  1.1  wdk  *	A machine-dependent opaque type describing the implementation of
    746  1.1  wdk  *	DMA for a given bus.
    747  1.1  wdk  */
    748  1.1  wdk 
    749  1.1  wdk struct mipsco_bus_dma_tag {
    750  1.1  wdk 	bus_addr_t	dma_offset;
    751  1.1  wdk 
    752  1.1  wdk 	/*
    753  1.1  wdk 	 * DMA mapping methods.
    754  1.1  wdk 	 */
    755  1.1  wdk 	int	(*_dmamap_create) __P((bus_dma_tag_t, bus_size_t, int,
    756  1.1  wdk 		    bus_size_t, bus_size_t, int, bus_dmamap_t *));
    757  1.1  wdk 	void	(*_dmamap_destroy) __P((bus_dma_tag_t, bus_dmamap_t));
    758  1.1  wdk 	int	(*_dmamap_load) __P((bus_dma_tag_t, bus_dmamap_t, void *,
    759  1.1  wdk 		    bus_size_t, struct proc *, int));
    760  1.1  wdk 	int	(*_dmamap_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t,
    761  1.1  wdk 		    struct mbuf *, int));
    762  1.1  wdk 	int	(*_dmamap_load_uio) __P((bus_dma_tag_t, bus_dmamap_t,
    763  1.1  wdk 		    struct uio *, int));
    764  1.1  wdk 	int	(*_dmamap_load_raw) __P((bus_dma_tag_t, bus_dmamap_t,
    765  1.1  wdk 		    bus_dma_segment_t *, int, bus_size_t, int));
    766  1.1  wdk 	void	(*_dmamap_unload) __P((bus_dma_tag_t, bus_dmamap_t));
    767  1.1  wdk 	void	(*_dmamap_sync) __P((bus_dma_tag_t, bus_dmamap_t,
    768  1.1  wdk 		    bus_addr_t, bus_size_t, int));
    769  1.1  wdk 
    770  1.1  wdk 	/*
    771  1.1  wdk 	 * DMA memory utility functions.
    772  1.1  wdk 	 */
    773  1.1  wdk 	int	(*_dmamem_alloc) __P((bus_dma_tag_t, bus_size_t, bus_size_t,
    774  1.1  wdk 		    bus_size_t, bus_dma_segment_t *, int, int *, int));
    775  1.1  wdk 	void	(*_dmamem_free) __P((bus_dma_tag_t,
    776  1.1  wdk 		    bus_dma_segment_t *, int));
    777  1.1  wdk 	int	(*_dmamem_map) __P((bus_dma_tag_t, bus_dma_segment_t *,
    778  1.1  wdk 		    int, size_t, caddr_t *, int));
    779  1.1  wdk 	void	(*_dmamem_unmap) __P((bus_dma_tag_t, caddr_t, size_t));
    780  1.1  wdk 	paddr_t	(*_dmamem_mmap) __P((bus_dma_tag_t, bus_dma_segment_t *,
    781  1.1  wdk 		    int, off_t, int, int));
    782  1.1  wdk };
    783  1.1  wdk 
    784  1.1  wdk #define bus_dmamap_create(t, s, n, m, b, f, p)			\
    785  1.1  wdk 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
    786  1.1  wdk #define bus_dmamap_destroy(t, p)				\
    787  1.1  wdk 	(*(t)->_dmamap_destroy)((t), (p))
    788  1.1  wdk #define bus_dmamap_load(t, m, b, s, p, f)			\
    789  1.1  wdk 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
    790  1.1  wdk #define bus_dmamap_load_mbuf(t, m, b, f)			\
    791  1.1  wdk 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
    792  1.1  wdk #define bus_dmamap_load_uio(t, m, u, f)				\
    793  1.1  wdk 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
    794  1.1  wdk #define bus_dmamap_load_raw(t, m, sg, n, s, f)			\
    795  1.1  wdk 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
    796  1.1  wdk #define bus_dmamap_unload(t, p)					\
    797  1.1  wdk 	(*(t)->_dmamap_unload)((t), (p))
    798  1.1  wdk #define bus_dmamap_sync(t, p, o, l, ops)			\
    799  1.1  wdk 	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
    800  1.1  wdk #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
    801  1.1  wdk 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
    802  1.1  wdk #define bus_dmamem_free(t, sg, n)				\
    803  1.1  wdk 	(*(t)->_dmamem_free)((t), (sg), (n))
    804  1.1  wdk #define bus_dmamem_map(t, sg, n, s, k, f)			\
    805  1.1  wdk 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
    806  1.1  wdk #define bus_dmamem_unmap(t, k, s)				\
    807  1.1  wdk 	(*(t)->_dmamem_unmap)((t), (k), (s))
    808  1.1  wdk #define bus_dmamem_mmap(t, sg, n, o, p, f)			\
    809  1.1  wdk 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
    810  1.1  wdk 
    811  1.1  wdk /*
    812  1.1  wdk  *	bus_dmamap_t
    813  1.1  wdk  *
    814  1.1  wdk  *	Describes a DMA mapping.
    815  1.1  wdk  */
    816  1.1  wdk struct mipsco_bus_dmamap {
    817  1.1  wdk 	/*
    818  1.1  wdk 	 * PRIVATE MEMBERS: not for use by machine-independent code.
    819  1.1  wdk 	 */
    820  1.1  wdk 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
    821  1.1  wdk 	int		_dm_segcnt;	/* number of segs this map can map */
    822  1.1  wdk 	bus_size_t	_dm_maxsegsz;	/* largest possible segment */
    823  1.1  wdk 	bus_size_t	_dm_boundary;	/* don't cross this */
    824  1.1  wdk 	int		_dm_flags;	/* misc. flags */
    825  1.1  wdk 
    826  1.1  wdk 	/*
    827  1.1  wdk 	 * Private cookie to be used by the DMA back-end.
    828  1.1  wdk 	 */
    829  1.1  wdk 	void		*_dm_cookie;
    830  1.1  wdk 
    831  1.1  wdk 	/*
    832  1.1  wdk 	 * PUBLIC MEMBERS: these are used by machine-independent code.
    833  1.1  wdk 	 */
    834  1.1  wdk 	bus_size_t	dm_mapsize;	/* size of the mapping */
    835  1.1  wdk 	int		dm_nsegs;	/* # valid segments in mapping */
    836  1.1  wdk 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
    837  1.1  wdk };
    838  1.1  wdk 
    839  1.1  wdk #ifdef _MIPSCO_BUS_DMA_PRIVATE
    840  1.1  wdk int	_bus_dmamap_create __P((bus_dma_tag_t, bus_size_t, int, bus_size_t,
    841  1.1  wdk 	    bus_size_t, int, bus_dmamap_t *));
    842  1.1  wdk void	_bus_dmamap_destroy __P((bus_dma_tag_t, bus_dmamap_t));
    843  1.1  wdk int	_bus_dmamap_load __P((bus_dma_tag_t, bus_dmamap_t, void *,
    844  1.1  wdk 	    bus_size_t, struct proc *, int));
    845  1.1  wdk int	_bus_dmamap_load_mbuf __P((bus_dma_tag_t, bus_dmamap_t,
    846  1.1  wdk 	    struct mbuf *, int));
    847  1.1  wdk int	_bus_dmamap_load_uio __P((bus_dma_tag_t, bus_dmamap_t,
    848  1.1  wdk 	    struct uio *, int));
    849  1.1  wdk int	_bus_dmamap_load_raw __P((bus_dma_tag_t, bus_dmamap_t,
    850  1.1  wdk 	    bus_dma_segment_t *, int, bus_size_t, int));
    851  1.1  wdk void	_bus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
    852  1.1  wdk void	_mips1_bus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    853  1.1  wdk 	    bus_size_t, int));
    854  1.1  wdk void	_mips3_bus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    855  1.1  wdk 	    bus_size_t, int));
    856  1.1  wdk 
    857  1.1  wdk int	_bus_dmamem_alloc __P((bus_dma_tag_t tag, bus_size_t size,
    858  1.1  wdk 	    bus_size_t alignment, bus_size_t boundary,
    859  1.1  wdk 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags));
    860  1.1  wdk int	_bus_dmamem_alloc_range __P((bus_dma_tag_t tag, bus_size_t size,
    861  1.1  wdk 	    bus_size_t alignment, bus_size_t boundary,
    862  1.1  wdk 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
    863  1.1  wdk 	    paddr_t low, paddr_t high));
    864  1.1  wdk void	_bus_dmamem_free __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    865  1.1  wdk 	    int nsegs));
    866  1.1  wdk int	_bus_dmamem_map __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    867  1.1  wdk 	    int nsegs, size_t size, caddr_t *kvap, int flags));
    868  1.1  wdk void	_bus_dmamem_unmap __P((bus_dma_tag_t tag, caddr_t kva,
    869  1.1  wdk 	    size_t size));
    870  1.1  wdk paddr_t	_bus_dmamem_mmap __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    871  1.1  wdk 	    int nsegs, off_t off, int prot, int flags));
    872  1.1  wdk 
    873  1.1  wdk int	_bus_dmamem_alloc_range __P((bus_dma_tag_t tag, bus_size_t size,
    874  1.1  wdk 	    bus_size_t alignment, bus_size_t boundary,
    875  1.1  wdk 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
    876  1.1  wdk 	    paddr_t low, paddr_t high));
    877  1.1  wdk #endif /* _MIPSCO_BUS_DMA_PRIVATE */
    878  1.1  wdk 
    879  1.1  wdk void	_bus_dma_tag_init __P((bus_dma_tag_t tag));
    880  1.1  wdk void	jazz_bus_dma_tag_init __P((bus_dma_tag_t tag));
    881  1.1  wdk void	isadma_bounce_tag_init __P((bus_dma_tag_t tag));
    882  1.1  wdk 
    883  1.1  wdk #endif /* _KERNEL */
    884  1.1  wdk #endif /* _MIPSCO_BUS_H_ */
    885