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