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