isa_io.c revision 1.13 1 /* $NetBSD: isa_io.c,v 1.13 2016/08/26 20:19:45 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.13 2016/08/26 20:19:45 macallan Exp $");
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/bus.h>
46 #include <machine/pio.h>
47 #include <machine/isa_machdep.h>
48 #include <machine/ofw.h>
49 #include "igsfb_ofbus.h"
50 #include "chipsfb_ofbus.h"
51
52 #if NIGSFB_OFBUS > 0
53 extern vaddr_t igsfb_mem_vaddr, igsfb_mmio_vaddr;
54 extern paddr_t igsfb_mem_paddr;
55 #endif
56
57 #if NCHIPSFB_OFBUS > 0
58 extern vaddr_t chipsfb_mem_vaddr, chipsfb_mmio_vaddr;
59 extern paddr_t chipsfb_mem_paddr;
60 #endif
61
62 /* Proto types for all the bus_space structure functions */
63
64 bs_protos(isa);
65 bs_protos(bs_notimpl);
66
67 /*
68 * Declare the isa bus space tags
69 * The IO and MEM structs are identical, except for the cookies,
70 * which contain the address space bases.
71 */
72
73 /*
74 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
75 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/IO!
76 */
77 struct bus_space isa_io_bs_tag = {
78 /* cookie */
79 NULL, /* initialized below */
80
81 /* mapping/unmapping */
82 isa_bs_map,
83 isa_bs_unmap,
84 isa_bs_subregion,
85
86 /* allocation/deallocation */
87 isa_bs_alloc,
88 isa_bs_free,
89
90 /* get kernel virtual address */
91 isa_bs_vaddr,
92
93 /* mmap bus space for userland */
94 isa_bs_mmap,
95
96 /* barrier */
97 isa_bs_barrier,
98
99 /* read (single) */
100 isa_bs_r_1,
101 isa_bs_r_2,
102 isa_bs_r_4,
103 bs_notimpl_bs_r_8,
104
105 /* read multiple */
106 isa_bs_rm_1,
107 isa_bs_rm_2,
108 isa_bs_rm_4,
109 bs_notimpl_bs_rm_8,
110
111 /* read region */
112 isa_bs_rr_1,
113 isa_bs_rr_2,
114 isa_bs_rr_4,
115 bs_notimpl_bs_rr_8,
116
117 /* write (single) */
118 isa_bs_w_1,
119 isa_bs_w_2,
120 isa_bs_w_4,
121 bs_notimpl_bs_w_8,
122
123 /* write multiple */
124 isa_bs_wm_1,
125 isa_bs_wm_2,
126 isa_bs_wm_4,
127 bs_notimpl_bs_wm_8,
128
129 /* write region */
130 isa_bs_wr_1,
131 isa_bs_wr_2,
132 isa_bs_wr_4,
133 bs_notimpl_bs_wr_8,
134
135 /* set multiple */
136 bs_notimpl_bs_sm_1,
137 bs_notimpl_bs_sm_2,
138 bs_notimpl_bs_sm_4,
139 bs_notimpl_bs_sm_8,
140
141 /* set region */
142 bs_notimpl_bs_sr_1,
143 isa_bs_sr_2,
144 bs_notimpl_bs_sr_4,
145 bs_notimpl_bs_sr_8,
146
147 /* copy */
148 bs_notimpl_bs_c_1,
149 isa_bs_c_2,
150 bs_notimpl_bs_c_4,
151 bs_notimpl_bs_c_8,
152
153 /* stream methods are identical to regular read/write here */
154 /* read stream single */
155 isa_bs_r_1,
156 isa_bs_r_2,
157 isa_bs_r_4,
158 bs_notimpl_bs_r_8,
159
160 /* read stream multiple */
161 isa_bs_rm_1,
162 isa_bs_rm_2,
163 isa_bs_rm_4,
164 bs_notimpl_bs_rm_8,
165
166 /* read region stream */
167 isa_bs_rr_1,
168 isa_bs_rr_2,
169 isa_bs_rr_4,
170 bs_notimpl_bs_rr_8,
171
172 /* write stream single */
173 isa_bs_w_1,
174 isa_bs_w_2,
175 isa_bs_w_4,
176 bs_notimpl_bs_w_8,
177
178 /* write stream multiple */
179 isa_bs_wm_1,
180 isa_bs_wm_2,
181 isa_bs_wm_4,
182 bs_notimpl_bs_wm_8,
183
184 /* write region stream */
185 isa_bs_wr_1,
186 isa_bs_wr_2,
187 isa_bs_wr_4,
188 bs_notimpl_bs_wr_8,
189
190 };
191
192 /*
193 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
194 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY!
195 */
196 struct bus_space isa_mem_bs_tag = {
197 /* cookie */
198 NULL, /* initialized below */
199
200 /* mapping/unmapping */
201 isa_bs_map,
202 isa_bs_unmap,
203 isa_bs_subregion,
204
205 /* allocation/deallocation */
206 isa_bs_alloc,
207 isa_bs_free,
208
209 /* get kernel virtual address */
210 isa_bs_vaddr,
211
212 /* mmap bus space for userland */
213 isa_bs_mmap,
214
215 /* barrier */
216 isa_bs_barrier,
217
218 /* read (single) */
219 isa_bs_r_1,
220 isa_bs_r_2,
221 isa_bs_r_4,
222 bs_notimpl_bs_r_8,
223
224 /* read multiple */
225 isa_bs_rm_1,
226 isa_bs_rm_2,
227 isa_bs_rm_4,
228 bs_notimpl_bs_rm_8,
229
230 /* read region */
231 isa_bs_rr_1,
232 isa_bs_rr_2,
233 isa_bs_rr_4,
234 bs_notimpl_bs_rr_8,
235
236 /* write (single) */
237 isa_bs_w_1,
238 isa_bs_w_2,
239 isa_bs_w_4,
240 bs_notimpl_bs_w_8,
241
242 /* write multiple */
243 isa_bs_wm_1,
244 isa_bs_wm_2,
245 isa_bs_wm_4,
246 bs_notimpl_bs_wm_8,
247
248 /* write region */
249 isa_bs_wr_1,
250 isa_bs_wr_2,
251 isa_bs_wr_4,
252 bs_notimpl_bs_wr_8,
253
254 /* set multiple */
255 bs_notimpl_bs_sm_1,
256 bs_notimpl_bs_sm_2,
257 bs_notimpl_bs_sm_4,
258 bs_notimpl_bs_sm_8,
259
260 /* set region */
261 bs_notimpl_bs_sr_1,
262 isa_bs_sr_2,
263 bs_notimpl_bs_sr_4,
264 bs_notimpl_bs_sr_8,
265
266 /* copy */
267 bs_notimpl_bs_c_1,
268 isa_bs_c_2,
269 bs_notimpl_bs_c_4,
270 bs_notimpl_bs_c_8,
271
272 /* stream methods are identical to regular read/write here */
273 /* read stream single */
274 isa_bs_r_1,
275 isa_bs_r_2,
276 isa_bs_r_4,
277 bs_notimpl_bs_r_8,
278
279 /* read stream multiple */
280 isa_bs_rm_1,
281 isa_bs_rm_2,
282 isa_bs_rm_4,
283 bs_notimpl_bs_rm_8,
284
285 /* read region stream */
286 isa_bs_rr_1,
287 isa_bs_rr_2,
288 isa_bs_rr_4,
289 bs_notimpl_bs_rr_8,
290
291 /* write stream single */
292 isa_bs_w_1,
293 isa_bs_w_2,
294 isa_bs_w_4,
295 bs_notimpl_bs_w_8,
296
297 /* write stream multiple */
298 isa_bs_wm_1,
299 isa_bs_wm_2,
300 isa_bs_wm_4,
301 bs_notimpl_bs_wm_8,
302
303 /* write region stream */
304 isa_bs_wr_1,
305 isa_bs_wr_2,
306 isa_bs_wr_4,
307 bs_notimpl_bs_wr_8,
308 };
309
310 /* bus space functions */
311
312 void
313 isa_io_init(vaddr_t isa_io_addr, vaddr_t isa_mem_addr)
314 {
315 isa_io_bs_tag.bs_cookie = (void *)isa_io_addr;
316 isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr;
317 }
318
319 /*
320 * break the abstraction: sometimes, other parts of the system
321 * (e.g. X servers) need to map ISA space directly. use these
322 * functions sparingly!
323 */
324 vaddr_t
325 isa_io_data_vaddr(void)
326 {
327 return (vaddr_t)isa_io_bs_tag.bs_cookie;
328 }
329
330 vaddr_t
331 isa_mem_data_vaddr(void)
332 {
333 return (vaddr_t)isa_mem_bs_tag.bs_cookie;
334 }
335
336 int
337 isa_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
338 {
339 *bshp = bpa + (bus_addr_t)t;
340 return(0);
341 }
342
343 void
344 isa_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
345 {
346 /* Nothing to do. */
347 }
348
349 paddr_t
350 isa_bs_mmap(void *cookie, bus_addr_t addr, off_t off, int prot,
351 int flags)
352 {
353 paddr_t paddr, ret;
354
355 #ifdef OFISA_DEBUG
356 printf("mmap %08x %08x %08x", (uint32_t)cookie, (uint32_t)addr, (uint32_t)off);
357 #endif
358 #if NIGSFB_OFBUS > 0
359 if ((vaddr_t)cookie == igsfb_mem_vaddr) {
360 paddr = igsfb_mem_paddr;
361 } else
362 #endif
363 #if NCHIPSFB_OFBUS > 0
364 if ((vaddr_t)cookie == chipsfb_mem_vaddr) {
365 paddr = chipsfb_mem_paddr;
366 } else
367 #endif
368 paddr = ofw_gettranslation((vaddr_t)cookie);
369
370 if (paddr == -1) {
371 #ifdef OFISA_DEBUG
372 printf(" no translation\n");
373 #endif
374 return -1;
375 }
376 ret = paddr + addr + off;
377 #ifdef OFISA_DEBUG
378 printf(" -> %08x %08x\n", (uint32_t)paddr, (uint32_t)ret);
379 #endif
380 return arm_btop(ret);
381 }
382
383 int
384 isa_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
385 {
386 /* printf("isa_subregion(tag=%p, bsh=%lx, off=%lx, sz=%lx)\n",
387 t, bsh, offset, size);*/
388 *nbshp = bsh + offset;
389 return(0);
390 }
391
392 int
393 isa_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
394 bus_size_t alignment, bus_size_t boundary, int cacheable,
395 bus_addr_t *bpap, bus_space_handle_t *bshp)
396 {
397 panic("isa_alloc(): Help!");
398 }
399
400 void
401 isa_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
402 {
403 panic("isa_free(): Help!");
404 }
405
406 void *
407 isa_bs_vaddr(void *t, bus_space_handle_t bsh)
408 {
409
410 return ((void *)bsh);
411 }
412
413 void
414 isa_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
415 {
416 /* just return */
417 }
418