bus_space.h revision 1.1 1 1.1 thorpej /* $NetBSD: bus_space.h,v 1.1 2024/01/02 07:41:00 thorpej 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 _VIRT68K_BUS_SPACE_H_
60 1.1 thorpej #define _VIRT68K_BUS_SPACE_H_
61 1.1 thorpej
62 1.1 thorpej /*
63 1.1 thorpej * Addresses (in bus space).
64 1.1 thorpej */
65 1.1 thorpej typedef u_long bus_addr_t;
66 1.1 thorpej typedef u_long bus_size_t;
67 1.1 thorpej
68 1.1 thorpej #define PRIxBUSADDR "lx"
69 1.1 thorpej #define PRIxBUSSIZE "lx"
70 1.1 thorpej #define PRIuBUSSIZE "lu"
71 1.1 thorpej
72 1.1 thorpej /*
73 1.1 thorpej * Access methods for bus resources and address space.
74 1.1 thorpej */
75 1.1 thorpej struct virt68k_bus_space_tag;
76 1.1 thorpej typedef struct virt68k_bus_space_tag *bus_space_tag_t;
77 1.1 thorpej typedef u_long bus_space_handle_t;
78 1.1 thorpej
79 1.1 thorpej #define PRIxBSH "lx"
80 1.1 thorpej
81 1.1 thorpej struct virt68k_bus_space_tag {
82 1.1 thorpej void *bs_cookie;
83 1.1 thorpej int (*bs_map)(void *, bus_addr_t, bus_size_t,
84 1.1 thorpej int, bus_space_handle_t *);
85 1.1 thorpej void (*bs_unmap)(void *, bus_space_handle_t, bus_size_t);
86 1.1 thorpej int (*bs_peek_1)(void *, bus_space_handle_t,
87 1.1 thorpej bus_size_t, uint8_t *);
88 1.1 thorpej int (*bs_peek_2)(void *, bus_space_handle_t,
89 1.1 thorpej bus_size_t, uint16_t *);
90 1.1 thorpej int (*bs_peek_4)(void *, bus_space_handle_t,
91 1.1 thorpej bus_size_t, uint32_t *);
92 1.1 thorpej #if 0
93 1.1 thorpej int (*bs_peek_8)(void *, bus_space_handle_t,
94 1.1 thorpej bus_size_t, uint64_t *);
95 1.1 thorpej #endif
96 1.1 thorpej int (*bs_poke_1)(void *, bus_space_handle_t,
97 1.1 thorpej bus_size_t, uint8_t);
98 1.1 thorpej int (*bs_poke_2)(void *, bus_space_handle_t,
99 1.1 thorpej bus_size_t, uint16_t);
100 1.1 thorpej int (*bs_poke_4)(void *, bus_space_handle_t,
101 1.1 thorpej bus_size_t, uint32_t);
102 1.1 thorpej #if 0
103 1.1 thorpej int (*bs_poke_8)(void *, bus_space_handle_t,
104 1.1 thorpej bus_size_t, uint64_t);
105 1.1 thorpej #endif
106 1.1 thorpej };
107 1.1 thorpej
108 1.1 thorpej /*
109 1.1 thorpej * int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
110 1.1 thorpej * bus_size_t size, int flags,
111 1.1 thorpej * bus_space_handle_t *bshp);
112 1.1 thorpej *
113 1.1 thorpej * Map a region of bus space.
114 1.1 thorpej */
115 1.1 thorpej #define bus_space_map(tag, offset, size, flags, handlep) \
116 1.1 thorpej (*((tag)->bs_map))((tag)->bs_cookie, (offset), (size), (flags), (handlep))
117 1.1 thorpej
118 1.1 thorpej /*
119 1.1 thorpej * Possible values for the 'flags' parameter of bus_space_map()
120 1.1 thorpej */
121 1.1 thorpej #define BUS_SPACE_MAP_CACHEABLE 0x01
122 1.1 thorpej #define BUS_SPACE_MAP_LINEAR 0x02
123 1.1 thorpej #define BUS_SPACE_MAP_PREFETCHABLE 0x04
124 1.1 thorpej
125 1.1 thorpej /*
126 1.1 thorpej * void bus_space_unmap(bus_space_tag_t t,
127 1.1 thorpej * bus_space_handle_t bsh, bus_size_t size);
128 1.1 thorpej *
129 1.1 thorpej * Unmap a region of bus space.
130 1.1 thorpej */
131 1.1 thorpej #define bus_space_unmap(tag, handle, size) \
132 1.1 thorpej (*((tag)->bs_unmap))((tag)->bs_cookie, (handle), (size))
133 1.1 thorpej
134 1.1 thorpej /*
135 1.1 thorpej * int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t h
136 1.1 thorpej * bus_addr_t offset, bus_size_t size, bus_space_handle_t *newh);
137 1.1 thorpej *
138 1.1 thorpej * Allocate a sub-region of an existing map
139 1.1 thorpej */
140 1.1 thorpej #define bus_space_subregion(t, h, o, s, hp) \
141 1.1 thorpej ((*(hp)=(h)+(o)), 0)
142 1.1 thorpej
143 1.1 thorpej /*
144 1.1 thorpej * Allocation and deallocation operations.
145 1.1 thorpej */
146 1.1 thorpej #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
147 1.1 thorpej (-1)
148 1.1 thorpej
149 1.1 thorpej #define bus_space_free(t, h, s)
150 1.1 thorpej
151 1.1 thorpej /*
152 1.1 thorpej * int bus_space_peek_N(bus_space_tag_t tag,
153 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset, uintN_t *valuep);
154 1.1 thorpej *
155 1.1 thorpej * Cautiously read 1, 2, 4 or 8 byte quantity from bus space described
156 1.1 thorpej * by tag/handle/offset.
157 1.1 thorpej * If no hardware responds to the read access, the function returns a
158 1.1 thorpej * non-zero value. Otherwise the value read is placed in `valuep'.
159 1.1 thorpej */
160 1.1 thorpej #define bus_space_peek_1(t, h, o, vp) \
161 1.1 thorpej (*((t)->bs_peek_1))((t)->bs_cookie, (h), (o), (vp))
162 1.1 thorpej
163 1.1 thorpej #define bus_space_peek_2(t, h, o, vp) \
164 1.1 thorpej (*((t)->bs_peek_2))((t)->bs_cookie, (h), (o), (vp))
165 1.1 thorpej
166 1.1 thorpej #define bus_space_peek_4(t, h, o, vp) \
167 1.1 thorpej (*((t)->bs_peek_4))((t)->bs_cookie, (h), (o), (vp))
168 1.1 thorpej
169 1.1 thorpej /*
170 1.1 thorpej * int bus_space_poke_N(bus_space_tag_t tag,
171 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset, uintN_t value);
172 1.1 thorpej *
173 1.1 thorpej * Cautiously write 1, 2, 4 or 8 byte quantity to bus space described
174 1.1 thorpej * by tag/handle/offset.
175 1.1 thorpej * If no hardware responds to the write access, the function returns a
176 1.1 thorpej * non-zero value.
177 1.1 thorpej */
178 1.1 thorpej #define bus_space_poke_1(t, h, o, v) \
179 1.1 thorpej (*((t)->bs_poke_1))((t)->bs_cookie, (h), (o), (v))
180 1.1 thorpej
181 1.1 thorpej #define bus_space_poke_2(t, h, o, v) \
182 1.1 thorpej (*((t)->bs_poke_2))((t)->bs_cookie, (h), (o), (v))
183 1.1 thorpej
184 1.1 thorpej #define bus_space_poke_4(t, h, o, v) \
185 1.1 thorpej (*((t)->bs_poke_4))((t)->bs_cookie, (h), (o), (v))
186 1.1 thorpej
187 1.1 thorpej /*
188 1.1 thorpej * uintN_t bus_space_read_N(bus_space_tag_t tag,
189 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset);
190 1.1 thorpej *
191 1.1 thorpej * Read a 1, 2, 4, or 8 byte quantity from bus space
192 1.1 thorpej * described by tag/handle/offset.
193 1.1 thorpej */
194 1.1 thorpej static inline uint8_t
195 1.1 thorpej bus_space_read_1(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
196 1.1 thorpej {
197 1.1 thorpej (void) t;
198 1.1 thorpej return *(volatile uint8_t *)((intptr_t)(h + o));
199 1.1 thorpej }
200 1.1 thorpej
201 1.1 thorpej static inline uint16_t
202 1.1 thorpej bus_space_read_2(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
203 1.1 thorpej {
204 1.1 thorpej (void) t;
205 1.1 thorpej return *(volatile uint16_t *)((intptr_t)(h + o));
206 1.1 thorpej }
207 1.1 thorpej
208 1.1 thorpej static inline uint32_t
209 1.1 thorpej bus_space_read_4(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o)
210 1.1 thorpej {
211 1.1 thorpej (void) t;
212 1.1 thorpej return *(volatile uint32_t *)((intptr_t)(h + o));
213 1.1 thorpej }
214 1.1 thorpej
215 1.1 thorpej /*
216 1.1 thorpej * void bus_space_read_multi_N(bus_space_tag_t tag,
217 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
218 1.1 thorpej * uintN_t *addr, size_t count);
219 1.1 thorpej *
220 1.1 thorpej * Read `count' 1, 2, 4, or 8 byte quantities from bus space
221 1.1 thorpej * described by tag/handle/offset and copy into buffer provided.
222 1.1 thorpej */
223 1.1 thorpej
224 1.1 thorpej #define bus_space_read_multi_1(t, h, o, a, c) do { \
225 1.1 thorpej (void) t; \
226 1.1 thorpej __asm volatile (" \
227 1.1 thorpej movl %0,%%a0 ; \
228 1.1 thorpej movl %1,%%a1 ; \
229 1.1 thorpej movl %2,%%d0 ; \
230 1.1 thorpej 1: movb %%a0@,%%a1@+ ; \
231 1.1 thorpej subql #1,%%d0 ; \
232 1.1 thorpej jne 1b" : \
233 1.1 thorpej : \
234 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
235 1.1 thorpej "a0","a1","d0","memory"); \
236 1.1 thorpej } while (0);
237 1.1 thorpej
238 1.1 thorpej #define bus_space_read_multi_2(t, h, o, a, c) do { \
239 1.1 thorpej (void) t; \
240 1.1 thorpej __asm volatile (" \
241 1.1 thorpej movl %0,%%a0 ; \
242 1.1 thorpej movl %1,%%a1 ; \
243 1.1 thorpej movl %2,%%d0 ; \
244 1.1 thorpej 1: movw %%a0@,%%a1@+ ; \
245 1.1 thorpej subql #1,%%d0 ; \
246 1.1 thorpej jne 1b" : \
247 1.1 thorpej : \
248 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
249 1.1 thorpej "a0","a1","d0","memory"); \
250 1.1 thorpej } while (0);
251 1.1 thorpej
252 1.1 thorpej #define bus_space_read_multi_4(t, h, o, a, c) do { \
253 1.1 thorpej (void) t; \
254 1.1 thorpej __asm volatile (" \
255 1.1 thorpej movl %0,%%a0 ; \
256 1.1 thorpej movl %1,%%a1 ; \
257 1.1 thorpej movl %2,%%d0 ; \
258 1.1 thorpej 1: movl %%a0@,%%a1@+ ; \
259 1.1 thorpej subql #1,%%d0 ; \
260 1.1 thorpej jne 1b" : \
261 1.1 thorpej : \
262 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
263 1.1 thorpej "a0","a1","d0","memory"); \
264 1.1 thorpej } while (0);
265 1.1 thorpej
266 1.1 thorpej /*
267 1.1 thorpej * void bus_space_read_region_N(bus_space_tag_t tag,
268 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
269 1.1 thorpej * uintN_t *addr, size_t count);
270 1.1 thorpej *
271 1.1 thorpej * Read `count' 1, 2, 4, or 8 byte quantities from bus space
272 1.1 thorpej * described by tag/handle and starting at `offset' and copy into
273 1.1 thorpej * buffer provided.
274 1.1 thorpej */
275 1.1 thorpej
276 1.1 thorpej #define bus_space_read_region_1(t, h, o, a, c) do { \
277 1.1 thorpej (void) t; \
278 1.1 thorpej __asm volatile (" \
279 1.1 thorpej movl %0,%%a0 ; \
280 1.1 thorpej movl %1,%%a1 ; \
281 1.1 thorpej movl %2,%%d0 ; \
282 1.1 thorpej 1: movb %%a0@+,%%a1@+ ; \
283 1.1 thorpej subql #1,%%d0 ; \
284 1.1 thorpej jne 1b" : \
285 1.1 thorpej : \
286 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
287 1.1 thorpej "a0","a1","d0","memory"); \
288 1.1 thorpej } while (0);
289 1.1 thorpej
290 1.1 thorpej #define bus_space_read_region_2(t, h, o, a, c) do { \
291 1.1 thorpej (void) t; \
292 1.1 thorpej __asm volatile (" \
293 1.1 thorpej movl %0,%%a0 ; \
294 1.1 thorpej movl %1,%%a1 ; \
295 1.1 thorpej movl %2,%%d0 ; \
296 1.1 thorpej 1: movw %%a0@+,%%a1@+ ; \
297 1.1 thorpej subql #1,%%d0 ; \
298 1.1 thorpej jne 1b" : \
299 1.1 thorpej : \
300 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
301 1.1 thorpej "a0","a1","d0","memory"); \
302 1.1 thorpej } while (0);
303 1.1 thorpej
304 1.1 thorpej #define bus_space_read_region_4(t, h, o, a, c) do { \
305 1.1 thorpej (void) t; \
306 1.1 thorpej __asm volatile (" \
307 1.1 thorpej movl %0,%%a0 ; \
308 1.1 thorpej movl %1,%%a1 ; \
309 1.1 thorpej movl %2,%%d0 ; \
310 1.1 thorpej 1: movl %%a0@+,%%a1@+ ; \
311 1.1 thorpej subql #1,%%d0 ; \
312 1.1 thorpej jne 1b" : \
313 1.1 thorpej : \
314 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
315 1.1 thorpej "a0","a1","d0","memory"); \
316 1.1 thorpej } while (0);
317 1.1 thorpej
318 1.1 thorpej /*
319 1.1 thorpej * void bus_space_write_N(bus_space_tag_t tag,
320 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
321 1.1 thorpej * uintN_t value);
322 1.1 thorpej *
323 1.1 thorpej * Write the 1, 2, 4, or 8 byte value `value' to bus space
324 1.1 thorpej * described by tag/handle/offset.
325 1.1 thorpej */
326 1.1 thorpej #define bus_space_write_1(t,h,o,v) \
327 1.1 thorpej do { \
328 1.1 thorpej (void) t; \
329 1.1 thorpej *((volatile uint8_t *)(intptr_t)((h) + (o))) = (v); \
330 1.1 thorpej } while (/*CONSTCOND*/0)
331 1.1 thorpej #define bus_space_write_2(t,h,o,v) \
332 1.1 thorpej do { \
333 1.1 thorpej (void) t; \
334 1.1 thorpej *((volatile uint16_t *)(intptr_t)((h) + (o))) = (v); \
335 1.1 thorpej } while (/*CONSTCOND*/0)
336 1.1 thorpej #define bus_space_write_4(t,h,o,v) \
337 1.1 thorpej do { \
338 1.1 thorpej (void) t; \
339 1.1 thorpej *((volatile uint32_t *)(intptr_t)((h) + (o))) = (v); \
340 1.1 thorpej } while (/*CONSTCOND*/0)
341 1.1 thorpej
342 1.1 thorpej /*
343 1.1 thorpej * void bus_space_write_multi_N(bus_space_tag_t tag,
344 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
345 1.1 thorpej * const uintN_t *addr, size_t count);
346 1.1 thorpej *
347 1.1 thorpej * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
348 1.1 thorpej * provided to bus space described by tag/handle/offset.
349 1.1 thorpej */
350 1.1 thorpej
351 1.1 thorpej #define bus_space_write_multi_1(t, h, o, a, c) do { \
352 1.1 thorpej (void) t; \
353 1.1 thorpej __asm volatile (" \
354 1.1 thorpej movl %0,%%a0 ; \
355 1.1 thorpej movl %1,%%a1 ; \
356 1.1 thorpej movl %2,%%d0 ; \
357 1.1 thorpej 1: movb %%a1@+,%%a0@ ; \
358 1.1 thorpej subql #1,%%d0 ; \
359 1.1 thorpej jne 1b" : \
360 1.1 thorpej : \
361 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
362 1.1 thorpej "a0","a1","d0"); \
363 1.1 thorpej } while (0);
364 1.1 thorpej
365 1.1 thorpej #define bus_space_write_multi_2(t, h, o, a, c) do { \
366 1.1 thorpej (void) t; \
367 1.1 thorpej __asm volatile (" \
368 1.1 thorpej movl %0,%%a0 ; \
369 1.1 thorpej movl %1,%%a1 ; \
370 1.1 thorpej movl %2,%%d0 ; \
371 1.1 thorpej 1: movw %%a1@+,%%a0@ ; \
372 1.1 thorpej subql #1,%%d0 ; \
373 1.1 thorpej jne 1b" : \
374 1.1 thorpej : \
375 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
376 1.1 thorpej "a0","a1","d0"); \
377 1.1 thorpej } while (0);
378 1.1 thorpej
379 1.1 thorpej #define bus_space_write_multi_4(t, h, o, a, c) do { \
380 1.1 thorpej (void) t; \
381 1.1 thorpej __asm volatile (" \
382 1.1 thorpej movl %0,%%a0 ; \
383 1.1 thorpej movl %1,%%a1 ; \
384 1.1 thorpej movl %2,%%d0 ; \
385 1.1 thorpej 1: movl a1@+,%%a0@ ; \
386 1.1 thorpej subql #1,%%d0 ; \
387 1.1 thorpej jne 1b" : \
388 1.1 thorpej : \
389 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
390 1.1 thorpej "a0","a1","d0"); \
391 1.1 thorpej } while (0);
392 1.1 thorpej
393 1.1 thorpej /*
394 1.1 thorpej * void bus_space_write_region_N(bus_space_tag_t tag,
395 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
396 1.1 thorpej * const uintN_t *addr, size_t count);
397 1.1 thorpej *
398 1.1 thorpej * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
399 1.1 thorpej * to bus space described by tag/handle starting at `offset'.
400 1.1 thorpej */
401 1.1 thorpej
402 1.1 thorpej #define bus_space_write_region_1(t, h, o, a, c) do { \
403 1.1 thorpej (void) t; \
404 1.1 thorpej __asm volatile (" \
405 1.1 thorpej movl %0,%%a0 ; \
406 1.1 thorpej movl %1,%%a1 ; \
407 1.1 thorpej movl %2,%%d0 ; \
408 1.1 thorpej 1: movb %%a1@+,%%a0@+ ; \
409 1.1 thorpej subql #1,%%d0 ; \
410 1.1 thorpej jne 1b" : \
411 1.1 thorpej : \
412 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
413 1.1 thorpej "a0","a1","d0"); \
414 1.1 thorpej } while (0);
415 1.1 thorpej
416 1.1 thorpej #define bus_space_write_region_2(t, h, o, a, c) do { \
417 1.1 thorpej (void) t; \
418 1.1 thorpej __asm volatile (" \
419 1.1 thorpej movl %0,%%a0 ; \
420 1.1 thorpej movl %1,%%a1 ; \
421 1.1 thorpej movl %2,%%d0 ; \
422 1.1 thorpej 1: movw %%a1@+,%%a0@+ ; \
423 1.1 thorpej subql #1,%%d0 ; \
424 1.1 thorpej jne 1b" : \
425 1.1 thorpej : \
426 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
427 1.1 thorpej "a0","a1","d0"); \
428 1.1 thorpej } while (0);
429 1.1 thorpej
430 1.1 thorpej #define bus_space_write_region_4(t, h, o, a, c) do { \
431 1.1 thorpej (void) t; \
432 1.1 thorpej __asm volatile (" \
433 1.1 thorpej movl %0,%%a0 ; \
434 1.1 thorpej movl %1,%%a1 ; \
435 1.1 thorpej movl %2,%%d0 ; \
436 1.1 thorpej 1: movl %%a1@+,%%a0@+ ; \
437 1.1 thorpej subql #1,%%d0 ; \
438 1.1 thorpej jne 1b" : \
439 1.1 thorpej : \
440 1.1 thorpej "r" ((h) + (o)), "g" (a), "g" (c) : \
441 1.1 thorpej "a0","a1","d0"); \
442 1.1 thorpej } while (0);
443 1.1 thorpej
444 1.1 thorpej /*
445 1.1 thorpej * void bus_space_set_multi_N(bus_space_tag_t tag,
446 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
447 1.1 thorpej * size_t count);
448 1.1 thorpej *
449 1.1 thorpej * Write the 1, 2, 4, or 8 byte value `val' to bus space described
450 1.1 thorpej * by tag/handle/offset `count' times.
451 1.1 thorpej */
452 1.1 thorpej
453 1.1 thorpej #define bus_space_set_multi_1(t, h, o, val, c) do { \
454 1.1 thorpej (void) t; \
455 1.1 thorpej __asm volatile (" \
456 1.1 thorpej movl %0,%%a0 ; \
457 1.1 thorpej movl %1,%%d1 ; \
458 1.1 thorpej movl %2,%%d0 ; \
459 1.1 thorpej 1: movb %%d1,%%a0@ ; \
460 1.1 thorpej subql #1,%%d0 ; \
461 1.1 thorpej jne 1b" : \
462 1.1 thorpej : \
463 1.1 thorpej "r" ((h) + (o)), "g" (val), "g" (c) : \
464 1.1 thorpej "a0","d0","d1"); \
465 1.1 thorpej } while (0);
466 1.1 thorpej
467 1.1 thorpej #define bus_space_set_multi_2(t, h, o, val, c) do { \
468 1.1 thorpej (void) t; \
469 1.1 thorpej __asm volatile (" \
470 1.1 thorpej movl %0,%%a0 ; \
471 1.1 thorpej movl %1,%%d1 ; \
472 1.1 thorpej movl %2,%%d0 ; \
473 1.1 thorpej 1: movw %%d1,%%a0@ ; \
474 1.1 thorpej subql #1,%%d0 ; \
475 1.1 thorpej jne 1b" : \
476 1.1 thorpej : \
477 1.1 thorpej "r" ((h) + (o)), "g" (val), "g" (c) : \
478 1.1 thorpej "a0","d0","d1"); \
479 1.1 thorpej } while (0);
480 1.1 thorpej
481 1.1 thorpej #define bus_space_set_multi_4(t, h, o, val, c) do { \
482 1.1 thorpej (void) t; \
483 1.1 thorpej __asm volatile (" \
484 1.1 thorpej movl %0,%%a0 ; \
485 1.1 thorpej movl %1,%%d1 ; \
486 1.1 thorpej movl %2,%%d0 ; \
487 1.1 thorpej 1: movl %%d1,%%a0@ ; \
488 1.1 thorpej subql #1,%%d0 ; \
489 1.1 thorpej jne 1b" : \
490 1.1 thorpej : \
491 1.1 thorpej "r" ((h) + (o)), "g" (val), "g" (c) : \
492 1.1 thorpej "a0","d0","d1"); \
493 1.1 thorpej } while (0);
494 1.1 thorpej
495 1.1 thorpej /*
496 1.1 thorpej * void bus_space_set_region_N(bus_space_tag_t tag,
497 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
498 1.1 thorpej * size_t count);
499 1.1 thorpej *
500 1.1 thorpej * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
501 1.1 thorpej * by tag/handle starting at `offset'.
502 1.1 thorpej */
503 1.1 thorpej
504 1.1 thorpej #define bus_space_set_region_1(t, h, o, val, c) do { \
505 1.1 thorpej (void) t; \
506 1.1 thorpej __asm volatile (" \
507 1.1 thorpej movl %0,%%a0 ; \
508 1.1 thorpej movl %1,%%d1 ; \
509 1.1 thorpej movl %2,%%d0 ; \
510 1.1 thorpej 1: movb %%d1,%%a0@+ ; \
511 1.1 thorpej subql #1,%%d0 ; \
512 1.1 thorpej jne 1b" : \
513 1.1 thorpej : \
514 1.1 thorpej "r" ((h) + (o)), "g" (val), "g" (c) : \
515 1.1 thorpej "a0","d0","d1"); \
516 1.1 thorpej } while (0);
517 1.1 thorpej
518 1.1 thorpej #define bus_space_set_region_2(t, h, o, val, c) do { \
519 1.1 thorpej (void) t; \
520 1.1 thorpej __asm volatile (" \
521 1.1 thorpej movl %0,%%a0 ; \
522 1.1 thorpej movl %1,%%d1 ; \
523 1.1 thorpej movl %2,%%d0 ; \
524 1.1 thorpej 1: movw %%d1,%%a0@+ ; \
525 1.1 thorpej subql #1,%%d0 ; \
526 1.1 thorpej jne 1b" : \
527 1.1 thorpej : \
528 1.1 thorpej "r" ((h) + (o)), "g" (val), "g" (c) : \
529 1.1 thorpej "a0","d0","d1"); \
530 1.1 thorpej } while (0);
531 1.1 thorpej
532 1.1 thorpej #define bus_space_set_region_4(t, h, o, val, c) do { \
533 1.1 thorpej (void) t; \
534 1.1 thorpej __asm volatile (" \
535 1.1 thorpej movl %0,%%a0 ; \
536 1.1 thorpej movl %1,%%d1 ; \
537 1.1 thorpej movl %2,%%d0 ; \
538 1.1 thorpej 1: movl d1,%%a0@+ ; \
539 1.1 thorpej subql #1,%%d0 ; \
540 1.1 thorpej jne 1b" : \
541 1.1 thorpej : \
542 1.1 thorpej "r" ((h) + (o)), "g" (val), "g" (c) : \
543 1.1 thorpej "a0","d0","d1"); \
544 1.1 thorpej } while (0);
545 1.1 thorpej
546 1.1 thorpej /*
547 1.1 thorpej * void bus_space_copy_N(bus_space_tag_t tag,
548 1.1 thorpej * bus_space_handle_t bsh1, bus_size_t off1,
549 1.1 thorpej * bus_space_handle_t bsh2, bus_size_t off2,
550 1.1 thorpej * size_t count);
551 1.1 thorpej *
552 1.1 thorpej * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
553 1.1 thorpej * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
554 1.1 thorpej */
555 1.1 thorpej
556 1.1 thorpej #define __VIRT68K_copy_region_N(BYTES) \
557 1.1 thorpej static __inline void __CONCAT(bus_space_copy_region_,BYTES) \
558 1.1 thorpej (bus_space_tag_t, \
559 1.1 thorpej bus_space_handle_t bsh1, bus_size_t off1, \
560 1.1 thorpej bus_space_handle_t bsh2, bus_size_t off2, \
561 1.1 thorpej bus_size_t count); \
562 1.1 thorpej \
563 1.1 thorpej static __inline void \
564 1.1 thorpej __CONCAT(bus_space_copy_region_,BYTES)( \
565 1.1 thorpej bus_space_tag_t t, \
566 1.1 thorpej bus_space_handle_t h1, \
567 1.1 thorpej bus_size_t o1, \
568 1.1 thorpej bus_space_handle_t h2, \
569 1.1 thorpej bus_size_t o2, \
570 1.1 thorpej bus_size_t c) \
571 1.1 thorpej { \
572 1.1 thorpej bus_size_t o; \
573 1.1 thorpej (void) t; \
574 1.1 thorpej \
575 1.1 thorpej if ((h1 + o1) >= (h2 + o2)) { \
576 1.1 thorpej /* src after dest: copy forward */ \
577 1.1 thorpej for (o = 0; c != 0; c--, o += BYTES) \
578 1.1 thorpej __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
579 1.1 thorpej __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
580 1.1 thorpej } else { \
581 1.1 thorpej /* dest after src: copy backwards */ \
582 1.1 thorpej for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
583 1.1 thorpej __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
584 1.1 thorpej __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
585 1.1 thorpej } \
586 1.1 thorpej }
587 1.1 thorpej __VIRT68K_copy_region_N(1)
588 1.1 thorpej __VIRT68K_copy_region_N(2)
589 1.1 thorpej __VIRT68K_copy_region_N(4)
590 1.1 thorpej
591 1.1 thorpej #undef __VIRT68K_copy_region_N
592 1.1 thorpej
593 1.1 thorpej /*
594 1.1 thorpej * Bus read/write barrier methods.
595 1.1 thorpej *
596 1.1 thorpej * void bus_space_barrier(bus_space_tag_t tag,
597 1.1 thorpej * bus_space_handle_t bsh, bus_size_t offset,
598 1.1 thorpej * bus_size_t len, int flags);
599 1.1 thorpej *
600 1.1 thorpej * Note: the 680x0 does not currently require barriers, but we must
601 1.1 thorpej * provide the flags to MI code.
602 1.1 thorpej */
603 1.1 thorpej #define bus_space_barrier(t, h, o, l, f) \
604 1.1 thorpej ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
605 1.1 thorpej #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
606 1.1 thorpej #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
607 1.1 thorpej
608 1.1 thorpej #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
609 1.1 thorpej
610 1.1 thorpej
611 1.1 thorpej #ifdef _VIRT68K_BUS_SPACE_PRIVATE
612 1.1 thorpej extern int _bus_space_map(void *, bus_addr_t, bus_size_t,
613 1.1 thorpej int, bus_space_handle_t *);
614 1.1 thorpej extern void _bus_space_unmap(void *, bus_space_handle_t, bus_size_t);
615 1.1 thorpej extern int _bus_space_peek_1(void *, bus_space_handle_t,
616 1.1 thorpej bus_size_t, uint8_t *);
617 1.1 thorpej extern int _bus_space_peek_2(void *, bus_space_handle_t,
618 1.1 thorpej bus_size_t, uint16_t *);
619 1.1 thorpej extern int _bus_space_peek_4(void *, bus_space_handle_t,
620 1.1 thorpej bus_size_t, uint32_t *);
621 1.1 thorpej extern int _bus_space_poke_1(void *, bus_space_handle_t, bus_size_t, uint8_t);
622 1.1 thorpej extern int _bus_space_poke_2(void *, bus_space_handle_t, bus_size_t, uint16_t);
623 1.1 thorpej extern int _bus_space_poke_4(void *, bus_space_handle_t, bus_size_t, uint32_t);
624 1.1 thorpej #endif /* _VIRT68K_BUS_SPACE_PRIVATE */
625 1.1 thorpej
626 1.1 thorpej #endif /* _VIRT68K_BUS_SPACE_H_ */
627