gemini_space.c revision 1.1
1/*	$NetBSD: gemini_space.c,v 1.1 2008/10/24 04:23:18 matt Exp $	*/
2
3/* adapted from:
4 *	NetBSD: pxa2x0_space.c,v 1.8 2005/11/24 13:08:32 yamt Exp
5 */
6
7/*
8 * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
9 * All rights reserved.
10 *
11 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 *    must display the following acknowledgement:
23 *	This product includes software developed for the NetBSD Project by
24 *	Wasabi Systems, Inc.
25 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
26 *    or promote products derived from this software without specific prior
27 *    written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
33 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
40 */
41/*
42 * Copyright (c) 1997 Mark Brinicombe.
43 * Copyright (c) 1997 Causality Limited.
44 * All rights reserved.
45 *
46 * This code is derived from software contributed to The NetBSD Foundation
47 * by Ichiro FUKUHARA.
48 *
49 * Redistribution and use in source and binary forms, with or without
50 * modification, are permitted provided that the following conditions
51 * are met:
52 * 1. Redistributions of source code must retain the above copyright
53 *    notice, this list of conditions and the following disclaimer.
54 * 2. Redistributions in binary form must reproduce the above copyright
55 *    notice, this list of conditions and the following disclaimer in the
56 *    documentation and/or other materials provided with the distribution.
57 * 3. All advertising materials mentioning features or use of this software
58 *    must display the following acknowledgement:
59 *	This product includes software developed by Mark Brinicombe.
60 * 4. The name of the company nor the name of the author may be used to
61 *    endorse or promote products derived from this software without specific
62 *    prior written permission.
63 *
64 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
65 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
66 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
67 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
68 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
69 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
70 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * SUCH DAMAGE.
75 */
76
77/*
78 * bus_space functions for Gemini processor.
79 */
80
81#include <sys/cdefs.h>
82__KERNEL_RCSID(0, "$NetBSD: gemini_space.c,v 1.1 2008/10/24 04:23:18 matt Exp $");
83
84#include <sys/param.h>
85#include <sys/systm.h>
86
87#include <uvm/uvm_extern.h>
88
89#include <machine/bus.h>
90
91/* Prototypes for all the bus_space structure functions */
92bs_protos(gemini);
93bs_protos(generic);
94bs_protos(generic_armv4);
95bs_protos(bs_notimpl);
96
97struct bus_space gemini_bs_tag = {
98	/* cookie */
99	(void *) 0,
100
101	/* mapping/unmapping */
102	gemini_bs_map,
103	gemini_bs_unmap,
104	gemini_bs_subregion,
105
106	/* allocation/deallocation */
107	gemini_bs_alloc,	/* not implemented */
108	gemini_bs_free,		/* not implemented */
109
110	/* get kernel virtual address */
111	gemini_bs_vaddr,
112
113	/* mmap */
114	bs_notimpl_bs_mmap,
115
116	/* barrier */
117	gemini_bs_barrier,
118
119	/* read (single) */
120	generic_bs_r_1,
121	generic_armv4_bs_r_2,
122	generic_bs_r_4,
123	bs_notimpl_bs_r_8,
124
125	/* read multiple */
126	generic_bs_rm_1,
127	generic_armv4_bs_rm_2,
128	generic_bs_rm_4,
129	bs_notimpl_bs_rm_8,
130
131	/* read region */
132	generic_bs_rr_1,
133	generic_armv4_bs_rr_2,
134	generic_bs_rr_4,
135	bs_notimpl_bs_rr_8,
136
137	/* write (single) */
138	generic_bs_w_1,
139	generic_armv4_bs_w_2,
140	generic_bs_w_4,
141	bs_notimpl_bs_w_8,
142
143	/* write multiple */
144	generic_bs_wm_1,
145	generic_armv4_bs_wm_2,
146	generic_bs_wm_4,
147	bs_notimpl_bs_wm_8,
148
149	/* write region */
150	generic_bs_wr_1,
151	generic_armv4_bs_wr_2,
152	generic_bs_wr_4,
153	bs_notimpl_bs_wr_8,
154
155	/* set multiple */
156	bs_notimpl_bs_sm_1,
157	bs_notimpl_bs_sm_2,
158	bs_notimpl_bs_sm_4,
159	bs_notimpl_bs_sm_8,
160
161	/* set region */
162	generic_bs_sr_1,
163	generic_armv4_bs_sr_2,
164	bs_notimpl_bs_sr_4,
165	bs_notimpl_bs_sr_8,
166
167	/* copy */
168	bs_notimpl_bs_c_1,
169	generic_armv4_bs_c_2,
170	bs_notimpl_bs_c_4,
171	bs_notimpl_bs_c_8,
172};
173
174int
175gemini_bs_map(void *t, bus_addr_t bpa, bus_size_t size,
176	      int flag, bus_space_handle_t *bshp)
177{
178	u_long startpa, endpa, pa;
179	vaddr_t va;
180	pt_entry_t *pte;
181	const struct pmap_devmap	*pd;
182
183	if ((pd = pmap_devmap_find_pa(bpa, size)) != NULL) {
184		/* Device was statically mapped. */
185		*bshp = pd->pd_va + (bpa - pd->pd_pa);
186		return 0;
187	}
188
189	startpa = trunc_page(bpa);
190	endpa = round_page(bpa + size);
191
192	/* XXX use extent manager to check duplicate mapping */
193
194	va = uvm_km_alloc(kernel_map, endpa - startpa, 0,
195	    UVM_KMF_VAONLY | UVM_KMF_NOWAIT);
196	if (! va)
197		return(ENOMEM);
198
199	*bshp = (bus_space_handle_t)(va + (bpa - startpa));
200
201	for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
202		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
203		if ((flag & BUS_SPACE_MAP_CACHEABLE) == 0) {
204			pte = vtopte(va);
205			*pte &= ~L2_S_CACHE_MASK;
206			PTE_SYNC(pte);
207			/* XXX: pmap_kenter_pa() also does PTE_SYNC(). a bit of
208			 *      waste.
209			 */
210		}
211	}
212	pmap_update(pmap_kernel());
213
214	return(0);
215}
216
217void
218gemini_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
219{
220	vaddr_t	va;
221	vsize_t	sz;
222
223	if (pmap_devmap_find_va(bsh, size) != NULL) {
224		/* Device was statically mapped; nothing to do. */
225		return;
226	}
227
228	va = trunc_page(bsh);
229	sz = round_page(bsh + size) - va;
230
231	pmap_kremove(va, sz);
232	pmap_update(pmap_kernel());
233	uvm_km_free(kernel_map, va, sz, UVM_KMF_VAONLY);
234}
235
236
237int
238gemini_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
239    bus_size_t size, bus_space_handle_t *nbshp)
240{
241
242	*nbshp = bsh + offset;
243	return (0);
244}
245
246void
247gemini_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
248    bus_size_t len, int flags)
249{
250
251	/* Nothing to do. */
252}
253
254void *
255gemini_bs_vaddr(void *t, bus_space_handle_t bsh)
256{
257
258	return ((void *)bsh);
259}
260
261
262int
263gemini_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend,
264    bus_size_t size, bus_size_t alignment, bus_size_t boundary, int flags,
265    bus_addr_t *bpap, bus_space_handle_t *bshp)
266{
267
268	panic("gemini_io_bs_alloc(): not implemented\n");
269}
270
271void
272gemini_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
273{
274
275	panic("gemini_io_bs_free(): not implemented\n");
276}
277
278