isa.c revision 1.110.6.1 1 1.110.6.1 eeh /* $NetBSD: isa.c,v 1.110.6.1 2002/04/06 16:12:08 eeh Exp $ */
2 1.58 cgd
3 1.1 cgd /*-
4 1.110 thorpej * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
5 1.105 mycroft * All rights reserved.
6 1.105 mycroft *
7 1.105 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.110 thorpej * by Charles M. Hannum; by Jason R. Thorpe of Wasabi Systems, Inc.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.1 cgd * 3. All advertising materials mentioning features or use of this software
19 1.1 cgd * must display the following acknowledgement:
20 1.105 mycroft * This product includes software developed by the NetBSD
21 1.105 mycroft * Foundation, Inc. and its contributors.
22 1.105 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.105 mycroft * contributors may be used to endorse or promote products derived
24 1.105 mycroft * from this software without specific prior written permission.
25 1.1 cgd *
26 1.105 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.105 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.105 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.105 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.105 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.105 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.105 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.105 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.105 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.105 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.105 mycroft * POSSIBILITY OF SUCH DAMAGE.
37 1.1 cgd */
38 1.109 lukem
39 1.109 lukem #include <sys/cdefs.h>
40 1.110.6.1 eeh __KERNEL_RCSID(0, "$NetBSD: isa.c,v 1.110.6.1 2002/04/06 16:12:08 eeh Exp $");
41 1.1 cgd
42 1.31 mycroft #include <sys/param.h>
43 1.31 mycroft #include <sys/systm.h>
44 1.40 mycroft #include <sys/kernel.h>
45 1.31 mycroft #include <sys/malloc.h>
46 1.46 mycroft #include <sys/device.h>
47 1.110.6.1 eeh #include <sys/properties.h>
48 1.85 thorpej
49 1.85 thorpej #include <machine/intr.h>
50 1.31 mycroft
51 1.72 cgd #include <dev/isa/isareg.h>
52 1.72 cgd #include <dev/isa/isavar.h>
53 1.95 thorpej #include <dev/isa/isadmareg.h>
54 1.77 cgd
55 1.102 leo #include "isadma.h"
56 1.102 leo
57 1.103 christos #include "isapnp.h"
58 1.108 fvdl #if NISAPNP > 0
59 1.103 christos #include <dev/isapnp/isapnpreg.h>
60 1.103 christos #include <dev/isapnp/isapnpvar.h>
61 1.103 christos #endif
62 1.103 christos
63 1.110 thorpej int isamatch(struct device *, struct cfdata *, void *);
64 1.110 thorpej void isaattach(struct device *, struct device *, void *);
65 1.110 thorpej int isaprint(void *, const char *);
66 1.77 cgd
67 1.79 thorpej struct cfattach isa_ca = {
68 1.79 thorpej sizeof(struct isa_softc), isamatch, isaattach
69 1.79 thorpej };
70 1.79 thorpej
71 1.110 thorpej void isa_attach_knowndevs(struct isa_softc *);
72 1.110 thorpej void isa_free_knowndevs(struct isa_softc *);
73 1.110 thorpej
74 1.110 thorpej int isasubmatch(struct device *, struct cfdata *, void *);
75 1.110 thorpej int isasearch(struct device *, struct cfdata *, void *);
76 1.91 cgd
77 1.77 cgd int
78 1.110 thorpej isamatch(struct device *parent, struct cfdata *cf, void *aux)
79 1.77 cgd {
80 1.77 cgd struct isabus_attach_args *iba = aux;
81 1.77 cgd
82 1.77 cgd if (strcmp(iba->iba_busname, cf->cf_driver->cd_name))
83 1.77 cgd return (0);
84 1.77 cgd
85 1.77 cgd /* XXX check other indicators */
86 1.77 cgd
87 1.77 cgd return (1);
88 1.77 cgd }
89 1.77 cgd
90 1.77 cgd void
91 1.110 thorpej isaattach(struct device *parent, struct device *self, void *aux)
92 1.77 cgd {
93 1.110.6.1 eeh struct isa_softc *sc = (struct isa_softc *)DEV_PRIVATE(self);
94 1.77 cgd struct isabus_attach_args *iba = aux;
95 1.98 thorpej
96 1.110.6.1 eeh sc->sc_devp = self;
97 1.110.6.1 eeh
98 1.110 thorpej TAILQ_INIT(&sc->sc_knowndevs);
99 1.110 thorpej sc->sc_dynamicdevs = 0;
100 1.110 thorpej
101 1.80 cgd isa_attach_hook(parent, self, iba);
102 1.88 christos printf("\n");
103 1.77 cgd
104 1.110 thorpej /* XXX Add code to fetch known-devices. */
105 1.110 thorpej
106 1.89 thorpej sc->sc_iot = iba->iba_iot;
107 1.110.6.1 eeh dev_setprop(self, "io-tag", &sc->sc_iot, sizeof(sc->sc_iot),
108 1.110.6.1 eeh PROP_INT, 0);
109 1.89 thorpej sc->sc_memt = iba->iba_memt;
110 1.110.6.1 eeh dev_setprop(self, "mem-tag", &sc->sc_memt, sizeof(sc->sc_memt),
111 1.110.6.1 eeh PROP_INT, 0);
112 1.95 thorpej sc->sc_dmat = iba->iba_dmat;
113 1.110.6.1 eeh dev_setprop(self, "dma-tag", &sc->sc_dmat, sizeof(sc->sc_dmat),
114 1.110.6.1 eeh PROP_INT, 0);
115 1.80 cgd sc->sc_ic = iba->iba_ic;
116 1.110.6.1 eeh dev_setprop(self, "chipset-tag", &sc->sc_ic, sizeof(sc->sc_ic),
117 1.110.6.1 eeh PROP_INT, 0);
118 1.103 christos
119 1.103 christos #if NISAPNP > 0
120 1.103 christos /*
121 1.103 christos * Reset isapnp cards that the bios configured for us
122 1.103 christos */
123 1.103 christos isapnp_isa_attach_hook(sc);
124 1.103 christos #endif
125 1.78 cgd
126 1.102 leo #if NISADMA > 0
127 1.82 thorpej /*
128 1.101 thorpej * Initialize our DMA state.
129 1.95 thorpej */
130 1.101 thorpej isa_dmainit(sc->sc_ic, sc->sc_iot, sc->sc_dmat, self);
131 1.102 leo #endif
132 1.100 drochner
133 1.110 thorpej /* Attach all direct-config children. */
134 1.110 thorpej isa_attach_knowndevs(sc);
135 1.110 thorpej
136 1.110 thorpej /*
137 1.110 thorpej * If we don't support dynamic hello/goodbye of devices,
138 1.110 thorpej * then free the knowndevs info now.
139 1.110 thorpej */
140 1.110 thorpej if (sc->sc_dynamicdevs == 0)
141 1.110 thorpej isa_free_knowndevs(sc);
142 1.110 thorpej
143 1.110 thorpej /* Attach all indrect-config children. */
144 1.91 cgd config_search(isasearch, self, NULL);
145 1.77 cgd }
146 1.1 cgd
147 1.110 thorpej void
148 1.110 thorpej isa_attach_knowndevs(struct isa_softc *sc)
149 1.110 thorpej {
150 1.110 thorpej struct isa_attach_args ia;
151 1.110 thorpej struct isa_knowndev *ik;
152 1.110.6.1 eeh struct device *child;
153 1.110 thorpej
154 1.110 thorpej if (TAILQ_EMPTY(&sc->sc_knowndevs))
155 1.110 thorpej return;
156 1.110 thorpej
157 1.110 thorpej TAILQ_FOREACH(ik, &sc->sc_knowndevs, ik_list) {
158 1.110 thorpej if (ik->ik_claimed != NULL)
159 1.110 thorpej continue;
160 1.110 thorpej
161 1.110.6.1 eeh if ((child = dev_config_create(sc->sc_devp, 0)) == NULL)
162 1.110.6.1 eeh panic("isa_attach_knowndevs: cannot allocate dev");
163 1.110.6.1 eeh
164 1.110 thorpej ia.ia_iot = sc->sc_iot;
165 1.110 thorpej ia.ia_memt = sc->sc_memt;
166 1.110 thorpej ia.ia_dmat = sc->sc_dmat;
167 1.110 thorpej ia.ia_ic = sc->sc_ic;
168 1.110 thorpej
169 1.110 thorpej ia.ia_pnpname = ik->ik_pnpname;
170 1.110.6.1 eeh if (ik->ik_pnpname) {
171 1.110.6.1 eeh dev_setprop(child, "PNP-name", ik->ik_pnpname,
172 1.110.6.1 eeh strlen(ik->ik_pnpname), PROP_STRING, 0);
173 1.110.6.1 eeh }
174 1.110 thorpej ia.ia_pnpcompatnames = ik->ik_pnpcompatnames;
175 1.110.6.1 eeh if (ik->ik_pnpcompatnames) {
176 1.110.6.1 eeh struct isa_pnpname *ipn;
177 1.110.6.1 eeh char buf[256];
178 1.110.6.1 eeh int i = 0;
179 1.110.6.1 eeh
180 1.110.6.1 eeh /*
181 1.110.6.1 eeh * Yeech. We need to concatenate all these
182 1.110.6.1 eeh * annoying strings into one big one and then
183 1.110.6.1 eeh * create a property with it. Good thing nothing
184 1.110.6.1 eeh * currently uses this feature. Hope 255 bytes is
185 1.110.6.1 eeh * enough.
186 1.110.6.1 eeh */
187 1.110.6.1 eeh
188 1.110.6.1 eeh for (ipn = ik->ik_pnpcompatnames; ipn != NULL;
189 1.110.6.1 eeh ipn = ipn->ipn_next) {
190 1.110.6.1 eeh strcpy(&buf[i], ipn->ipn_name);
191 1.110.6.1 eeh i += strlen(ipn->ipn_name);
192 1.110.6.1 eeh buf[i++] = 0;
193 1.110.6.1 eeh if (i > 256)
194 1.110.6.1 eeh panic("isa_attach_knowndevs: compat");
195 1.110.6.1 eeh }
196 1.110.6.1 eeh dev_setprop(child, "PNP-compat", buf, i, PROP_STRING,
197 1.110.6.1 eeh 0);
198 1.110.6.1 eeh }
199 1.110 thorpej
200 1.110 thorpej ia.ia_io = ik->ik_io;
201 1.110 thorpej ia.ia_nio = ik->ik_nio;
202 1.110.6.1 eeh if (ik->ik_nio) {
203 1.110.6.1 eeh if (ik->ik_io[0].ir_addr != ISACF_PORT_DEFAULT) {
204 1.110.6.1 eeh dev_setprop(child, "port",
205 1.110.6.1 eeh &ik->ik_io[0].ir_addr, sizeof(int),
206 1.110.6.1 eeh PROP_INT, 0);
207 1.110.6.1 eeh }
208 1.110.6.1 eeh if (ik->ik_io[0].ir_size != ISACF_SIZE_DEFAULT) {
209 1.110.6.1 eeh dev_setprop(child, "size",
210 1.110.6.1 eeh &ik->ik_io[0].ir_size, sizeof(int),
211 1.110.6.1 eeh PROP_INT, 0);
212 1.110.6.1 eeh }
213 1.110.6.1 eeh }
214 1.110 thorpej
215 1.110 thorpej ia.ia_iomem = ik->ik_iomem;
216 1.110 thorpej ia.ia_niomem = ik->ik_niomem;
217 1.110.6.1 eeh if (ik->ik_niomem) {
218 1.110.6.1 eeh if (ik->ik_iomem[0].ir_addr != ISACF_IOMEM_DEFAULT) {
219 1.110.6.1 eeh dev_setprop(child, "iomem",
220 1.110.6.1 eeh &ik->ik_iomem[0].ir_addr, sizeof(int),
221 1.110.6.1 eeh PROP_INT, 0);
222 1.110.6.1 eeh }
223 1.110.6.1 eeh if (ik->ik_iomem[0].ir_size != ISACF_IOSIZ_DEFAULT) {
224 1.110.6.1 eeh dev_setprop(child, "iosiz",
225 1.110.6.1 eeh &ik->ik_iomem[0].ir_size, sizeof(int),
226 1.110.6.1 eeh PROP_INT, 0);
227 1.110.6.1 eeh }
228 1.110.6.1 eeh }
229 1.110 thorpej
230 1.110 thorpej ia.ia_irq = ik->ik_irq;
231 1.110 thorpej ia.ia_nirq = ik->ik_nirq;
232 1.110.6.1 eeh if (ik->ik_nirq) {
233 1.110.6.1 eeh if (ik->ik_irq[0].ir_irq != ISACF_IRQ_DEFAULT) {
234 1.110.6.1 eeh dev_setprop(child, "irq",
235 1.110.6.1 eeh &ik->ik_irq[0].ir_irq, sizeof(int),
236 1.110.6.1 eeh PROP_INT, 0);
237 1.110.6.1 eeh }
238 1.110.6.1 eeh }
239 1.110 thorpej
240 1.110 thorpej ia.ia_drq = ik->ik_drq;
241 1.110 thorpej ia.ia_ndrq = ik->ik_ndrq;
242 1.110.6.1 eeh if (ik->ik_ndrq > 0 &&
243 1.110.6.1 eeh ik->ik_drq[0].ir_drq != ISACF_DRQ_DEFAULT) {
244 1.110.6.1 eeh dev_setprop(child, "drq",
245 1.110.6.1 eeh &ik->ik_drq[0].ir_drq, sizeof(int),
246 1.110.6.1 eeh PROP_INT, 0);
247 1.110.6.1 eeh }
248 1.110.6.1 eeh if (ik->ik_ndrq > 1 &&
249 1.110.6.1 eeh ik->ik_drq[1].ir_drq != ISACF_DRQ2_DEFAULT) {
250 1.110.6.1 eeh dev_setprop(child, "drq2",
251 1.110.6.1 eeh &ik->ik_drq[1].ir_drq, sizeof(int),
252 1.110.6.1 eeh PROP_INT, 0);
253 1.110.6.1 eeh }
254 1.110 thorpej
255 1.110 thorpej ia.ia_aux = NULL;
256 1.110 thorpej
257 1.110.6.1 eeh ik->ik_claimed = config_found_sad(sc->sc_devp, &ia,
258 1.110.6.1 eeh isaprint, isasubmatch, child);
259 1.110 thorpej }
260 1.110 thorpej }
261 1.110 thorpej
262 1.110 thorpej void
263 1.110 thorpej isa_free_knowndevs(struct isa_softc *sc)
264 1.110 thorpej {
265 1.110 thorpej struct isa_knowndev *ik;
266 1.110 thorpej struct isa_pnpname *ipn;
267 1.110 thorpej
268 1.110 thorpej #define FREEIT(x) if (x != NULL) free(x, M_DEVBUF)
269 1.110 thorpej
270 1.110 thorpej while ((ik = TAILQ_FIRST(&sc->sc_knowndevs)) != NULL) {
271 1.110 thorpej TAILQ_REMOVE(&sc->sc_knowndevs, ik, ik_list);
272 1.110 thorpej FREEIT(ik->ik_pnpname);
273 1.110 thorpej while ((ipn = ik->ik_pnpcompatnames) != NULL) {
274 1.110 thorpej ik->ik_pnpcompatnames = ipn->ipn_next;
275 1.110 thorpej free(ipn->ipn_name, M_DEVBUF);
276 1.110 thorpej free(ipn, M_DEVBUF);
277 1.110 thorpej }
278 1.110 thorpej FREEIT(ik->ik_io);
279 1.110 thorpej FREEIT(ik->ik_iomem);
280 1.110 thorpej FREEIT(ik->ik_irq);
281 1.110 thorpej FREEIT(ik->ik_drq);
282 1.110 thorpej free(ik, M_DEVBUF);
283 1.110 thorpej }
284 1.110 thorpej
285 1.110 thorpej #undef FREEIT
286 1.110 thorpej }
287 1.110 thorpej
288 1.110 thorpej int
289 1.110 thorpej isasubmatch(struct device *parent, struct cfdata *cf, void *aux)
290 1.110 thorpej {
291 1.110 thorpej struct isa_attach_args *ia = aux;
292 1.110 thorpej int i;
293 1.110 thorpej
294 1.110 thorpej if (ia->ia_nio == 0) {
295 1.110 thorpej if (cf->cf_iobase != ISACF_PORT_DEFAULT)
296 1.110 thorpej return (0);
297 1.110 thorpej } else {
298 1.110 thorpej if (cf->cf_iobase != ISACF_PORT_DEFAULT &&
299 1.110 thorpej cf->cf_iobase != ia->ia_io[0].ir_addr)
300 1.110 thorpej return (0);
301 1.110 thorpej }
302 1.110 thorpej
303 1.110 thorpej if (ia->ia_niomem == 0) {
304 1.110 thorpej if (cf->cf_maddr != ISACF_IOMEM_DEFAULT)
305 1.110 thorpej return (0);
306 1.110 thorpej } else {
307 1.110 thorpej if (cf->cf_maddr != ISACF_IOMEM_DEFAULT &&
308 1.110 thorpej cf->cf_maddr != ia->ia_iomem[0].ir_addr)
309 1.110 thorpej return (0);
310 1.110 thorpej }
311 1.110 thorpej
312 1.110 thorpej if (ia->ia_nirq == 0) {
313 1.110 thorpej if (cf->cf_irq != ISACF_IRQ_DEFAULT)
314 1.110 thorpej return (0);
315 1.110 thorpej } else {
316 1.110 thorpej if (cf->cf_irq != ISACF_IRQ_DEFAULT &&
317 1.110 thorpej cf->cf_irq != ia->ia_irq[0].ir_irq)
318 1.110 thorpej return (0);
319 1.110 thorpej }
320 1.110 thorpej
321 1.110 thorpej if (ia->ia_ndrq == 0) {
322 1.110 thorpej if (cf->cf_drq != ISACF_DRQ_DEFAULT)
323 1.110 thorpej return (0);
324 1.110 thorpej if (cf->cf_drq2 != ISACF_DRQ_DEFAULT)
325 1.110 thorpej return (0);
326 1.110 thorpej } else {
327 1.110 thorpej for (i = 0; i < 2; i++) {
328 1.110 thorpej if (i == ia->ia_ndrq)
329 1.110 thorpej break;
330 1.110 thorpej if (cf->cf_loc[ISACF_DRQ + i] != ISACF_DRQ_DEFAULT &&
331 1.110 thorpej cf->cf_loc[ISACF_DRQ + i] != ia->ia_drq[i].ir_drq)
332 1.110 thorpej return (0);
333 1.110 thorpej }
334 1.110 thorpej for (; i < 2; i++) {
335 1.110 thorpej if (cf->cf_loc[ISACF_DRQ + i] != ISACF_DRQ_DEFAULT)
336 1.110 thorpej return (0);
337 1.110 thorpej }
338 1.110 thorpej }
339 1.110 thorpej
340 1.110 thorpej return ((*cf->cf_attach->ca_match)(parent, cf, aux));
341 1.110 thorpej }
342 1.110 thorpej
343 1.46 mycroft int
344 1.110 thorpej isaprint(void *aux, const char *isa)
345 1.46 mycroft {
346 1.46 mycroft struct isa_attach_args *ia = aux;
347 1.110 thorpej const char *sep;
348 1.110 thorpej int i;
349 1.110 thorpej
350 1.110 thorpej /*
351 1.110 thorpej * This block of code only fires if we have a direct-config'd
352 1.110 thorpej * device for which there is no driver match.
353 1.110 thorpej */
354 1.110 thorpej if (isa != NULL) {
355 1.110 thorpej struct isa_pnpname *ipn;
356 1.110 thorpej
357 1.110 thorpej if (ia->ia_pnpname != NULL)
358 1.110 thorpej printf("%s", ia->ia_pnpname);
359 1.110 thorpej if ((ipn = ia->ia_pnpcompatnames) != NULL) {
360 1.110 thorpej printf(" ("); /* ) */
361 1.110 thorpej for (sep = ""; ipn != NULL;
362 1.110 thorpej ipn = ipn->ipn_next, sep = " ") {
363 1.110 thorpej printf("%s%s", sep, ipn->ipn_name);
364 1.110 thorpej }
365 1.110 thorpej /* ( */ printf(")");
366 1.110 thorpej }
367 1.110 thorpej printf(" at %s", isa);
368 1.110 thorpej }
369 1.110 thorpej
370 1.110 thorpej if (ia->ia_nio) {
371 1.110 thorpej sep = "";
372 1.110 thorpej printf(" port ");
373 1.110 thorpej for (i = 0; i < ia->ia_nio; i++) {
374 1.110 thorpej if (ia->ia_io[i].ir_size == 0)
375 1.110 thorpej continue;
376 1.110 thorpej printf("%s0x%x", sep, ia->ia_io[i].ir_addr);
377 1.110 thorpej if (ia->ia_io[i].ir_size > 1)
378 1.110 thorpej printf("-0x%x", ia->ia_io[i].ir_addr +
379 1.110 thorpej ia->ia_io[i].ir_size - 1);
380 1.110 thorpej sep = ",";
381 1.110 thorpej }
382 1.110 thorpej }
383 1.110 thorpej
384 1.110 thorpej if (ia->ia_niomem) {
385 1.110 thorpej sep = "";
386 1.110 thorpej printf(" iomem ");
387 1.110 thorpej for (i = 0; i < ia->ia_niomem; i++) {
388 1.110 thorpej if (ia->ia_iomem[i].ir_size == 0)
389 1.110 thorpej continue;
390 1.110 thorpej printf("%s0x%x", sep, ia->ia_iomem[i].ir_addr);
391 1.110 thorpej if (ia->ia_iomem[i].ir_size > 1)
392 1.110 thorpej printf("-0x%x", ia->ia_iomem[i].ir_addr +
393 1.110 thorpej ia->ia_iomem[i].ir_size - 1);
394 1.110 thorpej sep = ",";
395 1.110 thorpej }
396 1.110 thorpej }
397 1.110 thorpej
398 1.110 thorpej if (ia->ia_nirq) {
399 1.110 thorpej sep = "";
400 1.110 thorpej printf(" irq ");
401 1.110 thorpej for (i = 0; i < ia->ia_nirq; i++) {
402 1.110 thorpej if (ia->ia_irq[i].ir_irq == ISACF_IRQ_DEFAULT)
403 1.110 thorpej continue;
404 1.110 thorpej printf("%s%d", sep, ia->ia_irq[i].ir_irq);
405 1.110 thorpej sep = ",";
406 1.110 thorpej }
407 1.110 thorpej }
408 1.110 thorpej
409 1.110 thorpej if (ia->ia_ndrq) {
410 1.110 thorpej sep = "";
411 1.110 thorpej printf(" drq ");
412 1.110 thorpej for (i = 0; i < ia->ia_ndrq; i++) {
413 1.110 thorpej if (ia->ia_drq[i].ir_drq == ISACF_DRQ_DEFAULT)
414 1.110 thorpej continue;
415 1.110 thorpej printf("%s%d", sep, ia->ia_drq[i].ir_drq);
416 1.110 thorpej sep = ",";
417 1.110 thorpej }
418 1.110 thorpej }
419 1.46 mycroft
420 1.71 mycroft return (UNCONF);
421 1.46 mycroft }
422 1.46 mycroft
423 1.94 cgd int
424 1.110 thorpej isasearch(struct device *parent, struct cfdata *cf, void *aux)
425 1.94 cgd {
426 1.110.6.1 eeh struct device *child;
427 1.110 thorpej struct isa_io res_io[1];
428 1.110 thorpej struct isa_iomem res_mem[1];
429 1.110 thorpej struct isa_irq res_irq[1];
430 1.110 thorpej struct isa_drq res_drq[2];
431 1.110.6.1 eeh struct isa_softc *sc = (struct isa_softc *)DEV_PRIVATE(parent);
432 1.94 cgd struct isa_attach_args ia;
433 1.110.6.1 eeh int tryagain = 1;
434 1.94 cgd
435 1.110.6.1 eeh while (tryagain && (child = dev_config_create(parent, 0))) {
436 1.110 thorpej ia.ia_pnpname = NULL;
437 1.110 thorpej ia.ia_pnpcompatnames = NULL;
438 1.110 thorpej
439 1.110.6.1 eeh dev_setprop(child, "cd-name", cf->cf_driver->cd_name,
440 1.110.6.1 eeh strlen(cf->cf_driver->cd_name) + 1, PROP_STRING, 0);
441 1.110.6.1 eeh
442 1.110.6.1 eeh /*
443 1.110.6.1 eeh * ISA uses a slightly different property protocol for
444 1.110.6.1 eeh * locators. Instead of instantiating "loc-foo" properties
445 1.110.6.1 eeh * for each locator, we will attach a "foo" property, but
446 1.110.6.1 eeh * only if the locator is not wildcarded. When the device
447 1.110.6.1 eeh * attaches, if it wants to record or override locator
448 1.110.6.1 eeh * information, it creates appropriate properties, overriding
449 1.110.6.1 eeh * existing properties created here.
450 1.110.6.1 eeh */
451 1.110 thorpej res_io[0].ir_addr = cf->cf_loc[ISACF_PORT];
452 1.110 thorpej res_io[0].ir_size = 0;
453 1.110.6.1 eeh if (cf->cf_loc[ISACF_PORT] != ISACF_PORT_DEFAULT) {
454 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_PORT],
455 1.110.6.1 eeh &cf->cf_loc[ISACF_PORT], sizeof(int),
456 1.110.6.1 eeh PROP_CONST|PROP_INT, 0);
457 1.110.6.1 eeh }
458 1.110 thorpej
459 1.110 thorpej res_mem[0].ir_addr = cf->cf_loc[ISACF_IOMEM];
460 1.110.6.1 eeh if (cf->cf_loc[ISACF_IOMEM] != ISACF_IOMEM_DEFAULT) {
461 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_IOMEM],
462 1.110.6.1 eeh &cf->cf_loc[ISACF_IOMEM], sizeof(int),
463 1.110.6.1 eeh PROP_CONST|PROP_INT, 0);
464 1.110.6.1 eeh }
465 1.110 thorpej res_mem[0].ir_size = cf->cf_loc[ISACF_IOSIZ];
466 1.110.6.1 eeh if (cf->cf_loc[ISACF_IOSIZ] != ISACF_IOSIZ_DEFAULT) {
467 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_IOSIZ],
468 1.110.6.1 eeh &cf->cf_loc[ISACF_IOSIZ], sizeof(int),
469 1.110.6.1 eeh PROP_CONST|PROP_INT, 0);
470 1.110.6.1 eeh }
471 1.110 thorpej
472 1.110 thorpej res_irq[0].ir_irq =
473 1.110 thorpej cf->cf_loc[ISACF_IRQ] == 2 ? 9 : cf->cf_loc[ISACF_IRQ];
474 1.110.6.1 eeh if (res_irq[0].ir_irq != ISACF_IRQ_DEFAULT) {
475 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_IRQ],
476 1.110.6.1 eeh &res_irq[0].ir_irq, sizeof(int),
477 1.110.6.1 eeh PROP_INT, 0);
478 1.110.6.1 eeh }
479 1.110 thorpej
480 1.110 thorpej res_drq[0].ir_drq = cf->cf_loc[ISACF_DRQ];
481 1.110.6.1 eeh if (cf->cf_loc[ISACF_DRQ] != ISACF_DRQ_DEFAULT) {
482 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_DRQ],
483 1.110.6.1 eeh &cf->cf_loc[ISACF_DRQ], sizeof(int),
484 1.110.6.1 eeh PROP_CONST|PROP_INT, 0);
485 1.110.6.1 eeh }
486 1.110 thorpej res_drq[1].ir_drq = cf->cf_loc[ISACF_DRQ2];
487 1.110.6.1 eeh if (cf->cf_loc[ISACF_DRQ2] != ISACF_DRQ2_DEFAULT) {
488 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_DRQ2],
489 1.110.6.1 eeh &cf->cf_loc[ISACF_DRQ2], sizeof(int),
490 1.110.6.1 eeh PROP_CONST|PROP_INT, 0);
491 1.110.6.1 eeh }
492 1.110 thorpej
493 1.94 cgd ia.ia_iot = sc->sc_iot;
494 1.94 cgd ia.ia_memt = sc->sc_memt;
495 1.95 thorpej ia.ia_dmat = sc->sc_dmat;
496 1.94 cgd ia.ia_ic = sc->sc_ic;
497 1.110 thorpej
498 1.110 thorpej ia.ia_io = res_io;
499 1.110 thorpej ia.ia_nio = 1;
500 1.110 thorpej
501 1.110 thorpej ia.ia_iomem = res_mem;
502 1.110 thorpej ia.ia_niomem = 1;
503 1.110 thorpej
504 1.110 thorpej ia.ia_irq = res_irq;
505 1.110 thorpej ia.ia_nirq = 1;
506 1.110 thorpej
507 1.110 thorpej ia.ia_drq = res_drq;
508 1.110 thorpej ia.ia_ndrq = 2;
509 1.94 cgd
510 1.94 cgd tryagain = 0;
511 1.110.6.1 eeh
512 1.110.6.1 eeh /*
513 1.110.6.1 eeh * Find out if this is a new driver or old driver and call
514 1.110.6.1 eeh * the match function in the correct way.
515 1.110.6.1 eeh */
516 1.110.6.1 eeh if ((ssize_t)cf->cf_attach->ca_devsize < 0) {
517 1.110.6.1 eeh DEV_PRIVATE(child) = &ia;
518 1.110.6.1 eeh if ((*cf->cf_attach->ca_match)(parent, cf, child) > 0) {
519 1.110.6.1 eeh config_attach_ad(parent, cf, &ia,
520 1.110.6.1 eeh isaprint, child);
521 1.110.6.1 eeh tryagain = (cf->cf_fstate == FSTATE_STAR);
522 1.110.6.1 eeh } else {
523 1.110.6.1 eeh /* Destroy unused device node. */
524 1.110.6.1 eeh config_detach(child, 0);
525 1.110.6.1 eeh }
526 1.110.6.1 eeh } else if ((*cf->cf_attach->ca_match)(parent, cf, &ia) > 0) {
527 1.110.6.1 eeh
528 1.110.6.1 eeh /*
529 1.110.6.1 eeh * Old style devices do not update locator
530 1.110.6.1 eeh * properties, so we'll do that for them.
531 1.110.6.1 eeh */
532 1.110.6.1 eeh if (res_io[0].ir_addr != cf->cf_loc[ISACF_PORT] &&
533 1.110.6.1 eeh cf->cf_loc[ISACF_PORT] != ISACF_PORT_DEFAULT) {
534 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_PORT],
535 1.110.6.1 eeh &res_io[0].ir_addr, sizeof(int),
536 1.110.6.1 eeh PROP_INT, 0);
537 1.110.6.1 eeh }
538 1.110.6.1 eeh if (res_io[0].ir_size != 0) {
539 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_SIZE],
540 1.110.6.1 eeh &res_io[0].ir_size, sizeof(int),
541 1.110.6.1 eeh PROP_INT, 0);
542 1.110.6.1 eeh }
543 1.110.6.1 eeh
544 1.110.6.1 eeh if (res_mem[0].ir_addr != cf->cf_loc[ISACF_IOMEM] &&
545 1.110.6.1 eeh cf->cf_loc[ISACF_IOMEM] !=
546 1.110.6.1 eeh ISACF_IOMEM_DEFAULT) {
547 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_IOMEM],
548 1.110.6.1 eeh &res_mem[0].ir_addr, sizeof(int),
549 1.110.6.1 eeh PROP_INT, 0);
550 1.110.6.1 eeh }
551 1.110.6.1 eeh
552 1.110.6.1 eeh if (res_mem[0].ir_addr != cf->cf_loc[ISACF_IOSIZ] &&
553 1.110.6.1 eeh cf->cf_loc[ISACF_IOSIZ] !=
554 1.110.6.1 eeh ISACF_IOSIZ_DEFAULT) {
555 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_IOSIZ],
556 1.110.6.1 eeh &res_mem[0].ir_size, sizeof(int),
557 1.110.6.1 eeh PROP_INT, 0);
558 1.110.6.1 eeh }
559 1.110.6.1 eeh
560 1.110.6.1 eeh /*
561 1.110.6.1 eeh * Since this value may have been twiddled by us
562 1.110.6.1 eeh * earlier we cannot determine if the value was
563 1.110.6.1 eeh * untouched by our child.
564 1.110.6.1 eeh */
565 1.110.6.1 eeh if (res_irq[0].ir_irq != cf->cf_loc[ISACF_IRQ]) {
566 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_IRQ],
567 1.110.6.1 eeh &res_irq[0].ir_irq, sizeof(int),
568 1.110.6.1 eeh PROP_INT, 0);
569 1.110.6.1 eeh }
570 1.110.6.1 eeh
571 1.110.6.1 eeh if (res_drq[0].ir_drq != cf->cf_loc[ISACF_DRQ] &&
572 1.110.6.1 eeh cf->cf_loc[ISACF_DRQ] != ISACF_DRQ_DEFAULT) {
573 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_DRQ],
574 1.110.6.1 eeh &res_drq[0].ir_drq, sizeof(int),
575 1.110.6.1 eeh PROP_INT, 0);
576 1.110.6.1 eeh }
577 1.110.6.1 eeh if (res_drq[0].ir_drq != cf->cf_loc[ISACF_DRQ2] &&
578 1.110.6.1 eeh cf->cf_loc[ISACF_DRQ2] != ISACF_DRQ2_DEFAULT) {
579 1.110.6.1 eeh dev_setprop(child, cf->cf_locnames[ISACF_DRQ2],
580 1.110.6.1 eeh &res_drq[0].ir_drq, sizeof(int),
581 1.110.6.1 eeh PROP_INT, 0);
582 1.110.6.1 eeh }
583 1.110.6.1 eeh
584 1.110.6.1 eeh config_attach_ad(parent, cf, &ia, isaprint, child);
585 1.94 cgd tryagain = (cf->cf_fstate == FSTATE_STAR);
586 1.110.6.1 eeh } else {
587 1.110.6.1 eeh /* Destroy unused device node. */
588 1.110.6.1 eeh config_detach(child, 0);
589 1.94 cgd }
590 1.110.6.1 eeh }
591 1.94 cgd
592 1.91 cgd return (0);
593 1.72 cgd }
594 1.72 cgd
595 1.72 cgd char *
596 1.110 thorpej isa_intr_typename(int type)
597 1.72 cgd {
598 1.72 cgd
599 1.72 cgd switch (type) {
600 1.75 mycroft case IST_NONE :
601 1.72 cgd return ("none");
602 1.75 mycroft case IST_PULSE:
603 1.72 cgd return ("pulsed");
604 1.75 mycroft case IST_EDGE:
605 1.72 cgd return ("edge-triggered");
606 1.75 mycroft case IST_LEVEL:
607 1.72 cgd return ("level-triggered");
608 1.72 cgd default:
609 1.72 cgd panic("isa_intr_typename: invalid type %d", type);
610 1.72 cgd }
611 1.1 cgd }
612