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