bus.h revision 1.1
11.1Sjonathan/* $NetBSD: bus.h,v 1.1 1997/06/08 05:10:25 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.1Sjonathan 781.1Sjonathan/* 791.1Sjonathan * Bus address and size types 801.1Sjonathan */ 811.1Sjonathantypedef u_long bus_addr_t; 821.1Sjonathantypedef u_long bus_size_t; 831.1Sjonathan 841.1Sjonathan/* 851.1Sjonathan * Access types for bus resources and addresses. 861.1Sjonathan */ 871.1Sjonathantypedef int bus_space_tag_t; 881.1Sjonathantypedef u_long bus_space_handle_t; 891.1Sjonathan 901.1Sjonathan 911.1Sjonathan/* 921.1Sjonathan * Read or write a 1, 2, or 4-byte quantity from/to a bus-space 931.1Sjonathan * address, as defined by (space-tag, handle, offset 941.1Sjonathan */ 951.1Sjonathan#define bus_space_read_1(t, h, o) \ 961.1Sjonathan (*(volatile u_int8_t *)((h) + (o))) 971.1Sjonathan 981.1Sjonathan#define bus_space_read_2(t, h, o) \ 991.1Sjonathan (*(volatile u_int16_t *)((h) + (o))) 1001.1Sjonathan 1011.1Sjonathan#define bus_space_read_4(t, h, o) \ 1021.1Sjonathan (*(volatile u_int32_t *)((h) + (o))) 1031.1Sjonathan 1041.1Sjonathan#define bus_space_write_1(t, h, o, v) \ 1051.1Sjonathan do { ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))); } while (0) 1061.1Sjonathan 1071.1Sjonathan#define bus_space_write_2(t, h, o, v) \ 1081.1Sjonathan do { ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))); } while (0) 1091.1Sjonathan 1101.1Sjonathan#define bus_space_write_4(t, h, o, v) \ 1111.1Sjonathan do { ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))); } while (0) 1121.1Sjonathan 1131.1Sjonathan/* 1141.1Sjonathan * Read `count' 1, 2, or 4-byte quantities from bus-space 1151.1Sjonathan * address, defined by (space-tag, handle, offset). 1161.1Sjonathan * Copy to the specified buffer address. 1171.1Sjonathan */ 1181.1Sjonathan#define bus_space_read_multi_1(t, h, o, a, c) \ 1191.1Sjonathan do { \ 1201.1Sjonathan register int __i ; \ 1211.1Sjonathan for (__i = 0; i < (c); i++) \ 1221.1Sjonathan ((u_char *)(a))[__i] = bus_space_read_1(t, h, o); \ 1231.1Sjonathan } while (0) 1241.1Sjonathan 1251.1Sjonathan 1261.1Sjonathan#define bus_space_read_multi_2(t, h, o, a, c) \ 1271.1Sjonathan do { \ 1281.1Sjonathan register int __i ; \ 1291.1Sjonathan for (__i = 0; i < (c); i++) \ 1301.1Sjonathan ((u_int16t_t *)(a))[__i] = bus_space_read_2(t, h, o); \ 1311.1Sjonathan } while (0) 1321.1Sjonathan 1331.1Sjonathan#define bus_space_read_multi_4(t, h, o, a, c) \ 1341.1Sjonathan do { \ 1351.1Sjonathan register int __i ; \ 1361.1Sjonathan for (__i = 0; i < (c); i++) \ 1371.1Sjonathan ((u_int32_t *)(a))[__i] = bus_space_read_4(t, h, o); \ 1381.1Sjonathan } while (0) 1391.1Sjonathan 1401.1Sjonathan/* 1411.1Sjonathan * Write `count' 1, 2, or 4-byte quantities to a bus-space 1421.1Sjonathan * address, defined by (space-tag, handle, offset). 1431.1Sjonathan * Copy from the specified buffer address. 1441.1Sjonathan */ 1451.1Sjonathan#define bus_space_write_multi_1(t, h, o, a, c) \ 1461.1Sjonathan do { \ 1471.1Sjonathan register int __i ; \ 1481.1Sjonathan for (__i = 0; i < (c); i++) \ 1491.1Sjonathan bus_space_write_1(t, h, o, ((u_char *)(a))[__i]); \ 1501.1Sjonathan } while (0) 1511.1Sjonathan 1521.1Sjonathan#define bus_space_write_multi_2(t, h, o, a, c) \ 1531.1Sjonathan do { \ 1541.1Sjonathan register int __i ; \ 1551.1Sjonathan for (__i = 0; i < (c); i++) \ 1561.1Sjonathan bus_space_write_2(t, h, o, ((u_int16_t *)(a))[__i]); \ 1571.1Sjonathan } while (0) 1581.1Sjonathan 1591.1Sjonathan#define bus_space_write_multi_4(t, h, o, a, c) \ 1601.1Sjonathan do { \ 1611.1Sjonathan register int __i ; \ 1621.1Sjonathan for (__i = 0; i < (c); i++) \ 1631.1Sjonathan bus_space_write_4(t, h, o, ((u_int32_t *)(a))[__i]); \ 1641.1Sjonathan } while (0) 1651.1Sjonathan 1661.1Sjonathan/* 1671.1Sjonathan * Copy `count' 1, 2, or 4-byte values from one bus-space address 1681.1Sjonathan * (t, h, o triple) to another. 1691.1Sjonathan */ 1701.1Sjonathan#define bus_space_copy_multi_1(t, h1, h2, o1, o2, c) \ 1711.1Sjonathan do { \ 1721.1Sjonathan register int __i ; \ 1731.1Sjonathan for (__i = 0; i < (c); i++) \ 1741.1Sjonathan bus_space_write_1(t, h1, o1, bus_space_read_1(t, h2, o2)); \ 1751.1Sjonathan } while (0) 1761.1Sjonathan 1771.1Sjonathan#define bus_space_copy_multi_2(t, h1, h2, o1, o2, c) \ 1781.1Sjonathan do { \ 1791.1Sjonathan register int __i ; \ 1801.1Sjonathan for (__i = 0; i < (c); i++) \ 1811.1Sjonathan bus_space_write_2(t, h1, o1, bus_space_read_2(t, h2, o2)); \ 1821.1Sjonathan while (0) 1831.1Sjonathan 1841.1Sjonathan#define bus_space_copy_multi_4(t, h1, h2, o1, o2, c) \ 1851.1Sjonathan do { \ 1861.1Sjonathan register int __i ; \ 1871.1Sjonathan for (__i = 0; i < (c); i++) \ 1881.1Sjonathan bus_space_write_4(t, h1, o1, bus_space_read_4(t, h2, o2)); \ 1891.1Sjonathan } while (0) 1901.1Sjonathan 1911.1Sjonathan 1921.1Sjonathan/* 1931.1Sjonathan * Bus-space barriers. 1941.1Sjonathan * Since DECstation DMA is non-cache-coherent, we have to handle 1951.1Sjonathan * consistency in software anyway (e.g., via bus -DMA, or by ensuring 1961.1Sjonathan * that DMA buffers are referenced via uncached address space. 1971.1Sjonathan * For now, simply do CPU writebuffer flushes and export the flags 1981.1Sjonathan * to MI code. 1991.1Sjonathan */ 2001.1Sjonathan#define bus_space_barrier(t, h, o, l, f) \ 2011.1Sjonathan ((void) wbflush(); 2021.1Sjonathan 2031.1Sjonathan#define BUS_BARRIER_READ 0x01 2041.1Sjonathan#define BUS_BARRIER_WRITE 0x02 2051.1Sjonathan 2061.1Sjonathan#endif /* _PMAX_BUS_H_ */ 207