Home | History | Annotate | Line # | Download | only in include
bus.h revision 1.10
      1 /*	$NetBSD: bus.h,v 1.10 1999/03/23 21:29:04 drochner Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996 Leo Weppelman.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed by Leo Weppelman for the
     17  *	NetBSD Project.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #ifndef _AMIGA_BUS_H_
     34 #define _AMIGA_BUS_H_
     35 
     36 #include <sys/types.h>
     37 
     38 /*
     39  * Memory addresses (in bus space)
     40  */
     41 
     42 typedef u_int32_t bus_addr_t;
     43 typedef u_int32_t bus_size_t;
     44 
     45 /*
     46  * Access methods for bus resources and address space.
     47  */
     48 typedef struct bus_space_tag *bus_space_tag_t;
     49 typedef u_long	bus_space_handle_t;
     50 
     51 /*
     52  * Lazyness macros for function declarations.
     53  */
     54 
     55 #define bsr(what, typ) \
     56 	typ (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t)
     57 
     58 #define bsw(what, typ) \
     59 	void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, typ)
     60 
     61 #define bsrm(what, typ) \
     62 	void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
     63 		typ *, bus_size_t)
     64 
     65 #define bswm(what, typ) \
     66 	void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
     67 		const typ *, bus_size_t)
     68 
     69 #define bssr(what, typ) \
     70 	void (what)(bus_space_tag_t, bus_space_handle_t, bus_size_t, \
     71 		typ, bus_size_t)
     72 
     73 #define bscr(what, typ) \
     74 	void (what)(bus_space_tag_t, \
     75 		bus_space_handle_t, bus_size_t, \
     76 		bus_space_handle_t, bus_size_t, \
     77 		bus_size_t)
     78 
     79 /* declarations for _1 functions */
     80 
     81 bsrm(bus_space_read_multi_1, u_int8_t);
     82 bswm(bus_space_write_multi_1, u_int8_t);
     83 bsrm(bus_space_read_region_1, u_int8_t);
     84 bswm(bus_space_write_region_1, u_int8_t);
     85 bsrm(bus_space_read_region_stream_1, u_int8_t);
     86 bswm(bus_space_write_region_stream_1, u_int8_t);
     87 bssr(bus_space_set_region_1, u_int8_t);
     88 bscr(bus_space_copy_region_1, u_int8_t);
     89 
     90 /*
     91  * Implementation specific structures.
     92  * XXX Don't use outside of bus_space definitions!
     93  * XXX maybe this should be encapsuled in a non-global .h file?
     94  */
     95 
     96 struct bus_space_tag {
     97 	bus_addr_t	base;
     98 	u_int8_t	stride;
     99 	u_int8_t	dum[3];
    100 	const struct amiga_bus_space_methods *absm;
    101 };
    102 
    103 struct amiga_bus_space_methods {
    104 
    105 	/* 16bit methods */
    106 
    107 	bsr(*bsr2, u_int16_t);
    108 	bsw(*bsw2, u_int16_t);
    109 	bsrm(*bsrm2, u_int16_t);
    110 	bswm(*bswm2, u_int16_t);
    111 	bsrm(*bsrr2, u_int16_t);
    112 	bswm(*bswr2, u_int16_t);
    113 	bsrm(*bsrrs2, u_int16_t);
    114 	bswm(*bswrs2, u_int16_t);
    115 	bssr(*bssr2, u_int16_t);
    116 	bscr(*bscr2, u_int16_t);
    117 
    118 	/* add 32bit methods here */
    119 };
    120 
    121 const struct amiga_bus_space_methods amiga_contiguous_methods;
    122 const struct amiga_bus_space_methods amiga_interleaved_methods;
    123 const struct amiga_bus_space_methods amiga_interleaved_wordaccess_methods;
    124 
    125 /*
    126  * Macro definition of map, unmap, etc.
    127  */
    128 
    129 #define bus_space_map(tag,off,size,cache,handle) 			\
    130 	(*(handle) = (tag)->base + ((off)<<(tag)->stride), 0)
    131 
    132 #define bus_space_subregion(tag, handle, offset, size, nhandlep) \
    133 	(*(nhandlep) = (handle) + ((offset)<<(tag)->stride), 0)
    134 
    135 #define bus_space_unmap(tag,handle,size)	(void)0
    136 
    137 /*
    138  * Macro definition of some _1 functions:
    139  */
    140 
    141 #define	bus_space_read_1(t, h, o) \
    142     ((void) t, (*(volatile u_int8_t *)((h) + ((o)<<(t)->stride))))
    143 
    144 #define	bus_space_write_1(t, h, o, v) \
    145     ((void) t, ((void)(*(volatile u_int8_t *)((h) + ((o)<<(t)->stride)) = (v))))
    146 
    147 /*
    148  * Inline definition of other _1 functions:
    149  */
    150 
    151 extern __inline__ void
    152 bus_space_read_multi_1(t, h, o, a, c)
    153 	bus_space_tag_t		t;
    154 	bus_space_handle_t	h;
    155 	bus_size_t		o, c;
    156 	u_int8_t		*a;
    157 {
    158 	for (; c; a++, c--)
    159 		*a = bus_space_read_1(t, h, o);
    160 }
    161 
    162 extern __inline__ void
    163 bus_space_write_multi_1(t, h, o, a, c)
    164 	bus_space_tag_t		t;
    165 	bus_space_handle_t	h;
    166 	bus_size_t		o, c;
    167 	const u_int8_t		*a;
    168 {
    169 	for (; c; a++, c--)
    170 		bus_space_write_1(t, h, o, *a);
    171 }
    172 
    173 extern __inline__ void
    174 bus_space_read_region_1(t, h, o, a, c)
    175 	bus_space_tag_t		t;
    176 	bus_space_handle_t	h;
    177 	bus_size_t		o, c;
    178 	u_int8_t		*a;
    179 {
    180 	for (; c; a++, c--)
    181 		*a = bus_space_read_1(t, h, o++);
    182 }
    183 
    184 extern __inline__ void
    185 bus_space_write_region_1(t, h, o, a, c)
    186 	bus_space_tag_t		t;
    187 	bus_space_handle_t	h;
    188 	bus_size_t		o, c;
    189 	const u_int8_t		*a;
    190 {
    191 	for (; c; a++, c--)
    192 		 bus_space_write_1(t, h, o++, *a);
    193 }
    194 
    195 extern __inline__ void
    196 bus_space_set_region_1(t, h, o, v, c)
    197 	bus_space_tag_t		t;
    198 	bus_space_handle_t	h;
    199 	bus_size_t		o, c;
    200 	u_int8_t		v;
    201 {
    202 	while (c--)
    203 		 bus_space_write_1(t, h, o++, v);
    204 }
    205 
    206 extern __inline__ void
    207 bus_space_copy_region_1(t, srch, srco, dsth, dsto, c)
    208 	bus_space_tag_t		t;
    209 	bus_space_handle_t	srch, dsth;
    210 	bus_size_t		srco, dsto, c;
    211 {
    212 	u_int8_t		v;
    213 
    214 	while (c--) {
    215 		 v = bus_space_read_1(t, srch, srco++);
    216 		 bus_space_write_1(t, dsth, dsto++, v);
    217 	}
    218 }
    219 
    220 extern __inline__ void
    221 bus_space_read_region_stream_1(t, h, o, a, c)
    222 	bus_space_tag_t		t;
    223 	bus_space_handle_t	h;
    224 	bus_size_t		o, c;
    225 	u_int8_t		*a;
    226 {
    227 	for (; c; a++, c--)
    228 		*a = bus_space_read_1(t, h, o++);
    229 }
    230 
    231 extern __inline__ void
    232 bus_space_write_region_stream_1(t, h, o, a, c)
    233 	bus_space_tag_t		t;
    234 	bus_space_handle_t	h;
    235 	bus_size_t		o, c;
    236 	const u_int8_t		*a;
    237 {
    238 	for (; c; a++, c--)
    239 		 bus_space_write_1(t, h, o++, *a);
    240 }
    241 
    242 /*
    243  * Macro definition of _2 functions as indirect method array calls
    244  */
    245 
    246 #define bus_space_read_2(t, h, o)	((t)->absm->bsr2)((t), (h), (o))
    247 #define bus_space_write_2(t, h, o, v)	((t)->absm->bsw2)((t), (h), (o), (v))
    248 
    249 #define bus_space_read_multi_2(t, h, o, p, c) \
    250 	((t)->absm->bsrm2)((t), (h), (o), (p), (c))
    251 
    252 #define bus_space_write_multi_2(t, h, o, p, c) \
    253 	((t)->absm->bswm2)((t), (h), (o), (p), (c))
    254 
    255 #define bus_space_read_region_2(t, h, o, p, c) \
    256 	((t)->absm->bsrr2)((t), (h), (o), (p), (c))
    257 
    258 #define bus_space_write_region_2(t, h, o, p, c) \
    259 	((t)->absm->bswr2)((t), (h), (o), (p), (c))
    260 
    261 #define bus_space_read_region_stream_2(t, h, o, p, c) \
    262 	((t)->absm->bsrrs2)((t), (h), (o), (p), (c))
    263 
    264 #define bus_space_write_region_stream_2(t, h, o, p, c) \
    265 	((t)->absm->bswrs2)((t), (h), (o), (p), (c))
    266 
    267 #define bus_space_set_region_2(t, h, o, v, c) \
    268 	((t)->absm->bssr2)((t), (h), (o), (v), (c))
    269 
    270 #define bus_space_copy_region_2(t, srch, srco, dsth, dsto, c) \
    271 	((t)->absm->bscr2)((t), (srch), (srco), (dsth), (dsto), (c))
    272 
    273 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
    274 #endif /* _AMIGA_BUS_H_ */
    275