bus.h revision 1.2 1 /* $NetBSD: bus.h,v 1.2 1998/03/22 17:58:01 is Exp $ */
2
3 /*
4 * Copyright (c) 1996 Leo Weppelman. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Leo Weppelman for the
17 * NetBSD Project.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef _AMIGA_BUS_H_
34 #define _AMIGA_BUS_H_
35
36 /*
37 * Memory addresses (in bus space)
38 */
39 typedef u_long bus_addr_t;
40 typedef u_long bus_size_t;
41
42 /*
43 * Access methods for bus resources and address space.
44 */
45 typedef struct bus_space_tag {
46 bus_addr_t base;
47 u_char stride;
48 } *bus_space_tag_t;
49
50 typedef u_long bus_space_handle_t;
51
52 void bus_space_read_multi_1 __P((bus_space_tag_t, bus_space_handle_t,
53 int, caddr_t, int));
54 void bus_space_read_multi_2 __P((bus_space_tag_t, bus_space_handle_t,
55 int, caddr_t, int));
56 void bus_space_read_multi_4 __P((bus_space_tag_t, bus_space_handle_t,
57 int, caddr_t, int));
58 void bus_space_read_multi_8 __P((bus_space_tag_t, bus_space_handle_t,
59 int, caddr_t, int));
60 void bus_space_write_multi_1 __P((bus_space_tag_t, bus_space_handle_t,
61 int, caddr_t, int));
62 void bus_space_write_multi_2 __P((bus_space_tag_t, bus_space_handle_t,
63 int, caddr_t, int));
64 void bus_space_write_multi_4 __P((bus_space_tag_t, bus_space_handle_t,
65 int, caddr_t, int));
66 void bus_space_write_multi_8 __P((bus_space_tag_t, bus_space_handle_t,
67 int, caddr_t, int));
68
69 #if 0
70 int bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t,
71 int, bus_space_handle_t *));
72 void bus_space_unmap __P((bus_space_tag_t, bus_space_handle_t,
73 bus_size_t));
74 #endif
75
76 #define bus_space_map(tag,off,size,cache,handle) \
77 (*(handle) = (tag)->base + ((off)<<(tag)->stride), 0)
78
79 #define bus_space_subregion(tag, handle, offset, size, nhandlep) \
80 (*(nhandlep) = (handle) + ((offset)<<(tag)->stride), 0)
81
82 #define bus_space_unmap(tag,handle,size) (void)0
83
84 #define bus_space_read_1(t, h, o) \
85 ((void) t, (*(volatile u_int8_t *)((h) + ((o)<<(t)->stride))))
86
87 #define bus_space_write_1(t, h, o, v) \
88 ((void) t, ((void)(*(volatile u_int8_t *)((h) + ((o)<<(t)->stride)) = (v))))
89
90 extern __inline__ void
91 bus_space_read_multi_1(t, h, o, a, c)
92 bus_space_tag_t t;
93 bus_space_handle_t h;
94 int o, c;
95 caddr_t a;
96 {
97 for (; c; a++, c--)
98 *(u_int8_t *)a = bus_space_read_1(t, h, o);
99 }
100 #ifdef notyet
101 extern __inline__ void
102 bus_space_read_multi_2(t, h, o, a, c)
103 bus_space_tag_t t;
104 bus_space_handle_t h;
105 int o, c;
106 caddr_t a;
107 {
108 for (; c; a += 2, c--)
109 *(u_int16_t *)a = bus_space_read_2(t, h, o);
110 }
111
112 extern __inline__ void
113 bus_space_read_multi_4(t, h, o, a, c)
114 bus_space_tag_t t;
115 bus_space_handle_t h;
116 int o, c;
117 caddr_t a;
118 {
119 for (; c; a += 4, c--)
120 *(u_int32_t *)a = bus_space_read_4(t, h, o);
121 }
122
123 extern __inline__ void
124 bus_space_read_multi_8(t, h, o, a, c)
125 bus_space_tag_t t;
126 bus_space_handle_t h;
127 int o, c;
128 caddr_t a;
129 {
130 for (; c; a += 8, c--)
131 *(u_int64_t *)a = bus_space_read_8(t, h, o);
132 }
133 #endif
134
135 extern __inline__ void
136 bus_space_write_multi_1(t, h, o, a, c)
137 bus_space_tag_t t;
138 bus_space_handle_t h;
139 int o, c;
140 caddr_t a;
141 {
142 for (; c; a++, c--)
143 bus_space_write_1(t, h, o, *(u_int8_t *)a);
144 }
145
146 #ifdef notyet
147 extern __inline__ void
148 bus_space_write_multi_2(t, h, o, a, c)
149 bus_space_tag_t t;
150 bus_space_handle_t h;
151 int o, c;
152 caddr_t a;
153 {
154 for (; c; a += 2, c--)
155 bus_space_write_2(t, h, o, *(u_int16_t *)a);
156 }
157
158 extern __inline__ void
159 bus_space_write_multi_4(t, h, o, a, c)
160 bus_space_tag_t t;
161 bus_space_handle_t h;
162 int o, c;
163 caddr_t a;
164 {
165 for (; c; a += 4, c--)
166 bus_space_write_4(t, h, o, *(u_int32_t *)a);
167 }
168
169 extern __inline__ void
170 bus_space_write_multi_8(t, h, o, a, c)
171 bus_space_tag_t t;
172 bus_space_handle_t h;
173 int o, c;
174 caddr_t a;
175 {
176 for (; c; a += 8, c--)
177 bus_space_write_8(t, h, o, *(u_int64_t *)a);
178 }
179 #endif
180
181 #endif /* _AMIGA_BUS_H_ */
182