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