bus.h revision 1.2
11.2Sjonathan/*	$NetBSD: bus.h,v 1.2 1997/06/16 04:22:15 jonathan Exp $	*/
21.1Sjonathan
31.1Sjonathan/*
41.1Sjonathan * Copyright Notice:
51.1Sjonathan *
61.1Sjonathan * Copyright (c) 1995, 1996, 1997
71.1Sjonathan *     Jonathan R. Stone.  All rights reserved.
81.1Sjonathan *
91.1Sjonathan * License:
101.1Sjonathan *
111.1Sjonathan * This License applies to this software ("Software"), created
121.1Sjonathan * by Jonathan Stone ("Author").
131.1Sjonathan *
141.1Sjonathan * You may use, copy, modify and redistribute this Software without
151.1Sjonathan * charge, in either source code form, binary form, or both, on the
161.1Sjonathan * following conditions:
171.1Sjonathan *
181.1Sjonathan * 1.  (a) Binary code: (i) a complete copy of the above copyright notice
191.1Sjonathan * must be included within each copy of the Software in binary code form,
201.1Sjonathan * and (ii) a complete copy of the above copyright notice and all terms
211.1Sjonathan * of this License as presented here must be included within each copy of
221.1Sjonathan * all documentation accompanying or associated with binary code, in any
231.1Sjonathan * medium, along with a list of the software modules to which the license
241.1Sjonathan * applies.
251.1Sjonathan *
261.1Sjonathan * (b) Source Code: A complete copy of the above copyright notice and all
271.1Sjonathan * terms of this License as presented here must be included within: (i)
281.1Sjonathan * each copy of the Software in source code form, and (ii) each copy of
291.1Sjonathan * all accompanying or associated documentation, in any medium.
301.1Sjonathan *
311.1Sjonathan * 2. The following Acknowledgment must be used in communications
321.1Sjonathan * involving the Software as described below:
331.1Sjonathan *
341.1Sjonathan *      This product includes software developed by
351.1Sjonathan *      Jonathan Stone for the NetBSD Project.
361.1Sjonathan *
371.1Sjonathan * The Acknowledgment must be conspicuously and completely displayed
381.1Sjonathan * whenever the Software, or any software, products or systems containing
391.1Sjonathan * the Software, are mentioned in advertising, marketing, informational
401.1Sjonathan * or publicity materials of any kind, whether in print, electronic or
411.1Sjonathan * other media (except for information provided to support use of
421.1Sjonathan * products containing the Software by existing users or customers).
431.1Sjonathan *
441.1Sjonathan * 3. The name of the Author may not be used to endorse or promote
451.1Sjonathan * products derived from this Software without specific prior written
461.1Sjonathan * permission (conditions (1) and (2) above are not considered
471.1Sjonathan * endorsement or promotion).
481.1Sjonathan *
491.1Sjonathan * 4.  This license applies to: (a) all copies of the Software, whether
501.1Sjonathan * partial or whole, original or modified, and (b) your actions, and the
511.1Sjonathan * actions of all those who may act on your behalf.  All uses not
521.1Sjonathan * expressly permitted are reserved to the Author.
531.1Sjonathan *
541.1Sjonathan * 5.  Disclaimer.  THIS SOFTWARE IS MADE AVAILABLE BY THE AUTHOR TO THE
551.1Sjonathan * PUBLIC FOR FREE AND "AS IS.''  ALL USERS OF THIS FREE SOFTWARE ARE
561.1Sjonathan * SOLELY AND ENTIRELY RESPONSIBLE FOR THEIR OWN CHOICE AND USE OF THIS
571.1Sjonathan * SOFTWARE FOR THEIR OWN PURPOSES.  BY USING THIS SOFTWARE, EACH USER
581.1Sjonathan * AGREES THAT THE AUTHOR SHALL NOT BE LIABLE FOR DAMAGES OF ANY KIND IN
591.1Sjonathan * RELATION TO ITS USE OR PERFORMANCE.
601.1Sjonathan *
611.1Sjonathan * 6.  If you have a special need for a change in one or more of these
621.1Sjonathan * license conditions, please contact the Author via electronic mail to
631.1Sjonathan *
641.1Sjonathan *     jonathan@NetBSD.ORG
651.1Sjonathan *
661.1Sjonathan * or via the contact information on
671.1Sjonathan *
681.1Sjonathan *     http://www.NetBSD.ORG/People/Pages/jonathan.html
691.1Sjonathan */
701.1Sjonathan
711.1Sjonathan
721.1Sjonathan/*
731.1Sjonathan * NetBSD machine-indepedent bus accessor macros/functions for Decstations.
741.1Sjonathan */
751.1Sjonathan#ifndef _PMAX_BUS_H_
761.1Sjonathan#define _PMAX_BUS_H_
771.2Sjonathan
781.2Sjonathan#include <mips/locore.h>			/* wbflush() */
791.2Sjonathan
801.1Sjonathan
811.1Sjonathan/*
821.1Sjonathan * Bus address and size types
831.1Sjonathan */
841.1Sjonathantypedef u_long bus_addr_t;
851.1Sjonathantypedef u_long bus_size_t;
861.1Sjonathan
871.1Sjonathan/*
881.1Sjonathan * Access types for bus resources and addresses.
891.1Sjonathan */
901.1Sjonathantypedef int bus_space_tag_t;
911.1Sjonathantypedef u_long bus_space_handle_t;
921.1Sjonathan
931.1Sjonathan
941.1Sjonathan/*
951.1Sjonathan * Read or write a 1, 2, or 4-byte quantity from/to a bus-space
961.1Sjonathan * address, as defined by (space-tag,  handle, offset
971.1Sjonathan */
981.1Sjonathan#define bus_space_read_1(t, h, o) \
991.1Sjonathan	(*(volatile u_int8_t *)((h) + (o)))
1001.1Sjonathan
1011.1Sjonathan#define bus_space_read_2(t, h, o) \
1021.1Sjonathan	(*(volatile u_int16_t *)((h) + (o)))
1031.1Sjonathan
1041.1Sjonathan#define bus_space_read_4(t, h, o) \
1051.1Sjonathan	(*(volatile u_int32_t *)((h) + (o)))
1061.1Sjonathan
1071.1Sjonathan#define bus_space_write_1(t, h, o, v) \
1081.1Sjonathan	do { ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))); } while (0)
1091.1Sjonathan
1101.1Sjonathan#define bus_space_write_2(t, h, o, v) \
1111.1Sjonathan	do { ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))); } while (0)
1121.1Sjonathan
1131.1Sjonathan#define bus_space_write_4(t, h, o, v) \
1141.1Sjonathan	do { ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))); } while (0)
1151.1Sjonathan
1161.1Sjonathan/*
1171.1Sjonathan * Read `count'  1, 2, or 4-byte quantities from bus-space
1181.1Sjonathan * address, defined by (space-tag,  handle, offset).
1191.1Sjonathan * Copy to the specified buffer address.
1201.1Sjonathan */
1211.1Sjonathan#define	bus_space_read_multi_1(t, h, o, a, c) \
1221.1Sjonathan    do {								\
1231.1Sjonathan    	register int __i ;						\
1241.1Sjonathan	for (__i = 0; i < (c); i++)					\
1251.1Sjonathan	  ((u_char *)(a))[__i] = bus_space_read_1(t, h, o);		\
1261.1Sjonathan    } while (0)
1271.1Sjonathan
1281.1Sjonathan
1291.1Sjonathan#define	bus_space_read_multi_2(t, h, o, a, c) \
1301.1Sjonathan    do {								\
1311.1Sjonathan    	register int __i ;						\
1321.1Sjonathan	for (__i = 0; i < (c); i++)					\
1331.1Sjonathan	  ((u_int16t_t *)(a))[__i] = bus_space_read_2(t, h, o);		\
1341.1Sjonathan    } while (0)
1351.1Sjonathan
1361.1Sjonathan#define	bus_space_read_multi_4(t, h, o, a, c) \
1371.1Sjonathan    do {								\
1381.1Sjonathan    	register int __i ;						\
1391.1Sjonathan	for (__i = 0; i < (c); i++)					\
1401.1Sjonathan	  ((u_int32_t *)(a))[__i] = bus_space_read_4(t, h, o);		\
1411.1Sjonathan    } while (0)
1421.1Sjonathan
1431.1Sjonathan/*
1441.1Sjonathan * Write `count'  1, 2, or 4-byte quantities to a bus-space
1451.1Sjonathan * address, defined by (space-tag,  handle, offset).
1461.1Sjonathan * Copy from the specified buffer address.
1471.1Sjonathan */
1481.1Sjonathan#define	bus_space_write_multi_1(t, h, o, a, c)  \
1491.1Sjonathan    do {								\
1501.1Sjonathan    	register int __i ;						\
1511.1Sjonathan	for (__i = 0; i < (c); i++)					\
1521.1Sjonathan	  bus_space_write_1(t, h, o, ((u_char *)(a))[__i]);		\
1531.1Sjonathan    } while (0)
1541.1Sjonathan
1551.1Sjonathan#define	bus_space_write_multi_2(t, h, o, a, c)  \
1561.1Sjonathan    do {								\
1571.1Sjonathan    	register int __i ;						\
1581.1Sjonathan	for (__i = 0; i < (c); i++)					\
1591.1Sjonathan	  bus_space_write_2(t, h, o, ((u_int16_t *)(a))[__i]);		\
1601.1Sjonathan    } while (0)
1611.1Sjonathan
1621.1Sjonathan#define	bus_space_write_multi_4(t, h, o, a, c)  \
1631.1Sjonathan    do {								\
1641.1Sjonathan    	register int __i ;						\
1651.1Sjonathan	for (__i = 0; i < (c); i++)					\
1661.1Sjonathan	  bus_space_write_4(t, h, o, ((u_int32_t *)(a))[__i]);		\
1671.1Sjonathan    } while (0)
1681.1Sjonathan
1691.1Sjonathan/*
1701.1Sjonathan * Copy `count' 1, 2, or 4-byte values from one bus-space address
1711.1Sjonathan * (t,  h, o triple) to another.
1721.1Sjonathan */
1731.1Sjonathan#define	bus_space_copy_multi_1(t, h1, h2, o1, o2, c) \
1741.1Sjonathan    do {								\
1751.1Sjonathan    	register int __i ;						\
1761.1Sjonathan	for (__i = 0; i < (c); i++)					\
1771.1Sjonathan	  bus_space_write_1(t, h1, o1, bus_space_read_1(t, h2, o2));	\
1781.1Sjonathan    } while (0)
1791.1Sjonathan
1801.1Sjonathan#define	bus_space_copy_multi_2(t, h1, h2, o1, o2, c) \
1811.1Sjonathan    do {								\
1821.1Sjonathan    	register int __i ;						\
1831.1Sjonathan	for (__i = 0; i < (c); i++)					\
1841.1Sjonathan	  bus_space_write_2(t, h1, o1, bus_space_read_2(t, h2, o2));	\
1851.1Sjonathan    while (0)
1861.1Sjonathan
1871.1Sjonathan#define	bus_space_copy_multi_4(t,  h1, h2, o1, o2, c) \
1881.1Sjonathan    do {								\
1891.1Sjonathan    	register int __i ;						\
1901.1Sjonathan	for (__i = 0; i < (c); i++)					\
1911.1Sjonathan	  bus_space_write_4(t, h1, o1, bus_space_read_4(t, h2, o2));	\
1921.1Sjonathan    } while (0)
1931.1Sjonathan
1941.1Sjonathan
1951.1Sjonathan/*
1961.1Sjonathan * Bus-space barriers.
1971.1Sjonathan * Since DECstation DMA is non-cache-coherent, we have to handle
1981.1Sjonathan * consistency in software anyway (e.g., via bus -DMA, or by ensuring
1991.1Sjonathan * that DMA buffers are referenced via  uncached address space.
2001.1Sjonathan * For now, simply do CPU writebuffer flushes and export the flags
2011.1Sjonathan * to  MI code.
2021.1Sjonathan */
2031.1Sjonathan#define bus_space_barrier(t, h, o, l, f) \
2041.1Sjonathan	((void)  wbflush();
2051.1Sjonathan
2061.1Sjonathan#define BUS_BARRIER_READ 	0x01
2071.1Sjonathan#define BUS_BARRIER_WRITE	0x02
2081.1Sjonathan
2091.1Sjonathan#endif /* _PMAX_BUS_H_ */
210