1 /* $NetBSD: ixp12x0_io.c,v 1.13 2009/10/21 14:15:50 rmind Exp $ */
4 * Copyright (c) 2002, 2003
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: ixp12x0_io.c,v 1.13 2009/10/21 14:15:50 rmind Exp $");
34 * bus_space I/O functions for ixp12x0
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/queue.h>
43 #include <machine/bus.h>
45 #include <arm/ixp12x0/ixp12x0reg.h>
46 #include <arm/ixp12x0/ixp12x0var.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 ixp12x0_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
,
131 /* Common routines */
134 ixp12x0_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
,
135 int flags
, bus_space_handle_t
*bshp
)
137 const struct pmap_devmap
*pd
;
146 if ((pd
= pmap_devmap_find_pa(bpa
, size
)) != NULL
) {
147 /* Device was statically mapped. */
148 *bshp
= pd
->pd_va
+ (bpa
- pd
->pd_pa
);
152 endpa
= round_page(bpa
+ size
);
153 offset
= bpa
& PAGE_MASK
;
154 startpa
= trunc_page(bpa
);
156 va
= uvm_km_alloc(kernel_map
, endpa
- startpa
, 0,
157 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
163 for (pa
= startpa
; pa
< endpa
; pa
+= PAGE_SIZE
, va
+= PAGE_SIZE
) {
164 pmap_kenter_pa(va
, pa
, VM_PROT_READ
| VM_PROT_WRITE
, 0);
166 *pte
&= ~L2_S_CACHE_MASK
;
169 pmap_update(pmap_kernel());
175 ixp12x0_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
180 if (pmap_devmap_find_va(bsh
, size
) != NULL
) {
181 /* Device was statically mapped; nothing to do. */
185 endva
= round_page(bsh
+ size
);
186 va
= trunc_page(bsh
);
188 pmap_kremove(va
, endva
- va
);
189 uvm_km_free(kernel_map
, va
, endva
- va
, UVM_KMF_VAONLY
);
193 ixp12x0_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
, bus_size_t size
, bus_space_handle_t
*nbshp
)
196 *nbshp
= bsh
+ offset
;
201 ixp12x0_bs_vaddr(void *t
, bus_space_handle_t bsh
)
203 return ((void *)bsh
);
207 ixp12x0_bs_alloc(void *t
,
208 bus_addr_t rstart
, bus_addr_t rend
, bus_size_t size
,
209 bus_size_t alignment
, bus_size_t boundary
,
210 int flags
, bus_addr_t
*bpap
,
211 bus_space_handle_t
*bshp
)
213 panic("ixp12x0_bs_alloc(): not implemented\n");
217 ixp12x0_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
219 panic("ixp12x0_bs_free(): not implemented\n");
223 ixp12x0_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
, bus_size_t len
, int flags
)
228 /* End of ixp12x0_io.c */