1 /* $NetBSD: omap_space.c,v 1.2 2007/12/15 00:39:14 perry Exp $ */
4 * bus_space functions for Texas Instruments OMAP processor.
5 * Based on pxa2x0_space.c which in turn was derived from i80321_space.c.
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.
40 * Copyright (c) 1997 Mark Brinicombe.
41 * Copyright (c) 1997 Causality Limited.
42 * All rights reserved.
44 * This code is derived from software contributed to The NetBSD Foundation
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. All advertising materials mentioning features or use of this software
56 * must display the following acknowledgement:
57 * This product includes software developed by Mark Brinicombe.
58 * 4. The name of the company nor the name of the author may be used to
59 * endorse or promote products derived from this software without specific
60 * prior written permission.
62 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
63 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
64 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
65 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
66 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
67 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
68 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD: omap_space.c,v 1.2 2007/12/15 00:39:14 perry Exp $");
78 #include <sys/param.h>
79 #include <sys/systm.h>
81 #include <uvm/uvm_extern.h>
83 #include <machine/bus.h>
85 /* Prototypes for all the bus_space structure functions */
88 bs_protos(generic_armv4
);
89 bs_protos(bs_notimpl
);
91 struct bus_space omap_bs_tag
= {
95 /* mapping/unmapping */
100 /* allocation/deallocation */
101 omap_bs_alloc
, /* not implemented */
102 omap_bs_free
, /* not implemented */
104 /* get kernel virtual address */
115 generic_armv4_bs_r_2
,
121 generic_armv4_bs_rm_2
,
127 generic_armv4_bs_rr_2
,
133 generic_armv4_bs_w_2
,
139 generic_armv4_bs_wm_2
,
145 generic_armv4_bs_wr_2
,
157 generic_armv4_bs_sr_2
,
163 generic_armv4_bs_c_2
,
169 omap_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
,
170 int flag
, bus_space_handle_t
*bshp
)
172 u_long startpa
, endpa
, pa
;
175 const struct pmap_devmap
*pd
;
177 if ((pd
= pmap_devmap_find_pa(bpa
, size
)) != NULL
) {
178 /* Device was statically mapped. */
179 *bshp
= pd
->pd_va
+ (bpa
- pd
->pd_pa
);
183 startpa
= trunc_page(bpa
);
184 endpa
= round_page(bpa
+ size
);
186 /* XXX use extent manager to check duplicate mapping */
188 va
= uvm_km_alloc(kernel_map
, endpa
- startpa
, 0,
189 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
193 *bshp
= (bus_space_handle_t
)(va
+ (bpa
- startpa
));
195 for (pa
= startpa
; pa
< endpa
; pa
+= PAGE_SIZE
, va
+= PAGE_SIZE
) {
196 pmap_kenter_pa(va
, pa
, VM_PROT_READ
| VM_PROT_WRITE
, 0);
197 if ((flag
& BUS_SPACE_MAP_CACHEABLE
) == 0) {
199 *pte
&= ~L2_S_CACHE_MASK
;
201 /* XXX: pmap_kenter_pa() also does PTE_SYNC(). a bit of
206 pmap_update(pmap_kernel());
212 omap_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
217 if (pmap_devmap_find_va(bsh
, size
) != NULL
) {
218 /* Device was statically mapped; nothing to do. */
222 va
= trunc_page(bsh
);
223 sz
= round_page(bsh
+ size
) - va
;
225 pmap_kremove(va
, sz
);
226 pmap_update(pmap_kernel());
227 uvm_km_free(kernel_map
, va
, sz
, UVM_KMF_VAONLY
);
232 omap_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
233 bus_size_t size
, bus_space_handle_t
*nbshp
)
236 *nbshp
= bsh
+ offset
;
241 omap_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
242 bus_size_t len
, int flags
)
249 omap_bs_vaddr(void *t
, bus_space_handle_t bsh
)
252 return ((void *)bsh
);
257 omap_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
,
258 bus_size_t size
, bus_size_t alignment
, bus_size_t boundary
, int flags
,
259 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
262 panic("%s(): not implemented\n", __func__
);
266 omap_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
269 panic("%s(): not implemented\n", __func__
);