bus_space_funcs.h revision 1.2 1 /* $NetBSD: bus_space_funcs.h,v 1.2 2020/07/26 08:08:41 simonb Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998, 2000, 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 /*
34 * Copyright (c) 1996 Carnegie-Mellon University.
35 * All rights reserved.
36 *
37 * Author: Chris G. Demetriou
38 *
39 * Permission to use, copy, modify and distribute this software and
40 * its documentation is hereby granted, provided that both the copyright
41 * notice and this permission notice appear in all copies of the
42 * software, derivative works or modified versions, and any portions
43 * thereof, and that both notices appear in supporting documentation.
44 *
45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 *
49 * Carnegie Mellon requests users of this software to return to
50 *
51 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
55 *
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
58 */
59
60 #ifndef _MIPS_BUS_SPACE_FUNCS_H_
61 #define _MIPS_BUS_SPACE_FUNCS_H_
62
63 #ifdef _KERNEL
64 /*
65 * Utility macros; INTERNAL USE ONLY.
66 */
67 #define __bs_c(a,b) __CONCAT(a,b)
68 #define __bs_opname(op,size) __bs_c(__bs_c(__bs_c(bs_,op),_),size)
69
70 #define __bs_r(type, sz, tn, t, h, o) \
71 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \
72 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o))
73
74 #define __bs_w(type, sz, tn, t, h, o, v) \
75 do { \
76 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
77 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v); \
78 } while (0)
79
80 #define __bs_nonsingle(type, sz, tn, t, h, o, a, c) \
81 do { \
82 __BUS_SPACE_ADDRESS_SANITY((a), tn, "buffer"); \
83 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
84 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c); \
85 } while (0)
86
87 #define __bs_set(type, sz, tn, t, h, o, v, c) \
88 do { \
89 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
90 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c); \
91 } while (0)
92
93 #define __bs_copy(sz, tn, t, h1, o1, h2, o2, cnt) \
94 do { \
95 __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), tn, "bus addr 1"); \
96 __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), tn, "bus addr 2"); \
97 (*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt); \
98 } while (0)
99
100
101 /*
102 * Mapping and unmapping operations.
103 */
104 #define bus_space_map(t, a, s, f, hp) \
105 (*(t)->bs_map)((t)->bs_cookie, (a), (s), (f), (hp), 1)
106 #define mips_bus_space_map_noacct(t, a, s, f, hp) \
107 (*(t)->bs_map)((t)->bs_cookie, (a), (s), (f), (hp), 0)
108 #define bus_space_unmap(t, h, s) \
109 (*(t)->bs_unmap)((t)->bs_cookie, (h), (s), 1)
110 #define mips_bus_space_unmap_noacct(t, h, s) \
111 (*(t)->bs_unmap)((t)->bs_cookie, (h), (s), 0)
112 #define bus_space_subregion(t, h, o, s, hp) \
113 (*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp))
114
115 #define mips_bus_space_translate(t, a, s, f, bst) \
116 (*(t)->bs_translate)((t)->bs_cookie, (a), (s), (f), (bst))
117 #define mips_bus_space_get_window(t, w, bst) \
118 (*(t)->bs_get_window)((t)->bs_cookie, (w), (bst))
119
120 /*
121 * Allocation and deallocation operations.
122 */
123 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
124 (*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b), \
125 (f), (ap), (hp))
126 #define bus_space_free(t, h, s) \
127 (*(t)->bs_free)((t)->bs_cookie, (h), (s))
128
129 /*
130 * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
131 */
132 #define bus_space_vaddr(t, h) \
133 (*(t)->bs_vaddr)((t)->bs_cookie, (h))
134
135 /*
136 * Mmap bus space for a user application.
137 */
138 #define bus_space_mmap(t, a, o, p, f) \
139 (*(t)->bs_mmap)((t)->bs_cookie, (a), (o), (p), (f))
140
141 /*
142 * Bus barrier operations.
143 */
144 #define bus_space_barrier(t, h, o, l, f) \
145 (*(t)->bs_barrier)((t)->bs_cookie, (h), (o), (l), (f))
146
147 /*
148 * Bus read (single) operations.
149 */
150 #define bus_space_read_1(t, h, o) \
151 __bs_r(r,1,uint8_t,(t),(h),(o))
152 #define bus_space_read_2(t, h, o) \
153 __bs_r(r,2,uint16_t,(t),(h),(o))
154 #define bus_space_read_4(t, h, o) \
155 __bs_r(r,4,uint32_t,(t),(h),(o))
156 #define bus_space_read_8(t, h, o) \
157 __bs_r(r,8,uint64_t,(t),(h),(o))
158 #define bus_space_read_stream_1(t, h, o) \
159 __bs_r(rs,1,uint8_t,(t),(h),(o))
160 #define bus_space_read_stream_2(t, h, o) \
161 __bs_r(rs,2,uint16_t,(t),(h),(o))
162 #define bus_space_read_stream_4(t, h, o) \
163 __bs_r(rs,4,uint32_t,(t),(h),(o))
164 #define bus_space_read_stream_8(t, h, o) \
165 __bs_r(rs,8,uint64_t,(t),(h),(o))
166
167
168 /*
169 * Bus read multiple operations.
170 */
171 #define bus_space_read_multi_1(t, h, o, a, c) \
172 __bs_nonsingle(rm,1,uint8_t,(t),(h),(o),(a),(c))
173 #define bus_space_read_multi_2(t, h, o, a, c) \
174 __bs_nonsingle(rm,2,uint16_t,(t),(h),(o),(a),(c))
175 #define bus_space_read_multi_4(t, h, o, a, c) \
176 __bs_nonsingle(rm,4,uint32_t,(t),(h),(o),(a),(c))
177 #define bus_space_read_multi_8(t, h, o, a, c) \
178 __bs_nonsingle(rm,8,uint64_t,(t),(h),(o),(a),(c))
179 #define bus_space_read_multi_stream_1(t, h, o, a, c) \
180 __bs_nonsingle(rms,1,uint8_t,(t),(h),(o),(a),(c))
181 #define bus_space_read_multi_stream_2(t, h, o, a, c) \
182 __bs_nonsingle(rms,2,uint16_t,(t),(h),(o),(a),(c))
183 #define bus_space_read_multi_stream_4(t, h, o, a, c) \
184 __bs_nonsingle(rms,4,uint32_t,(t),(h),(o),(a),(c))
185 #define bus_space_read_multi_stream_8(t, h, o, a, c) \
186 __bs_nonsingle(rms,8,uint64_t,(t),(h),(o),(a),(c))
187
188
189 /*
190 * Bus read region operations.
191 */
192 #define bus_space_read_region_1(t, h, o, a, c) \
193 __bs_nonsingle(rr,1,uint8_t,(t),(h),(o),(a),(c))
194 #define bus_space_read_region_2(t, h, o, a, c) \
195 __bs_nonsingle(rr,2,uint16_t,(t),(h),(o),(a),(c))
196 #define bus_space_read_region_4(t, h, o, a, c) \
197 __bs_nonsingle(rr,4,uint32_t,(t),(h),(o),(a),(c))
198 #define bus_space_read_region_8(t, h, o, a, c) \
199 __bs_nonsingle(rr,8,uint64_t,(t),(h),(o),(a),(c))
200 #define bus_space_read_region_stream_1(t, h, o, a, c) \
201 __bs_nonsingle(rrs,1,uint8_t,(t),(h),(o),(a),(c))
202 #define bus_space_read_region_stream_2(t, h, o, a, c) \
203 __bs_nonsingle(rrs,2,uint16_t,(t),(h),(o),(a),(c))
204 #define bus_space_read_region_stream_4(t, h, o, a, c) \
205 __bs_nonsingle(rrs,4,uint32_t,(t),(h),(o),(a),(c))
206 #define bus_space_read_region_stream_8(t, h, o, a, c) \
207 __bs_nonsingle(rrs,8,uint64_t,(t),(h),(o),(a),(c))
208
209
210 /*
211 * Bus write (single) operations.
212 */
213 #define bus_space_write_1(t, h, o, v) \
214 __bs_w(w,1,uint8_t,(t),(h),(o),(v))
215 #define bus_space_write_2(t, h, o, v) \
216 __bs_w(w,2,uint16_t,(t),(h),(o),(v))
217 #define bus_space_write_4(t, h, o, v) \
218 __bs_w(w,4,uint32_t,(t),(h),(o),(v))
219 #define bus_space_write_8(t, h, o, v) \
220 __bs_w(w,8,uint64_t,(t),(h),(o),(v))
221 #define bus_space_write_stream_1(t, h, o, v) \
222 __bs_w(ws,1,uint8_t,(t),(h),(o),(v))
223 #define bus_space_write_stream_2(t, h, o, v) \
224 __bs_w(ws,2,uint16_t,(t),(h),(o),(v))
225 #define bus_space_write_stream_4(t, h, o, v) \
226 __bs_w(ws,4,uint32_t,(t),(h),(o),(v))
227 #define bus_space_write_stream_8(t, h, o, v) \
228 __bs_w(ws,8,uint64_t,(t),(h),(o),(v))
229
230
231 /*
232 * Bus write multiple operations.
233 */
234 #define bus_space_write_multi_1(t, h, o, a, c) \
235 __bs_nonsingle(wm,1,uint8_t,(t),(h),(o),(a),(c))
236 #define bus_space_write_multi_2(t, h, o, a, c) \
237 __bs_nonsingle(wm,2,uint16_t,(t),(h),(o),(a),(c))
238 #define bus_space_write_multi_4(t, h, o, a, c) \
239 __bs_nonsingle(wm,4,uint32_t,(t),(h),(o),(a),(c))
240 #define bus_space_write_multi_8(t, h, o, a, c) \
241 __bs_nonsingle(wm,8,uint64_t,(t),(h),(o),(a),(c))
242 #define bus_space_write_multi_stream_1(t, h, o, a, c) \
243 __bs_nonsingle(wms,1,uint8_t,(t),(h),(o),(a),(c))
244 #define bus_space_write_multi_stream_2(t, h, o, a, c) \
245 __bs_nonsingle(wms,2,uint16_t,(t),(h),(o),(a),(c))
246 #define bus_space_write_multi_stream_4(t, h, o, a, c) \
247 __bs_nonsingle(wms,4,uint32_t,(t),(h),(o),(a),(c))
248 #define bus_space_write_multi_stream_8(t, h, o, a, c) \
249 __bs_nonsingle(wms,8,uint64_t,(t),(h),(o),(a),(c))
250
251
252 /*
253 * Bus write region operations.
254 */
255 #define bus_space_write_region_1(t, h, o, a, c) \
256 __bs_nonsingle(wr,1,uint8_t,(t),(h),(o),(a),(c))
257 #define bus_space_write_region_2(t, h, o, a, c) \
258 __bs_nonsingle(wr,2,uint16_t,(t),(h),(o),(a),(c))
259 #define bus_space_write_region_4(t, h, o, a, c) \
260 __bs_nonsingle(wr,4,uint32_t,(t),(h),(o),(a),(c))
261 #define bus_space_write_region_8(t, h, o, a, c) \
262 __bs_nonsingle(wr,8,uint64_t,(t),(h),(o),(a),(c))
263 #define bus_space_write_region_stream_1(t, h, o, a, c) \
264 __bs_nonsingle(wrs,1,uint8_t,(t),(h),(o),(a),(c))
265 #define bus_space_write_region_stream_2(t, h, o, a, c) \
266 __bs_nonsingle(wrs,2,uint16_t,(t),(h),(o),(a),(c))
267 #define bus_space_write_region_stream_4(t, h, o, a, c) \
268 __bs_nonsingle(wrs,4,uint32_t,(t),(h),(o),(a),(c))
269 #define bus_space_write_region_stream_8(t, h, o, a, c) \
270 __bs_nonsingle(wrs,8,uint64_t,(t),(h),(o),(a),(c))
271
272
273 /*
274 * Set multiple operations.
275 */
276 #define bus_space_set_multi_1(t, h, o, v, c) \
277 __bs_set(sm,1,uint8_t,(t),(h),(o),(v),(c))
278 #define bus_space_set_multi_2(t, h, o, v, c) \
279 __bs_set(sm,2,uint16_t,(t),(h),(o),(v),(c))
280 #define bus_space_set_multi_4(t, h, o, v, c) \
281 __bs_set(sm,4,uint32_t,(t),(h),(o),(v),(c))
282 #define bus_space_set_multi_8(t, h, o, v, c) \
283 __bs_set(sm,8,uint64_t,(t),(h),(o),(v),(c))
284
285
286 /*
287 * Set region operations.
288 */
289 #define bus_space_set_region_1(t, h, o, v, c) \
290 __bs_set(sr,1,uint8_t,(t),(h),(o),(v),(c))
291 #define bus_space_set_region_2(t, h, o, v, c) \
292 __bs_set(sr,2,uint16_t,(t),(h),(o),(v),(c))
293 #define bus_space_set_region_4(t, h, o, v, c) \
294 __bs_set(sr,4,uint32_t,(t),(h),(o),(v),(c))
295 #define bus_space_set_region_8(t, h, o, v, c) \
296 __bs_set(sr,8,uint64_t,(t),(h),(o),(v),(c))
297
298
299 /*
300 * Copy region operations.
301 */
302 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \
303 __bs_copy(1, uint8_t, (t), (h1), (o1), (h2), (o2), (c))
304 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \
305 __bs_copy(2, uint16_t, (t), (h1), (o1), (h2), (o2), (c))
306 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \
307 __bs_copy(4, uint32_t, (t), (h1), (o1), (h2), (o2), (c))
308 #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \
309 __bs_copy(8, uint64_t, (t), (h1), (o1), (h2), (o2), (c))
310
311 #endif /* _KERNEL */
312
313 #endif /* _MIPS_BUS_SPACE_FUNCS_H_ */
314