No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / arm / s3c2xx0 / s3c2xx0_space.c
bloba70d1c31f9e674ffde9cafc654525083f863c79d
1 /* $NetBSD: s3c2xx0_space.c,v 1.7 2005/11/24 13:08:32 yamt Exp $ */
3 /*
4 * Copyright (c) 2002 Fujitsu Component Limited
5 * Copyright (c) 2002 Genetec Corporation
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of The Fujitsu Component Limited nor the name of
17 * Genetec corporation may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
21 * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
25 * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 /* derived from sa11x0_io.c */
37 * Copyright (c) 1997 Mark Brinicombe.
38 * Copyright (c) 1997 Causality Limited.
39 * All rights reserved.
41 * This code is derived from software contributed to The NetBSD Foundation
42 * by Ichiro FUKUHARA.
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by Mark Brinicombe.
55 * 4. The name of the company nor the name of the author may be used to
56 * endorse or promote products derived from this software without specific
57 * prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
60 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
61 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
63 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
64 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
65 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 * SUCH DAMAGE.
73 * bus_space functions for Samsung S3C2800/2400/2410.
76 #include <sys/cdefs.h>
77 __KERNEL_RCSID(0, "$NetBSD: s3c2xx0_space.c,v 1.7 2005/11/24 13:08:32 yamt Exp $");
79 #include <sys/param.h>
80 #include <sys/systm.h>
82 #include <uvm/uvm_extern.h>
84 #include <machine/bus.h>
86 /* Prototypes for all the bus_space structure functions */
87 bs_protos(s3c2xx0);
88 bs_protos(generic);
89 bs_protos(generic_armv4);
90 bs_protos(bs_notimpl);
92 struct bus_space s3c2xx0_bs_tag = {
93 /* cookie */
94 (void *) 0,
96 /* mapping/unmapping */
97 s3c2xx0_bs_map,
98 s3c2xx0_bs_unmap,
99 s3c2xx0_bs_subregion,
101 /* allocation/deallocation */
102 s3c2xx0_bs_alloc, /* not implemented */
103 s3c2xx0_bs_free, /* not implemented */
105 /* get kernel virtual address */
106 s3c2xx0_bs_vaddr,
108 /* mmap */
109 bs_notimpl_bs_mmap,
111 /* barrier */
112 s3c2xx0_bs_barrier,
114 /* read (single) */
115 generic_bs_r_1,
116 generic_armv4_bs_r_2,
117 generic_bs_r_4,
118 bs_notimpl_bs_r_8,
120 /* read multiple */
121 generic_bs_rm_1,
122 generic_armv4_bs_rm_2,
123 generic_bs_rm_4,
124 bs_notimpl_bs_rm_8,
126 /* read region */
127 generic_bs_rr_1,
128 generic_armv4_bs_rr_2,
129 generic_bs_rr_4,
130 bs_notimpl_bs_rr_8,
132 /* write (single) */
133 generic_bs_w_1,
134 generic_armv4_bs_w_2,
135 generic_bs_w_4,
136 bs_notimpl_bs_w_8,
138 /* write multiple */
139 generic_bs_wm_1,
140 generic_armv4_bs_wm_2,
141 generic_bs_wm_4,
142 bs_notimpl_bs_wm_8,
144 /* write region */
145 generic_bs_wr_1,
146 generic_armv4_bs_wr_2,
147 generic_bs_wr_4,
148 bs_notimpl_bs_wr_8,
150 /* set multiple */
151 bs_notimpl_bs_sm_1,
152 bs_notimpl_bs_sm_2,
153 bs_notimpl_bs_sm_4,
154 bs_notimpl_bs_sm_8,
156 /* set region */
157 generic_bs_sr_1,
158 generic_armv4_bs_sr_2,
159 bs_notimpl_bs_sr_4,
160 bs_notimpl_bs_sr_8,
162 /* copy */
163 bs_notimpl_bs_c_1,
164 generic_armv4_bs_c_2,
165 bs_notimpl_bs_c_4,
166 bs_notimpl_bs_c_8,
170 s3c2xx0_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
171 int flag, bus_space_handle_t * bshp)
173 u_long startpa, endpa, pa;
174 vaddr_t va;
175 pt_entry_t *pte;
176 const struct pmap_devmap *pd;
178 if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
179 /* Device was statically mapped. */
180 *bshp = pd->pd_va + (bpa - pd->pd_pa);
181 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 pte = vtopte(va);
198 if ((flag & BUS_SPACE_MAP_CACHEABLE) == 0)
199 *pte &= ~L2_S_CACHE_MASK;
201 pmap_update(pmap_kernel());
203 return (0);
206 void
207 s3c2xx0_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
209 vaddr_t va;
210 vaddr_t endva;
212 if (pmap_devmap_find_va(bsh, size) != NULL) {
213 /* Device was statically mapped; nothing to do. */
214 return;
217 endva = round_page(bsh + size);
218 va = trunc_page(bsh);
220 pmap_kremove(va, endva - va);
221 pmap_update(pmap_kernel());
222 uvm_km_free(kernel_map, va, endva - va, UVM_KMF_VAONLY);
227 s3c2xx0_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
228 bus_size_t size, bus_space_handle_t * nbshp)
231 *nbshp = bsh + offset;
232 return (0);
235 void
236 s3c2xx0_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
237 bus_size_t len, int flags)
240 /* Nothing to do. */
243 void *
244 s3c2xx0_bs_vaddr(void *t, bus_space_handle_t bsh)
247 return ((void *) bsh);
252 s3c2xx0_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
253 bus_size_t size, bus_size_t alignment, bus_size_t boundary,
254 int flags, bus_addr_t * bpap, bus_space_handle_t * bshp)
257 panic("s3c2xx0_io_bs_alloc(): not implemented\n");
260 void
261 s3c2xx0_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
264 panic("s3c2xx0_io_bs_free(): not implemented\n");