1 /* $OpenBSD: isavar.h,v 1.52 2007/01/06 20:17:43 miod Exp $ */
2 /* $NetBSD: isavar.h,v 1.26 1997/06/06 23:43:57 thorpej Exp $ */
3
4 /*-
5 * Copyright (c) 1997 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
10 * NASA Ames Research Center.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 /*
42 * Copyright (c) 1996 Christos Zoulas. All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 * 3. All advertising materials mentioning features or use of this software
53 * must display the following acknowledgement:
54 * This product includes software developed by Christos Zoulas.
55 * 4. The name of the author may not be used to endorse or promote products
56 * derived from this software without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 */
69
70 /*
71 * Copyright (c) 1995 Chris G. Demetriou
72 * Copyright (c) 1992 Berkeley Software Design, Inc.
73 * All rights reserved.
74 *
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
77 * are met:
78 * 1. Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in the
82 * documentation and/or other materials provided with the distribution.
83 * 3. All advertising materials mentioning features or use of this software
84 * must display the following acknowledgement:
85 * This product includes software developed by Berkeley Software
86 * Design, Inc.
87 * 4. The name of Berkeley Software Design must not be used to endorse
88 * or promote products derived from this software without specific
89 * prior written permission.
90 *
91 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``AS IS'' AND
92 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
94 * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN, INC. BE LIABLE
95 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
96 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
97 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
98 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
99 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
100 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 * SUCH DAMAGE.
102 *
103 * BSDI Id: isavar.h,v 1.5 1992/12/01 18:06:00 karels Exp
104 */
105
106 #ifndef _DEV_ISA_ISAVAR_H_
107 #define _DEV_ISA_ISAVAR_H_
108
109 /*
110 * Definitions for ISA and ISA PnP autoconfiguration.
111 */
112
113 #include <sys/queue.h>
114 #include <machine/bus.h>
115
116 #ifndef NISADMA
117 #include "isadma.h"
118 #endif
119
120 /*
121 * Structures and definitions needed by the machine-dependent header.
122 */
123 struct isabus_attach_args;
124
125 #if defined(__alpha__)
126 #include <alpha/isa/isa_machdep.h>
127 #elif defined(__cats__)
128 #include <cats/isa/isa_machdep.h>
129 #elif defined(hp300)
130 #include <hp300/dev/isa_machdep.h>
131 #elif defined(__i386__)
132 #include <i386/isa/isa_machdep.h>
133 #elif defined(__mvmeppc__)
134 #include <mvmeppc/isa/isa_machdep.h>
135 #elif defined(__powerpc__)
136 #include <powerpc/isa/isa_machdep.h>
137 #else
138 #include <machine/isa_machdep.h>
139 #endif
140
141 #include "isapnp.h"
142
143 #if NISAPNP > 0
144 /*
145 * Structures and definitions needed by the machine-dependent header.
146 */
147 struct isapnp_softc;
148
149 #if defined(__alpha__)
150 #include <alpha/isa/isapnp_machdep.h>
151 #elif defined(__i386__)
152 #include <i386/isa/isapnp_machdep.h>
153 #else
154 #error COMPILING ISAPNP FOR UNSUPPORTED MACHINE.
155 #endif
156 #endif /* NISAPNP */
157
158 # define ISAPNP_WRITE_ADDR(sc, v) \
159 bus_space_write_1(sc->sc_iot, sc->sc_addr_ioh, 0, v)
160 # define ISAPNP_WRITE_DATA(sc, v) \
161 bus_space_write_1(sc->sc_iot, sc->sc_wrdata_ioh, 0, v)
162 # define ISAPNP_READ_DATA(sc) \
163 bus_space_read_1(sc->sc_iot, sc->sc_read_ioh, 0)
164
165 # define ISAPNP_MALLOC(a) malloc(a, M_DEVBUF, M_WAITOK)
166 # define ISAPNP_FREE(a) free(a, M_DEVBUF)
167 # define ISAPNP_CLONE_SETUP(dest, src) \
168 do { \
169 bzero((dest), sizeof(*(dest))); \
170 (dest)->ia_ic = (src)->ia_ic; \
171 } while (0)
172
173 #ifndef _DEV_ISA_ISAPNPREG_H_
174 /*
175 * `reg' defines needed only for these structures.
176 */
177 #define ISAPNP_MAX_CARDS 8
178 #define ISAPNP_MAX_IDENT 32
179 #define ISAPNP_MAX_DEVCLASS 16
180 #define ISAPNP_SERIAL_SIZE 9
181
182 #define ISAPNP_NUM_MEM 4
183 #define ISAPNP_NUM_IO 8
184 #define ISAPNP_NUM_IRQ 16
185 #define ISAPNP_NUM_DRQ 8
186 #define ISAPNP_NUM_MEM32 4
187 #endif /* _DEV_ISA_ISAPNPREG_H_ */
188
189 /*
190 * ISA PnP-specific structures.
191 */
192 struct isapnp_softc {
193 struct device sc_dev;
194 TAILQ_HEAD(, isadev)
195 sc_subdevs; /* list of all children */
196
197 bus_space_tag_t sc_iot; /* isa io space tag */
198 bus_space_tag_t sc_memt; /* isa mem space tag */
199 #if NISADMA > 0
200 bus_dma_tag_t sc_dmat; /* isa DMA tag */
201 #endif /* NISADMA > 0 */
202
203 int sc_read_port;
204 bus_space_handle_t sc_addr_ioh;
205 bus_space_handle_t sc_wrdata_ioh;
206 bus_space_handle_t sc_read_ioh;
207 bus_space_handle_t sc_memh;
208 u_int8_t sc_ncards;
209 u_int8_t sc_id[ISAPNP_MAX_CARDS][ISAPNP_SERIAL_SIZE];
210 };
211
212 struct isapnp_region {
213 bus_space_handle_t h;
214 u_int32_t base;
215
216 u_int32_t minbase;
217 u_int32_t maxbase;
218 u_int32_t length;
219 u_int32_t align;
220 u_int8_t flags;
221 };
222
223 struct isapnp_pin {
224 int16_t num;
225 u_int8_t flags:4;
226 u_int8_t type:4;
227 u_int16_t bits;
228 };
229
230 struct isapnp_knowndev {
231 const char pnpid[8];
232 const char driver[5];
233 };
234
235 /*
236 * ISA bus attach arguments
237 */
238 struct isabus_attach_args {
239 char *iba_busname; /* XXX should be common */
240 bus_space_tag_t iba_iot; /* isa i/o space tag */
241 bus_space_tag_t iba_memt; /* isa mem space tag */
242 #if NISADMA > 0
243 bus_dma_tag_t iba_dmat; /* isa DMA tag */
244 #endif
245 isa_chipset_tag_t iba_ic;
246 };
247
248 /*
249 * ISA/ISA PnP shared driver attach arguments
250 */
251 struct isa_attach_args {
252 struct device *ia_isa; /* isa device */
253 bus_space_tag_t ia_iot; /* isa i/o space tag */
254 bus_space_tag_t ia_memt; /* isa mem space tag */
255 #if NISADMA > 0
256 bus_dma_tag_t ia_dmat; /* DMA tag */
257 #endif
258 bus_space_handle_t ia_delaybah; /* i/o handle for `delay port' */
259
260 isa_chipset_tag_t ia_ic;
261
262 /*
263 * ISA PnP configuration support. `ipa_' prefixes are used to denote
264 * PnP specific members of this structure.
265 */
266 struct isa_attach_args *ipa_sibling;
267 struct isa_attach_args *ipa_child;
268
269 char ipa_devident[ISAPNP_MAX_IDENT];
270 char ipa_devlogic[ISAPNP_MAX_DEVCLASS];
271 char ipa_devcompat[ISAPNP_MAX_DEVCLASS];
272 char ipa_devclass[ISAPNP_MAX_DEVCLASS];
273
274 u_char ipa_pref;
275 u_char ipa_devnum;
276
277 u_char ipa_nio;
278 u_char ipa_nirq;
279 u_char ipa_ndrq;
280 u_char ipa_nmem;
281 u_char ipa_nmem32;
282
283 struct isapnp_region ipa_io[ISAPNP_NUM_IO];
284 struct isapnp_region ipa_mem[ISAPNP_NUM_MEM];
285 struct isapnp_region ipa_mem32[ISAPNP_NUM_MEM32];
286 struct isapnp_pin ipa_irq[ISAPNP_NUM_IRQ];
287 struct isapnp_pin ipa_drq[ISAPNP_NUM_DRQ];
288
289 /*
290 * Compatibility defines for ISA drivers.
291 */
292 #define ia_iobase ipa_io[0].base
293 #define ia_iosize ipa_io[0].length
294 #define ia_ioh ipa_io[0].h
295 #define ia_irq ipa_irq[0].num
296 #define ia_drq ipa_drq[0].num
297 #define ia_drq2 ipa_drq[1].num
298 #define ia_maddr ipa_mem[0].base
299 #define ia_msize ipa_mem[0].length
300 #define ia_memh ipa_mem[0].h
301
302 void *ia_aux; /* driver specific */
303 };
304
305 #define IOBASEUNK -1 /* i/o address is unknown */
306 #define IRQUNK -1 /* interrupt request line is unknown */
307 #define DRQUNK -1 /* DMA request line is unknown */
308 #define MADDRUNK -1 /* shared memory address is unknown */
309
310 /*
311 * Per-device ISA variables
312 */
313 struct isadev {
314 struct device *id_dev; /* back pointer to generic */
315 TAILQ_ENTRY(isadev)
316 id_bchain; /* bus chain */
317 };
318
319 /*
320 * ISA master bus
321 */
322 struct isa_softc {
323 struct device sc_dev; /* base device */
324 TAILQ_HEAD(, isadev)
325 sc_subdevs; /* list of all children */
326
327 bus_space_tag_t sc_iot; /* isa io space tag */
328 bus_space_tag_t sc_memt; /* isa mem space tag */
329 #if NISADMA > 0
330 bus_dma_tag_t sc_dmat; /* isa DMA tag */
331 #endif /* NISADMA > 0 */
332
333 isa_chipset_tag_t sc_ic;
334
335 #if NISADMA > 0
336 /*
337 * Bitmap representing the DRQ channels available
338 * for ISA.
339 */
340 int sc_drqmap;
341 #define sc_drq sc_drqmap /* XXX compatibility mode */
342
343 bus_space_handle_t sc_dma1h; /* i/o handle for DMA controller #1 */
344 bus_space_handle_t sc_dma2h; /* i/o handle for DMA controller #2 */
345 bus_space_handle_t sc_dmapgh; /* i/o handle for DMA page registers */
346
347 /*
348 * DMA maps used for the 8 DMA channels.
349 */
350 bus_dmamap_t sc_dmamaps[8];
351 bus_size_t sc_dmalength[8];
352
353 int sc_dmareads; /* state for isa_dmadone() */
354 int sc_dmafinished; /* DMA completion state */
355 #endif /* NISADMA > 0 */
356
357 /*
358 * This i/o handle is used to map port 0x84, which is
359 * read to provide a 1.25us delay. This access handle
360 * is mapped in isaattach(), and exported to drivers
361 * via isa_attach_args.
362 */
363 bus_space_handle_t sc_delaybah;
364 };
365
366 #define ISA_DRQ_ISFREE(isadev, drq) \
367 ((((struct isa_softc *)(isadev))->sc_drqmap & (1 << (drq))) == 0)
368
369 #define ISA_DRQ_ALLOC(isadev, drq) \
370 ((struct isa_softc *)(isadev))->sc_drqmap |= (1 << (drq))
371
372 #define ISA_DRQ_FREE(isadev, drq) \
373 ((struct isa_softc *)(isadev))->sc_drqmap &= ~(1 << (drq))
374
375 #define cf_iobase cf_loc[0]
376 #define cf_iosize cf_loc[1]
377 #define cf_maddr cf_loc[2]
378 #define cf_msize cf_loc[3]
379 #define cf_irq cf_loc[4]
380 #define cf_drq cf_loc[5]
381 #define cf_drq2 cf_loc[6]
382
383 /*
384 * ISA interrupt handler manipulation.
385 *
386 * To establish an ISA interrupt handler, a driver calls isa_intr_establish()
387 * with the interrupt number, type, level, function, and function argument of
388 * the interrupt it wants to handle. Isa_intr_establish() returns an opaque
389 * handle to an event descriptor if it succeeds, and invokes panic() if it
390 * fails. (XXX It should return NULL, then drivers should handle that, but
391 * what should they do?) Interrupt handlers should return 0 for "interrupt
392 * not for me", 1 for "I took care of it", or -1 for "I guess it was mine,
393 * but I wasn't expecting it."
394 *
395 * To remove an interrupt handler, the driver calls isa_intr_disestablish()
396 * with the handle returned by isa_intr_establish() for that handler.
397 */
398
399 /* ISA interrupt sharing types */
400 char *isa_intr_typename(int type);
401
402 void isascan(struct device *parent, void *match);
403 int isaprint(void *, const char *);
404
405 /*
406 * Some ISA devices (e.g. on a VLB) can perform 32-bit DMA. This
407 * flag is passed to bus_dmamap_create() to indicate that fact.
408 */
409 #define ISABUS_DMA_32BIT BUS_DMA_BUS1
410
411 /*
412 * ISA PnP prototypes and support macros.
413 */
414 static __inline void isapnp_write_reg(struct isapnp_softc *, int, u_char);
415 static __inline u_char isapnp_read_reg(struct isapnp_softc *, int);
416
417 static __inline void
418 isapnp_write_reg(sc, r, v)
419 struct isapnp_softc *sc;
420 int r;
421 u_char v;
422 {
423 ISAPNP_WRITE_ADDR(sc, r);
424 ISAPNP_WRITE_DATA(sc, v);
425 }
426
427 static __inline u_char
428 isapnp_read_reg(sc, r)
429 struct isapnp_softc *sc;
430 int r;
431 {
432 ISAPNP_WRITE_ADDR(sc, r);
433 return ISAPNP_READ_DATA(sc);
434 }
435
436 struct isa_attach_args *
437 isapnp_get_resource(struct isapnp_softc *, int, struct isa_attach_args *);
438 char *isapnp_id_to_vendor(char *, const u_char *);
439
440 int isapnp_config(bus_space_tag_t, bus_space_tag_t,
441 struct isa_attach_args *);
442 void isapnp_unconfig(bus_space_tag_t, bus_space_tag_t,
443 struct isa_attach_args *);
444
445 void isapnp_isa_attach_hook(struct isa_softc *);
446 #ifdef DEBUG_ISAPNP
447 void isapnp_print_mem(const char *, const struct isapnp_region *);
448 void isapnp_print_io(const char *, const struct isapnp_region *);
449 void isapnp_print_irq(const char *, const struct isapnp_pin *);
450 void isapnp_print_drq(const char *, const struct isapnp_pin *);
451 void isapnp_print_dep_start(const char *, const u_char);
452 void isapnp_print_attach(const struct isa_attach_args *);
453 void isapnp_get_config(struct isapnp_softc *,
454 struct isa_attach_args *);
455 void isapnp_print_config(const struct isa_attach_args *);
456 #endif /* DEBUG_ISAPNP */
457 #endif /* _DEV_ISA_ISAVAR_H_ */