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