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