bus_space.h revision 1.22 1 /* $NetBSD: bus_space.h,v 1.22 2023/02/03 23:21:18 tsutsui 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 *
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.
31 */
32
33 /*
34 * Copyright (C) 1997 Scott Reynolds. All rights reserved.
35 *
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
46 *
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.
57 */
58
59 #ifndef _NEXT68K_BUS_SPACE_H_
60 #define _NEXT68K_BUS_SPACE_H_
61 /*
62 * Addresses (in bus space).
63 */
64 typedef u_long bus_addr_t;
65 typedef u_long bus_size_t;
66
67 #define PRIxBUSADDR "lx"
68 #define PRIxBUSSIZE "lx"
69 #define PRIuBUSSIZE "lu"
70
71 /*
72 * Access methods for bus resources and address space.
73 */
74 typedef volatile char * bus_space_tag_t;
75 typedef u_long bus_space_handle_t;
76
77 #define PRIxBSH "lx"
78
79 /*
80 * Value for the next68k bus space tag, not to be used directly by MI code.
81 */
82 #define NEXT68K_INTIO_BUS_SPACE ((bus_space_tag_t)intiobase)
83
84 /*
85 * Values for the next68k video bus space tags, not to be used directly
86 * by MI code.
87 */
88 #define NEXT68K_MONO_VIDEO_BUS_SPACE ((bus_space_tag_t)monobase)
89 #define NEXT68K_COLOR_VIDEO_BUS_SPACE ((bus_space_tag_t)colorbase)
90
91 /*
92 * Mapping and unmapping operations.
93 */
94 #define bus_space_map(t, a, s, f, hp) \
95 ((((a)>=INTIOBASE)&&((a)+(s)<INTIOTOP)) ? \
96 ((*(hp)=(bus_space_handle_t)((t)+((a)-INTIOBASE))),0) : \
97 ((((a)>=MONOBASE)&&((a)+(s)<MONOTOP)) ? \
98 ((*(hp)=(bus_space_handle_t)((t)+((a)-MONOBASE))),0) : \
99 ((((a)>=COLORBASE)&&((a)+(s)<COLORTOP)) ? \
100 ((*(hp)=(bus_space_handle_t)((t)+((a)-COLORBASE))),0) : (-1))))
101
102 #define bus_space_unmap(t, h, s)
103
104 #define bus_space_subregion(t, h, o, s, hp) \
105 (*(hp)=(h)+(o))
106
107 #define BUS_SPACE_MAP_CACHEABLE 0x01
108 #define BUS_SPACE_MAP_LINEAR 0x02
109
110 /*
111 * Allocation and deallocation operations.
112 */
113 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
114 (-1)
115
116 #define bus_space_free(t, h, s)
117
118 /*
119 * paddr_t bus_space_mmap(bus_space_tag_t t, bus_addr_t base,
120 * off_t offset, int prot, int flags);
121 *
122 * Mmap an area of bus space.
123 */
124
125 #define bus_space_mmap(t, a, s, prot, flags) \
126 ((((a)>=INTIOBASE)&&((a)+(s)<INTIOTOP)) ? \
127 m68k_btop((t)+((a)-INTIOBASE)) : \
128 ((((a)>=MONOBASE)&&((a)+(s)<MONOTOP)) ? \
129 m68k_btop((t)+((a)-MONOBASE)) : \
130 ((((a)>=COLORBASE)&&((a)+(s)<COLORTOP)) ? \
131 m68k_btop((t)+((a)-COLORBASE)) : (-1))))
132
133 /*
134 * uintN_t bus_space_read_N(bus_space_tag_t tag,
135 * bus_space_handle_t bsh, bus_size_t offset);
136 *
137 * Read a 1, 2, 4, or 8 byte quantity from bus space
138 * described by tag/handle/offset.
139 */
140
141 #define bus_space_read_1(t, h, o) \
142 ((void) t, (*(volatile uint8_t *)((h) + (o))))
143
144 #define bus_space_read_2(t, h, o) \
145 ((void) t, (*(volatile uint16_t *)((h) + (o))))
146
147 #define bus_space_read_4(t, h, o) \
148 ((void) t, (*(volatile uint32_t *)((h) + (o))))
149
150 /*
151 * void bus_space_read_multi_N(bus_space_tag_t tag,
152 * bus_space_handle_t bsh, bus_size_t offset,
153 * uintN_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","memory"); \
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","memory"); \
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","memory"); \
199 } while (0);
200
201 /*
202 * void bus_space_read_region_N(bus_space_tag_t tag,
203 * bus_space_handle_t bsh, bus_size_t offset,
204 * uintN_t *addr, size_t count);
205 *
206 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
207 * described by tag/handle and starting at `offset' and copy into
208 * buffer provided.
209 */
210
211 #define bus_space_read_region_1(t, h, o, a, c) do { \
212 (void) t; \
213 __asm volatile (" \
214 movl %0,%%a0 ; \
215 movl %1,%%a1 ; \
216 movl %2,%%d0 ; \
217 1: movb %%a0@+,%%a1@+ ; \
218 subql #1,%%d0 ; \
219 jne 1b" : \
220 : \
221 "r" ((h) + (o)), "g" (a), "g" (c) : \
222 "a0","a1","d0","memory"); \
223 } while (0);
224
225 #define bus_space_read_region_2(t, h, o, a, c) do { \
226 (void) t; \
227 __asm volatile (" \
228 movl %0,%%a0 ; \
229 movl %1,%%a1 ; \
230 movl %2,%%d0 ; \
231 1: movw %%a0@+,%%a1@+ ; \
232 subql #1,%%d0 ; \
233 jne 1b" : \
234 : \
235 "r" ((h) + (o)), "g" (a), "g" (c) : \
236 "a0","a1","d0","memory"); \
237 } while (0);
238
239 #define bus_space_read_region_4(t, h, o, a, c) do { \
240 (void) t; \
241 __asm volatile (" \
242 movl %0,%%a0 ; \
243 movl %1,%%a1 ; \
244 movl %2,%%d0 ; \
245 1: movl %%a0@+,%%a1@+ ; \
246 subql #1,%%d0 ; \
247 jne 1b" : \
248 : \
249 "r" ((h) + (o)), "g" (a), "g" (c) : \
250 "a0","a1","d0","memory"); \
251 } while (0);
252
253 /*
254 * void bus_space_write_N(bus_space_tag_t tag,
255 * bus_space_handle_t bsh, bus_size_t offset,
256 * uintN_t value);
257 *
258 * Write the 1, 2, 4, or 8 byte value `value' to bus space
259 * described by tag/handle/offset.
260 */
261
262 #define bus_space_write_1(t, h, o, v) \
263 ((void) t, ((void)(*(volatile uint8_t *)((h) + (o)) = (v))))
264
265 #define bus_space_write_2(t, h, o, v) \
266 ((void) t, ((void)(*(volatile uint16_t *)((h) + (o)) = (v))))
267
268 #define bus_space_write_4(t, h, o, v) \
269 ((void) t, ((void)(*(volatile uint32_t *)((h) + (o)) = (v))))
270
271 /*
272 * void bus_space_write_multi_N(bus_space_tag_t tag,
273 * bus_space_handle_t bsh, bus_size_t offset,
274 * const uintN_t *addr, size_t count);
275 *
276 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
277 * provided to bus space described by tag/handle/offset.
278 */
279
280 #define bus_space_write_multi_1(t, h, o, a, c) do { \
281 (void) t; \
282 __asm volatile (" \
283 movl %0,%%a0 ; \
284 movl %1,%%a1 ; \
285 movl %2,%%d0 ; \
286 1: movb %%a1@+,%%a0@ ; \
287 subql #1,%%d0 ; \
288 jne 1b" : \
289 : \
290 "r" ((h) + (o)), "g" (a), "g" (c) : \
291 "a0","a1","d0"); \
292 } while (0);
293
294 #define bus_space_write_multi_2(t, h, o, a, c) do { \
295 (void) t; \
296 __asm volatile (" \
297 movl %0,%%a0 ; \
298 movl %1,%%a1 ; \
299 movl %2,%%d0 ; \
300 1: movw %%a1@+,%%a0@ ; \
301 subql #1,%%d0 ; \
302 jne 1b" : \
303 : \
304 "r" ((h) + (o)), "g" (a), "g" (c) : \
305 "a0","a1","d0"); \
306 } while (0);
307
308 #define bus_space_write_multi_4(t, h, o, a, c) do { \
309 (void) t; \
310 __asm volatile (" \
311 movl %0,%%a0 ; \
312 movl %1,%%a1 ; \
313 movl %2,%%d0 ; \
314 1: movl %%a1@+,%%a0@ ; \
315 subql #1,%%d0 ; \
316 jne 1b" : \
317 : \
318 "r" ((h) + (o)), "g" (a), "g" (c) : \
319 "a0","a1","d0"); \
320 } while (0);
321
322 /*
323 * void bus_space_write_region_N(bus_space_tag_t tag,
324 * bus_space_handle_t bsh, bus_size_t offset,
325 * const uintN_t *addr, size_t count);
326 *
327 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
328 * to bus space described by tag/handle starting at `offset'.
329 */
330
331 #define bus_space_write_region_1(t, h, o, a, c) do { \
332 (void) t; \
333 __asm volatile (" \
334 movl %0,%%a0 ; \
335 movl %1,%%a1 ; \
336 movl %2,%%d0 ; \
337 1: movb %%a1@+,%%a0@+ ; \
338 subql #1,%%d0 ; \
339 jne 1b" : \
340 : \
341 "r" ((h) + (o)), "g" (a), "g" (c) : \
342 "a0","a1","d0"); \
343 } while (0);
344
345 #define bus_space_write_region_2(t, h, o, a, c) do { \
346 (void) t; \
347 __asm volatile (" \
348 movl %0,%%a0 ; \
349 movl %1,%%a1 ; \
350 movl %2,%%d0 ; \
351 1: movw %%a1@+,%%a0@+ ; \
352 subql #1,%%d0 ; \
353 jne 1b" : \
354 : \
355 "r" ((h) + (o)), "g" (a), "g" (c) : \
356 "a0","a1","d0"); \
357 } while (0);
358
359 #define bus_space_write_region_4(t, h, o, a, c) do { \
360 (void) t; \
361 __asm volatile (" \
362 movl %0,%%a0 ; \
363 movl %1,%%a1 ; \
364 movl %2,%%d0 ; \
365 1: movl %%a1@+,%%a0@+ ; \
366 subql #1,%%d0 ; \
367 jne 1b" : \
368 : \
369 "r" ((h) + (o)), "g" (a), "g" (c) : \
370 "a0","a1","d0"); \
371 } while (0);
372
373 /*
374 * void bus_space_set_multi_N(bus_space_tag_t tag,
375 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
376 * size_t count);
377 *
378 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
379 * by tag/handle/offset `count' times.
380 */
381
382 #define bus_space_set_multi_1(t, h, o, val, c) do { \
383 (void) t; \
384 __asm volatile (" \
385 movl %0,%%a0 ; \
386 movl %1,%%d1 ; \
387 movl %2,%%d0 ; \
388 1: movb %%d1,%%a0@ ; \
389 subql #1,%%d0 ; \
390 jne 1b" : \
391 : \
392 "r" ((h) + (o)), "g" (val), "g" (c) : \
393 "a0","d0","d1"); \
394 } while (0);
395
396 #define bus_space_set_multi_2(t, h, o, val, c) do { \
397 (void) t; \
398 __asm volatile (" \
399 movl %0,%%a0 ; \
400 movl %1,%%d1 ; \
401 movl %2,%%d0 ; \
402 1: movw %%d1,%%a0@ ; \
403 subql #1,%%d0 ; \
404 jne 1b" : \
405 : \
406 "r" ((h) + (o)), "g" (val), "g" (c) : \
407 "a0","d0","d1"); \
408 } while (0);
409
410 #define bus_space_set_multi_4(t, h, o, val, c) do { \
411 (void) t; \
412 __asm volatile (" \
413 movl %0,%%a0 ; \
414 movl %1,%%d1 ; \
415 movl %2,%%d0 ; \
416 1: movl %%d1,%%a0@ ; \
417 subql #1,%%d0 ; \
418 jne 1b" : \
419 : \
420 "r" ((h) + (o)), "g" (val), "g" (c) : \
421 "a0","d0","d1"); \
422 } while (0);
423
424 /*
425 * void bus_space_set_region_N(bus_space_tag_t tag,
426 * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
427 * size_t count);
428 *
429 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
430 * by tag/handle starting at `offset'.
431 */
432
433 #define bus_space_set_region_1(t, h, o, val, c) do { \
434 (void) t; \
435 __asm volatile (" \
436 movl %0,%%a0 ; \
437 movl %1,%%d1 ; \
438 movl %2,%%d0 ; \
439 1: movb %%d1,%%a0@+ ; \
440 subql #1,%%d0 ; \
441 jne 1b" : \
442 : \
443 "r" ((h) + (o)), "g" (val), "g" (c) : \
444 "a0","d0","d1"); \
445 } while (0);
446
447 #define bus_space_set_region_2(t, h, o, val, c) do { \
448 (void) t; \
449 __asm volatile (" \
450 movl %0,%%a0 ; \
451 movl %1,%%d1 ; \
452 movl %2,%%d0 ; \
453 1: movw %%d1,%%a0@+ ; \
454 subql #1,%%d0 ; \
455 jne 1b" : \
456 : \
457 "r" ((h) + (o)), "g" (val), "g" (c) : \
458 "a0","d0","d1"); \
459 } while (0);
460
461 #define bus_space_set_region_4(t, h, o, val, c) do { \
462 (void) t; \
463 __asm volatile (" \
464 movl %0,%%a0 ; \
465 movl %1,%%d1 ; \
466 movl %2,%%d0 ; \
467 1: movl %%d1,%%a0@+ ; \
468 subql #1,%%d0 ; \
469 jne 1b" : \
470 : \
471 "r" ((h) + (o)), "g" (val), "g" (c) : \
472 "a0","d0","d1"); \
473 } while (0);
474
475 /*
476 * void bus_space_copy_N(bus_space_tag_t tag,
477 * bus_space_handle_t bsh1, bus_size_t off1,
478 * bus_space_handle_t bsh2, bus_size_t off2,
479 * size_t count);
480 *
481 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
482 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
483 */
484
485 #define __NEXT68K_copy_region_N(BYTES) \
486 static __inline void __CONCAT(bus_space_copy_region_,BYTES) \
487 (bus_space_tag_t, \
488 bus_space_handle_t, bus_size_t, \
489 bus_space_handle_t, bus_size_t, \
490 bus_size_t); \
491 \
492 static __inline void \
493 __CONCAT(bus_space_copy_region_,BYTES)( \
494 bus_space_tag_t t, \
495 bus_space_handle_t h1, \
496 bus_size_t o1, \
497 bus_space_handle_t h2, \
498 bus_size_t o2, \
499 bus_size_t c) \
500 { \
501 bus_size_t o; \
502 \
503 if ((h1 + o1) >= (h2 + o2)) { \
504 /* src after dest: copy forward */ \
505 for (o = 0; c != 0; c--, o += BYTES) \
506 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
507 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
508 } else { \
509 /* dest after src: copy backwards */ \
510 for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
511 __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
512 __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
513 } \
514 }
515 __NEXT68K_copy_region_N(1)
516 __NEXT68K_copy_region_N(2)
517 __NEXT68K_copy_region_N(4)
518
519 #undef __NEXT68K_copy_region_N
520
521 /*
522 * Bus read/write barrier methods.
523 *
524 * void bus_space_barrier(bus_space_tag_t tag,
525 * bus_space_handle_t bsh, bus_size_t offset,
526 * bus_size_t len, int flags);
527 *
528 * Note: the 680x0 does not currently require barriers, but we must
529 * provide the flags to MI code.
530 */
531 #define bus_space_barrier(t, h, o, l, f) \
532 ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
533 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
534 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
535
536 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
537
538 #endif /* _NEXT68K_BUS_SPACE_H_ */
539