Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / next68k / include / bus_space.h
blobfaf5f2494ae939ab56fa655f243383a518ddb183
1 /* $NetBSD: bus_space.h,v 1.14 2006/02/16 20:17:14 perry Exp $ */
3 /*-
4 * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
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
13 * are met:
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
38 * are met:
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
80 * by MI code.
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) \
99 (*(hp)=(h)+(o))
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) \
108 (-1)
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 !!!
146 #endif
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 { \
158 (void) t; \
159 __asm volatile (" \
160 movl %0,%%a0 ; \
161 movl %1,%%a1 ; \
162 movl %2,%%d0 ; \
163 1: movb %%a0@,%%a1@+ ; \
164 subql #1,%%d0 ; \
165 jne 1b" : \
167 "r" ((h) + (o)), "g" (a), "g" (c) : \
168 "a0","a1","d0"); \
169 } while (0);
171 #define bus_space_read_multi_2(t, h, o, a, c) do { \
172 (void) t; \
173 __asm volatile (" \
174 movl %0,%%a0 ; \
175 movl %1,%%a1 ; \
176 movl %2,%%d0 ; \
177 1: movw %%a0@,%%a1@+ ; \
178 subql #1,%%d0 ; \
179 jne 1b" : \
181 "r" ((h) + (o)), "g" (a), "g" (c) : \
182 "a0","a1","d0"); \
183 } while (0);
185 #define bus_space_read_multi_4(t, h, o, a, c) do { \
186 (void) t; \
187 __asm volatile (" \
188 movl %0,%%a0 ; \
189 movl %1,%%a1 ; \
190 movl %2,%%d0 ; \
191 1: movl %%a0@,%%a1@+ ; \
192 subql #1,%%d0 ; \
193 jne 1b" : \
195 "r" ((h) + (o)), "g" (a), "g" (c) : \
196 "a0","a1","d0"); \
197 } while (0);
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 !!!
201 #endif
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
210 * buffer provided.
213 #define bus_space_read_region_1(t, h, o, a, c) do { \
214 (void) t; \
215 __asm volatile (" \
216 movl %0,%%a0 ; \
217 movl %1,%%a1 ; \
218 movl %2,%%d0 ; \
219 1: movb %%a0@+,%%a1@+ ; \
220 subql #1,%%d0 ; \
221 jne 1b" : \
223 "r" ((h) + (o)), "g" (a), "g" (c) : \
224 "a0","a1","d0"); \
225 } while (0);
227 #define bus_space_read_region_2(t, h, o, a, c) do { \
228 (void) t; \
229 __asm volatile (" \
230 movl %0,%%a0 ; \
231 movl %1,%%a1 ; \
232 movl %2,%%d0 ; \
233 1: movw %%a0@+,%%a1@+ ; \
234 subql #1,%%d0 ; \
235 jne 1b" : \
237 "r" ((h) + (o)), "g" (a), "g" (c) : \
238 "a0","a1","d0"); \
239 } while (0);
241 #define bus_space_read_region_4(t, h, o, a, c) do { \
242 (void) t; \
243 __asm volatile (" \
244 movl %0,%%a0 ; \
245 movl %1,%%a1 ; \
246 movl %2,%%d0 ; \
247 1: movl %%a0@+,%%a1@+ ; \
248 subql #1,%%d0 ; \
249 jne 1b" : \
251 "r" ((h) + (o)), "g" (a), "g" (c) : \
252 "a0","a1","d0"); \
253 } while (0);
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 !!!
257 #endif
260 * void bus_space_write_N(bus_space_tag_t tag,
261 * bus_space_handle_t bsh, bus_size_t offset,
262 * u_intN_t value);
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 !!!
279 #endif
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 { \
291 (void) t; \
292 __asm volatile (" \
293 movl %0,%%a0 ; \
294 movl %1,%%a1 ; \
295 movl %2,%%d0 ; \
296 1: movb %%a1@+,%%a0@ ; \
297 subql #1,%%d0 ; \
298 jne 1b" : \
300 "r" ((h) + (o)), "g" (a), "g" (c) : \
301 "a0","a1","d0"); \
302 } while (0);
304 #define bus_space_write_multi_2(t, h, o, a, c) do { \
305 (void) t; \
306 __asm volatile (" \
307 movl %0,%%a0 ; \
308 movl %1,%%a1 ; \
309 movl %2,%%d0 ; \
310 1: movw %%a1@+,%%a0@ ; \
311 subql #1,%%d0 ; \
312 jne 1b" : \
314 "r" ((h) + (o)), "g" (a), "g" (c) : \
315 "a0","a1","d0"); \
316 } while (0);
318 #define bus_space_write_multi_4(t, h, o, a, c) do { \
319 (void) t; \
320 __asm volatile (" \
321 movl %0,%%a0 ; \
322 movl %1,%%a1 ; \
323 movl %2,%%d0 ; \
324 1: movl %%a1@+,%%a0@ ; \
325 subql #1,%%d0 ; \
326 jne 1b" : \
328 "r" ((h) + (o)), "g" (a), "g" (c) : \
329 "a0","a1","d0"); \
330 } while (0);
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 !!!
335 #endif
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 { \
347 (void) t; \
348 __asm volatile (" \
349 movl %0,%%a0 ; \
350 movl %1,%%a1 ; \
351 movl %2,%%d0 ; \
352 1: movb %%a1@+,%%a0@+ ; \
353 subql #1,%%d0 ; \
354 jne 1b" : \
356 "r" ((h) + (o)), "g" (a), "g" (c) : \
357 "a0","a1","d0"); \
358 } while (0);
360 #define bus_space_write_region_2(t, h, o, a, c) do { \
361 (void) t; \
362 __asm volatile (" \
363 movl %0,%%a0 ; \
364 movl %1,%%a1 ; \
365 movl %2,%%d0 ; \
366 1: movw %%a1@+,%%a0@+ ; \
367 subql #1,%%d0 ; \
368 jne 1b" : \
370 "r" ((h) + (o)), "g" (a), "g" (c) : \
371 "a0","a1","d0"); \
372 } while (0);
374 #define bus_space_write_region_4(t, h, o, a, c) do { \
375 (void) t; \
376 __asm volatile (" \
377 movl %0,%%a0 ; \
378 movl %1,%%a1 ; \
379 movl %2,%%d0 ; \
380 1: movl %%a1@+,%%a0@+ ; \
381 subql #1,%%d0 ; \
382 jne 1b" : \
384 "r" ((h) + (o)), "g" (a), "g" (c) : \
385 "a0","a1","d0"); \
386 } while (0);
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 !!!
391 #endif
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,
396 * size_t count);
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 { \
403 (void) t; \
404 __asm volatile (" \
405 movl %0,%%a0 ; \
406 movl %1,%%d1 ; \
407 movl %2,%%d0 ; \
408 1: movb %%d1,%%a0@ ; \
409 subql #1,%%d0 ; \
410 jne 1b" : \
412 "r" ((h) + (o)), "g" (val), "g" (c) : \
413 "a0","d0","d1"); \
414 } while (0);
416 #define bus_space_set_multi_2(t, h, o, val, c) do { \
417 (void) t; \
418 __asm volatile (" \
419 movl %0,%%a0 ; \
420 movl %1,%%d1 ; \
421 movl %2,%%d0 ; \
422 1: movw %%d1,%%a0@ ; \
423 subql #1,%%d0 ; \
424 jne 1b" : \
426 "r" ((h) + (o)), "g" (val), "g" (c) : \
427 "a0","d0","d1"); \
428 } while (0);
430 #define bus_space_set_multi_4(t, h, o, val, c) do { \
431 (void) t; \
432 __asm volatile (" \
433 movl %0,%%a0 ; \
434 movl %1,%%d1 ; \
435 movl %2,%%d0 ; \
436 1: movl %%d1,%%a0@ ; \
437 subql #1,%%d0 ; \
438 jne 1b" : \
440 "r" ((h) + (o)), "g" (val), "g" (c) : \
441 "a0","d0","d1"); \
442 } while (0);
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 !!!
447 #endif
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,
452 * size_t count);
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 { \
459 (void) t; \
460 __asm volatile (" \
461 movl %0,%%a0 ; \
462 movl %1,%%d1 ; \
463 movl %2,%%d0 ; \
464 1: movb %%d1,%%a0@+ ; \
465 subql #1,%%d0 ; \
466 jne 1b" : \
468 "r" ((h) + (o)), "g" (val), "g" (c) : \
469 "a0","d0","d1"); \
470 } while (0);
472 #define bus_space_set_region_2(t, h, o, val, c) do { \
473 (void) t; \
474 __asm volatile (" \
475 movl %0,%%a0 ; \
476 movl %1,%%d1 ; \
477 movl %2,%%d0 ; \
478 1: movw %%d1,%%a0@+ ; \
479 subql #1,%%d0 ; \
480 jne 1b" : \
482 "r" ((h) + (o)), "g" (val), "g" (c) : \
483 "a0","d0","d1"); \
484 } while (0);
486 #define bus_space_set_region_4(t, h, o, val, c) do { \
487 (void) t; \
488 __asm volatile (" \
489 movl %0,%%a0 ; \
490 movl %1,%%d1 ; \
491 movl %2,%%d0 ; \
492 1: movl %%d1,%%a0@+ ; \
493 subql #1,%%d0 ; \
494 jne 1b" : \
496 "r" ((h) + (o)), "g" (val), "g" (c) : \
497 "a0","d0","d1"); \
498 } while (0);
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 !!!
503 #endif
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,
509 * size_t count);
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) \
517 (bus_space_tag_t, \
518 bus_space_handle_t, bus_size_t, \
519 bus_space_handle_t, bus_size_t, \
520 bus_size_t); \
522 static __inline void \
523 __CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c) \
524 bus_space_tag_t t; \
525 bus_space_handle_t h1, h2; \
526 bus_size_t o1, o2, c; \
528 bus_size_t o; \
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)); \
535 } else { \
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 !!!
548 #endif
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_ */