]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/alpha/include/bus.h
Add a bus_space_unmap() for the puc (and possibly other) drivers.
[FreeBSD/FreeBSD.git] / sys / alpha / include / bus.h
1 /*      $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $    */
2
3 /*-
4  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *      This product includes software developed by the NetBSD
22  *      Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39
40 /*
41  * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
42  * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  * 3. All advertising materials mentioning features or use of this software
53  *    must display the following acknowledgement:
54  *      This product includes software developed by Christopher G. Demetriou
55  *      for the NetBSD Project.
56  * 4. The name of the author may not be used to endorse or promote products
57  *    derived from this software without specific prior written permission
58  *
59  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
60  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
61  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
63  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
64  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
68  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69  */
70 /* $FreeBSD$ */
71
72 #ifndef _ALPHA_BUS_H_
73 #define _ALPHA_BUS_H_
74
75 /*
76  * Bus address and size types
77  */
78 typedef u_int64_t               bus_addr_t;
79 typedef u_int64_t               bus_size_t;
80 typedef struct alpha_busspace   *bus_space_tag_t;
81 typedef u_int32_t               bus_space_handle_t;
82
83 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
84 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
85 #define BUS_SPACE_MAXSIZE       (64 * 1024) /* Maximum supported size */
86 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
87 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
88 /* The largest address space known so far is 40 bits */
89 #define BUS_SPACE_MAXADDR       0xFFFFFFFFFUL
90
91 #define BUS_SPACE_UNRESTRICTED  (~0UL)
92
93 /*
94  * Unmap a region of device bus space.
95  */
96
97 static __inline void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
98                                      bus_size_t size);
99
100 static __inline void
101 bus_space_unmap(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused,
102                 bus_size_t size __unused)
103 {
104 }
105
106
107 /*
108  * Get a new handle for a subregion of an already-mapped area of bus space.
109  */
110
111 static __inline int bus_space_subregion(bus_space_tag_t t,
112                                         bus_space_handle_t bsh,
113                                         bus_size_t offset, bus_size_t size,
114                                         bus_space_handle_t *nbshp);
115
116 static __inline int
117 bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t bsh,
118                     bus_size_t offset, bus_size_t size __unused,
119                     bus_space_handle_t *nbshp)
120 {
121
122         *nbshp = bsh + offset;
123         return (0);
124 }
125
126
127 struct alpha_busspace;
128
129 struct alpha_busspace_ops {
130     u_int8_t    (*abo_read_1)(struct alpha_busspace *space, size_t offset);
131     u_int16_t   (*abo_read_2)(struct alpha_busspace *space, size_t offset);
132     u_int32_t   (*abo_read_4)(struct alpha_busspace *space, size_t offset);
133
134     void        (*abo_read_multi_1)(struct alpha_busspace *space,
135                                     size_t offset,
136                                     u_int8_t *addr, size_t count);
137     void        (*abo_read_multi_2)(struct alpha_busspace *space,
138                                     size_t offset,
139                                     u_int16_t *addr, size_t count);
140     void        (*abo_read_multi_4)(struct alpha_busspace *space,
141                                     size_t offset,
142                                     u_int32_t *addr, size_t count);
143
144     void        (*abo_read_region_1)(struct alpha_busspace *space,
145                                      size_t offset,
146                                      u_int8_t *addr, size_t count);
147     void        (*abo_read_region_2)(struct alpha_busspace *space,
148                                      size_t offset,
149                                      u_int16_t *addr, size_t count);
150     void        (*abo_read_region_4)(struct alpha_busspace *space,
151                                      size_t offset,
152                                      u_int32_t *addr, size_t count);
153
154     void        (*abo_write_1)(struct alpha_busspace *space, size_t offset,
155                                u_int8_t value);
156     void        (*abo_write_2)(struct alpha_busspace *space, size_t offset,
157                                u_int16_t value);
158     void        (*abo_write_4)(struct alpha_busspace *space, size_t offset,
159                                u_int32_t value);
160
161     void        (*abo_write_multi_1)(struct alpha_busspace *space,
162                                      size_t offset,
163                                      const u_int8_t *addr, size_t count);
164     void        (*abo_write_multi_2)(struct alpha_busspace *space,
165                                      size_t offset,
166                                      const u_int16_t *addr, size_t count);
167     void        (*abo_write_multi_4)(struct alpha_busspace *space,
168                                      size_t offset,
169                                      const u_int32_t *addr, size_t count);
170
171     void        (*abo_write_region_1)(struct alpha_busspace *space,
172                                       size_t offset,
173                                       const u_int8_t *addr, size_t count);
174     void        (*abo_write_region_2)(struct alpha_busspace *space,
175                                       size_t offset,
176                                       const u_int16_t *addr, size_t count);
177     void        (*abo_write_region_4)(struct alpha_busspace *space,
178                                       size_t offset,
179                                       const u_int32_t *addr, size_t count);
180
181     void        (*abo_set_multi_1)(struct alpha_busspace *space, size_t offset,
182                                    u_int8_t value, size_t count);
183     void        (*abo_set_multi_2)(struct alpha_busspace *space, size_t offset,
184                                    u_int16_t value, size_t count);
185     void        (*abo_set_multi_4)(struct alpha_busspace *space, size_t offset,
186                                    u_int32_t value, size_t count);
187
188     void        (*abo_set_region_1)(struct alpha_busspace *space,
189                                     size_t offset,
190                                     u_int8_t value, size_t count);
191     void        (*abo_set_region_2)(struct alpha_busspace *space,
192                                     size_t offset,
193                                     u_int16_t value, size_t count);
194     void        (*abo_set_region_4)(struct alpha_busspace *space,
195                                     size_t offset,
196                                     u_int32_t value, size_t count);
197
198     void        (*abo_copy_region_1)(struct alpha_busspace *space,
199                                      size_t offset1, size_t offset2,
200                                      size_t count);
201     void        (*abo_copy_region_2)(struct alpha_busspace *space,
202                                      size_t offset1, size_t offset2,
203                                      size_t count);
204     void        (*abo_copy_region_4)(struct alpha_busspace *space,
205                                      size_t offset1, size_t offset2,
206                                      size_t count);
207
208     void        (*abo_barrier)(struct alpha_busspace *space, size_t offset,
209                                size_t len, int flags);
210 };
211
212 struct alpha_busspace {
213     struct alpha_busspace_ops *ab_ops;
214 };
215
216 /* Back-compat functions for old ISA drivers */
217
218 extern struct alpha_busspace *busspace_isa_io;
219 extern struct alpha_busspace *busspace_isa_mem;
220
221 #define inb(o)          bus_space_read_1(busspace_isa_io, o, 0)
222 #define inw(o)          bus_space_read_2(busspace_isa_io, o, 0)
223 #define inl(o)          bus_space_read_4(busspace_isa_io, o, 0)
224 #define outb(o, v)      bus_space_write_1(busspace_isa_io, o, 0, v)
225 #define outw(o, v)      bus_space_write_2(busspace_isa_io, o, 0, v)
226 #define outl(o, v)      bus_space_write_4(busspace_isa_io, o, 0, v)
227
228 #define readb(o)        bus_space_read_1(busspace_isa_mem, o, 0)
229 #define readw(o)        bus_space_read_2(busspace_isa_mem, o, 0)
230 #define readl(o)        bus_space_read_4(busspace_isa_mem, o, 0)
231 #define writeb(o, v)    bus_space_write_1(busspace_isa_mem, o, 0, v)
232 #define writew(o, v)    bus_space_write_2(busspace_isa_mem, o, 0, v)
233 #define writel(o, v)    bus_space_write_4(busspace_isa_mem, o, 0, v)
234
235 #define insb(o, a, c)   bus_space_read_multi_1(busspace_isa_io, o, 0, \
236                                                (void*)a, c)
237 #define insw(o, a, c)   bus_space_read_multi_2(busspace_isa_io, o, 0, \
238                                                (void*)a, c)
239 #define insl(o, a, c)   bus_space_read_multi_4(busspace_isa_io, o, 0, \
240                                                (void*)a, c)
241
242 #define outsb(o, a, c)  bus_space_write_multi_1(busspace_isa_io, o, 0, \
243                                                 (void*)a, c)
244 #define outsw(o, a, c)  bus_space_write_multi_2(busspace_isa_io, o, 0, \
245                                                 (void*)a, c)
246 #define outsl(o, a, c)  bus_space_write_multi_4(busspace_isa_io, o, 0, \
247                                                 (void*)a, c)
248
249 #define memcpy_fromio(d, s, c) \
250         bus_space_read_region_1(busspace_isa_mem, s, 0, d, c)
251 #define memcpy_toio(d, s, c) \
252         bus_space_write_region_1(busspace_isa_mem, d, 0, s, c)
253 #define memcpy_io(d, s, c) \
254         bus_space_copy_region_1(busspace_isa_mem, s, 0, d, 0, c)
255 #define memset_io(d, v, c) \
256         bus_space_set_region_1(busspace_isa_mem, d, 0, v, c)
257 #define memsetw_io(d, v, c) \
258         bus_space_set_region_2(busspace_isa_mem, d, 0, v, c)
259
260 static __inline void
261 memsetw(void *d, int val, size_t size)
262 {
263     u_int16_t *sp = d;
264
265     while (size--)
266         *sp++ = val;
267 }
268
269 void busspace_generic_read_multi_1(struct alpha_busspace *space,
270                                    size_t offset,
271                                    u_int8_t *addr, size_t count);
272 void busspace_generic_read_multi_2(struct alpha_busspace *space,
273                                    size_t offset,
274                                    u_int16_t *addr, size_t count);
275 void busspace_generic_read_multi_4(struct alpha_busspace *space,
276                                    size_t offset,
277                                    u_int32_t *addr, size_t count);
278 void busspace_generic_read_region_1(struct alpha_busspace *space,
279                                     size_t offset,
280                                     u_int8_t *addr, size_t count);
281 void busspace_generic_read_region_2(struct alpha_busspace *space,
282                                     size_t offset,
283                                     u_int16_t *addr, size_t count);
284 void busspace_generic_read_region_4(struct alpha_busspace *space,
285                                     size_t offset,
286                                     u_int32_t *addr, size_t count);
287 void busspace_generic_write_multi_1(struct alpha_busspace *space,
288                                     size_t offset,
289                                     const u_int8_t *addr, size_t count);
290 void busspace_generic_write_multi_2(struct alpha_busspace *space,
291                                     size_t offset,
292                                     const u_int16_t *addr, size_t count);
293 void busspace_generic_write_multi_4(struct alpha_busspace *space,
294                                     size_t offset,
295                                     const u_int32_t *addr, size_t count);
296 void busspace_generic_write_region_1(struct alpha_busspace *space,
297                                      size_t offset,
298                                      const u_int8_t *addr, size_t count);
299 void busspace_generic_write_region_2(struct alpha_busspace *space,
300                                      size_t offset,
301                                      const u_int16_t *addr, size_t count);
302 void busspace_generic_write_region_4(struct alpha_busspace *space,
303                                      size_t offset,
304                                      const u_int32_t *addr, size_t count);
305 void busspace_generic_set_multi_1(struct alpha_busspace *space,
306                                   size_t offset,
307                                   u_int8_t value, size_t count);
308 void busspace_generic_set_multi_2(struct alpha_busspace *space,
309                                   size_t offset,
310                                   u_int16_t value, size_t count);
311 void busspace_generic_set_multi_4(struct alpha_busspace *space,
312                                   size_t offset,
313                                   u_int32_t value, size_t count);
314 void busspace_generic_set_region_1(struct alpha_busspace *space,
315                                    size_t offset,
316                                    u_int8_t value, size_t count);
317 void busspace_generic_set_region_2(struct alpha_busspace *space,
318                                    size_t offset,
319                                    u_int16_t value, size_t count);
320 void busspace_generic_set_region_4(struct alpha_busspace *space,
321                                    size_t offset,
322                                    u_int32_t value, size_t count);
323 void busspace_generic_copy_region_1(struct alpha_busspace *space,
324                                     size_t offset1,
325                                     size_t offset2,
326                                     size_t count);
327 void busspace_generic_copy_region_2(struct alpha_busspace *space,
328                                     size_t offset1,
329                                     size_t offset2,
330                                     size_t count);
331 void busspace_generic_copy_region_4(struct alpha_busspace *space,
332                                     size_t offset1,
333                                     size_t offset2,
334                                     size_t count);
335 void busspace_generic_barrier(struct alpha_busspace *space,
336                               size_t offset, size_t len,
337                               int flags);
338
339 #define BUS_SPACE_BARRIER_READ  0x01            /* force read barrier */
340 #define BUS_SPACE_BARRIER_WRITE 0x02            /* force write barrier */
341
342 #define bus_space_read_1(t, h, o) \
343         (t)->ab_ops->abo_read_1(t, (h)+(o))
344 #define bus_space_read_2(t, h, o) \
345         (t)->ab_ops->abo_read_2(t, (h)+(o))
346 #define bus_space_read_4(t, h, o) \
347         (t)->ab_ops->abo_read_4(t, (h)+(o))
348 #define bus_space_read_multi_1(t, h, o, a, c) \
349         (t)->ab_ops->abo_read_multi_1(t, (h)+(o), a, c)
350 #define bus_space_read_multi_2(t, h, o, a, c) \
351         (t)->ab_ops->abo_read_multi_2(t, (h)+(o), a, c)
352 #define bus_space_read_multi_4(t, h, o, a, c) \
353         (t)->ab_ops->abo_read_multi_4(t, (h)+(o), a, c)
354 #define bus_space_read_region_1(t, h, o, a, c) \
355         (t)->ab_ops->abo_read_region_1(t, (h)+(o), a, c)
356 #define bus_space_read_region_2(t, h, o, a, c) \
357         (t)->ab_ops->abo_read_region_2(t, (h)+(o), a, c)
358 #define bus_space_read_region_4(t, h, o, a, c) \
359         (t)->ab_ops->abo_read_region_4(t, (h)+(o), a, c)
360
361 #define bus_space_write_1(t, h, o, v) \
362         (t)->ab_ops->abo_write_1(t, (h)+(o), v)
363 #define bus_space_write_2(t, h, o, v) \
364         (t)->ab_ops->abo_write_2(t, (h)+(o), v)
365 #define bus_space_write_4(t, h, o, v) \
366         (t)->ab_ops->abo_write_4(t, (h)+(o), v)
367 #define bus_space_write_multi_1(t, h, o, a, c) \
368         (t)->ab_ops->abo_write_multi_1(t, (h)+(o), a, c)
369 #define bus_space_write_multi_2(t, h, o, a, c) \
370         (t)->ab_ops->abo_write_multi_2(t, (h)+(o), a, c)
371 #define bus_space_write_multi_4(t, h, o, a, c) \
372         (t)->ab_ops->abo_write_multi_4(t, (h)+(o), a, c)
373 #define bus_space_write_region_1(t, h, o, a, c) \
374         (t)->ab_ops->abo_write_region_1(t, (h)+(o), a, c)
375 #define bus_space_write_region_2(t, h, o, a, c) \
376         (t)->ab_ops->abo_write_region_2(t, (h)+(o), a, c)
377 #define bus_space_write_region_4(t, h, o, a, c) \
378         (t)->ab_ops->abo_write_region_4(t, (h)+(o), a, c)
379 #define bus_space_set_multi_1(t, h, o, v, c) \
380         (t)->ab_ops->abo_set_multi_1(t, (h)+(o), v, c)
381 #define bus_space_set_multi_2(t, h, o, v, c) \
382         (t)->ab_ops->abo_set_multi_2(t, (h)+(o), v, c)
383 #define bus_space_set_multi_4(t, h, o, v, c) \
384         (t)->ab_ops->abo_set_multi_4(t, (h)+(o), v, c)
385 #define bus_space_set_region_1(t, h, o, v, c) \
386         (t)->ab_ops->abo_set_region_1(t, (h)+(o), v, c)
387 #define bus_space_set_region_2(t, h, o, v, c) \
388         (t)->ab_ops->abo_set_region_2(t, (h)+(o), v, c)
389 #define bus_space_set_region_4(t, h, o, v, c) \
390         (t)->ab_ops->abo_set_region_4(t, (h)+(o), v, c)
391
392 #define bus_space_copy_region_1(t, h1, o1, h2, o2, c) \
393         (t)->ab_ops->abo_copy_region_1(t, (h1)+(o1), (h2)+(o2), c)
394 #define bus_space_copy_region_2(t, h1, o1, h2, o2, c) \
395         (t)->ab_ops->abo_copy_region_2(t, (h1)+(o1), (h2)+(o2), c)
396 #define bus_space_copy_region_4(t, h1, o1, h2, o2, c) \
397         (t)->ab_ops->abo_copy_region_4(t, (h1)+(o1), (h2)+(o2), c)
398
399 #define bus_space_barrier(t, h, o, l, f) \
400         (t)->ab_ops->abo_barrier(t, (h)+(o), l, f)
401
402 /*
403  * Stream accesses are the same as normal accesses on alpha; there are no
404  * supported bus systems with an endianess different from the host one.
405  */
406 #define bus_space_read_stream_1(t, h, o)        bus_space_read_1((t), (h), (o))
407 #define bus_space_read_stream_2(t, h, o)        bus_space_read_2((t), (h), (o))
408 #define bus_space_read_stream_4(t, h, o)        bus_space_read_4((t), (h), (o))
409
410 #define bus_space_read_multi_stream_1(t, h, o, a, c) \
411         bus_space_read_multi_1((t), (h), (o), (a), (c))
412 #define bus_space_read_multi_stream_2(t, h, o, a, c) \
413         bus_space_read_multi_2((t), (h), (o), (a), (c))
414 #define bus_space_read_multi_stream_4(t, h, o, a, c) \
415         bus_space_read_multi_4((t), (h), (o), (a), (c))
416
417 #define bus_space_write_stream_1(t, h, o, v) \
418         bus_space_write_1((t), (h), (o), (v))
419 #define bus_space_write_stream_2(t, h, o, v) \
420         bus_space_write_2((t), (h), (o), (v))
421 #define bus_space_write_stream_4(t, h, o, v) \
422         bus_space_write_4((t), (h), (o), (v))
423
424 #define bus_space_write_multi_stream_1(t, h, o, a, c) \
425         bus_space_write_multi_1((t), (h), (o), (a), (c))
426 #define bus_space_write_multi_stream_2(t, h, o, a, c) \
427         bus_space_write_multi_2((t), (h), (o), (a), (c))
428 #define bus_space_write_multi_stream_4(t, h, o, a, c) \
429         bus_space_write_multi_4((t), (h), (o), (a), (c))
430
431 #define bus_space_set_multi_stream_1(t, h, o, v, c) \
432         bus_space_set_multi_1((t), (h), (o), (v), (c))
433 #define bus_space_set_multi_stream_2(t, h, o, v, c) \
434         bus_space_set_multi_2((t), (h), (o), (v), (c))
435 #define bus_space_set_multi_stream_4(t, h, o, v, c) \
436         bus_space_set_multi_4((t), (h), (o), (v), (c))
437
438 #define bus_space_read_region_stream_1(t, h, o, a, c) \
439         bus_space_read_region_1((t), (h), (o), (a), (c))
440 #define bus_space_read_region_stream_2(t, h, o, a, c) \
441         bus_space_read_region_2((t), (h), (o), (a), (c))
442 #define bus_space_read_region_stream_4(t, h, o, a, c) \
443         bus_space_read_region_4((t), (h), (o), (a), (c))
444
445 #define bus_space_write_region_stream_1(t, h, o, a, c) \
446         bus_space_write_region_1((t), (h), (o), (a), (c))
447 #define bus_space_write_region_stream_2(t, h, o, a, c) \
448         bus_space_write_region_2((t), (h), (o), (a), (c))
449 #define bus_space_write_region_stream_4(t, h, o, a, c) \
450         bus_space_write_region_4((t), (h), (o), (a), (c))
451
452 #define bus_space_set_region_stream_1(t, h, o, v, c) \
453         bus_space_set_region_1((t), (h), (o), (v), (c))
454 #define bus_space_set_region_stream_2(t, h, o, v, c) \
455         bus_space_set_region_2((t), (h), (o), (v), (c))
456 #define bus_space_set_region_stream_4(t, h, o, v, c) \
457         bus_space_set_region_4((t), (h), (o), (v), (c))
458
459 #define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
460         bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
461 #define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
462         bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
463 #define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
464         bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
465
466 /*
467  * Flags used in various bus DMA methods.
468  */
469 #define BUS_DMA_WAITOK          0x00    /* safe to sleep (pseudo-flag) */
470 #define BUS_DMA_NOWAIT          0x01    /* not safe to sleep */
471 #define BUS_DMA_ALLOCNOW        0x02    /* perform resource allocation now */
472 #define BUS_DMAMEM_NOSYNC       0x04    /* map memory to not require sync */
473 #define BUS_DMA_ISA             0x10    /* map memory for ISA dma */
474 #define BUS_DMA_BUS2            0x20    /* placeholders for bus functions... */
475 #define BUS_DMA_BUS3            0x40
476 #define BUS_DMA_BUS4            0x80
477
478 /* Forwards needed by prototypes below. */
479 struct mbuf;
480 struct uio;
481
482 /*
483  *      bus_dmasync_op_t
484  *
485  *      Operations performed by bus_dmamap_sync().
486  */
487 typedef enum {
488         BUS_DMASYNC_PREREAD,
489         BUS_DMASYNC_POSTREAD,
490         BUS_DMASYNC_PREWRITE,
491         BUS_DMASYNC_POSTWRITE
492 } bus_dmasync_op_t;
493
494 /*
495  *      bus_dma_tag_t
496  *
497  *      A machine-dependent opaque type describing the characteristics
498  *      of how to perform DMA mappings.  This structure encapsultes
499  *      information concerning address and alignment restrictions, number
500  *      of S/G  segments, amount of data per S/G segment, etc.
501  */
502 typedef struct bus_dma_tag      *bus_dma_tag_t;
503
504 /*
505  *      bus_dmamap_t
506  *
507  *      DMA mapping instance information.
508  */
509 typedef struct bus_dmamap       *bus_dmamap_t;
510
511 /*
512  *      bus_dma_segment_t
513  *
514  *      Describes a single contiguous DMA transaction.  Values
515  *      are suitable for programming into DMA registers.
516  */
517 typedef struct bus_dma_segment {
518         bus_addr_t      ds_addr;        /* DMA address */
519         bus_size_t      ds_len;         /* length of transfer */
520 } bus_dma_segment_t;
521
522 /*
523  * A function that returns 1 if the address cannot be accessed by
524  * a device and 0 if it can be.
525  */
526 typedef int bus_dma_filter_t(void *, bus_addr_t);
527
528 /*
529  * Allocate a device specific dma_tag encapsulating the constraints of
530  * the parent tag in addition to other restrictions specified:
531  *
532  *      alignment:      alignment for segments.
533  *      boundary:       Boundary that segments cannot cross.
534  *      lowaddr:        Low restricted address that cannot appear in a mapping.
535  *      highaddr:       High restricted address that cannot appear in a mapping.
536  *      filtfunc:       An optional function to further test if an address
537  *                      within the range of lowaddr and highaddr cannot appear
538  *                      in a mapping.
539  *      filtfuncarg:    An argument that will be passed to filtfunc in addition
540  *                      to the address to test.
541  *      maxsize:        Maximum mapping size supported by this tag.
542  *      nsegments:      Number of discontinuities allowed in maps.
543  *      maxsegsz:       Maximum size of a segment in the map.
544  *      flags:          Bus DMA flags.
545  *      dmat:           A pointer to set to a valid dma tag should the return
546  *                      value of this function indicate success.
547  */
548 /* XXX Should probably allow specification of alignment */
549 int bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignemnt,
550                        bus_size_t boundary, bus_addr_t lowaddr,
551                        bus_addr_t highaddr, bus_dma_filter_t *filtfunc,
552                        void *filtfuncarg, bus_size_t maxsize, int nsegments,
553                        bus_size_t maxsegsz, int flags, bus_dma_tag_t *dmat);
554
555 int bus_dma_tag_destroy(bus_dma_tag_t dmat);
556
557 /*
558  * Allocate a handle for mapping from kva/uva/physical
559  * address space into bus device space.
560  */
561 int bus_dmamap_create(bus_dma_tag_t dmat, int flags, bus_dmamap_t *mapp);
562
563 /*
564  * Destroy  a handle for mapping from kva/uva/physical
565  * address space into bus device space.
566  */
567 int bus_dmamap_destroy(bus_dma_tag_t dmat, bus_dmamap_t map);
568
569 /*
570  * Allocate a piece of memory that can be efficiently mapped into
571  * bus device space based on the constraints lited in the dma tag.
572  * A dmamap to for use with dmamap_load is also allocated.
573  */
574 int bus_dmamem_alloc(bus_dma_tag_t dmat, void** vaddr, int flags,
575                      bus_dmamap_t *mapp);
576
577 /*
578  * Free a piece of memory and it's allociated dmamap, that was allocated
579  * via bus_dmamem_alloc.
580  */
581 void bus_dmamem_free(bus_dma_tag_t dmat, void *vaddr, bus_dmamap_t map);
582
583 /*
584  * A function that processes a successfully loaded dma map or an error
585  * from a delayed load map.
586  */
587 typedef void bus_dmamap_callback_t(void *, bus_dma_segment_t *, int, int);
588
589 /*
590  * Map the buffer buf into bus space using the dmamap map.
591  */
592 int bus_dmamap_load(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
593                     bus_size_t buflen, bus_dmamap_callback_t *callback,
594                     void *callback_arg, int flags);
595
596 /*
597  * Like bus_dmamap_callback but includes map size in bytes.  This is
598  * defined as a separate interface to maintain compatiiblity for users
599  * of bus_dmamap_callback_t--at some point these interfaces should be merged.
600  */
601 typedef void bus_dmamap_callback2_t(void *, bus_dma_segment_t *, int, bus_size_t, int);
602 /*
603  * Like bus_dmamap_load but for mbufs.  Note the use of the
604  * bus_dmamap_callback2_t interface.
605  */
606 int bus_dmamap_load_mbuf(bus_dma_tag_t dmat, bus_dmamap_t map,
607                          struct mbuf *mbuf,
608                          bus_dmamap_callback2_t *callback, void *callback_arg,
609                          int flags);
610 /*
611  * Like bus_dmamap_load but for uios.  Note the use of the
612  * bus_dmamap_callback2_t interface.
613  */
614 int bus_dmamap_load_uio(bus_dma_tag_t dmat, bus_dmamap_t map,
615                         struct uio *ui,
616                         bus_dmamap_callback2_t *callback, void *callback_arg,
617                         int flags);
618
619 /*
620  * Perform a syncronization operation on the given map.
621  */
622 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_dmasync_op_t);
623 #define bus_dmamap_sync(dmat, dmamap, op)               \
624         if ((dmamap) != NULL)                           \
625                 _bus_dmamap_sync(dmat, dmamap, op)
626
627 /*
628  * Release the mapping held by map.
629  */
630 void _bus_dmamap_unload(bus_dma_tag_t dmat, bus_dmamap_t map);
631 #define bus_dmamap_unload(dmat, dmamap)                 \
632         if ((dmamap) != NULL)                           \
633                 _bus_dmamap_unload(dmat, dmamap)
634
635 #endif /* _ALPHA_BUS_H_ */