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