| @@ -1,391 +1,395 @@ | | | @@ -1,391 +1,395 @@ |
1 | /* $NetBSD: bcm2835_space.c,v 1.3 2013/01/13 06:10:25 skrll Exp $ */ | | 1 | /* $NetBSD: bcm2835_space.c,v 1.4 2013/01/23 16:51:14 macallan Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2012 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2012 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Nick Hudson | | 8 | * by Nick Hudson |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
18 | * | | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | __KERNEL_RCSID(0, "$NetBSD: bcm2835_space.c,v 1.3 2013/01/13 06:10:25 skrll Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: bcm2835_space.c,v 1.4 2013/01/23 16:51:14 macallan Exp $"); |
35 | | | 35 | |
36 | #include <sys/param.h> | | 36 | #include <sys/param.h> |
37 | #include <sys/systm.h> | | 37 | #include <sys/systm.h> |
38 | | | 38 | |
39 | #include <uvm/uvm_extern.h> | | 39 | #include <uvm/uvm_extern.h> |
40 | | | 40 | |
41 | #include <sys/bus.h> | | 41 | #include <sys/bus.h> |
42 | | | 42 | |
43 | /* Prototypes for all the bus_space structure functions */ | | 43 | /* Prototypes for all the bus_space structure functions */ |
44 | bs_protos(bcm2835); | | 44 | bs_protos(bcm2835); |
45 | bs_protos(bcm2835_a4x); | | 45 | bs_protos(bcm2835_a4x); |
46 | bs_protos(generic); | | 46 | bs_protos(generic); |
47 | bs_protos(generic_armv4); | | 47 | bs_protos(generic_armv4); |
48 | bs_protos(a4x); | | 48 | bs_protos(a4x); |
49 | bs_protos(bs_notimpl); | | 49 | bs_protos(bs_notimpl); |
50 | | | 50 | |
51 | struct bus_space bcm2835_bs_tag = { | | 51 | struct bus_space bcm2835_bs_tag = { |
52 | /* cookie */ | | 52 | /* cookie */ |
53 | (void *) 0, | | 53 | (void *) 0, |
54 | | | 54 | |
55 | /* mapping/unmapping */ | | 55 | /* mapping/unmapping */ |
56 | bcm2835_bs_map, | | 56 | bcm2835_bs_map, |
57 | bcm2835_bs_unmap, | | 57 | bcm2835_bs_unmap, |
58 | bcm2835_bs_subregion, | | 58 | bcm2835_bs_subregion, |
59 | | | 59 | |
60 | /* allocation/deallocation */ | | 60 | /* allocation/deallocation */ |
61 | bcm2835_bs_alloc, /* not implemented */ | | 61 | bcm2835_bs_alloc, /* not implemented */ |
62 | bcm2835_bs_free, /* not implemented */ | | 62 | bcm2835_bs_free, /* not implemented */ |
63 | | | 63 | |
64 | /* get kernel virtual address */ | | 64 | /* get kernel virtual address */ |
65 | bcm2835_bs_vaddr, | | 65 | bcm2835_bs_vaddr, |
66 | | | 66 | |
67 | /* mmap */ | | 67 | /* mmap */ |
68 | bcm2835_bs_mmap, | | 68 | bcm2835_bs_mmap, |
69 | | | 69 | |
70 | /* barrier */ | | 70 | /* barrier */ |
71 | bcm2835_bs_barrier, | | 71 | bcm2835_bs_barrier, |
72 | | | 72 | |
73 | /* read (single) */ | | 73 | /* read (single) */ |
74 | generic_bs_r_1, | | 74 | generic_bs_r_1, |
75 | generic_armv4_bs_r_2, | | 75 | generic_armv4_bs_r_2, |
76 | generic_bs_r_4, | | 76 | generic_bs_r_4, |
77 | bs_notimpl_bs_r_8, | | 77 | bs_notimpl_bs_r_8, |
78 | | | 78 | |
79 | /* read multiple */ | | 79 | /* read multiple */ |
80 | generic_bs_rm_1, | | 80 | generic_bs_rm_1, |
81 | generic_armv4_bs_rm_2, | | 81 | generic_armv4_bs_rm_2, |
82 | generic_bs_rm_4, | | 82 | generic_bs_rm_4, |
83 | bs_notimpl_bs_rm_8, | | 83 | bs_notimpl_bs_rm_8, |
84 | | | 84 | |
85 | /* read region */ | | 85 | /* read region */ |
86 | generic_bs_rr_1, | | 86 | generic_bs_rr_1, |
87 | generic_armv4_bs_rr_2, | | 87 | generic_armv4_bs_rr_2, |
88 | generic_bs_rr_4, | | 88 | generic_bs_rr_4, |
89 | bs_notimpl_bs_rr_8, | | 89 | bs_notimpl_bs_rr_8, |
90 | | | 90 | |
91 | /* write (single) */ | | 91 | /* write (single) */ |
92 | generic_bs_w_1, | | 92 | generic_bs_w_1, |
93 | generic_armv4_bs_w_2, | | 93 | generic_armv4_bs_w_2, |
94 | generic_bs_w_4, | | 94 | generic_bs_w_4, |
95 | bs_notimpl_bs_w_8, | | 95 | bs_notimpl_bs_w_8, |
96 | | | 96 | |
97 | /* write multiple */ | | 97 | /* write multiple */ |
98 | generic_bs_wm_1, | | 98 | generic_bs_wm_1, |
99 | generic_armv4_bs_wm_2, | | 99 | generic_armv4_bs_wm_2, |
100 | generic_bs_wm_4, | | 100 | generic_bs_wm_4, |
101 | bs_notimpl_bs_wm_8, | | 101 | bs_notimpl_bs_wm_8, |
102 | | | 102 | |
103 | /* write region */ | | 103 | /* write region */ |
104 | generic_bs_wr_1, | | 104 | generic_bs_wr_1, |
105 | generic_armv4_bs_wr_2, | | 105 | generic_armv4_bs_wr_2, |
106 | generic_bs_wr_4, | | 106 | generic_bs_wr_4, |
107 | bs_notimpl_bs_wr_8, | | 107 | bs_notimpl_bs_wr_8, |
108 | | | 108 | |
109 | /* set multiple */ | | 109 | /* set multiple */ |
110 | bs_notimpl_bs_sm_1, | | 110 | bs_notimpl_bs_sm_1, |
111 | bs_notimpl_bs_sm_2, | | 111 | bs_notimpl_bs_sm_2, |
112 | bs_notimpl_bs_sm_4, | | 112 | bs_notimpl_bs_sm_4, |
113 | bs_notimpl_bs_sm_8, | | 113 | bs_notimpl_bs_sm_8, |
114 | | | 114 | |
115 | /* set region */ | | 115 | /* set region */ |
116 | generic_bs_sr_1, | | 116 | generic_bs_sr_1, |
117 | generic_armv4_bs_sr_2, | | 117 | generic_armv4_bs_sr_2, |
118 | bs_notimpl_bs_sr_4, | | 118 | bs_notimpl_bs_sr_4, |
119 | bs_notimpl_bs_sr_8, | | 119 | bs_notimpl_bs_sr_8, |
120 | | | 120 | |
121 | /* copy */ | | 121 | /* copy */ |
122 | bs_notimpl_bs_c_1, | | 122 | bs_notimpl_bs_c_1, |
123 | generic_armv4_bs_c_2, | | 123 | generic_armv4_bs_c_2, |
124 | bs_notimpl_bs_c_4, | | 124 | bs_notimpl_bs_c_4, |
125 | bs_notimpl_bs_c_8, | | 125 | bs_notimpl_bs_c_8, |
126 | | | 126 | |
127 | #ifdef __BUS_SPACE_HAS_STREAM_METHODS | | 127 | #ifdef __BUS_SPACE_HAS_STREAM_METHODS |
128 | /* read (single) */ | | 128 | /* read (single) */ |
129 | generic_bs_r_1, | | 129 | generic_bs_r_1, |
130 | generic_armv4_bs_r_2, | | 130 | generic_armv4_bs_r_2, |
131 | generic_bs_r_4, | | 131 | generic_bs_r_4, |
132 | bs_notimpl_bs_r_8, | | 132 | bs_notimpl_bs_r_8, |
133 | | | 133 | |
134 | /* read multiple */ | | 134 | /* read multiple */ |
135 | generic_bs_rm_1, | | 135 | generic_bs_rm_1, |
136 | generic_armv4_bs_rm_2, | | 136 | generic_armv4_bs_rm_2, |
137 | generic_bs_rm_4, | | 137 | generic_bs_rm_4, |
138 | bs_notimpl_bs_rm_8, | | 138 | bs_notimpl_bs_rm_8, |
139 | | | 139 | |
140 | /* read region */ | | 140 | /* read region */ |
141 | generic_bs_rr_1, | | 141 | generic_bs_rr_1, |
142 | generic_armv4_bs_rr_2, | | 142 | generic_armv4_bs_rr_2, |
143 | generic_bs_rr_4, | | 143 | generic_bs_rr_4, |
144 | bs_notimpl_bs_rr_8, | | 144 | bs_notimpl_bs_rr_8, |
145 | | | 145 | |
146 | /* write (single) */ | | 146 | /* write (single) */ |
147 | generic_bs_w_1, | | 147 | generic_bs_w_1, |
148 | generic_armv4_bs_w_2, | | 148 | generic_armv4_bs_w_2, |
149 | generic_bs_w_4, | | 149 | generic_bs_w_4, |
150 | bs_notimpl_bs_w_8, | | 150 | bs_notimpl_bs_w_8, |
151 | | | 151 | |
152 | /* write multiple */ | | 152 | /* write multiple */ |
153 | generic_bs_wm_1, | | 153 | generic_bs_wm_1, |
154 | generic_armv4_bs_wm_2, | | 154 | generic_armv4_bs_wm_2, |
155 | generic_bs_wm_4, | | 155 | generic_bs_wm_4, |
156 | bs_notimpl_bs_wm_8, | | 156 | bs_notimpl_bs_wm_8, |
157 | | | 157 | |
158 | /* write region */ | | 158 | /* write region */ |
159 | generic_bs_wr_1, | | 159 | generic_bs_wr_1, |
160 | generic_armv4_bs_wr_2, | | 160 | generic_armv4_bs_wr_2, |
161 | generic_bs_wr_4, | | 161 | generic_bs_wr_4, |
162 | bs_notimpl_bs_wr_8, | | 162 | bs_notimpl_bs_wr_8, |
163 | #endif | | 163 | #endif |
164 | }; | | 164 | }; |
165 | | | 165 | |
166 | struct bus_space bcm2835_a4x_bs_tag = { | | 166 | struct bus_space bcm2835_a4x_bs_tag = { |
167 | /* cookie */ | | 167 | /* cookie */ |
168 | (void *) 0, | | 168 | (void *) 0, |
169 | | | 169 | |
170 | /* mapping/unmapping */ | | 170 | /* mapping/unmapping */ |
171 | bcm2835_bs_map, | | 171 | bcm2835_bs_map, |
172 | bcm2835_bs_unmap, | | 172 | bcm2835_bs_unmap, |
173 | bcm2835_bs_subregion, | | 173 | bcm2835_bs_subregion, |
174 | | | 174 | |
175 | /* allocation/deallocation */ | | 175 | /* allocation/deallocation */ |
176 | bcm2835_bs_alloc, /* not implemented */ | | 176 | bcm2835_bs_alloc, /* not implemented */ |
177 | bcm2835_bs_free, /* not implemented */ | | 177 | bcm2835_bs_free, /* not implemented */ |
178 | | | 178 | |
179 | /* get kernel virtual address */ | | 179 | /* get kernel virtual address */ |
180 | bcm2835_bs_vaddr, | | 180 | bcm2835_bs_vaddr, |
181 | | | 181 | |
182 | /* mmap */ | | 182 | /* mmap */ |
183 | bs_notimpl_bs_mmap, | | 183 | bs_notimpl_bs_mmap, |
184 | | | 184 | |
185 | /* barrier */ | | 185 | /* barrier */ |
186 | bcm2835_bs_barrier, | | 186 | bcm2835_bs_barrier, |
187 | | | 187 | |
188 | /* read (single) */ | | 188 | /* read (single) */ |
189 | a4x_bs_r_1, | | 189 | a4x_bs_r_1, |
190 | a4x_bs_r_2, | | 190 | a4x_bs_r_2, |
191 | a4x_bs_r_4, | | 191 | a4x_bs_r_4, |
192 | bs_notimpl_bs_r_8, | | 192 | bs_notimpl_bs_r_8, |
193 | | | 193 | |
194 | /* read multiple */ | | 194 | /* read multiple */ |
195 | a4x_bs_rm_1, | | 195 | a4x_bs_rm_1, |
196 | a4x_bs_rm_2, | | 196 | a4x_bs_rm_2, |
197 | a4x_bs_rm_4, | | 197 | a4x_bs_rm_4, |
198 | bs_notimpl_bs_rm_8, | | 198 | bs_notimpl_bs_rm_8, |
199 | | | 199 | |
200 | /* read region */ | | 200 | /* read region */ |
201 | bs_notimpl_bs_rr_1, | | 201 | bs_notimpl_bs_rr_1, |
202 | bs_notimpl_bs_rr_2, | | 202 | bs_notimpl_bs_rr_2, |
203 | bs_notimpl_bs_rr_4, | | 203 | bs_notimpl_bs_rr_4, |
204 | bs_notimpl_bs_rr_8, | | 204 | bs_notimpl_bs_rr_8, |
205 | | | 205 | |
206 | /* write (single) */ | | 206 | /* write (single) */ |
207 | a4x_bs_w_1, | | 207 | a4x_bs_w_1, |
208 | a4x_bs_w_2, | | 208 | a4x_bs_w_2, |
209 | a4x_bs_w_4, | | 209 | a4x_bs_w_4, |
210 | bs_notimpl_bs_w_8, | | 210 | bs_notimpl_bs_w_8, |
211 | | | 211 | |
212 | /* write multiple */ | | 212 | /* write multiple */ |
213 | a4x_bs_wm_1, | | 213 | a4x_bs_wm_1, |
214 | a4x_bs_wm_2, | | 214 | a4x_bs_wm_2, |
215 | a4x_bs_wm_4, | | 215 | a4x_bs_wm_4, |
216 | bs_notimpl_bs_wm_8, | | 216 | bs_notimpl_bs_wm_8, |
217 | /* write region */ | | 217 | /* write region */ |
218 | bs_notimpl_bs_wr_1, | | 218 | bs_notimpl_bs_wr_1, |
219 | bs_notimpl_bs_wr_2, | | 219 | bs_notimpl_bs_wr_2, |
220 | bs_notimpl_bs_wr_4, | | 220 | bs_notimpl_bs_wr_4, |
221 | bs_notimpl_bs_wr_8, | | 221 | bs_notimpl_bs_wr_8, |
222 | | | 222 | |
223 | /* set multiple */ | | 223 | /* set multiple */ |
224 | bs_notimpl_bs_sm_1, | | 224 | bs_notimpl_bs_sm_1, |
225 | bs_notimpl_bs_sm_2, | | 225 | bs_notimpl_bs_sm_2, |
226 | bs_notimpl_bs_sm_4, | | 226 | bs_notimpl_bs_sm_4, |
227 | bs_notimpl_bs_sm_8, | | 227 | bs_notimpl_bs_sm_8, |
228 | | | 228 | |
229 | /* set region */ | | 229 | /* set region */ |
230 | bs_notimpl_bs_sr_1, | | 230 | bs_notimpl_bs_sr_1, |
231 | bs_notimpl_bs_sr_2, | | 231 | bs_notimpl_bs_sr_2, |
232 | bs_notimpl_bs_sr_4, | | 232 | bs_notimpl_bs_sr_4, |
233 | bs_notimpl_bs_sr_8, | | 233 | bs_notimpl_bs_sr_8, |
234 | | | 234 | |
235 | /* copy */ | | 235 | /* copy */ |
236 | bs_notimpl_bs_c_1, | | 236 | bs_notimpl_bs_c_1, |
237 | bs_notimpl_bs_c_2, | | 237 | bs_notimpl_bs_c_2, |
238 | bs_notimpl_bs_c_4, | | 238 | bs_notimpl_bs_c_4, |
239 | bs_notimpl_bs_c_8, | | 239 | bs_notimpl_bs_c_8, |
240 | | | 240 | |
241 | #ifdef __BUS_SPACE_HAS_STREAM_METHODS | | 241 | #ifdef __BUS_SPACE_HAS_STREAM_METHODS |
242 | /* read (single) */ | | 242 | /* read (single) */ |
243 | generic_bs_r_1, | | 243 | generic_bs_r_1, |
244 | generic_armv4_bs_r_2, | | 244 | generic_armv4_bs_r_2, |
245 | generic_bs_r_4, | | 245 | generic_bs_r_4, |
246 | bs_notimpl_bs_r_8, | | 246 | bs_notimpl_bs_r_8, |
247 | | | 247 | |
248 | /* read multiple */ | | 248 | /* read multiple */ |
249 | generic_bs_rm_1, | | 249 | generic_bs_rm_1, |
250 | generic_armv4_bs_rm_2, | | 250 | generic_armv4_bs_rm_2, |
251 | generic_bs_rm_4, | | 251 | generic_bs_rm_4, |
252 | bs_notimpl_bs_rm_8, | | 252 | bs_notimpl_bs_rm_8, |
253 | | | 253 | |
254 | /* read region */ | | 254 | /* read region */ |
255 | generic_bs_rr_1, | | 255 | generic_bs_rr_1, |
256 | generic_armv4_bs_rr_2, | | 256 | generic_armv4_bs_rr_2, |
257 | generic_bs_rr_4, | | 257 | generic_bs_rr_4, |
258 | bs_notimpl_bs_rr_8, | | 258 | bs_notimpl_bs_rr_8, |
259 | | | 259 | |
260 | /* write (single) */ | | 260 | /* write (single) */ |
261 | generic_bs_w_1, | | 261 | generic_bs_w_1, |
262 | generic_armv4_bs_w_2, | | 262 | generic_armv4_bs_w_2, |
263 | generic_bs_w_4, | | 263 | generic_bs_w_4, |
264 | bs_notimpl_bs_w_8, | | 264 | bs_notimpl_bs_w_8, |
265 | | | 265 | |
266 | /* write multiple */ | | 266 | /* write multiple */ |
267 | generic_bs_wm_1, | | 267 | generic_bs_wm_1, |
268 | generic_armv4_bs_wm_2, | | 268 | generic_armv4_bs_wm_2, |
269 | generic_bs_wm_4, | | 269 | generic_bs_wm_4, |
270 | bs_notimpl_bs_wm_8, | | 270 | bs_notimpl_bs_wm_8, |
271 | | | 271 | |
272 | /* write region */ | | 272 | /* write region */ |
273 | generic_bs_wr_1, | | 273 | generic_bs_wr_1, |
274 | generic_armv4_bs_wr_2, | | 274 | generic_armv4_bs_wr_2, |
275 | generic_bs_wr_4, | | 275 | generic_bs_wr_4, |
276 | bs_notimpl_bs_wr_8, | | 276 | bs_notimpl_bs_wr_8, |
277 | #endif | | 277 | #endif |
278 | | | 278 | |
279 | }; | | 279 | }; |
280 | | | 280 | |
281 | | | 281 | |
282 | int | | 282 | int |
283 | bcm2835_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flag, | | 283 | bcm2835_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flag, |
284 | bus_space_handle_t *bshp) | | 284 | bus_space_handle_t *bshp) |
285 | { | | 285 | { |
286 | u_long startpa, endpa, pa; | | 286 | u_long startpa, endpa, pa; |
287 | vaddr_t va; | | 287 | vaddr_t va; |
288 | const struct pmap_devmap *pd; | | 288 | const struct pmap_devmap *pd; |
289 | int pmap_flags; | | 289 | int pmap_flags; |
290 | | | 290 | |
291 | if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) { | | 291 | if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) { |
292 | /* Device was statically mapped. */ | | 292 | /* Device was statically mapped. */ |
293 | *bshp = pd->pd_va + (bpa - pd->pd_pa); | | 293 | *bshp = pd->pd_va + (bpa - pd->pd_pa); |
294 | return 0; | | 294 | return 0; |
295 | } | | 295 | } |
296 | | | 296 | |
297 | startpa = trunc_page(bpa); | | 297 | startpa = trunc_page(bpa); |
298 | endpa = round_page(bpa + size); | | 298 | endpa = round_page(bpa + size); |
299 | | | 299 | |
300 | /* XXX use extent manager to check duplicate mapping */ | | 300 | /* XXX use extent manager to check duplicate mapping */ |
301 | | | 301 | |
302 | va = uvm_km_alloc(kernel_map, endpa - startpa, 0, | | 302 | va = uvm_km_alloc(kernel_map, endpa - startpa, 0, |
303 | UVM_KMF_VAONLY | UVM_KMF_NOWAIT); | | 303 | UVM_KMF_VAONLY | UVM_KMF_NOWAIT); |
304 | if (!va) | | 304 | if (!va) |
305 | return ENOMEM; | | 305 | return ENOMEM; |
306 | | | 306 | |
307 | *bshp = (bus_space_handle_t)(va + (bpa - startpa)); | | 307 | *bshp = (bus_space_handle_t)(va + (bpa - startpa)); |
308 | | | 308 | |
309 | pmap_flags = (flag & BUS_SPACE_MAP_CACHEABLE) ? 0 : PMAP_NOCACHE; | | 309 | pmap_flags = (flag & BUS_SPACE_MAP_CACHEABLE) ? 0 : PMAP_NOCACHE; |
310 | for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { | | 310 | for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) { |
311 | pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, | | 311 | pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, |
312 | pmap_flags); | | 312 | pmap_flags); |
313 | } | | 313 | } |
314 | pmap_update(pmap_kernel()); | | 314 | pmap_update(pmap_kernel()); |
315 | | | 315 | |
316 | return 0; | | 316 | return 0; |
317 | } | | 317 | } |
318 | | | 318 | |
319 | void | | 319 | void |
320 | bcm2835_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) | | 320 | bcm2835_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) |
321 | { | | 321 | { |
322 | vaddr_t va; | | 322 | vaddr_t va; |
323 | vsize_t sz; | | 323 | vsize_t sz; |
324 | | | 324 | |
325 | if (pmap_devmap_find_va(bsh, size) != NULL) { | | 325 | if (pmap_devmap_find_va(bsh, size) != NULL) { |
326 | /* Device was statically mapped; nothing to do. */ | | 326 | /* Device was statically mapped; nothing to do. */ |
327 | return; | | 327 | return; |
328 | } | | 328 | } |
329 | | | 329 | |
330 | va = trunc_page(bsh); | | 330 | va = trunc_page(bsh); |
331 | sz = round_page(bsh + size) - va; | | 331 | sz = round_page(bsh + size) - va; |
332 | | | 332 | |
333 | pmap_kremove(va, sz); | | 333 | pmap_kremove(va, sz); |
334 | pmap_update(pmap_kernel()); | | 334 | pmap_update(pmap_kernel()); |
335 | uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY); | | 335 | uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY); |
336 | } | | 336 | } |
337 | | | 337 | |
338 | | | 338 | |
339 | int | | 339 | int |
340 | bcm2835_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, | | 340 | bcm2835_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, |
341 | bus_size_t size, bus_space_handle_t *nbshp) | | 341 | bus_size_t size, bus_space_handle_t *nbshp) |
342 | { | | 342 | { |
343 | | | 343 | |
344 | *nbshp = bsh + offset; | | 344 | *nbshp = bsh + offset; |
345 | return (0); | | 345 | return (0); |
346 | } | | 346 | } |
347 | | | 347 | |
348 | void | | 348 | void |
349 | bcm2835_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, | | 349 | bcm2835_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, |
350 | bus_size_t len, int flags) | | 350 | bus_size_t len, int flags) |
351 | { | | 351 | { |
352 | flags &= BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE; | | 352 | flags &= BUS_SPACE_BARRIER_READ|BUS_SPACE_BARRIER_WRITE; |
353 | | | 353 | |
354 | if (flags) { | | 354 | if (flags) { |
355 | /* Issue an ARM11 Data Syncronisation Barrier (DSB) */ | | 355 | /* Issue an ARM11 Data Syncronisation Barrier (DSB) */ |
356 | __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" : : "r" (0) | | 356 | __asm__ __volatile__ ("mcr p15, 0, %0, c7, c10, 4" : : "r" (0) |
357 | : "memory"); | | 357 | : "memory"); |
358 | return; | | 358 | return; |
359 | } | | 359 | } |
360 | | | 360 | |
361 | } | | 361 | } |
362 | | | 362 | |
363 | void * | | 363 | void * |
364 | bcm2835_bs_vaddr(void *t, bus_space_handle_t bsh) | | 364 | bcm2835_bs_vaddr(void *t, bus_space_handle_t bsh) |
365 | { | | 365 | { |
366 | | | 366 | |
367 | return (void *)bsh; | | 367 | return (void *)bsh; |
368 | } | | 368 | } |
369 | | | 369 | |
370 | paddr_t | | 370 | paddr_t |
371 | bcm2835_bs_mmap(void *t, bus_addr_t paddr, off_t offset, int prot, int flags) | | 371 | bcm2835_bs_mmap(void *t, bus_addr_t paddr, off_t offset, int prot, int flags) |
372 | { | | 372 | { |
| | | 373 | paddr_t bus_flags = 0; |
373 | | | 374 | |
374 | return (arm_btop((paddr + offset))); | | 375 | if (flags & BUS_SPACE_MAP_PREFETCHABLE) |
| | | 376 | bus_flags |= ARM32_MMAP_WRITECOMBINE; |
| | | 377 | |
| | | 378 | return (arm_btop(paddr + offset) | bus_flags); |
375 | } | | 379 | } |
376 | | | 380 | |
377 | int | | 381 | int |
378 | bcm2835_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, | | 382 | bcm2835_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, |
379 | bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags, | | 383 | bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags, |
380 | bus_addr_t *bpap, bus_space_handle_t *bshp) | | 384 | bus_addr_t *bpap, bus_space_handle_t *bshp) |
381 | { | | 385 | { |
382 | | | 386 | |
383 | panic("%s(): not implemented\n", __func__); | | 387 | panic("%s(): not implemented\n", __func__); |
384 | } | | 388 | } |
385 | | | 389 | |
386 | void | | 390 | void |
387 | bcm2835_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) | | 391 | bcm2835_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) |
388 | { | | 392 | { |
389 | | | 393 | |
390 | panic("%s(): not implemented\n", __func__); | | 394 | panic("%s(): not implemented\n", __func__); |
391 | } | | 395 | } |