1 /* $NetBSD: i80321_space.c,v 1.9.38.1 2007/05/22 17:26:41 matt Exp $ */
4 * Copyright (c) 2001, 2002 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 i80321 I/O Processor.
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: i80321_space.c,v 1.9.38.1 2007/05/22 17:26:41 matt 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/i80321reg.h>
53 #include <arm/xscale/i80321var.h>
55 #include "opt_i80321.h"
57 /* Prototypes for all the bus_space structure functions */
60 bs_protos(i80321_mem
);
62 bs_protos(generic_armv4
);
63 bs_protos(bs_notimpl
);
66 * Template bus_space -- copied, and the bits that are NULL are
69 const struct bus_space i80321_bs_tag_template
= {
73 /* mapping/unmapping */
78 /* allocation/deallocation */
82 /* get kernel virtual address */
99 generic_armv4_bs_rm_2
,
105 generic_armv4_bs_rr_2
,
111 generic_armv4_bs_w_2
,
117 generic_armv4_bs_wm_2
,
123 generic_armv4_bs_wr_2
,
135 generic_armv4_bs_sr_2
,
141 generic_armv4_bs_c_2
,
147 i80321_bs_init(bus_space_tag_t bs
, void *cookie
)
150 *bs
= i80321_bs_tag_template
;
151 bs
->bs_cookie
= cookie
;
155 i80321_io_bs_init(bus_space_tag_t bs
, void *cookie
)
158 *bs
= i80321_bs_tag_template
;
159 bs
->bs_cookie
= cookie
;
161 bs
->bs_map
= i80321_io_bs_map
;
162 bs
->bs_unmap
= i80321_io_bs_unmap
;
163 bs
->bs_alloc
= i80321_io_bs_alloc
;
164 bs
->bs_free
= i80321_io_bs_free
;
166 bs
->bs_vaddr
= i80321_io_bs_vaddr
;
170 i80321_mem_bs_init(bus_space_tag_t bs
, void *cookie
)
173 *bs
= i80321_bs_tag_template
;
174 bs
->bs_cookie
= cookie
;
176 bs
->bs_map
= i80321_mem_bs_map
;
177 bs
->bs_unmap
= i80321_mem_bs_unmap
;
178 bs
->bs_alloc
= i80321_mem_bs_alloc
;
179 bs
->bs_free
= i80321_mem_bs_free
;
181 bs
->bs_mmap
= i80321_mem_bs_mmap
;
184 /* *** Routines shared by i80321, PCI IO, and PCI MEM. *** */
187 i80321_bs_subregion(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
188 bus_size_t size
, bus_space_handle_t
*nbshp
)
191 *nbshp
= bsh
+ offset
;
196 i80321_bs_barrier(void *t
, bus_space_handle_t bsh
, bus_size_t offset
,
197 bus_size_t len
, int flags
)
204 i80321_bs_vaddr(void *t
, bus_space_handle_t bsh
)
207 return ((void *)bsh
);
211 i80321_bs_mmap(void *t
, bus_addr_t addr
, off_t off
, int prot
, int flags
)
218 /* *** Routines for PCI IO. *** */
221 i80321_io_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
, int flags
,
222 bus_space_handle_t
*bshp
)
224 struct i80321_softc
*sc
= t
;
228 if (bpa
>= sc
->sc_ioout_xlate
&&
229 bpa
< (sc
->sc_ioout_xlate
+ VERDE_OUT_XLATE_IO_WIN_SIZE
)) {
230 busbase
= sc
->sc_ioout_xlate
;
231 winvaddr
= sc
->sc_iow_vaddr
;
235 if ((bpa
+ size
) >= (busbase
+ VERDE_OUT_XLATE_IO_WIN_SIZE
))
239 * Found the window -- PCI I/O space is mapped at a fixed
240 * virtual address by board-specific code. Translate the
241 * bus address to the virtual address.
243 *bshp
= winvaddr
+ (bpa
- busbase
);
249 i80321_io_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
256 i80321_io_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
,
257 bus_size_t size
, bus_size_t alignment
, bus_size_t boundary
, int flags
,
258 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
261 panic("i80321_io_bs_alloc(): not implemented");
265 i80321_io_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
268 panic("i80321_io_bs_free(): not implemented");
272 i80321_io_bs_vaddr(void *t
, bus_space_handle_t bsh
)
279 /* *** Routines for PCI MEM. *** */
282 i80321_mem_bs_map(void *t
, bus_addr_t bpa
, bus_size_t size
, int flags
,
283 bus_space_handle_t
*bshp
)
286 #ifndef I80321_USE_DIRECT_WIN
287 struct i80321_softc
*sc
= t
;
291 paddr_t pa
, endpa
, physbase
;
293 #ifdef I80321_USE_DIRECT_WIN
294 if (bpa
>= (VERDE_OUT_DIRECT_WIN_BASE
) &&
295 bpa
< (VERDE_OUT_DIRECT_WIN_BASE
+ VERDE_OUT_DIRECT_WIN_SIZE
)) {
296 busbase
= VERDE_OUT_DIRECT_WIN_BASE
;
297 physbase
= VERDE_OUT_DIRECT_WIN_BASE
;
300 if ((bpa
+ size
) >= (VERDE_OUT_DIRECT_WIN_BASE
+
301 VERDE_OUT_DIRECT_WIN_SIZE
))
304 if (bpa
>= sc
->sc_owin
[0].owin_xlate_lo
&&
305 bpa
< (sc
->sc_owin
[0].owin_xlate_lo
+
306 VERDE_OUT_XLATE_MEM_WIN_SIZE
)) {
307 busbase
= sc
->sc_owin
[0].owin_xlate_lo
;
308 physbase
= sc
->sc_iwin
[1].iwin_xlate
;
312 if ((bpa
+ size
) >= (busbase
+ VERDE_OUT_XLATE_MEM_WIN_SIZE
))
317 * Found the window -- PCI MEM space is not mapped by allocating
318 * some kernel VA space and mapping the pages with pmap_enter().
319 * pmap_enter() will map unmanaged pages as non-cacheable.
321 pa
= trunc_page((bpa
- busbase
) + physbase
);
322 endpa
= round_page(((bpa
- busbase
) + physbase
) + size
);
324 va
= uvm_km_alloc(kernel_map
, endpa
- pa
, 0,
325 UVM_KMF_VAONLY
| UVM_KMF_NOWAIT
);
329 *bshp
= va
+ (bpa
& PAGE_MASK
);
331 for (; pa
< endpa
; pa
+= PAGE_SIZE
, va
+= PAGE_SIZE
) {
332 pmap_enter(pmap_kernel(), va
, pa
,
333 VM_PROT_READ
| VM_PROT_WRITE
,
334 VM_PROT_READ
| VM_PROT_WRITE
| PMAP_WIRED
);
336 pmap_update(pmap_kernel());
342 i80321_mem_bs_unmap(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
346 va
= trunc_page(bsh
);
347 endva
= round_page(bsh
+ size
);
349 pmap_remove(pmap_kernel(), va
, endva
- va
);
350 pmap_update(pmap_kernel());
352 /* Free the kernel virtual mapping. */
353 uvm_km_free(kernel_map
, va
, endva
- va
, UVM_KMF_VAONLY
);
357 i80321_mem_bs_alloc(void *t
, bus_addr_t rstart
, bus_addr_t rend
,
358 bus_size_t size
, bus_size_t alignment
, bus_size_t boundary
, int flags
,
359 bus_addr_t
*bpap
, bus_space_handle_t
*bshp
)
362 panic("i80321_mem_bs_alloc(): not implemented");
366 i80321_mem_bs_free(void *t
, bus_space_handle_t bsh
, bus_size_t size
)
369 panic("i80321_mem_bs_free(): not implemented");
373 i80321_mem_bs_mmap(void *t
, bus_addr_t addr
, off_t off
, int prot
, int flags
)