xref: /openbsd-src/sys/dev/isa/aic_isa.c (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /*	$OpenBSD: aic_isa.c,v 1.7 2014/09/14 14:17:25 jsg Exp $	*/
2 /*	$NetBSD: aic6360.c,v 1.52 1996/12/10 21:27:51 thorpej Exp $	*/
3 
4 /*
5  * Copyright (c) 1994, 1995, 1996 Charles Hannum.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by Charles M. Hannum.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * Copyright (c) 1994 Jarle Greipsland
22  * All rights reserved.
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  * 1. Redistributions of source code must retain the above copyright
28  *    notice, this list of conditions and the following disclaimer.
29  * 2. Redistributions in binary form must reproduce the above copyright
30  *    notice, this list of conditions and the following disclaimer in the
31  *    documentation and/or other materials provided with the distribution.
32  * 3. The name of the author may not be used to endorse or promote products
33  *    derived from this software without specific prior written permission.
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
36  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
37  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
39  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
41  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
43  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
44  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
45  * POSSIBILITY OF SUCH DAMAGE.
46  */
47 
48 /*
49  * Acknowledgements: Many of the algorithms used in this driver are
50  * inspired by the work of Julian Elischer (julian@tfs.com) and
51  * Charles Hannum (mycroft@duality.gnu.ai.mit.edu).  Thanks a million!
52  */
53 
54 #include <sys/types.h>
55 #include <sys/param.h>
56 #include <sys/systm.h>
57 #include <sys/kernel.h>
58 #include <sys/errno.h>
59 #include <sys/ioctl.h>
60 #include <sys/device.h>
61 #include <sys/buf.h>
62 #include <sys/queue.h>
63 
64 #include <machine/bus.h>
65 #include <machine/intr.h>
66 
67 #include <scsi/scsi_all.h>
68 #include <scsi/scsi_message.h>
69 #include <scsi/scsiconf.h>
70 
71 #include <dev/isa/isavar.h>
72 
73 #include <dev/ic/aic6360reg.h>
74 #include <dev/ic/aic6360var.h>
75 
76 int	aic_isa_probe(struct device *, void *, void *);
77 void	aic_isa_attach(struct device *, struct device *, void *);
78 
79 struct cfattach aic_isa_ca = {
80 	sizeof(struct aic_softc), aic_isa_probe, aic_isa_attach
81 };
82 
83 /*
84  * INITIALIZATION ROUTINES (probe, attach ++)
85  */
86 
87 /*
88  * aicprobe: probe for AIC6360 SCSI-controller
89  * returns non-zero value if a controller is found.
90  */
91 int
92 aic_isa_probe(parent, match, aux)
93 	struct device *parent;
94 	void *match, *aux;
95 {
96 	struct isa_attach_args *ia = aux;
97 	bus_space_tag_t iot = ia->ia_iot;
98 	bus_space_handle_t ioh;
99 	int rv;
100 
101 	if (bus_space_map(iot, ia->ia_iobase, AIC_NPORTS, 0, &ioh))
102 		return (0);
103 
104 	AIC_TRACE(("aic: probing for aic-chip at port 0x%x\n", ia->ia_iobase));
105 	rv = aic_find(iot, ioh);
106 
107 	bus_space_unmap(iot, ioh, AIC_NPORTS);
108 
109 	if (rv) {
110 		ia->ia_msize = 0;
111 		ia->ia_iosize = AIC_NPORTS;
112 	}
113 	return (rv);
114 }
115 
116 /*
117  * Attach the AIC6360, fill out some high and low level data structures
118  */
119 void
120 aic_isa_attach(parent, self, aux)
121 	struct device *parent, *self;
122 	void *aux;
123 {
124 	struct isa_attach_args *ia = aux;
125 	bus_space_tag_t iot = ia->ia_iot;
126 	bus_space_handle_t ioh;
127 	struct aic_softc *sc = (void *)self;
128 
129 	if (bus_space_map(iot, ia->ia_iobase, AIC_NPORTS, 0, &ioh))
130 		panic("%s: can't map i/o-ports", sc->sc_dev.dv_xname);
131 
132 	sc->sc_iot = iot;
133 	sc->sc_ioh = ioh;
134 
135 	printf("\n");
136 
137 	sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
138 	    IPL_BIO, aicintr, sc, sc->sc_dev.dv_xname);
139 
140 	aicattach(sc);
141 }
142 
143