1 /* $NetBSD: i80312_space.c,v 1.8 2005/04/01 11:59:25 yamt Exp $ */
4 * Copyright (c) 2001 Wasabi Systems, Inc.
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
39 * bus_space functions for i80312 Companion I/O chip.
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: i80312_space.c,v 1.8 2005/04/01 11:59:25 yamt Exp $");
45 #include <sys/param.h>
46 #include <sys/systm.h>
48 #include <uvm/uvm_extern.h>
50 #include <machine/bus.h>
52 #include <arm/xscale/i80312reg.h>
53 #include <arm/xscale/i80312var.h>
55 /* Prototypes for all the bus_space structure functions */
58 bs_protos(i80312_mem
);
60 bs_protos(generic_armv4
);
61 bs_protos(bs_notimpl
);
64 * Template bus_space -- copied, and the bits that are NULL are
67 const struct bus_space i80312_bs_tag_template
= {
71 /* mapping/unmapping */
76 /* allocation/deallocation */
80 /* get kernel virtual address */
97 generic_armv4_bs_rm_2
,
103 generic_armv4_bs_rr_2
,
109 generic_armv4_bs_w_2
,
115 generic_armv4_bs_wm_2
,
121 generic_armv4_bs_wr_2
,
133 generic_armv4_bs_sr_2
,
139 generic_armv4_bs_c_2
,
145 i80312_bs_init(bus_space_tag_t bs
, void *cookie
)
148 *bs
= i80312_bs_tag_template
;
149 bs
->bs_cookie
= cookie
;
153 i80312_io_bs_init(bus_space_tag_t bs
, void *cookie
)
156 *bs
= i80312_bs_tag_template
;
157 bs
->bs_cookie
= cookie
;
159 bs
->bs_map
= i80312_io_bs_map
;
160 bs
->bs_unmap
= i80312_io_bs_unmap
;
161 bs
->bs_alloc
= i80312_io_bs_alloc
;
162 bs
->bs_free
= i80312_io_bs_free
;
164 bs
->bs_vaddr
= i80312_io_bs_vaddr
;
168 i80312_mem_bs_init(bus_space_tag_t bs
, void *cookie
)
171 *bs
= i80312_bs_tag_template
;
172 bs
->bs_cookie
= cookie
;
174 bs
->bs_map
= i80312_mem_bs_map
;
175 bs
->bs_unmap
= i80312_mem_bs_unmap
;
176 bs
->bs_alloc
= i80312_mem_bs_alloc
;
177 bs
->bs_free
= i80312_mem_bs_free
;
179 bs
->bs_mmap
= i80312_mem_bs_mmap
;
182 /* *** Routines shared by i80312, PCI IO, and PCI MEM. *** */
185 i80312_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
186 bus_size_t size
, bus_space_handle_t
*nbshp
)
189 *nbshp
= bsh
+ offset
;
194 i80312_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
195 bus_size_t len
, int flags
)
202 i80312_bs_vaddr(void *t
, bus_space_handle_t bsh
)
205 return ((void *)bsh
);
209 i80312_bs_mmap(void *t
, bus_addr_t addr
, off_t off
, int prot
, int flags
)
216 /* *** Routines for PCI IO. *** */
219 i80312_io_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
, int flags
,
220 bus_space_handle_t
*bshp
)
222 struct i80312_softc
*sc
= t
;
224 uint32_t busbase
, bussize
;
226 if (bpa
>= sc
->sc_pioout_base
&&
227 bpa
< (sc
->sc_pioout_base
+ sc
->sc_pioout_size
)) {
228 busbase
= sc
->sc_pioout_base
;
229 bussize
= sc
->sc_pioout_size
;
230 winvaddr
= sc
->sc_piow_vaddr
;
231 } else if (bpa
>= sc
->sc_sioout_base
&&
232 bpa
< (sc
->sc_sioout_base
+ sc
->sc_sioout_size
)) {
233 busbase
= sc
->sc_sioout_base
;
234 bussize
= sc
->sc_sioout_size
;
235 winvaddr
= sc
->sc_siow_vaddr
;
239 if ((bpa
+ size
) >= (busbase
+ bussize
))
243 * Found the window -- PCI I/O space is mapped at a fixed
244 * virtual address by board-specific code. Translate the
245 * bus address to the virtual address.
247 *bshp
= winvaddr
+ (bpa
- busbase
);
253 i80312_io_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
260 i80312_io_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
,
261 bus_size_t size
, bus_size_t alignment
, bus_size_t boundary
, int flags
,
262 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
265 panic("i80312_io_bs_alloc(): not implemented");
269 i80312_io_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
272 panic("i80312_io_bs_free(): not implemented");
276 i80312_io_bs_vaddr(void *t
, bus_space_handle_t bsh
)
283 /* *** Routines for PCI MEM. *** */
286 i80312_mem_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
, int flags
,
287 bus_space_handle_t
*bshp
)
290 struct i80312_softc
*sc
= t
;
292 uint32_t busbase
, bussize
;
293 paddr_t pa
, endpa
, physbase
;
295 if (bpa
>= sc
->sc_pmemout_base
&&
296 bpa
< (sc
->sc_pmemout_base
+ sc
->sc_pmemout_size
)) {
297 busbase
= sc
->sc_pmemout_base
;
298 bussize
= sc
->sc_pmemout_size
;
299 physbase
= I80312_PCI_XLATE_PMW_BASE
;
300 } else if (bpa
>= sc
->sc_smemout_base
&&
301 bpa
< (sc
->sc_smemout_base
+ sc
->sc_smemout_size
)) {
302 busbase
= sc
->sc_smemout_base
;
303 bussize
= sc
->sc_smemout_size
;
304 physbase
= I80312_PCI_XLATE_SMW_BASE
;
308 if ((bpa
+ size
) >= (busbase
+ bussize
))
312 * Found the window -- PCI MEM space is not mapped by allocating
313 * some kernel VA space and mapping the pages with pmap_enter().
314 * pmap_enter() will map unmanaged pages as non-cacheable.
316 pa
= trunc_page((bpa
- busbase
) + physbase
);
317 endpa
= round_page(((bpa
- busbase
) + physbase
) + size
);
319 va
= uvm_km_alloc(kernel_map
, endpa
- pa
, 0,
320 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
324 *bshp
= va
+ (bpa
& PAGE_MASK
);
326 for (; pa
< endpa
; pa
+= PAGE_SIZE
, va
+= PAGE_SIZE
) {
327 pmap_enter(pmap_kernel(), va
, pa
,
328 VM_PROT_READ
| VM_PROT_WRITE
,
329 VM_PROT_READ
| VM_PROT_WRITE
| PMAP_WIRED
);
331 pmap_update(pmap_kernel());
337 i80312_mem_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
341 va
= trunc_page(bsh
);
342 endva
= round_page(bsh
+ size
);
344 /* Free the kernel virtual mapping. */
345 pmap_remove(pmap_kernel(), va
, endva
);
346 pmap_update(pmap_kernel());
347 uvm_km_free(kernel_map
, va
, endva
- va
, UVM_KMF_VAONLY
);
351 i80312_mem_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
,
352 bus_size_t size
, bus_size_t alignment
, bus_size_t boundary
, int flags
,
353 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
356 panic("i80312_mem_bs_alloc(): not implemented");
360 i80312_mem_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
363 panic("i80312_mem_bs_free(): not implemented");
367 i80312_mem_bs_mmap(void *t
, bus_addr_t addr
, off_t off
, int prot
, int flags
)