bus_funcs.h revision 1.3 1 /* $NetBSD: bus_funcs.h,v 1.3 2020/10/11 00:33:30 thorpej 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 _ALPHA_BUS_FUNCS_H_
61 #define _ALPHA_BUS_FUNCS_H_
62
63 #ifdef _KERNEL
64 /*
65 * Utility macros; INTERNAL USE ONLY.
66 */
67 #define __abs_c(a,b) __CONCAT(a,b)
68 #define __abs_opname(op,size) __abs_c(__abs_c(__abs_c(abs_,op),_),size)
69
70 #define __abs_rs(sz, tn, t, h, o) \
71 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \
72 (*(t)->__abs_opname(r,sz))((t)->abs_cookie, h, o))
73
74 #define __abs_ws(sz, tn, t, h, o, v) \
75 do { \
76 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
77 (*(t)->__abs_opname(w,sz))((t)->abs_cookie, h, o, v); \
78 } while (0)
79
80 #define __abs_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)->__abs_opname(type,sz))((t)->abs_cookie, h, o, a, c); \
85 } while (0)
86
87 #define __abs_set(type, sz, tn, t, h, o, v, c) \
88 do { \
89 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
90 (*(t)->__abs_opname(type,sz))((t)->abs_cookie, h, o, v, c); \
91 } while (0)
92
93 #define __abs_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)->__abs_opname(c,sz))((t)->abs_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)->abs_map)((t)->abs_cookie, (a), (s), (f), (hp), 1)
106 #define alpha_bus_space_map_noacct(t, a, s, f, hp) \
107 (*(t)->abs_map)((t)->abs_cookie, (a), (s), (f), (hp), 0)
108 #define bus_space_unmap(t, h, s) \
109 (*(t)->abs_unmap)((t)->abs_cookie, (h), (s), 1)
110 #define alpha_bus_space_unmap_noacct(t, h, s) \
111 (*(t)->abs_unmap)((t)->abs_cookie, (h), (s), 0)
112 #define bus_space_subregion(t, h, o, s, hp) \
113 (*(t)->abs_subregion)((t)->abs_cookie, (h), (o), (s), (hp))
114
115 #define alpha_bus_space_translate(t, a, s, f, abst) \
116 (*(t)->abs_translate)((t)->abs_cookie, (a), (s), (f), (abst))
117 #define alpha_bus_space_get_window(t, w, abst) \
118 (*(t)->abs_get_window)((t)->abs_cookie, (w), (abst))
119 #endif /* _KERNEL */
120
121 #ifdef _KERNEL
122 /*
123 * Allocation and deallocation operations.
124 */
125 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
126 (*(t)->abs_alloc)((t)->abs_cookie, (rs), (re), (s), (a), (b), \
127 (f), (ap), (hp))
128 #define bus_space_free(t, h, s) \
129 (*(t)->abs_free)((t)->abs_cookie, (h), (s))
130
131 /*
132 * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
133 */
134 #define bus_space_vaddr(t, h) \
135 (*(t)->abs_vaddr)((t)->abs_cookie, (h))
136
137 /*
138 * Mmap bus space for a user application.
139 */
140 #define bus_space_mmap(t, a, o, p, f) \
141 (*(t)->abs_mmap)((t)->abs_cookie, (a), (o), (p), (f))
142
143 /*
144 * Bus barrier operations.
145 */
146 #define bus_space_barrier(t, h, o, l, f) \
147 (*(t)->abs_barrier)((t)->abs_cookie, (h), (o), (l), (f))
148
149
150 /*
151 * Bus read (single) operations.
152 */
153 #define bus_space_read_1(t, h, o) __abs_rs(1,uint8_t,(t),(h),(o))
154 #define bus_space_read_2(t, h, o) __abs_rs(2,uint16_t,(t),(h),(o))
155 #define bus_space_read_4(t, h, o) __abs_rs(4,uint32_t,(t),(h),(o))
156 #define bus_space_read_8(t, h, o) __abs_rs(8,uint64_t,(t),(h),(o))
157
158
159 /*
160 * Bus read multiple operations.
161 */
162 #define bus_space_read_multi_1(t, h, o, a, c) \
163 __abs_nonsingle(rm,1,uint8_t,(t),(h),(o),(a),(c))
164 #define bus_space_read_multi_2(t, h, o, a, c) \
165 __abs_nonsingle(rm,2,uint16_t,(t),(h),(o),(a),(c))
166 #define bus_space_read_multi_4(t, h, o, a, c) \
167 __abs_nonsingle(rm,4,uint32_t,(t),(h),(o),(a),(c))
168 #define bus_space_read_multi_8(t, h, o, a, c) \
169 __abs_nonsingle(rm,8,uint64_t,(t),(h),(o),(a),(c))
170
171
172 /*
173 * Bus read region operations.
174 */
175 #define bus_space_read_region_1(t, h, o, a, c) \
176 __abs_nonsingle(rr,1,uint8_t,(t),(h),(o),(a),(c))
177 #define bus_space_read_region_2(t, h, o, a, c) \
178 __abs_nonsingle(rr,2,uint16_t,(t),(h),(o),(a),(c))
179 #define bus_space_read_region_4(t, h, o, a, c) \
180 __abs_nonsingle(rr,4,uint32_t,(t),(h),(o),(a),(c))
181 #define bus_space_read_region_8(t, h, o, a, c) \
182 __abs_nonsingle(rr,8,uint64_t,(t),(h),(o),(a),(c))
183
184
185 /*
186 * Bus write (single) operations.
187 */
188 #define bus_space_write_1(t, h, o, v) __abs_ws(1,uint8_t,(t),(h),(o),(v))
189 #define bus_space_write_2(t, h, o, v) __abs_ws(2,uint16_t,(t),(h),(o),(v))
190 #define bus_space_write_4(t, h, o, v) __abs_ws(4,uint32_t,(t),(h),(o),(v))
191 #define bus_space_write_8(t, h, o, v) __abs_ws(8,uint64_t,(t),(h),(o),(v))
192
193
194 /*
195 * Bus write multiple operations.
196 */
197 #define bus_space_write_multi_1(t, h, o, a, c) \
198 __abs_nonsingle(wm,1,uint8_t,(t),(h),(o),(a),(c))
199 #define bus_space_write_multi_2(t, h, o, a, c) \
200 __abs_nonsingle(wm,2,uint16_t,(t),(h),(o),(a),(c))
201 #define bus_space_write_multi_4(t, h, o, a, c) \
202 __abs_nonsingle(wm,4,uint32_t,(t),(h),(o),(a),(c))
203 #define bus_space_write_multi_8(t, h, o, a, c) \
204 __abs_nonsingle(wm,8,uint64_t,(t),(h),(o),(a),(c))
205
206
207 /*
208 * Bus write region operations.
209 */
210 #define bus_space_write_region_1(t, h, o, a, c) \
211 __abs_nonsingle(wr,1,uint8_t,(t),(h),(o),(a),(c))
212 #define bus_space_write_region_2(t, h, o, a, c) \
213 __abs_nonsingle(wr,2,uint16_t,(t),(h),(o),(a),(c))
214 #define bus_space_write_region_4(t, h, o, a, c) \
215 __abs_nonsingle(wr,4,uint32_t,(t),(h),(o),(a),(c))
216 #define bus_space_write_region_8(t, h, o, a, c) \
217 __abs_nonsingle(wr,8,uint64_t,(t),(h),(o),(a),(c))
218
219
220 /*
221 * Set multiple operations.
222 */
223 #define bus_space_set_multi_1(t, h, o, v, c) \
224 __abs_set(sm,1,uint8_t,(t),(h),(o),(v),(c))
225 #define bus_space_set_multi_2(t, h, o, v, c) \
226 __abs_set(sm,2,uint16_t,(t),(h),(o),(v),(c))
227 #define bus_space_set_multi_4(t, h, o, v, c) \
228 __abs_set(sm,4,uint32_t,(t),(h),(o),(v),(c))
229 #define bus_space_set_multi_8(t, h, o, v, c) \
230 __abs_set(sm,8,uint64_t,(t),(h),(o),(v),(c))
231
232
233 /*
234 * Set region operations.
235 */
236 #define bus_space_set_region_1(t, h, o, v, c) \
237 __abs_set(sr,1,uint8_t,(t),(h),(o),(v),(c))
238 #define bus_space_set_region_2(t, h, o, v, c) \
239 __abs_set(sr,2,uint16_t,(t),(h),(o),(v),(c))
240 #define bus_space_set_region_4(t, h, o, v, c) \
241 __abs_set(sr,4,uint32_t,(t),(h),(o),(v),(c))
242 #define bus_space_set_region_8(t, h, o, v, c) \
243 __abs_set(sr,8,uint64_t,(t),(h),(o),(v),(c))
244
245
246 /*
247 * Copy region operations.
248 */
249 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \
250 __abs_copy(1, uint8_t, (t), (h1), (o1), (h2), (o2), (c))
251 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \
252 __abs_copy(2, uint16_t, (t), (h1), (o1), (h2), (o2), (c))
253 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \
254 __abs_copy(4, uint32_t, (t), (h1), (o1), (h2), (o2), (c))
255 #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \
256 __abs_copy(8, uint64_t, (t), (h1), (o1), (h2), (o2), (c))
257
258 /*
259 * Bus stream operations--defined in terms of non-stream counterparts
260 */
261 #define bus_space_read_stream_1 bus_space_read_1
262 #define bus_space_read_stream_2 bus_space_read_2
263 #define bus_space_read_stream_4 bus_space_read_4
264 #define bus_space_read_stream_8 bus_space_read_8
265 #define bus_space_read_multi_stream_1 bus_space_read_multi_1
266 #define bus_space_read_multi_stream_2 bus_space_read_multi_2
267 #define bus_space_read_multi_stream_4 bus_space_read_multi_4
268 #define bus_space_read_multi_stream_8 bus_space_read_multi_8
269 #define bus_space_read_region_stream_1 bus_space_read_region_1
270 #define bus_space_read_region_stream_2 bus_space_read_region_2
271 #define bus_space_read_region_stream_4 bus_space_read_region_4
272 #define bus_space_read_region_stream_8 bus_space_read_region_8
273 #define bus_space_write_stream_1 bus_space_write_1
274 #define bus_space_write_stream_2 bus_space_write_2
275 #define bus_space_write_stream_4 bus_space_write_4
276 #define bus_space_write_stream_8 bus_space_write_8
277 #define bus_space_write_multi_stream_1 bus_space_write_multi_1
278 #define bus_space_write_multi_stream_2 bus_space_write_multi_2
279 #define bus_space_write_multi_stream_4 bus_space_write_multi_4
280 #define bus_space_write_multi_stream_8 bus_space_write_multi_8
281 #define bus_space_write_region_stream_1 bus_space_write_region_1
282 #define bus_space_write_region_stream_2 bus_space_write_region_2
283 #define bus_space_write_region_stream_4 bus_space_write_region_4
284 #define bus_space_write_region_stream_8 bus_space_write_region_8
285
286
287 /*
288 * Bus DMA methods.
289 */
290
291 /* Forwards needed by prototypes below. */
292 struct mbuf;
293 struct uio;
294 struct alpha_sgmap;
295
296 #define bus_dmamap_create(t, s, n, m, b, f, p) \
297 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
298 #define bus_dmamap_destroy(t, p) \
299 (*(t)->_dmamap_destroy)((t), (p))
300 #define bus_dmamap_load(t, m, b, s, p, f) \
301 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
302 #define bus_dmamap_load_mbuf(t, m, b, f) \
303 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
304 #define bus_dmamap_load_uio(t, m, u, f) \
305 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
306 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
307 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
308 #define bus_dmamap_unload(t, p) \
309 (void)(t), \
310 (*(p)->_dm_window->_dmamap_unload)((p)->_dm_window, (p))
311 #define bus_dmamap_sync(t, p, o, l, ops) \
312 (void)(t), \
313 (*(p)->_dm_window->_dmamap_sync)((p)->_dm_window, (p), (o), (l), (ops))
314 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
315 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
316 #define bus_dmamem_free(t, sg, n) \
317 (*(t)->_dmamem_free)((t), (sg), (n))
318 #define bus_dmamem_map(t, sg, n, s, k, f) \
319 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
320 #define bus_dmamem_unmap(t, k, s) \
321 (*(t)->_dmamem_unmap)((t), (k), (s))
322 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
323 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
324
325 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
326 #define bus_dmatag_destroy(t)
327
328 #ifdef _ALPHA_BUS_DMA_PRIVATE
329 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
330 bus_size_t, int, bus_dmamap_t *);
331 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
332
333 int _bus_dmamap_load_direct(bus_dma_tag_t, bus_dmamap_t,
334 void *, bus_size_t, struct proc *, int);
335 int _bus_dmamap_load_mbuf_direct(bus_dma_tag_t,
336 bus_dmamap_t, struct mbuf *, int);
337 int _bus_dmamap_load_uio_direct(bus_dma_tag_t,
338 bus_dmamap_t, struct uio *, int);
339 int _bus_dmamap_load_raw_direct(bus_dma_tag_t,
340 bus_dmamap_t, bus_dma_segment_t *, int, bus_size_t, int);
341
342 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
343 void _bus_dmamap_unload_common(bus_dma_tag_t, bus_dmamap_t);
344 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
345 bus_size_t, int);
346
347 int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
348 bus_size_t alignment, bus_size_t boundary,
349 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
350 int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
351 bus_size_t alignment, bus_size_t boundary,
352 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
353 paddr_t low, paddr_t high);
354 void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
355 int nsegs);
356 int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
357 int nsegs, size_t size, void **kvap, int flags);
358 void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
359 size_t size);
360 paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
361 int nsegs, off_t off, int prot, int flags);
362
363 #define _DMA_COUNT_DECL(type, cnt) \
364 static struct evcnt dma_stat_##type##_##cnt = \
365 EVCNT_INITIALIZER(EVCNT_TYPE_MISC, NULL, #type, #cnt); \
366 EVCNT_ATTACH_STATIC(dma_stat_##type##_##cnt)
367 #define _DMA_COUNT(type, cnt) \
368 atomic_inc_64(&dma_stat_##type##_##cnt .ev_count)
369
370 #endif /* _ALPHA_BUS_DMA_PRIVATE */
371
372 #endif /* _KERNEL */
373
374 #endif /* _ALPHA_BUS_FUNCS_H_ */
375