bus.h revision 1.6
11.6Sthorpej/*	$NetBSD: bus.h,v 1.6 1998/06/03 04:38:41 thorpej Exp $	*/
21.1Sjonathan
31.5Sthorpej/*-
41.5Sthorpej * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
51.3Sjonathan * All rights reserved.
61.1Sjonathan *
71.5Sthorpej * This code is derived from software contributed to The NetBSD Foundation
81.5Sthorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
91.5Sthorpej * NASA Ames Research Center.
101.5Sthorpej *
111.3Sjonathan * Redistribution and use in source and binary forms, with or without
121.3Sjonathan * modification, are permitted provided that the following conditions
131.3Sjonathan * are met:
141.3Sjonathan * 1. Redistributions of source code must retain the above copyright
151.3Sjonathan *    notice, this list of conditions and the following disclaimer.
161.3Sjonathan * 2. Redistributions in binary form must reproduce the above copyright
171.3Sjonathan *    notice, this list of conditions and the following disclaimer in the
181.3Sjonathan *    documentation and/or other materials provided with the distribution.
191.3Sjonathan * 3. All advertising materials mentioning features or use of this software
201.3Sjonathan *    must display the following acknowledgement:
211.5Sthorpej *	This product includes software developed by the NetBSD
221.5Sthorpej *	Foundation, Inc. and its contributors.
231.5Sthorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
241.5Sthorpej *    contributors may be used to endorse or promote products derived
251.5Sthorpej *    from this software without specific prior written permission.
261.5Sthorpej *
271.5Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
281.5Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
291.5Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
301.5Sthorpej * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
311.5Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
321.5Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
331.5Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
341.5Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
351.5Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
361.5Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
371.5Sthorpej * POSSIBILITY OF SUCH DAMAGE.
381.1Sjonathan */
391.1Sjonathan
401.1Sjonathan#ifndef _PMAX_BUS_H_
411.1Sjonathan#define _PMAX_BUS_H_
421.2Sjonathan
431.5Sthorpej#include <mips/locore.h>
441.2Sjonathan
451.5Sthorpej/*
461.5Sthorpej * Utility macros; do not use outside this file.
471.5Sthorpej */
481.5Sthorpej#define	__PB_TYPENAME_PREFIX(BITS)	___CONCAT(u_int,BITS)
491.5Sthorpej#define	__PB_TYPENAME(BITS)		___CONCAT(__PB_TYPENAME_PREFIX(BITS),_t)
501.1Sjonathan
511.1Sjonathan/*
521.1Sjonathan * Bus address and size types
531.1Sjonathan */
541.1Sjonathantypedef u_long bus_addr_t;
551.1Sjonathantypedef u_long bus_size_t;
561.1Sjonathan
571.1Sjonathan/*
581.5Sthorpej * Access methods for bus resources and address space.
591.1Sjonathan */
601.5Sthorpejtypedef int	bus_space_tag_t;
611.5Sthorpejtypedef u_long	bus_space_handle_t;
621.1Sjonathan
631.5Sthorpej/*
641.5Sthorpej *	int bus_space_map __P((bus_space_tag_t t, bus_addr_t addr,
651.5Sthorpej *	    bus_size_t size, int flags, bus_space_handle_t *bshp));
661.5Sthorpej *
671.5Sthorpej * Map a region of bus space.
681.5Sthorpej */
691.5Sthorpej
701.5Sthorpej#define	BUS_SPACE_MAP_CACHEABLE		0x01
711.5Sthorpej#define	BUS_SPACE_MAP_LINEAR		0x02
721.5Sthorpej
731.5Sthorpejint	bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t,
741.5Sthorpej	    int, bus_space_handle_t *));
751.5Sthorpej
761.5Sthorpej/*
771.5Sthorpej *	void bus_space_unmap __P((bus_space_tag_t t,
781.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t size));
791.5Sthorpej *
801.5Sthorpej * Unmap a region of bus space.
811.5Sthorpej */
821.5Sthorpej
831.5Sthorpejvoid	bus_space_unmap __P((bus_space_tag_t, bus_space_handle_t, bus_size_t));
841.1Sjonathan
851.1Sjonathan/*
861.5Sthorpej *	int bus_space_subregion __P((bus_space_tag_t t,
871.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
881.5Sthorpej *	    bus_space_handle_t *nbshp));
891.5Sthorpej *
901.5Sthorpej * Get a new handle for a subregion of an already-mapped area of bus space.
911.1Sjonathan */
921.1Sjonathan
931.5Sthorpejint	bus_space_subregion __P((bus_space_tag_t t, bus_space_handle_t bsh,
941.5Sthorpej	    bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp));
951.1Sjonathan
961.5Sthorpej/*
971.5Sthorpej *	int bus_space_alloc __P((bus_space_tag_t t, bus_addr_t, rstart,
981.5Sthorpej *	    bus_addr_t rend, bus_size_t size, bus_size_t align,
991.5Sthorpej *	    bus_size_t boundary, int flags, bus_addr_t *addrp,
1001.5Sthorpej *	    bus_space_handle_t *bshp));
1011.5Sthorpej *
1021.5Sthorpej * Allocate a region of bus space.
1031.5Sthorpej */
1041.1Sjonathan
1051.5Sthorpejint	bus_space_alloc __P((bus_space_tag_t t, bus_addr_t rstart,
1061.5Sthorpej	    bus_addr_t rend, bus_size_t size, bus_size_t align,
1071.5Sthorpej	    bus_size_t boundary, int cacheable, bus_addr_t *addrp,
1081.5Sthorpej	    bus_space_handle_t *bshp));
1091.1Sjonathan
1101.5Sthorpej/*
1111.5Sthorpej *	int bus_space_free __P((bus_space_tag_t t,
1121.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t size));
1131.5Sthorpej *
1141.5Sthorpej * Free a region of bus space.
1151.5Sthorpej */
1161.1Sjonathan
1171.5Sthorpejvoid	bus_space_free __P((bus_space_tag_t t, bus_space_handle_t bsh,
1181.5Sthorpej	    bus_size_t size));
1191.1Sjonathan
1201.1Sjonathan/*
1211.5Sthorpej *	u_intN_t bus_space_read_N __P((bus_space_tag_t tag,
1221.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset));
1231.5Sthorpej *
1241.5Sthorpej * Read a 1, 2, 4, or 8 byte quantity from bus space
1251.5Sthorpej * described by tag/handle/offset.
1261.1Sjonathan */
1271.1Sjonathan
1281.5Sthorpej#define	bus_space_read_1(t, h, o)					\
1291.5Sthorpej    (wbflush(),						/* XXX */	\
1301.5Sthorpej     (void) t, (*(volatile u_int8_t *)((h) + (o))))
1311.5Sthorpej
1321.5Sthorpej#define	bus_space_read_2(t, h, o)					\
1331.5Sthorpej    (wbflush(),						/* XXX */	\
1341.5Sthorpej     (void) t, (*(volatile u_int16_t *)((h) + (o))))
1351.5Sthorpej
1361.5Sthorpej#define	bus_space_read_4(t, h, o)					\
1371.5Sthorpej    (wbflush(),						/* XXX */	\
1381.5Sthorpej     (void) t, (*(volatile u_int32_t *)((h) + (o))))
1391.5Sthorpej
1401.5Sthorpej#if 0	/* Cause a link error for bus_space_read_8 */
1411.5Sthorpej#define	bus_space_read_8(t, h, o)	!!! bus_space_read_8 unimplemented !!!
1421.5Sthorpej#endif
1431.1Sjonathan
1441.5Sthorpej/*
1451.5Sthorpej *	void bus_space_read_multi_N __P((bus_space_tag_t tag,
1461.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
1471.5Sthorpej *	    u_intN_t *addr, size_t count));
1481.5Sthorpej *
1491.5Sthorpej * Read `count' 1, 2, 4, or 8 byte quantities from bus space
1501.5Sthorpej * described by tag/handle/offset and copy into buffer provided.
1511.5Sthorpej */
1521.5Sthorpej
1531.5Sthorpej#define __PMAX_bus_space_read_multi(BYTES,BITS)				\
1541.5Sthorpejstatic __inline void __CONCAT(bus_space_read_multi_,BYTES)		\
1551.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
1561.5Sthorpej	__PB_TYPENAME(BITS) *, size_t));				\
1571.5Sthorpej									\
1581.5Sthorpejstatic __inline void							\
1591.5Sthorpej__CONCAT(bus_space_read_multi_,BYTES)(t, h, o, a, c)			\
1601.5Sthorpej	bus_space_tag_t t;						\
1611.5Sthorpej	bus_space_handle_t h;						\
1621.5Sthorpej	bus_size_t o;							\
1631.5Sthorpej	__PB_TYPENAME(BITS) *a;						\
1641.5Sthorpej	size_t c;							\
1651.5Sthorpej{									\
1661.5Sthorpej									\
1671.5Sthorpej	while (c--)							\
1681.5Sthorpej		*a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o);	\
1691.5Sthorpej}
1701.5Sthorpej
1711.5Sthorpej__PMAX_bus_space_read_multi(1,8)
1721.5Sthorpej__PMAX_bus_space_read_multi(2,16)
1731.5Sthorpej__PMAX_bus_space_read_multi(4,32)
1741.5Sthorpej
1751.5Sthorpej#if 0	/* Cause a link error for bus_space_read_multi_8 */
1761.5Sthorpej#define	bus_space_read_multi_8	!!! bus_space_read_multi_8 unimplemented !!!
1771.5Sthorpej#endif
1781.1Sjonathan
1791.5Sthorpej#undef __PMAX_bus_space_read_multi
1801.1Sjonathan
1811.1Sjonathan/*
1821.5Sthorpej *	void bus_space_read_region_N __P((bus_space_tag_t tag,
1831.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
1841.5Sthorpej *	    u_intN_t *addr, size_t count));
1851.5Sthorpej *
1861.5Sthorpej * Read `count' 1, 2, 4, or 8 byte quantities from bus space
1871.5Sthorpej * described by tag/handle and starting at `offset' and copy into
1881.5Sthorpej * buffer provided.
1891.1Sjonathan */
1901.1Sjonathan
1911.5Sthorpej#define __PMAX_bus_space_read_region(BYTES,BITS)			\
1921.5Sthorpejstatic __inline void __CONCAT(bus_space_read_region_,BYTES)		\
1931.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
1941.5Sthorpej	__PB_TYPENAME(BITS) *, size_t));				\
1951.5Sthorpej									\
1961.5Sthorpejstatic __inline void							\
1971.5Sthorpej__CONCAT(bus_space_read_region_,BYTES)(t, h, o, a, c)			\
1981.5Sthorpej	bus_space_tag_t t;						\
1991.5Sthorpej	bus_space_handle_t h;						\
2001.5Sthorpej	bus_size_t o;							\
2011.5Sthorpej	__PB_TYPENAME(BITS) *a;						\
2021.5Sthorpej	size_t c;							\
2031.5Sthorpej{									\
2041.5Sthorpej									\
2051.5Sthorpej	while (c--) {							\
2061.5Sthorpej		*a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o);	\
2071.5Sthorpej		o += BYTES;						\
2081.5Sthorpej	}								\
2091.5Sthorpej}
2101.5Sthorpej
2111.5Sthorpej__PMAX_bus_space_read_region(1,8)
2121.5Sthorpej__PMAX_bus_space_read_region(2,16)
2131.5Sthorpej__PMAX_bus_space_read_region(4,32)
2141.5Sthorpej
2151.5Sthorpej#if 0	/* Cause a link error for bus_space_read_region_8 */
2161.5Sthorpej#define	bus_space_read_region_8	!!! bus_space_read_region_8 unimplemented !!!
2171.5Sthorpej#endif
2181.1Sjonathan
2191.5Sthorpej#undef __PMAX_bus_space_read_region
2201.1Sjonathan
2211.1Sjonathan/*
2221.5Sthorpej *	void bus_space_write_N __P((bus_space_tag_t tag,
2231.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
2241.5Sthorpej *	    u_intN_t value));
2251.5Sthorpej *
2261.5Sthorpej * Write the 1, 2, 4, or 8 byte value `value' to bus space
2271.5Sthorpej * described by tag/handle/offset.
2281.1Sjonathan */
2291.1Sjonathan
2301.5Sthorpej#define	bus_space_write_1(t, h, o, v)					\
2311.5Sthorpejdo {									\
2321.5Sthorpej	(void) t;							\
2331.5Sthorpej	*(volatile u_int8_t *)((h) + (o)) = (v);			\
2341.5Sthorpej	wbflush();					/* XXX */	\
2351.5Sthorpej} while (0)
2361.5Sthorpej
2371.5Sthorpej#define	bus_space_write_2(t, h, o, v)					\
2381.5Sthorpejdo {									\
2391.5Sthorpej	(void) t;							\
2401.5Sthorpej	*(volatile u_int16_t *)((h) + (o)) = (v);			\
2411.5Sthorpej	wbflush();					/* XXX */	\
2421.5Sthorpej} while (0)
2431.5Sthorpej
2441.5Sthorpej#define	bus_space_write_4(t, h, o, v)					\
2451.5Sthorpejdo {									\
2461.5Sthorpej	(void) t;							\
2471.5Sthorpej	*(volatile u_int32_t *)((h) + (o)) = (v);			\
2481.5Sthorpej	wbflush();					/* XXX */	\
2491.5Sthorpej} while (0)
2501.5Sthorpej
2511.5Sthorpej#if 0	/* Cause a link error for bus_space_write_8 */
2521.5Sthorpej#define	bus_space_write_8	!!! bus_space_write_8 not implemented !!!
2531.5Sthorpej#endif
2541.5Sthorpej
2551.5Sthorpej/*
2561.5Sthorpej *	void bus_space_write_multi_N __P((bus_space_tag_t tag,
2571.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
2581.5Sthorpej *	    const u_intN_t *addr, size_t count));
2591.5Sthorpej *
2601.5Sthorpej * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
2611.5Sthorpej * provided to bus space described by tag/handle/offset.
2621.5Sthorpej */
2631.5Sthorpej
2641.5Sthorpej#define __PMAX_bus_space_write_multi(BYTES,BITS)			\
2651.5Sthorpejstatic __inline void __CONCAT(bus_space_write_multi_,BYTES)		\
2661.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
2671.5Sthorpej	__PB_TYPENAME(BITS) *, size_t));				\
2681.5Sthorpej									\
2691.5Sthorpejstatic __inline void							\
2701.5Sthorpej__CONCAT(bus_space_write_multi_,BYTES)(t, h, o, a, c)			\
2711.5Sthorpej	bus_space_tag_t t;						\
2721.5Sthorpej	bus_space_handle_t h;						\
2731.5Sthorpej	bus_size_t o;							\
2741.5Sthorpej	__PB_TYPENAME(BITS) *a;						\
2751.5Sthorpej	size_t c;							\
2761.5Sthorpej{									\
2771.5Sthorpej									\
2781.5Sthorpej	while (c--)							\
2791.5Sthorpej		__CONCAT(bus_space_write_,BYTES)(t, h, o, *a++);	\
2801.5Sthorpej}
2811.5Sthorpej
2821.5Sthorpej__PMAX_bus_space_write_multi(1,8)
2831.5Sthorpej__PMAX_bus_space_write_multi(2,16)
2841.5Sthorpej__PMAX_bus_space_write_multi(4,32)
2851.5Sthorpej
2861.5Sthorpej#if 0	/* Cause a link error for bus_space_write_8 */
2871.5Sthorpej#define	bus_space_write_multi_8(t, h, o, a, c)				\
2881.5Sthorpej			!!! bus_space_write_multi_8 unimplimented !!!
2891.5Sthorpej#endif
2901.5Sthorpej
2911.5Sthorpej#undef __PMAX_bus_space_write_multi
2921.5Sthorpej
2931.5Sthorpej/*
2941.5Sthorpej *	void bus_space_write_region_N __P((bus_space_tag_t tag,
2951.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
2961.5Sthorpej *	    const u_intN_t *addr, size_t count));
2971.5Sthorpej *
2981.5Sthorpej * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
2991.5Sthorpej * to bus space described by tag/handle starting at `offset'.
3001.5Sthorpej */
3011.1Sjonathan
3021.5Sthorpej#define __PMAX_bus_space_write_region(BYTES,BITS)			\
3031.5Sthorpejstatic __inline void __CONCAT(bus_space_write_region_,BYTES)		\
3041.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
3051.5Sthorpej	__PB_TYPENAME(BITS) *, size_t));				\
3061.5Sthorpej									\
3071.5Sthorpejstatic __inline void							\
3081.5Sthorpej__CONCAT(bus_space_write_region_,BYTES)(t, h, o, a, c)			\
3091.5Sthorpej	bus_space_tag_t t;						\
3101.5Sthorpej	bus_space_handle_t h;						\
3111.5Sthorpej	bus_size_t o;							\
3121.5Sthorpej	__PB_TYPENAME(BITS) *a;						\
3131.5Sthorpej	size_t c;							\
3141.5Sthorpej{									\
3151.5Sthorpej									\
3161.5Sthorpej	while (c--) {							\
3171.5Sthorpej		__CONCAT(bus_space_write_,BYTES)(t, h, o, *a++);	\
3181.5Sthorpej		o += BYTES;						\
3191.5Sthorpej	}								\
3201.5Sthorpej}
3211.5Sthorpej
3221.5Sthorpej__PMAX_bus_space_write_region(1,8)
3231.5Sthorpej__PMAX_bus_space_write_region(2,16)
3241.5Sthorpej__PMAX_bus_space_write_region(4,32)
3251.5Sthorpej
3261.5Sthorpej#if 0	/* Cause a link error for bus_space_write_region_8 */
3271.5Sthorpej#define	bus_space_write_region_8					\
3281.5Sthorpej			!!! bus_space_write_region_8 unimplemented !!!
3291.5Sthorpej#endif
3301.1Sjonathan
3311.5Sthorpej#undef __PMAX_bus_space_write_region
3321.1Sjonathan
3331.1Sjonathan/*
3341.5Sthorpej *	void bus_space_set_multi_N __P((bus_space_tag_t tag,
3351.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
3361.5Sthorpej *	    size_t count));
3371.5Sthorpej *
3381.5Sthorpej * Write the 1, 2, 4, or 8 byte value `val' to bus space described
3391.5Sthorpej * by tag/handle/offset `count' times.
3401.5Sthorpej */
3411.5Sthorpej
3421.5Sthorpej#define __PMAX_bus_space_set_multi(BYTES,BITS)				\
3431.5Sthorpejstatic __inline void __CONCAT(bus_space_set_multi_,BYTES)		\
3441.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
3451.5Sthorpej	__PB_TYPENAME(BITS), size_t));					\
3461.5Sthorpej									\
3471.5Sthorpejstatic __inline void							\
3481.5Sthorpej__CONCAT(bus_space_set_multi_,BYTES)(t, h, o, v, c)			\
3491.5Sthorpej	bus_space_tag_t t;						\
3501.5Sthorpej	bus_space_handle_t h;						\
3511.5Sthorpej	bus_size_t o;							\
3521.5Sthorpej	__PB_TYPENAME(BITS) v;						\
3531.5Sthorpej	size_t c;							\
3541.5Sthorpej{									\
3551.5Sthorpej									\
3561.5Sthorpej	while (c--)							\
3571.5Sthorpej		__CONCAT(bus_space_write_,BYTES)(t, h, o, v);		\
3581.5Sthorpej}
3591.5Sthorpej
3601.5Sthorpej__PMAX_bus_space_set_multi(1,8)
3611.5Sthorpej__PMAX_bus_space_set_multi(2,16)
3621.5Sthorpej__PMAX_bus_space_set_multi(4,32)
3631.5Sthorpej
3641.5Sthorpej#if 0	/* Cause a link error for bus_space_set_multi_8 */
3651.5Sthorpej#define	bus_space_set_multi_8						\
3661.5Sthorpej			!!! bus_space_set_multi_8 unimplemented !!!
3671.5Sthorpej#endif
3681.5Sthorpej
3691.5Sthorpej#undef __PMAX_bus_space_set_multi
3701.5Sthorpej
3711.5Sthorpej/*
3721.5Sthorpej *	void bus_space_set_region_N __P((bus_space_tag_t tag,
3731.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
3741.5Sthorpej *	    size_t count));
3751.5Sthorpej *
3761.5Sthorpej * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
3771.5Sthorpej * by tag/handle starting at `offset'.
3781.5Sthorpej */
3791.5Sthorpej
3801.5Sthorpej#define __PMAX_bus_space_set_region(BYTES,BITS)				\
3811.5Sthorpejstatic __inline void __CONCAT(bus_space_set_region_,BYTES)		\
3821.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
3831.5Sthorpej	__PB_TYPENAME(BITS), size_t));					\
3841.5Sthorpej									\
3851.5Sthorpejstatic __inline void							\
3861.5Sthorpej__CONCAT(bus_space_set_region_,BYTES)(t, h, o, v, c)			\
3871.5Sthorpej	bus_space_tag_t t;						\
3881.5Sthorpej	bus_space_handle_t h;						\
3891.5Sthorpej	bus_size_t o;							\
3901.5Sthorpej	__PB_TYPENAME(BITS) v;						\
3911.5Sthorpej	size_t c;							\
3921.5Sthorpej{									\
3931.5Sthorpej									\
3941.5Sthorpej	while (c--) {							\
3951.5Sthorpej		__CONCAT(bus_space_write_,BYTES)(t, h, o, v);		\
3961.5Sthorpej		o += BYTES;						\
3971.5Sthorpej	}								\
3981.5Sthorpej}
3991.5Sthorpej
4001.5Sthorpej__PMAX_bus_space_set_region(1,8)
4011.5Sthorpej__PMAX_bus_space_set_region(2,16)
4021.5Sthorpej__PMAX_bus_space_set_region(4,32)
4031.5Sthorpej
4041.5Sthorpej#if 0	/* Cause a link error for bus_space_set_region_8 */
4051.5Sthorpej#define	bus_space_set_region_8						\
4061.5Sthorpej			!!! bus_space_set_region_8 unimplemented !!!
4071.5Sthorpej#endif
4081.5Sthorpej
4091.5Sthorpej#undef __PMAX_bus_space_set_region
4101.5Sthorpej
4111.5Sthorpej/*
4121.5Sthorpej *	void bus_space_copy_region_N __P((bus_space_tag_t tag,
4131.5Sthorpej *	    bus_space_handle_t bsh1, bus_size_t off1,
4141.5Sthorpej *	    bus_space_handle_t bsh2, bus_size_t off2,
4151.5Sthorpej *	    bus_size_t count));
4161.5Sthorpej *
4171.5Sthorpej * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
4181.5Sthorpej * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
4191.5Sthorpej */
4201.5Sthorpej
4211.5Sthorpej#define	__PMAX_copy_region(BYTES)					\
4221.5Sthorpejstatic __inline void __CONCAT(bus_space_copy_region_,BYTES)		\
4231.5Sthorpej	__P((bus_space_tag_t,						\
4241.5Sthorpej	    bus_space_handle_t bsh1, bus_size_t off1,			\
4251.5Sthorpej	    bus_space_handle_t bsh2, bus_size_t off2,			\
4261.5Sthorpej	    bus_size_t count));						\
4271.5Sthorpej									\
4281.5Sthorpejstatic __inline void							\
4291.5Sthorpej__CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c)		\
4301.5Sthorpej	bus_space_tag_t t;						\
4311.5Sthorpej	bus_space_handle_t h1, h2;					\
4321.5Sthorpej	bus_size_t o1, o2, c;						\
4331.5Sthorpej{									\
4341.5Sthorpej	bus_size_t o;							\
4351.5Sthorpej									\
4361.5Sthorpej	if ((h1 + o1) >= (h2 + o2)) {					\
4371.5Sthorpej		/* src after dest: copy forward */			\
4381.5Sthorpej		for (o = 0; c != 0; c--, o += BYTES)			\
4391.5Sthorpej			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
4401.5Sthorpej			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
4411.5Sthorpej	} else {							\
4421.5Sthorpej		/* dest after src: copy backwards */			\
4431.5Sthorpej		for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)	\
4441.5Sthorpej			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
4451.5Sthorpej			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
4461.5Sthorpej	}								\
4471.5Sthorpej}
4481.5Sthorpej
4491.5Sthorpej__PMAX_copy_region(1)
4501.5Sthorpej__PMAX_copy_region(2)
4511.5Sthorpej__PMAX_copy_region(4)
4521.5Sthorpej
4531.5Sthorpej#if 0	/* Cause a link error for bus_space_copy_region_8 */
4541.5Sthorpej#define	bus_space_copy_region_8						\
4551.5Sthorpej			!!! bus_space_copy_region_8 unimplemented !!!
4561.5Sthorpej#endif
4571.5Sthorpej
4581.5Sthorpej#undef __PMAX_copy_region
4591.5Sthorpej
4601.5Sthorpej/*
4611.5Sthorpej * Bus read/write barrier methods.
4621.5Sthorpej *
4631.5Sthorpej *	void bus_space_barrier __P((bus_space_tag_t tag,
4641.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
4651.5Sthorpej *	    bus_size_t len, int flags));
4661.5Sthorpej *
4671.5Sthorpej * On the MIPS, we just flush the write buffer.
4681.5Sthorpej */
4691.5Sthorpej#define	bus_space_barrier(t, h, o, l, f)	\
4701.5Sthorpej	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)),	\
4711.5Sthorpej	 wbflush())
4721.5Sthorpej#define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
4731.5Sthorpej#define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
4741.5Sthorpej
4751.5Sthorpej#undef __PB_TYPENAME_PREFIX
4761.5Sthorpej#undef __PB_TYPENAME
4771.5Sthorpej
4781.5Sthorpej/*
4791.5Sthorpej * Flags used in various bus DMA methods.
4801.5Sthorpej */
4811.5Sthorpej#define	BUS_DMA_WAITOK		0x00	/* safe to sleep (pseudo-flag) */
4821.5Sthorpej#define	BUS_DMA_NOWAIT		0x01	/* not safe to sleep */
4831.5Sthorpej#define	BUS_DMA_ALLOCNOW	0x02	/* perform resource allocation now */
4841.5Sthorpej#define	BUS_DMA_COHERENT	0x04	/* hint: map memory DMA coherent */
4851.5Sthorpej#define	BUS_DMA_BUS1		0x10	/* placeholders for bus functions... */
4861.5Sthorpej#define	BUS_DMA_BUS2		0x20
4871.5Sthorpej#define	BUS_DMA_BUS3		0x40
4881.5Sthorpej#define	BUS_DMA_BUS4		0x80
4891.5Sthorpej
4901.5Sthorpej#define	PMAX_DMAMAP_COHERENT	0x100	/* no cache flush necessary on sync */
4911.5Sthorpej
4921.5Sthorpej/* Forwards needed by prototypes below. */
4931.5Sthorpejstruct mbuf;
4941.5Sthorpejstruct uio;
4951.5Sthorpej
4961.5Sthorpej/*
4971.5Sthorpej * Operations performed by bus_dmamap_sync().
4981.5Sthorpej */
4991.5Sthorpej#define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
5001.5Sthorpej#define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
5011.5Sthorpej#define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
5021.5Sthorpej#define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
5031.5Sthorpej
5041.5Sthorpejtypedef struct pmax_bus_dma_tag		*bus_dma_tag_t;
5051.5Sthorpejtypedef struct pmax_bus_dmamap		*bus_dmamap_t;
5061.5Sthorpej
5071.5Sthorpej/*
5081.5Sthorpej *	bus_dma_segment_t
5091.5Sthorpej *
5101.5Sthorpej *	Describes a single contiguous DMA transaction.  Values
5111.5Sthorpej *	are suitable for programming into DMA registers.
5121.5Sthorpej */
5131.5Sthorpejstruct pmax_bus_dma_segment {
5141.5Sthorpej	bus_addr_t	ds_addr;	/* DMA address */
5151.5Sthorpej	bus_size_t	ds_len;		/* length of transfer */
5161.6Sthorpej	bus_addr_t	_ds_vaddr;	/* virtual address, 0 if invalid */
5171.5Sthorpej};
5181.5Sthorpejtypedef struct pmax_bus_dma_segment	bus_dma_segment_t;
5191.5Sthorpej
5201.5Sthorpej/*
5211.5Sthorpej *	bus_dma_tag_t
5221.5Sthorpej *
5231.5Sthorpej *	A machine-dependent opaque type describing the implementation of
5241.5Sthorpej *	DMA for a given bus.
5251.5Sthorpej */
5261.5Sthorpej
5271.5Sthorpejstruct pmax_bus_dma_tag {
5281.5Sthorpej	/*
5291.5Sthorpej	 * DMA mapping methods.
5301.5Sthorpej	 */
5311.5Sthorpej	int	(*_dmamap_create) __P((bus_dma_tag_t, bus_size_t, int,
5321.5Sthorpej		    bus_size_t, bus_size_t, int, bus_dmamap_t *));
5331.5Sthorpej	void	(*_dmamap_destroy) __P((bus_dma_tag_t, bus_dmamap_t));
5341.5Sthorpej	int	(*_dmamap_load) __P((bus_dma_tag_t, bus_dmamap_t, void *,
5351.5Sthorpej		    bus_size_t, struct proc *, int));
5361.5Sthorpej	int	(*_dmamap_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t,
5371.5Sthorpej		    struct mbuf *, int));
5381.5Sthorpej	int	(*_dmamap_load_uio) __P((bus_dma_tag_t, bus_dmamap_t,
5391.5Sthorpej		    struct uio *, int));
5401.5Sthorpej	int	(*_dmamap_load_raw) __P((bus_dma_tag_t, bus_dmamap_t,
5411.5Sthorpej		    bus_dma_segment_t *, int, bus_size_t, int));
5421.5Sthorpej	void	(*_dmamap_unload) __P((bus_dma_tag_t, bus_dmamap_t));
5431.5Sthorpej	void	(*_dmamap_sync) __P((bus_dma_tag_t, bus_dmamap_t,
5441.5Sthorpej		    bus_addr_t, bus_size_t, int));
5451.5Sthorpej
5461.5Sthorpej	/*
5471.5Sthorpej	 * DMA memory utility functions.
5481.5Sthorpej	 */
5491.5Sthorpej	int	(*_dmamem_alloc) __P((bus_dma_tag_t, bus_size_t, bus_size_t,
5501.5Sthorpej		    bus_size_t, bus_dma_segment_t *, int, int *, int));
5511.5Sthorpej	void	(*_dmamem_free) __P((bus_dma_tag_t,
5521.5Sthorpej		    bus_dma_segment_t *, int));
5531.5Sthorpej	int	(*_dmamem_map) __P((bus_dma_tag_t, bus_dma_segment_t *,
5541.5Sthorpej		    int, size_t, caddr_t *, int));
5551.5Sthorpej	void	(*_dmamem_unmap) __P((bus_dma_tag_t, caddr_t, size_t));
5561.5Sthorpej	int	(*_dmamem_mmap) __P((bus_dma_tag_t, bus_dma_segment_t *,
5571.5Sthorpej		    int, int, int, int));
5581.5Sthorpej};
5591.5Sthorpej
5601.5Sthorpej#define	bus_dmamap_create(t, s, n, m, b, f, p)			\
5611.5Sthorpej	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
5621.5Sthorpej#define	bus_dmamap_destroy(t, p)				\
5631.5Sthorpej	(*(t)->_dmamap_destroy)((t), (p))
5641.5Sthorpej#define	bus_dmamap_load(t, m, b, s, p, f)			\
5651.5Sthorpej	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
5661.5Sthorpej#define	bus_dmamap_load_mbuf(t, m, b, f)			\
5671.5Sthorpej	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
5681.5Sthorpej#define	bus_dmamap_load_uio(t, m, u, f)				\
5691.5Sthorpej	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
5701.5Sthorpej#define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
5711.5Sthorpej	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
5721.5Sthorpej#define	bus_dmamap_unload(t, p)					\
5731.5Sthorpej	(*(t)->_dmamap_unload)((t), (p))
5741.5Sthorpej#define	bus_dmamap_sync(t, p, o, l, ops)			\
5751.5Sthorpej	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
5761.5Sthorpej
5771.5Sthorpej#define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
5781.5Sthorpej	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
5791.5Sthorpej#define	bus_dmamem_free(t, sg, n)				\
5801.5Sthorpej	(*(t)->_dmamem_free)((t), (sg), (n))
5811.5Sthorpej#define	bus_dmamem_map(t, sg, n, s, k, f)			\
5821.5Sthorpej	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
5831.5Sthorpej#define	bus_dmamem_unmap(t, k, s)				\
5841.5Sthorpej	(*(t)->_dmamem_unmap)((t), (k), (s))
5851.5Sthorpej#define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
5861.5Sthorpej	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
5871.5Sthorpej
5881.5Sthorpej/*
5891.5Sthorpej *	bus_dmamap_t
5901.5Sthorpej *
5911.5Sthorpej *	Describes a DMA mapping.
5921.1Sjonathan */
5931.5Sthorpejstruct pmax_bus_dmamap {
5941.5Sthorpej	/*
5951.5Sthorpej	 * PRIVATE MEMBERS: not for use my machine-independent code.
5961.5Sthorpej	 */
5971.5Sthorpej	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
5981.5Sthorpej	int		_dm_segcnt;	/* number of segs this map can map */
5991.5Sthorpej	bus_size_t	_dm_maxsegsz;	/* largest possible segment */
6001.5Sthorpej	bus_size_t	_dm_boundary;	/* don't cross this */
6011.5Sthorpej	int		_dm_flags;	/* misc. flags */
6021.5Sthorpej
6031.5Sthorpej	/*
6041.5Sthorpej	 * PUBLIC MEMBERS: these are used by machine-independent code.
6051.5Sthorpej	 */
6061.5Sthorpej	bus_size_t	dm_mapsize;	/* size of the mapping */
6071.5Sthorpej	int		dm_nsegs;	/* # valid segments in mapping */
6081.5Sthorpej	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
6091.5Sthorpej};
6101.5Sthorpej
6111.5Sthorpej#ifdef _PMAX_BUS_DMA_PRIVATE
6121.5Sthorpejint	_bus_dmamap_create __P((bus_dma_tag_t, bus_size_t, int, bus_size_t,
6131.5Sthorpej	    bus_size_t, int, bus_dmamap_t *));
6141.5Sthorpejvoid	_bus_dmamap_destroy __P((bus_dma_tag_t, bus_dmamap_t));
6151.5Sthorpejint	_bus_dmamap_load __P((bus_dma_tag_t, bus_dmamap_t, void *,
6161.5Sthorpej	    bus_size_t, struct proc *, int));
6171.5Sthorpejint	_bus_dmamap_load_mbuf __P((bus_dma_tag_t, bus_dmamap_t,
6181.5Sthorpej	    struct mbuf *, int));
6191.5Sthorpejint	_bus_dmamap_load_uio __P((bus_dma_tag_t, bus_dmamap_t,
6201.5Sthorpej	    struct uio *, int));
6211.5Sthorpejint	_bus_dmamap_load_raw __P((bus_dma_tag_t, bus_dmamap_t,
6221.5Sthorpej	    bus_dma_segment_t *, int, bus_size_t, int));
6231.5Sthorpejvoid	_bus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
6241.5Sthorpejvoid	_bus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
6251.5Sthorpej	    bus_size_t, int));
6261.5Sthorpej
6271.5Sthorpejint	_bus_dmamem_alloc __P((bus_dma_tag_t tag, bus_size_t size,
6281.5Sthorpej	    bus_size_t alignment, bus_size_t boundary,
6291.5Sthorpej	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags));
6301.5Sthorpejvoid	_bus_dmamem_free __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
6311.5Sthorpej	    int nsegs));
6321.5Sthorpejint	_bus_dmamem_map __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
6331.5Sthorpej	    int nsegs, size_t size, caddr_t *kvap, int flags));
6341.5Sthorpejvoid	_bus_dmamem_unmap __P((bus_dma_tag_t tag, caddr_t kva,
6351.5Sthorpej	    size_t size));
6361.5Sthorpejint	_bus_dmamem_mmap __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
6371.5Sthorpej	    int nsegs, int off, int prot, int flags));
6381.5Sthorpej
6391.5Sthorpejint	_bus_dmamem_alloc_range __P((bus_dma_tag_t tag, bus_size_t size,
6401.5Sthorpej	    bus_size_t alignment, bus_size_t boundary,
6411.5Sthorpej	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
6421.5Sthorpej	    vm_offset_t low, vm_offset_t high));
6431.1Sjonathan
6441.5Sthorpejextern struct pmax_bus_dma_tag pmax_default_bus_dma_tag;
6451.5Sthorpej#endif /* _PMAX_BUS_DMA_PRIVATE */
6461.1Sjonathan
6471.1Sjonathan#endif /* _PMAX_BUS_H_ */
648