1 /* $NetBSD: bus.h,v 1.19 2008/02/03 06:28:01 matt Exp $ */
2 /* $OpenBSD: bus.h,v 1.1 1997/10/13 10:53:42 pefo Exp $ */
5 * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
35 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
36 * Copyright (c) 1996 Jason R. Thorpe. All rights reserved.
37 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
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.
67 * Copyright (c) 1997 Per Fogelstrom. All rights reserved.
68 * Copyright (c) 1996 Niklas Hallqvist. All rights reserved.
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 * notice, this list of conditions and the following disclaimer in the
77 * documentation and/or other materials provided with the distribution.
78 * 3. All advertising materials mentioning features or use of this software
79 * must display the following acknowledgement:
80 * This product includes software developed by Christopher G. Demetriou
81 * for the NetBSD Project.
82 * 4. The name of the author may not be used to endorse or promote products
83 * derived from this software without specific prior written permission
85 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
86 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
87 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
88 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
89 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
90 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
91 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
92 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
93 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
94 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97 #ifndef _POWERPC_BUS_H_
98 #define _POWERPC_BUS_H_
100 #if defined(_KERNEL_OPT) && !defined(BUS_DMA_COHERENT)
101 #include "opt_ppcarch.h"
102 #if defined(PPC_IBM4XX)
103 #define BUS_DMA_COHERENT BUS_DMA_NOCACHE
104 #endif /* PPC_IBM4XX */
105 #endif /* _KERNEL_OPT && !BUS_DMA_COHERENT */
111 typedef uint32_t bus_addr_t
;
112 typedef uint32_t bus_size_t
;
114 #ifndef __HAVE_LOCAL_BUS_SPACE
115 typedef uint32_t bus_space_handle_t
;
116 typedef const struct powerpc_bus_space
*bus_space_tag_t
;
120 struct powerpc_bus_space_scalar
{
121 uint8_t (*pbss_read_1
)(bus_space_tag_t
, bus_space_handle_t
,
123 uint16_t (*pbss_read_2
)(bus_space_tag_t
, bus_space_handle_t
,
125 uint32_t (*pbss_read_4
)(bus_space_tag_t
, bus_space_handle_t
,
127 uint64_t (*pbss_read_8
)(bus_space_tag_t
, bus_space_handle_t
,
130 void (*pbss_write_1
)(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
132 void (*pbss_write_2
)(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
134 void (*pbss_write_4
)(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
136 void (*pbss_write_8
)(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
140 struct powerpc_bus_space_group
{
141 void (*pbsg_read_1
)(bus_space_tag_t
, bus_space_handle_t
,
142 bus_size_t
, uint8_t *, size_t);
143 void (*pbsg_read_2
)(bus_space_tag_t
, bus_space_handle_t
,
144 bus_size_t
, uint16_t *, size_t);
145 void (*pbsg_read_4
)(bus_space_tag_t
, bus_space_handle_t
,
146 bus_size_t
, uint32_t *, size_t);
147 void (*pbsg_read_8
)(bus_space_tag_t
, bus_space_handle_t
,
148 bus_size_t
, uint64_t *, size_t);
150 void (*pbsg_write_1
)(bus_space_tag_t
, bus_space_handle_t
,
151 bus_size_t
, const uint8_t *, size_t);
152 void (*pbsg_write_2
)(bus_space_tag_t
, bus_space_handle_t
,
153 bus_size_t
, const uint16_t *, size_t);
154 void (*pbsg_write_4
)(bus_space_tag_t
, bus_space_handle_t
,
155 bus_size_t
, const uint32_t *, size_t);
156 void (*pbsg_write_8
)(bus_space_tag_t
, bus_space_handle_t
,
157 bus_size_t
, const uint64_t *, size_t);
160 struct powerpc_bus_space_set
{
161 void (*pbss_set_1
)(bus_space_tag_t
, bus_space_handle_t
,
162 bus_size_t
, uint8_t, size_t);
163 void (*pbss_set_2
)(bus_space_tag_t
, bus_space_handle_t
,
164 bus_size_t
, uint16_t, size_t);
165 void (*pbss_set_4
)(bus_space_tag_t
, bus_space_handle_t
,
166 bus_size_t
, uint32_t, size_t);
167 void (*pbss_set_8
)(bus_space_tag_t
, bus_space_handle_t
,
168 bus_size_t
, uint64_t, size_t);
171 struct powerpc_bus_space_copy
{
172 void (*pbsc_copy_1
)(bus_space_tag_t
, bus_space_handle_t
,
173 bus_size_t
, bus_space_handle_t
, bus_size_t
, size_t);
174 void (*pbsc_copy_2
)(bus_space_tag_t
, bus_space_handle_t
,
175 bus_size_t
, bus_space_handle_t
, bus_size_t
, size_t);
176 void (*pbsc_copy_4
)(bus_space_tag_t
, bus_space_handle_t
,
177 bus_size_t
, bus_space_handle_t
, bus_size_t
, size_t);
178 void (*pbsc_copy_8
)(bus_space_tag_t
, bus_space_handle_t
,
179 bus_size_t
, bus_space_handle_t
, bus_size_t
, size_t);
182 struct powerpc_bus_space
{
184 #define _BUS_SPACE_BIG_ENDIAN 0x00000100
185 #define _BUS_SPACE_LITTLE_ENDIAN 0x00000000
186 #define _BUS_SPACE_IO_TYPE 0x00000200
187 #define _BUS_SPACE_MEM_TYPE 0x00000000
188 #define _BUS_SPACE_STRIDE_MASK 0x0000001f
189 bus_addr_t pbs_offset
; /* offset to real start */
190 bus_addr_t pbs_base
; /* extent base */
191 bus_addr_t pbs_limit
; /* extent limit */
192 struct extent
*pbs_extent
;
194 paddr_t (*pbs_mmap
)(bus_space_tag_t
, bus_addr_t
, off_t
, int, int);
195 int (*pbs_map
)(bus_space_tag_t
, bus_addr_t
, bus_size_t
, int,
196 bus_space_handle_t
*);
197 void (*pbs_unmap
)(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
);
198 int (*pbs_alloc
)(bus_space_tag_t
, bus_addr_t
, bus_addr_t
, bus_size_t
,
199 bus_size_t align
, bus_size_t
, int, bus_addr_t
*,
200 bus_space_handle_t
*);
201 void (*pbs_free
)(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
);
202 int (*pbs_subregion
)(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
203 bus_size_t
, bus_space_handle_t
*);
205 struct powerpc_bus_space_scalar pbs_scalar
;
206 struct powerpc_bus_space_scalar pbs_scalar_stream
;
207 const struct powerpc_bus_space_group
*pbs_multi
;
208 const struct powerpc_bus_space_group
*pbs_multi_stream
;
209 const struct powerpc_bus_space_group
*pbs_region
;
210 const struct powerpc_bus_space_group
*pbs_region_stream
;
211 const struct powerpc_bus_space_set
*pbs_set
;
212 const struct powerpc_bus_space_set
*pbs_set_stream
;
213 const struct powerpc_bus_space_copy
*pbs_copy
;
216 #define _BUS_SPACE_STRIDE(t, o) \
217 ((o) << ((t)->pbs_flags & _BUS_SPACE_STRIDE_MASK))
218 #define _BUS_SPACE_UNSTRIDE(t, o) \
219 ((o) >> ((t)->pbs_flags & _BUS_SPACE_STRIDE_MASK))
221 #define BUS_SPACE_MAP_CACHEABLE 0x01
222 #define BUS_SPACE_MAP_LINEAR 0x02
223 #define BUS_SPACE_MAP_PREFETCHABLE 0x04
226 #define CAT(a,b) a##b
227 #define CAT3(a,b,c) a##b##c
229 #define CAT(a,b) a/**/b
230 #define CAT3(a,b,c) a/**/b/**/c
233 int bus_space_init(struct powerpc_bus_space
*, const char *, void *, size_t);
234 void bus_space_mallocok(void);
237 * Access methods for bus resources
240 #define __BUS_SPACE_HAS_STREAM_METHODS
243 * void *bus_space_vaddr (bus_space_tag_t, bus_space_handle_t);
245 * Get the kernel virtual address for the mapped bus space.
246 * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
249 #define bus_space_vaddr(t, h) ((void *)(h))
252 * paddr_t bus_space_mmap (bus_space_tag_t t, bus_addr_t addr,
253 * off_t offset, int prot, int flags);
255 * Mmap a region of bus space.
258 #define bus_space_mmap(t, b, o, p, f) \
259 ((*(t)->pbs_mmap)((t), (b), (o), (p), (f)))
262 * int bus_space_map (bus_space_tag_t t, bus_addr_t addr,
263 * bus_size_t size, int flags, bus_space_handle_t *bshp);
265 * Map a region of bus space.
268 #define bus_space_map(t, a, s, f, hp) \
269 ((*(t)->pbs_map)((t), (a), (s), (f), (hp)))
272 * int bus_space_unmap (bus_space_tag_t t,
273 * bus_space_handle_t bsh, bus_size_t size);
275 * Unmap a region of bus space.
278 #define bus_space_unmap(t, h, s) \
279 ((void)(*(t)->pbs_unmap)((t), (h), (s)))
282 * int bus_space_subregion (bus_space_tag_t t,
283 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
284 * bus_space_handle_t *nbshp);
286 * Get a new handle for a subregion of an already-mapped area of bus space.
289 #define bus_space_subregion(t, h, o, s, hp) \
290 ((*(t)->pbs_subregion)((t), (h), (o), (s), (hp)))
293 * int bus_space_alloc (bus_space_tag_t t, bus_addr_t rstart,
294 * bus_addr_t rend, bus_size_t size, bus_size_t align,
295 * bus_size_t boundary, int flags, bus_addr_t *bpap,
296 * bus_space_handle_t *bshp);
298 * Allocate a region of bus space.
301 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
302 ((*(t)->pbs_alloc)((t), (rs), (re), (s), (a), (b), (f), (ap), (hp)))
305 * int bus_space_free (bus_space_tag_t t,
306 * bus_space_handle_t bsh, bus_size_t size);
308 * Free a region of bus space.
311 #define bus_space_free(t, h, s) \
312 ((void)(*(t)->pbs_free)((t), (h), (s)))
315 * uintN_t bus_space_read_N (bus_space_tag_t tag,
316 * bus_space_handle_t bsh, bus_size_t offset);
318 * Read a 1, 2, 4, or 8 byte quantity from bus space
319 * described by tag/handle/offset.
322 #define bus_space_read_1(t, h, o) \
323 ((*(t)->pbs_scalar.pbss_read_1)((t), (h), (o)))
324 #define bus_space_read_2(t, h, o) \
325 ((*(t)->pbs_scalar.pbss_read_2)((t), (h), (o)))
326 #define bus_space_read_4(t, h, o) \
327 ((*(t)->pbs_scalar.pbss_read_4)((t), (h), (o)))
328 #define bus_space_read_8(t, h, o) \
329 ((*(t)->pbs_scalar.pbss_read_8)((t), (h), (o)))
332 * uintN_t bus_space_read_stream_N (bus_space_tag_t tag,
333 * bus_space_handle_t bsh, bus_size_t offset);
335 * Read a 2, 4, or 8 byte quantity from bus space
336 * described by tag/handle/offset ignoring endianness.
339 #define bus_space_read_stream_2(t, h, o) \
340 ((*(t)->pbs_scalar_stream.pbss_read_2)((t), (h), (o)))
341 #define bus_space_read_stream_4(t, h, o) \
342 ((*(t)->pbs_scalar_stream.pbss_read_4)((t), (h), (o)))
343 #define bus_space_read_stream_8(t, h, o) \
344 ((*(t)->pbs_scalar_stream.pbss_read_8)((t), (h), (o)))
347 * void bus_space_read_multi_N _P((bus_space_tag_t tag,
348 * bus_space_handle_t bsh, bus_size_t offset,
349 * uintN_t *addr, size_t count);
351 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
352 * described by tag/handle/offset and copy into buffer provided.
355 #define bus_space_read_multi_1(t, h, o, a, c) \
356 ((*(t)->pbs_multi->pbsg_read_1)((t), (h), (o), (a), (c)))
357 #define bus_space_read_multi_2(t, h, o, a, c) \
358 ((*(t)->pbs_multi->pbsg_read_2)((t), (h), (o), (a), (c)))
359 #define bus_space_read_multi_4(t, h, o, a, c) \
360 ((*(t)->pbs_multi->pbsg_read_4)((t), (h), (o), (a), (c)))
361 #define bus_space_read_multi_8(t, h, o, a, c) \
362 ((*(t)->pbs_multi->pbsg_read_8)((t), (h), (o), (a), (c)))
365 * void bus_space_read_multi_stream_N (bus_space_tag_t tag,
366 * bus_space_handle_t bsh, bus_size_t offset,
367 * uintN_t *addr, size_t count);
369 * Read `count' 2, 4, or 8 byte stream quantities from bus space
370 * described by tag/handle/offset and copy into buffer provided.
373 #define bus_space_read_multi_stream_2(t, h, o, a, c) \
374 ((*(t)->pbs_multi_stream->pbsg_read_2)((t), (h), (o), (a), (c)))
375 #define bus_space_read_multi_stream_4(t, h, o, a, c) \
376 ((*(t)->pbs_multi_stream->pbsg_read_4)((t), (h), (o), (a), (c)))
377 #define bus_space_read_multi_stream_8(t, h, o, a, c) \
378 ((*(t)->pbs_multi_stream->pbsg_read_8)((t), (h), (o), (a), (c)))
381 * void bus_space_write_N (bus_space_tag_t tag,
382 * bus_space_handle_t bsh, bus_size_t offset,
385 * Write the 1, 2, 4, or 8 byte value `value' to bus space
386 * described by tag/handle/offset.
389 #define bus_space_write_1(t, h, o, v) \
390 ((*(t)->pbs_scalar.pbss_write_1)((t), (h), (o), (v)))
391 #define bus_space_write_2(t, h, o, v) \
392 ((*(t)->pbs_scalar.pbss_write_2)((t), (h), (o), (v)))
393 #define bus_space_write_4(t, h, o, v) \
394 ((*(t)->pbs_scalar.pbss_write_4)((t), (h), (o), (v)))
395 #define bus_space_write_8(t, h, o, v) \
396 ((*(t)->pbs_scalar.pbss_write_8)((t), (h), (o), (v)))
399 * void bus_space_write_stream_N (bus_space_tag_t tag,
400 * bus_space_handle_t bsh, bus_size_t offset,
403 * Write the 2, 4, or 8 byte stream value `value' to bus space
404 * described by tag/handle/offset.
407 #define bus_space_write_stream_1(t, h, o, v) \
408 ((*(t)->pbs_scalar_stream.pbss_write_1)((t), (h), (o), (v)))
409 #define bus_space_write_stream_2(t, h, o, v) \
410 ((*(t)->pbs_scalar_stream.pbss_write_2)((t), (h), (o), (v)))
411 #define bus_space_write_stream_4(t, h, o, v) \
412 ((*(t)->pbs_scalar_stream.pbss_write_4)((t), (h), (o), (v)))
413 #define bus_space_write_stream_8(t, h, o, v) \
414 ((*(t)->pbs_scalar_stream.pbss_write_8)((t), (h), (o), (v)))
417 * void bus_space_write_multi_N (bus_space_tag_t tag,
418 * bus_space_handle_t bsh, bus_size_t offset,
419 * const uintN_t *addr, size_t count);
421 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
422 * provided to bus space described by tag/handle/offset.
425 #define bus_space_write_multi_1(t, h, o, a, c) \
426 ((*(t)->pbs_multi->pbsg_write_1)((t), (h), (o), (a), (c)))
427 #define bus_space_write_multi_2(t, h, o, a, c) \
428 ((*(t)->pbs_multi->pbsg_write_2)((t), (h), (o), (a), (c)))
429 #define bus_space_write_multi_4(t, h, o, a, c) \
430 ((*(t)->pbs_multi->pbsg_write_4)((t), (h), (o), (a), (c)))
431 #define bus_space_write_multi_8(t, h, o, a, c) \
432 ((*(t)->pbs_multi->pbsg_write_8)((t), (h), (o), (a), (c)))
435 * void bus_space_write_multi_stream_N (bus_space_tag_t tag,
436 * bus_space_handle_t bsh, bus_size_t offset,
437 * const uintN_t *addr, size_t count);
439 * Write `count' 2, 4, or 8 byte stream quantities from the buffer
440 * provided to bus space described by tag/handle/offset.
443 #define bus_space_write_multi_stream_1(t, h, o, a, c) \
444 ((*(t)->pbs_multi_stream->pbsg_write_1)((t), (h), (o), (a), (c)))
445 #define bus_space_write_multi_stream_2(t, h, o, a, c) \
446 ((*(t)->pbs_multi_stream->pbsg_write_2)((t), (h), (o), (a), (c)))
447 #define bus_space_write_multi_stream_4(t, h, o, a, c) \
448 ((*(t)->pbs_multi_stream->pbsg_write_4)((t), (h), (o), (a), (c)))
449 #define bus_space_write_multi_stream_8(t, h, o, a, c) \
450 ((*(t)->pbs_multi_stream->pbsg_write_8)((t), (h), (o), (a), (c)))
453 * void bus_space_read_region_N (bus_space_tag_t tag,
454 * bus_space_handle_t bsh, bus_size_t offset,
455 * uintN_t *addr, size_t count);
457 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
458 * described by tag/handle and starting at `offset' and copy into
461 #define bus_space_read_region_1(t, h, o, a, c) \
462 ((*(t)->pbs_region->pbsg_read_1)((t), (h), (o), (a), (c)))
463 #define bus_space_read_region_2(t, h, o, a, c) \
464 ((*(t)->pbs_region->pbsg_read_2)((t), (h), (o), (a), (c)))
465 #define bus_space_read_region_4(t, h, o, a, c) \
466 ((*(t)->pbs_region->pbsg_read_4)((t), (h), (o), (a), (c)))
467 #define bus_space_read_region_8(t, h, o, a, c) \
468 ((*(t)->pbs_region->pbsg_read_8)((t), (h), (o), (a), (c)))
471 * void bus_space_read_region_stream_N (bus_space_tag_t tag,
472 * bus_space_handle_t bsh, bus_size_t offset,
473 * uintN_t *addr, size_t count);
475 * Read `count' 2, 4, or 8 byte stream quantities from bus space
476 * described by tag/handle and starting at `offset' and copy into
479 #define bus_space_read_region_stream_2(t, h, o, a, c) \
480 ((*(t)->pbs_region_stream->pbsg_read_2)((t), (h), (o), (a), (c)))
481 #define bus_space_read_region_stream_4(t, h, o, a, c) \
482 ((*(t)->pbs_region_stream->pbsg_read_4)((t), (h), (o), (a), (c)))
483 #define bus_space_read_region_stream_8(t, h, o, a, c) \
484 ((*(t)->pbs_region_stream->pbsg_read_8)((t), (h), (o), (a), (c)))
487 * void bus_space_write_region_N (bus_space_tag_t tag,
488 * bus_space_handle_t bsh, bus_size_t offset,
489 * const uintN_t *addr, size_t count);
491 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
492 * to bus space described by tag/handle starting at `offset'.
494 #define bus_space_write_region_1(t, h, o, a, c) \
495 ((*(t)->pbs_region->pbsg_write_1)((t), (h), (o), (a), (c)))
496 #define bus_space_write_region_2(t, h, o, a, c) \
497 ((*(t)->pbs_region->pbsg_write_2)((t), (h), (o), (a), (c)))
498 #define bus_space_write_region_4(t, h, o, a, c) \
499 ((*(t)->pbs_region->pbsg_write_4)((t), (h), (o), (a), (c)))
500 #define bus_space_write_region_8(t, h, o, a, c) \
501 ((*(t)->pbs_region->pbsg_write_8)((t), (h), (o), (a), (c)))
504 * void bus_space_write_region_stream_N (bus_space_tag_t tag,
505 * bus_space_handle_t bsh, bus_size_t offset,
506 * const uintN_t *addr, size_t count);
508 * Write `count' 2, 4, or 8 byte stream quantities from the buffer provided
509 * to bus space described by tag/handle starting at `offset'.
511 #define bus_space_write_region_stream_2(t, h, o, a, c) \
512 ((*(t)->pbs_region_stream->pbsg_write_2)((t), (h), (o), (a), (c)))
513 #define bus_space_write_region_stream_4(t, h, o, a, c) \
514 ((*(t)->pbs_region_stream->pbsg_write_4)((t), (h), (o), (a), (c)))
515 #define bus_space_write_region_stream_8(t, h, o, a, c) \
516 ((*(t)->pbs_region_stream->pbsg_write_8)((t), (h), (o), (a), (c)))
520 * void bus_space_set_multi_N (bus_space_tag_t tag,
521 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
524 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
525 * by tag/handle/offset `count' times.
527 #define bus_space_set_multi_1(t, h, o, v, c)
528 ((*(t
)->pbs_set_multi_1
)((t
), (h
), (o
), (v
), (c
)))
529 #define bus_space_set_multi_2(t, h, o, v, c)
530 ((*(t
)->pbs_set_multi_2
)((t
), (h
), (o
), (v
), (c
)))
531 #define bus_space_set_multi_4(t, h, o, v, c)
532 ((*(t
)->pbs_set_multi_4
)((t
), (h
), (o
), (v
), (c
)))
533 #define bus_space_set_multi_8(t, h, o, v, c)
534 ((*(t
)->pbs_set_multi_8
)((t
), (h
), (o
), (v
), (c
)))
537 * void bus_space_set_multi_stream_N (bus_space_tag_t tag,
538 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
541 * Write the 2, 4, or 8 byte stream value `val' to bus space described
542 * by tag/handle/offset `count' times.
544 #define bus_space_set_multi_stream_2(t, h, o, v, c)
545 ((*(t
)->pbs_set_multi_stream_2
)((t
), (h
), (o
), (v
), (c
)))
546 #define bus_space_set_multi_stream_4(t, h, o, v, c)
547 ((*(t
)->pbs_set_multi_stream_4
)((t
), (h
), (o
), (v
), (c
)))
548 #define bus_space_set_multi_stream_8(t, h, o, v, c)
549 ((*(t
)->pbs_set_multi_stream_8
)((t
), (h
), (o
), (v
), (c
)))
554 * void bus_space_set_region_N (bus_space_tag_t tag,
555 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
558 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
559 * by tag/handle starting at `offset'.
561 #define bus_space_set_region_1(t, h, o, v, c) \
562 ((*(t)->pbs_set->pbss_set_1)((t), (h), (o), (v), (c)))
563 #define bus_space_set_region_2(t, h, o, v, c) \
564 ((*(t)->pbs_set->pbss_set_2)((t), (h), (o), (v), (c)))
565 #define bus_space_set_region_4(t, h, o, v, c) \
566 ((*(t)->pbs_set->pbss_set_4)((t), (h), (o), (v), (c)))
567 #define bus_space_set_region_8(t, h, o, v, c) \
568 ((*(t)->pbs_set->pbss_set_8)((t), (h), (o), (v), (c)))
571 * void bus_space_set_region_stream_N (bus_space_tag_t tag,
572 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
575 * Write `count' 2, 4, or 8 byte stream value `val' to bus space described
576 * by tag/handle starting at `offset'.
578 #define bus_space_set_region_stream_2(t, h, o, v, c) \
579 ((*(t)->pbs_set_stream->pbss_set_2)((t), (h), (o), (v), (c)))
580 #define bus_space_set_region_stream_4(t, h, o, v, c) \
581 ((*(t)->pbs_set_stream->pbss_set_4)((t), (h), (o), (v), (c)))
582 #define bus_space_set_region_stream_8(t, h, o, v, c) \
583 ((*(t)->pbs_set_stream->pbss_set_8)((t), (h), (o), (v), (c)))
587 * void bus_space_copy_region_N (bus_space_tag_t tag,
588 * bus_space_handle_t bsh1, bus_size_t off1,
589 * bus_space_handle_t bsh2, bus_size_t off2,
592 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
593 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
595 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \
596 ((*(t)->pbs_copy->pbsc_copy_1)((t), (h1), (o1), (h2), (o2), (c)))
597 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \
598 ((*(t)->pbs_copy->pbsc_copy_2)((t), (h1), (o1), (h2), (o2), (c)))
599 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \
600 ((*(t)->pbs_copy->pbsc_copy_4)((t), (h1), (o1), (h2), (o2), (c)))
601 #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \
602 ((*(t)->pbs_copy->pbsc_copy_8)((t), (h1), (o1), (h2), (o2), (c)))
605 * Bus read/write barrier methods.
607 * void bus_space_barrier (bus_space_tag_t tag,
608 * bus_space_handle_t bsh, bus_size_t offset,
609 * bus_size_t len, int flags);
612 #define bus_space_barrier(t, h, o, l, f) \
613 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
614 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
615 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
617 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
619 #endif /* !__HAVE_LOCAL_BUS_SPACE */
626 * Flags used in various bus DMA methods.
628 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
629 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
630 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
631 /* Allow machine-dependent code to override BUS_DMA_COHERENT */
632 #ifndef BUS_DMA_COHERENT
633 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
635 #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
636 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
637 #define BUS_DMA_BUS2 0x020
638 #define BUS_DMA_BUS3 0x040
639 #define BUS_DMA_BUS4 0x080
640 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
641 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
642 #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
644 /* Forwards needed by prototypes below. */
650 * Operations performed by bus_dmamap_sync().
652 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
653 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
654 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
655 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
657 typedef struct powerpc_bus_dma_tag
*bus_dma_tag_t
;
658 typedef struct powerpc_bus_dmamap
*bus_dmamap_t
;
660 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
665 * Describes a single contiguous DMA transaction. Values
666 * are suitable for programming into DMA registers.
668 struct powerpc_bus_dma_segment
{
669 bus_addr_t ds_addr
; /* DMA address */
670 bus_size_t ds_len
; /* length of transfer */
672 typedef struct powerpc_bus_dma_segment bus_dma_segment_t
;
677 * A machine-dependent opaque type describing the implementation of
678 * DMA for a given bus.
681 struct powerpc_bus_dma_tag
{
683 * The `bounce threshold' is checked while we are loading
684 * the DMA map. If the physical address of the segment
685 * exceeds the threshold, an error will be returned. The
686 * caller can then take whatever action is necessary to
687 * bounce the transfer. If this value is 0, it will be
690 bus_addr_t _bounce_thresh
;
693 * DMA mapping methods.
695 int (*_dmamap_create
) (bus_dma_tag_t
, bus_size_t
, int,
696 bus_size_t
, bus_size_t
, int, bus_dmamap_t
*);
697 void (*_dmamap_destroy
) (bus_dma_tag_t
, bus_dmamap_t
);
698 int (*_dmamap_load
) (bus_dma_tag_t
, bus_dmamap_t
, void *,
699 bus_size_t
, struct proc
*, int);
700 int (*_dmamap_load_mbuf
) (bus_dma_tag_t
, bus_dmamap_t
,
702 int (*_dmamap_load_uio
) (bus_dma_tag_t
, bus_dmamap_t
,
704 int (*_dmamap_load_raw
) (bus_dma_tag_t
, bus_dmamap_t
,
705 bus_dma_segment_t
*, int, bus_size_t
, int);
706 void (*_dmamap_unload
) (bus_dma_tag_t
, bus_dmamap_t
);
707 void (*_dmamap_sync
) (bus_dma_tag_t
, bus_dmamap_t
,
708 bus_addr_t
, bus_size_t
, int);
711 * DMA memory utility functions.
713 int (*_dmamem_alloc
) (bus_dma_tag_t
, bus_size_t
, bus_size_t
,
714 bus_size_t
, bus_dma_segment_t
*, int, int *, int);
715 void (*_dmamem_free
) (bus_dma_tag_t
,
716 bus_dma_segment_t
*, int);
717 int (*_dmamem_map
) (bus_dma_tag_t
, bus_dma_segment_t
*,
718 int, size_t, void **, int);
719 void (*_dmamem_unmap
) (bus_dma_tag_t
, void *, size_t);
720 paddr_t (*_dmamem_mmap
) (bus_dma_tag_t
, bus_dma_segment_t
*,
721 int, off_t
, int, int);
723 #ifndef PHYS_TO_BUS_MEM
724 bus_addr_t (*_dma_phys_to_bus_mem
)(bus_dma_tag_t
, bus_addr_t
);
725 #define PHYS_TO_BUS_MEM(t, addr) (*(t)->_dma_phys_to_bus_mem)((t), (addr))
727 #ifndef BUS_MEM_TO_PHYS
728 bus_addr_t (*_dma_bus_mem_to_phys
)(bus_dma_tag_t
, bus_addr_t
);
729 #define BUS_MEM_TO_PHYS(t, addr) (*(t)->_dma_bus_mem_to_phys)((t), (addr))
733 #define bus_dmamap_create(t, s, n, m, b, f, p) \
734 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
735 #define bus_dmamap_destroy(t, p) \
736 (*(t)->_dmamap_destroy)((t), (p))
737 #define bus_dmamap_load(t, m, b, s, p, f) \
738 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
739 #define bus_dmamap_load_mbuf(t, m, b, f) \
740 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
741 #define bus_dmamap_load_uio(t, m, u, f) \
742 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
743 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
744 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
745 #define bus_dmamap_unload(t, p) \
746 (*(t)->_dmamap_unload)((t), (p))
747 #define bus_dmamap_sync(t, p, o, l, ops) \
748 (void)((t)->_dmamap_sync ? \
749 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) : (void)0)
751 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
752 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
753 #define bus_dmamem_free(t, sg, n) \
754 (*(t)->_dmamem_free)((t), (sg), (n))
755 #define bus_dmamem_map(t, sg, n, s, k, f) \
756 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
757 #define bus_dmamem_unmap(t, k, s) \
758 (*(t)->_dmamem_unmap)((t), (k), (s))
759 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
760 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
762 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
763 #define bus_dmatag_destroy(t)
768 * Describes a DMA mapping.
770 struct powerpc_bus_dmamap
{
772 * PRIVATE MEMBERS: not for use my machine-independent code.
774 bus_size_t _dm_size
; /* largest DMA transfer mappable */
775 int _dm_segcnt
; /* number of segs this map can map */
776 bus_size_t _dm_maxmaxsegsz
; /* fixed largest possible segment */
777 bus_size_t _dm_boundary
; /* don't cross this */
778 bus_addr_t _dm_bounce_thresh
; /* bounce threshold; see tag */
779 int _dm_flags
; /* misc. flags */
781 void *_dm_cookie
; /* cookie for bus-specific functions */
784 * PUBLIC MEMBERS: these are used by machine-independent code.
786 bus_size_t dm_maxsegsz
; /* largest possible segment */
787 bus_size_t dm_mapsize
; /* size of the mapping */
788 int dm_nsegs
; /* # valid segments in mapping */
789 bus_dma_segment_t dm_segs
[1]; /* segments; variable length */
792 #ifdef _POWERPC_BUS_DMA_PRIVATE
793 int _bus_dmamap_create (bus_dma_tag_t
, bus_size_t
, int, bus_size_t
,
794 bus_size_t
, int, bus_dmamap_t
*);
795 void _bus_dmamap_destroy (bus_dma_tag_t
, bus_dmamap_t
);
796 int _bus_dmamap_load (bus_dma_tag_t
, bus_dmamap_t
, void *,
797 bus_size_t
, struct proc
*, int);
798 int _bus_dmamap_load_mbuf (bus_dma_tag_t
, bus_dmamap_t
,
800 int _bus_dmamap_load_uio (bus_dma_tag_t
, bus_dmamap_t
,
802 int _bus_dmamap_load_raw (bus_dma_tag_t
, bus_dmamap_t
,
803 bus_dma_segment_t
*, int, bus_size_t
, int);
804 void _bus_dmamap_unload (bus_dma_tag_t
, bus_dmamap_t
);
805 void _bus_dmamap_sync (bus_dma_tag_t
, bus_dmamap_t
, bus_addr_t
,
808 int _bus_dmamem_alloc (bus_dma_tag_t tag
, bus_size_t size
,
809 bus_size_t alignment
, bus_size_t boundary
,
810 bus_dma_segment_t
*segs
, int nsegs
, int *rsegs
, int flags
);
811 void _bus_dmamem_free (bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
813 int _bus_dmamem_map (bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
814 int nsegs
, size_t size
, void **kvap
, int flags
);
815 void _bus_dmamem_unmap (bus_dma_tag_t tag
, void *kva
,
817 paddr_t
_bus_dmamem_mmap (bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
818 int nsegs
, off_t off
, int prot
, int flags
);
820 int _bus_dmamem_alloc_range (bus_dma_tag_t tag
, bus_size_t size
,
821 bus_size_t alignment
, bus_size_t boundary
,
822 bus_dma_segment_t
*segs
, int nsegs
, int *rsegs
, int flags
,
823 paddr_t low
, paddr_t high
);
824 bus_addr_t
_bus_dma_phys_to_bus_mem_generic(bus_dma_tag_t
, bus_addr_t
);
825 bus_addr_t
_bus_dma_bus_mem_to_phys_generic(bus_dma_tag_t
, bus_addr_t
);
826 #endif /* _POWERPC_BUS_DMA_PRIVATE */
827 #endif /* _POWERPC_BUS_H_ */