xref: /netbsd/sys/arch/evbarm/iq80310/obio_space.c (revision c4a72b64)
1 /*	$NetBSD: obio_space.c,v 1.8 2002/09/27 15:36:00 provos Exp $	*/
2 
3 /*
4  * Copyright (c) 2001 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 IQ80310 on-board devices
40  */
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 
45 #include <uvm/uvm_extern.h>
46 
47 #include <machine/bus.h>
48 
49 #include "iq80310reg.h"
50 
51 /* Prototypes for all the bus_space structure functions */
52 bs_protos(obio);
53 bs_protos(generic);
54 bs_protos(bs_notimpl);
55 
56 /*
57  * The obio bus space tag.  This is constant for all instances, so
58  * we never have to explicitly "create" it.
59  */
60 struct bus_space obio_bs_tag = {
61 	/* cookie */
62 	(void *) 0,
63 
64 	/* mapping/unmapping */
65 	obio_bs_map,
66 	obio_bs_unmap,
67 	obio_bs_subregion,
68 
69 	/* allocation/deallocation */
70 	obio_bs_alloc,
71 	obio_bs_free,
72 
73 	/* get kernel virtual address */
74 	obio_bs_vaddr,
75 
76 	/* mmap */
77 	bs_notimpl_bs_mmap,
78 
79 	/* barrier */
80 	obio_bs_barrier,
81 
82 	/* read (single) */
83 	generic_bs_r_1,
84 	bs_notimpl_bs_r_2,
85 	generic_bs_r_4,
86 	bs_notimpl_bs_r_8,
87 
88 	/* read multiple */
89 	generic_bs_rm_1,
90 	bs_notimpl_bs_rm_2,
91 	bs_notimpl_bs_rm_4,
92 	bs_notimpl_bs_rm_8,
93 
94 	/* read region */
95 	generic_bs_rr_1,
96 	bs_notimpl_bs_rr_2,
97 	bs_notimpl_bs_rr_4,
98 	bs_notimpl_bs_rr_8,
99 
100 	/* write (single) */
101 	generic_bs_w_1,
102 	bs_notimpl_bs_w_2,
103 	generic_bs_w_4,
104 	bs_notimpl_bs_w_8,
105 
106 	/* write multiple */
107 	generic_bs_wm_1,
108 	bs_notimpl_bs_wm_2,
109 	bs_notimpl_bs_wm_4,
110 	bs_notimpl_bs_wm_8,
111 
112 	/* write region */
113 	bs_notimpl_bs_wr_1,
114 	bs_notimpl_bs_wr_2,
115 	bs_notimpl_bs_wr_4,
116 	bs_notimpl_bs_wr_8,
117 
118 	/* set multiple */
119 	bs_notimpl_bs_sm_1,
120 	bs_notimpl_bs_sm_2,
121 	bs_notimpl_bs_sm_4,
122 	bs_notimpl_bs_sm_8,
123 
124 	/* set region */
125 	bs_notimpl_bs_sr_1,
126 	bs_notimpl_bs_sr_2,
127 	bs_notimpl_bs_sr_4,
128 	bs_notimpl_bs_sr_8,
129 
130 	/* copy */
131 	bs_notimpl_bs_c_1,
132 	bs_notimpl_bs_c_2,
133 	bs_notimpl_bs_c_4,
134 	bs_notimpl_bs_c_8,
135 };
136 
137 int
138 obio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flags,
139     bus_space_handle_t *bshp)
140 {
141 	u_long startpa, endpa, pa;
142 	vaddr_t va;
143 	pt_entry_t *pte;
144 
145 	if (bpa > IQ80310_OBIO_BASE) {
146 
147 		/*
148 		 * IQ80310 on-board devices are mapped VA==PA.  All addresses
149 		 * we're provided, therefore, don't need any additional mapping.
150 		 */
151 		*bshp = bpa;
152 
153 	} else {
154 
155 		/*
156 		 * Some devices actually lie outside the range above.
157 		 * Notably: flash.
158 		 */
159 		startpa = trunc_page(bpa);
160 		endpa = round_page(bpa + size);
161 
162 		/* XXX use extent manager to check duplicate mapping */
163 
164 		va = uvm_km_valloc(kernel_map, endpa - startpa);
165 		if (! va)
166 			return(ENOMEM);
167 
168 		*bshp = (bus_space_handle_t)(va + (bpa - startpa));
169 
170 		for (pa = startpa; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
171 			pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
172 			pte = vtopte(va);
173 			*pte &= ~L2_S_CACHE_MASK;
174 			PTE_SYNC(pte);
175 		}
176 		pmap_update(pmap_kernel());
177 
178 	}
179 
180 	return 0;
181 }
182 
183 int
184 obio_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
185     bus_size_t alignment, bus_size_t boundary, int flags, bus_addr_t *bpap,
186     bus_space_handle_t *bshp)
187 {
188 
189 	panic("obio_bs_alloc(): not implemented");
190 }
191 
192 
193 void
194 obio_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
195 {
196 
197 	/* Nothing to do. */
198 	/* XXX -- technically, if we alloc and map above, we should
199 	 * unmap and free here, but we bail on this for now.
200 	 */
201 }
202 
203 void
204 obio_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
205 {
206 
207 	panic("obio_bs_free(): not implemented");
208 }
209 
210 int
211 obio_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset,
212     bus_size_t size, bus_space_handle_t *nbshp)
213 {
214 
215 	*nbshp = bsh + offset;
216 	return (0);
217 }
218 
219 void *
220 obio_bs_vaddr(void *t, bus_space_handle_t bsh)
221 {
222 
223 	return ((void *)bsh);
224 }
225 
226 void
227 obio_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset,
228     bus_size_t len, int flags)
229 {
230 
231 	/* Nothing to do. */
232 }
233