1 /* $NetBSD: i80321_space.c,v 1.6 2003/10/06 15:43:35 thorpej 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 __FBSDID("$FreeBSD$");
45 #include <sys/param.h>
46 #include <sys/systm.h>
49 #include <machine/pcb.h>
52 #include <vm/vm_kern.h>
54 #include <vm/vm_page.h>
55 #include <vm/vm_extern.h>
57 #include <machine/bus.h>
59 #include <arm/xscale/i80321/i80321reg.h>
60 #include <arm/xscale/i80321/i80321var.h>
62 /* Prototypes for all the bus_space structure functions */
65 bs_protos(i80321_mem);
67 bs_protos(generic_armv4);
70 * Template bus_space -- copied, and the bits that are NULL are
73 const struct bus_space i80321_bs_tag_template = {
77 /* mapping/unmapping */
82 /* allocation/deallocation */
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,
143 /* read (single) stream */
145 generic_armv4_bs_r_2,
149 /* read multiple stream */
151 generic_armv4_bs_rm_2,
155 /* read region stream */
157 generic_armv4_bs_rr_2,
161 /* write (single) stream */
163 generic_armv4_bs_w_2,
167 /* write multiple stream */
169 generic_armv4_bs_wm_2,
173 /* write region stream */
175 generic_armv4_bs_wr_2,
181 i80321_bs_init(bus_space_tag_t bs, void *cookie)
184 *bs = i80321_bs_tag_template;
185 bs->bs_cookie = cookie;
189 i80321_io_bs_init(bus_space_tag_t bs, void *cookie)
192 *bs = i80321_bs_tag_template;
193 bs->bs_cookie = cookie;
195 bs->bs_map = i80321_io_bs_map;
196 bs->bs_unmap = i80321_io_bs_unmap;
197 bs->bs_alloc = i80321_io_bs_alloc;
198 bs->bs_free = i80321_io_bs_free;
203 i80321_mem_bs_init(bus_space_tag_t bs, void *cookie)
206 *bs = i80321_bs_tag_template;
207 bs->bs_cookie = cookie;
209 bs->bs_map = i80321_mem_bs_map;
210 bs->bs_unmap = i80321_mem_bs_unmap;
211 bs->bs_alloc = i80321_mem_bs_alloc;
212 bs->bs_free = i80321_mem_bs_free;
216 /* *** Routines shared by i80321, PCI IO, and PCI MEM. *** */
219 i80321_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
220 bus_size_t size, bus_space_handle_t *nbshp)
223 *nbshp = bsh + offset;
228 i80321_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
229 bus_size_t len, int flags)
235 /* *** Routines for PCI IO. *** */
237 extern struct i80321_softc *i80321_softc;
239 i80321_io_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
240 bus_space_handle_t *bshp)
242 struct i80321_softc *sc = i80321_softc;
243 vm_offset_t winvaddr;
246 if (bpa >= sc->sc_ioout_xlate &&
247 bpa < (sc->sc_ioout_xlate + VERDE_OUT_XLATE_IO_WIN_SIZE)) {
248 busbase = sc->sc_ioout_xlate;
249 winvaddr = sc->sc_iow_vaddr;
253 if ((bpa + size) >= (busbase + VERDE_OUT_XLATE_IO_WIN_SIZE))
257 * Found the window -- PCI I/O space is mapped at a fixed
258 * virtual address by board-specific code. Translate the
259 * bus address to the virtual address.
261 *bshp = winvaddr + (bpa - busbase);
267 i80321_io_bs_unmap(void *t, bus_space_handle_t h, bus_size_t size)
274 i80321_io_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
275 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
276 bus_addr_t *bpap, bus_space_handle_t *bshp)
279 panic("i80321_io_bs_alloc(): not implemented");
283 i80321_io_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
286 panic("i80321_io_bs_free(): not implemented");
290 /* *** Routines for PCI MEM. *** */
291 extern int badaddr_read(void *, int, void *);
293 i80321_mem_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
294 bus_space_handle_t *bshp)
296 vm_paddr_t pa, endpa;
298 pa = trunc_page(bpa);
299 endpa = round_page(bpa + size);
301 *bshp = (vm_offset_t)pmap_mapdev(pa, endpa - pa);
307 i80321_mem_bs_unmap(void *t, bus_space_handle_t h, bus_size_t size)
309 vm_offset_t va, endva;
311 va = trunc_page((vm_offset_t)t);
312 endva = va + round_page(size);
314 /* Free the kernel virtual mapping. */
315 kmem_free(kernel_map, va, endva - va);
319 i80321_mem_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
320 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
321 bus_addr_t *bpap, bus_space_handle_t *bshp)
324 panic("i80321_mem_bs_alloc(): not implemented");
328 i80321_mem_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
331 panic("i80321_mem_bs_free(): not implemented");