bus_space.h revision 1.9
1/*	$NetBSD: bus_space.h,v 1.9 2005/12/11 12:18:17 christos Exp $ */
2
3/*-
4 * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 *    must display the following acknowledgement:
21 *	This product includes software developed by the NetBSD
22 *	Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 *    contributors may be used to endorse or promote products derived
25 *    from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40/*
41 * Copyright (C) 1997 Scott Reynolds.  All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 *    notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 *    notice, this list of conditions and the following disclaimer in the
50 *    documentation and/or other materials provided with the distribution.
51 * 3. The name of the author may not be used to endorse or promote products
52 *    derived from this software without specific prior written permission
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
59 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
63 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 */
65
66/*
67 * Lifted from the Next68k port.
68 * Modified for mvme68k by Steve Woodford.
69 *
70 * TODO: Support for VMEbus...
71 * (Do any existing VME card drivers use bus_space_* ?)
72 */
73
74#ifndef _MVME68K_BUS_SPACE_H_
75#define	_MVME68K_BUS_SPACE_H_
76
77/*
78 * Addresses (in bus space).
79 */
80typedef u_long bus_addr_t;
81typedef u_long bus_size_t;
82
83/*
84 * Access methods for bus resources and address space.
85 */
86struct mvme68k_bus_space_tag;
87typedef struct mvme68k_bus_space_tag	*bus_space_tag_t;
88typedef u_long	bus_space_handle_t;
89
90struct mvme68k_bus_space_tag {
91	void		*bs_cookie;
92	int		(*bs_map)(void *, bus_addr_t, bus_size_t,
93				  int, bus_space_handle_t *);
94	void		(*bs_unmap)(void *, bus_space_handle_t, bus_size_t);
95	int		(*bs_peek_1)(void *, bus_space_handle_t,
96				     bus_size_t, u_int8_t *);
97	int		(*bs_peek_2)(void *, bus_space_handle_t,
98				     bus_size_t, u_int16_t *);
99	int		(*bs_peek_4)(void *, bus_space_handle_t,
100				     bus_size_t, u_int32_t *);
101#if 0
102	int		(*bs_peek_8)(void *, bus_space_handle_t,
103				     bus_size_t, u_int64_t *);
104#endif
105	int		(*bs_poke_1)(void *, bus_space_handle_t,
106				     bus_size_t, u_int8_t);
107	int		(*bs_poke_2)(void *, bus_space_handle_t,
108				     bus_size_t, u_int16_t);
109	int		(*bs_poke_4)(void *, bus_space_handle_t,
110				     bus_size_t, u_int32_t);
111#if 0
112	int		(*bs_poke_8)(void *, bus_space_handle_t,
113				     bus_size_t, u_int64_t);
114#endif
115};
116
117/*
118 *	int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
119 *	                  bus_size_t size, int flags,
120 *                        bus_space_handle_t *bshp);
121 *
122 * Map a region of bus space.
123 */
124#define	bus_space_map(tag, offset, size, flags, handlep)		\
125    (*((tag)->bs_map))((tag)->bs_cookie, (offset), (size), (flags), (handlep))
126
127/*
128 * Possible values for the 'flags' parameter of bus_space_map()
129 */
130#define	BUS_SPACE_MAP_CACHEABLE		0x01
131#define	BUS_SPACE_MAP_LINEAR		0x02
132#define	BUS_SPACE_MAP_PREFETCHABLE	0x04
133
134/*
135 *	void bus_space_unmap(bus_space_tag_t t,
136 *                           bus_space_handle_t bsh, bus_size_t size);
137 *
138 * Unmap a region of bus space.
139 */
140#define bus_space_unmap(tag, handle, size)				\
141    (*((tag)->bs_unmap))((tag)->bs_cookie, (handle), (size))
142
143/*
144 *	int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t h
145 *	    bus_addr_t offset, bus_size_t size, bus_space_handle_t *newh);
146 *
147 * Allocate a sub-region of an existing map
148 */
149#define	bus_space_subregion(t, h, o, s, hp)				\
150     ((*(hp)=(h)+(o)), 0)
151
152/*
153 * Allocation and deallocation operations.
154 */
155#define	bus_space_alloc(t, rs, re, s, a, b, f, ap, hp)  		\
156     (-1)
157
158#define	bus_space_free(t, h, s)
159
160/*
161 *	int bus_space_peek_N(bus_space_tag_t tag,
162 *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t *valuep);
163 *
164 * Cautiously read 1, 2, 4 or 8 byte quantity from bus space described
165 * by tag/handle/offset.
166 * If no hardware responds to the read access, the function returns a
167 * non-zero value. Otherwise the value read is placed in `valuep'.
168 */
169#define	bus_space_peek_1(t, h, o, vp)					\
170    (*((t)->bs_peek_1))((t)->bs_cookie, (h), (o), (vp))
171
172#define	bus_space_peek_2(t, h, o, vp)					\
173    (*((t)->bs_peek_2))((t)->bs_cookie, (h), (o), (vp))
174
175#define	bus_space_peek_4(t, h, o, vp)					\
176    (*((t)->bs_peek_4))((t)->bs_cookie, (h), (o), (vp))
177
178#if 0	/* Cause a link error for bus_space_peek_8 */
179#define	bus_space_peek_8(t, h, o, vp)					\
180    (*((t)->bs_peek_8))((t)->bs_cookie, (h), (o), (vp))
181#endif
182
183/*
184 *	int bus_space_poke_N(bus_space_tag_t tag,
185 *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t value);
186 *
187 * Cautiously write 1, 2, 4 or 8 byte quantity to bus space described
188 * by tag/handle/offset.
189 * If no hardware responds to the write access, the function returns a
190 * non-zero value.
191 */
192#define	bus_space_poke_1(t, h, o, v)					\
193    (*((t)->bs_poke_1))((t)->bs_cookie, (h), (o), (v))
194
195#define	bus_space_poke_2(t, h, o, v)					\
196    (*((t)->bs_poke_2))((t)->bs_cookie, (h), (o), (v))
197
198#define	bus_space_poke_4(t, h, o, v)					\
199    (*((t)->bs_poke_4))((t)->bs_cookie, (h), (o), (v))
200
201#if 0	/* Cause a link error for bus_space_poke_8 */
202#define	bus_space_poke_8(t, h, o, v)					\
203    (*((t)->bs_poke_8))((t)->bs_cookie, (h), (o), (v))
204#endif
205
206/*
207 *	u_intN_t bus_space_read_N(bus_space_tag_t tag,
208 *	    bus_space_handle_t bsh, bus_size_t offset);
209 *
210 * Read a 1, 2, 4, or 8 byte quantity from bus space
211 * described by tag/handle/offset.
212 */
213#define	bus_space_read_1(t,h,o)	\
214	    (*((volatile u_int8_t *)(intptr_t)((h) + (o))))
215#define	bus_space_read_2(t,h,o)	\
216	    (*((volatile u_int16_t *)(intptr_t)((h) + (o))))
217#define	bus_space_read_4(t,h,o)	\
218	    (*((volatile u_int32_t *)(intptr_t)((h) + (o))))
219
220/*
221 *	void bus_space_read_multi_N(bus_space_tag_t tag,
222 *	    bus_space_handle_t bsh, bus_size_t offset,
223 *	    u_intN_t *addr, size_t count);
224 *
225 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
226 * described by tag/handle/offset and copy into buffer provided.
227 */
228
229#define	bus_space_read_multi_1(t, h, o, a, c) do {			\
230	(void) t;							\
231	__asm __volatile ("						\
232		movl	%0,%%a0					;	\
233		movl	%1,%%a1					;	\
234		movl	%2,%%d0					;	\
235	1:	movb	%%a0@,%%a1@+				;	\
236		subql	#1,%%d0					;	\
237		jne	1b"					:	\
238								:	\
239		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
240		    "a0","a1","d0");					\
241} while (0);
242
243#define	bus_space_read_multi_2(t, h, o, a, c) do {			\
244	(void) t;							\
245	__asm __volatile ("						\
246		movl	%0,%%a0					;	\
247		movl	%1,%%a1					;	\
248		movl	%2,%%d0					;	\
249	1:	movw	%%a0@,%%a1@+				;	\
250		subql	#1,%%d0					;	\
251		jne	1b"					:	\
252								:	\
253		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
254		    "a0","a1","d0");					\
255} while (0);
256
257#define	bus_space_read_multi_4(t, h, o, a, c) do {			\
258	(void) t;							\
259	__asm __volatile ("						\
260		movl	%0,%%a0					;	\
261		movl	%1,%%a1					;	\
262		movl	%2,%%d0					;	\
263	1:	movl	%%a0@,%%a1@+				;	\
264		subql	#1,%%d0					;	\
265		jne	1b"					:	\
266								:	\
267		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
268		    "a0","a1","d0");					\
269} while (0);
270
271#if 0	/* Cause a link error for bus_space_read_multi_8 */
272#define	bus_space_read_multi_8	!!! bus_space_read_multi_8 unimplemented !!!
273#endif
274
275/*
276 *	void bus_space_read_region_N(bus_space_tag_t tag,
277 *	    bus_space_handle_t bsh, bus_size_t offset,
278 *	    u_intN_t *addr, size_t count);
279 *
280 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
281 * described by tag/handle and starting at `offset' and copy into
282 * buffer provided.
283 */
284
285#define	bus_space_read_region_1(t, h, o, a, c) do {			\
286	(void) t;							\
287	__asm __volatile ("						\
288		movl	%0,%%a0					;	\
289		movl	%1,%%a1					;	\
290		movl	%2,%%d0					;	\
291	1:	movb	%%a0@+,%%a1@+				;	\
292		subql	#1,%%d0					;	\
293		jne	1b"					:	\
294								:	\
295		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
296		    "a0","a1","d0");					\
297} while (0);
298
299#define	bus_space_read_region_2(t, h, o, a, c) do {			\
300	(void) t;							\
301	__asm __volatile ("						\
302		movl	%0,%%a0					;	\
303		movl	%1,%%a1					;	\
304		movl	%2,%%d0					;	\
305	1:	movw	%%a0@+,%%a1@+				;	\
306		subql	#1,%%d0					;	\
307		jne	1b"					:	\
308								:	\
309		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
310		    "a0","a1","d0");					\
311} while (0);
312
313#define	bus_space_read_region_4(t, h, o, a, c) do {			\
314	(void) t;							\
315	__asm __volatile ("						\
316		movl	%0,%%a0					;	\
317		movl	%1,%%a1					;	\
318		movl	%2,%%d0					;	\
319	1:	movl	%%a0@+,%%a1@+				;	\
320		subql	#1,%%d0					;	\
321		jne	1b"					:	\
322								:	\
323		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
324		    "a0","a1","d0");					\
325} while (0);
326
327#if 0	/* Cause a link error for bus_space_read_region_8 */
328#define	bus_space_read_region_8	!!! bus_space_read_region_8 unimplemented !!!
329#endif
330
331/*
332 *	void bus_space_write_N(bus_space_tag_t tag,
333 *	    bus_space_handle_t bsh, bus_size_t offset,
334 *	    u_intN_t value);
335 *
336 * Write the 1, 2, 4, or 8 byte value `value' to bus space
337 * described by tag/handle/offset.
338 */
339#define	bus_space_write_1(t,h,o,v)					\
340	do {								\
341		*((volatile u_int8_t *)(intptr_t)((h) + (o))) = (v);	\
342	} while (/*CONSTCOND*/0)
343#define	bus_space_write_2(t,h,o,v)					\
344	do {								\
345		*((volatile u_int16_t *)(intptr_t)((h) + (o))) = (v);	\
346	} while (/*CONSTCOND*/0)
347#define	bus_space_write_4(t,h,o,v)					\
348	do {								\
349		*((volatile u_int32_t *)(intptr_t)((h) + (o))) = (v);	\
350	} while (/*CONSTCOND*/0)
351
352/*
353 *	void bus_space_write_multi_N(bus_space_tag_t tag,
354 *	    bus_space_handle_t bsh, bus_size_t offset,
355 *	    const u_intN_t *addr, size_t count);
356 *
357 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
358 * provided to bus space described by tag/handle/offset.
359 */
360
361#define	bus_space_write_multi_1(t, h, o, a, c) do {			\
362	(void) t;							\
363	__asm __volatile ("						\
364		movl	%0,%%a0					;	\
365		movl	%1,%%a1					;	\
366		movl	%2,%%d0					;	\
367	1:	movb	%%a1@+,%%a0@				;	\
368		subql	#1,%%d0					;	\
369		jne	1b"					:	\
370								:	\
371		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
372		    "a0","a1","d0");					\
373} while (0);
374
375#define	bus_space_write_multi_2(t, h, o, a, c) do {			\
376	(void) t;							\
377	__asm __volatile ("						\
378		movl	%0,%%a0					;	\
379		movl	%1,%%a1					;	\
380		movl	%2,%%d0					;	\
381	1:	movw	%%a1@+,%%a0@				;	\
382		subql	#1,%%d0					;	\
383		jne	1b"					:	\
384								:	\
385		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
386		    "a0","a1","d0");					\
387} while (0);
388
389#define	bus_space_write_multi_4(t, h, o, a, c) do {			\
390	(void) t;							\
391	__asm __volatile ("						\
392		movl	%0,%%a0					;	\
393		movl	%1,%%a1					;	\
394		movl	%2,%%d0					;	\
395	1:	movl	a1@+,%%a0@				;	\
396		subql	#1,%%d0					;	\
397		jne	1b"					:	\
398								:	\
399		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
400		    "a0","a1","d0");					\
401} while (0);
402
403#if 0	/* Cause a link error for bus_space_write_8 */
404#define	bus_space_write_multi_8(t, h, o, a, c)				\
405			!!! bus_space_write_multi_8 unimplimented !!!
406#endif
407
408/*
409 *	void bus_space_write_region_N(bus_space_tag_t tag,
410 *	    bus_space_handle_t bsh, bus_size_t offset,
411 *	    const u_intN_t *addr, size_t count);
412 *
413 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
414 * to bus space described by tag/handle starting at `offset'.
415 */
416
417#define	bus_space_write_region_1(t, h, o, a, c) do {			\
418	(void) t;							\
419	__asm __volatile ("						\
420		movl	%0,%%a0					;	\
421		movl	%1,%%a1					;	\
422		movl	%2,%%d0					;	\
423	1:	movb	%%a1@+,%%a0@+				;	\
424		subql	#1,%%d0					;	\
425		jne	1b"					:	\
426								:	\
427		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
428		    "a0","a1","d0");					\
429} while (0);
430
431#define	bus_space_write_region_2(t, h, o, a, c) do {			\
432	(void) t;							\
433	__asm __volatile ("						\
434		movl	%0,%%a0					;	\
435		movl	%1,%%a1					;	\
436		movl	%2,%%d0					;	\
437	1:	movw	%%a1@+,%%a0@+				;	\
438		subql	#1,%%d0					;	\
439		jne	1b"					:	\
440								:	\
441		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
442		    "a0","a1","d0");					\
443} while (0);
444
445#define	bus_space_write_region_4(t, h, o, a, c) do {			\
446	(void) t;							\
447	__asm __volatile ("						\
448		movl	%0,%%a0					;	\
449		movl	%1,%%a1					;	\
450		movl	%2,%%d0					;	\
451	1:	movl	%%a1@+,%%a0@+				;	\
452		subql	#1,%%d0					;	\
453		jne	1b"					:	\
454								:	\
455		    "r" ((h) + (o)), "g" (a), "g" (c)		:	\
456		    "a0","a1","d0");					\
457} while (0);
458
459#if 0	/* Cause a link error for bus_space_write_region_8 */
460#define	bus_space_write_region_8					\
461			!!! bus_space_write_region_8 unimplemented !!!
462#endif
463
464/*
465 *	void bus_space_set_multi_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 the 1, 2, 4, or 8 byte value `val' to bus space described
470 * by tag/handle/offset `count' times.
471 */
472
473#define	bus_space_set_multi_1(t, h, o, val, c) do {			\
474	(void) t;							\
475	__asm __volatile ("						\
476		movl	%0,%%a0					;	\
477		movl	%1,%%d1					;	\
478		movl	%2,%%d0					;	\
479	1:	movb	%%d1,%%a0@				;	\
480		subql	#1,%%d0					;	\
481		jne	1b"					:	\
482								:	\
483		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
484		    "a0","d0","d1");					\
485} while (0);
486
487#define	bus_space_set_multi_2(t, h, o, val, c) do {			\
488	(void) t;							\
489	__asm __volatile ("						\
490		movl	%0,%%a0					;	\
491		movl	%1,%%d1					;	\
492		movl	%2,%%d0					;	\
493	1:	movw	%%d1,%%a0@				;	\
494		subql	#1,%%d0					;	\
495		jne	1b"					:	\
496								:	\
497		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
498		    "a0","d0","d1");					\
499} while (0);
500
501#define	bus_space_set_multi_4(t, h, o, val, c) do {			\
502	(void) t;							\
503	__asm __volatile ("						\
504		movl	%0,%%a0					;	\
505		movl	%1,%%d1					;	\
506		movl	%2,%%d0					;	\
507	1:	movl	%%d1,%%a0@				;	\
508		subql	#1,%%d0					;	\
509		jne	1b"					:	\
510								:	\
511		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
512		    "a0","d0","d1");					\
513} while (0);
514
515#if 0	/* Cause a link error for bus_space_set_multi_8 */
516#define	bus_space_set_multi_8						\
517			!!! bus_space_set_multi_8 unimplemented !!!
518#endif
519
520/*
521 *	void bus_space_set_region_N(bus_space_tag_t tag,
522 *	    bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
523 *	    size_t count);
524 *
525 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
526 * by tag/handle starting at `offset'.
527 */
528
529#define	bus_space_set_region_1(t, h, o, val, c) do {			\
530	(void) t;							\
531	__asm __volatile ("						\
532		movl	%0,%%a0					;	\
533		movl	%1,%%d1					;	\
534		movl	%2,%%d0					;	\
535	1:	movb	%%d1,%%a0@+				;	\
536		subql	#1,%%d0					;	\
537		jne	1b"					:	\
538								:	\
539		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
540		    "a0","d0","d1");					\
541} while (0);
542
543#define	bus_space_set_region_2(t, h, o, val, c) do {			\
544	(void) t;							\
545	__asm __volatile ("						\
546		movl	%0,%%a0					;	\
547		movl	%1,%%d1					;	\
548		movl	%2,%%d0					;	\
549	1:	movw	%%d1,%%a0@+				;	\
550		subql	#1,%%d0					;	\
551		jne	1b"					:	\
552								:	\
553		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
554		    "a0","d0","d1");					\
555} while (0);
556
557#define	bus_space_set_region_4(t, h, o, val, c) do {			\
558	(void) t;							\
559	__asm __volatile ("						\
560		movl	%0,%%a0					;	\
561		movl	%1,%%d1					;	\
562		movl	%2,%%d0					;	\
563	1:	movl	d1,%%a0@+				;	\
564		subql	#1,%%d0					;	\
565		jne	1b"					:	\
566								:	\
567		    "r" ((h) + (o)), "g" (val), "g" (c)		:	\
568		    "a0","d0","d1");					\
569} while (0);
570
571#if 0	/* Cause a link error for bus_space_set_region_8 */
572#define	bus_space_set_region_8						\
573			!!! bus_space_set_region_8 unimplemented !!!
574#endif
575
576/*
577 *	void bus_space_copy_N(bus_space_tag_t tag,
578 *	    bus_space_handle_t bsh1, bus_size_t off1,
579 *	    bus_space_handle_t bsh2, bus_size_t off2,
580 *	    size_t count);
581 *
582 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
583 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
584 */
585
586#define	__MVME68K_copy_region_N(BYTES)					\
587static __inline void __CONCAT(bus_space_copy_region_,BYTES)		\
588	__P((bus_space_tag_t,						\
589	    bus_space_handle_t bsh1, bus_size_t off1,			\
590	    bus_space_handle_t bsh2, bus_size_t off2,			\
591	    bus_size_t count));						\
592									\
593static __inline void							\
594__CONCAT(bus_space_copy_region_,BYTES)(t, h1, o1, h2, o2, c)		\
595	bus_space_tag_t t;						\
596	bus_space_handle_t h1, h2;					\
597	bus_size_t o1, o2, c;						\
598{									\
599	bus_size_t o;							\
600									\
601	if ((h1 + o1) >= (h2 + o2)) {					\
602		/* src after dest: copy forward */			\
603		for (o = 0; c != 0; c--, o += BYTES)			\
604			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
605			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
606	} else {							\
607		/* dest after src: copy backwards */			\
608		for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES)	\
609			__CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o,	\
610			    __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
611	}								\
612}
613__MVME68K_copy_region_N(1)
614__MVME68K_copy_region_N(2)
615__MVME68K_copy_region_N(4)
616#if 0	/* Cause a link error for bus_space_copy_8 */
617#define	bus_space_copy_8						\
618			!!! bus_space_copy_8 unimplemented !!!
619#endif
620
621#undef __MVME68K_copy_region_N
622
623/*
624 * Bus read/write barrier methods.
625 *
626 *	void bus_space_barrier(bus_space_tag_t tag,
627 *	    bus_space_handle_t bsh, bus_size_t offset,
628 *	    bus_size_t len, int flags);
629 *
630 * Note: the 680x0 does not currently require barriers, but we must
631 * provide the flags to MI code.
632 */
633#define	bus_space_barrier(t, h, o, l, f)	\
634	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
635#define	BUS_SPACE_BARRIER_READ	0x01		/* force read barrier */
636#define	BUS_SPACE_BARRIER_WRITE	0x02		/* force write barrier */
637
638#define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
639
640
641#ifdef _MVME68K_BUS_SPACE_PRIVATE
642extern int _bus_space_map(void *, bus_addr_t, bus_size_t,
643    int, bus_space_handle_t *);
644extern void _bus_space_unmap(void *, bus_space_handle_t, bus_size_t);
645extern int _bus_space_peek_1(void *, bus_space_handle_t,
646    bus_size_t, u_int8_t *);
647extern int _bus_space_peek_2(void *, bus_space_handle_t,
648    bus_size_t, u_int16_t *);
649extern int _bus_space_peek_4(void *, bus_space_handle_t,
650    bus_size_t, u_int32_t *);
651extern int _bus_space_poke_1(void *, bus_space_handle_t, bus_size_t, u_int8_t);
652extern int _bus_space_poke_2(void *, bus_space_handle_t, bus_size_t, u_int16_t);
653extern int _bus_space_poke_4(void *, bus_space_handle_t, bus_size_t, u_int32_t);
654#endif /* _MVME68K_BUS_SPACE_PRIVATE */
655
656#endif /* _MVME68K_BUS_SPACE_H_ */
657