aha_isapnp.c revision 1.13 1 /* $NetBSD: aha_isapnp.c,v 1.13 2007/10/19 12:00:30 ad Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: aha_isapnp.c,v 1.13 2007/10/19 12:00:30 ad Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/conf.h>
45 #include <sys/device.h>
46
47 #include <sys/bus.h>
48
49 #include <dev/scsipi/scsi_all.h>
50 #include <dev/scsipi/scsipi_all.h>
51 #include <dev/scsipi/scsiconf.h>
52
53 #include <dev/isa/isavar.h>
54
55 #include <dev/isapnp/isapnpreg.h>
56 #include <dev/isapnp/isapnpvar.h>
57 #include <dev/isapnp/isapnpdevs.h>
58
59
60 #include <dev/ic/ahareg.h>
61 #include <dev/ic/ahavar.h>
62
63 int aha_isapnp_probe(struct device *, struct cfdata *, void *);
64 void aha_isapnp_attach(struct device *, struct device *, void *);
65
66 CFATTACH_DECL(aha_isapnp, sizeof(struct aha_softc),
67 aha_isapnp_probe, aha_isapnp_attach, NULL, NULL);
68
69 int
70 aha_isapnp_probe(struct device *parent, struct cfdata *match,
71 void *aux)
72 {
73 int pri, variant;
74
75 pri = isapnp_devmatch(aux, &isapnp_aha_devinfo, &variant);
76 if (pri && variant > 0)
77 pri = 0;
78 return (pri);
79 }
80
81 void
82 aha_isapnp_attach(struct device *parent, struct device *self,
83 void *aux)
84 {
85 struct aha_softc *sc = device_private(self);
86 struct aha_probe_data apd;
87 struct isapnp_attach_args *ipa = aux;
88
89 printf("\n");
90
91 if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
92 printf("%s: error in region allocation\n",
93 sc->sc_dev.dv_xname);
94 return;
95 }
96
97 sc->sc_iot = ipa->ipa_iot;
98 sc->sc_ioh = ipa->ipa_io[0].h;
99 sc->sc_dmat = ipa->ipa_dmat;
100
101 if (!aha_find(sc->sc_iot, sc->sc_ioh, &apd)) {
102 printf("%s: aha_find failed\n", sc->sc_dev.dv_xname);
103 return;
104 }
105
106 if (ipa->ipa_ndrq == 0) {
107 if (apd.sc_drq != -1) {
108 printf("%s: no PnP drq, but card has one\n",
109 sc->sc_dev.dv_xname);
110 return;
111 }
112 } else if (apd.sc_drq != ipa->ipa_drq[0].num) {
113 printf("%s: card drq # (%d) != PnP # (%d)\n",
114 sc->sc_dev.dv_xname, apd.sc_drq, ipa->ipa_drq[0].num);
115 return;
116 } else {
117 int error = isa_dmacascade(ipa->ipa_ic, ipa->ipa_drq[0].num);
118 if (error) {
119 printf("%s: unable to cascade DRQ, error = %d\n",
120 sc->sc_dev.dv_xname, error);
121 return;
122 }
123 }
124
125 if (apd.sc_irq != ipa->ipa_irq[0].num) {
126 printf("%s: card irq # (%d) != PnP # (%d)\n",
127 sc->sc_dev.dv_xname, apd.sc_irq, ipa->ipa_irq[0].num);
128 return;
129 }
130
131
132 sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
133 ipa->ipa_irq[0].type, IPL_BIO, aha_intr, sc);
134
135 if (sc->sc_ih == NULL) {
136 printf("%s: couldn't establish interrupt\n",
137 sc->sc_dev.dv_xname);
138 return;
139 }
140
141 aha_attach(sc, &apd);
142 }
143