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