1 /* $NetBSD: i80321_space.c,v 1.6 2003/10/06 15:43:35 thorpej Exp $ */
4 * SPDX-License-Identifier: BSD-4-Clause
6 * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
9 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed for the NetBSD Project by
22 * Wasabi Systems, Inc.
23 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
24 * or promote products derived from this software without specific prior
27 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * bus_space functions for i81342 I/O Processor.
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
47 #include <sys/param.h>
48 #include <sys/systm.h>
50 #include <sys/malloc.h>
52 #include <machine/pcb.h>
55 #include <vm/vm_kern.h>
57 #include <vm/vm_page.h>
58 #include <vm/vm_extern.h>
60 #include <machine/bus.h>
62 #include <arm/xscale/i8134x/i81342reg.h>
63 #include <arm/xscale/i8134x/i81342var.h>
65 /* Prototypes for all the bus_space structure functions */
68 bs_protos(i81342_mem);
71 i81342_bs_init(bus_space_tag_t bs, void *cookie)
74 *bs = *arm_base_bs_tag;
75 bs->bs_privdata = cookie;
79 i81342_io_bs_init(bus_space_tag_t bs, void *cookie)
82 *bs = *arm_base_bs_tag;
83 bs->bs_privdata = cookie;
85 bs->bs_map = i81342_io_bs_map;
86 bs->bs_unmap = i81342_io_bs_unmap;
87 bs->bs_alloc = i81342_io_bs_alloc;
88 bs->bs_free = i81342_io_bs_free;
93 i81342_mem_bs_init(bus_space_tag_t bs, void *cookie)
96 *bs = *arm_base_bs_tag;
97 bs->bs_privdata = cookie;
99 bs->bs_map = i81342_mem_bs_map;
100 bs->bs_unmap = i81342_mem_bs_unmap;
101 bs->bs_alloc = i81342_mem_bs_alloc;
102 bs->bs_free = i81342_mem_bs_free;
106 /* *** Routines shared by i81342, PCI IO, and PCI MEM. *** */
109 i81342_bs_subregion(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset,
110 bus_size_t size, bus_space_handle_t *nbshp)
113 *nbshp = bsh + offset;
118 i81342_bs_barrier(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t offset,
119 bus_size_t len, int flags)
125 /* *** Routines for PCI IO. *** */
128 i81342_io_bs_map(bus_space_tag_t tag, bus_addr_t bpa, bus_size_t size, int flags,
129 bus_space_handle_t *bshp)
137 i81342_io_bs_unmap(bus_space_tag_t tag, bus_space_handle_t h, bus_size_t size)
144 i81342_io_bs_alloc(bus_space_tag_t tag, bus_addr_t rstart, bus_addr_t rend,
145 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
146 bus_addr_t *bpap, bus_space_handle_t *bshp)
149 panic("i81342_io_bs_alloc(): not implemented");
153 i81342_io_bs_free(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t size)
156 panic("i81342_io_bs_free(): not implemented");
160 /* *** Routines for PCI MEM. *** */
161 extern int badaddr_read(void *, int, void *);
162 static vm_offset_t allocable = 0xe1000000;
164 i81342_mem_bs_map(bus_space_tag_t tag, bus_addr_t bpa, bus_size_t size, int flags,
165 bus_space_handle_t *bshp)
167 struct i81342_pci_softc *sc = (struct i81342_pci_softc *)tag->bs_privdata;
168 struct i81342_pci_map *tmp;
169 vm_offset_t addr, endaddr;
172 /* Lookup to see if we already have a mapping at this address. */
173 tmp = sc->sc_pci_mappings;
175 if (tmp->paddr <= bpa && tmp->paddr + tmp->size >
177 *bshp = bpa - tmp->paddr + tmp->vaddr;
183 endaddr = rounddown2(addr + size, 0x1000000) + 0x1000000;
184 if (endaddr >= IOP34X_VADDR)
185 panic("PCI virtual memory exhausted");
187 tmp = malloc(sizeof(*tmp), M_DEVBUF, M_WAITOK);
189 paddr = rounddown2(bpa, 0x100000);
193 while (addr < endaddr) {
194 pmap_kenter_supersection(addr, paddr + (sc->sc_is_atux ?
195 IOP34X_PCIX_OMBAR : IOP34X_PCIE_OMBAR), 0);
198 tmp->size += 0x1000000;
200 tmp->next = sc->sc_pci_mappings;
201 sc->sc_pci_mappings = tmp;
202 *bshp = bpa - tmp->paddr + tmp->vaddr;
207 i81342_mem_bs_unmap(bus_space_tag_t tag, bus_space_handle_t h, bus_size_t size)
210 vm_offset_t va, endva;
212 va = trunc_page((vm_offset_t)h);
213 endva = va + round_page(size);
215 /* Free the kernel virtual mapping. */
216 kva_free(va, endva - va);
221 i81342_mem_bs_alloc(bus_space_tag_t tag, bus_addr_t rstart, bus_addr_t rend,
222 bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
223 bus_addr_t *bpap, bus_space_handle_t *bshp)
226 panic("i81342_mem_bs_alloc(): not implemented");
230 i81342_mem_bs_free(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t size)
233 panic("i81342_mem_bs_free(): not implemented");