xref: /netbsd-src/sys/dev/isa/adv_isa.c (revision 274254cdae52594c1aa480a736aef78313d15c9c)
1 /*	$NetBSD: adv_isa.c,v 1.16 2008/04/28 20:23:51 martin Exp $	*/
2 
3 /*
4  * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved.
5  *
6  * Author: Baldassare Dante Profeta <dante@mclink.it>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 /*
30  * Device probe and attach routines for the following
31  * Advanced Systems Inc. SCSI controllers:
32  *
33  *    Connectivity Products:
34  *	ABP510/5150 - Bus-Master ISA (240 CDB) (Footnote 1)
35  *      ABP5140 - Bus-Master ISA (16 CDB) (Footnote 1) (Footnote 2)
36  *      ABP5142 - Bus-Master ISA with floppy (16 CDB) (Footnote 3)
37  *
38  *   Single Channel Products:
39  *	ABP542 - Bus-Master ISA with floppy (240 CDB)
40  *	ABP842 - Bus-Master VL (240 CDB)
41  *
42  *   Dual Channel Products:
43  *	ABP852 - Dual Channel Bus-Master VL (240 CDB Per Channel)
44  *
45  *   Footnotes:
46  *     1. This board has been shipped by HP with the 4020i CD-R drive.
47  *        The board has no BIOS so it cannot control a boot device, but
48  *        it can control any secondary SCSI device.
49  *     2. This board has been sold by SIIG as the i540 SpeedMaster.
50  *     3. This board has been sold by SIIG as the i542 SpeedMaster.
51  */
52 
53 #include <sys/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: adv_isa.c,v 1.16 2008/04/28 20:23:51 martin Exp $");
55 
56 #include <sys/param.h>
57 #include <sys/systm.h>
58 #include <sys/kernel.h>
59 #include <sys/errno.h>
60 #include <sys/ioctl.h>
61 #include <sys/device.h>
62 #include <sys/buf.h>
63 #include <sys/proc.h>
64 #include <sys/user.h>
65 #include <sys/queue.h>
66 
67 #include <sys/bus.h>
68 
69 #include <dev/scsipi/scsi_all.h>
70 #include <dev/scsipi/scsipi_all.h>
71 #include <dev/scsipi/scsiconf.h>
72 
73 #include <dev/isa/isavar.h>
74 
75 #include <dev/ic/advlib.h>
76 #include <dev/ic/adv.h>
77 
78 
79 /* Possible port addresses an ISA or VL adapter can live at */
80 static int asc_ioport[ASC_IOADR_TABLE_MAX_IX] =
81 {
82 	0x100,
83 	ASC_IOADR_1,	/* First selection in BIOS setup */
84 	0x120,
85 	ASC_IOADR_2,	/* Second selection in BIOS setup */
86 	0x140,
87 	ASC_IOADR_3,	/* Third selection in BIOS setup */
88 	ASC_IOADR_4,	/* Fourth selection in BIOS setup */
89 	ASC_IOADR_5,	/* Fifth selection in BIOS setup */
90 	ASC_IOADR_6,	/* Sixth selection in BIOS setup */
91 	ASC_IOADR_7,	/* Seventh selection in BIOS setup */
92 	ASC_IOADR_8	/* Eighth and default selection in BIOS setup */
93 };
94 
95 /******************************************************************************/
96 
97 int	adv_isa_probe(struct device *, struct cfdata *, void *);
98 void	adv_isa_attach(struct device *, struct device *, void *);
99 
100 CFATTACH_DECL(adv_isa, sizeof(ASC_SOFTC),
101     adv_isa_probe, adv_isa_attach, NULL, NULL);
102 
103 /******************************************************************************/
104 
105 int
106 adv_isa_probe( struct device *parent, struct cfdata *match,
107     void *aux)
108 {
109 	struct isa_attach_args *ia = aux;
110 	bus_space_tag_t iot = ia->ia_iot;
111 	bus_space_handle_t ioh;
112 	int port_index;
113 	int iobase, irq, drq;
114 	int rv = 0;
115 
116 	if (ia->ia_nio < 1)
117 		return (0);
118 	if (ia->ia_nirq < 1)
119 		return (0);
120 	if (ia->ia_ndrq < 1)
121 		return (0);
122 
123 	if (ISA_DIRECT_CONFIG(ia))
124 		return (0);
125 
126 	/*
127 	 * If the I/O address is wildcarded, look for boards
128 	 * in ascending order.
129 	 */
130 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT) {
131 		for (port_index = 0; port_index < ASC_IOADR_TABLE_MAX_IX;
132 		     port_index++) {
133 			iobase = asc_ioport[port_index];
134 
135 			if (iobase) {
136 				if (bus_space_map(iot, iobase, ASC_IOADR_GAP,
137 				    0, &ioh))
138 					continue;
139 
140 				rv = AscFindSignature(iot, ioh);
141 
142 				if (rv) {
143 					ia->ia_io[0].ir_addr = iobase;
144 					break;
145 				}
146 
147 				bus_space_unmap(iot, ioh, ASC_IOADR_GAP);
148 			}
149 		}
150 		if (rv == 0)
151 			return (0);
152 	} else {
153 		iobase = ia->ia_io[0].ir_addr;
154 		if (bus_space_map(iot, iobase, ASC_IOADR_GAP, 0, &ioh))
155 			return (0);
156 
157 		rv = AscFindSignature(iot, ioh);
158 
159 		if (rv == 0) {
160 			bus_space_unmap(iot, ioh, ASC_IOADR_GAP);
161 			return (0);
162 		}
163 	}
164 
165 	/* XXXJRT Probe routines should not have side-effects!! */
166 	ASC_SET_CHIP_CONTROL(iot, ioh, ASC_CC_HALT);
167 	ASC_SET_CHIP_STATUS(iot, ioh, 0);
168 
169 	irq = AscGetChipIRQ(iot, ioh, ASC_IS_ISA);
170 	drq = AscGetIsaDmaChannel(iot, ioh);
171 
172 	/* Verify that the IRQ/DRQ match (or are wildcarded). */
173 	if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
174 	    ia->ia_irq[0].ir_irq != irq) {
175 		rv = 0;
176 		goto out;
177 	}
178 	if (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ &&
179 	    ia->ia_drq[0].ir_drq != drq) {
180 		rv = 0;
181 		goto out;
182 	}
183 
184 	ia->ia_nio = 1;
185 	ia->ia_io[0].ir_addr = iobase;
186 	ia->ia_io[0].ir_size = ASC_IOADR_GAP;
187 
188 	ia->ia_nirq = 1;
189 	ia->ia_irq[0].ir_irq = irq;
190 
191 	ia->ia_ndrq = 1;
192 	ia->ia_drq[0].ir_drq = drq;
193 
194 	ia->ia_niomem = 0;
195 
196  out:
197 	bus_space_unmap(iot, ioh, ASC_IOADR_GAP);
198 	return rv;
199 }
200 
201 
202 void
203 adv_isa_attach(struct device *parent, struct device *self, void *aux)
204 {
205 	struct isa_attach_args *ia = aux;
206 	ASC_SOFTC *sc = (void *) self;
207 	bus_space_tag_t iot = ia->ia_iot;
208 	bus_space_handle_t ioh;
209 	isa_chipset_tag_t ic = ia->ia_ic;
210 	int error;
211 
212 	printf("\n");
213 
214 	sc->sc_flags = 0x0;
215 
216 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, ASC_IOADR_GAP, 0, &ioh)) {
217 		aprint_error_dev(&sc->sc_dev, "can't map i/o space\n");
218 		return;
219 	}
220 
221 	sc->sc_iot = iot;
222 	sc->sc_ioh = ioh;
223 	sc->sc_dmat = ia->ia_dmat;
224 	sc->bus_type = ASC_IS_ISA;
225 	sc->chip_version = ASC_GET_CHIP_VER_NO(iot, ioh);
226 	/*
227 	 * Memo:
228 	 * for EISA cards:
229 	 * sc->chip_version = (ASC_CHIP_MIN_VER_EISA - 1) + ea->ea_pid[1];
230 	 */
231 
232 	/*
233 	 * Initialize the board
234 	 */
235 	if (adv_init(sc)) {
236 		aprint_error_dev(&sc->sc_dev, "adv_init failed\n");
237 		return;
238 	}
239 
240 	if ((error = isa_dmacascade(ic, ia->ia_drq[0].ir_drq)) != 0) {
241 		aprint_error_dev(&sc->sc_dev, "unable to cascade DRQ, error = %d\n", error);
242 		return;
243 	}
244 
245 	sc->sc_ih = isa_intr_establish(ic, ia->ia_irq[0].ir_irq, IST_EDGE,
246 	    IPL_BIO, adv_intr, sc);
247 	if (sc->sc_ih == NULL) {
248 		aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt\n");
249 		return;
250 	}
251 
252 	adv_attach(sc);
253 }
254