bus_defs.h revision 1.1 1 /* $NetBSD: bus_defs.h,v 1.1 2011/07/01 17:10:01 dyoung 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 _SPARC_BUS_DEFS_H_
66 #define _SPARC_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 /* sparc uses this, it's not supposed to do anything on sparc64 */
175 #define BUS_SPACE_MAP_LARGE 0
176
177 /* flags for bus_space_barrier() */
178 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
179 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
180
181 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
182
183 /*
184 * Flags used in various bus DMA methods.
185 */
186 #define BUS_DMA_NOWRITE BUS_DMA_BUS1
187 #define BUS_DMA_DVMA BUS_DMA_BUS2 /* Don't bother with alignment */
188
189 /* Forwards needed by prototypes below. */
190 struct mbuf;
191 struct uio;
192
193 /*
194 * Operations performed by bus_dmamap_sync().
195 */
196 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
197 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
198 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
199 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
200
201 typedef struct sparc_bus_dma_tag *bus_dma_tag_t;
202 typedef struct sparc_bus_dmamap *bus_dmamap_t;
203
204 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
205
206 /*
207 * bus_dma_segment_t
208 *
209 * Describes a single contiguous DMA transaction. Values
210 * are suitable for programming into DMA registers.
211 */
212 struct sparc_bus_dma_segment {
213 bus_addr_t ds_addr; /* DVMA address */
214 bus_size_t ds_len; /* length of transfer */
215 bus_size_t _ds_boundary; /* don't cross this */
216 bus_size_t _ds_align; /* align to this */
217 void *_ds_mlist; /* XXX - dmamap_alloc'ed pages */
218 };
219 typedef struct sparc_bus_dma_segment bus_dma_segment_t;
220
221
222 /*
223 * bus_dma_tag_t
224 *
225 * A machine-dependent opaque type describing the implementation of
226 * DMA for a given bus.
227 */
228 struct sparc_bus_dma_tag {
229 void *_cookie; /* cookie used in the guts */
230 struct sparc_bus_dma_tag* _parent;
231
232 /*
233 * DMA mapping methods.
234 */
235 int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
236 bus_size_t, bus_size_t, int, bus_dmamap_t *);
237 void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
238 int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
239 bus_size_t, struct proc *, int);
240 int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
241 struct mbuf *, int);
242 int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
243 struct uio *, int);
244 int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
245 bus_dma_segment_t *, int, bus_size_t, int);
246 void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
247 void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
248 bus_addr_t, bus_size_t, int);
249
250 /*
251 * DMA memory utility functions.
252 */
253 int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
254 bus_size_t, bus_dma_segment_t *, int, int *, int);
255 void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int);
256 int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
257 int, size_t, void **, int);
258 void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
259 paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
260 int, off_t, int, int);
261 };
262
263 /*
264 * bus_dmamap_t
265 *
266 * Describes a DMA mapping.
267 */
268 struct sparc_bus_dmamap {
269 /*
270 * PRIVATE MEMBERS: not for use by machine-independent code.
271 */
272 bus_addr_t _dm_dvmastart; /* start and size of allocated */
273 bus_size_t _dm_dvmasize; /* DVMA segment for this map. */
274
275 bus_size_t _dm_size; /* largest DMA transfer mappable */
276 bus_size_t _dm_maxmaxsegsz; /* fixed largest possible segment */
277 bus_size_t _dm_boundary; /* don't cross this */
278 int _dm_segcnt; /* number of segs this map can map */
279 int _dm_flags; /* misc. flags */
280 #define _DM_TYPE_LOAD 0
281 #define _DM_TYPE_SEGS 1
282 #define _DM_TYPE_UIO 2
283 #define _DM_TYPE_MBUF 3
284 int _dm_type; /* type of mapping: raw, uio, mbuf, etc */
285 void *_dm_source; /* source mbuf, uio, etc. needed for unload */
286
287 void *_dm_cookie; /* cookie for bus-specific functions */
288
289 /*
290 * PUBLIC MEMBERS: these are used by machine-independent code.
291 */
292 bus_size_t dm_maxsegsz; /* largest possible segment */
293 bus_size_t dm_mapsize; /* size of the mapping */
294 int dm_nsegs; /* # valid segments in mapping */
295 bus_dma_segment_t dm_segs[1]; /* segments; variable length */
296 };
297
298 #endif /* _SPARC_BUS_DEFS_H_ */
299