isa_io.c revision 1.7 1 /* $NetBSD: isa_io.c,v 1.7 2006/12/07 03:10:14 macallan Exp $ */
2
3 /*
4 * Copyright 1997
5 * Digital Equipment Corporation. All rights reserved.
6 *
7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
12 *
13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as
15 * they appear in the source file.
16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Digital Equipment Corporation. Neither the "Digital Equipment
19 * Corporation" name nor any trademark or logo of Digital Equipment
20 * Corporation may be used to endorse or promote products derived
21 * from this software without the prior written permission of
22 * Digital Equipment Corporation.
23 *
24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage.
34 */
35
36 /*
37 * bus_space I/O functions for isa
38 */
39
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: isa_io.c,v 1.7 2006/12/07 03:10:14 macallan Exp $");
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <machine/bus.h>
46 #include <machine/pio.h>
47 #include <machine/isa_machdep.h>
48 #include <machine/ofw.h>
49 #include "igsfb_ofbus.h"
50
51 #if NIGSFB_OFBUS > 0
52 extern vaddr_t igsfb_mem_vaddr, igsfb_mmio_vaddr;
53 extern paddr_t igsfb_mem_paddr;
54 #endif
55
56 /* Proto types for all the bus_space structure functions */
57
58 bs_protos(isa);
59 bs_protos(bs_notimpl);
60
61 /*
62 * Declare the isa bus space tags
63 * The IO and MEM structs are identical, except for the cookies,
64 * which contain the address space bases.
65 */
66
67 /*
68 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
69 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/IO!
70 */
71 struct bus_space isa_io_bs_tag = {
72 /* cookie */
73 NULL, /* initialized below */
74
75 /* mapping/unmapping */
76 isa_bs_map,
77 isa_bs_unmap,
78 isa_bs_subregion,
79
80 /* allocation/deallocation */
81 isa_bs_alloc,
82 isa_bs_free,
83
84 /* get kernel virtual address */
85 isa_bs_vaddr,
86
87 /* mmap bus space for userland */
88 isa_bs_mmap,
89
90 /* barrier */
91 isa_bs_barrier,
92
93 /* read (single) */
94 isa_bs_r_1,
95 isa_bs_r_2,
96 isa_bs_r_4,
97 bs_notimpl_bs_r_8,
98
99 /* read multiple */
100 isa_bs_rm_1,
101 isa_bs_rm_2,
102 isa_bs_rm_4,
103 bs_notimpl_bs_rm_8,
104
105 /* read region */
106 isa_bs_rr_1,
107 isa_bs_rr_2,
108 isa_bs_rr_4,
109 bs_notimpl_bs_rr_8,
110
111 /* write (single) */
112 isa_bs_w_1,
113 isa_bs_w_2,
114 isa_bs_w_4,
115 bs_notimpl_bs_w_8,
116
117 /* write multiple */
118 isa_bs_wm_1,
119 isa_bs_wm_2,
120 isa_bs_wm_4,
121 bs_notimpl_bs_wm_8,
122
123 /* write region */
124 isa_bs_wr_1,
125 isa_bs_wr_2,
126 isa_bs_wr_4,
127 bs_notimpl_bs_wr_8,
128
129 /* set multiple */
130 bs_notimpl_bs_sm_1,
131 bs_notimpl_bs_sm_2,
132 bs_notimpl_bs_sm_4,
133 bs_notimpl_bs_sm_8,
134
135 /* set region */
136 bs_notimpl_bs_sr_1,
137 isa_bs_sr_2,
138 bs_notimpl_bs_sr_4,
139 bs_notimpl_bs_sr_8,
140
141 /* copy */
142 bs_notimpl_bs_c_1,
143 isa_bs_c_2,
144 bs_notimpl_bs_c_4,
145 bs_notimpl_bs_c_8,
146 };
147
148 /*
149 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
150 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY!
151 */
152 struct bus_space isa_mem_bs_tag = {
153 /* cookie */
154 NULL, /* initialized below */
155
156 /* mapping/unmapping */
157 isa_bs_map,
158 isa_bs_unmap,
159 isa_bs_subregion,
160
161 /* allocation/deallocation */
162 isa_bs_alloc,
163 isa_bs_free,
164
165 /* get kernel virtual address */
166 isa_bs_vaddr,
167
168 /* mmap bus space for userland */
169 isa_bs_mmap,
170
171 /* barrier */
172 isa_bs_barrier,
173
174 /* read (single) */
175 isa_bs_r_1,
176 isa_bs_r_2,
177 isa_bs_r_4,
178 bs_notimpl_bs_r_8,
179
180 /* read multiple */
181 isa_bs_rm_1,
182 isa_bs_rm_2,
183 isa_bs_rm_4,
184 bs_notimpl_bs_rm_8,
185
186 /* read region */
187 isa_bs_rr_1,
188 isa_bs_rr_2,
189 isa_bs_rr_4,
190 bs_notimpl_bs_rr_8,
191
192 /* write (single) */
193 isa_bs_w_1,
194 isa_bs_w_2,
195 isa_bs_w_4,
196 bs_notimpl_bs_w_8,
197
198 /* write multiple */
199 isa_bs_wm_1,
200 isa_bs_wm_2,
201 isa_bs_wm_4,
202 bs_notimpl_bs_wm_8,
203
204 /* write region */
205 isa_bs_wr_1,
206 isa_bs_wr_2,
207 isa_bs_wr_4,
208 bs_notimpl_bs_wr_8,
209
210 /* set multiple */
211 bs_notimpl_bs_sm_1,
212 bs_notimpl_bs_sm_2,
213 bs_notimpl_bs_sm_4,
214 bs_notimpl_bs_sm_8,
215
216 /* set region */
217 bs_notimpl_bs_sr_1,
218 isa_bs_sr_2,
219 bs_notimpl_bs_sr_4,
220 bs_notimpl_bs_sr_8,
221
222 /* copy */
223 bs_notimpl_bs_c_1,
224 isa_bs_c_2,
225 bs_notimpl_bs_c_4,
226 bs_notimpl_bs_c_8,
227 };
228
229 /* bus space functions */
230
231 void
232 isa_io_init(isa_io_addr, isa_mem_addr)
233 vaddr_t isa_io_addr;
234 vaddr_t isa_mem_addr;
235 {
236 isa_io_bs_tag.bs_cookie = (void *)isa_io_addr;
237 isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr;
238 }
239
240 /*
241 * break the abstraction: sometimes, other parts of the system
242 * (e.g. X servers) need to map ISA space directly. use these
243 * functions sparingly!
244 */
245 vaddr_t
246 isa_io_data_vaddr(void)
247 {
248 return (vaddr_t)isa_io_bs_tag.bs_cookie;
249 }
250
251 vaddr_t
252 isa_mem_data_vaddr(void)
253 {
254 return (vaddr_t)isa_mem_bs_tag.bs_cookie;
255 }
256
257 int
258 isa_bs_map(t, bpa, size, cacheable, bshp)
259 void *t;
260 bus_addr_t bpa;
261 bus_size_t size;
262 int cacheable;
263 bus_space_handle_t *bshp;
264 {
265 *bshp = bpa + (bus_addr_t)t;
266 return(0);
267 }
268
269 void
270 isa_bs_unmap(t, bsh, size)
271 void *t;
272 bus_space_handle_t bsh;
273 bus_size_t size;
274 {
275 /* Nothing to do. */
276 }
277
278 paddr_t
279 isa_bs_mmap(void *cookie, bus_addr_t addr, off_t off, int prot,
280 int flags)
281 {
282 paddr_t paddr, ret;
283
284 #ifdef OFISA_DEBUG
285 printf("mmap %08x %08x %08x", (uint32_t)cookie, (uint32_t)addr, (uint32_t)off);
286 #endif
287 #if NIGSFB_OFBUS > 0
288 if ((vaddr_t)cookie == igsfb_mem_vaddr) {
289 paddr = igsfb_mem_paddr;
290 } else
291 #endif
292 paddr = ofw_gettranslation((vaddr_t)cookie);
293
294 if (paddr == -1) {
295 #ifdef OFISA_DEBUG
296 printf(" no translation\n");
297 #endif
298 return -1;
299 }
300 ret = paddr + addr + off;
301 #ifdef OFISA_DEBUG
302 printf(" -> %08x %08x\n", (uint32_t)paddr, (uint32_t)ret);
303 #endif
304 return arm_btop(ret);
305 }
306
307 int
308 isa_bs_subregion(t, bsh, offset, size, nbshp)
309 void *t;
310 bus_space_handle_t bsh;
311 bus_size_t offset, size;
312 bus_space_handle_t *nbshp;
313 {
314 /* printf("isa_subregion(tag=%p, bsh=%lx, off=%lx, sz=%lx)\n",
315 t, bsh, offset, size);*/
316 *nbshp = bsh + offset;
317 return(0);
318 }
319
320 int
321 isa_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable,
322 bpap, bshp)
323 void *t;
324 bus_addr_t rstart, rend;
325 bus_size_t size, alignment, boundary;
326 int cacheable;
327 bus_addr_t *bpap;
328 bus_space_handle_t *bshp;
329 {
330 panic("isa_alloc(): Help!");
331 }
332
333 void
334 isa_bs_free(t, bsh, size)
335 void *t;
336 bus_space_handle_t bsh;
337 bus_size_t size;
338 {
339 panic("isa_free(): Help!");
340 }
341
342 void *
343 isa_bs_vaddr(t, bsh)
344 void *t;
345 bus_space_handle_t bsh;
346 {
347
348 return ((void *)bsh);
349 }
350
351 void
352 isa_bs_barrier(t, bsh, offset, len, flags)
353 void *t;
354 bus_space_handle_t bsh;
355 bus_size_t offset, len;
356 int flags;
357 {
358 /* just return */
359 }
360