]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/xscale/i8134x/i81342_space.c
Revert r336773: it removed too much.
[FreeBSD/FreeBSD.git] / sys / arm / xscale / i8134x / i81342_space.c
1 /*      $NetBSD: i80321_space.c,v 1.6 2003/10/06 15:43:35 thorpej Exp $ */
2
3 /*-
4  * SPDX-License-Identifier: BSD-4-Clause
5  *
6  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
7  * All rights reserved.
8  *
9  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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
25  *    written permission.
26  *
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.
38  */
39
40 /*
41  * bus_space functions for i81342 I/O Processor.
42  */
43
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/bus.h>
50 #include <sys/malloc.h>
51
52 #include <machine/pcb.h>
53
54 #include <vm/vm.h>
55 #include <vm/vm_kern.h>
56 #include <vm/pmap.h>
57 #include <vm/vm_page.h>
58 #include <vm/vm_extern.h>
59
60 #include <machine/bus.h>
61
62 #include <arm/xscale/i8134x/i81342reg.h>
63 #include <arm/xscale/i8134x/i81342var.h>
64
65 /* Prototypes for all the bus_space structure functions */
66 bs_protos(i81342);
67 bs_protos(i81342_io);
68 bs_protos(i81342_mem);
69
70 void
71 i81342_bs_init(bus_space_tag_t bs, void *cookie)
72 {
73
74         *bs = *arm_base_bs_tag;
75         bs->bs_privdata = cookie;
76 }
77
78 void
79 i81342_io_bs_init(bus_space_tag_t bs, void *cookie)
80 {
81
82         *bs = *arm_base_bs_tag;
83         bs->bs_privdata = cookie;
84
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;
89
90 }
91
92 void
93 i81342_mem_bs_init(bus_space_tag_t bs, void *cookie)
94 {
95
96         *bs = *arm_base_bs_tag;
97         bs->bs_privdata = cookie;
98
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;
103
104 }
105
106 /* *** Routines shared by i81342, PCI IO, and PCI MEM. *** */
107
108 int
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)
111 {
112
113         *nbshp = bsh + offset;
114         return (0);
115 }
116
117 void
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)
120 {
121
122         /* Nothing to do. */
123 }
124
125 /* *** Routines for PCI IO. *** */
126
127 int
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)
130 {
131
132         *bshp = bpa;
133         return (0);
134 }
135
136 void
137 i81342_io_bs_unmap(bus_space_tag_t tag, bus_space_handle_t h, bus_size_t size)
138 {
139
140         /* Nothing to do. */
141 }
142
143 int
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)
147 {
148
149         panic("i81342_io_bs_alloc(): not implemented");
150 }
151
152 void
153 i81342_io_bs_free(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t size)
154 {
155
156         panic("i81342_io_bs_free(): not implemented");
157 }
158
159
160 /* *** Routines for PCI MEM. *** */
161 extern int badaddr_read(void *, int, void *);
162 static vm_offset_t allocable = 0xe1000000;
163 int
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)
166 {
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;
170         vm_paddr_t paddr;
171
172         /* Lookup to see if we already have a mapping at this address. */
173         tmp = sc->sc_pci_mappings;
174         while (tmp) {
175                 if (tmp->paddr <= bpa && tmp->paddr + tmp->size >
176                     bpa + size) {
177                         *bshp = bpa - tmp->paddr + tmp->vaddr;
178                         return (0);
179                 }
180                 tmp = tmp->next;
181         }
182         addr = allocable;
183         endaddr = rounddown2(addr + size, 0x1000000) + 0x1000000;
184         if (endaddr >= IOP34X_VADDR)
185                 panic("PCI virtual memory exhausted");
186         allocable = endaddr;
187         tmp = malloc(sizeof(*tmp), M_DEVBUF, M_WAITOK);
188         tmp->next = NULL;
189         paddr = rounddown2(bpa, 0x100000);
190         tmp->paddr = paddr;
191         tmp->vaddr = addr;
192         tmp->size = 0;
193         while (addr < endaddr) {
194                 pmap_kenter_supersection(addr, paddr + (sc->sc_is_atux ?
195                     IOP34X_PCIX_OMBAR : IOP34X_PCIE_OMBAR), 0);
196                 addr += 0x1000000;
197                 paddr += 0x1000000;
198                 tmp->size += 0x1000000;
199         }
200         tmp->next = sc->sc_pci_mappings;
201         sc->sc_pci_mappings = tmp;
202         *bshp = bpa - tmp->paddr + tmp->vaddr;
203         return (0);
204 }
205
206 void
207 i81342_mem_bs_unmap(bus_space_tag_t tag, bus_space_handle_t h, bus_size_t size)
208 {
209 #if 0
210         vm_offset_t va, endva;
211
212         va = trunc_page((vm_offset_t)h);
213         endva = va + round_page(size);
214
215         /* Free the kernel virtual mapping. */
216         kva_free(va, endva - va);
217 #endif
218 }
219
220 int
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)
224 {
225
226         panic("i81342_mem_bs_alloc(): not implemented");
227 }
228
229 void
230 i81342_mem_bs_free(bus_space_tag_t tag, bus_space_handle_t bsh, bus_size_t size)
231 {
232
233         panic("i81342_mem_bs_free(): not implemented");
234 }