bus_space.h revision 1.8 1 /* $NetBSD: bus_space.h,v 1.8 2002/06/11 05:17:30 deberg Exp $ */
2
3 /*-
4 * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
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.
10 *
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.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Copyright (C) 1997 Scott Reynolds. All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. The name of the author may not be used to endorse or promote products
52 * derived from this software without specific prior written permission
53 *
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.
64 */
65
66 #ifndef _NEXT68K_BUS_SPACE_H_
67 #define _NEXT68K_BUS_SPACE_H_
68 /*
69 * Addresses (in bus space).
70 */
71 typedef u_long bus_addr_t;
72 typedef u_long bus_size_t;
73
74 /*
75 * Access methods for bus resources and address space.
76 */
77 typedef volatile char * bus_space_tag_t;
78 typedef u_long bus_space_handle_t;
79
80 /*
81 * Value for the next68k bus space tag, not to be used directly by MI code.
82 */
83 #define NEXT68K_INTIO_BUS_SPACE intiobase
84
85 /*
86 * Values for the next68k video bus space tags, not to be used directly
87 * by MI code.
88 */
89 #define NEXT68K_MONO_VIDEO_BUS_SPACE monobase
90 #define NEXT68K_COLOR_VIDEO_BUS_SPACE colorbase
91
92 /*
93 * Mapping and unmapping operations.
94 */
95 #define bus_space_map(t, a, s, f, hp) \
96 ((((a)>=INTIOBASE)&&((a)+(s)<INTIOTOP)) ? \
97 ((*(hp)=(bus_space_handle_t)((t)+((a)-INTIOBASE))),0) : \
98 ((((a)>=MONOBASE)&&((a)+(s)<MONOTOP)) ? \
99 ((*(hp)=(bus_space_handle_t)((t)+((a)-MONOBASE))),0) : \
100 ((((a)>=COLORBASE)&&((a)+(s)<COLORTOP)) ? \
101 ((*(hp)=(bus_space_handle_t)((t)+((a)-COLORBASE))),0) : (-1))))
102
103 #define bus_space_unmap(t, h, s)
104
105 #define bus_space_subregion(t, h, o, s, hp) \
106 (*(hp)=(h)+(o))
107
108 #define BUS_SPACE_MAP_CACHEABLE 0x01
109 #define BUS_SPACE_MAP_LINEAR 0x02
110
111 /*
112 * Allocation and deallocation operations.
113 */
114 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
115 (-1)
116
117 #define bus_space_free(t, h, s)
118
119 /*
120 * paddr_t bus_space_mmap __P((bus_space_tag_t t, bus_addr_t base,
121 * off_t offset, int prot, int flags));
122 *
123 * Mmap an area of bus space.
124 */
125
126 #define bus_space_mmap(t, addr, off, prot, flags) \
127 m68k_btop((addr) + (off))
128
129 /*
130 * u_intN_t bus_space_read_N __P((bus_space_tag_t tag,
131 * bus_space_handle_t bsh, bus_size_t offset));
132 *
133 * Read a 1, 2, 4, or 8 byte quantity from bus space
134 * described by tag/handle/offset.
135 */
136
137 #define bus_space_read_1(t, h, o) \
138 ((void) t, (*(volatile u_int8_t *)((h) + (o))))
139
140 #define bus_space_read_2(t, h, o) \
141 ((void) t, (*(volatile u_int16_t *)((h) + (o))))
142
143 #define bus_space_read_4(t, h, o) \
144 ((void) t, (*(volatile u_int32_t *)((h) + (o))))
145
146 #if 0 /* Cause a link error for bus_space_read_8 */
147 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
148 #endif
149
150 /*
151 * void bus_space_read_multi_N __P((bus_space_tag_t tag,
152 * bus_space_handle_t bsh, bus_size_t offset,
153 * u_intN_t *addr, size_t count));
154 *
155 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
156 * described by tag/handle/offset and copy into buffer provided.
157 */
158
159 #define bus_space_read_multi_1(t, h, o, a, c) do { \
160 (void) t; \
161 __asm __volatile (" \
162 movl %0,%%a0 ; \
163 movl %1,%%a1 ; \
164 movl %2,%%d0 ; \
165 1: movb %%a0@,%%a1@+ ; \
166 subql #1,%%d0 ; \
167 jne 1b" : \
168 : \
169 "r" ((h) + (o)), "g" (a), "g" (c) : \
170 "a0","a1","d0"); \
171 } while (0);
172
173 #define bus_space_read_multi_2(t, h, o, a, c) do { \
174 (void) t; \
175 __asm __volatile (" \
176 movl %0,%%a0 ; \
177 movl %1,%%a1 ; \
178 movl %2,%%d0 ; \
179 1: movw %%a0@,%%a1@+ ; \
180 subql #1,%%d0 ; \
181 jne 1b" : \
182 : \
183 "r" ((h) + (o)), "g" (a), "g" (c) : \
184 "a0","a1","d0"); \
185 } while (0);
186
187 #define bus_space_read_multi_4(t, h, o, a, c) do { \
188 (void) t; \
189 __asm __volatile (" \
190 movl %0,%%a0 ; \
191 movl %1,%%a1 ; \
192 movl %2,%%d0 ; \
193 1: movl %%a0@,%%a1@+ ; \
194 subql #1,%%d0 ; \
195 jne 1b" : \
196 : \
197 "r" ((h) + (o)), "g" (a), "g" (c) : \
198 "a0","a1","d0"); \
199 } while (0);
200
201 #if 0 /* Cause a link error for bus_space_read_multi_8 */
202 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
203 #endif
204
205 /*
206 * void bus_space_read_region_N __P((bus_space_tag_t tag,
207 * bus_space_handle_t bsh, bus_size_t offset,
208 * u_intN_t *addr, size_t count));
209 *
210 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
211 * described by tag/handle and starting at `offset' and copy into
212 * buffer provided.
213 */
214
215 #define bus_space_read_region_1(t, h, o, a, c) do { \
216 (void) t; \
217 __asm __volatile (" \
218 movl %0,%%a0 ; \
219 movl %1,%%a1 ; \
220 movl %2,%%d0 ; \
221 1: movb %%a0@+,%%a1@+ ; \
222 subql #1,%%d0 ; \
223 jne 1b" : \
224 : \
225 "r" ((h) + (o)), "g" (a), "g" (c) : \
226 "a0","a1","d0"); \
227 } while (0);
228
229 #define bus_space_read_region_2(t, h, o, a, c) do { \
230 (void) t; \
231 __asm __volatile (" \
232 movl %0,%%a0 ; \
233 movl %1,%%a1 ; \
234 movl %2,%%d0 ; \
235 1: movw %%a0@+,%%a1@+ ; \
236 subql #1,%%d0 ; \
237 jne 1b" : \
238 : \
239 "r" ((h) + (o)), "g" (a), "g" (c) : \
240 "a0","a1","d0"); \
241 } while (0);
242
243 #define bus_space_read_region_4(t, h, o, a, c) do { \
244 (void) t; \
245 __asm __volatile (" \
246 movl %0,%%a0 ; \
247 movl %1,%%a1 ; \
248 movl %2,%%d0 ; \
249 1: movl %%a0@+,%%a1@+ ; \
250 subql #1,%%d0 ; \
251 jne 1b" : \
252 : \
253 "r" ((h) + (o)), "g" (a), "g" (c) : \
254 "a0","a1","d0"); \
255 } while (0);
256
257 #if 0 /* Cause a link error for bus_space_read_region_8 */
258 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
259 #endif
260
261 /*
262 * void bus_space_write_N __P((bus_space_tag_t tag,
263 * bus_space_handle_t bsh, bus_size_t offset,
264 * u_intN_t value));
265 *
266 * Write the 1, 2, 4, or 8 byte value `value' to bus space
267 * described by tag/handle/offset.
268 */
269
270 #define bus_space_write_1(t, h, o, v) \
271 ((void) t, ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))))
272
273 #define bus_space_write_2(t, h, o, v) \
274 ((void) t, ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))))
275
276 #define bus_space_write_4(t, h, o, v) \
277 ((void) t, ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))))
278
279 #if 0 /* Cause a link error for bus_space_write_8 */
280 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
281 #endif
282
283 /*
284 * void bus_space_write_multi_N __P((bus_space_tag_t tag,
285 * bus_space_handle_t bsh, bus_size_t offset,
286 * const u_intN_t *addr, size_t count));
287 *
288 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
289 * provided to bus space described by tag/handle/offset.
290 */
291
292 #define bus_space_write_multi_1(t, h, o, a, c) do { \
293 (void) t; \
294 __asm __volatile (" \
295 movl %0,%%a0 ; \
296 movl %1,%%a1 ; \
297 movl %2,%%d0 ; \
298 1: movb %%a1@+,%%a0@ ; \
299 subql #1,%%d0 ; \
300 jne 1b" : \
301 : \
302 "r" ((h) + (o)), "g" (a), "g" (c) : \
303 "a0","a1","d0"); \
304 } while (0);
305
306 #define bus_space_write_multi_2(t, h, o, a, c) do { \
307 (void) t; \
308 __asm __volatile (" \
309 movl %0,%%a0 ; \
310 movl %1,%%a1 ; \
311 movl %2,%%d0 ; \
312 1: movw %%a1@+,%%a0@ ; \
313 subql #1,%%d0 ; \
314 jne 1b" : \
315 : \
316 "r" ((h) + (o)), "g" (a), "g" (c) : \
317 "a0","a1","d0"); \
318 } while (0);
319
320 #define bus_space_write_multi_4(t, h, o, a, c) do { \
321 (void) t; \
322 __asm __volatile (" \
323 movl %0,%%a0 ; \
324 movl %1,%%a1 ; \
325 movl %2,%%d0 ; \
326 1: movl %%a1@+,%%a0@ ; \
327 subql #1,%%d0 ; \
328 jne 1b" : \
329 : \
330 "r" ((h) + (o)), "g" (a), "g" (c) : \
331 "a0","a1","d0"); \
332 } while (0);
333
334 #if 0 /* Cause a link error for bus_space_write_8 */
335 #define bus_space_write_multi_8(t, h, o, a, c) \
336 !!! bus_space_write_multi_8 unimplimented !!!
337 #endif
338
339 /*
340 * void bus_space_write_region_N __P((bus_space_tag_t tag,
341 * bus_space_handle_t bsh, bus_size_t offset,
342 * const u_intN_t *addr, size_t count));
343 *
344 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
345 * to bus space described by tag/handle starting at `offset'.
346 */
347
348 #define bus_space_write_region_1(t, h, o, a, c) do { \
349 (void) t; \
350 __asm __volatile (" \
351 movl %0,%%a0 ; \
352 movl %1,%%a1 ; \
353 movl %2,%%d0 ; \
354 1: movb %%a1@+,%%a0@+ ; \
355 subql #1,%%d0 ; \
356 jne 1b" : \
357 : \
358 "r" ((h) + (o)), "g" (a), "g" (c) : \
359 "a0","a1","d0"); \
360 } while (0);
361
362 #define bus_space_write_region_2(t, h, o, a, c) do { \
363 (void) t; \
364 __asm __volatile (" \
365 movl %0,%%a0 ; \
366 movl %1,%%a1 ; \
367 movl %2,%%d0 ; \
368 1: movw %%a1@+,%%a0@+ ; \
369 subql #1,%%d0 ; \
370 jne 1b" : \
371 : \
372 "r" ((h) + (o)), "g" (a), "g" (c) : \
373 "a0","a1","d0"); \
374 } while (0);
375
376 #define bus_space_write_region_4(t, h, o, a, c) do { \
377 (void) t; \
378 __asm __volatile (" \
379 movl %0,%%a0 ; \
380 movl %1,%%a1 ; \
381 movl %2,%%d0 ; \
382 1: movl %%a1@+,%%a0@+ ; \
383 subql #1,%%d0 ; \
384 jne 1b" : \
385 : \
386 "r" ((h) + (o)), "g" (a), "g" (c) : \
387 "a0","a1","d0"); \
388 } while (0);
389
390 #if 0 /* Cause a link error for bus_space_write_region_8 */
391 #define bus_space_write_region_8 \
392 !!! bus_space_write_region_8 unimplemented !!!
393 #endif
394
395 /*
396 * void bus_space_set_multi_N __P((bus_space_tag_t tag,
397 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
398 * size_t count));
399 *
400 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
401 * by tag/handle/offset `count' times.
402 */
403
404 #define bus_space_set_multi_1(t, h, o, val, c) do { \
405 (void) t; \
406 __asm __volatile (" \
407 movl %0,%%a0 ; \
408 movl %1,%%d1 ; \
409 movl %2,%%d0 ; \
410 1: movb %%d1,%%a0@ ; \
411 subql #1,%%d0 ; \
412 jne 1b" : \
413 : \
414 "r" ((h) + (o)), "g" (val), "g" (c) : \
415 "a0","d0","d1"); \
416 } while (0);
417
418 #define bus_space_set_multi_2(t, h, o, val, c) do { \
419 (void) t; \
420 __asm __volatile (" \
421 movl %0,%%a0 ; \
422 movl %1,%%d1 ; \
423 movl %2,%%d0 ; \
424 1: movw %%d1,%%a0@ ; \
425 subql #1,%%d0 ; \
426 jne 1b" : \
427 : \
428 "r" ((h) + (o)), "g" (val), "g" (c) : \
429 "a0","d0","d1"); \
430 } while (0);
431
432 #define bus_space_set_multi_4(t, h, o, val, c) do { \
433 (void) t; \
434 __asm __volatile (" \
435 movl %0,%%a0 ; \
436 movl %1,%%d1 ; \
437 movl %2,%%d0 ; \
438 1: movl %%d1,%%a0@ ; \
439 subql #1,%%d0 ; \
440 jne 1b" : \
441 : \
442 "r" ((h) + (o)), "g" (val), "g" (c) : \
443 "a0","d0","d1"); \
444 } while (0);
445
446 #if 0 /* Cause a link error for bus_space_set_multi_8 */
447 #define bus_space_set_multi_8 \
448 !!! bus_space_set_multi_8 unimplemented !!!
449 #endif
450
451 /*
452 * void bus_space_set_region_N __P((bus_space_tag_t tag,
453 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
454 * size_t count));
455 *
456 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
457 * by tag/handle starting at `offset'.
458 */
459
460 #define bus_space_set_region_1(t, h, o, val, c) do { \
461 (void) t; \
462 __asm __volatile (" \
463 movl %0,%%a0 ; \
464 movl %1,%%d1 ; \
465 movl %2,%%d0 ; \
466 1: movb %%d1,%%a0@+ ; \
467 subql #1,%%d0 ; \
468 jne 1b" : \
469 : \
470 "r" ((h) + (o)), "g" (val), "g" (c) : \
471 "a0","d0","d1"); \
472 } while (0);
473
474 #define bus_space_set_region_2(t, h, o, val, c) do { \
475 (void) t; \
476 __asm __volatile (" \
477 movl %0,%%a0 ; \
478 movl %1,%%d1 ; \
479 movl %2,%%d0 ; \
480 1: movw %%d1,%%a0@+ ; \
481 subql #1,%%d0 ; \
482 jne 1b" : \
483 : \
484 "r" ((h) + (o)), "g" (val), "g" (c) : \
485 "a0","d0","d1"); \
486 } while (0);
487
488 #define bus_space_set_region_4(t, h, o, val, c) do { \
489 (void) t; \
490 __asm __volatile (" \
491 movl %0,%%a0 ; \
492 movl %1,%%d1 ; \
493 movl %2,%%d0 ; \
494 1: movl %%d1,%%a0@+ ; \
495 subql #1,%%d0 ; \
496 jne 1b" : \
497 : \
498 "r" ((h) + (o)), "g" (val), "g" (c) : \
499 "a0","d0","d1"); \
500 } while (0);
501
502 #if 0 /* Cause a link error for bus_space_set_region_8 */
503 #define bus_space_set_region_8 \
504 !!! bus_space_set_region_8 unimplemented !!!
505 #endif
506
507 /*
508 * void bus_space_copy_N __P((bus_space_tag_t tag,
509 * bus_space_handle_t bsh1, bus_size_t off1,
510 * bus_space_handle_t bsh2, bus_size_t off2,
511 * size_t count));
512 *
513 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
514 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
515 */
516
517 #define __NEXT68K_copy_region_N(BYTES) \
518 static __inline void __CONCAT(bus_space_copy_region_,BYTES) \
519 __P((bus_space_tag_t, \
520 bus_space_handle_t bsh1, bus_size_t off1, \
521 bus_space_handle_t bsh2, bus_size_t off2, \
522 bus_size_t count)); \
523 \
524 static __inline void \
525 __CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c) \
526 bus_space_tag_t t; \
527 bus_space_handle_t h1, h2; \
528 bus_size_t o1, o2, c; \
529 { \
530 bus_size_t o; \
531 \
532 if ((h1 + o1) >= (h2 + o2)) { \
533 /* src after dest: copy forward */ \
534 for (o = 0; c != 0; c--, o += BYTES) \
535 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
536 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
537 } else { \
538 /* dest after src: copy backwards */ \
539 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
540 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
541 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
542 } \
543 }
544 __NEXT68K_copy_region_N(1)
545 __NEXT68K_copy_region_N(2)
546 __NEXT68K_copy_region_N(4)
547 #if 0 /* Cause a link error for bus_space_copy_8 */
548 #define bus_space_copy_8 \
549 !!! bus_space_copy_8 unimplemented !!!
550 #endif
551
552 #undef __NEXT68K_copy_region_N
553
554 /*
555 * Bus read/write barrier methods.
556 *
557 * void bus_space_barrier __P((bus_space_tag_t tag,
558 * bus_space_handle_t bsh, bus_size_t offset,
559 * bus_size_t len, int flags));
560 *
561 * Note: the 680x0 does not currently require barriers, but we must
562 * provide the flags to MI code.
563 */
564 #define bus_space_barrier(t, h, o, l, f) \
565 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
566 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
567 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
568
569 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
570
571 #endif /* _NEXT68K_BUS_SPACE_H_ */
572