Home | History | Annotate | Line # | Download | only in include
bus.h revision 1.5
      1  1.5      wdk /*	$NetBSD: bus.h,v 1.5 2001/03/30 23:17:03 wdk 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.5      wdk 	u_int8_t	bs_stride;	/* log2(stride) */
    135  1.5      wdk 	u_int8_t	bs_bswap;	/* byte swap in stream methods */
    136  1.5      wdk 
    137  1.5      wdk 	u_int8_t	bs_offset_1;
    138  1.5      wdk 	u_int8_t	bs_offset_2;
    139  1.5      wdk 	u_int8_t	bs_offset_4;
    140  1.5      wdk 	u_int8_t	bs_offset_8;
    141  1.1      wdk 
    142  1.1      wdk 	/* compose a bus_space handle from tag/handle/addr/size/flags (MD) */
    143  1.1      wdk 	int	(*bs_compose_handle) __P((bus_space_tag_t, bus_addr_t,
    144  1.1      wdk 				bus_size_t, int, bus_space_handle_t *));
    145  1.1      wdk 
    146  1.1      wdk 	/* dispose a bus_space handle (MD) */
    147  1.1      wdk 	int	(*bs_dispose_handle) __P((bus_space_tag_t, bus_space_handle_t,
    148  1.1      wdk 				bus_size_t));
    149  1.1      wdk 
    150  1.1      wdk 	/* convert bus_space tag/handle to physical address (MD) */
    151  1.1      wdk 	int	(*bs_paddr) __P((bus_space_tag_t, bus_space_handle_t,
    152  1.1      wdk 				paddr_t *));
    153  1.1      wdk 
    154  1.1      wdk 	/* mapping/unmapping */
    155  1.1      wdk 	int	(*bs_map) __P((bus_space_tag_t, bus_addr_t, bus_size_t, int,
    156  1.1      wdk 				bus_space_handle_t *));
    157  1.1      wdk 	void	(*bs_unmap) __P((bus_space_tag_t, bus_space_handle_t,
    158  1.1      wdk 				bus_size_t));
    159  1.1      wdk 	int	(*bs_subregion) __P((bus_space_tag_t, bus_space_handle_t,
    160  1.1      wdk 				bus_size_t, bus_size_t,	bus_space_handle_t *));
    161  1.1      wdk 
    162  1.1      wdk 	/* allocation/deallocation */
    163  1.1      wdk 	int	(*bs_alloc) __P((bus_space_tag_t, bus_addr_t, bus_addr_t,
    164  1.1      wdk 				bus_size_t, bus_size_t,	bus_size_t, int,
    165  1.1      wdk 				bus_addr_t *, bus_space_handle_t *));
    166  1.1      wdk 	void	(*bs_free) __P((bus_space_tag_t, bus_space_handle_t,
    167  1.1      wdk 				bus_size_t));
    168  1.1      wdk 
    169  1.2      wdk 	/* interrupt attach */
    170  1.2      wdk 	void	(*bs_intr_establish) __P((
    171  1.2      wdk 				bus_space_tag_t,
    172  1.2      wdk 				int,			/*bus-specific intr*/
    173  1.2      wdk 				int,			/*priority/class*/
    174  1.2      wdk 				int,			/*flags*/
    175  1.2      wdk 				int (*) __P((void *)),	/*handler*/
    176  1.2      wdk 				void *));		/*handler arg*/
    177  1.2      wdk 
    178  1.1      wdk 	void	*bs_aux;
    179  1.1      wdk };
    180  1.1      wdk 
    181  1.1      wdk /* vaddr_t argument of mipsco_bus_space_init() */
    182  1.1      wdk #define MIPSCO_BUS_SPACE_UNMAPPED	((vaddr_t)0)
    183  1.1      wdk 
    184  1.1      wdk /* machine dependent utility function for bus_space users */
    185  1.1      wdk void	mipsco_bus_space_malloc_set_safe __P((void));
    186  1.1      wdk void	mipsco_bus_space_init __P((bus_space_tag_t, const char *,
    187  1.1      wdk 	    paddr_t, vaddr_t, bus_addr_t, bus_size_t));
    188  1.1      wdk void	mipsco_bus_space_init_extent __P((bus_space_tag_t, caddr_t, size_t));
    189  1.1      wdk void	mipsco_bus_space_set_aligned_stride __P((bus_space_tag_t, unsigned int));
    190  1.1      wdk void	mipsco_sparse_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 void	mipsco_large_bus_space_init __P((bus_space_tag_t, const char *,
    193  1.1      wdk 	    paddr_t, bus_addr_t, bus_size_t));
    194  1.1      wdk 
    195  1.1      wdk /* machine dependent utility function for bus_space implementations */
    196  1.1      wdk int	mipsco_bus_space_extent_malloc_flag __P((void));
    197  1.1      wdk 
    198  1.1      wdk /* these are provided for subclasses which override base bus_space. */
    199  1.1      wdk 
    200  1.1      wdk int	mipsco_bus_space_compose_handle __P((bus_space_tag_t,
    201  1.1      wdk 	    bus_addr_t, bus_size_t, int, bus_space_handle_t *));
    202  1.1      wdk int	mipsco_bus_space_dispose_handle __P((bus_space_tag_t,
    203  1.1      wdk 	    bus_space_handle_t, bus_size_t));
    204  1.1      wdk int	mipsco_bus_space_paddr __P((bus_space_tag_t,
    205  1.1      wdk 	    bus_space_handle_t, paddr_t *));
    206  1.1      wdk 
    207  1.1      wdk int	mipsco_sparse_bus_space_compose_handle __P((bus_space_tag_t,
    208  1.1      wdk 	    bus_addr_t, bus_size_t, int, bus_space_handle_t *));
    209  1.1      wdk int	mipsco_sparse_bus_space_dispose_handle __P((bus_space_tag_t,
    210  1.1      wdk 	    bus_space_handle_t, bus_size_t));
    211  1.1      wdk int	mipsco_sparse_bus_space_paddr __P((bus_space_tag_t,
    212  1.1      wdk 	    bus_space_handle_t, paddr_t *));
    213  1.1      wdk 
    214  1.1      wdk int	mipsco_bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t, int,
    215  1.1      wdk 	    bus_space_handle_t *));
    216  1.1      wdk void	mipsco_bus_space_unmap __P((bus_space_tag_t, bus_space_handle_t,
    217  1.1      wdk 	    bus_size_t));
    218  1.1      wdk int	mipsco_bus_space_subregion __P((bus_space_tag_t, bus_space_handle_t,
    219  1.1      wdk 	    bus_size_t, bus_size_t, bus_space_handle_t *));
    220  1.1      wdk int	mipsco_bus_space_alloc __P((bus_space_tag_t, bus_addr_t, bus_addr_t,
    221  1.1      wdk 	    bus_size_t, bus_size_t, bus_size_t, int, bus_addr_t *,
    222  1.1      wdk 	    bus_space_handle_t *));
    223  1.1      wdk #define mipsco_bus_space_free	mipsco_bus_space_unmap
    224  1.1      wdk 
    225  1.1      wdk /*
    226  1.1      wdk  *	int bus_space_compose_handle __P((bus_space_tag_t t, bus_addr_t addr,
    227  1.1      wdk  *	    bus_size_t size, int flags, bus_space_handle_t *bshp));
    228  1.1      wdk  *
    229  1.1      wdk  * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
    230  1.1      wdk  * Compose a bus_space handle from tag/handle/addr/size/flags.
    231  1.1      wdk  * A helper function for bus_space_map()/bus_space_alloc() implementation.
    232  1.1      wdk  */
    233  1.1      wdk #define bus_space_compose_handle(bst, addr, size, flags, bshp)		\
    234  1.1      wdk 	(*(bst)->bs_compose_handle)(bst, addr, size, flags, bshp)
    235  1.1      wdk 
    236  1.1      wdk /*
    237  1.1      wdk  *	int bus_space_dispose_handle __P((bus_space_tag_t t, bus_addr_t addr,
    238  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t size));
    239  1.1      wdk  *
    240  1.1      wdk  * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
    241  1.1      wdk  * Dispose a bus_space handle.
    242  1.1      wdk  * A helper function for bus_space_unmap()/bus_space_free() implementation.
    243  1.1      wdk  */
    244  1.1      wdk #define bus_space_dispose_handle(bst, bsh, size)			\
    245  1.1      wdk 	(*(bst)->bs_dispose_handle)(bst, bsh, size)
    246  1.1      wdk 
    247  1.1      wdk /*
    248  1.1      wdk  *	int bus_space_paddr __P((bus_space_tag_t tag,
    249  1.1      wdk  *	    bus_space_handle_t bsh, paddr_t *pap));
    250  1.1      wdk  *
    251  1.1      wdk  * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
    252  1.1      wdk  * (cannot be implemented on e.g. I/O space on i386, non-linear space on alpha)
    253  1.1      wdk  * Return physical address of a region.
    254  1.1      wdk  * A helper function for device mmap entry.
    255  1.1      wdk  */
    256  1.1      wdk #define bus_space_paddr(bst, bsh, pap)					\
    257  1.1      wdk 	(*(bst)->bs_paddr)(bst, bsh, pap)
    258  1.1      wdk 
    259  1.1      wdk /*
    260  1.1      wdk  *	void *bus_space_vaddr __P((bus_space_tag_t, bus_space_handle_t));
    261  1.1      wdk  *
    262  1.1      wdk  * Get the kernel virtual address for the mapped bus space.
    263  1.1      wdk  * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
    264  1.1      wdk  *  (XXX not enforced)
    265  1.1      wdk  */
    266  1.1      wdk #define bus_space_vaddr(bst, bsh)					\
    267  1.1      wdk 	((void *)(bsh))
    268  1.1      wdk 
    269  1.1      wdk /*
    270  1.1      wdk  *	int bus_space_map __P((bus_space_tag_t t, bus_addr_t addr,
    271  1.1      wdk  *	    bus_size_t size, int flags, bus_space_handle_t *bshp));
    272  1.1      wdk  *
    273  1.1      wdk  * Map a region of bus space.
    274  1.1      wdk  */
    275  1.1      wdk 
    276  1.1      wdk #define BUS_SPACE_MAP_CACHEABLE		0x01
    277  1.1      wdk #define BUS_SPACE_MAP_LINEAR		0x02
    278  1.1      wdk #define BUS_SPACE_MAP_PREFETCHABLE	0x04
    279  1.1      wdk 
    280  1.1      wdk #define bus_space_map(t, a, s, f, hp)					\
    281  1.1      wdk 	(*(t)->bs_map)((t), (a), (s), (f), (hp))
    282  1.1      wdk 
    283  1.1      wdk /*
    284  1.1      wdk  *	void bus_space_unmap __P((bus_space_tag_t t,
    285  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t size));
    286  1.1      wdk  *
    287  1.1      wdk  * Unmap a region of bus space.
    288  1.1      wdk  */
    289  1.1      wdk 
    290  1.1      wdk #define bus_space_unmap(t, h, s)					\
    291  1.1      wdk 	(*(t)->bs_unmap)((t), (h), (s))
    292  1.1      wdk 
    293  1.1      wdk /*
    294  1.1      wdk  *	int bus_space_subregion __P((bus_space_tag_t t,
    295  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
    296  1.1      wdk  *	    bus_space_handle_t *nbshp));
    297  1.1      wdk  *
    298  1.1      wdk  * Get a new handle for a subregion of an already-mapped area of bus space.
    299  1.1      wdk  */
    300  1.1      wdk 
    301  1.1      wdk #define bus_space_subregion(t, h, o, s, hp)				\
    302  1.1      wdk 	(*(t)->bs_subregion)((t), (h), (o), (s), (hp))
    303  1.1      wdk 
    304  1.1      wdk /*
    305  1.1      wdk  *	int bus_space_alloc __P((bus_space_tag_t t, bus_addr_t, rstart,
    306  1.1      wdk  *	    bus_addr_t rend, bus_size_t size, bus_size_t align,
    307  1.1      wdk  *	    bus_size_t boundary, int flags, bus_addr_t *addrp,
    308  1.1      wdk  *	    bus_space_handle_t *bshp));
    309  1.1      wdk  *
    310  1.1      wdk  * Allocate a region of bus space.
    311  1.1      wdk  */
    312  1.1      wdk 
    313  1.1      wdk #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp)			\
    314  1.1      wdk 	(*(t)->bs_alloc)((t), (rs), (re), (s), (a), (b), (f), (ap), (hp))
    315  1.1      wdk 
    316  1.1      wdk /*
    317  1.1      wdk  *	int bus_space_free __P((bus_space_tag_t t,
    318  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t size));
    319  1.1      wdk  *
    320  1.1      wdk  * Free a region of bus space.
    321  1.1      wdk  */
    322  1.1      wdk 
    323  1.1      wdk #define bus_space_free(t, h, s)						\
    324  1.1      wdk 	(*(t)->bs_free)((t), (h), (s))
    325  1.2      wdk 
    326  1.2      wdk /*
    327  1.2      wdk  *	void bus_intr_establish __P((bus_space_tag_t bst,
    328  1.2      wdk  *	     int level, int pri, int flags, int (*func) __P((void *))
    329  1.2      wdk  *	     void *arg));
    330  1.2      wdk  *
    331  1.2      wdk  *  Attach interrupt handler and softc argument
    332  1.2      wdk  */
    333  1.2      wdk 
    334  1.2      wdk #define bus_intr_establish(t, i, c, f, ihf, iha)			\
    335  1.2      wdk 	(*(t)->bs_intr_establish)((t), (i), (c), (f), (ihf), (iha))
    336  1.1      wdk 
    337  1.5      wdk 
    338  1.5      wdk /*
    339  1.5      wdk  * Utility macros; do not use outside this file.
    340  1.5      wdk  */
    341  1.5      wdk #define	__BS_TYPENAME(BITS)		__CONCAT3(u_int,BITS,_t)
    342  1.5      wdk #define __BS_OFFSET(t, o, BYTES)	((o) << (t)->bs_stride)
    343  1.5      wdk #define __BS_FUNCTION(func,BYTES)	__CONCAT3(func,_,BYTES)
    344  1.5      wdk 
    345  1.5      wdk /*
    346  1.5      wdk  * Calculate the target address using the bus_space parameters
    347  1.5      wdk  */
    348  1.5      wdk #define __BS_ADDR(t, h, offset, BITS, BYTES)				\
    349  1.5      wdk 	((volatile __CONCAT3(u_int,BITS,_t) *)				\
    350  1.5      wdk 	 ((h) + __BS_OFFSET(t, offset, BYTES) +				\
    351  1.5      wdk 	 (t)->__CONCAT(bs_offset_,BYTES)))
    352  1.5      wdk 
    353  1.1      wdk /*
    354  1.1      wdk  *	u_intN_t bus_space_read_N __P((bus_space_tag_t tag,
    355  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t offset));
    356  1.1      wdk  *
    357  1.1      wdk  * Read a 1, 2, 4, or 8 byte quantity from bus space
    358  1.1      wdk  * described by tag/handle/offset.
    359  1.1      wdk  */
    360  1.1      wdk 
    361  1.5      wdk #define __bus_space_read(BYTES,BITS)					\
    362  1.1      wdk static __inline __CONCAT3(u_int,BITS,_t)				\
    363  1.1      wdk __CONCAT(bus_space_read_,BYTES)(bus_space_tag_t bst,			\
    364  1.1      wdk     bus_space_handle_t bsh, bus_size_t offset)				\
    365  1.1      wdk {									\
    366  1.5      wdk 	return (*__BS_ADDR(bst, bsh, offset, BITS, BYTES));		\
    367  1.1      wdk }
    368  1.1      wdk 
    369  1.5      wdk __bus_space_read(1,8)
    370  1.5      wdk __bus_space_read(2,16)
    371  1.5      wdk __bus_space_read(4,32)
    372  1.5      wdk __bus_space_read(8,64)
    373  1.1      wdk 
    374  1.1      wdk /*
    375  1.1      wdk  *	void bus_space_read_multi_N __P((bus_space_tag_t tag,
    376  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    377  1.1      wdk  *	    u_intN_t *addr, size_t count));
    378  1.1      wdk  *
    379  1.1      wdk  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    380  1.1      wdk  * described by tag/handle/offset and copy into buffer provided.
    381  1.1      wdk  */
    382  1.1      wdk 
    383  1.5      wdk #define __bus_space_read_multi(BYTES,BITS)				\
    384  1.5      wdk static __inline void __BS_FUNCTION(bus_space_read_multi,BYTES)		\
    385  1.5      wdk 	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    386  1.5      wdk 	__BS_TYPENAME(BITS) *, size_t));				\
    387  1.5      wdk 									\
    388  1.1      wdk static __inline void							\
    389  1.5      wdk __BS_FUNCTION(bus_space_read_multi,BYTES)(t, h, o, a, c)		\
    390  1.5      wdk 	bus_space_tag_t t;						\
    391  1.5      wdk 	bus_space_handle_t h;						\
    392  1.5      wdk 	bus_size_t o;							\
    393  1.5      wdk 	__BS_TYPENAME(BITS) *a;						\
    394  1.5      wdk 	size_t c;							\
    395  1.5      wdk {									\
    396  1.5      wdk 									\
    397  1.5      wdk 	while (c--)							\
    398  1.5      wdk 		*a++ = __BS_FUNCTION(bus_space_read,BYTES)(t, h, o);	\
    399  1.5      wdk }
    400  1.5      wdk 
    401  1.5      wdk __bus_space_read_multi(1,8)
    402  1.5      wdk __bus_space_read_multi(2,16)
    403  1.5      wdk __bus_space_read_multi(4,32)
    404  1.5      wdk __bus_space_read_multi(8,64)
    405  1.5      wdk 
    406  1.1      wdk 
    407  1.1      wdk /*
    408  1.1      wdk  *	void bus_space_read_region_N __P((bus_space_tag_t tag,
    409  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    410  1.1      wdk  *	    u_intN_t *addr, size_t count));
    411  1.1      wdk  *
    412  1.1      wdk  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    413  1.1      wdk  * described by tag/handle and starting at `offset' and copy into
    414  1.1      wdk  * buffer provided.
    415  1.1      wdk  */
    416  1.1      wdk 
    417  1.5      wdk #define __bus_space_read_region(BYTES,BITS)				\
    418  1.5      wdk static __inline void __BS_FUNCTION(bus_space_read_region,BYTES)		\
    419  1.5      wdk 	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    420  1.5      wdk 	__BS_TYPENAME(BITS) *, size_t));				\
    421  1.5      wdk 									\
    422  1.1      wdk static __inline void							\
    423  1.5      wdk __BS_FUNCTION(bus_space_read_region,BYTES)(t, h, o, a, c)		\
    424  1.5      wdk 	bus_space_tag_t t;						\
    425  1.5      wdk 	bus_space_handle_t h;						\
    426  1.5      wdk 	bus_size_t o;							\
    427  1.5      wdk 	__BS_TYPENAME(BITS) *a;						\
    428  1.5      wdk 	size_t c;							\
    429  1.5      wdk {									\
    430  1.5      wdk 									\
    431  1.5      wdk 	while (c--) {							\
    432  1.5      wdk 		*a++ = __BS_FUNCTION(bus_space_read,BYTES)(t, h, o);	\
    433  1.5      wdk 		o += BYTES;						\
    434  1.1      wdk 	}								\
    435  1.1      wdk }
    436  1.1      wdk 
    437  1.5      wdk __bus_space_read_region(1,8)
    438  1.5      wdk __bus_space_read_region(2,16)
    439  1.5      wdk __bus_space_read_region(4,32)
    440  1.5      wdk __bus_space_read_region(8,64)
    441  1.5      wdk 
    442  1.1      wdk 
    443  1.1      wdk /*
    444  1.1      wdk  *	void bus_space_write_N __P((bus_space_tag_t tag,
    445  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    446  1.1      wdk  *	    u_intN_t value));
    447  1.1      wdk  *
    448  1.1      wdk  * Write the 1, 2, 4, or 8 byte value `value' to bus space
    449  1.1      wdk  * described by tag/handle/offset.
    450  1.1      wdk  */
    451  1.1      wdk 
    452  1.5      wdk #define __bus_space_write(BYTES,BITS)					\
    453  1.1      wdk static __inline void							\
    454  1.1      wdk __CONCAT(bus_space_write_,BYTES)(bus_space_tag_t bst,			\
    455  1.1      wdk     bus_space_handle_t bsh,						\
    456  1.1      wdk     bus_size_t offset, __CONCAT3(u_int,BITS,_t) data)			\
    457  1.1      wdk {									\
    458  1.5      wdk 	*__BS_ADDR(bst, bsh, offset, BITS, BYTES) = data;		\
    459  1.1      wdk 	wbflush();							\
    460  1.1      wdk }
    461  1.1      wdk 
    462  1.5      wdk __bus_space_write(1,8)
    463  1.5      wdk __bus_space_write(2,16)
    464  1.5      wdk __bus_space_write(4,32)
    465  1.5      wdk __bus_space_write(8,64)
    466  1.1      wdk 
    467  1.1      wdk /*
    468  1.1      wdk  *	void bus_space_write_multi_N __P((bus_space_tag_t tag,
    469  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    470  1.1      wdk  *	    const u_intN_t *addr, size_t count));
    471  1.1      wdk  *
    472  1.1      wdk  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
    473  1.1      wdk  * provided to bus space described by tag/handle/offset.
    474  1.1      wdk  */
    475  1.1      wdk 
    476  1.5      wdk #define __bus_space_write_multi(BYTES,BITS)				\
    477  1.5      wdk static __inline void __BS_FUNCTION(bus_space_write_multi,BYTES)       	\
    478  1.5      wdk 	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    479  1.5      wdk 	__BS_TYPENAME(BITS) *, size_t));				\
    480  1.5      wdk 									\
    481  1.1      wdk static __inline void							\
    482  1.5      wdk __BS_FUNCTION(bus_space_write_multi,BYTES)(t, h, o, a, c)     		\
    483  1.5      wdk 	bus_space_tag_t t;						\
    484  1.5      wdk 	bus_space_handle_t h;						\
    485  1.5      wdk 	bus_size_t o;							\
    486  1.5      wdk 	__BS_TYPENAME(BITS) *a;						\
    487  1.5      wdk 	size_t c;							\
    488  1.5      wdk {									\
    489  1.5      wdk 									\
    490  1.5      wdk 	while (c--)							\
    491  1.5      wdk 		__BS_FUNCTION(bus_space_write,BYTES)(t, h, o, *a++);	\
    492  1.1      wdk }
    493  1.1      wdk 
    494  1.5      wdk __bus_space_write_multi(1,8)
    495  1.5      wdk __bus_space_write_multi(2,16)
    496  1.5      wdk __bus_space_write_multi(4,32)
    497  1.5      wdk __bus_space_write_multi(8,64)
    498  1.5      wdk 
    499  1.1      wdk 
    500  1.1      wdk /*
    501  1.1      wdk  *	void bus_space_write_region_N __P((bus_space_tag_t tag,
    502  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    503  1.1      wdk  *	    const u_intN_t *addr, size_t count));
    504  1.1      wdk  *
    505  1.1      wdk  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
    506  1.1      wdk  * to bus space described by tag/handle starting at `offset'.
    507  1.1      wdk  */
    508  1.1      wdk 
    509  1.5      wdk #define __bus_space_write_region(BYTES,BITS)				\
    510  1.5      wdk static __inline void __BS_FUNCTION(bus_space_write_region,BYTES)      	\
    511  1.5      wdk 	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    512  1.5      wdk 	const __BS_TYPENAME(BITS) *, size_t));				\
    513  1.5      wdk 									\
    514  1.1      wdk static __inline void							\
    515  1.5      wdk __BS_FUNCTION(bus_space_write_region,BYTES)(t, h, o, a, c)    		\
    516  1.5      wdk 	bus_space_tag_t t;						\
    517  1.5      wdk 	bus_space_handle_t h;						\
    518  1.5      wdk 	bus_size_t o;							\
    519  1.5      wdk 	const __BS_TYPENAME(BITS) *a;					\
    520  1.5      wdk 	size_t c;							\
    521  1.5      wdk {									\
    522  1.5      wdk 									\
    523  1.5      wdk 	while (c--) {							\
    524  1.5      wdk 		__BS_FUNCTION(bus_space_write,BYTES)(t, h, o, *a++);	\
    525  1.5      wdk 		o += BYTES;						\
    526  1.1      wdk 	}								\
    527  1.1      wdk }
    528  1.1      wdk 
    529  1.5      wdk __bus_space_write_region(1,8)
    530  1.5      wdk __bus_space_write_region(2,16)
    531  1.5      wdk __bus_space_write_region(4,32)
    532  1.5      wdk __bus_space_write_region(8,64)
    533  1.5      wdk 
    534  1.1      wdk 
    535  1.1      wdk /*
    536  1.1      wdk  *	void bus_space_set_multi_N __P((bus_space_tag_t tag,
    537  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    538  1.1      wdk  *	    size_t count));
    539  1.1      wdk  *
    540  1.1      wdk  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
    541  1.1      wdk  * by tag/handle/offset `count' times.
    542  1.1      wdk  */
    543  1.1      wdk 
    544  1.5      wdk #define __bus_space_set_multi(BYTES,BITS)				\
    545  1.5      wdk static __inline void __BS_FUNCTION(bus_space_set_multi,BYTES)		\
    546  1.5      wdk 	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    547  1.5      wdk 	__BS_TYPENAME(BITS), size_t));					\
    548  1.5      wdk 									\
    549  1.1      wdk static __inline void							\
    550  1.5      wdk __BS_FUNCTION(bus_space_set_multi,BYTES)(t, h, o, v, c)       		\
    551  1.5      wdk 	bus_space_tag_t t;						\
    552  1.5      wdk 	bus_space_handle_t h;						\
    553  1.5      wdk 	bus_size_t o;							\
    554  1.5      wdk 	__BS_TYPENAME(BITS) v;						\
    555  1.5      wdk 	size_t c;							\
    556  1.5      wdk {									\
    557  1.5      wdk 									\
    558  1.5      wdk 	while (c--)							\
    559  1.5      wdk 		__BS_FUNCTION(bus_space_write,BYTES)(t, h, o, v);	\
    560  1.5      wdk }
    561  1.5      wdk 
    562  1.5      wdk __bus_space_set_multi(1,8)
    563  1.5      wdk __bus_space_set_multi(2,16)
    564  1.5      wdk __bus_space_set_multi(4,32)
    565  1.5      wdk __bus_space_set_multi(8,64)
    566  1.5      wdk 
    567  1.1      wdk 
    568  1.1      wdk /*
    569  1.1      wdk  *	void bus_space_set_region_N __P((bus_space_tag_t tag,
    570  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
    571  1.1      wdk  *	    size_t count));
    572  1.1      wdk  *
    573  1.1      wdk  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
    574  1.1      wdk  * by tag/handle starting at `offset'.
    575  1.1      wdk  */
    576  1.1      wdk 
    577  1.5      wdk #define __bus_space_set_region(BYTES,BITS)				\
    578  1.5      wdk static __inline void __BS_FUNCTION(bus_space_set_region,BYTES)		\
    579  1.5      wdk 	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    580  1.5      wdk 	__BS_TYPENAME(BITS), size_t));					\
    581  1.5      wdk 									\
    582  1.1      wdk static __inline void							\
    583  1.5      wdk __BS_FUNCTION(bus_space_set_region,BYTES)(t, h, o, v, c)		\
    584  1.5      wdk 	bus_space_tag_t t;						\
    585  1.5      wdk 	bus_space_handle_t h;						\
    586  1.5      wdk 	bus_size_t o;							\
    587  1.5      wdk 	__BS_TYPENAME(BITS) v;						\
    588  1.5      wdk 	size_t c;							\
    589  1.5      wdk {									\
    590  1.5      wdk 									\
    591  1.5      wdk 	while (c--) {							\
    592  1.5      wdk 		__BS_FUNCTION(bus_space_write,BYTES)(t, h, o, v);     	\
    593  1.5      wdk 		o += BYTES;						\
    594  1.1      wdk 	}								\
    595  1.1      wdk }
    596  1.1      wdk 
    597  1.5      wdk __bus_space_set_region(1,8)
    598  1.5      wdk __bus_space_set_region(2,16)
    599  1.5      wdk __bus_space_set_region(4,32)
    600  1.5      wdk __bus_space_set_region(8,64)
    601  1.5      wdk 
    602  1.1      wdk 
    603  1.1      wdk /*
    604  1.1      wdk  *	void bus_space_copy_region_N __P((bus_space_tag_t tag,
    605  1.1      wdk  *	    bus_space_handle_t bsh1, bus_size_t off1,
    606  1.1      wdk  *	    bus_space_handle_t bsh2, bus_size_t off2,
    607  1.5      wdk  *	    bus_size_t count));
    608  1.1      wdk  *
    609  1.1      wdk  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
    610  1.1      wdk  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
    611  1.1      wdk  */
    612  1.1      wdk 
    613  1.5      wdk #define	__bus_space_copy_region(BYTES)					\
    614  1.5      wdk static __inline void __BS_FUNCTION(bus_space_copy_region,BYTES)		\
    615  1.5      wdk 	__P((bus_space_tag_t,						\
    616  1.5      wdk 	    bus_space_handle_t bsh1, bus_size_t off1,			\
    617  1.5      wdk 	    bus_space_handle_t bsh2, bus_size_t off2,			\
    618  1.5      wdk 	    bus_size_t count));						\
    619  1.5      wdk 									\
    620  1.1      wdk static __inline void							\
    621  1.5      wdk __BS_FUNCTION(bus_space_copy_region,BYTES)(t, h1, o1, h2, o2, c)	\
    622  1.5      wdk 	bus_space_tag_t t;						\
    623  1.5      wdk 	bus_space_handle_t h1, h2;					\
    624  1.5      wdk 	bus_size_t o1, o2, c;						\
    625  1.5      wdk {									\
    626  1.5      wdk 	bus_size_t o;							\
    627  1.1      wdk 									\
    628  1.5      wdk 	if ((h1 + o1) >= (h2 + o2)) {					\
    629  1.1      wdk 		/* src after dest: copy forward */			\
    630  1.5      wdk 		for (o = 0; c != 0; c--, o += BYTES)			\
    631  1.5      wdk 		   __BS_FUNCTION(bus_space_write,BYTES)(t, h2, o2 + o,	\
    632  1.5      wdk 		       __BS_FUNCTION(bus_space_read,BYTES)(t, h1, o1 + o)); \
    633  1.1      wdk 	} else {							\
    634  1.5      wdk 		/* dest after src: copy backwards */			\
    635  1.5      wdk 		for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)	\
    636  1.5      wdk 		   __BS_FUNCTION(bus_space_write,BYTES)(t, h2, o2 + o,	\
    637  1.5      wdk 		       __BS_FUNCTION(bus_space_read,BYTES)(t, h1, o1 + o)); \
    638  1.1      wdk 	}								\
    639  1.1      wdk }
    640  1.1      wdk 
    641  1.5      wdk __bus_space_copy_region(1)
    642  1.5      wdk __bus_space_copy_region(2)
    643  1.5      wdk __bus_space_copy_region(4)
    644  1.5      wdk __bus_space_copy_region(8)
    645  1.5      wdk 
    646  1.1      wdk 
    647  1.1      wdk /*
    648  1.1      wdk  * Operations which handle byte stream data on word access.
    649  1.1      wdk  *
    650  1.1      wdk  * These functions are defined to resolve endian mismatch, by either
    651  1.1      wdk  * - When normal (i.e. stream-less) operations perform byte swap
    652  1.1      wdk  *   to resolve endian mismatch, these functions bypass the byte swap.
    653  1.1      wdk  * or
    654  1.1      wdk  * - When bus bridge performs automatic byte swap, these functions
    655  1.1      wdk  *   perform byte swap once more, to cancel the bridge's behavior.
    656  1.1      wdk  *
    657  1.5      wdk  * Mips Computer Systems platforms perform harware byte swapping -
    658  1.5      wdk  * therefore the streaming methods can byte swap as determined from
    659  1.5      wdk  * the bus space tag settings
    660  1.1      wdk  *
    661  1.1      wdk  */
    662  1.1      wdk #define __BUS_SPACE_HAS_STREAM_METHODS
    663  1.5      wdk 
    664  1.5      wdk /* Force creation of stream methods using the standard template macros */
    665  1.5      wdk #undef  __BS_FUNCTION
    666  1.5      wdk #define __BS_FUNCTION(func,BYTES)	__CONCAT3(func,_stream_,BYTES)
    667  1.5      wdk 
    668  1.5      wdk #define __BS_BSWAP(bst, val, BITS)					\
    669  1.5      wdk 	((bst->bs_bswap) ? __CONCAT(bswap,BITS)(val) : (val))
    670  1.5      wdk 
    671  1.5      wdk 
    672  1.5      wdk #define __bus_space_read_stream(BYTES,BITS)				\
    673  1.5      wdk static __inline __BS_TYPENAME(BITS)					\
    674  1.5      wdk __CONCAT(bus_space_read_stream_,BYTES)(bus_space_tag_t bst,		\
    675  1.5      wdk     bus_space_handle_t bsh, bus_size_t offset)				\
    676  1.5      wdk {									\
    677  1.5      wdk 	register __BS_TYPENAME(BITS) val =				\
    678  1.5      wdk 		__CONCAT(bus_space_read_,BYTES)(bst, bsh, offset);	\
    679  1.5      wdk 									\
    680  1.5      wdk 	return __BS_BSWAP(bst, val, BITS);				\
    681  1.5      wdk }
    682  1.5      wdk 
    683  1.5      wdk __bus_space_read_stream(2, 16)		/* bus_space_read_stream_2 */
    684  1.5      wdk __bus_space_read_stream(4, 32)		/* bus_space_read_stream_4 */
    685  1.5      wdk __bus_space_read_stream(8, 64)		/* bus_space_read_stream_8 */
    686  1.5      wdk 
    687  1.5      wdk 
    688  1.5      wdk #define __bus_space_write_stream(BYTES,BITS)				\
    689  1.5      wdk static __inline void							\
    690  1.5      wdk __CONCAT(bus_space_write_stream_,BYTES)(bus_space_tag_t bst,		\
    691  1.5      wdk     bus_space_handle_t bsh,						\
    692  1.5      wdk     bus_size_t offset, __CONCAT3(u_int,BITS,_t) data)			\
    693  1.5      wdk {									\
    694  1.5      wdk 	*__BS_ADDR(bst, bsh, offset, BITS, BYTES) =			\
    695  1.5      wdk 		__BS_BSWAP(bst, data, BITS);				\
    696  1.5      wdk 	wbflush();							\
    697  1.5      wdk }
    698  1.5      wdk 
    699  1.5      wdk __bus_space_write_stream(2,16)		/* bus_space_write_stream_2 */
    700  1.5      wdk __bus_space_write_stream(4,32)		/* bus_space_write_stream_4 */
    701  1.5      wdk __bus_space_write_stream(8,64)		/* bus_space_write_stream_8 */
    702  1.5      wdk 
    703  1.5      wdk __bus_space_read_multi(2,16)		/* bus_space_read_multi_stream_2 */
    704  1.5      wdk __bus_space_read_multi(4,32)		/* bus_space_read_multi_stream_4 */
    705  1.5      wdk __bus_space_read_multi(8,64)		/* bus_space_read_multi_stream_8 */
    706  1.5      wdk 
    707  1.5      wdk __bus_space_read_region(2,16)		/* bus_space_read_region_stream_2 */
    708  1.5      wdk __bus_space_read_region(4,32)		/* bus_space_read_region_stream_4 */
    709  1.5      wdk __bus_space_read_region(8,64)		/* bus_space_read_region_stream_8 */
    710  1.5      wdk 
    711  1.5      wdk __bus_space_write_multi(2,16)		/* bus_space_write_multi_stream_2 */
    712  1.5      wdk __bus_space_write_multi(4,32)		/* bus_space_write_multi_stream_4 */
    713  1.5      wdk __bus_space_write_multi(8,64)		/* bus_space_write_multi_stream_8 */
    714  1.5      wdk 
    715  1.5      wdk __bus_space_write_region(2,16)		/* bus_space_write_region_stream_2 */
    716  1.5      wdk __bus_space_write_region(4,32)		/* bus_space_write_region_stream_4 */
    717  1.5      wdk __bus_space_write_region(8,64)		/* bus_space_write_region_stream_8 */
    718  1.5      wdk 
    719  1.5      wdk __bus_space_set_multi(2,16)		/* bus_space_set_multi_stream_2 */
    720  1.5      wdk __bus_space_set_multi(4,32)		/* bus_space_set_multi_stream_4 */
    721  1.5      wdk __bus_space_set_multi(8,64)		/* bus_space_set_multi_stream_8 */
    722  1.5      wdk 
    723  1.5      wdk __bus_space_set_region(2,16)		/* bus_space_set_region_stream_2 */
    724  1.5      wdk __bus_space_set_region(4,32)		/* bus_space_set_region_stream_4 */
    725  1.5      wdk __bus_space_set_region(8, 64)		/* bus_space_set_region_stream_8 */
    726  1.5      wdk 
    727  1.5      wdk #undef __bus_space_read
    728  1.5      wdk #undef __bus_space_write
    729  1.5      wdk #undef __bus_space_read_stream
    730  1.5      wdk #undef __bus_space_write_stream
    731  1.5      wdk #undef __bus_space_read_multi
    732  1.5      wdk #undef __bus_space_read_region
    733  1.5      wdk #undef __bus_space_write_multi
    734  1.5      wdk #undef __bus_space_write_region
    735  1.5      wdk #undef __bus_space_set_multi
    736  1.5      wdk #undef __bus_space_set_region
    737  1.5      wdk #undef __bus_space_copy_region
    738  1.5      wdk 
    739  1.5      wdk #undef __BS_TYPENAME
    740  1.5      wdk #undef __BS_OFFSET
    741  1.5      wdk #undef __BS_FUNCTION
    742  1.5      wdk #undef __BS_ADDR
    743  1.1      wdk 
    744  1.1      wdk /*
    745  1.1      wdk  * Bus read/write barrier methods.
    746  1.1      wdk  *
    747  1.1      wdk  *	void bus_space_barrier __P((bus_space_tag_t tag,
    748  1.1      wdk  *	    bus_space_handle_t bsh, bus_size_t offset,
    749  1.1      wdk  *	    bus_size_t len, int flags));
    750  1.1      wdk  *
    751  1.1      wdk  * On the MIPS, we just flush the write buffer.
    752  1.1      wdk  */
    753  1.1      wdk #define bus_space_barrier(t, h, o, l, f)				\
    754  1.1      wdk 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)),	\
    755  1.1      wdk 	 wbflush())
    756  1.1      wdk 
    757  1.1      wdk #define BUS_SPACE_BARRIER_READ	0x01
    758  1.1      wdk #define BUS_SPACE_BARRIER_WRITE	0x02
    759  1.1      wdk 
    760  1.1      wdk /*
    761  1.1      wdk  * Flags used in various bus DMA methods.
    762  1.1      wdk  */
    763  1.1      wdk #define BUS_DMA_WAITOK		0x00	/* safe to sleep (pseudo-flag) */
    764  1.1      wdk #define BUS_DMA_NOWAIT		0x01	/* not safe to sleep */
    765  1.1      wdk #define BUS_DMA_ALLOCNOW	0x02	/* perform resource allocation now */
    766  1.1      wdk #define BUS_DMA_COHERENT	0x04	/* hint: map memory DMA coherent */
    767  1.4  thorpej #define	BUS_DMA_STREAMING	0x08	/* hint: sequential, unidirectional */
    768  1.1      wdk #define BUS_DMA_BUS1		0x10	/* placeholders for bus functions... */
    769  1.1      wdk #define BUS_DMA_BUS2		0x20
    770  1.1      wdk #define BUS_DMA_BUS3		0x40
    771  1.1      wdk #define BUS_DMA_BUS4		0x80
    772  1.1      wdk 
    773  1.1      wdk #define MIPSCO_DMAMAP_COHERENT	0x100	/* no cache flush necessary on sync */
    774  1.1      wdk 
    775  1.1      wdk /* Forwards needed by prototypes below. */
    776  1.1      wdk struct mbuf;
    777  1.1      wdk struct uio;
    778  1.1      wdk 
    779  1.1      wdk /*
    780  1.1      wdk  * Operations performed by bus_dmamap_sync().
    781  1.1      wdk  */
    782  1.1      wdk #define BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
    783  1.1      wdk #define BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
    784  1.1      wdk #define BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
    785  1.1      wdk #define BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
    786  1.1      wdk 
    787  1.1      wdk typedef struct mipsco_bus_dma_tag		*bus_dma_tag_t;
    788  1.1      wdk typedef struct mipsco_bus_dmamap		*bus_dmamap_t;
    789  1.1      wdk 
    790  1.1      wdk /*
    791  1.1      wdk  *	bus_dma_segment_t
    792  1.1      wdk  *
    793  1.1      wdk  *	Describes a single contiguous DMA transaction.  Values
    794  1.1      wdk  *	are suitable for programming into DMA registers.
    795  1.1      wdk  */
    796  1.1      wdk struct mipsco_bus_dma_segment {
    797  1.1      wdk 	/*
    798  1.1      wdk 	 * PUBLIC MEMBERS: these are used by device drivers.
    799  1.1      wdk 	 */
    800  1.1      wdk 	bus_addr_t	ds_addr;	/* DMA address */
    801  1.1      wdk 	bus_size_t	ds_len;		/* length of transfer */
    802  1.1      wdk 	/*
    803  1.1      wdk 	 * PRIVATE MEMBERS for the DMA back-end.: not for use by drivers.
    804  1.1      wdk 	 */
    805  1.1      wdk 	vaddr_t		_ds_paddr;	/* CPU physical address */
    806  1.1      wdk 	vaddr_t		_ds_vaddr;	/* virtual address, 0 if invalid */
    807  1.1      wdk };
    808  1.1      wdk typedef struct mipsco_bus_dma_segment	bus_dma_segment_t;
    809  1.1      wdk 
    810  1.1      wdk /*
    811  1.1      wdk  *	bus_dma_tag_t
    812  1.1      wdk  *
    813  1.1      wdk  *	A machine-dependent opaque type describing the implementation of
    814  1.1      wdk  *	DMA for a given bus.
    815  1.1      wdk  */
    816  1.1      wdk 
    817  1.1      wdk struct mipsco_bus_dma_tag {
    818  1.1      wdk 	bus_addr_t	dma_offset;
    819  1.1      wdk 
    820  1.1      wdk 	/*
    821  1.1      wdk 	 * DMA mapping methods.
    822  1.1      wdk 	 */
    823  1.1      wdk 	int	(*_dmamap_create) __P((bus_dma_tag_t, bus_size_t, int,
    824  1.1      wdk 		    bus_size_t, bus_size_t, int, bus_dmamap_t *));
    825  1.1      wdk 	void	(*_dmamap_destroy) __P((bus_dma_tag_t, bus_dmamap_t));
    826  1.1      wdk 	int	(*_dmamap_load) __P((bus_dma_tag_t, bus_dmamap_t, void *,
    827  1.1      wdk 		    bus_size_t, struct proc *, int));
    828  1.1      wdk 	int	(*_dmamap_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t,
    829  1.1      wdk 		    struct mbuf *, int));
    830  1.1      wdk 	int	(*_dmamap_load_uio) __P((bus_dma_tag_t, bus_dmamap_t,
    831  1.1      wdk 		    struct uio *, int));
    832  1.1      wdk 	int	(*_dmamap_load_raw) __P((bus_dma_tag_t, bus_dmamap_t,
    833  1.1      wdk 		    bus_dma_segment_t *, int, bus_size_t, int));
    834  1.1      wdk 	void	(*_dmamap_unload) __P((bus_dma_tag_t, bus_dmamap_t));
    835  1.1      wdk 	void	(*_dmamap_sync) __P((bus_dma_tag_t, bus_dmamap_t,
    836  1.1      wdk 		    bus_addr_t, bus_size_t, int));
    837  1.1      wdk 
    838  1.1      wdk 	/*
    839  1.1      wdk 	 * DMA memory utility functions.
    840  1.1      wdk 	 */
    841  1.1      wdk 	int	(*_dmamem_alloc) __P((bus_dma_tag_t, bus_size_t, bus_size_t,
    842  1.1      wdk 		    bus_size_t, bus_dma_segment_t *, int, int *, int));
    843  1.1      wdk 	void	(*_dmamem_free) __P((bus_dma_tag_t,
    844  1.1      wdk 		    bus_dma_segment_t *, int));
    845  1.1      wdk 	int	(*_dmamem_map) __P((bus_dma_tag_t, bus_dma_segment_t *,
    846  1.1      wdk 		    int, size_t, caddr_t *, int));
    847  1.1      wdk 	void	(*_dmamem_unmap) __P((bus_dma_tag_t, caddr_t, size_t));
    848  1.1      wdk 	paddr_t	(*_dmamem_mmap) __P((bus_dma_tag_t, bus_dma_segment_t *,
    849  1.1      wdk 		    int, off_t, int, int));
    850  1.1      wdk };
    851  1.1      wdk 
    852  1.1      wdk #define bus_dmamap_create(t, s, n, m, b, f, p)			\
    853  1.1      wdk 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
    854  1.1      wdk #define bus_dmamap_destroy(t, p)				\
    855  1.1      wdk 	(*(t)->_dmamap_destroy)((t), (p))
    856  1.1      wdk #define bus_dmamap_load(t, m, b, s, p, f)			\
    857  1.1      wdk 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
    858  1.1      wdk #define bus_dmamap_load_mbuf(t, m, b, f)			\
    859  1.1      wdk 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
    860  1.1      wdk #define bus_dmamap_load_uio(t, m, u, f)				\
    861  1.1      wdk 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
    862  1.1      wdk #define bus_dmamap_load_raw(t, m, sg, n, s, f)			\
    863  1.1      wdk 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
    864  1.1      wdk #define bus_dmamap_unload(t, p)					\
    865  1.1      wdk 	(*(t)->_dmamap_unload)((t), (p))
    866  1.1      wdk #define bus_dmamap_sync(t, p, o, l, ops)			\
    867  1.1      wdk 	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
    868  1.1      wdk #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
    869  1.1      wdk 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
    870  1.1      wdk #define bus_dmamem_free(t, sg, n)				\
    871  1.1      wdk 	(*(t)->_dmamem_free)((t), (sg), (n))
    872  1.1      wdk #define bus_dmamem_map(t, sg, n, s, k, f)			\
    873  1.1      wdk 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
    874  1.1      wdk #define bus_dmamem_unmap(t, k, s)				\
    875  1.1      wdk 	(*(t)->_dmamem_unmap)((t), (k), (s))
    876  1.1      wdk #define bus_dmamem_mmap(t, sg, n, o, p, f)			\
    877  1.1      wdk 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
    878  1.1      wdk 
    879  1.1      wdk /*
    880  1.1      wdk  *	bus_dmamap_t
    881  1.1      wdk  *
    882  1.1      wdk  *	Describes a DMA mapping.
    883  1.1      wdk  */
    884  1.1      wdk struct mipsco_bus_dmamap {
    885  1.1      wdk 	/*
    886  1.1      wdk 	 * PRIVATE MEMBERS: not for use by machine-independent code.
    887  1.1      wdk 	 */
    888  1.1      wdk 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
    889  1.1      wdk 	int		_dm_segcnt;	/* number of segs this map can map */
    890  1.1      wdk 	bus_size_t	_dm_maxsegsz;	/* largest possible segment */
    891  1.1      wdk 	bus_size_t	_dm_boundary;	/* don't cross this */
    892  1.1      wdk 	int		_dm_flags;	/* misc. flags */
    893  1.1      wdk 
    894  1.1      wdk 	/*
    895  1.1      wdk 	 * Private cookie to be used by the DMA back-end.
    896  1.1      wdk 	 */
    897  1.1      wdk 	void		*_dm_cookie;
    898  1.1      wdk 
    899  1.1      wdk 	/*
    900  1.1      wdk 	 * PUBLIC MEMBERS: these are used by machine-independent code.
    901  1.1      wdk 	 */
    902  1.1      wdk 	bus_size_t	dm_mapsize;	/* size of the mapping */
    903  1.1      wdk 	int		dm_nsegs;	/* # valid segments in mapping */
    904  1.1      wdk 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
    905  1.1      wdk };
    906  1.1      wdk 
    907  1.1      wdk #ifdef _MIPSCO_BUS_DMA_PRIVATE
    908  1.1      wdk int	_bus_dmamap_create __P((bus_dma_tag_t, bus_size_t, int, bus_size_t,
    909  1.1      wdk 	    bus_size_t, int, bus_dmamap_t *));
    910  1.1      wdk void	_bus_dmamap_destroy __P((bus_dma_tag_t, bus_dmamap_t));
    911  1.1      wdk int	_bus_dmamap_load __P((bus_dma_tag_t, bus_dmamap_t, void *,
    912  1.1      wdk 	    bus_size_t, struct proc *, int));
    913  1.1      wdk int	_bus_dmamap_load_mbuf __P((bus_dma_tag_t, bus_dmamap_t,
    914  1.1      wdk 	    struct mbuf *, int));
    915  1.1      wdk int	_bus_dmamap_load_uio __P((bus_dma_tag_t, bus_dmamap_t,
    916  1.1      wdk 	    struct uio *, int));
    917  1.1      wdk int	_bus_dmamap_load_raw __P((bus_dma_tag_t, bus_dmamap_t,
    918  1.1      wdk 	    bus_dma_segment_t *, int, bus_size_t, int));
    919  1.1      wdk void	_bus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
    920  1.1      wdk void	_mips1_bus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    921  1.1      wdk 	    bus_size_t, int));
    922  1.1      wdk void	_mips3_bus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    923  1.1      wdk 	    bus_size_t, int));
    924  1.1      wdk 
    925  1.1      wdk int	_bus_dmamem_alloc __P((bus_dma_tag_t tag, bus_size_t size,
    926  1.1      wdk 	    bus_size_t alignment, bus_size_t boundary,
    927  1.1      wdk 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags));
    928  1.1      wdk int	_bus_dmamem_alloc_range __P((bus_dma_tag_t tag, bus_size_t size,
    929  1.1      wdk 	    bus_size_t alignment, bus_size_t boundary,
    930  1.1      wdk 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
    931  1.1      wdk 	    paddr_t low, paddr_t high));
    932  1.1      wdk void	_bus_dmamem_free __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    933  1.1      wdk 	    int nsegs));
    934  1.1      wdk int	_bus_dmamem_map __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    935  1.1      wdk 	    int nsegs, size_t size, caddr_t *kvap, int flags));
    936  1.1      wdk void	_bus_dmamem_unmap __P((bus_dma_tag_t tag, caddr_t kva,
    937  1.1      wdk 	    size_t size));
    938  1.1      wdk paddr_t	_bus_dmamem_mmap __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
    939  1.1      wdk 	    int nsegs, off_t off, int prot, int flags));
    940  1.1      wdk 
    941  1.1      wdk int	_bus_dmamem_alloc_range __P((bus_dma_tag_t tag, bus_size_t size,
    942  1.1      wdk 	    bus_size_t alignment, bus_size_t boundary,
    943  1.1      wdk 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
    944  1.1      wdk 	    paddr_t low, paddr_t high));
    945  1.1      wdk #endif /* _MIPSCO_BUS_DMA_PRIVATE */
    946  1.1      wdk 
    947  1.1      wdk void	_bus_dma_tag_init __P((bus_dma_tag_t tag));
    948  1.1      wdk 
    949  1.1      wdk #endif /* _KERNEL */
    950  1.1      wdk #endif /* _MIPSCO_BUS_H_ */
    951