1 /* $NetBSD: bus.h,v 1.16 2008/04/28 20:23:38 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) 1996 Charles M. Hannum. All rights reserved.
35 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
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 _SUN68K_BUS_H_
65 #define _SUN68K_BUS_H_
67 #define SUN68K_BUS_SPACE 0
70 * Bus address and size types
72 typedef u_long bus_space_handle_t
;
73 typedef u_long bus_type_t
;
74 typedef u_long bus_addr_t
;
75 typedef u_long bus_size_t
;
77 #define BUS_ADDR_PADDR(x) ((x) & 0xffffffff)
80 * Access methods for bus resources and address space.
82 typedef struct sun68k_bus_space_tag
*bus_space_tag_t
;
84 struct sun68k_bus_space_tag
{
86 bus_space_tag_t parent
;
88 int (*sun68k_bus_map
)(
94 vaddr_t
, /*preferred vaddr*/
95 bus_space_handle_t
*);
97 int (*sun68k_bus_unmap
)(
102 int (*sun68k_bus_subregion
)(
105 bus_size_t
, /*offset*/
107 bus_space_handle_t
*);
109 void (*sun68k_bus_barrier
)(
112 bus_size_t
, /*offset*/
116 paddr_t (*sun68k_bus_mmap
)(
124 void *(*sun68k_intr_establish
)(
126 int, /*bus-specific intr*/
127 int, /*device class level,
130 int (*)(void *), /*handler*/
131 void *); /*handler arg*/
133 int (*sun68k_bus_peek
)(
136 bus_size_t
, /*offset*/
137 size_t, /*probe size*/
138 void *); /*result ptr*/
140 int (*sun68k_bus_poke
)(
143 bus_size_t
, /*offset*/
144 size_t, /*probe size*/
150 * The following macro could be used to generate the bus_space*() functions
151 * but it uses a gcc extension and is ANSI-only.
152 #define PROTO_bus_space_xxx (bus_space_tag_t t, ...)
153 #define RETURNTYPE_bus_space_xxx void *
154 #define BUSFUN(name, returntype, t, args...) \
155 __inline RETURNTYPE_##name \
156 bus_##name PROTO_##name \
158 while (t->sun68k_##name == NULL) \
160 return (*(t)->sun68k_##name)(t, args); \
166 * Bus space function prototypes.
168 static int bus_space_map(
173 bus_space_handle_t
*);
174 static int bus_space_map2(
180 vaddr_t
, /*preferred vaddr*/
181 bus_space_handle_t
*);
182 static int bus_space_unmap(
186 static int bus_space_subregion(
191 bus_space_handle_t
*);
192 static void bus_space_barrier(
198 static paddr_t
bus_space_mmap(
204 static paddr_t
bus_space_mmap2(
211 static void *bus_intr_establish(
213 int, /*bus-specific intr*/
214 int, /*device class level,
217 int (*)(void *), /*handler*/
218 void *); /*handler arg*/
219 static int _bus_space_peek(
222 bus_size_t
, /*offset*/
223 size_t, /*probe size*/
224 void *); /*result ptr*/
225 static int _bus_space_poke(
228 bus_size_t
, /*offset*/
229 size_t, /*probe size*/
232 /* This macro finds the first "upstream" implementation of method `f' */
233 #define _BS_CALL(t,f) \
234 while (t->f == NULL) \
239 bus_space_map(bus_space_tag_t t
, bus_addr_t a
, bus_size_t s
, int f
,
240 bus_space_handle_t
*hp
)
242 _BS_CALL(t
, sun68k_bus_map
)((t
), 0, (a
), (s
), (f
), 0, (hp
));
246 bus_space_map2(bus_space_tag_t t
, bus_type_t bt
, bus_addr_t a
, bus_size_t s
,
247 int f
, vaddr_t v
, bus_space_handle_t
*hp
)
249 _BS_CALL(t
, sun68k_bus_map
)(t
, bt
, a
, s
, f
, v
, hp
);
253 bus_space_unmap(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t s
)
255 _BS_CALL(t
, sun68k_bus_unmap
)(t
, h
, s
);
259 bus_space_subregion(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
260 bus_size_t s
, bus_space_handle_t
*hp
)
262 _BS_CALL(t
, sun68k_bus_subregion
)(t
, h
, o
, s
, hp
);
266 bus_space_mmap(bus_space_tag_t t
, bus_addr_t a
, off_t o
, int p
, int f
)
268 _BS_CALL(t
, sun68k_bus_mmap
)(t
, 0, a
, o
, p
, f
);
272 bus_space_mmap2(bus_space_tag_t t
, bus_type_t bt
, bus_addr_t a
, off_t o
, int p
,
275 _BS_CALL(t
, sun68k_bus_mmap
)(t
, bt
, a
, o
, p
, f
);
279 bus_intr_establish(bus_space_tag_t t
, int p
, int l
, int f
, int (*h
)(void *),
282 _BS_CALL(t
, sun68k_intr_establish
)(t
, p
, l
, f
, h
, a
);
286 bus_space_barrier(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
289 _BS_CALL(t
, sun68k_bus_barrier
)(t
, h
, o
, s
, f
);
293 _bus_space_peek(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
, size_t s
,
296 _BS_CALL(t
, sun68k_bus_peek
)(t
, h
, o
, s
, vp
);
300 _bus_space_poke(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
, size_t s
,
303 _BS_CALL(t
, sun68k_bus_poke
)(t
, h
, o
, s
, v
);
307 int bus_space_alloc(bus_space_tag_t
, bus_addr_t
, bus_addr_t
, bus_size_t
,
308 bus_size_t
, bus_size_t
, int, bus_addr_t
*, bus_space_handle_t
*);
309 void bus_space_free(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
);
313 * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
315 * Get the kernel virtual address for the mapped bus space.
316 * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
319 #define bus_space_vaddr(t, h) ((void)(t), (void *)(h))
321 /* flags for bus space map functions */
322 #define BUS_SPACE_MAP_CACHEABLE 0x0001
323 #define BUS_SPACE_MAP_LINEAR 0x0002
324 #define BUS_SPACE_MAP_PREFETCHABLE 0x0004
325 #define BUS_SPACE_MAP_BUS1 0x0100 /* placeholders for bus functions... */
326 #define BUS_SPACE_MAP_BUS2 0x0200
327 #define BUS_SPACE_MAP_BUS3 0x0400
328 #define BUS_SPACE_MAP_BUS4 0x0800
330 /* Internal flag: try to find and use a PROM maping for the device. */
331 #define _SUN68K_BUS_MAP_USE_PROM BUS_SPACE_MAP_BUS1
333 /* flags for intr_establish() */
334 #define BUS_INTR_ESTABLISH_FASTTRAP 1
335 #define BUS_INTR_ESTABLISH_SOFTINTR 2
337 /* flags for bus_space_barrier() */
338 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
339 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
342 * int bus_space_peek_N(bus_space_tag_t tag,
343 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t *valuep);
345 * Cautiously read 1, 2, 4 or 8 byte quantity from bus space described
346 * by tag/handle/offset.
347 * If no hardware responds to the read access, the function returns a
348 * non-zero value. Otherwise the value read is placed in `valuep'.
351 #define bus_space_peek_1(t, h, o, vp) \
352 _bus_space_peek(t, h, o, sizeof(uint8_t), (void *)vp)
354 #define bus_space_peek_2(t, h, o, vp) \
355 _bus_space_peek(t, h, o, sizeof(uint16_t), (void *)vp)
357 #define bus_space_peek_4(t, h, o, vp) \
358 _bus_space_peek(t, h, o, sizeof(uint32_t), (void *)vp)
361 * int bus_space_poke_N(bus_space_tag_t tag,
362 * bus_space_handle_t bsh, bus_size_t offset, uintN_t value);
364 * Cautiously write 1, 2, 4 or 8 byte quantity to bus space described
365 * by tag/handle/offset.
366 * If no hardware responds to the write access, the function returns a
370 #define bus_space_poke_1(t, h, o, v) \
371 _bus_space_poke(t, h, o, sizeof(uint8_t), v)
373 #define bus_space_poke_2(t, h, o, v) \
374 _bus_space_poke(t, h, o, sizeof(uint16_t), v)
376 #define bus_space_poke_4(t, h, o, v) \
377 _bus_space_poke(t, h, o, sizeof(uint32_t), v)
380 * uintN_t bus_space_read_N(bus_space_tag_t tag,
381 * bus_space_handle_t bsh, bus_size_t offset);
383 * Read a 1, 2, 4, or 8 byte quantity from bus space
384 * described by tag/handle/offset.
387 #define bus_space_read_1(t, h, o) \
388 ((void)t, *(volatile uint8_t *)((h) + (o)))
390 #define bus_space_read_2(t, h, o) \
391 ((void)t, *(volatile uint16_t *)((h) + (o)))
393 #define bus_space_read_4(t, h, o) \
394 ((void)t, *(volatile uint32_t *)((h) + (o)))
396 #define bus_space_read_8(t, h, o) \
397 ((void)t, *(volatile uint64_t *)((h) + (o)))
401 * void bus_space_write_N(bus_space_tag_t tag,
402 * bus_space_handle_t bsh, bus_size_t offset,
405 * Write the 1, 2, 4, or 8 byte value `value' to bus space
406 * described by tag/handle/offset.
409 #define bus_space_write_1(t, h, o, v) do { \
410 ((void)t, (void)(*(volatile uint8_t *)((h) + (o)) = (v))); \
413 #define bus_space_write_2(t, h, o, v) do { \
414 ((void)t, (void)(*(volatile uint16_t *)((h) + (o)) = (v))); \
417 #define bus_space_write_4(t, h, o, v) do { \
418 ((void)t, (void)(*(volatile uint32_t *)((h) + (o)) = (v))); \
421 #define bus_space_write_8(t, h, o, v) do { \
422 ((void)t, (void)(*(volatile uint64_t *)((h) + (o)) = (v))); \
427 * void bus_space_read_multi_N(bus_space_tag_t tag,
428 * bus_space_handle_t bsh, bus_size_t offset,
429 * uintN_t *addr, bus_size_t count);
431 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
432 * described by tag/handle/offset and copy into buffer provided.
435 void bus_space_read_multi_1(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
436 uint8_t *, bus_size_t
);
437 void bus_space_read_multi_2(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
438 uint16_t *, bus_size_t
);
439 void bus_space_read_multi_4(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
440 uint32_t *, bus_size_t
);
441 void bus_space_read_multi_8(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
442 uint64_t *, bus_size_t
);
445 bus_space_read_multi_1(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
446 uint8_t *a
, bus_size_t c
)
450 p
= (volatile uint8_t *)(h
+ o
);
456 bus_space_read_multi_2(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
457 uint16_t *a
, bus_size_t c
)
459 volatile uint16_t *p
;
461 p
= (volatile uint16_t *)(h
+ o
);
467 bus_space_read_multi_4(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
468 uint32_t *a
, bus_size_t c
)
470 volatile uint32_t *p
;
472 p
= (volatile uint32_t *)(h
+ o
);
478 bus_space_read_multi_8(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
479 uint64_t *a
, bus_size_t c
)
481 volatile uint64_t *p
;
483 p
= (volatile uint64_t *)(h
+ o
);
490 * void bus_space_write_multi_N(bus_space_tag_t tag,
491 * bus_space_handle_t bsh, bus_size_t offset,
492 * const u_intN_t *addr, bus_size_t count);
494 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
495 * provided to bus space described by tag/handle/offset.
497 void bus_space_write_multi_1(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
498 const uint8_t *, bus_size_t
);
499 void bus_space_write_multi_2(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
500 const uint16_t *, bus_size_t
);
501 void bus_space_write_multi_4(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
502 const uint32_t *, bus_size_t
);
503 void bus_space_write_multi_8(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
504 const uint64_t *, bus_size_t
);
507 bus_space_write_multi_1(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
508 const uint8_t *a
, bus_size_t c
)
512 p
= (volatile uint8_t *)(h
+ o
);
518 bus_space_write_multi_2(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
519 const uint16_t *a
, bus_size_t c
)
521 volatile uint16_t *p
;
523 p
= (volatile uint16_t *)(h
+ o
);
529 bus_space_write_multi_4(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
530 const uint32_t *a
, bus_size_t c
)
532 volatile uint32_t *p
;
534 p
= (volatile uint32_t *)(h
+ o
);
540 bus_space_write_multi_8(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
541 const uint64_t *a
, bus_size_t c
)
543 volatile uint64_t *p
;
545 p
= (volatile uint64_t *)(h
+ o
);
551 * void bus_space_set_multi_N(bus_space_tag_t tag,
552 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
555 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
556 * by tag/handle/offset `count' times.
558 void bus_space_set_multi_1(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
559 const uint8_t, bus_size_t
);
560 void bus_space_set_multi_2(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
561 const uint16_t, bus_size_t
);
562 void bus_space_set_multi_4(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
563 const uint32_t, bus_size_t
);
564 void bus_space_set_multi_8(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
565 const uint64_t, bus_size_t
);
568 bus_space_set_multi_1(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
569 const uint8_t v
, bus_size_t c
)
573 p
= (volatile uint8_t *)(h
+ o
);
579 bus_space_set_multi_2(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
580 const uint16_t v
, bus_size_t c
)
582 volatile uint16_t *p
;
584 p
= (volatile uint16_t *)(h
+ o
);
590 bus_space_set_multi_4(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
591 const uint32_t v
, bus_size_t c
)
593 volatile uint32_t *p
;
595 p
= (volatile uint32_t *)(h
+ o
);
601 bus_space_set_multi_8(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
602 const uint64_t v
, bus_size_t c
)
604 volatile uint64_t *p
;
606 p
= (volatile uint64_t *)(h
+ o
);
613 * void bus_space_read_region_N(bus_space_tag_t tag,
614 * bus_space_handle_t bsh, bus_size_t off,
615 * uintN_t *addr, bus_size_t count);
618 void bus_space_read_region_1(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
619 uint8_t *, bus_size_t
);
620 void bus_space_read_region_2(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
621 uint16_t *, bus_size_t
);
622 void bus_space_read_region_4(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
623 uint32_t *, bus_size_t
);
624 void bus_space_read_region_8(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
625 uint64_t *, bus_size_t
);
628 bus_space_read_region_1(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
629 uint8_t *a
, bus_size_t c
)
633 p
= (volatile uint8_t *)(h
+ o
);
638 bus_space_read_region_2(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
639 uint16_t *a
, bus_size_t c
)
641 volatile uint16_t *p
;
643 p
= (volatile uint16_t *)(h
+ o
);
648 bus_space_read_region_4(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
649 uint32_t *a
, bus_size_t c
)
651 volatile uint32_t *p
;
653 p
= (volatile uint32_t *)(h
+ o
);
658 bus_space_read_region_8(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
659 uint64_t *a
, bus_size_t c
)
661 volatile uint64_t *p
;
663 p
= (volatile uint64_t *)(h
+ o
);
669 * void bus_space_write_region_N(bus_space_tag_t tag,
670 * bus_space_handle_t bsh, bus_size_t off,
671 * uintN_t *addr, bus_size_t count);
674 void bus_space_write_region_1(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
675 const uint8_t *, bus_size_t
);
676 void bus_space_write_region_2(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
677 const uint16_t *, bus_size_t
);
678 void bus_space_write_region_4(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
679 const uint32_t *, bus_size_t
);
680 void bus_space_write_region_8(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
681 const uint64_t *, bus_size_t
);
684 bus_space_write_region_1(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
685 const uint8_t *a
, bus_size_t c
)
689 p
= (volatile uint8_t *)(h
+ o
);
695 bus_space_write_region_2(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
696 const uint16_t *a
, bus_size_t c
)
698 volatile uint16_t *p
;
700 p
= (volatile uint16_t *)(h
+ o
);
706 bus_space_write_region_4(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
707 const uint32_t *a
, bus_size_t c
)
709 volatile uint32_t *p
;
711 p
= (volatile uint32_t *)(h
+ o
);
717 bus_space_write_region_8(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
718 const uint64_t *a
, bus_size_t c
)
720 volatile uint64_t *p
;
722 p
= (volatile uint64_t *)(h
+ o
);
729 * void bus_space_set_region_N(bus_space_tag_t tag,
730 * bus_space_handle_t bsh, bus_size_t off,
731 * uintN_t *addr, bus_size_t count);
734 void bus_space_set_region_1(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
735 const uint8_t, bus_size_t
);
736 void bus_space_set_region_2(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
737 const uint16_t, bus_size_t
);
738 void bus_space_set_region_4(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
739 const uint32_t, bus_size_t
);
740 void bus_space_set_region_8(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
741 const uint64_t, bus_size_t
);
744 bus_space_set_region_1(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
745 const uint8_t v
, bus_size_t c
)
749 p
= (volatile uint8_t *)(h
+ o
);
755 bus_space_set_region_2(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
756 const uint16_t v
, bus_size_t c
)
758 volatile uint16_t *p
;
760 p
= (volatile uint16_t *)(h
+ o
);
766 bus_space_set_region_4(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
767 const uint32_t v
, bus_size_t c
)
769 volatile uint32_t *p
;
771 p
= (volatile uint32_t *)(h
+ o
);
777 bus_space_set_region_8(bus_space_tag_t t
, bus_space_handle_t h
, bus_size_t o
,
778 const uint64_t v
, bus_size_t c
)
780 volatile uint64_t *p
;
782 p
= (volatile uint64_t *)(h
+ o
);
789 * void bus_space_copy_region_N(bus_space_tag_t tag,
790 * bus_space_handle_t bsh1, bus_size_t off1,
791 * bus_space_handle_t bsh2, bus_size_t off2,
794 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
795 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
797 void bus_space_copy_region_1(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
798 bus_space_handle_t
, bus_size_t
, bus_size_t
);
799 void bus_space_copy_region_2(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
800 bus_space_handle_t
, bus_size_t
, bus_size_t
);
801 void bus_space_copy_region_4(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
802 bus_space_handle_t
, bus_size_t
, bus_size_t
);
803 void bus_space_copy_region_8(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
,
804 bus_space_handle_t
, bus_size_t
, bus_size_t
);
807 bus_space_copy_region_1(bus_space_tag_t t
, bus_space_handle_t h1
, bus_size_t o1
,
808 bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
810 volatile uint8_t *srcp
, *dstp
;
813 srcp
= (volatile uint8_t *)(h1
+ o1
);
814 dstp
= (volatile uint8_t *)(h2
+ o2
);
816 /* src after dest; copy forward */
817 for (offset
= 0; c
> 0; c
--, offset
++)
818 dstp
[offset
] = srcp
[offset
];
820 /* dst after src; copy backward */
821 for (offset
= c
; c
> 0; c
--, offset
--)
822 dstp
[offset
] = srcp
[offset
];
827 bus_space_copy_region_2(bus_space_tag_t t
, bus_space_handle_t h1
, bus_size_t o1
,
828 bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
830 volatile uint16_t *srcp
, *dstp
;
833 srcp
= (volatile uint16_t *)(h1
+ o1
);
834 dstp
= (volatile uint16_t *)(h2
+ o2
);
836 /* src after dest; copy forward */
837 for (offset
= 0; c
> 0; c
--, offset
++)
838 dstp
[offset
] = srcp
[offset
];
840 /* dst after src; copy backward */
841 for (offset
= c
; c
> 0; c
--, offset
--)
842 dstp
[offset
] = srcp
[offset
];
847 bus_space_copy_region_4(bus_space_tag_t t
, bus_space_handle_t h1
, bus_size_t o1
,
848 bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
850 volatile uint32_t *srcp
, *dstp
;
853 srcp
= (volatile uint32_t *)(h1
+ o1
);
854 dstp
= (volatile uint32_t *)(h2
+ o2
);
856 /* src after dest; copy forward */
857 for (offset
= 0; c
> 0; c
--, offset
++)
858 dstp
[offset
] = srcp
[offset
];
860 /* dst after src; copy backward */
861 for (offset
= c
; c
> 0; c
--, offset
--)
862 dstp
[offset
] = srcp
[offset
];
867 bus_space_copy_region_8(bus_space_tag_t t
, bus_space_handle_t h1
, bus_size_t o1
,
868 bus_space_handle_t h2
, bus_size_t o2
, bus_size_t c
)
870 volatile uint64_t *srcp
, *dstp
;
873 srcp
= (volatile uint64_t *)(h1
+ o1
);
874 dstp
= (volatile uint64_t *)(h2
+ o2
);
876 /* src after dest; copy forward */
877 for (offset
= 0; c
> 0; c
--, offset
++)
878 dstp
[offset
] = srcp
[offset
];
880 /* dst after src; copy backward */
881 for (offset
= c
; c
> 0; c
--, offset
--)
882 dstp
[offset
] = srcp
[offset
];
887 * void bus_space_copyin(bus_space_tag_t tag,
888 * bus_space_handle_t bsh, bus_size_t off,
889 * void *addr, bus_size_t count);
891 * Copy `count' bytes from bus space starting at tag/bsh/off
892 * to kernel memory at addr using the most optimized transfer
893 * possible for the bus.
896 #define bus_space_copyin(t, h, o, a, c) \
897 ((void)t, w16copy((uint8_t *)((h) + (o)), (a), (c)))
900 * void bus_space_copyout(bus_space_tag_t tag,
901 * bus_space_handle_t bsh, bus_size_t off,
902 * const void *addr, bus_size_t count);
904 * Copy `count' bytes to bus space starting at tag/bsh/off
905 * from kernel memory at addr using the most optimized transfer
906 * possible for the bus.
909 #define bus_space_copyout(t, h, o, a, c) \
910 ((void)t, w16copy((a), (uint8_t *)((h) + (o)), (c)))
912 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
914 int find_prom_map(paddr_t
, bus_type_t
, int, vaddr_t
*);
916 /*--------------------------------*/
919 * Flags used in various bus DMA methods.
921 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
922 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
923 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
924 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
925 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
926 #define BUS_DMA_BUS2 0x020
927 #define BUS_DMA_BUS3 0x040
928 #define BUS_DMA_BUS4 0x080
929 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
930 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
931 #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
933 /* For devices that have a 24-bit address space */
934 #define BUS_DMA_24BIT BUS_DMA_BUS1
936 /* Internal flag: current DVMA address is equal to the KVA buffer address */
937 #define _BUS_DMA_DIRECTMAP BUS_DMA_BUS2
940 * Internal flag: current DVMA address has been double-mapped by hand
941 * to the KVA buffer address (without the pmap's help).
943 #define _BUS_DMA_NOPMAP BUS_DMA_BUS3
945 /* Forwards needed by prototypes below. */
950 * Operations performed by bus_dmamap_sync().
952 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
953 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
954 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
955 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
957 typedef struct sun68k_bus_dma_tag
*bus_dma_tag_t
;
958 typedef struct sun68k_bus_dmamap
*bus_dmamap_t
;
960 #define BUS_DMA_TAG_VALID(t) ((t) != NULL)
965 * Describes a single contiguous DMA transaction. Values
966 * are suitable for programming into DMA registers.
968 struct sun68k_bus_dma_segment
{
969 bus_addr_t ds_addr
; /* DVMA address */
970 bus_size_t ds_len
; /* length of transfer */
971 bus_size_t _ds_sgsize
; /* size of allocated DVMA segment */
972 void *_ds_mlist
; /* page list when dmamem_alloc'ed */
973 vaddr_t _ds_va
; /* VA when dmamem_map'ed */
975 typedef struct sun68k_bus_dma_segment bus_dma_segment_t
;
981 * A machine-dependent opaque type describing the implementation of
982 * DMA for a given bus.
984 struct sun68k_bus_dma_tag
{
985 void *_cookie
; /* cookie used in the guts */
988 * DMA mapping methods.
990 int (*_dmamap_create
)(bus_dma_tag_t
, bus_size_t
, int, bus_size_t
,
991 bus_size_t
, int, bus_dmamap_t
*);
992 void (*_dmamap_destroy
)(bus_dma_tag_t
, bus_dmamap_t
);
993 int (*_dmamap_load
)(bus_dma_tag_t
, bus_dmamap_t
, void *, bus_size_t
,
995 int (*_dmamap_load_mbuf
)(bus_dma_tag_t
, bus_dmamap_t
, struct mbuf
*,
997 int (*_dmamap_load_uio
)(bus_dma_tag_t
, bus_dmamap_t
, struct uio
*,
999 int (*_dmamap_load_raw
)(bus_dma_tag_t
, bus_dmamap_t
,
1000 bus_dma_segment_t
*, int, bus_size_t
, int);
1001 void (*_dmamap_unload
)(bus_dma_tag_t
, bus_dmamap_t
);
1002 void (*_dmamap_sync
)(bus_dma_tag_t
, bus_dmamap_t
, bus_addr_t
,
1006 * DMA memory utility functions.
1008 int (*_dmamem_alloc
)(bus_dma_tag_t
, bus_size_t
, bus_size_t
,
1009 bus_size_t
, bus_dma_segment_t
*, int, int *, int);
1010 void (*_dmamem_free
)(bus_dma_tag_t
, bus_dma_segment_t
*, int);
1011 int (*_dmamem_map
)(bus_dma_tag_t
, bus_dma_segment_t
*, int, size_t,
1013 void (*_dmamem_unmap
)(bus_dma_tag_t
, void *, size_t);
1014 paddr_t (*_dmamem_mmap
)(bus_dma_tag_t
, bus_dma_segment_t
*, int, off_t
,
1018 #define bus_dmamap_create(t, s, n, m, b, f, p) \
1019 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
1020 #define bus_dmamap_destroy(t, p) \
1021 (*(t)->_dmamap_destroy)((t), (p))
1022 #define bus_dmamap_load(t, m, b, s, p, f) \
1023 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
1024 #define bus_dmamap_load_mbuf(t, m, b, f) \
1025 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
1026 #define bus_dmamap_load_uio(t, m, u, f) \
1027 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
1028 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
1029 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
1030 #define bus_dmamap_unload(t, p) \
1031 (*(t)->_dmamap_unload)((t), (p))
1032 #define bus_dmamap_sync(t, p, o, l, ops) \
1033 (void)((t)->_dmamap_sync ? \
1034 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) : (void)0)
1036 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
1037 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
1038 #define bus_dmamem_free(t, sg, n) \
1039 (*(t)->_dmamem_free)((t), (sg), (n))
1040 #define bus_dmamem_map(t, sg, n, s, k, f) \
1041 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
1042 #define bus_dmamem_unmap(t, k, s) \
1043 (*(t)->_dmamem_unmap)((t), (k), (s))
1044 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
1045 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
1047 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
1048 #define bus_dmatag_destroy(t)
1053 * Describes a DMA mapping.
1055 struct sun68k_bus_dmamap
{
1057 * PRIVATE MEMBERS: not for use by machine-independent code.
1059 bus_size_t _dm_size
; /* largest DMA transfer mappable */
1060 int _dm_segcnt
; /* number of segs this map can map */
1061 bus_size_t _dm_maxmaxsegsz
; /* fixed largest possible segment */
1062 bus_size_t _dm_boundary
; /* don't cross this */
1063 int _dm_flags
; /* misc. flags */
1065 void *_dm_cookie
; /* cookie for bus-specific functions */
1067 u_long _dm_align
; /* DVMA alignment; must be a
1068 multiple of the page size */
1069 u_long _dm_ex_start
; /* constraints on DVMA map */
1070 u_long _dm_ex_end
; /* allocations; used by the VME bus
1071 driver and by the IOMMU driver
1072 when mapping 24-bit devices */
1075 * PUBLIC MEMBERS: these are used by machine-independent code.
1077 bus_size_t dm_maxsegsz
; /* largest possible segment */
1078 bus_size_t dm_mapsize
; /* size of the mapping */
1079 int dm_nsegs
; /* # valid segments in mapping */
1080 bus_dma_segment_t dm_segs
[1]; /* segments; variable length */
1083 #ifdef _SUN68K_BUS_DMA_PRIVATE
1084 int _bus_dmamap_create(bus_dma_tag_t
, bus_size_t
, int, bus_size_t
,
1085 bus_size_t
, int, bus_dmamap_t
*);
1086 void _bus_dmamap_destroy(bus_dma_tag_t
, bus_dmamap_t
);
1087 int _bus_dmamap_load_mbuf(bus_dma_tag_t
, bus_dmamap_t
, struct mbuf
*, int);
1088 int _bus_dmamap_load_uio(bus_dma_tag_t
, bus_dmamap_t
, struct uio
*, int);
1089 int _bus_dmamap_load_raw(bus_dma_tag_t
, bus_dmamap_t
, bus_dma_segment_t
*,
1090 int, bus_size_t
, int);
1091 int _bus_dmamap_load(bus_dma_tag_t
, bus_dmamap_t
, void *, bus_size_t
,
1092 struct proc
*, int);
1093 void _bus_dmamap_unload(bus_dma_tag_t
, bus_dmamap_t
);
1094 void _bus_dmamap_sync(bus_dma_tag_t
, bus_dmamap_t
, bus_addr_t
, bus_size_t
,
1097 int _bus_dmamem_alloc(bus_dma_tag_t
, bus_size_t
, bus_size_t
, bus_size_t
,
1098 bus_dma_segment_t
*, int, int *, int);
1099 void _bus_dmamem_free(bus_dma_tag_t
, bus_dma_segment_t
*, int);
1100 int _bus_dmamem_map(bus_dma_tag_t
, bus_dma_segment_t
*, int, size_t,
1102 void _bus_dmamem_unmap(bus_dma_tag_t
, void *, size_t);
1103 paddr_t
_bus_dmamem_mmap(bus_dma_tag_t
, bus_dma_segment_t
*, int, off_t
, int,
1106 int _bus_dmamem_alloc_range(bus_dma_tag_t
, bus_size_t
, bus_size_t
,
1107 bus_size_t
, bus_dma_segment_t
*, int, int *, int, vaddr_t
, vaddr_t
);
1109 vaddr_t
_bus_dma_valloc_skewed(size_t, u_long
, u_long
, u_long
);
1110 #endif /* _SUN68K_BUS_DMA_PRIVATE */
1112 #endif /* _SUN68K_BUS_H_ */