1 /* $Id: imx31_space.c,v 1.3 2009/11/07 07:27:41 cegger Exp $ */
4 /* $NetBSD: imx31_space.c,v 1.2 2008/04/27 18:58:44 matt Exp $ */
7 * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
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
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
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
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
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
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>
87 bs_protos(generic_armv4
);
88 bs_protos(bs_notimpl
);
90 struct bus_space imx31_bs_tag
= {
94 /* mapping/unmapping */
99 /* allocation/deallocation */
100 imx31_bs_alloc
, /* not implemented */
101 imx31_bs_free
, /* not implemented */
103 /* get kernel virtual address */
114 generic_armv4_bs_r_2
,
120 generic_armv4_bs_rm_2
,
126 generic_armv4_bs_rr_2
,
132 generic_armv4_bs_w_2
,
138 generic_armv4_bs_wm_2
,
144 generic_armv4_bs_wr_2
,
156 generic_armv4_bs_sr_2
,
162 generic_armv4_bs_c_2
,
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
;
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
);
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
);
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) {
198 *pte
&= ~L2_S_CACHE_MASK
;
200 /* XXX: pmap_kenter_pa() also does PTE_SYNC(). a bit of
205 pmap_update(pmap_kernel());
211 imx31_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
216 if (pmap_devmap_find_va(bsh
, size
) != NULL
) {
217 /* Device was statically mapped; nothing to do. */
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
;
240 imx31_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
241 bus_size_t len
, int flags
)
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");
265 imx31_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
268 panic("imx31_io_bs_free(): not implemented\n");