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