1 /*        $NetBSD: aic_isa.c,v 1.26 2009/11/23 02:13:46 rmind Exp $   */
2 
3 /*
4  * Copyright (c) 1994, 1995, 1996 Charles M. Hannum.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *        This product includes software developed by Charles M. Hannum.
17  * 4. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * Copyright (c) 1994 Jarle Greipsland
21  * All rights reserved.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  * 1. Redistributions of source code must retain the above copyright
27  *    notice, this list of conditions and the following disclaimer.
28  * 2. Redistributions in binary form must reproduce the above copyright
29  *    notice, this list of conditions and the following disclaimer in the
30  *    documentation and/or other materials provided with the distribution.
31  * 3. The name of the author may not be used to endorse or promote products
32  *    derived from this software without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
35  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
36  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
38  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
39  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
42  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 /*
48  * Acknowledgements: Many of the algorithms used in this driver are
49  * inspired by the work of Julian Elischer (julian@tfs.com) and
50  * Charles Hannum (mycroft@duality.gnu.ai.mit.edu).  Thanks a million!
51  */
52 
53 #include <sys/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: aic_isa.c,v 1.26 2009/11/23 02:13:46 rmind 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/queue.h>
65 
66 #include <sys/bus.h>
67 #include <sys/intr.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/aic6360reg.h>
76 #include <dev/ic/aic6360var.h>
77 
78 static int          aic_isa_probe(device_t, cfdata_t, void *);
79 static void         aic_isa_attach(device_t, device_t, void *);
80 
81 struct aic_isa_softc {
82           struct    aic_softc sc_aic;   /* real "aic" softc */
83 
84           /* ISA-specific goo. */
85           void      *sc_ih;                       /* interrupt handler */
86 };
87 
88 CFATTACH_DECL_NEW(aic_isa, sizeof(struct aic_isa_softc),
89     aic_isa_probe, aic_isa_attach, NULL, NULL);
90 
91 
92 /*
93  * INITIALIZATION ROUTINES (probe, attach ++)
94  */
95 
96 /*
97  * aic_isa_probe: probe for AIC6360 SCSI-controller
98  * returns non-zero value if a controller is found.
99  */
100 int
aic_isa_probe(device_t parent,cfdata_t match,void * aux)101 aic_isa_probe(device_t parent, cfdata_t match, void *aux)
102 {
103           struct isa_attach_args *ia = aux;
104           bus_space_tag_t iot = ia->ia_iot;
105           bus_space_handle_t ioh;
106           int rv;
107 
108           if (ia->ia_nio < 1)
109                     return (0);
110           if (ia->ia_nirq < 1)
111                     return (0);
112 
113           if (ISA_DIRECT_CONFIG(ia))
114                     return (0);
115 
116           /* Disallow wildcarded i/o address. */
117           if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
118                     return (0);
119 
120           /* Disallow wildcarded IRQ. */
121           if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
122                     return (0);
123 
124           if (bus_space_map(iot, ia->ia_io[0].ir_addr, AIC_ISA_IOSIZE, 0, &ioh))
125                     return (0);
126 
127           rv = aic_find(iot, ioh);
128 
129           bus_space_unmap(iot, ioh, AIC_ISA_IOSIZE);
130 
131           if (rv) {
132                     ia->ia_nio = 1;
133                     ia->ia_io[0].ir_size = AIC_ISA_IOSIZE;
134 
135                     ia->ia_nirq = 1;
136 
137                     ia->ia_niomem = 0;
138                     ia->ia_ndrq = 0;
139           }
140           return rv;
141 }
142 
143 void
aic_isa_attach(device_t parent,device_t self,void * aux)144 aic_isa_attach(device_t parent, device_t self, void *aux)
145 {
146           struct isa_attach_args *ia = aux;
147           struct aic_isa_softc *isc = device_private(self);
148           struct aic_softc *sc = &isc->sc_aic;
149           bus_space_tag_t iot = ia->ia_iot;
150           bus_space_handle_t ioh;
151           isa_chipset_tag_t ic = ia->ia_ic;
152 
153           sc->sc_dev = self;
154 
155           printf("\n");
156 
157           if (bus_space_map(iot, ia->ia_io[0].ir_addr, AIC_ISA_IOSIZE, 0, &ioh)) {
158                     aprint_error_dev(self, "can't map i/o space\n");
159                     return;
160           }
161 
162           sc->sc_iot = iot;
163           sc->sc_ioh = ioh;
164           if (!aic_find(iot, ioh)) {
165                     aprint_error_dev(self, "aic_find failed\n");
166                     return;
167           }
168 
169           isc->sc_ih = isa_intr_establish(ic, ia->ia_irq[0].ir_irq, IST_EDGE,
170               IPL_BIO, aicintr, sc);
171           if (isc->sc_ih == NULL) {
172                     aprint_error_dev(self, "couldn't establish interrupt\n");
173                     return;
174           }
175 
176           aicattach(sc);
177 }
178