1 /* $NetBSD: bus.h,v 1.9 2008/04/28 20:23:26 martin Exp $ */
4 * Copyright (c) 1996, 1997, 1998 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 Scott Reynolds. All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. The name of the author may not be used to endorse or promote products
45 * derived from this software without specific prior written permission
47 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 #ifndef _MACHINE_BUS_H_
60 #define _MACHINE_BUS_H_
63 * Value for the luna68k bus space tag, not to be used directly by MI code.
65 #define MACHINE_BUS_SPACE_MEM 0 /* space is mem space */
68 * Bus address and size types
70 typedef u_long bus_addr_t
;
71 typedef u_long bus_size_t
;
74 * Access methods for bus resources and address space.
76 typedef int bus_space_tag_t
;
77 typedef u_long bus_space_handle_t
;
80 * int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
81 * bus_size_t size, int flags, bus_space_handle_t *bshp);
83 * Map a region of bus space.
86 #define BUS_SPACE_MAP_CACHEABLE 0x01
87 #define BUS_SPACE_MAP_LINEAR 0x02
88 #define BUS_SPACE_MAP_PREFETCHABLE 0x04
90 int bus_space_map(bus_space_tag_t
, bus_addr_t
, bus_size_t
,
91 int, bus_space_handle_t
*);
94 * void bus_space_unmap(bus_space_tag_t t,
95 * bus_space_handle_t bsh, bus_size_t size);
97 * Unmap a region of bus space.
100 void bus_space_unmap(bus_space_tag_t
, bus_space_handle_t
, bus_size_t
);
103 * int bus_space_subregion(bus_space_tag_t t,
104 * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
105 * bus_space_handle_t *nbshp);
107 * Get a new handle for a subregion of an already-mapped area of bus space.
110 int bus_space_subregion(bus_space_tag_t t
, bus_space_handle_t bsh
,
111 bus_size_t offset
, bus_size_t size
, bus_space_handle_t
*nbshp
);
114 * int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
115 * bus_addr_t rend, bus_size_t size, bus_size_t align,
116 * bus_size_t boundary, int flags, bus_addr_t *addrp,
117 * bus_space_handle_t *bshp);
119 * Allocate a region of bus space.
122 int bus_space_alloc(bus_space_tag_t t
, bus_addr_t rstart
,
123 bus_addr_t rend
, bus_size_t size
, bus_size_t align
,
124 bus_size_t boundary
, int cacheable
, bus_addr_t
*addrp
,
125 bus_space_handle_t
*bshp
);
128 * int bus_space_free(bus_space_tag_t t,
129 * bus_space_handle_t bsh, bus_size_t size);
131 * Free a region of bus space.
134 void bus_space_free(bus_space_tag_t t
, bus_space_handle_t bsh
,
138 * u_intN_t bus_space_read_N(bus_space_tag_t tag,
139 * bus_space_handle_t bsh, bus_size_t offset);
141 * Read a 1, 2, 4, or 8 byte quantity from bus space
142 * described by tag/handle/offset.
145 #define bus_space_read_1(t, h, o) \
146 ((void) t, (*(volatile u_int8_t *)((h) + 4*(o))))
148 #define bus_space_read_2(t, h, o) \
149 ((void) t, (*(volatile u_int16_t *)((h) + 4*(o))))
151 #define bus_space_read_4(t, h, o) \
152 ((void) t, (*(volatile u_int32_t *)((h) + 4*(o))))
154 #if 0 /* Cause a link error for bus_space_read_8 */
155 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
159 * void bus_space_read_multi_N(bus_space_tag_t tag,
160 * bus_space_handle_t bsh, bus_size_t offset,
161 * u_intN_t *addr, size_t count);
163 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
164 * described by tag/handle/offset and copy into buffer provided.
167 #define bus_space_read_multi_1(t, h, o, a, c) do { \
173 1: movb %%a0@,%%a1@+ ; \
177 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
181 #define bus_space_read_multi_2(t, h, o, a, c) do { \
187 1: movw %%a0@,%%a1@+ ; \
191 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
195 #define bus_space_read_multi_4(t, h, o, a, c) do { \
201 1: movl %%a0@,%%a1@+ ; \
205 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
209 #if 0 /* Cause a link error for bus_space_read_multi_8 */
210 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
214 * void bus_space_read_region_N(bus_space_tag_t tag,
215 * bus_space_handle_t bsh, bus_size_t offset,
216 * u_intN_t *addr, size_t count);
218 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
219 * described by tag/handle and starting at `offset' and copy into
223 #define bus_space_read_region_1(t, h, o, a, c) do { \
229 1: movb %%a0@+,%%a1@+ ; \
233 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
237 #define bus_space_read_region_2(t, h, o, a, c) do { \
243 1: movw %%a0@+,%%a1@+ ; \
247 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
251 #define bus_space_read_region_4(t, h, o, a, c) do { \
257 1: movl %%a0@+,%%a1@+ ; \
261 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
265 #if 0 /* Cause a link error for bus_space_read_region_8 */
266 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
270 * void bus_space_write_N(bus_space_tag_t tag,
271 * bus_space_handle_t bsh, bus_size_t offset,
274 * Write the 1, 2, 4, or 8 byte value `value' to bus space
275 * described by tag/handle/offset.
278 #define bus_space_write_1(t, h, o, v) \
279 ((void) t, ((void)(*(volatile u_int8_t *)((h) + 4*(o)) = (v))))
281 #define bus_space_write_2(t, h, o, v) \
282 ((void) t, ((void)(*(volatile u_int16_t *)((h) + 4*(o)) = (v))))
284 #define bus_space_write_4(t, h, o, v) \
285 ((void) t, ((void)(*(volatile u_int32_t *)((h) + 4*(o)) = (v))))
287 #if 0 /* Cause a link error for bus_space_write_8 */
288 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
292 * void bus_space_write_multi_N(bus_space_tag_t tag,
293 * bus_space_handle_t bsh, bus_size_t offset,
294 * const u_intN_t *addr, size_t count);
296 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
297 * provided to bus space described by tag/handle/offset.
300 #define bus_space_write_multi_1(t, h, o, a, c) do { \
306 1: movb %%a1@+,%%a0@ ; \
310 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
314 #define bus_space_write_multi_2(t, h, o, a, c) do { \
320 1: movw %%a1@+,%%a0@ ; \
324 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
328 #define bus_space_write_multi_4(t, h, o, a, c) do { \
334 1: movl %%a1@+,%%a0@ ; \
338 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
342 #if 0 /* Cause a link error for bus_space_write_8 */
343 #define bus_space_write_multi_8(t, h, o, a, c) \
344 !!! bus_space_write_multi_8 unimplimented !!!
348 * void bus_space_write_region_N(bus_space_tag_t tag,
349 * bus_space_handle_t bsh, bus_size_t offset,
350 * const u_intN_t *addr, size_t count);
352 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
353 * to bus space described by tag/handle starting at `offset'.
356 #define bus_space_write_region_1(t, h, o, a, c) do { \
362 1: movb %%a1@+,%%a0@+ ; \
366 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
370 #define bus_space_write_region_2(t, h, o, a, c) do { \
376 1: movw %%a1@+,%%a0@+ ; \
380 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
384 #define bus_space_write_region_4(t, h, o, a, c) do { \
390 1: movl %%a1@+,%%a0@+ ; \
394 "r" ((h) + (o)), "g" (a), "g" ((size_t)(c)) : \
398 #if 0 /* Cause a link error for bus_space_write_region_8 */
399 #define bus_space_write_region_8 \
400 !!! bus_space_write_region_8 unimplemented !!!
404 * void bus_space_set_multi_N(bus_space_tag_t tag,
405 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
408 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
409 * by tag/handle/offset `count' times.
412 #define bus_space_set_multi_1(t, h, o, val, c) do { \
418 1: movb %%d1,%%a0@ ; \
422 "r" ((h)+(o)), "g" ((u_long)val), \
423 "g" ((size_t)(c)) : \
427 #define bus_space_set_multi_2(t, h, o, val, c) do { \
433 1: movw %%d1,%%a0@ ; \
437 "r" ((h)+(o)), "g" ((u_long)val), \
438 "g" ((size_t)(c)) : \
442 #define bus_space_set_multi_4(t, h, o, val, c) do { \
448 1: movl %%d1,%%a0@ ; \
452 "r" ((h)+(o)), "g" ((u_long)val), \
453 "g" ((size_t)(c)) : \
457 #if 0 /* Cause a link error for bus_space_set_multi_8 */
458 #define bus_space_set_multi_8 \
459 !!! bus_space_set_multi_8 unimplemented !!!
463 * void bus_space_set_region_N(bus_space_tag_t tag,
464 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
467 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
468 * by tag/handle starting at `offset'.
471 #define bus_space_set_region_1(t, h, o, val, c) do { \
477 1: movb %%d1,%%a0@+ ; \
481 "r" ((h)+(o)), "g" ((u_long)val), \
482 "g" ((size_t)(c)) : \
486 #define bus_space_set_region_2(t, h, o, val, c) do { \
492 1: movw %%d1,%%a0@+ ; \
496 "r" ((h)+(o)), "g" ((u_long)val), \
497 "g" ((size_t)(c)) : \
501 #define bus_space_set_region_4(t, h, o, val, c) do { \
507 1: movl %%d1,%%a0@+ ; \
511 "r" ((h)+(o)), "g" ((u_long)val), \
512 "g" ((size_t)(c)) : \
516 #if 0 /* Cause a link error for bus_space_set_region_8 */
517 #define bus_space_set_region_8 \
518 !!! bus_space_set_region_8 unimplemented !!!
522 * void bus_space_copy_N(bus_space_tag_t tag,
523 * bus_space_handle_t bsh1, bus_size_t off1,
524 * bus_space_handle_t bsh2, bus_size_t off2,
527 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
528 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
531 #define __MACHINE_copy_region_N(BYTES) \
532 static __inline void __CONCAT(bus_space_copy_region_,BYTES) \
534 bus_space_handle_t bsh1, bus_size_t off1, \
535 bus_space_handle_t bsh2, bus_size_t off2, \
538 static __inline void \
539 __CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c) \
541 bus_space_handle_t h1, h2; \
542 bus_size_t o1, o2, c; \
546 if ((h1 + o1) >= (h2 + o2)) { \
547 /* src after dest: copy forward */ \
548 for (o = 0; c != 0; c--, o += BYTES) \
549 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
550 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
552 /* dest after src: copy backwards */ \
553 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
554 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
555 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
558 __MACHINE_copy_region_N(1)
559 __MACHINE_copy_region_N(2)
560 __MACHINE_copy_region_N(4)
561 #if 0 /* Cause a link error for bus_space_copy_8 */
562 #define bus_space_copy_8 \
563 !!! bus_space_copy_8 unimplemented !!!
566 #undef __MACHINE_copy_region_N
569 * Bus read/write barrier methods.
571 * void bus_space_barrier(bus_space_tag_t tag,
572 * bus_space_handle_t bsh, bus_size_t offset,
573 * bus_size_t len, int flags);
575 * Note: the 680x0 does not currently require barriers, but we must
576 * provide the flags to MI code.
578 #define bus_space_barrier(t, h, o, l, f) \
579 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
580 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
581 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
583 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
585 #endif /* _MACHINE_BUS_H_ */