1 /* $NetBSD: sa11x0_io.c,v 1.17 2006/06/27 13:58:08 peter Exp $ */
4 * Copyright (c) 1997 Mark Brinicombe.
5 * Copyright (c) 1997 Causality Limited.
8 * This code is derived from software contributed to The NetBSD Foundation
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Mark Brinicombe.
22 * 4. The name of the company nor the name of the author may be used to
23 * endorse or promote products derived from this software without specific
24 * prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * bus_space I/O functions for sa11x0
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: sa11x0_io.c,v 1.17 2006/06/27 13:58:08 peter Exp $");
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/queue.h>
52 #include <machine/bus.h>
53 #include <machine/pmap.h>
55 /* Prototypes for all the bus_space structure functions */
58 bs_protos(bs_notimpl
);
60 /* Declare the sa11x0 bus space tag */
62 struct bus_space sa11x0_bs_tag
= {
66 /* mapping/unmapping */
71 /* allocation/deallocation */
75 /* get kernel virtual address */
78 /* mmap bus space for userland */
139 /* bus space functions */
142 sa11x0_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
, int cacheable
,
143 bus_space_handle_t
*bshp
)
145 u_long startpa
, endpa
, pa
;
148 const struct pmap_devmap
*pd
;
150 if ((pd
= pmap_devmap_find_pa(bpa
, size
)) != NULL
) {
151 /* Device was statically mapped. */
152 *bshp
= pd
->pd_va
+ (bpa
- pd
->pd_pa
);
156 startpa
= trunc_page(bpa
);
157 endpa
= round_page(bpa
+ size
);
159 /* XXX use extent manager to check duplicate mapping */
161 va
= uvm_km_alloc(kernel_map
, endpa
- startpa
, 0,
162 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
166 *bshp
= (bus_space_handle_t
)(va
+ (bpa
- startpa
));
168 for (pa
= startpa
; pa
< endpa
; pa
+= PAGE_SIZE
, va
+= PAGE_SIZE
) {
169 pmap_kenter_pa(va
, pa
, VM_PROT_READ
| VM_PROT_WRITE
, 0);
171 if (cacheable
== 0) {
172 *pte
&= ~L2_S_CACHE_MASK
;
176 pmap_update(pmap_kernel());
182 sa11x0_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
, bus_size_t size
,
183 bus_size_t alignment
, bus_size_t boundary
, int cacheable
,
184 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
187 panic("sa11x0_bs_alloc(): Help!");
191 sa11x0_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
195 if (pmap_devmap_find_va(bsh
, size
) != NULL
) {
196 /* Device was statically mapped; nothing to do. */
200 va
= trunc_page(bsh
);
201 endva
= round_page(bsh
+ size
);
203 pmap_kremove(va
, endva
- va
);
204 pmap_update(pmap_kernel());
206 uvm_km_free(kernel_map
, va
, endva
- va
, UVM_KMF_VAONLY
);
210 sa11x0_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
213 panic("sa11x0_bs_free(): Help!");
217 sa11x0_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
218 bus_size_t size
, bus_space_handle_t
*nbshp
)
221 *nbshp
= bsh
+ offset
;
226 sa11x0_bs_mmap(void *t
, bus_addr_t paddr
, off_t offset
, int prot
, int flags
)
229 * mmap from address `paddr+offset' for one page
231 return arm_btop((paddr
+ offset
));
235 sa11x0_bs_vaddr(void *t
, bus_space_handle_t bsh
)
241 sa11x0_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
242 bus_size_t len
, int flags
)