Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / arc / include / bus.h
blob743eb27a7ed5abc223217097042152152006bcc5
1 /* $NetBSD: bus.h,v 1.25 2007/03/04 05:59:35 christos Exp $ */
2 /* NetBSD: bus.h,v 1.27 2000/03/15 16:44:50 drochner Exp */
3 /* $OpenBSD: bus.h,v 1.15 1999/08/11 23:15:21 niklas Exp $ */
5 /*-
6 * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
7 * All rights reserved.
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
11 * NASA Ames Research Center.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
36 * Copyright (c) 1997 Per Fogelstrom. All rights reserved.
37 * Copyright (c) 1996 Niklas Hallqvist. All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by Christopher G. Demetriou
50 * for the NetBSD Project.
51 * 4. The name of the author may not be used to endorse or promote products
52 * derived from this software without specific prior written permission
54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
59 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
63 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 #ifndef _ARC_BUS_H_
67 #define _ARC_BUS_H_
68 #ifdef _KERNEL
70 #include <mips/locore.h>
72 #ifdef BUS_SPACE_DEBUG
73 #include <sys/systm.h> /* for printf() prototype */
75 * Macros for checking the aligned-ness of pointers passed to bus
76 * space ops. Strict alignment is required by the MIPS architecture,
77 * and a trap will occur if unaligned access is performed. These
78 * may aid in the debugging of a broken device driver by displaying
79 * useful information about the problem.
81 #define __BUS_SPACE_ALIGNED_ADDRESS(p, t) \
82 ((((u_long)(p)) & (sizeof(t)-1)) == 0)
84 #define __BUS_SPACE_ADDRESS_SANITY(p, t, d) \
85 ({ \
86 if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) { \
87 printf("%s 0x%lx not aligned to %d bytes %s:%d\n", \
88 d, (u_long)(p), sizeof(t), __FILE__, __LINE__); \
89 } \
90 (void) 0; \
93 #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
94 #else
95 #define __BUS_SPACE_ADDRESS_SANITY(p,t,d) (void) 0
96 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
97 #endif /* BUS_SPACE_DEBUG */
100 * Utility macro; do not use outside this file.
102 #ifdef __STDC__
103 #define __CONCAT3(a,b,c) a##b##c
104 #else
105 #define __CONCAT3(a,b,c) a/**/b/**/c
106 #endif
109 * Bus address and size types
111 typedef u_long bus_addr_t;
112 typedef u_long bus_size_t;
115 * Access methods for bus resources and address space.
117 typedef uint32_t bus_space_handle_t;
118 typedef struct arc_bus_space *bus_space_tag_t;
120 struct arc_bus_space {
121 const char *bs_name;
122 struct extent *bs_extent;
123 bus_addr_t bs_start;
124 bus_size_t bs_size;
126 paddr_t bs_pbase;
127 vaddr_t bs_vbase;
129 /* sparse addressing shift count */
130 uint8_t bs_stride_1;
131 uint8_t bs_stride_2;
132 uint8_t bs_stride_4;
133 uint8_t bs_stride_8;
135 /* compose a bus_space handle from tag/handle/addr/size/flags (MD) */
136 int (*bs_compose_handle)(bus_space_tag_t, bus_addr_t,
137 bus_size_t, int, bus_space_handle_t *);
139 /* dispose a bus_space handle (MD) */
140 int (*bs_dispose_handle)(bus_space_tag_t, bus_space_handle_t,
141 bus_size_t);
143 /* convert bus_space tag/handle to physical address (MD) */
144 int (*bs_paddr)(bus_space_tag_t, bus_space_handle_t,
145 paddr_t *);
147 /* mapping/unmapping */
148 int (*bs_map)(bus_space_tag_t, bus_addr_t, bus_size_t, int,
149 bus_space_handle_t *);
150 void (*bs_unmap)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
151 int (*bs_subregion)(bus_space_tag_t, bus_space_handle_t,
152 bus_size_t, bus_size_t, bus_space_handle_t *);
153 paddr_t (*bs_mmap)(bus_space_tag_t, bus_addr_t, off_t, int, int);
155 /* allocation/deallocation */
156 int (*bs_alloc)(bus_space_tag_t, bus_addr_t, bus_addr_t,
157 bus_size_t, bus_size_t, bus_size_t, int,
158 bus_addr_t *, bus_space_handle_t *);
159 void (*bs_free)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
161 void *bs_aux;
164 /* vaddr_t argument of arc_bus_space_init() */
165 #define ARC_BUS_SPACE_UNMAPPED ((vaddr_t)0)
167 /* machine dependent utility function for bus_space users */
168 void arc_bus_space_malloc_set_safe(void);
169 void arc_bus_space_init(bus_space_tag_t, const char *,
170 paddr_t, vaddr_t, bus_addr_t, bus_size_t);
171 void arc_bus_space_init_extent(bus_space_tag_t, void *, size_t);
172 void arc_bus_space_set_aligned_stride(bus_space_tag_t, unsigned int);
173 void arc_sparse_bus_space_init(bus_space_tag_t, const char *,
174 paddr_t, bus_addr_t, bus_size_t);
175 void arc_large_bus_space_init(bus_space_tag_t, const char *,
176 paddr_t, bus_addr_t, bus_size_t);
178 /* machine dependent utility function for bus_space implementations */
179 int arc_bus_space_extent_malloc_flag(void);
181 /* these are provided for subclasses which override base bus_space. */
183 int arc_bus_space_compose_handle(bus_space_tag_t,
184 bus_addr_t, bus_size_t, int, bus_space_handle_t *);
185 int arc_bus_space_dispose_handle(bus_space_tag_t,
186 bus_space_handle_t, bus_size_t);
187 int arc_bus_space_paddr(bus_space_tag_t,
188 bus_space_handle_t, paddr_t *);
190 int arc_sparse_bus_space_compose_handle(bus_space_tag_t,
191 bus_addr_t, bus_size_t, int, bus_space_handle_t *);
192 int arc_sparse_bus_space_dispose_handle(bus_space_tag_t,
193 bus_space_handle_t, bus_size_t);
194 int arc_sparse_bus_space_paddr(bus_space_tag_t,
195 bus_space_handle_t, paddr_t *);
197 int arc_bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t, int,
198 bus_space_handle_t *);
199 void arc_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,
200 bus_size_t);
201 int arc_bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
202 bus_size_t, bus_size_t, bus_space_handle_t *);
203 paddr_t arc_bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int);
204 int arc_bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t,
205 bus_size_t, bus_size_t, bus_size_t, int, bus_addr_t *,
206 bus_space_handle_t *);
207 #define arc_bus_space_free arc_bus_space_unmap
210 * int bus_space_compose_handle(bus_space_tag_t t, bus_addr_t addr,
211 * bus_size_t size, int flags, bus_space_handle_t *bshp);
213 * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
214 * Compose a bus_space handle from tag/handle/addr/size/flags.
215 * A helper function for bus_space_map()/bus_space_alloc() implementation.
217 #define bus_space_compose_handle(bst, addr, size, flags, bshp) \
218 (*(bst)->bs_compose_handle)(bst, addr, size, flags, bshp)
221 * int bus_space_dispose_handle(bus_space_tag_t t, bus_addr_t addr,
222 * bus_space_handle_t bsh, bus_size_t size);
224 * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
225 * Dispose a bus_space handle.
226 * A helper function for bus_space_unmap()/bus_space_free() implementation.
228 #define bus_space_dispose_handle(bst, bsh, size) \
229 (*(bst)->bs_dispose_handle)(bst, bsh, size)
232 * int bus_space_paddr(bus_space_tag_t tag,
233 * bus_space_handle_t bsh, paddr_t *pap);
235 * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
236 * (cannot be implemented on e.g. I/O space on i386, non-linear space on alpha)
237 * Return physical address of a region.
238 * A helper function for machine-dependent device mmap entry.
240 #define bus_space_paddr(bst, bsh, pap) \
241 (*(bst)->bs_paddr)(bst, bsh, pap)
244 * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
246 * Get the kernel virtual address for the mapped bus space.
247 * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
248 * (XXX not enforced)
250 #define bus_space_vaddr(bst, bsh) \
251 ((void *)(bsh))
254 * paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t,
255 * int, int);
257 * Mmap bus space on behalf of the user.
259 #define bus_space_mmap(bst, addr, off, prot, flags) \
260 (*(bst)->bs_mmap)((bst), (addr), (off), (prot), (flags))
263 * int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
264 * bus_size_t size, int flags, bus_space_handle_t *bshp);
266 * Map a region of bus space.
269 #define BUS_SPACE_MAP_CACHEABLE 0x01
270 #define BUS_SPACE_MAP_LINEAR 0x02
271 #define BUS_SPACE_MAP_PREFETCHABLE 0x04
273 #define bus_space_map(t, a, s, f, hp) \
274 (*(t)->bs_map)((t), (a), (s), (f), (hp))
277 * void bus_space_unmap(bus_space_tag_t t,
278 * bus_space_handle_t bsh, bus_size_t size);
280 * Unmap a region of bus space.
283 #define bus_space_unmap(t, h, s) \
284 (*(t)->bs_unmap)((t), (h), (s))
287 * int bus_space_subregion(bus_space_tag_t t,
288 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
289 * bus_space_handle_t *nbshp);
291 * Get a new handle for a subregion of an already-mapped area of bus space.
294 #define bus_space_subregion(t, h, o, s, hp) \
295 (*(t)->bs_subregion)((t), (h), (o), (s), (hp))
298 * int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
299 * bus_addr_t rend, bus_size_t size, bus_size_t align,
300 * bus_size_t boundary, int flags, bus_addr_t *addrp,
301 * bus_space_handle_t *bshp);
303 * Allocate a region of bus space.
306 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
307 (*(t)->bs_alloc)((t), (rs), (re), (s), (a), (b), (f), (ap), (hp))
310 * int bus_space_free(bus_space_tag_t t,
311 * bus_space_handle_t bsh, bus_size_t size);
313 * Free a region of bus space.
316 #define bus_space_free(t, h, s) \
317 (*(t)->bs_free)((t), (h), (s))
320 * uintN_t bus_space_read_N(bus_space_tag_t tag,
321 * bus_space_handle_t bsh, bus_size_t offset);
323 * Read a 1, 2, 4, or 8 byte quantity from bus space
324 * described by tag/handle/offset.
327 #define bus_space_read(BYTES,BITS) \
328 static __inline __CONCAT3(uint,BITS,_t) \
329 __CONCAT(bus_space_read_,BYTES)(bus_space_tag_t bst, \
330 bus_space_handle_t bsh, bus_size_t offset) \
332 return (*(volatile __CONCAT3(uint,BITS,_t) *) \
333 (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES)))); \
336 bus_space_read(1,8)
337 bus_space_read(2,16)
338 bus_space_read(4,32)
339 bus_space_read(8,64)
342 * void bus_space_read_multi_N(bus_space_tag_t tag,
343 * bus_space_handle_t bsh, bus_size_t offset,
344 * uintN_t *addr, size_t count);
346 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
347 * described by tag/handle/offset and copy into buffer provided.
350 #define bus_space_read_multi(BYTES,BITS) \
351 static __inline void \
352 __CONCAT(bus_space_read_multi_,BYTES)(bus_space_tag_t bst, \
353 bus_space_handle_t bsh, bus_size_t offset, \
354 __CONCAT3(uint,BITS,_t) *datap, bus_size_t count) \
356 volatile __CONCAT3(uint,BITS,_t) *p = \
357 (volatile __CONCAT3(uint,BITS,_t) *) \
358 (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))); \
360 for (; count > 0; --count) \
361 *datap++ = *p; \
364 bus_space_read_multi(1,8)
365 bus_space_read_multi(2,16)
366 bus_space_read_multi(4,32)
367 bus_space_read_multi(8,64)
370 * void bus_space_read_region_N(bus_space_tag_t tag,
371 * bus_space_handle_t bsh, bus_size_t offset,
372 * uintN_t *addr, size_t count);
374 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
375 * described by tag/handle and starting at `offset' and copy into
376 * buffer provided.
379 #define bus_space_read_region(BYTES,BITS) \
380 static __inline void \
381 __CONCAT(bus_space_read_region_,BYTES)(bus_space_tag_t bst, \
382 bus_space_handle_t bsh, bus_size_t offset, \
383 __CONCAT3(uint,BITS,_t) *datap, bus_size_t count) \
385 int stride = 1 << __CONCAT(bst->bs_stride_,BYTES); \
386 volatile __CONCAT3(uint,BITS,_t) *p = \
387 (volatile __CONCAT3(uint,BITS,_t) *) \
388 (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))); \
390 for (; count > 0; --count) { \
391 *datap++ = *p; \
392 p += stride; \
396 bus_space_read_region(1,8)
397 bus_space_read_region(2,16)
398 bus_space_read_region(4,32)
399 bus_space_read_region(8,64)
402 * void bus_space_write_N(bus_space_tag_t tag,
403 * bus_space_handle_t bsh, bus_size_t offset,
404 * uintN_t value);
406 * Write the 1, 2, 4, or 8 byte value `value' to bus space
407 * described by tag/handle/offset.
410 #define bus_space_write(BYTES,BITS) \
411 static __inline void \
412 __CONCAT(bus_space_write_,BYTES)(bus_space_tag_t bst, \
413 bus_space_handle_t bsh, \
414 bus_size_t offset, __CONCAT3(uint,BITS,_t) data) \
416 *(volatile __CONCAT3(uint,BITS,_t) *) \
417 (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))) = data; \
420 bus_space_write(1,8)
421 bus_space_write(2,16)
422 bus_space_write(4,32)
423 bus_space_write(8,64)
426 * void bus_space_write_multi_N(bus_space_tag_t tag,
427 * bus_space_handle_t bsh, bus_size_t offset,
428 * const uintN_t *addr, size_t count);
430 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
431 * provided to bus space described by tag/handle/offset.
434 #define bus_space_write_multi(BYTES,BITS) \
435 static __inline void \
436 __CONCAT(bus_space_write_multi_,BYTES)(bus_space_tag_t bst, \
437 bus_space_handle_t bsh, bus_size_t offset, \
438 const __CONCAT3(uint,BITS,_t) *datap, bus_size_t count) \
440 volatile __CONCAT3(uint,BITS,_t) *p = \
441 (volatile __CONCAT3(uint,BITS,_t) *) \
442 (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))); \
444 for (; count > 0; --count) \
445 *p = *datap++; \
448 bus_space_write_multi(1,8)
449 bus_space_write_multi(2,16)
450 bus_space_write_multi(4,32)
451 bus_space_write_multi(8,64)
454 * void bus_space_write_region_N(bus_space_tag_t tag,
455 * bus_space_handle_t bsh, bus_size_t offset,
456 * const uintN_t *addr, size_t count);
458 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
459 * to bus space described by tag/handle starting at `offset'.
462 #define bus_space_write_region(BYTES,BITS) \
463 static __inline void \
464 __CONCAT(bus_space_write_region_,BYTES)(bus_space_tag_t bst, \
465 bus_space_handle_t bsh, bus_size_t offset, \
466 const __CONCAT3(uint,BITS,_t) *datap, bus_size_t count) \
468 int stride = 1 << __CONCAT(bst->bs_stride_,BYTES); \
469 volatile __CONCAT3(uint,BITS,_t) *p = \
470 (volatile __CONCAT3(uint,BITS,_t) *) \
471 (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))); \
473 for (; count > 0; --count) { \
474 *p = *datap++; \
475 p += stride; \
479 bus_space_write_region(1,8)
480 bus_space_write_region(2,16)
481 bus_space_write_region(4,32)
482 bus_space_write_region(8,64)
485 * void bus_space_set_multi_N(bus_space_tag_t tag,
486 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
487 * size_t count);
489 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
490 * by tag/handle/offset `count' times.
493 #define bus_space_set_multi(BYTES,BITS) \
494 static __inline void \
495 __CONCAT(bus_space_set_multi_,BYTES)(bus_space_tag_t bst, \
496 bus_space_handle_t bsh, bus_size_t offset, \
497 const __CONCAT3(uint,BITS,_t) data, bus_size_t count) \
499 volatile __CONCAT3(uint,BITS,_t) *p = \
500 (volatile __CONCAT3(uint,BITS,_t) *) \
501 (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))); \
503 for (; count > 0; --count) \
504 *p = data; \
507 bus_space_set_multi(1,8)
508 bus_space_set_multi(2,16)
509 bus_space_set_multi(4,32)
510 bus_space_set_multi(8,64)
513 * void bus_space_set_region_N(bus_space_tag_t tag,
514 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
515 * size_t count);
517 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
518 * by tag/handle starting at `offset'.
521 #define bus_space_set_region(BYTES,BITS) \
522 static __inline void \
523 __CONCAT(bus_space_set_region_,BYTES)(bus_space_tag_t bst, \
524 bus_space_handle_t bsh, bus_size_t offset, \
525 __CONCAT3(uint,BITS,_t) data, bus_size_t count) \
527 int stride = 1 << __CONCAT(bst->bs_stride_,BYTES); \
528 volatile __CONCAT3(uint,BITS,_t) *p = \
529 (volatile __CONCAT3(uint,BITS,_t) *) \
530 (bsh + (offset << __CONCAT(bst->bs_stride_,BYTES))); \
532 for (; count > 0; --count) { \
533 *p = data; \
534 p += stride; \
538 bus_space_set_region(1,8)
539 bus_space_set_region(2,16)
540 bus_space_set_region(4,32)
541 bus_space_set_region(8,64)
544 * void bus_space_copy_region_N(bus_space_tag_t tag,
545 * bus_space_handle_t bsh1, bus_size_t off1,
546 * bus_space_handle_t bsh2, bus_size_t off2,
547 * size_t count);
549 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
550 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
553 #define bus_space_copy_region(BYTES,BITS) \
554 static __inline void \
555 __CONCAT(bus_space_copy_region_,BYTES)(bus_space_tag_t bst, \
556 bus_space_handle_t srcbsh, bus_size_t srcoffset, \
557 bus_space_handle_t dstbsh, bus_size_t dstoffset, bus_size_t count) \
559 int stride = 1 << __CONCAT(bst->bs_stride_,BYTES); \
560 volatile __CONCAT3(uint,BITS,_t) *srcp = \
561 (volatile __CONCAT3(uint,BITS,_t) *) \
562 (srcbsh + (srcoffset << __CONCAT(bst->bs_stride_,BYTES))); \
563 volatile __CONCAT3(uint,BITS,_t) *dstp = \
564 (volatile __CONCAT3(uint,BITS,_t) *) \
565 (dstbsh + (dstoffset << __CONCAT(bst->bs_stride_,BYTES))); \
566 bus_size_t offset; \
568 if (srcp >= dstp) { \
569 /* src after dest: copy forward */ \
570 for (offset = 0; count > 0; --count, offset += stride) \
571 dstp[offset] = srcp[offset]; \
572 } else { \
573 /* dest after src: copy backward */ \
574 offset = (count << __CONCAT(bst->bs_stride_,BYTES)) \
575 - stride; \
576 for (; count > 0; --count, offset -= stride) \
577 dstp[offset] = srcp[offset]; \
581 bus_space_copy_region(1,8)
582 bus_space_copy_region(2,16)
583 bus_space_copy_region(4,32)
584 bus_space_copy_region(8,64)
587 * Operations which handle byte stream data on word access.
589 * These functions are defined to resolve endian mismatch, by either
590 * - When normal (i.e. stream-less) operations perform byte swap
591 * to resolve endian mismatch, these functions bypass the byte swap.
592 * or
593 * - When bus bridge performs automatic byte swap, these functions
594 * perform byte swap once more, to cancel the bridge's behavior.
596 * Currently these are just same as normal operations, since all
597 * supported buses are same endian with CPU (i.e. little-endian).
600 #define __BUS_SPACE_HAS_STREAM_METHODS
601 #define bus_space_read_stream_2(tag, bsh, offset) \
602 bus_space_read_2(tag, bsh, offset)
603 #define bus_space_read_stream_4(tag, bsh, offset) \
604 bus_space_read_4(tag, bsh, offset)
605 #define bus_space_read_stream_8(tag, bsh, offset) \
606 bus_space_read_8(tag, bsh, offset)
607 #define bus_space_read_multi_stream_2(tag, bsh, offset, datap, count) \
608 bus_space_read_multi_2(tag, bsh, offset, datap, count)
609 #define bus_space_read_multi_stream_4(tag, bsh, offset, datap, count) \
610 bus_space_read_multi_4(tag, bsh, offset, datap, count)
611 #define bus_space_read_multi_stream_8(tag, bsh, offset, datap, count) \
612 bus_space_read_multi_8(tag, bsh, offset, datap, count)
613 #define bus_space_read_region_stream_2(tag, bsh, offset, datap, count) \
614 bus_space_read_region_2(tag, bsh, offset, datap, count)
615 #define bus_space_read_region_stream_4(tag, bsh, offset, datap, count) \
616 bus_space_read_region_4(tag, bsh, offset, datap, count)
617 #define bus_space_read_region_stream_8(tag, bsh, offset, datap, count) \
618 bus_space_read_region_8(tag, bsh, offset, datap, count)
619 #define bus_space_write_stream_2(tag, bsh, offset, data) \
620 bus_space_write_2(tag, bsh, offset, data)
621 #define bus_space_write_stream_4(tag, bsh, offset, data) \
622 bus_space_write_4(tag, bsh, offset, data)
623 #define bus_space_write_stream_8(tag, bsh, offset, data) \
624 bus_space_write_8(tag, bsh, offset, data)
625 #define bus_space_write_multi_stream_2(tag, bsh, offset, datap, count) \
626 bus_space_write_multi_2(tag, bsh, offset, datap, count)
627 #define bus_space_write_multi_stream_4(tag, bsh, offset, datap, count) \
628 bus_space_write_multi_4(tag, bsh, offset, datap, count)
629 #define bus_space_write_multi_stream_8(tag, bsh, offset, datap, count) \
630 bus_space_write_multi_8(tag, bsh, offset, datap, count)
631 #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count) \
632 bus_space_write_region_2(tag, bsh, offset, datap, count)
633 #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count) \
634 bus_space_write_region_4(tag, bsh, offset, datap, count)
635 #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count) \
636 bus_space_write_region_8(tag, bsh, offset, datap, count)
637 #define bus_space_write_region_stream_2(tag, bsh, offset, datap, count) \
638 bus_space_write_region_2(tag, bsh, offset, datap, count)
639 #define bus_space_write_region_stream_4(tag, bsh, offset, datap, count) \
640 bus_space_write_region_4(tag, bsh, offset, datap, count)
641 #define bus_space_write_region_stream_8(tag, bsh, offset, datap, count) \
642 bus_space_write_region_8(tag, bsh, offset, datap, count)
643 #define bus_space_set_multi_stream_2(tag, bsh, offset, data, count) \
644 bus_space_set_multi_2(tag, bsh, offset, data, count)
645 #define bus_space_set_multi_stream_4(tag, bsh, offset, data, count) \
646 bus_space_set_multi_4(tag, bsh, offset, data, count)
647 #define bus_space_set_multi_stream_8(tag, bsh, offset, data, count) \
648 bus_space_set_multi_8(tag, bsh, offset, data, count)
649 #define bus_space_set_region_stream_2(tag, bsh, offset, data, count) \
650 bus_space_set_region_2(tag, bsh, offset, data, count)
651 #define bus_space_set_region_stream_4(tag, bsh, offset, data, count) \
652 bus_space_set_region_4(tag, bsh, offset, data, count)
653 #define bus_space_set_region_stream_8(tag, bsh, offset, data, count) \
654 bus_space_set_region_8(tag, bsh, offset, data, count)
657 * Bus read/write barrier methods.
659 * void bus_space_barrier(bus_space_tag_t tag,
660 * bus_space_handle_t bsh, bus_size_t offset,
661 * bus_size_t len, int flags);
663 * On the MIPS, we just flush the write buffer.
665 #define bus_space_barrier(t, h, o, l, f) \
666 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f), \
667 wbflush()))
669 #define BUS_SPACE_BARRIER_READ 0x01
670 #define BUS_SPACE_BARRIER_WRITE 0x02
673 * Flags used in various bus DMA methods.
675 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
676 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
677 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
678 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
679 #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
680 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
681 #define BUS_DMA_BUS2 0x020
682 #define BUS_DMA_BUS3 0x040
683 #define BUS_DMA_BUS4 0x080
684 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
685 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
686 #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
688 #define ARC_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */
690 /* Forwards needed by prototypes below. */
691 struct mbuf;
692 struct uio;
695 * Operations performed by bus_dmamap_sync().
697 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
698 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
699 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
700 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
702 typedef struct arc_bus_dma_tag *bus_dma_tag_t;
703 typedef struct arc_bus_dmamap *bus_dmamap_t;
705 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
708 * bus_dma_segment_t
710 * Describes a single contiguous DMA transaction. Values
711 * are suitable for programming into DMA registers.
713 struct arc_bus_dma_segment {
715 * PUBLIC MEMBERS: these are used by device drivers.
717 bus_addr_t ds_addr; /* DMA address */
718 bus_size_t ds_len; /* length of transfer */
720 * PRIVATE MEMBERS for the DMA back-end.: not for use by drivers.
722 vaddr_t _ds_paddr; /* CPU physical address */
723 vaddr_t _ds_vaddr; /* virtual address, 0 if invalid */
725 typedef struct arc_bus_dma_segment bus_dma_segment_t;
728 * bus_dma_tag_t
730 * A machine-dependent opaque type describing the implementation of
731 * DMA for a given bus.
734 struct arc_bus_dma_tag {
735 bus_addr_t dma_offset;
738 * DMA mapping methods.
740 int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
741 bus_size_t, bus_size_t, int, bus_dmamap_t *);
742 void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
743 int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
744 bus_size_t, struct proc *, int);
745 int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
746 struct mbuf *, int);
747 int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
748 struct uio *, int);
749 int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
750 bus_dma_segment_t *, int, bus_size_t, int);
751 void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
752 void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
753 bus_addr_t, bus_size_t, int);
756 * DMA memory utility functions.
758 int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
759 bus_size_t, bus_dma_segment_t *, int, int *, int);
760 void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int);
761 int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
762 int, size_t, void **, int);
763 void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
764 paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
765 int, off_t, int, int);
768 #define bus_dmamap_create(t, s, n, m, b, f, p) \
769 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
770 #define bus_dmamap_destroy(t, p) \
771 (*(t)->_dmamap_destroy)((t), (p))
772 #define bus_dmamap_load(t, m, b, s, p, f) \
773 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
774 #define bus_dmamap_load_mbuf(t, m, b, f) \
775 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
776 #define bus_dmamap_load_uio(t, m, u, f) \
777 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
778 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
779 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
780 #define bus_dmamap_unload(t, p) \
781 (*(t)->_dmamap_unload)((t), (p))
782 #define bus_dmamap_sync(t, p, o, l, ops) \
783 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
784 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
785 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
786 #define bus_dmamem_free(t, sg, n) \
787 (*(t)->_dmamem_free)((t), (sg), (n))
788 #define bus_dmamem_map(t, sg, n, s, k, f) \
789 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
790 #define bus_dmamem_unmap(t, k, s) \
791 (*(t)->_dmamem_unmap)((t), (k), (s))
792 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
793 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
795 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
796 #define bus_dmatag_destroy(t)
799 * bus_dmamap_t
801 * Describes a DMA mapping.
803 struct arc_bus_dmamap {
805 * PRIVATE MEMBERS: not for use by machine-independent code.
807 bus_size_t _dm_size; /* largest DMA transfer mappable */
808 int _dm_segcnt; /* number of segs this map can map */
809 bus_size_t _dm_maxmaxsegsz; /* fixed largest possible segment */
810 bus_size_t _dm_boundary; /* don't cross this */
811 int _dm_flags; /* misc. flags */
812 struct vmspace *_dm_vmspace; /* vmspace that owns the mapping */
815 * Private cookie to be used by the DMA back-end.
817 void *_dm_cookie;
820 * PUBLIC MEMBERS: these are used by machine-independent code.
822 bus_size_t dm_maxsegsz; /* largest possible segment */
823 bus_size_t dm_mapsize; /* size of the mapping */
824 int dm_nsegs; /* # valid segments in mapping */
825 bus_dma_segment_t dm_segs[1]; /* segments; variable length */
828 #ifdef _ARC_BUS_DMA_PRIVATE
829 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
830 bus_size_t, int, bus_dmamap_t *);
831 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
832 int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
833 bus_size_t, struct proc *, int);
834 int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
835 struct mbuf *, int);
836 int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
837 struct uio *, int);
838 int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
839 bus_dma_segment_t *, int, bus_size_t, int);
840 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
841 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
842 bus_size_t, int);
844 int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
845 bus_size_t alignment, bus_size_t boundary,
846 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
847 int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
848 bus_size_t alignment, bus_size_t boundary,
849 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
850 paddr_t low, paddr_t high);
851 void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
852 int nsegs);
853 int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
854 int nsegs, size_t size, void **kvap, int flags);
855 void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
856 size_t size);
857 paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
858 int nsegs, off_t off, int prot, int flags);
860 int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
861 bus_size_t alignment, bus_size_t boundary,
862 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
863 paddr_t low, paddr_t high);
864 #endif /* _ARC_BUS_DMA_PRIVATE */
866 void _bus_dma_tag_init(bus_dma_tag_t tag);
867 void jazz_bus_dma_tag_init(bus_dma_tag_t tag);
868 void isadma_bounce_tag_init(bus_dma_tag_t tag);
870 #endif /* _KERNEL */
871 #endif /* _ARC_BUS_H_ */