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