No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / gemini / gemini_space.c
blob0ba4b67b3d54a25ba9bfd1bae7e0be2108edee5b
1 /* $NetBSD: gemini_space.c,v 1.1 2008/10/24 04:23:18 matt Exp $ */
3 /* adapted from:
4 * NetBSD: pxa2x0_space.c,v 1.8 2005/11/24 13:08:32 yamt Exp
5 */
7 /*
8 * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
9 * All rights reserved.
11 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed for the NetBSD Project by
24 * Wasabi Systems, Inc.
25 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
26 * or promote products derived from this software without specific prior
27 * written permission.
29 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
33 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
42 * Copyright (c) 1997 Mark Brinicombe.
43 * Copyright (c) 1997 Causality Limited.
44 * All rights reserved.
46 * This code is derived from software contributed to The NetBSD Foundation
47 * by Ichiro FUKUHARA.
49 * Redistribution and use in source and binary forms, with or without
50 * modification, are permitted provided that the following conditions
51 * are met:
52 * 1. Redistributions of source code must retain the above copyright
53 * notice, this list of conditions and the following disclaimer.
54 * 2. Redistributions in binary form must reproduce the above copyright
55 * notice, this list of conditions and the following disclaimer in the
56 * documentation and/or other materials provided with the distribution.
57 * 3. All advertising materials mentioning features or use of this software
58 * must display the following acknowledgement:
59 * This product includes software developed by Mark Brinicombe.
60 * 4. The name of the company nor the name of the author may be used to
61 * endorse or promote products derived from this software without specific
62 * prior written permission.
64 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
65 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
66 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
67 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
68 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
69 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
70 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * SUCH DAMAGE.
78 * bus_space functions for Gemini processor.
81 #include <sys/cdefs.h>
82 __KERNEL_RCSID(0, "$NetBSD: gemini_space.c,v 1.1 2008/10/24 04:23:18 matt Exp $");
84 #include <sys/param.h>
85 #include <sys/systm.h>
87 #include <uvm/uvm_extern.h>
89 #include <machine/bus.h>
91 /* Prototypes for all the bus_space structure functions */
92 bs_protos(gemini);
93 bs_protos(generic);
94 bs_protos(generic_armv4);
95 bs_protos(bs_notimpl);
97 struct bus_space gemini_bs_tag = {
98 /* cookie */
99 (void *) 0,
101 /* mapping/unmapping */
102 gemini_bs_map,
103 gemini_bs_unmap,
104 gemini_bs_subregion,
106 /* allocation/deallocation */
107 gemini_bs_alloc, /* not implemented */
108 gemini_bs_free, /* not implemented */
110 /* get kernel virtual address */
111 gemini_bs_vaddr,
113 /* mmap */
114 bs_notimpl_bs_mmap,
116 /* barrier */
117 gemini_bs_barrier,
119 /* read (single) */
120 generic_bs_r_1,
121 generic_armv4_bs_r_2,
122 generic_bs_r_4,
123 bs_notimpl_bs_r_8,
125 /* read multiple */
126 generic_bs_rm_1,
127 generic_armv4_bs_rm_2,
128 generic_bs_rm_4,
129 bs_notimpl_bs_rm_8,
131 /* read region */
132 generic_bs_rr_1,
133 generic_armv4_bs_rr_2,
134 generic_bs_rr_4,
135 bs_notimpl_bs_rr_8,
137 /* write (single) */
138 generic_bs_w_1,
139 generic_armv4_bs_w_2,
140 generic_bs_w_4,
141 bs_notimpl_bs_w_8,
143 /* write multiple */
144 generic_bs_wm_1,
145 generic_armv4_bs_wm_2,
146 generic_bs_wm_4,
147 bs_notimpl_bs_wm_8,
149 /* write region */
150 generic_bs_wr_1,
151 generic_armv4_bs_wr_2,
152 generic_bs_wr_4,
153 bs_notimpl_bs_wr_8,
155 /* set multiple */
156 bs_notimpl_bs_sm_1,
157 bs_notimpl_bs_sm_2,
158 bs_notimpl_bs_sm_4,
159 bs_notimpl_bs_sm_8,
161 /* set region */
162 generic_bs_sr_1,
163 generic_armv4_bs_sr_2,
164 bs_notimpl_bs_sr_4,
165 bs_notimpl_bs_sr_8,
167 /* copy */
168 bs_notimpl_bs_c_1,
169 generic_armv4_bs_c_2,
170 bs_notimpl_bs_c_4,
171 bs_notimpl_bs_c_8,
175 gemini_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
176 int flag, bus_space_handle_t *bshp)
178 u_long startpa, endpa, pa;
179 vaddr_t va;
180 pt_entry_t *pte;
181 const struct pmap_devmap *pd;
183 if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
184 /* Device was statically mapped. */
185 *bshp = pd->pd_va + (bpa - pd->pd_pa);
186 return 0;
189 startpa = trunc_page(bpa);
190 endpa = round_page(bpa + size);
192 /* XXX use extent manager to check duplicate mapping */
194 va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
195 UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
196 if (! va)
197 return(ENOMEM);
199 *bshp = (bus_space_handle_t)(va + (bpa - startpa));
201 for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
202 pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, 0);
203 if ((flag & BUS_SPACE_MAP_CACHEABLE) == 0) {
204 pte = vtopte(va);
205 *pte &= ~L2_S_CACHE_MASK;
206 PTE_SYNC(pte);
207 /* XXX: pmap_kenter_pa() also does PTE_SYNC(). a bit of
208 * waste.
212 pmap_update(pmap_kernel());
214 return(0);
217 void
218 gemini_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
220 vaddr_t va;
221 vsize_t sz;
223 if (pmap_devmap_find_va(bsh, size) != NULL) {
224 /* Device was statically mapped; nothing to do. */
225 return;
228 va = trunc_page(bsh);
229 sz = round_page(bsh + size) - va;
231 pmap_kremove(va, sz);
232 pmap_update(pmap_kernel());
233 uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY);
238 gemini_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
239 bus_size_t size, bus_space_handle_t *nbshp)
242 *nbshp = bsh + offset;
243 return (0);
246 void
247 gemini_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
248 bus_size_t len, int flags)
251 /* Nothing to do. */
254 void *
255 gemini_bs_vaddr(void *t, bus_space_handle_t bsh)
258 return ((void *)bsh);
263 gemini_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
264 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
265 bus_addr_t *bpap, bus_space_handle_t *bshp)
268 panic("gemini_io_bs_alloc(): not implemented\n");
271 void
272 gemini_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
275 panic("gemini_io_bs_free(): not implemented\n");