Home | History | Annotate | Line # | Download | only in include
bus.h revision 1.18.40.1
      1 /*	$NetBSD: bus.h,v 1.18.40.1 2008/06/02 13:22:29 mjf Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #ifndef _NEWSMIPS_BUS_H_
     34 #define _NEWSMIPS_BUS_H_
     35 
     36 #include <mips/locore.h>
     37 
     38 /*
     39  * Utility macros; do not use outside this file.
     40  */
     41 #define	__PB_TYPENAME_PREFIX(BITS)	___CONCAT(uint,BITS)
     42 #define	__PB_TYPENAME(BITS)		___CONCAT(__PB_TYPENAME_PREFIX(BITS),_t)
     43 
     44 /*
     45  * Bus address and size types
     46  */
     47 typedef u_long bus_addr_t;
     48 typedef u_long bus_size_t;
     49 
     50 /*
     51  * Access methods for bus resources and address space.
     52  */
     53 typedef int	bus_space_tag_t;
     54 typedef u_long	bus_space_handle_t;
     55 
     56 /*
     57  *	int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
     58  *	    bus_size_t size, int flags, bus_space_handle_t *bshp);
     59  *
     60  * Map a region of bus space.
     61  */
     62 
     63 #define	BUS_SPACE_MAP_CACHEABLE		0x01
     64 #define	BUS_SPACE_MAP_LINEAR		0x02
     65 #define BUS_SPACE_MAP_PREFETCHABLE	0x04
     66 
     67 int	bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
     68 	    int, bus_space_handle_t *);
     69 
     70 /*
     71  *	void bus_space_unmap(bus_space_tag_t t,
     72  *	     bus_space_handle_t bsh, bus_size_t size);
     73  *
     74  * Unmap a region of bus space.
     75  */
     76 
     77 void	bus_space_unmap (bus_space_tag_t, bus_space_handle_t, bus_size_t);
     78 
     79 /*
     80  *	int bus_space_subregion(bus_space_tag_t t,
     81  *	    bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
     82  *	    bus_space_handle_t *nbshp);
     83  *
     84  * Get a new handle for a subregion of an already-mapped area of bus space.
     85  */
     86 
     87 int	bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
     88 	    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
     89 
     90 /*
     91  *	int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
     92  *	    bus_addr_t rend, bus_size_t size, bus_size_t align,
     93  *	    bus_size_t boundary, int flags, bus_addr_t *addrp,
     94  *	    bus_space_handle_t *bshp);
     95  *
     96  * Allocate a region of bus space.
     97  */
     98 
     99 int	bus_space_alloc (bus_space_tag_t t, bus_addr_t rstart,
    100 	    bus_addr_t rend, bus_size_t size, bus_size_t align,
    101 	    bus_size_t boundary, int cacheable, bus_addr_t *addrp,
    102 	    bus_space_handle_t *bshp);
    103 
    104 /*
    105  *	int bus_space_free (bus_space_tag_t t,
    106  *	    bus_space_handle_t bsh, bus_size_t size);
    107  *
    108  * Free a region of bus space.
    109  */
    110 
    111 void	bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
    112 	    bus_size_t size);
    113 
    114 /*
    115  *	uintN_t bus_space_read_N(bus_space_tag_t tag,
    116  *	    bus_space_handle_t bsh, bus_size_t offset);
    117  *
    118  * Read a 1, 2, 4, or 8 byte quantity from bus space
    119  * described by tag/handle/offset.
    120  */
    121 
    122 #define	bus_space_read_1(t, h, o)					\
    123      ((void) t, (*(volatile uint8_t *)((h) + (o))))
    124 
    125 #define	bus_space_read_2(t, h, o)					\
    126      ((void) t, (*(volatile uint16_t *)((h) + (o))))
    127 
    128 #define	bus_space_read_4(t, h, o)					\
    129      ((void) t, (*(volatile uint32_t *)((h) + (o))))
    130 
    131 #if 0	/* Cause a link error for bus_space_read_8 */
    132 #define	bus_space_read_8(t, h, o)	!!! bus_space_read_8 unimplemented !!!
    133 #endif
    134 
    135 /*
    136  *	void bus_space_read_multi_N(bus_space_tag_t tag,
    137  *	    bus_space_handle_t bsh, bus_size_t offset,
    138  *	    uintN_t *addr, size_t count);
    139  *
    140  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    141  * described by tag/handle/offset and copy into buffer provided.
    142  */
    143 
    144 #define __NEWSMIPS_bus_space_read_multi(BYTES,BITS)			\
    145 static __inline void __CONCAT(bus_space_read_multi_,BYTES)		\
    146 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    147 	__PB_TYPENAME(BITS) *, size_t);					\
    148 									\
    149 static __inline void							\
    150 __CONCAT(bus_space_read_multi_,BYTES)(t, h, o, a, c)			\
    151 	bus_space_tag_t t;						\
    152 	bus_space_handle_t h;						\
    153 	bus_size_t o;							\
    154 	__PB_TYPENAME(BITS) *a;						\
    155 	size_t c;							\
    156 {									\
    157 									\
    158 	while (c--)							\
    159 		*a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o);	\
    160 }
    161 
    162 __NEWSMIPS_bus_space_read_multi(1,8)
    163 __NEWSMIPS_bus_space_read_multi(2,16)
    164 __NEWSMIPS_bus_space_read_multi(4,32)
    165 
    166 #if 0	/* Cause a link error for bus_space_read_multi_8 */
    167 #define	bus_space_read_multi_8	!!! bus_space_read_multi_8 unimplemented !!!
    168 #endif
    169 
    170 #undef __NEWSMIPS_bus_space_read_multi
    171 
    172 /*
    173  *	void bus_space_read_region_N(bus_space_tag_t tag,
    174  *	    bus_space_handle_t bsh, bus_size_t offset,
    175  *	    uintN_t *addr, size_t count);
    176  *
    177  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
    178  * described by tag/handle and starting at `offset' and copy into
    179  * buffer provided.
    180  */
    181 
    182 #define __NEWSMIPS_bus_space_read_region(BYTES,BITS)			\
    183 static __inline void __CONCAT(bus_space_read_region_,BYTES)		\
    184 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    185 	__PB_TYPENAME(BITS) *, size_t);					\
    186 									\
    187 static __inline void							\
    188 __CONCAT(bus_space_read_region_,BYTES)(t, h, o, a, c)			\
    189 	bus_space_tag_t t;						\
    190 	bus_space_handle_t h;						\
    191 	bus_size_t o;							\
    192 	__PB_TYPENAME(BITS) *a;						\
    193 	size_t c;							\
    194 {									\
    195 									\
    196 	while (c--) {							\
    197 		*a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o);	\
    198 		o += BYTES;						\
    199 	}								\
    200 }
    201 
    202 __NEWSMIPS_bus_space_read_region(1,8)
    203 __NEWSMIPS_bus_space_read_region(2,16)
    204 __NEWSMIPS_bus_space_read_region(4,32)
    205 
    206 #if 0	/* Cause a link error for bus_space_read_region_8 */
    207 #define	bus_space_read_region_8	!!! bus_space_read_region_8 unimplemented !!!
    208 #endif
    209 
    210 #undef __NEWSMIPS_bus_space_read_region
    211 
    212 /*
    213  *	void bus_space_write_N(bus_space_tag_t tag,
    214  *	    bus_space_handle_t bsh, bus_size_t offset,
    215  *	    uintN_t value);
    216  *
    217  * Write the 1, 2, 4, or 8 byte value `value' to bus space
    218  * described by tag/handle/offset.
    219  */
    220 
    221 #define	bus_space_write_1(t, h, o, v)					\
    222 do {									\
    223 	(void) t;							\
    224 	*(volatile uint8_t *)((h) + (o)) = (v);			\
    225 } while (0)
    226 
    227 #define	bus_space_write_2(t, h, o, v)					\
    228 do {									\
    229 	(void) t;							\
    230 	*(volatile uint16_t *)((h) + (o)) = (v);			\
    231 } while (0)
    232 
    233 #define	bus_space_write_4(t, h, o, v)					\
    234 do {									\
    235 	(void) t;							\
    236 	*(volatile uint32_t *)((h) + (o)) = (v);			\
    237 } while (0)
    238 
    239 #if 0	/* Cause a link error for bus_space_write_8 */
    240 #define	bus_space_write_8	!!! bus_space_write_8 not implemented !!!
    241 #endif
    242 
    243 /*
    244  *	void bus_space_write_multi_N(bus_space_tag_t tag,
    245  *	    bus_space_handle_t bsh, bus_size_t offset,
    246  *	    const uintN_t *addr, size_t count);
    247  *
    248  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
    249  * provided to bus space described by tag/handle/offset.
    250  */
    251 
    252 #define __NEWSMIPS_bus_space_write_multi(BYTES,BITS)			\
    253 static __inline void __CONCAT(bus_space_write_multi_,BYTES)		\
    254 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    255 	const __PB_TYPENAME(BITS) *, size_t);				\
    256 									\
    257 static __inline void							\
    258 __CONCAT(bus_space_write_multi_,BYTES)(t, h, o, a, c)			\
    259 	bus_space_tag_t t;						\
    260 	bus_space_handle_t h;						\
    261 	bus_size_t o;							\
    262 	const __PB_TYPENAME(BITS) *a;					\
    263 	size_t c;							\
    264 {									\
    265 									\
    266 	while (c--)							\
    267 		__CONCAT(bus_space_write_,BYTES)(t, h, o, *a++);	\
    268 }
    269 
    270 __NEWSMIPS_bus_space_write_multi(1,8)
    271 __NEWSMIPS_bus_space_write_multi(2,16)
    272 __NEWSMIPS_bus_space_write_multi(4,32)
    273 
    274 #if 0	/* Cause a link error for bus_space_write_8 */
    275 #define	bus_space_write_multi_8(t, h, o, a, c)				\
    276 			!!! bus_space_write_multi_8 unimplimented !!!
    277 #endif
    278 
    279 #undef __NEWSMIPS_bus_space_write_multi
    280 
    281 /*
    282  *	void bus_space_write_region_N(bus_space_tag_t tag,
    283  *	    bus_space_handle_t bsh, bus_size_t offset,
    284  *	    const uintN_t *addr, size_t count);
    285  *
    286  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
    287  * to bus space described by tag/handle starting at `offset'.
    288  */
    289 
    290 #define __NEWSMIPS_bus_space_write_region(BYTES,BITS)			\
    291 static __inline void __CONCAT(bus_space_write_region_,BYTES)		\
    292 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    293 	const __PB_TYPENAME(BITS) *, size_t);				\
    294 									\
    295 static __inline void							\
    296 __CONCAT(bus_space_write_region_,BYTES)(t, h, o, a, c)			\
    297 	bus_space_tag_t t;						\
    298 	bus_space_handle_t h;						\
    299 	bus_size_t o;							\
    300 	const __PB_TYPENAME(BITS) *a;					\
    301 	size_t c;							\
    302 {									\
    303 									\
    304 	while (c--) {							\
    305 		__CONCAT(bus_space_write_,BYTES)(t, h, o, *a++);	\
    306 		o += BYTES;						\
    307 	}								\
    308 }
    309 
    310 __NEWSMIPS_bus_space_write_region(1,8)
    311 __NEWSMIPS_bus_space_write_region(2,16)
    312 __NEWSMIPS_bus_space_write_region(4,32)
    313 
    314 #if 0	/* Cause a link error for bus_space_write_region_8 */
    315 #define	bus_space_write_region_8					\
    316 			!!! bus_space_write_region_8 unimplemented !!!
    317 #endif
    318 
    319 #undef __NEWSMIPS_bus_space_write_region
    320 
    321 /*
    322  *	void bus_space_set_multi_N(bus_space_tag_t tag,
    323  *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
    324  *	    size_t count);
    325  *
    326  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
    327  * by tag/handle/offset `count' times.
    328  */
    329 
    330 #define __NEWSMIPS_bus_space_set_multi(BYTES,BITS)			\
    331 static __inline void __CONCAT(bus_space_set_multi_,BYTES)		\
    332 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    333 	__PB_TYPENAME(BITS), size_t);					\
    334 									\
    335 static __inline void							\
    336 __CONCAT(bus_space_set_multi_,BYTES)(t, h, o, v, c)			\
    337 	bus_space_tag_t t;						\
    338 	bus_space_handle_t h;						\
    339 	bus_size_t o;							\
    340 	__PB_TYPENAME(BITS) v;						\
    341 	size_t c;							\
    342 {									\
    343 									\
    344 	while (c--)							\
    345 		__CONCAT(bus_space_write_,BYTES)(t, h, o, v);		\
    346 }
    347 
    348 __NEWSMIPS_bus_space_set_multi(1,8)
    349 __NEWSMIPS_bus_space_set_multi(2,16)
    350 __NEWSMIPS_bus_space_set_multi(4,32)
    351 
    352 #if 0	/* Cause a link error for bus_space_set_multi_8 */
    353 #define	bus_space_set_multi_8						\
    354 			!!! bus_space_set_multi_8 unimplemented !!!
    355 #endif
    356 
    357 #undef __NEWSMIPS_bus_space_set_multi
    358 
    359 /*
    360  *	void bus_space_set_region_N(bus_space_tag_t tag,
    361  *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
    362  *	    size_t count);
    363  *
    364  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
    365  * by tag/handle starting at `offset'.
    366  */
    367 
    368 #define __NEWSMIPS_bus_space_set_region(BYTES,BITS)			\
    369 static __inline void __CONCAT(bus_space_set_region_,BYTES)		\
    370 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
    371 	__PB_TYPENAME(BITS), size_t);					\
    372 									\
    373 static __inline void							\
    374 __CONCAT(bus_space_set_region_,BYTES)(t, h, o, v, c)			\
    375 	bus_space_tag_t t;						\
    376 	bus_space_handle_t h;						\
    377 	bus_size_t o;							\
    378 	__PB_TYPENAME(BITS) v;						\
    379 	size_t c;							\
    380 {									\
    381 									\
    382 	while (c--) {							\
    383 		__CONCAT(bus_space_write_,BYTES)(t, h, o, v);		\
    384 		o += BYTES;						\
    385 	}								\
    386 }
    387 
    388 __NEWSMIPS_bus_space_set_region(1,8)
    389 __NEWSMIPS_bus_space_set_region(2,16)
    390 __NEWSMIPS_bus_space_set_region(4,32)
    391 
    392 #if 0	/* Cause a link error for bus_space_set_region_8 */
    393 #define	bus_space_set_region_8						\
    394 			!!! bus_space_set_region_8 unimplemented !!!
    395 #endif
    396 
    397 #undef __NEWSMIPS_bus_space_set_region
    398 
    399 /*
    400  *	void bus_space_copy_region_N(bus_space_tag_t tag,
    401  *	    bus_space_handle_t bsh1, bus_size_t off1,
    402  *	    bus_space_handle_t bsh2, bus_size_t off2,
    403  *	    bus_size_t count);
    404  *
    405  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
    406  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
    407  */
    408 
    409 #define	__NEWSMIPS_copy_region(BYTES)					\
    410 static __inline void __CONCAT(bus_space_copy_region_,BYTES)		\
    411 	(bus_space_tag_t,						\
    412 	    bus_space_handle_t bsh1, bus_size_t off1,			\
    413 	    bus_space_handle_t bsh2, bus_size_t off2,			\
    414 	    bus_size_t count);						\
    415 									\
    416 static __inline void							\
    417 __CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c)		\
    418 	bus_space_tag_t t;						\
    419 	bus_space_handle_t h1, h2;					\
    420 	bus_size_t o1, o2, c;						\
    421 {									\
    422 	bus_size_t o;							\
    423 									\
    424 	if ((h1 + o1) >= (h2 + o2)) {					\
    425 		/* src after dest: copy forward */			\
    426 		for (o = 0; c != 0; c--, o += BYTES)			\
    427 			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
    428 			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
    429 	} else {							\
    430 		/* dest after src: copy backwards */			\
    431 		for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)	\
    432 			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
    433 			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
    434 	}								\
    435 }
    436 
    437 __NEWSMIPS_copy_region(1)
    438 __NEWSMIPS_copy_region(2)
    439 __NEWSMIPS_copy_region(4)
    440 
    441 #if 0	/* Cause a link error for bus_space_copy_region_8 */
    442 #define	bus_space_copy_region_8						\
    443 			!!! bus_space_copy_region_8 unimplemented !!!
    444 #endif
    445 
    446 #undef __NEWSMIPS_copy_region
    447 
    448 /*
    449  * Bus read/write barrier methods.
    450  *
    451  *	void bus_space_barrier(bus_space_tag_t tag,
    452  *	    bus_space_handle_t bsh, bus_size_t offset,
    453  *	    bus_size_t len, int flags);
    454  *
    455  * On the MIPS, we just flush the write buffer.
    456  */
    457 #define	bus_space_barrier(t, h, o, l, f)	\
    458 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f),	\
    459 	 wbflush()))
    460 #define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
    461 #define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
    462 
    463 #undef __PB_TYPENAME_PREFIX
    464 #undef __PB_TYPENAME
    465 
    466 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
    467 
    468 /*
    469  * Flags used in various bus DMA methods.
    470  */
    471 #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
    472 #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
    473 #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
    474 #define	BUS_DMA_COHERENT	0x004	/* hint: map memory DMA coherent */
    475 #define	BUS_DMA_STREAMING	0x008	/* hint: sequential, unidirectional */
    476 #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
    477 #define	BUS_DMA_BUS2		0x020
    478 #define	BUS_DMA_BUS3		0x040
    479 #define	BUS_DMA_BUS4		0x080
    480 #define	BUS_DMA_READ		0x100	/* mapping is device -> memory only */
    481 #define	BUS_DMA_WRITE		0x200	/* mapping is memory -> device only */
    482 #define	BUS_DMA_NOCACHE		0x400	/* hint: map non-cached memory */
    483 
    484 #define	NEWSMIPS_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */
    485 #define	NEWSMIPS_DMAMAP_MAPTBL	0x20000	/* use DMA maping table */
    486 
    487 /* Forwards needed by prototypes below. */
    488 struct mbuf;
    489 struct uio;
    490 
    491 /*
    492  * Operations performed by bus_dmamap_sync().
    493  */
    494 #define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
    495 #define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
    496 #define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
    497 #define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
    498 
    499 typedef struct newsmips_bus_dma_tag		*bus_dma_tag_t;
    500 typedef struct newsmips_bus_dmamap		*bus_dmamap_t;
    501 
    502 #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
    503 
    504 /*
    505  *	bus_dma_segment_t
    506  *
    507  *	Describes a single contiguous DMA transaction.  Values
    508  *	are suitable for programming into DMA registers.
    509  */
    510 struct newsmips_bus_dma_segment {
    511 	bus_addr_t	ds_addr;	/* DMA address */
    512 	bus_size_t	ds_len;		/* length of transfer */
    513 	bus_addr_t	_ds_vaddr;	/* virtual address, 0 if invalid */
    514 };
    515 typedef struct newsmips_bus_dma_segment	bus_dma_segment_t;
    516 
    517 /*
    518  *	bus_dma_tag_t
    519  *
    520  *	A machine-dependent opaque type describing the implementation of
    521  *	DMA for a given bus.
    522  */
    523 
    524 struct newsmips_bus_dma_tag {
    525 	/*
    526 	 * DMA mapping methods.
    527 	 */
    528 	int	(*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
    529 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
    530 	void	(*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
    531 	int	(*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
    532 		    bus_size_t, struct proc *, int);
    533 	int	(*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
    534 		    struct mbuf *, int);
    535 	int	(*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
    536 		    struct uio *, int);
    537 	int	(*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
    538 		    bus_dma_segment_t *, int, bus_size_t, int);
    539 	void	(*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
    540 	void	(*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
    541 		    bus_addr_t, bus_size_t, int);
    542 
    543 	/*
    544 	 * DMA memory utility functions.
    545 	 */
    546 	int	(*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
    547 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
    548 	void	(*_dmamem_free)(bus_dma_tag_t,
    549 		    bus_dma_segment_t *, int);
    550 	int	(*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
    551 		    int, size_t, void **, int);
    552 	void	(*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
    553 	paddr_t	(*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
    554 		    int, off_t, int, int);
    555 
    556 	/*
    557 	 * NEWSMIPS quirks.
    558 	 * This is NOT a constant.  Slot dependent information is
    559 	 * required to flush DMA cache correctly.
    560 	 */
    561 	int	_slotno;
    562 	bus_space_tag_t	_slotbaset;
    563 	bus_space_handle_t _slotbaseh;
    564 };
    565 
    566 #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
    567 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
    568 #define	bus_dmamap_destroy(t, p)				\
    569 	(*(t)->_dmamap_destroy)((t), (p))
    570 #define	bus_dmamap_load(t, m, b, s, p, f)			\
    571 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
    572 #define	bus_dmamap_load_mbuf(t, m, b, f)			\
    573 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
    574 #define	bus_dmamap_load_uio(t, m, u, f)				\
    575 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
    576 #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
    577 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
    578 #define	bus_dmamap_unload(t, p)					\
    579 	(*(t)->_dmamap_unload)((t), (p))
    580 #define	bus_dmamap_sync(t, p, o, l, ops)			\
    581 	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
    582 
    583 #define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
    584 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
    585 #define	bus_dmamem_free(t, sg, n)				\
    586 	(*(t)->_dmamem_free)((t), (sg), (n))
    587 #define	bus_dmamem_map(t, sg, n, s, k, f)			\
    588 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
    589 #define	bus_dmamem_unmap(t, k, s)				\
    590 	(*(t)->_dmamem_unmap)((t), (k), (s))
    591 #define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
    592 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
    593 
    594 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
    595 #define bus_dmatag_destroy(t)
    596 
    597 /*
    598  *	bus_dmamap_t
    599  *
    600  *	Describes a DMA mapping.
    601  */
    602 struct newsmips_bus_dmamap {
    603 	/*
    604 	 * PRIVATE MEMBERS: not for use my machine-independent code.
    605 	 */
    606 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
    607 	int		_dm_segcnt;	/* number of segs this map can map */
    608 	bus_size_t	_dm_maxmaxsegsz; /* fixed largest possible segment */
    609 	bus_size_t	_dm_boundary;	/* don't cross this */
    610 	int		_dm_flags;	/* misc. flags */
    611 	int		_dm_maptbl;	/* DMA mapping table index */
    612 	int		_dm_maptblcnt;	/* number of DMA mapping table */
    613 	struct vmspace	*_dm_vmspace;	/* vmspace that owns the mapping */
    614 
    615 	/*
    616 	 * PUBLIC MEMBERS: these are used by machine-independent code.
    617 	 */
    618 	bus_size_t	dm_maxsegsz;	/* largest possible segment */
    619 	bus_size_t	dm_mapsize;	/* size of the mapping */
    620 	int		dm_nsegs;	/* # valid segments in mapping */
    621 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
    622 };
    623 
    624 #ifdef _NEWSMIPS_BUS_DMA_PRIVATE
    625 void	newsmips_bus_dma_init(void);
    626 
    627 int	_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
    628 	    bus_size_t, int, bus_dmamap_t *);
    629 void	_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
    630 int	_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
    631 	    bus_size_t, struct proc *, int);
    632 int	_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
    633 	    struct mbuf *, int);
    634 int	_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
    635 	    struct uio *, int);
    636 int	_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
    637 	    bus_dma_segment_t *, int, bus_size_t, int);
    638 void	_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
    639 void	_bus_dmamap_sync_r3k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    640 	    bus_size_t, int);
    641 void	_bus_dmamap_sync_r4k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
    642 	    bus_size_t, int);
    643 
    644 int	_bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
    645 	    bus_size_t alignment, bus_size_t boundary,
    646 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
    647 void	_bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
    648 	    int nsegs);
    649 int	_bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
    650 	    int nsegs, size_t size, void **kvap, int flags);
    651 void	_bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
    652 	    size_t size);
    653 paddr_t	_bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
    654 	    int nsegs, off_t off, int prot, int flags);
    655 
    656 int	_bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
    657 	    bus_size_t alignment, bus_size_t boundary,
    658 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
    659 	    vaddr_t low, vaddr_t high);
    660 
    661 extern struct newsmips_bus_dma_tag newsmips_default_bus_dma_tag;
    662 #endif /* _NEWSMIPS_BUS_DMA_PRIVATE */
    663 
    664 #endif /* _NEWSMIPS_BUS_H_ */
    665