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 i81342 I/O Processor.
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
45 #include <sys/param.h>
46 #include <sys/systm.h>
48 #include <sys/malloc.h>
50 #include <machine/pcb.h>
53 #include <vm/vm_kern.h>
55 #include <vm/vm_page.h>
56 #include <vm/vm_extern.h>
58 #include <machine/bus.h>
60 #include <arm/xscale/i8134x/i81342reg.h>
61 #include <arm/xscale/i8134x/i81342var.h>
63 /* Prototypes for all the bus_space structure functions */
66 bs_protos(i81342_mem);
68 bs_protos(generic_armv4);
71 * Template bus_space -- copied, and the bits that are NULL are
74 const struct bus_space i81342_bs_tag_template = {
78 /* mapping/unmapping */
83 /* allocation/deallocation */
98 generic_armv4_bs_rm_2,
104 generic_armv4_bs_rr_2,
110 generic_armv4_bs_w_2,
116 generic_armv4_bs_wm_2,
122 generic_armv4_bs_wr_2,
134 generic_armv4_bs_sr_2,
140 generic_armv4_bs_c_2,
144 /* read (single) stream */
146 generic_armv4_bs_r_2,
150 /* read multiple stream */
152 generic_armv4_bs_rm_2,
156 /* read region stream */
158 generic_armv4_bs_rr_2,
162 /* write (single) stream */
164 generic_armv4_bs_w_2,
168 /* write multiple stream */
170 generic_armv4_bs_wm_2,
174 /* write region stream */
176 generic_armv4_bs_wr_2,
182 i81342_bs_init(bus_space_tag_t bs, void *cookie)
185 *bs = i81342_bs_tag_template;
186 bs->bs_cookie = cookie;
190 i81342_io_bs_init(bus_space_tag_t bs, void *cookie)
193 *bs = i81342_bs_tag_template;
194 bs->bs_cookie = cookie;
196 bs->bs_map = i81342_io_bs_map;
197 bs->bs_unmap = i81342_io_bs_unmap;
198 bs->bs_alloc = i81342_io_bs_alloc;
199 bs->bs_free = i81342_io_bs_free;
204 i81342_mem_bs_init(bus_space_tag_t bs, void *cookie)
207 *bs = i81342_bs_tag_template;
208 bs->bs_cookie = cookie;
210 bs->bs_map = i81342_mem_bs_map;
211 bs->bs_unmap = i81342_mem_bs_unmap;
212 bs->bs_alloc = i81342_mem_bs_alloc;
213 bs->bs_free = i81342_mem_bs_free;
217 /* *** Routines shared by i81342, PCI IO, and PCI MEM. *** */
220 i81342_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
221 bus_size_t size, bus_space_handle_t *nbshp)
224 *nbshp = bsh + offset;
229 i81342_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
230 bus_size_t len, int flags)
236 /* *** Routines for PCI IO. *** */
239 i81342_io_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
240 bus_space_handle_t *bshp)
248 i81342_io_bs_unmap(void *t, bus_space_handle_t h, bus_size_t size)
255 i81342_io_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
256 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
257 bus_addr_t *bpap, bus_space_handle_t *bshp)
260 panic("i81342_io_bs_alloc(): not implemented");
264 i81342_io_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
267 panic("i81342_io_bs_free(): not implemented");
271 /* *** Routines for PCI MEM. *** */
272 extern int badaddr_read(void *, int, void *);
273 static vm_offset_t allocable = 0xe1000000;
275 i81342_mem_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
276 bus_space_handle_t *bshp)
278 struct i81342_pci_softc *sc = (struct i81342_pci_softc *)t;
279 struct i81342_pci_map *tmp;
280 vm_offset_t addr, endaddr;
283 /* Lookup to see if we already have a mapping at this address. */
284 tmp = sc->sc_pci_mappings;
286 if (tmp->paddr <= bpa && tmp->paddr + tmp->size >
288 *bshp = bpa - tmp->paddr + tmp->vaddr;
294 endaddr = ((addr + size) &~ (0x1000000 - 1)) + 0x1000000;
295 if (endaddr >= IOP34X_VADDR)
296 panic("PCI virtual memory exhausted");
298 tmp = malloc(sizeof(*tmp), M_DEVBUF, M_WAITOK);
300 paddr = bpa &~ (0x100000 - 1);
304 while (addr < endaddr) {
305 pmap_kenter_supersection(addr, paddr + (sc->sc_is_atux ?
306 IOP34X_PCIX_OMBAR : IOP34X_PCIE_OMBAR), 0);
309 tmp->size += 0x1000000;
311 tmp->next = sc->sc_pci_mappings;
312 sc->sc_pci_mappings = tmp;
313 *bshp = bpa - tmp->paddr + tmp->vaddr;
318 i81342_mem_bs_unmap(void *t, bus_space_handle_t h, bus_size_t size)
321 vm_offset_t va, endva;
323 va = trunc_page((vm_offset_t)t);
324 endva = va + round_page(size);
326 /* Free the kernel virtual mapping. */
327 kmem_free(kernel_map, va, endva - va);
332 i81342_mem_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
333 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
334 bus_addr_t *bpap, bus_space_handle_t *bshp)
337 panic("i81342_mem_bs_alloc(): not implemented");
341 i81342_mem_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
344 panic("i81342_mem_bs_free(): not implemented");