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