1*1cd76c75SBen Gras /* $NetBSD: bus_private.h,v 1.14 2011/09/01 15:10:31 christos Exp $ */
2*1cd76c75SBen Gras /* NetBSD: bus.h,v 1.8 2005/03/09 19:04:46 matt Exp */
3*1cd76c75SBen Gras
4*1cd76c75SBen Gras /*-
5*1cd76c75SBen Gras * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
6*1cd76c75SBen Gras * All rights reserved.
7*1cd76c75SBen Gras *
8*1cd76c75SBen Gras * This code is derived from software contributed to The NetBSD Foundation
9*1cd76c75SBen Gras * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10*1cd76c75SBen Gras * NASA Ames Research Center.
11*1cd76c75SBen Gras *
12*1cd76c75SBen Gras * Redistribution and use in source and binary forms, with or without
13*1cd76c75SBen Gras * modification, are permitted provided that the following conditions
14*1cd76c75SBen Gras * are met:
15*1cd76c75SBen Gras * 1. Redistributions of source code must retain the above copyright
16*1cd76c75SBen Gras * notice, this list of conditions and the following disclaimer.
17*1cd76c75SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
18*1cd76c75SBen Gras * notice, this list of conditions and the following disclaimer in the
19*1cd76c75SBen Gras * documentation and/or other materials provided with the distribution.
20*1cd76c75SBen Gras *
21*1cd76c75SBen Gras * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22*1cd76c75SBen Gras * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23*1cd76c75SBen Gras * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24*1cd76c75SBen Gras * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25*1cd76c75SBen Gras * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26*1cd76c75SBen Gras * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27*1cd76c75SBen Gras * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28*1cd76c75SBen Gras * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29*1cd76c75SBen Gras * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30*1cd76c75SBen Gras * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31*1cd76c75SBen Gras * POSSIBILITY OF SUCH DAMAGE.
32*1cd76c75SBen Gras */
33*1cd76c75SBen Gras
34*1cd76c75SBen Gras /*
35*1cd76c75SBen Gras * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
36*1cd76c75SBen Gras * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
37*1cd76c75SBen Gras *
38*1cd76c75SBen Gras * Redistribution and use in source and binary forms, with or without
39*1cd76c75SBen Gras * modification, are permitted provided that the following conditions
40*1cd76c75SBen Gras * are met:
41*1cd76c75SBen Gras * 1. Redistributions of source code must retain the above copyright
42*1cd76c75SBen Gras * notice, this list of conditions and the following disclaimer.
43*1cd76c75SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
44*1cd76c75SBen Gras * notice, this list of conditions and the following disclaimer in the
45*1cd76c75SBen Gras * documentation and/or other materials provided with the distribution.
46*1cd76c75SBen Gras * 3. All advertising materials mentioning features or use of this software
47*1cd76c75SBen Gras * must display the following acknowledgement:
48*1cd76c75SBen Gras * This product includes software developed by Christopher G. Demetriou
49*1cd76c75SBen Gras * for the NetBSD Project.
50*1cd76c75SBen Gras * 4. The name of the author may not be used to endorse or promote products
51*1cd76c75SBen Gras * derived from this software without specific prior written permission
52*1cd76c75SBen Gras *
53*1cd76c75SBen Gras * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
54*1cd76c75SBen Gras * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55*1cd76c75SBen Gras * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56*1cd76c75SBen Gras * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
57*1cd76c75SBen Gras * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
58*1cd76c75SBen Gras * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59*1cd76c75SBen Gras * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60*1cd76c75SBen Gras * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61*1cd76c75SBen Gras * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
62*1cd76c75SBen Gras * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63*1cd76c75SBen Gras */
64*1cd76c75SBen Gras
65*1cd76c75SBen Gras #if !defined(_X86_BUS_PRIVATE_H_)
66*1cd76c75SBen Gras #define _X86_BUS_PRIVATE_H_
67*1cd76c75SBen Gras
68*1cd76c75SBen Gras /*
69*1cd76c75SBen Gras * Cookie used for bounce buffers. A pointer to one of these it stashed in
70*1cd76c75SBen Gras * the DMA map.
71*1cd76c75SBen Gras */
72*1cd76c75SBen Gras struct x86_bus_dma_cookie {
73*1cd76c75SBen Gras int id_flags; /* flags; see below */
74*1cd76c75SBen Gras
75*1cd76c75SBen Gras /*
76*1cd76c75SBen Gras * Information about the original buffer used during
77*1cd76c75SBen Gras * DMA map syncs. Note that origibuflen is only used
78*1cd76c75SBen Gras * for ID_BUFTYPE_LINEAR.
79*1cd76c75SBen Gras */
80*1cd76c75SBen Gras void *id_origbuf; /* pointer to orig buffer if
81*1cd76c75SBen Gras bouncing */
82*1cd76c75SBen Gras bus_size_t id_origbuflen; /* ...and size */
83*1cd76c75SBen Gras int id_buftype; /* type of buffer */
84*1cd76c75SBen Gras
85*1cd76c75SBen Gras void *id_bouncebuf; /* pointer to the bounce buffer */
86*1cd76c75SBen Gras bus_size_t id_bouncebuflen; /* ...and size */
87*1cd76c75SBen Gras int id_nbouncesegs; /* number of valid bounce segs */
88*1cd76c75SBen Gras bus_dma_segment_t id_bouncesegs[0]; /* array of bounce buffer
89*1cd76c75SBen Gras physical memory segments */
90*1cd76c75SBen Gras };
91*1cd76c75SBen Gras
92*1cd76c75SBen Gras /* id_flags */
93*1cd76c75SBen Gras #define X86_DMA_MIGHT_NEED_BOUNCE 0x01 /* may need bounce buffers */
94*1cd76c75SBen Gras #define X86_DMA_HAS_BOUNCE 0x02 /* has bounce buffers */
95*1cd76c75SBen Gras #define X86_DMA_IS_BOUNCING 0x04 /* is bouncing current xfer */
96*1cd76c75SBen Gras
97*1cd76c75SBen Gras /* id_buftype */
98*1cd76c75SBen Gras #define X86_DMA_BUFTYPE_INVALID 0
99*1cd76c75SBen Gras #define X86_DMA_BUFTYPE_LINEAR 1
100*1cd76c75SBen Gras #define X86_DMA_BUFTYPE_MBUF 2
101*1cd76c75SBen Gras #define X86_DMA_BUFTYPE_UIO 3
102*1cd76c75SBen Gras #define X86_DMA_BUFTYPE_RAW 4
103*1cd76c75SBen Gras
104*1cd76c75SBen Gras /*
105*1cd76c75SBen Gras * default address translation macros, which are appropriate where
106*1cd76c75SBen Gras * paddr_t == bus_addr_t.
107*1cd76c75SBen Gras */
108*1cd76c75SBen Gras
109*1cd76c75SBen Gras #if !defined(_BUS_PHYS_TO_BUS)
110*1cd76c75SBen Gras #define _BUS_PHYS_TO_BUS(pa) ((bus_addr_t)(pa))
111*1cd76c75SBen Gras #endif /* !defined(_BUS_PHYS_TO_BUS) */
112*1cd76c75SBen Gras
113*1cd76c75SBen Gras #if !defined(_BUS_BUS_TO_PHYS)
114*1cd76c75SBen Gras #define _BUS_BUS_TO_PHYS(ba) ((paddr_t)(ba))
115*1cd76c75SBen Gras #endif /* !defined(_BUS_BUS_TO_PHYS) */
116*1cd76c75SBen Gras
117*1cd76c75SBen Gras #if !defined(_BUS_VM_PAGE_TO_BUS)
118*1cd76c75SBen Gras #define _BUS_VM_PAGE_TO_BUS(pg) _BUS_PHYS_TO_BUS(VM_PAGE_TO_PHYS(pg))
119*1cd76c75SBen Gras #endif /* !defined(_BUS_VM_PAGE_TO_BUS) */
120*1cd76c75SBen Gras
121*1cd76c75SBen Gras #if !defined(_BUS_BUS_TO_VM_PAGE)
122*1cd76c75SBen Gras #define _BUS_BUS_TO_VM_PAGE(ba) PHYS_TO_VM_PAGE(ba)
123*1cd76c75SBen Gras #endif /* !defined(_BUS_BUS_TO_VM_PAGE) */
124*1cd76c75SBen Gras
125*1cd76c75SBen Gras #if !defined(_BUS_PMAP_ENTER)
126*1cd76c75SBen Gras #define _BUS_PMAP_ENTER(pmap, va, ba, prot, flags) \
127*1cd76c75SBen Gras pmap_enter(pmap, va, ba, prot, flags)
128*1cd76c75SBen Gras #endif /* _BUS_PMAP_ENTER */
129*1cd76c75SBen Gras
130*1cd76c75SBen Gras #if !defined(_BUS_VIRT_TO_BUS)
131*1cd76c75SBen Gras #include <uvm/uvm.h>
132*1cd76c75SBen Gras
133*1cd76c75SBen Gras static __inline bus_addr_t _bus_virt_to_bus(struct pmap *, vaddr_t);
134*1cd76c75SBen Gras #define _BUS_VIRT_TO_BUS(pm, va) _bus_virt_to_bus((pm), (va))
135*1cd76c75SBen Gras
136*1cd76c75SBen Gras static __inline bus_addr_t
_bus_virt_to_bus(struct pmap * pm,vaddr_t va)137*1cd76c75SBen Gras _bus_virt_to_bus(struct pmap *pm, vaddr_t va)
138*1cd76c75SBen Gras {
139*1cd76c75SBen Gras paddr_t pa;
140*1cd76c75SBen Gras
141*1cd76c75SBen Gras if (!pmap_extract(pm, va, &pa)) {
142*1cd76c75SBen Gras panic("_bus_virt_to_bus");
143*1cd76c75SBen Gras }
144*1cd76c75SBen Gras
145*1cd76c75SBen Gras return _BUS_PHYS_TO_BUS(pa);
146*1cd76c75SBen Gras }
147*1cd76c75SBen Gras #endif /* !defined(_BUS_VIRT_TO_BUS) */
148*1cd76c75SBen Gras
149*1cd76c75SBen Gras /*
150*1cd76c75SBen Gras * by default, the end address of RAM visible on bus is the same as the
151*1cd76c75SBen Gras * largest physical address.
152*1cd76c75SBen Gras */
153*1cd76c75SBen Gras #ifndef _BUS_AVAIL_END
154*1cd76c75SBen Gras #define _BUS_AVAIL_END (avail_end)
155*1cd76c75SBen Gras #endif
156*1cd76c75SBen Gras
157*1cd76c75SBen Gras struct x86_bus_dma_tag {
158*1cd76c75SBen Gras bus_dma_tag_t bdt_super;
159*1cd76c75SBen Gras /* bdt_present: bitmap indicating overrides present (1) in *this* tag,
160*1cd76c75SBen Gras * bdt_exists: bitmap indicating overrides present (1) in *this* tag
161*1cd76c75SBen Gras * or in an ancestor's tag (follow bdt_super to ancestors)
162*1cd76c75SBen Gras */
163*1cd76c75SBen Gras uint64_t bdt_present;
164*1cd76c75SBen Gras uint64_t bdt_exists;
165*1cd76c75SBen Gras const struct bus_dma_overrides *bdt_ov;
166*1cd76c75SBen Gras void *bdt_ctx;
167*1cd76c75SBen Gras /*
168*1cd76c75SBen Gras * The `bounce threshold' is checked while we are loading
169*1cd76c75SBen Gras * the DMA map. If the physical address of the segment
170*1cd76c75SBen Gras * exceeds the threshold, an error will be returned. The
171*1cd76c75SBen Gras * caller can then take whatever action is necessary to
172*1cd76c75SBen Gras * bounce the transfer. If this value is 0, it will be
173*1cd76c75SBen Gras * ignored.
174*1cd76c75SBen Gras */
175*1cd76c75SBen Gras int _tag_needs_free;
176*1cd76c75SBen Gras bus_addr_t _bounce_thresh;
177*1cd76c75SBen Gras bus_addr_t _bounce_alloc_lo;
178*1cd76c75SBen Gras bus_addr_t _bounce_alloc_hi;
179*1cd76c75SBen Gras int (*_may_bounce)(bus_dma_tag_t, bus_dmamap_t, int, int *);
180*1cd76c75SBen Gras };
181*1cd76c75SBen Gras
182*1cd76c75SBen Gras #endif /* !defined(_X86_BUS_PRIVATE_H_) */
183