bus_funcs.h revision 1.1 1 /* $NetBSD: bus_funcs.h,v 1.1 2011/07/01 17:10:01 dyoung Exp $ */
2
3 /*-
4 * Copyright (c) 1996, 1997, 1998, 2001 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 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
35 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by Christopher G. Demetriou
48 * for the NetBSD Project.
49 * 4. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
53 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
54 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
55 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
56 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
57 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
61 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 */
63
64 #ifndef _SPARC_BUS_FUNCS_H_
65 #define _SPARC_BUS_FUNCS_H_
66
67 bus_space_tag_t bus_space_tag_alloc(bus_space_tag_t, void *);
68 int bus_space_translate_address_generic(struct openprom_range *,
69 int, bus_addr_t *);
70
71 /*
72 * Bus space function prototypes.
73 * In bus_space_map2(), supply a special virtual address only if you
74 * get it from ../sparc/vaddrs.h.
75 */
76 int bus_space_map2(
77 bus_space_tag_t,
78 bus_addr_t,
79 bus_size_t,
80 int, /*flags*/
81 vaddr_t, /*preferred vaddr*/
82 bus_space_handle_t *);
83 void *bus_intr_establish(
84 bus_space_tag_t,
85 int, /*bus-specific intr*/
86 int, /*device class level,
87 see machine/intr.h*/
88 int (*)(void *), /*handler*/
89 void *); /*handler arg*/
90 void *bus_intr_establish2(
91 bus_space_tag_t,
92 int, /*bus-specific intr*/
93 int, /*device class level,
94 see machine/intr.h*/
95 int (*)(void *), /*handler*/
96 void *, /*handler arg*/
97 void (*)(void)); /*optional fast vector*/
98
99 #define bus_space_vaddr(t, h) ((void)(t), (void *)(h))
100
101 /*
102 * Device space probe assistant.
103 * The optional callback function's arguments are:
104 * the temporary virtual address
105 * the passed `arg' argument
106 */
107 int bus_space_probe(
108 bus_space_tag_t,
109 bus_addr_t,
110 bus_size_t, /* probe size */
111 size_t, /* offset */
112 int, /* flags */
113 int (*)(void *, void *), /* callback function */
114 void *); /* callback arg */
115
116 /*
117 * u_intN_t bus_space_read_N(bus_space_tag_t tag,
118 * bus_space_handle_t bsh, bus_size_t offset);
119 *
120 * Read a 1, 2, 4, or 8 byte quantity from bus space
121 * described by tag/handle/offset.
122 */
123
124 #define bus_space_read_1_real(t, h, o) \
125 ((void)(t), *(volatile uint8_t *)((h) + (o)))
126
127 #define bus_space_read_2_real(t, h, o) \
128 ((void)(t), *(volatile uint16_t *)((h) + (o)))
129
130 #define bus_space_read_4_real(t, h, o) \
131 ((void)(t), *(volatile uint32_t *)((h) + (o)))
132
133 #define bus_space_read_8_real(t, h, o) \
134 ((void)(t), *(volatile uint64_t *)((h) + (o)))
135
136 #define bus_space_read_stream_1 bus_space_read_1_real
137 #define bus_space_read_stream_2 bus_space_read_2_real
138 #define bus_space_read_stream_4 bus_space_read_4_real
139 #define bus_space_read_stream_8 bus_space_read_8_real
140
141
142 /*
143 * void bus_space_write_N(bus_space_tag_t tag,
144 * bus_space_handle_t bsh, bus_size_t offset,
145 * u_intN_t value);
146 *
147 * Write the 1, 2, 4, or 8 byte value `value' to bus space
148 * described by tag/handle/offset.
149 */
150
151 #define bus_space_write_1_real(t, h, o, v) do { \
152 ((void)(t), (void)(*(volatile uint8_t *)((h) + (o)) = (v))); \
153 } while (/* CONSTCOND */ 0)
154
155 #define bus_space_write_2_real(t, h, o, v) do { \
156 ((void)(t), (void)(*(volatile uint16_t *)((h) + (o)) = (v))); \
157 } while (/* CONSTCOND */ 0)
158
159 #define bus_space_write_4_real(t, h, o, v) do { \
160 ((void)(t), (void)(*(volatile uint32_t *)((h) + (o)) = (v))); \
161 } while (/* CONSTCOND */ 0)
162
163 #define bus_space_write_8_real(t, h, o, v) do { \
164 ((void)(t), (void)(*(volatile uint64_t *)((h) + (o)) = (v))); \
165 } while (/* CONSTCOND */ 0)
166
167 #define bus_space_write_stream_1 bus_space_write_1_real
168 #define bus_space_write_stream_2 bus_space_write_2_real
169 #define bus_space_write_stream_4 bus_space_write_4_real
170 #define bus_space_write_stream_8 bus_space_write_8_real
171
172 #define bus_space_read_multi_stream_1 bus_space_read_multi_1
173 #define bus_space_write_multi_stream_1 bus_space_write_multi_1
174
175 /* Forwards needed by prototypes below. */
176 struct mbuf;
177 struct uio;
178
179 #define bus_dmamap_create(t, s, n, m, b, f, p) \
180 (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
181 #define bus_dmamap_destroy(t, p) \
182 (*(t)->_dmamap_destroy)((t), (p))
183 #define bus_dmamap_load(t, m, b, s, p, f) \
184 (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
185 #define bus_dmamap_load_mbuf(t, m, b, f) \
186 (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
187 #define bus_dmamap_load_uio(t, m, u, f) \
188 (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
189 #define bus_dmamap_load_raw(t, m, sg, n, s, f) \
190 (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
191 #define bus_dmamap_unload(t, p) \
192 (*(t)->_dmamap_unload)((t), (p))
193 #define bus_dmamap_sync(t, p, o, l, ops) \
194 (void)((t)->_dmamap_sync ? \
195 (*(t)->_dmamap_sync)((t), (p), (o), (l), (ops)) : (void)0)
196
197 #define bus_dmamem_alloc(t, s, a, b, sg, n, r, f) \
198 (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
199 #define bus_dmamem_free(t, sg, n) \
200 (*(t)->_dmamem_free)((t), (sg), (n))
201 #define bus_dmamem_map(t, sg, n, s, k, f) \
202 (*(t)->_dmamem_map)((t), (sg), (n), (s), (k), (f))
203 #define bus_dmamem_unmap(t, k, s) \
204 (*(t)->_dmamem_unmap)((t), (k), (s))
205 #define bus_dmamem_mmap(t, sg, n, o, p, f) \
206 (*(t)->_dmamem_mmap)((t), (sg), (n), (o), (p), (f))
207
208 #define bus_dmatag_subregion(t, mna, mxa, nt, f) EOPNOTSUPP
209 #define bus_dmatag_destroy(t)
210
211 #ifdef _SPARC_BUS_DMA_PRIVATE
212 int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
213 bus_size_t, int, bus_dmamap_t *);
214 void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
215 int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
216 struct mbuf *, int);
217 int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
218 struct uio *, int);
219 int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
220 bus_dma_segment_t *, int, bus_size_t, int);
221 void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
222 void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
223 bus_size_t, int);
224
225 int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
226 bus_size_t alignment, bus_size_t boundary,
227 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
228 void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
229 int nsegs);
230 void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva,
231 size_t size);
232 paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
233 int nsegs, off_t off, int prot, int flags);
234
235 int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
236 bus_size_t alignment, bus_size_t boundary,
237 bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
238 vaddr_t low, vaddr_t high);
239
240 vaddr_t _bus_dma_valloc_skewed(size_t, u_long, u_long, u_long);
241 #endif /* _SPARC_BUS_DMA_PRIVATE */
242
243 #endif /* _SPARC_BUS_FUNCS_H_ */
244