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 $
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
36 #include <sys/devicestat.h>
39 #include <machine/bus_pio.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
44 #include <dev/ida/idavar.h>
45 #include <dev/ida/idareg.h>
47 #include <dev/eisa/eisaconf.h>
49 #define IDA_EISA_IOPORT_START 0x0c88
50 #define IDA_EISA_IOPORT_LEN 0x0017
52 #define IDA_EISA_IRQ_REG 0x0cc0
53 #define IDA_EISA_IRQ_MASK 0xf0
54 #define IDA_EISA_IRQ_15 0x80
55 #define IDA_EISA_IRQ_14 0x40
56 #define IDA_EISA_IRQ_11 0x10
57 #define IDA_EISA_IRQ_10 0x20
60 ida_v1_fifo_full(struct ida_softc *ida)
64 status = ida_inb(ida, R_EISA_SYSTEM_DOORBELL);
65 return ((status & EISA_CHANNEL_CLEAR) == 0);
69 ida_v1_submit(struct ida_softc *ida, struct ida_qcb *qcb)
74 * On these cards, this location is actually for control flags.
75 * Set them to zero and pass in structure size via an I/O port.
77 size = qcb->hwqcb->hdr.size << 2;
78 qcb->hwqcb->hdr.size = 0;
80 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_CLEAR);
81 ida_outl(ida, R_EISA_LIST_ADDR, qcb->hwqcb_busaddr);
82 ida_outw(ida, R_EISA_LIST_LEN, size);
83 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY);
87 ida_v1_done(struct ida_softc *ida)
89 struct ida_hardware_qcb *hwqcb;
93 if ((ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY) == 0)
96 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, EISA_CHANNEL_BUSY);
97 completed = ida_inl(ida, R_EISA_COMPLETE_ADDR);
98 status = ida_inb(ida, R_EISA_LIST_STATUS);
99 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_CLEAR);
101 if (completed != 0) {
102 hwqcb = (struct ida_hardware_qcb *)
103 ((bus_addr_t)ida->hwqcbs +
104 ((completed & ~3) - ida->hwqcb_busaddr));
105 hwqcb->req.error = status;
112 ida_v1_int_pending(struct ida_softc *ida)
114 return (ida_inb(ida, R_EISA_SYSTEM_DOORBELL) & EISA_CHANNEL_BUSY);
118 ida_v1_int_enable(struct ida_softc *ida, int enable)
121 ida_outb(ida, R_EISA_SYSTEM_DOORBELL, ~EISA_CHANNEL_CLEAR);
122 ida_outb(ida, R_EISA_LOCAL_DOORBELL, EISA_CHANNEL_BUSY);
123 ida_outb(ida, R_EISA_INT_MASK, INT_ENABLE);
124 ida_outb(ida, R_EISA_SYSTEM_MASK, INT_ENABLE);
125 ida->flags |= IDA_INTERRUPTS;
127 ida_outb(ida, R_EISA_SYSTEM_MASK, INT_DISABLE);
128 ida->flags &= ~IDA_INTERRUPTS;
133 ida_v2_fifo_full(struct ida_softc *ida)
135 return (ida_inl(ida, R_CMD_FIFO) == 0);
139 ida_v2_submit(struct ida_softc *ida, struct ida_qcb *qcb)
141 ida_outl(ida, R_CMD_FIFO, qcb->hwqcb_busaddr);
145 ida_v2_done(struct ida_softc *ida)
147 return (ida_inl(ida, R_DONE_FIFO));
151 ida_v2_int_pending(struct ida_softc *ida)
153 return (ida_inl(ida, R_INT_PENDING));
157 ida_v2_int_enable(struct ida_softc *ida, int enable)
160 ida->flags |= IDA_INTERRUPTS;
162 ida->flags &= ~IDA_INTERRUPTS;
163 ida_outl(ida, R_INT_MASK, enable ? INT_ENABLE : INT_DISABLE);
166 static struct ida_access ida_v1_access = {
174 static struct ida_access ida_v2_access = {
182 static struct ida_board board_id[] = {
183 { 0x0e114001, "Compaq IDA controller",
185 { 0x0e114002, "Compaq IDA-2 controller",
187 { 0x0e114010, "Compaq IAES controller",
189 { 0x0e114020, "Compaq SMART array controller",
191 { 0x0e114030, "Compaq SMART-2/E array controller",
197 static struct ida_board *ida_eisa_match(eisa_id_t);
198 static int ida_eisa_probe(device_t);
199 static int ida_eisa_attach(device_t);
201 static device_method_t ida_eisa_methods[] = {
202 DEVMETHOD(device_probe, ida_eisa_probe),
203 DEVMETHOD(device_attach, ida_eisa_attach),
204 DEVMETHOD(device_detach, ida_detach),
209 static driver_t ida_eisa_driver = {
212 sizeof(struct ida_softc)
215 static devclass_t ida_devclass;
217 static struct ida_board *
218 ida_eisa_match(eisa_id_t id)
222 for (i = 0; board_id[i].board; i++)
223 if (board_id[i].board == id)
224 return (&board_id[i]);
229 ida_eisa_probe(device_t dev)
231 struct ida_board *board;
235 board = ida_eisa_match(eisa_get_id(dev));
238 device_set_desc(dev, board->desc);
240 io_base = (eisa_get_slot(dev) * EISA_SLOT_SIZE);
242 switch (IDA_EISA_IRQ_MASK & (inb(IDA_EISA_IRQ_REG + io_base))) {
243 case IDA_EISA_IRQ_15:
246 case IDA_EISA_IRQ_14:
249 case IDA_EISA_IRQ_11:
252 case IDA_EISA_IRQ_10:
256 device_printf(dev, "slot %d, illegal irq setting.\n",
261 eisa_add_iospace(dev, (io_base + IDA_EISA_IOPORT_START),
262 IDA_EISA_IOPORT_LEN, RESVADDR_NONE);
264 eisa_add_intr(dev, irq, EISA_TRIGGER_LEVEL); /* XXX ??? */
270 ida_eisa_attach(device_t dev)
272 struct ida_softc *ida;
273 struct ida_board *board;
277 ida = device_get_softc(dev);
280 board = ida_eisa_match(eisa_get_id(dev));
281 ida->cmd = *board->accessor;
282 ida->flags = board->flags;
284 ida->regs_res_type = SYS_RES_IOPORT;
285 ida->regs_res_id = 0;
286 ida->regs = bus_alloc_resource(dev, ida->regs_res_type,
287 &ida->regs_res_id, 0, ~0, 1, RF_ACTIVE);
288 if (ida->regs == NULL) {
289 device_printf(dev, "can't allocate register resources\n");
293 error = bus_dma_tag_create(
297 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
298 /* highaddr */ BUS_SPACE_MAXADDR,
300 /* filterarg */ NULL,
301 /* maxsize */ MAXBSIZE,
302 /* nsegments */ IDA_NSEG,
303 /* maxsegsize */ BUS_SPACE_MAXSIZE_32BIT,
304 /* flags */ BUS_DMA_ALLOCNOW,
308 device_printf(dev, "can't allocate DMA tag\n");
314 ida->irq_res_type = SYS_RES_IRQ;
315 ida->irq = bus_alloc_resource(dev, ida->irq_res_type, &rid,
316 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
317 if (ida->irq == NULL) {
322 error = bus_setup_intr(dev, ida->irq, INTR_TYPE_BIO,
323 ida_intr, ida, &ida->ih);
325 device_printf(dev, "can't setup interrupt\n");
330 error = ida_init(ida);
337 ida->flags |= IDA_ATTACHED;
342 DRIVER_MODULE(ida, eisa, ida_eisa_driver, ida_devclass, 0, 0);