bus.h revision 1.16 1 1.16 tsutsui /* $NetBSD: bus.h,v 1.16 2011/02/12 05:15:39 tsutsui Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 thorpej * NASA Ames Research Center.
10 1.1 thorpej *
11 1.1 thorpej * Redistribution and use in source and binary forms, with or without
12 1.1 thorpej * modification, are permitted provided that the following conditions
13 1.1 thorpej * are met:
14 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer.
16 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.1 thorpej * documentation and/or other materials provided with the distribution.
19 1.1 thorpej *
20 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
31 1.1 thorpej */
32 1.1 thorpej
33 1.1 thorpej /*
34 1.1 thorpej * Copyright (C) 1997 Scott Reynolds. All rights reserved.
35 1.1 thorpej *
36 1.1 thorpej * Redistribution and use in source and binary forms, with or without
37 1.1 thorpej * modification, are permitted provided that the following conditions
38 1.1 thorpej * are met:
39 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
40 1.1 thorpej * notice, this list of conditions and the following disclaimer.
41 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
43 1.1 thorpej * documentation and/or other materials provided with the distribution.
44 1.1 thorpej * 3. The name of the author may not be used to endorse or promote products
45 1.1 thorpej * derived from this software without specific prior written permission
46 1.1 thorpej *
47 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 1.1 thorpej * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 1.1 thorpej * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 1.1 thorpej * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 1.1 thorpej * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 1.1 thorpej * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 1.1 thorpej * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 1.1 thorpej * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 1.1 thorpej * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 1.1 thorpej * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 1.1 thorpej */
58 1.1 thorpej
59 1.1 thorpej #ifndef _HP300_BUS_H_
60 1.1 thorpej #define _HP300_BUS_H_
61 1.1 thorpej
62 1.1 thorpej /*
63 1.1 thorpej * Values for the hp300 bus space tag, not to be used directly by MI code.
64 1.1 thorpej */
65 1.1 thorpej #define HP300_BUS_SPACE_INTIO 0 /* space is intio space */
66 1.1 thorpej #define HP300_BUS_SPACE_DIO 1 /* space is dio space */
67 1.16 tsutsui #define HP300_BUS_SPACE_SGC 2 /* space is sgc space */
68 1.1 thorpej
69 1.1 thorpej /*
70 1.1 thorpej * Bus address and size types
71 1.1 thorpej */
72 1.1 thorpej typedef u_long bus_addr_t;
73 1.1 thorpej typedef u_long bus_size_t;
74 1.1 thorpej
75 1.1 thorpej /*
76 1.1 thorpej * Access methods for bus resources and address space.
77 1.1 thorpej */
78 1.7 tsutsui typedef struct bus_space_tag *bus_space_tag_t;
79 1.7 tsutsui typedef u_long bus_space_handle_t;
80 1.7 tsutsui
81 1.7 tsutsui /*
82 1.7 tsutsui * Implementation specific structures.
83 1.7 tsutsui * XXX Don't use outside of bus_space definitions!
84 1.7 tsutsui * XXX maybe this should be encapsuled in a non-global .h file?
85 1.8 tsutsui */
86 1.7 tsutsui
87 1.7 tsutsui struct bus_space_tag {
88 1.7 tsutsui u_int bustype;
89 1.7 tsutsui
90 1.10 tsutsui uint8_t (*bsr1)(bus_space_tag_t, bus_space_handle_t,
91 1.9 thorpej bus_size_t);
92 1.10 tsutsui uint16_t (*bsr2)(bus_space_tag_t, bus_space_handle_t,
93 1.9 thorpej bus_size_t);
94 1.10 tsutsui uint32_t (*bsr4)(bus_space_tag_t, bus_space_handle_t,
95 1.9 thorpej bus_size_t);
96 1.9 thorpej void (*bsrm1)(bus_space_tag_t, bus_space_handle_t,
97 1.10 tsutsui bus_size_t, uint8_t *, bus_size_t);
98 1.9 thorpej void (*bsrm2)(bus_space_tag_t, bus_space_handle_t,
99 1.10 tsutsui bus_size_t, uint16_t *, bus_size_t);
100 1.9 thorpej void (*bsrm4)(bus_space_tag_t, bus_space_handle_t,
101 1.10 tsutsui bus_size_t, uint32_t *, bus_size_t);
102 1.9 thorpej void (*bsrr1)(bus_space_tag_t, bus_space_handle_t,
103 1.10 tsutsui bus_size_t, uint8_t *, bus_size_t);
104 1.9 thorpej void (*bsrr2)(bus_space_tag_t, bus_space_handle_t,
105 1.10 tsutsui bus_size_t, uint16_t *, bus_size_t);
106 1.9 thorpej void (*bsrr4)(bus_space_tag_t, bus_space_handle_t,
107 1.10 tsutsui bus_size_t, uint32_t *, bus_size_t);
108 1.9 thorpej void (*bsw1)(bus_space_tag_t, bus_space_handle_t,
109 1.10 tsutsui bus_size_t, uint8_t);
110 1.9 thorpej void (*bsw2)(bus_space_tag_t, bus_space_handle_t,
111 1.10 tsutsui bus_size_t, uint16_t);
112 1.9 thorpej void (*bsw4)(bus_space_tag_t, bus_space_handle_t,
113 1.10 tsutsui bus_size_t, uint32_t);
114 1.9 thorpej void (*bswm1)(bus_space_tag_t, bus_space_handle_t,
115 1.10 tsutsui bus_size_t, const uint8_t *, bus_size_t);
116 1.9 thorpej void (*bswm2)(bus_space_tag_t, bus_space_handle_t,
117 1.10 tsutsui bus_size_t, const uint16_t *, bus_size_t);
118 1.9 thorpej void (*bswm4)(bus_space_tag_t, bus_space_handle_t,
119 1.10 tsutsui bus_size_t, const uint32_t *, bus_size_t);
120 1.9 thorpej void (*bswr1)(bus_space_tag_t, bus_space_handle_t ,
121 1.10 tsutsui bus_size_t, const uint8_t *, bus_size_t);
122 1.9 thorpej void (*bswr2)(bus_space_tag_t, bus_space_handle_t,
123 1.10 tsutsui bus_size_t, const uint16_t *, bus_size_t);
124 1.9 thorpej void (*bswr4)(bus_space_tag_t, bus_space_handle_t,
125 1.10 tsutsui bus_size_t, const uint32_t *, bus_size_t);
126 1.9 thorpej void (*bssm1)(bus_space_tag_t, bus_space_handle_t,
127 1.10 tsutsui bus_size_t, uint8_t, bus_size_t);
128 1.9 thorpej void (*bssm2)(bus_space_tag_t, bus_space_handle_t,
129 1.10 tsutsui bus_size_t, uint16_t, bus_size_t);
130 1.9 thorpej void (*bssm4)(bus_space_tag_t, bus_space_handle_t,
131 1.10 tsutsui bus_size_t, uint32_t, bus_size_t);
132 1.9 thorpej void (*bssr1)(bus_space_tag_t, bus_space_handle_t,
133 1.10 tsutsui bus_size_t, uint8_t, bus_size_t);
134 1.9 thorpej void (*bssr2)(bus_space_tag_t, bus_space_handle_t,
135 1.10 tsutsui bus_size_t, uint16_t, bus_size_t);
136 1.9 thorpej void (*bssr4)(bus_space_tag_t, bus_space_handle_t,
137 1.10 tsutsui bus_size_t, uint32_t, bus_size_t);
138 1.7 tsutsui };
139 1.1 thorpej
140 1.1 thorpej /*
141 1.9 thorpej * int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
142 1.9 thorpej * bus_size_t size, int flags, bus_space_handle_t *bshp);
143 1.1 thorpej *
144 1.1 thorpej * Map a region of bus space.
145 1.1 thorpej */
146 1.1 thorpej
147 1.1 thorpej #define BUS_SPACE_MAP_CACHEABLE 0x01
148 1.1 thorpej #define BUS_SPACE_MAP_LINEAR 0x02
149 1.7 tsutsui #define BUS_SPACE_MAP_PREFETCHABLE 0x04
150 1.1 thorpej
151 1.9 thorpej int bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
152 1.9 thorpej int, bus_space_handle_t *);
153 1.1 thorpej
154 1.1 thorpej /*
155 1.9 thorpej * void bus_space_unmap(bus_space_tag_t t,
156 1.9 thorpej * bus_space_handle_t bsh, bus_size_t size);
157 1.1 thorpej *
158 1.1 thorpej * Unmap a region of bus space.
159 1.1 thorpej */
160 1.1 thorpej
161 1.9 thorpej void bus_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t);
162 1.1 thorpej
163 1.1 thorpej /*
164 1.9 thorpej * int bus_space_subregion(bus_space_tag_t t,
165 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
166 1.9 thorpej * bus_space_handle_t *nbshp);
167 1.1 thorpej *
168 1.1 thorpej * Get a new handle for a subregion of an already-mapped area of bus space.
169 1.1 thorpej */
170 1.1 thorpej
171 1.9 thorpej int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
172 1.9 thorpej bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
173 1.1 thorpej
174 1.1 thorpej /*
175 1.9 thorpej * int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
176 1.1 thorpej * bus_addr_t rend, bus_size_t size, bus_size_t align,
177 1.1 thorpej * bus_size_t boundary, int flags, bus_addr_t *addrp,
178 1.9 thorpej * bus_space_handle_t *bshp);
179 1.1 thorpej *
180 1.1 thorpej * Allocate a region of bus space.
181 1.1 thorpej */
182 1.1 thorpej
183 1.9 thorpej int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
184 1.1 thorpej bus_addr_t rend, bus_size_t size, bus_size_t align,
185 1.1 thorpej bus_size_t boundary, int cacheable, bus_addr_t *addrp,
186 1.9 thorpej bus_space_handle_t *bshp);
187 1.1 thorpej
188 1.1 thorpej /*
189 1.9 thorpej * int bus_space_free(bus_space_tag_t t,
190 1.9 thorpej * bus_space_handle_t bsh, bus_size_t size);
191 1.1 thorpej *
192 1.1 thorpej * Free a region of bus space.
193 1.1 thorpej */
194 1.1 thorpej
195 1.9 thorpej void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
196 1.9 thorpej bus_size_t size);
197 1.5 gmcgarry
198 1.5 gmcgarry /*
199 1.9 thorpej * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
200 1.5 gmcgarry *
201 1.5 gmcgarry * Get the kernel virtual address for the mapped bus space.
202 1.5 gmcgarry * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
203 1.5 gmcgarry * (XXX not enforced)
204 1.5 gmcgarry */
205 1.6 gmcgarry #define bus_space_vaddr(t, h) (void *)(h)
206 1.1 thorpej
207 1.1 thorpej /*
208 1.9 thorpej * int hp300_bus_space_probe(bus_space_tag_t t,
209 1.9 thorpej * bus_space_handle_t bsh, bus_size_t offset, int sz);
210 1.1 thorpej *
211 1.1 thorpej * Probe the bus at t/bsh/offset, using sz as the size of the load.
212 1.1 thorpej *
213 1.1 thorpej * This is a machine-dependent extension, and is not to be used by
214 1.1 thorpej * machine-independent code.
215 1.1 thorpej */
216 1.1 thorpej
217 1.9 thorpej int hp300_bus_space_probe(bus_space_tag_t t,
218 1.9 thorpej bus_space_handle_t bsh, bus_size_t offset, int sz);
219 1.1 thorpej
220 1.1 thorpej /*
221 1.9 thorpej * u_intN_t bus_space_read_N(bus_space_tag_t tag,
222 1.9 thorpej * bus_space_handle_t bsh, bus_size_t offset);
223 1.1 thorpej *
224 1.1 thorpej * Read a 1, 2, 4, or 8 byte quantity from bus space
225 1.1 thorpej * described by tag/handle/offset.
226 1.1 thorpej */
227 1.1 thorpej
228 1.1 thorpej #define bus_space_read_1(t, h, o) \
229 1.7 tsutsui (((t)->bsr1 != NULL) ? ((t)->bsr1)(t, h, o) : \
230 1.10 tsutsui (*(volatile uint8_t *)((h) + (o))))
231 1.1 thorpej
232 1.1 thorpej #define bus_space_read_2(t, h, o) \
233 1.7 tsutsui (((t)->bsr2 != NULL) ? ((t)->bsr2)(t, h, o) : \
234 1.10 tsutsui (*(volatile uint16_t *)((h) + (o))))
235 1.1 thorpej
236 1.1 thorpej #define bus_space_read_4(t, h, o) \
237 1.7 tsutsui (((t)->bsr4 != NULL) ? ((t)->bsr4)(t, h, o) : \
238 1.10 tsutsui (*(volatile uint32_t *)((h) + (o))))
239 1.1 thorpej
240 1.1 thorpej #if 0 /* Cause a link error for bus_space_read_8 */
241 1.1 thorpej #define bus_space_read_8(t, h, o) !!! bus_space_read_8 unimplemented !!!
242 1.1 thorpej #endif
243 1.1 thorpej
244 1.1 thorpej /*
245 1.9 thorpej * void bus_space_read_multi_N(bus_space_tag_t tag,
246 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
247 1.9 thorpej * u_intN_t *addr, size_t count);
248 1.1 thorpej *
249 1.1 thorpej * Read `count' 1, 2, 4, or 8 byte quantities from bus space
250 1.1 thorpej * described by tag/handle/offset and copy into buffer provided.
251 1.1 thorpej */
252 1.1 thorpej
253 1.7 tsutsui #define bus_space_read_multi_1(t, h, o, a, c) \
254 1.7 tsutsui do { \
255 1.7 tsutsui if ((t)->bsrm1 != NULL) \
256 1.7 tsutsui ((t)->bsrm1)(t, h, o, a, c); \
257 1.7 tsutsui else { \
258 1.12 perry __asm volatile (" \
259 1.7 tsutsui movl %0,%%a0 ; \
260 1.7 tsutsui movl %1,%%a1 ; \
261 1.7 tsutsui movl %2,%%d0 ; \
262 1.7 tsutsui 1: movb %%a0@,%%a1@+ ; \
263 1.7 tsutsui subql #1,%%d0 ; \
264 1.7 tsutsui jne 1b" : \
265 1.7 tsutsui : \
266 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
267 1.7 tsutsui "%a0","%a1","%d0"); \
268 1.7 tsutsui } \
269 1.7 tsutsui } while (/* CONSTCOND */ 0)
270 1.7 tsutsui
271 1.7 tsutsui #define bus_space_read_multi_2(t, h, o, a, c) \
272 1.7 tsutsui do { \
273 1.7 tsutsui if ((t)->bsrm2 != NULL) \
274 1.7 tsutsui ((t)->bsrm2)(t, h, o, a, c); \
275 1.7 tsutsui else { \
276 1.12 perry __asm volatile (" \
277 1.7 tsutsui movl %0,%%a0 ; \
278 1.7 tsutsui movl %1,%%a1 ; \
279 1.7 tsutsui movl %2,%%d0 ; \
280 1.7 tsutsui 1: movw %%a0@,%%a1@+ ; \
281 1.7 tsutsui subql #1,%%d0 ; \
282 1.7 tsutsui jne 1b" : \
283 1.7 tsutsui : \
284 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
285 1.7 tsutsui "%a0","%a1","%d0"); \
286 1.7 tsutsui } \
287 1.7 tsutsui } while (/* CONSTCOND */ 0)
288 1.1 thorpej
289 1.1 thorpej #define bus_space_read_multi_4(t, h, o, a, c) do { \
290 1.7 tsutsui if ((t)->bsrm4 != NULL) \
291 1.7 tsutsui ((t)->bsrm4)(t, h, o, a, c); \
292 1.7 tsutsui else { \
293 1.12 perry __asm volatile (" \
294 1.7 tsutsui movl %0,%%a0 ; \
295 1.7 tsutsui movl %1,%%a1 ; \
296 1.7 tsutsui movl %2,%%d0 ; \
297 1.7 tsutsui 1: movl %%a0@,%%a1@+ ; \
298 1.7 tsutsui subql #1,%%d0 ; \
299 1.7 tsutsui jne 1b" : \
300 1.7 tsutsui : \
301 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
302 1.7 tsutsui "%a0","%a1","%d0"); \
303 1.7 tsutsui } \
304 1.7 tsutsui } while (/* CONSTCOND */ 0)
305 1.1 thorpej
306 1.1 thorpej #if 0 /* Cause a link error for bus_space_read_multi_8 */
307 1.1 thorpej #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
308 1.1 thorpej #endif
309 1.1 thorpej
310 1.1 thorpej /*
311 1.9 thorpej * void bus_space_read_region_N(bus_space_tag_t tag,
312 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
313 1.9 thorpej * u_intN_t *addr, size_t count);
314 1.1 thorpej *
315 1.1 thorpej * Read `count' 1, 2, 4, or 8 byte quantities from bus space
316 1.1 thorpej * described by tag/handle and starting at `offset' and copy into
317 1.1 thorpej * buffer provided.
318 1.1 thorpej */
319 1.1 thorpej
320 1.7 tsutsui #define bus_space_read_region_1(t, h, o, a, c) \
321 1.7 tsutsui do { \
322 1.7 tsutsui if ((t)->bsrr1 != NULL) \
323 1.7 tsutsui ((t)->bsrr1)(t, h, o, a, c); \
324 1.7 tsutsui else { \
325 1.12 perry __asm volatile (" \
326 1.7 tsutsui movl %0,%%a0 ; \
327 1.7 tsutsui movl %1,%%a1 ; \
328 1.7 tsutsui movl %2,%%d0 ; \
329 1.7 tsutsui 1: movb %%a0@+,%%a1@+ ; \
330 1.7 tsutsui subql #1,%%d0 ; \
331 1.7 tsutsui jne 1b" : \
332 1.7 tsutsui : \
333 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
334 1.7 tsutsui "%a0","%a1","%d0"); \
335 1.7 tsutsui } \
336 1.7 tsutsui } while (/* CONSTCOND */ 0)
337 1.7 tsutsui
338 1.7 tsutsui #define bus_space_read_region_2(t, h, o, a, c) \
339 1.7 tsutsui do { \
340 1.7 tsutsui if ((t)->bsrr2 != NULL) \
341 1.7 tsutsui ((t)->bsrr2)(t, h, o, a, c); \
342 1.7 tsutsui else { \
343 1.12 perry __asm volatile (" \
344 1.7 tsutsui movl %0,%%a0 ; \
345 1.7 tsutsui movl %1,%%a1 ; \
346 1.7 tsutsui movl %2,%%d0 ; \
347 1.7 tsutsui 1: movw %%a0@+,%%a1@+ ; \
348 1.7 tsutsui subql #1,%%d0 ; \
349 1.7 tsutsui jne 1b" : \
350 1.7 tsutsui : \
351 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
352 1.7 tsutsui "%a0","%a1","%d0"); \
353 1.7 tsutsui } \
354 1.7 tsutsui } while (/* CONSTCOND */ 0)
355 1.7 tsutsui
356 1.7 tsutsui #define bus_space_read_region_4(t, h, o, a, c) \
357 1.7 tsutsui do { \
358 1.7 tsutsui if ((t)->bsrr4 != NULL) \
359 1.7 tsutsui ((t)->bsrr4)(t, h, o, a, c); \
360 1.7 tsutsui else { \
361 1.12 perry __asm volatile (" \
362 1.7 tsutsui movl %0,%%a0 ; \
363 1.7 tsutsui movl %1,%%a1 ; \
364 1.7 tsutsui movl %2,%%d0 ; \
365 1.7 tsutsui 1: movl %%a0@+,%%a1@+ ; \
366 1.7 tsutsui subql #1,%%d0 ; \
367 1.7 tsutsui jne 1b" : \
368 1.7 tsutsui : \
369 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
370 1.7 tsutsui "%a0","%a1","%d0"); \
371 1.7 tsutsui } \
372 1.7 tsutsui } while (/* CONSTCOND */ 0)
373 1.1 thorpej
374 1.1 thorpej #if 0 /* Cause a link error for bus_space_read_region_8 */
375 1.1 thorpej #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
376 1.1 thorpej #endif
377 1.1 thorpej
378 1.1 thorpej /*
379 1.9 thorpej * void bus_space_write_N(bus_space_tag_t tag,
380 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
381 1.9 thorpej * u_intN_t value);
382 1.1 thorpej *
383 1.1 thorpej * Write the 1, 2, 4, or 8 byte value `value' to bus space
384 1.1 thorpej * described by tag/handle/offset.
385 1.1 thorpej */
386 1.1 thorpej
387 1.1 thorpej #define bus_space_write_1(t, h, o, v) \
388 1.7 tsutsui do { \
389 1.7 tsutsui if ((t)->bsw1 != NULL) \
390 1.7 tsutsui ((t)->bsw1)(t, h, o, v); \
391 1.7 tsutsui else \
392 1.10 tsutsui ((void)(*(volatile uint8_t *)((h) + (o)) = (v))); \
393 1.7 tsutsui } while (/* CONSTCOND */ 0)
394 1.1 thorpej
395 1.1 thorpej #define bus_space_write_2(t, h, o, v) \
396 1.7 tsutsui do { \
397 1.7 tsutsui if ((t)->bsw2 != NULL) \
398 1.7 tsutsui ((t)->bsw2)(t, h, o, v); \
399 1.7 tsutsui else \
400 1.10 tsutsui ((void)(*(volatile uint16_t *)((h) + (o)) = (v))); \
401 1.7 tsutsui } while (/* CONSTCOND */ 0)
402 1.1 thorpej
403 1.1 thorpej #define bus_space_write_4(t, h, o, v) \
404 1.7 tsutsui do { \
405 1.7 tsutsui if ((t)->bsw4 != NULL) \
406 1.7 tsutsui ((t)->bsw4)(t, h, o, v); \
407 1.7 tsutsui else \
408 1.10 tsutsui ((void)(*(volatile uint32_t *)((h) + (o)) = (v))); \
409 1.7 tsutsui } while (/* CONSTCOND */ 0)
410 1.1 thorpej
411 1.1 thorpej #if 0 /* Cause a link error for bus_space_write_8 */
412 1.1 thorpej #define bus_space_write_8 !!! bus_space_write_8 not implemented !!!
413 1.1 thorpej #endif
414 1.1 thorpej
415 1.1 thorpej /*
416 1.9 thorpej * void bus_space_write_multi_N(bus_space_tag_t tag,
417 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
418 1.9 thorpej * const u_intN_t *addr, size_t count);
419 1.1 thorpej *
420 1.1 thorpej * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
421 1.1 thorpej * provided to bus space described by tag/handle/offset.
422 1.1 thorpej */
423 1.1 thorpej
424 1.7 tsutsui #define bus_space_write_multi_1(t, h, o, a, c) \
425 1.7 tsutsui do { \
426 1.7 tsutsui if ((t)->bswm1 != NULL) \
427 1.7 tsutsui ((t)->bswm1)(t, h, o, a, c); \
428 1.7 tsutsui else { \
429 1.12 perry __asm volatile (" \
430 1.7 tsutsui movl %0,%%a0 ; \
431 1.7 tsutsui movl %1,%%a1 ; \
432 1.7 tsutsui movl %2,%%d0 ; \
433 1.7 tsutsui 1: movb %%a1@+,%%a0@ ; \
434 1.7 tsutsui subql #1,%%d0 ; \
435 1.7 tsutsui jne 1b" : \
436 1.7 tsutsui : \
437 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
438 1.7 tsutsui "%a0","%a1","%d0"); \
439 1.7 tsutsui } \
440 1.7 tsutsui } while (/* CONSTCOND */ 0)
441 1.7 tsutsui
442 1.7 tsutsui #define bus_space_write_multi_2(t, h, o, a, c) \
443 1.7 tsutsui do { \
444 1.7 tsutsui if ((t)->bswm2 != NULL) \
445 1.7 tsutsui ((t)->bswm2)(t, h, o, a, c); \
446 1.7 tsutsui else { \
447 1.12 perry __asm volatile (" \
448 1.7 tsutsui movl %0,%%a0 ; \
449 1.7 tsutsui movl %1,%%a1 ; \
450 1.7 tsutsui movl %2,%%d0 ; \
451 1.7 tsutsui 1: movw %%a1@+,%%a0@ ; \
452 1.7 tsutsui subql #1,%%d0 ; \
453 1.7 tsutsui jne 1b" : \
454 1.7 tsutsui : \
455 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
456 1.7 tsutsui "%a0","%a1","%d0"); \
457 1.7 tsutsui } \
458 1.7 tsutsui } while (/* CONSTCOND */ 0)
459 1.7 tsutsui
460 1.7 tsutsui #define bus_space_write_multi_4(t, h, o, a, c) \
461 1.7 tsutsui do { \
462 1.7 tsutsui (void) t; \
463 1.7 tsutsui if ((t)->bswm4 != NULL) \
464 1.7 tsutsui ((t)->bswm4)(t, h, o, a, c); \
465 1.7 tsutsui else { \
466 1.12 perry __asm volatile (" \
467 1.7 tsutsui movl %0,%%a0 ; \
468 1.7 tsutsui movl %1,%%a1 ; \
469 1.7 tsutsui movl %2,%%d0 ; \
470 1.7 tsutsui 1: movl %%a1@+,%%a0@ ; \
471 1.7 tsutsui subql #1,%%d0 ; \
472 1.7 tsutsui jne 1b" : \
473 1.7 tsutsui : \
474 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
475 1.7 tsutsui "%a0","%a1","%d0"); \
476 1.7 tsutsui } \
477 1.7 tsutsui } while (/* CONSTCOND */ 0)
478 1.1 thorpej
479 1.1 thorpej #if 0 /* Cause a link error for bus_space_write_8 */
480 1.1 thorpej #define bus_space_write_multi_8(t, h, o, a, c) \
481 1.1 thorpej !!! bus_space_write_multi_8 unimplimented !!!
482 1.1 thorpej #endif
483 1.1 thorpej
484 1.1 thorpej /*
485 1.9 thorpej * void bus_space_write_region_N(bus_space_tag_t tag,
486 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
487 1.9 thorpej * const u_intN_t *addr, size_t count);
488 1.1 thorpej *
489 1.1 thorpej * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
490 1.1 thorpej * to bus space described by tag/handle starting at `offset'.
491 1.1 thorpej */
492 1.1 thorpej
493 1.7 tsutsui #define bus_space_write_region_1(t, h, o, a, c) \
494 1.7 tsutsui do { \
495 1.7 tsutsui if ((t)->bswr1 != NULL) \
496 1.7 tsutsui ((t)->bswr1)(t, h, o, a, c); \
497 1.7 tsutsui else { \
498 1.12 perry __asm volatile (" \
499 1.7 tsutsui movl %0,%%a0 ; \
500 1.7 tsutsui movl %1,%%a1 ; \
501 1.7 tsutsui movl %2,%%d0 ; \
502 1.7 tsutsui 1: movb %%a1@+,%%a0@+ ; \
503 1.7 tsutsui subql #1,%%d0 ; \
504 1.7 tsutsui jne 1b" : \
505 1.7 tsutsui : \
506 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
507 1.7 tsutsui "%a0","%a1","%d0"); \
508 1.7 tsutsui } \
509 1.7 tsutsui } while (/* CONSTCOND */ 0)
510 1.7 tsutsui
511 1.7 tsutsui #define bus_space_write_region_2(t, h, o, a, c) \
512 1.7 tsutsui do { \
513 1.7 tsutsui if ((t)->bswr2) != NULL) \
514 1.7 tsutsui ((t)->bswr2)(t, h, o, a, c); \
515 1.7 tsutsui else { \
516 1.12 perry __asm volatile (" \
517 1.7 tsutsui movl %0,%%a0 ; \
518 1.7 tsutsui movl %1,%%a1 ; \
519 1.7 tsutsui movl %2,%%d0 ; \
520 1.7 tsutsui 1: movw %%a1@+,%%a0@+ ; \
521 1.7 tsutsui subql #1,%%d0 ; \
522 1.7 tsutsui jne 1b" : \
523 1.7 tsutsui : \
524 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
525 1.7 tsutsui "%a0","%a1","%d0"); \
526 1.7 tsutsui } \
527 1.7 tsutsui } while (/* CONSTCOND */ 0)
528 1.7 tsutsui
529 1.7 tsutsui #define bus_space_write_region_4(t, h, o, a, c) \
530 1.7 tsutsui do { \
531 1.7 tsutsui if ((t)->bswr4) != NULL) \
532 1.7 tsutsui ((t)->bswr4)(t, h, o, a, c); \
533 1.7 tsutsui else { \
534 1.12 perry __asm volatile (" \
535 1.7 tsutsui movl %0,%%a0 ; \
536 1.7 tsutsui movl %1,%%a1 ; \
537 1.7 tsutsui movl %2,%%d0 ; \
538 1.7 tsutsui 1: movl %%a1@+,%%a0@+ ; \
539 1.7 tsutsui subql #1,%%d0 ; \
540 1.7 tsutsui jne 1b" : \
541 1.7 tsutsui : \
542 1.7 tsutsui "r" ((h) + (o)), "g" (a), "g" (c) : \
543 1.7 tsutsui "%a0","%a1","%d0"); \
544 1.7 tsutsui } \
545 1.7 tsutsui } while (/* CONSTCOND */ 0)
546 1.1 thorpej
547 1.1 thorpej #if 0 /* Cause a link error for bus_space_write_region_8 */
548 1.1 thorpej #define bus_space_write_region_8 \
549 1.1 thorpej !!! bus_space_write_region_8 unimplemented !!!
550 1.1 thorpej #endif
551 1.1 thorpej
552 1.1 thorpej /*
553 1.9 thorpej * void bus_space_set_multi_N(bus_space_tag_t tag,
554 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
555 1.9 thorpej * size_t count);
556 1.1 thorpej *
557 1.1 thorpej * Write the 1, 2, 4, or 8 byte value `val' to bus space described
558 1.1 thorpej * by tag/handle/offset `count' times.
559 1.1 thorpej */
560 1.1 thorpej
561 1.7 tsutsui #define bus_space_set_multi_1(t, h, o, val, c) \
562 1.7 tsutsui do { \
563 1.7 tsutsui if ((t)->bssm1 != NULL) \
564 1.7 tsutsui ((t)->bssm1)(t, h, o, val, c); \
565 1.7 tsutsui else { \
566 1.12 perry __asm volatile (" \
567 1.7 tsutsui movl %0,%%a0 ; \
568 1.7 tsutsui movl %1,%%d1 ; \
569 1.7 tsutsui movl %2,%%d0 ; \
570 1.7 tsutsui 1: movb %%d1,%%a0@ ; \
571 1.7 tsutsui subql #1,%%d0 ; \
572 1.7 tsutsui jne 1b" : \
573 1.7 tsutsui : \
574 1.7 tsutsui "r" ((h) + (o)), "g" (val), "g" (c) : \
575 1.7 tsutsui "%a0","%d0","%d1"); \
576 1.7 tsutsui } \
577 1.7 tsutsui } while (/* CONSTCOND */ 0)
578 1.7 tsutsui
579 1.7 tsutsui #define bus_space_set_multi_2(t, h, o, val, c) \
580 1.7 tsutsui do { \
581 1.7 tsutsui if ((t)->bssm2 != NULL) \
582 1.7 tsutsui ((t)->bssm2)(t, h, o, val, c); \
583 1.7 tsutsui else { \
584 1.12 perry __asm volatile (" \
585 1.7 tsutsui movl %0,%%a0 ; \
586 1.7 tsutsui movl %1,%%d1 ; \
587 1.7 tsutsui movl %2,%%d0 ; \
588 1.7 tsutsui 1: movw %%d1,%%a0@ ; \
589 1.7 tsutsui subql #1,%%d0 ; \
590 1.7 tsutsui jne 1b" : \
591 1.7 tsutsui : \
592 1.7 tsutsui "r" ((h) + (o)), "g" (val), "g" (c) : \
593 1.7 tsutsui "%a0","%d0","%d1"); \
594 1.7 tsutsui } \
595 1.7 tsutsui } while (/* CONSTCOND */ 0)
596 1.7 tsutsui
597 1.7 tsutsui #define bus_space_set_multi_4(t, h, o, val, c) \
598 1.7 tsutsui do { \
599 1.7 tsutsui if ((t)->bssm4 != NULL) \
600 1.7 tsutsui ((t)->bssm4)(t, h, o, val, c); \
601 1.7 tsutsui else { \
602 1.12 perry __asm volatile (" \
603 1.7 tsutsui movl %0,%%a0 ; \
604 1.7 tsutsui movl %1,%%d1 ; \
605 1.7 tsutsui movl %2,%%d0 ; \
606 1.7 tsutsui 1: movl %%d1,%%a0@ ; \
607 1.7 tsutsui subql #1,%%d0 ; \
608 1.7 tsutsui jne 1b" : \
609 1.7 tsutsui : \
610 1.7 tsutsui "r" ((h) + (o)), "g" (val), "g" (c) : \
611 1.7 tsutsui "%a0","%d0","%d1"); \
612 1.7 tsutsui } \
613 1.7 tsutsui } while (/* CONSTCOND */ 0)
614 1.1 thorpej
615 1.1 thorpej #if 0 /* Cause a link error for bus_space_set_multi_8 */
616 1.1 thorpej #define bus_space_set_multi_8 \
617 1.1 thorpej !!! bus_space_set_multi_8 unimplemented !!!
618 1.1 thorpej #endif
619 1.1 thorpej
620 1.1 thorpej /*
621 1.9 thorpej * void bus_space_set_region_N(bus_space_tag_t tag,
622 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
623 1.9 thorpej * size_t count);
624 1.1 thorpej *
625 1.1 thorpej * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
626 1.1 thorpej * by tag/handle starting at `offset'.
627 1.1 thorpej */
628 1.1 thorpej
629 1.7 tsutsui #define bus_space_set_region_1(t, h, o, val, c) \
630 1.7 tsutsui do { \
631 1.7 tsutsui if ((t)->bssr1 != NULL) \
632 1.7 tsutsui ((t)->bssr1)(t, h, o, val, c); \
633 1.7 tsutsui else { \
634 1.12 perry __asm volatile (" \
635 1.7 tsutsui movl %0,%%a0 ; \
636 1.7 tsutsui movl %1,%%d1 ; \
637 1.7 tsutsui movl %2,%%d0 ; \
638 1.7 tsutsui 1: movb %%d1,%%a0@+ ; \
639 1.7 tsutsui subql #1,%%d0 ; \
640 1.7 tsutsui jne 1b" : \
641 1.7 tsutsui : \
642 1.7 tsutsui "r" ((h) + (o)), "g" (val), "g" (c) : \
643 1.7 tsutsui "%a0","%d0","%d1"); \
644 1.7 tsutsui } \
645 1.7 tsutsui } while (/* CONSTCOND */ 0)
646 1.7 tsutsui
647 1.7 tsutsui #define bus_space_set_region_2(t, h, o, val, c) \
648 1.7 tsutsui do { \
649 1.7 tsutsui if ((t)->bssr2 != NULL) \
650 1.7 tsutsui ((t)->bssr2)(t, h, o, val, c); \
651 1.7 tsutsui else { \
652 1.12 perry __asm volatile (" \
653 1.7 tsutsui movl %0,%%a0 ; \
654 1.7 tsutsui movl %1,%%d1 ; \
655 1.7 tsutsui movl %2,%%d0 ; \
656 1.7 tsutsui 1: movw %%d1,%%a0@+ ; \
657 1.7 tsutsui subql #1,%%d0 ; \
658 1.7 tsutsui jne 1b" : \
659 1.7 tsutsui : \
660 1.7 tsutsui "r" ((h) + (o)), "g" (val), "g" (c) : \
661 1.7 tsutsui "%a0","%d0","%d1"); \
662 1.7 tsutsui } \
663 1.7 tsutsui } while (/* CONSTCOND */ 0)
664 1.7 tsutsui
665 1.7 tsutsui #define bus_space_set_region_4(t, h, o, val, c) \
666 1.7 tsutsui do { \
667 1.7 tsutsui (void) t; \
668 1.7 tsutsui if ((t)->bssr4 != NULL) \
669 1.7 tsutsui ((t)->bssr4)(t, h, o, val, c); \
670 1.7 tsutsui else { \
671 1.12 perry __asm volatile (" \
672 1.7 tsutsui movl %0,%%a0 ; \
673 1.7 tsutsui movl %1,%%d1 ; \
674 1.7 tsutsui movl %2,%%d0 ; \
675 1.7 tsutsui 1: movl %%d1,%%a0@+ ; \
676 1.7 tsutsui subql #1,%%d0 ; \
677 1.7 tsutsui jne 1b" : \
678 1.7 tsutsui : \
679 1.7 tsutsui "r" ((h) + (o)), "g" (val), "g" (c) : \
680 1.7 tsutsui "%a0","%d0","%d1"); \
681 1.7 tsutsui } \
682 1.7 tsutsui } while (/* CONSTCOND */ 0)
683 1.1 thorpej
684 1.1 thorpej #if 0 /* Cause a link error for bus_space_set_region_8 */
685 1.1 thorpej #define bus_space_set_region_8 \
686 1.1 thorpej !!! bus_space_set_region_8 unimplemented !!!
687 1.1 thorpej #endif
688 1.1 thorpej
689 1.1 thorpej /*
690 1.9 thorpej * void bus_space_copy_region_N(bus_space_tag_t tag,
691 1.1 thorpej * bus_space_handle_t bsh1, bus_size_t off1,
692 1.1 thorpej * bus_space_handle_t bsh2, bus_size_t off2,
693 1.9 thorpej * bus_size_t count);
694 1.1 thorpej *
695 1.1 thorpej * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
696 1.1 thorpej * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
697 1.1 thorpej */
698 1.1 thorpej
699 1.1 thorpej #define __HP300_copy_region_N(BYTES) \
700 1.14 christos static __inline void \
701 1.9 thorpej __CONCAT(bus_space_copy_region_,BYTES)(bus_space_tag_t t, \
702 1.9 thorpej bus_space_handle_t h1, bus_size_t o1, bus_space_handle_t h2, \
703 1.9 thorpej bus_size_t o2, bus_size_t c) \
704 1.1 thorpej { \
705 1.1 thorpej bus_size_t o; \
706 1.1 thorpej \
707 1.1 thorpej if ((h1 + o1) >= (h2 + o2)) { \
708 1.1 thorpej /* src after dest: copy forward */ \
709 1.1 thorpej for (o = 0; c != 0; c--, o += BYTES) \
710 1.1 thorpej __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
711 1.1 thorpej __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
712 1.1 thorpej } else { \
713 1.1 thorpej /* dest after src: copy backwards */ \
714 1.1 thorpej for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
715 1.1 thorpej __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
716 1.1 thorpej __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
717 1.1 thorpej } \
718 1.1 thorpej }
719 1.1 thorpej __HP300_copy_region_N(1)
720 1.1 thorpej __HP300_copy_region_N(2)
721 1.1 thorpej __HP300_copy_region_N(4)
722 1.1 thorpej #if 0 /* Cause a link error for bus_space_copy_region_8 */
723 1.1 thorpej #define bus_space_copy_region_8 \
724 1.1 thorpej !!! bus_space_copy_region_8 unimplemented !!!
725 1.1 thorpej #endif
726 1.1 thorpej
727 1.1 thorpej #undef __HP300_copy_region_N
728 1.1 thorpej
729 1.1 thorpej /*
730 1.1 thorpej * Bus read/write barrier methods.
731 1.1 thorpej *
732 1.9 thorpej * void bus_space_barrier(bus_space_tag_t tag,
733 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
734 1.9 thorpej * bus_size_t len, int flags);
735 1.1 thorpej *
736 1.1 thorpej * Note: the 680x0 does not currently require barriers, but we must
737 1.1 thorpej * provide the flags to MI code.
738 1.1 thorpej */
739 1.1 thorpej #define bus_space_barrier(t, h, o, l, f) \
740 1.1 thorpej ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
741 1.1 thorpej #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
742 1.1 thorpej #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
743 1.2 drochner
744 1.2 drochner #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
745 1.1 thorpej
746 1.1 thorpej #endif /* _HP300_BUS_H_ */
747