bus.h revision 1.10
11.10Sad/*	$NetBSD: bus.h,v 1.10 2000/01/09 15:34:42 ad 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.9Snisimura     ((void) t, (*(volatile u_int8_t *)((h) + (o))))
1301.5Sthorpej
1311.5Sthorpej#define	bus_space_read_2(t, h, o)					\
1321.9Snisimura     ((void) t, (*(volatile u_int16_t *)((h) + (o))))
1331.5Sthorpej
1341.5Sthorpej#define	bus_space_read_4(t, h, o)					\
1351.9Snisimura     ((void) t, (*(volatile u_int32_t *)((h) + (o))))
1361.5Sthorpej
1371.5Sthorpej#if 0	/* Cause a link error for bus_space_read_8 */
1381.5Sthorpej#define	bus_space_read_8(t, h, o)	!!! bus_space_read_8 unimplemented !!!
1391.5Sthorpej#endif
1401.1Sjonathan
1411.5Sthorpej/*
1421.5Sthorpej *	void bus_space_read_multi_N __P((bus_space_tag_t tag,
1431.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
1441.5Sthorpej *	    u_intN_t *addr, size_t count));
1451.5Sthorpej *
1461.5Sthorpej * Read `count' 1, 2, 4, or 8 byte quantities from bus space
1471.5Sthorpej * described by tag/handle/offset and copy into buffer provided.
1481.5Sthorpej */
1491.5Sthorpej
1501.5Sthorpej#define __PMAX_bus_space_read_multi(BYTES,BITS)				\
1511.5Sthorpejstatic __inline void __CONCAT(bus_space_read_multi_,BYTES)		\
1521.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
1531.5Sthorpej	__PB_TYPENAME(BITS) *, size_t));				\
1541.5Sthorpej									\
1551.5Sthorpejstatic __inline void							\
1561.5Sthorpej__CONCAT(bus_space_read_multi_,BYTES)(t, h, o, a, c)			\
1571.5Sthorpej	bus_space_tag_t t;						\
1581.5Sthorpej	bus_space_handle_t h;						\
1591.5Sthorpej	bus_size_t o;							\
1601.5Sthorpej	__PB_TYPENAME(BITS) *a;						\
1611.5Sthorpej	size_t c;							\
1621.5Sthorpej{									\
1631.5Sthorpej									\
1641.5Sthorpej	while (c--)							\
1651.5Sthorpej		*a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o);	\
1661.5Sthorpej}
1671.5Sthorpej
1681.5Sthorpej__PMAX_bus_space_read_multi(1,8)
1691.5Sthorpej__PMAX_bus_space_read_multi(2,16)
1701.5Sthorpej__PMAX_bus_space_read_multi(4,32)
1711.5Sthorpej
1721.5Sthorpej#if 0	/* Cause a link error for bus_space_read_multi_8 */
1731.5Sthorpej#define	bus_space_read_multi_8	!!! bus_space_read_multi_8 unimplemented !!!
1741.5Sthorpej#endif
1751.1Sjonathan
1761.5Sthorpej#undef __PMAX_bus_space_read_multi
1771.1Sjonathan
1781.1Sjonathan/*
1791.5Sthorpej *	void bus_space_read_region_N __P((bus_space_tag_t tag,
1801.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
1811.5Sthorpej *	    u_intN_t *addr, size_t count));
1821.5Sthorpej *
1831.5Sthorpej * Read `count' 1, 2, 4, or 8 byte quantities from bus space
1841.5Sthorpej * described by tag/handle and starting at `offset' and copy into
1851.5Sthorpej * buffer provided.
1861.1Sjonathan */
1871.1Sjonathan
1881.5Sthorpej#define __PMAX_bus_space_read_region(BYTES,BITS)			\
1891.5Sthorpejstatic __inline void __CONCAT(bus_space_read_region_,BYTES)		\
1901.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
1911.5Sthorpej	__PB_TYPENAME(BITS) *, size_t));				\
1921.5Sthorpej									\
1931.5Sthorpejstatic __inline void							\
1941.5Sthorpej__CONCAT(bus_space_read_region_,BYTES)(t, h, o, a, c)			\
1951.5Sthorpej	bus_space_tag_t t;						\
1961.5Sthorpej	bus_space_handle_t h;						\
1971.5Sthorpej	bus_size_t o;							\
1981.5Sthorpej	__PB_TYPENAME(BITS) *a;						\
1991.5Sthorpej	size_t c;							\
2001.5Sthorpej{									\
2011.5Sthorpej									\
2021.5Sthorpej	while (c--) {							\
2031.5Sthorpej		*a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o);	\
2041.5Sthorpej		o += BYTES;						\
2051.5Sthorpej	}								\
2061.5Sthorpej}
2071.5Sthorpej
2081.5Sthorpej__PMAX_bus_space_read_region(1,8)
2091.5Sthorpej__PMAX_bus_space_read_region(2,16)
2101.5Sthorpej__PMAX_bus_space_read_region(4,32)
2111.5Sthorpej
2121.5Sthorpej#if 0	/* Cause a link error for bus_space_read_region_8 */
2131.5Sthorpej#define	bus_space_read_region_8	!!! bus_space_read_region_8 unimplemented !!!
2141.5Sthorpej#endif
2151.1Sjonathan
2161.5Sthorpej#undef __PMAX_bus_space_read_region
2171.1Sjonathan
2181.1Sjonathan/*
2191.5Sthorpej *	void bus_space_write_N __P((bus_space_tag_t tag,
2201.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
2211.5Sthorpej *	    u_intN_t value));
2221.5Sthorpej *
2231.5Sthorpej * Write the 1, 2, 4, or 8 byte value `value' to bus space
2241.5Sthorpej * described by tag/handle/offset.
2251.1Sjonathan */
2261.1Sjonathan
2271.5Sthorpej#define	bus_space_write_1(t, h, o, v)					\
2281.5Sthorpejdo {									\
2291.5Sthorpej	(void) t;							\
2301.5Sthorpej	*(volatile u_int8_t *)((h) + (o)) = (v);			\
2311.5Sthorpej	wbflush();					/* XXX */	\
2321.5Sthorpej} while (0)
2331.5Sthorpej
2341.5Sthorpej#define	bus_space_write_2(t, h, o, v)					\
2351.5Sthorpejdo {									\
2361.5Sthorpej	(void) t;							\
2371.5Sthorpej	*(volatile u_int16_t *)((h) + (o)) = (v);			\
2381.5Sthorpej	wbflush();					/* XXX */	\
2391.5Sthorpej} while (0)
2401.5Sthorpej
2411.5Sthorpej#define	bus_space_write_4(t, h, o, v)					\
2421.5Sthorpejdo {									\
2431.5Sthorpej	(void) t;							\
2441.5Sthorpej	*(volatile u_int32_t *)((h) + (o)) = (v);			\
2451.5Sthorpej	wbflush();					/* XXX */	\
2461.5Sthorpej} while (0)
2471.5Sthorpej
2481.5Sthorpej#if 0	/* Cause a link error for bus_space_write_8 */
2491.5Sthorpej#define	bus_space_write_8	!!! bus_space_write_8 not implemented !!!
2501.5Sthorpej#endif
2511.5Sthorpej
2521.5Sthorpej/*
2531.5Sthorpej *	void bus_space_write_multi_N __P((bus_space_tag_t tag,
2541.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
2551.5Sthorpej *	    const u_intN_t *addr, size_t count));
2561.5Sthorpej *
2571.5Sthorpej * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
2581.5Sthorpej * provided to bus space described by tag/handle/offset.
2591.5Sthorpej */
2601.5Sthorpej
2611.5Sthorpej#define __PMAX_bus_space_write_multi(BYTES,BITS)			\
2621.5Sthorpejstatic __inline void __CONCAT(bus_space_write_multi_,BYTES)		\
2631.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
2641.5Sthorpej	__PB_TYPENAME(BITS) *, size_t));				\
2651.5Sthorpej									\
2661.5Sthorpejstatic __inline void							\
2671.5Sthorpej__CONCAT(bus_space_write_multi_,BYTES)(t, h, o, a, c)			\
2681.5Sthorpej	bus_space_tag_t t;						\
2691.5Sthorpej	bus_space_handle_t h;						\
2701.5Sthorpej	bus_size_t o;							\
2711.5Sthorpej	__PB_TYPENAME(BITS) *a;						\
2721.5Sthorpej	size_t c;							\
2731.5Sthorpej{									\
2741.5Sthorpej									\
2751.5Sthorpej	while (c--)							\
2761.5Sthorpej		__CONCAT(bus_space_write_,BYTES)(t, h, o, *a++);	\
2771.5Sthorpej}
2781.5Sthorpej
2791.5Sthorpej__PMAX_bus_space_write_multi(1,8)
2801.5Sthorpej__PMAX_bus_space_write_multi(2,16)
2811.5Sthorpej__PMAX_bus_space_write_multi(4,32)
2821.5Sthorpej
2831.5Sthorpej#if 0	/* Cause a link error for bus_space_write_8 */
2841.5Sthorpej#define	bus_space_write_multi_8(t, h, o, a, c)				\
2851.5Sthorpej			!!! bus_space_write_multi_8 unimplimented !!!
2861.5Sthorpej#endif
2871.5Sthorpej
2881.5Sthorpej#undef __PMAX_bus_space_write_multi
2891.5Sthorpej
2901.5Sthorpej/*
2911.5Sthorpej *	void bus_space_write_region_N __P((bus_space_tag_t tag,
2921.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
2931.5Sthorpej *	    const u_intN_t *addr, size_t count));
2941.5Sthorpej *
2951.5Sthorpej * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
2961.5Sthorpej * to bus space described by tag/handle starting at `offset'.
2971.5Sthorpej */
2981.1Sjonathan
2991.5Sthorpej#define __PMAX_bus_space_write_region(BYTES,BITS)			\
3001.5Sthorpejstatic __inline void __CONCAT(bus_space_write_region_,BYTES)		\
3011.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
3021.5Sthorpej	__PB_TYPENAME(BITS) *, size_t));				\
3031.5Sthorpej									\
3041.5Sthorpejstatic __inline void							\
3051.5Sthorpej__CONCAT(bus_space_write_region_,BYTES)(t, h, o, a, c)			\
3061.5Sthorpej	bus_space_tag_t t;						\
3071.5Sthorpej	bus_space_handle_t h;						\
3081.5Sthorpej	bus_size_t o;							\
3091.5Sthorpej	__PB_TYPENAME(BITS) *a;						\
3101.5Sthorpej	size_t c;							\
3111.5Sthorpej{									\
3121.5Sthorpej									\
3131.5Sthorpej	while (c--) {							\
3141.5Sthorpej		__CONCAT(bus_space_write_,BYTES)(t, h, o, *a++);	\
3151.5Sthorpej		o += BYTES;						\
3161.5Sthorpej	}								\
3171.5Sthorpej}
3181.5Sthorpej
3191.5Sthorpej__PMAX_bus_space_write_region(1,8)
3201.5Sthorpej__PMAX_bus_space_write_region(2,16)
3211.5Sthorpej__PMAX_bus_space_write_region(4,32)
3221.5Sthorpej
3231.5Sthorpej#if 0	/* Cause a link error for bus_space_write_region_8 */
3241.5Sthorpej#define	bus_space_write_region_8					\
3251.5Sthorpej			!!! bus_space_write_region_8 unimplemented !!!
3261.5Sthorpej#endif
3271.1Sjonathan
3281.5Sthorpej#undef __PMAX_bus_space_write_region
3291.1Sjonathan
3301.1Sjonathan/*
3311.5Sthorpej *	void bus_space_set_multi_N __P((bus_space_tag_t tag,
3321.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
3331.5Sthorpej *	    size_t count));
3341.5Sthorpej *
3351.5Sthorpej * Write the 1, 2, 4, or 8 byte value `val' to bus space described
3361.5Sthorpej * by tag/handle/offset `count' times.
3371.5Sthorpej */
3381.5Sthorpej
3391.5Sthorpej#define __PMAX_bus_space_set_multi(BYTES,BITS)				\
3401.5Sthorpejstatic __inline void __CONCAT(bus_space_set_multi_,BYTES)		\
3411.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
3421.5Sthorpej	__PB_TYPENAME(BITS), size_t));					\
3431.5Sthorpej									\
3441.5Sthorpejstatic __inline void							\
3451.5Sthorpej__CONCAT(bus_space_set_multi_,BYTES)(t, h, o, v, c)			\
3461.5Sthorpej	bus_space_tag_t t;						\
3471.5Sthorpej	bus_space_handle_t h;						\
3481.5Sthorpej	bus_size_t o;							\
3491.5Sthorpej	__PB_TYPENAME(BITS) v;						\
3501.5Sthorpej	size_t c;							\
3511.5Sthorpej{									\
3521.5Sthorpej									\
3531.5Sthorpej	while (c--)							\
3541.5Sthorpej		__CONCAT(bus_space_write_,BYTES)(t, h, o, v);		\
3551.5Sthorpej}
3561.5Sthorpej
3571.5Sthorpej__PMAX_bus_space_set_multi(1,8)
3581.5Sthorpej__PMAX_bus_space_set_multi(2,16)
3591.5Sthorpej__PMAX_bus_space_set_multi(4,32)
3601.5Sthorpej
3611.5Sthorpej#if 0	/* Cause a link error for bus_space_set_multi_8 */
3621.5Sthorpej#define	bus_space_set_multi_8						\
3631.5Sthorpej			!!! bus_space_set_multi_8 unimplemented !!!
3641.5Sthorpej#endif
3651.5Sthorpej
3661.5Sthorpej#undef __PMAX_bus_space_set_multi
3671.5Sthorpej
3681.5Sthorpej/*
3691.5Sthorpej *	void bus_space_set_region_N __P((bus_space_tag_t tag,
3701.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
3711.5Sthorpej *	    size_t count));
3721.5Sthorpej *
3731.5Sthorpej * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
3741.5Sthorpej * by tag/handle starting at `offset'.
3751.5Sthorpej */
3761.5Sthorpej
3771.5Sthorpej#define __PMAX_bus_space_set_region(BYTES,BITS)				\
3781.5Sthorpejstatic __inline void __CONCAT(bus_space_set_region_,BYTES)		\
3791.5Sthorpej	__P((bus_space_tag_t, bus_space_handle_t, bus_size_t,		\
3801.5Sthorpej	__PB_TYPENAME(BITS), size_t));					\
3811.5Sthorpej									\
3821.5Sthorpejstatic __inline void							\
3831.5Sthorpej__CONCAT(bus_space_set_region_,BYTES)(t, h, o, v, c)			\
3841.5Sthorpej	bus_space_tag_t t;						\
3851.5Sthorpej	bus_space_handle_t h;						\
3861.5Sthorpej	bus_size_t o;							\
3871.5Sthorpej	__PB_TYPENAME(BITS) v;						\
3881.5Sthorpej	size_t c;							\
3891.5Sthorpej{									\
3901.5Sthorpej									\
3911.5Sthorpej	while (c--) {							\
3921.5Sthorpej		__CONCAT(bus_space_write_,BYTES)(t, h, o, v);		\
3931.5Sthorpej		o += BYTES;						\
3941.5Sthorpej	}								\
3951.5Sthorpej}
3961.5Sthorpej
3971.5Sthorpej__PMAX_bus_space_set_region(1,8)
3981.5Sthorpej__PMAX_bus_space_set_region(2,16)
3991.5Sthorpej__PMAX_bus_space_set_region(4,32)
4001.5Sthorpej
4011.5Sthorpej#if 0	/* Cause a link error for bus_space_set_region_8 */
4021.5Sthorpej#define	bus_space_set_region_8						\
4031.5Sthorpej			!!! bus_space_set_region_8 unimplemented !!!
4041.5Sthorpej#endif
4051.5Sthorpej
4061.5Sthorpej#undef __PMAX_bus_space_set_region
4071.5Sthorpej
4081.5Sthorpej/*
4091.5Sthorpej *	void bus_space_copy_region_N __P((bus_space_tag_t tag,
4101.5Sthorpej *	    bus_space_handle_t bsh1, bus_size_t off1,
4111.5Sthorpej *	    bus_space_handle_t bsh2, bus_size_t off2,
4121.5Sthorpej *	    bus_size_t count));
4131.5Sthorpej *
4141.5Sthorpej * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
4151.5Sthorpej * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
4161.5Sthorpej */
4171.5Sthorpej
4181.5Sthorpej#define	__PMAX_copy_region(BYTES)					\
4191.5Sthorpejstatic __inline void __CONCAT(bus_space_copy_region_,BYTES)		\
4201.5Sthorpej	__P((bus_space_tag_t,						\
4211.5Sthorpej	    bus_space_handle_t bsh1, bus_size_t off1,			\
4221.5Sthorpej	    bus_space_handle_t bsh2, bus_size_t off2,			\
4231.5Sthorpej	    bus_size_t count));						\
4241.5Sthorpej									\
4251.5Sthorpejstatic __inline void							\
4261.5Sthorpej__CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c)		\
4271.5Sthorpej	bus_space_tag_t t;						\
4281.5Sthorpej	bus_space_handle_t h1, h2;					\
4291.5Sthorpej	bus_size_t o1, o2, c;						\
4301.5Sthorpej{									\
4311.5Sthorpej	bus_size_t o;							\
4321.5Sthorpej									\
4331.5Sthorpej	if ((h1 + o1) >= (h2 + o2)) {					\
4341.5Sthorpej		/* src after dest: copy forward */			\
4351.5Sthorpej		for (o = 0; c != 0; c--, o += BYTES)			\
4361.5Sthorpej			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
4371.5Sthorpej			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
4381.5Sthorpej	} else {							\
4391.5Sthorpej		/* dest after src: copy backwards */			\
4401.5Sthorpej		for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)	\
4411.5Sthorpej			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
4421.5Sthorpej			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
4431.5Sthorpej	}								\
4441.5Sthorpej}
4451.5Sthorpej
4461.5Sthorpej__PMAX_copy_region(1)
4471.5Sthorpej__PMAX_copy_region(2)
4481.5Sthorpej__PMAX_copy_region(4)
4491.5Sthorpej
4501.5Sthorpej#if 0	/* Cause a link error for bus_space_copy_region_8 */
4511.5Sthorpej#define	bus_space_copy_region_8						\
4521.5Sthorpej			!!! bus_space_copy_region_8 unimplemented !!!
4531.5Sthorpej#endif
4541.5Sthorpej
4551.5Sthorpej#undef __PMAX_copy_region
4561.5Sthorpej
4571.5Sthorpej/*
4581.5Sthorpej * Bus read/write barrier methods.
4591.5Sthorpej *
4601.5Sthorpej *	void bus_space_barrier __P((bus_space_tag_t tag,
4611.5Sthorpej *	    bus_space_handle_t bsh, bus_size_t offset,
4621.5Sthorpej *	    bus_size_t len, int flags));
4631.5Sthorpej *
4641.5Sthorpej * On the MIPS, we just flush the write buffer.
4651.5Sthorpej */
4661.5Sthorpej#define	bus_space_barrier(t, h, o, l, f)	\
4671.5Sthorpej	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)),	\
4681.5Sthorpej	 wbflush())
4691.5Sthorpej#define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
4701.5Sthorpej#define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
4711.5Sthorpej
4721.5Sthorpej#undef __PB_TYPENAME_PREFIX
4731.5Sthorpej#undef __PB_TYPENAME
4741.8Sdrochner
4751.8Sdrochner#define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
4761.5Sthorpej
4771.5Sthorpej/*
4781.5Sthorpej * Flags used in various bus DMA methods.
4791.5Sthorpej */
4801.5Sthorpej#define	BUS_DMA_WAITOK		0x00	/* safe to sleep (pseudo-flag) */
4811.5Sthorpej#define	BUS_DMA_NOWAIT		0x01	/* not safe to sleep */
4821.5Sthorpej#define	BUS_DMA_ALLOCNOW	0x02	/* perform resource allocation now */
4831.5Sthorpej#define	BUS_DMA_COHERENT	0x04	/* hint: map memory DMA coherent */
4841.5Sthorpej#define	BUS_DMA_BUS1		0x10	/* placeholders for bus functions... */
4851.5Sthorpej#define	BUS_DMA_BUS2		0x20
4861.5Sthorpej#define	BUS_DMA_BUS3		0x40
4871.5Sthorpej#define	BUS_DMA_BUS4		0x80
4881.5Sthorpej
4891.5Sthorpej#define	PMAX_DMAMAP_COHERENT	0x100	/* no cache flush necessary on sync */
4901.5Sthorpej
4911.5Sthorpej/* Forwards needed by prototypes below. */
4921.5Sthorpejstruct mbuf;
4931.5Sthorpejstruct uio;
4941.5Sthorpej
4951.5Sthorpej/*
4961.5Sthorpej * Operations performed by bus_dmamap_sync().
4971.5Sthorpej */
4981.5Sthorpej#define	BUS_DMASYNC_PREREAD	0x01	/* pre-read synchronization */
4991.5Sthorpej#define	BUS_DMASYNC_POSTREAD	0x02	/* post-read synchronization */
5001.5Sthorpej#define	BUS_DMASYNC_PREWRITE	0x04	/* pre-write synchronization */
5011.5Sthorpej#define	BUS_DMASYNC_POSTWRITE	0x08	/* post-write synchronization */
5021.5Sthorpej
5031.5Sthorpejtypedef struct pmax_bus_dma_tag		*bus_dma_tag_t;
5041.5Sthorpejtypedef struct pmax_bus_dmamap		*bus_dmamap_t;
5051.5Sthorpej
5061.5Sthorpej/*
5071.5Sthorpej *	bus_dma_segment_t
5081.5Sthorpej *
5091.5Sthorpej *	Describes a single contiguous DMA transaction.  Values
5101.5Sthorpej *	are suitable for programming into DMA registers.
5111.5Sthorpej */
5121.5Sthorpejstruct pmax_bus_dma_segment {
5131.5Sthorpej	bus_addr_t	ds_addr;	/* DMA address */
5141.5Sthorpej	bus_size_t	ds_len;		/* length of transfer */
5151.6Sthorpej	bus_addr_t	_ds_vaddr;	/* virtual address, 0 if invalid */
5161.5Sthorpej};
5171.5Sthorpejtypedef struct pmax_bus_dma_segment	bus_dma_segment_t;
5181.5Sthorpej
5191.5Sthorpej/*
5201.5Sthorpej *	bus_dma_tag_t
5211.5Sthorpej *
5221.5Sthorpej *	A machine-dependent opaque type describing the implementation of
5231.5Sthorpej *	DMA for a given bus.
5241.5Sthorpej */
5251.5Sthorpej
5261.5Sthorpejstruct pmax_bus_dma_tag {
5271.5Sthorpej	/*
5281.5Sthorpej	 * DMA mapping methods.
5291.5Sthorpej	 */
5301.5Sthorpej	int	(*_dmamap_create) __P((bus_dma_tag_t, bus_size_t, int,
5311.5Sthorpej		    bus_size_t, bus_size_t, int, bus_dmamap_t *));
5321.5Sthorpej	void	(*_dmamap_destroy) __P((bus_dma_tag_t, bus_dmamap_t));
5331.5Sthorpej	int	(*_dmamap_load) __P((bus_dma_tag_t, bus_dmamap_t, void *,
5341.5Sthorpej		    bus_size_t, struct proc *, int));
5351.5Sthorpej	int	(*_dmamap_load_mbuf) __P((bus_dma_tag_t, bus_dmamap_t,
5361.5Sthorpej		    struct mbuf *, int));
5371.5Sthorpej	int	(*_dmamap_load_uio) __P((bus_dma_tag_t, bus_dmamap_t,
5381.5Sthorpej		    struct uio *, int));
5391.5Sthorpej	int	(*_dmamap_load_raw) __P((bus_dma_tag_t, bus_dmamap_t,
5401.5Sthorpej		    bus_dma_segment_t *, int, bus_size_t, int));
5411.5Sthorpej	void	(*_dmamap_unload) __P((bus_dma_tag_t, bus_dmamap_t));
5421.5Sthorpej	void	(*_dmamap_sync) __P((bus_dma_tag_t, bus_dmamap_t,
5431.5Sthorpej		    bus_addr_t, bus_size_t, int));
5441.5Sthorpej
5451.5Sthorpej	/*
5461.5Sthorpej	 * DMA memory utility functions.
5471.5Sthorpej	 */
5481.5Sthorpej	int	(*_dmamem_alloc) __P((bus_dma_tag_t, bus_size_t, bus_size_t,
5491.5Sthorpej		    bus_size_t, bus_dma_segment_t *, int, int *, int));
5501.5Sthorpej	void	(*_dmamem_free) __P((bus_dma_tag_t,
5511.5Sthorpej		    bus_dma_segment_t *, int));
5521.5Sthorpej	int	(*_dmamem_map) __P((bus_dma_tag_t, bus_dma_segment_t *,
5531.5Sthorpej		    int, size_t, caddr_t *, int));
5541.5Sthorpej	void	(*_dmamem_unmap) __P((bus_dma_tag_t, caddr_t, size_t));
5551.5Sthorpej	int	(*_dmamem_mmap) __P((bus_dma_tag_t, bus_dma_segment_t *,
5561.5Sthorpej		    int, int, int, int));
5571.5Sthorpej};
5581.5Sthorpej
5591.5Sthorpej#define	bus_dmamap_create(t, s, n, m, b, f, p)			\
5601.5Sthorpej	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
5611.5Sthorpej#define	bus_dmamap_destroy(t, p)				\
5621.5Sthorpej	(*(t)->_dmamap_destroy)((t), (p))
5631.5Sthorpej#define	bus_dmamap_load(t, m, b, s, p, f)			\
5641.5Sthorpej	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
5651.5Sthorpej#define	bus_dmamap_load_mbuf(t, m, b, f)			\
5661.5Sthorpej	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
5671.5Sthorpej#define	bus_dmamap_load_uio(t, m, u, f)				\
5681.5Sthorpej	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
5691.5Sthorpej#define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
5701.5Sthorpej	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
5711.5Sthorpej#define	bus_dmamap_unload(t, p)					\
5721.5Sthorpej	(*(t)->_dmamap_unload)((t), (p))
5731.5Sthorpej#define	bus_dmamap_sync(t, p, o, l, ops)			\
5741.5Sthorpej	(*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
5751.5Sthorpej
5761.5Sthorpej#define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
5771.5Sthorpej	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
5781.5Sthorpej#define	bus_dmamem_free(t, sg, n)				\
5791.5Sthorpej	(*(t)->_dmamem_free)((t), (sg), (n))
5801.5Sthorpej#define	bus_dmamem_map(t, sg, n, s, k, f)			\
5811.5Sthorpej	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
5821.5Sthorpej#define	bus_dmamem_unmap(t, k, s)				\
5831.5Sthorpej	(*(t)->_dmamem_unmap)((t), (k), (s))
5841.5Sthorpej#define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
5851.5Sthorpej	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
5861.5Sthorpej
5871.5Sthorpej/*
5881.5Sthorpej *	bus_dmamap_t
5891.5Sthorpej *
5901.5Sthorpej *	Describes a DMA mapping.
5911.1Sjonathan */
5921.5Sthorpejstruct pmax_bus_dmamap {
5931.5Sthorpej	/*
5941.5Sthorpej	 * PRIVATE MEMBERS: not for use my machine-independent code.
5951.5Sthorpej	 */
5961.5Sthorpej	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
5971.5Sthorpej	int		_dm_segcnt;	/* number of segs this map can map */
5981.5Sthorpej	bus_size_t	_dm_maxsegsz;	/* largest possible segment */
5991.5Sthorpej	bus_size_t	_dm_boundary;	/* don't cross this */
6001.5Sthorpej	int		_dm_flags;	/* misc. flags */
6011.5Sthorpej
6021.5Sthorpej	/*
6031.5Sthorpej	 * PUBLIC MEMBERS: these are used by machine-independent code.
6041.5Sthorpej	 */
6051.5Sthorpej	bus_size_t	dm_mapsize;	/* size of the mapping */
6061.5Sthorpej	int		dm_nsegs;	/* # valid segments in mapping */
6071.5Sthorpej	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
6081.5Sthorpej};
6091.5Sthorpej
6101.5Sthorpej#ifdef _PMAX_BUS_DMA_PRIVATE
6111.5Sthorpejint	_bus_dmamap_create __P((bus_dma_tag_t, bus_size_t, int, bus_size_t,
6121.5Sthorpej	    bus_size_t, int, bus_dmamap_t *));
6131.5Sthorpejvoid	_bus_dmamap_destroy __P((bus_dma_tag_t, bus_dmamap_t));
6141.5Sthorpejint	_bus_dmamap_load __P((bus_dma_tag_t, bus_dmamap_t, void *,
6151.5Sthorpej	    bus_size_t, struct proc *, int));
6161.5Sthorpejint	_bus_dmamap_load_mbuf __P((bus_dma_tag_t, bus_dmamap_t,
6171.5Sthorpej	    struct mbuf *, int));
6181.5Sthorpejint	_bus_dmamap_load_uio __P((bus_dma_tag_t, bus_dmamap_t,
6191.5Sthorpej	    struct uio *, int));
6201.5Sthorpejint	_bus_dmamap_load_raw __P((bus_dma_tag_t, bus_dmamap_t,
6211.5Sthorpej	    bus_dma_segment_t *, int, bus_size_t, int));
6221.5Sthorpejvoid	_bus_dmamap_unload __P((bus_dma_tag_t, bus_dmamap_t));
6231.5Sthorpejvoid	_bus_dmamap_sync __P((bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
6241.5Sthorpej	    bus_size_t, int));
6251.5Sthorpej
6261.5Sthorpejint	_bus_dmamem_alloc __P((bus_dma_tag_t tag, bus_size_t size,
6271.5Sthorpej	    bus_size_t alignment, bus_size_t boundary,
6281.5Sthorpej	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags));
6291.5Sthorpejvoid	_bus_dmamem_free __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
6301.5Sthorpej	    int nsegs));
6311.5Sthorpejint	_bus_dmamem_map __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
6321.5Sthorpej	    int nsegs, size_t size, caddr_t *kvap, int flags));
6331.5Sthorpejvoid	_bus_dmamem_unmap __P((bus_dma_tag_t tag, caddr_t kva,
6341.5Sthorpej	    size_t size));
6351.5Sthorpejint	_bus_dmamem_mmap __P((bus_dma_tag_t tag, bus_dma_segment_t *segs,
6361.5Sthorpej	    int nsegs, int off, int prot, int flags));
6371.5Sthorpej
6381.5Sthorpejint	_bus_dmamem_alloc_range __P((bus_dma_tag_t tag, bus_size_t size,
6391.5Sthorpej	    bus_size_t alignment, bus_size_t boundary,
6401.5Sthorpej	    bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
6411.7Snisimura	    vaddr_t low, vaddr_t high));
6421.1Sjonathan
6431.5Sthorpejextern struct pmax_bus_dma_tag pmax_default_bus_dma_tag;
6441.5Sthorpej#endif /* _PMAX_BUS_DMA_PRIVATE */
6451.1Sjonathan
6461.10Sad#endif /* !_PMAX_BUS_H_ */
647