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