footbridge_io.c revision 1.8
1/*	$NetBSD: footbridge_io.c,v 1.8 2003/03/23 14:12:25 chris Exp $	*/
2
3/*
4 * Copyright (c) 1997 Causality Limited
5 * Copyright (c) 1997 Mark Brinicombe.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed by Mark Brinicombe
19 *	for the NetBSD Project.
20 * 4. The name of the company nor the name of the author may be used to
21 *    endorse or promote products derived from this software without specific
22 *    prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37/*
38 * bus_space I/O functions for footbridge
39 */
40
41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: footbridge_io.c,v 1.8 2003/03/23 14:12:25 chris Exp $");
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <machine/bus.h>
47#include <arm/footbridge/footbridge.h>
48#include <arm/footbridge/dc21285mem.h>
49#include <uvm/uvm_extern.h>
50
51/* Proto types for all the bus_space structure functions */
52
53bs_protos(footbridge);
54bs_protos(generic);
55bs_protos(generic_armv4);
56bs_protos(bs_notimpl);
57bs_map_proto(footbridge_mem);
58bs_unmap_proto(footbridge_mem);
59
60/* Declare the footbridge bus space tag */
61
62struct bus_space footbridge_bs_tag = {
63	/* cookie */
64	(void *) 0,			/* Base address */
65
66	/* mapping/unmapping */
67	footbridge_bs_map,
68	footbridge_bs_unmap,
69	footbridge_bs_subregion,
70
71	/* allocation/deallocation */
72	footbridge_bs_alloc,
73	footbridge_bs_free,
74
75	/* get kernel virtual address */
76	footbridge_bs_vaddr,
77
78	/* Mmap bus space for user */
79	bs_notimpl_bs_mmap,
80
81	/* barrier */
82	footbridge_bs_barrier,
83
84	/* read (single) */
85	generic_bs_r_1,
86	generic_armv4_bs_r_2,
87	generic_bs_r_4,
88	bs_notimpl_bs_r_8,
89
90	/* read multiple */
91	generic_bs_rm_1,
92	generic_armv4_bs_rm_2,
93	generic_bs_rm_4,
94	bs_notimpl_bs_rm_8,
95
96	/* read region */
97	bs_notimpl_bs_rr_1,
98	generic_armv4_bs_rr_2,
99	generic_bs_rr_4,
100	bs_notimpl_bs_rr_8,
101
102	/* write (single) */
103	generic_bs_w_1,
104	generic_armv4_bs_w_2,
105	generic_bs_w_4,
106	bs_notimpl_bs_w_8,
107
108	/* write multiple */
109	generic_bs_wm_1,
110	generic_armv4_bs_wm_2,
111	generic_bs_wm_4,
112	bs_notimpl_bs_wm_8,
113
114	/* write region */
115	bs_notimpl_bs_wr_1,
116	generic_armv4_bs_wr_2,
117	generic_bs_wr_4,
118	bs_notimpl_bs_wr_8,
119
120	/* set multiple */
121	bs_notimpl_bs_sm_1,
122	bs_notimpl_bs_sm_2,
123	bs_notimpl_bs_sm_4,
124	bs_notimpl_bs_sm_8,
125
126	/* set region */
127	bs_notimpl_bs_sr_1,
128	generic_armv4_bs_sr_2,
129	bs_notimpl_bs_sr_4,
130	bs_notimpl_bs_sr_8,
131
132	/* copy */
133	bs_notimpl_bs_c_1,
134	generic_armv4_bs_c_2,
135	bs_notimpl_bs_c_4,
136	bs_notimpl_bs_c_8,
137};
138
139void footbridge_create_io_bs_tag(t, cookie)
140	struct bus_space *t;
141	void *cookie;
142{
143	*t = footbridge_bs_tag;
144	t->bs_cookie = cookie;
145}
146
147void footbridge_create_mem_bs_tag(t, cookie)
148	struct bus_space *t;
149	void *cookie;
150{
151	*t = footbridge_bs_tag;
152	t->bs_map = footbridge_mem_bs_map;
153	t->bs_unmap = footbridge_mem_bs_unmap;
154	t->bs_cookie = cookie;
155}
156
157/* bus space functions */
158
159int
160footbridge_bs_map(t, bpa, size, cacheable, bshp)
161	void *t;
162	bus_addr_t bpa;
163	bus_size_t size;
164	int cacheable;
165	bus_space_handle_t *bshp;
166{
167	/*
168	 * The whole 64K of PCI space is always completely mapped during
169	 * boot.
170	 *
171	 * Eventually this function will do the mapping check overlapping /
172	 * multiple mappings.
173	 */
174
175	/* The cookie is the base address for the I/O area */
176	*bshp = bpa + (bus_addr_t)t;
177	return(0);
178}
179
180int
181footbridge_mem_bs_map(t, bpa, size, cacheable, bshp)
182	void *t;
183	bus_addr_t bpa;
184	bus_size_t size;
185	int cacheable;
186	bus_space_handle_t *bshp;
187{
188	bus_addr_t startpa, endpa;
189	vaddr_t va;
190
191	/* Round the allocation to page boundries */
192	startpa = trunc_page(bpa);
193	endpa = round_page(bpa + size);
194
195	/*
196	 * Check for mappings below 1MB as we have this space already
197	 * mapped. In practice it is only the VGA hole that takes
198	 * advantage of this.
199	 */
200	if (endpa < DC21285_PCI_ISA_MEM_VSIZE) {
201		/* Store the bus space handle */
202		*bshp = DC21285_PCI_ISA_MEM_VBASE + bpa;
203		return 0;
204	}
205
206	/*
207	 * Eventually this function will do the mapping check for overlapping /
208	 * multiple mappings
209	 */
210
211	va = uvm_km_valloc(kernel_map, endpa - startpa);
212	if (va == 0)
213		return ENOMEM;
214
215	/* Store the bus space handle */
216	*bshp = va + (bpa & PGOFSET);
217
218	/* Now map the pages */
219	/* The cookie is the physical base address for the I/O area */
220	while (startpa < endpa) {
221		pmap_enter(pmap_kernel(), va, (bus_addr_t)t + startpa,
222		    VM_PROT_READ | VM_PROT_WRITE, 0);
223		va += NBPG;
224		startpa += NBPG;
225	}
226	pmap_update(pmap_kernel());
227
228/*	if (bpa >= DC21285_PCI_MEM_VSIZE && bpa != DC21285_ARMCSR_VBASE)
229		panic("footbridge_bs_map: Address out of range (%08lx)", bpa);
230*/
231	return(0);
232}
233
234int
235footbridge_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
236    bpap, bshp)
237	void *t;
238	bus_addr_t rstart, rend;
239	bus_size_t size, alignment, boundary;
240	int cacheable;
241	bus_addr_t *bpap;
242	bus_space_handle_t *bshp;
243{
244	panic("footbridge_alloc(): Help!");
245}
246
247
248void
249footbridge_bs_unmap(t, bsh, size)
250	void *t;
251	bus_space_handle_t bsh;
252	bus_size_t size;
253{
254	/*
255	 * Temporary implementation
256	 */
257}
258
259void
260footbridge_mem_bs_unmap(t, bsh, size)
261	void *t;
262	bus_space_handle_t bsh;
263	bus_size_t size;
264{
265	vaddr_t startva, endva;
266
267	/*
268	 * Check for mappings below 1MB as we have this space permenantly
269	 * mapped. In practice it is only the VGA hole that takes
270	 * advantage of this.
271	 */
272	if (bsh >= DC21285_PCI_ISA_MEM_VBASE
273	    && bsh < (DC21285_PCI_ISA_MEM_VBASE + DC21285_PCI_ISA_MEM_VSIZE)) {
274		return;
275	}
276
277	startva = trunc_page(bsh);
278	endva = round_page(bsh + size);
279
280	uvm_km_free(kernel_map, startva, endva - startva);
281}
282
283void
284footbridge_bs_free(t, bsh, size)
285	void *t;
286	bus_space_handle_t bsh;
287	bus_size_t size;
288{
289
290	panic("footbridge_free(): Help!");
291	/* footbridge_bs_unmap() does all that we need to do. */
292/*	footbridge_bs_unmap(t, bsh, size);*/
293}
294
295int
296footbridge_bs_subregion(t, bsh, offset, size, nbshp)
297	void *t;
298	bus_space_handle_t bsh;
299	bus_size_t offset, size;
300	bus_space_handle_t *nbshp;
301{
302
303	*nbshp = bsh + (offset << ((int)t));
304	return (0);
305}
306
307void *
308footbridge_bs_vaddr(t, bsh)
309	void *t;
310	bus_space_handle_t bsh;
311{
312
313	return ((void *)bsh);
314}
315
316void
317footbridge_bs_barrier(t, bsh, offset, len, flags)
318	void *t;
319	bus_space_handle_t bsh;
320	bus_size_t offset, len;
321	int flags;
322{
323}
324