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