1 /* $NetBSD: bus_space.h,v 1.14 2006/02/16 20:17:14 perry 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 _NEXT68K_BUS_SPACE_H_
60 #define _NEXT68K_BUS_SPACE_H_
62 * Addresses (in bus space).
64 typedef u_long bus_addr_t
;
65 typedef u_long bus_size_t
;
68 * Access methods for bus resources and address space.
70 typedef volatile char * bus_space_tag_t
;
71 typedef u_long bus_space_handle_t
;
74 * Value for the next68k bus space tag, not to be used directly by MI code.
76 #define NEXT68K_INTIO_BUS_SPACE ((bus_space_tag_t)intiobase)
79 * Values for the next68k video bus space tags, not to be used directly
82 #define NEXT68K_MONO_VIDEO_BUS_SPACE ((bus_space_tag_t)monobase)
83 #define NEXT68K_COLOR_VIDEO_BUS_SPACE ((bus_space_tag_t)colorbase)
86 * Mapping and unmapping operations.
88 #define bus_space_map(t, a, s, f, hp) \
89 ((((a)>=INTIOBASE)&&((a)+(s)<INTIOTOP)) ? \
90 ((*(hp)=(bus_space_handle_t)((t)+((a)-INTIOBASE))),0) : \
91 ((((a)>=MONOBASE)&&((a)+(s)<MONOTOP)) ? \
92 ((*(hp)=(bus_space_handle_t)((t)+((a)-MONOBASE))),0) : \
93 ((((a)>=COLORBASE)&&((a)+(s)<COLORTOP)) ? \
94 ((*(hp)=(bus_space_handle_t)((t)+((a)-COLORBASE))),0) : (-1))))
96 #define bus_space_unmap(t, h, s)
98 #define bus_space_subregion(t, h, o, s, hp) \
101 #define BUS_SPACE_MAP_CACHEABLE 0x01
102 #define BUS_SPACE_MAP_LINEAR 0x02
105 * Allocation and deallocation operations.
107 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
110 #define bus_space_free(t, h, s)
113 * paddr_t bus_space_mmap(bus_space_tag_t t, bus_addr_t base,
114 * off_t offset, int prot, int flags);
116 * Mmap an area of bus space.
119 #define bus_space_mmap(t, a, s, prot, flags) \
120 ((((a)>=INTIOBASE)&&((a)+(s)<INTIOTOP)) ? \
121 m68k_btop((t)+((a)-INTIOBASE)) : \
122 ((((a)>=MONOBASE)&&((a)+(s)<MONOTOP)) ? \
123 m68k_btop((t)+((a)-MONOBASE)) : \
124 ((((a)>=COLORBASE)&&((a)+(s)<COLORTOP)) ? \
125 m68k_btop((t)+((a)-COLORBASE)) : (-1))))
128 * u_intN_t bus_space_read_N(bus_space_tag_t tag,
129 * bus_space_handle_t bsh, bus_size_t offset);
131 * Read a 1, 2, 4, or 8 byte quantity from bus space
132 * described by tag/handle/offset.
135 #define bus_space_read_1(t, h, o) \
136 ((void) t, (*(volatile u_int8_t *)((h) + (o))))
138 #define bus_space_read_2(t, h, o) \
139 ((void) t, (*(volatile u_int16_t *)((h) + (o))))
141 #define bus_space_read_4(t, h, o) \
142 ((void) t, (*(volatile u_int32_t *)((h) + (o))))
144 #if 0 /* Cause a link error for bus_space_read_8 */
145 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
149 * void bus_space_read_multi_N(bus_space_tag_t tag,
150 * bus_space_handle_t bsh, bus_size_t offset,
151 * u_intN_t *addr, size_t count);
153 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
154 * described by tag/handle/offset and copy into buffer provided.
157 #define bus_space_read_multi_1(t, h, o, a, c) do { \
163 1: movb %%a0@,%%a1@+ ; \
167 "r" ((h) + (o)), "g" (a), "g" (c) : \
171 #define bus_space_read_multi_2(t, h, o, a, c) do { \
177 1: movw %%a0@,%%a1@+ ; \
181 "r" ((h) + (o)), "g" (a), "g" (c) : \
185 #define bus_space_read_multi_4(t, h, o, a, c) do { \
191 1: movl %%a0@,%%a1@+ ; \
195 "r" ((h) + (o)), "g" (a), "g" (c) : \
199 #if 0 /* Cause a link error for bus_space_read_multi_8 */
200 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
204 * void bus_space_read_region_N(bus_space_tag_t tag,
205 * bus_space_handle_t bsh, bus_size_t offset,
206 * u_intN_t *addr, size_t count);
208 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
209 * described by tag/handle and starting at `offset' and copy into
213 #define bus_space_read_region_1(t, h, o, a, c) do { \
219 1: movb %%a0@+,%%a1@+ ; \
223 "r" ((h) + (o)), "g" (a), "g" (c) : \
227 #define bus_space_read_region_2(t, h, o, a, c) do { \
233 1: movw %%a0@+,%%a1@+ ; \
237 "r" ((h) + (o)), "g" (a), "g" (c) : \
241 #define bus_space_read_region_4(t, h, o, a, c) do { \
247 1: movl %%a0@+,%%a1@+ ; \
251 "r" ((h) + (o)), "g" (a), "g" (c) : \
255 #if 0 /* Cause a link error for bus_space_read_region_8 */
256 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
260 * void bus_space_write_N(bus_space_tag_t tag,
261 * bus_space_handle_t bsh, bus_size_t offset,
264 * Write the 1, 2, 4, or 8 byte value `value' to bus space
265 * described by tag/handle/offset.
268 #define bus_space_write_1(t, h, o, v) \
269 ((void) t, ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))))
271 #define bus_space_write_2(t, h, o, v) \
272 ((void) t, ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))))
274 #define bus_space_write_4(t, h, o, v) \
275 ((void) t, ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))))
277 #if 0 /* Cause a link error for bus_space_write_8 */
278 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
282 * void bus_space_write_multi_N(bus_space_tag_t tag,
283 * bus_space_handle_t bsh, bus_size_t offset,
284 * const u_intN_t *addr, size_t count);
286 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
287 * provided to bus space described by tag/handle/offset.
290 #define bus_space_write_multi_1(t, h, o, a, c) do { \
296 1: movb %%a1@+,%%a0@ ; \
300 "r" ((h) + (o)), "g" (a), "g" (c) : \
304 #define bus_space_write_multi_2(t, h, o, a, c) do { \
310 1: movw %%a1@+,%%a0@ ; \
314 "r" ((h) + (o)), "g" (a), "g" (c) : \
318 #define bus_space_write_multi_4(t, h, o, a, c) do { \
324 1: movl %%a1@+,%%a0@ ; \
328 "r" ((h) + (o)), "g" (a), "g" (c) : \
332 #if 0 /* Cause a link error for bus_space_write_8 */
333 #define bus_space_write_multi_8(t, h, o, a, c) \
334 !!! bus_space_write_multi_8 unimplimented !!!
338 * void bus_space_write_region_N(bus_space_tag_t tag,
339 * bus_space_handle_t bsh, bus_size_t offset,
340 * const u_intN_t *addr, size_t count);
342 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
343 * to bus space described by tag/handle starting at `offset'.
346 #define bus_space_write_region_1(t, h, o, a, c) do { \
352 1: movb %%a1@+,%%a0@+ ; \
356 "r" ((h) + (o)), "g" (a), "g" (c) : \
360 #define bus_space_write_region_2(t, h, o, a, c) do { \
366 1: movw %%a1@+,%%a0@+ ; \
370 "r" ((h) + (o)), "g" (a), "g" (c) : \
374 #define bus_space_write_region_4(t, h, o, a, c) do { \
380 1: movl %%a1@+,%%a0@+ ; \
384 "r" ((h) + (o)), "g" (a), "g" (c) : \
388 #if 0 /* Cause a link error for bus_space_write_region_8 */
389 #define bus_space_write_region_8 \
390 !!! bus_space_write_region_8 unimplemented !!!
394 * void bus_space_set_multi_N(bus_space_tag_t tag,
395 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
398 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
399 * by tag/handle/offset `count' times.
402 #define bus_space_set_multi_1(t, h, o, val, c) do { \
408 1: movb %%d1,%%a0@ ; \
412 "r" ((h) + (o)), "g" (val), "g" (c) : \
416 #define bus_space_set_multi_2(t, h, o, val, c) do { \
422 1: movw %%d1,%%a0@ ; \
426 "r" ((h) + (o)), "g" (val), "g" (c) : \
430 #define bus_space_set_multi_4(t, h, o, val, c) do { \
436 1: movl %%d1,%%a0@ ; \
440 "r" ((h) + (o)), "g" (val), "g" (c) : \
444 #if 0 /* Cause a link error for bus_space_set_multi_8 */
445 #define bus_space_set_multi_8 \
446 !!! bus_space_set_multi_8 unimplemented !!!
450 * void bus_space_set_region_N(bus_space_tag_t tag,
451 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
454 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
455 * by tag/handle starting at `offset'.
458 #define bus_space_set_region_1(t, h, o, val, c) do { \
464 1: movb %%d1,%%a0@+ ; \
468 "r" ((h) + (o)), "g" (val), "g" (c) : \
472 #define bus_space_set_region_2(t, h, o, val, c) do { \
478 1: movw %%d1,%%a0@+ ; \
482 "r" ((h) + (o)), "g" (val), "g" (c) : \
486 #define bus_space_set_region_4(t, h, o, val, c) do { \
492 1: movl %%d1,%%a0@+ ; \
496 "r" ((h) + (o)), "g" (val), "g" (c) : \
500 #if 0 /* Cause a link error for bus_space_set_region_8 */
501 #define bus_space_set_region_8 \
502 !!! bus_space_set_region_8 unimplemented !!!
506 * void bus_space_copy_N(bus_space_tag_t tag,
507 * bus_space_handle_t bsh1, bus_size_t off1,
508 * bus_space_handle_t bsh2, bus_size_t off2,
511 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
512 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
515 #define __NEXT68K_copy_region_N(BYTES) \
516 static __inline void __CONCAT(bus_space_copy_region_,BYTES) \
518 bus_space_handle_t, bus_size_t, \
519 bus_space_handle_t, bus_size_t, \
522 static __inline void \
523 __CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c) \
525 bus_space_handle_t h1, h2; \
526 bus_size_t o1, o2, c; \
530 if ((h1 + o1) >= (h2 + o2)) { \
531 /* src after dest: copy forward */ \
532 for (o = 0; c != 0; c--, o += BYTES) \
533 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
534 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
536 /* dest after src: copy backwards */ \
537 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
538 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
539 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
542 __NEXT68K_copy_region_N(1)
543 __NEXT68K_copy_region_N(2)
544 __NEXT68K_copy_region_N(4)
545 #if 0 /* Cause a link error for bus_space_copy_8 */
546 #define bus_space_copy_8 \
547 !!! bus_space_copy_8 unimplemented !!!
550 #undef __NEXT68K_copy_region_N
553 * Bus read/write barrier methods.
555 * void bus_space_barrier(bus_space_tag_t tag,
556 * bus_space_handle_t bsh, bus_size_t offset,
557 * bus_size_t len, int flags);
559 * Note: the 680x0 does not currently require barriers, but we must
560 * provide the flags to MI code.
562 #define bus_space_barrier(t, h, o, l, f) \
563 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
564 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
565 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
567 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
569 #endif /* _NEXT68K_BUS_SPACE_H_ */