xref: /netbsd-src/sys/dev/isa/adv_isa.c (revision 10ad5ffa714ce1a679dcc9dd8159648df2d67b5a)
1 /*	$NetBSD: adv_isa.c,v 1.18 2009/05/12 09:10:15 cegger 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.18 2009/05/12 09:10:15 cegger 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(device_t, cfdata_t, void *);
98 void	adv_isa_attach(device_t, device_t, 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(device_t parent, cfdata_t match, void *aux)
107 {
108 	struct isa_attach_args *ia = aux;
109 	bus_space_tag_t iot = ia->ia_iot;
110 	bus_space_handle_t ioh;
111 	int port_index;
112 	int iobase, irq, drq;
113 	int rv = 0;
114 
115 	if (ia->ia_nio < 1)
116 		return (0);
117 	if (ia->ia_nirq < 1)
118 		return (0);
119 	if (ia->ia_ndrq < 1)
120 		return (0);
121 
122 	if (ISA_DIRECT_CONFIG(ia))
123 		return (0);
124 
125 	/*
126 	 * If the I/O address is wildcarded, look for boards
127 	 * in ascending order.
128 	 */
129 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT) {
130 		for (port_index = 0; port_index < ASC_IOADR_TABLE_MAX_IX;
131 		     port_index++) {
132 			iobase = asc_ioport[port_index];
133 
134 			if (iobase) {
135 				if (bus_space_map(iot, iobase, ASC_IOADR_GAP,
136 				    0, &ioh))
137 					continue;
138 
139 				rv = AscFindSignature(iot, ioh);
140 
141 				if (rv) {
142 					ia->ia_io[0].ir_addr = iobase;
143 					break;
144 				}
145 
146 				bus_space_unmap(iot, ioh, ASC_IOADR_GAP);
147 			}
148 		}
149 		if (rv == 0)
150 			return (0);
151 	} else {
152 		iobase = ia->ia_io[0].ir_addr;
153 		if (bus_space_map(iot, iobase, ASC_IOADR_GAP, 0, &ioh))
154 			return (0);
155 
156 		rv = AscFindSignature(iot, ioh);
157 
158 		if (rv == 0) {
159 			bus_space_unmap(iot, ioh, ASC_IOADR_GAP);
160 			return (0);
161 		}
162 	}
163 
164 	/* XXXJRT Probe routines should not have side-effects!! */
165 	ASC_SET_CHIP_CONTROL(iot, ioh, ASC_CC_HALT);
166 	ASC_SET_CHIP_STATUS(iot, ioh, 0);
167 
168 	irq = AscGetChipIRQ(iot, ioh, ASC_IS_ISA);
169 	drq = AscGetIsaDmaChannel(iot, ioh);
170 
171 	/* Verify that the IRQ/DRQ match (or are wildcarded). */
172 	if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
173 	    ia->ia_irq[0].ir_irq != irq) {
174 		rv = 0;
175 		goto out;
176 	}
177 	if (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ &&
178 	    ia->ia_drq[0].ir_drq != drq) {
179 		rv = 0;
180 		goto out;
181 	}
182 
183 	ia->ia_nio = 1;
184 	ia->ia_io[0].ir_addr = iobase;
185 	ia->ia_io[0].ir_size = ASC_IOADR_GAP;
186 
187 	ia->ia_nirq = 1;
188 	ia->ia_irq[0].ir_irq = irq;
189 
190 	ia->ia_ndrq = 1;
191 	ia->ia_drq[0].ir_drq = drq;
192 
193 	ia->ia_niomem = 0;
194 
195  out:
196 	bus_space_unmap(iot, ioh, ASC_IOADR_GAP);
197 	return rv;
198 }
199 
200 
201 void
202 adv_isa_attach(device_t parent, device_t self, void *aux)
203 {
204 	struct isa_attach_args *ia = aux;
205 	ASC_SOFTC *sc = (void *) self;
206 	bus_space_tag_t iot = ia->ia_iot;
207 	bus_space_handle_t ioh;
208 	isa_chipset_tag_t ic = ia->ia_ic;
209 	int error;
210 
211 	printf("\n");
212 
213 	sc->sc_flags = 0x0;
214 
215 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, ASC_IOADR_GAP, 0, &ioh)) {
216 		aprint_error_dev(&sc->sc_dev, "can't map i/o space\n");
217 		return;
218 	}
219 
220 	sc->sc_iot = iot;
221 	sc->sc_ioh = ioh;
222 	sc->sc_dmat = ia->ia_dmat;
223 	sc->bus_type = ASC_IS_ISA;
224 	sc->chip_version = ASC_GET_CHIP_VER_NO(iot, ioh);
225 	/*
226 	 * Memo:
227 	 * for EISA cards:
228 	 * sc->chip_version = (ASC_CHIP_MIN_VER_EISA - 1) + ea->ea_pid[1];
229 	 */
230 
231 	/*
232 	 * Initialize the board
233 	 */
234 	if (adv_init(sc)) {
235 		aprint_error_dev(&sc->sc_dev, "adv_init failed\n");
236 		return;
237 	}
238 
239 	if ((error = isa_dmacascade(ic, ia->ia_drq[0].ir_drq)) != 0) {
240 		aprint_error_dev(&sc->sc_dev, "unable to cascade DRQ, error = %d\n", error);
241 		return;
242 	}
243 
244 	sc->sc_ih = isa_intr_establish(ic, ia->ia_irq[0].ir_irq, IST_EDGE,
245 	    IPL_BIO, adv_intr, sc);
246 	if (sc->sc_ih == NULL) {
247 		aprint_error_dev(&sc->sc_dev, "couldn't establish interrupt\n");
248 		return;
249 	}
250 
251 	adv_attach(sc);
252 }
253