xref: /netbsd-src/sys/dev/isa/aha_isa.c (revision 481fca6e59249d8ffcf24fef7cfbe7b131bfb080)
1 /*	$NetBSD: aha_isa.c,v 1.11 1998/08/15 10:10:51 mycroft 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/types.h>
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 
44 #include <machine/bus.h>
45 #include <machine/intr.h>
46 
47 #include <dev/scsipi/scsi_all.h>
48 #include <dev/scsipi/scsipi_all.h>
49 #include <dev/scsipi/scsiconf.h>
50 
51 #include <dev/isa/isavar.h>
52 #include <dev/isa/isadmavar.h>
53 
54 #include <dev/ic/ahareg.h>
55 #include <dev/ic/ahavar.h>
56 
57 #define	AHA_ISA_IOSIZE	4
58 
59 int	aha_isa_probe __P((struct device *, struct cfdata *, void *));
60 void	aha_isa_attach __P((struct device *, struct device *, void *));
61 
62 struct cfattach aha_isa_ca = {
63 	sizeof(struct aha_softc), aha_isa_probe, aha_isa_attach
64 };
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 aha_isa_probe(parent, match, aux)
73 	struct device *parent;
74 	struct cfdata *match;
75 	void *aux;
76 {
77 	struct isa_attach_args *ia = aux;
78 	bus_space_tag_t iot = ia->ia_iot;
79 	bus_space_handle_t ioh;
80 	struct aha_probe_data apd;
81 	int rv;
82 
83 	/* Disallow wildcarded i/o address. */
84 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
85 		return (0);
86 
87 	if (bus_space_map(iot, ia->ia_iobase, AHA_ISA_IOSIZE, 0, &ioh))
88 		return (0);
89 
90 	rv = aha_find(iot, ioh, &apd);
91 
92 	bus_space_unmap(iot, ioh, AHA_ISA_IOSIZE);
93 
94 	if (rv) {
95 		if (ia->ia_irq != -1 && ia->ia_irq != apd.sc_irq)
96 			return (0);
97 		if (ia->ia_drq != -1 && ia->ia_drq != apd.sc_drq)
98 			return (0);
99 		ia->ia_irq = apd.sc_irq;
100 		ia->ia_drq = apd.sc_drq;
101 		ia->ia_msize = 0;
102 		ia->ia_iosize = AHA_ISA_IOSIZE;
103 	}
104 	return (rv);
105 }
106 
107 /*
108  * Attach all the sub-devices we can find
109  */
110 void
111 aha_isa_attach(parent, self, aux)
112 	struct device *parent, *self;
113 	void *aux;
114 {
115 	struct isa_attach_args *ia = aux;
116 	struct aha_softc *sc = (void *)self;
117 	bus_space_tag_t iot = ia->ia_iot;
118 	bus_space_handle_t ioh;
119 	struct aha_probe_data apd;
120 	isa_chipset_tag_t ic = ia->ia_ic;
121 	int error;
122 
123 	printf("\n");
124 
125 	if (bus_space_map(iot, ia->ia_iobase, AHA_ISA_IOSIZE, 0, &ioh)) {
126 		printf("%s: can't map i/o space\n", sc->sc_dev.dv_xname);
127 		return;
128 	}
129 
130 	sc->sc_iot = iot;
131 	sc->sc_ioh = ioh;
132 	sc->sc_dmat = ia->ia_dmat;
133 	if (!aha_find(iot, ioh, &apd)) {
134 		printf("%s: aha_find failed\n", sc->sc_dev.dv_xname);
135 		return;
136 	}
137 
138 	if (apd.sc_drq != -1) {
139 		if ((error = isa_dmacascade(ic, apd.sc_drq)) != 0) {
140 			printf("%s: unable to cascade DRQ, error = %d\n",
141 			    sc->sc_dev.dv_xname, error);
142 			return;
143 		}
144 	}
145 
146 	sc->sc_ih = isa_intr_establish(ic, apd.sc_irq, IST_EDGE, IPL_BIO,
147 	    aha_intr, sc);
148 	if (sc->sc_ih == NULL) {
149 		printf("%s: couldn't establish interrupt\n",
150 		    sc->sc_dev.dv_xname);
151 		return;
152 	}
153 
154 	aha_attach(sc, &apd);
155 }
156