bus_funcs.h revision 1.2 1 /* $NetBSD: bus_funcs.h,v 1.2 2014/07/29 21:21:44 skrll Exp $ */
2
3 /*
4 * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef _COBALT_BUS_FUNCS_H_
34 #define _COBALT_BUS_FUNCS_H_
35
36 /*
37 * uintN_t bus_space_read_N(bus_space_tag_t tag,
38 * bus_space_handle_t bsh, bus_size_t offset);
39 *
40 * Read a 1, 2, 4, or 8 byte quantity from bus space
41 * described by tag/handle/offset.
42 */
43
44 #define bus_space_read_1(t, h, o) \
45 ((void) t, (*(volatile uint8_t *)((h) + (o))))
46
47 #define bus_space_read_2(t, h, o) \
48 ((void) t, (*(volatile uint16_t *)((h) + (o))))
49
50 #define bus_space_read_4(t, h, o) \
51 ((void) t, (*(volatile uint32_t *)((h) + (o))))
52
53 #if 0 /* Cause a link error for bus_space_read_8 */
54 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
55 #endif
56
57 /*
58 * void bus_space_write_N(bus_space_tag_t tag,
59 * bus_space_handle_t bsh, bus_size_t offset,
60 * uintN_t value);
61 *
62 * Write the 1, 2, 4, or 8 byte value `value' to bus space
63 * described by tag/handle/offset.
64 */
65
66 #define bus_space_write_1(t, h, o, v) \
67 do { \
68 (void) t; \
69 *(volatile uint8_t *)((h) + (o)) = (v); \
70 } while (0)
71
72 #define bus_space_write_2(t, h, o, v) \
73 do { \
74 (void) t; \
75 *(volatile uint16_t *)((h) + (o)) = (v); \
76 } while (0)
77
78 #define bus_space_write_4(t, h, o, v) \
79 do { \
80 (void) t; \
81 *(volatile uint32_t *)((h) + (o)) = (v); \
82 } while (0)
83
84 #if 0 /* Cause a link error for bus_space_write_8 */
85 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
86 #endif
87
88 /*
89 * Operations which handle byte stream data on word access.
90 *
91 * These functions are defined to resolve endian mismatch, by either
92 * - When normal (i.e. stream-less) operations perform byte swap
93 * to resolve endian mismatch, these functions bypass the byte swap.
94 * or
95 * - When bus bridge performs automatic byte swap, these functions
96 * perform byte swap once more, to cancel the bridge's behavior.
97 *
98 * Currently these are just same as normal operations, since all
99 * supported buses are same endian with CPU (i.e. little-endian).
100 *
101 */
102 #define bus_space_read_stream_2(tag, bsh, offset) \
103 bus_space_read_2(tag, bsh, offset)
104 #define bus_space_read_stream_4(tag, bsh, offset) \
105 bus_space_read_4(tag, bsh, offset)
106 #define bus_space_read_stream_8(tag, bsh, offset) \
107 bus_space_read_8(tag, bsh, offset)
108 #define bus_space_read_multi_stream_2(tag, bsh, offset, datap, count) \
109 bus_space_read_multi_2(tag, bsh, offset, datap, count)
110 #define bus_space_read_multi_stream_4(tag, bsh, offset, datap, count) \
111 bus_space_read_multi_4(tag, bsh, offset, datap, count)
112 #define bus_space_read_multi_stream_8(tag, bsh, offset, datap, count) \
113 bus_space_read_multi_8(tag, bsh, offset, datap, count)
114 #define bus_space_read_region_stream_2(tag, bsh, offset, datap, count) \
115 bus_space_read_region_2(tag, bsh, offset, datap, count)
116 #define bus_space_read_region_stream_4(tag, bsh, offset, datap, count) \
117 bus_space_read_region_4(tag, bsh, offset, datap, count)
118 #define bus_space_read_region_stream_8(tag, bsh, offset, datap, count) \
119 bus_space_read_region_8(tag, bsh, offset, datap, count)
120 #define bus_space_write_stream_2(tag, bsh, offset, data) \
121 bus_space_write_2(tag, bsh, offset, data)
122 #define bus_space_write_stream_4(tag, bsh, offset, data) \
123 bus_space_write_4(tag, bsh, offset, data)
124 #define bus_space_write_stream_8(tag, bsh, offset, data) \
125 bus_space_write_8(tag, bsh, offset, data)
126 #define bus_space_write_multi_stream_2(tag, bsh, offset, datap, count) \
127 bus_space_write_multi_2(tag, bsh, offset, datap, count)
128 #define bus_space_write_multi_stream_4(tag, bsh, offset, datap, count) \
129 bus_space_write_multi_4(tag, bsh, offset, datap, count)
130 #define bus_space_write_multi_stream_8(tag, bsh, offset, datap, count) \
131 bus_space_write_multi_8(tag, bsh, offset, datap, count)
132 #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count) \
133 bus_space_write_region_2(tag, bsh, offset, datap, count)
134 #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count) \
135 bus_space_write_region_4(tag, bsh, offset, datap, count)
136 #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count) \
137 bus_space_write_region_8(tag, bsh, offset, datap, count)
138 #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count) \
139 bus_space_write_region_2(tag, bsh, offset, datap, count)
140 #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count) \
141 bus_space_write_region_4(tag, bsh, offset, datap, count)
142 #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count) \
143 bus_space_write_region_8(tag, bsh, offset, datap, count)
144 #define bus_space_set_multi_stream_2(tag, bsh, offset, data, count) \
145 bus_space_set_multi_2(tag, bsh, offset, data, count)
146 #define bus_space_set_multi_stream_4(tag, bsh, offset, data, count) \
147 bus_space_set_multi_4(tag, bsh, offset, data, count)
148 #define bus_space_set_multi_stream_8(tag, bsh, offset, data, count) \
149 bus_space_set_multi_8(tag, bsh, offset, data, count)
150 #define bus_space_set_region_stream_2(tag, bsh, offset, data, count) \
151 bus_space_set_region_2(tag, bsh, offset, data, count)
152 #define bus_space_set_region_stream_4(tag, bsh, offset, data, count) \
153 bus_space_set_region_4(tag, bsh, offset, data, count)
154 #define bus_space_set_region_stream_8(tag, bsh, offset, data, count) \
155 bus_space_set_region_8(tag, bsh, offset, data, count)
156
157 /*
158 * Bus read/write barrier methods.
159 *
160 * void bus_space_barrier(bus_space_tag_t tag,
161 * bus_space_handle_t bsh, bus_size_t offset,
162 * bus_size_t len, int flags);
163 *
164 * On the MIPS, we just flush the write buffer.
165 */
166 #define bus_space_barrier(t, h, o, l, f) \
167 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f), \
168 wbflush()))
169
170 #include <mips/bus_dma_funcs.h>
171
172 #endif /* _COBALT_BUS_FUNCS_H_ */
173