bus_space.h revision 1.14 1 /* $NetBSD: bus_space.h,v 1.14 2006/02/16 20:17:14 perry 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 ((bus_space_tag_t)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 ((bus_space_tag_t)monobase)
90 #define NEXT68K_COLOR_VIDEO_BUS_SPACE ((bus_space_tag_t)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(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, a, s, prot, flags) \
127 ((((a)>=INTIOBASE)&&((a)+(s)<INTIOTOP)) ? \
128 m68k_btop((t)+((a)-INTIOBASE)) : \
129 ((((a)>=MONOBASE)&&((a)+(s)<MONOTOP)) ? \
130 m68k_btop((t)+((a)-MONOBASE)) : \
131 ((((a)>=COLORBASE)&&((a)+(s)<COLORTOP)) ? \
132 m68k_btop((t)+((a)-COLORBASE)) : (-1))))
133
134 /*
135 * u_intN_t bus_space_read_N(bus_space_tag_t tag,
136 * bus_space_handle_t bsh, bus_size_t offset);
137 *
138 * Read a 1, 2, 4, or 8 byte quantity from bus space
139 * described by tag/handle/offset.
140 */
141
142 #define bus_space_read_1(t, h, o) \
143 ((void) t, (*(volatile u_int8_t *)((h) + (o))))
144
145 #define bus_space_read_2(t, h, o) \
146 ((void) t, (*(volatile u_int16_t *)((h) + (o))))
147
148 #define bus_space_read_4(t, h, o) \
149 ((void) t, (*(volatile u_int32_t *)((h) + (o))))
150
151 #if 0 /* Cause a link error for bus_space_read_8 */
152 #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
153 #endif
154
155 /*
156 * void bus_space_read_multi_N(bus_space_tag_t tag,
157 * bus_space_handle_t bsh, bus_size_t offset,
158 * u_intN_t *addr, size_t count);
159 *
160 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
161 * described by tag/handle/offset and copy into buffer provided.
162 */
163
164 #define bus_space_read_multi_1(t, h, o, a, c) do { \
165 (void) t; \
166 __asm volatile (" \
167 movl %0,%%a0 ; \
168 movl %1,%%a1 ; \
169 movl %2,%%d0 ; \
170 1: movb %%a0@,%%a1@+ ; \
171 subql #1,%%d0 ; \
172 jne 1b" : \
173 : \
174 "r" ((h) + (o)), "g" (a), "g" (c) : \
175 "a0","a1","d0"); \
176 } while (0);
177
178 #define bus_space_read_multi_2(t, h, o, a, c) do { \
179 (void) t; \
180 __asm volatile (" \
181 movl %0,%%a0 ; \
182 movl %1,%%a1 ; \
183 movl %2,%%d0 ; \
184 1: movw %%a0@,%%a1@+ ; \
185 subql #1,%%d0 ; \
186 jne 1b" : \
187 : \
188 "r" ((h) + (o)), "g" (a), "g" (c) : \
189 "a0","a1","d0"); \
190 } while (0);
191
192 #define bus_space_read_multi_4(t, h, o, a, c) do { \
193 (void) t; \
194 __asm volatile (" \
195 movl %0,%%a0 ; \
196 movl %1,%%a1 ; \
197 movl %2,%%d0 ; \
198 1: movl %%a0@,%%a1@+ ; \
199 subql #1,%%d0 ; \
200 jne 1b" : \
201 : \
202 "r" ((h) + (o)), "g" (a), "g" (c) : \
203 "a0","a1","d0"); \
204 } while (0);
205
206 #if 0 /* Cause a link error for bus_space_read_multi_8 */
207 #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
208 #endif
209
210 /*
211 * void bus_space_read_region_N(bus_space_tag_t tag,
212 * bus_space_handle_t bsh, bus_size_t offset,
213 * u_intN_t *addr, size_t count);
214 *
215 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
216 * described by tag/handle and starting at `offset' and copy into
217 * buffer provided.
218 */
219
220 #define bus_space_read_region_1(t, h, o, a, c) do { \
221 (void) t; \
222 __asm volatile (" \
223 movl %0,%%a0 ; \
224 movl %1,%%a1 ; \
225 movl %2,%%d0 ; \
226 1: movb %%a0@+,%%a1@+ ; \
227 subql #1,%%d0 ; \
228 jne 1b" : \
229 : \
230 "r" ((h) + (o)), "g" (a), "g" (c) : \
231 "a0","a1","d0"); \
232 } while (0);
233
234 #define bus_space_read_region_2(t, h, o, a, c) do { \
235 (void) t; \
236 __asm volatile (" \
237 movl %0,%%a0 ; \
238 movl %1,%%a1 ; \
239 movl %2,%%d0 ; \
240 1: movw %%a0@+,%%a1@+ ; \
241 subql #1,%%d0 ; \
242 jne 1b" : \
243 : \
244 "r" ((h) + (o)), "g" (a), "g" (c) : \
245 "a0","a1","d0"); \
246 } while (0);
247
248 #define bus_space_read_region_4(t, h, o, a, c) do { \
249 (void) t; \
250 __asm volatile (" \
251 movl %0,%%a0 ; \
252 movl %1,%%a1 ; \
253 movl %2,%%d0 ; \
254 1: movl %%a0@+,%%a1@+ ; \
255 subql #1,%%d0 ; \
256 jne 1b" : \
257 : \
258 "r" ((h) + (o)), "g" (a), "g" (c) : \
259 "a0","a1","d0"); \
260 } while (0);
261
262 #if 0 /* Cause a link error for bus_space_read_region_8 */
263 #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
264 #endif
265
266 /*
267 * void bus_space_write_N(bus_space_tag_t tag,
268 * bus_space_handle_t bsh, bus_size_t offset,
269 * u_intN_t value);
270 *
271 * Write the 1, 2, 4, or 8 byte value `value' to bus space
272 * described by tag/handle/offset.
273 */
274
275 #define bus_space_write_1(t, h, o, v) \
276 ((void) t, ((void)(*(volatile u_int8_t *)((h) + (o)) = (v))))
277
278 #define bus_space_write_2(t, h, o, v) \
279 ((void) t, ((void)(*(volatile u_int16_t *)((h) + (o)) = (v))))
280
281 #define bus_space_write_4(t, h, o, v) \
282 ((void) t, ((void)(*(volatile u_int32_t *)((h) + (o)) = (v))))
283
284 #if 0 /* Cause a link error for bus_space_write_8 */
285 #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
286 #endif
287
288 /*
289 * void bus_space_write_multi_N(bus_space_tag_t tag,
290 * bus_space_handle_t bsh, bus_size_t offset,
291 * const u_intN_t *addr, size_t count);
292 *
293 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
294 * provided to bus space described by tag/handle/offset.
295 */
296
297 #define bus_space_write_multi_1(t, h, o, a, c) do { \
298 (void) t; \
299 __asm volatile (" \
300 movl %0,%%a0 ; \
301 movl %1,%%a1 ; \
302 movl %2,%%d0 ; \
303 1: movb %%a1@+,%%a0@ ; \
304 subql #1,%%d0 ; \
305 jne 1b" : \
306 : \
307 "r" ((h) + (o)), "g" (a), "g" (c) : \
308 "a0","a1","d0"); \
309 } while (0);
310
311 #define bus_space_write_multi_2(t, h, o, a, c) do { \
312 (void) t; \
313 __asm volatile (" \
314 movl %0,%%a0 ; \
315 movl %1,%%a1 ; \
316 movl %2,%%d0 ; \
317 1: movw %%a1@+,%%a0@ ; \
318 subql #1,%%d0 ; \
319 jne 1b" : \
320 : \
321 "r" ((h) + (o)), "g" (a), "g" (c) : \
322 "a0","a1","d0"); \
323 } while (0);
324
325 #define bus_space_write_multi_4(t, h, o, a, c) do { \
326 (void) t; \
327 __asm volatile (" \
328 movl %0,%%a0 ; \
329 movl %1,%%a1 ; \
330 movl %2,%%d0 ; \
331 1: movl %%a1@+,%%a0@ ; \
332 subql #1,%%d0 ; \
333 jne 1b" : \
334 : \
335 "r" ((h) + (o)), "g" (a), "g" (c) : \
336 "a0","a1","d0"); \
337 } while (0);
338
339 #if 0 /* Cause a link error for bus_space_write_8 */
340 #define bus_space_write_multi_8(t, h, o, a, c) \
341 !!! bus_space_write_multi_8 unimplimented !!!
342 #endif
343
344 /*
345 * void bus_space_write_region_N(bus_space_tag_t tag,
346 * bus_space_handle_t bsh, bus_size_t offset,
347 * const u_intN_t *addr, size_t count);
348 *
349 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
350 * to bus space described by tag/handle starting at `offset'.
351 */
352
353 #define bus_space_write_region_1(t, h, o, a, c) do { \
354 (void) t; \
355 __asm volatile (" \
356 movl %0,%%a0 ; \
357 movl %1,%%a1 ; \
358 movl %2,%%d0 ; \
359 1: movb %%a1@+,%%a0@+ ; \
360 subql #1,%%d0 ; \
361 jne 1b" : \
362 : \
363 "r" ((h) + (o)), "g" (a), "g" (c) : \
364 "a0","a1","d0"); \
365 } while (0);
366
367 #define bus_space_write_region_2(t, h, o, a, c) do { \
368 (void) t; \
369 __asm volatile (" \
370 movl %0,%%a0 ; \
371 movl %1,%%a1 ; \
372 movl %2,%%d0 ; \
373 1: movw %%a1@+,%%a0@+ ; \
374 subql #1,%%d0 ; \
375 jne 1b" : \
376 : \
377 "r" ((h) + (o)), "g" (a), "g" (c) : \
378 "a0","a1","d0"); \
379 } while (0);
380
381 #define bus_space_write_region_4(t, h, o, a, c) do { \
382 (void) t; \
383 __asm volatile (" \
384 movl %0,%%a0 ; \
385 movl %1,%%a1 ; \
386 movl %2,%%d0 ; \
387 1: movl %%a1@+,%%a0@+ ; \
388 subql #1,%%d0 ; \
389 jne 1b" : \
390 : \
391 "r" ((h) + (o)), "g" (a), "g" (c) : \
392 "a0","a1","d0"); \
393 } while (0);
394
395 #if 0 /* Cause a link error for bus_space_write_region_8 */
396 #define bus_space_write_region_8 \
397 !!! bus_space_write_region_8 unimplemented !!!
398 #endif
399
400 /*
401 * void bus_space_set_multi_N(bus_space_tag_t tag,
402 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
403 * size_t count);
404 *
405 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
406 * by tag/handle/offset `count' times.
407 */
408
409 #define bus_space_set_multi_1(t, h, o, val, c) do { \
410 (void) t; \
411 __asm volatile (" \
412 movl %0,%%a0 ; \
413 movl %1,%%d1 ; \
414 movl %2,%%d0 ; \
415 1: movb %%d1,%%a0@ ; \
416 subql #1,%%d0 ; \
417 jne 1b" : \
418 : \
419 "r" ((h) + (o)), "g" (val), "g" (c) : \
420 "a0","d0","d1"); \
421 } while (0);
422
423 #define bus_space_set_multi_2(t, h, o, val, c) do { \
424 (void) t; \
425 __asm volatile (" \
426 movl %0,%%a0 ; \
427 movl %1,%%d1 ; \
428 movl %2,%%d0 ; \
429 1: movw %%d1,%%a0@ ; \
430 subql #1,%%d0 ; \
431 jne 1b" : \
432 : \
433 "r" ((h) + (o)), "g" (val), "g" (c) : \
434 "a0","d0","d1"); \
435 } while (0);
436
437 #define bus_space_set_multi_4(t, h, o, val, c) do { \
438 (void) t; \
439 __asm volatile (" \
440 movl %0,%%a0 ; \
441 movl %1,%%d1 ; \
442 movl %2,%%d0 ; \
443 1: movl %%d1,%%a0@ ; \
444 subql #1,%%d0 ; \
445 jne 1b" : \
446 : \
447 "r" ((h) + (o)), "g" (val), "g" (c) : \
448 "a0","d0","d1"); \
449 } while (0);
450
451 #if 0 /* Cause a link error for bus_space_set_multi_8 */
452 #define bus_space_set_multi_8 \
453 !!! bus_space_set_multi_8 unimplemented !!!
454 #endif
455
456 /*
457 * void bus_space_set_region_N(bus_space_tag_t tag,
458 * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
459 * size_t count);
460 *
461 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
462 * by tag/handle starting at `offset'.
463 */
464
465 #define bus_space_set_region_1(t, h, o, val, c) do { \
466 (void) t; \
467 __asm volatile (" \
468 movl %0,%%a0 ; \
469 movl %1,%%d1 ; \
470 movl %2,%%d0 ; \
471 1: movb %%d1,%%a0@+ ; \
472 subql #1,%%d0 ; \
473 jne 1b" : \
474 : \
475 "r" ((h) + (o)), "g" (val), "g" (c) : \
476 "a0","d0","d1"); \
477 } while (0);
478
479 #define bus_space_set_region_2(t, h, o, val, c) do { \
480 (void) t; \
481 __asm volatile (" \
482 movl %0,%%a0 ; \
483 movl %1,%%d1 ; \
484 movl %2,%%d0 ; \
485 1: movw %%d1,%%a0@+ ; \
486 subql #1,%%d0 ; \
487 jne 1b" : \
488 : \
489 "r" ((h) + (o)), "g" (val), "g" (c) : \
490 "a0","d0","d1"); \
491 } while (0);
492
493 #define bus_space_set_region_4(t, h, o, val, c) do { \
494 (void) t; \
495 __asm volatile (" \
496 movl %0,%%a0 ; \
497 movl %1,%%d1 ; \
498 movl %2,%%d0 ; \
499 1: movl %%d1,%%a0@+ ; \
500 subql #1,%%d0 ; \
501 jne 1b" : \
502 : \
503 "r" ((h) + (o)), "g" (val), "g" (c) : \
504 "a0","d0","d1"); \
505 } while (0);
506
507 #if 0 /* Cause a link error for bus_space_set_region_8 */
508 #define bus_space_set_region_8 \
509 !!! bus_space_set_region_8 unimplemented !!!
510 #endif
511
512 /*
513 * void bus_space_copy_N(bus_space_tag_t tag,
514 * bus_space_handle_t bsh1, bus_size_t off1,
515 * bus_space_handle_t bsh2, bus_size_t off2,
516 * size_t count);
517 *
518 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
519 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
520 */
521
522 #define __NEXT68K_copy_region_N(BYTES) \
523 static __inline void __CONCAT(bus_space_copy_region_,BYTES) \
524 (bus_space_tag_t, \
525 bus_space_handle_t, bus_size_t, \
526 bus_space_handle_t, bus_size_t, \
527 bus_size_t); \
528 \
529 static __inline void \
530 __CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c) \
531 bus_space_tag_t t; \
532 bus_space_handle_t h1, h2; \
533 bus_size_t o1, o2, c; \
534 { \
535 bus_size_t o; \
536 \
537 if ((h1 + o1) >= (h2 + o2)) { \
538 /* src after dest: copy forward */ \
539 for (o = 0; 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 } else { \
543 /* dest after src: copy backwards */ \
544 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
545 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
546 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
547 } \
548 }
549 __NEXT68K_copy_region_N(1)
550 __NEXT68K_copy_region_N(2)
551 __NEXT68K_copy_region_N(4)
552 #if 0 /* Cause a link error for bus_space_copy_8 */
553 #define bus_space_copy_8 \
554 !!! bus_space_copy_8 unimplemented !!!
555 #endif
556
557 #undef __NEXT68K_copy_region_N
558
559 /*
560 * Bus read/write barrier methods.
561 *
562 * void bus_space_barrier(bus_space_tag_t tag,
563 * bus_space_handle_t bsh, bus_size_t offset,
564 * bus_size_t len, int flags);
565 *
566 * Note: the 680x0 does not currently require barriers, but we must
567 * provide the flags to MI code.
568 */
569 #define bus_space_barrier(t, h, o, l, f) \
570 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
571 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
572 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
573
574 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
575
576 #endif /* _NEXT68K_BUS_SPACE_H_ */
577