2 * Copyright (c) 2000 Jonathan Lemon
3 * Copyright (c) 1999 by Matthew N. Dodd <winter@jurai.net>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification, immediately at the beginning of the file.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
44 #include <geom/geom_disk.h>
46 #include <dev/ida/idavar.h>
47 #include <dev/ida/idareg.h>
49 #include <dev/eisa/eisaconf.h>
51 #define IDA_EISA_IOPORT_START 0x0c88
52 #define IDA_EISA_IOPORT_LEN 0x0017
54 #define IDA_EISA_IRQ_REG 0x0cc0
55 #define IDA_EISA_IRQ_MASK 0xf0
56 #define IDA_EISA_IRQ_15 0x80
57 #define IDA_EISA_IRQ_14 0x40
58 #define IDA_EISA_IRQ_11 0x10
59 #define IDA_EISA_IRQ_10 0x20
62 ida_v1_fifo_full(struct ida_softc *ida)
66 status = ida_inb(ida, R_EISA_SYSTEM_DOORBELL);
67 return ((status & EISA_CHANNEL_CLEAR) == 0);
71 ida_v1_submit(struct ida_softc *ida, struct ida_qcb *qcb)
76 * On these cards, this location is actually for control flags.
77 * Set them to zero and pass in structure size via an I/O port.
79 size = qcb->hwqcb->hdr.size << 2;
80 qcb->hwqcb->hdr.size = 0;
82 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_CLEAR);
83 ida_outl(ida, R_EISA_LIST_ADDR, qcb->hwqcb_busaddr);
84 ida_outw(ida, R_EISA_LIST_LEN, size);
85 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY);
89 ida_v1_done(struct ida_softc *ida)
91 struct ida_hardware_qcb *hwqcb;
95 if ((ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY) == 0)
98 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_BUSY);
99 completed = ida_inl(ida, R_EISA_COMPLETE_ADDR);
100 status = ida_inb(ida, R_EISA_LIST_STATUS);
101 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_CLEAR);
103 if (completed != 0) {
104 hwqcb = (struct ida_hardware_qcb *)
105 ((bus_addr_t)ida->hwqcbs +
106 ((completed & ~3) - ida->hwqcb_busaddr));
107 hwqcb->req.error = status;
114 ida_v1_int_pending(struct ida_softc *ida)
116 return (ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY);
120 ida_v1_int_enable(struct ida_softc *ida, int enable)
123 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, ~EISA_CHANNEL_CLEAR);
124 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY);
125 ida_outb(ida, R_EISA_INT_MASK, INT_ENABLE);
126 ida_outb(ida, R_EISA_SYSTEM_MASK, INT_ENABLE);
127 ida->flags |= IDA_INTERRUPTS;
129 ida_outb(ida, R_EISA_SYSTEM_MASK, INT_DISABLE);
130 ida->flags &= ~IDA_INTERRUPTS;
135 ida_v2_fifo_full(struct ida_softc *ida)
137 return (ida_inl(ida, R_CMD_FIFO) == 0);
141 ida_v2_submit(struct ida_softc *ida, struct ida_qcb *qcb)
143 ida_outl(ida, R_CMD_FIFO, qcb->hwqcb_busaddr);
147 ida_v2_done(struct ida_softc *ida)
149 return (ida_inl(ida, R_DONE_FIFO));
153 ida_v2_int_pending(struct ida_softc *ida)
155 return (ida_inl(ida, R_INT_PENDING));
159 ida_v2_int_enable(struct ida_softc *ida, int enable)
162 ida->flags |= IDA_INTERRUPTS;
164 ida->flags &= ~IDA_INTERRUPTS;
165 ida_outl(ida, R_INT_MASK, enable ? INT_ENABLE : INT_DISABLE);
168 static struct ida_access ida_v1_access = {
176 static struct ida_access ida_v2_access = {
184 static struct ida_board board_id[] = {
185 { 0x0e114001, "Compaq IDA controller",
187 { 0x0e114002, "Compaq IDA-2 controller",
189 { 0x0e114010, "Compaq IAES controller",
191 { 0x0e114020, "Compaq SMART array controller",
193 { 0x0e114030, "Compaq SMART-2/E array controller",
199 static struct ida_board *ida_eisa_match(eisa_id_t);
200 static int ida_eisa_probe(device_t);
201 static int ida_eisa_attach(device_t);
203 static device_method_t ida_eisa_methods[] = {
204 DEVMETHOD(device_probe, ida_eisa_probe),
205 DEVMETHOD(device_attach, ida_eisa_attach),
206 DEVMETHOD(device_detach, ida_detach),
211 static driver_t ida_eisa_driver = {
214 sizeof(struct ida_softc)
217 static devclass_t ida_devclass;
219 static struct ida_board *
220 ida_eisa_match(eisa_id_t id)
224 for (i = 0; board_id[i].board; i++)
225 if (board_id[i].board == id)
226 return (&board_id[i]);
231 ida_eisa_probe(device_t dev)
233 struct ida_board *board;
237 board = ida_eisa_match(eisa_get_id(dev));
240 device_set_desc(dev, board->desc);
242 io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE);
244 switch (IDA_EISA_IRQ_MASK & (inb(IDA_EISA_IRQ_REG + io_base))) {
245 case IDA_EISA_IRQ_15:
248 case IDA_EISA_IRQ_14:
251 case IDA_EISA_IRQ_11:
254 case IDA_EISA_IRQ_10:
258 device_printf(dev, "slot %d, illegal irq setting.\n",
263 eisa_add_iospace(dev, (io_base + IDA_EISA_IOPORT_START),
264 IDA_EISA_IOPORT_LEN, RESVADDR_NONE);
266 eisa_add_intr(dev, irq, EISA_TRIGGER_LEVEL); /* XXX ??? */
272 ida_eisa_attach(device_t dev)
274 struct ida_softc *ida;
275 struct ida_board *board;
279 ida = device_get_softc(dev);
282 board = ida_eisa_match(eisa_get_id(dev));
283 ida->cmd = *board->accessor;
284 ida->flags = board->flags;
286 ida->regs_res_type = SYS_RES_IOPORT;
287 ida->regs_res_id = 0;
288 ida->regs = bus_alloc_resource_any(dev, ida->regs_res_type,
289 &ida->regs_res_id, RF_ACTIVE);
290 if (ida->regs == NULL) {
291 device_printf(dev, "can't allocate register resources\n");
295 error = bus_dma_tag_create(
299 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
300 /* highaddr */ BUS_SPACE_MAXADDR,
302 /* filterarg */ NULL,
303 /* maxsize */ MAXBSIZE,
304 /* nsegments */ IDA_NSEG,
305 /* maxsegsize */ BUS_SPACE_MAXSIZE_32BIT,
306 /* flags */ BUS_DMA_ALLOCNOW,
312 device_printf(dev, "can't allocate DMA tag\n");
318 ida->irq_res_type = SYS_RES_IRQ;
319 ida->irq = bus_alloc_resource_any(dev, ida->irq_res_type, &rid,
320 RF_ACTIVE | RF_SHAREABLE);
321 if (ida->irq == NULL) {
326 error = bus_setup_intr(dev, ida->irq, INTR_TYPE_BIO | INTR_ENTROPY,
327 ida_intr, ida, &ida->ih);
329 device_printf(dev, "can't setup interrupt\n");
334 error = ida_init(ida);
341 ida->flags |= IDA_ATTACHED;
346 DRIVER_MODULE(ida, eisa, ida_eisa_driver, ida_devclass, 0, 0);