i80321_space.c revision 135669
1/*	$NetBSD: i80321_space.c,v 1.6 2003/10/06 15:43:35 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 i80321 I/O Processor.
40 */
41
42#include <sys/cdefs.h>
43__FBSDID("$FreeBSD: head/sys/arm/xscale/i80321/i80321_space.c 135669 2004-09-23 22:45:36Z cognet $");
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/bus.h>
48
49#include <machine/pcb.h>
50
51#include <vm/vm.h>
52#include <vm/vm_kern.h>
53#include <vm/pmap.h>
54#include <vm/vm_page.h>
55#include <vm/vm_extern.h>
56
57#include <machine/bus.h>
58
59#include <arm/xscale/i80321/i80321reg.h>
60#include <arm/xscale/i80321/i80321var.h>
61
62/* Prototypes for all the bus_space structure functions */
63bs_protos(i80321);
64bs_protos(i80321_io);
65bs_protos(i80321_mem);
66bs_protos(generic);
67bs_protos(generic_armv4);
68bs_protos(bs_notimpl);
69
70/*
71 * Template bus_space -- copied, and the bits that are NULL are
72 * filled in.
73 */
74const struct bus_space i80321_bs_tag_template = {
75	/* cookie */
76	(void *) 0,
77
78	/* mapping/unmapping */
79	NULL,
80	NULL,
81	i80321_bs_subregion,
82
83	/* allocation/deallocation */
84	NULL,
85	NULL,
86
87	/* barrier */
88	i80321_bs_barrier,
89
90	/* read (single) */
91	generic_bs_r_1,
92	generic_armv4_bs_r_2,
93	generic_bs_r_4,
94	NULL,
95
96	/* read multiple */
97	generic_bs_rm_1,
98	generic_armv4_bs_rm_2,
99	generic_bs_rm_4,
100	NULL,
101
102	/* read region */
103	NULL,
104	generic_armv4_bs_rr_2,
105	generic_bs_rr_4,
106	NULL,
107
108	/* write (single) */
109	generic_bs_w_1,
110	generic_armv4_bs_w_2,
111	generic_bs_w_4,
112	NULL,
113
114	/* write multiple */
115	generic_bs_wm_1,
116	generic_armv4_bs_wm_2,
117	generic_bs_wm_4,
118	NULL,
119
120	/* write region */
121	NULL,
122	generic_armv4_bs_wr_2,
123	generic_bs_wr_4,
124	NULL,
125
126	/* set multiple */
127	NULL,
128	NULL,
129	NULL,
130	NULL,
131
132	/* set region */
133	NULL,
134	generic_armv4_bs_sr_2,
135	generic_bs_sr_4,
136	NULL,
137
138	/* copy */
139	NULL,
140	generic_armv4_bs_c_2,
141	NULL,
142	NULL,
143};
144
145void
146i80321_bs_init(bus_space_tag_t bs, void *cookie)
147{
148
149	*bs = i80321_bs_tag_template;
150	bs->bs_cookie = cookie;
151}
152
153void
154i80321_io_bs_init(bus_space_tag_t bs, void *cookie)
155{
156
157	*bs = i80321_bs_tag_template;
158	bs->bs_cookie = cookie;
159
160	bs->bs_map = i80321_io_bs_map;
161	bs->bs_unmap = i80321_io_bs_unmap;
162	bs->bs_alloc = i80321_io_bs_alloc;
163	bs->bs_free = i80321_io_bs_free;
164
165}
166
167void
168i80321_mem_bs_init(bus_space_tag_t bs, void *cookie)
169{
170
171	*bs = i80321_bs_tag_template;
172	bs->bs_cookie = cookie;
173
174	bs->bs_map = i80321_mem_bs_map;
175	bs->bs_unmap = i80321_mem_bs_unmap;
176	bs->bs_alloc = i80321_mem_bs_alloc;
177	bs->bs_free = i80321_mem_bs_free;
178
179}
180
181/* *** Routines shared by i80321, PCI IO, and PCI MEM. *** */
182
183int
184i80321_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
185    bus_size_t size, bus_space_handle_t *nbshp)
186{
187
188	*nbshp = bsh + offset;
189	return (0);
190}
191
192void
193i80321_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
194    bus_size_t len, int flags)
195{
196
197	/* Nothing to do. */
198}
199
200/* *** Routines for PCI IO. *** */
201
202extern struct i80321_softc *i80321_softc;
203int
204i80321_io_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
205    bus_space_handle_t *bshp)
206{
207	struct i80321_softc *sc = i80321_softc;
208	vm_offset_t winvaddr;
209	uint32_t busbase;
210
211	if (bpa >= sc->sc_ioout_xlate &&
212	    bpa < (sc->sc_ioout_xlate + VERDE_OUT_XLATE_IO_WIN_SIZE)) {
213		busbase = sc->sc_ioout_xlate;
214		winvaddr = sc->sc_iow_vaddr;
215	} else
216		return (EINVAL);
217
218	if ((bpa + size) >= (busbase + VERDE_OUT_XLATE_IO_WIN_SIZE))
219		return (EINVAL);
220
221	/*
222	 * Found the window -- PCI I/O space is mapped at a fixed
223	 * virtual address by board-specific code.  Translate the
224	 * bus address to the virtual address.
225	 */
226	*bshp = winvaddr + (bpa - busbase);
227
228	return (0);
229}
230
231void
232i80321_io_bs_unmap(void *t, bus_size_t size)
233{
234
235	/* Nothing to do. */
236}
237
238int
239i80321_io_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
240    bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
241    bus_addr_t *bpap, bus_space_handle_t *bshp)
242{
243
244	panic("i80321_io_bs_alloc(): not implemented");
245}
246
247void
248i80321_io_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
249{
250
251	panic("i80321_io_bs_free(): not implemented");
252}
253
254
255/* *** Routines for PCI MEM. *** */
256extern int badaddr_read(void *, int, void *);
257int
258i80321_mem_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
259    bus_space_handle_t *bshp)
260{
261
262	vm_offset_t va;
263	uint32_t busbase;
264	vm_paddr_t pa, endpa, physbase;
265
266	/*
267	 * Found the window -- PCI MEM space is not mapped by allocating
268	 * some kernel VA space and mapping the pages with pmap_enter().
269	 * pmap_enter() will map unmanaged pages as non-cacheable.
270	 */
271	pa = trunc_page((bpa - busbase) + physbase);
272	endpa = round_page(((bpa - busbase) + physbase) + size);
273	pa = trunc_page(bpa);
274	endpa = round_page(bpa + size);
275
276	*bshp = va + (bpa & PAGE_MASK);
277	*bshp = pa;
278	*bshp = (vm_offset_t)pmap_mapdev(pa, endpa - pa);
279
280	return (0);
281}
282
283void
284i80321_mem_bs_unmap(void *t, bus_size_t size)
285{
286	vm_offset_t va, endva;
287
288	va = trunc_page((vm_offset_t)t);
289	endva = va + round_page(size);
290
291	/* Free the kernel virtual mapping. */
292	kmem_free(kernel_map, va, endva - va);
293}
294
295int
296i80321_mem_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
297    bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
298    bus_addr_t *bpap, bus_space_handle_t *bshp)
299{
300
301	panic("i80321_mem_bs_alloc(): not implemented");
302}
303
304void
305i80321_mem_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
306{
307
308	panic("i80321_mem_bs_free(): not implemented");
309}
310