1 /* $NetBSD: ep93xx_space.c,v 1.3 2005/11/24 13:08:32 yamt Exp $ */
4 * Copyright (c) 2004 Jesse Off
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: ep93xx_space.c,v 1.3 2005/11/24 13:08:32 yamt Exp $");
33 * bus_space I/O functions for ep93xx
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/queue.h>
42 #include <machine/bus.h>
44 #include <arm/ep93xx/ep93xxreg.h>
45 #include <arm/ep93xx/ep93xxvar.h>
47 /* Proto types for all the bus_space structure functions */
50 bs_protos(generic_armv4
);
51 bs_protos(bs_notimpl
);
53 struct bus_space ep93xx_bs_tag
= {
57 /* mapping/unmapping */
62 /* allocation/deallocation */
66 /* get kernel virtual address */
69 /* mmap bus space for userland */
83 generic_armv4_bs_rm_2
,
89 generic_armv4_bs_rr_2
,
101 generic_armv4_bs_wm_2
,
107 generic_armv4_bs_wr_2
,
119 generic_armv4_bs_sr_2
,
125 generic_armv4_bs_c_2
,
131 ep93xx_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
,
132 int cacheable
, bus_space_handle_t
*bshp
)
134 const struct pmap_devmap
*pd
;
142 if ((pd
= pmap_devmap_find_pa(bpa
, size
)) != NULL
) {
143 /* Device was statically mapped. */
144 *bshp
= pd
->pd_va
+ (bpa
- pd
->pd_pa
);
148 endpa
= round_page(bpa
+ size
);
149 offset
= bpa
& PAGE_MASK
;
150 startpa
= trunc_page(bpa
);
153 va
= uvm_km_alloc(kernel_map
, endpa
- startpa
, 0,
154 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
158 /* Store the bus space handle */
161 /* Now map the pages */
162 for (pa
= startpa
; pa
< endpa
; pa
+= PAGE_SIZE
, va
+= PAGE_SIZE
) {
163 pmap_enter(pmap_kernel(), va
, pa
,
164 VM_PROT_READ
| VM_PROT_WRITE
,
165 VM_PROT_READ
| VM_PROT_WRITE
| PMAP_WIRED
);
167 pmap_update(pmap_kernel());
173 ep93xx_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
178 if (pmap_devmap_find_va(bsh
, size
) != NULL
) {
179 /* Device was statically mapped; nothing to do. */
183 endva
= round_page(bsh
+ size
);
184 va
= trunc_page(bsh
);
186 pmap_remove(pmap_kernel(), va
, endva
);
187 pmap_update(pmap_kernel());
188 uvm_km_free(kernel_map
, va
, endva
- va
, UVM_KMF_VAONLY
);
192 ep93xx_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
,
193 bus_size_t size
, bus_size_t alignment
, bus_size_t boundary
, int cacheable
,
194 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
196 panic("ep93xx_bs_alloc(): not implemented\n");
200 ep93xx_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
202 panic("ep93xx_bs_free(): not implemented\n");
206 ep93xx_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
207 bus_size_t size
, bus_space_handle_t
*nbshp
)
209 *nbshp
= bsh
+ offset
;
214 ep93xx_bs_vaddr(void *t
, bus_space_handle_t bsh
)
216 return ((void *)bsh
);
220 ep93xx_bs_mmap(void *t
, bus_addr_t addr
, off_t off
, int prot
, int flags
)
227 ep93xx_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
228 bus_size_t len
, int flags
)
232 /* End of ep93xx_space.c */