No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / landisk / include / bus.h
blob440e027cb17c6309f31210d377c4e00ccc128be6
1 /* $NetBSD: bus.h,v 1.4 2008/04/28 20:23:26 martin Exp $ */
3 /*-
4 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
5 * All rights reserved.
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.
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.
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.
34 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
35 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by Christopher G. Demetriou
48 * for the NetBSD Project.
49 * 4. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission
52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #ifndef _LANDISK_BUS_H_
65 #define _LANDISK_BUS_H_
67 #include <sys/types.h>
69 #ifdef _KERNEL
71 * Turn on BUS_SPACE_DEBUG if the global DEBUG option is enabled.
73 #if defined(DEBUG) && !defined(BUS_SPACE_DEBUG)
74 #define BUS_SPACE_DEBUG
75 #endif
77 #ifdef BUS_SPACE_DEBUG
78 #include <sys/systm.h> /* for printf() prototype */
80 * Macros for checking the aligned-ness of pointers passed to bus
81 * space ops. Strict alignment is required by the Alpha architecture,
82 * and a trap will occur if unaligned access is performed. These
83 * may aid in the debugging of a broken device driver by displaying
84 * useful information about the problem.
86 #define __BUS_SPACE_ALIGNED_ADDRESS(p, t) \
87 ((((u_long)(p)) & (sizeof(t)-1)) == 0)
89 #define __BUS_SPACE_ADDRESS_SANITY(p, t, d) \
90 ({ \
91 if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) { \
92 printf("%s 0x%lx not aligned to %lu bytes %s:%d\n", \
93 d, (u_long)(p), (u_long)sizeof(t), __FILE__, __LINE__); \
94 } \
95 (void) 0; \
98 #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
99 #else
100 #define __BUS_SPACE_ADDRESS_SANITY(p, t, d) (void) 0
101 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
102 #endif /* BUS_SPACE_DEBUG */
103 #endif /* _KERNEL */
105 typedef u_long bus_addr_t;
106 typedef u_long bus_size_t;
108 typedef struct _bus_space *bus_space_tag_t;
109 typedef u_long bus_space_handle_t;
111 struct _bus_space {
112 /* cookie */
113 void *bs_cookie;
115 /* mapping/unmapping */
116 int (*bs_map)(void *, bus_addr_t, bus_size_t,
117 int, bus_space_handle_t *);
118 void (*bs_unmap)(void *, bus_space_handle_t,
119 bus_size_t);
120 int (*bs_subregion)(void *, bus_space_handle_t,
121 bus_size_t, bus_size_t, bus_space_handle_t *);
123 /* allocation/deallocation */
124 int (*bs_alloc)(void *, bus_addr_t, bus_addr_t,
125 bus_size_t, bus_size_t, bus_size_t, int,
126 bus_addr_t *, bus_space_handle_t *);
127 void (*bs_free)(void *, bus_space_handle_t,
128 bus_size_t);
130 /* get kernel virtual address */
131 void * (*bs_vaddr)(void *, bus_space_handle_t);
133 /* mmap bus space for user */
134 paddr_t (*bs_mmap)(void *, bus_addr_t, off_t, int, int);
136 /* read (single) */
137 uint8_t (*bs_r_1)(void *, bus_space_handle_t,
138 bus_size_t);
139 uint16_t (*bs_r_2)(void *, bus_space_handle_t,
140 bus_size_t);
141 uint32_t (*bs_r_4)(void *, bus_space_handle_t,
142 bus_size_t);
143 uint64_t (*bs_r_8)(void *, bus_space_handle_t,
144 bus_size_t);
146 /* read multiple */
147 void (*bs_rm_1)(void *, bus_space_handle_t,
148 bus_size_t, uint8_t *, bus_size_t);
149 void (*bs_rm_2)(void *, bus_space_handle_t,
150 bus_size_t, uint16_t *, bus_size_t);
151 void (*bs_rm_4)(void *, bus_space_handle_t,
152 bus_size_t, uint32_t *, bus_size_t);
153 void (*bs_rm_8)(void *, bus_space_handle_t,
154 bus_size_t, uint64_t *, bus_size_t);
156 /* read region */
157 void (*bs_rr_1)(void *, bus_space_handle_t,
158 bus_size_t, uint8_t *, bus_size_t);
159 void (*bs_rr_2)(void *, bus_space_handle_t,
160 bus_size_t, uint16_t *, bus_size_t);
161 void (*bs_rr_4)(void *, bus_space_handle_t,
162 bus_size_t, uint32_t *, bus_size_t);
163 void (*bs_rr_8)(void *, bus_space_handle_t,
164 bus_size_t, uint64_t *, bus_size_t);
166 /* write (single) */
167 void (*bs_w_1)(void *, bus_space_handle_t,
168 bus_size_t, uint8_t);
169 void (*bs_w_2)(void *, bus_space_handle_t,
170 bus_size_t, uint16_t);
171 void (*bs_w_4)(void *, bus_space_handle_t,
172 bus_size_t, uint32_t);
173 void (*bs_w_8)(void *, bus_space_handle_t,
174 bus_size_t, uint64_t);
176 /* write multiple */
177 void (*bs_wm_1)(void *, bus_space_handle_t,
178 bus_size_t, const uint8_t *, bus_size_t);
179 void (*bs_wm_2)(void *, bus_space_handle_t,
180 bus_size_t, const uint16_t *, bus_size_t);
181 void (*bs_wm_4)(void *, bus_space_handle_t,
182 bus_size_t, const uint32_t *, bus_size_t);
183 void (*bs_wm_8)(void *, bus_space_handle_t,
184 bus_size_t, const uint64_t *, bus_size_t);
186 /* write region */
187 void (*bs_wr_1)(void *, bus_space_handle_t,
188 bus_size_t, const uint8_t *, bus_size_t);
189 void (*bs_wr_2)(void *, bus_space_handle_t,
190 bus_size_t, const uint16_t *, bus_size_t);
191 void (*bs_wr_4)(void *, bus_space_handle_t,
192 bus_size_t, const uint32_t *, bus_size_t);
193 void (*bs_wr_8)(void *, bus_space_handle_t,
194 bus_size_t, const uint64_t *, bus_size_t);
196 /* set multiple */
197 void (*bs_sm_1)(void *, bus_space_handle_t,
198 bus_size_t, uint8_t, bus_size_t);
199 void (*bs_sm_2)(void *, bus_space_handle_t,
200 bus_size_t, uint16_t, bus_size_t);
201 void (*bs_sm_4)(void *, bus_space_handle_t,
202 bus_size_t, uint32_t, bus_size_t);
203 void (*bs_sm_8)(void *, bus_space_handle_t,
204 bus_size_t, uint64_t, bus_size_t);
206 /* set region */
207 void (*bs_sr_1)(void *, bus_space_handle_t,
208 bus_size_t, uint8_t, bus_size_t);
209 void (*bs_sr_2)(void *, bus_space_handle_t,
210 bus_size_t, uint16_t, bus_size_t);
211 void (*bs_sr_4)(void *, bus_space_handle_t,
212 bus_size_t, uint32_t, bus_size_t);
213 void (*bs_sr_8)(void *, bus_space_handle_t,
214 bus_size_t, uint64_t, bus_size_t);
216 /* copy */
217 void (*bs_c_1)(void *, bus_space_handle_t, bus_size_t,
218 bus_space_handle_t, bus_size_t, bus_size_t);
219 void (*bs_c_2)(void *, bus_space_handle_t, bus_size_t,
220 bus_space_handle_t, bus_size_t, bus_size_t);
221 void (*bs_c_4)(void *, bus_space_handle_t, bus_size_t,
222 bus_space_handle_t, bus_size_t, bus_size_t);
223 void (*bs_c_8)(void *, bus_space_handle_t, bus_size_t,
224 bus_space_handle_t, bus_size_t, bus_size_t);
227 #ifdef _KERNEL
229 * Utility macros; INTERNAL USE ONLY.
231 #define __bs_c(a,b) __CONCAT(a,b)
232 #define __bs_opname(op,size) __bs_c(__bs_c(__bs_c(bs_,op),_),size)
234 #define __bs_rs(sz, tn, t, h, o) \
235 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \
236 (*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o))
238 #define __bs_ws(sz, tn, t, h, o, v) \
239 do { \
240 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
241 (*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v); \
242 } while (0)
244 #define __bs_nonsingle(type, sz, tn, t, h, o, a, c) \
245 do { \
246 __BUS_SPACE_ADDRESS_SANITY((a), tn, "buffer"); \
247 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
248 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c); \
249 } while (0)
251 #define __bs_set(type, sz, tn, t, h, o, v, c) \
252 do { \
253 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
254 (*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c); \
255 } while (0)
257 #define __bs_copy(sz, tn, t, h1, o1, h2, o2, cnt) \
258 do { \
259 __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), tn, "bus addr 1"); \
260 __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), tn, "bus addr 2"); \
261 (*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt); \
262 } while (0)
266 * Mapping and unmapping operations.
268 #define bus_space_map(t, a, s, f, hp) \
269 (*(t)->bs_map)((t)->bs_cookie, (a), (s), (f), (hp))
270 #define bus_space_unmap(t, h, s) \
271 (*(t)->bs_unmap)((t)->bs_cookie, (h), (s))
272 #define bus_space_subregion(t, h, o, s, hp) \
273 (*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp))
275 #endif /* _KERNEL */
277 #define BUS_SPACE_MAP_CACHEABLE 0x01
278 #define BUS_SPACE_MAP_LINEAR 0x02
279 #define BUS_SPACE_MAP_PREFETCHABLE 0x04
281 #ifdef _KERNEL
283 * Allocation and deallocation operations.
285 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
286 (*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b), \
287 (f), (ap), (hp))
288 #define bus_space_free(t, h, s) \
289 (*(t)->bs_free)((t)->bs_cookie, (h), (s))
292 * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
294 #define bus_space_vaddr(t, h) \
295 (*(t)->bs_vaddr)((t)->bs_cookie, (h))
298 * MMap bus space for a user application.
300 #define bus_space_mmap(t, a, o, p, f) \
301 (*(t)->bs_mmap)((t)->bs_cookie, (a), (o), (p), (f))
304 * Bus barrier operations. The SH3 does not currently require
305 * barriers, but we must provide the flags to MI code.
307 #define bus_space_barrier(t, h, o, l, f) \
308 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
310 #define BUS_SPACE_BARRIER_READ 0x01
311 #define BUS_SPACE_BARRIER_WRITE 0x02
315 * Bus read (single) operations.
317 #define bus_space_read_1(t, h, o) __bs_rs(1,uint8_t,(t),(h),(o))
318 #define bus_space_read_2(t, h, o) __bs_rs(2,uint16_t,(t),(h),(o))
319 #define bus_space_read_4(t, h, o) __bs_rs(4,uint32_t,(t),(h),(o))
320 #define bus_space_read_8(t, h, o) __bs_rs(8,uint64_t,(t),(h),(o))
324 * Bus read multiple operations.
326 #define bus_space_read_multi_1(t, h, o, a, c) \
327 __bs_nonsingle(rm,1,uint8_t,(t),(h),(o),(a),(c))
328 #define bus_space_read_multi_2(t, h, o, a, c) \
329 __bs_nonsingle(rm,2,uint16_t,(t),(h),(o),(a),(c))
330 #define bus_space_read_multi_4(t, h, o, a, c) \
331 __bs_nonsingle(rm,4,uint32_t,(t),(h),(o),(a),(c))
332 #define bus_space_read_multi_8(t, h, o, a, c) \
333 __bs_nonsingle(rm,8,uint64_t,(t),(h),(o),(a),(c))
337 * Bus read region operations.
339 #define bus_space_read_region_1(t, h, o, a, c) \
340 __bs_nonsingle(rr,1,uint8_t,(t),(h),(o),(a),(c))
341 #define bus_space_read_region_2(t, h, o, a, c) \
342 __bs_nonsingle(rr,2,uint16_t,(t),(h),(o),(a),(c))
343 #define bus_space_read_region_4(t, h, o, a, c) \
344 __bs_nonsingle(rr,4,uint32_t,(t),(h),(o),(a),(c))
345 #define bus_space_read_region_8(t, h, o, a, c) \
346 __bs_nonsingle(rr,8,uint64_t,(t),(h),(o),(a),(c))
350 * Bus write (single) operations.
352 #define bus_space_write_1(t, h, o, v) __bs_ws(1,uint8_t,(t),(h),(o),(v))
353 #define bus_space_write_2(t, h, o, v) __bs_ws(2,uint16_t,(t),(h),(o),(v))
354 #define bus_space_write_4(t, h, o, v) __bs_ws(4,uint32_t,(t),(h),(o),(v))
355 #define bus_space_write_8(t, h, o, v) __bs_ws(8,uint64_t,(t),(h),(o),(v))
359 * Bus write multiple operations.
361 #define bus_space_write_multi_1(t, h, o, a, c) \
362 __bs_nonsingle(wm,1,uint8_t,(t),(h),(o),(a),(c))
363 #define bus_space_write_multi_2(t, h, o, a, c) \
364 __bs_nonsingle(wm,2,uint16_t,(t),(h),(o),(a),(c))
365 #define bus_space_write_multi_4(t, h, o, a, c) \
366 __bs_nonsingle(wm,4,uint32_t,(t),(h),(o),(a),(c))
367 #define bus_space_write_multi_8(t, h, o, a, c) \
368 __bs_nonsingle(wm,8,uint64_t,(t),(h),(o),(a),(c))
372 * Bus write region operations.
374 #define bus_space_write_region_1(t, h, o, a, c) \
375 __bs_nonsingle(wr,1,uint8_t,(t),(h),(o),(a),(c))
376 #define bus_space_write_region_2(t, h, o, a, c) \
377 __bs_nonsingle(wr,2,uint16_t,(t),(h),(o),(a),(c))
378 #define bus_space_write_region_4(t, h, o, a, c) \
379 __bs_nonsingle(wr,4,uint32_t,(t),(h),(o),(a),(c))
380 #define bus_space_write_region_8(t, h, o, a, c) \
381 __bs_nonsingle(wr,8,uint64_t,(t),(h),(o),(a),(c))
385 * Set multiple operations.
387 #define bus_space_set_multi_1(t, h, o, v, c) \
388 __bs_set(sm,1,uint8_t,(t),(h),(o),(v),(c))
389 #define bus_space_set_multi_2(t, h, o, v, c) \
390 __bs_set(sm,2,uint16_t,(t),(h),(o),(v),(c))
391 #define bus_space_set_multi_4(t, h, o, v, c) \
392 __bs_set(sm,4,uint32_t,(t),(h),(o),(v),(c))
393 #define bus_space_set_multi_8(t, h, o, v, c) \
394 __bs_set(sm,8,uint64_t,(t),(h),(o),(v),(c))
398 * Set region operations.
400 #define bus_space_set_region_1(t, h, o, v, c) \
401 __bs_set(sr,1,uint8_t,(t),(h),(o),(v),(c))
402 #define bus_space_set_region_2(t, h, o, v, c) \
403 __bs_set(sr,2,uint16_t,(t),(h),(o),(v),(c))
404 #define bus_space_set_region_4(t, h, o, v, c) \
405 __bs_set(sr,4,uint32_t,(t),(h),(o),(v),(c))
406 #define bus_space_set_region_8(t, h, o, v, c) \
407 __bs_set(sr,8,uint64_t,(t),(h),(o),(v),(c))
411 * Copy region operations.
413 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \
414 __bs_copy(1, uint8_t, (t), (h1), (o1), (h2), (o2), (c))
415 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \
416 __bs_copy(2, uint16_t, (t), (h1), (o1), (h2), (o2), (c))
417 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \
418 __bs_copy(4, uint32_t, (t), (h1), (o1), (h2), (o2), (c))
419 #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \
420 __bs_copy(8, uint64_t, (t), (h1), (o1), (h2), (o2), (c))
423 * Bus stream operations--defined in terms of non-stream counterparts
425 #define __BUS_SPACE_HAS_STREAM_METHODS
426 #define bus_space_read_stream_1 bus_space_read_1
427 #define bus_space_read_stream_2 bus_space_read_2
428 #define bus_space_read_stream_4 bus_space_read_4
429 #define bus_space_read_stream_8 bus_space_read_8
430 #define bus_space_read_multi_stream_1 bus_space_read_multi_1
431 #define bus_space_read_multi_stream_2 bus_space_read_multi_2
432 #define bus_space_read_multi_stream_4 bus_space_read_multi_4
433 #define bus_space_read_multi_stream_8 bus_space_read_multi_8
434 #define bus_space_read_region_stream_1 bus_space_read_region_1
435 #define bus_space_read_region_stream_2 bus_space_read_region_2
436 #define bus_space_read_region_stream_4 bus_space_read_region_4
437 #define bus_space_read_region_stream_8 bus_space_read_region_8
438 #define bus_space_write_stream_1 bus_space_write_1
439 #define bus_space_write_stream_2 bus_space_write_2
440 #define bus_space_write_stream_4 bus_space_write_4
441 #define bus_space_write_stream_8 bus_space_write_8
442 #define bus_space_write_multi_stream_1 bus_space_write_multi_1
443 #define bus_space_write_multi_stream_2 bus_space_write_multi_2
444 #define bus_space_write_multi_stream_4 bus_space_write_multi_4
445 #define bus_space_write_multi_stream_8 bus_space_write_multi_8
446 #define bus_space_write_region_stream_1 bus_space_write_region_1
447 #define bus_space_write_region_stream_2 bus_space_write_region_2
448 #define bus_space_write_region_stream_4 bus_space_write_region_4
449 #define bus_space_write_region_stream_8 bus_space_write_region_8
451 #endif /* _KERNEL */
454 * Flags used in various bus DMA methods.
456 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
457 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
458 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
459 #define BUS_DMA_COHERENT 0x004 /* map memory to not require sync */
460 #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
461 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
462 #define BUS_DMA_BUS2 0x020
463 #define BUS_DMA_BUS3 0x040
464 #define BUS_DMA_BUS4 0x080
465 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
466 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
467 #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
469 /* Forwards needed by prototypes below. */
470 struct mbuf;
471 struct uio;
474 * Operations performed by bus_dmamap_sync().
476 #define BUS_DMASYNC_PREREAD 0x01
477 #define BUS_DMASYNC_POSTREAD 0x02
478 #define BUS_DMASYNC_PREWRITE 0x04
479 #define BUS_DMASYNC_POSTWRITE 0x08
481 typedef struct _bus_dma_tag *bus_dma_tag_t;
482 typedef struct _bus_dmamap *bus_dmamap_t;
484 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
487 * bus_dma_segment_t
489 * Describes a single contiguous DMA transaction. Values
490 * are suitable for programming into DMA registers.
492 struct _bus_dma_segment {
493 bus_addr_t ds_addr; /* DMA address */
494 bus_size_t ds_len; /* length of transfer */
496 /* private section */
497 bus_addr_t _ds_vaddr; /* virtual address */
499 typedef struct _bus_dma_segment bus_dma_segment_t;
502 * bus_dma_tag_t
504 * A machine-dependent opaque type describing the implementation of
505 * DMA for a given bus.
508 struct _bus_dma_tag {
509 void *_cookie; /* cookie used in the guts */
512 * DMA mapping methods.
514 int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
515 bus_size_t, bus_size_t, int, bus_dmamap_t *);
516 void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
517 int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
518 bus_size_t, struct proc *, int);
519 int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
520 struct mbuf *, int);
521 int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
522 struct uio *, int);
523 int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
524 bus_dma_segment_t *, int, bus_size_t, int);
525 void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
526 void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
527 bus_addr_t, bus_size_t, int);
530 * DMA memory utility functions.
532 int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
533 bus_size_t, bus_dma_segment_t *, int, int *, int);
534 void (*_dmamem_free)(bus_dma_tag_t,
535 bus_dma_segment_t *, int);
536 int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
537 int, size_t, void **, int);
538 void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
539 paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
540 int, off_t, int, int);
543 #define bus_dmamap_create(t, s, n, m, b, f, p) \
544 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
545 #define bus_dmamap_destroy(t, p) \
546 (*(t)->_dmamap_destroy)((t), (p))
547 #define bus_dmamap_load(t, m, b, s, p, f) \
548 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
549 #define bus_dmamap_load_mbuf(t, m, b, f) \
550 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
551 #define bus_dmamap_load_uio(t, m, u, f) \
552 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
553 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
554 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
555 #define bus_dmamap_unload(t, p) \
556 (*(t)->_dmamap_unload)((t), (p))
557 #define bus_dmamap_sync(t, m, o, l, op) \
558 (void)((t)->_dmamap_sync ? \
559 (*(t)->_dmamap_sync)((t), (m), (o), (l), (op)) : (void)0)
561 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
562 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
563 #define bus_dmamem_free(t, sg, n) \
564 (*(t)->_dmamem_free)((t), (sg), (n))
565 #define bus_dmamem_map(t, sg, n, s, k, f) \
566 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
567 #define bus_dmamem_unmap(t, k, s) \
568 (*(t)->_dmamem_unmap)((t), (k), (s))
569 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
570 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
572 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
573 #define bus_dmatag_destroy(t)
576 * bus_dmamap_t
578 * Describes a DMA mapping.
580 struct _bus_dmamap {
582 * PRIVATE MEMBERS: not for use my machine-independent code.
584 bus_size_t _dm_size; /* largest DMA transfer mappable */
585 int _dm_segcnt; /* number of segs this map can map */
586 bus_size_t _dm_maxsegsz; /* largest possible segment */
587 bus_size_t _dm_boundary; /* don't cross this */
588 int _dm_flags; /* misc. flags */
590 void *_dm_cookie; /* cookie for bus-specific functions */
593 * PUBLIC MEMBERS: these are used by machine-independent code.
595 bus_size_t dm_mapsize; /* size of the mapping */
596 int dm_nsegs; /* # valid segments in mapping */
597 bus_dma_segment_t dm_segs[1]; /* segments; variable length */
600 #if defined(_LANDISK_BUS_DMA_PRIVATE)
601 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
602 bus_size_t, int, bus_dmamap_t *);
603 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
604 int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
605 struct proc *, int);
606 int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *,int);
607 int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int);
608 int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
609 int, bus_size_t, int);
610 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
611 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
612 bus_size_t, int);
614 int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
615 bus_size_t alignment, bus_size_t boundary, bus_dma_segment_t *segs,
616 int nsegs, int *rsegs, int flags);
617 void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
618 int nsegs);
619 int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs,
620 size_t size, void **kvap, int flags);
621 void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva, size_t size);
622 paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
623 int nsegs, off_t off, int prot, int flags);
624 #endif /* _LANDISK_BUS_DMA_PRIVATE */
626 #endif /* _LANDISK_BUS_H_ */