xref: /netbsd-src/sys/dev/isa/bha_isa.c (revision b331f99208984c02b5aa8f16ba7c8645bc00e8c9)
1 /*	$NetBSD: bha_isa.c,v 1.37 2016/07/14 04:19:27 msaitoh 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  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: bha_isa.c,v 1.37 2016/07/14 04:19:27 msaitoh Exp $");
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 
39 #include <sys/bus.h>
40 #include <sys/intr.h>
41 
42 #include <dev/scsipi/scsipi_all.h>
43 #include <dev/scsipi/scsiconf.h>
44 
45 #include <dev/isa/isavar.h>
46 #include <dev/isa/isadmavar.h>
47 
48 #include <dev/ic/bhareg.h>
49 #include <dev/ic/bhavar.h>
50 
51 #define	BHA_ISA_IOSIZE	4
52 
53 int	bha_isa_probe(device_t, cfdata_t, void *);
54 void	bha_isa_attach(device_t, device_t, void *);
55 
56 CFATTACH_DECL_NEW(bha_isa, sizeof(struct bha_softc),
57     bha_isa_probe, bha_isa_attach, NULL, NULL);
58 
59 /*
60  * Check the slots looking for a board we recognise
61  * If we find one, note its address (slot) and call
62  * the actual probe routine to check it out.
63  */
64 int
bha_isa_probe(device_t parent,cfdata_t match,void * aux)65 bha_isa_probe(device_t parent, cfdata_t match, void *aux)
66 {
67 	struct isa_attach_args *ia = aux;
68 	bus_space_tag_t iot = ia->ia_iot;
69 	bus_space_handle_t ioh;
70 	struct bha_probe_data bpd;
71 	int rv;
72 
73 	if (ia->ia_nio < 1)
74 		return (0);
75 	if (ia->ia_nirq < 1)
76 		return (0);
77 	if (ia->ia_ndrq < 1)
78 		return (0);
79 
80 	if (ISA_DIRECT_CONFIG(ia))
81 		return (0);
82 
83 	/* Disallow wildcarded i/o address. */
84 	if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
85 		return (0);
86 
87 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, BHA_ISA_IOSIZE, 0, &ioh))
88 		return (0);
89 
90 	rv = bha_probe_inquiry(iot, ioh, &bpd);
91 
92 	bus_space_unmap(iot, ioh, BHA_ISA_IOSIZE);
93 
94 	if (rv) {
95 		if (ia->ia_irq[0].ir_irq != ISA_UNKNOWN_IRQ &&
96 		    ia->ia_irq[0].ir_irq != bpd.sc_irq)
97 			return (0);
98 		if (ia->ia_drq[0].ir_drq != ISA_UNKNOWN_DRQ &&
99 		    ia->ia_drq[0].ir_drq != bpd.sc_drq)
100 			return (0);
101 
102 		ia->ia_nio = 1;
103 		ia->ia_io[0].ir_size = BHA_ISA_IOSIZE;
104 
105 		ia->ia_nirq = 1;
106 		ia->ia_irq[0].ir_irq = bpd.sc_irq;
107 
108 		ia->ia_ndrq = 1;
109 		ia->ia_drq[0].ir_drq = bpd.sc_drq;
110 
111 		ia->ia_niomem = 0;
112 	}
113 	return (rv);
114 }
115 
116 /*
117  * Attach all the sub-devices we can find
118  */
119 void
bha_isa_attach(device_t parent,device_t self,void * aux)120 bha_isa_attach(device_t parent, device_t self, void *aux)
121 {
122 	struct isa_attach_args *ia = aux;
123 	struct bha_softc *sc = device_private(self);
124 	bus_space_tag_t iot = ia->ia_iot;
125 	bus_space_handle_t ioh;
126 	struct bha_probe_data bpd;
127 	isa_chipset_tag_t ic = ia->ia_ic;
128 	int error;
129 
130 	printf("\n");
131 
132 	sc->sc_dev = self;
133 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, BHA_ISA_IOSIZE, 0, &ioh)) {
134 		aprint_error_dev(sc->sc_dev, "can't map i/o space\n");
135 		return;
136 	}
137 
138 	sc->sc_iot = iot;
139 	sc->sc_ioh = ioh;
140 	sc->sc_dmat = ia->ia_dmat;
141 	if (!bha_probe_inquiry(iot, ioh, &bpd)) {
142 		aprint_error_dev(sc->sc_dev, "bha_isa_attach failed\n");
143 		return;
144 	}
145 
146 	sc->sc_dmaflags = 0;
147 	if (bpd.sc_drq != -1) {
148 		if ((error = isa_dmacascade(ic, bpd.sc_drq)) != 0) {
149 			aprint_error_dev(sc->sc_dev,
150 			    " unable to cascade DRQ, error = %d\n", error);
151 			return;
152 		}
153 	} else {
154 		/*
155 		 * We have a VLB controller.  If we're at least both
156 		 * hardware revision E and firmware revision 3.37,
157 		 * we can do 32-bit DMA (earlier revisions are buggy
158 		 * in this regard).
159 		 */
160 		(void) bha_info(sc);
161 		if (strcmp(sc->sc_firmware, "3.37") < 0)
162 		    printf("%s: buggy VLB controller, disabling 32-bit DMA\n",
163 		        device_xname(sc->sc_dev));
164 		else
165 			sc->sc_dmaflags = ISABUS_DMA_32BIT;
166 	}
167 
168 	sc->sc_ih = isa_intr_establish(ic, bpd.sc_irq, IST_EDGE, IPL_BIO,
169 	    bha_intr, sc);
170 	if (sc->sc_ih == NULL) {
171 		aprint_error_dev(sc->sc_dev, "couldn't establish interrupt\n");
172 		return;
173 	}
174 
175 	bha_attach(sc);
176 }
177