imx_space.c revision 1.5 1 1.5 matt /* $Id: imx_space.c,v 1.5 2012/09/01 14:44:42 matt Exp $ */
2 1.1 bsh
3 1.1 bsh /* derived from: */
4 1.5 matt /* $NetBSD: imx_space.c,v 1.5 2012/09/01 14:44:42 matt Exp $ */
5 1.1 bsh
6 1.1 bsh /*
7 1.1 bsh * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
8 1.1 bsh * All rights reserved.
9 1.1 bsh *
10 1.1 bsh * Written by Jason R. Thorpe for Wasabi Systems, Inc.
11 1.1 bsh *
12 1.1 bsh * Redistribution and use in source and binary forms, with or without
13 1.1 bsh * modification, are permitted provided that the following conditions
14 1.1 bsh * are met:
15 1.1 bsh * 1. Redistributions of source code must retain the above copyright
16 1.1 bsh * notice, this list of conditions and the following disclaimer.
17 1.1 bsh * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 bsh * notice, this list of conditions and the following disclaimer in the
19 1.1 bsh * documentation and/or other materials provided with the distribution.
20 1.1 bsh * 3. All advertising materials mentioning features or use of this software
21 1.1 bsh * must display the following acknowledgement:
22 1.1 bsh * This product includes software developed for the NetBSD Project by
23 1.1 bsh * Wasabi Systems, Inc.
24 1.1 bsh * 4. The name of Wasabi Systems, Inc. may not be used to endorse
25 1.1 bsh * or promote products derived from this software without specific prior
26 1.1 bsh * written permission.
27 1.1 bsh *
28 1.1 bsh * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
29 1.1 bsh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 1.1 bsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 1.1 bsh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
32 1.1 bsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 1.1 bsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 1.1 bsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 1.1 bsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 1.1 bsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 1.1 bsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 1.1 bsh * POSSIBILITY OF SUCH DAMAGE.
39 1.1 bsh */
40 1.1 bsh /*
41 1.1 bsh * Copyright (c) 1997 Mark Brinicombe.
42 1.1 bsh * Copyright (c) 1997 Causality Limited.
43 1.1 bsh * All rights reserved.
44 1.1 bsh *
45 1.1 bsh * This code is derived from software contributed to The NetBSD Foundation
46 1.1 bsh * by Ichiro FUKUHARA.
47 1.1 bsh *
48 1.1 bsh * Redistribution and use in source and binary forms, with or without
49 1.1 bsh * modification, are permitted provided that the following conditions
50 1.1 bsh * are met:
51 1.1 bsh * 1. Redistributions of source code must retain the above copyright
52 1.1 bsh * notice, this list of conditions and the following disclaimer.
53 1.1 bsh * 2. Redistributions in binary form must reproduce the above copyright
54 1.1 bsh * notice, this list of conditions and the following disclaimer in the
55 1.1 bsh * documentation and/or other materials provided with the distribution.
56 1.1 bsh * 3. All advertising materials mentioning features or use of this software
57 1.1 bsh * must display the following acknowledgement:
58 1.1 bsh * This product includes software developed by Mark Brinicombe.
59 1.1 bsh * 4. The name of the company nor the name of the author may be used to
60 1.1 bsh * endorse or promote products derived from this software without specific
61 1.1 bsh * prior written permission.
62 1.1 bsh *
63 1.1 bsh * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
64 1.1 bsh * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
65 1.1 bsh * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
66 1.1 bsh * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
67 1.1 bsh * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
68 1.1 bsh * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
69 1.1 bsh * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 1.1 bsh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 1.1 bsh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 1.1 bsh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 1.1 bsh * SUCH DAMAGE.
74 1.1 bsh */
75 1.1 bsh
76 1.1 bsh /*
77 1.1 bsh * bus_space(9) support for Freescale iMX31 processor
78 1.1 bsh */
79 1.1 bsh
80 1.1 bsh #include <sys/param.h>
81 1.1 bsh #include <sys/systm.h>
82 1.1 bsh #include <uvm/uvm_extern.h>
83 1.3 dyoung #include <sys/bus.h>
84 1.1 bsh
85 1.2 bsh bs_protos(imx);
86 1.1 bsh bs_protos(generic);
87 1.1 bsh bs_protos(generic_armv4);
88 1.1 bsh bs_protos(bs_notimpl);
89 1.1 bsh
90 1.2 bsh struct bus_space imx_bs_tag = {
91 1.1 bsh /* cookie */
92 1.1 bsh (void *) 0,
93 1.1 bsh
94 1.1 bsh /* mapping/unmapping */
95 1.2 bsh imx_bs_map,
96 1.2 bsh imx_bs_unmap,
97 1.2 bsh imx_bs_subregion,
98 1.1 bsh
99 1.1 bsh /* allocation/deallocation */
100 1.2 bsh imx_bs_alloc, /* not implemented */
101 1.2 bsh imx_bs_free, /* not implemented */
102 1.1 bsh
103 1.1 bsh /* get kernel virtual address */
104 1.2 bsh imx_bs_vaddr,
105 1.1 bsh
106 1.1 bsh /* mmap */
107 1.1 bsh bs_notimpl_bs_mmap,
108 1.1 bsh
109 1.1 bsh /* barrier */
110 1.2 bsh imx_bs_barrier,
111 1.1 bsh
112 1.1 bsh /* read (single) */
113 1.1 bsh generic_bs_r_1,
114 1.1 bsh generic_armv4_bs_r_2,
115 1.1 bsh generic_bs_r_4,
116 1.1 bsh bs_notimpl_bs_r_8,
117 1.1 bsh
118 1.1 bsh /* read multiple */
119 1.1 bsh generic_bs_rm_1,
120 1.1 bsh generic_armv4_bs_rm_2,
121 1.1 bsh generic_bs_rm_4,
122 1.1 bsh bs_notimpl_bs_rm_8,
123 1.1 bsh
124 1.1 bsh /* read region */
125 1.1 bsh generic_bs_rr_1,
126 1.1 bsh generic_armv4_bs_rr_2,
127 1.1 bsh generic_bs_rr_4,
128 1.1 bsh bs_notimpl_bs_rr_8,
129 1.1 bsh
130 1.1 bsh /* write (single) */
131 1.1 bsh generic_bs_w_1,
132 1.1 bsh generic_armv4_bs_w_2,
133 1.1 bsh generic_bs_w_4,
134 1.1 bsh bs_notimpl_bs_w_8,
135 1.1 bsh
136 1.1 bsh /* write multiple */
137 1.1 bsh generic_bs_wm_1,
138 1.1 bsh generic_armv4_bs_wm_2,
139 1.1 bsh generic_bs_wm_4,
140 1.1 bsh bs_notimpl_bs_wm_8,
141 1.1 bsh
142 1.1 bsh /* write region */
143 1.1 bsh generic_bs_wr_1,
144 1.1 bsh generic_armv4_bs_wr_2,
145 1.1 bsh generic_bs_wr_4,
146 1.1 bsh bs_notimpl_bs_wr_8,
147 1.1 bsh
148 1.1 bsh /* set multiple */
149 1.1 bsh bs_notimpl_bs_sm_1,
150 1.1 bsh bs_notimpl_bs_sm_2,
151 1.1 bsh bs_notimpl_bs_sm_4,
152 1.1 bsh bs_notimpl_bs_sm_8,
153 1.1 bsh
154 1.1 bsh /* set region */
155 1.1 bsh generic_bs_sr_1,
156 1.1 bsh generic_armv4_bs_sr_2,
157 1.1 bsh bs_notimpl_bs_sr_4,
158 1.1 bsh bs_notimpl_bs_sr_8,
159 1.1 bsh
160 1.1 bsh /* copy */
161 1.1 bsh bs_notimpl_bs_c_1,
162 1.1 bsh generic_armv4_bs_c_2,
163 1.1 bsh bs_notimpl_bs_c_4,
164 1.1 bsh bs_notimpl_bs_c_8,
165 1.4 matt
166 1.4 matt #ifdef __BUS_SPACE_HAS_STREAM_METHODS
167 1.4 matt /* read (single) */
168 1.4 matt generic_bs_r_1,
169 1.4 matt generic_armv4_bs_r_2,
170 1.4 matt generic_bs_r_4,
171 1.4 matt bs_notimpl_bs_r_8,
172 1.4 matt
173 1.4 matt /* read multiple */
174 1.4 matt generic_bs_rm_1,
175 1.4 matt generic_armv4_bs_rm_2,
176 1.4 matt generic_bs_rm_4,
177 1.4 matt bs_notimpl_bs_rm_8,
178 1.4 matt
179 1.4 matt /* read region */
180 1.4 matt generic_bs_rr_1,
181 1.4 matt generic_armv4_bs_rr_2,
182 1.4 matt generic_bs_rr_4,
183 1.4 matt bs_notimpl_bs_rr_8,
184 1.4 matt
185 1.4 matt /* write (single) */
186 1.4 matt generic_bs_w_1,
187 1.4 matt generic_armv4_bs_w_2,
188 1.4 matt generic_bs_w_4,
189 1.4 matt bs_notimpl_bs_w_8,
190 1.4 matt
191 1.4 matt /* write multiple */
192 1.4 matt generic_bs_wm_1,
193 1.4 matt generic_armv4_bs_wm_2,
194 1.4 matt generic_bs_wm_4,
195 1.4 matt bs_notimpl_bs_wm_8,
196 1.4 matt
197 1.4 matt /* write region */
198 1.4 matt generic_bs_wr_1,
199 1.4 matt generic_armv4_bs_wr_2,
200 1.4 matt generic_bs_wr_4,
201 1.4 matt bs_notimpl_bs_wr_8,
202 1.4 matt #endif
203 1.1 bsh };
204 1.1 bsh
205 1.1 bsh int
206 1.2 bsh imx_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
207 1.1 bsh int flag, bus_space_handle_t *bshp)
208 1.1 bsh {
209 1.5 matt const struct pmap_devmap *pd;
210 1.5 matt paddr_t startpa, endpa, pa;
211 1.1 bsh vaddr_t va;
212 1.1 bsh
213 1.1 bsh if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
214 1.1 bsh /* Device was statically mapped. */
215 1.1 bsh *bshp = pd->pd_va + (bpa - pd->pd_pa);
216 1.1 bsh return 0;
217 1.1 bsh }
218 1.1 bsh
219 1.1 bsh startpa = trunc_page(bpa);
220 1.1 bsh endpa = round_page(bpa + size);
221 1.1 bsh
222 1.1 bsh /* XXX use extent manager to check duplicate mapping */
223 1.1 bsh
224 1.1 bsh va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
225 1.1 bsh UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
226 1.1 bsh if (! va)
227 1.1 bsh return(ENOMEM);
228 1.1 bsh
229 1.1 bsh *bshp = (bus_space_handle_t)(va + (bpa - startpa));
230 1.1 bsh
231 1.1 bsh for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
232 1.4 matt pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE,
233 1.4 matt (flag & BUS_SPACE_MAP_CACHEABLE) ? 0 : PMAP_NOCACHE);
234 1.1 bsh }
235 1.1 bsh pmap_update(pmap_kernel());
236 1.1 bsh
237 1.1 bsh return(0);
238 1.1 bsh }
239 1.1 bsh
240 1.1 bsh void
241 1.2 bsh imx_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
242 1.1 bsh {
243 1.1 bsh vaddr_t va;
244 1.1 bsh vsize_t sz;
245 1.1 bsh
246 1.1 bsh if (pmap_devmap_find_va(bsh, size) != NULL) {
247 1.1 bsh /* Device was statically mapped; nothing to do. */
248 1.1 bsh return;
249 1.1 bsh }
250 1.1 bsh
251 1.1 bsh va = trunc_page(bsh);
252 1.1 bsh sz = round_page(bsh + size) - va;
253 1.1 bsh
254 1.1 bsh pmap_kremove(va, sz);
255 1.1 bsh pmap_update(pmap_kernel());
256 1.1 bsh uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY);
257 1.1 bsh }
258 1.1 bsh
259 1.1 bsh
260 1.1 bsh int
261 1.2 bsh imx_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
262 1.1 bsh bus_size_t size, bus_space_handle_t *nbshp)
263 1.1 bsh {
264 1.1 bsh
265 1.1 bsh *nbshp = bsh + offset;
266 1.1 bsh return (0);
267 1.1 bsh }
268 1.1 bsh
269 1.1 bsh void
270 1.2 bsh imx_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
271 1.1 bsh bus_size_t len, int flags)
272 1.1 bsh {
273 1.1 bsh
274 1.1 bsh /* Nothing to do. */
275 1.1 bsh }
276 1.1 bsh
277 1.1 bsh void *
278 1.2 bsh imx_bs_vaddr(void *t, bus_space_handle_t bsh)
279 1.1 bsh {
280 1.1 bsh
281 1.1 bsh return ((void *)bsh);
282 1.1 bsh }
283 1.1 bsh
284 1.1 bsh
285 1.1 bsh int
286 1.2 bsh imx_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
287 1.1 bsh bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
288 1.1 bsh bus_addr_t *bpap, bus_space_handle_t *bshp)
289 1.1 bsh {
290 1.1 bsh
291 1.2 bsh panic("imx_io_bs_alloc(): not implemented\n");
292 1.1 bsh }
293 1.1 bsh
294 1.1 bsh void
295 1.2 bsh imx_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
296 1.1 bsh {
297 1.1 bsh
298 1.2 bsh panic("imx_io_bs_free(): not implemented\n");
299 1.1 bsh }
300 1.1 bsh
301 1.1 bsh
302