1 /*	$NetBSD: isavar.h,v 1.53 2009/05/12 09:10:15 cegger Exp $	*/
2 
3 /*-
4  * Copyright (c) 1997, 2001 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of Wasabi Systems, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Copyright (c) 1995 Chris G. Demetriou
34  * Copyright (c) 1992 Berkeley Software Design, Inc.
35  * 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 Berkeley Software
48  *	Design, Inc.
49  * 4. The name of Berkeley Software Design must not be used to endorse
50  *    or promote products derived from this software without specific
51  *    prior written permission.
52  *
53  * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``AS IS'' AND
54  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56  * ARE DISCLAIMED.  IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN, INC. BE LIABLE
57  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63  * SUCH DAMAGE.
64  *
65  *	BSDI Id: isavar.h,v 1.5 1992/12/01 18:06:00 karels Exp
66  */
67 
68 #ifndef _DEV_ISA_ISAVAR_H_
69 #define	_DEV_ISA_ISAVAR_H_
70 
71 /*
72  * Definitions for ISA autoconfiguration.
73  */
74 
75 #include <sys/queue.h>
76 #include <sys/bus.h>
77 
78 /*
79  * Structures and definitions needed by the machine-dependent header.
80  */
81 struct isabus_attach_args;
82 
83 #include <machine/isa_machdep.h>
84 
85 /*
86  * ISA bus attach arguments
87  */
88 struct isabus_attach_args {
89 	const char *_iba_busname;		/* XXX placeholder */
90 	bus_space_tag_t iba_iot;	/* isa i/o space tag */
91 	bus_space_tag_t iba_memt;	/* isa mem space tag */
92 	bus_dma_tag_t iba_dmat;		/* isa DMA tag */
93 	isa_chipset_tag_t iba_ic;
94 };
95 
96 /*
97  * ISA bus resources.
98  */
99 
100 struct isa_io {
101 	int ir_addr;
102 	int ir_size;
103 };
104 
105 struct isa_iomem {
106 	int ir_addr;
107 	int ir_size;
108 };
109 
110 struct isa_irq {
111 	int ir_irq;
112 };
113 
114 struct isa_drq {
115 	int ir_drq;
116 };
117 
118 struct isa_pnpname {
119 	struct isa_pnpname *ipn_next;
120 	char *ipn_name;
121 };
122 
123 /*
124  * Machine-dependent code provides a list of these to describe
125  * devices on the ISA bus which should be attached via direct
126  * configuration.
127  *
128  * All of this information is dynamically allocated, so that
129  * the ISA bus driver may free all of this information if the
130  * bus does not support dynamic attach/detach of devices (e.g.
131  * on a docking station).
132  *
133  * Some info on the "ik_key" field: This is a unique number for
134  * each knowndev node.  If, when we need to re-enumerate the
135  * knowndevs, we discover that a node with key N is in the old
136  * list but not in the new, the device has disappeared.  Similarly,
137  * if a node with key M is in the new list but not in the old,
138  * the device is new.  Note that the knowndevs list must be
139  * sorted in ascending "key" order.
140  */
141 struct isa_knowndev {
142 	TAILQ_ENTRY(isa_knowndev) ik_list;
143 	uintptr_t ik_key;
144 	device_t ik_claimed;
145 
146 	/*
147 	 * The rest of these fields correspond to isa_attach_args
148 	 * fields.
149 	 */
150 	char *ik_pnpname;
151 	struct isa_pnpname *ik_pnpcompatnames;
152 
153 	struct isa_io *ik_io;
154 	int ik_nio;
155 
156 	struct isa_iomem *ik_iomem;
157 	int ik_niomem;
158 
159 	struct isa_irq *ik_irq;
160 	int ik_nirq;
161 
162 	struct isa_drq *ik_drq;
163 	int ik_ndrq;
164 };
165 
166 /*
167  * ISA driver attach arguments
168  */
169 struct isa_attach_args {
170 	bus_space_tag_t ia_iot;		/* isa i/o space tag */
171 	bus_space_tag_t ia_memt;	/* isa mem space tag */
172 	bus_dma_tag_t ia_dmat;		/* DMA tag */
173 
174 	isa_chipset_tag_t ia_ic;
175 
176 	/*
177 	 * PNP (or other) names to with which we can match a device
178 	 * driver to a device that machine-dependent code tells us
179 	 * is there (i.e. support for direct-configuration of ISA
180 	 * devices).
181 	 */
182 	char *ia_pnpname;
183 	struct isa_pnpname *ia_pnpcompatnames;
184 
185 	struct isa_io *ia_io;		/* I/O resources */
186 	int ia_nio;
187 
188 	struct isa_iomem *ia_iomem;	/* memory resources */
189 	int ia_niomem;
190 
191 	struct isa_irq *ia_irq;		/* IRQ resources */
192 	int ia_nirq;
193 
194 	struct isa_drq *ia_drq;		/* DRQ resources */
195 	int ia_ndrq;
196 
197 	void	*ia_aux;		/* driver specific */
198 };
199 
200 /*
201  * Test to determine if a given call to an ISA device probe routine
202  * is actually an attempt to do direct configuration.
203  */
204 #define	ISA_DIRECT_CONFIG(ia)						\
205 	((ia)->ia_pnpname != NULL || (ia)->ia_pnpcompatnames != NULL)
206 
207 /*
208  * ISA master bus
209  */
210 struct isa_softc {
211 	device_t sc_dev;		/* base device */
212 
213 	bus_space_tag_t sc_iot;		/* isa io space tag */
214 	bus_space_tag_t sc_memt;	/* isa mem space tag */
215 	bus_dma_tag_t sc_dmat;		/* isa DMA tag */
216 
217 	isa_chipset_tag_t sc_ic;
218 
219 	TAILQ_HEAD(, isa_knowndev) sc_knowndevs;
220 	int sc_dynamicdevs;
221 };
222 
223 /*
224  * These must be in sync with the ISACF_XXX_DEFAULT definitions
225  * in "locators.h" (generated from files.isa).
226  * (not including "locators.h" here to avoid dependency)
227  */
228 #define ISA_UNKNOWN_PORT	(-1)
229 #define ISA_UNKNOWN_IOMEM	(-1)
230 #define ISA_UNKNOWN_IOSIZ	(0)
231 #define ISA_UNKNOWN_IRQ		(-1)
232 #define ISA_UNKNOWN_DRQ		(-1)
233 #define ISA_UNKNOWN_DRQ2	(-1)
234 
235 int	isabusprint(void *, const char *);
236 
237 /*
238  * ISA interrupt handler manipulation.
239  *
240  * To establish an ISA interrupt handler, a driver calls isa_intr_establish()
241  * with the interrupt number, type, level, function, and function argument of
242  * the interrupt it wants to handle.  Isa_intr_establish() returns an opaque
243  * handle to an event descriptor if it succeeds, and returns NULL on failure.
244  * (XXX: some drivers can't handle this, since the former behaviour was to
245  * invoke panic() on failure). When the system does not accept any of the
246  * interrupt types supported by the driver, the driver should fail the attach.
247  * Interrupt handlers should return 0 for "interrupt not for me", 1  for
248  * "I took care of it", or -1 for "I guess it was mine, but I wasn't
249  * expecting it."
250  *
251  * To remove an interrupt handler, the driver calls isa_intr_disestablish()
252  * with the handle returned by isa_intr_establish() for that handler.
253  *
254  * The event counter (struct evcnt) associated with an interrupt line
255  * (to be used as 'parent' for an ISA device's interrupt handler's evcnt)
256  * can be obtained with isa_intr_evcnt().
257  */
258 
259 /* ISA interrupt sharing types */
260 const char	*isa_intr_typename(int);
261 
262 /*
263  * Some ISA devices (e.g. on a VLB) can perform 32-bit DMA.  This
264  * flag is passed to bus_dmamap_create() to indicate that fact.
265  */
266 #define	ISABUS_DMA_32BIT	BUS_DMA_BUS1
267 
268 /*
269  * This flag indicates that the DMA channel should not yet be reserved,
270  * even if BUS_DMA_ALLOCNOW is specified.
271  */
272 #define ISABUS_DMA_DEFERCHAN	BUS_DMA_BUS2
273 
274 void	isa_set_slotcount(int);
275 int	isa_get_slotcount(void);
276 
277 #endif /* _DEV_ISA_ISAVAR_H_ */
278