xref: /netbsd-src/sys/dev/isa/bha_isa.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: bha_isa.c,v 1.30 2007/10/19 12:00:15 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 Charles M. Hannum.
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: bha_isa.c,v 1.30 2007/10/19 12:00:15 ad Exp $");
41 
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/device.h>
45 
46 #include <sys/bus.h>
47 #include <sys/intr.h>
48 
49 #include <dev/scsipi/scsipi_all.h>
50 #include <dev/scsipi/scsiconf.h>
51 
52 #include <dev/isa/isavar.h>
53 #include <dev/isa/isadmavar.h>
54 
55 #include <dev/ic/bhareg.h>
56 #include <dev/ic/bhavar.h>
57 
58 #define	BHA_ISA_IOSIZE	4
59 
60 int	bha_isa_probe(struct device *, struct cfdata *, void *);
61 void	bha_isa_attach(struct device *, struct device *, void *);
62 
63 CFATTACH_DECL(bha_isa, sizeof(struct bha_softc),
64     bha_isa_probe, bha_isa_attach, NULL, NULL);
65 
66 /*
67  * Check the slots looking for a board we recognise
68  * If we find one, note it's address (slot) and call
69  * the actual probe routine to check it out.
70  */
71 int
72 bha_isa_probe(struct device *parent, struct cfdata *match,
73     void *aux)
74 {
75 	struct isa_attach_args *ia = aux;
76 	bus_space_tag_t iot = ia->ia_iot;
77 	bus_space_handle_t ioh;
78 	struct bha_probe_data bpd;
79 	int rv;
80 
81 	if (ia->ia_nio < 1)
82 		return (0);
83 	if (ia->ia_nirq < 1)
84 		return (0);
85 	if (ia->ia_ndrq < 1)
86 		return (0);
87 
88 	if (ISA_DIRECT_CONFIG(ia))
89 		return (0);
90 
91 	/* Disallow wildcarded i/o address. */
92 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
93 		return (0);
94 
95 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, BHA_ISA_IOSIZE, 0, &ioh))
96 		return (0);
97 
98 	rv = bha_probe_inquiry(iot, ioh, &bpd);
99 
100 	bus_space_unmap(iot, ioh, BHA_ISA_IOSIZE);
101 
102 	if (rv) {
103 		if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
104 		    ia->ia_irq[0].ir_irq != bpd.sc_irq)
105 			return (0);
106 		if (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ &&
107 		    ia->ia_drq[0].ir_drq != bpd.sc_drq)
108 			return (0);
109 
110 		ia->ia_nio = 1;
111 		ia->ia_io[0].ir_size = BHA_ISA_IOSIZE;
112 
113 		ia->ia_nirq = 1;
114 		ia->ia_irq[0].ir_irq = bpd.sc_irq;
115 
116 		ia->ia_ndrq = 1;
117 		ia->ia_drq[0].ir_drq = bpd.sc_drq;
118 
119 		ia->ia_niomem = 0;
120 	}
121 	return (rv);
122 }
123 
124 /*
125  * Attach all the sub-devices we can find
126  */
127 void
128 bha_isa_attach(struct device *parent, struct device *self,
129     void *aux)
130 {
131 	struct isa_attach_args *ia = aux;
132 	struct bha_softc *sc = (void *)self;
133 	bus_space_tag_t iot = ia->ia_iot;
134 	bus_space_handle_t ioh;
135 	struct bha_probe_data bpd;
136 	isa_chipset_tag_t ic = ia->ia_ic;
137 	int error;
138 
139 	printf("\n");
140 
141 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, BHA_ISA_IOSIZE, 0, &ioh)) {
142 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
143 		return;
144 	}
145 
146 	sc->sc_iot = iot;
147 	sc->sc_ioh = ioh;
148 	sc->sc_dmat = ia->ia_dmat;
149 	if (!bha_probe_inquiry(iot, ioh, &bpd)) {
150 		printf("%s: bha_isa_attach failed\n", sc->sc_dev.dv_xname);
151 		return;
152 	}
153 
154 	sc->sc_dmaflags = 0;
155 	if (bpd.sc_drq != -1) {
156 		if ((error = isa_dmacascade(ic, bpd.sc_drq)) != 0) {
157 			printf("%s: unable to cascade DRQ, error = %d\n",
158 			    sc->sc_dev.dv_xname, error);
159 			return;
160 		}
161 	} else {
162 		/*
163 		 * We have a VLB controller.  If we're at least both
164 		 * hardware revision E and firmware revision 3.37,
165 		 * we can do 32-bit DMA (earlier revisions are buggy
166 		 * in this regard).
167 		 */
168 		(void) bha_info(sc);
169 		if (strcmp(sc->sc_firmware, "3.37") < 0)
170 		    printf("%s: buggy VLB controller, disabling 32-bit DMA\n",
171 		        sc->sc_dev.dv_xname);
172 		else
173 			sc->sc_dmaflags = ISABUS_DMA_32BIT;
174 	}
175 
176 	sc->sc_ih = isa_intr_establish(ic, bpd.sc_irq, IST_EDGE, IPL_BIO,
177 	    bha_intr, sc);
178 	if (sc->sc_ih == NULL) {
179 		printf("%s: couldn't establish interrupt\n",
180 		    sc->sc_dev.dv_xname);
181 		return;
182 	}
183 
184 	bha_attach(sc);
185 }
186