bus_funcs.h revision 1.1 1 1.1 dyoung /* $NetBSD: bus_funcs.h,v 1.1 2011/07/19 15:52:31 dyoung 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 _DREAMCAST_BUS_FUNCS_H_
61 1.1 dyoung #define _DREAMCAST_BUS_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 __dbs_c(a,b) __CONCAT(a,b)
68 1.1 dyoung #define __dbs_opname(op,size) __dbs_c(__dbs_c(__dbs_c(dbs_,op),_),size)
69 1.1 dyoung
70 1.1 dyoung #define __dbs_rs(sz, tn, t, h, o) \
71 1.1 dyoung (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \
72 1.1 dyoung (*(t)->__dbs_opname(r,sz))((t)->dbs_cookie, h, o))
73 1.1 dyoung
74 1.1 dyoung #define __dbs_ws(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)->__dbs_opname(w,sz))((t)->dbs_cookie, h, o, v); \
78 1.1 dyoung } while (0)
79 1.1 dyoung
80 1.1 dyoung #define __dbs_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)->__dbs_opname(type,sz))((t)->dbs_cookie, h, o, a, c); \
85 1.1 dyoung } while (0)
86 1.1 dyoung
87 1.1 dyoung #define __dbs_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)->__dbs_opname(type,sz))((t)->dbs_cookie, h, o, v, c); \
91 1.1 dyoung } while (0)
92 1.1 dyoung
93 1.1 dyoung #define __dbs_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)->__dbs_opname(c,sz))((t)->dbs_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)->dbs_map)((t)->dbs_cookie, (a), (s), (f), (hp))
106 1.1 dyoung #define bus_space_unmap(t, h, s) \
107 1.1 dyoung (*(t)->dbs_unmap)((t)->dbs_cookie, (h), (s))
108 1.1 dyoung #define bus_space_subregion(t, h, o, s, hp) \
109 1.1 dyoung (*(t)->dbs_subregion)((t)->dbs_cookie, (h), (o), (s), (hp))
110 1.1 dyoung #define bus_space_mmap(t, a, o, p, f) \
111 1.1 dyoung (*(t)->dbs_mmap)((t)->dbs_cookie, (a), (o), (p), (f))
112 1.1 dyoung
113 1.1 dyoung #endif /* _KERNEL */
114 1.1 dyoung
115 1.1 dyoung #ifdef _KERNEL
116 1.1 dyoung /*
117 1.1 dyoung * Allocation and deallocation operations.
118 1.1 dyoung */
119 1.1 dyoung #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
120 1.1 dyoung (*(t)->dbs_alloc)((t)->dbs_cookie, (rs), (re), (s), (a), (b), \
121 1.1 dyoung (f), (ap), (hp))
122 1.1 dyoung #define bus_space_free(t, h, s) \
123 1.1 dyoung (*(t)->dbs_free)((t)->dbs_cookie, (h), (s))
124 1.1 dyoung
125 1.1 dyoung /*
126 1.1 dyoung * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
127 1.1 dyoung */
128 1.1 dyoung #define bus_space_vaddr(t, h) \
129 1.1 dyoung (*(t)->dbs_vaddr)((t)->dbs_cookie, (h))
130 1.1 dyoung
131 1.1 dyoung /*
132 1.1 dyoung * Bus barrier operations. The Dreamcast does not currently require
133 1.1 dyoung * barriers, but we must provide the flags to MI code.
134 1.1 dyoung */
135 1.1 dyoung #define bus_space_barrier(t, h, o, l, f) \
136 1.1 dyoung ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
137 1.1 dyoung
138 1.1 dyoung /*
139 1.1 dyoung * Bus read (single) operations.
140 1.1 dyoung */
141 1.1 dyoung #define bus_space_read_1(t, h, o) __dbs_rs(1,uint8_t,(t),(h),(o))
142 1.1 dyoung #define bus_space_read_2(t, h, o) __dbs_rs(2,uint16_t,(t),(h),(o))
143 1.1 dyoung #define bus_space_read_4(t, h, o) __dbs_rs(4,uint32_t,(t),(h),(o))
144 1.1 dyoung #define bus_space_read_8(t, h, o) __dbs_rs(8,uint64_t,(t),(h),(o))
145 1.1 dyoung
146 1.1 dyoung
147 1.1 dyoung /*
148 1.1 dyoung * Bus read multiple operations.
149 1.1 dyoung */
150 1.1 dyoung #define bus_space_read_multi_1(t, h, o, a, c) \
151 1.1 dyoung __dbs_nonsingle(rm,1,uint8_t,(t),(h),(o),(a),(c))
152 1.1 dyoung #define bus_space_read_multi_2(t, h, o, a, c) \
153 1.1 dyoung __dbs_nonsingle(rm,2,uint16_t,(t),(h),(o),(a),(c))
154 1.1 dyoung #define bus_space_read_multi_4(t, h, o, a, c) \
155 1.1 dyoung __dbs_nonsingle(rm,4,uint32_t,(t),(h),(o),(a),(c))
156 1.1 dyoung #define bus_space_read_multi_8(t, h, o, a, c) \
157 1.1 dyoung __dbs_nonsingle(rm,8,uint64_t,(t),(h),(o),(a),(c))
158 1.1 dyoung
159 1.1 dyoung
160 1.1 dyoung /*
161 1.1 dyoung * Bus read region operations.
162 1.1 dyoung */
163 1.1 dyoung #define bus_space_read_region_1(t, h, o, a, c) \
164 1.1 dyoung __dbs_nonsingle(rr,1,uint8_t,(t),(h),(o),(a),(c))
165 1.1 dyoung #define bus_space_read_region_2(t, h, o, a, c) \
166 1.1 dyoung __dbs_nonsingle(rr,2,uint16_t,(t),(h),(o),(a),(c))
167 1.1 dyoung #define bus_space_read_region_4(t, h, o, a, c) \
168 1.1 dyoung __dbs_nonsingle(rr,4,uint32_t,(t),(h),(o),(a),(c))
169 1.1 dyoung #define bus_space_read_region_8(t, h, o, a, c) \
170 1.1 dyoung __dbs_nonsingle(rr,8,uint64_t,(t),(h),(o),(a),(c))
171 1.1 dyoung
172 1.1 dyoung
173 1.1 dyoung /*
174 1.1 dyoung * Bus write (single) operations.
175 1.1 dyoung */
176 1.1 dyoung #define bus_space_write_1(t, h, o, v) __dbs_ws(1,uint8_t,(t),(h),(o),(v))
177 1.1 dyoung #define bus_space_write_2(t, h, o, v) __dbs_ws(2,uint16_t,(t),(h),(o),(v))
178 1.1 dyoung #define bus_space_write_4(t, h, o, v) __dbs_ws(4,uint32_t,(t),(h),(o),(v))
179 1.1 dyoung #define bus_space_write_8(t, h, o, v) __dbs_ws(8,uint64_t,(t),(h),(o),(v))
180 1.1 dyoung
181 1.1 dyoung
182 1.1 dyoung /*
183 1.1 dyoung * Bus write multiple operations.
184 1.1 dyoung */
185 1.1 dyoung #define bus_space_write_multi_1(t, h, o, a, c) \
186 1.1 dyoung __dbs_nonsingle(wm,1,uint8_t,(t),(h),(o),(a),(c))
187 1.1 dyoung #define bus_space_write_multi_2(t, h, o, a, c) \
188 1.1 dyoung __dbs_nonsingle(wm,2,uint16_t,(t),(h),(o),(a),(c))
189 1.1 dyoung #define bus_space_write_multi_4(t, h, o, a, c) \
190 1.1 dyoung __dbs_nonsingle(wm,4,uint32_t,(t),(h),(o),(a),(c))
191 1.1 dyoung #define bus_space_write_multi_8(t, h, o, a, c) \
192 1.1 dyoung __dbs_nonsingle(wm,8,uint64_t,(t),(h),(o),(a),(c))
193 1.1 dyoung
194 1.1 dyoung
195 1.1 dyoung /*
196 1.1 dyoung * Bus write region operations.
197 1.1 dyoung */
198 1.1 dyoung #define bus_space_write_region_1(t, h, o, a, c) \
199 1.1 dyoung __dbs_nonsingle(wr,1,uint8_t,(t),(h),(o),(a),(c))
200 1.1 dyoung #define bus_space_write_region_2(t, h, o, a, c) \
201 1.1 dyoung __dbs_nonsingle(wr,2,uint16_t,(t),(h),(o),(a),(c))
202 1.1 dyoung #define bus_space_write_region_4(t, h, o, a, c) \
203 1.1 dyoung __dbs_nonsingle(wr,4,uint32_t,(t),(h),(o),(a),(c))
204 1.1 dyoung #define bus_space_write_region_8(t, h, o, a, c) \
205 1.1 dyoung __dbs_nonsingle(wr,8,uint64_t,(t),(h),(o),(a),(c))
206 1.1 dyoung
207 1.1 dyoung
208 1.1 dyoung /*
209 1.1 dyoung * Set multiple operations.
210 1.1 dyoung */
211 1.1 dyoung #define bus_space_set_multi_1(t, h, o, v, c) \
212 1.1 dyoung __dbs_set(sm,1,uint8_t,(t),(h),(o),(v),(c))
213 1.1 dyoung #define bus_space_set_multi_2(t, h, o, v, c) \
214 1.1 dyoung __dbs_set(sm,2,uint16_t,(t),(h),(o),(v),(c))
215 1.1 dyoung #define bus_space_set_multi_4(t, h, o, v, c) \
216 1.1 dyoung __dbs_set(sm,4,uint32_t,(t),(h),(o),(v),(c))
217 1.1 dyoung #define bus_space_set_multi_8(t, h, o, v, c) \
218 1.1 dyoung __dbs_set(sm,8,uint64_t,(t),(h),(o),(v),(c))
219 1.1 dyoung
220 1.1 dyoung
221 1.1 dyoung /*
222 1.1 dyoung * Set region operations.
223 1.1 dyoung */
224 1.1 dyoung #define bus_space_set_region_1(t, h, o, v, c) \
225 1.1 dyoung __dbs_set(sr,1,uint8_t,(t),(h),(o),(v),(c))
226 1.1 dyoung #define bus_space_set_region_2(t, h, o, v, c) \
227 1.1 dyoung __dbs_set(sr,2,uint16_t,(t),(h),(o),(v),(c))
228 1.1 dyoung #define bus_space_set_region_4(t, h, o, v, c) \
229 1.1 dyoung __dbs_set(sr,4,uint32_t,(t),(h),(o),(v),(c))
230 1.1 dyoung #define bus_space_set_region_8(t, h, o, v, c) \
231 1.1 dyoung __dbs_set(sr,8,uint64_t,(t),(h),(o),(v),(c))
232 1.1 dyoung
233 1.1 dyoung
234 1.1 dyoung /*
235 1.1 dyoung * Copy region operations.
236 1.1 dyoung */
237 1.1 dyoung #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \
238 1.1 dyoung __dbs_copy(1, uint8_t, (t), (h1), (o1), (h2), (o2), (c))
239 1.1 dyoung #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \
240 1.1 dyoung __dbs_copy(2, uint16_t, (t), (h1), (o1), (h2), (o2), (c))
241 1.1 dyoung #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \
242 1.1 dyoung __dbs_copy(4, uint32_t, (t), (h1), (o1), (h2), (o2), (c))
243 1.1 dyoung #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \
244 1.1 dyoung __dbs_copy(8, uint64_t, (t), (h1), (o1), (h2), (o2), (c))
245 1.1 dyoung
246 1.1 dyoung /*
247 1.1 dyoung * Bus stream operations--defined in terms of non-stream counterparts
248 1.1 dyoung */
249 1.1 dyoung #define __BUS_SPACE_HAS_STREAM_METHODS 1
250 1.1 dyoung #define bus_space_read_stream_1 bus_space_read_1
251 1.1 dyoung #define bus_space_read_stream_2 bus_space_read_2
252 1.1 dyoung #define bus_space_read_stream_4 bus_space_read_4
253 1.1 dyoung #define bus_space_read_stream_8 bus_space_read_8
254 1.1 dyoung #define bus_space_read_multi_stream_1 bus_space_read_multi_1
255 1.1 dyoung #define bus_space_read_multi_stream_2 bus_space_read_multi_2
256 1.1 dyoung #define bus_space_read_multi_stream_4 bus_space_read_multi_4
257 1.1 dyoung #define bus_space_read_multi_stream_8 bus_space_read_multi_8
258 1.1 dyoung #define bus_space_read_region_stream_1 bus_space_read_region_1
259 1.1 dyoung #define bus_space_read_region_stream_2 bus_space_read_region_2
260 1.1 dyoung #define bus_space_read_region_stream_4 bus_space_read_region_4
261 1.1 dyoung #define bus_space_read_region_stream_8 bus_space_read_region_8
262 1.1 dyoung #define bus_space_write_stream_1 bus_space_write_1
263 1.1 dyoung #define bus_space_write_stream_2 bus_space_write_2
264 1.1 dyoung #define bus_space_write_stream_4 bus_space_write_4
265 1.1 dyoung #define bus_space_write_stream_8 bus_space_write_8
266 1.1 dyoung #define bus_space_write_multi_stream_1 bus_space_write_multi_1
267 1.1 dyoung #define bus_space_write_multi_stream_2 bus_space_write_multi_2
268 1.1 dyoung #define bus_space_write_multi_stream_4 bus_space_write_multi_4
269 1.1 dyoung #define bus_space_write_multi_stream_8 bus_space_write_multi_8
270 1.1 dyoung #define bus_space_write_region_stream_1 bus_space_write_region_1
271 1.1 dyoung #define bus_space_write_region_stream_2 bus_space_write_region_2
272 1.1 dyoung #define bus_space_write_region_stream_4 bus_space_write_region_4
273 1.1 dyoung #define bus_space_write_region_stream_8 bus_space_write_region_8
274 1.1 dyoung
275 1.1 dyoung #endif /* _KERNEL */
276 1.1 dyoung
277 1.1 dyoung #define bus_dmamap_create(t, s, n, m, b, f, p) \
278 1.1 dyoung (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
279 1.1 dyoung #define bus_dmamap_destroy(t, p) \
280 1.1 dyoung (*(t)->_dmamap_destroy)((t), (p))
281 1.1 dyoung #define bus_dmamap_load(t, m, b, s, p, f) \
282 1.1 dyoung (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
283 1.1 dyoung #define bus_dmamap_load_mbuf(t, m, b, f) \
284 1.1 dyoung (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
285 1.1 dyoung #define bus_dmamap_load_uio(t, m, u, f) \
286 1.1 dyoung (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
287 1.1 dyoung #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
288 1.1 dyoung (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
289 1.1 dyoung #define bus_dmamap_unload(t, p) \
290 1.1 dyoung (*(t)->_dmamap_unload)((t), (p))
291 1.1 dyoung #define bus_dmamap_sync(t, m, o, l, op) \
292 1.1 dyoung (void)((t)->_dmamap_sync ? \
293 1.1 dyoung (*(t)->_dmamap_sync)((t), (m), (o), (l), (op)) : (void)0)
294 1.1 dyoung
295 1.1 dyoung #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
296 1.1 dyoung (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
297 1.1 dyoung #define bus_dmamem_free(t, sg, n) \
298 1.1 dyoung (*(t)->_dmamem_free)((t), (sg), (n))
299 1.1 dyoung #define bus_dmamem_map(t, sg, n, s, k, f) \
300 1.1 dyoung (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
301 1.1 dyoung #define bus_dmamem_unmap(t, k, s) \
302 1.1 dyoung (*(t)->_dmamem_unmap)((t), (k), (s))
303 1.1 dyoung #define bus_dmamem_mmap(t, sg, n, o, p, f) \
304 1.1 dyoung (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
305 1.1 dyoung
306 1.1 dyoung #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
307 1.1 dyoung #define bus_dmatag_destroy(t)
308 1.1 dyoung
309 1.1 dyoung #endif /* _DREAMCAST_BUS_FUNCS_H_ */
310