Annotation of prex-old/dev/include/bus.h, Revision 1.1
1.1 ! nbrk 1: /*
! 2: * $Id$
! 3: */
! 4: /* $OpenBSD: bus.h,v 1.8 2007/04/10 18:22:08 miod Exp $ */
! 5: /* $NetBSD: bus.h,v 1.12 2003/10/23 15:03:24 scw Exp $ */
! 6:
! 7: /*-
! 8: * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
! 9: * All rights reserved.
! 10: *
! 11: * This code is derived from software contributed to The NetBSD Foundation
! 12: * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
! 13: * NASA Ames Research Center.
! 14: *
! 15: * Redistribution and use in source and binary forms, with or without
! 16: * modification, are permitted provided that the following conditions
! 17: * are met:
! 18: * 1. Redistributions of source code must retain the above copyright
! 19: * notice, this list of conditions and the following disclaimer.
! 20: * 2. Redistributions in binary form must reproduce the above copyright
! 21: * notice, this list of conditions and the following disclaimer in the
! 22: * documentation and/or other materials provided with the distribution.
! 23: * 3. All advertising materials mentioning features or use of this software
! 24: * must display the following acknowledgement:
! 25: * This product includes software developed by the NetBSD
! 26: * Foundation, Inc. and its contributors.
! 27: * 4. Neither the name of The NetBSD Foundation nor the names of its
! 28: * contributors may be used to endorse or promote products derived
! 29: * from this software without specific prior written permission.
! 30: *
! 31: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
! 32: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! 33: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
! 34: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
! 35: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! 36: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! 37: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! 38: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! 39: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! 40: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 41: * POSSIBILITY OF SUCH DAMAGE.
! 42: */
! 43:
! 44: /*
! 45: * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
! 46: * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
! 47: *
! 48: * Redistribution and use in source and binary forms, with or without
! 49: * modification, are permitted provided that the following conditions
! 50: * are met:
! 51: * 1. Redistributions of source code must retain the above copyright
! 52: * notice, this list of conditions and the following disclaimer.
! 53: * 2. Redistributions in binary form must reproduce the above copyright
! 54: * notice, this list of conditions and the following disclaimer in the
! 55: * documentation and/or other materials provided with the distribution.
! 56: * 3. All advertising materials mentioning features or use of this software
! 57: * must display the following acknowledgement:
! 58: * This product includes software developed by Christopher G. Demetriou
! 59: * for the NetBSD Project.
! 60: * 4. The name of the author may not be used to endorse or promote products
! 61: * derived from this software without specific prior written permission
! 62: *
! 63: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 64: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 65: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 66: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! 67: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
! 68: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! 69: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! 70: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 71: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
! 72: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 73: */
! 74:
! 75: #ifndef _INCLUDE_BUS_H_
! 76: #define _INCLUDE_BUS_H_
! 77:
! 78: #include <driver.h>
! 79:
! 80: /*
! 81: * Addresses (in bus space).
! 82: */
! 83: typedef u_long bus_addr_t;
! 84: typedef u_long bus_size_t;
! 85:
! 86: /*
! 87: * Access methods for bus space.
! 88: */
! 89: typedef struct bus_space *bus_space_tag_t;
! 90: typedef u_long bus_space_handle_t;
! 91:
! 92: /*
! 93: * int bus_space_map (bus_space_tag_t t, bus_addr_t addr,
! 94: * bus_size_t size, int flags, bus_space_handle_t *bshp);
! 95: *
! 96: * Map a region of bus space.
! 97: */
! 98:
! 99: #define BUS_SPACE_MAP_CACHEABLE 0x01
! 100: #define BUS_SPACE_MAP_LINEAR 0x02
! 101: #define BUS_SPACE_MAP_PREFETCHABLE 0x04
! 102:
! 103: struct bus_space {
! 104: /* cookie */
! 105: void *bs_cookie;
! 106:
! 107: /* mapping/unmapping */
! 108: int (*bs_map) (void *, bus_addr_t, bus_size_t,
! 109: int, bus_space_handle_t *);
! 110: void (*bs_unmap) (void *, bus_space_handle_t,
! 111: bus_size_t);
! 112: int (*bs_subregion) (void *, bus_space_handle_t,
! 113: bus_size_t, bus_size_t, bus_space_handle_t *);
! 114:
! 115: /* barrier */
! 116: void (*bs_barrier) (void *, bus_space_handle_t,
! 117: bus_size_t, bus_size_t, int);
! 118:
! 119: /* read (single) */
! 120: uint8_t (*bs_r_1) (void *, bus_space_handle_t,
! 121: bus_size_t);
! 122: uint16_t (*bs_r_2) (void *, bus_space_handle_t,
! 123: bus_size_t);
! 124: uint32_t (*bs_r_4) (void *, bus_space_handle_t,
! 125: bus_size_t);
! 126:
! 127: /* write (single) */
! 128: void (*bs_w_1) (void *, bus_space_handle_t,
! 129: bus_size_t, uint8_t);
! 130: void (*bs_w_2) (void *, bus_space_handle_t,
! 131: bus_size_t, uint16_t);
! 132: void (*bs_w_4) (void *, bus_space_handle_t,
! 133: bus_size_t, uint32_t);
! 134: };
! 135:
! 136:
! 137: /*
! 138: * Utility macros; INTERNAL USE ONLY.
! 139: */
! 140: #define __bs_c(a,b) __CONCAT(a,b)
! 141: #define __bs_opname(op,size) __bs_c(__bs_c(__bs_c(bs_,op),_),size)
! 142:
! 143: #define __bs_rs(sz, t, h, o) \
! 144: (*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o)
! 145: #define __bs_ws(sz, t, h, o, v) \
! 146: (*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v)
! 147: #define __bs_nonsingle(type, sz, t, h, o, a, c) \
! 148: (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c)
! 149:
! 150: /*
! 151: * Mapping and unmapping operations.
! 152: */
! 153: #define bus_space_map(t, a, s, c, hp) \
! 154: (*(t)->bs_map)((t)->bs_cookie, (a), (s), (c), (hp))
! 155: #define bus_space_unmap(t, h, s) \
! 156: (*(t)->bs_unmap)((t)->bs_cookie, (h), (s))
! 157: #define bus_space_subregion(t, h, o, s, hp) \
! 158: (*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp))
! 159:
! 160: /*
! 161: * Bus barrier operations.
! 162: */
! 163: #define bus_space_barrier(t, h, o, l, f) \
! 164: (*(t)->bs_barrier)((t)->bs_cookie, (h), (o), (l), (f))
! 165:
! 166: #define BUS_SPACE_BARRIER_READ 0x01
! 167: #define BUS_SPACE_BARRIER_WRITE 0x02
! 168:
! 169: /*
! 170: * Bus read (single) operations.
! 171: */
! 172: #define bus_space_read_1(t, h, o) __bs_rs(1,(t),(h),(o))
! 173: #define bus_space_read_2(t, h, o) __bs_rs(2,(t),(h),(o))
! 174: #define bus_space_read_4(t, h, o) __bs_rs(4,(t),(h),(o))
! 175:
! 176: /*
! 177: * Bus write (single) operations.
! 178: */
! 179: #define bus_space_write_1(t, h, o, v) __bs_ws(1,(t),(h),(o),(v))
! 180: #define bus_space_write_2(t, h, o, v) __bs_ws(2,(t),(h),(o),(v))
! 181: #define bus_space_write_4(t, h, o, v) __bs_ws(4,(t),(h),(o),(v))
! 182:
! 183:
! 184: /*
! 185: * Macros to provide prototypes for all the functions used in the
! 186: * bus_space structure
! 187: */
! 188:
! 189: #define bs_map_proto(f) \
! 190: int __bs_c(f,_bs_map) (void *t, bus_addr_t addr, \
! 191: bus_size_t size, int cacheable, bus_space_handle_t *bshp);
! 192:
! 193: #define bs_unmap_proto(f) \
! 194: void __bs_c(f,_bs_unmap) (void *t, bus_space_handle_t bsh, \
! 195: bus_size_t size);
! 196:
! 197: #define bs_subregion_proto(f) \
! 198: int __bs_c(f,_bs_subregion) (void *t, bus_space_handle_t bsh, \
! 199: bus_size_t offset, bus_size_t size, \
! 200: bus_space_handle_t *nbshp);
! 201:
! 202: #define bs_barrier_proto(f) \
! 203: void __bs_c(f,_bs_barrier) (void *t, bus_space_handle_t bsh, \
! 204: bus_size_t offset, bus_size_t len, int flags);
! 205:
! 206: #define bs_r_1_proto(f) \
! 207: uint8_t __bs_c(f,_bs_r_1) (void *t, bus_space_handle_t bsh, \
! 208: bus_size_t offset);
! 209:
! 210: #define bs_r_2_proto(f) \
! 211: uint16_t __bs_c(f,_bs_r_2) (void *t, bus_space_handle_t bsh, \
! 212: bus_size_t offset);
! 213:
! 214: #define bs_r_4_proto(f) \
! 215: uint32_t __bs_c(f,_bs_r_4) (void *t, bus_space_handle_t bsh, \
! 216: bus_size_t offset);
! 217:
! 218: #define bs_w_1_proto(f) \
! 219: void __bs_c(f,_bs_w_1) (void *t, bus_space_handle_t bsh, \
! 220: bus_size_t offset, uint8_t value);
! 221:
! 222: #define bs_w_2_proto(f) \
! 223: void __bs_c(f,_bs_w_2) (void *t, bus_space_handle_t bsh, \
! 224: bus_size_t offset, uint16_t value);
! 225:
! 226: #define bs_w_4_proto(f) \
! 227: void __bs_c(f,_bs_w_4) (void *t, bus_space_handle_t bsh, \
! 228: bus_size_t offset, uint32_t value);
! 229:
! 230: #define bs_protos(f) \
! 231: bs_map_proto(f); \
! 232: bs_unmap_proto(f); \
! 233: bs_subregion_proto(f); \
! 234: bs_barrier_proto(f); \
! 235: bs_r_1_proto(f); \
! 236: bs_r_2_proto(f); \
! 237: bs_r_4_proto(f); \
! 238: bs_r_8_proto(f); \
! 239: bs_w_1_proto(f); \
! 240: bs_w_2_proto(f); \
! 241: bs_w_4_proto(f); \
! 242: bs_w_8_proto(f);
! 243:
! 244: #endif /* _INCLUDE_BUS_H_ */
CVSweb