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
27 * $FreeBSD: src/sys/dev/ida/ida_eisa.c,v 1.1.2.4 2001/07/30 20:29:58 jlemon Exp $
28 * $DragonFly: src/sys/dev/raid/ida/ida_eisa.c,v 1.3 2003/08/07 21:17:09 dillon Exp $
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
37 #include <sys/devicestat.h>
40 #include <machine/bus_pio.h>
41 #include <machine/bus.h>
42 #include <machine/resource.h>
48 #include <bus/eisa/eisaconf.h>
50 #define IDA_EISA_IOPORT_START 0x0c88
51 #define IDA_EISA_IOPORT_LEN 0x0017
53 #define IDA_EISA_IRQ_REG 0x0cc0
54 #define IDA_EISA_IRQ_MASK 0xf0
55 #define IDA_EISA_IRQ_15 0x80
56 #define IDA_EISA_IRQ_14 0x40
57 #define IDA_EISA_IRQ_11 0x10
58 #define IDA_EISA_IRQ_10 0x20
61 ida_v1_fifo_full(struct ida_softc *ida)
65 status = ida_inb(ida, R_EISA_SYSTEM_DOORBELL);
66 return ((status & EISA_CHANNEL_CLEAR) == 0);
70 ida_v1_submit(struct ida_softc *ida, struct ida_qcb *qcb)
75 * On these cards, this location is actually for control flags.
76 * Set them to zero and pass in structure size via an I/O port.
78 size = qcb->hwqcb->hdr.size << 2;
79 qcb->hwqcb->hdr.size = 0;
81 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_CLEAR);
82 ida_outl(ida, R_EISA_LIST_ADDR, qcb->hwqcb_busaddr);
83 ida_outw(ida, R_EISA_LIST_LEN, size);
84 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY);
88 ida_v1_done(struct ida_softc *ida)
90 struct ida_hardware_qcb *hwqcb;
94 if ((ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY) == 0)
97 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_BUSY);
98 completed = ida_inl(ida, R_EISA_COMPLETE_ADDR);
99 status = ida_inb(ida, R_EISA_LIST_STATUS);
100 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_CLEAR);
102 if (completed != 0) {
103 hwqcb = (struct ida_hardware_qcb *)
104 ((bus_addr_t)ida->hwqcbs +
105 ((completed & ~3) - ida->hwqcb_busaddr));
106 hwqcb->req.error = status;
113 ida_v1_int_pending(struct ida_softc *ida)
115 return (ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY);
119 ida_v1_int_enable(struct ida_softc *ida, int enable)
122 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, ~EISA_CHANNEL_CLEAR);
123 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY);
124 ida_outb(ida, R_EISA_INT_MASK, INT_ENABLE);
125 ida_outb(ida, R_EISA_SYSTEM_MASK, INT_ENABLE);
126 ida->flags |= IDA_INTERRUPTS;
128 ida_outb(ida, R_EISA_SYSTEM_MASK, INT_DISABLE);
129 ida->flags &= ~IDA_INTERRUPTS;
134 ida_v2_fifo_full(struct ida_softc *ida)
136 return (ida_inl(ida, R_CMD_FIFO) == 0);
140 ida_v2_submit(struct ida_softc *ida, struct ida_qcb *qcb)
142 ida_outl(ida, R_CMD_FIFO, qcb->hwqcb_busaddr);
146 ida_v2_done(struct ida_softc *ida)
148 return (ida_inl(ida, R_DONE_FIFO));
152 ida_v2_int_pending(struct ida_softc *ida)
154 return (ida_inl(ida, R_INT_PENDING));
158 ida_v2_int_enable(struct ida_softc *ida, int enable)
161 ida->flags |= IDA_INTERRUPTS;
163 ida->flags &= ~IDA_INTERRUPTS;
164 ida_outl(ida, R_INT_MASK, enable ? INT_ENABLE : INT_DISABLE);
167 static struct ida_access ida_v1_access = {
175 static struct ida_access ida_v2_access = {
183 static struct ida_board board_id[] = {
184 { 0x0e114001, "Compaq IDA controller",
186 { 0x0e114002, "Compaq IDA-2 controller",
188 { 0x0e114010, "Compaq IAES controller",
190 { 0x0e114020, "Compaq SMART array controller",
192 { 0x0e114030, "Compaq SMART-2/E array controller",
198 static struct ida_board *ida_eisa_match(eisa_id_t);
199 static int ida_eisa_probe(device_t);
200 static int ida_eisa_attach(device_t);
202 static device_method_t ida_eisa_methods[] = {
203 DEVMETHOD(device_probe, ida_eisa_probe),
204 DEVMETHOD(device_attach, ida_eisa_attach),
205 DEVMETHOD(device_detach, ida_detach),
210 static driver_t ida_eisa_driver = {
213 sizeof(struct ida_softc)
216 static devclass_t ida_devclass;
218 static struct ida_board *
219 ida_eisa_match(eisa_id_t id)
223 for (i = 0; board_id[i].board; i++)
224 if (board_id[i].board == id)
225 return (&board_id[i]);
230 ida_eisa_probe(device_t dev)
232 struct ida_board *board;
236 board = ida_eisa_match(eisa_get_id(dev));
239 device_set_desc(dev, board->desc);
241 io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE);
243 switch (IDA_EISA_IRQ_MASK & (inb(IDA_EISA_IRQ_REG + io_base))) {
244 case IDA_EISA_IRQ_15:
247 case IDA_EISA_IRQ_14:
250 case IDA_EISA_IRQ_11:
253 case IDA_EISA_IRQ_10:
257 device_printf(dev, "slot %d, illegal irq setting.\n",
262 eisa_add_iospace(dev, (io_base + IDA_EISA_IOPORT_START),
263 IDA_EISA_IOPORT_LEN, RESVADDR_NONE);
265 eisa_add_intr(dev, irq, EISA_TRIGGER_LEVEL); /* XXX ??? */
271 ida_eisa_attach(device_t dev)
273 struct ida_softc *ida;
274 struct ida_board *board;
278 ida = device_get_softc(dev);
281 board = ida_eisa_match(eisa_get_id(dev));
282 ida->cmd = *board->accessor;
283 ida->flags = board->flags;
285 ida->regs_res_type = SYS_RES_IOPORT;
286 ida->regs_res_id = 0;
287 ida->regs = bus_alloc_resource(dev, ida->regs_res_type,
288 &ida->regs_res_id, 0, ~0, 1, RF_ACTIVE);
289 if (ida->regs == NULL) {
290 device_printf(dev, "can't allocate register resources\n");
294 error = bus_dma_tag_create(
298 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
299 /* highaddr */ BUS_SPACE_MAXADDR,
301 /* filterarg */ NULL,
302 /* maxsize */ MAXBSIZE,
303 /* nsegments */ IDA_NSEG,
304 /* maxsegsize */ BUS_SPACE_MAXSIZE_32BIT,
305 /* flags */ BUS_DMA_ALLOCNOW,
309 device_printf(dev, "can't allocate DMA tag\n");
315 ida->irq_res_type = SYS_RES_IRQ;
316 ida->irq = bus_alloc_resource(dev, ida->irq_res_type, &rid,
317 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
318 if (ida->irq == NULL) {
323 error = bus_setup_intr(dev, ida->irq, INTR_TYPE_BIO,
324 ida_intr, ida, &ida->ih);
326 device_printf(dev, "can't setup interrupt\n");
331 error = ida_init(ida);
338 ida->flags |= IDA_ATTACHED;
343 DRIVER_MODULE(ida, eisa, ida_eisa_driver, ida_devclass, 0, 0);