bus.h revision 1.3
11.3Sjonathan/*	$NetBSD: bus.h,v 1.3 1997/08/30 01:51:02 jonathan Exp $	*/
21.1Sjonathan
31.1Sjonathan/*
41.3Sjonathan * Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author)
51.3Sjonathan * All rights reserved.
61.1Sjonathan *
71.3Sjonathan * Redistribution and use in source and binary forms, with or without
81.3Sjonathan * modification, are permitted provided that the following conditions
91.3Sjonathan * are met:
101.3Sjonathan * 1. Redistributions of source code must retain the above copyright
111.3Sjonathan *    notice, this list of conditions and the following disclaimer.
121.3Sjonathan * 2. Redistributions in binary form must reproduce the above copyright
131.3Sjonathan *    notice, this list of conditions and the following disclaimer in the
141.3Sjonathan *    documentation and/or other materials provided with the distribution.
151.3Sjonathan * 3. All advertising materials mentioning features or use of this software
161.3Sjonathan *    must display the following acknowledgement:
171.3Sjonathan *      This product includes software developed by Jonathan Stone for
181.3Sjonathan *      the NetBSD Project.
191.3Sjonathan * 4. The name of the author may not be used to endorse or promote products
201.3Sjonathan *    derived from this software without specific prior written permission.
211.3Sjonathan *
221.3Sjonathan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
231.3Sjonathan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.3Sjonathan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.3Sjonathan * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
261.3Sjonathan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.3Sjonathan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.3Sjonathan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.3Sjonathan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.3Sjonathan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.3Sjonathan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.3Sjonathan * SUCH DAMAGE.
331.1Sjonathan */
341.1Sjonathan
351.1Sjonathan
361.1Sjonathan/*
371.1Sjonathan * NetBSD machine-indepedent bus accessor macros/functions for Decstations.
381.1Sjonathan */
391.1Sjonathan#ifndef _PMAX_BUS_H_
401.1Sjonathan#define _PMAX_BUS_H_
411.2Sjonathan
421.2Sjonathan#include <mips/locore.h>			/* wbflush() */
431.2Sjonathan
441.1Sjonathan
451.1Sjonathan/*
461.1Sjonathan * Bus address and size types
471.1Sjonathan */
481.1Sjonathantypedef u_long bus_addr_t;
491.1Sjonathantypedef u_long bus_size_t;
501.1Sjonathan
511.1Sjonathan/*
521.1Sjonathan * Access types for bus resources and addresses.
531.1Sjonathan */
541.1Sjonathantypedef int bus_space_tag_t;
551.1Sjonathantypedef u_long bus_space_handle_t;
561.1Sjonathan
571.1Sjonathan
581.1Sjonathan/*
591.1Sjonathan * Read or write a 1, 2, or 4-byte quantity from/to a bus-space
601.1Sjonathan * address, as defined by (space-tag,  handle, offset
611.1Sjonathan */
621.1Sjonathan#define bus_space_read_1(t, h, o) \
631.1Sjonathan	(*(volatile u_int8_t *)((h) + (o)))
641.1Sjonathan
651.1Sjonathan#define bus_space_read_2(t, h, o) \
661.1Sjonathan	(*(volatile u_int16_t *)((h) + (o)))
671.1Sjonathan
681.1Sjonathan#define bus_space_read_4(t, h, o) \
691.1Sjonathan	(*(volatile u_int32_t *)((h) + (o)))
701.1Sjonathan
711.1Sjonathan#define bus_space_write_1(t, h, o, v) \
721.1Sjonathan	do { ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))); } while (0)
731.1Sjonathan
741.1Sjonathan#define bus_space_write_2(t, h, o, v) \
751.1Sjonathan	do { ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))); } while (0)
761.1Sjonathan
771.1Sjonathan#define bus_space_write_4(t, h, o, v) \
781.1Sjonathan	do { ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))); } while (0)
791.1Sjonathan
801.1Sjonathan/*
811.1Sjonathan * Read `count'  1, 2, or 4-byte quantities from bus-space
821.1Sjonathan * address, defined by (space-tag,  handle, offset).
831.1Sjonathan * Copy to the specified buffer address.
841.1Sjonathan */
851.1Sjonathan#define	bus_space_read_multi_1(t, h, o, a, c) \
861.1Sjonathan    do {								\
871.1Sjonathan    	register int __i ;						\
881.1Sjonathan	for (__i = 0; i < (c); i++)					\
891.1Sjonathan	  ((u_char *)(a))[__i] = bus_space_read_1(t, h, o);		\
901.1Sjonathan    } while (0)
911.1Sjonathan
921.1Sjonathan
931.1Sjonathan#define	bus_space_read_multi_2(t, h, o, a, c) \
941.1Sjonathan    do {								\
951.1Sjonathan    	register int __i ;						\
961.1Sjonathan	for (__i = 0; i < (c); i++)					\
971.1Sjonathan	  ((u_int16t_t *)(a))[__i] = bus_space_read_2(t, h, o);		\
981.1Sjonathan    } while (0)
991.1Sjonathan
1001.1Sjonathan#define	bus_space_read_multi_4(t, h, o, a, c) \
1011.1Sjonathan    do {								\
1021.1Sjonathan    	register int __i ;						\
1031.1Sjonathan	for (__i = 0; i < (c); i++)					\
1041.1Sjonathan	  ((u_int32_t *)(a))[__i] = bus_space_read_4(t, h, o);		\
1051.1Sjonathan    } while (0)
1061.1Sjonathan
1071.1Sjonathan/*
1081.1Sjonathan * Write `count'  1, 2, or 4-byte quantities to a bus-space
1091.1Sjonathan * address, defined by (space-tag,  handle, offset).
1101.1Sjonathan * Copy from the specified buffer address.
1111.1Sjonathan */
1121.1Sjonathan#define	bus_space_write_multi_1(t, h, o, a, c)  \
1131.1Sjonathan    do {								\
1141.1Sjonathan    	register int __i ;						\
1151.1Sjonathan	for (__i = 0; i < (c); i++)					\
1161.1Sjonathan	  bus_space_write_1(t, h, o, ((u_char *)(a))[__i]);		\
1171.1Sjonathan    } while (0)
1181.1Sjonathan
1191.1Sjonathan#define	bus_space_write_multi_2(t, h, o, a, c)  \
1201.1Sjonathan    do {								\
1211.1Sjonathan    	register int __i ;						\
1221.1Sjonathan	for (__i = 0; i < (c); i++)					\
1231.1Sjonathan	  bus_space_write_2(t, h, o, ((u_int16_t *)(a))[__i]);		\
1241.1Sjonathan    } while (0)
1251.1Sjonathan
1261.1Sjonathan#define	bus_space_write_multi_4(t, h, o, a, c)  \
1271.1Sjonathan    do {								\
1281.1Sjonathan    	register int __i ;						\
1291.1Sjonathan	for (__i = 0; i < (c); i++)					\
1301.1Sjonathan	  bus_space_write_4(t, h, o, ((u_int32_t *)(a))[__i]);		\
1311.1Sjonathan    } while (0)
1321.1Sjonathan
1331.1Sjonathan/*
1341.1Sjonathan * Copy `count' 1, 2, or 4-byte values from one bus-space address
1351.1Sjonathan * (t,  h, o triple) to another.
1361.1Sjonathan */
1371.1Sjonathan#define	bus_space_copy_multi_1(t, h1, h2, o1, o2, c) \
1381.1Sjonathan    do {								\
1391.1Sjonathan    	register int __i ;						\
1401.1Sjonathan	for (__i = 0; i < (c); i++)					\
1411.1Sjonathan	  bus_space_write_1(t, h1, o1, bus_space_read_1(t, h2, o2));	\
1421.1Sjonathan    } while (0)
1431.1Sjonathan
1441.1Sjonathan#define	bus_space_copy_multi_2(t, h1, h2, o1, o2, c) \
1451.1Sjonathan    do {								\
1461.1Sjonathan    	register int __i ;						\
1471.1Sjonathan	for (__i = 0; i < (c); i++)					\
1481.1Sjonathan	  bus_space_write_2(t, h1, o1, bus_space_read_2(t, h2, o2));	\
1491.1Sjonathan    while (0)
1501.1Sjonathan
1511.1Sjonathan#define	bus_space_copy_multi_4(t,  h1, h2, o1, o2, c) \
1521.1Sjonathan    do {								\
1531.1Sjonathan    	register int __i ;						\
1541.1Sjonathan	for (__i = 0; i < (c); i++)					\
1551.1Sjonathan	  bus_space_write_4(t, h1, o1, bus_space_read_4(t, h2, o2));	\
1561.1Sjonathan    } while (0)
1571.1Sjonathan
1581.1Sjonathan
1591.1Sjonathan/*
1601.1Sjonathan * Bus-space barriers.
1611.1Sjonathan * Since DECstation DMA is non-cache-coherent, we have to handle
1621.1Sjonathan * consistency in software anyway (e.g., via bus -DMA, or by ensuring
1631.1Sjonathan * that DMA buffers are referenced via  uncached address space.
1641.1Sjonathan * For now, simply do CPU writebuffer flushes and export the flags
1651.1Sjonathan * to  MI code.
1661.1Sjonathan */
1671.1Sjonathan#define bus_space_barrier(t, h, o, l, f) \
1681.1Sjonathan	((void)  wbflush();
1691.1Sjonathan
1701.1Sjonathan#define BUS_BARRIER_READ 	0x01
1711.1Sjonathan#define BUS_BARRIER_WRITE	0x02
1721.1Sjonathan
1731.1Sjonathan#endif /* _PMAX_BUS_H_ */
174