2 * Copyright (c) 1999,2000 Jonathan Lemon
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/param.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
35 #include <sys/devicestat.h>
38 #include <machine/bus_memio.h>
39 #include <machine/bus_pio.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
44 #include <pci/pcireg.h>
45 #include <pci/pcivar.h>
47 #include <dev/ida/idavar.h>
48 #include <dev/ida/idareg.h>
50 #define IDA_PCI_MAX_DMA_ADDR 0xFFFFFFFF
51 #define IDA_PCI_MAX_DMA_COUNT 0xFFFFFFFF
53 #define IDA_PCI_MEMADDR (PCIR_MAPS + 4) /* Mem I/O Address */
55 #define IDA_DEVICEID_SMART 0xAE100E11
56 #define IDA_DEVICEID_DEC_SMART 0x00461011
59 ida_v3_fifo_full(struct ida_softc *ida)
61 return (ida_inl(ida, R_CMD_FIFO) == 0);
65 ida_v3_submit(struct ida_softc *ida, struct ida_qcb *qcb)
67 ida_outl(ida, R_CMD_FIFO, qcb->hwqcb_busaddr);
71 ida_v3_done(struct ida_softc *ida)
73 return (ida_inl(ida, R_DONE_FIFO));
77 ida_v3_int_pending(struct ida_softc *ida)
79 return (ida_inl(ida, R_INT_PENDING));
83 ida_v3_int_enable(struct ida_softc *ida, int enable)
85 ida_outl(ida, R_INT_MASK, enable ? INT_ENABLE : INT_DISABLE);
89 ida_v4_fifo_full(struct ida_softc *ida)
91 return (ida_inl(ida, R_42XX_REQUEST) != 0);
95 ida_v4_submit(struct ida_softc *ida, struct ida_qcb *qcb)
97 ida_outl(ida, R_42XX_REQUEST, qcb->hwqcb_busaddr);
101 ida_v4_done(struct ida_softc *ida)
103 bus_addr_t completed;
105 completed = ida_inl(ida, R_42XX_REPLY);
107 return (0); /* fifo is empty */
108 ida_outl(ida, R_42XX_REPLY, 0); /* confirm read */
113 ida_v4_int_pending(struct ida_softc *ida)
115 return (ida_inl(ida, R_42XX_STATUS) & STATUS_42XX_INT_PENDING);
119 ida_v4_int_enable(struct ida_softc *ida, int enable)
121 ida_outl(ida, R_42XX_INT_MASK,
122 enable ? INT_ENABLE_42XX : INT_DISABLE_42XX);
125 static struct ida_access ida_v3_access = {
133 static struct ida_access ida_v4_access = {
141 static struct ida_board board_id[] = {
142 { 0x4030, "Compaq SMART-2/P array controller", &ida_v3_access },
143 { 0x4031, "Compaq SMART-2SL array controller", &ida_v3_access },
144 { 0x4032, "Compaq Smart Array 3200 controller", &ida_v3_access },
145 { 0x4033, "Compaq Smart Array 3100ES controller", &ida_v3_access },
146 { 0x4034, "Compaq Smart Array 221 controller", &ida_v3_access },
148 { 0x4040, "Compaq Integrated Array controller", &ida_v4_access },
149 { 0x4050, "Compaq Smart Array 4200 controller", &ida_v4_access },
150 { 0x4051, "Compaq Smart Array 4250ES controller", &ida_v4_access },
151 { 0x4058, "Compaq Smart Array 431 controller", &ida_v4_access },
153 { IDA_DEVICEID_DEC_SMART,
154 "DEC/Compaq Smart Array 4200 controller", &ida_v4_access },
159 static int ida_pci_probe(device_t dev);
160 static int ida_pci_attach(device_t dev);
162 static device_method_t ida_pci_methods[] = {
163 DEVMETHOD(device_probe, ida_pci_probe),
164 DEVMETHOD(device_attach, ida_pci_attach),
165 DEVMETHOD(device_detach, ida_detach),
167 DEVMETHOD(bus_print_child, bus_generic_print_child),
172 static driver_t ida_pci_driver = {
175 sizeof(struct ida_softc)
178 static devclass_t ida_devclass;
180 static struct ida_board *
181 ida_pci_match(u_int32_t id)
185 for (i = 0; board_id[i].board; i++)
186 if (board_id[i].board == id)
187 return (&board_id[i]);
192 ida_pci_probe(device_t dev)
194 struct ida_board *board = NULL;
195 u_int32_t id = pci_get_devid(dev);
197 if (id == IDA_DEVICEID_SMART)
198 board = ida_pci_match(pci_get_subdevice(dev));
199 if (id == IDA_DEVICEID_DEC_SMART)
200 board = ida_pci_match(id);
202 device_set_desc(dev, board->desc);
209 ida_pci_attach(device_t dev)
211 struct ida_board *board;
212 struct ida_softc *ida;
216 command = pci_read_config(dev, PCIR_COMMAND, 1);
219 * it appears that this board only does MEMIO access.
221 if ((command & PCIM_CMD_MEMEN) == 0) {
222 device_printf(dev, "Only memory mapped I/O is supported\n");
226 ida = (struct ida_softc *)device_get_softc(dev);
229 board = ida_pci_match(pci_get_subdevice(dev));
231 board = ida_pci_match(pci_get_devid(dev));
232 ida->cmd = *board->accessor;
234 ida->regs_res_type = SYS_RES_MEMORY;
235 ida->regs_res_id = IDA_PCI_MEMADDR;
236 ida->regs = bus_alloc_resource(dev, ida->regs_res_type,
237 &ida->regs_res_id, 0, ~0, 1, RF_ACTIVE);
238 if (ida->regs == NULL) {
239 device_printf(dev, "can't allocate register resources\n");
243 error = bus_dma_tag_create(/*parent*/NULL, /*alignment*/1,
244 /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR_32BIT,
245 /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL,
246 /*maxsize*/MAXBSIZE, /*nsegments*/IDA_NSEG,
247 /*maxsegsize*/BUS_SPACE_MAXSIZE_32BIT, /*flags*/BUS_DMA_ALLOCNOW,
250 device_printf(dev, "can't allocate DMA tag\n");
256 ida->irq_res_type = SYS_RES_IRQ;
257 ida->irq = bus_alloc_resource(dev, ida->irq_res_type, &rid,
258 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
259 if (ida->irq == NULL) {
263 error = bus_setup_intr(dev, ida->irq, INTR_TYPE_BIO,
264 ida_intr, ida, &ida->ih);
266 device_printf(dev, "can't setup interrupt\n");
271 error = ida_init(ida);
277 ida->flags = IDA_ATTACHED;
282 DRIVER_MODULE(ida, pci, ida_pci_driver, ida_devclass, 0, 0);