footbridge_io.c revision 1.4
1/*	$NetBSD: footbridge_io.c,v 1.4 2001/09/10 23:05:19 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/param.h>
42#include <sys/systm.h>
43#include <machine/bus.h>
44#include <arm/footbridge/dc21285mem.h>
45#include <uvm/uvm_extern.h>
46
47/* Proto types for all the bus_space structure functions */
48
49bs_protos(footbridge);
50bs_protos(bs_notimpl);
51bs_map_proto(footbridge_mem);
52bs_unmap_proto(footbridge_mem);
53
54/* Declare the footbridge bus space tag */
55
56struct bus_space footbridge_bs_tag = {
57	/* cookie */
58	(void *) 0,			/* Base address */
59
60	/* mapping/unmapping */
61	footbridge_bs_map,
62	footbridge_bs_unmap,
63	footbridge_bs_subregion,
64
65	/* allocation/deallocation */
66	footbridge_bs_alloc,
67	footbridge_bs_free,
68
69	/* get kernel virtual address */
70	footbridge_bs_vaddr,
71
72	/* Mmap bus space for user */
73	bs_notimpl_bs_mmap,
74
75	/* barrier */
76	footbridge_bs_barrier,
77
78	/* read (single) */
79	footbridge_bs_r_1,
80	footbridge_bs_r_2,
81	footbridge_bs_r_4,
82	bs_notimpl_bs_r_8,
83
84	/* read multiple */
85	footbridge_bs_rm_1,
86	footbridge_bs_rm_2,
87	footbridge_bs_rm_4,
88	bs_notimpl_bs_rm_8,
89
90	/* read region */
91	bs_notimpl_bs_rr_1,
92	footbridge_bs_rr_2,
93	footbridge_bs_rr_4,
94	bs_notimpl_bs_rr_8,
95
96	/* write (single) */
97	footbridge_bs_w_1,
98	footbridge_bs_w_2,
99	footbridge_bs_w_4,
100	bs_notimpl_bs_w_8,
101
102	/* write multiple */
103	footbridge_bs_wm_1,
104	footbridge_bs_wm_2,
105	footbridge_bs_wm_4,
106	bs_notimpl_bs_wm_8,
107
108	/* write region */
109	bs_notimpl_bs_wr_1,
110	footbridge_bs_wr_2,
111	footbridge_bs_wr_4,
112	bs_notimpl_bs_wr_8,
113
114	/* set multiple */
115	bs_notimpl_bs_sm_1,
116	bs_notimpl_bs_sm_2,
117	bs_notimpl_bs_sm_4,
118	bs_notimpl_bs_sm_8,
119
120	/* set region */
121	bs_notimpl_bs_sr_1,
122	footbridge_bs_sr_2,
123	bs_notimpl_bs_sr_4,
124	bs_notimpl_bs_sr_8,
125
126	/* copy */
127	bs_notimpl_bs_c_1,
128	footbridge_bs_c_2,
129	bs_notimpl_bs_c_4,
130	bs_notimpl_bs_c_8,
131};
132
133void footbridge_create_io_bs_tag(t, cookie)
134	struct bus_space *t;
135	void *cookie;
136{
137	*t = footbridge_bs_tag;
138	t->bs_cookie = cookie;
139}
140
141void footbridge_create_mem_bs_tag(t, cookie)
142	struct bus_space *t;
143	void *cookie;
144{
145	*t = footbridge_bs_tag;
146	t->bs_map = footbridge_mem_bs_map;
147	t->bs_unmap = footbridge_mem_bs_unmap;
148	t->bs_cookie = cookie;
149}
150
151/* bus space functions */
152
153int
154footbridge_bs_map(t, bpa, size, cacheable, bshp)
155	void *t;
156	bus_addr_t bpa;
157	bus_size_t size;
158	int cacheable;
159	bus_space_handle_t *bshp;
160{
161	/*
162	 * The whole 64K of PCI space is always completely mapped during
163	 * boot.
164	 *
165	 * Eventually this function will do the mapping check overlapping /
166	 * multiple mappings.
167	 */
168
169	/* The cookie is the base address for the I/O area */
170	*bshp = bpa + (bus_addr_t)t;
171	return(0);
172}
173
174int
175footbridge_mem_bs_map(t, bpa, size, cacheable, bshp)
176	void *t;
177	bus_addr_t bpa;
178	bus_size_t size;
179	int cacheable;
180	bus_space_handle_t *bshp;
181{
182	bus_addr_t startpa, endpa;
183	vaddr_t va;
184
185	/* Round the allocation to page boundries */
186	startpa = trunc_page(bpa);
187	endpa = round_page(bpa + size);
188
189	/*
190	 * Check for mappings below 1MB as we have this space already
191	 * mapped. In practice it is only the VGA hole that takes
192	 * advantage of this.
193	 */
194	if (endpa < DC21285_PCI_ISA_MEM_VSIZE) {
195		/* Store the bus space handle */
196		*bshp = DC21285_PCI_ISA_MEM_VBASE + bpa;
197		return 0;
198	}
199
200	/*
201	 * Eventually this function will do the mapping check for overlapping /
202	 * multiple mappings
203	 */
204
205	va = uvm_km_valloc(kernel_map, endpa - startpa);
206	if (va == 0)
207		return ENOMEM;
208
209	/* Store the bus space handle */
210	*bshp = va + (bpa & PGOFSET);
211
212	/* Now map the pages */
213	/* The cookie is the physical base address for the I/O area */
214	while (startpa < endpa) {
215		pmap_enter(pmap_kernel(), va, (bus_addr_t)t + startpa,
216		    VM_PROT_READ | VM_PROT_WRITE, 0);
217		va += NBPG;
218		startpa += NBPG;
219	}
220	pmap_update(pmap_kernel());
221
222/*	if (bpa >= DC21285_PCI_MEM_VSIZE && bpa != DC21285_ARMCSR_VBASE)
223		panic("footbridge_bs_map: Address out of range (%08lx)\n", bpa);
224*/
225	return(0);
226}
227
228int
229footbridge_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
230    bpap, bshp)
231	void *t;
232	bus_addr_t rstart, rend;
233	bus_size_t size, alignment, boundary;
234	int cacheable;
235	bus_addr_t *bpap;
236	bus_space_handle_t *bshp;
237{
238	panic("footbridge_alloc(): Help!\n");
239}
240
241
242void
243footbridge_bs_unmap(t, bsh, size)
244	void *t;
245	bus_space_handle_t bsh;
246	bus_size_t size;
247{
248	/*
249	 * Temporary implementation
250	 */
251}
252
253void
254footbridge_mem_bs_unmap(t, bsh, size)
255	void *t;
256	bus_space_handle_t bsh;
257	bus_size_t size;
258{
259	vaddr_t startva, endva;
260
261	/*
262	 * Check for mappings below 1MB as we have this space permenantly
263	 * mapped. In practice it is only the VGA hole that takes
264	 * advantage of this.
265	 */
266	if (bsh >= DC21285_PCI_ISA_MEM_VBASE
267	    && bsh < (DC21285_PCI_ISA_MEM_VBASE + DC21285_PCI_ISA_MEM_VSIZE)) {
268		return;
269	}
270
271	startva = trunc_page(bsh);
272	endva = round_page(bsh + size);
273
274	uvm_km_free(kernel_map, startva, endva - startva);
275}
276
277void
278footbridge_bs_free(t, bsh, size)
279	void *t;
280	bus_space_handle_t bsh;
281	bus_size_t size;
282{
283
284	panic("footbridge_free(): Help!\n");
285	/* footbridge_bs_unmap() does all that we need to do. */
286/*	footbridge_bs_unmap(t, bsh, size);*/
287}
288
289int
290footbridge_bs_subregion(t, bsh, offset, size, nbshp)
291	void *t;
292	bus_space_handle_t bsh;
293	bus_size_t offset, size;
294	bus_space_handle_t *nbshp;
295{
296
297	*nbshp = bsh + (offset << ((int)t));
298	return (0);
299}
300
301void *
302footbridge_bs_vaddr(t, bsh)
303	void *t;
304	bus_space_handle_t bsh;
305{
306
307	return ((void *)bsh);
308}
309
310void
311footbridge_bs_barrier(t, bsh, offset, len, flags)
312	void *t;
313	bus_space_handle_t bsh;
314	bus_size_t offset, len;
315	int flags;
316{
317}
318