bus_defs.h revision 1.1.54.1 1 /* $NetBSD: bus_defs.h,v 1.1.54.1 2020/04/13 08:03:31 martin Exp $ */
2 /* NetBSD: bus.h,v 1.27 2000/03/15 16:44:50 drochner Exp */
3 /* $OpenBSD: bus.h,v 1.15 1999/08/11 23:15:21 niklas Exp $ */
4
5 /*-
6 * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
7 * All rights reserved.
8 *
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
11 * NASA Ames Research Center.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 /*
36 * Copyright (c) 1997 Per Fogelstrom. All rights reserved.
37 * Copyright (c) 1996 Niklas Hallqvist. All rights reserved.
38 *
39 * Redistribution and use in source and binary forms, with or without
40 * modification, are permitted provided that the following conditions
41 * are met:
42 * 1. Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * 2. Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in the
46 * documentation and/or other materials provided with the distribution.
47 * 3. All advertising materials mentioning features or use of this software
48 * must display the following acknowledgement:
49 * This product includes software developed by Christopher G. Demetriou
50 * for the NetBSD Project.
51 * 4. The name of the author may not be used to endorse or promote products
52 * derived from this software without specific prior written permission
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
55 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
56 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
57 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
58 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
59 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
60 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
61 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
62 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
63 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 */
65
66 #ifndef _ARC_BUS_DEFS_H_
67 #define _ARC_BUS_DEFS_H_
68 #ifdef _KERNEL
69
70 /*
71 * Bus address and size types
72 */
73 typedef u_long bus_addr_t;
74 typedef u_long bus_size_t;
75
76 #define PRIxBUSADDR "lx"
77 #define PRIxBUSSIZE "lx"
78 #define PRIuBUSSIZE "lu"
79
80 #include <mips/locore.h>
81
82 #ifdef BUS_SPACE_DEBUG
83 #include <sys/systm.h> /* for printf() prototype */
84 /*
85 * Macros for checking the aligned-ness of pointers passed to bus
86 * space ops. Strict alignment is required by the MIPS architecture,
87 * and a trap will occur if unaligned access is performed. These
88 * may aid in the debugging of a broken device driver by displaying
89 * useful information about the problem.
90 */
91 #define __BUS_SPACE_ALIGNED_ADDRESS(p, t) \
92 ((((u_long)(p)) & (sizeof(t)-1)) == 0)
93
94 #define __BUS_SPACE_ADDRESS_SANITY(p, t, d) \
95 ({ \
96 if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) { \
97 printf("%s 0x%lx not aligned to %d bytes %s:%d\n", \
98 d, (u_long)(p), sizeof(t), __FILE__, __LINE__); \
99 } \
100 (void) 0; \
101 })
102
103 #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
104 #else
105 #define __BUS_SPACE_ADDRESS_SANITY(p,t,d) (void) 0
106 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
107 #endif /* BUS_SPACE_DEBUG */
108
109 /*
110 * Access methods for bus resources and address space.
111 */
112 typedef uint32_t bus_space_handle_t;
113 typedef struct arc_bus_space *bus_space_tag_t;
114
115 #define PRIxBSH "lx"
116
117 struct arc_bus_space {
118 const char *bs_name;
119 struct extent *bs_extent;
120 bus_addr_t bs_start;
121 bus_size_t bs_size;
122
123 paddr_t bs_pbase;
124 vaddr_t bs_vbase;
125
126 /* sparse addressing shift count */
127 uint8_t bs_stride_1;
128 uint8_t bs_stride_2;
129 uint8_t bs_stride_4;
130 uint8_t bs_stride_8;
131
132 /* compose a bus_space handle from tag/handle/addr/size/flags (MD) */
133 int (*bs_compose_handle)(bus_space_tag_t, bus_addr_t,
134 bus_size_t, int, bus_space_handle_t *);
135
136 /* dispose a bus_space handle (MD) */
137 int (*bs_dispose_handle)(bus_space_tag_t, bus_space_handle_t,
138 bus_size_t);
139
140 /* convert bus_space tag/handle to physical address (MD) */
141 int (*bs_paddr)(bus_space_tag_t, bus_space_handle_t,
142 paddr_t *);
143
144 /* mapping/unmapping */
145 int (*bs_map)(bus_space_tag_t, bus_addr_t, bus_size_t, int,
146 bus_space_handle_t *);
147 void (*bs_unmap)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
148 int (*bs_subregion)(bus_space_tag_t, bus_space_handle_t,
149 bus_size_t, bus_size_t, bus_space_handle_t *);
150 paddr_t (*bs_mmap)(bus_space_tag_t, bus_addr_t, off_t, int, int);
151
152 /* allocation/deallocation */
153 int (*bs_alloc)(bus_space_tag_t, bus_addr_t, bus_addr_t,
154 bus_size_t, bus_size_t, bus_size_t, int,
155 bus_addr_t *, bus_space_handle_t *);
156 void (*bs_free)(bus_space_tag_t, bus_space_handle_t, bus_size_t);
157
158 void *bs_aux;
159 };
160
161 /* vaddr_t argument of arc_bus_space_init() */
162 #define ARC_BUS_SPACE_UNMAPPED ((vaddr_t)0)
163
164 #define BUS_SPACE_MAP_CACHEABLE 0x01
165 #define BUS_SPACE_MAP_LINEAR 0x02
166 #define BUS_SPACE_MAP_PREFETCHABLE 0x04
167
168 #define __BUS_SPACE_HAS_STREAM_METHODS
169
170 #define BUS_SPACE_BARRIER_READ 0x01
171 #define BUS_SPACE_BARRIER_WRITE 0x02
172
173 /*
174 * Flags used in various bus DMA methods.
175 */
176 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
177 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
178 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
179 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
180 #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
181 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
182 #define BUS_DMA_BUS2 0x020
183 #define BUS_DMA_BUS3 0x040
184 #define BUS_DMA_BUS4 0x080
185 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
186 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
187 #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
188
189 #define ARC_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */
190
191 /* Forwards needed by prototypes below. */
192 struct mbuf;
193 struct uio;
194
195 /*
196 * Operations performed by bus_dmamap_sync().
197 */
198 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
199 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
200 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
201 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
202
203 typedef struct arc_bus_dma_tag *bus_dma_tag_t;
204 typedef struct arc_bus_dmamap *bus_dmamap_t;
205
206 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
207
208 /*
209 * bus_dma_segment_t
210 *
211 * Describes a single contiguous DMA transaction. Values
212 * are suitable for programming into DMA registers.
213 */
214 struct arc_bus_dma_segment {
215 /*
216 * PUBLIC MEMBERS: these are used by device drivers.
217 */
218 bus_addr_t ds_addr; /* DMA address */
219 bus_size_t ds_len; /* length of transfer */
220 /*
221 * PRIVATE MEMBERS for the DMA back-end.: not for use by drivers.
222 */
223 vaddr_t _ds_paddr; /* CPU physical address */
224 vaddr_t _ds_vaddr; /* virtual address, 0 if invalid */
225 };
226 typedef struct arc_bus_dma_segment bus_dma_segment_t;
227
228 /*
229 * bus_dma_tag_t
230 *
231 * A machine-dependent opaque type describing the implementation of
232 * DMA for a given bus.
233 */
234
235 struct arc_bus_dma_tag {
236 bus_addr_t dma_offset;
237
238 /*
239 * DMA mapping methods.
240 */
241 int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
242 bus_size_t, bus_size_t, int, bus_dmamap_t *);
243 void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
244 int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
245 bus_size_t, struct proc *, int);
246 int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
247 struct mbuf *, int);
248 int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
249 struct uio *, int);
250 int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
251 bus_dma_segment_t *, int, bus_size_t, int);
252 void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
253 void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
254 bus_addr_t, bus_size_t, int);
255
256 /*
257 * DMA memory utility functions.
258 */
259 int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
260 bus_size_t, bus_dma_segment_t *, int, int *, int);
261 void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int);
262 int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
263 int, size_t, void **, int);
264 void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
265 paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
266 int, off_t, int, int);
267 };
268
269 /*
270 * bus_dmamap_t
271 *
272 * Describes a DMA mapping.
273 */
274 struct arc_bus_dmamap {
275 /*
276 * PRIVATE MEMBERS: not for use by machine-independent code.
277 */
278 bus_size_t _dm_size; /* largest DMA transfer mappable */
279 int _dm_segcnt; /* number of segs this map can map */
280 bus_size_t _dm_maxmaxsegsz; /* fixed largest possible segment */
281 bus_size_t _dm_boundary; /* don't cross this */
282 int _dm_flags; /* misc. flags */
283 struct vmspace *_dm_vmspace; /* vmspace that owns the mapping */
284
285 /*
286 * Private cookie to be used by the DMA back-end.
287 */
288 void *_dm_cookie;
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 /* _KERNEL */
300 #endif /* _ARC_BUS_DEFS_H_ */
301