bus.h revision 1.15.30.1       1  1.15.30.1    martin /*	$NetBSD: bus.h,v 1.15.30.1 2020/04/13 08:04:03 martin Exp $	*/
      2        1.1       uch 
      3        1.1       uch /*-
      4        1.1       uch  * Copyright (c) 1997, 1998, 2000, 2001 The NetBSD Foundation, Inc.
      5        1.1       uch  * All rights reserved.
      6        1.1       uch  *
      7        1.1       uch  * This code is derived from software contributed to The NetBSD Foundation
      8        1.1       uch  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9        1.1       uch  * NASA Ames Research Center.
     10        1.1       uch  *
     11        1.1       uch  * Redistribution and use in source and binary forms, with or without
     12        1.1       uch  * modification, are permitted provided that the following conditions
     13        1.1       uch  * are met:
     14        1.1       uch  * 1. Redistributions of source code must retain the above copyright
     15        1.1       uch  *    notice, this list of conditions and the following disclaimer.
     16        1.1       uch  * 2. Redistributions in binary form must reproduce the above copyright
     17        1.1       uch  *    notice, this list of conditions and the following disclaimer in the
     18        1.1       uch  *    documentation and/or other materials provided with the distribution.
     19        1.1       uch  *
     20        1.1       uch  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21        1.1       uch  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22        1.1       uch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23        1.1       uch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24        1.1       uch  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25        1.1       uch  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26        1.1       uch  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27        1.1       uch  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28        1.1       uch  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29        1.1       uch  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30        1.1       uch  * POSSIBILITY OF SUCH DAMAGE.
     31        1.1       uch  */
     32        1.1       uch 
     33        1.1       uch /*
     34        1.1       uch  * Copyright (c) 1996 Carnegie-Mellon University.
     35        1.1       uch  * All rights reserved.
     36        1.1       uch  *
     37        1.1       uch  * Author: Chris G. Demetriou
     38        1.1       uch  *
     39        1.1       uch  * Permission to use, copy, modify and distribute this software and
     40        1.1       uch  * its documentation is hereby granted, provided that both the copyright
     41        1.1       uch  * notice and this permission notice appear in all copies of the
     42        1.1       uch  * software, derivative works or modified versions, and any portions
     43        1.1       uch  * thereof, and that both notices appear in supporting documentation.
     44        1.1       uch  *
     45        1.1       uch  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     46        1.1       uch  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     47        1.1       uch  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     48        1.1       uch  *
     49        1.1       uch  * Carnegie Mellon requests users of this software to return to
     50        1.1       uch  *
     51        1.1       uch  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     52        1.1       uch  *  School of Computer Science
     53        1.1       uch  *  Carnegie Mellon University
     54        1.1       uch  *  Pittsburgh PA 15213-3890
     55        1.1       uch  *
     56        1.1       uch  * any improvements or extensions that they make and grant Carnegie the
     57        1.1       uch  * rights to redistribute these changes.
     58        1.1       uch  */
     59        1.1       uch 
     60        1.1       uch #ifndef _PLAYSTATION2_BUS_H_
     61        1.1       uch #define	_PLAYSTATION2_BUS_H_
     62        1.1       uch 
     63        1.1       uch #include <sys/types.h>
     64        1.1       uch 
     65        1.1       uch #ifdef _KERNEL
     66        1.1       uch /*
     67        1.1       uch  * Turn on BUS_SPACE_DEBUG if the global DEBUG option is enabled.
     68        1.1       uch  */
     69        1.1       uch #if defined(DEBUG) && !defined(BUS_SPACE_DEBUG)
     70        1.1       uch #define	BUS_SPACE_DEBUG
     71        1.1       uch #endif
     72        1.1       uch 
     73        1.1       uch #ifdef BUS_SPACE_DEBUG
     74        1.1       uch #include <sys/systm.h> /* for printf() prototype */
     75        1.1       uch /*
     76        1.1       uch  * Macros for checking the aligned-ness of pointers passed to bus
     77        1.1       uch  * space ops.  Strict alignment is required by the MIPS architecture,
     78        1.1       uch  * and a trap will occur if unaligned access is performed.  These
     79        1.1       uch  * may aid in the debugging of a broken device driver by displaying
     80        1.1       uch  * useful information about the problem.
     81        1.1       uch  */
     82        1.1       uch #define	__BUS_SPACE_ALIGNED_ADDRESS(p, t)				\
     83        1.1       uch 	((((u_int32_t)(p)) & (sizeof(t)-1)) == 0)
     84        1.1       uch 
     85        1.1       uch #define	__BUS_SPACE_ADDRESS_SANITY(p, t, d)				\
     86        1.1       uch ({									\
     87        1.1       uch 	if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) {			\
     88        1.1       uch 		printf("%s 0x%x not aligned to %u bytes %s:%d\n",	\
     89        1.1       uch 		    d, (u_int32_t)(p), (u_int32_t)sizeof(t), __FILE__,	\
     90        1.1       uch 		    __LINE__);						\
     91        1.1       uch 	}								\
     92        1.1       uch 	(void) 0;							\
     93        1.1       uch })
     94        1.1       uch 
     95        1.1       uch #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
     96        1.1       uch #else
     97        1.1       uch #define	__BUS_SPACE_ADDRESS_SANITY(p, t, d)	(void) 0
     98        1.1       uch #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
     99        1.1       uch #endif /* BUS_SPACE_DEBUG */
    100        1.1       uch #endif /* _KERNEL */
    101        1.1       uch 
    102        1.1       uch /*
    103        1.1       uch  * Addresses (in bus space).
    104        1.1       uch  */
    105        1.1       uch typedef long bus_addr_t;
    106        1.1       uch typedef long bus_size_t;
    107        1.1       uch 
    108  1.15.30.1    martin #define PRIxBUSADDR	"lx"
    109  1.15.30.1    martin #define PRIxBUSSIZE	"lx"
    110  1.15.30.1    martin #define PRIuBUSSIZE	"lu"
    111        1.1       uch /*
    112        1.1       uch  * Access methods for bus space.
    113        1.1       uch  */
    114        1.1       uch typedef const struct playstation2_bus_space *bus_space_tag_t;
    115        1.1       uch typedef bus_addr_t bus_space_handle_t;
    116        1.1       uch 
    117  1.15.30.1    martin #define PRIxBSH		PRIxBUSADDR
    118  1.15.30.1    martin 
    119        1.1       uch struct extent; /* forward declaration */
    120        1.1       uch 
    121        1.1       uch struct playstation2_bus_space {
    122        1.1       uch 	struct extent	*pbs_extent;
    123        1.1       uch 	bus_addr_t	pbs_base_addr;
    124        1.1       uch 
    125        1.1       uch 	/* cookie */
    126        1.1       uch 	void		*pbs_cookie;
    127        1.1       uch 
    128        1.1       uch 	/* mapping/unmapping */
    129        1.1       uch 	int		(*pbs_map)(void *, bus_addr_t, bus_size_t,
    130        1.1       uch 			    int, bus_space_handle_t *);
    131        1.1       uch 	void		(*pbs_unmap)(void *, bus_space_handle_t,
    132        1.1       uch 			    bus_size_t);
    133        1.1       uch 	int		(*pbs_subregion)(void *, bus_space_handle_t,
    134        1.1       uch 			    bus_size_t, bus_size_t, bus_space_handle_t *);
    135        1.1       uch 
    136        1.1       uch 	/* allocation/deallocation */
    137        1.1       uch 	int		(*pbs_alloc)(void *, bus_addr_t, bus_addr_t,
    138        1.1       uch 			    bus_size_t, bus_size_t, bus_size_t, int,
    139        1.1       uch 			    bus_addr_t *, bus_space_handle_t *);
    140        1.1       uch 	void		(*pbs_free)(void *, bus_space_handle_t,
    141        1.1       uch 			    bus_size_t);
    142        1.1       uch 
    143        1.1       uch 	/* get kernel virtual address */
    144        1.1       uch 	void *		(*pbs_vaddr)(void *, bus_space_handle_t);
    145        1.1       uch 
    146        1.1       uch 	/* read (single) */
    147        1.1       uch 	u_int8_t	(*pbs_r_1)(void *, bus_space_handle_t,
    148        1.1       uch 			    bus_size_t);
    149        1.1       uch 	u_int16_t	(*pbs_r_2)(void *, bus_space_handle_t,
    150        1.1       uch 			    bus_size_t);
    151        1.1       uch 	u_int32_t	(*pbs_r_4)(void *, bus_space_handle_t,
    152        1.1       uch 			    bus_size_t);
    153        1.1       uch 	u_int64_t	(*pbs_r_8)(void *, bus_space_handle_t,
    154        1.1       uch 			    bus_size_t);
    155        1.1       uch 
    156        1.1       uch 	/* read multiple */
    157        1.1       uch 	void		(*pbs_rm_1)(void *, bus_space_handle_t,
    158        1.1       uch 			    bus_size_t, u_int8_t *, bus_size_t);
    159        1.1       uch 	void		(*pbs_rm_2)(void *, bus_space_handle_t,
    160        1.1       uch 			    bus_size_t, u_int16_t *, bus_size_t);
    161        1.1       uch 	void		(*pbs_rm_4)(void *, bus_space_handle_t,
    162        1.1       uch 			    bus_size_t, u_int32_t *, bus_size_t);
    163        1.1       uch 	void		(*pbs_rm_8)(void *, bus_space_handle_t,
    164        1.1       uch 			    bus_size_t, u_int64_t *, bus_size_t);
    165        1.1       uch 
    166        1.1       uch 	/* read region */
    167        1.1       uch 	void		(*pbs_rr_1)(void *, bus_space_handle_t,
    168        1.1       uch 			    bus_size_t, u_int8_t *, bus_size_t);
    169        1.1       uch 	void		(*pbs_rr_2)(void *, bus_space_handle_t,
    170        1.1       uch 			    bus_size_t, u_int16_t *, bus_size_t);
    171        1.1       uch 	void		(*pbs_rr_4)(void *, bus_space_handle_t,
    172        1.1       uch 			    bus_size_t, u_int32_t *, bus_size_t);
    173        1.1       uch 	void		(*pbs_rr_8)(void *, bus_space_handle_t,
    174        1.1       uch 			    bus_size_t, u_int64_t *, bus_size_t);
    175        1.1       uch 
    176        1.1       uch 	/* write (single) */
    177        1.1       uch 	void		(*pbs_w_1)(void *, bus_space_handle_t,
    178        1.1       uch 			    bus_size_t, u_int8_t);
    179        1.1       uch 	void		(*pbs_w_2)(void *, bus_space_handle_t,
    180        1.1       uch 			    bus_size_t, u_int16_t);
    181        1.1       uch 	void		(*pbs_w_4)(void *, bus_space_handle_t,
    182        1.1       uch 			    bus_size_t, u_int32_t);
    183        1.1       uch 	void		(*pbs_w_8)(void *, bus_space_handle_t,
    184        1.1       uch 			    bus_size_t, u_int64_t);
    185        1.1       uch 
    186        1.1       uch 	/* write multiple */
    187        1.1       uch 	void		(*pbs_wm_1)(void *, bus_space_handle_t,
    188        1.1       uch 			    bus_size_t, const u_int8_t *, bus_size_t);
    189        1.1       uch 	void		(*pbs_wm_2)(void *, bus_space_handle_t,
    190        1.1       uch 			    bus_size_t, const u_int16_t *, bus_size_t);
    191        1.1       uch 	void		(*pbs_wm_4)(void *, bus_space_handle_t,
    192        1.1       uch 			    bus_size_t, const u_int32_t *, bus_size_t);
    193        1.1       uch 	void		(*pbs_wm_8)(void *, bus_space_handle_t,
    194        1.1       uch 			    bus_size_t, const u_int64_t *, bus_size_t);
    195        1.1       uch 
    196        1.1       uch 	/* write region */
    197        1.1       uch 	void		(*pbs_wr_1)(void *, bus_space_handle_t,
    198        1.1       uch 			    bus_size_t, const u_int8_t *, bus_size_t);
    199        1.1       uch 	void		(*pbs_wr_2)(void *, bus_space_handle_t,
    200        1.1       uch 			    bus_size_t, const u_int16_t *, bus_size_t);
    201        1.1       uch 	void		(*pbs_wr_4)(void *, bus_space_handle_t,
    202        1.1       uch 			    bus_size_t, const u_int32_t *, bus_size_t);
    203        1.1       uch 	void		(*pbs_wr_8)(void *, bus_space_handle_t,
    204        1.1       uch 			    bus_size_t, const u_int64_t *, bus_size_t);
    205        1.1       uch 
    206        1.1       uch 	/* set multiple */
    207        1.1       uch 	void		(*pbs_sm_1)(void *, bus_space_handle_t,
    208        1.1       uch 			    bus_size_t, u_int8_t, bus_size_t);
    209        1.1       uch 	void		(*pbs_sm_2)(void *, bus_space_handle_t,
    210        1.1       uch 			    bus_size_t, u_int16_t, bus_size_t);
    211        1.1       uch 	void		(*pbs_sm_4)(void *, bus_space_handle_t,
    212        1.1       uch 			    bus_size_t, u_int32_t, bus_size_t);
    213        1.1       uch 	void		(*pbs_sm_8)(void *, bus_space_handle_t,
    214        1.1       uch 			    bus_size_t, u_int64_t, bus_size_t);
    215        1.1       uch 
    216        1.1       uch 	/* set region */
    217        1.1       uch 	void		(*pbs_sr_1)(void *, bus_space_handle_t,
    218        1.1       uch 			    bus_size_t, u_int8_t, bus_size_t);
    219        1.1       uch 	void		(*pbs_sr_2)(void *, bus_space_handle_t,
    220        1.1       uch 			    bus_size_t, u_int16_t, bus_size_t);
    221        1.1       uch 	void		(*pbs_sr_4)(void *, bus_space_handle_t,
    222        1.1       uch 			    bus_size_t, u_int32_t, bus_size_t);
    223        1.1       uch 	void		(*pbs_sr_8)(void *, bus_space_handle_t,
    224        1.1       uch 			    bus_size_t, u_int64_t, bus_size_t);
    225        1.1       uch 
    226        1.1       uch 	/* copy */
    227        1.1       uch 	void		(*pbs_c_1)(void *, bus_space_handle_t, bus_size_t,
    228        1.1       uch 			    bus_space_handle_t, bus_size_t, bus_size_t);
    229        1.1       uch 	void		(*pbs_c_2)(void *, bus_space_handle_t, bus_size_t,
    230        1.1       uch 			    bus_space_handle_t, bus_size_t, bus_size_t);
    231        1.1       uch 	void		(*pbs_c_4)(void *, bus_space_handle_t, bus_size_t,
    232        1.1       uch 			    bus_space_handle_t, bus_size_t, bus_size_t);
    233        1.1       uch 	void		(*pbs_c_8)(void *, bus_space_handle_t, bus_size_t,
    234        1.1       uch 			    bus_space_handle_t, bus_size_t, bus_size_t);
    235        1.1       uch };
    236        1.1       uch 
    237        1.1       uch #ifdef _KERNEL
    238        1.8     perry #define _wbflush()	__asm volatile("sync.l")
    239        1.1       uch #ifdef _PLAYSTATION2_BUS_SPACE_PRIVATE
    240        1.1       uch 
    241        1.1       uch #ifndef __read_1
    242        1.8     perry #define	__read_1(a)	(*(volatile u_int8_t *)(a))
    243        1.1       uch #endif
    244        1.1       uch #ifndef __read_2
    245        1.8     perry #define	__read_2(a)	(*(volatile u_int16_t *)(a))
    246        1.1       uch #endif
    247        1.1       uch #ifndef __read_4
    248        1.8     perry #define	__read_4(a)	(*(volatile u_int32_t *)(a))
    249        1.1       uch #endif
    250        1.1       uch #ifndef __read_8
    251        1.1       uch #define __read_8(a)							\
    252        1.1       uch ({									\
    253        1.1       uch 	u_int32_t lo, hi;						\
    254        1.8     perry 	__asm volatile(						\
    255        1.1       uch 		".set noreorder;"					\
    256        1.1       uch 		".set push;"						\
    257        1.1       uch 		".set mips3;"						\
    258        1.1       uch 		"ld	$8, (%2);"					\
    259        1.1       uch 		"dsra	%1, $8, 32;"					\
    260        1.1       uch 		"dsll	%0, $8, 32;"					\
    261        1.1       uch 		"dsra	%0, %0, 32;"					\
    262        1.1       uch 		".set pop;"						\
    263        1.1       uch 		".set reorder;"						\
    264        1.1       uch 		: "=r"(lo), "=r"(hi) : "r"(a) : "$8");			\
    265        1.1       uch 	((u_int64_t)hi << 32) | lo;					\
    266        1.1       uch })
    267        1.1       uch #endif
    268        1.1       uch #define __read_16(a)	"error. not yet"
    269        1.1       uch 
    270        1.1       uch #ifndef __write_1
    271        1.1       uch #define	__write_1(a, v) {						\
    272        1.8     perry 	*(volatile u_int8_t *)(a) = (v);				\
    273        1.1       uch 	_wbflush();							\
    274        1.1       uch }
    275        1.1       uch #endif
    276        1.1       uch #ifndef __write_2
    277        1.1       uch #define	__write_2(a, v)	{						\
    278        1.8     perry 	*(volatile u_int16_t *)(a) = (v);				\
    279        1.1       uch 	_wbflush();							\
    280        1.1       uch }
    281        1.1       uch #endif
    282        1.1       uch #ifndef __write_4
    283        1.1       uch #define	__write_4(a, v)	{						\
    284        1.8     perry 	*(volatile u_int32_t *)(a) = (v);				\
    285        1.1       uch 	_wbflush();							\
    286        1.1       uch }
    287        1.1       uch #endif
    288        1.1       uch #ifdef EE_GCC
    289        1.1       uch #ifndef __write_8
    290        1.1       uch #define	__write_8(a, v)	(*(volatile u_int64_t *)(a) = (v)) {		\
    291        1.1       uch 	_wbflush();							\
    292        1.1       uch }
    293        1.1       uch #endif
    294        1.1       uch #ifndef __write_16
    295        1.1       uch #define __write_16(a, v)	(*(volatile u_int128_t *)(a) = (v)) {	\
    296        1.1       uch 	_wbflush();							\
    297        1.1       uch }
    298        1.1       uch #endif
    299        1.1       uch #else /* EE_GCC */
    300        1.1       uch #ifdef __write_8
    301        1.1       uch #error "can't override __write_8"
    302        1.1       uch #endif
    303        1.9     perry static __inline void
    304        1.1       uch __write_8(bus_addr_t a, u_int64_t v)
    305        1.1       uch {
    306        1.8     perry 	__asm volatile(
    307        1.1       uch 		".set noreorder;"
    308        1.1       uch 		".set push;"
    309       1.15    martin 		".set arch = r5900;"
    310        1.1       uch 		"pextlw	$8, %0, %1;"
    311        1.1       uch 		"sd	$8, 0(%2);"
    312        1.1       uch 		"sync.l;"
    313        1.1       uch 		".set pop;"
    314        1.1       uch 		".set reorder;"
    315        1.1       uch 		: : "r"((u_int32_t)((u_int64_t)(v) >> 32)),
    316        1.1       uch 		"r"((u_int32_t)(v)), "r"((u_int32_t)(a)) : "$8");
    317        1.1       uch }
    318        1.1       uch #define _write_16(a)	"error. not yet"
    319        1.1       uch #endif /* EE_GCC */
    320        1.1       uch 
    321        1.1       uch #define	__TYPENAME(BITS)	u_int##BITS##_t
    322        1.1       uch 
    323        1.1       uch #define _BUS_SPACE_READ(PREFIX, BYTES, BITS)				\
    324        1.1       uch static __TYPENAME(BITS)							\
    325        1.1       uch PREFIX##_read_##BYTES(void *, bus_space_handle_t,  bus_size_t);		\
    326        1.1       uch static __TYPENAME(BITS)							\
    327        1.1       uch PREFIX##_read_##BYTES(void *tag, bus_space_handle_t bsh,		\
    328        1.1       uch     bus_size_t offset)							\
    329        1.1       uch {									\
    330        1.3      kent 	return __read_##BYTES(VADDR(bsh, offset));			\
    331        1.1       uch }
    332        1.1       uch 
    333        1.1       uch #define _BUS_SPACE_READ_MULTI(PREFIX, BYTES, BITS)			\
    334        1.1       uch static void								\
    335        1.1       uch PREFIX##_read_multi_##BYTES(void *, bus_space_handle_t,	bus_size_t,	\
    336        1.1       uch     __TYPENAME(BITS) *,	bus_size_t);					\
    337        1.1       uch static void								\
    338        1.1       uch PREFIX##_read_multi_##BYTES(void *tag, bus_space_handle_t bsh,		\
    339        1.1       uch     bus_size_t offset, __TYPENAME(BITS) *addr, bus_size_t count)	\
    340        1.1       uch {									\
    341        1.1       uch 	bus_addr_t a = VADDR(bsh, offset);				\
    342        1.1       uch 	while (count--)							\
    343        1.3      kent 		*addr++ = __read_##BYTES(a);				\
    344        1.1       uch }
    345        1.1       uch 
    346        1.1       uch #define _BUS_SPACE_READ_REGION(PREFIX, BYTES, BITS)			\
    347        1.1       uch static void								\
    348        1.1       uch PREFIX##_read_region_##BYTES(void *, bus_space_handle_t, bus_size_t,	\
    349        1.1       uch     __TYPENAME(BITS) *, bus_size_t);					\
    350        1.1       uch static void								\
    351        1.1       uch PREFIX##_read_region_##BYTES(void *tag, bus_space_handle_t bsh,		\
    352        1.1       uch     bus_size_t offset, __TYPENAME(BITS) *addr, bus_size_t count)	\
    353        1.1       uch {									\
    354        1.1       uch 	while (count--) {						\
    355        1.3      kent 		*addr++ = __read_##BYTES(VADDR(bsh, offset));		\
    356        1.1       uch 		offset += BYTES;					\
    357        1.1       uch 	}								\
    358        1.1       uch }
    359        1.1       uch 
    360        1.1       uch #define _BUS_SPACE_WRITE(PREFIX, BYTES, BITS)				\
    361        1.1       uch static void								\
    362        1.1       uch PREFIX##_write_##BYTES(void *, bus_space_handle_t, bus_size_t,		\
    363        1.1       uch     __TYPENAME(BITS));							\
    364        1.1       uch static void								\
    365        1.1       uch PREFIX##_write_##BYTES(void *tag, bus_space_handle_t bsh,		\
    366        1.1       uch     bus_size_t offset, __TYPENAME(BITS) value)				\
    367        1.1       uch {									\
    368        1.3      kent 	__write_##BYTES(VADDR(bsh, offset), value);			\
    369        1.1       uch }
    370        1.1       uch 
    371        1.1       uch #define _BUS_SPACE_WRITE_MULTI(PREFIX, BYTES, BITS)			\
    372        1.1       uch static void								\
    373        1.1       uch PREFIX##_write_multi_##BYTES(void *, bus_space_handle_t, bus_size_t,	\
    374        1.1       uch     const __TYPENAME(BITS) *, bus_size_t);				\
    375        1.1       uch static void								\
    376        1.1       uch PREFIX##_write_multi_##BYTES(void *tag, bus_space_handle_t bsh,		\
    377        1.1       uch     bus_size_t offset, const __TYPENAME(BITS) *addr, bus_size_t count)	\
    378        1.1       uch {									\
    379        1.1       uch 	bus_addr_t a = VADDR(bsh, offset);				\
    380        1.1       uch 	while (count--) {						\
    381        1.3      kent 		__write_##BYTES(a, *addr++);				\
    382        1.1       uch 	}								\
    383        1.1       uch }
    384        1.1       uch 
    385        1.1       uch #define _BUS_SPACE_WRITE_REGION(PREFIX, BYTES, BITS)			\
    386        1.1       uch static void								\
    387        1.1       uch PREFIX##_write_region_##BYTES(void *, bus_space_handle_t, bus_size_t,	\
    388        1.1       uch     const __TYPENAME(BITS) *, bus_size_t);				\
    389        1.1       uch static void								\
    390        1.1       uch PREFIX##_write_region_##BYTES(void *tag, bus_space_handle_t bsh,	\
    391        1.1       uch     bus_size_t offset, const __TYPENAME(BITS) *addr, bus_size_t count)	\
    392        1.1       uch {									\
    393        1.1       uch 	while (count--) {						\
    394        1.3      kent 		__write_##BYTES(VADDR(bsh, offset), *addr++);		\
    395        1.1       uch 		offset += BYTES;					\
    396        1.1       uch 	}								\
    397        1.1       uch }
    398        1.1       uch 
    399        1.1       uch #define _BUS_SPACE_SET_MULTI(PREFIX, BYTES, BITS)			\
    400        1.1       uch static void								\
    401        1.1       uch PREFIX##_set_multi_##BYTES(void *, bus_space_handle_t, bus_size_t,	\
    402        1.1       uch     __TYPENAME(BITS), bus_size_t);					\
    403        1.1       uch static void								\
    404        1.1       uch PREFIX##_set_multi_##BYTES(void *tag, bus_space_handle_t bsh,		\
    405        1.1       uch     bus_size_t offset, __TYPENAME(BITS) value, bus_size_t count)	\
    406        1.1       uch {									\
    407        1.1       uch 	bus_addr_t a = VADDR(bsh, offset);				\
    408        1.1       uch 	while (count--) {						\
    409        1.3      kent 		__write_##BYTES(a, value);				\
    410        1.1       uch 	}								\
    411        1.1       uch }
    412        1.1       uch 
    413        1.1       uch #define _BUS_SPACE_SET_REGION(PREFIX, BYTES, BITS)			\
    414        1.1       uch static void								\
    415        1.1       uch PREFIX##_set_region_##BYTES(void *, bus_space_handle_t, bus_size_t,	\
    416        1.1       uch     __TYPENAME(BITS), bus_size_t);					\
    417        1.1       uch static void								\
    418        1.1       uch PREFIX##_set_region_##BYTES(void *tag, bus_space_handle_t bsh,		\
    419        1.1       uch     bus_size_t offset, __TYPENAME(BITS) value, bus_size_t count)	\
    420        1.1       uch {									\
    421        1.1       uch 	while (count--) {						\
    422        1.3      kent 		__write_##BYTES(VADDR(bsh, offset), value);		\
    423        1.1       uch 		offset += BYTES;					\
    424        1.1       uch 	}								\
    425        1.1       uch }
    426        1.1       uch 
    427        1.1       uch #define _BUS_SPACE_COPY_REGION(PREFIX, BYTES, BITS)			\
    428        1.1       uch static void								\
    429        1.1       uch PREFIX##_copy_region_##BYTES(void *, bus_space_handle_t, bus_size_t,	\
    430        1.1       uch     bus_space_handle_t, bus_size_t, bus_size_t);			\
    431        1.1       uch static void								\
    432        1.1       uch PREFIX##_copy_region_##BYTES(void *t, bus_space_handle_t h1,		\
    433        1.1       uch     bus_size_t o1, bus_space_handle_t h2, bus_size_t o2, bus_size_t c)	\
    434        1.1       uch {									\
    435        1.1       uch 	bus_size_t o;							\
    436        1.1       uch 	if ((h1 + o1) >= (h2 + o2)) {					\
    437        1.1       uch 		/* src after dest: copy forward */			\
    438        1.1       uch 		for (o = 0; c != 0; c--, o += BYTES)			\
    439        1.3      kent 			__write_##BYTES(VADDR(h2, o2 + o),		\
    440        1.3      kent 			    __read_##BYTES(VADDR(h1, o1 + o)));	\
    441        1.1       uch 	} else {							\
    442        1.1       uch 		/* dest after src: copy backwards */			\
    443        1.1       uch 		for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)	\
    444        1.3      kent 			__write_##BYTES(VADDR(h2, o2 + o),		\
    445        1.3      kent 			    __read_##BYTES(VADDR(h1, o1 + o)));	\
    446        1.1       uch 	}								\
    447        1.1       uch }
    448        1.1       uch 
    449        1.1       uch #define _BUS_SPACE_NO_MAP						\
    450        1.1       uch 	(int (*)(void *, bus_addr_t, bus_size_t, int,			\
    451        1.1       uch 	bus_space_handle_t *))_bus_space_invalid_access
    452        1.1       uch #define _BUS_SPACE_NO_UNMAP						\
    453        1.1       uch 	(void (*)(void *, bus_space_handle_t, bus_size_t))		\
    454        1.1       uch 	_bus_space_invalid_access
    455        1.1       uch #define _BUS_SPACE_NO_SUBREGION						\
    456        1.1       uch 	(int (*)(void *, bus_space_handle_t, bus_size_t, bus_size_t,	\
    457        1.1       uch 	bus_space_handle_t *))_bus_space_invalid_access
    458        1.1       uch #define _BUS_SPACE_NO_ALLOC						\
    459        1.1       uch 	(int (*)(void *, bus_addr_t, bus_addr_t, bus_size_t, bus_size_t,\
    460        1.1       uch 	 bus_size_t, int, bus_addr_t *,	bus_space_handle_t *))		\
    461        1.1       uch 	_bus_space_invalid_access
    462        1.1       uch #define _BUS_SPACE_NO_FREE						\
    463        1.1       uch 	(void (*)(void *, bus_space_handle_t, bus_size_t))		\
    464        1.1       uch 	_bus_space_invalid_access
    465        1.1       uch #define _BUS_SPACE_NO_VADDR						\
    466        1.1       uch 	(void *(*)(void *, bus_space_handle_t))_bus_space_invalid_access
    467        1.1       uch #define _BUS_SPACE_NO_READ(BYTES, BITS)					\
    468        1.1       uch 	(u_int##BITS##_t (*)(void *, bus_space_handle_t, bus_size_t))	\
    469        1.1       uch 	_bus_space_invalid_access
    470        1.1       uch #define _BUS_SPACE_NO_READ_MULTI(BYTES, BITS)				\
    471        1.1       uch 	(void (*)(void *, bus_space_handle_t, bus_size_t,		\
    472        1.1       uch 	u_int##BITS##_t *, bus_size_t))_bus_space_invalid_access
    473        1.1       uch #define _BUS_SPACE_NO_READ_REGION(BYTES, BITS)				\
    474        1.1       uch 	(void (*)(void *, bus_space_handle_t, bus_size_t,		\
    475        1.1       uch 	u_int##BITS##_t *, bus_size_t))_bus_space_invalid_access
    476        1.1       uch #define _BUS_SPACE_NO_WRITE(BYTES, BITS)				\
    477        1.1       uch 	(void (*)(void *, bus_space_handle_t, bus_size_t,		\
    478        1.1       uch 	u_int##BITS##_t))_bus_space_invalid_access
    479        1.1       uch #define _BUS_SPACE_NO_WRITE_MULTI(BYTES, BITS)				\
    480        1.1       uch 	(void (*)(void *, bus_space_handle_t, bus_size_t,		\
    481        1.1       uch 	const u_int##BITS##_t *, bus_size_t))_bus_space_invalid_access
    482        1.1       uch #define _BUS_SPACE_NO_WRITE_REGION(BYTES, BITS)				\
    483        1.1       uch 	(void (*)(void *, bus_space_handle_t, bus_size_t,		\
    484        1.1       uch 	const u_int##BITS##_t *, bus_size_t))_bus_space_invalid_access
    485        1.1       uch #define _BUS_SPACE_NO_SET_MULTI(BYTES, BITS)				\
    486        1.1       uch 	(void (*)(void *, bus_space_handle_t, bus_size_t,		\
    487        1.1       uch 	u_int##BITS##_t, bus_size_t))_bus_space_invalid_access
    488        1.1       uch #define _BUS_SPACE_NO_SET_REGION(BYTES, BITS)				\
    489        1.1       uch 	(void (*)(void *, bus_space_handle_t, bus_size_t,		\
    490        1.1       uch 	u_int##BITS##_t, bus_size_t))_bus_space_invalid_access
    491        1.1       uch #define _BUS_SPACE_NO_COPY_REGION(BYTES, BITS)				\
    492        1.1       uch 	(void (*)(void *, bus_space_handle_t, bus_size_t,		\
    493        1.1       uch 	bus_space_handle_t, bus_size_t, bus_size_t))_bus_space_invalid_access
    494        1.1       uch 
    495        1.1       uch void _bus_space_invalid_access(void);
    496        1.1       uch #endif /* _PLAYSTATION2_BUS_SPACE_PRIVATE */
    497        1.1       uch 
    498        1.1       uch #define	__pbs_c(a,b)		__CONCAT(a,b)
    499        1.1       uch #define	__pbs_opname(op,size)	__pbs_c(__pbs_c(__pbs_c(pbs_,op),_),size)
    500        1.1       uch 
    501        1.1       uch #define	__pbs_rs(sz, tn, t, h, o)					\
    502        1.1       uch 	(__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"),		\
    503        1.1       uch 	 (*(t)->__pbs_opname(r,sz))((t)->pbs_cookie, h, o))
    504        1.1       uch 
    505        1.1       uch #define	__pbs_ws(sz, tn, t, h, o, v)					\
    506        1.1       uch ({									\
    507        1.1       uch 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr");		\
    508        1.1       uch 	(*(t)->__pbs_opname(w,sz))((t)->pbs_cookie, h, o, v);		\
    509        1.1       uch })
    510        1.1       uch 
    511        1.1       uch #define	__pbs_nonsingle(type, sz, tn, t, h, o, a, c)			\
    512        1.1       uch ({									\
    513        1.1       uch 	__BUS_SPACE_ADDRESS_SANITY((a), tn, "buffer");			\
    514        1.1       uch 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr");		\
    515        1.1       uch 	(*(t)->__pbs_opname(type,sz))((t)->pbs_cookie, h, o, a, c);	\
    516        1.1       uch })
    517        1.1       uch 
    518        1.1       uch #define	__pbs_set(type, sz, tn, t, h, o, v, c)				\
    519        1.1       uch ({									\
    520        1.1       uch 	__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr");		\
    521        1.1       uch 	(*(t)->__pbs_opname(type,sz))((t)->pbs_cookie, h, o, v, c);	\
    522        1.1       uch })
    523        1.1       uch 
    524        1.1       uch #define	__pbs_copy(sz, tn, t, h1, o1, h2, o2, cnt)			\
    525        1.1       uch ({									\
    526        1.1       uch 	__BUS_SPACE_ADDRESS_SANITY((h1) + (o1), tn, "bus addr 1");	\
    527        1.1       uch 	__BUS_SPACE_ADDRESS_SANITY((h2) + (o2), tn, "bus addr 2");	\
    528        1.1       uch 	(*(t)->__pbs_opname(c,sz))((t)->pbs_cookie, h1, o1, h2, o2, cnt); \
    529        1.1       uch })
    530        1.1       uch 
    531        1.1       uch /*
    532        1.1       uch  * Create default bus_space tag.
    533        1.1       uch  */
    534        1.1       uch bus_space_tag_t bus_space_create(bus_space_tag_t, const char *, bus_addr_t,
    535        1.1       uch     bus_size_t);
    536        1.1       uch void bus_space_destroy(bus_space_tag_t);
    537        1.1       uch 
    538        1.1       uch /*
    539        1.1       uch  * Mapping and unmapping operations.
    540        1.1       uch  */
    541        1.1       uch #define	bus_space_map(t, a, s, f, hp)					\
    542        1.1       uch 	(*(t)->pbs_map)((t)->pbs_cookie, (a), (s), (f), (hp))
    543        1.1       uch #define	bus_space_unmap(t, h, s)					\
    544        1.1       uch 	(*(t)->pbs_unmap)((t)->pbs_cookie, (h), (s))
    545        1.1       uch #define	bus_space_subregion(t, h, o, s, hp)				\
    546        1.1       uch 	(*(t)->pbs_subregion)((t)->pbs_cookie, (h), (o), (s), (hp))
    547        1.1       uch 
    548        1.1       uch #endif /* _KERNEL */
    549        1.1       uch 
    550        1.1       uch #define	BUS_SPACE_MAP_CACHEABLE		0x01
    551        1.1       uch #define	BUS_SPACE_MAP_LINEAR		0x02
    552        1.1       uch #define	BUS_SPACE_MAP_PREFETCHABLE     	0x04
    553        1.1       uch 
    554        1.1       uch #ifdef _KERNEL
    555        1.1       uch /*
    556        1.1       uch  * Allocation and deallocation operations.
    557        1.1       uch  */
    558        1.1       uch #define	bus_space_alloc(t, rs, re, s, a, b, f, ap, hp)			\
    559        1.1       uch 	(*(t)->pbs_alloc)((t)->pbs_cookie, (rs), (re), (s), (a), (b),	\
    560        1.1       uch 	    (f), (ap), (hp))
    561        1.1       uch #define	bus_space_free(t, h, s)						\
    562        1.1       uch 	(*(t)->pbs_free)((t)->pbs_cookie, (h), (s))
    563        1.1       uch 
    564        1.1       uch /*
    565        1.1       uch  * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
    566        1.1       uch  */
    567        1.1       uch #define bus_space_vaddr(t, h)						\
    568        1.1       uch 	(*(t)->pbs_vaddr)((t)->pbs_cookie, (h))
    569        1.1       uch 
    570        1.1       uch /*
    571        1.1       uch  * Bus barrier operations.  The playstation2 does not currently require
    572        1.1       uch  * barriers, but we must provide the flags to MI code.
    573        1.1       uch  */
    574        1.1       uch #define	bus_space_barrier(t, h, o, l, f)				\
    575        1.1       uch ({									\
    576        1.1       uch 	_wbflush();							\
    577        1.1       uch })
    578        1.1       uch 
    579        1.1       uch 
    580        1.1       uch #define	BUS_SPACE_BARRIER_READ	0x01
    581        1.1       uch #define	BUS_SPACE_BARRIER_WRITE	0x02
    582        1.1       uch 
    583        1.1       uch 
    584        1.1       uch /*
    585        1.1       uch  * Bus read (single) operations.
    586        1.1       uch  */
    587        1.1       uch #define	bus_space_read_1(t, h, o)	__pbs_rs(1,u_int8_t,(t),(h),(o))
    588        1.1       uch #define	bus_space_read_2(t, h, o)	__pbs_rs(2,u_int16_t,(t),(h),(o))
    589        1.1       uch #define	bus_space_read_4(t, h, o)	__pbs_rs(4,u_int32_t,(t),(h),(o))
    590        1.1       uch #define	bus_space_read_8(t, h, o)	__pbs_rs(8,u_int64_t,(t),(h),(o))
    591        1.1       uch 
    592        1.1       uch 
    593        1.1       uch /*
    594        1.1       uch  * Bus read multiple operations.
    595        1.1       uch  */
    596        1.1       uch #define	bus_space_read_multi_1(t, h, o, a, c)				\
    597        1.1       uch 	__pbs_nonsingle(rm,1,u_int8_t,(t),(h),(o),(a),(c))
    598        1.1       uch #define	bus_space_read_multi_2(t, h, o, a, c)				\
    599        1.1       uch 	__pbs_nonsingle(rm,2,u_int16_t,(t),(h),(o),(a),(c))
    600        1.1       uch #define	bus_space_read_multi_4(t, h, o, a, c)				\
    601        1.1       uch 	__pbs_nonsingle(rm,4,u_int32_t,(t),(h),(o),(a),(c))
    602        1.1       uch #define	bus_space_read_multi_8(t, h, o, a, c)				\
    603        1.1       uch 	__pbs_nonsingle(rm,8,u_int64_t,(t),(h),(o),(a),(c))
    604        1.1       uch 
    605        1.1       uch 
    606        1.1       uch /*
    607        1.1       uch  * Bus read region operations.
    608        1.1       uch  */
    609        1.1       uch #define	bus_space_read_region_1(t, h, o, a, c)				\
    610        1.1       uch 	__pbs_nonsingle(rr,1,u_int8_t,(t),(h),(o),(a),(c))
    611        1.1       uch #define	bus_space_read_region_2(t, h, o, a, c)				\
    612        1.1       uch 	__pbs_nonsingle(rr,2,u_int16_t,(t),(h),(o),(a),(c))
    613        1.1       uch #define	bus_space_read_region_4(t, h, o, a, c)				\
    614        1.1       uch 	__pbs_nonsingle(rr,4,u_int32_t,(t),(h),(o),(a),(c))
    615        1.1       uch #define	bus_space_read_region_8(t, h, o, a, c)				\
    616        1.1       uch 	__pbs_nonsingle(rr,8,u_int64_t,(t),(h),(o),(a),(c))
    617        1.1       uch 
    618        1.1       uch 
    619        1.1       uch /*
    620        1.1       uch  * Bus write (single) operations.
    621        1.1       uch  */
    622        1.1       uch #define	bus_space_write_1(t, h, o, v)	__pbs_ws(1,u_int8_t,(t),(h),(o),(v))
    623        1.1       uch #define	bus_space_write_2(t, h, o, v)	__pbs_ws(2,u_int16_t,(t),(h),(o),(v))
    624        1.1       uch #define	bus_space_write_4(t, h, o, v)	__pbs_ws(4,u_int32_t,(t),(h),(o),(v))
    625        1.1       uch #define	bus_space_write_8(t, h, o, v)	__pbs_ws(8,u_int64_t,(t),(h),(o),(v))
    626        1.1       uch 
    627        1.1       uch 
    628        1.1       uch /*
    629        1.1       uch  * Bus write multiple operations.
    630        1.1       uch  */
    631        1.1       uch #define	bus_space_write_multi_1(t, h, o, a, c)				\
    632        1.1       uch 	__pbs_nonsingle(wm,1,u_int8_t,(t),(h),(o),(a),(c))
    633        1.1       uch #define	bus_space_write_multi_2(t, h, o, a, c)				\
    634        1.1       uch 	__pbs_nonsingle(wm,2,u_int16_t,(t),(h),(o),(a),(c))
    635        1.1       uch #define	bus_space_write_multi_4(t, h, o, a, c)				\
    636        1.1       uch 	__pbs_nonsingle(wm,4,u_int32_t,(t),(h),(o),(a),(c))
    637        1.1       uch #define	bus_space_write_multi_8(t, h, o, a, c)				\
    638        1.1       uch 	__pbs_nonsingle(wm,8,u_int64_t,(t),(h),(o),(a),(c))
    639        1.1       uch 
    640        1.1       uch 
    641        1.1       uch /*
    642        1.1       uch  * Bus write region operations.
    643        1.1       uch  */
    644        1.1       uch #define	bus_space_write_region_1(t, h, o, a, c)				\
    645        1.1       uch 	__pbs_nonsingle(wr,1,u_int8_t,(t),(h),(o),(a),(c))
    646        1.1       uch #define	bus_space_write_region_2(t, h, o, a, c)				\
    647        1.1       uch 	__pbs_nonsingle(wr,2,u_int16_t,(t),(h),(o),(a),(c))
    648        1.1       uch #define	bus_space_write_region_4(t, h, o, a, c)				\
    649        1.1       uch 	__pbs_nonsingle(wr,4,u_int32_t,(t),(h),(o),(a),(c))
    650        1.1       uch #define	bus_space_write_region_8(t, h, o, a, c)				\
    651        1.1       uch 	__pbs_nonsingle(wr,8,u_int64_t,(t),(h),(o),(a),(c))
    652        1.1       uch 
    653        1.1       uch 
    654        1.1       uch /*
    655        1.1       uch  * Set multiple operations.
    656        1.1       uch  */
    657        1.1       uch #define	bus_space_set_multi_1(t, h, o, v, c)				\
    658        1.1       uch 	__pbs_set(sm,1,u_int8_t,(t),(h),(o),(v),(c))
    659        1.1       uch #define	bus_space_set_multi_2(t, h, o, v, c)				\
    660        1.1       uch 	__pbs_set(sm,2,u_int16_t,(t),(h),(o),(v),(c))
    661        1.1       uch #define	bus_space_set_multi_4(t, h, o, v, c)				\
    662        1.1       uch 	__pbs_set(sm,4,u_int32_t,(t),(h),(o),(v),(c))
    663        1.1       uch #define	bus_space_set_multi_8(t, h, o, v, c)				\
    664        1.1       uch 	__pbs_set(sm,8,u_int64_t,(t),(h),(o),(v),(c))
    665        1.1       uch 
    666        1.1       uch 
    667        1.1       uch /*
    668        1.1       uch  * Set region operations.
    669        1.1       uch  */
    670        1.1       uch #define	bus_space_set_region_1(t, h, o, v, c)				\
    671        1.1       uch 	__pbs_set(sr,1,u_int8_t,(t),(h),(o),(v),(c))
    672        1.1       uch #define	bus_space_set_region_2(t, h, o, v, c)				\
    673        1.1       uch 	__pbs_set(sr,2,u_int16_t,(t),(h),(o),(v),(c))
    674        1.1       uch #define	bus_space_set_region_4(t, h, o, v, c)				\
    675        1.1       uch 	__pbs_set(sr,4,u_int32_t,(t),(h),(o),(v),(c))
    676        1.1       uch #define	bus_space_set_region_8(t, h, o, v, c)				\
    677        1.1       uch 	__pbs_set(sr,8,u_int64_t,(t),(h),(o),(v),(c))
    678        1.1       uch 
    679        1.1       uch 
    680        1.1       uch /*
    681        1.1       uch  * Copy region operations.
    682        1.1       uch  */
    683        1.1       uch #define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)			\
    684        1.1       uch 	__pbs_copy(1, u_int8_t, (t), (h1), (o1), (h2), (o2), (c))
    685        1.1       uch #define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)			\
    686        1.1       uch 	__pbs_copy(2, u_int16_t, (t), (h1), (o1), (h2), (o2), (c))
    687        1.1       uch #define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)			\
    688        1.1       uch 	__pbs_copy(4, u_int32_t, (t), (h1), (o1), (h2), (o2), (c))
    689        1.1       uch #define	bus_space_copy_region_8(t, h1, o1, h2, o2, c)			\
    690        1.1       uch 	__pbs_copy(8, u_int64_t, (t), (h1), (o1), (h2), (o2), (c))
    691        1.1       uch 
    692        1.1       uch /*
    693        1.1       uch  * Bus stream operations--defined in terms of non-stream counterparts
    694        1.1       uch  */
    695        1.1       uch #define __BUS_SPACE_HAS_STREAM_METHODS 1
    696        1.1       uch #define bus_space_read_stream_1 bus_space_read_1
    697        1.1       uch #define bus_space_read_stream_2 bus_space_read_2
    698        1.1       uch #define bus_space_read_stream_4 bus_space_read_4
    699        1.1       uch #define	bus_space_read_stream_8 bus_space_read_8
    700        1.1       uch #define bus_space_read_multi_stream_1 bus_space_read_multi_1
    701        1.1       uch #define bus_space_read_multi_stream_2 bus_space_read_multi_2
    702        1.1       uch #define bus_space_read_multi_stream_4 bus_space_read_multi_4
    703        1.1       uch #define	bus_space_read_multi_stream_8 bus_space_read_multi_8
    704        1.1       uch #define bus_space_read_region_stream_1 bus_space_read_region_1
    705        1.1       uch #define bus_space_read_region_stream_2 bus_space_read_region_2
    706        1.1       uch #define bus_space_read_region_stream_4 bus_space_read_region_4
    707        1.1       uch #define	bus_space_read_region_stream_8 bus_space_read_region_8
    708        1.1       uch #define bus_space_write_stream_1 bus_space_write_1
    709        1.1       uch #define bus_space_write_stream_2 bus_space_write_2
    710        1.1       uch #define bus_space_write_stream_4 bus_space_write_4
    711        1.1       uch #define	bus_space_write_stream_8 bus_space_write_8
    712        1.1       uch #define bus_space_write_multi_stream_1 bus_space_write_multi_1
    713        1.1       uch #define bus_space_write_multi_stream_2 bus_space_write_multi_2
    714        1.1       uch #define bus_space_write_multi_stream_4 bus_space_write_multi_4
    715        1.1       uch #define	bus_space_write_multi_stream_8 bus_space_write_multi_8
    716        1.1       uch #define bus_space_write_region_stream_1 bus_space_write_region_1
    717        1.1       uch #define bus_space_write_region_stream_2 bus_space_write_region_2
    718        1.1       uch #define bus_space_write_region_stream_4 bus_space_write_region_4
    719        1.1       uch #define	bus_space_write_region_stream_8	bus_space_write_region_8
    720        1.1       uch 
    721        1.1       uch #endif /* _KERNEL */
    722        1.1       uch 
    723        1.1       uch /*
    724        1.1       uch  * Flags used in various bus DMA methods.
    725        1.1       uch  */
    726        1.1       uch #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
    727        1.1       uch #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
    728        1.1       uch #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
    729        1.1       uch #define	BUS_DMA_COHERENT	0x004	/* hint: map memory DMA coherent */
    730        1.1       uch #define	BUS_DMA_STREAMING	0x008	/* hint: sequential, unidirectional */
    731        1.1       uch #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
    732        1.1       uch #define	BUS_DMA_BUS2		0x020
    733        1.1       uch #define	BUS_DMA_BUS3		0x040
    734        1.1       uch #define	BUS_DMA_BUS4		0x080
    735        1.1       uch #define	BUS_DMA_READ		0x100	/* mapping is device -> memory only */
    736        1.1       uch #define	BUS_DMA_WRITE		0x200	/* mapping is memory -> device only */
    737        1.4      kent #define	BUS_DMA_NOCACHE		0x400	/* hint: map non-cached memory */
    738        1.1       uch 
    739        1.2    simonb #define	PLAYSTATION2_DMAMAP_COHERENT	0x10000	/* no cache flush necessary on sync */
    740        1.1       uch 
    741        1.1       uch /* Forwards needed by prototypes below. */
    742        1.1       uch struct mbuf;
    743        1.1       uch struct uio;
    744        1.1       uch 
    745        1.1       uch /*
    746        1.1       uch  * Operations performed by bus_dmamap_sync().
    747        1.1       uch  */
    748        1.1       uch #define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
    749        1.1       uch #define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
    750        1.1       uch #define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
    751        1.1       uch #define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
    752        1.1       uch 
    753        1.1       uch typedef struct playstation2_bus_dma_tag		*bus_dma_tag_t;
    754        1.1       uch typedef struct playstation2_bus_dmamap		*bus_dmamap_t;
    755        1.5      fvdl 
    756        1.5      fvdl #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
    757        1.1       uch 
    758        1.1       uch /*
    759        1.1       uch  *	bus_dma_segment_t
    760        1.1       uch  *
    761        1.1       uch  *	Describes a single contiguous DMA transaction.  Values
    762        1.1       uch  *	are suitable for programming into DMA registers.
    763        1.1       uch  */
    764        1.1       uch struct playstation2_bus_dma_segment {
    765        1.1       uch 	bus_addr_t	ds_addr;	/* DMA address */
    766        1.1       uch 	bus_size_t	ds_len;		/* length of transfer */
    767        1.1       uch 	bus_addr_t	_ds_vaddr;	/* virtual address, 0 if invalid */
    768        1.1       uch };
    769        1.1       uch typedef struct playstation2_bus_dma_segment	bus_dma_segment_t;
    770        1.1       uch 
    771        1.1       uch /*
    772        1.1       uch  *	bus_dma_tag_t
    773        1.1       uch  *
    774        1.1       uch  *	A machine-dependent opaque type describing the implementation of
    775        1.1       uch  *	DMA for a given bus.
    776        1.1       uch  */
    777        1.1       uch 
    778        1.1       uch struct playstation2_bus_dma_tag {
    779        1.1       uch 	/*
    780        1.1       uch 	 * DMA mapping methods.
    781        1.1       uch 	 */
    782        1.1       uch 	int	(*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
    783        1.1       uch 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
    784        1.1       uch 	void	(*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
    785        1.1       uch 	int	(*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
    786        1.1       uch 		    bus_size_t, struct proc *, int);
    787        1.1       uch 	int	(*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
    788        1.1       uch 		    struct mbuf *, int);
    789        1.1       uch 	int	(*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
    790        1.1       uch 		    struct uio *, int);
    791        1.1       uch 	int	(*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
    792        1.1       uch 		    bus_dma_segment_t *, int, bus_size_t, int);
    793        1.1       uch 	void	(*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
    794        1.1       uch 	void	(*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
    795        1.1       uch 		    bus_addr_t, bus_size_t, int);
    796        1.1       uch 
    797        1.1       uch 	/*
    798        1.1       uch 	 * DMA memory utility functions.
    799        1.1       uch 	 */
    800        1.1       uch 	int	(*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
    801        1.1       uch 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
    802        1.1       uch 	void	(*_dmamem_free)(bus_dma_tag_t,
    803        1.1       uch 		    bus_dma_segment_t *, int);
    804        1.1       uch 	int	(*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
    805       1.11  christos 		    int, size_t, void **, int);
    806       1.11  christos 	void	(*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
    807        1.1       uch 	paddr_t	(*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
    808        1.1       uch 		    int, off_t, int, int);
    809        1.1       uch 
    810        1.1       uch 	/*
    811        1.1       uch 	 * DMA controller private.
    812        1.1       uch 	 */
    813        1.1       uch 	void	*_dmachip_cookie;
    814        1.1       uch };
    815        1.1       uch 
    816        1.1       uch #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
    817        1.1       uch 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
    818        1.1       uch #define	bus_dmamap_destroy(t, p)				\
    819        1.1       uch 	(*(t)->_dmamap_destroy)((t), (p))
    820        1.1       uch #define	bus_dmamap_load(t, m, b, s, p, f)			\
    821        1.1       uch 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
    822        1.1       uch #define	bus_dmamap_load_mbuf(t, m, b, f)			\
    823        1.1       uch 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
    824        1.1       uch #define	bus_dmamap_load_uio(t, m, u, f)				\
    825        1.1       uch 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
    826        1.1       uch #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
    827        1.1       uch 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
    828        1.1       uch #define	bus_dmamap_unload(t, p)					\
    829        1.1       uch 	(*(t)->_dmamap_unload)((t), (p))
    830        1.1       uch #define	bus_dmamap_sync(t, p, o, l, ops)			\
    831        1.1       uch 	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
    832        1.1       uch 
    833        1.1       uch #define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
    834        1.1       uch 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
    835        1.1       uch #define	bus_dmamem_free(t, sg, n)				\
    836        1.1       uch 	(*(t)->_dmamem_free)((t), (sg), (n))
    837        1.1       uch #define	bus_dmamem_map(t, sg, n, s, k, f)			\
    838        1.1       uch 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
    839        1.1       uch #define	bus_dmamem_unmap(t, k, s)				\
    840        1.1       uch 	(*(t)->_dmamem_unmap)((t), (k), (s))
    841        1.1       uch #define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
    842        1.1       uch 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
    843        1.1       uch 
    844       1.10       mrg #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
    845       1.10       mrg #define bus_dmatag_destroy(t)
    846       1.10       mrg 
    847        1.1       uch /*
    848        1.1       uch  *	bus_dmamap_t
    849        1.1       uch  *
    850        1.1       uch  *	Describes a DMA mapping.
    851        1.1       uch  */
    852        1.1       uch struct playstation2_bus_dmamap {
    853        1.1       uch 	/*
    854        1.1       uch 	 * PRIVATE MEMBERS: not for use my machine-independent code.
    855        1.1       uch 	 */
    856        1.1       uch 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
    857        1.1       uch 	int		_dm_segcnt;	/* number of segs this map can map */
    858        1.6      matt 	bus_size_t	_dm_maxmaxsegsz; /* fixed largest possible segment */
    859        1.1       uch 	bus_size_t	_dm_boundary;	/* don't cross this */
    860        1.1       uch 	int		_dm_flags;	/* misc. flags */
    861        1.1       uch 
    862        1.1       uch 	/*
    863        1.1       uch 	 * PUBLIC MEMBERS: these are used by machine-independent code.
    864        1.1       uch 	 */
    865        1.6      matt 	bus_size_t	dm_maxsegsz;	/* largest possible segment */
    866        1.1       uch 	bus_size_t	dm_mapsize;	/* size of the mapping */
    867        1.1       uch 	int		dm_nsegs;	/* # valid segments in mapping */
    868        1.1       uch 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
    869        1.1       uch };
    870        1.1       uch 
    871        1.1       uch #ifdef _PLAYSTATION2_BUS_DMA_PRIVATE
    872        1.1       uch int	_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
    873        1.1       uch 	    bus_size_t, int, bus_dmamap_t *);
    874        1.1       uch void	_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
    875        1.1       uch int	_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
    876        1.1       uch 	    bus_size_t, struct proc *, int);
    877        1.1       uch int	_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
    878        1.1       uch 	    struct mbuf *, int);
    879        1.1       uch int	_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
    880        1.1       uch 	    struct uio *, int);
    881        1.1       uch int	_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
    882        1.1       uch 	    bus_dma_segment_t *, int, bus_size_t, int);
    883        1.1       uch void	_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
    884        1.1       uch void	_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    885        1.1       uch 	    bus_size_t, int);
    886        1.1       uch 
    887        1.1       uch int	_bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
    888        1.1       uch 	    bus_size_t alignment, bus_size_t boundary,
    889        1.1       uch 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
    890        1.1       uch void	_bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
    891        1.1       uch 	    int nsegs);
    892        1.1       uch int	_bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
    893       1.11  christos 	    int nsegs, size_t size, void **kvap, int flags);
    894       1.11  christos void	_bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
    895        1.1       uch 	    size_t size);
    896        1.1       uch paddr_t	_bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
    897        1.1       uch 	    int nsegs, off_t off, int prot, int flags);
    898        1.1       uch 
    899        1.1       uch int	_bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
    900        1.1       uch 	    bus_size_t alignment, bus_size_t boundary,
    901        1.1       uch 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
    902        1.1       uch 	    vaddr_t low, vaddr_t high);
    903        1.1       uch 
    904        1.1       uch extern struct playstation2_bus_dma_tag playstation2_default_bus_dma_tag;
    905        1.1       uch #endif /* _PLAYSTATION2_BUS_DMA_PRIVATE */
    906        1.1       uch 
    907        1.1       uch #endif /* _PLAYSTATION2_BUS_H_ */
    908