1 /* $NetBSD: pxa2x0_space.c,v 1.8 2005/11/24 13:08:32 yamt Exp $ */
4 * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1997 Mark Brinicombe.
39 * Copyright (c) 1997 Causality Limited.
40 * All rights reserved.
42 * This code is derived from software contributed to The NetBSD Foundation
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by Mark Brinicombe.
56 * 4. The name of the company nor the name of the author may be used to
57 * endorse or promote products derived from this software without specific
58 * prior written permission.
60 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
61 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
62 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
64 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
65 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
66 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * bus_space functions for Intel PXA2[51]0 application processor.
75 * Derived from i80321_space.c.
78 #include <sys/cdefs.h>
79 __KERNEL_RCSID(0, "$NetBSD: pxa2x0_space.c,v 1.8 2005/11/24 13:08:32 yamt Exp $");
81 #include <sys/param.h>
82 #include <sys/systm.h>
84 #include <uvm/uvm_extern.h>
86 #include <machine/bus.h>
88 /* Prototypes for all the bus_space structure functions */
91 bs_protos(generic_armv4
);
92 bs_protos(bs_notimpl
);
94 struct bus_space pxa2x0_bs_tag
= {
98 /* mapping/unmapping */
103 /* allocation/deallocation */
104 pxa2x0_bs_alloc
, /* not implemented */
105 pxa2x0_bs_free
, /* not implemented */
107 /* get kernel virtual address */
118 generic_armv4_bs_r_2
,
124 generic_armv4_bs_rm_2
,
130 generic_armv4_bs_rr_2
,
136 generic_armv4_bs_w_2
,
142 generic_armv4_bs_wm_2
,
148 generic_armv4_bs_wr_2
,
160 generic_armv4_bs_sr_2
,
166 generic_armv4_bs_c_2
,
172 pxa2x0_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
,
173 int flag
, bus_space_handle_t
*bshp
)
175 u_long startpa
, endpa
, pa
;
178 const struct pmap_devmap
*pd
;
180 if ((pd
= pmap_devmap_find_pa(bpa
, size
)) != NULL
) {
181 /* Device was statically mapped. */
182 *bshp
= pd
->pd_va
+ (bpa
- pd
->pd_pa
);
186 startpa
= trunc_page(bpa
);
187 endpa
= round_page(bpa
+ size
);
189 /* XXX use extent manager to check duplicate mapping */
191 va
= uvm_km_alloc(kernel_map
, endpa
- startpa
, 0,
192 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
196 *bshp
= (bus_space_handle_t
)(va
+ (bpa
- startpa
));
198 for (pa
= startpa
; pa
< endpa
; pa
+= PAGE_SIZE
, va
+= PAGE_SIZE
) {
199 pmap_kenter_pa(va
, pa
, VM_PROT_READ
| VM_PROT_WRITE
, 0);
200 if ((flag
& BUS_SPACE_MAP_CACHEABLE
) == 0) {
202 *pte
&= ~L2_S_CACHE_MASK
;
204 /* XXX: pmap_kenter_pa() also does PTE_SYNC(). a bit of
209 pmap_update(pmap_kernel());
215 pxa2x0_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
220 if (pmap_devmap_find_va(bsh
, size
) != NULL
) {
221 /* Device was statically mapped; nothing to do. */
225 va
= trunc_page(bsh
);
226 sz
= round_page(bsh
+ size
) - va
;
228 pmap_kremove(va
, sz
);
229 pmap_update(pmap_kernel());
230 uvm_km_free(kernel_map
, va
, sz
, UVM_KMF_VAONLY
);
235 pxa2x0_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
236 bus_size_t size
, bus_space_handle_t
*nbshp
)
239 *nbshp
= bsh
+ offset
;
244 pxa2x0_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
245 bus_size_t len
, int flags
)
252 pxa2x0_bs_vaddr(void *t
, bus_space_handle_t bsh
)
255 return ((void *)bsh
);
260 pxa2x0_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
,
261 bus_size_t size
, bus_size_t alignment
, bus_size_t boundary
, int flags
,
262 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
265 panic("pxa2x0_io_bs_alloc(): not implemented\n");
269 pxa2x0_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
272 panic("pxa2x0_io_bs_free(): not implemented\n");