1 /* $NetBSD: ifpga_io.c,v 1.8 2005/11/24 13:08:33 yamt Exp $ */
4 * Copyright (c) 1997 Causality Limited
5 * Copyright (c) 1997 Mark Brinicombe.
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.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Mark Brinicombe
19 * for the NetBSD Project.
20 * 4. The name of the company nor the name of the author may be used to
21 * endorse or promote products derived from this software without specific
22 * prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * From arm/footbridge/footbridge_io.c
40 * bus_space I/O functions for IFPGA
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD: ifpga_io.c,v 1.8 2005/11/24 13:08:33 yamt Exp $");
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <machine/bus.h>
49 #include <uvm/uvm_extern.h>
51 #include <evbarm/ifpga/ifpgavar.h>
53 /* Proto types for all the bus_space structure functions */
57 bs_protos(generic_armv4
);
58 bs_protos(bs_notimpl
);
59 bs_map_proto(ifpga_mem
);
60 bs_unmap_proto(ifpga_mem
);
62 /* Declare the ifpga bus space tag */
64 struct bus_space ifpga_bs_tag
= {
66 (void *) 0, /* Physical base address */
68 /* mapping/unmapping */
73 /* allocation/deallocation */
77 /* get kernel virtual address */
94 generic_armv4_bs_rm_2
,
100 generic_armv4_bs_rr_2
,
106 generic_armv4_bs_w_2
,
112 generic_armv4_bs_wm_2
,
118 generic_armv4_bs_wr_2
,
130 generic_armv4_bs_sr_2
,
136 generic_armv4_bs_c_2
,
141 void ifpga_create_io_bs_tag(t
, cookie
)
146 t
->bs_cookie
= cookie
;
149 void ifpga_create_mem_bs_tag(t
, cookie
)
154 t
->bs_map
= ifpga_mem_bs_map
;
155 t
->bs_unmap
= ifpga_mem_bs_unmap
;
156 t
->bs_cookie
= cookie
;
159 /* bus space functions */
162 ifpga_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
, int cacheable
, bus_space_handle_t
*bshp
)
164 /* The cookie is the base address for the I/O area */
165 *bshp
= bpa
+ (bus_addr_t
)t
;
170 ifpga_mem_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
, int cacheable
, bus_space_handle_t
*bshp
)
172 bus_addr_t startpa
, endpa
;
175 /* Round the allocation to page boundries */
176 startpa
= trunc_page(bpa
);
177 endpa
= round_page(bpa
+ size
);
180 va
= uvm_km_alloc(kernel_map
, endpa
- startpa
, 0,
181 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
185 /* Store the bus space handle */
186 *bshp
= va
+ (bpa
& PGOFSET
);
188 /* Now map the pages */
189 /* The cookie is the physical base address for the I/O area */
190 while (startpa
< endpa
) {
191 /* XXX pmap_kenter_pa maps pages cacheable -- not what
193 pmap_enter(pmap_kernel(), va
, (bus_addr_t
)t
+ startpa
,
194 VM_PROT_READ
| VM_PROT_WRITE
, 0);
196 startpa
+= PAGE_SIZE
;
198 pmap_update(pmap_kernel());
204 ifpga_bs_alloc(t
, rstart
, rend
, size
, alignment
, boundary
, cacheable
,
207 bus_addr_t rstart
, rend
;
208 bus_size_t size
, alignment
, boundary
;
211 bus_space_handle_t
*bshp
;
213 panic("ifpga_alloc(): Help!");
218 ifpga_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
220 /* Nothing to do for an io map. */
224 ifpga_mem_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
226 vaddr_t startva
, endva
;
228 startva
= trunc_page(bsh
);
229 endva
= round_page(bsh
+ size
);
231 pmap_remove(pmap_kernel(), startva
, endva
);
232 pmap_update(pmap_kernel());
233 uvm_km_free(kernel_map
, startva
, endva
- startva
, UVM_KMF_VAONLY
);
237 ifpga_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
240 panic("ifpga_free(): Help!");
241 /* ifpga_bs_unmap() does all that we need to do. */
242 /* ifpga_bs_unmap(t, bsh, size);*/
246 ifpga_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
, bus_size_t size
, bus_space_handle_t
*nbshp
)
249 *nbshp
= bsh
+ (offset
<< ((int)t
));
254 ifpga_bs_vaddr(void *t
, bus_space_handle_t bsh
)
257 return ((void *)bsh
);
261 ifpga_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
, bus_size_t len
, int flags
)