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