xref: /openbsd/sys/arch/landisk/include/bus.h (revision 404b540a)
1 /*	$OpenBSD: bus.h,v 1.6 2009/04/20 00:42:06 oga Exp $	*/
2 /*	$NetBSD: bus.h,v 1.1 2006/09/01 21:26:18 uwe Exp $	*/
3 
4 /*-
5  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10  * NASA Ames Research Center.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
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 _LANDISK_BUS_H_
66 #define	_LANDISK_BUS_H_
67 
68 #include <sys/types.h>
69 
70 typedef	u_long	bus_addr_t;
71 typedef	u_long	bus_size_t;
72 
73 typedef struct _bus_space *bus_space_tag_t;
74 typedef u_long bus_space_handle_t;
75 
76 struct _bus_space {
77 	/* cookie */
78 	void		*bs_cookie;
79 
80 	/* mapping/unmapping */
81 	int		(*bs_map)(void *, bus_addr_t, bus_size_t,
82 			    int, bus_space_handle_t *);
83 	void		(*bs_unmap)(void *, bus_space_handle_t,
84 			    bus_size_t);
85 	int		(*bs_subregion)(void *, bus_space_handle_t,
86 			    bus_size_t, bus_size_t, bus_space_handle_t *);
87 
88 	/* allocation/deallocation */
89 	int		(*bs_alloc)(void *, bus_addr_t, bus_addr_t,
90 			    bus_size_t, bus_size_t, bus_size_t, int,
91 			    bus_addr_t *, bus_space_handle_t *);
92 	void		(*bs_free)(void *, bus_space_handle_t,
93 			    bus_size_t);
94 
95 	/* get kernel virtual address */
96 	void *		(*bs_vaddr)(void *, bus_space_handle_t);
97 
98 	/* read (single) */
99 	uint8_t		(*bs_r_1)(void *, bus_space_handle_t,
100 			    bus_size_t);
101 	uint16_t	(*bs_r_2)(void *, bus_space_handle_t,
102 			    bus_size_t);
103 	uint32_t	(*bs_r_4)(void *, bus_space_handle_t,
104 			    bus_size_t);
105 	uint64_t	(*bs_r_8)(void *, bus_space_handle_t,
106 			    bus_size_t);
107 
108 	/* read multiple */
109 	void		(*bs_rm_1)(void *, bus_space_handle_t,
110 			    bus_size_t, uint8_t *, bus_size_t);
111 	void		(*bs_rm_2)(void *, bus_space_handle_t,
112 			    bus_size_t, uint16_t *, bus_size_t);
113 	void		(*bs_rm_4)(void *, bus_space_handle_t,
114 			    bus_size_t, uint32_t *, bus_size_t);
115 	void		(*bs_rm_8)(void *, bus_space_handle_t,
116 			    bus_size_t, uint64_t *, bus_size_t);
117 
118 	void		(*bs_rrm_2)(void *, bus_space_handle_t,
119 			    bus_size_t, uint8_t *, bus_size_t);
120 	void		(*bs_rrm_4)(void *, bus_space_handle_t,
121 			    bus_size_t, uint8_t *, bus_size_t);
122 	void		(*bs_rrm_8)(void *, bus_space_handle_t,
123 			    bus_size_t, uint8_t *, bus_size_t);
124 
125 	/* read region */
126 	void		(*bs_rr_1)(void *, bus_space_handle_t,
127 			    bus_size_t, uint8_t *, bus_size_t);
128 	void		(*bs_rr_2)(void *, bus_space_handle_t,
129 			    bus_size_t, uint16_t *, bus_size_t);
130 	void		(*bs_rr_4)(void *, bus_space_handle_t,
131 			    bus_size_t, uint32_t *, bus_size_t);
132 	void		(*bs_rr_8)(void *, bus_space_handle_t,
133 			    bus_size_t, uint64_t *, bus_size_t);
134 
135 	void		(*bs_rrr_2)(void *, bus_space_handle_t,
136 			    bus_size_t, uint8_t *, bus_size_t);
137 	void		(*bs_rrr_4)(void *, bus_space_handle_t,
138 			    bus_size_t, uint8_t *, bus_size_t);
139 	void		(*bs_rrr_8)(void *, bus_space_handle_t,
140 			    bus_size_t, uint8_t *, bus_size_t);
141 
142 	/* write (single) */
143 	void		(*bs_w_1)(void *, bus_space_handle_t,
144 			    bus_size_t, uint8_t);
145 	void		(*bs_w_2)(void *, bus_space_handle_t,
146 			    bus_size_t, uint16_t);
147 	void		(*bs_w_4)(void *, bus_space_handle_t,
148 			    bus_size_t, uint32_t);
149 	void		(*bs_w_8)(void *, bus_space_handle_t,
150 			    bus_size_t, uint64_t);
151 
152 	/* write multiple */
153 	void		(*bs_wm_1)(void *, bus_space_handle_t,
154 			    bus_size_t, const uint8_t *, bus_size_t);
155 	void		(*bs_wm_2)(void *, bus_space_handle_t,
156 			    bus_size_t, const uint16_t *, bus_size_t);
157 	void		(*bs_wm_4)(void *, bus_space_handle_t,
158 			    bus_size_t, const uint32_t *, bus_size_t);
159 	void		(*bs_wm_8)(void *, bus_space_handle_t,
160 			    bus_size_t, const uint64_t *, bus_size_t);
161 
162 	void		(*bs_wrm_2)(void *, bus_space_handle_t,
163 			    bus_size_t, const uint8_t *, bus_size_t);
164 	void		(*bs_wrm_4)(void *, bus_space_handle_t,
165 			    bus_size_t, const uint8_t *, bus_size_t);
166 	void		(*bs_wrm_8)(void *, bus_space_handle_t,
167 			    bus_size_t, const uint8_t *, bus_size_t);
168 
169 	/* write region */
170 	void		(*bs_wr_1)(void *, bus_space_handle_t,
171 			    bus_size_t, const uint8_t *, bus_size_t);
172 	void		(*bs_wr_2)(void *, bus_space_handle_t,
173 			    bus_size_t, const uint16_t *, bus_size_t);
174 	void		(*bs_wr_4)(void *, bus_space_handle_t,
175 			    bus_size_t, const uint32_t *, bus_size_t);
176 	void		(*bs_wr_8)(void *, bus_space_handle_t,
177 			    bus_size_t, const uint64_t *, bus_size_t);
178 
179 	void		(*bs_wrr_2)(void *, bus_space_handle_t,
180 			    bus_size_t, const uint8_t *, bus_size_t);
181 	void		(*bs_wrr_4)(void *, bus_space_handle_t,
182 			    bus_size_t, const uint8_t *, bus_size_t);
183 	void		(*bs_wrr_8)(void *, bus_space_handle_t,
184 			    bus_size_t, const uint8_t *, bus_size_t);
185 
186 	/* set multiple */
187 	void		(*bs_sm_1)(void *, bus_space_handle_t,
188 			    bus_size_t, uint8_t, bus_size_t);
189 	void		(*bs_sm_2)(void *, bus_space_handle_t,
190 			    bus_size_t, uint16_t, bus_size_t);
191 	void		(*bs_sm_4)(void *, bus_space_handle_t,
192 			    bus_size_t, uint32_t, bus_size_t);
193 	void		(*bs_sm_8)(void *, bus_space_handle_t,
194 			    bus_size_t, uint64_t, bus_size_t);
195 
196 	/* set region */
197 	void		(*bs_sr_1)(void *, bus_space_handle_t,
198 			    bus_size_t, uint8_t, bus_size_t);
199 	void		(*bs_sr_2)(void *, bus_space_handle_t,
200 			    bus_size_t, uint16_t, bus_size_t);
201 	void		(*bs_sr_4)(void *, bus_space_handle_t,
202 			    bus_size_t, uint32_t, bus_size_t);
203 	void		(*bs_sr_8)(void *, bus_space_handle_t,
204 			    bus_size_t, uint64_t, bus_size_t);
205 
206 	/* copy */
207 	void		(*bs_c_1)(void *, bus_space_handle_t, bus_size_t,
208 			    bus_space_handle_t, bus_size_t, bus_size_t);
209 	void		(*bs_c_2)(void *, bus_space_handle_t, bus_size_t,
210 			    bus_space_handle_t, bus_size_t, bus_size_t);
211 	void		(*bs_c_4)(void *, bus_space_handle_t, bus_size_t,
212 			    bus_space_handle_t, bus_size_t, bus_size_t);
213 	void		(*bs_c_8)(void *, bus_space_handle_t, bus_size_t,
214 			    bus_space_handle_t, bus_size_t, bus_size_t);
215 };
216 
217 #ifdef _KERNEL
218 /*
219  * Utility macros; INTERNAL USE ONLY.
220  */
221 #define	__bs_c(a,b)		__CONCAT(a,b)
222 #define	__bs_opname(op,size)	__bs_c(__bs_c(__bs_c(bs_,op),_),size)
223 
224 #define	__bs_rs(sz, tn, t, h, o)					\
225 	(*(t)->__bs_opname(r,sz))((t)->bs_cookie, h, o)
226 
227 #define	__bs_ws(sz, tn, t, h, o, v)					\
228 	(*(t)->__bs_opname(w,sz))((t)->bs_cookie, h, o, v)
229 
230 #define	__bs_nonsingle(type, sz, tn, t, h, o, a, c)			\
231 	(*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, a, c)
232 
233 #define	__bs_set(type, sz, tn, t, h, o, v, c)				\
234 	(*(t)->__bs_opname(type,sz))((t)->bs_cookie, h, o, v, c)
235 
236 #define	__bs_copy(sz, tn, t, h1, o1, h2, o2, cnt)			\
237 	(*(t)->__bs_opname(c,sz))((t)->bs_cookie, h1, o1, h2, o2, cnt)
238 
239 
240 /*
241  * Mapping and unmapping operations.
242  */
243 #define	bus_space_map(t, a, s, f, hp)					\
244 	(*(t)->bs_map)((t)->bs_cookie, (a), (s), (f), (hp))
245 #define	bus_space_unmap(t, h, s)					\
246 	(*(t)->bs_unmap)((t)->bs_cookie, (h), (s))
247 #define	bus_space_subregion(t, h, o, s, hp)				\
248 	(*(t)->bs_subregion)((t)->bs_cookie, (h), (o), (s), (hp))
249 
250 #endif /* _KERNEL */
251 
252 #define	BUS_SPACE_MAP_CACHEABLE		0x01
253 #define	BUS_SPACE_MAP_LINEAR		0x02
254 #define	BUS_SPACE_MAP_PREFETCHABLE     	0x04
255 
256 #ifdef _KERNEL
257 /*
258  * Allocation and deallocation operations.
259  */
260 #define	bus_space_alloc(t, rs, re, s, a, b, f, ap, hp)			\
261 	(*(t)->bs_alloc)((t)->bs_cookie, (rs), (re), (s), (a), (b),	\
262 	    (f), (ap), (hp))
263 #define	bus_space_free(t, h, s)						\
264 	(*(t)->bs_free)((t)->bs_cookie, (h), (s))
265 
266 /*
267  * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
268  */
269 #define bus_space_vaddr(t, h) \
270 	(*(t)->bs_vaddr)((t)->bs_cookie, (h))
271 
272 /*
273  * Bus barrier operations.  The SH3 does not currently require
274  * barriers, but we must provide the flags to MI code.
275  */
276 #define	bus_space_barrier(t, h, o, l, f)				\
277 	((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f)))
278 
279 #define	BUS_SPACE_BARRIER_READ	0x01
280 #define	BUS_SPACE_BARRIER_WRITE	0x02
281 
282 
283 /*
284  * Bus read (single) operations.
285  */
286 #define	bus_space_read_1(t, h, o)	__bs_rs(1,uint8_t,(t),(h),(o))
287 #define	bus_space_read_2(t, h, o)	__bs_rs(2,uint16_t,(t),(h),(o))
288 #define	bus_space_read_4(t, h, o)	__bs_rs(4,uint32_t,(t),(h),(o))
289 #define	bus_space_read_8(t, h, o)	__bs_rs(8,uint64_t,(t),(h),(o))
290 
291 
292 /*
293  * Bus read multiple operations.
294  */
295 #define	bus_space_read_multi_1(t, h, o, a, c)				\
296 	__bs_nonsingle(rm,1,uint8_t,(t),(h),(o),(a),(c))
297 #define	bus_space_read_multi_2(t, h, o, a, c)				\
298 	__bs_nonsingle(rm,2,uint16_t,(t),(h),(o),(a),(c))
299 #define	bus_space_read_multi_4(t, h, o, a, c)				\
300 	__bs_nonsingle(rm,4,uint32_t,(t),(h),(o),(a),(c))
301 #define	bus_space_read_multi_8(t, h, o, a, c)				\
302 	__bs_nonsingle(rm,8,uint64_t,(t),(h),(o),(a),(c))
303 
304 #define	bus_space_read_raw_multi_2(t, h, o, a, c)			\
305 	__bs_nonsingle(rrm,2,uint16_t,(t),(h),(o),(a),(c))
306 #define	bus_space_read_raw_multi_4(t, h, o, a, c)			\
307 	__bs_nonsingle(rrm,4,uint32_t,(t),(h),(o),(a),(c))
308 #define	bus_space_read_raw_multi_8(t, h, o, a, c)			\
309 	__bs_nonsingle(rrm,8,uint64_t,(t),(h),(o),(a),(c))
310 
311 
312 /*
313  * Bus read region operations.
314  */
315 #define	bus_space_read_region_1(t, h, o, a, c)				\
316 	__bs_nonsingle(rr,1,uint8_t,(t),(h),(o),(a),(c))
317 #define	bus_space_read_region_2(t, h, o, a, c)				\
318 	__bs_nonsingle(rr,2,uint16_t,(t),(h),(o),(a),(c))
319 #define	bus_space_read_region_4(t, h, o, a, c)				\
320 	__bs_nonsingle(rr,4,uint32_t,(t),(h),(o),(a),(c))
321 #define	bus_space_read_region_8(t, h, o, a, c)				\
322 	__bs_nonsingle(rr,8,uint64_t,(t),(h),(o),(a),(c))
323 
324 #define	bus_space_read_raw_region_2(t, h, o, a, c)			\
325 	__bs_nonsingle(rrr,2,uint16_t,(t),(h),(o),(a),(c))
326 #define	bus_space_read_raw_region_4(t, h, o, a, c)			\
327 	__bs_nonsingle(rrr,4,uint32_t,(t),(h),(o),(a),(c))
328 #define	bus_space_read_raw_region_8(t, h, o, a, c)			\
329 	__bs_nonsingle(rrr,8,uint64_t,(t),(h),(o),(a),(c))
330 
331 
332 /*
333  * Bus write (single) operations.
334  */
335 #define	bus_space_write_1(t, h, o, v)	__bs_ws(1,uint8_t,(t),(h),(o),(v))
336 #define	bus_space_write_2(t, h, o, v)	__bs_ws(2,uint16_t,(t),(h),(o),(v))
337 #define	bus_space_write_4(t, h, o, v)	__bs_ws(4,uint32_t,(t),(h),(o),(v))
338 #define	bus_space_write_8(t, h, o, v)	__bs_ws(8,uint64_t,(t),(h),(o),(v))
339 
340 
341 /*
342  * Bus write multiple operations.
343  */
344 #define	bus_space_write_multi_1(t, h, o, a, c)				\
345 	__bs_nonsingle(wm,1,uint8_t,(t),(h),(o),(a),(c))
346 #define	bus_space_write_multi_2(t, h, o, a, c)				\
347 	__bs_nonsingle(wm,2,uint16_t,(t),(h),(o),(a),(c))
348 #define	bus_space_write_multi_4(t, h, o, a, c)				\
349 	__bs_nonsingle(wm,4,uint32_t,(t),(h),(o),(a),(c))
350 #define	bus_space_write_multi_8(t, h, o, a, c)				\
351 	__bs_nonsingle(wm,8,uint64_t,(t),(h),(o),(a),(c))
352 
353 #define	bus_space_write_raw_multi_2(t, h, o, a, c)			\
354 	__bs_nonsingle(wrm,2,uint16_t,(t),(h),(o),(a),(c))
355 #define	bus_space_write_raw_multi_4(t, h, o, a, c)			\
356 	__bs_nonsingle(wrm,4,uint32_t,(t),(h),(o),(a),(c))
357 #define	bus_space_write_raw_multi_8(t, h, o, a, c)			\
358 	__bs_nonsingle(wrm,8,uint64_t,(t),(h),(o),(a),(c))
359 
360 
361 /*
362  * Bus write region operations.
363  */
364 #define	bus_space_write_region_1(t, h, o, a, c)				\
365 	__bs_nonsingle(wr,1,uint8_t,(t),(h),(o),(a),(c))
366 #define	bus_space_write_region_2(t, h, o, a, c)				\
367 	__bs_nonsingle(wr,2,uint16_t,(t),(h),(o),(a),(c))
368 #define	bus_space_write_region_4(t, h, o, a, c)				\
369 	__bs_nonsingle(wr,4,uint32_t,(t),(h),(o),(a),(c))
370 #define	bus_space_write_region_8(t, h, o, a, c)				\
371 	__bs_nonsingle(wr,8,uint64_t,(t),(h),(o),(a),(c))
372 
373 #define	bus_space_write_raw_region_2(t, h, o, a, c)			\
374 	__bs_nonsingle(wrr,2,uint16_t,(t),(h),(o),(a),(c))
375 #define	bus_space_write_raw_region_4(t, h, o, a, c)			\
376 	__bs_nonsingle(wrr,4,uint32_t,(t),(h),(o),(a),(c))
377 #define	bus_space_write_raw_region_8(t, h, o, a, c)			\
378 	__bs_nonsingle(wrr,8,uint64_t,(t),(h),(o),(a),(c))
379 
380 
381 /*
382  * Set multiple operations.
383  */
384 #define	bus_space_set_multi_1(t, h, o, v, c)				\
385 	__bs_set(sm,1,uint8_t,(t),(h),(o),(v),(c))
386 #define	bus_space_set_multi_2(t, h, o, v, c)				\
387 	__bs_set(sm,2,uint16_t,(t),(h),(o),(v),(c))
388 #define	bus_space_set_multi_4(t, h, o, v, c)				\
389 	__bs_set(sm,4,uint32_t,(t),(h),(o),(v),(c))
390 #define	bus_space_set_multi_8(t, h, o, v, c)				\
391 	__bs_set(sm,8,uint64_t,(t),(h),(o),(v),(c))
392 
393 
394 /*
395  * Set region operations.
396  */
397 #define	bus_space_set_region_1(t, h, o, v, c)				\
398 	__bs_set(sr,1,uint8_t,(t),(h),(o),(v),(c))
399 #define	bus_space_set_region_2(t, h, o, v, c)				\
400 	__bs_set(sr,2,uint16_t,(t),(h),(o),(v),(c))
401 #define	bus_space_set_region_4(t, h, o, v, c)				\
402 	__bs_set(sr,4,uint32_t,(t),(h),(o),(v),(c))
403 #define	bus_space_set_region_8(t, h, o, v, c)				\
404 	__bs_set(sr,8,uint64_t,(t),(h),(o),(v),(c))
405 
406 
407 /*
408  * Copy region operations.
409  */
410 #define	bus_space_copy_region_1(t, h1, o1, h2, o2, c)			\
411 	__bs_copy(1, uint8_t, (t), (h1), (o1), (h2), (o2), (c))
412 #define	bus_space_copy_region_2(t, h1, o1, h2, o2, c)			\
413 	__bs_copy(2, uint16_t, (t), (h1), (o1), (h2), (o2), (c))
414 #define	bus_space_copy_region_4(t, h1, o1, h2, o2, c)			\
415 	__bs_copy(4, uint32_t, (t), (h1), (o1), (h2), (o2), (c))
416 #define	bus_space_copy_region_8(t, h1, o1, h2, o2, c)			\
417 	__bs_copy(8, uint64_t, (t), (h1), (o1), (h2), (o2), (c))
418 
419 #endif /* _KERNEL */
420 
421 /*
422  * Flags used in various bus DMA methods.
423  */
424 #define	BUS_DMA_WAITOK		0x000	/* safe to sleep (pseudo-flag) */
425 #define	BUS_DMA_NOWAIT		0x001	/* not safe to sleep */
426 #define	BUS_DMA_ALLOCNOW	0x002	/* perform resource allocation now */
427 #define	BUS_DMA_COHERENT	0x004	/* map memory to not require sync */
428 #define	BUS_DMA_STREAMING	0x008	/* hint: sequential, unidirectional */
429 #define	BUS_DMA_BUS1		0x010	/* placeholders for bus functions... */
430 #define	BUS_DMA_BUS2		0x020
431 #define	BUS_DMA_BUS3		0x040
432 #define	BUS_DMA_BUS4		0x080
433 #define	BUS_DMA_READ		0x100	/* mapping is device -> memory only */
434 #define	BUS_DMA_WRITE		0x200	/* mapping is memory -> device only */
435 #define	BUS_DMA_NOCACHE		0x400	/* hint: map non-cached memory */
436 #define	BUS_DMA_ZERO		0x800	/* zero memory in dmamem_alloc */
437 
438 /* Forwards needed by prototypes below. */
439 struct mbuf;
440 struct uio;
441 
442 /*
443  *	Operations performed by bus_dmamap_sync().
444  */
445 #define	BUS_DMASYNC_PREREAD	0x01
446 #define	BUS_DMASYNC_POSTREAD	0x02
447 #define	BUS_DMASYNC_PREWRITE	0x04
448 #define	BUS_DMASYNC_POSTWRITE	0x08
449 
450 typedef struct _bus_dma_tag *bus_dma_tag_t;
451 typedef struct _bus_dmamap *bus_dmamap_t;
452 
453 #define BUS_DMA_TAG_VALID(t)    ((t) != (bus_dma_tag_t)0)
454 
455 /*
456  *	bus_dma_segment_t
457  *
458  *	Describes a single contiguous DMA transaction.  Values
459  *	are suitable for programming into DMA registers.
460  */
461 struct _bus_dma_segment {
462 	bus_addr_t	ds_addr;	/* DMA address */
463 	bus_size_t	ds_len;		/* length of transfer */
464 
465 	/* private section */
466 	bus_addr_t	_ds_vaddr;	/* virtual address */
467 };
468 typedef struct _bus_dma_segment	bus_dma_segment_t;
469 
470 /*
471  *	bus_dma_tag_t
472  *
473  *	A machine-dependent opaque type describing the implementation of
474  *	DMA for a given bus.
475  */
476 
477 struct _bus_dma_tag {
478 	void	*_cookie;		/* cookie used in the guts */
479 
480 	/*
481 	 * DMA mapping methods.
482 	 */
483 	int	(*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
484 		    bus_size_t, bus_size_t, int, bus_dmamap_t *);
485 	void	(*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
486 	int	(*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
487 		    bus_size_t, struct proc *, int);
488 	int	(*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
489 		    struct mbuf *, int);
490 	int	(*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
491 		    struct uio *, int);
492 	int	(*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
493 		    bus_dma_segment_t *, int, bus_size_t, int);
494 	void	(*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
495 	void	(*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
496 		    bus_addr_t, bus_size_t, int);
497 
498 	/*
499 	 * DMA memory utility functions.
500 	 */
501 	int	(*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
502 		    bus_size_t, bus_dma_segment_t *, int, int *, int);
503 	void	(*_dmamem_free)(bus_dma_tag_t,
504 		    bus_dma_segment_t *, int);
505 	int	(*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
506 		    int, size_t, caddr_t *, int);
507 	void	(*_dmamem_unmap)(bus_dma_tag_t, caddr_t, size_t);
508 	paddr_t	(*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
509 		    int, off_t, int, int);
510 };
511 
512 #define	bus_dmamap_create(t, s, n, m, b, f, p)			\
513 	(*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
514 #define	bus_dmamap_destroy(t, p)				\
515 	(*(t)->_dmamap_destroy)((t), (p))
516 #define	bus_dmamap_load(t, m, b, s, p, f)			\
517 	(*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
518 #define	bus_dmamap_load_mbuf(t, m, b, f)			\
519 	(*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
520 #define	bus_dmamap_load_uio(t, m, u, f)				\
521 	(*(t)->_dmamap_load_uio)((t), (m), (u), (f))
522 #define	bus_dmamap_load_raw(t, m, sg, n, s, f)			\
523 	(*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
524 #define	bus_dmamap_unload(t, p)					\
525 	(*(t)->_dmamap_unload)((t), (p))
526 #define	bus_dmamap_sync(t, m, o, l, op)				\
527 	(void)((t)->_dmamap_sync ?				\
528 	    (*(t)->_dmamap_sync)((t), (m), (o), (l), (op)) : (void)0)
529 
530 #define	bus_dmamem_alloc(t, s, a, b, sg, n, r, f)		\
531 	(*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
532 #define	bus_dmamem_free(t, sg, n)				\
533 	(*(t)->_dmamem_free)((t), (sg), (n))
534 #define	bus_dmamem_map(t, sg, n, s, k, f)			\
535 	(*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
536 #define	bus_dmamem_unmap(t, k, s)				\
537 	(*(t)->_dmamem_unmap)((t), (k), (s))
538 #define	bus_dmamem_mmap(t, sg, n, o, p, f)			\
539 	(*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
540 
541 /*
542  *	bus_dmamap_t
543  *
544  *	Describes a DMA mapping.
545  */
546 struct _bus_dmamap {
547 	/*
548 	 * PRIVATE MEMBERS: not for use my machine-independent code.
549 	 */
550 	bus_size_t	_dm_size;	/* largest DMA transfer mappable */
551 	int		_dm_segcnt;	/* number of segs this map can map */
552 	bus_size_t	_dm_maxsegsz;	/* largest possible segment */
553 	bus_size_t	_dm_boundary;	/* don't cross this */
554 	int		_dm_flags;	/* misc. flags */
555 
556 	void		*_dm_cookie;	/* cookie for bus-specific functions */
557 
558 	/*
559 	 * PUBLIC MEMBERS: these are used by machine-independent code.
560 	 */
561 	bus_size_t	dm_mapsize;	/* size of the mapping */
562 	int		dm_nsegs;	/* # valid segments in mapping */
563 	bus_dma_segment_t dm_segs[1];	/* segments; variable length */
564 };
565 
566 #if defined(_LANDISK_BUS_DMA_PRIVATE)
567 int	_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
568 	    bus_size_t, int, bus_dmamap_t *);
569 void	_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
570 int	_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
571 	    struct proc *, int);
572 int	_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *,int);
573 int	_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int);
574 int	_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
575 	    int, bus_size_t, int);
576 void	_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
577 void	_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
578 	    bus_size_t, int);
579 
580 int	_bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
581 	    bus_size_t alignment, bus_size_t boundary, bus_dma_segment_t *segs,
582 	    int nsegs, int *rsegs, int flags);
583 void	_bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
584 	    int nsegs);
585 int	_bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs, int nsegs,
586 	    size_t size, caddr_t *kvap, int flags);
587 void	_bus_dmamem_unmap(bus_dma_tag_t tag, caddr_t kva, size_t size);
588 paddr_t	_bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
589 	    int nsegs, off_t off, int prot, int flags);
590 #endif	/* _LANDISK_BUS_DMA_PRIVATE */
591 
592 #endif	/* _LANDISK_BUS_H_ */
593