bus.h revision 1.5 1 1.5 skrll /* $NetBSD: bus.h,v 1.5 2021/11/15 07:26:23 skrll Exp $ */
2 1.1 kiyohara
3 1.1 kiyohara /*-
4 1.1 kiyohara * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
5 1.1 kiyohara * All rights reserved.
6 1.1 kiyohara *
7 1.1 kiyohara * This code is derived from software contributed to The NetBSD Foundation
8 1.1 kiyohara * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 kiyohara * NASA Ames Research Center.
10 1.1 kiyohara *
11 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
12 1.1 kiyohara * modification, are permitted provided that the following conditions
13 1.1 kiyohara * are met:
14 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
15 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
16 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
18 1.1 kiyohara * documentation and/or other materials provided with the distribution.
19 1.1 kiyohara *
20 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 kiyohara * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 kiyohara * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 kiyohara * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 kiyohara * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 kiyohara * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 kiyohara * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 kiyohara * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 kiyohara * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 kiyohara * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 kiyohara * POSSIBILITY OF SUCH DAMAGE.
31 1.1 kiyohara */
32 1.1 kiyohara
33 1.1 kiyohara /*
34 1.1 kiyohara * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
35 1.1 kiyohara * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
36 1.1 kiyohara *
37 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
38 1.1 kiyohara * modification, are permitted provided that the following conditions
39 1.1 kiyohara * are met:
40 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
41 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
42 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
43 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
44 1.1 kiyohara * documentation and/or other materials provided with the distribution.
45 1.1 kiyohara * 3. All advertising materials mentioning features or use of this software
46 1.1 kiyohara * must display the following acknowledgement:
47 1.1 kiyohara * This product includes software developed by Christopher G. Demetriou
48 1.1 kiyohara * for the NetBSD Project.
49 1.1 kiyohara * 4. The name of the author may not be used to endorse or promote products
50 1.1 kiyohara * derived from this software without specific prior written permission
51 1.1 kiyohara *
52 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53 1.1 kiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54 1.1 kiyohara * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55 1.1 kiyohara * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56 1.1 kiyohara * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57 1.1 kiyohara * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 1.1 kiyohara * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 1.1 kiyohara * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 1.1 kiyohara * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61 1.1 kiyohara * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 1.1 kiyohara */
63 1.1 kiyohara
64 1.1 kiyohara #ifndef _IA64_BUS_H_
65 1.1 kiyohara #define _IA64_BUS_H_
66 1.1 kiyohara
67 1.1 kiyohara #include <sys/systm.h>
68 1.1 kiyohara
69 1.1 kiyohara #include <machine/cpufunc.h>
70 1.1 kiyohara #include <machine/vmparam.h>
71 1.1 kiyohara
72 1.1 kiyohara #ifdef BUS_SPACE_DEBUG
73 1.1 kiyohara /*
74 1.1 kiyohara * Macros for sanity-checking the aligned-ness of pointers passed to
75 1.1 kiyohara * bus space ops. These are not strictly necessary on the x86, but
76 1.1 kiyohara * could lead to performance improvements, and help catch problems
77 1.1 kiyohara * with drivers that would creep up on other architectures.
78 1.1 kiyohara */
79 1.1 kiyohara #define __BUS_SPACE_ALIGNED_ADDRESS(p, t) \
80 1.1 kiyohara ((((u_long)(p)) & (sizeof(t)-1)) == 0)
81 1.1 kiyohara
82 1.1 kiyohara #define __BUS_SPACE_ADDRESS_SANITY(p, t, d) \
83 1.1 kiyohara ({ \
84 1.1 kiyohara if (__BUS_SPACE_ALIGNED_ADDRESS((p), t) == 0) { \
85 1.1 kiyohara printf("%s 0x%lx not aligned to %d bytes %s:%d\n", \
86 1.1 kiyohara d, (u_long)(p), sizeof(t), __FILE__, __LINE__); \
87 1.1 kiyohara } \
88 1.1 kiyohara (void) 0; \
89 1.1 kiyohara })
90 1.1 kiyohara
91 1.1 kiyohara #define BUS_SPACE_ALIGNED_POINTER(p, t) __BUS_SPACE_ALIGNED_ADDRESS(p, t)
92 1.1 kiyohara #else
93 1.1 kiyohara #define __BUS_SPACE_ADDRESS_SANITY(p,t,d) (void) 0
94 1.1 kiyohara #define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
95 1.1 kiyohara #endif /* BUS_SPACE_DEBUG */
96 1.1 kiyohara
97 1.1 kiyohara /*
98 1.1 kiyohara * bus_space_map flags
99 1.1 kiyohara */
100 1.1 kiyohara
101 1.1 kiyohara #define BUS_SPACE_MAP_CACHEABLE 0x01
102 1.1 kiyohara #define BUS_SPACE_MAP_LINEAR 0x02
103 1.1 kiyohara #define BUS_SPACE_MAP_PREFETCHABLE 0x04
104 1.1 kiyohara
105 1.1 kiyohara /*
106 1.1 kiyohara * Derived from x86 implementation, ia64 has both i/o and mem spaces
107 1.1 kiyohara * These values are for bus space tag.
108 1.1 kiyohara */
109 1.1 kiyohara #define IA64_BUS_SPACE_IO 0 /* space is i/o space */
110 1.1 kiyohara #define IA64_BUS_SPACE_MEM 1 /* space is mem space */
111 1.1 kiyohara
112 1.1 kiyohara #define __BUS_SPACE_HAS_STREAM_METHODS 1
113 1.1 kiyohara
114 1.1 kiyohara /*
115 1.1 kiyohara * Bus address and size types
116 1.1 kiyohara */
117 1.1 kiyohara typedef u_long bus_addr_t;
118 1.1 kiyohara typedef u_long bus_size_t;
119 1.1 kiyohara
120 1.3 skrll #define PRIxBUSADDR "lx"
121 1.3 skrll #define PRIxBUSSIZE "lx"
122 1.3 skrll #define PRIuBUSSIZE "lu"
123 1.3 skrll
124 1.1 kiyohara /*
125 1.1 kiyohara * Access methods for bus resources and address space.
126 1.1 kiyohara */
127 1.1 kiyohara typedef int bus_space_tag_t;
128 1.1 kiyohara typedef u_long bus_space_handle_t;
129 1.1 kiyohara
130 1.3 skrll #define PRIxBSH "lx"
131 1.3 skrll
132 1.1 kiyohara /* map/unmap */
133 1.1 kiyohara
134 1.1 kiyohara int ia64_bus_space_map(bus_space_tag_t, bus_addr_t,
135 1.1 kiyohara bus_size_t, int, bus_space_handle_t *);
136 1.1 kiyohara void ia64_bus_space_unmap(bus_space_tag_t, bus_space_handle_t,
137 1.1 kiyohara bus_size_t);
138 1.1 kiyohara int ia64_bus_space_subregion(bus_space_tag_t, bus_space_handle_t,
139 1.1 kiyohara bus_size_t, bus_size_t, bus_space_handle_t *);
140 1.1 kiyohara #define bus_space_map(t, a, s, f, hp) \
141 1.1 kiyohara ia64_bus_space_map((t), (a), (s), (f), (hp))
142 1.1 kiyohara #define bus_space_unmap(t, h, s) \
143 1.1 kiyohara ia64_bus_space_unmap((t), (h), (s))
144 1.1 kiyohara #define bus_space_subregion(t, h, o, s, nhp) \
145 1.1 kiyohara ia64_bus_space_subregion((t), (h), (o), (s), (nhp))
146 1.1 kiyohara
147 1.1 kiyohara /* vaddr */
148 1.1 kiyohara
149 1.1 kiyohara #define bus_space_vaddr(t, h) \
150 1.1 kiyohara ((t) == IA64_BUS_SPACE_MEM ? (void *)(h) : (void *)0)
151 1.1 kiyohara
152 1.1 kiyohara /* map to user space */
153 1.1 kiyohara
154 1.1 kiyohara paddr_t ia64_bus_space_mmap(bus_space_tag_t, bus_addr_t, off_t, int, int);
155 1.1 kiyohara
156 1.1 kiyohara #define bus_space_mmap(t, b, o, p, f) \
157 1.1 kiyohara ia64_bus_space_mmap((t), (b), (o), (p), (f))
158 1.1 kiyohara
159 1.1 kiyohara /* alloc/free */
160 1.1 kiyohara
161 1.1 kiyohara int ia64_bus_space_alloc(bus_space_tag_t, bus_addr_t, bus_addr_t,
162 1.1 kiyohara bus_size_t, bus_size_t, bus_size_t, int, bus_addr_t *,
163 1.1 kiyohara bus_space_handle_t *);
164 1.1 kiyohara void ia64_bus_space_free(bus_space_tag_t, bus_space_handle_t, bus_size_t);
165 1.1 kiyohara
166 1.1 kiyohara #define bus_space_alloc(t, rs, re, s, a, b, f, ap, hp) \
167 1.1 kiyohara ia64_bus_space__alloc((t), (rs), (re), (s), (a), (b), (f), (ap), (hp))
168 1.1 kiyohara #define bus_space_free(t, h, s) \
169 1.1 kiyohara ia64_bus_space_free((t), (h), (s))
170 1.1 kiyohara
171 1.1 kiyohara /*
172 1.1 kiyohara * uintN_t bus_space_read_N(bus_space_tag_t tag,
173 1.1 kiyohara * bus_space_handle_t bsh, bus_size_t offset);
174 1.1 kiyohara *
175 1.1 kiyohara * Read a 1, 2, 4, or 8 byte quantity from bus space
176 1.1 kiyohara * described by tag/handle/offset.
177 1.1 kiyohara */
178 1.1 kiyohara
179 1.1 kiyohara #define bus_space_read_1(t, h, o) \
180 1.1 kiyohara ((t) == IA64_BUS_SPACE_IO ? (inb((h) + (o))) :\
181 1.1 kiyohara (*(volatile uint8_t *)((h) + (o))))
182 1.1 kiyohara
183 1.1 kiyohara #define bus_space_read_2(t, h, o) \
184 1.1 kiyohara (__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr"), \
185 1.1 kiyohara ((t) == IA64_BUS_SPACE_IO ? (inw((h) + (o))) : \
186 1.1 kiyohara (*(volatile uint16_t *)((h) + (o)))))
187 1.1 kiyohara
188 1.1 kiyohara #define bus_space_read_4(t, h, o) \
189 1.1 kiyohara (__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr"), \
190 1.1 kiyohara ((t) == IA64_BUS_SPACE_IO ? (inl((h) + (o))) : \
191 1.1 kiyohara (*(volatile uint32_t *)((h) + (o)))))
192 1.1 kiyohara
193 1.1 kiyohara #define bus_space_read_8(t, h, o) \
194 1.1 kiyohara (__BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr"), \
195 1.1 kiyohara ((t) == IA64_BUS_SPACE_IO ? \
196 1.1 kiyohara ({ printf("%s: can't read 8bytes from I/O space\n", __FUNCTION__); 0;}) : \
197 1.1 kiyohara (*(volatile uint64_t *)((h) + (o)))))
198 1.1 kiyohara
199 1.1 kiyohara #define bus_space_read_stream_1 bus_space_read_1
200 1.1 kiyohara #define bus_space_read_stream_2 bus_space_read_2
201 1.1 kiyohara #define bus_space_read_stream_4 bus_space_read_4
202 1.1 kiyohara #define bus_space_read_stream_8 bus_space_read_8
203 1.1 kiyohara
204 1.1 kiyohara /*
205 1.1 kiyohara * void bus_space_read_multi_N(bus_space_tag_t tag,
206 1.1 kiyohara * bus_space_handle_t bsh, bus_size_t offset,
207 1.1 kiyohara * uintN_t *addr, size_t count);
208 1.1 kiyohara *
209 1.1 kiyohara * Read `count' 1, 2, 4, or 8 byte quantities from bus space
210 1.1 kiyohara * described by tag/handle/offset and copy into buffer provided.
211 1.1 kiyohara */
212 1.1 kiyohara
213 1.1 kiyohara #define bus_space_read_multi_1(t, h, o, ptr, cnt) \
214 1.1 kiyohara do { \
215 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
216 1.1 kiyohara insb((h) + (o), (ptr), (cnt)); \
217 1.1 kiyohara } else { \
218 1.1 kiyohara int __i; \
219 1.1 kiyohara volatile uint8_t *__p = (uint8_t *)((h) + (o)); \
220 1.1 kiyohara uint8_t *__dst = (ptr); \
221 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
222 1.1 kiyohara *__dst++ = *__p; \
223 1.1 kiyohara } \
224 1.1 kiyohara } while (/* CONSTCOND */ 0)
225 1.1 kiyohara
226 1.1 kiyohara #define bus_space_read_multi_2(t, h, o, ptr, cnt) \
227 1.1 kiyohara do { \
228 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint16_t, "buffer"); \
229 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr"); \
230 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
231 1.1 kiyohara insw((h) + (o), (ptr), (cnt)); \
232 1.1 kiyohara } else { \
233 1.1 kiyohara int __i; \
234 1.1 kiyohara volatile uint16_t *__p = (uint16_t *)((h) + (o)); \
235 1.1 kiyohara uint16_t *__dst = (ptr); \
236 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
237 1.1 kiyohara *__dst++ = *__p; \
238 1.1 kiyohara } \
239 1.1 kiyohara } while (/* CONSTCOND */ 0)
240 1.1 kiyohara
241 1.1 kiyohara #define bus_space_read_multi_4(t, h, o, ptr, cnt) \
242 1.1 kiyohara do { \
243 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint32_t, "buffer"); \
244 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr"); \
245 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
246 1.1 kiyohara insl((h) + (o), (ptr), (cnt)); \
247 1.1 kiyohara } else { \
248 1.1 kiyohara int __i; \
249 1.1 kiyohara volatile uint32_t *__p = (uint32_t *)((h) + (o)); \
250 1.1 kiyohara uint32_t *__dst = (ptr); \
251 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
252 1.1 kiyohara *__dst++ = *__p; \
253 1.1 kiyohara } \
254 1.1 kiyohara } while (/* CONSTCOND */ 0)
255 1.1 kiyohara
256 1.1 kiyohara #define bus_space_read_multi_8(t, h, o, ptr, cnt) \
257 1.1 kiyohara do { \
258 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint64_t, "buffer"); \
259 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr"); \
260 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
261 1.1 kiyohara printf("%s: can't read 8bytes from I/O space\n", \
262 1.1 kiyohara __FUNCTION__); \
263 1.1 kiyohara } else { \
264 1.1 kiyohara int __i; \
265 1.1 kiyohara volatile uint64_t *__p = (uint64_t *)((h) + (o)); \
266 1.1 kiyohara uint64_t *__dst = (ptr); \
267 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
268 1.1 kiyohara *__dst++ = *__p; \
269 1.1 kiyohara } \
270 1.1 kiyohara } while (/* CONSTCOND */ 0)
271 1.1 kiyohara
272 1.1 kiyohara #define bus_space_read_multi_stream_1 bus_space_read_multi_1
273 1.1 kiyohara #define bus_space_read_multi_stream_2 bus_space_read_multi_2
274 1.1 kiyohara #define bus_space_read_multi_stream_4 bus_space_read_multi_4
275 1.1 kiyohara #define bus_space_read_multi_stream_8 bus_space_read_multi_8
276 1.1 kiyohara
277 1.1 kiyohara
278 1.1 kiyohara /*
279 1.1 kiyohara * void bus_space_read_region_N(bus_space_tag_t tag,
280 1.1 kiyohara * bus_space_handle_t bsh, bus_size_t offset,
281 1.1 kiyohara * uintN_t *addr, size_t count);
282 1.1 kiyohara *
283 1.1 kiyohara * Read `count' 1, 2, 4, or 8 byte quantities from bus space
284 1.1 kiyohara * described by tag/handle and starting at `offset' and copy into
285 1.1 kiyohara * buffer provided.
286 1.1 kiyohara */
287 1.1 kiyohara
288 1.1 kiyohara #define bus_space_read_region_1(t, h, o, ptr, cnt) \
289 1.1 kiyohara do { \
290 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
291 1.1 kiyohara int __i; \
292 1.1 kiyohara volatile bus_addr_t __port = (h) + (o); \
293 1.1 kiyohara uint8_t *__dst = (ptr); \
294 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) { \
295 1.1 kiyohara *__dst++ = inb(__port); \
296 1.1 kiyohara __port++; \
297 1.1 kiyohara } \
298 1.1 kiyohara } else { \
299 1.1 kiyohara int __i; \
300 1.1 kiyohara volatile uint8_t *__p = (uint8_t *)((h) + (o)); \
301 1.1 kiyohara uint8_t *__dst = (ptr); \
302 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
303 1.1 kiyohara *__dst++ = *__p++; \
304 1.1 kiyohara } \
305 1.1 kiyohara } while (/* CONSTCOND */ 0)
306 1.1 kiyohara
307 1.1 kiyohara #define bus_space_read_region_2(t, h, o, ptr, cnt) \
308 1.1 kiyohara do { \
309 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint16_t, "buffer"); \
310 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr"); \
311 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
312 1.1 kiyohara int __i; \
313 1.1 kiyohara volatile bus_addr_t __port = (h) + (o); \
314 1.1 kiyohara uint8_t *__dst = (ptr); \
315 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) { \
316 1.1 kiyohara *__dst++ = inb(__port); \
317 1.1 kiyohara __port += 2; \
318 1.1 kiyohara } \
319 1.1 kiyohara } else { \
320 1.1 kiyohara int __i; \
321 1.1 kiyohara volatile uint16_t *__p = (uint16_t *)((h) + (o)); \
322 1.1 kiyohara uint16_t *__dst = (ptr); \
323 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
324 1.1 kiyohara *__dst++ = *__p++; \
325 1.1 kiyohara } \
326 1.1 kiyohara } while (/* CONSTCOND */ 0)
327 1.1 kiyohara
328 1.1 kiyohara #define bus_space_read_region_4(t, h, o, ptr, cnt) \
329 1.1 kiyohara do { \
330 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint32_t, "buffer"); \
331 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr"); \
332 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
333 1.1 kiyohara int __i; \
334 1.1 kiyohara volatile bus_addr_t __port = (h) + (o); \
335 1.1 kiyohara uint8_t *__dst = (ptr); \
336 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) { \
337 1.1 kiyohara *__dst++ = inb(__port); \
338 1.1 kiyohara __port += 4; \
339 1.1 kiyohara } \
340 1.1 kiyohara } else { \
341 1.1 kiyohara volatile uint32_t *__p = (uint32_t *)((h) + (o)); \
342 1.1 kiyohara uint32_t *__dst = (ptr); \
343 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
344 1.1 kiyohara *__dst++ = *__p++; \
345 1.1 kiyohara } \
346 1.1 kiyohara } while (/* CONSTCOND */ 0)
347 1.1 kiyohara
348 1.1 kiyohara #define bus_space_read_region_8(t, h, o, ptr, cnt) \
349 1.1 kiyohara do { \
350 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint64_t, "buffer"); \
351 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr"); \
352 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
353 1.1 kiyohara printf("%s: can't read 8bytes from I/O space\n", \
354 1.1 kiyohara __FUNCTION__); \
355 1.1 kiyohara } else { \
356 1.1 kiyohara volatile uint64_t *__p = (uint64_t *)((h) + (o)); \
357 1.1 kiyohara uint64_t *__dst = (ptr); \
358 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
359 1.1 kiyohara *__dst++ = *__p++; \
360 1.1 kiyohara } \
361 1.1 kiyohara } while (/* CONSTCOND */ 0)
362 1.1 kiyohara
363 1.1 kiyohara #define bus_space_read_region_stream_1 bus_space_read_region_1
364 1.1 kiyohara #define bus_space_read_region_stream_2 bus_space_read_region_2
365 1.1 kiyohara #define bus_space_read_region_stream_4 bus_space_read_region_4
366 1.1 kiyohara #define bus_space_read_region_stream_8 bus_space_read_region_8
367 1.1 kiyohara
368 1.1 kiyohara
369 1.1 kiyohara /*
370 1.1 kiyohara * void bus_space_write_N(bus_space_tag_t tag,
371 1.1 kiyohara * bus_space_handle_t bsh, bus_size_t offset,
372 1.1 kiyohara * uintN_t value);
373 1.1 kiyohara *
374 1.1 kiyohara * Write the 1, 2, 4, or 8 byte value `value' to bus space
375 1.1 kiyohara * described by tag/handle/offset.
376 1.1 kiyohara */
377 1.1 kiyohara
378 1.1 kiyohara #define bus_space_write_1(t, h, o, v) \
379 1.1 kiyohara do { \
380 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) \
381 1.1 kiyohara outb((h) + (o), (v)); \
382 1.1 kiyohara else \
383 1.1 kiyohara ((void)(*(volatile uint8_t *)((h) + (o)) = (v))); \
384 1.1 kiyohara } while (/* CONSTCOND */ 0)
385 1.1 kiyohara
386 1.1 kiyohara #define bus_space_write_2(t, h, o, v) \
387 1.1 kiyohara do { \
388 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr"); \
389 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) \
390 1.1 kiyohara outw((h) + (o), (v)); \
391 1.1 kiyohara else \
392 1.1 kiyohara ((void)(*(volatile uint16_t *)((h) + (o)) = (v))); \
393 1.1 kiyohara } while (/* CONSTCOND */ 0)
394 1.1 kiyohara
395 1.1 kiyohara #define bus_space_write_4(t, h, o, v) \
396 1.1 kiyohara do { \
397 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr"); \
398 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) \
399 1.1 kiyohara outl((h) + (o), (v)); \
400 1.1 kiyohara else \
401 1.1 kiyohara ((void)(*(volatile uint32_t *)((h) + (o)) = (v))); \
402 1.1 kiyohara } while (/* CONSTCOND */ 0)
403 1.1 kiyohara
404 1.1 kiyohara #define bus_space_write_8(t, h, o, v) \
405 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr"); \
406 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO ? \
407 1.1 kiyohara printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__); : \
408 1.1 kiyohara (*(volatile uint64_t *)((h) + (o)) = (v)))
409 1.1 kiyohara
410 1.1 kiyohara #define bus_space_write_stream_1 bus_space_write_1
411 1.1 kiyohara #define bus_space_write_stream_2 bus_space_write_2
412 1.1 kiyohara #define bus_space_write_stream_4 bus_space_write_4
413 1.1 kiyohara #define bus_space_write_stream_8 bus_space_write_8
414 1.1 kiyohara
415 1.1 kiyohara /*
416 1.1 kiyohara * void bus_space_write_multi_N(bus_space_tag_t tag,
417 1.1 kiyohara * bus_space_handle_t bsh, bus_size_t offset,
418 1.1 kiyohara * const uintN_t *addr, size_t count);
419 1.1 kiyohara *
420 1.1 kiyohara * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
421 1.1 kiyohara * provided to bus space described by tag/handle/offset.
422 1.1 kiyohara */
423 1.1 kiyohara
424 1.1 kiyohara #define bus_space_write_multi_1(t, h, o, ptr, cnt) \
425 1.1 kiyohara do { \
426 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
427 1.1 kiyohara outsb((h) + (o), (ptr), (cnt)); \
428 1.1 kiyohara } else { \
429 1.1 kiyohara int __i; \
430 1.1 kiyohara volatile uint8_t *__p = (uint8_t *)((h) + (o)); \
431 1.5 skrll const uint8_t *__src = (ptr); \
432 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
433 1.1 kiyohara *__p = *__src++; \
434 1.1 kiyohara } \
435 1.1 kiyohara } while (/* CONSTCOND */ 0)
436 1.1 kiyohara
437 1.1 kiyohara #define bus_space_write_multi_2(t, h, o, ptr, cnt) \
438 1.1 kiyohara do { \
439 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint16_t, "buffer"); \
440 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr"); \
441 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
442 1.1 kiyohara outsw((h) + (o), (ptr), (cnt)); \
443 1.1 kiyohara } else { \
444 1.1 kiyohara int __i; \
445 1.1 kiyohara volatile uint16_t *__p = (uint16_t *)((h) + (o)); \
446 1.5 skrll const uint16_t *__src = (ptr); \
447 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
448 1.1 kiyohara *__p = *__src++; \
449 1.1 kiyohara } \
450 1.1 kiyohara } while (/* CONSTCOND */ 0)
451 1.1 kiyohara
452 1.1 kiyohara #define bus_space_write_multi_4(t, h, o, ptr, cnt) \
453 1.1 kiyohara do { \
454 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint32_t, "buffer"); \
455 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr"); \
456 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
457 1.1 kiyohara outsl((h) + (o), (ptr), (cnt)); \
458 1.1 kiyohara } else { \
459 1.1 kiyohara int __i; \
460 1.1 kiyohara volatile uint32_t *__p = (uint32_t *)((h) + (o)); \
461 1.5 skrll const uint32_t *__src = (ptr); \
462 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
463 1.1 kiyohara *__p = *__src++; \
464 1.1 kiyohara } \
465 1.1 kiyohara } while (/* CONSTCOND */ 0)
466 1.1 kiyohara
467 1.1 kiyohara #define bus_space_write_multi_8(t, h, o, ptr, cnt) \
468 1.1 kiyohara do { \
469 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint64_t, "buffer"); \
470 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr"); \
471 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
472 1.1 kiyohara printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__);\
473 1.1 kiyohara } else { \
474 1.1 kiyohara int __i; \
475 1.1 kiyohara volatile uint64_t *__p = (uint64_t *)((h) + (o)); \
476 1.5 skrll const uint64_t *__src = (ptr); \
477 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
478 1.1 kiyohara *__p = *__src++; \
479 1.1 kiyohara } \
480 1.1 kiyohara } while (/* CONSTCOND */ 0)
481 1.1 kiyohara
482 1.1 kiyohara #define bus_space_write_multi_stream_1 bus_space_write_multi_1
483 1.1 kiyohara #define bus_space_write_multi_stream_2 bus_space_write_multi_2
484 1.1 kiyohara #define bus_space_write_multi_stream_4 bus_space_write_multi_4
485 1.1 kiyohara #define bus_space_write_multi_stream_8 bus_space_write_multi_8
486 1.1 kiyohara
487 1.1 kiyohara
488 1.1 kiyohara /*
489 1.1 kiyohara * void bus_space_write_region_N(bus_space_tag_t tag,
490 1.1 kiyohara * bus_space_handle_t bsh, bus_size_t offset,
491 1.1 kiyohara * const uintN_t *addr, size_t count);
492 1.1 kiyohara *
493 1.1 kiyohara * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
494 1.1 kiyohara * to bus space described by tag/handle starting at `offset'.
495 1.1 kiyohara */
496 1.1 kiyohara
497 1.1 kiyohara #define bus_space_write_region_1(t, h, o, ptr, cnt) \
498 1.1 kiyohara do { \
499 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
500 1.1 kiyohara int __i; \
501 1.1 kiyohara volatile bus_addr_t __port = (h) + (o); \
502 1.5 skrll const uint8_t *__src = (ptr); \
503 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) { \
504 1.1 kiyohara outb(__port, *__src); \
505 1.1 kiyohara __port++; \
506 1.1 kiyohara __src++; \
507 1.1 kiyohara } \
508 1.1 kiyohara } else { \
509 1.1 kiyohara int __i; \
510 1.1 kiyohara volatile uint8_t *__p = (uint8_t *)((h) + (o)); \
511 1.5 skrll const uint8_t *__src = (ptr); \
512 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
513 1.1 kiyohara *__p++ = *__src++; \
514 1.1 kiyohara } \
515 1.1 kiyohara } while (/* CONSTCOND */ 0)
516 1.1 kiyohara
517 1.1 kiyohara #define bus_space_write_region_2(t, h, o, ptr, cnt) \
518 1.1 kiyohara do { \
519 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint16_t, "buffer"); \
520 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr"); \
521 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
522 1.1 kiyohara int __i; \
523 1.1 kiyohara volatile bus_addr_t __port = (h) + (o); \
524 1.5 skrll const uint16_t *__src = (ptr); \
525 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) { \
526 1.1 kiyohara outw(__port, *__src); \
527 1.1 kiyohara __port += 2; \
528 1.1 kiyohara __src++; \
529 1.1 kiyohara } \
530 1.1 kiyohara } else { \
531 1.1 kiyohara int __i; \
532 1.1 kiyohara volatile uint16_t *__p = (uint16_t *)((h) + (o)); \
533 1.5 skrll const uint16_t *__src = (ptr); \
534 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
535 1.1 kiyohara *__p++ = *__src++; \
536 1.1 kiyohara } \
537 1.1 kiyohara } while (/* CONSTCOND */ 0)
538 1.1 kiyohara
539 1.1 kiyohara #define bus_space_write_region_4(t, h, o, ptr, cnt) \
540 1.1 kiyohara do { \
541 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint32_t, "buffer"); \
542 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr"); \
543 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
544 1.1 kiyohara int __i; \
545 1.1 kiyohara volatile bus_addr_t __port = (h) + (o); \
546 1.5 skrll const uint32_t *__src = (ptr); \
547 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) { \
548 1.1 kiyohara outl(__port, *__src); \
549 1.1 kiyohara __port += 4; \
550 1.1 kiyohara __src++; \
551 1.1 kiyohara } \
552 1.1 kiyohara } else { \
553 1.1 kiyohara int __i; \
554 1.1 kiyohara volatile uint32_t *__p = (uint32_t *)(h) + (o); \
555 1.5 skrll const uint32_t *__src = (ptr); \
556 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
557 1.1 kiyohara *__p++ = *__src++; \
558 1.1 kiyohara } \
559 1.1 kiyohara } while (/* CONSTCOND */ 0)
560 1.1 kiyohara
561 1.1 kiyohara #define bus_space_write_region_8(t, h, o, ptr, cnt) \
562 1.1 kiyohara do { \
563 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((ptr), uint64_t, "buffer"); \
564 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr"); \
565 1.1 kiyohara if ((t) == IA64_BUS_SPACE_IO) { \
566 1.1 kiyohara printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__);\
567 1.1 kiyohara } else { \
568 1.1 kiyohara int __i; \
569 1.1 kiyohara volatile uint64_t *__p = (uint64_t *)((h) + (o)); \
570 1.5 skrll const uint64_t *__src = (ptr); \
571 1.1 kiyohara for (__i = 0; __i < (cnt); __i++) \
572 1.1 kiyohara *__p++ = *__src++; \
573 1.1 kiyohara } \
574 1.1 kiyohara } while (/* CONSTCOND */ 0)
575 1.1 kiyohara
576 1.1 kiyohara #define bus_space_write_region_stream_1 bus_space_write_region_1
577 1.1 kiyohara #define bus_space_write_region_stream_2 bus_space_write_region_2
578 1.1 kiyohara #define bus_space_write_region_stream_4 bus_space_write_region_4
579 1.1 kiyohara #define bus_space_write_region_stream_8 bus_space_write_region_8
580 1.1 kiyohara
581 1.1 kiyohara
582 1.1 kiyohara /*
583 1.1 kiyohara * void bus_space_set_multi_N(bus_space_tag_t tag,
584 1.1 kiyohara * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
585 1.1 kiyohara * size_t count);
586 1.1 kiyohara *
587 1.1 kiyohara * Write the 1, 2, 4, or 8 byte value `val' to bus space described
588 1.1 kiyohara * by tag/handle/offset `count' times.
589 1.1 kiyohara */
590 1.1 kiyohara
591 1.1 kiyohara static __inline void ia64_bus_space_set_multi_1(bus_space_tag_t,
592 1.1 kiyohara bus_space_handle_t, bus_size_t, uint8_t, size_t);
593 1.1 kiyohara static __inline void ia64_bus_space_set_multi_2(bus_space_tag_t,
594 1.1 kiyohara bus_space_handle_t, bus_size_t, uint16_t, size_t);
595 1.1 kiyohara static __inline void ia64_bus_space_set_multi_4(bus_space_tag_t,
596 1.1 kiyohara bus_space_handle_t, bus_size_t, uint32_t, size_t);
597 1.1 kiyohara static __inline void ia64_bus_space_set_multi_8(bus_space_tag_t,
598 1.1 kiyohara bus_space_handle_t, bus_size_t, uint64_t, size_t);
599 1.1 kiyohara
600 1.1 kiyohara #define bus_space_set_multi_1(t, h, o, v, c) \
601 1.1 kiyohara ia64_bus_space_set_multi_1((t), (h), (o), (v), (c))
602 1.1 kiyohara
603 1.1 kiyohara #define bus_space_set_multi_2(t, h, o, v, c) \
604 1.1 kiyohara do { \
605 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr"); \
606 1.1 kiyohara ia64_bus_space_set_multi_2((t), (h), (o), (v), (c)); \
607 1.1 kiyohara } while (/* CONSTCOND */ 0)
608 1.1 kiyohara
609 1.1 kiyohara #define bus_space_set_multi_4(t, h, o, v, c) \
610 1.1 kiyohara do { \
611 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr"); \
612 1.1 kiyohara ia64_bus_space_set_multi_4((t), (h), (o), (v), (c)); \
613 1.1 kiyohara } while (/* CONSTCOND */ 0)
614 1.1 kiyohara
615 1.1 kiyohara #define bus_space_set_multi_8(t, h, o, v, c) \
616 1.1 kiyohara do { \
617 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr"); \
618 1.1 kiyohara ia64_bus_space_set_multi_8((t), (h), (o), (v), (c)); \
619 1.1 kiyohara } while (/* CONSTCOND */ 0)
620 1.1 kiyohara
621 1.1 kiyohara static __inline void
622 1.1 kiyohara ia64_bus_space_set_multi_1(bus_space_tag_t t, bus_space_handle_t h,
623 1.1 kiyohara bus_size_t o, uint8_t v, size_t c)
624 1.1 kiyohara {
625 1.1 kiyohara bus_addr_t addr = h + o;
626 1.1 kiyohara
627 1.1 kiyohara if (t == IA64_BUS_SPACE_IO)
628 1.1 kiyohara while (c--)
629 1.1 kiyohara outb(addr, v);
630 1.1 kiyohara else
631 1.1 kiyohara while (c--)
632 1.1 kiyohara *(volatile uint8_t *)(addr) = v;
633 1.1 kiyohara }
634 1.1 kiyohara
635 1.1 kiyohara static __inline void
636 1.1 kiyohara ia64_bus_space_set_multi_2(bus_space_tag_t t, bus_space_handle_t h,
637 1.1 kiyohara bus_size_t o, uint16_t v, size_t c)
638 1.1 kiyohara {
639 1.1 kiyohara bus_addr_t addr = h + o;
640 1.1 kiyohara
641 1.1 kiyohara if (t == IA64_BUS_SPACE_IO)
642 1.1 kiyohara while (c--)
643 1.1 kiyohara outw(addr, v);
644 1.1 kiyohara else
645 1.1 kiyohara while (c--)
646 1.1 kiyohara *(volatile uint16_t *)(addr) = v;
647 1.1 kiyohara }
648 1.1 kiyohara
649 1.1 kiyohara static __inline void
650 1.1 kiyohara ia64_bus_space_set_multi_4(bus_space_tag_t t, bus_space_handle_t h,
651 1.1 kiyohara bus_size_t o, uint32_t v, size_t c)
652 1.1 kiyohara {
653 1.1 kiyohara bus_addr_t addr = h + o;
654 1.1 kiyohara
655 1.1 kiyohara if (t == IA64_BUS_SPACE_IO)
656 1.1 kiyohara while (c--)
657 1.1 kiyohara outl(addr, v);
658 1.1 kiyohara else
659 1.1 kiyohara while (c--)
660 1.1 kiyohara *(volatile uint32_t *)(addr) = v;
661 1.1 kiyohara }
662 1.1 kiyohara
663 1.1 kiyohara static __inline void
664 1.1 kiyohara ia64_bus_space_set_multi_8(bus_space_tag_t t, bus_space_handle_t h,
665 1.1 kiyohara bus_size_t o, uint64_t v, size_t c)
666 1.1 kiyohara {
667 1.1 kiyohara bus_addr_t addr = h + o;
668 1.1 kiyohara
669 1.1 kiyohara if (t == IA64_BUS_SPACE_IO)
670 1.1 kiyohara printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__);
671 1.1 kiyohara else
672 1.1 kiyohara while (c--)
673 1.1 kiyohara *(volatile uint64_t *)(addr) = v;
674 1.1 kiyohara }
675 1.1 kiyohara
676 1.1 kiyohara
677 1.1 kiyohara /*
678 1.1 kiyohara * void bus_space_set_region_N(bus_space_tag_t tag,
679 1.1 kiyohara * bus_space_handle_t bsh, bus_size_t offset, uintN_t val,
680 1.1 kiyohara * size_t count);
681 1.1 kiyohara *
682 1.1 kiyohara * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
683 1.1 kiyohara * by tag/handle starting at `offset'.
684 1.1 kiyohara */
685 1.1 kiyohara
686 1.1 kiyohara static __inline void ia64_bus_space_set_region_1(bus_space_tag_t,
687 1.1 kiyohara bus_space_handle_t, bus_size_t, uint8_t, size_t);
688 1.1 kiyohara static __inline void ia64_bus_space_set_region_2(bus_space_tag_t,
689 1.1 kiyohara bus_space_handle_t, bus_size_t, uint16_t, size_t);
690 1.1 kiyohara static __inline void ia64_bus_space_set_region_4(bus_space_tag_t,
691 1.1 kiyohara bus_space_handle_t, bus_size_t, uint32_t, size_t);
692 1.1 kiyohara
693 1.1 kiyohara #define bus_space_set_region_1(t, h, o, v, c) \
694 1.1 kiyohara ia64_bus_space_set_region_1((t), (h), (o), (v), (c))
695 1.1 kiyohara
696 1.1 kiyohara #define bus_space_set_region_2(t, h, o, v, c) \
697 1.1 kiyohara do { \
698 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint16_t, "bus addr"); \
699 1.1 kiyohara ia64_bus_space_set_region_2((t), (h), (o), (v), (c)); \
700 1.1 kiyohara } while (/* CONSTCOND */ 0)
701 1.1 kiyohara
702 1.1 kiyohara #define bus_space_set_region_4(t, h, o, v, c) \
703 1.1 kiyohara do { \
704 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint32_t, "bus addr"); \
705 1.1 kiyohara ia64_bus_space_set_region_4((t), (h), (o), (v), (c)); \
706 1.1 kiyohara } while (/* CONSTCOND */ 0)
707 1.1 kiyohara
708 1.1 kiyohara #define bus_space_set_region_8(t, h, o, v, c) \
709 1.1 kiyohara do { \
710 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h) + (o), uint64_t, "bus addr"); \
711 1.1 kiyohara ia64_bus_space_set_region_8((t), (h), (o), (v), (c)); \
712 1.1 kiyohara } while (/* CONSTCOND */ 0)
713 1.1 kiyohara
714 1.1 kiyohara static __inline void
715 1.1 kiyohara ia64_bus_space_set_region_1(bus_space_tag_t t, bus_space_handle_t h,
716 1.1 kiyohara bus_size_t o, uint8_t v, size_t c)
717 1.1 kiyohara {
718 1.1 kiyohara bus_addr_t addr = h + o;
719 1.1 kiyohara
720 1.1 kiyohara if (t == IA64_BUS_SPACE_IO)
721 1.1 kiyohara for (; c != 0; c--, addr++)
722 1.1 kiyohara outb(addr, v);
723 1.1 kiyohara else
724 1.1 kiyohara for (; c != 0; c--, addr++)
725 1.1 kiyohara *(volatile uint8_t *)(addr) = v;
726 1.1 kiyohara }
727 1.1 kiyohara
728 1.1 kiyohara static __inline void
729 1.1 kiyohara ia64_bus_space_set_region_2(bus_space_tag_t t, bus_space_handle_t h,
730 1.1 kiyohara bus_size_t o, uint16_t v, size_t c)
731 1.1 kiyohara {
732 1.1 kiyohara bus_addr_t addr = h + o;
733 1.1 kiyohara
734 1.1 kiyohara if (t == IA64_BUS_SPACE_IO)
735 1.1 kiyohara for (; c != 0; c--, addr += 2)
736 1.1 kiyohara outw(addr, v);
737 1.1 kiyohara else
738 1.1 kiyohara for (; c != 0; c--, addr += 2)
739 1.1 kiyohara *(volatile uint16_t *)(addr) = v;
740 1.1 kiyohara }
741 1.1 kiyohara
742 1.1 kiyohara static __inline void
743 1.1 kiyohara ia64_bus_space_set_region_4(bus_space_tag_t t, bus_space_handle_t h,
744 1.1 kiyohara bus_size_t o, uint32_t v, size_t c)
745 1.1 kiyohara {
746 1.1 kiyohara bus_addr_t addr = h + o;
747 1.1 kiyohara
748 1.1 kiyohara if (t == IA64_BUS_SPACE_IO)
749 1.1 kiyohara for (; c != 0; c--, addr += 4)
750 1.1 kiyohara outl(addr, v);
751 1.1 kiyohara else
752 1.1 kiyohara for (; c != 0; c--, addr += 4)
753 1.1 kiyohara *(volatile uint32_t *)(addr) = v;
754 1.1 kiyohara }
755 1.1 kiyohara
756 1.1 kiyohara static __inline void
757 1.1 kiyohara ia64_bus_space_set_region_8(bus_space_tag_t t, bus_space_handle_t h,
758 1.1 kiyohara bus_size_t o, uint64_t v, size_t c)
759 1.1 kiyohara {
760 1.1 kiyohara bus_addr_t addr = h + o;
761 1.1 kiyohara
762 1.1 kiyohara if (t == IA64_BUS_SPACE_IO)
763 1.1 kiyohara printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__);
764 1.1 kiyohara else
765 1.1 kiyohara for (; c != 0; c--, addr += 8)
766 1.1 kiyohara *(volatile uint32_t *)(addr) = v;
767 1.1 kiyohara }
768 1.1 kiyohara
769 1.1 kiyohara
770 1.1 kiyohara /*
771 1.1 kiyohara * void bus_space_copy_region_N(bus_space_tag_t tag,
772 1.1 kiyohara * bus_space_handle_t bsh1, bus_size_t off1,
773 1.1 kiyohara * bus_space_handle_t bsh2, bus_size_t off2,
774 1.1 kiyohara * size_t count);
775 1.1 kiyohara *
776 1.1 kiyohara * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
777 1.1 kiyohara * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
778 1.1 kiyohara */
779 1.1 kiyohara
780 1.1 kiyohara static __inline void ia64_bus_space_copy_region_1(bus_space_tag_t,
781 1.1 kiyohara bus_space_handle_t, bus_size_t, bus_space_handle_t,
782 1.1 kiyohara bus_size_t, size_t);
783 1.1 kiyohara static __inline void ia64_bus_space_copy_region_2(bus_space_tag_t,
784 1.1 kiyohara bus_space_handle_t, bus_size_t, bus_space_handle_t,
785 1.1 kiyohara bus_size_t, size_t);
786 1.1 kiyohara static __inline void ia64_bus_space_copy_region_4(bus_space_tag_t,
787 1.1 kiyohara bus_space_handle_t, bus_size_t, bus_space_handle_t,
788 1.1 kiyohara bus_size_t, size_t);
789 1.1 kiyohara
790 1.1 kiyohara #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \
791 1.1 kiyohara ia64_bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
792 1.1 kiyohara
793 1.1 kiyohara #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \
794 1.1 kiyohara do { \
795 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), uint16_t, "bus addr 1"); \
796 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), uint16_t, "bus addr 2"); \
797 1.1 kiyohara ia64_bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c)); \
798 1.1 kiyohara } while (/* CONSTCOND */ 0)
799 1.1 kiyohara
800 1.1 kiyohara #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \
801 1.1 kiyohara do { \
802 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), uint32_t, "bus addr 1"); \
803 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), uint32_t, "bus addr 2"); \
804 1.1 kiyohara ia64_bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c)); \
805 1.1 kiyohara } while (/* CONSTCOND */ 0)
806 1.1 kiyohara
807 1.1 kiyohara #define bus_space_copy_region_8(t, h1, o1, h2, o2, c) \
808 1.1 kiyohara do { \
809 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h1) + (o1), uint64_t, "bus addr 1"); \
810 1.1 kiyohara __BUS_SPACE_ADDRESS_SANITY((h2) + (o2), uint64_t, "bus addr 2"); \
811 1.1 kiyohara ia64_bus_space_copy_region_8((t), (h1), (o1), (h2), (o2), (c)); \
812 1.1 kiyohara } while (/* CONSTCOND */ 0)
813 1.1 kiyohara
814 1.1 kiyohara static __inline void
815 1.1 kiyohara ia64_bus_space_copy_region_1(bus_space_tag_t t,
816 1.1 kiyohara bus_space_handle_t h1, bus_size_t o1,
817 1.1 kiyohara bus_space_handle_t h2, bus_size_t o2, size_t c)
818 1.1 kiyohara {
819 1.1 kiyohara bus_addr_t addr1 = h1 + o1;
820 1.1 kiyohara bus_addr_t addr2 = h2 + o2;
821 1.1 kiyohara
822 1.1 kiyohara if (t == IA64_BUS_SPACE_IO) {
823 1.1 kiyohara if (addr1 >= addr2) {
824 1.1 kiyohara /* src after dest: copy forward */
825 1.1 kiyohara for (; c != 0; c--, addr1++, addr2++)
826 1.1 kiyohara outb(addr2, inb(addr1));
827 1.1 kiyohara } else {
828 1.1 kiyohara /* dest after src: copy backwards */
829 1.1 kiyohara for (addr1 += (c - 1), addr2 += (c - 1);
830 1.1 kiyohara c != 0; c--, addr1--, addr2--)
831 1.1 kiyohara outb(addr2, inb(addr1));
832 1.1 kiyohara }
833 1.1 kiyohara } else {
834 1.1 kiyohara if (addr1 >= addr2) {
835 1.1 kiyohara /* src after dest: copy forward */
836 1.1 kiyohara for (; c != 0; c--, addr1++, addr2++)
837 1.1 kiyohara *(volatile uint8_t *)(addr2) =
838 1.1 kiyohara *(volatile uint8_t *)(addr1);
839 1.1 kiyohara } else {
840 1.1 kiyohara /* dest after src: copy backwards */
841 1.1 kiyohara for (addr1 += (c - 1), addr2 += (c - 1);
842 1.1 kiyohara c != 0; c--, addr1--, addr2--)
843 1.1 kiyohara *(volatile uint8_t *)(addr2) =
844 1.1 kiyohara *(volatile uint8_t *)(addr1);
845 1.1 kiyohara }
846 1.1 kiyohara }
847 1.1 kiyohara }
848 1.1 kiyohara
849 1.1 kiyohara static __inline void
850 1.1 kiyohara ia64_bus_space_copy_region_2(bus_space_tag_t t,
851 1.1 kiyohara bus_space_handle_t h1, bus_size_t o1,
852 1.1 kiyohara bus_space_handle_t h2, bus_size_t o2, size_t c)
853 1.1 kiyohara {
854 1.1 kiyohara bus_addr_t addr1 = h1 + o1;
855 1.1 kiyohara bus_addr_t addr2 = h2 + o2;
856 1.1 kiyohara
857 1.1 kiyohara if (t == IA64_BUS_SPACE_IO) {
858 1.1 kiyohara if (addr1 >= addr2) {
859 1.1 kiyohara /* src after dest: copy forward */
860 1.1 kiyohara for (; c != 0; c--, addr1 += 2, addr2 += 2)
861 1.1 kiyohara outw(addr2, inw(addr1));
862 1.1 kiyohara } else {
863 1.1 kiyohara /* dest after src: copy backwards */
864 1.1 kiyohara for (addr1 += 2 * (c - 1), addr2 += 2 * (c - 1);
865 1.1 kiyohara c != 0; c--, addr1 -= 2, addr2 -= 2)
866 1.1 kiyohara outw(addr2, inw(addr1));
867 1.1 kiyohara }
868 1.1 kiyohara } else {
869 1.1 kiyohara if (addr1 >= addr2) {
870 1.1 kiyohara /* src after dest: copy forward */
871 1.1 kiyohara for (; c != 0; c--, addr1 += 2, addr2 += 2)
872 1.1 kiyohara *(volatile uint16_t *)(addr2) =
873 1.1 kiyohara *(volatile uint16_t *)(addr1);
874 1.1 kiyohara } else {
875 1.1 kiyohara /* dest after src: copy backwards */
876 1.1 kiyohara for (addr1 += 2 * (c - 1), addr2 += 2 * (c - 1);
877 1.1 kiyohara c != 0; c--, addr1 -= 2, addr2 -= 2)
878 1.1 kiyohara *(volatile uint16_t *)(addr2) =
879 1.1 kiyohara *(volatile uint16_t *)(addr1);
880 1.1 kiyohara }
881 1.1 kiyohara }
882 1.1 kiyohara }
883 1.1 kiyohara
884 1.1 kiyohara static __inline void
885 1.1 kiyohara ia64_bus_space_copy_region_4(bus_space_tag_t t,
886 1.1 kiyohara bus_space_handle_t h1, bus_size_t o1,
887 1.1 kiyohara bus_space_handle_t h2, bus_size_t o2, size_t c)
888 1.1 kiyohara {
889 1.1 kiyohara bus_addr_t addr1 = h1 + o1;
890 1.1 kiyohara bus_addr_t addr2 = h2 + o2;
891 1.1 kiyohara
892 1.1 kiyohara if (t == IA64_BUS_SPACE_IO) {
893 1.1 kiyohara if (addr1 >= addr2) {
894 1.1 kiyohara /* src after dest: copy forward */
895 1.1 kiyohara for (; c != 0; c--, addr1 += 4, addr2 += 4)
896 1.1 kiyohara outl(addr2, inl(addr1));
897 1.1 kiyohara } else {
898 1.1 kiyohara /* dest after src: copy backwards */
899 1.1 kiyohara for (addr1 += 4 * (c - 1), addr2 += 4 * (c - 1);
900 1.1 kiyohara c != 0; c--, addr1 -= 4, addr2 -= 4)
901 1.1 kiyohara outl(addr2, inl(addr1));
902 1.1 kiyohara }
903 1.1 kiyohara } else {
904 1.1 kiyohara if (addr1 >= addr2) {
905 1.1 kiyohara /* src after dest: copy forward */
906 1.1 kiyohara for (; c != 0; c--, addr1 += 4, addr2 += 4)
907 1.1 kiyohara *(volatile uint32_t *)(addr2) =
908 1.1 kiyohara *(volatile uint32_t *)(addr1);
909 1.1 kiyohara } else {
910 1.1 kiyohara /* dest after src: copy backwards */
911 1.1 kiyohara for (addr1 += 4 * (c - 1), addr2 += 4 * (c - 1);
912 1.1 kiyohara c != 0; c--, addr1 -= 4, addr2 -= 4)
913 1.1 kiyohara *(volatile uint32_t *)(addr2) =
914 1.1 kiyohara *(volatile uint32_t *)(addr1);
915 1.1 kiyohara }
916 1.1 kiyohara }
917 1.1 kiyohara }
918 1.1 kiyohara
919 1.1 kiyohara static __inline void
920 1.1 kiyohara ia64_bus_space_copy_region_8(bus_space_tag_t t,
921 1.1 kiyohara bus_space_handle_t h1, bus_size_t o1,
922 1.1 kiyohara bus_space_handle_t h2, bus_size_t o2, size_t c)
923 1.1 kiyohara {
924 1.1 kiyohara bus_addr_t addr1 = h1 + o1;
925 1.1 kiyohara bus_addr_t addr2 = h2 + o2;
926 1.1 kiyohara
927 1.1 kiyohara if (t == IA64_BUS_SPACE_IO) {
928 1.1 kiyohara printf("%s: can't write 8bytes to I/O space\n", __FUNCTION__);
929 1.1 kiyohara } else {
930 1.1 kiyohara if (addr1 >= addr2) {
931 1.1 kiyohara /* src after dest: copy forward */
932 1.1 kiyohara for (; c != 0; c--, addr1 += 8, addr2 += 8)
933 1.1 kiyohara *(volatile uint64_t *)(addr2) =
934 1.1 kiyohara *(volatile uint64_t *)(addr1);
935 1.1 kiyohara } else {
936 1.1 kiyohara /* dest after src: copy backwards */
937 1.1 kiyohara for (addr1 += 8 * (c - 1), addr2 += 8 * (c - 1);
938 1.1 kiyohara c != 0; c--, addr1 -= 8, addr2 -= 8)
939 1.1 kiyohara *(volatile uint64_t *)(addr2) =
940 1.1 kiyohara *(volatile uint64_t *)(addr1);
941 1.1 kiyohara }
942 1.1 kiyohara }
943 1.1 kiyohara }
944 1.1 kiyohara
945 1.1 kiyohara
946 1.1 kiyohara /*
947 1.1 kiyohara * Bus read/write barrier methods.
948 1.1 kiyohara *
949 1.1 kiyohara * void bus_space_barrier(bus_space_tag_t tag,
950 1.1 kiyohara * bus_space_handle_t bsh, bus_size_t offset,
951 1.1 kiyohara * bus_size_t len, int flags);
952 1.1 kiyohara *
953 1.1 kiyohara * Note: the x86 does not currently require barriers, but we must
954 1.1 kiyohara * provide the flags to MI code.
955 1.1 kiyohara */
956 1.1 kiyohara #define bus_space_barrier(t, h, o, l, f) \
957 1.1 kiyohara ia64_bus_space_barrier((t), (h), (o), (l), (f))
958 1.1 kiyohara
959 1.1 kiyohara #define BUS_SPACE_BARRIER_READ 0x01
960 1.1 kiyohara #define BUS_SPACE_BARRIER_WRITE 0x02
961 1.1 kiyohara
962 1.1 kiyohara static __inline void
963 1.1 kiyohara ia64_bus_space_barrier(bus_space_tag_t t, bus_space_handle_t handle,
964 1.1 kiyohara bus_size_t offset, bus_size_t length, int flags)
965 1.1 kiyohara {
966 1.1 kiyohara if (t == IA64_BUS_SPACE_IO)
967 1.1 kiyohara return;
968 1.1 kiyohara
969 1.1 kiyohara switch (flags) {
970 1.1 kiyohara case BUS_SPACE_BARRIER_READ:
971 1.1 kiyohara __asm volatile("mf" ::: "memory");
972 1.1 kiyohara break;
973 1.1 kiyohara case BUS_SPACE_BARRIER_WRITE:
974 1.1 kiyohara __asm volatile("mf" ::: "memory");
975 1.1 kiyohara break;
976 1.1 kiyohara case BUS_SPACE_BARRIER_READ | BUS_SPACE_BARRIER_WRITE:
977 1.1 kiyohara __asm volatile("mf" ::: "memory");
978 1.1 kiyohara break;
979 1.1 kiyohara default:
980 1.1 kiyohara printf("%s: Unknown barrier %d\n", __FUNCTION__, flags);
981 1.1 kiyohara break;
982 1.1 kiyohara }
983 1.1 kiyohara }
984 1.1 kiyohara
985 1.1 kiyohara
986 1.1 kiyohara /*
987 1.1 kiyohara * Flags used in various bus DMA methods.
988 1.1 kiyohara */
989 1.1 kiyohara #define BUS_DMA_WAITOK 0x000 /* safe to sleep (pseudo-flag) */
990 1.1 kiyohara #define BUS_DMA_NOWAIT 0x001 /* not safe to sleep */
991 1.1 kiyohara #define BUS_DMA_ALLOCNOW 0x002 /* perform resource allocation now */
992 1.1 kiyohara #define BUS_DMA_COHERENT 0x004 /* hint: map memory DMA coherent */
993 1.1 kiyohara #define BUS_DMA_STREAMING 0x008 /* hint: sequential, unidirectional */
994 1.1 kiyohara #define BUS_DMA_BUS1 0x010 /* placeholders for bus functions... */
995 1.1 kiyohara #define BUS_DMA_BUS2 0x020
996 1.1 kiyohara #define BUS_DMA_BUS3 0x040
997 1.1 kiyohara #define BUS_DMA_BUS4 0x080
998 1.1 kiyohara #define BUS_DMA_READ 0x100 /* mapping is device -> memory only */
999 1.1 kiyohara #define BUS_DMA_WRITE 0x200 /* mapping is memory -> device only */
1000 1.1 kiyohara #define BUS_DMA_NOCACHE 0x400 /* hint: map non-cached memory */
1001 1.1 kiyohara
1002 1.1 kiyohara /* Forwards needed by prototypes below. */
1003 1.1 kiyohara struct mbuf;
1004 1.1 kiyohara struct uio;
1005 1.1 kiyohara
1006 1.1 kiyohara /*
1007 1.1 kiyohara * Operations performed by bus_dmamap_sync().
1008 1.1 kiyohara */
1009 1.1 kiyohara #define BUS_DMASYNC_PREREAD 0x01 /* pre-read synchronization */
1010 1.1 kiyohara #define BUS_DMASYNC_POSTREAD 0x02 /* post-read synchronization */
1011 1.1 kiyohara #define BUS_DMASYNC_PREWRITE 0x04 /* pre-write synchronization */
1012 1.1 kiyohara #define BUS_DMASYNC_POSTWRITE 0x08 /* post-write synchronization */
1013 1.1 kiyohara
1014 1.1 kiyohara typedef struct ia64_bus_dma_tag *bus_dma_tag_t;
1015 1.1 kiyohara typedef struct ia64_bus_dmamap *bus_dmamap_t;
1016 1.1 kiyohara
1017 1.1 kiyohara #define BUS_DMA_TAG_VALID(t) ((t) != (bus_dma_tag_t)0)
1018 1.1 kiyohara
1019 1.1 kiyohara /*
1020 1.1 kiyohara * bus_dma_segment_t
1021 1.1 kiyohara *
1022 1.1 kiyohara * Describes a single contiguous DMA transaction. Values
1023 1.1 kiyohara * are suitable for programming into DMA registers.
1024 1.1 kiyohara */
1025 1.1 kiyohara struct ia64_bus_dma_segment {
1026 1.1 kiyohara bus_addr_t ds_addr; /* DMA address */
1027 1.1 kiyohara bus_size_t ds_len; /* length of transfer */
1028 1.1 kiyohara };
1029 1.1 kiyohara typedef struct ia64_bus_dma_segment bus_dma_segment_t;
1030 1.1 kiyohara
1031 1.1 kiyohara /*
1032 1.1 kiyohara * bus_dma_tag_t
1033 1.1 kiyohara *
1034 1.1 kiyohara * A machine-dependent opaque type describing the implementation of
1035 1.1 kiyohara * DMA for a given bus.
1036 1.1 kiyohara */
1037 1.1 kiyohara
1038 1.1 kiyohara struct ia64_bus_dma_tag {
1039 1.1 kiyohara /*
1040 1.1 kiyohara * The `bounce threshold' is checked while we are loading
1041 1.1 kiyohara * the DMA map. If the physical address of the segment
1042 1.1 kiyohara * exceeds the threshold, an error will be returned. The
1043 1.1 kiyohara * caller can then take whatever action is necessary to
1044 1.1 kiyohara * bounce the transfer. If this value is 0, it will be
1045 1.1 kiyohara * ignored.
1046 1.1 kiyohara */
1047 1.1 kiyohara bus_addr_t _bounce_thresh;
1048 1.1 kiyohara bus_addr_t _bounce_alloc_lo;
1049 1.1 kiyohara bus_addr_t _bounce_alloc_hi;
1050 1.1 kiyohara int (*_may_bounce)(bus_dma_tag_t, bus_dmamap_t, int, int *);
1051 1.1 kiyohara
1052 1.1 kiyohara /*
1053 1.1 kiyohara * DMA mapping methods.
1054 1.1 kiyohara */
1055 1.1 kiyohara int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
1056 1.1 kiyohara bus_size_t, bus_size_t, int, bus_dmamap_t *);
1057 1.1 kiyohara void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
1058 1.1 kiyohara int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
1059 1.1 kiyohara bus_size_t, struct proc *, int);
1060 1.1 kiyohara int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
1061 1.1 kiyohara struct mbuf *, int);
1062 1.1 kiyohara int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
1063 1.1 kiyohara struct uio *, int);
1064 1.1 kiyohara int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
1065 1.1 kiyohara bus_dma_segment_t *, int, bus_size_t, int);
1066 1.1 kiyohara void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
1067 1.1 kiyohara void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
1068 1.1 kiyohara bus_addr_t, bus_size_t, int);
1069 1.1 kiyohara
1070 1.1 kiyohara /*
1071 1.1 kiyohara * DMA memory utility functions.
1072 1.1 kiyohara */
1073 1.1 kiyohara int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
1074 1.1 kiyohara bus_size_t, bus_dma_segment_t *, int, int *, int);
1075 1.1 kiyohara void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int);
1076 1.1 kiyohara int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
1077 1.1 kiyohara int, size_t, void **, int);
1078 1.1 kiyohara void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
1079 1.1 kiyohara paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
1080 1.1 kiyohara int, off_t, int, int);
1081 1.1 kiyohara };
1082 1.1 kiyohara
1083 1.1 kiyohara static __inline void bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t,
1084 1.1 kiyohara bus_addr_t, bus_size_t, int) __attribute__((__unused__));
1085 1.1 kiyohara
1086 1.1 kiyohara #define bus_dmamap_create(t, s, n, m, b, f, p) \
1087 1.1 kiyohara (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
1088 1.1 kiyohara #define bus_dmamap_destroy(t, p) \
1089 1.1 kiyohara (*(t)->_dmamap_destroy)((t), (p))
1090 1.1 kiyohara #define bus_dmamap_load(t, m, b, s, p, f) \
1091 1.1 kiyohara (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
1092 1.1 kiyohara #define bus_dmamap_load_mbuf(t, m, b, f) \
1093 1.1 kiyohara (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
1094 1.1 kiyohara #define bus_dmamap_load_uio(t, m, u, f) \
1095 1.1 kiyohara (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
1096 1.1 kiyohara #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
1097 1.1 kiyohara (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
1098 1.1 kiyohara #define bus_dmamap_unload(t, p) \
1099 1.1 kiyohara (*(t)->_dmamap_unload)((t), (p))
1100 1.1 kiyohara static __inline void
1101 1.1 kiyohara bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t p, bus_addr_t o, bus_size_t l,
1102 1.1 kiyohara int ops)
1103 1.1 kiyohara {
1104 1.1 kiyohara /* if (ops & BUS_DMASYNC_POSTREAD)
1105 1.1 kiyohara x86_lfence(); */
1106 1.1 kiyohara if (t->_dmamap_sync)
1107 1.1 kiyohara (*t->_dmamap_sync)(t, p, o, l, ops);
1108 1.1 kiyohara }
1109 1.1 kiyohara
1110 1.1 kiyohara #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
1111 1.1 kiyohara (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
1112 1.1 kiyohara #define bus_dmamem_free(t, sg, n) \
1113 1.1 kiyohara (*(t)->_dmamem_free)((t), (sg), (n))
1114 1.1 kiyohara #define bus_dmamem_map(t, sg, n, s, k, f) \
1115 1.1 kiyohara (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
1116 1.1 kiyohara #define bus_dmamem_unmap(t, k, s) \
1117 1.1 kiyohara (*(t)->_dmamem_unmap)((t), (k), (s))
1118 1.1 kiyohara #define bus_dmamem_mmap(t, sg, n, o, p, f) \
1119 1.1 kiyohara (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
1120 1.1 kiyohara
1121 1.1 kiyohara /*
1122 1.1 kiyohara * bus_dmamap_t
1123 1.1 kiyohara *
1124 1.1 kiyohara * Describes a DMA mapping.
1125 1.1 kiyohara */
1126 1.1 kiyohara struct ia64_bus_dmamap {
1127 1.1 kiyohara /*
1128 1.1 kiyohara * PRIVATE MEMBERS: not for use by machine-independent code.
1129 1.1 kiyohara */
1130 1.1 kiyohara bus_size_t _dm_size; /* largest DMA transfer mappable */
1131 1.1 kiyohara int _dm_segcnt; /* number of segs this map can map */
1132 1.1 kiyohara bus_size_t _dm_maxmaxsegsz; /* fixed largest possible segment */
1133 1.1 kiyohara bus_size_t _dm_boundary; /* don't cross this */
1134 1.1 kiyohara bus_addr_t _dm_bounce_thresh; /* bounce threshold; see tag */
1135 1.1 kiyohara int _dm_flags; /* misc. flags */
1136 1.1 kiyohara
1137 1.1 kiyohara void *_dm_cookie; /* cookie for bus-specific functions */
1138 1.1 kiyohara
1139 1.1 kiyohara /*
1140 1.1 kiyohara * PUBLIC MEMBERS: these are used by machine-independent code.
1141 1.1 kiyohara */
1142 1.1 kiyohara bus_size_t dm_maxsegsz; /* largest possible segment */
1143 1.1 kiyohara bus_size_t dm_mapsize; /* size of the mapping */
1144 1.1 kiyohara int dm_nsegs; /* # valid segments in mapping */
1145 1.1 kiyohara bus_dma_segment_t dm_segs[1]; /* segments; variable length */
1146 1.1 kiyohara };
1147 1.1 kiyohara
1148 1.1 kiyohara #endif /* _IA64_BUS_H_ */
1149