2 * Copyright (c) 1999 Matthew N. Dodd <winter@jurai.net>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/kernel.h>
36 #include <sys/mutex.h>
38 #include <sys/module.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
44 #include <isa/isavar.h>
46 #include <dev/mca/mca_busreg.h>
47 #include <dev/mca/mca_busvar.h>
49 #include <dev/aha/ahareg.h>
51 static struct mca_ident aha_mca_devs[] = {
52 { 0x0f1f, "Adaptec AHA-1640 SCSI Adapter" },
56 #define AHA_MCA_IOPORT_POS MCA_ADP_POS(MCA_POS1)
57 # define AHA_MCA_IOPORT_MASK1 0x07
58 # define AHA_MCA_IOPORT_MASK2 0xc0
59 # define AHA_MCA_IOPORT_SIZE 0x03
60 # define AHA_MCA_IOPORT(pos) (0x30 + \
62 AHA_MCA_IOPORT_MASK1) << 8) + \
64 AHA_MCA_IOPORT_MASK2) >> 4))
66 #define AHA_MCA_DRQ_POS MCA_ADP_POS(MCA_POS3)
67 # define AHA_MCA_DRQ_MASK 0x0f
68 # define AHA_MCA_DRQ(pos) (pos & AHA_MCA_DRQ_MASK)
70 #define AHA_MCA_IRQ_POS MCA_ADP_POS(MCA_POS2)
71 # define AHA_MCA_IRQ_MASK 0x07
72 # define AHA_MCA_IRQ(pos) ((pos & AHA_MCA_IRQ_MASK) + 8)
75 * Not needed as the board knows its config
76 * internally and the ID will be fetched
77 * via AOP_INQUIRE_SETUP_INFO command.
79 #define AHA_MCA_SCSIID_POS MCA_ADP_POS(MCA_POS2)
80 #define AHA_MCA_SCSIID_MASK 0xe0
81 #define AHA_MCA_SCSIID(pos) ((pos & AHA_MCA_SCSIID_MASK) >> 5)
84 aha_mca_probe (device_t dev)
87 mca_id_t id = mca_get_id(dev);
94 desc = mca_match_id(id, aha_mca_devs);
97 device_set_desc(dev, desc);
99 pos = mca_pos_read(dev, AHA_MCA_IOPORT_POS);
100 iobase = AHA_MCA_IOPORT(pos);
101 iosize = AHA_MCA_IOPORT_SIZE;
103 pos = mca_pos_read(dev, AHA_MCA_DRQ_POS);
104 drq = AHA_MCA_DRQ(pos);
106 pos = mca_pos_read(dev, AHA_MCA_IRQ_POS);
107 irq = AHA_MCA_IRQ(pos);
109 mca_add_iospace(dev, iobase, iosize);
110 mca_add_drq(dev, drq);
111 mca_add_irq(dev, irq);
117 aha_mca_attach (device_t dev)
119 struct aha_softc * sc = device_get_softc(dev);
121 int unit = device_get_unit(dev);
125 sc->port = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->portrid,
127 if (sc->port == NULL) {
128 device_printf(dev, "No I/O space?!\n");
133 sc->irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irqrid,
135 if (sc->irq == NULL) {
136 device_printf(dev, "No IRQ?!\n");
141 sc->drq = bus_alloc_resource_any(dev, SYS_RES_DRQ, &sc->drqrid,
143 if (sc->drq == NULL) {
144 device_printf(dev, "No DRQ?!\n");
148 aha_alloc(sc, unit, rman_get_bustag(sc->port),
149 rman_get_bushandle(sc->port));
150 error = aha_probe(sc);
152 device_printf(dev, "aha_probe() failed!\n");
156 error = aha_fetch_adapter_info(sc);
158 device_printf(dev, "aha_fetch_adapter_info() failed!\n");
162 isa_dmacascade(rman_get_start(sc->drq));
164 error = bus_dma_tag_create(
168 /* lowaddr */ BUS_SPACE_MAXADDR_24BIT,
169 /* highaddr */ BUS_SPACE_MAXADDR,
171 /* filterarg */ NULL,
172 /* maxsize */ BUS_SPACE_MAXSIZE_24BIT,
174 /* maxsegsz */ BUS_SPACE_MAXSIZE_24BIT,
176 /* lockfunc */ busdma_lock_mutex,
177 /* lockarg */ &Giant,
180 device_printf(dev, "bus_dma_tag_create() failed!\n");
184 error = aha_init(sc);
186 device_printf(dev, "aha_init() failed\n");
190 error = aha_attach(sc);
192 device_printf(dev, "aha_attach() failed\n");
196 error = bus_setup_intr(dev, sc->irq, INTR_TYPE_CAM | INTR_ENTROPY,
197 NULL, aha_intr, sc, &ih);
199 device_printf(dev, "Unable to register interrupt handler\n");
207 bus_free_resource(dev, SYS_RES_IOPORT, sc->port);
208 bus_free_resource(dev, SYS_RES_IRQ, sc->irq);
209 bus_free_resource(dev, SYS_RES_DRQ, sc->drq);
213 static device_method_t aha_mca_methods[] = {
214 DEVMETHOD(device_probe, aha_mca_probe),
215 DEVMETHOD(device_attach, aha_mca_attach),
220 static driver_t aha_mca_driver = {
225 sizeof(struct aha_softc *),
229 static devclass_t aha_devclass;
231 DRIVER_MODULE(aha, mca, aha_mca_driver, aha_devclass, 0, 0);
232 MODULE_DEPEND(aha, mca, 1, 1, 1);