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