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