No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / omap / omap_space.c
blob100343a4b20156ed91ad47e59174f8a7954301d4
1 /* $NetBSD: omap_space.c,v 1.2 2007/12/15 00:39:14 perry Exp $ */
3 /*
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.
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.
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
45 * by Ichiro FUKUHARA.
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
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
72 * SUCH DAMAGE.
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 */
86 bs_protos(omap);
87 bs_protos(generic);
88 bs_protos(generic_armv4);
89 bs_protos(bs_notimpl);
91 struct bus_space omap_bs_tag = {
92 /* cookie */
93 (void *) 0,
95 /* mapping/unmapping */
96 omap_bs_map,
97 omap_bs_unmap,
98 omap_bs_subregion,
100 /* allocation/deallocation */
101 omap_bs_alloc, /* not implemented */
102 omap_bs_free, /* not implemented */
104 /* get kernel virtual address */
105 omap_bs_vaddr,
107 /* mmap */
108 bs_notimpl_bs_mmap,
110 /* barrier */
111 omap_bs_barrier,
113 /* read (single) */
114 generic_bs_r_1,
115 generic_armv4_bs_r_2,
116 generic_bs_r_4,
117 bs_notimpl_bs_r_8,
119 /* read multiple */
120 generic_bs_rm_1,
121 generic_armv4_bs_rm_2,
122 generic_bs_rm_4,
123 bs_notimpl_bs_rm_8,
125 /* read region */
126 generic_bs_rr_1,
127 generic_armv4_bs_rr_2,
128 generic_bs_rr_4,
129 bs_notimpl_bs_rr_8,
131 /* write (single) */
132 generic_bs_w_1,
133 generic_armv4_bs_w_2,
134 generic_bs_w_4,
135 bs_notimpl_bs_w_8,
137 /* write multiple */
138 generic_bs_wm_1,
139 generic_armv4_bs_wm_2,
140 generic_bs_wm_4,
141 bs_notimpl_bs_wm_8,
143 /* write region */
144 generic_bs_wr_1,
145 generic_armv4_bs_wr_2,
146 generic_bs_wr_4,
147 bs_notimpl_bs_wr_8,
149 /* set multiple */
150 bs_notimpl_bs_sm_1,
151 bs_notimpl_bs_sm_2,
152 bs_notimpl_bs_sm_4,
153 bs_notimpl_bs_sm_8,
155 /* set region */
156 generic_bs_sr_1,
157 generic_armv4_bs_sr_2,
158 bs_notimpl_bs_sr_4,
159 bs_notimpl_bs_sr_8,
161 /* copy */
162 bs_notimpl_bs_c_1,
163 generic_armv4_bs_c_2,
164 bs_notimpl_bs_c_4,
165 bs_notimpl_bs_c_8,
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;
173 vaddr_t va;
174 pt_entry_t *pte;
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);
180 return 0;
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);
190 if (! va)
191 return(ENOMEM);
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) {
198 pte = vtopte(va);
199 *pte &= ~L2_S_CACHE_MASK;
200 PTE_SYNC(pte);
201 /* XXX: pmap_kenter_pa() also does PTE_SYNC(). a bit of
202 * waste.
206 pmap_update(pmap_kernel());
208 return(0);
211 void
212 omap_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
214 vaddr_t va;
215 vsize_t sz;
217 if (pmap_devmap_find_va(bsh, size) != NULL) {
218 /* Device was statically mapped; nothing to do. */
219 return;
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;
237 return (0);
240 void
241 omap_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
242 bus_size_t len, int flags)
245 /* Nothing to do. */
248 void *
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__);
265 void
266 omap_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
269 panic("%s(): not implemented\n", __func__);