1 /* $NetBSD: bus.h,v 1.53 2007/03/04 05:59:11 christos Exp $ */
4 * Copyright (c) 1997, 1998, 2000, 2001 The NetBSD Foundation, Inc.
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.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
34 * Copyright (c) 1996 Carnegie-Mellon University.
35 * All rights reserved.
37 * Author: Chris G. Demetriou
39 * Permission to use, copy, modify and distribute this software and
40 * its documentation is hereby granted, provided that both the copyright
41 * notice and this permission notice appear in all copies of the
42 * software, derivative works or modified versions, and any portions
43 * thereof, and that both notices appear in supporting documentation.
45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
49 * Carnegie Mellon requests users of this software to return to
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
56 * any improvements or extensions that they make and grant Carnegie the
57 * rights to redistribute these changes.
63 #include <sys/types.h>
67 * Turn on BUS_SPACE_DEBUG if the global DEBUG option is enabled.
69 #if defined(DEBUG) && !defined(BUS_SPACE_DEBUG)
70 #define BUS_SPACE_DEBUG
73 #ifdef BUS_SPACE_DEBUG
74 #include <sys/systm.h> /* for printf() prototype */
76 * Macros for checking the aligned-ness of pointers passed to bus
77 * space ops. Strict alignment is required by the Alpha architecture,
78 * and a trap will occur if unaligned access is performed. These
79 * may aid in the debugging of a broken device driver by displaying
80 * useful information about the problem.
82 #define __BUS_SPACE_ALIGNED_ADDRESS(p, t) \
83 ((((u_long)(p)) & (sizeof(t)-1)) == 0)
85 #define __BUS_SPACE_ADDRESS_SANITY(p, t, d) \
87 if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) { \
88 printf("%s 0x%lx not aligned to %lu bytes %s:%d\n", \
89 d, (u_long)(p), sizeof(t), __FILE__, __LINE__); \
94 #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
96 #define __BUS_SPACE_ADDRESS_SANITY(p, t, d) (void) 0
97 #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
98 #endif /* BUS_SPACE_DEBUG */
101 struct alpha_bus_space_translation
;
104 * Addresses (in bus space).
106 typedef u_long bus_addr_t
;
107 typedef u_long bus_size_t
;
110 * Access methods for bus space.
112 typedef struct alpha_bus_space
*bus_space_tag_t
;
113 typedef u_long bus_space_handle_t
;
115 struct alpha_bus_space
{
119 /* mapping/unmapping */
120 int (*abs_map
)(void *, bus_addr_t
, bus_size_t
,
121 int, bus_space_handle_t
*, int);
122 void (*abs_unmap
)(void *, bus_space_handle_t
,
124 int (*abs_subregion
)(void *, bus_space_handle_t
,
125 bus_size_t
, bus_size_t
, bus_space_handle_t
*);
127 /* ALPHA SPECIFIC MAPPING METHOD */
128 int (*abs_translate
)(void *, bus_addr_t
, bus_size_t
,
129 int, struct alpha_bus_space_translation
*);
130 int (*abs_get_window
)(void *, int,
131 struct alpha_bus_space_translation
*);
133 /* allocation/deallocation */
134 int (*abs_alloc
)(void *, bus_addr_t
, bus_addr_t
,
135 bus_size_t
, bus_size_t
, bus_size_t
, int,
136 bus_addr_t
*, bus_space_handle_t
*);
137 void (*abs_free
)(void *, bus_space_handle_t
,
140 /* get kernel virtual address */
141 void * (*abs_vaddr
)(void *, bus_space_handle_t
);
143 /* mmap bus space for user */
144 paddr_t (*abs_mmap
)(void *, bus_addr_t
, off_t
, int, int);
147 void (*abs_barrier
)(void *, bus_space_handle_t
,
148 bus_size_t
, bus_size_t
, int);
151 u_int8_t (*abs_r_1
)(void *, bus_space_handle_t
,
153 u_int16_t (*abs_r_2
)(void *, bus_space_handle_t
,
155 u_int32_t (*abs_r_4
)(void *, bus_space_handle_t
,
157 u_int64_t (*abs_r_8
)(void *, bus_space_handle_t
,
161 void (*abs_rm_1
)(void *, bus_space_handle_t
,
162 bus_size_t
, u_int8_t
*, bus_size_t
);
163 void (*abs_rm_2
)(void *, bus_space_handle_t
,
164 bus_size_t
, u_int16_t
*, bus_size_t
);
165 void (*abs_rm_4
)(void *, bus_space_handle_t
,
166 bus_size_t
, u_int32_t
*, bus_size_t
);
167 void (*abs_rm_8
)(void *, bus_space_handle_t
,
168 bus_size_t
, u_int64_t
*, bus_size_t
);
171 void (*abs_rr_1
)(void *, bus_space_handle_t
,
172 bus_size_t
, u_int8_t
*, bus_size_t
);
173 void (*abs_rr_2
)(void *, bus_space_handle_t
,
174 bus_size_t
, u_int16_t
*, bus_size_t
);
175 void (*abs_rr_4
)(void *, bus_space_handle_t
,
176 bus_size_t
, u_int32_t
*, bus_size_t
);
177 void (*abs_rr_8
)(void *, bus_space_handle_t
,
178 bus_size_t
, u_int64_t
*, bus_size_t
);
181 void (*abs_w_1
)(void *, bus_space_handle_t
,
182 bus_size_t
, u_int8_t
);
183 void (*abs_w_2
)(void *, bus_space_handle_t
,
184 bus_size_t
, u_int16_t
);
185 void (*abs_w_4
)(void *, bus_space_handle_t
,
186 bus_size_t
, u_int32_t
);
187 void (*abs_w_8
)(void *, bus_space_handle_t
,
188 bus_size_t
, u_int64_t
);
191 void (*abs_wm_1
)(void *, bus_space_handle_t
,
192 bus_size_t
, const u_int8_t
*, bus_size_t
);
193 void (*abs_wm_2
)(void *, bus_space_handle_t
,
194 bus_size_t
, const u_int16_t
*, bus_size_t
);
195 void (*abs_wm_4
)(void *, bus_space_handle_t
,
196 bus_size_t
, const u_int32_t
*, bus_size_t
);
197 void (*abs_wm_8
)(void *, bus_space_handle_t
,
198 bus_size_t
, const u_int64_t
*, bus_size_t
);
201 void (*abs_wr_1
)(void *, bus_space_handle_t
,
202 bus_size_t
, const u_int8_t
*, bus_size_t
);
203 void (*abs_wr_2
)(void *, bus_space_handle_t
,
204 bus_size_t
, const u_int16_t
*, bus_size_t
);
205 void (*abs_wr_4
)(void *, bus_space_handle_t
,
206 bus_size_t
, const u_int32_t
*, bus_size_t
);
207 void (*abs_wr_8
)(void *, bus_space_handle_t
,
208 bus_size_t
, const u_int64_t
*, bus_size_t
);
211 void (*abs_sm_1
)(void *, bus_space_handle_t
,
212 bus_size_t
, u_int8_t
, bus_size_t
);
213 void (*abs_sm_2
)(void *, bus_space_handle_t
,
214 bus_size_t
, u_int16_t
, bus_size_t
);
215 void (*abs_sm_4
)(void *, bus_space_handle_t
,
216 bus_size_t
, u_int32_t
, bus_size_t
);
217 void (*abs_sm_8
)(void *, bus_space_handle_t
,
218 bus_size_t
, u_int64_t
, bus_size_t
);
221 void (*abs_sr_1
)(void *, bus_space_handle_t
,
222 bus_size_t
, u_int8_t
, bus_size_t
);
223 void (*abs_sr_2
)(void *, bus_space_handle_t
,
224 bus_size_t
, u_int16_t
, bus_size_t
);
225 void (*abs_sr_4
)(void *, bus_space_handle_t
,
226 bus_size_t
, u_int32_t
, bus_size_t
);
227 void (*abs_sr_8
)(void *, bus_space_handle_t
,
228 bus_size_t
, u_int64_t
, bus_size_t
);
231 void (*abs_c_1
)(void *, bus_space_handle_t
, bus_size_t
,
232 bus_space_handle_t
, bus_size_t
, bus_size_t
);
233 void (*abs_c_2
)(void *, bus_space_handle_t
, bus_size_t
,
234 bus_space_handle_t
, bus_size_t
, bus_size_t
);
235 void (*abs_c_4
)(void *, bus_space_handle_t
, bus_size_t
,
236 bus_space_handle_t
, bus_size_t
, bus_size_t
);
237 void (*abs_c_8
)(void *, bus_space_handle_t
, bus_size_t
,
238 bus_space_handle_t
, bus_size_t
, bus_size_t
);
242 * Translation of an Alpha bus address; INTERNAL USE ONLY.
244 struct alpha_bus_space_translation
{
245 bus_addr_t abst_bus_start
; /* start of bus window */
246 bus_addr_t abst_bus_end
; /* end of bus window */
247 paddr_t abst_sys_start
; /* start of sysBus window */
248 paddr_t abst_sys_end
; /* end of sysBus window */
249 int abst_addr_shift
;/* address shift */
250 int abst_size_shift
;/* size shift */
251 int abst_flags
; /* flags; see below */
254 #define ABST_BWX 0x01 /* use BWX to access the bus */
255 #define ABST_DENSE 0x02 /* space is dense */
259 * Utility macros; INTERNAL USE ONLY.
261 #define __abs_c(a,b) __CONCAT(a,b)
262 #define __abs_opname(op,size) __abs_c(__abs_c(__abs_c(abs_,op),_),size)
264 #define __abs_rs(sz, tn, t, h, o) \
265 (__BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"), \
266 (*(t)->__abs_opname(r,sz))((t)->abs_cookie, h, o))
268 #define __abs_ws(sz, tn, t, h, o, v) \
270 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
271 (*(t)->__abs_opname(w,sz))((t)->abs_cookie, h, o, v); \
274 #define __abs_nonsingle(type, sz, tn, t, h, o, a, c) \
276 __BUS_SPACE_ADDRESS_SANITY((a), tn, "buffer"); \
277 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
278 (*(t)->__abs_opname(type,sz))((t)->abs_cookie, h, o, a, c); \
281 #define __abs_set(type, sz, tn, t, h, o, v, c) \
283 __BUS_SPACE_ADDRESS_SANITY((h) + (o), tn, "bus addr"); \
284 (*(t)->__abs_opname(type,sz))((t)->abs_cookie, h, o, v, c); \
287 #define __abs_copy(sz, tn, t, h1, o1, h2, o2, cnt) \
289 __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), tn, "bus addr 1"); \
290 __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), tn, "bus addr 2"); \
291 (*(t)->__abs_opname(c,sz))((t)->abs_cookie, h1, o1, h2, o2, cnt); \
296 * Mapping and unmapping operations.
298 #define bus_space_map(t, a, s, f, hp) \
299 (*(t)->abs_map)((t)->abs_cookie, (a), (s), (f), (hp), 1)
300 #define alpha_bus_space_map_noacct(t, a, s, f, hp) \
301 (*(t)->abs_map)((t)->abs_cookie, (a), (s), (f), (hp), 0)
302 #define bus_space_unmap(t, h, s) \
303 (*(t)->abs_unmap)((t)->abs_cookie, (h), (s), 1)
304 #define alpha_bus_space_unmap_noacct(t, h, s) \
305 (*(t)->abs_unmap)((t)->abs_cookie, (h), (s), 0)
306 #define bus_space_subregion(t, h, o, s, hp) \
307 (*(t)->abs_subregion)((t)->abs_cookie, (h), (o), (s), (hp))
309 #define alpha_bus_space_translate(t, a, s, f, abst) \
310 (*(t)->abs_translate)((t)->abs_cookie, (a), (s), (f), (abst))
311 #define alpha_bus_space_get_window(t, w, abst) \
312 (*(t)->abs_get_window)((t)->abs_cookie, (w), (abst))
315 #define BUS_SPACE_MAP_CACHEABLE 0x01
316 #define BUS_SPACE_MAP_LINEAR 0x02
317 #define BUS_SPACE_MAP_PREFETCHABLE 0x04
321 * Allocation and deallocation operations.
323 #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
324 (*(t)->abs_alloc)((t)->abs_cookie, (rs), (re), (s), (a), (b), \
326 #define bus_space_free(t, h, s) \
327 (*(t)->abs_free)((t)->abs_cookie, (h), (s))
330 * Get kernel virtual address for ranges mapped BUS_SPACE_MAP_LINEAR.
332 #define bus_space_vaddr(t, h) \
333 (*(t)->abs_vaddr)((t)->abs_cookie, (h))
336 * Mmap bus space for a user application.
338 #define bus_space_mmap(t, a, o, p, f) \
339 (*(t)->abs_mmap)((t)->abs_cookie, (a), (o), (p), (f))
342 * Bus barrier operations.
344 #define bus_space_barrier(t, h, o, l, f) \
345 (*(t)->abs_barrier)((t)->abs_cookie, (h), (o), (l), (f))
347 #define BUS_SPACE_BARRIER_READ 0x01
348 #define BUS_SPACE_BARRIER_WRITE 0x02
352 * Bus read (single) operations.
354 #define bus_space_read_1(t, h, o) __abs_rs(1,u_int8_t,(t),(h),(o))
355 #define bus_space_read_2(t, h, o) __abs_rs(2,u_int16_t,(t),(h),(o))
356 #define bus_space_read_4(t, h, o) __abs_rs(4,u_int32_t,(t),(h),(o))
357 #define bus_space_read_8(t, h, o) __abs_rs(8,u_int64_t,(t),(h),(o))
361 * Bus read multiple operations.
363 #define bus_space_read_multi_1(t, h, o, a, c) \
364 __abs_nonsingle(rm,1,u_int8_t,(t),(h),(o),(a),(c))
365 #define bus_space_read_multi_2(t, h, o, a, c) \
366 __abs_nonsingle(rm,2,u_int16_t,(t),(h),(o),(a),(c))
367 #define bus_space_read_multi_4(t, h, o, a, c) \
368 __abs_nonsingle(rm,4,u_int32_t,(t),(h),(o),(a),(c))
369 #define bus_space_read_multi_8(t, h, o, a, c) \
370 __abs_nonsingle(rm,8,u_int64_t,(t),(h),(o),(a),(c))
374 * Bus read region operations.
376 #define bus_space_read_region_1(t, h, o, a, c) \
377 __abs_nonsingle(rr,1,u_int8_t,(t),(h),(o),(a),(c))
378 #define bus_space_read_region_2(t, h, o, a, c) \
379 __abs_nonsingle(rr,2,u_int16_t,(t),(h),(o),(a),(c))
380 #define bus_space_read_region_4(t, h, o, a, c) \
381 __abs_nonsingle(rr,4,u_int32_t,(t),(h),(o),(a),(c))
382 #define bus_space_read_region_8(t, h, o, a, c) \
383 __abs_nonsingle(rr,8,u_int64_t,(t),(h),(o),(a),(c))
387 * Bus write (single) operations.
389 #define bus_space_write_1(t, h, o, v) __abs_ws(1,u_int8_t,(t),(h),(o),(v))
390 #define bus_space_write_2(t, h, o, v) __abs_ws(2,u_int16_t,(t),(h),(o),(v))
391 #define bus_space_write_4(t, h, o, v) __abs_ws(4,u_int32_t,(t),(h),(o),(v))
392 #define bus_space_write_8(t, h, o, v) __abs_ws(8,u_int64_t,(t),(h),(o),(v))
396 * Bus write multiple operations.
398 #define bus_space_write_multi_1(t, h, o, a, c) \
399 __abs_nonsingle(wm,1,u_int8_t,(t),(h),(o),(a),(c))
400 #define bus_space_write_multi_2(t, h, o, a, c) \
401 __abs_nonsingle(wm,2,u_int16_t,(t),(h),(o),(a),(c))
402 #define bus_space_write_multi_4(t, h, o, a, c) \
403 __abs_nonsingle(wm,4,u_int32_t,(t),(h),(o),(a),(c))
404 #define bus_space_write_multi_8(t, h, o, a, c) \
405 __abs_nonsingle(wm,8,u_int64_t,(t),(h),(o),(a),(c))
409 * Bus write region operations.
411 #define bus_space_write_region_1(t, h, o, a, c) \
412 __abs_nonsingle(wr,1,u_int8_t,(t),(h),(o),(a),(c))
413 #define bus_space_write_region_2(t, h, o, a, c) \
414 __abs_nonsingle(wr,2,u_int16_t,(t),(h),(o),(a),(c))
415 #define bus_space_write_region_4(t, h, o, a, c) \
416 __abs_nonsingle(wr,4,u_int32_t,(t),(h),(o),(a),(c))
417 #define bus_space_write_region_8(t, h, o, a, c) \
418 __abs_nonsingle(wr,8,u_int64_t,(t),(h),(o),(a),(c))
422 * Set multiple operations.
424 #define bus_space_set_multi_1(t, h, o, v, c) \
425 __abs_set(sm,1,u_int8_t,(t),(h),(o),(v),(c))
426 #define bus_space_set_multi_2(t, h, o, v, c) \
427 __abs_set(sm,2,u_int16_t,(t),(h),(o),(v),(c))
428 #define bus_space_set_multi_4(t, h, o, v, c) \
429 __abs_set(sm,4,u_int32_t,(t),(h),(o),(v),(c))
430 #define bus_space_set_multi_8(t, h, o, v, c) \
431 __abs_set(sm,8,u_int64_t,(t),(h),(o),(v),(c))
435 * Set region operations.
437 #define bus_space_set_region_1(t, h, o, v, c) \
438 __abs_set(sr,1,u_int8_t,(t),(h),(o),(v),(c))
439 #define bus_space_set_region_2(t, h, o, v, c) \
440 __abs_set(sr,2,u_int16_t,(t),(h),(o),(v),(c))
441 #define bus_space_set_region_4(t, h, o, v, c) \
442 __abs_set(sr,4,u_int32_t,(t),(h),(o),(v),(c))
443 #define bus_space_set_region_8(t, h, o, v, c) \
444 __abs_set(sr,8,u_int64_t,(t),(h),(o),(v),(c))
448 * Copy region operations.
450 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \
451 __abs_copy(1, u_int8_t, (t), (h1), (o1), (h2), (o2), (c))
452 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \
453 __abs_copy(2, u_int16_t, (t), (h1), (o1), (h2), (o2), (c))
454 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \
455 __abs_copy(4, u_int32_t, (t), (h1), (o1), (h2), (o2), (c))
456 #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \
457 __abs_copy(8, u_int64_t, (t), (h1), (o1), (h2), (o2), (c))
460 * Bus stream operations--defined in terms of non-stream counterparts
462 #define __BUS_SPACE_HAS_STREAM_METHODS 1
463 #define bus_space_read_stream_1 bus_space_read_1
464 #define bus_space_read_stream_2 bus_space_read_2
465 #define bus_space_read_stream_4 bus_space_read_4
466 #define bus_space_read_stream_8 bus_space_read_8
467 #define bus_space_read_multi_stream_1 bus_space_read_multi_1
468 #define bus_space_read_multi_stream_2 bus_space_read_multi_2
469 #define bus_space_read_multi_stream_4 bus_space_read_multi_4
470 #define bus_space_read_multi_stream_8 bus_space_read_multi_8
471 #define bus_space_read_region_stream_1 bus_space_read_region_1
472 #define bus_space_read_region_stream_2 bus_space_read_region_2
473 #define bus_space_read_region_stream_4 bus_space_read_region_4
474 #define bus_space_read_region_stream_8 bus_space_read_region_8
475 #define bus_space_write_stream_1 bus_space_write_1
476 #define bus_space_write_stream_2 bus_space_write_2
477 #define bus_space_write_stream_4 bus_space_write_4
478 #define bus_space_write_stream_8 bus_space_write_8
479 #define bus_space_write_multi_stream_1 bus_space_write_multi_1
480 #define bus_space_write_multi_stream_2 bus_space_write_multi_2
481 #define bus_space_write_multi_stream_4 bus_space_write_multi_4
482 #define bus_space_write_multi_stream_8 bus_space_write_multi_8
483 #define bus_space_write_region_stream_1 bus_space_write_region_1
484 #define bus_space_write_region_stream_2 bus_space_write_region_2
485 #define bus_space_write_region_stream_4 bus_space_write_region_4
486 #define bus_space_write_region_stream_8 bus_space_write_region_8
494 * Flags used in various bus DMA methods.
496 #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
497 #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
498 #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
499 #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
500 #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
501 #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
502 #define BUS_DMA_BUS2 0x020
503 #define BUS_DMA_BUS3 0x040
504 #define BUS_DMA_BUS4 0x080
505 #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
506 #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
507 #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
510 * Private flags stored in the DMA map.
512 #define DMAMAP_NO_COALESCE 0x40000000 /* don't coalesce adjacent
515 /* Forwards needed by prototypes below. */
521 * Operations performed by bus_dmamap_sync().
523 #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
524 #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
525 #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
526 #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
531 * Busses supported by NetBSD/alpha, used by internal
532 * utility functions. NOT TO BE USED BY MACHINE-INDEPENDENT
536 ALPHA_BUS_TURBOCHANNEL
,
543 typedef struct alpha_bus_dma_tag
*bus_dma_tag_t
;
544 typedef struct alpha_bus_dmamap
*bus_dmamap_t
;
546 #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
551 * Describes a single contiguous DMA transaction. Values
552 * are suitable for programming into DMA registers.
554 struct alpha_bus_dma_segment
{
555 bus_addr_t ds_addr
; /* DMA address */
556 bus_size_t ds_len
; /* length of transfer */
558 typedef struct alpha_bus_dma_segment bus_dma_segment_t
;
563 * A machine-dependent opaque type describing the implementation of
564 * DMA for a given bus.
566 struct alpha_bus_dma_tag
{
567 void *_cookie
; /* cookie used in the guts */
568 bus_addr_t _wbase
; /* DMA window base */
571 * The following two members are used to chain DMA windows
572 * together. If, during the course of a map load, the
573 * resulting physical memory address is too large to
574 * be addressed by the window, the next window will be
575 * attempted. These would be chained together like so:
577 * direct -> sgmap -> NULL
583 * If the window size is 0, it will not be checked (e.g.
587 struct alpha_bus_dma_tag
*_next_window
;
590 * Some chipsets have a built-in boundary constraint, independent
591 * of what the device requests. This allows that boundary to
592 * be specified. If the device has a more restrictive constraint,
593 * the map will use that, otherwise this boundary will be used.
594 * This value is ignored if 0.
596 bus_size_t _boundary
;
599 * A chipset may have more than one SGMAP window, so SGMAP
600 * windows also get a pointer to their SGMAP state.
602 struct alpha_sgmap
*_sgmap
;
605 * The SGMAP MMU implements a prefetch FIFO to keep data
606 * moving down the pipe, when doing host->bus DMA writes.
607 * The threshold (distance until the next page) used to
608 * trigger the prefetch is differnet on different chipsets,
609 * and we need to know what it is in order to know whether
610 * or not to allocate a spill page.
612 bus_size_t _pfthresh
;
615 * Internal-use only utility methods. NOT TO BE USED BY
616 * MACHINE-INDEPENDENT CODE!
618 bus_dma_tag_t (*_get_tag
)(bus_dma_tag_t
, alpha_bus_t
);
621 * DMA mapping methods.
623 int (*_dmamap_create
)(bus_dma_tag_t
, bus_size_t
, int,
624 bus_size_t
, bus_size_t
, int, bus_dmamap_t
*);
625 void (*_dmamap_destroy
)(bus_dma_tag_t
, bus_dmamap_t
);
626 int (*_dmamap_load
)(bus_dma_tag_t
, bus_dmamap_t
, void *,
627 bus_size_t
, struct proc
*, int);
628 int (*_dmamap_load_mbuf
)(bus_dma_tag_t
, bus_dmamap_t
,
630 int (*_dmamap_load_uio
)(bus_dma_tag_t
, bus_dmamap_t
,
632 int (*_dmamap_load_raw
)(bus_dma_tag_t
, bus_dmamap_t
,
633 bus_dma_segment_t
*, int, bus_size_t
, int);
634 void (*_dmamap_unload
)(bus_dma_tag_t
, bus_dmamap_t
);
635 void (*_dmamap_sync
)(bus_dma_tag_t
, bus_dmamap_t
,
636 bus_addr_t
, bus_size_t
, int);
639 * DMA memory utility functions.
641 int (*_dmamem_alloc
)(bus_dma_tag_t
, bus_size_t
, bus_size_t
,
642 bus_size_t
, bus_dma_segment_t
*, int, int *, int);
643 void (*_dmamem_free
)(bus_dma_tag_t
,
644 bus_dma_segment_t
*, int);
645 int (*_dmamem_map
)(bus_dma_tag_t
, bus_dma_segment_t
*,
646 int, size_t, void **, int);
647 void (*_dmamem_unmap
)(bus_dma_tag_t
, void *, size_t);
648 paddr_t (*_dmamem_mmap
)(bus_dma_tag_t
, bus_dma_segment_t
*,
649 int, off_t
, int, int);
652 #define alphabus_dma_get_tag(t, b) \
653 (*(t)->_get_tag)(t, b)
655 #define bus_dmamap_create(t, s, n, m, b, f, p) \
656 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
657 #define bus_dmamap_destroy(t, p) \
658 (*(t)->_dmamap_destroy)((t), (p))
659 #define bus_dmamap_load(t, m, b, s, p, f) \
660 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
661 #define bus_dmamap_load_mbuf(t, m, b, f) \
662 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
663 #define bus_dmamap_load_uio(t, m, u, f) \
664 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
665 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
666 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
667 #define bus_dmamap_unload(t, p) \
669 (*(p)->_dm_window->_dmamap_unload)((p)->_dm_window, (p))
670 #define bus_dmamap_sync(t, p, o, l, ops) \
672 (*(p)->_dm_window->_dmamap_sync)((p)->_dm_window, (p), (o), (l), (ops))
673 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
674 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
675 #define bus_dmamem_free(t, sg, n) \
676 (*(t)->_dmamem_free)((t), (sg), (n))
677 #define bus_dmamem_map(t, sg, n, s, k, f) \
678 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
679 #define bus_dmamem_unmap(t, k, s) \
680 (*(t)->_dmamem_unmap)((t), (k), (s))
681 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
682 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
684 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
685 #define bus_dmatag_destroy(t)
690 * Describes a DMA mapping.
692 struct alpha_bus_dmamap
{
694 * PRIVATE MEMBERS: not for use my machine-independent code.
696 bus_size_t _dm_size
; /* largest DMA transfer mappable */
697 int _dm_segcnt
; /* number of segs this map can map */
698 bus_size_t _dm_maxmaxsegsz
; /* fixed largest possible segment */
699 bus_size_t _dm_boundary
; /* don't cross this */
700 int _dm_flags
; /* misc. flags */
703 * Private cookie to be used by the DMA back-end.
708 * The DMA window that we ended up being mapped in.
710 bus_dma_tag_t _dm_window
;
713 * PUBLIC MEMBERS: these are used by machine-independent code.
715 bus_size_t dm_maxsegsz
; /* largest possible segment */
716 bus_size_t dm_mapsize
; /* size of the mapping */
717 int dm_nsegs
; /* # valid segments in mapping */
718 bus_dma_segment_t dm_segs
[1]; /* segments; variable length */
721 #ifdef _ALPHA_BUS_DMA_PRIVATE
722 int _bus_dmamap_create(bus_dma_tag_t
, bus_size_t
, int, bus_size_t
,
723 bus_size_t
, int, bus_dmamap_t
*);
724 void _bus_dmamap_destroy(bus_dma_tag_t
, bus_dmamap_t
);
726 int _bus_dmamap_load_direct(bus_dma_tag_t
, bus_dmamap_t
,
727 void *, bus_size_t
, struct proc
*, int);
728 int _bus_dmamap_load_mbuf_direct(bus_dma_tag_t
,
729 bus_dmamap_t
, struct mbuf
*, int);
730 int _bus_dmamap_load_uio_direct(bus_dma_tag_t
,
731 bus_dmamap_t
, struct uio
*, int);
732 int _bus_dmamap_load_raw_direct(bus_dma_tag_t
,
733 bus_dmamap_t
, bus_dma_segment_t
*, int, bus_size_t
, int);
735 void _bus_dmamap_unload(bus_dma_tag_t
, bus_dmamap_t
);
736 void _bus_dmamap_sync(bus_dma_tag_t
, bus_dmamap_t
, bus_addr_t
,
739 int _bus_dmamem_alloc(bus_dma_tag_t tag
, bus_size_t size
,
740 bus_size_t alignment
, bus_size_t boundary
,
741 bus_dma_segment_t
*segs
, int nsegs
, int *rsegs
, int flags
);
742 int _bus_dmamem_alloc_range(bus_dma_tag_t tag
, bus_size_t size
,
743 bus_size_t alignment
, bus_size_t boundary
,
744 bus_dma_segment_t
*segs
, int nsegs
, int *rsegs
, int flags
,
745 paddr_t low
, paddr_t high
);
746 void _bus_dmamem_free(bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
748 int _bus_dmamem_map(bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
749 int nsegs
, size_t size
, void **kvap
, int flags
);
750 void _bus_dmamem_unmap(bus_dma_tag_t tag
, void *kva
,
752 paddr_t
_bus_dmamem_mmap(bus_dma_tag_t tag
, bus_dma_segment_t
*segs
,
753 int nsegs
, off_t off
, int prot
, int flags
);
754 #endif /* _ALPHA_BUS_DMA_PRIVATE */
758 #endif /* _ALPHA_BUS_H_ */