ida_pci.c revision 63934
1/*- 2 * Copyright (c) 1999,2000 Jonathan Lemon 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 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. 13 * 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 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: head/sys/dev/ida/ida_pci.c 63934 2000-07-27 22:24:44Z jlemon $ 27 */ 28 29#include <sys/param.h> 30#include <sys/systm.h> 31#include <sys/kernel.h> 32 33#include <sys/bio.h> 34#include <sys/bus.h> 35#include <sys/devicestat.h> 36#include <sys/disk.h> 37 38#include <machine/bus_memio.h> 39#include <machine/bus_pio.h> 40#include <machine/bus.h> 41#include <machine/resource.h> 42#include <sys/rman.h> 43 44#include <pci/pcireg.h> 45#include <pci/pcivar.h> 46 47#include <dev/ida/idavar.h> 48#include <dev/ida/idareg.h> 49 50#define IDA_PCI_MAX_DMA_ADDR 0xFFFFFFFF 51#define IDA_PCI_MAX_DMA_COUNT 0xFFFFFFFF 52 53#define IDA_PCI_MEMADDR (PCIR_MAPS + 4) /* Mem I/O Address */ 54 55#define IDA_DEVICEID_SMART 0xAE100E11 56#define IDA_DEVICEID_DEC_SMART 0x00461011 57#define IDA_DEVICEID_NCR_53C1510 0x00101000 58 59static int 60ida_v3_fifo_full(struct ida_softc *ida) 61{ 62 return (ida_inl(ida, R_CMD_FIFO) == 0); 63} 64 65static void 66ida_v3_submit(struct ida_softc *ida, struct ida_qcb *qcb) 67{ 68 ida_outl(ida, R_CMD_FIFO, qcb->hwqcb_busaddr); 69} 70 71static bus_addr_t 72ida_v3_done(struct ida_softc *ida) 73{ 74 return (ida_inl(ida, R_DONE_FIFO)); 75} 76 77static int 78ida_v3_int_pending(struct ida_softc *ida) 79{ 80 return (ida_inl(ida, R_INT_PENDING)); 81} 82 83static void 84ida_v3_int_enable(struct ida_softc *ida, int enable) 85{ 86 ida_outl(ida, R_INT_MASK, enable ? INT_ENABLE : INT_DISABLE); 87} 88 89static int 90ida_v4_fifo_full(struct ida_softc *ida) 91{ 92 return (ida_inl(ida, R_42XX_REQUEST) != 0); 93} 94 95static void 96ida_v4_submit(struct ida_softc *ida, struct ida_qcb *qcb) 97{ 98 ida_outl(ida, R_42XX_REQUEST, qcb->hwqcb_busaddr); 99} 100 101static bus_addr_t 102ida_v4_done(struct ida_softc *ida) 103{ 104 bus_addr_t completed; 105 106 completed = ida_inl(ida, R_42XX_REPLY); 107 if (completed == -1) 108 return (0); /* fifo is empty */ 109 ida_outl(ida, R_42XX_REPLY, 0); /* confirm read */ 110 return (completed); 111} 112 113static int 114ida_v4_int_pending(struct ida_softc *ida) 115{ 116 return (ida_inl(ida, R_42XX_STATUS) & STATUS_42XX_INT_PENDING); 117} 118 119static void 120ida_v4_int_enable(struct ida_softc *ida, int enable) 121{ 122 ida_outl(ida, R_42XX_INT_MASK, 123 enable ? INT_ENABLE_42XX : INT_DISABLE_42XX); 124} 125 126static struct ida_access ida_v3_access = { 127 ida_v3_fifo_full, 128 ida_v3_submit, 129 ida_v3_done, 130 ida_v3_int_pending, 131 ida_v3_int_enable, 132}; 133 134static struct ida_access ida_v4_access = { 135 ida_v4_fifo_full, 136 ida_v4_submit, 137 ida_v4_done, 138 ida_v4_int_pending, 139 ida_v4_int_enable, 140}; 141 142static struct ida_board board_id[] = { 143 { 0x4030, "Compaq SMART-2/P array controller", &ida_v3_access }, 144 { 0x4031, "Compaq SMART-2SL array controller", &ida_v3_access }, 145 { 0x4032, "Compaq Smart Array 3200 controller", &ida_v3_access }, 146 { 0x4033, "Compaq Smart Array 3100ES controller", &ida_v3_access }, 147 { 0x4034, "Compaq Smart Array 221 controller", &ida_v3_access }, 148 149 { 0x4040, "Compaq Integrated Array controller", &ida_v4_access }, 150 { 0x4050, "Compaq Smart Array 4200 controller", &ida_v4_access }, 151 { 0x4051, "Compaq Smart Array 4250ES controller", &ida_v4_access }, 152 { 0x4058, "Compaq Smart Array 431 controller", &ida_v4_access }, 153 154 { IDA_DEVICEID_DEC_SMART, 155 "DEC/Compaq Smart Array 4200 controller", &ida_v4_access }, 156 { IDA_DEVICEID_NCR_53C1510, 157 "NCR/Compaq Integrated Array controller", &ida_v4_access }, 158 159 { 0, "", 0 }, 160}; 161 162static int ida_pci_probe(device_t dev); 163static int ida_pci_attach(device_t dev); 164 165static device_method_t ida_pci_methods[] = { 166 DEVMETHOD(device_probe, ida_pci_probe), 167 DEVMETHOD(device_attach, ida_pci_attach), 168 DEVMETHOD(device_detach, ida_detach), 169 170 DEVMETHOD(bus_print_child, bus_generic_print_child), 171 172 { 0, 0 } 173}; 174 175static driver_t ida_pci_driver = { 176 "ida", 177 ida_pci_methods, 178 sizeof(struct ida_softc) 179}; 180 181static devclass_t ida_devclass; 182 183static struct ida_board * 184ida_pci_match(u_int32_t id) 185{ 186 int i; 187 188 for (i = 0; board_id[i].board; i++) 189 if (board_id[i].board == id) 190 return (&board_id[i]); 191 return (NULL); 192} 193 194static int 195ida_pci_probe(device_t dev) 196{ 197 struct ida_board *board = NULL; 198 u_int32_t id = pci_get_devid(dev); 199 200 if (id == IDA_DEVICEID_SMART) 201 board = ida_pci_match(pci_get_subdevice(dev)); 202 if (id == IDA_DEVICEID_DEC_SMART || 203 id == IDA_DEVICEID_NCR_53C1510) 204 board = ida_pci_match(id); 205 if (board != NULL) { 206 device_set_desc(dev, board->desc); 207 return (0); 208 } 209 return (ENXIO); 210} 211 212static int 213ida_pci_attach(device_t dev) 214{ 215 struct ida_board *board; 216 struct ida_softc *ida; 217 u_int command; 218 int error, rid; 219 220 command = pci_read_config(dev, PCIR_COMMAND, 1); 221 222 /* 223 * it appears that this board only does MEMIO access. 224 */ 225 if ((command & PCIM_CMD_MEMEN) == 0) { 226 device_printf(dev, "Only memory mapped I/O is supported\n"); 227 return (ENXIO); 228 } 229 230 ida = (struct ida_softc *)device_get_softc(dev); 231 ida->dev = dev; 232 233 board = ida_pci_match(pci_get_devid(dev)); 234 if (board == NULL) 235 board = ida_pci_match(pci_get_subdevice(dev)); 236 ida->cmd = *board->accessor; 237 238 ida->regs_res_type = SYS_RES_MEMORY; 239 ida->regs_res_id = IDA_PCI_MEMADDR; 240 if (board->board == IDA_DEVICEID_DEC_SMART) 241 ida->regs_res_id = PCIR_MAPS; 242 243 ida->regs = bus_alloc_resource(dev, ida->regs_res_type, 244 &ida->regs_res_id, 0, ~0, 1, RF_ACTIVE); 245 if (ida->regs == NULL) { 246 device_printf(dev, "can't allocate memory resources\n"); 247 return (ENOMEM); 248 } 249 250 error = bus_dma_tag_create(/*parent*/NULL, /*alignment*/1, 251 /*boundary*/0, /*lowaddr*/BUS_SPACE_MAXADDR_32BIT, 252 /*highaddr*/BUS_SPACE_MAXADDR, /*filter*/NULL, /*filterarg*/NULL, 253 /*maxsize*/MAXBSIZE, /*nsegments*/IDA_NSEG, 254 /*maxsegsize*/BUS_SPACE_MAXSIZE_32BIT, /*flags*/BUS_DMA_ALLOCNOW, 255 &ida->parent_dmat); 256 if (error != 0) { 257 device_printf(dev, "can't allocate DMA tag\n"); 258 ida_free(ida); 259 return (ENOMEM); 260 } 261 262 rid = 0; 263 ida->irq_res_type = SYS_RES_IRQ; 264 ida->irq = bus_alloc_resource(dev, ida->irq_res_type, &rid, 265 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE); 266 if (ida->irq == NULL) { 267 ida_free(ida); 268 return (ENOMEM); 269 } 270 error = bus_setup_intr(dev, ida->irq, INTR_TYPE_BIO, 271 ida_intr, ida, &ida->ih); 272 if (error) { 273 device_printf(dev, "can't setup interrupt\n"); 274 ida_free(ida); 275 return (ENOMEM); 276 } 277 278 ida->flags = 0; 279 error = ida_init(ida); 280 if (error) { 281 ida_free(ida); 282 return (error); 283 } 284 ida_attach(ida); 285 ida->flags |= IDA_ATTACHED; 286 287 return (0); 288} 289 290DRIVER_MODULE(ida, pci, ida_pci_driver, ida_devclass, 0, 0); 291