FreeBSD/Linux Kernel Cross Reference
sys/dev/aha/aha_mca.c
1 /*-
2 * Copyright (c) 1999 Matthew N. Dodd <winter@jurai.net>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: releng/5.0/sys/dev/aha/aha_mca.c 104710 2002-10-09 08:54:32Z peter $
27 *
28 * Based on aha_isa.c
29 */
30
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34
35 #include <sys/module.h>
36 #include <sys/bus.h>
37 #include <machine/bus.h>
38 #include <machine/resource.h>
39 #include <sys/rman.h>
40
41 #include <i386/isa/isa_dma.h>
42
43 #include <dev/mca/mca_busreg.h>
44 #include <dev/mca/mca_busvar.h>
45
46 #include <dev/aha/ahareg.h>
47
48 static struct mca_ident aha_mca_devs[] = {
49 { 0x0f1f, "Adaptec AHA-1640 SCSI Adapter" },
50 { 0, NULL },
51 };
52
53 #define AHA_MCA_IOPORT_POS MCA_ADP_POS(MCA_POS1)
54 # define AHA_MCA_IOPORT_MASK1 0x07
55 # define AHA_MCA_IOPORT_MASK2 0xc0
56 # define AHA_MCA_IOPORT_SIZE 0x03
57 # define AHA_MCA_IOPORT(pos) (0x30 + \
58 (((u_int32_t)pos & \
59 AHA_MCA_IOPORT_MASK1) << 8) + \
60 (((u_int32_t)pos & \
61 AHA_MCA_IOPORT_MASK2) >> 4))
62
63 #define AHA_MCA_DRQ_POS MCA_ADP_POS(MCA_POS3)
64 # define AHA_MCA_DRQ_MASK 0x0f
65 # define AHA_MCA_DRQ(pos) (pos & AHA_MCA_DRQ_MASK)
66
67 #define AHA_MCA_IRQ_POS MCA_ADP_POS(MCA_POS2)
68 # define AHA_MCA_IRQ_MASK 0x07
69 # define AHA_MCA_IRQ(pos) ((pos & AHA_MCA_IRQ_MASK) + 8)
70
71 /*
72 * Not needed as the board knows its config
73 * internally and the ID will be fetched
74 * via AOP_INQUIRE_SETUP_INFO command.
75 */
76 #define AHA_MCA_SCSIID_POS MCA_ADP_POS(MCA_POS2)
77 #define AHA_MCA_SCSIID_MASK 0xe0
78 #define AHA_MCA_SCSIID(pos) ((pos & AHA_MCA_SCSIID_MASK) >> 5)
79
80 static int
81 aha_mca_probe (device_t dev)
82 {
83 const char * desc;
84 mca_id_t id = mca_get_id(dev);
85 u_int32_t iobase = 0;
86 u_int32_t iosize = 0;
87 u_int8_t drq = 0;
88 u_int8_t irq = 0;
89 u_int8_t pos;
90
91 desc = mca_match_id(id, aha_mca_devs);
92 if (!desc)
93 return (ENXIO);
94 device_set_desc(dev, desc);
95
96 pos = mca_pos_read(dev, AHA_MCA_IOPORT_POS);
97 iobase = AHA_MCA_IOPORT(pos);
98 iosize = AHA_MCA_IOPORT_SIZE;
99
100 pos = mca_pos_read(dev, AHA_MCA_DRQ_POS);
101 drq = AHA_MCA_DRQ(pos);
102
103 pos = mca_pos_read(dev, AHA_MCA_IRQ_POS);
104 irq = AHA_MCA_IRQ(pos);
105
106 mca_add_iospace(dev, iobase, iosize);
107 mca_add_drq(dev, drq);
108 mca_add_irq(dev, irq);
109
110 aha_unit++;
111
112 return (0);
113 }
114
115 static int
116 aha_mca_attach (device_t dev)
117 {
118 struct aha_softc * sc = NULL;
119 struct resource * io = NULL;
120 struct resource * irq = NULL;
121 struct resource * drq = NULL;
122 int error = 0;
123 int unit = device_get_unit(dev);
124 int rid;
125 void * ih;
126
127 rid = 0;
128 io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
129 0, ~0, 1, RF_ACTIVE);
130 if (!io) {
131 device_printf(dev, "No I/O space?!\n");
132 error = ENOMEM;
133 goto bad;
134 }
135
136 rid = 0;
137 irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid,
138 0, ~0, 1, RF_ACTIVE);
139 if (irq == NULL) {
140 device_printf(dev, "No IRQ?!\n");
141 error = ENOMEM;
142 goto bad;
143 }
144
145 rid = 0;
146 drq = bus_alloc_resource(dev, SYS_RES_DRQ, &rid,
147 0, ~0, 1, RF_ACTIVE);
148 if (drq == NULL) {
149 device_printf(dev, "No DRQ?!\n");
150 error = ENOMEM;
151 goto bad;
152 }
153
154 sc = aha_alloc(unit, rman_get_bustag(io), rman_get_bushandle(io));
155 if (sc == NULL) {
156 device_printf(dev, "aha_alloc() failed!\n");
157 error = ENOMEM;
158 goto bad;
159 }
160
161 error = aha_probe(sc);
162 if (error) {
163 device_printf(dev, "aha_probe() failed!\n");
164 goto bad;
165 }
166
167 error = aha_fetch_adapter_info(sc);
168 if (error) {
169 device_printf(dev, "aha_fetch_adapter_info() failed!\n");
170 goto bad;
171 }
172
173 isa_dmacascade(rman_get_start(drq));
174
175 error = bus_dma_tag_create(/* parent */ NULL,
176 /* alignemnt */ 1,
177 /* boundary */ 0,
178 BUS_SPACE_MAXADDR_24BIT,
179 /* highaddr */ BUS_SPACE_MAXADDR,
180 NULL,
181 NULL,
182 /* maxsize */ BUS_SPACE_MAXSIZE_24BIT,
183 /* nsegments */ ~0,
184 /* maxsegsz */ BUS_SPACE_MAXSIZE_24BIT,
185 /* flags */ 0,
186 &sc->parent_dmat);
187 if (error) {
188 device_printf(dev, "bus_dma_tag_create() failed!\n");
189 goto bad;
190 }
191
192 error = aha_init(sc);
193 if (error) {
194 device_printf(dev, "aha_init() failed\n");
195 goto bad;
196 }
197
198 error = aha_attach(sc);
199 if (error) {
200 device_printf(dev, "aha_attach() failed\n");
201 goto bad;
202 }
203
204 error = bus_setup_intr(dev, irq, INTR_TYPE_CAM|INTR_ENTROPY, aha_intr, sc, &ih);
205 if (error) {
206 device_printf(dev, "Unable to register interrupt handler\n");
207 goto bad;
208 }
209
210 return (0);
211
212 bad:
213 aha_free(sc);
214
215 if (io)
216 bus_release_resource(dev, SYS_RES_IOPORT, 0, io);
217 if (irq)
218 bus_release_resource(dev, SYS_RES_IRQ, 0, irq);
219 if (drq)
220 bus_release_resource(dev, SYS_RES_DRQ, 0, drq);
221
222 return (error);
223 }
224
225 static device_method_t aha_mca_methods[] = {
226 DEVMETHOD(device_probe, aha_mca_probe),
227 DEVMETHOD(device_attach, aha_mca_attach),
228
229 { 0, 0 }
230 };
231
232 static driver_t aha_mca_driver = {
233 "aha",
234 aha_mca_methods,
235 1,
236 /*
237 sizeof(struct aha_softc *),
238 */
239 };
240
241 static devclass_t aha_devclass;
242
243 DRIVER_MODULE(aha, mca, aha_mca_driver, aha_devclass, 0, 0);
Cache object: 25405092d21802e21c8ac8bfa55584df
|