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