Home | History | Annotate | Line # | Download | only in include
bus.h revision 1.3
      1 /*	$NetBSD: bus.h,v 1.3 1998/09/02 23:00:04 is 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 /*
     37  * Memory addresses (in bus space)
     38  */
     39 typedef u_long	bus_addr_t;
     40 typedef u_long	bus_size_t;
     41 
     42 /*
     43  * Access methods for bus resources and address space.
     44  */
     45 typedef struct bus_space_tag {
     46 	bus_addr_t	base;
     47 	u_char		stride;
     48 } *bus_space_tag_t;
     49 
     50 typedef u_long	bus_space_handle_t;
     51 
     52 void	bus_space_read_multi_1 __P((bus_space_tag_t, bus_space_handle_t,
     53 				int, caddr_t, int));
     54 void	bus_space_read_multi_2 __P((bus_space_tag_t, bus_space_handle_t,
     55 				int, caddr_t, int));
     56 void	bus_space_read_multi_4 __P((bus_space_tag_t, bus_space_handle_t,
     57 				int, caddr_t, int));
     58 void	bus_space_read_multi_8 __P((bus_space_tag_t, bus_space_handle_t,
     59 				int, caddr_t, int));
     60 void	bus_space_write_multi_1 __P((bus_space_tag_t, bus_space_handle_t,
     61 				int, caddr_t, int));
     62 void	bus_space_write_multi_2 __P((bus_space_tag_t, bus_space_handle_t,
     63 				int, caddr_t, int));
     64 void	bus_space_write_multi_4 __P((bus_space_tag_t, bus_space_handle_t,
     65 				int, caddr_t, int));
     66 void	bus_space_write_multi_8 __P((bus_space_tag_t, bus_space_handle_t,
     67 				int, caddr_t, int));
     68 
     69 void	bus_space_read_region_1 __P((bus_space_tag_t, bus_space_handle_t,
     70 				int, caddr_t, int));
     71 
     72 void	bus_space_write_region_1 __P((bus_space_tag_t, bus_space_handle_t,
     73 				int, caddr_t, int));
     74 
     75 #if 0
     76 int	bus_space_map __P((bus_space_tag_t, bus_addr_t, bus_size_t,
     77 				int, bus_space_handle_t *));
     78 void	bus_space_unmap __P((bus_space_tag_t, bus_space_handle_t,
     79 				bus_size_t));
     80 #endif
     81 
     82 #define bus_space_map(tag,off,size,cache,handle) 			\
     83 	(*(handle) = (tag)->base + ((off)<<(tag)->stride), 0)
     84 
     85 #define bus_space_subregion(tag, handle, offset, size, nhandlep) \
     86 	(*(nhandlep) = (handle) + ((offset)<<(tag)->stride), 0)
     87 
     88 #define bus_space_unmap(tag,handle,size)	(void)0
     89 
     90 #define	bus_space_read_1(t, h, o) \
     91     ((void) t, (*(volatile u_int8_t *)((h) + ((o)<<(t)->stride))))
     92 
     93 #define	bus_space_write_1(t, h, o, v) \
     94     ((void) t, ((void)(*(volatile u_int8_t *)((h) + ((o)<<(t)->stride)) = (v))))
     95 
     96 extern __inline__ void
     97 bus_space_read_multi_1(t, h, o, a, c)
     98 	bus_space_tag_t		t;
     99 	bus_space_handle_t	h;
    100 	int			o, c;
    101 	caddr_t			a;
    102 {
    103 	for (; c; a++, c--)
    104 		*(u_int8_t *)a = bus_space_read_1(t, h, o);
    105 }
    106 #ifdef notyet
    107 extern __inline__ void
    108 bus_space_read_multi_2(t, h, o, a, c)
    109 	bus_space_tag_t		t;
    110 	bus_space_handle_t	h;
    111 	int			o, c;
    112 	caddr_t			a;
    113 {
    114 	for (; c; a += 2, c--)
    115 		*(u_int16_t *)a = bus_space_read_2(t, h, o);
    116 }
    117 
    118 extern __inline__ void
    119 bus_space_read_multi_4(t, h, o, a, c)
    120 	bus_space_tag_t		t;
    121 	bus_space_handle_t	h;
    122 	int			o, c;
    123 	caddr_t			a;
    124 {
    125 	for (; c; a += 4, c--)
    126 		*(u_int32_t *)a = bus_space_read_4(t, h, o);
    127 }
    128 
    129 extern __inline__ void
    130 bus_space_read_multi_8(t, h, o, a, c)
    131 	bus_space_tag_t		t;
    132 	bus_space_handle_t	h;
    133 	int			o, c;
    134 	caddr_t			a;
    135 {
    136 	for (; c; a += 8, c--)
    137 		*(u_int64_t *)a = bus_space_read_8(t, h, o);
    138 }
    139 #endif
    140 
    141 extern __inline__ void
    142 bus_space_write_multi_1(t, h, o, a, c)
    143 	bus_space_tag_t		t;
    144 	bus_space_handle_t	h;
    145 	int			o, c;
    146 	caddr_t			a;
    147 {
    148 	for (; c; a++, c--)
    149 		bus_space_write_1(t, h, o, *(u_int8_t *)a);
    150 }
    151 
    152 #ifdef notyet
    153 extern __inline__ void
    154 bus_space_write_multi_2(t, h, o, a, c)
    155 	bus_space_tag_t		t;
    156 	bus_space_handle_t	h;
    157 	int			o, c;
    158 	caddr_t			a;
    159 {
    160 	for (; c; a += 2, c--)
    161 		bus_space_write_2(t, h, o, *(u_int16_t *)a);
    162 }
    163 
    164 extern __inline__ void
    165 bus_space_write_multi_4(t, h, o, a, c)
    166 	bus_space_tag_t		t;
    167 	bus_space_handle_t	h;
    168 	int			o, c;
    169 	caddr_t			a;
    170 {
    171 	for (; c; a += 4, c--)
    172 		bus_space_write_4(t, h, o, *(u_int32_t *)a);
    173 }
    174 
    175 extern __inline__ void
    176 bus_space_write_multi_8(t, h, o, a, c)
    177 	bus_space_tag_t		t;
    178 	bus_space_handle_t	h;
    179 	int			o, c;
    180 	caddr_t			a;
    181 {
    182 	for (; c; a += 8, c--)
    183 		bus_space_write_8(t, h, o, *(u_int64_t *)a);
    184 }
    185 #endif
    186 
    187 extern __inline__ void
    188 bus_space_read_region_1(t, h, o, a, c)
    189 	bus_space_tag_t		t;
    190 	bus_space_handle_t	h;
    191 	int			o, c;
    192 	caddr_t			a;
    193 {
    194 	for (; c; a++, c--)
    195 		*(u_int8_t *)a = bus_space_read_1(t, h, o++);
    196 }
    197 
    198 extern __inline__ void
    199 bus_space_write_region_1(t, h, o, a, c)
    200 	bus_space_tag_t		t;
    201 	bus_space_handle_t	h;
    202 	int			o, c;
    203 	caddr_t			a;
    204 {
    205 	for (; c; a++, c--)
    206 		 bus_space_write_1(t, h, o++, *(u_int8_t *)a);
    207 }
    208 #endif /* _AMIGA_BUS_H_ */
    209