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