bus.h revision 1.5 1 1.5 christos /* $NetBSD: bus.h,v 1.5 2021/01/23 19:38:07 christos Exp $ */
2 1.1 pooka
3 1.1 pooka /*-
4 1.1 pooka * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
5 1.1 pooka * All rights reserved.
6 1.1 pooka *
7 1.1 pooka * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pooka * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 pooka * NASA Ames Research Center.
10 1.1 pooka *
11 1.1 pooka * Redistribution and use in source and binary forms, with or without
12 1.1 pooka * modification, are permitted provided that the following conditions
13 1.1 pooka * are met:
14 1.1 pooka * 1. Redistributions of source code must retain the above copyright
15 1.1 pooka * notice, this list of conditions and the following disclaimer.
16 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 pooka * notice, this list of conditions and the following disclaimer in the
18 1.1 pooka * documentation and/or other materials provided with the distribution.
19 1.1 pooka *
20 1.1 pooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 pooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 pooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 pooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 pooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 pooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 pooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 pooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 pooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 pooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 pooka * POSSIBILITY OF SUCH DAMAGE.
31 1.1 pooka */
32 1.1 pooka
33 1.1 pooka #ifndef _EMIPS_BUS_H_
34 1.1 pooka #define _EMIPS_BUS_H_
35 1.1 pooka
36 1.1 pooka #include <mips/locore.h>
37 1.1 pooka
38 1.1 pooka /*
39 1.1 pooka * Utility macros; do not use outside this file.
40 1.1 pooka */
41 1.1 pooka #define __PB_TYPENAME_PREFIX(BITS) ___CONCAT(u_int,BITS)
42 1.1 pooka #define __PB_TYPENAME(BITS) ___CONCAT(__PB_TYPENAME_PREFIX(BITS),_t)
43 1.1 pooka
44 1.1 pooka /*
45 1.1 pooka * Bus address and size types
46 1.1 pooka */
47 1.1 pooka typedef u_long bus_addr_t;
48 1.1 pooka typedef u_long bus_size_t;
49 1.1 pooka
50 1.3 skrll #define PRIxBUSADDR "lx"
51 1.3 skrll #define PRIxBUSSIZE "lx"
52 1.3 skrll #define PRIuBUSSIZE "lu"
53 1.1 pooka /*
54 1.1 pooka * Access methods for bus resources and address space.
55 1.1 pooka */
56 1.1 pooka typedef int bus_space_tag_t;
57 1.1 pooka typedef u_long bus_space_handle_t;
58 1.1 pooka
59 1.3 skrll #define PRIxBSH "lx"
60 1.3 skrll
61 1.1 pooka /*
62 1.1 pooka * int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
63 1.1 pooka * bus_size_t size, int flags, bus_space_handle_t *bshp);
64 1.1 pooka *
65 1.1 pooka * Map a region of bus space.
66 1.1 pooka */
67 1.1 pooka
68 1.1 pooka #define BUS_SPACE_MAP_CACHEABLE 0x01
69 1.1 pooka #define BUS_SPACE_MAP_LINEAR 0x02
70 1.1 pooka #define BUS_SPACE_MAP_PREFETCHABLE 0x04
71 1.1 pooka
72 1.1 pooka int bus_space_map(bus_space_tag_t, bus_addr_t, bus_size_t,
73 1.1 pooka int, bus_space_handle_t *);
74 1.1 pooka
75 1.1 pooka /*
76 1.1 pooka * void bus_space_unmap(bus_space_tag_t t,
77 1.1 pooka * bus_space_handle_t bsh, bus_size_t size);
78 1.1 pooka *
79 1.1 pooka * Unmap a region of bus space.
80 1.1 pooka */
81 1.1 pooka
82 1.1 pooka void bus_space_unmap(bus_space_tag_t, bus_space_handle_t, bus_size_t);
83 1.1 pooka
84 1.1 pooka /*
85 1.1 pooka * int bus_space_subregion(bus_space_tag_t t,
86 1.1 pooka * bus_space_handle_t bsh, bus_size_t offset, bus_size_t size,
87 1.1 pooka * bus_space_handle_t *nbshp);
88 1.1 pooka *
89 1.1 pooka * Get a new handle for a subregion of an already-mapped area of bus space.
90 1.1 pooka */
91 1.1 pooka
92 1.1 pooka int bus_space_subregion(bus_space_tag_t t, bus_space_handle_t bsh,
93 1.1 pooka bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp);
94 1.1 pooka
95 1.1 pooka /*
96 1.1 pooka * int bus_space_alloc(bus_space_tag_t t, bus_addr_t, rstart,
97 1.1 pooka * bus_addr_t rend, bus_size_t size, bus_size_t align,
98 1.1 pooka * bus_size_t boundary, int flags, bus_addr_t *addrp,
99 1.1 pooka * bus_space_handle_t *bshp);
100 1.1 pooka *
101 1.1 pooka * Allocate a region of bus space.
102 1.1 pooka */
103 1.1 pooka
104 1.1 pooka int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
105 1.1 pooka bus_addr_t rend, bus_size_t size, bus_size_t align,
106 1.1 pooka bus_size_t boundary, int cacheable, bus_addr_t *addrp,
107 1.1 pooka bus_space_handle_t *bshp);
108 1.1 pooka
109 1.1 pooka /*
110 1.1 pooka * int bus_space_free(bus_space_tag_t t,
111 1.1 pooka * bus_space_handle_t bsh, bus_size_t size);
112 1.1 pooka *
113 1.1 pooka * Free a region of bus space.
114 1.1 pooka */
115 1.1 pooka
116 1.1 pooka void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
117 1.1 pooka bus_size_t size);
118 1.1 pooka
119 1.1 pooka /*
120 1.1 pooka * void *bus_space_vaddr(bus_space_tag_t, bus_space_handle_t);
121 1.1 pooka *
122 1.1 pooka * Get the kernel virtual address for the mapped bus space.
123 1.1 pooka * Only allowed for regions mapped with BUS_SPACE_MAP_LINEAR.
124 1.1 pooka * (XXX not enforced)
125 1.1 pooka */
126 1.1 pooka #define bus_space_vaddr(t, h) \
127 1.1 pooka ((void *)(h))
128 1.1 pooka
129 1.1 pooka /*
130 1.1 pooka * u_intN_t bus_space_read_N(bus_space_tag_t tag,
131 1.1 pooka * bus_space_handle_t bsh, bus_size_t offset);
132 1.1 pooka *
133 1.1 pooka * Read a 1, 2, 4, or 8 byte quantity from bus space
134 1.1 pooka * described by tag/handle/offset.
135 1.1 pooka */
136 1.1 pooka
137 1.1 pooka #define bus_space_read_1(t, h, o) \
138 1.1 pooka ((void) t, (*(volatile u_int8_t *)((h) + (o))))
139 1.1 pooka
140 1.1 pooka #define bus_space_read_2(t, h, o) \
141 1.1 pooka ((void) t, (*(volatile u_int16_t *)((h) + (o))))
142 1.1 pooka
143 1.1 pooka #define bus_space_read_4(t, h, o) \
144 1.1 pooka ((void) t, (*(volatile u_int32_t *)((h) + (o))))
145 1.1 pooka
146 1.1 pooka /*
147 1.1 pooka * void bus_space_read_multi_N(bus_space_tag_t tag,
148 1.1 pooka * bus_space_handle_t bsh, bus_size_t offset,
149 1.1 pooka * u_intN_t *addr, size_t count);
150 1.1 pooka *
151 1.1 pooka * Read `count' 1, 2, 4, or 8 byte quantities from bus space
152 1.1 pooka * described by tag/handle/offset and copy into buffer provided.
153 1.1 pooka */
154 1.1 pooka
155 1.2 matt #define __EMIPS_bus_space_read_multi(BYTES,BITS) \
156 1.1 pooka static __inline void __CONCAT(bus_space_read_multi_,BYTES) \
157 1.2 matt (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
158 1.2 matt __PB_TYPENAME(BITS) *, size_t); \
159 1.1 pooka \
160 1.1 pooka static __inline void \
161 1.2 matt __CONCAT(bus_space_read_multi_,BYTES)( \
162 1.2 matt bus_space_tag_t t, \
163 1.2 matt bus_space_handle_t h, \
164 1.2 matt bus_size_t o, \
165 1.2 matt __PB_TYPENAME(BITS) *a, \
166 1.2 matt size_t c) \
167 1.1 pooka { \
168 1.1 pooka \
169 1.1 pooka while (c--) \
170 1.1 pooka *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o); \
171 1.1 pooka }
172 1.1 pooka
173 1.1 pooka __EMIPS_bus_space_read_multi(1,8)
174 1.1 pooka __EMIPS_bus_space_read_multi(2,16)
175 1.1 pooka __EMIPS_bus_space_read_multi(4,32)
176 1.1 pooka
177 1.1 pooka #undef __EMIPS_bus_space_read_multi
178 1.1 pooka
179 1.1 pooka /*
180 1.1 pooka * void bus_space_read_region_N(bus_space_tag_t tag,
181 1.1 pooka * bus_space_handle_t bsh, bus_size_t offset,
182 1.1 pooka * u_intN_t *addr, size_t count);
183 1.1 pooka *
184 1.1 pooka * Read `count' 1, 2, 4, or 8 byte quantities from bus space
185 1.1 pooka * described by tag/handle and starting at `offset' and copy into
186 1.1 pooka * buffer provided.
187 1.1 pooka */
188 1.1 pooka
189 1.1 pooka #define __EMIPS_bus_space_read_region(BYTES,BITS) \
190 1.1 pooka static __inline void __CONCAT(bus_space_read_region_,BYTES) \
191 1.2 matt (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
192 1.2 matt __PB_TYPENAME(BITS) *, size_t); \
193 1.1 pooka \
194 1.1 pooka static __inline void \
195 1.2 matt __CONCAT(bus_space_read_region_,BYTES)( \
196 1.2 matt bus_space_tag_t t, \
197 1.2 matt bus_space_handle_t h, \
198 1.2 matt bus_size_t o, \
199 1.2 matt __PB_TYPENAME(BITS) *a, \
200 1.2 matt size_t c) \
201 1.1 pooka { \
202 1.1 pooka \
203 1.1 pooka while (c--) { \
204 1.1 pooka *a++ = __CONCAT(bus_space_read_,BYTES)(t, h, o); \
205 1.1 pooka o += BYTES; \
206 1.1 pooka } \
207 1.1 pooka }
208 1.1 pooka
209 1.1 pooka __EMIPS_bus_space_read_region(1,8)
210 1.1 pooka __EMIPS_bus_space_read_region(2,16)
211 1.1 pooka __EMIPS_bus_space_read_region(4,32)
212 1.1 pooka
213 1.1 pooka #undef __EMIPS_bus_space_read_region
214 1.1 pooka
215 1.1 pooka /*
216 1.1 pooka * void bus_space_write_N(bus_space_tag_t tag,
217 1.1 pooka * bus_space_handle_t bsh, bus_size_t offset,
218 1.1 pooka * u_intN_t value);
219 1.1 pooka *
220 1.1 pooka * Write the 1, 2, 4, or 8 byte value `value' to bus space
221 1.1 pooka * described by tag/handle/offset.
222 1.1 pooka */
223 1.1 pooka
224 1.1 pooka #define bus_space_write_1(t, h, o, v) \
225 1.1 pooka do { \
226 1.1 pooka (void) t; \
227 1.1 pooka *(volatile u_int8_t *)((h) + (o)) = (v); \
228 1.1 pooka wbflush(); /* XXX */ \
229 1.1 pooka } while (0)
230 1.1 pooka
231 1.1 pooka #define bus_space_write_2(t, h, o, v) \
232 1.1 pooka do { \
233 1.1 pooka (void) t; \
234 1.1 pooka *(volatile u_int16_t *)((h) + (o)) = (v); \
235 1.1 pooka wbflush(); /* XXX */ \
236 1.1 pooka } while (0)
237 1.1 pooka
238 1.1 pooka #define bus_space_write_4(t, h, o, v) \
239 1.1 pooka do { \
240 1.1 pooka (void) t; \
241 1.1 pooka *(volatile u_int32_t *)((h) + (o)) = (v); \
242 1.1 pooka wbflush(); /* XXX */ \
243 1.1 pooka } while (0)
244 1.1 pooka
245 1.1 pooka /*
246 1.1 pooka * void bus_space_write_multi_N(bus_space_tag_t tag,
247 1.1 pooka * bus_space_handle_t bsh, bus_size_t offset,
248 1.1 pooka * const u_intN_t *addr, size_t count);
249 1.1 pooka *
250 1.1 pooka * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
251 1.1 pooka * provided to bus space described by tag/handle/offset.
252 1.1 pooka */
253 1.1 pooka
254 1.1 pooka #define __EMIPS_bus_space_write_multi(BYTES,BITS) \
255 1.1 pooka static __inline void __CONCAT(bus_space_write_multi_,BYTES) \
256 1.2 matt (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
257 1.2 matt __PB_TYPENAME(BITS) *, size_t); \
258 1.1 pooka \
259 1.1 pooka static __inline void \
260 1.2 matt __CONCAT(bus_space_write_multi_,BYTES)( \
261 1.2 matt bus_space_tag_t t, \
262 1.2 matt bus_space_handle_t h, \
263 1.2 matt bus_size_t o, \
264 1.2 matt __PB_TYPENAME(BITS) *a, \
265 1.2 matt size_t c) \
266 1.1 pooka { \
267 1.1 pooka \
268 1.1 pooka while (c--) \
269 1.1 pooka __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++); \
270 1.1 pooka }
271 1.1 pooka
272 1.1 pooka __EMIPS_bus_space_write_multi(1,8)
273 1.1 pooka __EMIPS_bus_space_write_multi(2,16)
274 1.1 pooka __EMIPS_bus_space_write_multi(4,32)
275 1.1 pooka
276 1.1 pooka #undef __EMIPS_bus_space_write_multi
277 1.1 pooka
278 1.1 pooka /*
279 1.1 pooka * void bus_space_write_region_N(bus_space_tag_t tag,
280 1.1 pooka * bus_space_handle_t bsh, bus_size_t offset,
281 1.1 pooka * const u_intN_t *addr, size_t count);
282 1.1 pooka *
283 1.1 pooka * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
284 1.1 pooka * to bus space described by tag/handle starting at `offset'.
285 1.1 pooka */
286 1.1 pooka
287 1.1 pooka #define __EMIPS_bus_space_write_region(BYTES,BITS) \
288 1.1 pooka static __inline void __CONCAT(bus_space_write_region_,BYTES) \
289 1.2 matt (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
290 1.2 matt __PB_TYPENAME(BITS) *, size_t); \
291 1.1 pooka \
292 1.1 pooka static __inline void \
293 1.2 matt __CONCAT(bus_space_write_region_,BYTES)( \
294 1.2 matt bus_space_tag_t t, \
295 1.2 matt bus_space_handle_t h, \
296 1.2 matt bus_size_t o, \
297 1.2 matt __PB_TYPENAME(BITS) *a, \
298 1.2 matt size_t c) \
299 1.1 pooka { \
300 1.1 pooka \
301 1.1 pooka while (c--) { \
302 1.1 pooka __CONCAT(bus_space_write_,BYTES)(t, h, o, *a++); \
303 1.1 pooka o += BYTES; \
304 1.1 pooka } \
305 1.1 pooka }
306 1.1 pooka
307 1.1 pooka __EMIPS_bus_space_write_region(1,8)
308 1.1 pooka __EMIPS_bus_space_write_region(2,16)
309 1.1 pooka __EMIPS_bus_space_write_region(4,32)
310 1.1 pooka
311 1.1 pooka #undef __EMIPS_bus_space_write_region
312 1.1 pooka
313 1.1 pooka /*
314 1.1 pooka * void bus_space_set_multi_N(bus_space_tag_t tag,
315 1.1 pooka * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
316 1.1 pooka * size_t count);
317 1.1 pooka *
318 1.1 pooka * Write the 1, 2, 4, or 8 byte value `val' to bus space described
319 1.1 pooka * by tag/handle/offset `count' times.
320 1.1 pooka */
321 1.1 pooka
322 1.1 pooka #define __EMIPS_bus_space_set_multi(BYTES,BITS) \
323 1.1 pooka static __inline void __CONCAT(bus_space_set_multi_,BYTES) \
324 1.2 matt (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
325 1.1 pooka __PB_TYPENAME(BITS), size_t); \
326 1.1 pooka \
327 1.1 pooka static __inline void \
328 1.2 matt __CONCAT(bus_space_set_multi_,BYTES)( \
329 1.2 matt bus_space_tag_t t, \
330 1.2 matt bus_space_handle_t h, \
331 1.2 matt bus_size_t o, \
332 1.2 matt __PB_TYPENAME(BITS) v, \
333 1.2 matt size_t c) \
334 1.1 pooka { \
335 1.1 pooka \
336 1.1 pooka while (c--) \
337 1.1 pooka __CONCAT(bus_space_write_,BYTES)(t, h, o, v); \
338 1.1 pooka }
339 1.1 pooka
340 1.1 pooka __EMIPS_bus_space_set_multi(1,8)
341 1.1 pooka __EMIPS_bus_space_set_multi(2,16)
342 1.1 pooka __EMIPS_bus_space_set_multi(4,32)
343 1.1 pooka
344 1.1 pooka #undef __EMIPS_bus_space_set_multi
345 1.1 pooka
346 1.1 pooka /*
347 1.1 pooka * void bus_space_set_region_N(bus_space_tag_t tag,
348 1.1 pooka * bus_space_handle_t bsh, bus_size_t offset, u_intN_t val,
349 1.1 pooka * size_t count);
350 1.1 pooka *
351 1.1 pooka * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
352 1.1 pooka * by tag/handle starting at `offset'.
353 1.1 pooka */
354 1.1 pooka
355 1.2 matt #define __EMIPS_bus_space_set_region(BYTES,BITS) \
356 1.1 pooka static __inline void __CONCAT(bus_space_set_region_,BYTES) \
357 1.2 matt (bus_space_tag_t, bus_space_handle_t, bus_size_t, \
358 1.1 pooka __PB_TYPENAME(BITS), size_t); \
359 1.1 pooka \
360 1.1 pooka static __inline void \
361 1.2 matt __CONCAT(bus_space_set_region_,BYTES)( \
362 1.2 matt bus_space_tag_t t, \
363 1.2 matt bus_space_handle_t h, \
364 1.2 matt bus_size_t o, \
365 1.2 matt __PB_TYPENAME(BITS) v, \
366 1.2 matt size_t c) \
367 1.1 pooka { \
368 1.1 pooka \
369 1.1 pooka while (c--) { \
370 1.1 pooka __CONCAT(bus_space_write_,BYTES)(t, h, o, v); \
371 1.1 pooka o += BYTES; \
372 1.1 pooka } \
373 1.1 pooka }
374 1.1 pooka
375 1.1 pooka __EMIPS_bus_space_set_region(1,8)
376 1.1 pooka __EMIPS_bus_space_set_region(2,16)
377 1.1 pooka __EMIPS_bus_space_set_region(4,32)
378 1.1 pooka
379 1.1 pooka #undef __EMIPS_bus_space_set_region
380 1.1 pooka
381 1.1 pooka /*
382 1.1 pooka * void bus_space_copy_region_N(bus_space_tag_t tag,
383 1.1 pooka * bus_space_handle_t bsh1, bus_size_t off1,
384 1.1 pooka * bus_space_handle_t bsh2, bus_size_t off2,
385 1.1 pooka * bus_size_t count);
386 1.1 pooka *
387 1.1 pooka * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
388 1.1 pooka * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
389 1.1 pooka */
390 1.1 pooka
391 1.1 pooka #define __EMIPS_copy_region(BYTES) \
392 1.1 pooka static __inline void __CONCAT(bus_space_copy_region_,BYTES) \
393 1.2 matt (bus_space_tag_t, \
394 1.1 pooka bus_space_handle_t bsh1, bus_size_t off1, \
395 1.1 pooka bus_space_handle_t bsh2, bus_size_t off2, \
396 1.1 pooka bus_size_t count); \
397 1.1 pooka \
398 1.1 pooka static __inline void \
399 1.2 matt __CONCAT(bus_space_copy_region_,BYTES)( \
400 1.2 matt bus_space_tag_t t, \
401 1.2 matt bus_space_handle_t h1, \
402 1.2 matt bus_size_t o1, \
403 1.2 matt bus_space_handle_t h2, \
404 1.2 matt bus_size_t o2, \
405 1.2 matt bus_size_t c) \
406 1.1 pooka { \
407 1.1 pooka bus_size_t o; \
408 1.1 pooka \
409 1.1 pooka if ((h1 + o1) >= (h2 + o2)) { \
410 1.1 pooka /* src after dest: copy forward */ \
411 1.1 pooka for (o = 0; c != 0; c--, o += BYTES) \
412 1.1 pooka __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
413 1.1 pooka __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
414 1.1 pooka } else { \
415 1.1 pooka /* dest after src: copy backwards */ \
416 1.1 pooka for (o = (c - 1) * BYTES; c != 0; c--, o -= BYTES) \
417 1.1 pooka __CONCAT(bus_space_write_,BYTES)(t, h2, o2 + o, \
418 1.1 pooka __CONCAT(bus_space_read_,BYTES)(t, h1, o1 + o)); \
419 1.1 pooka } \
420 1.1 pooka }
421 1.1 pooka
422 1.1 pooka __EMIPS_copy_region(1)
423 1.1 pooka __EMIPS_copy_region(2)
424 1.1 pooka __EMIPS_copy_region(4)
425 1.1 pooka
426 1.1 pooka #undef __EMIPS_copy_region
427 1.1 pooka
428 1.1 pooka /*
429 1.1 pooka * Bus read/write barrier methods.
430 1.1 pooka *
431 1.1 pooka * void bus_space_barrier(bus_space_tag_t tag,
432 1.1 pooka * bus_space_handle_t bsh, bus_size_t offset,
433 1.1 pooka * bus_size_t len, int flags);
434 1.1 pooka *
435 1.1 pooka * On the MIPS, we just flush the write buffer.
436 1.1 pooka */
437 1.1 pooka #define bus_space_barrier(t, h, o, l, f) \
438 1.1 pooka ((void)((void)(t), (void)(h), (void)(o), (void)(l), (void)(f), \
439 1.1 pooka wbflush()))
440 1.1 pooka #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
441 1.1 pooka #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
442 1.1 pooka
443 1.1 pooka #undef __PB_TYPENAME_PREFIX
444 1.1 pooka #undef __PB_TYPENAME
445 1.1 pooka
446 1.1 pooka #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
447 1.1 pooka
448 1.1 pooka /*
449 1.1 pooka * Flags used in various bus DMA methods.
450 1.1 pooka */
451 1.1 pooka #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
452 1.1 pooka #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
453 1.1 pooka #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
454 1.1 pooka #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
455 1.1 pooka #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
456 1.1 pooka #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
457 1.1 pooka #define BUS_DMA_BUS2 0x020
458 1.1 pooka #define BUS_DMA_BUS3 0x040
459 1.1 pooka #define BUS_DMA_BUS4 0x080
460 1.1 pooka #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
461 1.1 pooka #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
462 1.1 pooka #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
463 1.1 pooka
464 1.1 pooka #define EMIPS_DMAMAP_COHERENT 0x10000 /* no cache flush necessary on sync */
465 1.1 pooka
466 1.1 pooka /* Forwards needed by prototypes below. */
467 1.1 pooka struct mbuf;
468 1.1 pooka struct uio;
469 1.1 pooka
470 1.1 pooka /*
471 1.1 pooka * Operations performed by bus_dmamap_sync().
472 1.1 pooka */
473 1.1 pooka #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
474 1.1 pooka #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
475 1.1 pooka #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
476 1.1 pooka #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
477 1.1 pooka
478 1.1 pooka typedef struct emips_bus_dma_tag *bus_dma_tag_t;
479 1.1 pooka typedef struct emips_bus_dmamap *bus_dmamap_t;
480 1.1 pooka
481 1.1 pooka #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
482 1.1 pooka
483 1.1 pooka /*
484 1.1 pooka * bus_dma_segment_t
485 1.1 pooka *
486 1.1 pooka * Describes a single contiguous DMA transaction. Values
487 1.1 pooka * are suitable for programming into DMA registers.
488 1.1 pooka */
489 1.1 pooka struct emips_bus_dma_segment {
490 1.1 pooka bus_addr_t ds_addr; /* DMA address */
491 1.1 pooka bus_size_t ds_len; /* length of transfer */
492 1.1 pooka bus_addr_t _ds_vaddr; /* virtual address, 0 if invalid */
493 1.1 pooka };
494 1.1 pooka typedef struct emips_bus_dma_segment bus_dma_segment_t;
495 1.1 pooka
496 1.1 pooka /*
497 1.1 pooka * bus_dma_tag_t
498 1.1 pooka *
499 1.1 pooka * A machine-dependent opaque type describing the implementation of
500 1.1 pooka * DMA for a given bus.
501 1.1 pooka */
502 1.1 pooka
503 1.1 pooka struct emips_bus_dma_tag {
504 1.1 pooka /*
505 1.1 pooka * DMA mapping methods.
506 1.1 pooka */
507 1.1 pooka int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
508 1.1 pooka bus_size_t, bus_size_t, int, bus_dmamap_t *);
509 1.1 pooka void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
510 1.1 pooka int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
511 1.1 pooka bus_size_t, struct proc *, int);
512 1.1 pooka int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
513 1.1 pooka struct mbuf *, int);
514 1.1 pooka int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
515 1.1 pooka struct uio *, int);
516 1.1 pooka int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
517 1.1 pooka bus_dma_segment_t *, int, bus_size_t, int);
518 1.1 pooka void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
519 1.1 pooka void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
520 1.1 pooka bus_addr_t, bus_size_t, int);
521 1.1 pooka
522 1.1 pooka /*
523 1.1 pooka * DMA memory utility functions.
524 1.1 pooka */
525 1.1 pooka int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
526 1.1 pooka bus_size_t, bus_dma_segment_t *, int, int *, int);
527 1.1 pooka void (*_dmamem_free)(bus_dma_tag_t,
528 1.1 pooka bus_dma_segment_t *, int);
529 1.1 pooka int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
530 1.1 pooka int, size_t, void **, int);
531 1.1 pooka void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
532 1.1 pooka paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
533 1.1 pooka int, off_t, int, int);
534 1.1 pooka };
535 1.1 pooka
536 1.1 pooka #define bus_dmamap_create(t, s, n, m, b, f, p) \
537 1.1 pooka (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
538 1.1 pooka #define bus_dmamap_destroy(t, p) \
539 1.1 pooka (*(t)->_dmamap_destroy)((t), (p))
540 1.1 pooka #define bus_dmamap_load(t, m, b, s, p, f) \
541 1.1 pooka (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
542 1.1 pooka #define bus_dmamap_load_mbuf(t, m, b, f) \
543 1.1 pooka (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
544 1.1 pooka #define bus_dmamap_load_uio(t, m, u, f) \
545 1.1 pooka (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
546 1.1 pooka #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
547 1.1 pooka (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
548 1.1 pooka #define bus_dmamap_unload(t, p) \
549 1.1 pooka (*(t)->_dmamap_unload)((t), (p))
550 1.1 pooka #define bus_dmamap_sync(t, p, o, l, ops) \
551 1.1 pooka (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops))
552 1.1 pooka
553 1.1 pooka #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
554 1.1 pooka (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
555 1.1 pooka #define bus_dmamem_free(t, sg, n) \
556 1.1 pooka (*(t)->_dmamem_free)((t), (sg), (n))
557 1.1 pooka #define bus_dmamem_map(t, sg, n, s, k, f) \
558 1.1 pooka (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
559 1.1 pooka #define bus_dmamem_unmap(t, k, s) \
560 1.1 pooka (*(t)->_dmamem_unmap)((t), (k), (s))
561 1.1 pooka #define bus_dmamem_mmap(t, sg, n, o, p, f) \
562 1.1 pooka (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
563 1.1 pooka
564 1.1 pooka #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
565 1.1 pooka #define bus_dmatag_destroy(t)
566 1.1 pooka
567 1.1 pooka /*
568 1.1 pooka * bus_dmamap_t
569 1.1 pooka *
570 1.1 pooka * Describes a DMA mapping.
571 1.1 pooka */
572 1.1 pooka struct emips_bus_dmamap {
573 1.1 pooka /*
574 1.1 pooka * PRIVATE MEMBERS: not for use my machine-independent code.
575 1.1 pooka */
576 1.1 pooka bus_size_t _dm_size; /* largest DMA transfer mappable */
577 1.1 pooka int _dm_segcnt; /* number of segs this map can map */
578 1.1 pooka bus_size_t _dm_maxmaxsegsz; /* fixed largest possible segment */
579 1.1 pooka bus_size_t _dm_boundary; /* don't cross this */
580 1.1 pooka int _dm_flags; /* misc. flags */
581 1.1 pooka struct vmspace *_dm_vmspace; /* vmspace that owns the mapping */
582 1.1 pooka
583 1.1 pooka /*
584 1.1 pooka * PUBLIC MEMBERS: these are used by machine-independent code.
585 1.1 pooka */
586 1.1 pooka bus_size_t dm_maxsegsz; /* largest possible segment */
587 1.1 pooka bus_size_t dm_mapsize; /* size of the mapping */
588 1.1 pooka int dm_nsegs; /* # valid segments in mapping */
589 1.1 pooka bus_dma_segment_t dm_segs[1]; /* segments; variable length */
590 1.1 pooka };
591 1.1 pooka
592 1.1 pooka #ifdef _EMIPS_BUS_DMA_PRIVATE
593 1.1 pooka void emips_bus_dma_init(void);
594 1.1 pooka
595 1.1 pooka int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
596 1.1 pooka bus_size_t, int, bus_dmamap_t *);
597 1.1 pooka void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
598 1.1 pooka int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
599 1.1 pooka bus_size_t, struct proc *, int);
600 1.1 pooka int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
601 1.1 pooka struct mbuf *, int);
602 1.1 pooka int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
603 1.1 pooka struct uio *, int);
604 1.1 pooka int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
605 1.1 pooka bus_dma_segment_t *, int, bus_size_t, int);
606 1.1 pooka void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
607 1.1 pooka void _bus_dmamap_sync_r3k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
608 1.1 pooka bus_size_t, int);
609 1.1 pooka void _bus_dmamap_sync_r4k(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
610 1.1 pooka bus_size_t, int);
611 1.1 pooka
612 1.1 pooka int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
613 1.1 pooka bus_size_t alignment, bus_size_t boundary,
614 1.1 pooka bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
615 1.1 pooka void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
616 1.1 pooka int nsegs);
617 1.1 pooka int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
618 1.1 pooka int nsegs, size_t size, void **kvap, int flags);
619 1.1 pooka void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
620 1.1 pooka size_t size);
621 1.1 pooka paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
622 1.1 pooka int nsegs, off_t off, int prot, int flags);
623 1.1 pooka
624 1.1 pooka int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
625 1.1 pooka bus_size_t alignment, bus_size_t boundary,
626 1.1 pooka bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
627 1.1 pooka vaddr_t low, vaddr_t high);
628 1.1 pooka
629 1.1 pooka extern struct emips_bus_dma_tag emips_default_bus_dma_tag;
630 1.1 pooka #endif /* _EMIPS_BUS_DMA_PRIVATE */
631 1.1 pooka
632 1.1 pooka #endif /* !_EMIPS_BUS_H_ */
633