bus_private.h revision 1.13 1 1.13 dyoung /* $NetBSD: bus_private.h,v 1.13 2011/08/31 20:21:06 dyoung Exp $ */
2 1.1 yamt /* NetBSD: bus.h,v 1.8 2005/03/09 19:04:46 matt Exp */
3 1.1 yamt
4 1.1 yamt /*-
5 1.1 yamt * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
6 1.1 yamt * All rights reserved.
7 1.1 yamt *
8 1.1 yamt * This code is derived from software contributed to The NetBSD Foundation
9 1.1 yamt * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 1.1 yamt * NASA Ames Research Center.
11 1.1 yamt *
12 1.1 yamt * Redistribution and use in source and binary forms, with or without
13 1.1 yamt * modification, are permitted provided that the following conditions
14 1.1 yamt * are met:
15 1.1 yamt * 1. Redistributions of source code must retain the above copyright
16 1.1 yamt * notice, this list of conditions and the following disclaimer.
17 1.1 yamt * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 yamt * notice, this list of conditions and the following disclaimer in the
19 1.1 yamt * documentation and/or other materials provided with the distribution.
20 1.1 yamt *
21 1.1 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 1.1 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.1 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 1.1 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 1.1 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 1.1 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 1.1 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1 yamt * POSSIBILITY OF SUCH DAMAGE.
32 1.1 yamt */
33 1.1 yamt
34 1.1 yamt /*
35 1.1 yamt * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
36 1.1 yamt * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
37 1.1 yamt *
38 1.1 yamt * Redistribution and use in source and binary forms, with or without
39 1.1 yamt * modification, are permitted provided that the following conditions
40 1.1 yamt * are met:
41 1.1 yamt * 1. Redistributions of source code must retain the above copyright
42 1.1 yamt * notice, this list of conditions and the following disclaimer.
43 1.1 yamt * 2. Redistributions in binary form must reproduce the above copyright
44 1.1 yamt * notice, this list of conditions and the following disclaimer in the
45 1.1 yamt * documentation and/or other materials provided with the distribution.
46 1.1 yamt * 3. All advertising materials mentioning features or use of this software
47 1.1 yamt * must display the following acknowledgement:
48 1.1 yamt * This product includes software developed by Christopher G. Demetriou
49 1.1 yamt * for the NetBSD Project.
50 1.1 yamt * 4. The name of the author may not be used to endorse or promote products
51 1.1 yamt * derived from this software without specific prior written permission
52 1.1 yamt *
53 1.1 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
54 1.1 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55 1.1 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 1.1 yamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
57 1.1 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58 1.1 yamt * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 1.1 yamt * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 1.1 yamt * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 1.1 yamt * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
62 1.1 yamt * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 1.1 yamt */
64 1.1 yamt
65 1.1 yamt #if !defined(_X86_BUS_PRIVATE_H_)
66 1.1 yamt #define _X86_BUS_PRIVATE_H_
67 1.1 yamt
68 1.1 yamt int _bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t,
69 1.1 yamt bus_size_t, int, bus_dmamap_t *);
70 1.1 yamt void _bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
71 1.1 yamt int _bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
72 1.1 yamt bus_size_t, struct proc *, int);
73 1.1 yamt int _bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
74 1.1 yamt struct mbuf *, int);
75 1.1 yamt int _bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
76 1.1 yamt struct uio *, int);
77 1.1 yamt int _bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
78 1.1 yamt bus_dma_segment_t *, int, bus_size_t, int);
79 1.1 yamt void _bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
80 1.1 yamt void _bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t,
81 1.1 yamt bus_size_t, int);
82 1.1 yamt
83 1.1 yamt int _bus_dmamem_alloc(bus_dma_tag_t tag, bus_size_t size,
84 1.1 yamt bus_size_t alignment, bus_size_t boundary,
85 1.1 yamt bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags);
86 1.1 yamt void _bus_dmamem_free(bus_dma_tag_t tag, bus_dma_segment_t *segs,
87 1.1 yamt int nsegs);
88 1.1 yamt int _bus_dmamem_map(bus_dma_tag_t tag, bus_dma_segment_t *segs,
89 1.8 christos int nsegs, size_t size, void **kvap, int flags);
90 1.8 christos void _bus_dmamem_unmap(bus_dma_tag_t tag, void *kva, size_t size);
91 1.1 yamt paddr_t _bus_dmamem_mmap(bus_dma_tag_t tag, bus_dma_segment_t *segs,
92 1.1 yamt int nsegs, off_t off, int prot, int flags);
93 1.1 yamt
94 1.7 mrg int _bus_dmatag_subregion(bus_dma_tag_t tag, bus_addr_t min_addr,
95 1.7 mrg bus_addr_t max_addr, bus_dma_tag_t *newtag, int flags);
96 1.7 mrg void _bus_dmatag_destroy(bus_dma_tag_t tag);
97 1.7 mrg
98 1.3 bouyer #ifndef _BUS_DMAMEM_ALLOC_RANGE
99 1.1 yamt int _bus_dmamem_alloc_range(bus_dma_tag_t tag, bus_size_t size,
100 1.1 yamt bus_size_t alignment, bus_size_t boundary,
101 1.1 yamt bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags,
102 1.2 bouyer bus_addr_t low, bus_addr_t high);
103 1.2 bouyer #endif
104 1.1 yamt
105 1.1 yamt /*
106 1.1 yamt * Cookie used for bounce buffers. A pointer to one of these it stashed in
107 1.1 yamt * the DMA map.
108 1.1 yamt */
109 1.1 yamt struct x86_bus_dma_cookie {
110 1.1 yamt int id_flags; /* flags; see below */
111 1.1 yamt
112 1.1 yamt /*
113 1.1 yamt * Information about the original buffer used during
114 1.1 yamt * DMA map syncs. Note that origibuflen is only used
115 1.1 yamt * for ID_BUFTYPE_LINEAR.
116 1.1 yamt */
117 1.1 yamt void *id_origbuf; /* pointer to orig buffer if
118 1.1 yamt bouncing */
119 1.1 yamt bus_size_t id_origbuflen; /* ...and size */
120 1.1 yamt int id_buftype; /* type of buffer */
121 1.1 yamt
122 1.1 yamt void *id_bouncebuf; /* pointer to the bounce buffer */
123 1.1 yamt bus_size_t id_bouncebuflen; /* ...and size */
124 1.1 yamt int id_nbouncesegs; /* number of valid bounce segs */
125 1.1 yamt bus_dma_segment_t id_bouncesegs[0]; /* array of bounce buffer
126 1.1 yamt physical memory segments */
127 1.1 yamt };
128 1.1 yamt
129 1.1 yamt /* id_flags */
130 1.1 yamt #define X86_DMA_MIGHT_NEED_BOUNCE 0x01 /* may need bounce buffers */
131 1.1 yamt #define X86_DMA_HAS_BOUNCE 0x02 /* has bounce buffers */
132 1.1 yamt #define X86_DMA_IS_BOUNCING 0x04 /* is bouncing current xfer */
133 1.1 yamt
134 1.1 yamt /* id_buftype */
135 1.1 yamt #define X86_DMA_BUFTYPE_INVALID 0
136 1.1 yamt #define X86_DMA_BUFTYPE_LINEAR 1
137 1.1 yamt #define X86_DMA_BUFTYPE_MBUF 2
138 1.1 yamt #define X86_DMA_BUFTYPE_UIO 3
139 1.1 yamt #define X86_DMA_BUFTYPE_RAW 4
140 1.1 yamt
141 1.1 yamt /*
142 1.1 yamt * default address translation macros, which are appropriate where
143 1.1 yamt * paddr_t == bus_addr_t.
144 1.1 yamt */
145 1.1 yamt
146 1.1 yamt #if !defined(_BUS_PHYS_TO_BUS)
147 1.1 yamt #define _BUS_PHYS_TO_BUS(pa) ((bus_addr_t)(pa))
148 1.1 yamt #endif /* !defined(_BUS_PHYS_TO_BUS) */
149 1.1 yamt
150 1.6 bouyer #if !defined(_BUS_BUS_TO_PHYS)
151 1.6 bouyer #define _BUS_BUS_TO_PHYS(ba) ((paddr_t)(ba))
152 1.6 bouyer #endif /* !defined(_BUS_BUS_TO_PHYS) */
153 1.6 bouyer
154 1.1 yamt #if !defined(_BUS_VM_PAGE_TO_BUS)
155 1.1 yamt #define _BUS_VM_PAGE_TO_BUS(pg) _BUS_PHYS_TO_BUS(VM_PAGE_TO_PHYS(pg))
156 1.1 yamt #endif /* !defined(_BUS_VM_PAGE_TO_BUS) */
157 1.1 yamt
158 1.6 bouyer #if !defined(_BUS_BUS_TO_VM_PAGE)
159 1.6 bouyer #define _BUS_BUS_TO_VM_PAGE(ba) PHYS_TO_VM_PAGE(ba)
160 1.6 bouyer #endif /* !defined(_BUS_BUS_TO_VM_PAGE) */
161 1.6 bouyer
162 1.6 bouyer #if !defined(_BUS_PMAP_ENTER)
163 1.6 bouyer #define _BUS_PMAP_ENTER(pmap, va, ba, prot, flags) \
164 1.6 bouyer pmap_enter(pmap, va, ba, prot, flags)
165 1.6 bouyer #endif /* _BUS_PMAP_ENTER */
166 1.6 bouyer
167 1.1 yamt #if !defined(_BUS_VIRT_TO_BUS)
168 1.12 uebayasi #include <uvm/uvm.h>
169 1.1 yamt
170 1.5 perry static __inline bus_addr_t _bus_virt_to_bus(struct pmap *, vaddr_t);
171 1.1 yamt #define _BUS_VIRT_TO_BUS(pm, va) _bus_virt_to_bus((pm), (va))
172 1.1 yamt
173 1.5 perry static __inline bus_addr_t
174 1.1 yamt _bus_virt_to_bus(struct pmap *pm, vaddr_t va)
175 1.1 yamt {
176 1.1 yamt paddr_t pa;
177 1.1 yamt
178 1.1 yamt if (!pmap_extract(pm, va, &pa)) {
179 1.1 yamt panic("_bus_virt_to_bus");
180 1.1 yamt }
181 1.1 yamt
182 1.1 yamt return _BUS_PHYS_TO_BUS(pa);
183 1.1 yamt }
184 1.1 yamt #endif /* !defined(_BUS_VIRT_TO_BUS) */
185 1.1 yamt
186 1.2 bouyer /*
187 1.2 bouyer * by default, the end address of RAM visible on bus is the same as the
188 1.2 bouyer * largest physical address.
189 1.2 bouyer */
190 1.2 bouyer #ifndef _BUS_AVAIL_END
191 1.2 bouyer #define _BUS_AVAIL_END (avail_end)
192 1.2 bouyer #endif
193 1.2 bouyer
194 1.9 ad struct x86_bus_dma_tag {
195 1.13 dyoung bus_dma_tag_t bdt_super;
196 1.13 dyoung /* bdt_present: bitmap indicating overrides present (1) in *this* tag,
197 1.13 dyoung * bdt_exists: bitmap indicating overrides present (1) in *this* tag
198 1.13 dyoung * or in an ancestor's tag (follow bdt_super to ancestors)
199 1.13 dyoung */
200 1.13 dyoung uint64_t bdt_present;
201 1.13 dyoung uint64_t bdt_exists;
202 1.13 dyoung const struct bus_dma_overrides *bdt_ov;
203 1.13 dyoung void *bdt_ctx;
204 1.9 ad /*
205 1.9 ad * The `bounce threshold' is checked while we are loading
206 1.9 ad * the DMA map. If the physical address of the segment
207 1.9 ad * exceeds the threshold, an error will be returned. The
208 1.9 ad * caller can then take whatever action is necessary to
209 1.9 ad * bounce the transfer. If this value is 0, it will be
210 1.9 ad * ignored.
211 1.9 ad */
212 1.9 ad int _tag_needs_free;
213 1.9 ad bus_addr_t _bounce_thresh;
214 1.9 ad bus_addr_t _bounce_alloc_lo;
215 1.9 ad bus_addr_t _bounce_alloc_hi;
216 1.9 ad int (*_may_bounce)(bus_dma_tag_t, bus_dmamap_t, int, int *);
217 1.9 ad
218 1.9 ad /*
219 1.9 ad * DMA mapping methods.
220 1.9 ad */
221 1.9 ad int (*_dmamap_create)(bus_dma_tag_t, bus_size_t, int,
222 1.9 ad bus_size_t, bus_size_t, int, bus_dmamap_t *);
223 1.9 ad void (*_dmamap_destroy)(bus_dma_tag_t, bus_dmamap_t);
224 1.9 ad int (*_dmamap_load)(bus_dma_tag_t, bus_dmamap_t, void *,
225 1.9 ad bus_size_t, struct proc *, int);
226 1.9 ad int (*_dmamap_load_mbuf)(bus_dma_tag_t, bus_dmamap_t,
227 1.9 ad struct mbuf *, int);
228 1.9 ad int (*_dmamap_load_uio)(bus_dma_tag_t, bus_dmamap_t,
229 1.9 ad struct uio *, int);
230 1.9 ad int (*_dmamap_load_raw)(bus_dma_tag_t, bus_dmamap_t,
231 1.9 ad bus_dma_segment_t *, int, bus_size_t, int);
232 1.9 ad void (*_dmamap_unload)(bus_dma_tag_t, bus_dmamap_t);
233 1.9 ad void (*_dmamap_sync)(bus_dma_tag_t, bus_dmamap_t,
234 1.9 ad bus_addr_t, bus_size_t, int);
235 1.9 ad
236 1.9 ad /*
237 1.9 ad * DMA memory utility functions.
238 1.9 ad */
239 1.9 ad int (*_dmamem_alloc)(bus_dma_tag_t, bus_size_t, bus_size_t,
240 1.9 ad bus_size_t, bus_dma_segment_t *, int, int *, int);
241 1.9 ad void (*_dmamem_free)(bus_dma_tag_t, bus_dma_segment_t *, int);
242 1.9 ad int (*_dmamem_map)(bus_dma_tag_t, bus_dma_segment_t *,
243 1.9 ad int, size_t, void **, int);
244 1.9 ad void (*_dmamem_unmap)(bus_dma_tag_t, void *, size_t);
245 1.9 ad paddr_t (*_dmamem_mmap)(bus_dma_tag_t, bus_dma_segment_t *,
246 1.9 ad int, off_t, int, int);
247 1.9 ad int (*_dmatag_subregion)(bus_dma_tag_t, bus_addr_t, bus_addr_t,
248 1.9 ad bus_dma_tag_t *, int);
249 1.9 ad void (*_dmatag_destroy)(bus_dma_tag_t);
250 1.9 ad };
251 1.2 bouyer
252 1.1 yamt #endif /* !defined(_X86_BUS_PRIVATE_H_) */
253