1 /* $NetBSD: ixp425_space.c,v 1.6 2006/04/10 03:36:03 simonb Exp $ */
5 * Ichiro FUKUHARA <ichiro@ichiro.org>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
17 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __KERNEL_RCSID(0, "$NetBSD: ixp425_space.c,v 1.6 2006/04/10 03:36:03 simonb Exp $");
34 * bus_space I/O functions for ixp425
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/queue.h>
43 #include <machine/bus.h>
45 #include <arm/xscale/ixp425reg.h>
46 #include <arm/xscale/ixp425var.h>
48 /* Proto types for all the bus_space structure functions */
51 bs_protos(generic_armv4
);
52 bs_protos(bs_notimpl
);
54 struct bus_space ixp425_bs_tag
= {
58 /* mapping/unmapping */
63 /* allocation/deallocation */
67 /* get kernel virtual address */
70 /* mmap bus space for userland */
84 generic_armv4_bs_rm_2
,
90 generic_armv4_bs_rr_2
,
102 generic_armv4_bs_wm_2
,
108 generic_armv4_bs_wr_2
,
120 generic_armv4_bs_sr_2
,
126 generic_armv4_bs_c_2
,
132 ixp425_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
,
133 int cacheable
, bus_space_handle_t
*bshp
)
135 const struct pmap_devmap
*pd
;
143 if ((pd
= pmap_devmap_find_pa(bpa
, size
)) != NULL
) {
144 /* Device was statically mapped. */
145 *bshp
= pd
->pd_va
+ (bpa
- pd
->pd_pa
);
149 endpa
= round_page(bpa
+ size
);
150 offset
= bpa
& PAGE_MASK
;
151 startpa
= trunc_page(bpa
);
154 va
= uvm_km_alloc(kernel_map
, endpa
- startpa
, 0,
155 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
159 /* Store the bus space handle */
162 /* Now map the pages */
163 for (pa
= startpa
; pa
< endpa
; pa
+= PAGE_SIZE
, va
+= PAGE_SIZE
) {
164 pmap_enter(pmap_kernel(), va
, pa
,
165 VM_PROT_READ
| VM_PROT_WRITE
,
166 VM_PROT_READ
| VM_PROT_WRITE
| PMAP_WIRED
);
168 pmap_update(pmap_kernel());
174 ixp425_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
179 if (pmap_devmap_find_va(bsh
, size
) != NULL
) {
180 /* Device was statically mapped; nothing to do. */
184 endva
= round_page(bsh
+ size
);
185 va
= trunc_page(bsh
);
187 pmap_remove(pmap_kernel(), va
, endva
);
188 pmap_update(pmap_kernel());
189 uvm_km_free(kernel_map
, va
, endva
- va
, UVM_KMF_VAONLY
);
193 ixp425_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
,
194 bus_size_t size
, bus_size_t alignment
, bus_size_t boundary
, int cacheable
,
195 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
197 panic("ixp425_bs_alloc(): not implemented\n");
201 ixp425_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
203 panic("ixp425_bs_free(): not implemented\n");
207 ixp425_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
208 bus_size_t size
, bus_space_handle_t
*nbshp
)
210 *nbshp
= bsh
+ offset
;
215 ixp425_bs_vaddr(void *t
, bus_space_handle_t bsh
)
217 return ((void *)bsh
);
221 ixp425_bs_mmap(void *t
, bus_addr_t addr
, off_t off
, int prot
, int flags
)
228 ixp425_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
229 bus_size_t len
, int flags
)
233 /* End of ixp425_space.c */