Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / cobalt / include / bus.h
blobcbafbd3553bb816d0f7805f4b89af98c48c0c1b8
1 /* $NetBSD: bus.h,v 1.22 2008/04/28 20:23:16 martin Exp $ */
3 /*
4 * Copyright (c) 1996, 1997, 1998, 2001 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.
33 #ifndef _COBALT_BUS_H_
34 #define _COBALT_BUS_H_
36 #include <mips/locore.h>
39 * Utility macros; do not use outside this file.
41 #define __PB_TYPENAME_PREFIX(BITS) ___CONCAT(uint,BITS)
42 #define __PB_TYPENAME(BITS) ___CONCAT(__PB_TYPENAME_PREFIX(BITS),_t)
45 * Bus address and size types
47 typedef u_long bus_addr_t;
48 typedef u_long bus_size_t;
51 * Access methods for bus resources and address space.
53 typedef int bus_space_tag_t;
54 typedef u_long bus_space_handle_t;
57 * int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
58 * bus_size_t size, int flags, bus_space_handle_t *bshp);
60 * Map a region of bus space.
63 #define BUS_SPACE_MAP_CACHEABLE 0x01
64 #define BUS_SPACE_MAP_LINEAR 0x02
65 #define BUS_SPACE_MAP_PREFETCHABLE 0x04
67 int bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
68 int, bus_space_handle_t *);
71 * void bus_space_unmap(bus_space_tag_t t,
72 * bus_space_handle_t bsh, bus_size_t size);
74 * Unmap a region of bus space.
77 void bus_space_unmap (bus_space_tag_t, bus_space_handle_t, bus_size_t);
80 * int bus_space_subregion(bus_space_tag_t t,
81 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
82 * bus_space_handle_t *nbshp);
84 * Get a new handle for a subregion of an already-mapped area of bus space.
87 int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
88 bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
91 * paddr_t bus_space_mmap(bus_space_tag_t t,
92 * bus_addr_t addr, off_t offset, int prot, int flags);
94 * Mmap bus space for a user application.
97 paddr_t bus_space_mmap(bus_space_tag_t t, bus_addr_t addr, off_t off, int prot,
98 int flags);
101 * int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
102 * bus_addr_t rend, bus_size_t size, bus_size_t align,
103 * bus_size_t boundary, int flags, bus_addr_t *addrp,
104 * bus_space_handle_t *bshp);
106 * Allocate a region of bus space.
109 int bus_space_alloc (bus_space_tag_t t, bus_addr_t rstart,
110 bus_addr_t rend, bus_size_t size, bus_size_t align,
111 bus_size_t boundary, int cacheable, bus_addr_t *addrp,
112 bus_space_handle_t *bshp);
115 * int bus_space_free (bus_space_tag_t t,
116 * bus_space_handle_t bsh, bus_size_t size);
118 * Free a region of bus space.
121 void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
122 bus_size_t size);
125 * uintN_t bus_space_read_N(bus_space_tag_t tag,
126 * bus_space_handle_t bsh, bus_size_t offset);
128 * Read a 1, 2, 4, or 8 byte quantity from bus space
129 * described by tag/handle/offset.
132 #define bus_space_read_1(t, h, o) \
133 ((void) t, (*(volatile uint8_t *)((h) + (o))))
135 #define bus_space_read_2(t, h, o) \
136 ((void) t, (*(volatile uint16_t *)((h) + (o))))
138 #define bus_space_read_4(t, h, o) \
139 ((void) t, (*(volatile uint32_t *)((h) + (o))))
141 #if 0 /* Cause a link error for bus_space_read_8 */
142 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
143 #endif
146 * void bus_space_read_multi_N(bus_space_tag_t tag,
147 * bus_space_handle_t bsh, bus_size_t offset,
148 * uintN_t *addr, size_t count);
150 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
151 * described by tag/handle/offset and copy into buffer provided.
154 #define __COBALT_bus_space_read_multi(BYTES,BITS) \
155 static __inline void __CONCAT(bus_space_read_multi_,BYTES) \
156 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
157 __PB_TYPENAME(BITS) *, size_t); \
159 static __inline void \
160 __CONCAT(bus_space_read_multi_,BYTES)(t, h, o, a, c) \
161 bus_space_tag_t t; \
162 bus_space_handle_t h; \
163 bus_size_t o; \
164 __PB_TYPENAME(BITS) *a; \
165 size_t c; \
168 while (c--) \
169 *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o); \
172 __COBALT_bus_space_read_multi(1,8)
173 __COBALT_bus_space_read_multi(2,16)
174 __COBALT_bus_space_read_multi(4,32)
176 #if 0 /* Cause a link error for bus_space_read_multi_8 */
177 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
178 #endif
180 #undef __COBALT_bus_space_read_multi
183 * void bus_space_read_region_N(bus_space_tag_t tag,
184 * bus_space_handle_t bsh, bus_size_t offset,
185 * uintN_t *addr, size_t count);
187 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
188 * described by tag/handle and starting at `offset' and copy into
189 * buffer provided.
192 #define __COBALT_bus_space_read_region(BYTES,BITS) \
193 static __inline void __CONCAT(bus_space_read_region_,BYTES) \
194 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
195 __PB_TYPENAME(BITS) *, size_t); \
197 static __inline void \
198 __CONCAT(bus_space_read_region_,BYTES)(t, h, o, a, c) \
199 bus_space_tag_t t; \
200 bus_space_handle_t h; \
201 bus_size_t o; \
202 __PB_TYPENAME(BITS) *a; \
203 size_t c; \
206 while (c--) { \
207 *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o); \
208 o += BYTES; \
212 __COBALT_bus_space_read_region(1,8)
213 __COBALT_bus_space_read_region(2,16)
214 __COBALT_bus_space_read_region(4,32)
216 #if 0 /* Cause a link error for bus_space_read_region_8 */
217 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
218 #endif
220 #undef __COBALT_bus_space_read_region
223 * void bus_space_write_N(bus_space_tag_t tag,
224 * bus_space_handle_t bsh, bus_size_t offset,
225 * uintN_t value);
227 * Write the 1, 2, 4, or 8 byte value `value' to bus space
228 * described by tag/handle/offset.
231 #define bus_space_write_1(t, h, o, v) \
232 do { \
233 (void) t; \
234 *(volatile uint8_t *)((h) + (o)) = (v); \
235 } while (0)
237 #define bus_space_write_2(t, h, o, v) \
238 do { \
239 (void) t; \
240 *(volatile uint16_t *)((h) + (o)) = (v); \
241 } while (0)
243 #define bus_space_write_4(t, h, o, v) \
244 do { \
245 (void) t; \
246 *(volatile uint32_t *)((h) + (o)) = (v); \
247 } while (0)
249 #if 0 /* Cause a link error for bus_space_write_8 */
250 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
251 #endif
254 * void bus_space_write_multi_N(bus_space_tag_t tag,
255 * bus_space_handle_t bsh, bus_size_t offset,
256 * const uintN_t *addr, size_t count);
258 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
259 * provided to bus space described by tag/handle/offset.
262 #define __COBALT_bus_space_write_multi(BYTES,BITS) \
263 static __inline void __CONCAT(bus_space_write_multi_,BYTES) \
264 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
265 const __PB_TYPENAME(BITS) *, size_t); \
267 static __inline void \
268 __CONCAT(bus_space_write_multi_,BYTES)(t, h, o, a, c) \
269 bus_space_tag_t t; \
270 bus_space_handle_t h; \
271 bus_size_t o; \
272 const __PB_TYPENAME(BITS) *a; \
273 size_t c; \
276 while (c--) \
277 __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++); \
280 __COBALT_bus_space_write_multi(1,8)
281 __COBALT_bus_space_write_multi(2,16)
282 __COBALT_bus_space_write_multi(4,32)
284 #if 0 /* Cause a link error for bus_space_write_8 */
285 #define bus_space_write_multi_8(t, h, o, a, c) \
286 !!! bus_space_write_multi_8 unimplimented !!!
287 #endif
289 #undef __COBALT_bus_space_write_multi
292 * void bus_space_write_region_N(bus_space_tag_t tag,
293 * bus_space_handle_t bsh, bus_size_t offset,
294 * const uintN_t *addr, size_t count);
296 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
297 * to bus space described by tag/handle starting at `offset'.
300 #define __COBALT_bus_space_write_region(BYTES,BITS) \
301 static __inline void __CONCAT(bus_space_write_region_,BYTES) \
302 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
303 const __PB_TYPENAME(BITS) *, size_t); \
305 static __inline void \
306 __CONCAT(bus_space_write_region_,BYTES)(t, h, o, a, c) \
307 bus_space_tag_t t; \
308 bus_space_handle_t h; \
309 bus_size_t o; \
310 const __PB_TYPENAME(BITS) *a; \
311 size_t c; \
314 while (c--) { \
315 __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++); \
316 o += BYTES; \
320 __COBALT_bus_space_write_region(1,8)
321 __COBALT_bus_space_write_region(2,16)
322 __COBALT_bus_space_write_region(4,32)
324 #if 0 /* Cause a link error for bus_space_write_region_8 */
325 #define bus_space_write_region_8 \
326 !!! bus_space_write_region_8 unimplemented !!!
327 #endif
329 #undef __COBALT_bus_space_write_region
332 * void bus_space_set_multi_N(bus_space_tag_t tag,
333 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
334 * size_t count);
336 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
337 * by tag/handle/offset `count' times.
340 #define __COBALT_bus_space_set_multi(BYTES,BITS) \
341 static __inline void __CONCAT(bus_space_set_multi_,BYTES) \
342 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
343 __PB_TYPENAME(BITS), size_t); \
345 static __inline void \
346 __CONCAT(bus_space_set_multi_,BYTES)(t, h, o, v, c) \
347 bus_space_tag_t t; \
348 bus_space_handle_t h; \
349 bus_size_t o; \
350 __PB_TYPENAME(BITS) v; \
351 size_t c; \
354 while (c--) \
355 __CONCAT(bus_space_write_,BYTES)(t, h, o, v); \
358 __COBALT_bus_space_set_multi(1,8)
359 __COBALT_bus_space_set_multi(2,16)
360 __COBALT_bus_space_set_multi(4,32)
362 #if 0 /* Cause a link error for bus_space_set_multi_8 */
363 #define bus_space_set_multi_8 \
364 !!! bus_space_set_multi_8 unimplemented !!!
365 #endif
367 #undef __COBALT_bus_space_set_multi
370 * void bus_space_set_region_N(bus_space_tag_t tag,
371 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
372 * size_t count);
374 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
375 * by tag/handle starting at `offset'.
378 #define __COBALT_bus_space_set_region(BYTES,BITS) \
379 static __inline void __CONCAT(bus_space_set_region_,BYTES) \
380 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
381 __PB_TYPENAME(BITS), size_t); \
383 static __inline void \
384 __CONCAT(bus_space_set_region_,BYTES)(t, h, o, v, c) \
385 bus_space_tag_t t; \
386 bus_space_handle_t h; \
387 bus_size_t o; \
388 __PB_TYPENAME(BITS) v; \
389 size_t c; \
392 while (c--) { \
393 __CONCAT(bus_space_write_,BYTES)(t, h, o, v); \
394 o += BYTES; \
398 __COBALT_bus_space_set_region(1,8)
399 __COBALT_bus_space_set_region(2,16)
400 __COBALT_bus_space_set_region(4,32)
402 #if 0 /* Cause a link error for bus_space_set_region_8 */
403 #define bus_space_set_region_8 \
404 !!! bus_space_set_region_8 unimplemented !!!
405 #endif
407 #undef __COBALT_bus_space_set_region
410 * void bus_space_copy_region_N(bus_space_tag_t tag,
411 * bus_space_handle_t bsh1, bus_size_t off1,
412 * bus_space_handle_t bsh2, bus_size_t off2,
413 * bus_size_t count);
415 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
416 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
419 #define __COBALT_copy_region(BYTES) \
420 static __inline void __CONCAT(bus_space_copy_region_,BYTES) \
421 (bus_space_tag_t, \
422 bus_space_handle_t bsh1, bus_size_t off1, \
423 bus_space_handle_t bsh2, bus_size_t off2, \
424 bus_size_t count); \
426 static __inline void \
427 __CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c) \
428 bus_space_tag_t t; \
429 bus_space_handle_t h1, h2; \
430 bus_size_t o1, o2, c; \
432 bus_size_t o; \
434 if ((h1 + o1) >= (h2 + o2)) { \
435 /* src after dest: copy forward */ \
436 for (o = 0; c != 0; c--, o += BYTES) \
437 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
438 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
439 } else { \
440 /* dest after src: copy backwards */ \
441 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
442 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
443 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
447 __COBALT_copy_region(1)
448 __COBALT_copy_region(2)
449 __COBALT_copy_region(4)
451 #if 0 /* Cause a link error for bus_space_copy_region_8 */
452 #define bus_space_copy_region_8 \
453 !!! bus_space_copy_region_8 unimplemented !!!
454 #endif
456 #undef __COBALT_copy_region
459 * Operations which handle byte stream data on word access.
461 * These functions are defined to resolve endian mismatch, by either
462 * - When normal (i.e. stream-less) operations perform byte swap
463 * to resolve endian mismatch, these functions bypass the byte swap.
464 * or
465 * - When bus bridge performs automatic byte swap, these functions
466 * perform byte swap once more, to cancel the bridge's behavior.
468 * Currently these are just same as normal operations, since all
469 * supported buses are same endian with CPU (i.e. little-endian).
472 #define __BUS_SPACE_HAS_STREAM_METHODS
473 #define bus_space_read_stream_2(tag, bsh, offset) \
474 bus_space_read_2(tag, bsh, offset)
475 #define bus_space_read_stream_4(tag, bsh, offset) \
476 bus_space_read_4(tag, bsh, offset)
477 #define bus_space_read_stream_8(tag, bsh, offset) \
478 bus_space_read_8(tag, bsh, offset)
479 #define bus_space_read_multi_stream_2(tag, bsh, offset, datap, count) \
480 bus_space_read_multi_2(tag, bsh, offset, datap, count)
481 #define bus_space_read_multi_stream_4(tag, bsh, offset, datap, count) \
482 bus_space_read_multi_4(tag, bsh, offset, datap, count)
483 #define bus_space_read_multi_stream_8(tag, bsh, offset, datap, count) \
484 bus_space_read_multi_8(tag, bsh, offset, datap, count)
485 #define bus_space_read_region_stream_2(tag, bsh, offset, datap, count) \
486 bus_space_read_region_2(tag, bsh, offset, datap, count)
487 #define bus_space_read_region_stream_4(tag, bsh, offset, datap, count) \
488 bus_space_read_region_4(tag, bsh, offset, datap, count)
489 #define bus_space_read_region_stream_8(tag, bsh, offset, datap, count) \
490 bus_space_read_region_8(tag, bsh, offset, datap, count)
491 #define bus_space_write_stream_2(tag, bsh, offset, data) \
492 bus_space_write_2(tag, bsh, offset, data)
493 #define bus_space_write_stream_4(tag, bsh, offset, data) \
494 bus_space_write_4(tag, bsh, offset, data)
495 #define bus_space_write_stream_8(tag, bsh, offset, data) \
496 bus_space_write_8(tag, bsh, offset, data)
497 #define bus_space_write_multi_stream_2(tag, bsh, offset, datap, count) \
498 bus_space_write_multi_2(tag, bsh, offset, datap, count)
499 #define bus_space_write_multi_stream_4(tag, bsh, offset, datap, count) \
500 bus_space_write_multi_4(tag, bsh, offset, datap, count)
501 #define bus_space_write_multi_stream_8(tag, bsh, offset, datap, count) \
502 bus_space_write_multi_8(tag, bsh, offset, datap, count)
503 #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count) \
504 bus_space_write_region_2(tag, bsh, offset, datap, count)
505 #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count) \
506 bus_space_write_region_4(tag, bsh, offset, datap, count)
507 #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count) \
508 bus_space_write_region_8(tag, bsh, offset, datap, count)
509 #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count) \
510 bus_space_write_region_2(tag, bsh, offset, datap, count)
511 #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count) \
512 bus_space_write_region_4(tag, bsh, offset, datap, count)
513 #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count) \
514 bus_space_write_region_8(tag, bsh, offset, datap, count)
515 #define bus_space_set_multi_stream_2(tag, bsh, offset, data, count) \
516 bus_space_set_multi_2(tag, bsh, offset, data, count)
517 #define bus_space_set_multi_stream_4(tag, bsh, offset, data, count) \
518 bus_space_set_multi_4(tag, bsh, offset, data, count)
519 #define bus_space_set_multi_stream_8(tag, bsh, offset, data, count) \
520 bus_space_set_multi_8(tag, bsh, offset, data, count)
521 #define bus_space_set_region_stream_2(tag, bsh, offset, data, count) \
522 bus_space_set_region_2(tag, bsh, offset, data, count)
523 #define bus_space_set_region_stream_4(tag, bsh, offset, data, count) \
524 bus_space_set_region_4(tag, bsh, offset, data, count)
525 #define bus_space_set_region_stream_8(tag, bsh, offset, data, count) \
526 bus_space_set_region_8(tag, bsh, offset, data, count)
529 * Bus read/write barrier methods.
531 * void bus_space_barrier(bus_space_tag_t tag,
532 * bus_space_handle_t bsh, bus_size_t offset,
533 * bus_size_t len, int flags);
535 * On the MIPS, we just flush the write buffer.
537 #define bus_space_barrier(t, h, o, l, f) \
538 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f), \
539 wbflush()))
540 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
541 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
543 #undef __PB_TYPENAME_PREFIX
544 #undef __PB_TYPENAME
546 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
549 * Flags used in various bus DMA methods.
551 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
552 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
553 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
554 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
555 #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
556 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
557 #define BUS_DMA_BUS2 0x020
558 #define BUS_DMA_BUS3 0x040
559 #define BUS_DMA_BUS4 0x080
560 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
561 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
562 #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
564 #define COBALT_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */
566 /* Forwards needed by prototypes below. */
567 struct mbuf;
568 struct uio;
571 * Operations performed by bus_dmamap_sync().
573 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
574 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
575 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
576 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
578 typedef struct cobalt_bus_dma_tag *bus_dma_tag_t;
579 typedef struct cobalt_bus_dmamap *bus_dmamap_t;
581 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
584 * bus_dma_segment_t
586 * Describes a single contiguous DMA transaction. Values
587 * are suitable for programming into DMA registers.
589 struct cobalt_bus_dma_segment {
590 bus_addr_t ds_addr; /* DMA address */
591 bus_size_t ds_len; /* length of transfer */
592 vaddr_t _ds_vaddr; /* virtual address, 0 if invalid */
594 typedef struct cobalt_bus_dma_segment bus_dma_segment_t;
597 * bus_dma_tag_t
599 * A machine-dependent opaque type describing the implementation of
600 * DMA for a given bus.
603 struct cobalt_bus_dma_tag {
605 * DMA mapping methods.
607 int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
608 bus_size_t, bus_size_t, int, bus_dmamap_t *);
609 void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
610 int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
611 bus_size_t, struct proc *, int);
612 int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
613 struct mbuf *, int);
614 int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
615 struct uio *, int);
616 int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
617 bus_dma_segment_t *, int, bus_size_t, int);
618 void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
619 void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
620 bus_addr_t, bus_size_t, int);
623 * DMA memory utility functions.
625 int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
626 bus_size_t, bus_dma_segment_t *, int, int *, int);
627 void (*_dmamem_free)(bus_dma_tag_t,
628 bus_dma_segment_t *, int);
629 int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
630 int, size_t, void **, int);
631 void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
632 paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
633 int, off_t, int, int);
636 #define bus_dmamap_create(t, s, n, m, b, f, p) \
637 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
638 #define bus_dmamap_destroy(t, p) \
639 (*(t)->_dmamap_destroy)((t), (p))
640 #define bus_dmamap_load(t, m, b, s, p, f) \
641 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
642 #define bus_dmamap_load_mbuf(t, m, b, f) \
643 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
644 #define bus_dmamap_load_uio(t, m, u, f) \
645 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
646 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
647 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
648 #define bus_dmamap_unload(t, p) \
649 (*(t)->_dmamap_unload)((t), (p))
650 #define bus_dmamap_sync(t, p, o, l, ops) \
651 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
653 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
654 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
655 #define bus_dmamem_free(t, sg, n) \
656 (*(t)->_dmamem_free)((t), (sg), (n))
657 #define bus_dmamem_map(t, sg, n, s, k, f) \
658 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
659 #define bus_dmamem_unmap(t, k, s) \
660 (*(t)->_dmamem_unmap)((t), (k), (s))
661 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
662 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
664 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
665 #define bus_dmatag_destroy(t)
668 * bus_dmamap_t
670 * Describes a DMA mapping.
672 struct cobalt_bus_dmamap {
674 * PRIVATE MEMBERS: not for use my machine-independent code.
676 bus_size_t _dm_size; /* largest DMA transfer mappable */
677 int _dm_segcnt; /* number of segs this map can map */
678 bus_size_t _dm_maxmaxsegsz; /* fixed largest possible segment */
679 bus_size_t _dm_boundary; /* don't cross this */
680 int _dm_flags; /* misc. flags */
681 struct vmspace *_dm_vmspace; /* vmspace that owns this mapping */
684 * PUBLIC MEMBERS: these are used by machine-independent code.
686 bus_size_t dm_maxsegsz; /* largest possible segment */
687 bus_size_t dm_mapsize; /* size of the mapping */
688 int dm_nsegs; /* # valid segments in mapping */
689 bus_dma_segment_t dm_segs[1]; /* segments; variable length */
692 #ifdef _COBALT_BUS_DMA_PRIVATE
693 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
694 bus_size_t, int, bus_dmamap_t *);
695 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
696 int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
697 bus_size_t, struct proc *, int);
698 int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
699 struct mbuf *, int);
700 int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
701 struct uio *, int);
702 int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
703 bus_dma_segment_t *, int, bus_size_t, int);
704 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
705 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
706 bus_size_t, int);
708 int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
709 bus_size_t alignment, bus_size_t boundary,
710 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
711 void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
712 int nsegs);
713 int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
714 int nsegs, size_t size, void **kvap, int flags);
715 void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
716 size_t size);
717 paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
718 int nsegs, off_t off, int prot, int flags);
720 int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
721 bus_size_t alignment, bus_size_t boundary,
722 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
723 vaddr_t low, vaddr_t high);
725 extern struct cobalt_bus_dma_tag cobalt_default_bus_dma_tag;
726 #endif /* _COBALT_BUS_DMA_PRIVATE */
728 #endif /* _COBALT_BUS_H_ */