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