1 /* $NetBSD: at91_bus_space.c,v 1.2 2008/07/03 01:15:38 matt Exp $ */
4 * Based on ep93xx_space.c
5 * Copyright (c) 2007 Embedtronics Oy
8 * Copyright (c) 2004 Jesse Off
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.
20 * THIS SOFTWARE IS PROVIDED BY ICHIRO FUKUHARA ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL ICHIRO FUKUHARA OR THE VOICES IN HIS HEAD BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: at91_bus_space.c,v 1.2 2008/07/03 01:15:38 matt Exp $");
37 * bus_space I/O functions for ep93xx
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/queue.h>
46 #include <machine/bus.h>
48 #include <arm/at91/at91var.h>
49 //#include <arm/ep93xx/ep93xxreg.h>
50 //#include <arm/ep93xx/ep93xxvar.h>
52 /* Proto types for all the bus_space structure functions */
55 bs_protos(generic_armv4
);
56 bs_protos(bs_notimpl
);
58 struct bus_space at91_bs_tag
= {
62 /* mapping/unmapping */
67 /* allocation/deallocation */
71 /* get kernel virtual address */
74 /* mmap bus space for userland */
88 generic_armv4_bs_rm_2
,
94 generic_armv4_bs_rr_2
,
100 generic_armv4_bs_w_2
,
106 generic_armv4_bs_wm_2
,
112 generic_armv4_bs_wr_2
,
124 generic_armv4_bs_sr_2
,
130 generic_armv4_bs_c_2
,
136 at91_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
,
137 int cacheable
, bus_space_handle_t
*bshp
)
139 const struct pmap_devmap
*pd
;
147 if ((pd
= pmap_devmap_find_pa(bpa
, size
)) != NULL
) {
148 /* Device was statically mapped. */
149 *bshp
= pd
->pd_va
+ (bpa
- pd
->pd_pa
);
153 endpa
= round_page(bpa
+ size
);
154 offset
= bpa
& PAGE_MASK
;
155 startpa
= trunc_page(bpa
);
158 va
= uvm_km_alloc(kernel_map
, endpa
- startpa
, 0,
159 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
163 /* Store the bus space handle */
166 /* Now map the pages */
167 for (pa
= startpa
; pa
< endpa
; pa
+= PAGE_SIZE
, va
+= PAGE_SIZE
) {
168 pmap_enter(pmap_kernel(), va
, pa
,
169 VM_PROT_READ
| VM_PROT_WRITE
,
170 VM_PROT_READ
| VM_PROT_WRITE
| PMAP_WIRED
);
172 pmap_update(pmap_kernel());
178 at91_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
183 if (pmap_devmap_find_va(bsh
, size
) != NULL
) {
184 /* Device was statically mapped; nothing to do. */
188 endva
= round_page(bsh
+ size
);
189 va
= trunc_page(bsh
);
191 pmap_remove(pmap_kernel(), va
, endva
);
192 pmap_update(pmap_kernel());
193 uvm_km_free(kernel_map
, va
, endva
- va
, UVM_KMF_VAONLY
);
197 at91_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
,
198 bus_size_t size
, bus_size_t alignment
, bus_size_t boundary
, int cacheable
,
199 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
201 panic("at91_bs_alloc(): not implemented\n");
205 at91_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
207 panic("at91_bs_free(): not implemented\n");
211 at91_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
212 bus_size_t size
, bus_space_handle_t
*nbshp
)
214 *nbshp
= bsh
+ offset
;
219 at91_bs_vaddr(void *t
, bus_space_handle_t bsh
)
221 return ((void *)bsh
);
225 at91_bs_mmap(void *t
, bus_addr_t addr
, off_t off
, int prot
, int flags
)
232 at91_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
233 bus_size_t len
, int flags
)
237 /* End of at91_io.c */