xref: /netbsd-src/sys/arch/amigappc/include/bus_defs.h (revision 95fcb4b968bc1e35d01b4107c99e25e9e39160bd)
1 /*	$NetBSD: bus_defs.h,v 1.8 2020/03/06 02:31:13 christos 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  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef _AMIGAPPC_BUS_DEFS_H_
28 #define _AMIGAPPC_BUS_DEFS_H_
29 
30 /*
31  * Memory addresses (in bus space)
32  */
33 
34 typedef uint32_t bus_addr_t;
35 typedef uint32_t bus_size_t;
36 
37 #define PRIxBUSADDR	"x"
38 #define PRIxBUSSIZE	"x"
39 #define PRIuBUSSIZE	"u"
40 /*
41  * Access methods for bus resources and address space.
42  */
43 typedef struct bus_space_tag *bus_space_tag_t;
44 typedef u_long	bus_space_handle_t;
45 
46 #define PRIxBSH		"lx"
47 
48 struct amigappc_bus_dma_segment;
49 struct amigappc_bus_dma_tag;
50 struct amigappc_bus_dmamap;
51 typedef struct amigappc_bus_dma_segment bus_dma_segment_t;
52 typedef struct amigappc_bus_dma_tag bus_dma_tag_t;
53 typedef struct amigappc_bus_dmamap bus_dmamap_t;
54 
55 struct amigappc_bus_dma_tag {
56 	int dummy;
57 };
58 
59 struct amigappc_bus_dma_segment {
60 	bus_addr_t	ds_addr;
61 	bus_size_t	ds_len;
62 };
63 
64 struct amigappc_bus_dmamap {
65 	bus_size_t		dm_maxsegsz;
66 	bus_size_t		dm_mapsize;
67 	int			dm_nsegs;
68 	bus_dma_segment_t	*dm_segs;
69 	/* TBD */
70 };
71 
72 /* unpublic, but needed by method implementors */
73 
74 /*
75  * Lazyness macros for function declarations.
76  */
77 
78 #define bsr(what, typ) \
79 	typ (what)(bus_space_handle_t, bus_addr_t)
80 
81 #define bsw(what, typ) \
82 	void (what)(bus_space_handle_t, bus_addr_t, unsigned)
83 
84 #define bsrm(what, typ) \
85 	void (what)(bus_space_handle_t, bus_size_t, typ *, bus_size_t)
86 
87 #define bswm(what, typ) \
88 	void (what)(bus_space_handle_t, bus_size_t, const typ *, bus_size_t)
89 
90 #define bssr(what, typ) \
91 	void (what)(bus_space_handle_t, bus_size_t, unsigned, bus_size_t)
92 
93 #define bscr(what, typ) \
94 	void (what)(bus_space_handle_t, bus_size_t, \
95 		    bus_space_handle_t, bus_size_t, bus_size_t)
96 
97 /*
98  * Implementation specific structures.
99  * XXX Don't use outside of bus_space definitions!
100  * XXX maybe this should be encapsuled in a non-global .h file?
101  */
102 
103 struct bus_space_tag {
104 	bus_addr_t	base;
105 	const struct amiga_bus_space_methods *absm;
106 };
107 
108 struct amiga_bus_space_methods {
109 
110 	/* map, unmap, etc */
111 
112 	int (*bsm)(bus_space_tag_t,
113 		bus_addr_t, bus_size_t, int, bus_space_handle_t *);
114 
115 	int (*bsms)(bus_space_handle_t,
116 		bus_size_t, bus_size_t, bus_space_handle_t *);
117 
118 	void (*bsu)(bus_space_handle_t, bus_size_t);
119 
120 	/* placeholders for currently not implemented alloc and free */
121 
122 	void *bsa;
123 	void *bsf;
124 
125 	/* 8 bit methods */
126 
127 	bsr(*bsr1, uint8_t);
128 	bsw(*bsw1, uint8_t);
129 	bsrm(*bsrm1, uint8_t);
130 	bswm(*bswm1, uint8_t);
131 	bsrm(*bsrr1, uint8_t);
132 	bswm(*bswr1, uint8_t);
133 	bssr(*bssr1, uint8_t);
134 	bscr(*bscr1, uint8_t);
135 
136 	/* 16bit methods */
137 
138 	bsr(*bsr2, uint16_t);
139 	bsw(*bsw2, uint16_t);
140 	bsr(*bsrs2, uint16_t);
141 	bsw(*bsws2, uint16_t);
142 	bsrm(*bsrm2, uint16_t);
143 	bswm(*bswm2, uint16_t);
144 	bsrm(*bsrms2, uint16_t);
145 	bswm(*bswms2, uint16_t);
146 	bsrm(*bsrr2, uint16_t);
147 	bswm(*bswr2, uint16_t);
148 	bsrm(*bsrrs2, uint16_t);
149 	bswm(*bswrs2, uint16_t);
150 	bssr(*bssr2, uint16_t);
151 	bscr(*bscr2, uint16_t);
152 
153 	/* 32bit methods */
154 
155 	bsr(*bsr4, uint32_t);
156 	bsw(*bsw4, uint32_t);
157 	bsr(*bsrs4, uint32_t);
158 	bsw(*bsws4, uint32_t);
159 	bsrm(*bsrm4, uint32_t);
160 	bswm(*bswm4, uint32_t);
161 	bsrm(*bsrms4, uint32_t);
162 	bswm(*bswms4, uint32_t);
163 	bsrm(*bsrr4, uint32_t);
164 	bswm(*bswr4, uint32_t);
165 	bsrm(*bsrrs4, uint32_t);
166 	bswm(*bswrs4, uint32_t);
167 	bssr(*bssr4, uint32_t);
168 	bscr(*bscr4, uint32_t);
169 };
170 
171 #define BUS_SPACE_BARRIER_READ  0x01            /* force read barrier */
172 #define BUS_SPACE_BARRIER_WRITE 0x02            /* force write barrier */
173 
174 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
175 
176 #define __BUS_SPACE_HAS_STREAM_METHODS
177 
178 extern const struct amiga_bus_space_methods amiga_bus_stride_1;
179 extern const struct amiga_bus_space_methods amiga_bus_stride_1swap;
180 extern const struct amiga_bus_space_methods amiga_bus_stride_1swap_abs;
181 extern const struct amiga_bus_space_methods amiga_bus_stride_2;
182 extern const struct amiga_bus_space_methods amiga_bus_stride_4;
183 extern const struct amiga_bus_space_methods amiga_bus_stride_4swap;
184 extern const struct amiga_bus_space_methods amiga_bus_stride_16;
185 extern const struct amiga_bus_space_methods amiga_bus_stride_0x1000;
186 extern const struct amiga_bus_space_methods amiga_bus_stride_0x4000;
187 
188 #endif /* _AMIGAPPC_BUS_DEFS_H_ */
189