xref: /netbsd-src/sys/arch/newsmips/include/bus.h (revision 97492ef8ca5312ac7b3728a7a1f05e69d4da5bdf)
1*97492ef8Schristos /*	$NetBSD: bus.h,v 1.23 2021/01/23 19:38:08 christos Exp $	*/
21383251dSonoe 
31383251dSonoe /*
42c4c690fSthorpej  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
51383251dSonoe  * All rights reserved.
61383251dSonoe  *
71383251dSonoe  * This code is derived from software contributed to The NetBSD Foundation
81383251dSonoe  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
91383251dSonoe  * NASA Ames Research Center.
101383251dSonoe  *
111383251dSonoe  * Redistribution and use in source and binary forms, with or without
121383251dSonoe  * modification, are permitted provided that the following conditions
131383251dSonoe  * are met:
141383251dSonoe  * 1. Redistributions of source code must retain the above copyright
151383251dSonoe  *    notice, this list of conditions and the following disclaimer.
161383251dSonoe  * 2. Redistributions in binary form must reproduce the above copyright
171383251dSonoe  *    notice, this list of conditions and the following disclaimer in the
181383251dSonoe  *    documentation and/or other materials provided with the distribution.
191383251dSonoe  *
201383251dSonoe  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
211383251dSonoe  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
221383251dSonoe  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
231383251dSonoe  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
241383251dSonoe  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
251383251dSonoe  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
261383251dSonoe  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
271383251dSonoe  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
281383251dSonoe  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
291383251dSonoe  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
301383251dSonoe  * POSSIBILITY OF SUCH DAMAGE.
311383251dSonoe  */
321383251dSonoe 
331383251dSonoe #ifndef _NEWSMIPS_BUS_H_
341383251dSonoe #define _NEWSMIPS_BUS_H_
351383251dSonoe 
361383251dSonoe #include <mips/locore.h>
371383251dSonoe 
381383251dSonoe /*
391383251dSonoe  * Utility macros; do not use outside this file.
401383251dSonoe  */
416930b9d3Stsutsui #define	__PB_TYPENAME_PREFIX(BITS)	___CONCAT(uint,BITS)
421383251dSonoe #define	__PB_TYPENAME(BITS)		___CONCAT(__PB_TYPENAME_PREFIX(BITS),_t)
431383251dSonoe 
441383251dSonoe /*
451383251dSonoe  * Bus address and size types
461383251dSonoe  */
471383251dSonoe typedef u_long bus_addr_t;
481383251dSonoe typedef u_long bus_size_t;
491383251dSonoe 
50bf158e33Sskrll #define PRIxBUSADDR	"lx"
51bf158e33Sskrll #define PRIxBUSSIZE	"lx"
52bf158e33Sskrll #define PRIuBUSSIZE	"lu"
53bf158e33Sskrll 
541383251dSonoe /*
551383251dSonoe  * Access methods for bus resources and address space.
561383251dSonoe  */
571383251dSonoe typedef int	bus_space_tag_t;
581383251dSonoe typedef u_long	bus_space_handle_t;
591383251dSonoe 
60bf158e33Sskrll #define PRIxBSH		"lx"
61bf158e33Sskrll 
621383251dSonoe /*
631383251dSonoe  *	int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
641383251dSonoe  *	    bus_size_t size, int flags, bus_space_handle_t *bshp);
651383251dSonoe  *
661383251dSonoe  * Map a region of bus space.
671383251dSonoe  */
681383251dSonoe 
691383251dSonoe #define	BUS_SPACE_MAP_CACHEABLE		0x01
701383251dSonoe #define	BUS_SPACE_MAP_LINEAR		0x02
711383251dSonoe #define BUS_SPACE_MAP_PREFETCHABLE	0x04
721383251dSonoe 
731383251dSonoe int	bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
741383251dSonoe 	    int, bus_space_handle_t *);
751383251dSonoe 
761383251dSonoe /*
771383251dSonoe  *	void bus_space_unmap(bus_space_tag_t t,
781383251dSonoe  *	     bus_space_handle_t bsh, bus_size_t size);
791383251dSonoe  *
801383251dSonoe  * Unmap a region of bus space.
811383251dSonoe  */
821383251dSonoe 
831383251dSonoe void	bus_space_unmap (bus_space_tag_t, bus_space_handle_t, bus_size_t);
841383251dSonoe 
851383251dSonoe /*
861383251dSonoe  *	int bus_space_subregion(bus_space_tag_t t,
871383251dSonoe  *	    bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
881383251dSonoe  *	    bus_space_handle_t *nbshp);
891383251dSonoe  *
901383251dSonoe  * Get a new handle for a subregion of an already-mapped area of bus space.
911383251dSonoe  */
921383251dSonoe 
931383251dSonoe int	bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
941383251dSonoe 	    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
951383251dSonoe 
961383251dSonoe /*
971383251dSonoe  *	int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
981383251dSonoe  *	    bus_addr_t rend, bus_size_t size, bus_size_t align,
991383251dSonoe  *	    bus_size_t boundary, int flags, bus_addr_t *addrp,
1001383251dSonoe  *	    bus_space_handle_t *bshp);
1011383251dSonoe  *
1021383251dSonoe  * Allocate a region of bus space.
1031383251dSonoe  */
1041383251dSonoe 
1051383251dSonoe int	bus_space_alloc (bus_space_tag_t t, bus_addr_t rstart,
1061383251dSonoe 	    bus_addr_t rend, bus_size_t size, bus_size_t align,
1071383251dSonoe 	    bus_size_t boundary, int cacheable, bus_addr_t *addrp,
1081383251dSonoe 	    bus_space_handle_t *bshp);
1091383251dSonoe 
1101383251dSonoe /*
1111383251dSonoe  *	int bus_space_free (bus_space_tag_t t,
1121383251dSonoe  *	    bus_space_handle_t bsh, bus_size_t size);
1131383251dSonoe  *
1141383251dSonoe  * Free a region of bus space.
1151383251dSonoe  */
1161383251dSonoe 
1171383251dSonoe void	bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
1181383251dSonoe 	    bus_size_t size);
1191383251dSonoe 
1201383251dSonoe /*
121fd4afa03Stsutsui  *	uintN_t bus_space_read_N(bus_space_tag_t tag,
1221383251dSonoe  *	    bus_space_handle_t bsh, bus_size_t offset);
1231383251dSonoe  *
1241383251dSonoe  * Read a 1, 2, 4, or 8 byte quantity from bus space
1251383251dSonoe  * described by tag/handle/offset.
1261383251dSonoe  */
1271383251dSonoe 
1281383251dSonoe #define	bus_space_read_1(t, h, o)					\
129fd4afa03Stsutsui      ((void) t, (*(volatile uint8_t *)((h) + (o))))
1301383251dSonoe 
1311383251dSonoe #define	bus_space_read_2(t, h, o)					\
132fd4afa03Stsutsui      ((void) t, (*(volatile uint16_t *)((h) + (o))))
1331383251dSonoe 
1341383251dSonoe #define	bus_space_read_4(t, h, o)					\
135fd4afa03Stsutsui      ((void) t, (*(volatile uint32_t *)((h) + (o))))
1361383251dSonoe 
1371383251dSonoe /*
1381383251dSonoe  *	void bus_space_read_multi_N(bus_space_tag_t tag,
1391383251dSonoe  *	    bus_space_handle_t bsh, bus_size_t offset,
140fd4afa03Stsutsui  *	    uintN_t *addr, size_t count);
1411383251dSonoe  *
1421383251dSonoe  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
1431383251dSonoe  * described by tag/handle/offset and copy into buffer provided.
1441383251dSonoe  */
1451383251dSonoe 
1461383251dSonoe #define __NEWSMIPS_bus_space_read_multi(BYTES,BITS)			\
147fbae48b9Sperry static __inline void __CONCAT(bus_space_read_multi_,BYTES)		\
1481383251dSonoe 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
1491383251dSonoe 	__PB_TYPENAME(BITS) *, size_t);					\
1501383251dSonoe 									\
151fbae48b9Sperry static __inline void							\
1521d7f24eaSmatt __CONCAT(bus_space_read_multi_,BYTES)(					\
1531d7f24eaSmatt 	bus_space_tag_t t,						\
1541d7f24eaSmatt 	bus_space_handle_t h,						\
1551d7f24eaSmatt 	bus_size_t o,							\
1561d7f24eaSmatt 	__PB_TYPENAME(BITS) *a,						\
1571d7f24eaSmatt 	size_t c)							\
1581383251dSonoe {									\
1591383251dSonoe 									\
1601383251dSonoe 	while (c--)							\
1611383251dSonoe 		*a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o);	\
1621383251dSonoe }
1631383251dSonoe 
1641383251dSonoe __NEWSMIPS_bus_space_read_multi(1,8)
1651383251dSonoe __NEWSMIPS_bus_space_read_multi(2,16)
1661383251dSonoe __NEWSMIPS_bus_space_read_multi(4,32)
1671383251dSonoe 
1681383251dSonoe #undef __NEWSMIPS_bus_space_read_multi
1691383251dSonoe 
1701383251dSonoe /*
1711383251dSonoe  *	void bus_space_read_region_N(bus_space_tag_t tag,
1721383251dSonoe  *	    bus_space_handle_t bsh, bus_size_t offset,
173fd4afa03Stsutsui  *	    uintN_t *addr, size_t count);
1741383251dSonoe  *
1751383251dSonoe  * Read `count' 1, 2, 4, or 8 byte quantities from bus space
1761383251dSonoe  * described by tag/handle and starting at `offset' and copy into
1771383251dSonoe  * buffer provided.
1781383251dSonoe  */
1791383251dSonoe 
1801383251dSonoe #define __NEWSMIPS_bus_space_read_region(BYTES,BITS)			\
181fbae48b9Sperry static __inline void __CONCAT(bus_space_read_region_,BYTES)		\
1821383251dSonoe 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
1831383251dSonoe 	__PB_TYPENAME(BITS) *, size_t);					\
1841383251dSonoe 									\
185fbae48b9Sperry static __inline void							\
1861d7f24eaSmatt __CONCAT(bus_space_read_region_,BYTES)(					\
1871d7f24eaSmatt 	bus_space_tag_t t,						\
1881d7f24eaSmatt 	bus_space_handle_t h,						\
1891d7f24eaSmatt 	bus_size_t o,							\
1901d7f24eaSmatt 	__PB_TYPENAME(BITS) *a,						\
1911d7f24eaSmatt 	size_t c)							\
1921383251dSonoe {									\
1931383251dSonoe 									\
1941383251dSonoe 	while (c--) {							\
1951383251dSonoe 		*a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o);	\
1961383251dSonoe 		o += BYTES;						\
1971383251dSonoe 	}								\
1981383251dSonoe }
1991383251dSonoe 
2001383251dSonoe __NEWSMIPS_bus_space_read_region(1,8)
2011383251dSonoe __NEWSMIPS_bus_space_read_region(2,16)
2021383251dSonoe __NEWSMIPS_bus_space_read_region(4,32)
2031383251dSonoe 
2041383251dSonoe #undef __NEWSMIPS_bus_space_read_region
2051383251dSonoe 
2061383251dSonoe /*
2071383251dSonoe  *	void bus_space_write_N(bus_space_tag_t tag,
2081383251dSonoe  *	    bus_space_handle_t bsh, bus_size_t offset,
209fd4afa03Stsutsui  *	    uintN_t value);
2101383251dSonoe  *
2111383251dSonoe  * Write the 1, 2, 4, or 8 byte value `value' to bus space
2121383251dSonoe  * described by tag/handle/offset.
2131383251dSonoe  */
2141383251dSonoe 
2151383251dSonoe #define	bus_space_write_1(t, h, o, v)					\
2161383251dSonoe do {									\
2171383251dSonoe 	(void) t;							\
218fd4afa03Stsutsui 	*(volatile uint8_t *)((h) + (o)) = (v);			\
2191383251dSonoe } while (0)
2201383251dSonoe 
2211383251dSonoe #define	bus_space_write_2(t, h, o, v)					\
2221383251dSonoe do {									\
2231383251dSonoe 	(void) t;							\
224fd4afa03Stsutsui 	*(volatile uint16_t *)((h) + (o)) = (v);			\
2251383251dSonoe } while (0)
2261383251dSonoe 
2271383251dSonoe #define	bus_space_write_4(t, h, o, v)					\
2281383251dSonoe do {									\
2291383251dSonoe 	(void) t;							\
230fd4afa03Stsutsui 	*(volatile uint32_t *)((h) + (o)) = (v);			\
2311383251dSonoe } while (0)
2321383251dSonoe 
2331383251dSonoe /*
2341383251dSonoe  *	void bus_space_write_multi_N(bus_space_tag_t tag,
2351383251dSonoe  *	    bus_space_handle_t bsh, bus_size_t offset,
236fd4afa03Stsutsui  *	    const uintN_t *addr, size_t count);
2371383251dSonoe  *
2381383251dSonoe  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
2391383251dSonoe  * provided to bus space described by tag/handle/offset.
2401383251dSonoe  */
2411383251dSonoe 
2421383251dSonoe #define __NEWSMIPS_bus_space_write_multi(BYTES,BITS)			\
243fbae48b9Sperry static __inline void __CONCAT(bus_space_write_multi_,BYTES)		\
2441383251dSonoe 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
2451383251dSonoe 	const __PB_TYPENAME(BITS) *, size_t);				\
2461383251dSonoe 									\
247fbae48b9Sperry static __inline void							\
2481d7f24eaSmatt __CONCAT(bus_space_write_multi_,BYTES)(					\
2491d7f24eaSmatt 	bus_space_tag_t t,						\
2501d7f24eaSmatt 	bus_space_handle_t h,						\
2511d7f24eaSmatt 	bus_size_t o,							\
2521d7f24eaSmatt 	const __PB_TYPENAME(BITS) *a,					\
2531d7f24eaSmatt 	size_t c)							\
2541383251dSonoe {									\
2551383251dSonoe 									\
2561383251dSonoe 	while (c--)							\
2571383251dSonoe 		__CONCAT(bus_space_write_,BYTES)(t, h, o, *a++);	\
2581383251dSonoe }
2591383251dSonoe 
2601383251dSonoe __NEWSMIPS_bus_space_write_multi(1,8)
2611383251dSonoe __NEWSMIPS_bus_space_write_multi(2,16)
2621383251dSonoe __NEWSMIPS_bus_space_write_multi(4,32)
2631383251dSonoe 
2641383251dSonoe #undef __NEWSMIPS_bus_space_write_multi
2651383251dSonoe 
2661383251dSonoe /*
2671383251dSonoe  *	void bus_space_write_region_N(bus_space_tag_t tag,
2681383251dSonoe  *	    bus_space_handle_t bsh, bus_size_t offset,
269fd4afa03Stsutsui  *	    const uintN_t *addr, size_t count);
2701383251dSonoe  *
2711383251dSonoe  * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
2721383251dSonoe  * to bus space described by tag/handle starting at `offset'.
2731383251dSonoe  */
2741383251dSonoe 
2751383251dSonoe #define __NEWSMIPS_bus_space_write_region(BYTES,BITS)			\
276fbae48b9Sperry static __inline void __CONCAT(bus_space_write_region_,BYTES)		\
2771383251dSonoe 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
2781383251dSonoe 	const __PB_TYPENAME(BITS) *, size_t);				\
2791383251dSonoe 									\
280fbae48b9Sperry static __inline void							\
2811d7f24eaSmatt __CONCAT(bus_space_write_region_,BYTES)(				\
2821d7f24eaSmatt 	bus_space_tag_t t,						\
2831d7f24eaSmatt 	bus_space_handle_t h,						\
2841d7f24eaSmatt 	bus_size_t o,							\
2851d7f24eaSmatt 	const __PB_TYPENAME(BITS) *a,					\
2861d7f24eaSmatt 	size_t c)							\
2871383251dSonoe {									\
2881383251dSonoe 									\
2891383251dSonoe 	while (c--) {							\
2901383251dSonoe 		__CONCAT(bus_space_write_,BYTES)(t, h, o, *a++);	\
2911383251dSonoe 		o += BYTES;						\
2921383251dSonoe 	}								\
2931383251dSonoe }
2941383251dSonoe 
2951383251dSonoe __NEWSMIPS_bus_space_write_region(1,8)
2961383251dSonoe __NEWSMIPS_bus_space_write_region(2,16)
2971383251dSonoe __NEWSMIPS_bus_space_write_region(4,32)
2981383251dSonoe 
2991383251dSonoe #undef __NEWSMIPS_bus_space_write_region
3001383251dSonoe 
3011383251dSonoe /*
3021383251dSonoe  *	void bus_space_set_multi_N(bus_space_tag_t tag,
303fd4afa03Stsutsui  *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
3041383251dSonoe  *	    size_t count);
3051383251dSonoe  *
3061383251dSonoe  * Write the 1, 2, 4, or 8 byte value `val' to bus space described
3071383251dSonoe  * by tag/handle/offset `count' times.
3081383251dSonoe  */
3091383251dSonoe 
3101383251dSonoe #define __NEWSMIPS_bus_space_set_multi(BYTES,BITS)			\
311fbae48b9Sperry static __inline void __CONCAT(bus_space_set_multi_,BYTES)		\
3121383251dSonoe 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
3131383251dSonoe 	__PB_TYPENAME(BITS), size_t);					\
3141383251dSonoe 									\
315fbae48b9Sperry static __inline void							\
3161d7f24eaSmatt __CONCAT(bus_space_set_multi_,BYTES)(					\
3171d7f24eaSmatt 	bus_space_tag_t t,						\
3181d7f24eaSmatt 	bus_space_handle_t h,						\
3191d7f24eaSmatt 	bus_size_t o,							\
3201d7f24eaSmatt 	__PB_TYPENAME(BITS) v,						\
3211d7f24eaSmatt 	size_t c)							\
3221383251dSonoe {									\
3231383251dSonoe 									\
3241383251dSonoe 	while (c--)							\
3251383251dSonoe 		__CONCAT(bus_space_write_,BYTES)(t, h, o, v);		\
3261383251dSonoe }
3271383251dSonoe 
3281383251dSonoe __NEWSMIPS_bus_space_set_multi(1,8)
3291383251dSonoe __NEWSMIPS_bus_space_set_multi(2,16)
3301383251dSonoe __NEWSMIPS_bus_space_set_multi(4,32)
3311383251dSonoe 
3321383251dSonoe #undef __NEWSMIPS_bus_space_set_multi
3331383251dSonoe 
3341383251dSonoe /*
3351383251dSonoe  *	void bus_space_set_region_N(bus_space_tag_t tag,
336fd4afa03Stsutsui  *	    bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
3371383251dSonoe  *	    size_t count);
3381383251dSonoe  *
3391383251dSonoe  * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
3401383251dSonoe  * by tag/handle starting at `offset'.
3411383251dSonoe  */
3421383251dSonoe 
3431383251dSonoe #define __NEWSMIPS_bus_space_set_region(BYTES,BITS)			\
344fbae48b9Sperry static __inline void __CONCAT(bus_space_set_region_,BYTES)		\
3451383251dSonoe 	(bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
3461383251dSonoe 	__PB_TYPENAME(BITS), size_t);					\
3471383251dSonoe 									\
348fbae48b9Sperry static __inline void							\
3491d7f24eaSmatt __CONCAT(bus_space_set_region_,BYTES)(					\
3501d7f24eaSmatt 	bus_space_tag_t t,						\
3511d7f24eaSmatt 	bus_space_handle_t h,						\
3521d7f24eaSmatt 	bus_size_t o,							\
3531d7f24eaSmatt 	__PB_TYPENAME(BITS) v,						\
3541d7f24eaSmatt 	size_t c)							\
3551383251dSonoe {									\
3561383251dSonoe 									\
3571383251dSonoe 	while (c--) {							\
3581383251dSonoe 		__CONCAT(bus_space_write_,BYTES)(t, h, o, v);		\
3591383251dSonoe 		o += BYTES;						\
3601383251dSonoe 	}								\
3611383251dSonoe }
3621383251dSonoe 
3631383251dSonoe __NEWSMIPS_bus_space_set_region(1,8)
3641383251dSonoe __NEWSMIPS_bus_space_set_region(2,16)
3651383251dSonoe __NEWSMIPS_bus_space_set_region(4,32)
3661383251dSonoe 
3671383251dSonoe #undef __NEWSMIPS_bus_space_set_region
3681383251dSonoe 
3691383251dSonoe /*
3701383251dSonoe  *	void bus_space_copy_region_N(bus_space_tag_t tag,
3711383251dSonoe  *	    bus_space_handle_t bsh1, bus_size_t off1,
3721383251dSonoe  *	    bus_space_handle_t bsh2, bus_size_t off2,
3731383251dSonoe  *	    bus_size_t count);
3741383251dSonoe  *
3751383251dSonoe  * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
3761383251dSonoe  * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
3771383251dSonoe  */
3781383251dSonoe 
3791383251dSonoe #define	__NEWSMIPS_copy_region(BYTES)					\
380fbae48b9Sperry static __inline void __CONCAT(bus_space_copy_region_,BYTES)		\
3811383251dSonoe 	(bus_space_tag_t,						\
3821383251dSonoe 	    bus_space_handle_t bsh1, bus_size_t off1,			\
3831383251dSonoe 	    bus_space_handle_t bsh2, bus_size_t off2,			\
3841383251dSonoe 	    bus_size_t count);						\
3851383251dSonoe 									\
386fbae48b9Sperry static __inline void							\
3871d7f24eaSmatt __CONCAT(bus_space_copy_region_,BYTES)(					\
3881d7f24eaSmatt 	bus_space_tag_t t,						\
3891d7f24eaSmatt 	bus_space_handle_t h1,						\
3901d7f24eaSmatt 	bus_size_t o1,							\
3911d7f24eaSmatt 	bus_space_handle_t h2,						\
3921d7f24eaSmatt 	bus_size_t o2,							\
3931d7f24eaSmatt 	bus_size_t c)							\
3941383251dSonoe {									\
3951383251dSonoe 	bus_size_t o;							\
3961383251dSonoe 									\
3971383251dSonoe 	if ((h1 + o1) >= (h2 + o2)) {					\
3981383251dSonoe 		/* src after dest: copy forward */			\
3991383251dSonoe 		for (o = 0; c != 0; c--, o += BYTES)			\
4001383251dSonoe 			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
4011383251dSonoe 			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
4021383251dSonoe 	} else {							\
4031383251dSonoe 		/* dest after src: copy backwards */			\
4041383251dSonoe 		for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)	\
4051383251dSonoe 			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
4061383251dSonoe 			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
4071383251dSonoe 	}								\
4081383251dSonoe }
4091383251dSonoe 
4101383251dSonoe __NEWSMIPS_copy_region(1)
4111383251dSonoe __NEWSMIPS_copy_region(2)
4121383251dSonoe __NEWSMIPS_copy_region(4)
4131383251dSonoe 
4141383251dSonoe #undef __NEWSMIPS_copy_region
4151383251dSonoe 
4161383251dSonoe /*
4171383251dSonoe  * Bus read/write barrier methods.
4181383251dSonoe  *
4191383251dSonoe  *	void bus_space_barrier(bus_space_tag_t tag,
4201383251dSonoe  *	    bus_space_handle_t bsh, bus_size_t offset,
4211383251dSonoe  *	    bus_size_t len, int flags);
4221383251dSonoe  *
4231383251dSonoe  * On the MIPS, we just flush the write buffer.
4241383251dSonoe  */
4251383251dSonoe #define	bus_space_barrier(t, h, o, l, f)	\
426a465c6b8Stsutsui 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f),	\
427a465c6b8Stsutsui 	 wbflush()))
4281383251dSonoe #define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
4291383251dSonoe #define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
4301383251dSonoe 
4311383251dSonoe #undef __PB_TYPENAME_PREFIX
4321383251dSonoe #undef __PB_TYPENAME
4331383251dSonoe 
4341383251dSonoe #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
4351383251dSonoe 
4361383251dSonoe /*
4371383251dSonoe  * Flags used in various bus DMA methods.
4381383251dSonoe  */
439babefc53Sthorpej #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
440babefc53Sthorpej #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
441babefc53Sthorpej #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
442babefc53Sthorpej #define	BUS_DMA_COHERENT	0x004	/* hint: map memory DMA coherent */
443babefc53Sthorpej #define	BUS_DMA_STREAMING	0x008	/* hint: sequential, unidirectional */
444babefc53Sthorpej #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
445babefc53Sthorpej #define	BUS_DMA_BUS2		0x020
446babefc53Sthorpej #define	BUS_DMA_BUS3		0x040
447babefc53Sthorpej #define	BUS_DMA_BUS4		0x080
448babefc53Sthorpej #define	BUS_DMA_READ		0x100	/* mapping is device -> memory only */
449babefc53Sthorpej #define	BUS_DMA_WRITE		0x200	/* mapping is memory -> device only */
450cd7d9faeSkent #define	BUS_DMA_NOCACHE		0x400	/* hint: map non-cached memory */
4511383251dSonoe 
452a85e214bSsimonb #define	NEWSMIPS_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */
453a85e214bSsimonb #define	NEWSMIPS_DMAMAP_MAPTBL	0x20000	/* use DMA maping table */
4541383251dSonoe 
4551383251dSonoe /* Forwards needed by prototypes below. */
4561383251dSonoe struct mbuf;
4571383251dSonoe struct uio;
4581383251dSonoe 
4591383251dSonoe /*
4601383251dSonoe  * Operations performed by bus_dmamap_sync().
4611383251dSonoe  */
4621383251dSonoe #define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
4631383251dSonoe #define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
4641383251dSonoe #define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
4651383251dSonoe #define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
4661383251dSonoe 
4671383251dSonoe typedef struct newsmips_bus_dma_tag		*bus_dma_tag_t;
4681383251dSonoe typedef struct newsmips_bus_dmamap		*bus_dmamap_t;
4691383251dSonoe 
4707dd7f8baSfvdl #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
4717dd7f8baSfvdl 
4721383251dSonoe /*
4731383251dSonoe  *	bus_dma_segment_t
4741383251dSonoe  *
4751383251dSonoe  *	Describes a single contiguous DMA transaction.  Values
4761383251dSonoe  *	are suitable for programming into DMA registers.
4771383251dSonoe  */
4781383251dSonoe struct newsmips_bus_dma_segment {
4791383251dSonoe 	bus_addr_t	ds_addr;	/* DMA address */
4801383251dSonoe 	bus_size_t	ds_len;		/* length of transfer */
4811383251dSonoe 	bus_addr_t	_ds_vaddr;	/* virtual address, 0 if invalid */
4821383251dSonoe };
4831383251dSonoe typedef struct newsmips_bus_dma_segment	bus_dma_segment_t;
4841383251dSonoe 
4851383251dSonoe /*
4861383251dSonoe  *	bus_dma_tag_t
4871383251dSonoe  *
4881383251dSonoe  *	A machine-dependent opaque type describing the implementation of
4891383251dSonoe  *	DMA for a given bus.
4901383251dSonoe  */
4911383251dSonoe 
4921383251dSonoe struct newsmips_bus_dma_tag {
4931383251dSonoe 	/*
4941383251dSonoe 	 * DMA mapping methods.
4951383251dSonoe 	 */
4961383251dSonoe 	int	(*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
4971383251dSonoe 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
4981383251dSonoe 	void	(*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
4991383251dSonoe 	int	(*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
5001383251dSonoe 		    bus_size_t, struct proc *, int);
5011383251dSonoe 	int	(*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
5021383251dSonoe 		    struct mbuf *, int);
5031383251dSonoe 	int	(*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
5041383251dSonoe 		    struct uio *, int);
5051383251dSonoe 	int	(*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
5061383251dSonoe 		    bus_dma_segment_t *, int, bus_size_t, int);
5071383251dSonoe 	void	(*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
5081383251dSonoe 	void	(*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
5091383251dSonoe 		    bus_addr_t, bus_size_t, int);
5101383251dSonoe 
5111383251dSonoe 	/*
5121383251dSonoe 	 * DMA memory utility functions.
5131383251dSonoe 	 */
5141383251dSonoe 	int	(*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
5151383251dSonoe 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
5161383251dSonoe 	void	(*_dmamem_free)(bus_dma_tag_t,
5171383251dSonoe 		    bus_dma_segment_t *, int);
5181383251dSonoe 	int	(*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
51953524e44Schristos 		    int, size_t, void **, int);
52053524e44Schristos 	void	(*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
5211383251dSonoe 	paddr_t	(*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
5221383251dSonoe 		    int, off_t, int, int);
5231383251dSonoe 
5241383251dSonoe 	/*
5251383251dSonoe 	 * NEWSMIPS quirks.
5261383251dSonoe 	 * This is NOT a constant.  Slot dependent information is
5271383251dSonoe 	 * required to flush DMA cache correctly.
5281383251dSonoe 	 */
5291383251dSonoe 	int	_slotno;
5301383251dSonoe 	bus_space_tag_t	_slotbaset;
5311383251dSonoe 	bus_space_handle_t _slotbaseh;
5321383251dSonoe };
5331383251dSonoe 
5341383251dSonoe #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
5351383251dSonoe 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
5361383251dSonoe #define	bus_dmamap_destroy(t, p)				\
5371383251dSonoe 	(*(t)->_dmamap_destroy)((t), (p))
5381383251dSonoe #define	bus_dmamap_load(t, m, b, s, p, f)			\
5391383251dSonoe 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
5401383251dSonoe #define	bus_dmamap_load_mbuf(t, m, b, f)			\
5411383251dSonoe 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
5421383251dSonoe #define	bus_dmamap_load_uio(t, m, u, f)				\
5431383251dSonoe 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
5441383251dSonoe #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
5451383251dSonoe 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
5461383251dSonoe #define	bus_dmamap_unload(t, p)					\
5471383251dSonoe 	(*(t)->_dmamap_unload)((t), (p))
5481383251dSonoe #define	bus_dmamap_sync(t, p, o, l, ops)			\
5491383251dSonoe 	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
5501383251dSonoe 
5511383251dSonoe #define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
5521383251dSonoe 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
5531383251dSonoe #define	bus_dmamem_free(t, sg, n)				\
5541383251dSonoe 	(*(t)->_dmamem_free)((t), (sg), (n))
5551383251dSonoe #define	bus_dmamem_map(t, sg, n, s, k, f)			\
5561383251dSonoe 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
5571383251dSonoe #define	bus_dmamem_unmap(t, k, s)				\
5581383251dSonoe 	(*(t)->_dmamem_unmap)((t), (k), (s))
5591383251dSonoe #define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
5601383251dSonoe 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
5611383251dSonoe 
5624410329bSmrg #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
5634410329bSmrg #define bus_dmatag_destroy(t)
5644410329bSmrg 
5651383251dSonoe /*
5661383251dSonoe  *	bus_dmamap_t
5671383251dSonoe  *
5681383251dSonoe  *	Describes a DMA mapping.
5691383251dSonoe  */
5701383251dSonoe struct newsmips_bus_dmamap {
5711383251dSonoe 	/*
5721383251dSonoe 	 * PRIVATE MEMBERS: not for use my machine-independent code.
5731383251dSonoe 	 */
5741383251dSonoe 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
5751383251dSonoe 	int		_dm_segcnt;	/* number of segs this map can map */
576a6db24a4Smatt 	bus_size_t	_dm_maxmaxsegsz; /* fixed largest possible segment */
5771383251dSonoe 	bus_size_t	_dm_boundary;	/* don't cross this */
5781383251dSonoe 	int		_dm_flags;	/* misc. flags */
57926c411deSonoe 	int		_dm_maptbl;	/* DMA mapping table index */
58026c411deSonoe 	int		_dm_maptblcnt;	/* number of DMA mapping table */
581ec5a9318Syamt 	struct vmspace	*_dm_vmspace;	/* vmspace that owns the mapping */
5821383251dSonoe 
5831383251dSonoe 	/*
5841383251dSonoe 	 * PUBLIC MEMBERS: these are used by machine-independent code.
5851383251dSonoe 	 */
586a6db24a4Smatt 	bus_size_t	dm_maxsegsz;	/* largest possible segment */
5871383251dSonoe 	bus_size_t	dm_mapsize;	/* size of the mapping */
5881383251dSonoe 	int		dm_nsegs;	/* # valid segments in mapping */
5891383251dSonoe 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
5901383251dSonoe };
5911383251dSonoe 
5921383251dSonoe #ifdef _NEWSMIPS_BUS_DMA_PRIVATE
593af66038fSthorpej void	newsmips_bus_dma_init(void);
594af66038fSthorpej 
5951383251dSonoe int	_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
5961383251dSonoe 	    bus_size_t, int, bus_dmamap_t *);
5971383251dSonoe void	_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
5981383251dSonoe int	_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
5991383251dSonoe 	    bus_size_t, struct proc *, int);
6001383251dSonoe int	_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
6011383251dSonoe 	    struct mbuf *, int);
6021383251dSonoe int	_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
6031383251dSonoe 	    struct uio *, int);
6041383251dSonoe int	_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
6051383251dSonoe 	    bus_dma_segment_t *, int, bus_size_t, int);
6061383251dSonoe void	_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
607af66038fSthorpej void	_bus_dmamap_sync_r3k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
608af66038fSthorpej 	    bus_size_t, int);
609af66038fSthorpej void	_bus_dmamap_sync_r4k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
6101383251dSonoe 	    bus_size_t, int);
6111383251dSonoe 
6121383251dSonoe int	_bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
6131383251dSonoe 	    bus_size_t alignment, bus_size_t boundary,
6141383251dSonoe 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
6151383251dSonoe void	_bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
6161383251dSonoe 	    int nsegs);
6171383251dSonoe int	_bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
61853524e44Schristos 	    int nsegs, size_t size, void **kvap, int flags);
61953524e44Schristos void	_bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
6201383251dSonoe 	    size_t size);
6211383251dSonoe paddr_t	_bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
6221383251dSonoe 	    int nsegs, off_t off, int prot, int flags);
6231383251dSonoe 
6241383251dSonoe int	_bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
6251383251dSonoe 	    bus_size_t alignment, bus_size_t boundary,
6261383251dSonoe 	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
6271383251dSonoe 	    vaddr_t low, vaddr_t high);
6281383251dSonoe 
6291383251dSonoe extern struct newsmips_bus_dma_tag newsmips_default_bus_dma_tag;
6301383251dSonoe #endif /* _NEWSMIPS_BUS_DMA_PRIVATE */
6311383251dSonoe 
6321383251dSonoe #endif /* _NEWSMIPS_BUS_H_ */
633