1 /*	$OpenBSD: isavar.h,v 1.51 2004/02/03 09:25:02 mickey 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 (__alpha__ + amiga + __cats__ + __i386__ + arc + __wgrisc__ + __powerpc__ + __hppa__ + __amd64__ != 1)
126 #error "COMPILING ISA FOR UNSUPPORTED MACHINE, OR MORE THAN ONE."
127 #endif
128 #ifdef __alpha__
129 #include <alpha/isa/isa_machdep.h>
130 #endif
131 #ifdef amiga
132 #include <amiga/isa/isa_machdep.h>
133 #endif
134 #ifdef __cats__
135 #include <cats/isa/isa_machdep.h>
136 #endif
137 #ifdef __i386__
138 #include <i386/isa/isa_machdep.h>
139 #endif
140 #ifdef arc
141 #include <arc/isa/isa_machdep.h>
142 #endif
143 #ifdef __wgrisc__
144 #include <wgrisc/isa/isa_machdep.h>
145 #endif
146 #ifdef __powerpc__
147 #ifdef __mvmeppc__
148 #include <mvmeppc/isa/isa_machdep.h>
149 #else
150 #include <powerpc/isa/isa_machdep.h>
151 #endif
152 #endif
153 #ifdef __hppa__
154 #include <hppa/include/isa_machdep.h>
155 #endif
156 #ifdef __amd64__
157 #include <amd64/include/isa_machdep.h>
158 #endif
159 
160 #include "isapnp.h"
161 
162 #if NISAPNP > 0
163 /*
164  * Structures and definitions needed by the machine-dependent header.
165  */
166 struct isapnp_softc;
167 
168 #if (__i386__ != 1 && __alpha__ != 1)
169 #error COMPILING ISAPNP FOR UNSUPPORTED MACHINE, OR MORE THAN ONE.
170 #endif
171 #if __i386__
172 #include <i386/isa/isapnp_machdep.h>
173 #endif
174 #if __alpha__
175 #include <alpha/isa/isapnp_machdep.h>
176 #endif
177 #endif	/* NISAPNP */
178 
179 # define ISAPNP_WRITE_ADDR(sc, v) \
180     bus_space_write_1(sc->sc_iot, sc->sc_addr_ioh, 0, v)
181 # define ISAPNP_WRITE_DATA(sc, v) \
182     bus_space_write_1(sc->sc_iot, sc->sc_wrdata_ioh, 0, v)
183 # define ISAPNP_READ_DATA(sc) \
184     bus_space_read_1(sc->sc_iot, sc->sc_read_ioh, 0)
185 
186 # define ISAPNP_MALLOC(a) malloc(a, M_DEVBUF, M_WAITOK)
187 # define ISAPNP_FREE(a) free(a, M_DEVBUF)
188 # define ISAPNP_CLONE_SETUP(dest, src) \
189 	do { \
190 		bzero((dest), sizeof(*(dest))); \
191 		(dest)->ia_ic = (src)->ia_ic; \
192 	} while (0)
193 
194 #ifndef _DEV_ISA_ISAPNPREG_H_
195 /*
196  * `reg' defines needed only for these structures.
197  */
198 #define ISAPNP_MAX_CARDS 	8
199 #define ISAPNP_MAX_IDENT	32
200 #define ISAPNP_MAX_DEVCLASS	16
201 #define ISAPNP_SERIAL_SIZE	9
202 
203 #define ISAPNP_NUM_MEM		4
204 #define ISAPNP_NUM_IO		8
205 #define ISAPNP_NUM_IRQ		16
206 #define ISAPNP_NUM_DRQ		8
207 #define ISAPNP_NUM_MEM32	4
208 #endif	/* _DEV_ISA_ISAPNPREG_H_ */
209 
210 /*
211  * ISA PnP-specific structures.
212  */
213 struct isapnp_softc {
214 	struct device		sc_dev;
215 	TAILQ_HEAD(, isadev)
216 		sc_subdevs;		/* list of all children */
217 
218 	bus_space_tag_t sc_iot;		/* isa io space tag */
219 	bus_space_tag_t sc_memt;	/* isa mem space tag */
220 #if NISADMA > 0
221 	bus_dma_tag_t sc_dmat;		/* isa DMA tag */
222 #endif /* NISADMA > 0 */
223 
224 	int			sc_read_port;
225 	bus_space_handle_t	sc_addr_ioh;
226 	bus_space_handle_t	sc_wrdata_ioh;
227 	bus_space_handle_t	sc_read_ioh;
228 	bus_space_handle_t	sc_memh;
229 	u_int8_t		sc_ncards;
230     	u_int8_t		sc_id[ISAPNP_MAX_CARDS][ISAPNP_SERIAL_SIZE];
231 };
232 
233 struct isapnp_region {
234 	bus_space_handle_t h;
235 	u_int32_t base;
236 
237 	u_int32_t minbase;
238 	u_int32_t maxbase;
239 	u_int32_t length;
240 	u_int32_t align;
241 	u_int8_t  flags;
242 };
243 
244 struct isapnp_pin {
245 	int16_t	  num;
246 	u_int8_t  flags:4;
247 	u_int8_t  type:4;
248 	u_int16_t bits;
249 };
250 
251 struct isapnp_knowndev {
252 	const char pnpid[8];
253 	const char driver[5];
254 };
255 
256 /*
257  * ISA bus attach arguments
258  */
259 struct isabus_attach_args {
260 	char	*iba_busname;		/* XXX should be common */
261 	bus_space_tag_t iba_iot;	/* isa i/o space tag */
262 	bus_space_tag_t iba_memt;	/* isa mem space tag */
263 #if NISADMA > 0
264 	bus_dma_tag_t iba_dmat;		/* isa DMA tag */
265 #endif
266 	isa_chipset_tag_t iba_ic;
267 };
268 
269 /*
270  * ISA/ISA PnP shared driver attach arguments
271  */
272 struct isa_attach_args {
273 	struct device  *ia_isa;		/* isa device */
274 	bus_space_tag_t ia_iot;		/* isa i/o space tag */
275 	bus_space_tag_t ia_memt;	/* isa mem space tag */
276 #if NISADMA > 0
277 	bus_dma_tag_t ia_dmat;		/* DMA tag */
278 #endif
279 	bus_space_handle_t ia_delaybah;	/* i/o handle for `delay port' */
280 
281 	isa_chipset_tag_t ia_ic;
282 
283 	/*
284 	 * ISA PnP configuration support.  `ipa_' prefixes are used to denote
285 	 * PnP specific members of this structure.
286 	 */
287 	struct isa_attach_args	*ipa_sibling;
288 	struct isa_attach_args	*ipa_child;
289 
290 	char	ipa_devident[ISAPNP_MAX_IDENT];
291 	char	ipa_devlogic[ISAPNP_MAX_DEVCLASS];
292 	char	ipa_devcompat[ISAPNP_MAX_DEVCLASS];
293 	char	ipa_devclass[ISAPNP_MAX_DEVCLASS];
294 
295 	u_char	ipa_pref;
296 	u_char	ipa_devnum;
297 
298 	u_char	ipa_nio;
299 	u_char	ipa_nirq;
300 	u_char	ipa_ndrq;
301 	u_char	ipa_nmem;
302 	u_char	ipa_nmem32;
303 
304 	struct isapnp_region	ipa_io[ISAPNP_NUM_IO];
305 	struct isapnp_region	ipa_mem[ISAPNP_NUM_MEM];
306 	struct isapnp_region	ipa_mem32[ISAPNP_NUM_MEM32];
307 	struct isapnp_pin	ipa_irq[ISAPNP_NUM_IRQ];
308 	struct isapnp_pin	ipa_drq[ISAPNP_NUM_DRQ];
309 
310 	/*
311 	 * Compatibility defines for ISA drivers.
312 	 */
313 #define ia_iobase	ipa_io[0].base
314 #define ia_iosize	ipa_io[0].length
315 #define ia_ioh		ipa_io[0].h
316 #define ia_irq		ipa_irq[0].num
317 #define	ia_drq		ipa_drq[0].num
318 #define	ia_drq2		ipa_drq[1].num
319 #define ia_maddr	ipa_mem[0].base
320 #define ia_msize	ipa_mem[0].length
321 #define ia_memh		ipa_mem[0].h
322 
323 	void	*ia_aux;		/* driver specific */
324 };
325 
326 #define	IOBASEUNK	-1		/* i/o address is unknown */
327 #define	IRQUNK		-1		/* interrupt request line is unknown */
328 #define	DRQUNK		-1		/* DMA request line is unknown */
329 #define	MADDRUNK	-1		/* shared memory address is unknown */
330 
331 /*
332  * Per-device ISA variables
333  */
334 struct isadev {
335 	struct  device *id_dev;		/* back pointer to generic */
336 	TAILQ_ENTRY(isadev)
337 		id_bchain;		/* bus chain */
338 };
339 
340 /*
341  * ISA master bus
342  */
343 struct isa_softc {
344 	struct	device sc_dev;		/* base device */
345 	TAILQ_HEAD(, isadev)
346 		sc_subdevs;		/* list of all children */
347 
348 	bus_space_tag_t sc_iot;		/* isa io space tag */
349 	bus_space_tag_t sc_memt;	/* isa mem space tag */
350 #if NISADMA > 0
351 	bus_dma_tag_t sc_dmat;		/* isa DMA tag */
352 #endif /* NISADMA > 0 */
353 
354 	isa_chipset_tag_t sc_ic;
355 
356 #if NISADMA > 0
357 	/*
358 	 * Bitmap representing the DRQ channels available
359 	 * for ISA.
360 	 */
361 	int	sc_drqmap;
362 #define sc_drq	sc_drqmap		/* XXX compatibility mode */
363 
364 	bus_space_handle_t sc_dma1h;	/* i/o handle for DMA controller #1 */
365 	bus_space_handle_t sc_dma2h;	/* i/o handle for DMA controller #2 */
366 	bus_space_handle_t sc_dmapgh;	/* i/o handle for DMA page registers */
367 
368 	/*
369 	 * DMA maps used for the 8 DMA channels.
370 	 */
371 	bus_dmamap_t	sc_dmamaps[8];
372 	bus_size_t 	sc_dmalength[8];
373 
374 	int	sc_dmareads;		/* state for isa_dmadone() */
375 	int	sc_dmafinished;		/* DMA completion state */
376 #endif /* NISADMA > 0 */
377 
378 	/*
379 	 * This i/o handle is used to map port 0x84, which is
380 	 * read to provide a 1.25us delay.  This access handle
381 	 * is mapped in isaattach(), and exported to drivers
382 	 * via isa_attach_args.
383 	 */
384 	bus_space_handle_t   sc_delaybah;
385 };
386 
387 #define	ISA_DRQ_ISFREE(isadev, drq) \
388 	((((struct isa_softc *)(isadev))->sc_drqmap & (1 << (drq))) == 0)
389 
390 #define	ISA_DRQ_ALLOC(isadev, drq) \
391 	((struct isa_softc *)(isadev))->sc_drqmap |= (1 << (drq))
392 
393 #define	ISA_DRQ_FREE(isadev, drq) \
394 	((struct isa_softc *)(isadev))->sc_drqmap &= ~(1 << (drq))
395 
396 #define		cf_iobase		cf_loc[0]
397 #define		cf_iosize		cf_loc[1]
398 #define		cf_maddr		cf_loc[2]
399 #define		cf_msize		cf_loc[3]
400 #define		cf_irq			cf_loc[4]
401 #define		cf_drq			cf_loc[5]
402 #define		cf_drq2			cf_loc[6]
403 
404 /*
405  * ISA interrupt handler manipulation.
406  *
407  * To establish an ISA interrupt handler, a driver calls isa_intr_establish()
408  * with the interrupt number, type, level, function, and function argument of
409  * the interrupt it wants to handle.  Isa_intr_establish() returns an opaque
410  * handle to an event descriptor if it succeeds, and invokes panic() if it
411  * fails.  (XXX It should return NULL, then drivers should handle that, but
412  * what should they do?)  Interrupt handlers should return 0 for "interrupt
413  * not for me", 1  for "I took care of it", or -1 for "I guess it was mine,
414  * but I wasn't expecting it."
415  *
416  * To remove an interrupt handler, the driver calls isa_intr_disestablish()
417  * with the handle returned by isa_intr_establish() for that handler.
418  */
419 
420 /* ISA interrupt sharing types */
421 char	*isa_intr_typename(int type);
422 
423 void	isascan(struct device *parent, void *match);
424 int	isaprint(void *, const char *);
425 
426 /*
427  * Some ISA devices (e.g. on a VLB) can perform 32-bit DMA.  This
428  * flag is passed to bus_dmamap_create() to indicate that fact.
429  */
430 #define	ISABUS_DMA_32BIT	BUS_DMA_BUS1
431 
432 /*
433  * ISA PnP prototypes and support macros.
434  */
435 static __inline void isapnp_write_reg(struct isapnp_softc *, int, u_char);
436 static __inline u_char isapnp_read_reg(struct isapnp_softc *, int);
437 
438 static __inline void
isapnp_write_reg(sc,r,v)439 isapnp_write_reg(sc, r, v)
440 	struct isapnp_softc *sc;
441 	int r;
442 	u_char v;
443 {
444 	ISAPNP_WRITE_ADDR(sc, r);
445 	ISAPNP_WRITE_DATA(sc, v);
446 }
447 
448 static __inline u_char
isapnp_read_reg(sc,r)449 isapnp_read_reg(sc, r)
450 	struct isapnp_softc *sc;
451 	int r;
452 {
453 	ISAPNP_WRITE_ADDR(sc, r);
454 	return ISAPNP_READ_DATA(sc);
455 }
456 
457 struct isa_attach_args *
458     isapnp_get_resource(struct isapnp_softc *, int, struct isa_attach_args *);
459 char *isapnp_id_to_vendor(char *, const u_char *);
460 
461 int isapnp_config(bus_space_tag_t, bus_space_tag_t,
462     struct isa_attach_args *);
463 void isapnp_unconfig(bus_space_tag_t, bus_space_tag_t,
464     struct isa_attach_args *);
465 
466 void isapnp_isa_attach_hook(struct isa_softc *);
467 #ifdef DEBUG_ISAPNP
468 void isapnp_print_mem(const char *, const struct isapnp_region *);
469 void isapnp_print_io(const char *, const struct isapnp_region *);
470 void isapnp_print_irq(const char *, const struct isapnp_pin *);
471 void isapnp_print_drq(const char *, const struct isapnp_pin *);
472 void isapnp_print_dep_start(const char *, const u_char);
473 void isapnp_print_attach(const struct isa_attach_args *);
474 void isapnp_get_config(struct isapnp_softc *,
475 	struct isa_attach_args *);
476 void isapnp_print_config(const struct isa_attach_args *);
477 #endif	/* DEBUG_ISAPNP */
478 #endif /* _DEV_ISA_ISAVAR_H_ */
479