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