1 /* $NetBSD: bus.h,v 1.19 2008/04/28 20:23:28 martin Exp $ */
4 * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
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
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) 1997 Per Fogelstrom. All rights reserved.
35 * Copyright (c) 1996 Niklas Hallqvist. All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
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 _MIPSCO_BUS_H_
65 #define _MIPSCO_BUS_H_
68 #include <mips/locore.h>
70 #ifdef BUS_SPACE_DEBUG
71 #include <sys/systm.h> /* for printf() prototype */
73 * Macros for checking the aligned-ness of pointers passed to bus
74 * space ops. Strict alignment is required by the MIPS architecture,
75 * and a trap will occur if unaligned access is performed. These
76 * may aid in the debugging of a broken device driver by displaying
77 * useful information about the problem.
79 #define __BUS_SPACE_ALIGNED_ADDRESS(p, t) \
80 ((((u_long)(p)) & (sizeof(t)-1)) == 0)
82 #define __BUS_SPACE_ADDRESS_SANITY(p, t, d) \
84 if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) { \
85 printf("%s 0x%lx not aligned to %d bytes %s:%d\n", \
86 d, (u_long)(p), sizeof(t), __FILE__, __LINE__); \
91 #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
93 #define __BUS_SPACE_ADDRESS_SANITY(p,t,d) (void) 0
94 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
95 #endif /* BUS_SPACE_DEBUG */
98 * Utility macro; do not use outside this file.
101 #define __CONCAT3(a,b,c) a##b##c
103 #define __CONCAT3(a,b,c) a/**/b/**/c
107 * Bus address and size types
109 typedef u_long bus_addr_t
;
110 typedef u_long bus_size_t
;
113 * Access methods for bus resources and address space.
115 typedef u_int32_t bus_space_handle_t
;
116 typedef struct mipsco_bus_space
*bus_space_tag_t
;
118 struct mipsco_bus_space
{
120 struct extent
*bs_extent
;
127 u_int8_t bs_stride
; /* log2(stride) */
128 u_int8_t bs_bswap
; /* byte swap in stream methods */
130 u_int8_t bs_offset_1
;
131 u_int8_t bs_offset_2
;
132 u_int8_t bs_offset_4
;
133 u_int8_t bs_offset_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
,
143 /* convert bus_space tag/handle to physical address (MD) */
144 int (*bs_paddr
)(bus_space_tag_t
, bus_space_handle_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
,
152 int (*bs_subregion
)(bus_space_tag_t
, bus_space_handle_t
,
153 bus_size_t
, bus_size_t
, bus_space_handle_t
*);
154 paddr_t (*bs_mmap
)(bus_space_tag_t
, bus_addr_t
, off_t
, int, int);
157 /* allocation/deallocation */
158 int (*bs_alloc
)(bus_space_tag_t
, bus_addr_t
, bus_addr_t
,
159 bus_size_t
, bus_size_t
, bus_size_t
, int,
160 bus_addr_t
*, bus_space_handle_t
*);
161 void (*bs_free
)(bus_space_tag_t
, bus_space_handle_t
,
164 /* interrupt attach */
165 void (*bs_intr_establish
)(
167 int, /*bus-specific intr*/
168 int, /*priority/class*/
170 int (*)(void *), /*handler*/
171 void *); /*handler arg*/
176 /* vaddr_t argument of mipsco_bus_space_init() */
177 #define MIPSCO_BUS_SPACE_UNMAPPED ((vaddr_t)0)
179 /* machine dependent utility function for bus_space users */
180 void mipsco_bus_space_malloc_set_safe(void);
181 void mipsco_bus_space_init(bus_space_tag_t
, const char *,
182 paddr_t
, vaddr_t
, bus_addr_t
, bus_size_t
);
183 void mipsco_bus_space_init_extent(bus_space_tag_t
, void *, size_t);
184 void mipsco_bus_space_set_aligned_stride(bus_space_tag_t
, unsigned int);
185 void mipsco_sparse_bus_space_init(bus_space_tag_t
, const char *,
186 paddr_t
, bus_addr_t
, bus_size_t
);
187 void mipsco_large_bus_space_init(bus_space_tag_t
, const char *,
188 paddr_t
, bus_addr_t
, bus_size_t
);
190 /* machine dependent utility function for bus_space implementations */
191 int mipsco_bus_space_extent_malloc_flag(void);
193 /* these are provided for subclasses which override base bus_space. */
195 int mipsco_bus_space_compose_handle(bus_space_tag_t
,
196 bus_addr_t
, bus_size_t
, int, bus_space_handle_t
*);
197 int mipsco_bus_space_dispose_handle(bus_space_tag_t
,
198 bus_space_handle_t
, bus_size_t
);
199 int mipsco_bus_space_paddr(bus_space_tag_t
,
200 bus_space_handle_t
, paddr_t
*);
202 int mipsco_sparse_bus_space_compose_handle(bus_space_tag_t
,
203 bus_addr_t
, bus_size_t
, int, bus_space_handle_t
*);
204 int mipsco_sparse_bus_space_dispose_handle(bus_space_tag_t
,
205 bus_space_handle_t
, bus_size_t
);
206 int mipsco_sparse_bus_space_paddr(bus_space_tag_t
,
207 bus_space_handle_t
, paddr_t
*);
209 int mipsco_bus_space_map(bus_space_tag_t
, bus_addr_t
, bus_size_t
, int,
210 bus_space_handle_t
*);
211 void mipsco_bus_space_unmap(bus_space_tag_t
, bus_space_handle_t
,
213 int mipsco_bus_space_subregion(bus_space_tag_t
, bus_space_handle_t
,
214 bus_size_t
, bus_size_t
, bus_space_handle_t
*);
215 paddr_t
mipsco_bus_space_mmap(bus_space_tag_t
, bus_addr_t
, off_t
,
217 int mipsco_bus_space_alloc(bus_space_tag_t
, bus_addr_t
, bus_addr_t
,
218 bus_size_t
, bus_size_t
, bus_size_t
, int, bus_addr_t
*,
219 bus_space_handle_t
*);
220 #define mipsco_bus_space_free mipsco_bus_space_unmap
223 * int bus_space_compose_handle(bus_space_tag_t t, bus_addr_t addr,
224 * bus_size_t size, int flags, bus_space_handle_t *bshp);
226 * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
227 * Compose a bus_space handle from tag/handle/addr/size/flags.
228 * A helper function for bus_space_map()/bus_space_alloc() implementation.
230 #define bus_space_compose_handle(bst, addr, size, flags, bshp) \
231 (*(bst)->bs_compose_handle)(bst, addr, size, flags, bshp)
234 * int bus_space_dispose_handle(bus_space_tag_t t, bus_addr_t addr,
235 * bus_space_handle_t bsh, bus_size_t size);
237 * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
238 * Dispose a bus_space handle.
239 * A helper function for bus_space_unmap()/bus_space_free() implementation.
241 #define bus_space_dispose_handle(bst, bsh, size) \
242 (*(bst)->bs_dispose_handle)(bst, bsh, size)
245 * int bus_space_paddr(bus_space_tag_t tag,
246 * bus_space_handle_t bsh, paddr_t *pap);
248 * MACHINE DEPENDENT, NOT PORTABLE INTERFACE:
249 * (cannot be implemented on e.g. I/O space on i386, non-linear space on alpha)
250 * Return physical address of a region.
251 * A helper function for device mmap entry.
253 #define bus_space_paddr(bst, bsh, pap) \
254 (*(bst)->bs_paddr)(bst, bsh, pap)
257 * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
259 * Get the kernel virtual address for the mapped bus space.
260 * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
263 #define bus_space_vaddr(bst, bsh) \
267 * paddr_t bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t,
270 * Mmap bus space on behalf of the user.
272 #define bus_space_mmap(bst, addr, off, prot, flags) \
273 (*(bst)->bs_mmap)((bst), (addr), (off), (prot), (flags))
276 * int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
277 * bus_size_t size, int flags, bus_space_handle_t *bshp);
279 * Map a region of bus space.
282 #define BUS_SPACE_MAP_CACHEABLE 0x01
283 #define BUS_SPACE_MAP_LINEAR 0x02
284 #define BUS_SPACE_MAP_PREFETCHABLE 0x04
286 #define bus_space_map(t, a, s, f, hp) \
287 (*(t)->bs_map)((t), (a), (s), (f), (hp))
290 * void bus_space_unmap(bus_space_tag_t t,
291 * bus_space_handle_t bsh, bus_size_t size);
293 * Unmap a region of bus space.
296 #define bus_space_unmap(t, h, s) \
297 (*(t)->bs_unmap)((t), (h), (s))
300 * int bus_space_subregion(bus_space_tag_t t,
301 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
302 * bus_space_handle_t *nbshp);
304 * Get a new handle for a subregion of an already-mapped area of bus space.
307 #define bus_space_subregion(t, h, o, s, hp) \
308 (*(t)->bs_subregion)((t), (h), (o), (s), (hp))
311 * int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
312 * bus_addr_t rend, bus_size_t size, bus_size_t align,
313 * bus_size_t boundary, int flags, bus_addr_t *addrp,
314 * bus_space_handle_t *bshp);
316 * Allocate a region of bus space.
319 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
320 (*(t)->bs_alloc)((t), (rs), (re), (s), (a), (b), (f), (ap), (hp))
323 * int bus_space_free(bus_space_tag_t t,
324 * bus_space_handle_t bsh, bus_size_t size);
326 * Free a region of bus space.
329 #define bus_space_free(t, h, s) \
330 (*(t)->bs_free)((t), (h), (s))
333 * void bus_intr_establish(bus_space_tag_t bst,
334 * int level, int pri, int flags, int (*func)(void *)
337 * Attach interrupt handler and softc argument
340 #define bus_intr_establish(t, i, c, f, ihf, iha) \
341 (*(t)->bs_intr_establish)((t), (i), (c), (f), (ihf), (iha))
345 * Utility macros; do not use outside this file.
347 #define __BS_TYPENAME(BITS) __CONCAT3(u_int,BITS,_t)
348 #define __BS_OFFSET(t, o, BYTES) ((o) << (t)->bs_stride)
349 #define __BS_FUNCTION(func,BYTES) __CONCAT3(func,_,BYTES)
352 * Calculate the target address using the bus_space parameters
354 #define __BS_ADDR(t, h, offset, BITS, BYTES) \
355 ((volatile __CONCAT3(u_int,BITS,_t) *) \
356 ((h) + __BS_OFFSET(t, offset, BYTES) + \
357 (t)->__CONCAT(bs_offset_,BYTES)))
360 * u_intN_t bus_space_read_N(bus_space_tag_t tag,
361 * bus_space_handle_t bsh, bus_size_t offset);
363 * Read a 1, 2, 4, or 8 byte quantity from bus space
364 * described by tag/handle/offset.
367 #define __bus_space_read(BYTES,BITS) \
368 static __inline __CONCAT3(u_int,BITS,_t) \
369 __CONCAT(bus_space_read_,BYTES)(bus_space_tag_t bst, \
370 bus_space_handle_t bsh, bus_size_t offset) \
372 return (*__BS_ADDR(bst, bsh, offset, BITS, BYTES)); \
375 __bus_space_read(1,8)
376 __bus_space_read(2,16)
377 __bus_space_read(4,32)
378 __bus_space_read(8,64)
381 * void bus_space_read_multi_N(bus_space_tag_t tag,
382 * bus_space_handle_t bsh, bus_size_t offset,
383 * u_intN_t *addr, size_t count);
385 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
386 * described by tag/handle/offset and copy into buffer provided.
389 #define __bus_space_read_multi(BYTES,BITS) \
390 static __inline void __BS_FUNCTION(bus_space_read_multi,BYTES) \
391 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
392 __BS_TYPENAME(BITS) *, size_t); \
394 static __inline void \
395 __BS_FUNCTION(bus_space_read_multi,BYTES)(t, h, o, a, c) \
397 bus_space_handle_t h; \
399 __BS_TYPENAME(BITS) *a; \
404 *a++ = __BS_FUNCTION(bus_space_read,BYTES)(t, h, o); \
407 __bus_space_read_multi(1,8)
408 __bus_space_read_multi(2,16)
409 __bus_space_read_multi(4,32)
410 __bus_space_read_multi(8,64)
414 * void bus_space_read_region_N(bus_space_tag_t tag,
415 * bus_space_handle_t bsh, bus_size_t offset,
416 * u_intN_t *addr, size_t count);
418 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
419 * described by tag/handle and starting at `offset' and copy into
423 #define __bus_space_read_region(BYTES,BITS) \
424 static __inline void __BS_FUNCTION(bus_space_read_region,BYTES) \
425 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
426 __BS_TYPENAME(BITS) *, size_t); \
428 static __inline void \
429 __BS_FUNCTION(bus_space_read_region,BYTES)(t, h, o, a, c) \
431 bus_space_handle_t h; \
433 __BS_TYPENAME(BITS) *a; \
438 *a++ = __BS_FUNCTION(bus_space_read,BYTES)(t, h, o); \
443 __bus_space_read_region(1,8)
444 __bus_space_read_region(2,16)
445 __bus_space_read_region(4,32)
446 __bus_space_read_region(8,64)
450 * void bus_space_write_N(bus_space_tag_t tag,
451 * bus_space_handle_t bsh, bus_size_t offset,
454 * Write the 1, 2, 4, or 8 byte value `value' to bus space
455 * described by tag/handle/offset.
458 #define __bus_space_write(BYTES,BITS) \
459 static __inline void \
460 __CONCAT(bus_space_write_,BYTES)(bus_space_tag_t bst, \
461 bus_space_handle_t bsh, \
462 bus_size_t offset, __CONCAT3(u_int,BITS,_t) data) \
464 *__BS_ADDR(bst, bsh, offset, BITS, BYTES) = data; \
468 __bus_space_write(1,8)
469 __bus_space_write(2,16)
470 __bus_space_write(4,32)
471 __bus_space_write(8,64)
474 * void bus_space_write_multi_N(bus_space_tag_t tag,
475 * bus_space_handle_t bsh, bus_size_t offset,
476 * const u_intN_t *addr, size_t count);
478 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
479 * provided to bus space described by tag/handle/offset.
482 #define __bus_space_write_multi(BYTES,BITS) \
483 static __inline void __BS_FUNCTION(bus_space_write_multi,BYTES) \
484 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
485 __BS_TYPENAME(BITS) *, size_t); \
487 static __inline void \
488 __BS_FUNCTION(bus_space_write_multi,BYTES)(t, h, o, a, c) \
490 bus_space_handle_t h; \
492 __BS_TYPENAME(BITS) *a; \
497 __BS_FUNCTION(bus_space_write,BYTES)(t, h, o, *a++); \
500 __bus_space_write_multi(1,8)
501 __bus_space_write_multi(2,16)
502 __bus_space_write_multi(4,32)
503 __bus_space_write_multi(8,64)
507 * void bus_space_write_region_N(bus_space_tag_t tag,
508 * bus_space_handle_t bsh, bus_size_t offset,
509 * const u_intN_t *addr, size_t count);
511 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
512 * to bus space described by tag/handle starting at `offset'.
515 #define __bus_space_write_region(BYTES,BITS) \
516 static __inline void __BS_FUNCTION(bus_space_write_region,BYTES) \
517 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
518 const __BS_TYPENAME(BITS) *, size_t); \
520 static __inline void \
521 __BS_FUNCTION(bus_space_write_region,BYTES)(t, h, o, a, c) \
523 bus_space_handle_t h; \
525 const __BS_TYPENAME(BITS) *a; \
530 __BS_FUNCTION(bus_space_write,BYTES)(t, h, o, *a++); \
535 __bus_space_write_region(1,8)
536 __bus_space_write_region(2,16)
537 __bus_space_write_region(4,32)
538 __bus_space_write_region(8,64)
542 * void bus_space_set_multi_N(bus_space_tag_t tag,
543 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
546 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
547 * by tag/handle/offset `count' times.
550 #define __bus_space_set_multi(BYTES,BITS) \
551 static __inline void __BS_FUNCTION(bus_space_set_multi,BYTES) \
552 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
553 __BS_TYPENAME(BITS), size_t); \
555 static __inline void \
556 __BS_FUNCTION(bus_space_set_multi,BYTES)(t, h, o, v, c) \
558 bus_space_handle_t h; \
560 __BS_TYPENAME(BITS) v; \
565 __BS_FUNCTION(bus_space_write,BYTES)(t, h, o, v); \
568 __bus_space_set_multi(1,8)
569 __bus_space_set_multi(2,16)
570 __bus_space_set_multi(4,32)
571 __bus_space_set_multi(8,64)
575 * void bus_space_set_region_N(bus_space_tag_t tag,
576 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
579 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
580 * by tag/handle starting at `offset'.
583 #define __bus_space_set_region(BYTES,BITS) \
584 static __inline void __BS_FUNCTION(bus_space_set_region,BYTES) \
585 (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
586 __BS_TYPENAME(BITS), size_t); \
588 static __inline void \
589 __BS_FUNCTION(bus_space_set_region,BYTES)(t, h, o, v, c) \
591 bus_space_handle_t h; \
593 __BS_TYPENAME(BITS) v; \
598 __BS_FUNCTION(bus_space_write,BYTES)(t, h, o, v); \
603 __bus_space_set_region(1,8)
604 __bus_space_set_region(2,16)
605 __bus_space_set_region(4,32)
606 __bus_space_set_region(8,64)
610 * void bus_space_copy_region_N(bus_space_tag_t tag,
611 * bus_space_handle_t bsh1, bus_size_t off1,
612 * bus_space_handle_t bsh2, bus_size_t off2,
615 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
616 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
619 #define __bus_space_copy_region(BYTES) \
620 static __inline void __BS_FUNCTION(bus_space_copy_region,BYTES) \
622 bus_space_handle_t bsh1, bus_size_t off1, \
623 bus_space_handle_t bsh2, bus_size_t off2, \
626 static __inline void \
627 __BS_FUNCTION(bus_space_copy_region,BYTES)(t, h1, o1, h2, o2, c) \
629 bus_space_handle_t h1, h2; \
630 bus_size_t o1, o2, c; \
634 if ((h1 + o1) >= (h2 + o2)) { \
635 /* src after dest: copy forward */ \
636 for (o = 0; c != 0; c--, o += BYTES) \
637 __BS_FUNCTION(bus_space_write,BYTES)(t, h2, o2 + o, \
638 __BS_FUNCTION(bus_space_read,BYTES)(t, h1, o1 + o)); \
640 /* dest after src: copy backwards */ \
641 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
642 __BS_FUNCTION(bus_space_write,BYTES)(t, h2, o2 + o, \
643 __BS_FUNCTION(bus_space_read,BYTES)(t, h1, o1 + o)); \
647 __bus_space_copy_region(1)
648 __bus_space_copy_region(2)
649 __bus_space_copy_region(4)
650 __bus_space_copy_region(8)
654 * Operations which handle byte stream data on word access.
656 * These functions are defined to resolve endian mismatch, by either
657 * - When normal (i.e. stream-less) operations perform byte swap
658 * to resolve endian mismatch, these functions bypass the byte swap.
660 * - When bus bridge performs automatic byte swap, these functions
661 * perform byte swap once more, to cancel the bridge's behavior.
663 * Mips Computer Systems platforms perform harware byte swapping -
664 * therefore the streaming methods can byte swap as determined from
665 * the bus space tag settings
668 #define __BUS_SPACE_HAS_STREAM_METHODS
670 /* Force creation of stream methods using the standard template macros */
672 #define __BS_FUNCTION(func,BYTES) __CONCAT3(func,_stream_,BYTES)
674 #define __BS_BSWAP(bst, val, BITS) \
675 ((bst->bs_bswap) ? __CONCAT(bswap,BITS)(val) : (val))
678 #define __bus_space_read_stream(BYTES,BITS) \
679 static __inline __BS_TYPENAME(BITS) \
680 __CONCAT(bus_space_read_stream_,BYTES)(bus_space_tag_t bst, \
681 bus_space_handle_t bsh, bus_size_t offset) \
683 register __BS_TYPENAME(BITS) val = \
684 __CONCAT(bus_space_read_,BYTES)(bst, bsh, offset); \
686 return __BS_BSWAP(bst, val, BITS); \
689 __bus_space_read_stream(2, 16) /* bus_space_read_stream_2 */
690 __bus_space_read_stream(4, 32) /* bus_space_read_stream_4 */
691 __bus_space_read_stream(8, 64) /* bus_space_read_stream_8 */
694 #define __bus_space_write_stream(BYTES,BITS) \
695 static __inline void \
696 __CONCAT(bus_space_write_stream_,BYTES)(bus_space_tag_t bst, \
697 bus_space_handle_t bsh, \
698 bus_size_t offset, __CONCAT3(u_int,BITS,_t) data) \
700 *__BS_ADDR(bst, bsh, offset, BITS, BYTES) = \
701 __BS_BSWAP(bst, data, BITS); \
705 __bus_space_write_stream(2,16) /* bus_space_write_stream_2 */
706 __bus_space_write_stream(4,32) /* bus_space_write_stream_4 */
707 __bus_space_write_stream(8,64) /* bus_space_write_stream_8 */
709 __bus_space_read_multi(2,16) /* bus_space_read_multi_stream_2 */
710 __bus_space_read_multi(4,32) /* bus_space_read_multi_stream_4 */
711 __bus_space_read_multi(8,64) /* bus_space_read_multi_stream_8 */
713 __bus_space_read_region(2,16) /* bus_space_read_region_stream_2 */
714 __bus_space_read_region(4,32) /* bus_space_read_region_stream_4 */
715 __bus_space_read_region(8,64) /* bus_space_read_region_stream_8 */
717 __bus_space_write_multi(2,16) /* bus_space_write_multi_stream_2 */
718 __bus_space_write_multi(4,32) /* bus_space_write_multi_stream_4 */
719 __bus_space_write_multi(8,64) /* bus_space_write_multi_stream_8 */
721 __bus_space_write_region(2,16) /* bus_space_write_region_stream_2 */
722 __bus_space_write_region(4,32) /* bus_space_write_region_stream_4 */
723 __bus_space_write_region(8,64) /* bus_space_write_region_stream_8 */
725 __bus_space_set_multi(2,16) /* bus_space_set_multi_stream_2 */
726 __bus_space_set_multi(4,32) /* bus_space_set_multi_stream_4 */
727 __bus_space_set_multi(8,64) /* bus_space_set_multi_stream_8 */
729 __bus_space_set_region(2,16) /* bus_space_set_region_stream_2 */
730 __bus_space_set_region(4,32) /* bus_space_set_region_stream_4 */
731 __bus_space_set_region(8, 64) /* bus_space_set_region_stream_8 */
733 #undef __bus_space_read
734 #undef __bus_space_write
735 #undef __bus_space_read_stream
736 #undef __bus_space_write_stream
737 #undef __bus_space_read_multi
738 #undef __bus_space_read_region
739 #undef __bus_space_write_multi
740 #undef __bus_space_write_region
741 #undef __bus_space_set_multi
742 #undef __bus_space_set_region
743 #undef __bus_space_copy_region
751 * Bus read/write barrier methods.
753 * void bus_space_barrier(bus_space_tag_t tag,
754 * bus_space_handle_t bsh, bus_size_t offset,
755 * bus_size_t len, int flags);
757 * On the MIPS, we just flush the write buffer.
759 #define bus_space_barrier(t, h, o, l, f) \
760 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f), \
763 #define BUS_SPACE_BARRIER_READ 0x01
764 #define BUS_SPACE_BARRIER_WRITE 0x02
767 * Flags used in various bus DMA methods.
769 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
770 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
771 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
772 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
773 #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
774 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
775 #define BUS_DMA_BUS2 0x020
776 #define BUS_DMA_BUS3 0x040
777 #define BUS_DMA_BUS4 0x080
778 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
779 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
780 #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
782 #define MIPSCO_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */
784 /* Forwards needed by prototypes below. */
789 * Operations performed by bus_dmamap_sync().
791 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
792 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
793 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
794 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
796 typedef struct mipsco_bus_dma_tag
*bus_dma_tag_t
;
797 typedef struct mipsco_bus_dmamap
*bus_dmamap_t
;
799 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
804 * Describes a single contiguous DMA transaction. Values
805 * are suitable for programming into DMA registers.
807 struct mipsco_bus_dma_segment
{
809 * PUBLIC MEMBERS: these are used by device drivers.
811 bus_addr_t ds_addr
; /* DMA address */
812 bus_size_t ds_len
; /* length of transfer */
814 * PRIVATE MEMBERS for the DMA back-end.: not for use by drivers.
816 vaddr_t _ds_paddr
; /* CPU physical address */
817 vaddr_t _ds_vaddr
; /* virtual address, 0 if invalid */
819 typedef struct mipsco_bus_dma_segment bus_dma_segment_t
;
824 * A machine-dependent opaque type describing the implementation of
825 * DMA for a given bus.
828 struct mipsco_bus_dma_tag
{
829 bus_addr_t dma_offset
;
832 * DMA mapping methods.
834 int (*_dmamap_create
)(bus_dma_tag_t
, bus_size_t
, int,
835 bus_size_t
, bus_size_t
, int, bus_dmamap_t
*);
836 void (*_dmamap_destroy
)(bus_dma_tag_t
, bus_dmamap_t
);
837 int (*_dmamap_load
)(bus_dma_tag_t
, bus_dmamap_t
, void *,
838 bus_size_t
, struct proc
*, int);
839 int (*_dmamap_load_mbuf
)(bus_dma_tag_t
, bus_dmamap_t
,
841 int (*_dmamap_load_uio
)(bus_dma_tag_t
, bus_dmamap_t
,
843 int (*_dmamap_load_raw
)(bus_dma_tag_t
, bus_dmamap_t
,
844 bus_dma_segment_t
*, int, bus_size_t
, int);
845 void (*_dmamap_unload
)(bus_dma_tag_t
, bus_dmamap_t
);
846 void (*_dmamap_sync
)(bus_dma_tag_t
, bus_dmamap_t
,
847 bus_addr_t
, bus_size_t
, int);
850 * DMA memory utility functions.
852 int (*_dmamem_alloc
)(bus_dma_tag_t
, bus_size_t
, bus_size_t
,
853 bus_size_t
, bus_dma_segment_t
*, int, int *, int);
854 void (*_dmamem_free
)(bus_dma_tag_t
,
855 bus_dma_segment_t
*, int);
856 int (*_dmamem_map
)(bus_dma_tag_t
, bus_dma_segment_t
*,
857 int, size_t, void **, int);
858 void (*_dmamem_unmap
)(bus_dma_tag_t
, void *, size_t);
859 paddr_t (*_dmamem_mmap
)(bus_dma_tag_t
, bus_dma_segment_t
*,
860 int, off_t
, int, int);
863 #define bus_dmamap_create(t, s, n, m, b, f, p) \
864 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
865 #define bus_dmamap_destroy(t, p) \
866 (*(t)->_dmamap_destroy)((t), (p))
867 #define bus_dmamap_load(t, m, b, s, p, f) \
868 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
869 #define bus_dmamap_load_mbuf(t, m, b, f) \
870 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
871 #define bus_dmamap_load_uio(t, m, u, f) \
872 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
873 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
874 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
875 #define bus_dmamap_unload(t, p) \
876 (*(t)->_dmamap_unload)((t), (p))
877 #define bus_dmamap_sync(t, p, o, l, ops) \
878 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
879 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
880 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
881 #define bus_dmamem_free(t, sg, n) \
882 (*(t)->_dmamem_free)((t), (sg), (n))
883 #define bus_dmamem_map(t, sg, n, s, k, f) \
884 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
885 #define bus_dmamem_unmap(t, k, s) \
886 (*(t)->_dmamem_unmap)((t), (k), (s))
887 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
888 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
890 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
891 #define bus_dmatag_destroy(t)
896 * Describes a DMA mapping.
898 struct mipsco_bus_dmamap
{
900 * PRIVATE MEMBERS: not for use by machine-independent code.
902 bus_size_t _dm_size
; /* largest DMA transfer mappable */
903 int _dm_segcnt
; /* number of segs this map can map */
904 bus_size_t _dm_maxmaxsegsz
; /* fixed largest possible segment */
905 bus_size_t _dm_boundary
; /* don't cross this */
906 int _dm_flags
; /* misc. flags */
909 * Private cookie to be used by the DMA back-end.
914 * PUBLIC MEMBERS: these are used by machine-independent code.
916 bus_size_t dm_maxsegsz
; /* largest possible segment */
917 bus_size_t dm_mapsize
; /* size of the mapping */
918 int dm_nsegs
; /* # valid segments in mapping */
919 bus_dma_segment_t dm_segs
[1]; /* segments; variable length */
922 #ifdef _MIPSCO_BUS_DMA_PRIVATE
923 int _bus_dmamap_create(bus_dma_tag_t
, bus_size_t
, int, bus_size_t
,
924 bus_size_t
, int, bus_dmamap_t
*);
925 void _bus_dmamap_destroy(bus_dma_tag_t
, bus_dmamap_t
);
926 int _bus_dmamap_load(bus_dma_tag_t
, bus_dmamap_t
, void *,
927 bus_size_t
, struct proc
*, int);
928 int _bus_dmamap_load_mbuf(bus_dma_tag_t
, bus_dmamap_t
,
930 int _bus_dmamap_load_uio(bus_dma_tag_t
, bus_dmamap_t
,
932 int _bus_dmamap_load_raw(bus_dma_tag_t
, bus_dmamap_t
,
933 bus_dma_segment_t
*, int, bus_size_t
, int);
934 void _bus_dmamap_unload(bus_dma_tag_t
, bus_dmamap_t
);
935 void _bus_dmamap_sync(bus_dma_tag_t
, bus_dmamap_t
, bus_addr_t
,
938 int _bus_dmamem_alloc(bus_dma_tag_t tag
, bus_size_t size
,
939 bus_size_t alignment
, bus_size_t boundary
,
940 bus_dma_segment_t
*segs
, int nsegs
, int *rsegs
, int flags
);
941 int _bus_dmamem_alloc_range(bus_dma_tag_t tag
, bus_size_t size
,
942 bus_size_t alignment
, bus_size_t boundary
,
943 bus_dma_segment_t
*segs
, int nsegs
, int *rsegs
, int flags
,
944 paddr_t low
, paddr_t high
);
945 void _bus_dmamem_free(bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
947 int _bus_dmamem_map(bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
948 int nsegs
, size_t size
, void **kvap
, int flags
);
949 void _bus_dmamem_unmap(bus_dma_tag_t tag
, void *kva
,
951 paddr_t
_bus_dmamem_mmap(bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
952 int nsegs
, off_t off
, int prot
, int flags
);
954 int _bus_dmamem_alloc_range(bus_dma_tag_t tag
, bus_size_t size
,
955 bus_size_t alignment
, bus_size_t boundary
,
956 bus_dma_segment_t
*segs
, int nsegs
, int *rsegs
, int flags
,
957 paddr_t low
, paddr_t high
);
958 #endif /* _MIPSCO_BUS_DMA_PRIVATE */
960 void _bus_dma_tag_init(bus_dma_tag_t tag
);
963 #endif /* _MIPSCO_BUS_H_ */