xref: /netbsd-src/sys/arch/arm/xscale/becc_space.c (revision d710132b4b8ce7f7cccaaf660cb16aa16b4077a0)
1 /*	$NetBSD: becc_space.c,v 1.2 2003/05/30 18:38:02 thorpej Exp $	*/
2 
3 /*
4  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
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
23  *    written permission.
24  *
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.
36  */
37 
38 /*
39  * bus_space functions for the ADI Engineering Big Endian Companion Chip.
40  */
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 
45 #include <uvm/uvm_extern.h>
46 
47 #include <machine/bus.h>
48 
49 #include <arm/xscale/beccreg.h>
50 #include <arm/xscale/beccvar.h>
51 
52 /* Prototypes for all the bus_space structure functions */
53 bs_protos(becc);
54 bs_protos(becc_io);
55 bs_protos(becc_mem);
56 bs_protos(becc_pci);
57 bs_protos(bs_notimpl);
58 
59 /*
60  * Template bus_space -- copied, and the bits that are NULL are
61  * filled in.
62  */
63 const struct bus_space becc_bs_tag_template = {
64 	/* cookie */
65 	(void *) 0,
66 
67 	/* mapping/unmapping */
68 	NULL,
69 	NULL,
70 	becc_bs_subregion,
71 
72 	/* allocation/deallocation */
73 	NULL,
74 	NULL,
75 
76 	/* get kernel virtual address */
77 	becc_bs_vaddr,
78 
79 	/* mmap */
80 	becc_bs_mmap,
81 
82 	/* barrier */
83 	becc_bs_barrier,
84 
85 	/* read (single) */
86 	becc_pci_bs_r_1,
87 	becc_pci_bs_r_2,
88 	becc_pci_bs_r_4,
89 	bs_notimpl_bs_r_8,
90 
91 	/* read multiple */
92 	bs_notimpl_bs_rm_1,
93 	bs_notimpl_bs_rm_2,
94 	bs_notimpl_bs_rm_4,
95 	bs_notimpl_bs_rm_8,
96 
97 	/* read region */
98 	bs_notimpl_bs_rr_1,
99 	bs_notimpl_bs_rr_2,
100 	bs_notimpl_bs_rr_4,
101 	bs_notimpl_bs_rr_8,
102 
103 	/* write (single) */
104 	becc_pci_bs_w_1,
105 	becc_pci_bs_w_2,
106 	becc_pci_bs_w_4,
107 	bs_notimpl_bs_w_8,
108 
109 	/* write multiple */
110 	bs_notimpl_bs_wm_1,
111 	bs_notimpl_bs_wm_2,
112 	bs_notimpl_bs_wm_4,
113 	bs_notimpl_bs_wm_8,
114 
115 	/* write region */
116 	bs_notimpl_bs_wr_1,
117 	bs_notimpl_bs_wr_2,
118 	bs_notimpl_bs_wr_4,
119 	bs_notimpl_bs_wr_8,
120 
121 	/* set multiple */
122 	bs_notimpl_bs_sm_1,
123 	bs_notimpl_bs_sm_2,
124 	bs_notimpl_bs_sm_4,
125 	bs_notimpl_bs_sm_8,
126 
127 	/* set region */
128 	bs_notimpl_bs_sr_1,
129 	bs_notimpl_bs_sr_2,
130 	bs_notimpl_bs_sr_4,
131 	bs_notimpl_bs_sr_8,
132 
133 	/* copy */
134 	bs_notimpl_bs_c_1,
135 	bs_notimpl_bs_c_2,
136 	bs_notimpl_bs_c_4,
137 	bs_notimpl_bs_c_8,
138 };
139 
140 void
141 becc_io_bs_init(bus_space_tag_t bs, void *cookie)
142 {
143 
144 	*bs = becc_bs_tag_template;
145 	bs->bs_cookie = cookie;
146 
147 	bs->bs_map = becc_io_bs_map;
148 	bs->bs_unmap = becc_io_bs_unmap;
149 	bs->bs_alloc = becc_io_bs_alloc;
150 	bs->bs_free = becc_io_bs_free;
151 
152 	bs->bs_vaddr = becc_io_bs_vaddr;
153 }
154 
155 void
156 becc_mem_bs_init(bus_space_tag_t bs, void *cookie)
157 {
158 
159 	*bs = becc_bs_tag_template;
160 	bs->bs_cookie = cookie;
161 
162 	bs->bs_map = becc_mem_bs_map;
163 	bs->bs_unmap = becc_mem_bs_unmap;
164 	bs->bs_alloc = becc_mem_bs_alloc;
165 	bs->bs_free = becc_mem_bs_free;
166 
167 	bs->bs_mmap = becc_mem_bs_mmap;
168 }
169 
170 /* *** Routines shared by becc, PCI IO, and PCI MEM. *** */
171 
172 int
173 becc_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
174     bus_size_t size, bus_space_handle_t *nbshp)
175 {
176 
177 	*nbshp = bsh + offset;
178 	return (0);
179 }
180 
181 void
182 becc_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
183     bus_size_t len, int flags)
184 {
185 
186 	/* Nothing to do. */
187 }
188 
189 void *
190 becc_bs_vaddr(void *t, bus_space_handle_t bsh)
191 {
192 
193 	return ((void *)bsh);
194 }
195 
196 paddr_t
197 becc_bs_mmap(void *t, bus_addr_t addr, off_t off, int prot, int flags)
198 {
199 
200 	/* Not supported. */
201 	return (-1);
202 }
203 
204 /* *** Routines for PCI IO. *** */
205 
206 int
207 becc_io_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
208     bus_space_handle_t *bshp)
209 {
210 	struct becc_softc *sc = t;
211 	vaddr_t winvaddr;
212 	uint32_t busbase;
213 
214 	if (bpa >= sc->sc_ioout_xlate &&
215 	    bpa < (sc->sc_ioout_xlate + (64 * 1024))) {
216 		busbase = sc->sc_ioout_xlate;
217 		winvaddr = sc->sc_pci_io_base;
218 	} else
219 		return (EINVAL);
220 
221 	if ((bpa + size) >= (busbase + (64 * 1024)))
222 		return (EINVAL);
223 
224 	/*
225 	 * Found the window -- PCI I/O space is mapped at a fixed
226 	 * virtual address by board-specific code.  Translate the
227 	 * bus address to the virtual address.
228 	 */
229 	*bshp = winvaddr + (bpa - busbase);
230 
231 	return (0);
232 }
233 
234 void
235 becc_io_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
236 {
237 
238 	/* Nothing to do. */
239 }
240 
241 int
242 becc_io_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
243     bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
244     bus_addr_t *bpap, bus_space_handle_t *bshp)
245 {
246 
247 	panic("becc_io_bs_alloc(): not implemented\n");
248 }
249 
250 void
251 becc_io_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
252 {
253 
254 	panic("becc_io_bs_free(): not implemented\n");
255 }
256 
257 void *
258 becc_io_bs_vaddr(void *t, bus_space_handle_t bsh)
259 {
260 
261 	/* Not supported. */
262 	return (NULL);
263 }
264 
265 /* *** Routines for PCI MEM. *** */
266 
267 int
268 becc_mem_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
269     bus_space_handle_t *bshp)
270 {
271 
272 	struct becc_softc *sc = t;
273 	vaddr_t winvaddr;
274 	uint32_t busbase;
275 
276 	/*
277 	 * The two memory windows have been configured to the same
278 	 * PCI base by board-specific code, so we only need to look
279 	 * at the first one.
280 	 */
281 
282 	if (bpa >= sc->sc_owin_xlate[0] &&
283 	    bpa < (sc->sc_owin_xlate[0] + BECC_PCI_MEM1_SIZE)) {
284 		busbase = sc->sc_owin_xlate[0];
285 		winvaddr = sc->sc_pci_mem_base[0];
286 	} else
287 		return (EINVAL);
288 
289 	if ((bpa + size) >= (busbase + BECC_PCI_MEM1_SIZE))
290 		return (EINVAL);
291 
292 	/*
293 	 * Found the window -- PCI MEM space is mapped at a fixed
294 	 * virtual address by board-specific code.  Translate the
295 	 * bus address to the virtual address.
296 	 */
297 	*bshp = winvaddr + (bpa - busbase);
298 
299 	return (0);
300 }
301 
302 void
303 becc_mem_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
304 {
305 
306 	/* Nothing to do. */
307 }
308 
309 int
310 becc_mem_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
311     bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
312     bus_addr_t *bpap, bus_space_handle_t *bshp)
313 {
314 
315 	panic("becc_mem_bs_alloc(): not implemented\n");
316 }
317 
318 void
319 becc_mem_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
320 {
321 
322 	panic("becc_mem_bs_free(): not implemented\n");
323 }
324 
325 paddr_t
326 becc_mem_bs_mmap(void *t, bus_addr_t addr, off_t off, int prot, int flags)
327 {
328 
329 	/* XXX */
330 	return (-1);
331 }
332