xref: /netbsd-src/sys/arch/arm/xscale/becc_space.c (revision b8c616269f5ebf18ab2e35cb8099d683130a177c)
1 /*	$NetBSD: becc_space.c,v 1.1 2003/01/25 01:57:19 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(generic);
57 bs_protos(generic_armv4);
58 bs_protos(bs_notimpl);
59 
60 /*
61  * Template bus_space -- copied, and the bits that are NULL are
62  * filled in.
63  */
64 const struct bus_space becc_bs_tag_template = {
65 	/* cookie */
66 	(void *) 0,
67 
68 	/* mapping/unmapping */
69 	NULL,
70 	NULL,
71 	becc_bs_subregion,
72 
73 	/* allocation/deallocation */
74 	NULL,
75 	NULL,
76 
77 	/* get kernel virtual address */
78 	becc_bs_vaddr,
79 
80 	/* mmap */
81 	becc_bs_mmap,
82 
83 	/* barrier */
84 	becc_bs_barrier,
85 
86 	/* read (single) */
87 	generic_bs_r_1,
88 	generic_armv4_bs_r_2,
89 	generic_bs_r_4,
90 	bs_notimpl_bs_r_8,
91 
92 	/* read multiple */
93 	generic_bs_rm_1,
94 	generic_armv4_bs_rm_2,
95 	generic_bs_rm_4,
96 	bs_notimpl_bs_rm_8,
97 
98 	/* read region */
99 	bs_notimpl_bs_rr_1,
100 	generic_armv4_bs_rr_2,
101 	generic_bs_rr_4,
102 	bs_notimpl_bs_rr_8,
103 
104 	/* write (single) */
105 	generic_bs_w_1,
106 	generic_armv4_bs_w_2,
107 	generic_bs_w_4,
108 	bs_notimpl_bs_w_8,
109 
110 	/* write multiple */
111 	generic_bs_wm_1,
112 	generic_armv4_bs_wm_2,
113 	generic_bs_wm_4,
114 	bs_notimpl_bs_wm_8,
115 
116 	/* write region */
117 	bs_notimpl_bs_wr_1,
118 	generic_armv4_bs_wr_2,
119 	generic_bs_wr_4,
120 	bs_notimpl_bs_wr_8,
121 
122 	/* set multiple */
123 	bs_notimpl_bs_sm_1,
124 	bs_notimpl_bs_sm_2,
125 	bs_notimpl_bs_sm_4,
126 	bs_notimpl_bs_sm_8,
127 
128 	/* set region */
129 	bs_notimpl_bs_sr_1,
130 	generic_armv4_bs_sr_2,
131 	bs_notimpl_bs_sr_4,
132 	bs_notimpl_bs_sr_8,
133 
134 	/* copy */
135 	bs_notimpl_bs_c_1,
136 	generic_armv4_bs_c_2,
137 	bs_notimpl_bs_c_4,
138 	bs_notimpl_bs_c_8,
139 };
140 
141 void
142 becc_io_bs_init(bus_space_tag_t bs, void *cookie)
143 {
144 
145 	*bs = becc_bs_tag_template;
146 	bs->bs_cookie = cookie;
147 
148 	bs->bs_map = becc_io_bs_map;
149 	bs->bs_unmap = becc_io_bs_unmap;
150 	bs->bs_alloc = becc_io_bs_alloc;
151 	bs->bs_free = becc_io_bs_free;
152 
153 	bs->bs_vaddr = becc_io_bs_vaddr;
154 }
155 
156 void
157 becc_mem_bs_init(bus_space_tag_t bs, void *cookie)
158 {
159 
160 	*bs = becc_bs_tag_template;
161 	bs->bs_cookie = cookie;
162 
163 	bs->bs_map = becc_mem_bs_map;
164 	bs->bs_unmap = becc_mem_bs_unmap;
165 	bs->bs_alloc = becc_mem_bs_alloc;
166 	bs->bs_free = becc_mem_bs_free;
167 
168 	bs->bs_mmap = becc_mem_bs_mmap;
169 }
170 
171 /* *** Routines shared by becc, PCI IO, and PCI MEM. *** */
172 
173 int
174 becc_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
175     bus_size_t size, bus_space_handle_t *nbshp)
176 {
177 
178 	*nbshp = bsh + offset;
179 	return (0);
180 }
181 
182 void
183 becc_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
184     bus_size_t len, int flags)
185 {
186 
187 	/* Nothing to do. */
188 }
189 
190 void *
191 becc_bs_vaddr(void *t, bus_space_handle_t bsh)
192 {
193 
194 	return ((void *)bsh);
195 }
196 
197 paddr_t
198 becc_bs_mmap(void *t, bus_addr_t addr, off_t off, int prot, int flags)
199 {
200 
201 	/* Not supported. */
202 	return (-1);
203 }
204 
205 /* *** Routines for PCI IO. *** */
206 
207 int
208 becc_io_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
209     bus_space_handle_t *bshp)
210 {
211 	struct becc_softc *sc = t;
212 	vaddr_t winvaddr;
213 	uint32_t busbase;
214 
215 	if (bpa >= sc->sc_ioout_xlate &&
216 	    bpa < (sc->sc_ioout_xlate + (64 * 1024))) {
217 		busbase = sc->sc_ioout_xlate;
218 		winvaddr = sc->sc_pci_io_base;
219 	} else
220 		return (EINVAL);
221 
222 	if ((bpa + size) >= (busbase + (64 * 1024)))
223 		return (EINVAL);
224 
225 	/*
226 	 * Found the window -- PCI I/O space is mapped at a fixed
227 	 * virtual address by board-specific code.  Translate the
228 	 * bus address to the virtual address.
229 	 */
230 	*bshp = winvaddr + (bpa - busbase);
231 
232 	return (0);
233 }
234 
235 void
236 becc_io_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
237 {
238 
239 	/* Nothing to do. */
240 }
241 
242 int
243 becc_io_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
244     bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
245     bus_addr_t *bpap, bus_space_handle_t *bshp)
246 {
247 
248 	panic("becc_io_bs_alloc(): not implemented\n");
249 }
250 
251 void
252 becc_io_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
253 {
254 
255 	panic("becc_io_bs_free(): not implemented\n");
256 }
257 
258 void *
259 becc_io_bs_vaddr(void *t, bus_space_handle_t bsh)
260 {
261 
262 	/* Not supported. */
263 	return (NULL);
264 }
265 
266 /* *** Routines for PCI MEM. *** */
267 
268 int
269 becc_mem_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
270     bus_space_handle_t *bshp)
271 {
272 
273 	struct becc_softc *sc = t;
274 	vaddr_t winvaddr;
275 	uint32_t busbase;
276 
277 	/*
278 	 * The two memory windows have been configured to the same
279 	 * PCI base by board-specific code, so we only need to look
280 	 * at the first one.
281 	 */
282 
283 	if (bpa >= sc->sc_owin_xlate[0] &&
284 	    bpa < (sc->sc_owin_xlate[0] + BECC_PCI_MEM1_SIZE)) {
285 		busbase = sc->sc_owin_xlate[0];
286 		winvaddr = sc->sc_pci_mem_base[0];
287 	} else
288 		return (EINVAL);
289 
290 	if ((bpa + size) >= (busbase + BECC_PCI_MEM1_SIZE))
291 		return (EINVAL);
292 
293 	/*
294 	 * Found the window -- PCI MEM space is mapped at a fixed
295 	 * virtual address by board-specific code.  Translate the
296 	 * bus address to the virtual address.
297 	 */
298 	*bshp = winvaddr + (bpa - busbase);
299 
300 	return (0);
301 }
302 
303 void
304 becc_mem_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
305 {
306 
307 	/* Nothing to do. */
308 }
309 
310 int
311 becc_mem_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
312     bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
313     bus_addr_t *bpap, bus_space_handle_t *bshp)
314 {
315 
316 	panic("becc_mem_bs_alloc(): not implemented\n");
317 }
318 
319 void
320 becc_mem_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
321 {
322 
323 	panic("becc_mem_bs_free(): not implemented\n");
324 }
325 
326 paddr_t
327 becc_mem_bs_mmap(void *t, bus_addr_t addr, off_t off, int prot, int flags)
328 {
329 
330 	/* XXX */
331 	return (-1);
332 }
333