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_pio.h>
41 #include <machine/bus.h>
42 #include <machine/resource.h>
45 #include <geom/geom_disk.h>
47 #include <dev/ida/idavar.h>
48 #include <dev/ida/idareg.h>
50 #include <dev/eisa/eisaconf.h>
52 #define IDA_EISA_IOPORT_START 0x0c88
53 #define IDA_EISA_IOPORT_LEN 0x0017
55 #define IDA_EISA_IRQ_REG 0x0cc0
56 #define IDA_EISA_IRQ_MASK 0xf0
57 #define IDA_EISA_IRQ_15 0x80
58 #define IDA_EISA_IRQ_14 0x40
59 #define IDA_EISA_IRQ_11 0x10
60 #define IDA_EISA_IRQ_10 0x20
63 ida_v1_fifo_full(struct ida_softc *ida)
67 status = ida_inb(ida, R_EISA_SYSTEM_DOORBELL);
68 return ((status & EISA_CHANNEL_CLEAR) == 0);
72 ida_v1_submit(struct ida_softc *ida, struct ida_qcb *qcb)
77 * On these cards, this location is actually for control flags.
78 * Set them to zero and pass in structure size via an I/O port.
80 size = qcb->hwqcb->hdr.size << 2;
81 qcb->hwqcb->hdr.size = 0;
83 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_CLEAR);
84 ida_outl(ida, R_EISA_LIST_ADDR, qcb->hwqcb_busaddr);
85 ida_outw(ida, R_EISA_LIST_LEN, size);
86 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY);
90 ida_v1_done(struct ida_softc *ida)
92 struct ida_hardware_qcb *hwqcb;
96 if ((ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY) == 0)
99 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_BUSY);
100 completed = ida_inl(ida, R_EISA_COMPLETE_ADDR);
101 status = ida_inb(ida, R_EISA_LIST_STATUS);
102 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_CLEAR);
104 if (completed != 0) {
105 hwqcb = (struct ida_hardware_qcb *)
106 ((bus_addr_t)ida->hwqcbs +
107 ((completed & ~3) - ida->hwqcb_busaddr));
108 hwqcb->req.error = status;
115 ida_v1_int_pending(struct ida_softc *ida)
117 return (ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY);
121 ida_v1_int_enable(struct ida_softc *ida, int enable)
124 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, ~EISA_CHANNEL_CLEAR);
125 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY);
126 ida_outb(ida, R_EISA_INT_MASK, INT_ENABLE);
127 ida_outb(ida, R_EISA_SYSTEM_MASK, INT_ENABLE);
128 ida->flags |= IDA_INTERRUPTS;
130 ida_outb(ida, R_EISA_SYSTEM_MASK, INT_DISABLE);
131 ida->flags &= ~IDA_INTERRUPTS;
136 ida_v2_fifo_full(struct ida_softc *ida)
138 return (ida_inl(ida, R_CMD_FIFO) == 0);
142 ida_v2_submit(struct ida_softc *ida, struct ida_qcb *qcb)
144 ida_outl(ida, R_CMD_FIFO, qcb->hwqcb_busaddr);
148 ida_v2_done(struct ida_softc *ida)
150 return (ida_inl(ida, R_DONE_FIFO));
154 ida_v2_int_pending(struct ida_softc *ida)
156 return (ida_inl(ida, R_INT_PENDING));
160 ida_v2_int_enable(struct ida_softc *ida, int enable)
163 ida->flags |= IDA_INTERRUPTS;
165 ida->flags &= ~IDA_INTERRUPTS;
166 ida_outl(ida, R_INT_MASK, enable ? INT_ENABLE : INT_DISABLE);
169 static struct ida_access ida_v1_access = {
177 static struct ida_access ida_v2_access = {
185 static struct ida_board board_id[] = {
186 { 0x0e114001, "Compaq IDA controller",
188 { 0x0e114002, "Compaq IDA-2 controller",
190 { 0x0e114010, "Compaq IAES controller",
192 { 0x0e114020, "Compaq SMART array controller",
194 { 0x0e114030, "Compaq SMART-2/E array controller",
200 static struct ida_board *ida_eisa_match(eisa_id_t);
201 static int ida_eisa_probe(device_t);
202 static int ida_eisa_attach(device_t);
204 static device_method_t ida_eisa_methods[] = {
205 DEVMETHOD(device_probe, ida_eisa_probe),
206 DEVMETHOD(device_attach, ida_eisa_attach),
207 DEVMETHOD(device_detach, ida_detach),
212 static driver_t ida_eisa_driver = {
215 sizeof(struct ida_softc)
218 static devclass_t ida_devclass;
220 static struct ida_board *
221 ida_eisa_match(eisa_id_t id)
225 for (i = 0; board_id[i].board; i++)
226 if (board_id[i].board == id)
227 return (&board_id[i]);
232 ida_eisa_probe(device_t dev)
234 struct ida_board *board;
238 board = ida_eisa_match(eisa_get_id(dev));
241 device_set_desc(dev, board->desc);
243 io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE);
245 switch (IDA_EISA_IRQ_MASK & (inb(IDA_EISA_IRQ_REG + io_base))) {
246 case IDA_EISA_IRQ_15:
249 case IDA_EISA_IRQ_14:
252 case IDA_EISA_IRQ_11:
255 case IDA_EISA_IRQ_10:
259 device_printf(dev, "slot %d, illegal irq setting.\n",
264 eisa_add_iospace(dev, (io_base + IDA_EISA_IOPORT_START),
265 IDA_EISA_IOPORT_LEN, RESVADDR_NONE);
267 eisa_add_intr(dev, irq, EISA_TRIGGER_LEVEL); /* XXX ??? */
273 ida_eisa_attach(device_t dev)
275 struct ida_softc *ida;
276 struct ida_board *board;
280 ida = device_get_softc(dev);
283 board = ida_eisa_match(eisa_get_id(dev));
284 ida->cmd = *board->accessor;
285 ida->flags = board->flags;
287 ida->regs_res_type = SYS_RES_IOPORT;
288 ida->regs_res_id = 0;
289 ida->regs = bus_alloc_resource_any(dev, ida->regs_res_type,
290 &ida->regs_res_id, RF_ACTIVE);
291 if (ida->regs == NULL) {
292 device_printf(dev, "can't allocate register resources\n");
296 error = bus_dma_tag_create(
300 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
301 /* highaddr */ BUS_SPACE_MAXADDR,
303 /* filterarg */ NULL,
304 /* maxsize */ MAXBSIZE,
305 /* nsegments */ IDA_NSEG,
306 /* maxsegsize */ BUS_SPACE_MAXSIZE_32BIT,
307 /* flags */ BUS_DMA_ALLOCNOW,
313 device_printf(dev, "can't allocate DMA tag\n");
319 ida->irq_res_type = SYS_RES_IRQ;
320 ida->irq = bus_alloc_resource_any(dev, ida->irq_res_type, &rid,
321 RF_ACTIVE | RF_SHAREABLE);
322 if (ida->irq == NULL) {
327 error = bus_setup_intr(dev, ida->irq, INTR_TYPE_BIO | INTR_ENTROPY,
328 ida_intr, ida, &ida->ih);
330 device_printf(dev, "can't setup interrupt\n");
335 error = ida_init(ida);
342 ida->flags |= IDA_ATTACHED;
347 DRIVER_MODULE(ida, eisa, ida_eisa_driver, ida_devclass, 0, 0);