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