bus_defs.h revision 1.3.2.1 1 /* $NetBSD: bus_defs.h,v 1.3.2.1 2016/11/04 14:49:05 pgoyette Exp $ */
2
3 /*-
4 * Copyright (c) 1996, 1997, 1998, 2001 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 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Copyright (c) 1997-1999, 2001 Eduardo E. Horvath. All rights reserved.
35 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
36 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by Christopher G. Demetriou
49 * for the NetBSD Project.
50 * 4. The name of the author may not be used to endorse or promote products
51 * derived from this software without specific prior written permission
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
54 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
57 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
62 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 */
64
65 #ifndef _SPARC64_BUS_DEFS_H_
66 #define _SPARC64_BUS_DEFS_H_
67
68 #include <machine/types.h>
69 #include <machine/ctlreg.h>
70
71 /*
72 * Debug hooks
73 */
74
75 #define BSDB_ACCESS 0x01
76 #define BSDB_MAP 0x02
77
78 /*
79 * UPA and SBUS spaces are non-cached and big endian
80 * (except for RAM and PROM)
81 *
82 * PCI spaces are non-cached and little endian
83 */
84
85 enum bus_type {
86 UPA_BUS_SPACE,
87 SBUS_BUS_SPACE,
88 PCI_CONFIG_BUS_SPACE,
89 PCI_IO_BUS_SPACE,
90 PCI_MEMORY_BUS_SPACE,
91 LAST_BUS_SPACE
92 };
93 /* For backwards compatibility */
94 #define SPARC_BUS_SPACE UPA_BUS_SPACE
95
96 #define __BUS_SPACE_HAS_STREAM_METHODS 1
97
98 /*
99 * Bus address and size types
100 */
101 typedef struct _bus_space_handle {
102 uint64_t _ptr;
103 uint8_t _asi;
104 uint8_t _sasi;
105 } bus_space_handle_t;
106 typedef enum bus_type bus_type_t;
107 typedef uint64_t bus_addr_t;
108 typedef uint64_t bus_size_t;
109
110 /*
111 * XXXX -- convert prom virtual address to bus_space_handle_t
112 */
113 #define sparc_promaddr_to_handle(tag, promaddr, hp) \
114 do { \
115 (hp)->_ptr = (uint64_t)(promaddr); \
116 (hp)->_asi = ASI_PRIMARY; \
117 (hp)->_sasi = ASI_PRIMARY; \
118 } while (0)
119
120 /* For buses which have an iospace. */
121 #define BUS_ADDR_IOSPACE(x) ((x)>>32)
122 #define BUS_ADDR_PADDR(x) ((x)&0xffffffff)
123 #define BUS_ADDR(io, pa) ((((bus_addr_t)io)<<32)|(pa))
124
125 /*
126 * Access methods for bus resources and address space.
127 */
128 typedef struct sparc_bus_space_tag *bus_space_tag_t;
129
130 struct sparc_bus_space_tag {
131 void *cookie;
132 bus_space_tag_t parent;
133 /*
134 * Windows onto the parent bus that this tag maps. If ranges
135 * is non-NULL, the address will be translated, and recursively
136 * mapped via the parent tag.
137 */
138 struct openprom_range *ranges;
139 int nranges;
140
141 int type;
142
143 int (*sparc_bus_alloc)(bus_space_tag_t, bus_addr_t,
144 bus_addr_t, bus_size_t, bus_size_t, bus_size_t, int,
145 bus_addr_t *, bus_space_handle_t *);
146
147 void (*sparc_bus_free)(bus_space_tag_t, bus_space_handle_t,
148 bus_size_t);
149
150 int (*sparc_bus_map)(bus_space_tag_t, bus_addr_t, bus_size_t,
151 int, vaddr_t, bus_space_handle_t *);
152
153 int (*sparc_bus_unmap)(bus_space_tag_t, bus_space_handle_t,
154 bus_size_t);
155
156 int (*sparc_bus_subregion)(bus_space_tag_t,
157 bus_space_handle_t, bus_size_t, bus_size_t,
158 bus_space_handle_t *);
159
160 paddr_t (*sparc_bus_mmap)(bus_space_tag_t, bus_addr_t, off_t,
161 int, int);
162
163 void *(*sparc_intr_establish)(bus_space_tag_t, int, int,
164 int (*)(void *), void *, void (*)(void));
165
166 };
167
168 /* flags for bus space map functions */
169 #define BUS_SPACE_MAP_READONLY 0x0008
170 #define BUS_SPACE_MAP_BUS1 0x0100
171 #define BUS_SPACE_MAP_BUS2 0x0200
172 #define BUS_SPACE_MAP_BUS3 0x0400
173 #define BUS_SPACE_MAP_BUS4 0x0800
174 #define BUS_SPACE_MAP_LITTLE 0x1000
175 /* sparc uses this, it's not supposed to do anything on sparc64 */
176 #define BUS_SPACE_MAP_LARGE 0
177
178 /* flags for bus_space_barrier() */
179 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
180 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
181
182 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
183
184 /*
185 * Flags used in various bus DMA methods.
186 */
187 #define BUS_DMA_NOWRITE BUS_DMA_BUS1
188 #define BUS_DMA_DVMA BUS_DMA_BUS2 /* Don't bother with alignment */
189
190 /* Forwards needed by prototypes below. */
191 struct mbuf;
192 struct uio;
193
194 /*
195 * Operations performed by bus_dmamap_sync().
196 */
197 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
198 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
199 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
200 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
201
202 typedef struct sparc_bus_dma_tag *bus_dma_tag_t;
203 typedef struct sparc_bus_dmamap *bus_dmamap_t;
204
205 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
206
207 /*
208 * bus_dma_segment_t
209 *
210 * Describes a single contiguous DMA transaction. Values
211 * are suitable for programming into DMA registers.
212 */
213 struct sparc_bus_dma_segment {
214 bus_addr_t ds_addr; /* DVMA address */
215 bus_size_t ds_len; /* length of transfer */
216 bus_size_t _ds_boundary; /* don't cross this */
217 bus_size_t _ds_align; /* align to this */
218 void *_ds_mlist; /* XXX - dmamap_alloc'ed pages */
219 };
220 typedef struct sparc_bus_dma_segment bus_dma_segment_t;
221
222
223 /*
224 * bus_dma_tag_t
225 *
226 * A machine-dependent opaque type describing the implementation of
227 * DMA for a given bus.
228 */
229 struct sparc_bus_dma_tag {
230 void *_cookie; /* cookie used in the guts */
231 struct sparc_bus_dma_tag* _parent;
232
233 /*
234 * DMA mapping methods.
235 */
236 int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
237 bus_size_t, bus_size_t, int, bus_dmamap_t *);
238 void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
239 int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
240 bus_size_t, struct proc *, int);
241 int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
242 struct mbuf *, int);
243 int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
244 struct uio *, int);
245 int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
246 bus_dma_segment_t *, int, bus_size_t, int);
247 void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
248 void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
249 bus_addr_t, bus_size_t, int);
250
251 /*
252 * DMA memory utility functions.
253 */
254 int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
255 bus_size_t, bus_dma_segment_t *, int, int *, int);
256 void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int);
257 int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
258 int, size_t, void **, int);
259 void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
260 paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
261 int, off_t, int, int);
262 };
263
264 /*
265 * bus_dmamap_t
266 *
267 * Describes a DMA mapping.
268 */
269 struct sparc_bus_dmamap {
270 /*
271 * PRIVATE MEMBERS: not for use by machine-independent code.
272 */
273 bus_addr_t _dm_dvmastart; /* start and size of allocated */
274 bus_size_t _dm_dvmasize; /* DVMA segment for this map. */
275
276 bus_size_t _dm_size; /* largest DMA transfer mappable */
277 bus_size_t _dm_maxmaxsegsz; /* fixed largest possible segment */
278 bus_size_t _dm_boundary; /* don't cross this */
279 int _dm_segcnt; /* number of segs this map can map */
280 int _dm_flags; /* misc. flags */
281 #define _DM_TYPE_LOAD 0
282 #define _DM_TYPE_SEGS 1
283 #define _DM_TYPE_UIO 2
284 #define _DM_TYPE_MBUF 3
285 int _dm_type; /* type of mapping: raw, uio, mbuf, etc */
286 void *_dm_source; /* source mbuf, uio, etc. needed for unload */
287
288 void *_dm_cookie; /* cookie for bus-specific functions */
289
290 /*
291 * PUBLIC MEMBERS: these are used by machine-independent code.
292 */
293 bus_size_t dm_maxsegsz; /* largest possible segment */
294 bus_size_t dm_mapsize; /* size of the mapping */
295 int dm_nsegs; /* # valid segments in mapping */
296 bus_dma_segment_t dm_segs[1]; /* segments; variable length */
297 };
298
299 #endif /* _SPARC64_BUS_DEFS_H_ */
300